Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: replace .eslintrc.js with .eslintrc.cjs #209

Merged
merged 2 commits into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading