@nx/plugin 16.8.0-beta.4 → 16.8.0-beta.5

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.
@@ -1,75 +1,76 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.executorSchematic = exports.executorGenerator = exports.createExecutorsJson = void 0;
4
- const tslib_1 = require("tslib");
5
4
  const devkit_1 = require("@nx/devkit");
6
5
  const path = require("path");
7
6
  const generator_1 = require("../lint-checks/generator");
8
7
  const versions_1 = require("../../utils/versions");
9
8
  function addFiles(host, options) {
10
- (0, devkit_1.generateFiles)(host, path.join(__dirname, './files/executor'), `${options.projectSourceRoot}/executors`, Object.assign(Object.assign({}, options), { tmpl: '' }));
9
+ (0, devkit_1.generateFiles)(host, path.join(__dirname, './files/executor'), `${options.projectSourceRoot}/executors`, {
10
+ ...options,
11
+ tmpl: '',
12
+ });
11
13
  if (options.unitTestRunner === 'none') {
12
14
  host.delete((0, devkit_1.joinPathFragments)(options.projectSourceRoot, 'executors', options.fileName, `executor.spec.ts`));
13
15
  }
14
16
  }
15
17
  function addHasherFiles(host, options) {
16
- (0, devkit_1.generateFiles)(host, path.join(__dirname, './files/hasher'), `${options.projectSourceRoot}/executors`, Object.assign(Object.assign({}, options), { tmpl: '' }));
18
+ (0, devkit_1.generateFiles)(host, path.join(__dirname, './files/hasher'), `${options.projectSourceRoot}/executors`, {
19
+ ...options,
20
+ tmpl: '',
21
+ });
17
22
  if (options.unitTestRunner === 'none') {
18
23
  host.delete((0, devkit_1.joinPathFragments)(options.projectSourceRoot, 'executors', options.fileName, 'hasher.spec.ts'));
19
24
  }
20
25
  }
