@nx/js 16.4.0-beta.5 → 16.4.0-beta.7
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/generators.json +12 -0
- package/package.json +5 -5
- package/src/executors/node/node.impl.js +26 -1
- package/src/generators/library/library.js +2 -0
- package/src/generators/library/schema.json +2 -2
- package/src/generators/setup-build/generator.d.ts +5 -0
- package/src/generators/setup-build/generator.js +133 -0
- package/src/generators/setup-build/schema.d.ts +7 -0
- package/src/generators/setup-build/schema.json +42 -0
- package/src/utils/swc/add-swc-config.d.ts +1 -1
package/generators.json
CHANGED
|
@@ -29,6 +29,12 @@
|
|
|
29
29
|
"schema": "./src/generators/setup-verdaccio/schema.json",
|
|
30
30
|
"alias": ["verdaccio"],
|
|
31
31
|
"description": "Setup Verdaccio for local package management."
|
|
32
|
+
},
|
|
33
|
+
"setup-build": {
|
|
34
|
+
"factory": "./src/generators/setup-build/generator#setupBuildSchematic",
|
|
35
|
+
"schema": "./src/generators/setup-build/schema.json",
|
|
36
|
+
"alias": ["build"],
|
|
37
|
+
"description": "setup-build generator"
|
|
32
38
|
}
|
|
33
39
|
},
|
|
34
40
|
"generators": {
|
|
@@ -59,6 +65,12 @@
|
|
|
59
65
|
"schema": "./src/generators/setup-verdaccio/schema.json",
|
|
60
66
|
"alias": ["verdaccio"],
|
|
61
67
|
"description": "Setup Verdaccio for local package management."
|
|
68
|
+
},
|
|
69
|
+
"setup-build": {
|
|
70
|
+
"factory": "./src/generators/setup-build/generator",
|
|
71
|
+
"schema": "./src/generators/setup-build/schema.json",
|
|
72
|
+
"alias": ["build"],
|
|
73
|
+
"description": "setup-build generator"
|
|
62
74
|
}
|
|
63
75
|
}
|
|
64
76
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/js",
|
|
3
|
-
"version": "16.4.0-beta.
|
|
3
|
+
"version": "16.4.0-beta.7",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "The JS plugin for Nx contains executors and generators that provide the best experience for developing JavaScript and TypeScript projects. ",
|
|
6
6
|
"repository": {
|
|
@@ -39,9 +39,9 @@
|
|
|
39
39
|
"@babel/preset-env": "^7.15.0",
|
|
40
40
|
"@babel/preset-typescript": "^7.15.0",
|
|
41
41
|
"@babel/runtime": "^7.14.8",
|
|
42
|
-
"@nrwl/js": "16.4.0-beta.
|
|
43
|
-
"@nx/devkit": "16.4.0-beta.
|
|
44
|
-
"@nx/workspace": "16.4.0-beta.
|
|
42
|
+
"@nrwl/js": "16.4.0-beta.7",
|
|
43
|
+
"@nx/devkit": "16.4.0-beta.7",
|
|
44
|
+
"@nx/workspace": "16.4.0-beta.7",
|
|
45
45
|
"@phenomnomnominal/tsquery": "~5.0.1",
|
|
46
46
|
"babel-plugin-const-enum": "^1.0.1",
|
|
47
47
|
"babel-plugin-macros": "^2.8.0",
|
|
@@ -69,5 +69,5 @@
|
|
|
69
69
|
"access": "public"
|
|
70
70
|
},
|
|
71
71
|
"types": "./src/index.d.ts",
|
|
72
|
-
"gitHead": "
|
|
72
|
+
"gitHead": "847d3a45b61cd2c267acb66c4165a5bb875aff4f"
|
|
73
73
|
}
|
|
@@ -32,6 +32,14 @@ function nodeExecutor(options, context) {
|
|
|
32
32
|
else {
|
|
33
33
|
throw new Error(`Cannot find build target ${chalk.bold(options.buildTarget)} for project ${chalk.bold(context.projectName)}`);
|
|
34
34
|
}
|
|
35
|
+
if (options.waitUntilTargets && options.waitUntilTargets.length > 0) {
|
|
36
|
+
const results = yield tslib_1.__await(runWaitUntilTargets(options, context));
|
|
37
|
+
for (const [i, result] of results.entries()) {
|
|
38
|
+
if (!result.success) {
|
|
39
|
+
throw new Error(`Wait until target failed: ${options.waitUntilTargets[i]}.`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
35
43
|
// Re-map buildable workspace projects to their output directory.
|
|
36
44
|
const mappings = calculateResolveMappings(context, options);
|
|
37
45
|
const fileToRun = (0, path_1.join)(context.root, buildOptions.outputPath, (_d = buildOptions.outputFileName) !== null && _d !== void 0 ? _d : 'main.js');
|
|
@@ -174,7 +182,9 @@ function nodeExecutor(options, context) {
|
|
|
174
182
|
}
|
|
175
183
|
exports.nodeExecutor = nodeExecutor;
|
|
176
184
|
function getExecArgv(options) {
|
|
177
|
-
|
|
185
|
+
var _a;
|
|
186
|
+
const args = ((_a = options.runtimeArgs) !== null && _a !== void 0 ? _a : (options.runtimeArgs = []));
|
|
187
|
+
args.push('-r', require.resolve('source-map-support/register'));
|
|
178
188
|
if (options.inspect === true) {
|
|
179
189
|
options.inspect = "inspect" /* InspectType.Inspect */;
|
|
180
190
|
}
|
|
@@ -193,4 +203,19 @@ function calculateResolveMappings(context, options) {
|
|
|
193
203
|
return m;
|
|
194
204
|
}, {});
|
|
195
205
|
}
|
|
206
|
+
function runWaitUntilTargets(options, context) {
|
|
207
|
+
return Promise.all(options.waitUntilTargets.map((waitUntilTarget) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
208
|
+
const target = (0, devkit_1.parseTargetString)(waitUntilTarget, context.projectGraph);
|
|
209
|
+
const output = yield (0, devkit_1.runExecutor)(target, {}, context);
|
|
210
|
+
return new Promise((resolve) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
211
|
+
let event = yield output.next();
|
|
212
|
+
// Resolve after first event
|
|
213
|
+
resolve(event.value);
|
|
214
|
+
// Continue iterating
|
|
215
|
+
while (!event.done) {
|
|
216
|
+
event = yield output.next();
|
|
217
|
+
}
|
|
218
|
+
}));
|
|
219
|
+
})));
|
|
220
|
+
}
|
|
196
221
|
exports.default = nodeExecutor;
|
|
@@ -44,6 +44,7 @@ function projectGenerator(tree, schema, destinationDir, filesDir) {
|
|
|
44
44
|
includeVitest: options.unitTestRunner === 'vitest',
|
|
45
45
|
includeLib: true,
|
|
46
46
|
skipFormat: true,
|
|
47
|
+
testEnvironment: options.testEnvironment,
|
|
47
48
|
});
|
|
48
49
|
tasks.push(viteTask);
|
|
49
50
|
}
|
|
@@ -67,6 +68,7 @@ function projectGenerator(tree, schema, destinationDir, filesDir) {
|
|
|
67
68
|
uiFramework: 'none',
|
|
68
69
|
coverageProvider: 'c8',
|
|
69
70
|
skipFormat: true,
|
|
71
|
+
testEnvironment: options.testEnvironment,
|
|
70
72
|
});
|
|
71
73
|
tasks.push(vitestTask);
|
|
72
74
|
}
|
|
@@ -56,8 +56,8 @@
|
|
|
56
56
|
"testEnvironment": {
|
|
57
57
|
"type": "string",
|
|
58
58
|
"enum": ["jsdom", "node"],
|
|
59
|
-
"description": "The test environment to use if unitTestRunner is set to jest.",
|
|
60
|
-
"default": "
|
|
59
|
+
"description": "The test environment to use if unitTestRunner is set to jest or vitest.",
|
|
60
|
+
"default": "node"
|
|
61
61
|
},
|
|
62
62
|
"pascalCaseFiles": {
|
|
63
63
|
"type": "boolean",
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type GeneratorCallback, type Tree } from '@nx/devkit';
|
|
2
|
+
import { SetupBuildGeneratorSchema } from './schema';
|
|
3
|
+
export declare function setupBuildGenerator(tree: Tree, options: SetupBuildGeneratorSchema): Promise<GeneratorCallback>;
|
|
4
|
+
export default setupBuildGenerator;
|
|
5
|
+
export declare const setupBuildSchematic: (generatorOptions: SetupBuildGeneratorSchema) => (tree: any, context: any) => Promise<any>;
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setupBuildSchematic = exports.setupBuildGenerator = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const devkit_1 = require("@nx/devkit");
|
|
6
|
+
const add_swc_config_1 = require("../../utils/swc/add-swc-config");
|
|
7
|
+
const add_swc_dependencies_1 = require("../../utils/swc/add-swc-dependencies");
|
|
8
|
+
const versions_1 = require("../../utils/versions");
|
|
9
|
+
function setupBuildGenerator(tree, options) {
|
|
10
|
+
var _a, _b, _c;
|
|
11
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
12
|
+
const tasks = [];
|
|
13
|
+
const project = (0, devkit_1.readProjectConfiguration)(tree, options.project);
|
|
14
|
+
const buildTarget = (_a = options.buildTarget) !== null && _a !== void 0 ? _a : 'build';
|
|
15
|
+
(_b = project.targets) !== null && _b !== void 0 ? _b : (project.targets = {});
|
|
16
|
+
let mainFile;
|
|
17
|
+
if (options.main) {
|
|
18
|
+
mainFile = options.main;
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
const root = (_c = project.sourceRoot) !== null && _c !== void 0 ? _c : project.root;
|
|
22
|
+
for (const f of [
|
|
23
|
+
(0, devkit_1.joinPathFragments)(root, 'main.ts'),
|
|
24
|
+
(0, devkit_1.joinPathFragments)(root, 'main.js'),
|
|
25
|
+
(0, devkit_1.joinPathFragments)(root, 'index.ts'),
|
|
26
|
+
(0, devkit_1.joinPathFragments)(root, 'index.js'),
|
|
27
|
+
]) {
|
|
28
|
+
if (tree.exists(f)) {
|
|
29
|
+
mainFile = f;
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
if (!mainFile || !tree.exists(mainFile)) {
|
|
35
|
+
throw new Error(`Cannot locate a main file for ${options.project}. Please specify one using --main=<file-path>.`);
|
|
36
|
+
}
|
|
37
|
+
let tsConfigFile;
|
|
38
|
+
if (options.tsConfig) {
|
|
39
|
+
tsConfigFile = options.tsConfig;
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
for (const f of [
|
|
43
|
+
'tsconfig.lib.json',
|
|
44
|
+
'tsconfig.app.json',
|
|
45
|
+
'tsconfig.json',
|
|
46
|
+
]) {
|
|
47
|
+
const candidate = (0, devkit_1.joinPathFragments)(project.root, f);
|
|
48
|
+
if (tree.exists(candidate)) {
|
|
49
|
+
tsConfigFile = candidate;
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
if (!tsConfigFile || !tree.exists(tsConfigFile)) {
|
|
55
|
+
throw new Error(`Cannot locate a tsConfig file for ${options.project}. Please specify one using --tsConfig=<file-path>.`);
|
|
56
|
+
}
|
|
57
|
+
switch (options.bundler) {
|
|
58
|
+
case 'vite': {
|
|
59
|
+
const { viteConfigurationGenerator } = (0, devkit_1.ensurePackage)('@nx/vite', versions_1.nxVersion);
|
|
60
|
+
const task = yield viteConfigurationGenerator(tree, {
|
|
61
|
+
buildTarget: options.buildTarget,
|
|
62
|
+
project: options.project,
|
|
63
|
+
newProject: true,
|
|
64
|
+
uiFramework: 'none',
|
|
65
|
+
includeVitest: false,
|
|
66
|
+
includeLib: true,
|
|
67
|
+
skipFormat: true,
|
|
68
|
+
});
|
|
69
|
+
tasks.push(task);
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
case 'esbuild': {
|
|
73
|
+
const { esbuildProjectGenerator } = (0, devkit_1.ensurePackage)('@nx/esbuild', versions_1.nxVersion);
|
|
74
|
+
const task = yield esbuildProjectGenerator(tree, {
|
|
75
|
+
main: mainFile,
|
|
76
|
+
buildTarget: options.buildTarget,
|
|
77
|
+
project: options.project,
|
|
78
|
+
skipFormat: true,
|
|
79
|
+
});
|
|
80
|
+
tasks.push(task);
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
case 'rollup': {
|
|
84
|
+
const { rollupProjectGenerator } = (0, devkit_1.ensurePackage)('@nx/rollup', versions_1.nxVersion);
|
|
85
|
+
const task = yield rollupProjectGenerator(tree, {
|
|
86
|
+
buildTarget: options.buildTarget,
|
|
87
|
+
main: mainFile,
|
|
88
|
+
project: options.project,
|
|
89
|
+
skipFormat: true,
|
|
90
|
+
compiler: 'tsc',
|
|
91
|
+
});
|
|
92
|
+
tasks.push(task);
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
case 'tsc': {
|
|
96
|
+
const outputPath = (0, devkit_1.joinPathFragments)('dist', project.root);
|
|
97
|
+
project.targets[buildTarget] = {
|
|
98
|
+
executor: `@nx/js:tsc`,
|
|
99
|
+
outputs: ['{options.outputPath}'],
|
|
100
|
+
options: {
|
|
101
|
+
outputPath,
|
|
102
|
+
main: mainFile,
|
|
103
|
+
tsConfig: tsConfigFile,
|
|
104
|
+
assets: [],
|
|
105
|
+
},
|
|
106
|
+
};
|
|
107
|
+
(0, devkit_1.updateProjectConfiguration)(tree, options.project, project);
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
case 'swc': {
|
|
111
|
+
const outputPath = (0, devkit_1.joinPathFragments)('dist', project.root);
|
|
112
|
+
project.targets[buildTarget] = {
|
|
113
|
+
executor: `@nx/js:swc`,
|
|
114
|
+
outputs: ['{options.outputPath}'],
|
|
115
|
+
options: {
|
|
116
|
+
outputPath,
|
|
117
|
+
main: mainFile,
|
|
118
|
+
tsConfig: tsConfigFile,
|
|
119
|
+
assets: [],
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
(0, devkit_1.updateProjectConfiguration)(tree, options.project, project);
|
|
123
|
+
(0, add_swc_dependencies_1.addSwcDependencies)(tree);
|
|
124
|
+
(0, add_swc_config_1.addSwcConfig)(tree, project.root, 'es6');
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
yield (0, devkit_1.formatFiles)(tree);
|
|
128
|
+
return (0, devkit_1.runTasksInSerial)(...tasks);
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
exports.setupBuildGenerator = setupBuildGenerator;
|
|
132
|
+
exports.default = setupBuildGenerator;
|
|
133
|
+
exports.setupBuildSchematic = (0, devkit_1.convertNxGenerator)(setupBuildGenerator);
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/schema",
|
|
3
|
+
"$id": "SetupBuild",
|
|
4
|
+
"title": "Setup Build",
|
|
5
|
+
"description": "Sets up build target for a project.",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"properties": {
|
|
8
|
+
"project": {
|
|
9
|
+
"type": "string",
|
|
10
|
+
"description": "Project to add the build target to.",
|
|
11
|
+
"$default": {
|
|
12
|
+
"$source": "argv",
|
|
13
|
+
"index": 0
|
|
14
|
+
},
|
|
15
|
+
"x-prompt": "Which project do you want to add build to?",
|
|
16
|
+
"x-dropdown": "projects",
|
|
17
|
+
"x-priority": "important"
|
|
18
|
+
},
|
|
19
|
+
"bundler": {
|
|
20
|
+
"description": "The bundler to use to build the project.",
|
|
21
|
+
"type": "string",
|
|
22
|
+
"enum": ["tsc", "swc", "rollup", "vite", "esbuild"],
|
|
23
|
+
"default": "tsc",
|
|
24
|
+
"x-prompt": "Which bundler would you like to use to build the project?",
|
|
25
|
+
"x-priority": "important"
|
|
26
|
+
},
|
|
27
|
+
"main": {
|
|
28
|
+
"description": "The path to the main entry file, relative to workspace root. Defaults to <project>/src/index.ts or <project>/src/main.ts.",
|
|
29
|
+
"type": "string"
|
|
30
|
+
},
|
|
31
|
+
"tsConfig": {
|
|
32
|
+
"description": "The path to the tsConfig file, relative to workspace root. Defaults to <project>/tsconfig.lib.json or <project>/tsconfig.app.json depending on project type.",
|
|
33
|
+
"type": "string"
|
|
34
|
+
},
|
|
35
|
+
"buildTarget": {
|
|
36
|
+
"description": "The build target to add.",
|
|
37
|
+
"type": "string",
|
|
38
|
+
"default": "build"
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"required": ["project", "bundler"]
|
|
42
|
+
}
|