diff --git a/files/eslintrc-strict.js b/files/eslintrc-strict.cjs similarity index 100% rename from files/eslintrc-strict.js rename to files/eslintrc-strict.cjs diff --git a/files/eslintrc-test-strict.js b/files/eslintrc-test-strict.cjs similarity index 97% rename from files/eslintrc-test-strict.js rename to files/eslintrc-test-strict.cjs index b98fb7d4..da31d212 100644 --- a/files/eslintrc-test-strict.js +++ b/files/eslintrc-test-strict.cjs @@ -9,7 +9,7 @@ // See more at https://github.com/forcedotcom/sfdx-dev-packages/tree/master/packages/dev-scripts module.exports = { - extends: '../.eslintrc.js', + extends: '../.eslintrc.cjs', // Allow describe and it env: { mocha: true }, rules: { diff --git a/files/eslintrc-test.js b/files/eslintrc-test.cjs similarity index 96% rename from files/eslintrc-test.js rename to files/eslintrc-test.cjs index 79fd9f43..fadf2c90 100644 --- a/files/eslintrc-test.js +++ b/files/eslintrc-test.cjs @@ -6,7 +6,7 @@ */ module.exports = { - extends: '../.eslintrc.js', + extends: '../.eslintrc.cjs', // Allow describe and it env: { mocha: true }, rules: { diff --git a/files/eslintrc.js b/files/eslintrc.cjs similarity index 100% rename from files/eslintrc.js rename to files/eslintrc.cjs diff --git a/package.json b/package.json index 1b2bc3a4..53f309a3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@salesforce/dev-scripts", - "version": "5.7.0", + "version": "5.7.1-qa.0", "description": "Standardize package.json scripts and config files for Salesforce projects.", "repository": "forcedotcom/dev-scripts", "bin": { @@ -68,4 +68,4 @@ "publishConfig": { "access": "public" } -} \ No newline at end of file +} diff --git a/utils/standardize-files.js b/utils/standardize-files.js index 6a851f64..b7f7d105 100644 --- a/utils/standardize-files.js +++ b/utils/standardize-files.js @@ -92,6 +92,14 @@ function writeMocharcJson(targetDir) { return copyFile(mocharcSourcePath, gitignoreTargetPath); } +function replaceInFile(filePath, replaceFn) { + const contents = readFileSync(filePath, 'utf8'); + const newContents = replaceFn(contents); + if (newContents !== contents) { + writeFileSync(filePath, newContents); + } +} + // eslint-disable-next-line complexity module.exports = (packageRoot = require('./package-path')) => { const config = resolveConfig(packageRoot); @@ -126,13 +134,31 @@ module.exports = (packageRoot = require('./package-path')) => { const lintConfig = config.lint || {}; const strict = config.strict || lintConfig.strict; - const eslintSourcePath = join(FILES_PATH, strict ? 'eslintrc-strict.js' : 'eslintrc.js'); - const eslintTargetPath = join(packageRoot, '.eslintrc.js'); + const eslintJsTargetPath = join(packageRoot, '.eslintrc.js'); + // if .eslintrc.js exists, copy it to .eslintrc.cjs and remove .eslintrc.js + if (exists(eslintJsTargetPath)) { + replaceInFile(eslintJsTargetPath, (contents) => contents.replace(/eslintrc.js/, 'eslintrc.cjs')); + added.push(copyFile(eslintJsTargetPath, eslintJsTargetPath.replace('.js', '.cjs'), strict)); + unlinkSync(eslintJsTargetPath); + removed.push(eslintJsTargetPath); + } + + const eslintSourcePath = join(FILES_PATH, strict ? 'eslintrc-strict.cjs' : 'eslintrc.cjs'); + const eslintTargetPath = join(packageRoot, '.eslintrc.cjs'); added.push(copyFile(eslintSourcePath, eslintTargetPath, strict)); if (exists(testPath)) { - const eslintTestSourcePath = join(FILES_PATH, strict ? 'eslintrc-test-strict.js' : 'eslintrc-test.js'); - const eslintTestTargetPath = join(testPath, '.eslintrc.js'); + const eslintJsTestTargetPath = join(testPath, '.eslintrc.js'); + // if .eslintrc.js exists, copy it to .eslintrc.cjs and remove .eslintrc.js + if (exists(eslintJsTestTargetPath)) { + replaceInFile(eslintJsTestTargetPath, (contents) => contents.replace(/eslintrc.js/, 'eslintrc.cjs')); + added.push(copyFile(eslintJsTestTargetPath, eslintJsTestTargetPath.replace('.js', '.cjs'), strict)); + unlinkSync(eslintJsTestTargetPath); + removed.push(eslintJsTestTargetPath); + } + + const eslintTestSourcePath = join(FILES_PATH, strict ? 'eslintrc-test-strict.cjs' : 'eslintrc-test.cjs'); + const eslintTestTargetPath = join(testPath, '.eslintrc.cjs'); added.push(copyFile(eslintTestSourcePath, eslintTestTargetPath, strict)); }