@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.
- package/package.json +7 -7
- package/src/executors/e2e/e2e.impl.js +30 -63
- package/src/generators/create-package/create-package.js +70 -64
- package/src/generators/create-package/files/e2e/__cliName__.spec.ts__tmpl__ +1 -1
- package/src/generators/create-package/utils/normalize-schema.js +15 -14
- package/src/generators/e2e-project/e2e.js +105 -93
- package/src/generators/executor/executor.js +67 -65
- package/src/generators/generator/generator.js +67 -66
- package/src/generators/lint-checks/generator.js +54 -54
- package/src/generators/migration/migration.js +29 -29
- package/src/generators/plugin/plugin.js +54 -50
- package/src/generators/plugin/utils/normalize-schema.js +36 -33
- package/src/generators/preset/generator.js +41 -44
- package/src/migrations/update-14-1-9/add-swc-deps-if-needed.js +4 -7
- package/src/migrations/update-15-0-0/specify-output-capture.js +39 -42
- package/src/migrations/update-15-9-0/jest-29-configs.js +28 -34
- package/src/migrations/update-15-9-0/jest-29-tests.js +11 -14
- package/src/migrations/update-16-0-0/cli-in-schema-json.js +6 -9
- package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js +3 -6
- package/src/migrations/update-16-2-0/replace-e2e-executor.js +26 -26
- package/src/utils/has-generator.js +3 -3
- package/src/utils/testing-utils/async-commands.js +2 -3
- package/src/utils/testing-utils/commands.js +4 -6
- package/src/utils/testing-utils/nx-project.js +8 -2
|
@@ -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
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
|
|
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
|
|
57
|
-
|
|
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
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
options.createPackageName
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
-
|
|
25
|
-
|
|
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(
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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,
|
|
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
-
|
|
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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
(
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
|
|
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
|
-
|
|
37
|
-
|
|
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 (
|
|
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
|
|
127
|
+
return foundConfig?.initializer?.getText() || '';
|
|
133
128
|
}
|
|
134
129
|
function getGlobalConfigWithoutTsJest(node) {
|
|
135
|
-
|
|
136
|
-
const
|
|
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 (
|
|
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
|
-
|
|
12
|
-
|
|
13
|
-
(0,
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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(
|
|
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(
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
108
|
+
for (const migration in json.schematics ?? {}) {
|
|
112
109
|
if (json.schematics[migration].cli === 'nx') {
|
|
113
|
-
|
|
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
|
-
|
|
8
|
-
|
|
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;
|