@o3r/eslint-config 12.3.0-prerelease.9 → 12.4.0-prerelease.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@o3r/eslint-config",
3
- "version": "12.3.0-prerelease.9",
3
+ "version": "12.4.0-prerelease.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -13,6 +13,9 @@
13
13
  ".": {
14
14
  "default": "./src/rules/typescript.cjs"
15
15
  },
16
+ "./helpers": {
17
+ "default": "./src/helpers/index.cjs"
18
+ },
16
19
  "./typescript": {
17
20
  "default": "./src/rules/typescript.cjs"
18
21
  },
@@ -33,22 +36,25 @@
33
36
  "prepare:build:builders": "yarn cpy 'schematics/**/*.json' 'schematics/**/templates/**' dist/schematics && yarn cpy 'collection.json' dist",
34
37
  "build:builders": "tsc -b tsconfig.builders.json --pretty && yarn generate-cjs-manifest"
35
38
  },
39
+ "dependencies": {
40
+ "@o3r/schematics": "^12.4.0-prerelease.0"
41
+ },
36
42
  "peerDependencies": {
37
43
  "@angular-devkit/core": "^19.0.0",
38
44
  "@angular-devkit/schematics": "^19.0.0",
39
45
  "@angular-eslint/builder": "^19.0.0",
40
46
  "@angular/compiler": "^19.0.0",
41
47
  "@eslint-community/eslint-plugin-eslint-comments": "^4.4.0",
42
- "@eslint/js": "^8.57.0 || ^9.16.0",
43
- "@o3r/eslint-plugin": "^12.3.0-prerelease.9",
44
- "@o3r/schematics": "^12.3.0-prerelease.9",
48
+ "@eslint/js": "^8.57.0 || ^9.22.0",
49
+ "@o3r/eslint-plugin": "^12.4.0-prerelease.0",
50
+ "@o3r/schematics": "^12.4.0-prerelease.0",
45
51
  "@schematics/angular": "^19.0.0",
46
52
  "@stylistic/eslint-plugin": "~3.1.0",
47
53
  "@typescript-eslint/parser": "^8.15.0",
48
54
  "@typescript-eslint/types": "^8.15.0",
49
55
  "@typescript-eslint/utils": "^8.15.0",
50
56
  "angular-eslint": "^19.0.0",
51
- "eslint": "^8.57.0 || ^9.16.0",
57
+ "eslint": "^8.57.0 || ^9.22.0",
52
58
  "eslint-import-resolver-node": "^0.3.4",
53
59
  "eslint-import-resolver-typescript": "^3.6.3",
54
60
  "eslint-plugin-import": "^2.31.0",
@@ -63,6 +69,7 @@
63
69
  "jest": "^29.7.0",
64
70
  "jsonc-eslint-parser": "^2.4.0",
65
71
  "ts-node": "^10.9.2",
72
+ "type-fest": "^4.30.1",
66
73
  "typescript": "^5.5.4",
67
74
  "typescript-eslint": "^8.15.0"
68
75
  },
@@ -71,21 +78,20 @@
71
78
  "@angular-devkit/schematics": "~19.2.0",
72
79
  "@angular/compiler": "~19.2.0",
73
80
  "@eslint-community/eslint-plugin-eslint-comments": "^4.4.0",
74
- "@eslint/js": "~9.23.0",
75
- "@nx/eslint-plugin": "~20.7.0",
76
- "@o3r/build-helpers": "^12.3.0-prerelease.9",
77
- "@o3r/eslint-plugin": "^12.3.0-prerelease.9",
78
- "@o3r/schematics": "^12.3.0-prerelease.9",
79
- "@o3r/test-helpers": "^12.3.0-prerelease.9",
81
+ "@eslint/js": "~9.26.0",
82
+ "@nx/eslint-plugin": "~20.8.0",
83
+ "@o3r/build-helpers": "^12.4.0-prerelease.0",
84
+ "@o3r/eslint-plugin": "^12.4.0-prerelease.0",
85
+ "@o3r/test-helpers": "^12.4.0-prerelease.0",
80
86
  "@schematics/angular": "~19.2.0",
81
87
  "@stylistic/eslint-plugin": "~3.1.0",
82
88
  "@types/eslint__js": "^8.42.3",
83
89
  "@types/jest": "~29.5.2",
84
90
  "@types/node": "^20.0.0",
85
- "@typescript-eslint/parser": "~8.29.0",
86
- "angular-eslint": "~19.3.0",
91
+ "@typescript-eslint/parser": "~8.32.0",
92
+ "angular-eslint": "~19.4.0",
87
93
  "cpy-cli": "^5.0.0",
88
- "eslint": "~9.23.0",
94
+ "eslint": "~9.26.0",
89
95
  "eslint-import-resolver-node": "~0.3.9",
90
96
  "eslint-import-resolver-typescript": "~3.10.0",
91
97
  "eslint-plugin-import": "~2.31.0",
