@nx/plugin 0.0.0-pr-22179-271588f
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/LICENSE +22 -0
- package/README.md +72 -0
- package/executors.json +10 -0
- package/generators.d.ts +6 -0
- package/generators.js +9 -0
- package/generators.json +49 -0
- package/index.d.ts +0 -0
- package/index.js +0 -0
- package/migrations.json +40 -0
- package/package.json +44 -0
- package/src/executors/e2e/e2e.impl.d.ts +6 -0
- package/src/executors/e2e/e2e.impl.js +43 -0
- package/src/executors/e2e/schema.d.ts +6 -0
- package/src/executors/e2e/schema.json +220 -0
- package/src/generators/create-package/create-package.d.ts +5 -0
- package/src/generators/create-package/create-package.js +112 -0
- package/src/generators/create-package/files/create-framework-package/bin/index.ts__tmpl__ +27 -0
- package/src/generators/create-package/files/e2e/__cliName__.spec.ts__tmpl__ +56 -0
- package/src/generators/create-package/schema.d.ts +19 -0
- package/src/generators/create-package/schema.json +79 -0
- package/src/generators/create-package/utils/normalize-schema.d.ts +8 -0
- package/src/generators/create-package/utils/normalize-schema.js +22 -0
- package/src/generators/e2e-project/e2e.d.ts +6 -0
- package/src/generators/e2e-project/e2e.js +144 -0
- package/src/generators/e2e-project/files/src/__pluginName__.spec.ts__tmpl__ +66 -0
- package/src/generators/e2e-project/files/tsconfig.json__tmpl__ +6 -0
- package/src/generators/e2e-project/schema.d.ts +15 -0
- package/src/generators/e2e-project/schema.json +57 -0
- package/src/generators/executor/executor.d.ts +6 -0
- package/src/generators/executor/executor.js +126 -0
- package/src/generators/executor/files/executor/executor.spec.ts.template +11 -0
- package/src/generators/executor/files/executor/executor.ts.template +11 -0
- package/src/generators/executor/files/executor/schema.d.ts.template +1 -0
- package/src/generators/executor/files/executor/schema.json.template +9 -0
- package/src/generators/executor/files/hasher/hasher.spec.ts.template +23 -0
- package/src/generators/executor/files/hasher/hasher.ts.template +12 -0
- package/src/generators/executor/schema.d.ts +17 -0
- package/src/generators/executor/schema.json +76 -0
- package/src/generators/generator/files/generator/generator.spec.ts.template +20 -0
- package/src/generators/generator/files/generator/generator.ts.template +26 -0
- package/src/generators/generator/files/generator/schema.d.ts.template +3 -0
- package/src/generators/generator/files/generator/schema.json.template +18 -0
- package/src/generators/generator/generator.d.ts +6 -0
- package/src/generators/generator/generator.js +127 -0
- package/src/generators/generator/schema.d.ts +16 -0
- package/src/generators/generator/schema.json +70 -0
- package/src/generators/lint-checks/generator.d.ts +7 -0
- package/src/generators/lint-checks/generator.js +187 -0
- package/src/generators/lint-checks/schema.d.ts +4 -0
- package/src/generators/lint-checks/schema.json +31 -0
- package/src/generators/migration/files/migration/__name__.spec.ts__tmpl__ +17 -0
- package/src/generators/migration/files/migration/__name__.ts__tmpl__ +6 -0
- package/src/generators/migration/migration.d.ts +5 -0
- package/src/generators/migration/migration.js +135 -0
- package/src/generators/migration/schema.d.ts +16 -0
- package/src/generators/migration/schema.json +68 -0
- package/src/generators/plugin/files/plugin/src/index.ts__tmpl__ +0 -0
- package/src/generators/plugin/plugin.d.ts +5 -0
- package/src/generators/plugin/plugin.js +107 -0
- package/src/generators/plugin/schema.d.ts +20 -0
- package/src/generators/plugin/schema.json +104 -0
- package/src/generators/plugin/utils/normalize-schema.d.ts +13 -0
- package/src/generators/plugin/utils/normalize-schema.js +44 -0
- package/src/generators/preset/generator.d.ts +3 -0
- package/src/generators/preset/generator.js +58 -0
- package/src/generators/preset/schema.d.ts +4 -0
- package/src/generators/preset/schema.json +30 -0
- package/src/migrations/update-15-0-0/specify-output-capture.d.ts +2 -0
- package/src/migrations/update-15-0-0/specify-output-capture.js +53 -0
- package/src/migrations/update-15-9-0/jest-29-configs.d.ts +3 -0
- package/src/migrations/update-15-9-0/jest-29-configs.js +147 -0
- package/src/migrations/update-15-9-0/jest-29-tests.d.ts +5 -0
- package/src/migrations/update-15-9-0/jest-29-tests.js +61 -0
- package/src/migrations/update-16-0-0/cli-in-schema-json.d.ts +3 -0
- package/src/migrations/update-16-0-0/cli-in-schema-json.js +135 -0
- package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.d.ts +2 -0
- package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js +9 -0
- package/src/migrations/update-16-2-0/replace-e2e-executor.d.ts +2 -0
- package/src/migrations/update-16-2-0/replace-e2e-executor.js +32 -0
- package/src/utils/has-generator.d.ts +2 -0
- package/src/utils/has-generator.js +16 -0
- package/src/utils/testing-utils/async-commands.d.ts +28 -0
- package/src/utils/testing-utils/async-commands.js +50 -0
- package/src/utils/testing-utils/commands.d.ts +17 -0
- package/src/utils/testing-utils/commands.js +63 -0
- package/src/utils/testing-utils/index.d.ts +5 -0
- package/src/utils/testing-utils/index.js +8 -0
- package/src/utils/testing-utils/nx-project.d.ts +25 -0
- package/src/utils/testing-utils/nx-project.js +70 -0
- package/src/utils/testing-utils/paths.d.ts +15 -0
- package/src/utils/testing-utils/paths.js +32 -0
- package/src/utils/testing-utils/utils.d.ts +80 -0
- package/src/utils/testing-utils/utils.js +144 -0
- package/src/utils/versions.d.ts +2 -0
- package/src/utils/versions.js +5 -0
- package/testing.d.ts +1 -0
- package/testing.js +4 -0
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/schema",
|
|
3
|
+
"cli": "nx",
|
|
4
|
+
"$id": "NxPluginPlugin",
|
|
5
|
+
"title": "Create a Plugin for Nx",
|
|
6
|
+
"description": "Create a Plugin for Nx.",
|
|
7
|
+
"type": "object",
|
|
8
|
+
"examples": [
|
|
9
|
+
{
|
|
10
|
+
"command": "nx g plugin my-plugin --directory=plugins --importPath=@myorg/my-plugin",
|
|
11
|
+
"description": "Generates an Nx plugin project called `plugins-my-plugin` at `libs/plugins/my-plugin`. The project will have an npm package name and import path of `@myorg/my-plugin`."
|
|
12
|
+
}
|
|
13
|
+
],
|
|
14
|
+
"properties": {
|
|
15
|
+
"name": {
|
|
16
|
+
"type": "string",
|
|
17
|
+
"description": "Plugin name",
|
|
18
|
+
"$default": {
|
|
19
|
+
"$source": "argv",
|
|
20
|
+
"index": 0
|
|
21
|
+
},
|
|
22
|
+
"x-prompt": "What name would you like to use for the plugin?",
|
|
23
|
+
"x-priority": "important",
|
|
24
|
+
"pattern": "(?:^@[a-zA-Z0-9-*~][a-zA-Z0-9-*._~]*\\/[a-zA-Z0-9-~][a-zA-Z0-9-._~]*|^[a-zA-Z][^:]*)$"
|
|
25
|
+
},
|
|
26
|
+
"directory": {
|
|
27
|
+
"type": "string",
|
|
28
|
+
"description": "A directory where the plugin is placed."
|
|
29
|
+
},
|
|
30
|
+
"projectNameAndRootFormat": {
|
|
31
|
+
"description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).",
|
|
32
|
+
"type": "string",
|
|
33
|
+
"enum": ["as-provided", "derived"]
|
|
34
|
+
},
|
|
35
|
+
"importPath": {
|
|
36
|
+
"type": "string",
|
|
37
|
+
"description": "How the plugin will be published, like `@myorg/my-awesome-plugin`. Note this must be a valid NPM name.",
|
|
38
|
+
"x-priority": "important"
|
|
39
|
+
},
|
|
40
|
+
"linter": {
|
|
41
|
+
"description": "The tool to use for running lint checks.",
|
|
42
|
+
"type": "string",
|
|
43
|
+
"enum": ["eslint"],
|
|
44
|
+
"default": "eslint"
|
|
45
|
+
},
|
|
46
|
+
"unitTestRunner": {
|
|
47
|
+
"type": "string",
|
|
48
|
+
"enum": ["jest", "none"],
|
|
49
|
+
"description": "Test runner to use for unit tests.",
|
|
50
|
+
"default": "jest"
|
|
51
|
+
},
|
|
52
|
+
"tags": {
|
|
53
|
+
"type": "string",
|
|
54
|
+
"description": "Add tags to the library (used for linting).",
|
|
55
|
+
"alias": "t"
|
|
56
|
+
},
|
|
57
|
+
"skipFormat": {
|
|
58
|
+
"description": "Skip formatting files.",
|
|
59
|
+
"type": "boolean",
|
|
60
|
+
"default": false,
|
|
61
|
+
"x-priority": "internal"
|
|
62
|
+
},
|
|
63
|
+
"skipTsConfig": {
|
|
64
|
+
"type": "boolean",
|
|
65
|
+
"default": false,
|
|
66
|
+
"description": "Do not update tsconfig.json for development experience.",
|
|
67
|
+
"x-priority": "internal"
|
|
68
|
+
},
|
|
69
|
+
"skipLintChecks": {
|
|
70
|
+
"type": "boolean",
|
|
71
|
+
"default": false,
|
|
72
|
+
"description": "Do not eslint configuration for plugin json files."
|
|
73
|
+
},
|
|
74
|
+
"e2eTestRunner": {
|
|
75
|
+
"type": "string",
|
|
76
|
+
"enum": ["jest", "none"],
|
|
77
|
+
"description": "Test runner to use for end to end (E2E) tests.",
|
|
78
|
+
"default": "none"
|
|
79
|
+
},
|
|
80
|
+
"standaloneConfig": {
|
|
81
|
+
"description": "Split the project configuration into `<projectRoot>/project.json` rather than including it inside `workspace.json`.",
|
|
82
|
+
"type": "boolean",
|
|
83
|
+
"default": true,
|
|
84
|
+
"x-deprecated": "Nx only supports standaloneConfig"
|
|
85
|
+
},
|
|
86
|
+
"setParserOptionsProject": {
|
|
87
|
+
"type": "boolean",
|
|
88
|
+
"description": "Whether or not to configure the ESLint `parserOptions.project` option. We do not do this by default for lint performance reasons.",
|
|
89
|
+
"default": false
|
|
90
|
+
},
|
|
91
|
+
"compiler": {
|
|
92
|
+
"type": "string",
|
|
93
|
+
"enum": ["tsc", "swc"],
|
|
94
|
+
"default": "tsc",
|
|
95
|
+
"description": "The compiler used by the build and test targets."
|
|
96
|
+
},
|
|
97
|
+
"publishable": {
|
|
98
|
+
"type": "boolean",
|
|
99
|
+
"description": "Generates a boilerplate for publishing the plugin to npm.",
|
|
100
|
+
"default": false
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
"required": ["name"]
|
|
104
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Tree } from '@nx/devkit';
|
|
2
|
+
import { Schema } from '../schema';
|
|
3
|
+
export interface NormalizedSchema extends Schema {
|
|
4
|
+
name: string;
|
|
5
|
+
fileName: string;
|
|
6
|
+
projectRoot: string;
|
|
7
|
+
projectDirectory: string;
|
|
8
|
+
parsedTags: string[];
|
|
9
|
+
npmPackageName: string;
|
|
10
|
+
bundler: 'swc' | 'tsc';
|
|
11
|
+
publishable: boolean;
|
|
12
|
+
}
|
|
13
|
+
export declare function normalizeOptions(host: Tree, options: Schema): Promise<NormalizedSchema>;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.normalizeOptions = void 0;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const project_name_and_root_utils_1 = require("@nx/devkit/src/generators/project-name-and-root-utils");
|
|
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',
|
|
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
|
+
};
|
|
43
|
+
}
|
|
44
|
+
exports.normalizeOptions = normalizeOptions;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const devkit_1 = require("@nx/devkit");
|
|
4
|
+
const eslint_1 = require("@nx/eslint");
|
|
5
|
+
const plugin_1 = require("../plugin/plugin");
|
|
6
|
+
const create_package_1 = require("../create-package/create-package");
|
|
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: eslint_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
|
+
moveNxPluginToDevDeps(tree);
|
|
33
|
+
if (options.createPackageName) {
|
|
34
|
+
const e2eProject = `${options.pluginName}-e2e`;
|
|
35
|
+
const cliTask = await (0, create_package_1.default)(tree, {
|
|
36
|
+
directory: 'packages',
|
|
37
|
+
name: options.createPackageName,
|
|
38
|
+
e2eProject: e2eProject,
|
|
39
|
+
project: options.pluginName,
|
|
40
|
+
skipFormat: true,
|
|
41
|
+
unitTestRunner: 'jest',
|
|
42
|
+
linter: eslint_1.Linter.EsLint,
|
|
43
|
+
compiler: 'tsc',
|
|
44
|
+
});
|
|
45
|
+
tasks.push(cliTask);
|
|
46
|
+
}
|
|
47
|
+
await (0, devkit_1.formatFiles)(tree);
|
|
48
|
+
return (0, devkit_1.runTasksInSerial)(...tasks);
|
|
49
|
+
}
|
|
50
|
+
exports.default = default_1;
|
|
51
|
+
function moveNxPluginToDevDeps(tree) {
|
|
52
|
+
(0, devkit_1.updateJson)(tree, 'package.json', (json) => {
|
|
53
|
+
const nxPluginEntry = json.dependencies['@nx/plugin'];
|
|
54
|
+
delete json.dependencies['@nx/plugin'];
|
|
55
|
+
json.devDependencies['@nx/plugin'] = nxPluginEntry;
|
|
56
|
+
return json;
|
|
57
|
+
});
|
|
58
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/schema",
|
|
3
|
+
"cli": "nx",
|
|
4
|
+
"$id": "NxPluginPreset",
|
|
5
|
+
"title": "Generator ran by create-nx-plugin",
|
|
6
|
+
"description": "Initializes a workspace with an nx-plugin inside of it. Use as: `create-nx-plugin` or `create-nx-workspace --preset @nx/nx-plugin`.",
|
|
7
|
+
"examples": [
|
|
8
|
+
{
|
|
9
|
+
"command": "npx create-nx-plugin",
|
|
10
|
+
"description": "Creates a new Nx workspace containing an Nx plugin."
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
"command": "npx create-nx-workspace --preset @nx/plugin",
|
|
14
|
+
"description": "Creates a new Nx workspace containing an Nx plugin."
|
|
15
|
+
}
|
|
16
|
+
],
|
|
17
|
+
"type": "object",
|
|
18
|
+
"properties": {
|
|
19
|
+
"pluginName": {
|
|
20
|
+
"type": "string",
|
|
21
|
+
"description": "Plugin name",
|
|
22
|
+
"aliases": ["name"]
|
|
23
|
+
},
|
|
24
|
+
"createPackageName": {
|
|
25
|
+
"type": "string",
|
|
26
|
+
"description": "Name of package which creates a workspace"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"required": ["pluginName"]
|
|
30
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const devkit_1 = require("@nx/devkit");
|
|
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)) {
|
|
18
|
+
continue;
|
|
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) {
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
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';
|
|
42
|
+
}
|
|
43
|
+
return { ...newProperties, ...json };
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
await (0, devkit_1.formatFiles)(tree);
|
|
52
|
+
}
|
|
53
|
+
exports.default = update;
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.updateConfigsJest29 = void 0;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const tsquery_1 = require("@phenomnomnominal/tsquery");
|
|
6
|
+
const ts = require("typescript");
|
|
7
|
+
const executor_options_utils_1 = require("@nx/devkit/src/generators/executor-options-utils");
|
|
8
|
+
const ast_utils_1 = require("@nx/jest/src/utils/ast-utils");
|
|
9
|
+
const find_root_jest_files_1 = require("@nx/jest/src/utils/config/find-root-jest-files");
|
|
10
|
+
// NOTE: this is a copy of the @nrwl/jest v15.8.0 migrations
|
|
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"`);
|
|
23
|
+
}
|
|
24
|
+
updateTsJestOptions(tree, options.jestConfig);
|
|
25
|
+
updateNgJestOptions(tree, options.jestConfig);
|
|
26
|
+
}
|
|
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.
|
|
36
|
+
By default Nx kept the older style to prevent breaking of existing tests with snapshots.
|
|
37
|
+
It's recommend you update to the latest format.
|
|
38
|
+
You can do this in your project's jest config file.
|
|
39
|
+
Remove the snapshotFormat property and re-run tests with the --update-snapshot flag.
|
|
40
|
+
More info: https://jestjs.io/docs/upgrading-to-jest29#snapshot-format`);
|
|
41
|
+
}
|
|
42
|
+
exports.updateConfigsJest29 = updateConfigsJest29;
|
|
43
|
+
function addSnapshotOptionsToConfig(tree, configPath, updateSnapshotExample) {
|
|
44
|
+
const config = tree.read(configPath, 'utf-8');
|
|
45
|
+
const hasSnapshotOptions = tsquery_1.tsquery.query(config, `${ast_utils_1.TS_QUERY_JEST_CONFIG_PREFIX} > ObjectLiteralExpression PropertyAssignment:has(Identifier[name="snapshotFormat"])`);
|
|
46
|
+
if (hasSnapshotOptions.length > 0) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const updatedConfig = tsquery_1.tsquery.replace(config, `${ast_utils_1.TS_QUERY_JEST_CONFIG_PREFIX} > ObjectLiteralExpression`, (node) => {
|
|
50
|
+
return `{
|
|
51
|
+
${node.properties.map((p) => getNodeWithComments(config, p)).join(',\n')},
|
|
52
|
+
/* TODO: Update to latest Jest snapshotFormat
|
|
53
|
+
* By default Nx has kept the older style of Jest Snapshot formats
|
|
54
|
+
* to prevent breaking of any existing tests with snapshots.
|
|
55
|
+
* It's recommend you update to the latest format.
|
|
56
|
+
* You can do this by removing snapshotFormat property
|
|
57
|
+
* and running tests with --update-snapshot flag.
|
|
58
|
+
* Example: ${updateSnapshotExample}
|
|
59
|
+
* More info: https://jestjs.io/docs/upgrading-to-jest29#snapshot-format
|
|
60
|
+
*/
|
|
61
|
+
snapshotFormat: { escapeString: true, printBasicPrototype: true }
|
|
62
|
+
}`;
|
|
63
|
+
}, { visitAllChildren: false });
|
|
64
|
+
tree.write(configPath, updatedConfig);
|
|
65
|
+
}
|
|
66
|
+
function hasPresetConfigured(tree, configPath) {
|
|
67
|
+
const contents = tree.read(configPath, 'utf-8');
|
|
68
|
+
return (tsquery_1.tsquery.query(contents, `${ast_utils_1.TS_QUERY_JEST_CONFIG_PREFIX} > ObjectLiteralExpression PropertyAssignment:has(Identifier[name="preset"])`)?.length > 0);
|
|
69
|
+
}
|
|
70
|
+
function updateTsJestOptions(tree, configPath) {
|
|
71
|
+
// query for the globals property, if they don't have one then there's nothing to modify.
|
|
72
|
+
const contents = tree.read(configPath, 'utf-8');
|
|
73
|
+
let tsJestGlobalsConfig;
|
|
74
|
+
const noTsJestGlobals = tsquery_1.tsquery.replace(contents, `${ast_utils_1.TS_QUERY_JEST_CONFIG_PREFIX} > ObjectLiteralExpression PropertyAssignment:has(Identifier[name="globals"])`, (node) => {
|
|
75
|
+
if (tsJestGlobalsConfig) {
|
|
76
|
+
devkit_1.logger.warn((0, devkit_1.stripIndents) `Found more than one "globals" object in the jest config, ${configPath}
|
|
77
|
+
Will use the first one`);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
tsJestGlobalsConfig = getGlobalTsJestConfig(node);
|
|
81
|
+
return getGlobalConfigWithoutTsJest(node);
|
|
82
|
+
});
|
|
83
|
+
if (!tsJestGlobalsConfig) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
const updatedTsJestTransformer = tsquery_1.tsquery.replace(noTsJestGlobals, `${ast_utils_1.TS_QUERY_JEST_CONFIG_PREFIX}> ObjectLiteralExpression PropertyAssignment:has(Identifier[name="transform"]) PropertyAssignment > :has(StringLiteral[value="ts-jest"], StringLiteral[value="jest-preset-angular"])`, (node) => {
|
|
87
|
+
return `[${node.getText()}, ${tsJestGlobalsConfig}]`;
|
|
88
|
+
});
|
|
89
|
+
tree.write(configPath, updatedTsJestTransformer);
|
|
90
|
+
}
|
|
91
|
+
function updateNgJestOptions(tree, configPath) {
|
|
92
|
+
const contents = tree.read(configPath, 'utf-8');
|
|
93
|
+
let ngJestTeardownConfig;
|
|
94
|
+
const noTeardownConfig = tsquery_1.tsquery.replace(contents, 'BinaryExpression:has(PropertyAccessExpression:has(Identifier[name=ngJest])) PropertyAssignment:has(Identifier[name=teardown])', (node) => {
|
|
95
|
+
ngJestTeardownConfig = node.initializer.getText();
|
|
96
|
+
return ' ';
|
|
97
|
+
});
|
|
98
|
+
if (!ngJestTeardownConfig) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
let maybeUpdatedTestEnvOpts = tsquery_1.tsquery.replace(noTeardownConfig, `${ast_utils_1.TS_QUERY_JEST_CONFIG_PREFIX} > ObjectLiteralExpression PropertyAssignment:has(Identifier[name="testEnvironmentOptions"]) ObjectLiteralExpression`, (node) => {
|
|
102
|
+
return `{
|
|
103
|
+
${node.properties
|
|
104
|
+
.map((p) => getNodeWithComments(noTeardownConfig, p))
|
|
105
|
+
.join(',\n')},
|
|
106
|
+
teardown: ${ngJestTeardownConfig}
|
|
107
|
+
}`;
|
|
108
|
+
});
|
|
109
|
+
if (maybeUpdatedTestEnvOpts !== noTeardownConfig) {
|
|
110
|
+
tree.write(configPath, maybeUpdatedTestEnvOpts);
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
// didn't find existing testEnvironmentOptions, so add the new property
|
|
114
|
+
const updatedConfig = tsquery_1.tsquery.replace(maybeUpdatedTestEnvOpts, `${ast_utils_1.TS_QUERY_JEST_CONFIG_PREFIX} > ObjectLiteralExpression`, (node) => {
|
|
115
|
+
return `{
|
|
116
|
+
${node.properties
|
|
117
|
+
.map((p) => getNodeWithComments(maybeUpdatedTestEnvOpts, p))
|
|
118
|
+
.join(',\n')},
|
|
119
|
+
testEnvironmentOptions: { teardown: ${ngJestTeardownConfig} },
|
|
120
|
+
}`;
|
|
121
|
+
}, { visitAllChildren: false });
|
|
122
|
+
tree.write(configPath, updatedConfig);
|
|
123
|
+
}
|
|
124
|
+
function getGlobalTsJestConfig(node) {
|
|
125
|
+
const globalObject = node.initializer;
|
|
126
|
+
const foundConfig = globalObject.properties.find((p) => ts.isPropertyAssignment(p) && p.name.getText().includes('ts-jest'));
|
|
127
|
+
return foundConfig?.initializer?.getText() || '';
|
|
128
|
+
}
|
|
129
|
+
function getGlobalConfigWithoutTsJest(node) {
|
|
130
|
+
const globalObject = node?.initializer;
|
|
131
|
+
const withoutTsJest = globalObject?.properties?.filter((p) => {
|
|
132
|
+
return !(ts.isPropertyAssignment(p) && p.name.getText().includes('ts-jest'));
|
|
133
|
+
});
|
|
134
|
+
const globalConfigs = withoutTsJest.map((c) => c.getText()).join(',\n');
|
|
135
|
+
return `globals: { ${globalConfigs} }`;
|
|
136
|
+
}
|
|
137
|
+
function getNodeWithComments(fullText, node) {
|
|
138
|
+
const commentRanges = ts.getLeadingCommentRanges(fullText, node.getFullStart());
|
|
139
|
+
if (commentRanges?.length > 0) {
|
|
140
|
+
const withComments = `${commentRanges
|
|
141
|
+
.map((r) => fullText.slice(r.pos, r.end))
|
|
142
|
+
.join('\n')}\n${node.getText()}`;
|
|
143
|
+
return withComments;
|
|
144
|
+
}
|
|
145
|
+
return node.getText();
|
|
146
|
+
}
|
|
147
|
+
exports.default = updateConfigsJest29;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Tree } from '@nx/devkit';
|
|
2
|
+
export declare function updateTestsJest29(tree: Tree): Promise<void>;
|
|
3
|
+
export declare function updateJestMockTypes(tree: Tree, filePath: string): void;
|
|
4
|
+
export declare function updateJestMocked(tree: Tree, filePath: string): void;
|
|
5
|
+
export default updateTestsJest29;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.updateJestMocked = exports.updateJestMockTypes = exports.updateTestsJest29 = void 0;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const ast_utils_1 = require("@nx/jest/src/utils/ast-utils");
|
|
6
|
+
const executor_options_utils_1 = require("@nx/devkit/src/generators/executor-options-utils");
|
|
7
|
+
const tsquery_1 = require("@phenomnomnominal/tsquery");
|
|
8
|
+
// NOTE: this is a copy of the @nrwl/jest v15.8.0 migrations
|
|
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);
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
await (0, devkit_1.formatFiles)(tree);
|
|
22
|
+
}
|
|
23
|
+
exports.updateTestsJest29 = updateTestsJest29;
|
|
24
|
+
function updateJestMockTypes(tree, filePath) {
|
|
25
|
+
const contents = tree.read(filePath, 'utf-8');
|
|
26
|
+
const updatedContent = tsquery_1.tsquery.replace(contents, ':matches(ImportDeclaration, VariableStatement):has(Identifier[name="MaybeMockedDeep"], Identifier[name="MaybeMocked"]):has(StringLiteral[value="jest-mock"])', (node) => {
|
|
27
|
+
const text = node.getText();
|
|
28
|
+
return (text
|
|
29
|
+
// MaybeMockedDeep and MaybeMocked now are exported as Mocked and MockedShallow
|
|
30
|
+
.replace('MaybeMockedDeep', 'Mocked')
|
|
31
|
+
.replace('MaybeMocked', 'MockedShallow'));
|
|
32
|
+
});
|
|
33
|
+
tree.write(filePath, updatedContent);
|
|
34
|
+
}
|
|
35
|
+
exports.updateJestMockTypes = updateJestMockTypes;
|
|
36
|
+
function updateJestMocked(tree, filePath) {
|
|
37
|
+
const contents = tree.read(filePath, 'utf-8');
|
|
38
|
+
const jestGlobalNodes = tsquery_1.tsquery.query(contents, ':matches(ImportDeclaration, VariableStatement):has(Identifier[name="jest"]):has(StringLiteral[value="@jest/globals"])');
|
|
39
|
+
// this only applies if using jest from @jest/globals
|
|
40
|
+
if (jestGlobalNodes.length === 0) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const updatedJestMockTypes = tsquery_1.tsquery.replace(contents, 'CallExpression:has(Identifier[name="jest"]):has(Identifier[name="mocked"])', (node) => {
|
|
44
|
+
if (node.arguments.length === 2 &&
|
|
45
|
+
node.getText().startsWith('jest.mocked(')) {
|
|
46
|
+
const text = node.getText();
|
|
47
|
+
// jest.mocked(someObject, true); => jest.mocked(someObject);
|
|
48
|
+
if (node.arguments[1].getText() === 'true') {
|
|
49
|
+
return text.replace(/,\s*true/g, '');
|
|
50
|
+
}
|
|
51
|
+
// jest.mocked(someObject, false); => jest.mocked(someObject, {shallow: true});
|
|
52
|
+
// opt into the new behavior unless explicitly opting out
|
|
53
|
+
if (node.arguments[1].getText() === 'false') {
|
|
54
|
+
return text.replace('false', '{shallow: true}');
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
tree.write(filePath, updatedJestMockTypes);
|
|
59
|
+
}
|
|
60
|
+
exports.updateJestMocked = updateJestMocked;
|
|
61
|
+
exports.default = updateTestsJest29;
|