Skip to content

Commit dec2166

Browse files
authored
feat(core): Add ESM support for Eslint config file (#29613)
This pull request includes changes to migrate ESLint configuration files from CommonJS (`.cjs`) to ECMAScript modules (`.mjs`) as the default. ### ESLint Configuration Generation Changes The changes also ensure consistent generated eslint configs based on the base eslint config. - If the workspace root has an `eslint.config.cjs` or `eslint.config.js` with `module.exports`. When you create a library or application it will generate an accompanying config at path `{projectRoot}/eslint.config.cjs` of the same format. - If the workspace root has an `eslint.config.mjs` or `eslint.config.mjs` with `export default`. When you create a library or application it will generate an accompanying config at path `{projectRoot}/eslint.config.mjs`. - If no eslint config is found at the workspace root one will be created `eslint.config.mjs`
1 parent a468d72 commit dec2166

File tree

33 files changed

+4289
-1269
lines changed

33 files changed

+4289
-1269
lines changed

e2e/angular/src/misc.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ describe('Move Angular Project', () => {
3939
expect(moveOutput).toContain(`CREATE ${newPath}/tsconfig.app.json`);
4040
expect(moveOutput).toContain(`CREATE ${newPath}/tsconfig.json`);
4141
expect(moveOutput).toContain(`CREATE ${newPath}/tsconfig.spec.json`);
42-
expect(moveOutput).toContain(`CREATE ${newPath}/eslint.config.cjs`);
42+
expect(moveOutput).toContain(`CREATE ${newPath}/eslint.config.mjs`);
4343
expect(moveOutput).toContain(`CREATE ${newPath}/public/favicon.ico`);
4444
expect(moveOutput).toContain(`CREATE ${newPath}/src/index.html`);
4545
expect(moveOutput).toContain(`CREATE ${newPath}/src/main.ts`);

e2e/angular/src/projects.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,13 @@ describe('Angular Projects', () => {
164164

165165
it('should lint correctly with eslint and handle external HTML files and inline templates', async () => {
166166
// disable the prefer-standalone rule for app1 which is not standalone
167-
let app1EslintConfig = readFile(`${app1}/eslint.config.cjs`);
167+
let app1EslintConfig = readFile(`${app1}/eslint.config.mjs`);
168168
app1EslintConfig = app1EslintConfig.replace(
169169
`'@angular-eslint/directive-selector': [`,
170170
`'@angular-eslint/prefer-standalone': 'off',
171171
'@angular-eslint/directive-selector': [`
172172
);
173-
updateFile(`${app1}/eslint.config.cjs`, app1EslintConfig);
173+
updateFile(`${app1}/eslint.config.mjs`, app1EslintConfig);
174174

175175
// check apps and lib pass linting for initial generated code
176176
runCLI(`run-many --target lint --projects=${app1},${lib1} --parallel`);

e2e/eslint/src/linter-legacy.test.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,10 @@ describe('Linter (legacy)', () => {
150150
env: { NX_ADD_PLUGINS: 'false' },
151151
});
152152
checkFilesExist(
153-
'eslint.config.cjs',
154-
`apps/${myapp}/eslint.config.cjs`,
155-
`libs/${mylib}/eslint.config.cjs`,
156-
`libs/${mylib2}/eslint.config.cjs`
153+
'eslint.config.mjs',
154+
`apps/${myapp}/eslint.config.mjs`,
155+
`libs/${mylib}/eslint.config.mjs`,
156+
`libs/${mylib2}/eslint.config.mjs`
157157
);
158158
checkFilesDoNotExist(
159159
'.eslintrc.json',
@@ -164,12 +164,12 @@ describe('Linter (legacy)', () => {
164164

165165
// move eslint.config one step up
166166
// to test the absence of the flat eslint config in the project root folder
167-
renameFile(`libs/${mylib2}/eslint.config.cjs`, `libs/eslint.config.cjs`);
167+
renameFile(`libs/${mylib2}/eslint.config.mjs`, `libs/eslint.config.mjs`);
168168
updateFile(
169-
`libs/eslint.config.cjs`,
170-
readFile(`libs/eslint.config.cjs`).replace(
171-
`../../eslint.config.cjs`,
172-
`../eslint.config.cjs`
169+
`libs/eslint.config.mjs`,
170+
readFile(`libs/eslint.config.mjs`).replace(
171+
`../../eslint.config.mjs`,
172+
`../eslint.config.mjs`
173173
)
174174
);
175175

@@ -202,9 +202,9 @@ describe('Linter (legacy)', () => {
202202
env: { NX_ADD_PLUGINS: 'false' },
203203
});
204204
checkFilesExist(
205-
'eslint.config.cjs',
206-
`${mylib}/eslint.config.cjs`,
207-
'eslint.base.config.cjs'
205+
'eslint.config.mjs',
206+
`${mylib}/eslint.config.mjs`,
207+
'eslint.base.config.mjs'
208208
);
209209
checkFilesDoNotExist(
210210
'.eslintrc.json',

e2e/eslint/src/linter.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -615,8 +615,8 @@ describe('Linter', () => {
615615
runCLI(`generate @nx/js:lib ${jsLib} --linter eslint`);
616616

617617
checkFilesExist(
618-
`${reactLib}/eslint.config.cjs`,
619-
`${jsLib}/eslint.config.cjs`
618+
`${reactLib}/eslint.config.mjs`,
619+
`${jsLib}/eslint.config.mjs`
620620
);
621621
checkFilesDoNotExist(
622622
`${reactLib}/.eslintrc.json`,

e2e/nx/src/__snapshots__/extras.test.ts.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ exports[`Extra Nx Misc Tests task graph inputs should correctly expand dependent
2626
],
2727
"lib-base-123": [
2828
"libs/lib-base-123/README.md",
29-
"libs/lib-base-123/eslint.config.cjs",
29+
"libs/lib-base-123/eslint.config.mjs",
3030
"libs/lib-base-123/jest.config.ts",
3131
"libs/lib-base-123/package.json",
3232
"libs/lib-base-123/project.json",
@@ -39,7 +39,7 @@ exports[`Extra Nx Misc Tests task graph inputs should correctly expand dependent
3939
],
4040
"lib-dependent-123": [
4141
"libs/lib-dependent-123/README.md",
42-
"libs/lib-dependent-123/eslint.config.cjs",
42+
"libs/lib-dependent-123/eslint.config.mjs",
4343
"libs/lib-dependent-123/jest.config.ts",
4444
"libs/lib-dependent-123/package.json",
4545
"libs/lib-dependent-123/project.json",

packages/angular/src/generators/ng-add/__snapshots__/migrate-from-angular-cli.spec.ts.snap

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ exports[`workspace move to nx layout should create nx.json 1`] = `
9494
"!{projectRoot}/karma.conf.js",
9595
"!{projectRoot}/.eslintrc.json",
9696
"!{projectRoot}/eslint.config.cjs",
97+
"!{projectRoot}/eslint.config.mjs",
9798
],
9899
"sharedGlobals": [],
99100
},
@@ -104,7 +105,7 @@ exports[`workspace move to nx layout should create nx.json 1`] = `
104105
"default",
105106
"{workspaceRoot}/.eslintrc.json",
106107
"{workspaceRoot}/.eslintignore",
107-
"{workspaceRoot}/eslint.config.cjs",
108+
"{workspaceRoot}/eslint.config.mjs",
108109
],
109110
},
110111
"build": {

0 commit comments

Comments
 (0)