@nx/plugin 16.8.0-beta.3 → 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,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.pluginSchematic = exports.pluginGeneratorInternal = exports.pluginGenerator = void 0;
4
- const tslib_1 = require("tslib");
5
4
  const devkit_1 = require("@nx/devkit");
6
5
  const js_1 = require("@nx/js");
7
6
  const add_swc_dependencies_1 = require("@nx/js/src/utils/swc/add-swc-dependencies");
@@ -13,18 +12,17 @@ const normalize_schema_1 = require("./utils/normalize-schema");
13
12
  const add_tslib_dependencies_1 = require("@nx/js/src/utils/typescript/add-tslib-dependencies");
14
13
  const add_swc_dependencies_2 = require("@nx/js/src/utils/swc/add-swc-dependencies");
15
14
  const nxVersion = require('../../../package.json').version;
16
- function addFiles(host, options) {
17
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
18
- host.delete((0, devkit_1.normalizePath)(`${options.projectRoot}/src/lib`));
19
- (0, devkit_1.generateFiles)(host, path.join(__dirname, './files/plugin'), options.projectRoot, Object.assign(Object.assign({}, options), { tmpl: '' }));
15
+ async function addFiles(host, options) {
16
+ host.delete((0, devkit_1.normalizePath)(`${options.projectRoot}/src/lib`));
17
+ (0, devkit_1.generateFiles)(host, path.join(__dirname, './files/plugin'), options.projectRoot, {
18
+ ...options,
19
+ tmpl: '',
20
20
  });
21
21
  }
22
22
  function updatePluginConfig(host, options) {
23
- var _a;
24
- var _b;
25
23
  const project = (0, devkit_1.readProjectConfiguration)(host, options.name);
26
24
  if (project.targets.build) {
27
- (_a = (_b = project.targets.build.options).assets) !== null && _a !== void 0 ? _a : (_b.assets = []);
25
+ project.targets.build.options.assets ??= [];
28
26
  const root = options.projectRoot === '.' ? '.' : './' + options.projectRoot;
29
27
  project.targets.build.options.assets = [
30
28
  ...project.targets.build.options.assets,
@@ -52,52 +50,58 @@ function updatePluginConfig(host, options) {
52
50
  (0, devkit_1.updateProjectConfiguration)(host, options.name, project);
53
51
  }
54
52
  }
55
- function pluginGenerator(host, schema) {
56
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
57
- return yield pluginGeneratorInternal(host, Object.assign({ projectNameAndRootFormat: 'derived' }, schema));
53
+ async function pluginGenerator(host, schema) {
54
+ return await pluginGeneratorInternal(host, {
55
+ projectNameAndRootFormat: 'derived',
56
+ ...schema,
58
57
  });
59
58
  }
60
59
  exports.pluginGenerator = pluginGenerator;
61
- function pluginGeneratorInternal(host, schema) {
62
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
63
- const options = yield (0, normalize_schema_1.normalizeOptions)(host, schema);
64
- const tasks = [];
65
- tasks.push(yield (0, js_1.libraryGenerator)(host, Object.assign(Object.assign({}, schema), { config: 'project', bundler: options.bundler, publishable: options.publishable, importPath: options.npmPackageName, skipFormat: true })));
66
- if (options.bundler === 'tsc') {
67
- tasks.push((0, add_tslib_dependencies_1.addTsLibDependencies)(host));
68
- }
69
- tasks.push((0, devkit_1.addDependenciesToPackageJson)(host, {
70
- '@nx/devkit': nxVersion,
71
- }, {
72
- '@nx/jest': nxVersion,
73
- '@nx/js': nxVersion,
74
- '@nx/plugin': nxVersion,
60
+ async function pluginGeneratorInternal(host, schema) {
61
+ const options = await (0, normalize_schema_1.normalizeOptions)(host, schema);
62
+ const tasks = [];
63
+ tasks.push(await (0, js_1.libraryGenerator)(host, {
64
+ ...schema,
65
+ config: 'project',
66
+ bundler: options.bundler,
67
+ publishable: options.publishable,
68
+ importPath: options.npmPackageName,
69
+ skipFormat: true,
70
+ }));
71
+ if (options.bundler === 'tsc') {
72
+ tasks.push((0, add_tslib_dependencies_1.addTsLibDependencies)(host));
73
+ }
74
+ tasks.push((0, devkit_1.addDependenciesToPackageJson)(host, {
75
+ '@nx/devkit': nxVersion,
76
+ }, {
77
+ '@nx/jest': nxVersion,
78
+ '@nx/js': nxVersion,
79
+ '@nx/plugin': nxVersion,
80
+ }));
81
+ // Ensures Swc Deps are installed to handle running
82
+ // local plugin generators and executors
83
+ tasks.push((0, add_swc_dependencies_1.addSwcDependencies)(host));
84
+ tasks.push((0, add_swc_dependencies_2.addSwcRegisterDependencies)(host));
85
+ await addFiles(host, options);
86
+ updatePluginConfig(host, options);
87
+ if (options.e2eTestRunner !== 'none') {
88
+ tasks.push(await (0, e2e_1.e2eProjectGenerator)(host, {
89
+ pluginName: options.name,
90
+ projectDirectory: options.projectDirectory,
91
+ pluginOutputPath: (0, devkit_1.joinPathFragments)('dist', options.rootProject ? options.name : options.projectRoot),
92
+ npmPackageName: options.npmPackageName,
93
+ skipFormat: true,
94
+ rootProject: options.rootProject,
95
+ projectNameAndRootFormat: options.projectNameAndRootFormat,
75
96
  }));
76
- // Ensures Swc Deps are installed to handle running
77
- // local plugin generators and executors
78
- tasks.push((0, add_swc_dependencies_1.addSwcDependencies)(host));
79
- tasks.push((0, add_swc_dependencies_2.addSwcRegisterDependencies)(host));
80
- yield addFiles(host, options);
81
- updatePluginConfig(host, options);
82
- if (options.e2eTestRunner !== 'none') {
83
- tasks.push(yield (0, e2e_1.e2eProjectGenerator)(host, {
84
- pluginName: options.name,
85
- projectDirectory: options.projectDirectory,
86
- pluginOutputPath: (0, devkit_1.joinPathFragments)('dist', options.rootProject ? options.name : options.projectRoot),
87
- npmPackageName: options.npmPackageName,
88
- skipFormat: true,
89
- rootProject: options.rootProject,
90
- projectNameAndRootFormat: options.projectNameAndRootFormat,
91
- }));
92
- }
93
- if (options.linter === linter_1.Linter.EsLint && !options.skipLintChecks) {
94
- yield (0, generator_1.default)(host, { projectName: options.name });
95
- }
96
- if (!options.skipFormat) {
97
- yield (0, devkit_1.formatFiles)(host);
98
- }
99
- return (0, devkit_1.runTasksInSerial)(...tasks);
100
- });
97
+ }
98
+ if (options.linter === linter_1.Linter.EsLint && !options.skipLintChecks) {
99
+ await (0, generator_1.default)(host, { projectName: options.name });
100
+ }
101
+ if (!options.skipFormat) {
102
+ await (0, devkit_1.formatFiles)(host);
103
+ }
104
+ return (0, devkit_1.runTasksInSerial)(...tasks);
101
105
  }
102
106
  exports.pluginGeneratorInternal = pluginGeneratorInternal;
103
107
  exports.default = pluginGenerator;
@@ -1,41 +1,44 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.normalizeOptions = void 0;
4
- const tslib_1 = require("tslib");
5
4
  const devkit_1 = require("@nx/devkit");
6
5
  const project_name_and_root_utils_1 = require("@nx/devkit/src/generators/project-name-and-root-utils");
7
- function normalizeOptions(host, options) {
8
- var _a, _b;
9
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
10
- const { projectName, projectRoot, importPath: npmPackageName, projectNameAndRootFormat, } = yield (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(host, {
11
- name: options.name,
12
- projectType: 'library',
13
- directory: options.directory,
14
- importPath: options.importPath,
15
- projectNameAndRootFormat: options.projectNameAndRootFormat,
16
- rootProject: options.rootProject,
17
- callingGenerator: '@nx/plugin:plugin',
18
- });
19
- options.projectNameAndRootFormat = projectNameAndRootFormat;
20
- options.rootProject = projectRoot === '.';
21
- let projectDirectory = projectRoot;
22
- if (options.projectNameAndRootFormat === 'derived') {
23
- let { layoutDirectory } = (0, devkit_1.extractLayoutDirectory)(options.directory);
24
- if (!layoutDirectory) {
25
- const { libsDir } = (0, devkit_1.getWorkspaceLayout)(host);
26
- layoutDirectory = libsDir;
27
- }
28
- if (projectRoot.startsWith(`${layoutDirectory}/`)) {
29
- projectDirectory = projectRoot.replace(`${layoutDirectory}/`, '');
30
- }
31
- }
32
- const parsedTags = options.tags
33
- ? options.tags.split(',').map((s) => s.trim())
34
- : [];
35
- return Object.assign(Object.assign({}, options), { bundler: (_a = options.compiler) !== null && _a !== void 0 ? _a : 'tsc', fileName: projectName, name: projectName, projectRoot,
36
- projectDirectory,
37
- parsedTags,
38
- npmPackageName, publishable: (_b = options.publishable) !== null && _b !== void 0 ? _b : false });
6
+ async function normalizeOptions(host, options) {
7
+ const { projectName, projectRoot, importPath: npmPackageName, projectNameAndRootFormat, } = await (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(host, {
8
+ name: options.name,
9
+ projectType: 'library',
10
+ directory: options.directory,
11
+ importPath: options.importPath,
12
+ projectNameAndRootFormat: options.projectNameAndRootFormat,
13
+ rootProject: options.rootProject,
14
+ callingGenerator: '@nx/plugin:plugin',
39
15
  });
16
+ options.projectNameAndRootFormat = projectNameAndRootFormat;
17
+ options.rootProject = projectRoot === '.';
18
+ let projectDirectory = projectRoot;
19
+ if (options.projectNameAndRootFormat === 'derived') {
20
+ let { layoutDirectory } = (0, devkit_1.extractLayoutDirectory)(options.directory);
21
+ if (!layoutDirectory) {
22
+ const { libsDir } = (0, devkit_1.getWorkspaceLayout)(host);
23
+ layoutDirectory = libsDir;
24
+ }
25
+ if (projectRoot.startsWith(`${layoutDirectory}/`)) {
26
+ projectDirectory = projectRoot.replace(`${layoutDirectory}/`, '');
27
+ }
28
+ }
29
+ const parsedTags = options.tags
30
+ ? options.tags.split(',').map((s) => s.trim())
31
+ : [];
32
+ return {
33
+ ...options,
34
+ bundler: options.compiler ?? 'tsc',
35
+ fileName: projectName,
36
+ name: projectName,
37
+ projectRoot,
38
+ projectDirectory,
39
+ parsedTags,
40
+ npmPackageName,
41
+ publishable: options.publishable ?? false,
42
+ };
40
43
  }
41
44
  exports.normalizeOptions = normalizeOptions;
@@ -1,59 +1,56 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
3
  const devkit_1 = require("@nx/devkit");
5
4
  const linter_1 = require("@nx/linter");
6
5
  const plugin_1 = require("../plugin/plugin");
7
6
  const create_package_1 = require("../create-package/create-package");
8
- function default_1(tree, options) {
9
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
10
- const tasks = [];
11
- const pluginProjectName = (0, devkit_1.names)(options.pluginName.includes('/')
12
- ? options.pluginName.split('/')[1]
13
- : options.pluginName).fileName;
14
- options.createPackageName =
15
- options.createPackageName === 'false' // for command line in e2e, it is passed as a string
16
- ? undefined
17
- : options.createPackageName;
18
- const pluginTask = yield (0, plugin_1.pluginGenerator)(tree, {
19
- compiler: 'tsc',
20
- linter: linter_1.Linter.EsLint,
21
- name: pluginProjectName,
7
+ async function default_1(tree, options) {
8
+ const tasks = [];
9
+ const pluginProjectName = (0, devkit_1.names)(options.pluginName.includes('/')
10
+ ? options.pluginName.split('/')[1]
11
+ : options.pluginName).fileName;
12
+ options.createPackageName =
13
+ options.createPackageName === 'false' // for command line in e2e, it is passed as a string
14
+ ? undefined
15
+ : options.createPackageName;
16
+ const pluginTask = await (0, plugin_1.pluginGenerator)(tree, {
17
+ compiler: 'tsc',
18
+ linter: linter_1.Linter.EsLint,
19
+ name: pluginProjectName,
20
+ skipFormat: true,
21
+ unitTestRunner: 'jest',
22
+ importPath: options.pluginName,
23
+ e2eTestRunner: 'jest',
24
+ publishable: true,
25
+ // when creating a CLI package, the plugin will be in the packages folder
26
+ directory: options.createPackageName && options.createPackageName !== 'false'
27
+ ? 'packages'
28
+ : undefined,
29
+ rootProject: options.createPackageName ? false : true,
30
+ });
31
+ tasks.push(pluginTask);
32
+ removeNpmScope(tree);
33
+ moveNxPluginToDevDeps(tree);
34
+ if (options.createPackageName) {
35
+ const e2eProject = `${options.pluginName}-e2e`;
36
+ const cliTask = await (0, create_package_1.default)(tree, {
37
+ directory: 'packages',
38
+ name: options.createPackageName,
39
+ e2eProject: e2eProject,
40
+ project: options.pluginName,
22
41
  skipFormat: true,
23
42
  unitTestRunner: 'jest',
24
- importPath: options.pluginName,
25
- e2eTestRunner: 'jest',
26
- publishable: true,
27
- // when creating a CLI package, the plugin will be in the packages folder
28
- directory: options.createPackageName && options.createPackageName !== 'false'
29
- ? 'packages'
30
- : undefined,
31
- rootProject: options.createPackageName ? false : true,
43
+ linter: linter_1.Linter.EsLint,
44
+ compiler: 'tsc',
32
45
  });
33
- tasks.push(pluginTask);
34
- removeNpmScope(tree);
35
- moveNxPluginToDevDeps(tree);
36
- if (options.createPackageName) {
37
- const e2eProject = `${options.pluginName}-e2e`;
38
- const cliTask = yield (0, create_package_1.default)(tree, {
39
- directory: 'packages',
40
- name: options.createPackageName,
41
- e2eProject: e2eProject,
42
- project: options.pluginName,
43
- skipFormat: true,
44
- unitTestRunner: 'jest',
45
- linter: linter_1.Linter.EsLint,
46
- compiler: 'tsc',
47
- });
48
- tasks.push(cliTask);
49
- }
50
- yield (0, devkit_1.formatFiles)(tree);
51
- return (0, devkit_1.runTasksInSerial)(...tasks);
52
- });
46
+ tasks.push(cliTask);
47
+ }
48
+ await (0, devkit_1.formatFiles)(tree);
49
+ return (0, devkit_1.runTasksInSerial)(...tasks);
53
50
  }
54
51
  exports.default = default_1;
55
52
  function removeNpmScope(tree) {
56
- (0, devkit_1.updateNxJson)(tree, Object.assign(Object.assign({}, (0, devkit_1.readNxJson)(tree)), { npmScope: undefined }));
53
+ (0, devkit_1.updateNxJson)(tree, { ...(0, devkit_1.readNxJson)(tree), npmScope: undefined });
57
54
  }
58
55
  function moveNxPluginToDevDeps(tree) {
59
56
  (0, devkit_1.updateJson)(tree, 'package.json', (json) => {
@@ -1,13 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
3
  const devkit_1 = require("@nx/devkit");
5
4
  const add_swc_dependencies_1 = require("@nx/js/src/utils/swc/add-swc-dependencies");
6
- function addSwcNodeIfNeeded(tree) {
7
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
8
- (0, add_swc_dependencies_1.addSwcRegisterDependencies)(tree);
9
- yield (0, devkit_1.formatFiles)(tree);
10
- return (0, devkit_1.installPackagesTask)(tree);
11
- });
5
+ async function addSwcNodeIfNeeded(tree) {
6
+ (0, add_swc_dependencies_1.addSwcRegisterDependencies)(tree);
7
+ await (0, devkit_1.formatFiles)(tree);
8
+ return (0, devkit_1.installPackagesTask)(tree);
12
9
  }
13
10
  exports.default = addSwcNodeIfNeeded;
@@ -1,56 +1,53 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
3
  const devkit_1 = require("@nx/devkit");
5
- function update(tree) {
6
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
7
- for (const [project, { root }] of (0, devkit_1.getProjects)(tree)) {
8
- const packageJsonPath = (0, devkit_1.joinPathFragments)(root, 'package.json');
9
- if (!tree.exists(packageJsonPath)) {
10
- continue;
11
- }
12
- const packageJson = (0, devkit_1.readJson)(tree, packageJsonPath);
13
- if (!packageJson.executors && !packageJson.builders) {
4
+ async function update(tree) {
5
+ for (const [project, { root }] of (0, devkit_1.getProjects)(tree)) {
6
+ const packageJsonPath = (0, devkit_1.joinPathFragments)(root, 'package.json');
7
+ if (!tree.exists(packageJsonPath)) {
8
+ continue;
9
+ }
10
+ const packageJson = (0, devkit_1.readJson)(tree, packageJsonPath);
11
+ if (!packageJson.executors && !packageJson.builders) {
12
+ continue;
13
+ }
14
+ const paths = [packageJson.executors, packageJson.builders].filter(Boolean);
15
+ for (const collectionPathSegment of paths) {
16
+ const collectionPath = (0, devkit_1.joinPathFragments)(root, collectionPathSegment);
17
+ if (!tree.exists(collectionPath)) {
14
18
  continue;
15
19
  }
16
- const paths = [packageJson.executors, packageJson.builders].filter(Boolean);
17
- for (const collectionPathSegment of paths) {
18
- const collectionPath = (0, devkit_1.joinPathFragments)(root, collectionPathSegment);
19
- if (!tree.exists(collectionPath)) {
20
+ const collectionFile = (0, devkit_1.readJson)(tree, collectionPath);
21
+ const collections = [
22
+ collectionFile.builders,
23
+ collectionFile.executors,
24
+ ].filter(Boolean);
25
+ for (const collection of collections) {
26
+ if (!collection) {
20
27
  continue;
21
28
  }
22
- const collectionFile = (0, devkit_1.readJson)(tree, collectionPath);
23
- const collections = [
24
- collectionFile.builders,
25
- collectionFile.executors,
26
- ].filter(Boolean);
27
- for (const collection of collections) {
28
- if (!collection) {
29
- continue;
30
- }
31
- for (const entry of Object.values(collection)) {
32
- const schemaPath = (0, devkit_1.joinPathFragments)(root, entry.schema);
33
- if (tree.exists(schemaPath)) {
34
- (0, devkit_1.updateJson)(tree, schemaPath, (json) => {
35
- if (json.version) {
36
- return json;
37
- }
38
- else {
39
- const newProperties = {
40
- version: 2,
41
- };
42
- if (!json.outputCapture) {
43
- newProperties.outputCapture = 'direct-nodejs';
44
- }
45
- return Object.assign(Object.assign({}, newProperties), json);
29
+ for (const entry of Object.values(collection)) {
30
+ const schemaPath = (0, devkit_1.joinPathFragments)(root, entry.schema);
31
+ if (tree.exists(schemaPath)) {
32
+ (0, devkit_1.updateJson)(tree, schemaPath, (json) => {
33
+ if (json.version) {
34
+ return json;
35
+ }
36
+ else {
37
+ const newProperties = {
38
+ version: 2,
39
+ };
40
+ if (!json.outputCapture) {
41
+ newProperties.outputCapture = 'direct-nodejs';
46
42
  }
47
- });
48
- }
43
+ return { ...newProperties, ...json };
44
+ }
45
+ });
49
46
  }
50
47
  }
51
48
  }
52
49
  }
53
- yield (0, devkit_1.formatFiles)(tree);
54
- });
50
+ }
51
+ await (0, devkit_1.formatFiles)(tree);
55
52
  }
56
53
  exports.default = update;
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.updateConfigsJest29 = void 0;
4
- const tslib_1 = require("tslib");
5
4
  const devkit_1 = require("@nx/devkit");
6
5
  const tsquery_1 = require("@phenomnomnominal/tsquery");
7
6
  const ts = require("typescript");
@@ -9,38 +8,36 @@ const executor_options_utils_1 = require("@nx/devkit/src/generators/executor-opt
9
8
  const ast_utils_1 = require("@nx/jest/src/utils/ast-utils");
10
9
  const find_root_jest_files_1 = require("@nx/jest/src/utils/config/find-root-jest-files");
11
10
  // NOTE: this is a copy of the @nrwl/jest v15.8.0 migrations
12
- function updateConfigsJest29(tree) {
13
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
14
- const rootPreset = (0, find_root_jest_files_1.findRootJestPreset)(tree);
15
- const targetsWithJest = new Set();
16
- // have to use graph so the negative configuration targets are expanded
17
- const graph = yield (0, devkit_1.createProjectGraphAsync)();
18
- (0, executor_options_utils_1.forEachExecutorOptionsInGraph)(graph, '@nrwl/nx-plugin:e2e', (options, projectName, targetName) => {
19
- if (options.jestConfig && tree.exists(options.jestConfig)) {
20
- targetsWithJest.add(targetName);
21
- // if the default root preset exists or if the project doesn't have a 'preset' configured
22
- // -> update snapshot config
23
- if (!rootPreset || !hasPresetConfigured(tree, options.jestConfig)) {
24
- addSnapshotOptionsToConfig(tree, options.jestConfig, `From within the project directory, run "nx test --update-snapshot"`);
25
- }
26
- updateTsJestOptions(tree, options.jestConfig);
27
- updateNgJestOptions(tree, options.jestConfig);
11
+ async function updateConfigsJest29(tree) {
12
+ const rootPreset = (0, find_root_jest_files_1.findRootJestPreset)(tree);
13
+ const targetsWithJest = new Set();
14
+ // have to use graph so the negative configuration targets are expanded
15
+ const graph = await (0, devkit_1.createProjectGraphAsync)();
16
+ (0, executor_options_utils_1.forEachExecutorOptionsInGraph)(graph, '@nrwl/nx-plugin:e2e', (options, projectName, targetName) => {
17
+ if (options.jestConfig && tree.exists(options.jestConfig)) {
18
+ targetsWithJest.add(targetName);
19
+ // if the default root preset exists or if the project doesn't have a 'preset' configured
20
+ // -> update snapshot config
21
+ if (!rootPreset || !hasPresetConfigured(tree, options.jestConfig)) {
22
+ addSnapshotOptionsToConfig(tree, options.jestConfig, `From within the project directory, run "nx test --update-snapshot"`);
28
23
  }
29
- });
30
- if (rootPreset && tree.exists(rootPreset)) {
31
- const cmd = `"nx affected --targets=${Array.from(targetsWithJest).join(',')} --update-snapshot"`;
32
- addSnapshotOptionsToConfig(tree, rootPreset, cmd);
33
- updateTsJestOptions(tree, rootPreset);
34
- updateNgJestOptions(tree, rootPreset);
24
+ updateTsJestOptions(tree, options.jestConfig);
25
+ updateNgJestOptions(tree, options.jestConfig);
35
26
  }
36
- yield (0, devkit_1.formatFiles)(tree);
37
- devkit_1.logger.info((0, devkit_1.stripIndents) `NX Jest Snapshot format changed in v29.
27
+ });
28
+ if (rootPreset && tree.exists(rootPreset)) {
29
+ const cmd = `"nx affected --targets=${Array.from(targetsWithJest).join(',')} --update-snapshot"`;
30
+ addSnapshotOptionsToConfig(tree, rootPreset, cmd);
31
+ updateTsJestOptions(tree, rootPreset);
32
+ updateNgJestOptions(tree, rootPreset);
33
+ }
34
+ await (0, devkit_1.formatFiles)(tree);
35
+ devkit_1.logger.info((0, devkit_1.stripIndents) `NX Jest Snapshot format changed in v29.
38
36
  By default Nx kept the older style to prevent breaking of existing tests with snapshots.
39
37
  It's recommend you update to the latest format.
40
38
  You can do this in your project's jest config file.
41
39
  Remove the snapshotFormat property and re-run tests with the --update-snapshot flag.
42
40
  More info: https://jestjs.io/docs/upgrading-to-jest29#snapshot-format`);
43
- });
44
41
  }
45
42
  exports.updateConfigsJest29 = updateConfigsJest29;
46
43
  function addSnapshotOptionsToConfig(tree, configPath, updateSnapshotExample) {
@@ -67,9 +64,8 @@ snapshotFormat: { escapeString: true, printBasicPrototype: true }
67
64
  tree.write(configPath, updatedConfig);
68
65
  }
69
66
  function hasPresetConfigured(tree, configPath) {
70
- var _a;
71
67
  const contents = tree.read(configPath, 'utf-8');
72
- return (((_a = tsquery_1.tsquery.query(contents, `${ast_utils_1.TS_QUERY_JEST_CONFIG_PREFIX} > ObjectLiteralExpression PropertyAssignment:has(Identifier[name="preset"])`)) === null || _a === void 0 ? void 0 : _a.length) > 0);
68
+ return (tsquery_1.tsquery.query(contents, `${ast_utils_1.TS_QUERY_JEST_CONFIG_PREFIX} > ObjectLiteralExpression PropertyAssignment:has(Identifier[name="preset"])`)?.length > 0);
73
69
  }
74
70
  function updateTsJestOptions(tree, configPath) {
75
71
  // query for the globals property, if they don't have one then there's nothing to modify.
@@ -126,15 +122,13 @@ testEnvironmentOptions: { teardown: ${ngJestTeardownConfig} },
126
122
  tree.write(configPath, updatedConfig);
127
123
  }
128
124
  function getGlobalTsJestConfig(node) {
129
- var _a;
130
125
  const globalObject = node.initializer;
131
126
  const foundConfig = globalObject.properties.find((p) => ts.isPropertyAssignment(p) && p.name.getText().includes('ts-jest'));
132
- return ((_a = foundConfig === null || foundConfig === void 0 ? void 0 : foundConfig.initializer) === null || _a === void 0 ? void 0 : _a.getText()) || '';
127
+ return foundConfig?.initializer?.getText() || '';
133
128
  }
134
129
  function getGlobalConfigWithoutTsJest(node) {
135
- var _a;
136
- const globalObject = node === null || node === void 0 ? void 0 : node.initializer;
137
- const withoutTsJest = (_a = globalObject === null || globalObject === void 0 ? void 0 : globalObject.properties) === null || _a === void 0 ? void 0 : _a.filter((p) => {
130
+ const globalObject = node?.initializer;
131
+ const withoutTsJest = globalObject?.properties?.filter((p) => {
138
132
  return !(ts.isPropertyAssignment(p) && p.name.getText().includes('ts-jest'));
139
133
  });
140
134
  const globalConfigs = withoutTsJest.map((c) => c.getText()).join(',\n');
@@ -142,7 +136,7 @@ function getGlobalConfigWithoutTsJest(node) {
142
136
  }
143
137
  function getNodeWithComments(fullText, node) {
144
138
  const commentRanges = ts.getLeadingCommentRanges(fullText, node.getFullStart());
145
- if ((commentRanges === null || commentRanges === void 0 ? void 0 : commentRanges.length) > 0) {
139
+ if (commentRanges?.length > 0) {
146
140
  const withComments = `${commentRanges
147
141
  .map((r) => fullText.slice(r.pos, r.end))
148
142
  .join('\n')}\n${node.getText()}`;
@@ -1,27 +1,24 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.updateJestMocked = exports.updateJestMockTypes = exports.updateTestsJest29 = void 0;
4
- const tslib_1 = require("tslib");
5
4
  const devkit_1 = require("@nx/devkit");
6
5
  const ast_utils_1 = require("@nx/jest/src/utils/ast-utils");
7
6
  const executor_options_utils_1 = require("@nx/devkit/src/generators/executor-options-utils");
8
7
  const tsquery_1 = require("@phenomnomnominal/tsquery");
9
8
  // NOTE: this is a copy of the @nrwl/jest v15.8.0 migrations
10
- function updateTestsJest29(tree) {
11
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
12
- const graph = yield (0, devkit_1.createProjectGraphAsync)();
13
- (0, executor_options_utils_1.forEachExecutorOptionsInGraph)(graph, '@nrwl/nx-plugin:e2e', (options, projectName) => {
14
- const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, projectName);
15
- (0, devkit_1.visitNotIgnoredFiles)(tree, projectConfig.sourceRoot || projectConfig.root, (file) => {
16
- if (!ast_utils_1.TEST_FILE_PATTERN.test(file)) {
17
- return;
18
- }
19
- updateJestMockTypes(tree, file);
20
- updateJestMocked(tree, file);
21
- });
9
+ async function updateTestsJest29(tree) {
10
+ const graph = await (0, devkit_1.createProjectGraphAsync)();
11
+ (0, executor_options_utils_1.forEachExecutorOptionsInGraph)(graph, '@nrwl/nx-plugin:e2e', (options, projectName) => {
12
+ const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, projectName);
13
+ (0, devkit_1.visitNotIgnoredFiles)(tree, projectConfig.sourceRoot || projectConfig.root, (file) => {
14
+ if (!ast_utils_1.TEST_FILE_PATTERN.test(file)) {
15
+ return;
16
+ }
17
+ updateJestMockTypes(tree, file);
18
+ updateJestMocked(tree, file);
22
19
  });
23
- yield (0, devkit_1.formatFiles)(tree);
24
20
  });
21
+ await (0, devkit_1.formatFiles)(tree);
25
22
  }
26
23
  exports.updateTestsJest29 = updateTestsJest29;
27
24
  function updateJestMockTypes(tree, filePath) {
@@ -85,32 +85,29 @@ function updateCliPropsForPlugins(tree) {
85
85
  }
86
86
  exports.updateCliPropsForPlugins = updateCliPropsForPlugins;
87
87
  function removeCliFromExecutorSchemaJsonFiles(tree, collectionPath) {
88
- var _a, _b;
89
88
  const collection = (0, devkit_1.readJson)(tree, collectionPath);
90
- for (const [name, entry] of Object.entries((_a = collection.executors) !== null && _a !== void 0 ? _a : {}).concat(Object.entries((_b = collection.builders) !== null && _b !== void 0 ? _b : {}))) {
89
+ for (const [name, entry] of Object.entries(collection.executors ?? {}).concat(Object.entries(collection.builders ?? {}))) {
91
90
  deleteCliPropFromSchemaFile(collectionPath, entry, tree);
92
91
  }
93
92
  }
94
93
  function removeCliFromGeneratorSchemaJsonFiles(tree, collectionPath) {
95
- var _a, _b;
96
94
  const collection = (0, devkit_1.readJson)(tree, collectionPath);
97
- for (const [name, entry] of Object.entries((_a = collection.generators) !== null && _a !== void 0 ? _a : {}).concat(Object.entries((_b = collection.schematics) !== null && _b !== void 0 ? _b : {}))) {
95
+ for (const [name, entry] of Object.entries(collection.generators ?? {}).concat(Object.entries(collection.schematics ?? {}))) {
98
96
  deleteCliPropFromSchemaFile(collectionPath, entry, tree);
99
97
  }
100
98
  }
101
99
  function updateMigrationsJsonForPlugin(tree, collectionPath) {
102
100
  (0, devkit_1.updateJson)(tree, collectionPath, (json) => {
103
- var _a, _b, _c, _d;
104
- for (const migration in (_a = json.generators) !== null && _a !== void 0 ? _a : {}) {
101
+ for (const migration in json.generators ?? {}) {
105
102
  if (!(json.generators[migration].cli === 'nx')) {
106
- (_b = json.schematics) !== null && _b !== void 0 ? _b : (json.schematics = {});
103
+ json.schematics ??= {};
107
104
  json.schematics[migration] = json.generators[migration];
108
105
  delete json.generators[migration];
109
106
  }
110
107
  }
111
- for (const migration in (_c = json.schematics) !== null && _c !== void 0 ? _c : {}) {
108
+ for (const migration in json.schematics ?? {}) {
112
109
  if (json.schematics[migration].cli === 'nx') {
113
- (_d = json.generators) !== null && _d !== void 0 ? _d : (json.generators = {});
110
+ json.generators ??= {};
114
111
  json.generators[migration] = json.schematics[migration];
115
112
  delete json.schematics[migration];
116
113
  }
@@ -1,12 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
3
  const devkit_1 = require("@nx/devkit");
5
4
  const replace_package_1 = require("@nx/devkit/src/utils/replace-package");
6
- function replacePackage(tree) {
7
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
8
- yield (0, replace_package_1.replaceNrwlPackageWithNxPackage)(tree, '@nrwl/nx-plugin', '@nx/plugin');
9
- yield (0, devkit_1.formatFiles)(tree);
10
- });
5
+ async function replacePackage(tree) {
6
+ await (0, replace_package_1.replaceNrwlPackageWithNxPackage)(tree, '@nrwl/nx-plugin', '@nx/plugin');
7
+ await (0, devkit_1.formatFiles)(tree);
11
8
  }
12
9
  exports.default = replacePackage;