@nx/js 16.8.0-beta.3 → 16.8.0-beta.4
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 +5 -5
- package/src/executors/node/schema.json +1 -1
- package/src/generators/library/library.d.ts +1 -1
- package/src/generators/library/library.js +46 -3
- package/src/generators/setup-build/generator.js +17 -6
- package/src/utils/find-npm-dependencies.d.ts +1 -0
- package/src/utils/find-npm-dependencies.js +19 -7
- package/src/utils/package-json/update-package-json.js +3 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/js",
|
|
3
|
-
"version": "16.8.0-beta.
|
|
3
|
+
"version": "16.8.0-beta.4",
|
|
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.22.9",
|
|
40
40
|
"@babel/preset-typescript": "^7.22.5",
|
|
41
41
|
"@babel/runtime": "^7.22.6",
|
|
42
|
-
"@nrwl/js": "16.8.0-beta.
|
|
43
|
-
"@nx/devkit": "16.8.0-beta.
|
|
44
|
-
"@nx/workspace": "16.8.0-beta.
|
|
42
|
+
"@nrwl/js": "16.8.0-beta.4",
|
|
43
|
+
"@nx/devkit": "16.8.0-beta.4",
|
|
44
|
+
"@nx/workspace": "16.8.0-beta.4",
|
|
45
45
|
"@phenomnomnominal/tsquery": "~5.0.1",
|
|
46
46
|
"babel-plugin-const-enum": "^1.0.1",
|
|
47
47
|
"babel-plugin-macros": "^2.8.0",
|
|
@@ -71,5 +71,5 @@
|
|
|
71
71
|
"access": "public"
|
|
72
72
|
},
|
|
73
73
|
"type": "commonjs",
|
|
74
|
-
"gitHead": "
|
|
74
|
+
"gitHead": "c9aad2dc8c2b34531cf61549bff872e68c481e4e"
|
|
75
75
|
}
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
},
|
|
19
19
|
"waitUntilTargets": {
|
|
20
20
|
"type": "array",
|
|
21
|
-
"description": "The targets to run before starting the node app.",
|
|
21
|
+
"description": "The targets to run before starting the node app. Listed in the form <project>:<target>. The main target will run once all listed targets have output something to the console.",
|
|
22
22
|
"default": [],
|
|
23
23
|
"items": {
|
|
24
24
|
"type": "string"
|
|
@@ -11,7 +11,7 @@ export interface NormalizedSchema extends LibraryGeneratorSchema {
|
|
|
11
11
|
parsedTags: string[];
|
|
12
12
|
importPath?: string;
|
|
13
13
|
}
|
|
14
|
-
export type AddLintOptions = Pick<NormalizedSchema, 'name' | 'linter' | 'projectRoot' | 'unitTestRunner' | 'js' | 'setParserOptionsProject' | 'rootProject'>;
|
|
14
|
+
export type AddLintOptions = Pick<NormalizedSchema, 'name' | 'linter' | 'projectRoot' | 'unitTestRunner' | 'js' | 'setParserOptionsProject' | 'rootProject' | 'bundler'>;
|
|
15
15
|
export declare function addLint(tree: Tree, options: AddLintOptions): Promise<GeneratorCallback>;
|
|
16
16
|
export default libraryGenerator;
|
|
17
17
|
export declare const librarySchematic: (generatorOptions: LibraryGeneratorSchema) => (tree: any, context: any) => Promise<any>;
|
|
@@ -150,6 +150,7 @@ function addProject(tree, options) {
|
|
|
150
150
|
function addLint(tree, options) {
|
|
151
151
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
152
152
|
const { lintProjectGenerator } = (0, devkit_1.ensurePackage)('@nx/linter', versions_1.nxVersion);
|
|
153
|
+
const projectConfiguration = (0, devkit_1.readProjectConfiguration)(tree, options.name);
|
|
153
154
|
const task = lintProjectGenerator(tree, {
|
|
154
155
|
project: options.name,
|
|
155
156
|
linter: options.linter,
|
|
@@ -164,12 +165,12 @@ function addLint(tree, options) {
|
|
|
164
165
|
setParserOptionsProject: options.setParserOptionsProject,
|
|
165
166
|
rootProject: options.rootProject,
|
|
166
167
|
});
|
|
168
|
+
const { addOverrideToLintConfig, lintConfigHasOverride, isEslintConfigSupported, updateOverrideInLintConfig,
|
|
169
|
+
// nx-ignore-next-line
|
|
170
|
+
} = require('@nx/linter/src/generators/utils/eslint-file');
|
|
167
171
|
// Also update the root ESLint config. The lintProjectGenerator will not generate it for root projects.
|
|
168
172
|
// But we need to set the package.json checks.
|
|
169
173
|
if (options.rootProject) {
|
|
170
|
-
const { addOverrideToLintConfig, isEslintConfigSupported,
|
|
171
|
-
// nx-ignore-next-line
|
|
172
|
-
} = require('@nx/linter/src/generators/utils/eslint-file');
|
|
173
174
|
if (isEslintConfigSupported(tree)) {
|
|
174
175
|
addOverrideToLintConfig(tree, '', {
|
|
175
176
|
files: ['*.json'],
|
|
@@ -180,6 +181,48 @@ function addLint(tree, options) {
|
|
|
180
181
|
});
|
|
181
182
|
}
|
|
182
183
|
}
|
|
184
|
+
// If project lints package.json with @nx/dependency-checks, then add ignore files for
|
|
185
|
+
// build configuration files such as vite.config.ts. These config files need to be
|
|
186
|
+
// ignored, otherwise we will errors on missing dependencies that are for dev only.
|
|
187
|
+
if (lintConfigHasOverride(tree, projectConfiguration.root, (o) => {
|
|
188
|
+
var _a;
|
|
189
|
+
return Array.isArray(o.files)
|
|
190
|
+
? o.files.some((f) => f.match(/\.json$/))
|
|
191
|
+
: !!((_a = o.files) === null || _a === void 0 ? void 0 : _a.match(/\.json$/));
|
|
192
|
+
}, true)) {
|
|
193
|
+
updateOverrideInLintConfig(tree, projectConfiguration.root, (o) => { var _a; return (_a = o.rules) === null || _a === void 0 ? void 0 : _a['@nx/dependency-checks']; }, (o) => {
|
|
194
|
+
const value = o.rules['@nx/dependency-checks'];
|
|
195
|
+
let ruleSeverity;
|
|
196
|
+
let ruleOptions;
|
|
197
|
+
if (Array.isArray(value)) {
|
|
198
|
+
ruleSeverity = value[0];
|
|
199
|
+
ruleOptions = value[1];
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
202
|
+
ruleSeverity = value;
|
|
203
|
+
ruleOptions = {};
|
|
204
|
+
}
|
|
205
|
+
if (options.bundler === 'vite' || options.unitTestRunner === 'vitest') {
|
|
206
|
+
ruleOptions.ignoredFiles = [
|
|
207
|
+
'{projectRoot}/vite.config.{js,ts,mjs,mts}',
|
|
208
|
+
];
|
|
209
|
+
o.rules['@nx/dependency-checks'] = [ruleSeverity, ruleOptions];
|
|
210
|
+
}
|
|
211
|
+
else if (options.bundler === 'rollup') {
|
|
212
|
+
ruleOptions.ignoredFiles = [
|
|
213
|
+
'{projectRoot}/rollup.config.{js,ts,mjs,mts}',
|
|
214
|
+
];
|
|
215
|
+
o.rules['@nx/dependency-checks'] = [ruleSeverity, ruleOptions];
|
|
216
|
+
}
|
|
217
|
+
else if (options.bundler === 'esbuild') {
|
|
218
|
+
ruleOptions.ignoredFiles = [
|
|
219
|
+
'{projectRoot}/esbuild.config.{js,ts,mjs,mts}',
|
|
220
|
+
];
|
|
221
|
+
o.rules['@nx/dependency-checks'] = [ruleSeverity, ruleOptions];
|
|
222
|
+
}
|
|
223
|
+
return o;
|
|
224
|
+
});
|
|
225
|
+
}
|
|
183
226
|
return task;
|
|
184
227
|
});
|
|
185
228
|
}
|
|
@@ -7,18 +7,22 @@ const add_swc_config_1 = require("../../utils/swc/add-swc-config");
|
|
|
7
7
|
const add_swc_dependencies_1 = require("../../utils/swc/add-swc-dependencies");
|
|
8
8
|
const versions_1 = require("../../utils/versions");
|
|
9
9
|
function setupBuildGenerator(tree, options) {
|
|
10
|
-
var _a, _b, _c;
|
|
10
|
+
var _a, _b, _c, _d, _e;
|
|
11
11
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
12
12
|
const tasks = [];
|
|
13
13
|
const project = (0, devkit_1.readProjectConfiguration)(tree, options.project);
|
|
14
14
|
const buildTarget = (_a = options.buildTarget) !== null && _a !== void 0 ? _a : 'build';
|
|
15
|
-
(_b = project.targets)
|
|
15
|
+
const prevBuildOptions = (_c = (_b = project.targets) === null || _b === void 0 ? void 0 : _b[buildTarget]) === null || _c === void 0 ? void 0 : _c.options;
|
|
16
|
+
(_d = project.targets) !== null && _d !== void 0 ? _d : (project.targets = {});
|
|
16
17
|
let mainFile;
|
|
17
|
-
if (
|
|
18
|
+
if (prevBuildOptions === null || prevBuildOptions === void 0 ? void 0 : prevBuildOptions.main) {
|
|
19
|
+
mainFile = prevBuildOptions.main;
|
|
20
|
+
}
|
|
21
|
+
else if (options.main) {
|
|
18
22
|
mainFile = options.main;
|
|
19
23
|
}
|
|
20
24
|
else {
|
|
21
|
-
const root = (
|
|
25
|
+
const root = (_e = project.sourceRoot) !== null && _e !== void 0 ? _e : project.root;
|
|
22
26
|
for (const f of [
|
|
23
27
|
(0, devkit_1.joinPathFragments)(root, 'main.ts'),
|
|
24
28
|
(0, devkit_1.joinPathFragments)(root, 'main.js'),
|
|
@@ -35,7 +39,10 @@ function setupBuildGenerator(tree, options) {
|
|
|
35
39
|
throw new Error(`Cannot locate a main file for ${options.project}. Please specify one using --main=<file-path>.`);
|
|
36
40
|
}
|
|
37
41
|
let tsConfigFile;
|
|
38
|
-
if (
|
|
42
|
+
if (prevBuildOptions === null || prevBuildOptions === void 0 ? void 0 : prevBuildOptions.tsConfig) {
|
|
43
|
+
tsConfigFile = prevBuildOptions.tsConfig;
|
|
44
|
+
}
|
|
45
|
+
else if (options.tsConfig) {
|
|
39
46
|
tsConfigFile = options.tsConfig;
|
|
40
47
|
}
|
|
41
48
|
else {
|
|
@@ -76,6 +83,7 @@ function setupBuildGenerator(tree, options) {
|
|
|
76
83
|
buildTarget: options.buildTarget,
|
|
77
84
|
project: options.project,
|
|
78
85
|
skipFormat: true,
|
|
86
|
+
skipValidation: true,
|
|
79
87
|
});
|
|
80
88
|
tasks.push(task);
|
|
81
89
|
break;
|
|
@@ -85,9 +93,12 @@ function setupBuildGenerator(tree, options) {
|
|
|
85
93
|
const task = yield configurationGenerator(tree, {
|
|
86
94
|
buildTarget: options.buildTarget,
|
|
87
95
|
main: mainFile,
|
|
96
|
+
tsConfig: tsConfigFile,
|
|
88
97
|
project: options.project,
|
|
89
|
-
skipFormat: true,
|
|
90
98
|
compiler: 'tsc',
|
|
99
|
+
format: ['cjs', 'esm'],
|
|
100
|
+
skipFormat: true,
|
|
101
|
+
skipValidation: true,
|
|
91
102
|
});
|
|
92
103
|
tasks.push(task);
|
|
93
104
|
break;
|
|
@@ -4,4 +4,5 @@ import { type ProjectGraph, type ProjectGraphProjectNode, type ProjectFileMap }
|
|
|
4
4
|
*/
|
|
5
5
|
export declare function findNpmDependencies(workspaceRoot: string, sourceProject: ProjectGraphProjectNode, projectGraph: ProjectGraph, projectFileMap: ProjectFileMap, buildTarget: string, options?: {
|
|
6
6
|
includeTransitiveDependencies?: boolean;
|
|
7
|
+
ignoredFiles?: string[];
|
|
7
8
|
}): Record<string, string>;
|
|
@@ -20,7 +20,8 @@ function findNpmDependencies(workspaceRoot, sourceProject, projectGraph, project
|
|
|
20
20
|
function collectAll(currentProject, collectedDeps) {
|
|
21
21
|
if (seen === null || seen === void 0 ? void 0 : seen.has(currentProject.name))
|
|
22
22
|
return;
|
|
23
|
-
|
|
23
|
+
seen === null || seen === void 0 ? void 0 : seen.add(currentProject.name);
|
|
24
|
+
collectDependenciesFromFileMap(workspaceRoot, currentProject, projectGraph, projectFileMap, buildTarget, options.ignoredFiles, collectedDeps);
|
|
24
25
|
collectHelperDependencies(workspaceRoot, currentProject, projectGraph, buildTarget, collectedDeps);
|
|
25
26
|
if (options.includeTransitiveDependencies) {
|
|
26
27
|
const projectDeps = projectGraph.dependencies[currentProject.name];
|
|
@@ -37,14 +38,20 @@ function findNpmDependencies(workspaceRoot, sourceProject, projectGraph, project
|
|
|
37
38
|
exports.findNpmDependencies = findNpmDependencies;
|
|
38
39
|
// Keep track of workspace libs we already read package.json for so we don't read from disk again.
|
|
39
40
|
const seenWorkspaceDeps = {};
|
|
40
|
-
function collectDependenciesFromFileMap(workspaceRoot, sourceProject, projectGraph, projectFileMap, buildTarget, npmDeps) {
|
|
41
|
+
function collectDependenciesFromFileMap(workspaceRoot, sourceProject, projectGraph, projectFileMap, buildTarget, ignoredFiles, npmDeps) {
|
|
41
42
|
const rawFiles = projectFileMap[sourceProject.name];
|
|
42
43
|
if (!rawFiles)
|
|
43
44
|
return;
|
|
44
|
-
//
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
45
|
+
// If build target does not exist in project, use all files as input.
|
|
46
|
+
// This is needed for transitive dependencies for apps -- where libs may not be buildable.
|
|
47
|
+
const inputs = sourceProject.data.targets[buildTarget]
|
|
48
|
+
? (0, task_hasher_1.getTargetInputs)((0, configuration_1.readNxJson)(), sourceProject, buildTarget).selfInputs
|
|
49
|
+
: ['{projectRoot}/**/*'];
|
|
50
|
+
if (ignoredFiles) {
|
|
51
|
+
for (const pattern of ignoredFiles) {
|
|
52
|
+
inputs.push(`!${pattern}`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
48
55
|
const files = (0, task_hasher_1.filterUsingGlobPatterns)(sourceProject.data.root, projectFileMap[sourceProject.name] || [], inputs);
|
|
49
56
|
for (const fileData of files) {
|
|
50
57
|
if (!fileData.deps ||
|
|
@@ -70,7 +77,12 @@ function collectDependenciesFromFileMap(workspaceRoot, sourceProject, projectGra
|
|
|
70
77
|
}
|
|
71
78
|
else {
|
|
72
79
|
const packageJson = readPackageJson(workspaceDep, workspaceRoot);
|
|
73
|
-
if (
|
|
80
|
+
if (
|
|
81
|
+
// Check that this is a buildable project, otherwise it cannot be a dependency in package.json.
|
|
82
|
+
workspaceDep.data.targets[buildTarget] &&
|
|
83
|
+
(
|
|
84
|
+
// Make sure package.json exists and has a valid name.
|
|
85
|
+
packageJson === null || packageJson === void 0 ? void 0 : packageJson.name)) {
|
|
74
86
|
// This is a workspace lib so we can't reliably read in a specific version since it depends on how the workspace is set up.
|
|
75
87
|
// ASSUMPTION: Most users will use '*' for workspace lib versions. Otherwise, they can manually update it.
|
|
76
88
|
npmDeps[packageJson.name] = '*';
|
|
@@ -42,8 +42,9 @@ function updatePackageJson(options, context, target, dependencies, fileMap = nul
|
|
|
42
42
|
// save files
|
|
43
43
|
(0, devkit_1.writeJsonFile)(`${options.outputPath}/package.json`, packageJson);
|
|
44
44
|
if (options.generateLockfile) {
|
|
45
|
-
const
|
|
46
|
-
(0,
|
|
45
|
+
const packageManager = (0, devkit_1.detectPackageManager)(context.root);
|
|
46
|
+
const lockFile = (0, lock_file_1.createLockFile)(packageJson, context.projectGraph, packageManager);
|
|
47
|
+
(0, fs_extra_1.writeFileSync)(`${options.outputPath}/${(0, lock_file_1.getLockFileName)(packageManager)}`, lockFile, {
|
|
47
48
|
encoding: 'utf-8',
|
|
48
49
|
});
|
|
49
50
|
}
|