21
- function createExecutorsJson(host, projectRoot, projectName, skipLintChecks) {
22
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
23
- (0, devkit_1.updateJson)(host, (0, devkit_1.joinPathFragments)(projectRoot, 'package.json'), (json) => {
24
- var _a;
25
- (_a = json.executors) !== null && _a !== void 0 ? _a : (json.executors = './executors.json');
26
- return json;
27
- });
28
- (0, devkit_1.writeJson)(host, (0, devkit_1.joinPathFragments)(projectRoot, 'executors.json'), {
29
- executors: {},
30
- });
31
- if (!skipLintChecks) {
32
- yield (0, generator_1.default)(host, {
33
- projectName,
34
- });
35
- }
26
+ async function createExecutorsJson(host, projectRoot, projectName, skipLintChecks) {
27
+ (0, devkit_1.updateJson)(host, (0, devkit_1.joinPathFragments)(projectRoot, 'package.json'), (json) => {
28
+ json.executors ??= './executors.json';
29
+ return json;
30
+ });
31
+ (0, devkit_1.writeJson)(host, (0, devkit_1.joinPathFragments)(projectRoot, 'executors.json'), {
32
+ executors: {},
36
33
  });
34
+ if (!skipLintChecks) {
35
+ await (0, generator_1.default)(host, {
36
+ projectName,
37
+ });
38
+ }
37
39
  }
38
40
  exports.createExecutorsJson = createExecutorsJson;
39
- function updateExecutorJson(host, options) {
40
- var _a;
41
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
42
- const packageJson = (0, devkit_1.readJson)(host, (0, devkit_1.joinPathFragments)(options.projectRoot, 'package.json'));
43
- const packageJsonExecutors = (_a = packageJson.executors) !== null && _a !== void 0 ? _a : packageJson.builders;
44
- let executorsPath = packageJsonExecutors
45
- ? (0, devkit_1.joinPathFragments)(options.projectRoot, packageJsonExecutors)
46
- : null;
47
- if (!executorsPath) {
48
- executorsPath = (0, devkit_1.joinPathFragments)(options.projectRoot, 'executors.json');
49
- }
50
- if (!host.exists(executorsPath)) {
51
- yield createExecutorsJson(host, options.projectRoot, options.project, options.skipLintChecks);
41
+ async function updateExecutorJson(host, options) {
42
+ const packageJson = (0, devkit_1.readJson)(host, (0, devkit_1.joinPathFragments)(options.projectRoot, 'package.json'));
43
+ const packageJsonExecutors = packageJson.executors ?? packageJson.builders;
44
+ let executorsPath = packageJsonExecutors
45
+ ? (0, devkit_1.joinPathFragments)(options.projectRoot, packageJsonExecutors)
46
+ : null;
47
+ if (!executorsPath) {
48
+ executorsPath = (0, devkit_1.joinPathFragments)(options.projectRoot, 'executors.json');
49
+ }
50
+ if (!host.exists(executorsPath)) {
51
+ await createExecutorsJson(host, options.projectRoot, options.project, options.skipLintChecks);
52
+ }
53
+ // add dependencies
54
+ (0, devkit_1.updateJson)(host, (0, devkit_1.joinPathFragments)(options.projectRoot, 'package.json'), (json) => {
55
+ json.dependencies = {
56
+ '@nx/devkit': versions_1.nxVersion,
57
+ ...json.dependencies,
58
+ };
59
+ return json;
60
+ });
61
+ return (0, devkit_1.updateJson)(host, executorsPath, (json) => {
62
+ let executors = json.executors ?? json.builders;
63
+ executors ||= {};
64
+ executors[options.name] = {
65
+ implementation: `./src/executors/${options.fileName}/executor`,
66
+ schema: `./src/executors/${options.fileName}/schema.json`,
67
+ description: options.description,
68
+ };
69
+ if (options.includeHasher) {
70
+ executors[options.name].hasher = `./src/executors/${options.fileName}/hasher`;
52
71
  }
53
- // add dependencies
54
- (0, devkit_1.updateJson)(host, (0, devkit_1.joinPathFragments)(options.projectRoot, 'package.json'), (json) => {
55
- json.dependencies = Object.assign({ '@nx/devkit': versions_1.nxVersion }, json.dependencies);
56
- return json;
57
- });
58
- return (0, devkit_1.updateJson)(host, executorsPath, (json) => {
59
- var _a;
60
- let executors = (_a = json.executors) !== null && _a !== void 0 ? _a : json.builders;
61
- executors || (executors = {});
62
- executors[options.name] = {
63
- implementation: `./src/executors/${options.fileName}/executor`,
64
- schema: `./src/executors/${options.fileName}/schema.json`,
65
- description: options.description,
66
- };
67
- if (options.includeHasher) {
68
- executors[options.name].hasher = `./src/executors/${options.fileName}/hasher`;
69
- }
70
- json.executors = executors;
71
- return json;
72
- });
72
+ json.executors = executors;
73
+ return json;
73
74
  });
74
75
  }
75
76
  function normalizeOptions(host, options) {
@@ -83,26 +84,27 @@ function normalizeOptions(host, options) {
83
84
  else {
84
85
  description = `${options.name} executor`;
85
86
  }
86
- return Object.assign(Object.assign({}, options), { fileName,
87
+ return {
88
+ ...options,
89
+ fileName,
87
90
  className,
88
91
  propertyName,
89
92
  description,
90
93
  projectRoot,
91
94
  projectSourceRoot,
92
- npmScope });
95
+ npmScope,
96
+ };
93
97
  }
94
- function executorGenerator(host, schema) {
95
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
96
- const options = normalizeOptions(host, schema);
97
- addFiles(host, options);
98
- if (options.includeHasher) {
99
- addHasherFiles(host, options);
100
- }
101
- yield updateExecutorJson(host, options);
102
- if (!schema.skipFormat) {
103
- yield (0, devkit_1.formatFiles)(host);
104
- }
105
- });
98
+ async function executorGenerator(host, schema) {
99
+ const options = normalizeOptions(host, schema);
100
+ addFiles(host, options);
101
+ if (options.includeHasher) {
102
+ addHasherFiles(host, options);
103
+ }
104
+ await updateExecutorJson(host, options);
105
+ if (!schema.skipFormat) {
106
+ await (0, devkit_1.formatFiles)(host);
107
+ }
106
108
  }
107
109
  exports.executorGenerator = executorGenerator;
108
110
  exports.default = executorGenerator;
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generatorSchematic = exports.generatorGenerator = exports.createGeneratorsJson = void 0;
4
- const tslib_1 = require("tslib");
5
4
  const devkit_1 = require("@nx/devkit");
6
5
  const path = require("path");
7
6
  const has_generator_1 = require("../../utils/has-generator");
@@ -18,91 +17,93 @@ function normalizeOptions(host, options) {
18
17
  else {
19
18
  description = `${options.name} generator`;
20
19
  }
21
- return Object.assign(Object.assign(Object.assign({}, options), (0, devkit_1.names)(options.name)), { description,
20
+ return {
21
+ ...options,
22
+ ...(0, devkit_1.names)(options.name),
23
+ description,
22
24
  projectRoot,
23
25
  projectSourceRoot,
24
26
  npmScope,
25
- npmPackageName });
27
+ npmPackageName,
28
+ };
26
29
  }
27
30
  function addFiles(host, options) {
28
31
  const indexPath = `${options.projectSourceRoot}/generators/${options.fileName}/files/src/index.ts.template`;
29
32
  if (!host.exists(indexPath)) {
30
33
  host.write(indexPath, 'const variable = "<%= name %>";');
31
34
  }
32
- (0, devkit_1.generateFiles)(host, path.join(__dirname, './files/generator'), `${options.projectSourceRoot}/generators`, Object.assign(Object.assign({}, options), { generatorFnName: `${options.propertyName}Generator`, schemaInterfaceName: `${options.className}GeneratorSchema` }));
35
+ (0, devkit_1.generateFiles)(host, path.join(__dirname, './files/generator'), `${options.projectSourceRoot}/generators`, {
36
+ ...options,
37
+ generatorFnName: `${options.propertyName}Generator`,
38
+ schemaInterfaceName: `${options.className}GeneratorSchema`,
39
+ });
33
40
  if (options.unitTestRunner === 'none') {
34
41
  host.delete(path.join(options.projectSourceRoot, 'generators', options.fileName, `generator.spec.ts`));
35
42
  }
36
43
  }
37
- function createGeneratorsJson(host, projectRoot, projectName, skipLintChecks, skipFormat) {
38
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
39
- (0, devkit_1.updateJson)(host, (0, devkit_1.joinPathFragments)(projectRoot, 'package.json'), (json) => {
40
- var _a;
41
- (_a = json.generators) !== null && _a !== void 0 ? _a : (json.generators = './generators.json');
42
- return json;
43
- });
44
- (0, devkit_1.writeJson)(host, (0, devkit_1.joinPathFragments)(projectRoot, 'generators.json'), {
45
- generators: {},
46
- });
47
- if (!skipLintChecks) {
48
- yield (0, generator_1.default)(host, {
49
- projectName,
50
- skipFormat,
51
- });
52
- }
44
+ async function createGeneratorsJson(host, projectRoot, projectName, skipLintChecks, skipFormat) {
45
+ (0, devkit_1.updateJson)(host, (0, devkit_1.joinPathFragments)(projectRoot, 'package.json'), (json) => {
46
+ json.generators ??= './generators.json';
47
+ return json;
48
+ });
49
+ (0, devkit_1.writeJson)(host, (0, devkit_1.joinPathFragments)(projectRoot, 'generators.json'), {
50
+ generators: {},
53
51
  });
52
+ if (!skipLintChecks) {
53
+ await (0, generator_1.default)(host, {
54
+ projectName,
55
+ skipFormat,
56
+ });
57
+ }
54
58
  }
55
59
  exports.createGeneratorsJson = createGeneratorsJson;
56
- function updateGeneratorJson(host, options) {
57
- var _a;
58
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
59
- const packageJson = (0, devkit_1.readJson)(host, (0, devkit_1.joinPathFragments)(options.projectRoot, 'package.json'));
60
- const packageJsonGenerators = (_a = packageJson.generators) !== null && _a !== void 0 ? _a : packageJson.schematics;
61
- let generatorsPath = packageJsonGenerators
62
- ? (0, devkit_1.joinPathFragments)(options.projectRoot, packageJsonGenerators)
63
- : null;
64
- if (!generatorsPath) {
65
- generatorsPath = (0, devkit_1.joinPathFragments)(options.projectRoot, 'generators.json');
66
- }
67
- if (!host.exists(generatorsPath)) {
68
- yield createGeneratorsJson(host, options.projectRoot, options.project, options.skipLintChecks, options.skipFormat);
69
- }
70
- // add dependencies
71
- (0, devkit_1.updateJson)(host, (0, devkit_1.joinPathFragments)(options.projectRoot, 'package.json'), (json) => {
72
- json.dependencies = Object.assign({ '@nx/devkit': versions_1.nxVersion }, json.dependencies);
73
- return json;
74
- });
75
- (0, devkit_1.updateJson)(host, generatorsPath, (json) => {
76
- var _a;
77
- let generators = (_a = json.generators) !== null && _a !== void 0 ? _a : json.schematics;
78
- generators = generators || {};
79
- generators[options.name] = {
80
- factory: `./src/generators/${options.fileName}/generator`,
81
- schema: `./src/generators/${options.fileName}/schema.json`,
82
- description: options.description,
83
- };
84
- // @todo(v17): Remove this, prop is defunct.
85
- if (options.name === 'preset') {
86
- generators[options.name]['x-use-standalone-layout'] = true;
87
- }
88
- json.generators = generators;
89
- return json;
90
- });
60
+ async function updateGeneratorJson(host, options) {
61
+ const packageJson = (0, devkit_1.readJson)(host, (0, devkit_1.joinPathFragments)(options.projectRoot, 'package.json'));
62
+ const packageJsonGenerators = packageJson.generators ?? packageJson.schematics;
63
+ let generatorsPath = packageJsonGenerators
64
+ ? (0, devkit_1.joinPathFragments)(options.projectRoot, packageJsonGenerators)
65
+ : null;
66
+ if (!generatorsPath) {
67
+ generatorsPath = (0, devkit_1.joinPathFragments)(options.projectRoot, 'generators.json');
68
+ }
69
+ if (!host.exists(generatorsPath)) {
70
+ await createGeneratorsJson(host, options.projectRoot, options.project, options.skipLintChecks, options.skipFormat);
71
+ }
72
+ // add dependencies
73
+ (0, devkit_1.updateJson)(host, (0, devkit_1.joinPathFragments)(options.projectRoot, 'package.json'), (json) => {
74
+ json.dependencies = {
75
+ '@nx/devkit': versions_1.nxVersion,
76
+ ...json.dependencies,
77
+ };
78
+ return json;
91
79
  });
92
- }
93
- function generatorGenerator(host, schema) {
94
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
95
- const options = normalizeOptions(host, schema);
96
- if ((0, has_generator_1.hasGenerator)(host, options.project, options.name)) {
97
- throw new Error(`Generator ${options.name} already exists.`);
98
- }
99
- addFiles(host, options);
100
- yield updateGeneratorJson(host, options);
101
- if (!options.skipFormat) {
102
- yield (0, devkit_1.formatFiles)(host);
80
+ (0, devkit_1.updateJson)(host, generatorsPath, (json) => {
81
+ let generators = json.generators ?? json.schematics;
82
+ generators = generators || {};
83
+ generators[options.name] = {
84
+ factory: `./src/generators/${options.fileName}/generator`,
85
+ schema: `./src/generators/${options.fileName}/schema.json`,
86
+ description: options.description,
87
+ };
88
+ // @todo(v17): Remove this, prop is defunct.
89
+ if (options.name === 'preset') {
90
+ generators[options.name]['x-use-standalone-layout'] = true;
103
91
  }
92
+ json.generators = generators;
93
+ return json;
104
94
  });
105
95
  }
96
+ async function generatorGenerator(host, schema) {
97
+ const options = normalizeOptions(host, schema);
98
+ if ((0, has_generator_1.hasGenerator)(host, options.project, options.name)) {
99
+ throw new Error(`Generator ${options.name} already exists.`);
100
+ }
101
+ addFiles(host, options);
102
+ await updateGeneratorJson(host, options);
103
+ if (!options.skipFormat) {
104
+ await (0, devkit_1.formatFiles)(host);
105
+ }
106
+ }
106
107
  exports.generatorGenerator = generatorGenerator;
107
108
  exports.default = generatorGenerator;
108
109
  exports.generatorSchematic = (0, devkit_1.convertNxGenerator)(generatorGenerator);
@@ -1,43 +1,39 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getEsLintOptions = exports.addMigrationJsonChecks = void 0;
4
- const tslib_1 = require("tslib");
5
4
  const devkit_1 = require("@nx/devkit");
6
5
  const logger_1 = require("nx/src/utils/logger");
7
6
  const package_json_1 = require("nx/src/utils/package-json");
8
7
  const eslint_file_1 = require("@nx/linter/src/generators/utils/eslint-file");
9
8
  const flat_config_1 = require("@nx/linter/src/utils/flat-config");
10
- function pluginLintCheckGenerator(host, options) {
11
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
12
- const project = (0, devkit_1.readProjectConfiguration)(host, options.projectName);
13
- const packageJson = (0, devkit_1.readJson)(host, (0, devkit_1.joinPathFragments)(project.root, 'package.json'));
14
- // This rule is eslint **only**
15
- if (projectIsEsLintEnabled(project)) {
16
- updateRootEslintConfig(host);
17
- updateProjectEslintConfig(host, project, packageJson);
18
- updateProjectTarget(host, options, packageJson);
19
- // Project is setup for vscode
20
- if (host.exists('.vscode')) {
21
- setupVsCodeLintingForJsonFiles(host);
22
- }
23
- // Project contains migrations.json
24
- const migrationsPath = (0, package_json_1.readNxMigrateConfig)(packageJson).migrations;
25
- if (migrationsPath &&
26
- host.exists((0, devkit_1.joinPathFragments)(project.root, migrationsPath))) {
27
- addMigrationJsonChecks(host, options, packageJson);
28
- }
29
- }
30
- else {
31
- devkit_1.logger.error(`${logger_1.NX_PREFIX} plugin lint checks can only be added to plugins which use eslint for linting`);
9
+ async function pluginLintCheckGenerator(host, options) {
10
+ const project = (0, devkit_1.readProjectConfiguration)(host, options.projectName);
11
+ const packageJson = (0, devkit_1.readJson)(host, (0, devkit_1.joinPathFragments)(project.root, 'package.json'));
12
+ // This rule is eslint **only**
13
+ if (projectIsEsLintEnabled(project)) {
14
+ updateRootEslintConfig(host);
15
+ updateProjectEslintConfig(host, project, packageJson);
16
+ updateProjectTarget(host, options, packageJson);
17
+ // Project is setup for vscode
18
+ if (host.exists('.vscode')) {
19
+ setupVsCodeLintingForJsonFiles(host);
32
20
  }
33
- if (!options.skipFormat) {
34
- yield (0, devkit_1.formatFiles)(host);
21
+ // Project contains migrations.json
22
+ const migrationsPath = (0, package_json_1.readNxMigrateConfig)(packageJson).migrations;
23
+ if (migrationsPath &&
24
+ host.exists((0, devkit_1.joinPathFragments)(project.root, migrationsPath))) {
25
+ addMigrationJsonChecks(host, options, packageJson);
35
26
  }
36
- });
27
+ }
28
+ else {
29
+ devkit_1.logger.error(`${logger_1.NX_PREFIX} plugin lint checks can only be added to plugins which use eslint for linting`);
30
+ }
31
+ if (!options.skipFormat) {
32
+ await (0, devkit_1.formatFiles)(host);
33
+ }
37
34
  }
38
35
  exports.default = pluginLintCheckGenerator;
39
36
  function addMigrationJsonChecks(host, options, packageJson) {
40
- var _a, _b;
41
37
  const projectConfiguration = (0, devkit_1.readProjectConfiguration)(host, options.projectName);
42
38
  if (!projectIsEsLintEnabled(projectConfiguration)) {
43
39
  return;
@@ -49,25 +45,24 @@ function addMigrationJsonChecks(host, options, packageJson) {
49
45
  }
50
46
  const migrationsJsonPath = (0, devkit_1.joinPathFragments)(projectConfiguration.root, relativeMigrationsJsonPath);
51
47
  if (eslintTarget &&
52
- !((_b = (_a = eslintTargetConfiguration.options) === null || _a === void 0 ? void 0 : _a.lintFilePatterns) === null || _b === void 0 ? void 0 : _b.includes(migrationsJsonPath))) {
48
+ !eslintTargetConfiguration.options?.lintFilePatterns?.includes(migrationsJsonPath)) {
53
49
  // Add to lintFilePatterns
54
50
  eslintTargetConfiguration.options.lintFilePatterns.push(migrationsJsonPath);
55
51
  (0, devkit_1.updateProjectConfiguration)(host, options.projectName, projectConfiguration);
56
52
  // Update project level eslintrc
57
- (0, eslint_file_1.updateOverrideInLintConfig)(host, projectConfiguration.root, (o) => {
58
- var _a, _b, _c, _d;
59
- return ((_b = Object.keys((_a = o.rules) !== null && _a !== void 0 ? _a : {})) === null || _b === void 0 ? void 0 : _b.includes('@nx/nx-plugin-checks')) ||
60
- ((_d = Object.keys((_c = o.rules) !== null && _c !== void 0 ? _c : {})) === null || _d === void 0 ? void 0 : _d.includes('@nrwl/nx/nx-plugin-checks'));
61
- }, (o) => {
53
+ (0, eslint_file_1.updateOverrideInLintConfig)(host, projectConfiguration.root, (o) => Object.keys(o.rules ?? {})?.includes('@nx/nx-plugin-checks') ||
54
+ Object.keys(o.rules ?? {})?.includes('@nrwl/nx/nx-plugin-checks'), (o) => {
62
55
  const fileSet = new Set(Array.isArray(o.files) ? o.files : [o.files]);
63
56
  fileSet.add(relativeMigrationsJsonPath);
64
- return Object.assign(Object.assign({}, o), { files: Array.from(fileSet) });
57
+ return {
58
+ ...o,
59
+ files: Array.from(fileSet),
60
+ };
65
61
  });
66
62
  }
67
63
  }
68
64
  exports.addMigrationJsonChecks = addMigrationJsonChecks;
69
65
  function updateProjectTarget(host, options, packageJson) {
70
- var _a, _b;
71
66
  const project = (0, devkit_1.readProjectConfiguration)(host, options.projectName);
72
67
  if (!project.targets) {
73
68
  return;
@@ -75,8 +70,8 @@ function updateProjectTarget(host, options, packageJson) {
75
70
  for (const [target, configuration] of Object.entries(project.targets)) {
76
71
  if (configuration.executor === '@nx/linter:eslint' ||
77
72
  configuration.executor === '@nrwl/linter:eslint') {
78
- const opts = (_a = configuration.options) !== null && _a !== void 0 ? _a : {};
79
- (_b = opts.lintFilePatterns) !== null && _b !== void 0 ? _b : (opts.lintFilePatterns = []);
73
+ const opts = configuration.options ?? {};
74
+ opts.lintFilePatterns ??= [];
80
75
  if (packageJson.generators) {
81
76
  opts.lintFilePatterns.push((0, devkit_1.joinPathFragments)(project.root, packageJson.generators));
82
77
  }
@@ -100,11 +95,8 @@ function updateProjectTarget(host, options, packageJson) {
100
95
  }
101
96
  function updateProjectEslintConfig(host, options, packageJson) {
102
97
  if ((0, eslint_file_1.isEslintConfigSupported)(host, options.root)) {
103
- const lookup = (o) => {
104
- var _a, _b;
105
- return Object.keys((_a = o.rules) !== null && _a !== void 0 ? _a : {}).includes('@nx/nx-plugin-checks') ||
106
- Object.keys((_b = o.rules) !== null && _b !== void 0 ? _b : {}).includes('@nrwl/nx/nx-plugin-checks');
107
- };
98
+ const lookup = (o) => Object.keys(o.rules ?? {}).includes('@nx/nx-plugin-checks') ||
99
+ Object.keys(o.rules ?? {}).includes('@nrwl/nx/nx-plugin-checks');
108
100
  const files = [
109
101
  './package.json',
110
102
  packageJson.generators,
@@ -117,18 +109,30 @@ function updateProjectEslintConfig(host, options, packageJson) {
117
109
  : { parser: 'jsonc-eslint-parser' };
118
110
  if ((0, eslint_file_1.lintConfigHasOverride)(host, options.root, lookup)) {
119
111
  // update it
120
- (0, eslint_file_1.updateOverrideInLintConfig)(host, options.root, lookup, (o) => (Object.assign(Object.assign(Object.assign(Object.assign({}, o), { files: [
112
+ (0, eslint_file_1.updateOverrideInLintConfig)(host, options.root, lookup, (o) => ({
113
+ ...o,
114
+ files: [
121
115
  ...new Set([
122
116
  ...(Array.isArray(o.files) ? o.files : [o.files]),
123
117
  ...files,
124
118
  ]),
125
- ] }), parser), { rules: Object.assign(Object.assign({}, o.rules), { '@nx/nx-plugin-checks': 'error' }) })));
119
+ ],
120
+ ...parser,
121
+ rules: {
122
+ ...o.rules,
123
+ '@nx/nx-plugin-checks': 'error',
124
+ },
125
+ }));
126
126
  }
127
127
  else {
128
128
  // add it
129
- (0, eslint_file_1.addOverrideToLintConfig)(host, options.root, Object.assign(Object.assign({ files }, parser), { rules: {
129
+ (0, eslint_file_1.addOverrideToLintConfig)(host, options.root, {
130
+ files,
131
+ ...parser,
132
+ rules: {
130
133
  '@nx/nx-plugin-checks': 'error',
131
- } }));
134
+ },
135
+ });
132
136
  }
133
137
  }
134
138
  }
@@ -137,12 +141,9 @@ function updateProjectEslintConfig(host, options, packageJson) {
137
141
  // will display false errors in the IDE
138
142
  function updateRootEslintConfig(host) {
139
143
  if ((0, eslint_file_1.isEslintConfigSupported)(host)) {
140
- if (!(0, eslint_file_1.lintConfigHasOverride)(host, '', (o) => {
141
- var _a;
142
- return Array.isArray(o.files)
143
- ? o.files.some((f) => f.match(/\.json$/))
144
- : !!((_a = o.files) === null || _a === void 0 ? void 0 : _a.match(/\.json$/));
145
- }, true)) {
144
+ if (!(0, eslint_file_1.lintConfigHasOverride)(host, '', (o) => Array.isArray(o.files)
145
+ ? o.files.some((f) => f.match(/\.json$/))
146
+ : !!o.files?.match(/\.json$/), true)) {
146
147
  (0, eslint_file_1.addOverrideToLintConfig)(host, '', {
147
148
  files: '*.json',
148
149
  parser: 'jsonc-eslint-parser',
@@ -162,7 +163,6 @@ function updateRootEslintConfig(host) {
162
163
  }
163
164
  }
164
165
  function setupVsCodeLintingForJsonFiles(host) {
165
- var _a;
166
166
  let existing = {};
167
167
  if (host.exists('.vscode/settings.json')) {
168
168
  existing = (0, devkit_1.readJson)(host, '.vscode/settings.json');
@@ -171,7 +171,7 @@ function setupVsCodeLintingForJsonFiles(host) {
171
171
  devkit_1.logger.info(`${logger_1.NX_PREFIX} We've updated the vscode settings for this repository to ensure that plugin lint checks show up inside your IDE. This created .vscode/settings.json. To read more about this file, check vscode's documentation. It is frequently not committed, so other developers may need to add similar settings if they'd like to see the lint checks in the IDE rather than only during linting.`);
172
172
  }
173
173
  // setup eslint validation for json files
174
- const eslintValidate = (_a = existing['eslint.validate']) !== null && _a !== void 0 ? _a : [];
174
+ const eslintValidate = existing['eslint.validate'] ?? [];
175
175
  if (!eslintValidate.includes('json')) {
176
176
  existing['eslint.validate'] = [...eslintValidate, 'json'];
177
177
  }
@@ -1,14 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.migrationSchematic = exports.migrationGenerator = void 0;
4
- const tslib_1 = require("tslib");
5
4
  const devkit_1 = require("@nx/devkit");
6
5
  const path = require("path");
7
6
  const generator_1 = require("../lint-checks/generator");
8
7
  const package_json_1 = require("nx/src/utils/package-json");
9
8
  const versions_1 = require("../../utils/versions");
10
9
  function normalizeOptions(host, options) {
11
- var _a;
12
10
  let name;
13
11
  if (options.name) {
14
12
  name = (0, devkit_1.names)(options.name).fileName;
@@ -16,25 +14,27 @@ function normalizeOptions(host, options) {
16
14
  else {
17
15
  name = (0, devkit_1.names)(`update-${options.packageVersion}`).fileName;
18
16
  }
19
- const description = (_a = options.description) !== null && _a !== void 0 ? _a : name;
17
+ const description = options.description ?? name;
20
18
  const { root: projectRoot, sourceRoot: projectSourceRoot } = (0, devkit_1.readProjectConfiguration)(host, options.project);
21
- const normalized = Object.assign(Object.assign({}, options), { name,
19
+ const normalized = {
20
+ ...options,
21
+ name,
22
22
  description,
23
23
  projectRoot,
24
- projectSourceRoot });
24
+ projectSourceRoot,
25
+ };
25
26
  return normalized;
26
27
  }
27
28
  function addFiles(host, options) {
28
- (0, devkit_1.generateFiles)(host, path.join(__dirname, 'files/migration'), `${options.projectSourceRoot}/migrations`, Object.assign(Object.assign({}, options), { tmpl: '' }));
29
+ (0, devkit_1.generateFiles)(host, path.join(__dirname, 'files/migration'), `${options.projectSourceRoot}/migrations`, { ...options, tmpl: '' });
29
30
  }
30
31
  function updateMigrationsJson(host, options) {
31
- var _a, _b;
32
32
  const configuredMigrationPath = (0, package_json_1.readNxMigrateConfig)((0, devkit_1.readJson)(host, (0, devkit_1.joinPathFragments)(options.projectRoot, 'package.json'))).migrations;
33
- const migrationsPath = (0, devkit_1.joinPathFragments)(options.projectRoot, configuredMigrationPath !== null && configuredMigrationPath !== void 0 ? configuredMigrationPath : 'migrations.json');
33
+ const migrationsPath = (0, devkit_1.joinPathFragments)(options.projectRoot, configuredMigrationPath ?? 'migrations.json');
34
34
  const migrations = host.exists(migrationsPath)
35
35
  ? (0, devkit_1.readJson)(host, migrationsPath)
36
36
  : {};
37
- const generators = (_a = migrations.generators) !== null && _a !== void 0 ? _a : {};
37
+ const generators = migrations.generators ?? {};
38
38
  generators[options.name] = {
39
39
  version: options.packageVersion,
40
40
  description: options.description,
@@ -42,7 +42,7 @@ function updateMigrationsJson(host, options) {
42
42
  };
43
43
  migrations.generators = generators;
44
44
  if (options.packageJsonUpdates) {
45
- const packageJsonUpdatesObj = (_b = migrations.packageJsonUpdates) !== null && _b !== void 0 ? _b : {};
45
+ const packageJsonUpdatesObj = migrations.packageJsonUpdates ?? {};
46
46
  if (!packageJsonUpdatesObj[options.packageVersion]) {
47
47
  packageJsonUpdatesObj[options.packageVersion] = {
48
48
  version: options.packageVersion,
@@ -69,14 +69,16 @@ function updatePackageJson(host, options) {
69
69
  preexistingValue.migrations = './migrations.json';
70
70
  }
71
71
  // add dependencies
72
- json.dependencies = Object.assign({ '@nx/devkit': versions_1.nxVersion }, json.dependencies);
72
+ json.dependencies = {
73
+ '@nx/devkit': versions_1.nxVersion,
74
+ ...json.dependencies,
75
+ };
73
76
  return json;
74
77
  });
75
78
  }
76
79
  function updateWorkspaceJson(host, options) {
77
- var _a, _b;
78
80
  const project = (0, devkit_1.readProjectConfiguration)(host, options.project);
79
- const assets = (_b = (_a = project.targets.build) === null || _a === void 0 ? void 0 : _a.options) === null || _b === void 0 ? void 0 : _b.assets;
81
+ const assets = project.targets.build?.options?.assets;
80
82
  if (assets &&
81
83
  assets.filter((a) => a.glob === 'migrations.json').length === 0) {
82
84
  project.targets.build.options.assets = [
@@ -90,22 +92,20 @@ function updateWorkspaceJson(host, options) {
90
92
  (0, devkit_1.updateProjectConfiguration)(host, options.project, project);
91
93
  }
92
94
  }
93
- function migrationGenerator(host, schema) {
94
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
95
- const options = normalizeOptions(host, schema);
96
- addFiles(host, options);
97
- updateMigrationsJson(host, options);
98
- updateWorkspaceJson(host, options);
99
- updateMigrationsJson(host, options);
100
- updatePackageJson(host, options);
101
- if (!host.exists('migrations.json')) {
102
- const packageJsonPath = (0, devkit_1.joinPathFragments)(options.projectRoot, 'package.json');
103
- (0, generator_1.addMigrationJsonChecks)(host, { projectName: schema.project }, (0, devkit_1.readJson)(host, packageJsonPath));
104
- }
105
- if (!options.skipFormat) {
106
- yield (0, devkit_1.formatFiles)(host);
107
- }
108
- });
95
+ async function migrationGenerator(host, schema) {
96
+ const options = normalizeOptions(host, schema);
97
+ addFiles(host, options);
98
+ updateMigrationsJson(host, options);
99
+ updateWorkspaceJson(host, options);
100
+ updateMigrationsJson(host, options);
101
+ updatePackageJson(host, options);
102
+ if (!host.exists('migrations.json')) {
103
+ const packageJsonPath = (0, devkit_1.joinPathFragments)(options.projectRoot, 'package.json');
104
+ (0, generator_1.addMigrationJsonChecks)(host, { projectName: schema.project }, (0, devkit_1.readJson)(host, packageJsonPath));
105
+ }
106
+ if (!options.skipFormat) {
107
+ await (0, devkit_1.formatFiles)(host);
108
+ }
109
109
  }
110
110
  exports.migrationGenerator = migrationGenerator;
111
111
  exports.default = migrationGenerator;