@@ -99,7 +105,7 @@
99
105
  "jest": "~29.7.0",
100
106
  "jest-junit": "~16.0.0",
101
107
  "jsonc-eslint-parser": "~2.4.0",
102
- "nx": "~20.7.0",
108
+ "nx": "~20.8.0",
103
109
  "pid-from-port": "^1.1.3",
104
110
  "rxjs": "^7.8.1",
105
111
  "semver": "^7.5.2",
@@ -108,7 +114,7 @@
108
114
  "tslib": "^2.6.2",
109
115
  "type-fest": "^4.30.1",
110
116
  "typescript": "~5.8.2",
111
- "typescript-eslint": "~8.29.0"
117
+ "typescript-eslint": "~8.32.0"
112
118
  },
113
119
  "peerDependenciesMeta": {
114
120
  "@angular-devkit/core": {
@@ -144,6 +150,9 @@
144
150
  "jest": {
145
151
  "optional": true
146
152
  },
153
+ "type-fest": {
154
+ "optional": true
155
+ },
147
156
  "typescript": {
148
157
  "optional": true
149
158
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../schematics/ng-add/eslint/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAQL,KAAK,IAAI,EAGV,MAAM,4BAA4B,CAAC;AAqCpC;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,GAAI,UAAU,MAAM,EAAE,cAAc,MAAM,KAAG,IA4D3E,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../schematics/ng-add/eslint/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAQL,KAAK,IAAI,EAGV,MAAM,4BAA4B,CAAC;AAyCpC;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,GAAI,UAAU,MAAM,EAAE,cAAc,MAAM,KAAG,IA2D3E,CAAC"}
@@ -4,12 +4,12 @@ exports.updateEslintConfig = void 0;
4
4
  const path = require("node:path");
5
5
  const core_1 = require("@angular-devkit/core");
6
6
  const schematics_1 = require("@angular-devkit/schematics");
7
+ const schematics_2 = require("@o3r/schematics");
7
8
  const index_1 = require("../tsconfig/index");
8
- const editAngularJson = (projectName, extension) => async (tree, context) => {
9
+ const editAngularJson = (projectName, extension) => (tree, context) => {
9
10
  let workspace = null;
10
11
  try {
11
- const { getWorkspaceConfig } = await Promise.resolve().then(() => require('@o3r/schematics'));
12
- workspace = getWorkspaceConfig(tree);
12
+ workspace = (0, schematics_2.getWorkspaceConfig)(tree);
13
13
  }
14
14
  catch {
15
15
  context.logger.warn(`No @o3r/schematics installed, we could not detect the workspace. The linter task for ${projectName} can not be added.`);
@@ -37,13 +37,12 @@ const editAngularJson = (projectName, extension) => async (tree, context) => {
37
37
  * @param rootPath
38
38
  * @param projectName
39
39
  */
40
- const updateEslintConfig = (rootPath, projectName) => async (tree, context) => {
41
- const { findFilesInTree, getTemplateFolder, getWorkspaceConfig } = await Promise.resolve().then(() => require('@o3r/schematics'));
42
- const workspace = getWorkspaceConfig(tree);
40
+ const updateEslintConfig = (rootPath, projectName) => (tree, context) => {
41
+ const workspace = (0, schematics_2.getWorkspaceConfig)(tree);
43
42
  const workspaceProject = workspace?.projects[projectName || ''];
44
43
  const projectRootPath = workspaceProject?.root || '.';
45
44
  const workingDir = tree.getDir(projectRootPath);
46
- const eslintConfigFiles = findFilesInTree(workingDir, (file) => /eslint.config.[cm]?js/.test(file));
45
+ const eslintConfigFiles = (0, schematics_2.findFilesInTree)(workingDir, (file) => /eslint.config.[cm]?js/.test(file));
47
46
  if (eslintConfigFiles.length > 1) {
48
47
  context.logger.warn('Unable to add the "@o3r/eslint-config" recommendation because several ESLint config file detected.\n'
49
48
  + eslintConfigFiles.map((file) => `\t- ${file.path.toString()}`).join('\n'));
@@ -56,7 +55,7 @@ const updateEslintConfig = (rootPath, projectName) => async (tree, context) => {
56
55
  oldConfig: '',
57
56
  relativePathToRoot: path.posix.relative(projectRootPath, '.'),
58
57
  packageName: tree.readJson(workingDir.file((0, core_1.fragment)('package.json'))?.path || 'package.json').name,
59
- detectedTsConfigs: findFilesInTree(workingDir, (f) => /tsconfig\..*\.json/.test(f)).map((entry) => path.basename(entry.path)).concat('tsconfig.eslint.json'),
58
+ detectedTsConfigs: (0, schematics_2.findFilesInTree)(workingDir, (f) => /tsconfig\..*\.json/.test(f)).map((entry) => path.basename(entry.path)).concat('tsconfig.eslint.json'),
60
59
  isApp: workspaceProject?.projectType === 'application'
61
60
  };
62
61
  if (eslintConfigFiles.length === 1) {
@@ -81,7 +80,7 @@ const updateEslintConfig = (rootPath, projectName) => async (tree, context) => {
81
80
  projectName ? editAngularJson(projectName, templateOptions.extension) : (0, schematics_1.noop)(),
82
81
  (0, schematics_1.applyToSubtree)(projectRootPath, [
83
82
  (0, index_1.updateOrAddTsconfigEslint)(rootPath),
84
- (0, schematics_1.mergeWith)((0, schematics_1.apply)((0, schematics_1.url)(getTemplateFolder(rootPath, __dirname, `./templates/${projectRootPath === '.' ? 'workspace' : 'project'}`)), [
83
+ (0, schematics_1.mergeWith)((0, schematics_1.apply)((0, schematics_1.url)((0, schematics_2.getTemplateFolder)(rootPath, __dirname, `./templates/${projectRootPath === '.' ? 'workspace' : 'project'}`)), [
85
84
  (0, schematics_1.template)(templateOptions),
86
85
  (0, schematics_1.renameTemplateFiles)()
87
86
  ]), schematics_1.MergeStrategy.Overwrite)
@@ -1,10 +1,14 @@
1
- <% if (extension === 'mjs') { %>import local from './eslint.local.config.mjs';
1
+ <% if (extension === 'mjs') { %>import {
2
+ defineConfig,
3
+ } from 'eslint/config';
4
+ import local from './eslint.local.config.mjs';
2
5
  import shared from '<%= relativePathToRoot %>/eslint.shared.config.mjs';
3
- <% } else { %>const local = require('./eslint.local.config.<%= extension %>');
6
+ <% } else { %>const { defineConfig } = require('eslint/config');
7
+ const local = require('./eslint.local.config.<%= extension %>');
4
8
  const shared = require('<%= relativePathToRoot %>/eslint.shared.config.<%= extension %>');
5
9
  <% } %>
6
10
 
7
- <%= extension === 'mjs' ? 'export default' : 'module.exports =' %> [
11
+ <%= extension === 'mjs' ? 'export default' : 'module.exports =' %> defineConfig([
8
12
  ...shared,
9
13
  ...local
10
- ];
14
+ ]);
@@ -1,31 +1,35 @@
1
- <% if (extension === 'mjs') { %>import { dirname } from 'node:path';
2
- import { fileURLToPath } from 'node:url';
1
+ <% if (extension === 'mjs') { %>import {
2
+ defineConfig,
3
+ } from 'eslint/config';
4
+ import {
5
+ dirname,
6
+ } from 'node:path';
7
+ import {
8
+ fileURLToPath,
9
+ } from 'node:url';
3
10
  <% if (isApp) {
4
11
  %>import globals from 'globals';<%
5
12
  } %>
6
13
  const __filename = fileURLToPath(import.meta.url);
7
14
  // __dirname is not defined in ES module scope
8
15
  const __dirname = dirname(__filename);
9
- <% } else if (isApp) { %>const globals = require('globals');
16
+ <% } else { %>const { defineConfig } = require('eslint/config');
17
+ <% if (isApp) { %>const globals = require('globals');
10
18
  <% } %>
11
- <%= extension === 'mjs' ? 'export default' : 'module.exports =' %> [
19
+ <% } %>
20
+
21
+ <%= extension === 'mjs' ? 'export default' : 'module.exports =' %> defineConfig([
12
22
  {
13
23
  name: '<%= packageName %>/projects',
14
24
  languageOptions: {
15
25
  sourceType: 'module',
16
26
  parserOptions: {
17
27
  tsconfigRootDir: __dirname,
18
- project: [
19
- <%= detectedTsConfigs.map((tsconfig) => ` '${tsconfig}'`).join(',\n') %>
20
- ]
28
+ projectService: true
21
29
  }<% if (isApp) { %>,
22
30
  globals: {
23
31
  ...globals.browser
24
32
  }<% } %>
25
33
  }
26
- },
27
- {
28
- name: '<%= packageName %>/ignores',
29
- ignores: []
30
34
  }
31
- ];
35
+ ]);
@@ -1,66 +1,20 @@
1
1
  <% if (extension === 'mjs') { %>import {
2
+ mergeESLintFlatConfigs,
3
+ } from '@o3r/eslint-config/helpers';
4
+ import {
2
5
  dirname,
3
- posix,
4
- relative,
5
- sep
6
6
  } from 'node:path';
7
7
  import {
8
8
  fileURLToPath,
9
- pathToFileURL
10
9
  } from 'node:url';
11
10
  import shared from './eslint.shared.config.mjs';
12
- import {
13
- sync
14
- } from 'globby';
15
11
 
16
12
  const __filename = fileURLToPath(import.meta.url);
17
13
  // __dirname is not defined in ES module scope
18
14
  const __dirname = dirname(__filename);
19
15
  <% } else { %>
20
- const { dirname, posix, relative, sep } = require('node:path');
21
- const { sync } = require('globby');
16
+ const { mergeESLintFlatConfigs } = require('@o3r/eslint-config/helpers');
22
17
  const shared = require('./eslint.shared.config.<%= extension %>');
23
18
  <% } %>
24
19
 
25
- /**
26
- * Add a prefix to a path glob
27
- * @param {string} prefix
28
- * @param {string | undefined} pathGlob
29
- * @returns {string}
30
- */
31
- const addPrefix = (prefix, pathGlob = '**/*') => pathGlob.replace(/^(!?)(\.?\/)?/, `$1${prefix}/`).replaceAll(sep, posix.sep).replace(/^\//, '');
32
-
33
- /**
34
- * Merge ESLint config
35
- * @param {string | string[]} globs List of globs to find ESLint config path
36
- * @returns {Promise<import('@typescript-eslint/utils').TSESLint.FlatConfig.ConfigArray>}
37
- */
38
- const mergeESLintConfigs = async (globs) => {
39
- const localConfigFiles = sync(globs, { absolute: true });
40
- /** @type {import('@typescript-eslint/utils').TSESLint.FlatConfig.ConfigArray} */
41
- let localConfigs = [];
42
- for (const localConfigFile of localConfigFiles) {
43
- const module = await import(pathToFileURL(localConfigFile));
44
- const moduleConfig = await (module.default ?? module);
45
- /** @type {import('@typescript-eslint/utils').TSESLint.FlatConfig.ConfigArray} */
46
- const configArray = Array.isArray(moduleConfig) ? moduleConfig : [moduleConfig];
47
- const directory = relative(__dirname, dirname(localConfigFile));
48
- localConfigs = localConfigs.concat(
49
- configArray.map((config) => ({
50
- ...config,
51
- ...(
52
- config.ignores
53
- ? { ignores: config.ignores.map((pathGlob) => addPrefix(directory, pathGlob)) }
54
- : { files: (config.files || ['**/*']).flat().map((pathGlob) => addPrefix(directory, pathGlob)) }
55
- )
56
- }))
57
- );
58
- }
59
-
60
- return [
61
- ...shared,
62
- ...localConfigs
63
- ];
64
- };
65
-
66
- <%= extension === 'mjs' ? 'export default' : 'module.exports =' %> mergeESLintConfigs('**/eslint.local.config.mjs');
20
+ <%= extension === 'mjs' ? 'export default' : 'module.exports =' %> mergeESLintFlatConfigs(__dirname, '**/eslint.local.config.mjs', shared);
@@ -1,22 +1,29 @@
1
- <% if (extension === 'mjs') { %>import { dirname } from 'node:path';
2
- import { fileURLToPath } from 'node:url';
1
+ <% if (extension === 'mjs') { %>import {
2
+ defineConfig,
3
+ } from 'eslint/config';
4
+ import {
5
+ dirname,
6
+ } from 'node:path';
7
+ import {
8
+ fileURLToPath,
9
+ } from 'node:url';
3
10
 
4
11
  const __filename = fileURLToPath(import.meta.url);
5
12
  // __dirname is not defined in ES module scope
6
13
  const __dirname = dirname(__filename);
14
+ <% } else { %>const { defineConfig } = require('eslint/config');
15
+ <% } %>
7
16
 
8
- <% } %><%= codeBeforeConfig %><%= extension === 'mjs' ? 'export default' : 'module.exports =' %> [
17
+ <%= codeBeforeConfig %><%= extension === 'mjs' ? 'export default' : 'module.exports =' %> defineConfig([
9
18
  {
10
19
  name: '<%= packageName %>/projects',
11
20
  languageOptions: {
12
21
  sourceType: 'commonjs',
13
22
  parserOptions: {
14
23
  tsconfigRootDir: __dirname,
15
- project: [
16
- <%= detectedTsConfigs.map((tsconfig) => ` '${tsconfig}'`).join(',\n') %>
17
- ]
24
+ projectService: true
18
25
  }
19
26
  }
20
27
  }
21
- ].concat(<%= oldConfig %>);
28
+ ].concat(<%= oldConfig %>));
22
29
  <%= codeAfterConfig %>
@@ -1,16 +1,29 @@
1
- <% if (extension === 'mjs') { %>import { dirname, join } from 'node:path';
2
- import { fileURLToPath } from 'node:url';
1
+ <% if (extension === 'mjs') { %>
2
+ import {
3
+ defineConfig,
4
+ globalIgnores,
5
+ } from 'eslint/config';
6
+ import {
7
+ dirname,
8
+ join,
9
+ } from 'node:path';
10
+ import {
11
+ fileURLToPath,
12
+ } from 'node:url';
3
13
  import o3rConfig from '@o3r/eslint-config';
4
14
  import o3rTemplate from '@o3r/eslint-config/template';
15
+ import jsonParser from 'jsonc-eslint-parser';
5
16
 
6
17
  const __filename = fileURLToPath(import.meta.url);
7
18
  // __dirname is not defined in ES module scope
8
19
  const __dirname = dirname(__filename);
9
20
  <% } else { %>const o3rConfig = require('@o3r/eslint-config');
10
21
  const o3rTemplate = require('@o3r/eslint-config/template');
22
+ const { defineConfig, globalIgnores } = require('eslint/config');
23
+ const jsonParser = require('jsonc-eslint-parser');
11
24
  <% } %>
12
25
 
13
- <%= extension === 'mjs' ? 'export default' : 'module.exports =' %> [
26
+ <%= extension === 'mjs' ? 'export default' : 'module.exports =' %> defineConfig([
14
27
  ...o3rConfig,
15
28
  ...o3rTemplate,
16
29
  {
@@ -19,9 +32,31 @@ const o3rTemplate = require('@o3r/eslint-config/template');
19
32
  reportUnusedDisableDirectives: 'error'
20
33
  }
21
34
  },
35
+ globalIgnores(
36
+ [
37
+ '**/dist/'
38
+ ],
39
+ '<%= packageName %>/ignores'
40
+ ),
22
41
  {
23
- name: '<%= packageName %>/ignores',
24
- ignores: []
42
+ name: '<%= packageName %>/parser/json',
43
+ files: ['**/*.json'],
44
+ languageOptions: {
45
+ parser: jsonParser
46
+ }
47
+ },
48
+ {
49
+ name: '<%= packageName %>/package-json',
50
+ files: ['**/package.json'],
51
+ rules: {
52
+ '@o3r/json-dependency-versions-harmonize': [
53
+ 'error',
54
+ {
55
+ alignPeerDependencies: false,
56
+ alignEngines: true
57
+ }
58
+ ]
59
+ }
25
60
  },
26
61
  {
27
62
  name: '<%= packageName %>/settings',
@@ -29,9 +64,7 @@ const o3rTemplate = require('@o3r/eslint-config/template');
29
64
  'import/resolver': {
30
65
  node: true,
31
66
  typescript: {
32
- project: [
33
- <%= detectedTsConfigs.map((tsconfig) => ` join(__dirname, '${tsconfig}')`).join(',\n') %>
34
- ]
67
+ projectService: true
35
68
  }
36
69
  }
37
70
  }
@@ -48,4 +81,4 @@ const o3rTemplate = require('@o3r/eslint-config/template');
48
81
  ]
49
82
  }
50
83
  }<% } %>
51
- ];
84
+ ]);
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../schematics/ng-add/index.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,KAAK,IAAI,EAGV,MAAM,4BAA4B,CAAC;AAIpC,OAAO,KAAK,EACV,qBAAqB,EACtB,MAAM,UAAU,CAAC;AAgIlB;;;GAGG;AACH,eAAO,MAAM,KAAK,GAAI,SAAS,qBAAqB,KAAG,IAKtD,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../schematics/ng-add/index.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,KAAK,IAAI,EAIV,MAAM,4BAA4B,CAAC;AAkBpC,OAAO,KAAK,EACV,qBAAqB,EACtB,MAAM,UAAU,CAAC;AA2IlB;;;GAGG;AACH,eAAO,MAAM,KAAK,GAAI,SAAS,qBAAqB,SAA2C,CAAC"}
@@ -3,19 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ngAdd = void 0;
4
4
  const path = require("node:path");
5
5
  const schematics_1 = require("@angular-devkit/schematics");
6
+ const schematics_2 = require("@o3r/schematics");
6
7
  const index_1 = require("./eslint/index");
7
8
  const index_2 = require("./vscode/index");
8
- const reportMissingSchematicsDep = (logger) => (reason) => {
9
- logger.error(`[ERROR]: Adding @o3r/eslint-config has failed.
10
- You need to install '@o3r/schematics' package to be able to use the eslint-config package. Please run 'ng add @o3r/schematics' .`);
11
- throw reason;
12
- };
13
- const handleOtterEslintErrors = (projectName) => async (tree, context) => {
9
+ const handleOtterEslintErrors = (projectName) => (tree, context) => {
14
10
  if (!projectName) {
15
11
  return;
16
12
  }
17
- const { getWorkspaceConfig } = await Promise.resolve().then(() => require('@o3r/schematics'));
18
- const workspace = getWorkspaceConfig(tree);
13
+ const workspace = (0, schematics_2.getWorkspaceConfig)(tree);
19
14
  if (!workspace) {
20
15
  return;
21
16
  }
@@ -37,6 +32,30 @@ const handleOtterEslintErrors = (projectName) => async (tree, context) => {
37
32
  }
38
33
  context.logger.warn('Linter errors may occur and should be fixed by hand or by running the linter with the option `--fix`.');
39
34
  };
35
+ /**
36
+ * Add a harmonize script in package.json
37
+ */
38
+ const addHarmonizeScript = () => {
39
+ const rootPackageJsonPath = '/package.json';
40
+ return (tree, context) => {
41
+ if (!tree.exists(rootPackageJsonPath)) {
42
+ throw new schematics_1.SchematicsException('Root package.json does not exist');
43
+ }
44
+ const isYarnPackageManager = (0, schematics_2.getPackageManager)() === 'yarn';
45
+ const extraPostInstall = isYarnPackageManager ? 'yarn harmonize && yarn install --mode=skip-build' : 'npm run harmonize && npm install --ignore-scripts';
46
+ const rootPackageJsonObject = tree.readJson(rootPackageJsonPath);
47
+ rootPackageJsonObject.scripts ||= {};
48
+ if (rootPackageJsonObject.scripts.harmonize) {
49
+ context.logger.info('A "harmonize" script already exists in the root "package.json". Version harmonize script will not be added.');
50
+ return tree;
51
+ }
52
+ const postInstall = rootPackageJsonObject.scripts.postinstall;
53
+ rootPackageJsonObject.scripts.harmonize = `eslint '**/package.json' ${isYarnPackageManager ? '.yarnrc.yml ' : ''}--quiet --fix`;
54
+ rootPackageJsonObject.scripts.postinstall = `${postInstall ? postInstall + ' && ' : ''}${extraPostInstall}`;
55
+ tree.overwrite(rootPackageJsonPath, JSON.stringify(rootPackageJsonObject, null, 2));
56
+ return tree;
57
+ };
58
+ };
40
59
  function ngAddFn(options) {
41
60
  /* ng add rules */
42
61
  return async (tree, context) => {
@@ -74,22 +93,21 @@ function ngAddFn(options) {
74
93
  'yaml-eslint-parser',
75
94
  ...(options.projectName ? ['@angular-eslint/builder'] : [])
76
95
  ];
77
- const { getExternalDependenciesVersionRange, setupDependencies, getWorkspaceConfig, getO3rPeerDeps, getProjectNewDependenciesTypes, getPackageInstallConfig } = await Promise.resolve().then(() => require('@o3r/schematics'));
78
- const depsInfo = getO3rPeerDeps(path.resolve(__dirname, '..', '..', 'package.json'), true, /^@(?:o3r|ama-sdk)/);
79
- const workspaceProject = options.projectName ? getWorkspaceConfig(tree)?.projects[options.projectName] : undefined;
96
+ const depsInfo = (0, schematics_2.getO3rPeerDeps)(path.resolve(__dirname, '..', '..', 'package.json'), true, /^@(?:o3r|ama-sdk)/);
97
+ const workspaceProject = options.projectName ? (0, schematics_2.getWorkspaceConfig)(tree)?.projects[options.projectName] : undefined;
80
98
  const { NodeDependencyType } = await Promise.resolve().then(() => require('@schematics/angular/utility/dependencies'));
81
99
  const packageJsonPath = path.resolve(__dirname, '..', '..', 'package.json');
82
100
  const dependencies = depsInfo.o3rPeerDeps.reduce((acc, dep) => {
83
101
  acc[dep] = {
84
102
  inManifest: [{
85
103
  range: `${options.exactO3rVersion ? '' : '~'}${depsInfo.packageVersion}`,
86
- types: getProjectNewDependenciesTypes(workspaceProject)
104
+ types: (0, schematics_2.getProjectNewDependenciesTypes)(workspaceProject)
87
105
  }],
88
106
  ngAddOptions: { exactO3rVersion: options.exactO3rVersion }
89
107
  };
90
108
  return acc;
91
- }, getPackageInstallConfig(packageJsonPath, tree, options.projectName, true, !!options.exactO3rVersion));
92
- Object.entries(getExternalDependenciesVersionRange(devDependenciesToInstall, packageJsonPath, context.logger))
109
+ }, (0, schematics_2.getPackageInstallConfig)(packageJsonPath, tree, options.projectName, true, !!options.exactO3rVersion));
110
+ Object.entries((0, schematics_2.getExternalDependenciesVersionRange)(devDependenciesToInstall, packageJsonPath, context.logger))
93
111
  .forEach(([dep, range]) => {
94
112
  dependencies[dep] = {
95
113
  inManifest: [{
@@ -99,19 +117,21 @@ function ngAddFn(options) {
99
117
  };
100
118
  });
101
119
  return () => (0, schematics_1.chain)([
102
- setupDependencies({
120
+ (0, schematics_2.setupDependencies)({
103
121
  projectName: options.projectName,
104
122
  dependencies,
105
123
  ngAddToRun: depsInfo.o3rPeerDeps
106
124
  }),
107
125
  index_2.updateVscode,
108
126
  (0, index_1.updateEslintConfig)(__dirname),
127
+ addHarmonizeScript(),
109
128
  options.projectName && workspaceProject?.root
110
129
  ? (0, schematics_1.chain)([
111
130
  (0, index_1.updateEslintConfig)(__dirname, options.projectName),
112
131
  options.fix ? handleOtterEslintErrors(options.projectName) : (0, schematics_1.noop)()
113
132
  ])
114
- : (0, schematics_1.noop)()
133
+ : (0, schematics_1.noop)(),
134
+ options.skipLinter ? (0, schematics_1.noop)() : (0, schematics_2.applyEditorConfig)()
115
135
  ])(tree, context);
116
136
  };
117
137
  }
@@ -119,9 +139,6 @@ function ngAddFn(options) {
119
139
  * Add Otter eslint-config to an Angular Project
120
140
  * @param options Options for the schematic
121
141
  */
122
- const ngAdd = (options) => async (_, { logger }) => {
123
- const { createOtterSchematic } = await Promise.resolve().then(() => require('@o3r/schematics')).catch(reportMissingSchematicsDep(logger));
124
- return createOtterSchematic(ngAddFn)(options);
125
- };
142
+ const ngAdd = (options) => (0, schematics_2.createOtterSchematic)(ngAddFn)(options);
126
143
  exports.ngAdd = ngAdd;
127
144
  //# sourceMappingURL=index.js.map
@@ -6,5 +6,7 @@ export interface NgAddSchematicsSchema extends SchematicOptionObject {
6
6
  exactO3rVersion?: boolean;
7
7
  /** Fix known issues with our ESLint config after Otter application or library generation */
8
8
  fix?: boolean;
9
+ /** Skip the linter process which includes EditorConfig rules applying */
10
+ skipLinter: boolean;
9
11
  }
10
12
  //# sourceMappingURL=schema.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../schematics/ng-add/schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,qBAAqB,EACtB,MAAM,iBAAiB,CAAC;AAEzB,MAAM,WAAW,qBAAsB,SAAQ,qBAAqB;IAClE,mBAAmB;IACnB,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC,8CAA8C;IAC9C,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,4FAA4F;IAC5F,GAAG,CAAC,EAAE,OAAO,CAAC;CACf"}
1
+ {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../schematics/ng-add/schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,qBAAqB,EACtB,MAAM,iBAAiB,CAAC;AAEzB,MAAM,WAAW,qBAAsB,SAAQ,qBAAqB;IAClE,mBAAmB;IACnB,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC,8CAA8C;IAC9C,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,4FAA4F;IAC5F,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,yEAAyE;IACzE,UAAU,EAAE,OAAO,CAAC;CACrB"}
@@ -18,6 +18,11 @@
18
18
  "fix": {
19
19
  "type": "boolean",
20
20
  "description": "Fix known issues with our ESLint config after Otter application or library generation"
21
+ },
22
+ "skipLinter": {
23
+ "type": "boolean",
24
+ "description": "Skip the linter process which includes EditorConfig rules applying",
25
+ "default": false
21
26
  }
22
27
  },
23
28
  "additionalProperties": true,
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../schematics/ng-add/tsconfig/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAKL,KAAK,IAAI,EAGV,MAAM,4BAA4B,CAAC;AAEpC;;;;GAIG;AACH,eAAO,MAAM,yBAAyB,GAAI,UAAU,MAAM,EAAE,wBAA4B,KAAG,IAa1F,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../schematics/ng-add/tsconfig/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAKL,KAAK,IAAI,EAGV,MAAM,4BAA4B,CAAC;AAIpC;;;;GAIG;AACH,eAAO,MAAM,yBAAyB,GAAI,UAAU,MAAM,EAAE,wBAA4B,KAAG,IAa1F,CAAC"}
@@ -2,12 +2,13 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.updateOrAddTsconfigEslint = void 0;
4
4
  const schematics_1 = require("@angular-devkit/schematics");
5
+ const schematics_2 = require("@o3r/schematics");
5
6
  /**
6
7
  * Update or add tsconfig.eslint.json file
7
8
  * @param rootPath
8
9
  * @param projectTsConfig
9
10
  */
10
- const updateOrAddTsconfigEslint = (rootPath, projectTsConfig = 'tsconfig') => async (tree) => {
11
+ const updateOrAddTsconfigEslint = (rootPath, projectTsConfig = 'tsconfig') => (tree) => {
11
12
  const tsconfigPath = 'tsconfig.eslint.json';
12
13
  if (tree.exists(tsconfigPath)) {
13
14
  const tsconfig = tree.readJson(tsconfigPath);
@@ -15,8 +16,7 @@ const updateOrAddTsconfigEslint = (rootPath, projectTsConfig = 'tsconfig') => as
15
16
  tree.overwrite(tsconfigPath, JSON.stringify(tsconfig, null, 2));
16
17
  return () => tree;
17
18
  }
18
- const { getTemplateFolder } = await Promise.resolve().then(() => require('@o3r/schematics'));
19
- return () => (0, schematics_1.mergeWith)((0, schematics_1.apply)((0, schematics_1.url)(getTemplateFolder(rootPath, __dirname)), [
19
+ return () => (0, schematics_1.mergeWith)((0, schematics_1.apply)((0, schematics_1.url)((0, schematics_2.getTemplateFolder)(rootPath, __dirname)), [
20
20
  (0, schematics_1.template)({ projectTsConfig }),
21
21
  (0, schematics_1.renameTemplateFiles)()
22
22
  ]), schematics_1.MergeStrategy.Overwrite);
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../schematics/ng-add/vscode/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAEL,KAAK,IAAI,EACV,MAAM,4BAA4B,CAAC;AAoCpC;;GAEG;AACH,eAAO,MAAM,YAAY,EAAE,IAwB1B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../schematics/ng-add/vscode/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAEL,KAAK,IAAI,EACV,MAAM,4BAA4B,CAAC;AAuCpC;;GAEG;AACH,eAAO,MAAM,YAAY,EAAE,IAuB1B,CAAC"}
@@ -2,13 +2,13 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.updateVscode = void 0;
4
4
  const schematics_1 = require("@angular-devkit/schematics");
5
+ const schematics_2 = require("@o3r/schematics");
5
6
  /**
6
7
  * Update VSCode recommendations and settings
7
8
  */
8
- const updateVscode = async () => {
9
- const { addVsCodeRecommendations } = await Promise.resolve().then(() => require('@o3r/schematics'));
9
+ const updateVscode = () => {
10
10
  return (0, schematics_1.chain)([
11
- addVsCodeRecommendations(['dbaeumer.vscode-eslint']),
11
+ (0, schematics_2.addVsCodeRecommendations)(['dbaeumer.vscode-eslint']),
12
12
  (tree) => {
13
13
  const vscodeSettingsPath = '.vscode/settings.json';
14
14
  const settings = (tree.exists(vscodeSettingsPath) ? (tree.readJson(vscodeSettingsPath) || {}) : {});
@@ -0,0 +1,55 @@
1
+ 'use strict';
2
+ const { dirname, posix, relative, sep } = require('node:path');
3
+ const { pathToFileURL } = require('node:url');
4
+ const { defineConfig } = require('eslint/config');
5
+ const { sync } = require('globby');
6
+
7
+ /**
8
+ * Add a prefix to a path glob
9
+ * @param {string} prefix
10
+ * @param {string | undefined} pathGlob
11
+ * @returns {string}
12
+ */
13
+ const addPrefix = (prefix, pathGlob = '**/*') => pathGlob.replace(/^(!?)(\.?\/)?/, `$1${prefix}/`).replaceAll(sep, posix.sep).replace(/^\//, '');
14
+
15
+ /**
16
+ * Merge ESLint flat config
17
+ * @param {string} localDirname The directory name of the current module
18
+ * @param {string | string[]} globs List of globs to find ESLint config path
19
+ * @param {import('@typescript-eslint/utils').TSESLint.FlatConfig.ConfigArray[]} additionalConfigs List of additional config to apply first
20
+ * @returns {Promise<import('@typescript-eslint/utils').TSESLint.FlatConfig.ConfigArray>}
21
+ */
22
+ const mergeESLintFlatConfigs = async (localDirname, globs, ...additionalConfigs) => {
23
+ const localConfigFiles = sync(globs, { absolute: true });
24
+ /** @type {import('@typescript-eslint/utils').TSESLint.FlatConfig.ConfigArray} */
25
+ let configs = [];
26
+ for (const localConfigFile of localConfigFiles) {
27
+ const module = await import(pathToFileURL(localConfigFile));
28
+ const moduleConfig = await (module.default ?? module);
29
+ /** @type {import('@typescript-eslint/utils').TSESLint.FlatConfig.ConfigArray} */
30
+ const configArray = Array.isArray(moduleConfig) ? moduleConfig : [moduleConfig];
31
+ const directory = relative(localDirname, dirname(localConfigFile));
32
+ configs = configs.concat(
33
+ configArray.map((config) => ({
34
+ ...config,
35
+ ...(
36
+ config.ignores
37
+ ? {
38
+ ignores: config.ignores.map((pathGlob) => addPrefix(directory, pathGlob)),
39
+ ...config.files && config.files.flat().map((pathGlob) => addPrefix(directory, pathGlob))
40
+ }
41
+ : { files: (config.files || ['**/*']).flat().map((pathGlob) => addPrefix(directory, pathGlob)) }
42
+ )
43
+ }))
44
+ );
45
+ }
46
+
47
+ return defineConfig([
48
+ ...additionalConfigs,
49
+ ...configs
50
+ ]);
51
+ };
52
+
53
+ module.exports = {
54
+ mergeESLintFlatConfigs
55
+ };