Skip to content

Commit

Permalink
Merge pull request #209 from forcedotcom/mdonnalley/cjs-eslint
Browse files Browse the repository at this point in the history
feat: replace .eslintrc.js with .eslintrc.cjs
  • Loading branch information
mshanemc committed Aug 31, 2023
2 parents ff06259 + 368b038 commit e760b5b
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 8 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.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down 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 e760b5b

Please sign in to comment.