Skip to content

Commit

Permalink
feat: replace .eslintrc.js with .eslintrc.cjs
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonnalley committed Aug 24, 2023
1 parent ff06259 commit dbf8b28
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 7 deletions.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
2 changes: 1 addition & 1 deletion files/eslintrc-test.js → files/eslintrc-test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

module.exports = {
extends: '../.eslintrc.js',
extends: '../.eslintrc.cjs',
// Allow describe and it
env: { mocha: true },
rules: {
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,4 @@
"publishConfig": {
"access": "public"
}
}
}
34 changes: 30 additions & 4 deletions utils/standardize-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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));
}

Expand Down

0 comments on commit dbf8b28

Please sign in to comment.