@nx/js 23.2.0-beta.1 → 23.2.0-beta.11
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/README.md +2 -2
- package/dist/internal.d.ts +9 -3
- package/dist/internal.js +28 -17
- package/dist/src/executors/copy-workspace-modules/copy-workspace-modules.js +122 -21
- package/dist/src/executors/node/lib/output-file.js +4 -4
- package/dist/src/executors/node/node.impl.js +9 -10
- package/dist/src/executors/prune-lockfile/prune-lockfile.d.ts +1 -1
- package/dist/src/executors/prune-lockfile/prune-lockfile.js +40 -33
- package/dist/src/executors/tsc/lib/batch/watch.js +3 -3
- package/dist/src/executors/tsc/lib/typescript-compilation.js +1 -1
- package/dist/src/executors/tsc/tsc.batch-impl.d.ts +1 -1
- package/dist/src/executors/tsc/tsc.batch-impl.js +2 -2
- package/dist/src/executors/verdaccio/verdaccio.impl.js +8 -1
- package/dist/src/generators/init/init.js +32 -15
- package/dist/src/generators/init/schema.d.ts +1 -1
- package/dist/src/generators/init/schema.json +1 -1
- package/dist/src/generators/library/library.d.ts +1 -1
- package/dist/src/generators/library/library.js +34 -20
- package/dist/src/generators/library/schema.d.ts +12 -5
- package/dist/src/generators/library/schema.json +15 -4
- package/dist/src/generators/library/utils/add-release-config.js +2 -2
- package/dist/src/generators/setup-build/generator.js +2 -7
- package/dist/src/generators/typescript-sync/typescript-sync.d.ts +1 -1
- package/dist/src/generators/typescript-sync/typescript-sync.js +2 -2
- package/dist/src/index.d.ts +3 -2
- package/dist/src/index.js +8 -8
- package/dist/src/migrations/update-23-1-0/add-ignore-deprecations-for-ts6.d.ts +3 -2
- package/dist/src/migrations/update-23-1-0/add-ignore-deprecations-for-ts6.js +17 -11
- package/dist/src/migrations/update-23-2-0/add-pnpm-deploy-output-cache-inputs.d.ts +14 -0
- package/dist/src/migrations/update-23-2-0/add-pnpm-deploy-output-cache-inputs.js +242 -0
- package/dist/src/migrations/update-23-2-0/add-pnpm-deploy-output-cache-inputs.md +64 -0
- package/dist/src/migrations/update-23-2-0/add-pnpm-prune-lockfile-cache-config.d.ts +2 -0
- package/dist/src/migrations/update-23-2-0/add-pnpm-prune-lockfile-cache-config.js +305 -0
- package/dist/src/migrations/update-23-2-0/add-pnpm-prune-lockfile-cache-config.md +59 -0
- package/dist/src/plugins/typescript/plugin.js +9 -14
- package/dist/src/plugins/typescript/util.d.ts +1 -1
- package/dist/src/release/utils/update-lock-file.js +47 -8
- package/dist/src/release/version-actions.d.ts +12 -3
- package/dist/src/release/version-actions.js +236 -76
- package/dist/src/utils/add-linting-to-project.d.ts +46 -0
- package/dist/src/utils/add-linting-to-project.js +112 -0
- package/dist/src/utils/assets/copy-assets-handler.d.ts +1 -1
- package/dist/src/utils/assets/copy-assets-handler.js +2 -2
- package/dist/src/utils/buildable-libs-utils.js +10 -13
- package/dist/src/utils/find-npm-dependencies.js +7 -10
- package/dist/src/utils/formatter-setup.d.ts +26 -0
- package/dist/src/utils/formatter-setup.js +43 -0
- package/dist/src/utils/generate-globs.js +11 -14
- package/dist/src/utils/generator-prompts.d.ts +2 -1
- package/dist/src/utils/generator-prompts.js +23 -22
- package/dist/src/utils/get-main-file-dir.js +2 -2
- package/dist/src/utils/linter.d.ts +30 -0
- package/dist/src/utils/linter.js +43 -0
- package/dist/src/utils/npm-config.d.ts +1 -1
- package/dist/src/utils/nx-formatter-internals.d.ts +8 -0
- package/dist/src/utils/nx-formatter-internals.js +18 -0
- package/dist/src/utils/oxfmt.d.ts +4 -0
- package/dist/src/utils/oxfmt.js +35 -0
- package/dist/src/utils/package-json/update-package-json.d.ts +1 -1
- package/dist/src/utils/package-json/update-package-json.js +11 -22
- package/dist/src/utils/package-manager-workspaces.js +2 -2
- package/dist/src/utils/pnpm-deploy-output-cache-inputs.d.ts +29 -0
- package/dist/src/utils/pnpm-deploy-output-cache-inputs.js +177 -0
- package/dist/src/utils/pnpm-install-settings-inputs.d.ts +45 -0
- package/dist/src/utils/pnpm-install-settings-inputs.js +77 -0
- package/dist/src/utils/prettier.js +14 -33
- package/dist/src/utils/schema.d.ts +1 -2
- package/dist/src/utils/target-defaults-matching.d.ts +57 -0
- package/dist/src/utils/target-defaults-matching.js +126 -0
- package/dist/src/utils/typescript/configuration.js +3 -5
- package/dist/src/utils/typescript/create-ts-config.d.ts +1 -1
- package/dist/src/utils/typescript/create-ts-config.js +5 -5
- package/dist/src/utils/typescript/plugin.js +2 -2
- package/dist/src/utils/typescript/run-type-check.js +2 -2
- package/dist/src/utils/typescript/ts-config.d.ts +51 -1
- package/dist/src/utils/typescript/ts-config.js +114 -0
- package/dist/src/utils/typescript/ts-solution-setup.d.ts +1 -1
- package/dist/src/utils/typescript/ts-solution-setup.js +3 -3
- package/dist/src/utils/versions.d.ts +1 -0
- package/dist/src/utils/versions.js +2 -1
- package/dist/src/utils/watch-for-single-file-changes.js +2 -2
- package/dist/src/utils/workspace-module-sections.d.ts +16 -0
- package/dist/src/utils/workspace-module-sections.js +24 -0
- package/migrations.json +13 -1
- package/package.json +12 -5
|
@@ -9,14 +9,11 @@ exports.updatePaths = updatePaths;
|
|
|
9
9
|
exports.updateBuildableProjectPackageJsonDependencies = updateBuildableProjectPackageJsonDependencies;
|
|
10
10
|
const devkit_1 = require("@nx/devkit");
|
|
11
11
|
const fs_1 = require("fs");
|
|
12
|
-
const operators_1 = require("nx/src/project-graph/operators");
|
|
13
|
-
const fileutils_1 = require("nx/src/utils/fileutils");
|
|
14
|
-
const output_1 = require("nx/src/utils/output");
|
|
15
12
|
const path_1 = require("path");
|
|
16
13
|
const ts_config_1 = require("./typescript/ts-config");
|
|
17
14
|
const strip_glob_to_base_dir_1 = require("./strip-glob-to-base-dir");
|
|
18
15
|
const crypto_1 = require("crypto");
|
|
19
|
-
const
|
|
16
|
+
const internal_1 = require("@nx/devkit/internal");
|
|
20
17
|
function isBuildable(target, node) {
|
|
21
18
|
return (node.data.targets &&
|
|
22
19
|
node.data.targets[target] &&
|
|
@@ -49,11 +46,11 @@ function calculateProjectDependencies(projGraph, root, projectName, targetName,
|
|
|
49
46
|
.map(({ name: dep, isTopLevel }) => {
|
|
50
47
|
let project = null;
|
|
51
48
|
const depNode = projGraph.nodes[dep] || projGraph.externalNodes[dep];
|
|
52
|
-
if ((0,
|
|
49
|
+
if ((0, internal_1.isProjectGraphProjectNode)(depNode) && depNode.type === 'lib') {
|
|
53
50
|
if (isBuildable(targetName, depNode)) {
|
|
54
51
|
const libPackageJsonPath = (0, path_1.join)(root, depNode.data.root, 'package.json');
|
|
55
52
|
project = {
|
|
56
|
-
name: (0,
|
|
53
|
+
name: (0, internal_1.fileExists)(libPackageJsonPath)
|
|
57
54
|
? (0, devkit_1.readJsonFile)(libPackageJsonPath).name // i.e. @workspace/mylib
|
|
58
55
|
: dep,
|
|
59
56
|
outputs: (0, devkit_1.getOutputsForTargetAndConfiguration)({
|
|
@@ -68,7 +65,7 @@ function calculateProjectDependencies(projGraph, root, projectName, targetName,
|
|
|
68
65
|
nonBuildableDependencies.push(dep);
|
|
69
66
|
}
|
|
70
67
|
}
|
|
71
|
-
else if ((0,
|
|
68
|
+
else if ((0, internal_1.isProjectGraphExternalNode)(depNode)) {
|
|
72
69
|
project = {
|
|
73
70
|
name: depNode.data.packageName,
|
|
74
71
|
outputs: [],
|
|
@@ -130,7 +127,7 @@ function readTsConfigWithRemappedPaths(originalTsconfigPath, generatedTsconfigPa
|
|
|
130
127
|
}
|
|
131
128
|
generatedTsConfig.compilerOptions.paths = paths;
|
|
132
129
|
if (process.env.NX_VERBOSE_LOGGING_PATH_MAPPINGS === 'true') {
|
|
133
|
-
|
|
130
|
+
devkit_1.output.log({
|
|
134
131
|
title: 'TypeScript path mappings have been rewritten.',
|
|
135
132
|
});
|
|
136
133
|
console.log(JSON.stringify(generatedTsConfig.compilerOptions.paths, null, 2));
|
|
@@ -158,7 +155,7 @@ function calculateDependenciesFromTaskGraph(taskGraph, projectGraph, root, proje
|
|
|
158
155
|
}
|
|
159
156
|
const libPackageJsonPath = (0, path_1.join)(root, depProjectNode.data.root, 'package.json');
|
|
160
157
|
project = {
|
|
161
|
-
name: (0,
|
|
158
|
+
name: (0, internal_1.fileExists)(libPackageJsonPath)
|
|
162
159
|
? (0, devkit_1.readJsonFile)(libPackageJsonPath).name // i.e. @workspace/mylib
|
|
163
160
|
: depTask.target.project,
|
|
164
161
|
outputs,
|
|
@@ -264,7 +261,7 @@ function updatePaths(dependencies, paths) {
|
|
|
264
261
|
const pathsKeys = Object.keys(paths);
|
|
265
262
|
// For each registered dependency
|
|
266
263
|
dependencies
|
|
267
|
-
.filter((dep) => (0,
|
|
264
|
+
.filter((dep) => (0, internal_1.isProjectGraphProjectNode)(dep.node))
|
|
268
265
|
.forEach((dep) => {
|
|
269
266
|
// If there are outputs
|
|
270
267
|
if (dep.outputs && dep.outputs.length > 0) {
|
|
@@ -335,7 +332,7 @@ function updateBuildableProjectPackageJsonDependencies(root, projectName, target
|
|
|
335
332
|
packageJson.peerDependencies = packageJson.peerDependencies || {};
|
|
336
333
|
let updatePackageJson = false;
|
|
337
334
|
dependencies.forEach((entry) => {
|
|
338
|
-
const packageName = (0,
|
|
335
|
+
const packageName = (0, internal_1.isNpmProject)(entry.node)
|
|
339
336
|
? entry.node.data.packageName
|
|
340
337
|
: entry.name;
|
|
341
338
|
if (!hasDependency(packageJson, 'dependencies', packageName) &&
|
|
@@ -343,7 +340,7 @@ function updateBuildableProjectPackageJsonDependencies(root, projectName, target
|
|
|
343
340
|
!hasDependency(packageJson, 'peerDependencies', packageName)) {
|
|
344
341
|
try {
|
|
345
342
|
let depVersion;
|
|
346
|
-
if ((0,
|
|
343
|
+
if ((0, internal_1.isProjectGraphProjectNode)(entry.node) &&
|
|
347
344
|
entry.node.type === 'lib') {
|
|
348
345
|
const outputs = (0, devkit_1.getOutputsForTargetAndConfiguration)({
|
|
349
346
|
project: projectName,
|
|
@@ -354,7 +351,7 @@ function updateBuildableProjectPackageJsonDependencies(root, projectName, target
|
|
|
354
351
|
depVersion = (0, devkit_1.readJsonFile)(depPackageJsonPath).version;
|
|
355
352
|
packageJson[typeOfDependency][packageName] = depVersion;
|
|
356
353
|
}
|
|
357
|
-
else if ((0,
|
|
354
|
+
else if ((0, internal_1.isNpmProject)(entry.node)) {
|
|
358
355
|
// If an npm dep is part of the workspace devDependencies, do not include it the library
|
|
359
356
|
if (!!workspacePackageJson.devDependencies?.[entry.node.data.packageName]) {
|
|
360
357
|
return;
|
|
@@ -2,12 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.findNpmDependencies = findNpmDependencies;
|
|
4
4
|
const path_1 = require("path");
|
|
5
|
-
const configuration_1 = require("nx/src/config/configuration");
|
|
6
5
|
const devkit_1 = require("@nx/devkit");
|
|
7
|
-
const fileutils_1 = require("nx/src/utils/fileutils");
|
|
8
|
-
const project_graph_1 = require("nx/src/config/project-graph");
|
|
9
6
|
const ts_config_1 = require("./typescript/ts-config");
|
|
10
|
-
const
|
|
7
|
+
const internal_1 = require("@nx/devkit/internal");
|
|
11
8
|
/**
|
|
12
9
|
* Finds all npm dependencies and their expected versions for a given project.
|
|
13
10
|
*/
|
|
@@ -44,14 +41,14 @@ function collectDependenciesFromFileMap(workspaceRoot, sourceProject, projectGra
|
|
|
44
41
|
// If build target does not exist in project, use all files as input.
|
|
45
42
|
// This is needed for transitive dependencies for apps -- where libs may not be buildable.
|
|
46
43
|
const inputs = sourceProject.data.targets[buildTarget]
|
|
47
|
-
? (0,
|
|
44
|
+
? (0, internal_1.getTargetInputs)((0, internal_1.readNxJsonFromDisk)(), sourceProject, buildTarget).selfInputs
|
|
48
45
|
: ['{projectRoot}/**/*'];
|
|
49
46
|
if (ignoredFiles) {
|
|
50
47
|
for (const pattern of ignoredFiles) {
|
|
51
48
|
inputs.push(`!${pattern}`);
|
|
52
49
|
}
|
|
53
50
|
}
|
|
54
|
-
const files = (0,
|
|
51
|
+
const files = (0, internal_1.filterUsingGlobPatterns)(sourceProject.data.root, projectFileMap[sourceProject.name] || [], inputs);
|
|
55
52
|
for (const fileData of files) {
|
|
56
53
|
if (!fileData.deps ||
|
|
57
54
|
fileData.file ===
|
|
@@ -59,7 +56,7 @@ function collectDependenciesFromFileMap(workspaceRoot, sourceProject, projectGra
|
|
|
59
56
|
continue;
|
|
60
57
|
}
|
|
61
58
|
for (const dep of fileData.deps) {
|
|
62
|
-
const target = (0,
|
|
59
|
+
const target = (0, internal_1.fileDataDepTarget)(dep);
|
|
63
60
|
// If the node is external, then read package info from `data`.
|
|
64
61
|
const externalDep = projectGraph.externalNodes[target];
|
|
65
62
|
if (externalDep?.type === 'npm') {
|
|
@@ -110,7 +107,7 @@ function collectDependenciesFromFileMap(workspaceRoot, sourceProject, projectGra
|
|
|
110
107
|
}
|
|
111
108
|
function readPackageJson(project, workspaceRoot) {
|
|
112
109
|
const packageJsonPath = (0, path_1.join)(workspaceRoot, project.data.root, 'package.json');
|
|
113
|
-
if ((0,
|
|
110
|
+
if ((0, internal_1.fileExists)(packageJsonPath))
|
|
114
111
|
return (0, devkit_1.readJsonFile)(packageJsonPath);
|
|
115
112
|
return null;
|
|
116
113
|
}
|
|
@@ -139,7 +136,7 @@ function collectHelperDependencies(workspaceRoot, sourceProject, projectGraph, b
|
|
|
139
136
|
const swcConfigPath = target.options.swcrc
|
|
140
137
|
? (0, path_1.join)(workspaceRoot, target.options.swcrc)
|
|
141
138
|
: (0, path_1.join)(workspaceRoot, sourceProject.data.root, '.swcrc');
|
|
142
|
-
const swcConfig = (0,
|
|
139
|
+
const swcConfig = (0, internal_1.fileExists)(swcConfigPath)
|
|
143
140
|
? (0, devkit_1.readJsonFile)(swcConfigPath)
|
|
144
141
|
: {};
|
|
145
142
|
if (swcConfig?.jsc?.externalHelpers &&
|
|
@@ -169,7 +166,7 @@ function resolveTsConfigForRunCommandsTarget(workspaceRoot, sourceProject, targe
|
|
|
169
166
|
const resolved = (0, path_1.isAbsolute)(commandTsConfig)
|
|
170
167
|
? commandTsConfig
|
|
171
168
|
: (0, path_1.join)(cwdAbsolute, commandTsConfig);
|
|
172
|
-
if ((0,
|
|
169
|
+
if ((0, internal_1.fileExists)(resolved))
|
|
173
170
|
return resolved;
|
|
174
171
|
}
|
|
175
172
|
// Preserves prior behavior when the tsconfig can't be determined from the command.
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { GeneratorCallback, Tree } from '@nx/devkit';
|
|
2
|
+
type FormatterSetup = {
|
|
3
|
+
setUp: (tree: Tree, options: {
|
|
4
|
+
skipPackageJson?: boolean;
|
|
5
|
+
}) => GeneratorCallback;
|
|
6
|
+
version: string;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* The setup for a formatter name that came from a schema, or `undefined` for
|
|
10
|
+
* `'none'` and anything unrecognised.
|
|
11
|
+
*
|
|
12
|
+
* `hasOwnProperty` rather than `in`, which would answer `true` for inherited
|
|
13
|
+
* members like `'constructor'` and hand back an `Object.prototype` function.
|
|
14
|
+
*/
|
|
15
|
+
export declare function getFormatterSetup(formatter: string | undefined): FormatterSetup | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* Writes the chosen formatter's config and queues its install.
|
|
18
|
+
*
|
|
19
|
+
* For callers that only need the formatter configured - a preset that creates
|
|
20
|
+
* an empty workspace, say - rather than the whole of `@nx/js:init`. Does
|
|
21
|
+
* nothing for `'none'` or an unrecognised value.
|
|
22
|
+
*/
|
|
23
|
+
export declare function setUpFormatter(tree: Tree, formatter: string | undefined, options?: {
|
|
24
|
+
skipPackageJson?: boolean;
|
|
25
|
+
}): GeneratorCallback;
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getFormatterSetup = getFormatterSetup;
|
|
4
|
+
exports.setUpFormatter = setUpFormatter;
|
|
5
|
+
const oxfmt_1 = require("./oxfmt");
|
|
6
|
+
const prettier_1 = require("./prettier");
|
|
7
|
+
const versions_1 = require("./versions");
|
|
8
|
+
/**
|
|
9
|
+
* Not `Partial`, so a new `FormatterType` member fails to compile here until it
|
|
10
|
+
* is set up - but only after `packages/nx` is rebuilt, since the type comes
|
|
11
|
+
* from its emitted declarations. The guard must stay structural: under
|
|
12
|
+
* `strict: false` an untyped lookup yields `any` instead of an error.
|
|
13
|
+
*
|
|
14
|
+
* The key doubles as the npm package name; callers install by it.
|
|
15
|
+
*/
|
|
16
|
+
const formatterSetups = {
|
|
17
|
+
prettier: { setUp: prettier_1.generatePrettierSetup, version: versions_1.prettierVersion },
|
|
18
|
+
oxfmt: { setUp: oxfmt_1.generateOxfmtSetup, version: versions_1.oxfmtVersion },
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* The setup for a formatter name that came from a schema, or `undefined` for
|
|
22
|
+
* `'none'` and anything unrecognised.
|
|
23
|
+
*
|
|
24
|
+
* `hasOwnProperty` rather than `in`, which would answer `true` for inherited
|
|
25
|
+
* members like `'constructor'` and hand back an `Object.prototype` function.
|
|
26
|
+
*/
|
|
27
|
+
function getFormatterSetup(formatter) {
|
|
28
|
+
return formatter !== undefined &&
|
|
29
|
+
Object.prototype.hasOwnProperty.call(formatterSetups, formatter)
|
|
30
|
+
? formatterSetups[formatter]
|
|
31
|
+
: undefined;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Writes the chosen formatter's config and queues its install.
|
|
35
|
+
*
|
|
36
|
+
* For callers that only need the formatter configured - a preset that creates
|
|
37
|
+
* an empty workspace, say - rather than the whole of `@nx/js:init`. Does
|
|
38
|
+
* nothing for `'none'` or an unrecognised value.
|
|
39
|
+
*/
|
|
40
|
+
function setUpFormatter(tree, formatter, options = {}) {
|
|
41
|
+
const setup = getFormatterSetup(formatter);
|
|
42
|
+
return setup ? setup.setUp(tree, options) : () => { };
|
|
43
|
+
}
|
|
@@ -3,16 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.createGlobPatternsForDependencies = createGlobPatternsForDependencies;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const devkit_1 = require("@nx/devkit");
|
|
6
|
-
const workspace_root_1 = require("nx/src/utils/workspace-root");
|
|
7
6
|
const path_1 = require("path");
|
|
8
|
-
const project_graph_1 = require("nx/src/project-graph/project-graph");
|
|
9
|
-
const project_graph_utils_1 = require("nx/src/utils/project-graph-utils");
|
|
10
7
|
const fs_1 = require("fs");
|
|
11
8
|
const ignore_1 = tslib_1.__importDefault(require("ignore"));
|
|
12
|
-
const
|
|
9
|
+
const internal_1 = require("@nx/devkit/internal");
|
|
13
10
|
function configureIgnore() {
|
|
14
11
|
let ig;
|
|
15
|
-
const pathToGitIgnore = (0, path_1.join)(
|
|
12
|
+
const pathToGitIgnore = (0, path_1.join)(devkit_1.workspaceRoot, '.gitignore');
|
|
16
13
|
if ((0, fs_1.existsSync)(pathToGitIgnore)) {
|
|
17
14
|
ig = (0, ignore_1.default)();
|
|
18
15
|
ig.add((0, fs_1.readFileSync)(pathToGitIgnore, { encoding: 'utf-8' }));
|
|
@@ -26,13 +23,13 @@ function configureIgnore() {
|
|
|
26
23
|
*/
|
|
27
24
|
function createGlobPatternsForDependencies(dirPath, fileGlobPattern) {
|
|
28
25
|
let ig = configureIgnore();
|
|
29
|
-
const filenameRelativeToWorkspaceRoot = (0, devkit_1.normalizePath)((0, path_1.relative)(
|
|
30
|
-
const projectGraph = (0,
|
|
31
|
-
const projectRootMappings = (0,
|
|
26
|
+
const filenameRelativeToWorkspaceRoot = (0, devkit_1.normalizePath)((0, path_1.relative)(devkit_1.workspaceRoot, dirPath));
|
|
27
|
+
const projectGraph = (0, devkit_1.readCachedProjectGraph)();
|
|
28
|
+
const projectRootMappings = (0, internal_1.createProjectRootMappings)(projectGraph.nodes);
|
|
32
29
|
// find the project
|
|
33
30
|
let projectName;
|
|
34
31
|
try {
|
|
35
|
-
projectName = (0,
|
|
32
|
+
projectName = (0, internal_1.findProjectForPath)(filenameRelativeToWorkspaceRoot, projectRootMappings);
|
|
36
33
|
if (!projectName) {
|
|
37
34
|
throw new Error(`createGlobPatternsForDependencies: Could not find any project containing the file "${filenameRelativeToWorkspaceRoot}" among it's project files`);
|
|
38
35
|
}
|
|
@@ -42,17 +39,17 @@ function createGlobPatternsForDependencies(dirPath, fileGlobPattern) {
|
|
|
42
39
|
}
|
|
43
40
|
// generate the glob
|
|
44
41
|
try {
|
|
45
|
-
const [projectDirs, warnings] = (0,
|
|
42
|
+
const [projectDirs, warnings] = (0, internal_1.getSourceDirOfDependentProjects)(projectName, projectGraph);
|
|
46
43
|
const dirsToUse = [];
|
|
47
44
|
const recursiveScanDirs = (dirPath) => {
|
|
48
|
-
const children = (0, fs_1.readdirSync)((0, path_1.resolve)(
|
|
45
|
+
const children = (0, fs_1.readdirSync)((0, path_1.resolve)(devkit_1.workspaceRoot, dirPath));
|
|
49
46
|
for (const child of children) {
|
|
50
47
|
const childPath = (0, path_1.join)(dirPath, child);
|
|
51
48
|
if (ig?.ignores(childPath) ||
|
|
52
|
-
!(0, fs_1.lstatSync)((0, path_1.resolve)(
|
|
49
|
+
!(0, fs_1.lstatSync)((0, path_1.resolve)(devkit_1.workspaceRoot, childPath)).isDirectory()) {
|
|
53
50
|
continue;
|
|
54
51
|
}
|
|
55
|
-
if ((0, fs_1.existsSync)((0, path_1.join)(
|
|
52
|
+
if ((0, fs_1.existsSync)((0, path_1.join)(devkit_1.workspaceRoot, childPath, 'ng-package.json'))) {
|
|
56
53
|
dirsToUse.push(childPath);
|
|
57
54
|
}
|
|
58
55
|
else {
|
|
@@ -72,7 +69,7 @@ ${warnings.join('\n- ')}\n
|
|
|
72
69
|
due to missing "sourceRoot" in the dependencies' project configuration
|
|
73
70
|
`);
|
|
74
71
|
}
|
|
75
|
-
return dirsToUse.map((sourceDir) => (0, path_1.resolve)(
|
|
72
|
+
return dirsToUse.map((sourceDir) => (0, path_1.resolve)(devkit_1.workspaceRoot, (0, devkit_1.joinPathFragments)(sourceDir, fileGlobPattern)));
|
|
76
73
|
}
|
|
77
74
|
catch (e) {
|
|
78
75
|
throw new Error(`createGlobPatternsForDependencies: Error when generating globs.\n${e?.message}`);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import type { Tree } from '@nx/devkit';
|
|
2
|
-
|
|
2
|
+
import { type LinterType } from './linter';
|
|
3
|
+
export declare function normalizeLinterOption(tree: Tree, linter: undefined | LinterType): Promise<LinterType>;
|
|
3
4
|
export declare function normalizeUnitTestRunnerOption<T extends 'none' | 'jest' | 'vitest'>(tree: Tree, unitTestRunner: undefined | T, testRunners?: Array<'jest' | 'vitest'>): Promise<T>;
|
|
@@ -4,37 +4,38 @@ exports.normalizeLinterOption = normalizeLinterOption;
|
|
|
4
4
|
exports.normalizeUnitTestRunnerOption = normalizeUnitTestRunnerOption;
|
|
5
5
|
const internal_1 = require("@nx/devkit/internal");
|
|
6
6
|
const ts_solution_setup_1 = require("./typescript/ts-solution-setup");
|
|
7
|
+
const linter_1 = require("./linter");
|
|
7
8
|
async function normalizeLinterOption(tree, linter) {
|
|
8
9
|
if (linter) {
|
|
9
10
|
return linter;
|
|
10
11
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
12
|
+
// Following the workspace is not a question. When it already has a linter,
|
|
13
|
+
// use it — including in a hybrid workspace, where `detectLinters` puts the
|
|
14
|
+
// one being migrated *to* first. Pass `--linter` to choose something else.
|
|
15
|
+
const [detected] = (0, linter_1.detectLinters)(tree);
|
|
16
|
+
if (detected) {
|
|
17
|
+
return detected;
|
|
18
|
+
}
|
|
19
|
+
// Nothing to follow, so this is a real choice. `none` is the non-interactive
|
|
20
|
+
// answer, and leads the list so the interactive default matches it.
|
|
21
|
+
return (0, internal_1.isInteractive)()
|
|
22
|
+
? (0, internal_1.selectPrompt)({
|
|
23
|
+
message: `Which linter would you like to use?`,
|
|
24
|
+
choices: [{ value: 'none' }, { value: 'eslint' }, { value: 'oxlint' }],
|
|
25
|
+
})
|
|
26
|
+
: 'none';
|
|
23
27
|
}
|
|
24
28
|
async function normalizeUnitTestRunnerOption(tree, unitTestRunner, testRunners = ['jest', 'vitest']) {
|
|
25
29
|
if (unitTestRunner) {
|
|
26
30
|
return unitTestRunner;
|
|
27
31
|
}
|
|
28
32
|
const isTsSolutionSetup = (0, ts_solution_setup_1.isUsingTsSolutionSetup)(tree);
|
|
29
|
-
const choices = isTsSolutionSetup
|
|
30
|
-
? [{ name: 'none' }, ...testRunners.map((runner) => ({ name: runner }))]
|
|
31
|
-
: [...testRunners.map((runner) => ({ name: runner })), { name: 'none' }];
|
|
33
|
+
const choices = (isTsSolutionSetup ? ['none', ...testRunners] : [...testRunners, 'none']).map((value) => ({ value: value }));
|
|
32
34
|
const defaultValue = (isTsSolutionSetup ? 'none' : testRunners[0]);
|
|
33
|
-
return
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}, { unitTestRunner: defaultValue }).then(({ unitTestRunner }) => unitTestRunner);
|
|
35
|
+
return (0, internal_1.isInteractive)()
|
|
36
|
+
? (0, internal_1.selectPrompt)({
|
|
37
|
+
message: `Which unit test runner would you like to use?`,
|
|
38
|
+
choices,
|
|
39
|
+
})
|
|
40
|
+
: defaultValue;
|
|
40
41
|
}
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getRelativeDirectoryToProjectRoot = getRelativeDirectoryToProjectRoot;
|
|
4
4
|
const path_1 = require("path");
|
|
5
|
-
const
|
|
5
|
+
const devkit_1 = require("@nx/devkit");
|
|
6
6
|
function getRelativeDirectoryToProjectRoot(file, projectRoot) {
|
|
7
7
|
const dir = (0, path_1.dirname)(file);
|
|
8
|
-
const relativeDir = (0,
|
|
8
|
+
const relativeDir = (0, devkit_1.normalizePath)((0, path_1.relative)(projectRoot, dir));
|
|
9
9
|
return relativeDir === '' ? `./` : `./${relativeDir}/`;
|
|
10
10
|
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type Tree } from '@nx/devkit';
|
|
2
|
+
/**
|
|
3
|
+
* The linters Nx generators can set up for a project.
|
|
4
|
+
*
|
|
5
|
+
* Canonical home. `@nx/eslint` re-exports this for back-compat. Two standalone
|
|
6
|
+
* copies exist because neither package can depend on `@nx/js`: `@nx/workspace`
|
|
7
|
+
* (which `@nx/js` itself depends on) and `LINTERS` in `create-nx-workspace`.
|
|
8
|
+
* The assertion below pins the first; `create-nx-workspace` has no edge to
|
|
9
|
+
* assert across, so that one is still kept in sync by hand.
|
|
10
|
+
*/
|
|
11
|
+
export type LinterType = 'eslint' | 'oxlint' | 'none';
|
|
12
|
+
/**
|
|
13
|
+
* Every linter the workspace has installed, most-preferred first — so `[0]` is
|
|
14
|
+
* the one a generator should follow when it was not told which to set up, and
|
|
15
|
+
* `.includes(x)` answers whether the workspace uses `x` at all. Those differ in
|
|
16
|
+
* a workspace part-way through a migration: it has both, and a project
|
|
17
|
+
* generated for Oxlint still lives under the root ESLint config.
|
|
18
|
+
*
|
|
19
|
+
* Oxlint sorts first when both are present. A workspace with both has adopted
|
|
20
|
+
* Oxlint alongside its existing ESLint setup, and new projects should follow
|
|
21
|
+
* the direction of travel rather than the setup being migrated away from.
|
|
22
|
+
*
|
|
23
|
+
* Empty means the workspace opted out of linting; callers that need a concrete
|
|
24
|
+
* answer should read that as `none` rather than inferring ESLint for it.
|
|
25
|
+
*
|
|
26
|
+
* Reads the tree, never the generator's own module resolution: `eslint` is a
|
|
27
|
+
* peer dependency of several first-party plugins, so it resolves from disk in
|
|
28
|
+
* workspaces that do not use it.
|
|
29
|
+
*/
|
|
30
|
+
export declare function detectLinters(tree: Tree): Exclude<LinterType, 'none'>[];
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.detectLinters = detectLinters;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
function hasPlugin(tree, plugin) {
|
|
6
|
+
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
7
|
+
return !!nxJson?.plugins?.some((p) => typeof p === 'string' ? p === plugin : p.plugin === plugin);
|
|
8
|
+
}
|
|
9
|
+
function hasAnyDependency(tree, packages) {
|
|
10
|
+
return packages.some((pkg) => Boolean((0, devkit_1.getDependencyVersionFromPackageJson)(tree, pkg)));
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Every linter the workspace has installed, most-preferred first — so `[0]` is
|
|
14
|
+
* the one a generator should follow when it was not told which to set up, and
|
|
15
|
+
* `.includes(x)` answers whether the workspace uses `x` at all. Those differ in
|
|
16
|
+
* a workspace part-way through a migration: it has both, and a project
|
|
17
|
+
* generated for Oxlint still lives under the root ESLint config.
|
|
18
|
+
*
|
|
19
|
+
* Oxlint sorts first when both are present. A workspace with both has adopted
|
|
20
|
+
* Oxlint alongside its existing ESLint setup, and new projects should follow
|
|
21
|
+
* the direction of travel rather than the setup being migrated away from.
|
|
22
|
+
*
|
|
23
|
+
* Empty means the workspace opted out of linting; callers that need a concrete
|
|
24
|
+
* answer should read that as `none` rather than inferring ESLint for it.
|
|
25
|
+
*
|
|
26
|
+
* Reads the tree, never the generator's own module resolution: `eslint` is a
|
|
27
|
+
* peer dependency of several first-party plugins, so it resolves from disk in
|
|
28
|
+
* workspaces that do not use it.
|
|
29
|
+
*/
|
|
30
|
+
function detectLinters(tree) {
|
|
31
|
+
const linters = [];
|
|
32
|
+
if (hasPlugin(tree, '@nx/oxlint') ||
|
|
33
|
+
hasAnyDependency(tree, ['@nx/oxlint', 'oxlint'])) {
|
|
34
|
+
linters.push('oxlint');
|
|
35
|
+
}
|
|
36
|
+
// `@nx/eslint` registers its inference plugin as `@nx/eslint/plugin`, unlike
|
|
37
|
+
// `@nx/oxlint`, which registers under its bare package name.
|
|
38
|
+
if (hasPlugin(tree, '@nx/eslint/plugin') ||
|
|
39
|
+
hasAnyDependency(tree, ['@nx/eslint', 'eslint'])) {
|
|
40
|
+
linters.push('eslint');
|
|
41
|
+
}
|
|
42
|
+
return linters;
|
|
43
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@nx/js` inherits `@nx/devkit`'s `nx` peer, which spans a major either
|
|
3
|
+
* side, so an older nx without these helpers can legally be installed. A
|
|
4
|
+
* missing CommonJS named export arrives as `undefined`, so the first use
|
|
5
|
+
* would otherwise be a bare `undefined.every` naming neither package nor
|
|
6
|
+
* cause.
|
|
7
|
+
*/
|
|
8
|
+
export declare function assertNxSupportsFormatters(): void;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.assertNxSupportsFormatters = assertNxSupportsFormatters;
|
|
4
|
+
const internal_1 = require("@nx/devkit/internal");
|
|
5
|
+
/**
|
|
6
|
+
* `@nx/js` inherits `@nx/devkit`'s `nx` peer, which spans a major either
|
|
7
|
+
* side, so an older nx without these helpers can legally be installed. A
|
|
8
|
+
* missing CommonJS named export arrives as `undefined`, so the first use
|
|
9
|
+
* would otherwise be a bare `undefined.every` naming neither package nor
|
|
10
|
+
* cause.
|
|
11
|
+
*/
|
|
12
|
+
function assertNxSupportsFormatters() {
|
|
13
|
+
if (internal_1.detectFormatterInTree && internal_1.oxfmtConfigFiles && internal_1.prettierConfigFiles) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
throw new Error('The installed version of nx does not export the formatter helpers that @nx/js needs to detect and set up a formatter. ' +
|
|
17
|
+
'This happens when nx and @nx/js are on different major versions. Run `nx migrate latest` to bring them into line.');
|
|
18
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateOxfmtSetup = generateOxfmtSetup;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
// Imported rather than copied: detection ("is this workspace using oxfmt?")
|
|
6
|
+
// and setup ("should a config be written?") have to agree on the same list, or
|
|
7
|
+
// a workspace that already has a config gets a second, redundant one.
|
|
8
|
+
const internal_1 = require("@nx/devkit/internal");
|
|
9
|
+
const nx_formatter_internals_1 = require("./nx-formatter-internals");
|
|
10
|
+
const versions_1 = require("./versions");
|
|
11
|
+
function generateOxfmtSetup(tree, options) {
|
|
12
|
+
(0, nx_formatter_internals_1.assertNxSupportsFormatters)();
|
|
13
|
+
if (internal_1.oxfmtConfigFiles.every((name) => !tree.exists(name))) {
|
|
14
|
+
// oxfmt defaults to double quotes and we prefer single, so that is the one
|
|
15
|
+
// option worth setting. Line width is left at oxfmt's default.
|
|
16
|
+
(0, devkit_1.writeJson)(tree, '.oxfmtrc.json', { singleQuote: true });
|
|
17
|
+
}
|
|
18
|
+
// The oxc extension is what drives oxfmt in the editor, so recommend it for
|
|
19
|
+
// the same reason the prettier setup recommends its own. Only when the file
|
|
20
|
+
// is already there - creating it would push an editor choice on a workspace
|
|
21
|
+
// that has not made one.
|
|
22
|
+
if (tree.exists('.vscode/extensions.json')) {
|
|
23
|
+
(0, devkit_1.updateJson)(tree, '.vscode/extensions.json', (json) => {
|
|
24
|
+
json.recommendations ??= [];
|
|
25
|
+
const extension = 'oxc.oxc-vscode';
|
|
26
|
+
if (!json.recommendations.includes(extension)) {
|
|
27
|
+
json.recommendations.push(extension);
|
|
28
|
+
}
|
|
29
|
+
return json;
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
return options.skipPackageJson
|
|
33
|
+
? () => { }
|
|
34
|
+
: (0, devkit_1.addDependenciesToPackageJson)(tree, {}, { oxfmt: versions_1.oxfmtVersion });
|
|
35
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { type PackageJson } from '@nx/devkit/internal';
|
|
1
2
|
import { ExecutorContext, ProjectFileMap, ProjectGraphProjectNode } from '@nx/devkit';
|
|
2
3
|
import { DependentBuildableProjectNode } from '../buildable-libs-utils';
|
|
3
|
-
import type { PackageJson } from 'nx/src/utils/package-json';
|
|
4
4
|
export type SupportedFormat = 'cjs' | 'esm';
|
|
5
5
|
export interface UpdatePackageJsonOption {
|
|
6
6
|
rootDir?: string;
|
|
@@ -4,24 +4,19 @@ exports.updatePackageJson = updatePackageJson;
|
|
|
4
4
|
exports.getExports = getExports;
|
|
5
5
|
exports.getUpdatedPackageJsonContent = getUpdatedPackageJsonContent;
|
|
6
6
|
exports.getOutputDir = getOutputDir;
|
|
7
|
-
|
|
8
|
-
const lock_file_1 = require("nx/src/plugins/js/lock-file/lock-file");
|
|
9
|
-
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
|
|
10
|
-
const create_package_json_1 = require("nx/src/plugins/js/package-json/create-package-json");
|
|
7
|
+
const internal_1 = require("@nx/devkit/internal");
|
|
11
8
|
const devkit_1 = require("@nx/devkit");
|
|
12
9
|
const node_fs_1 = require("node:fs");
|
|
13
10
|
const path_1 = require("path");
|
|
14
|
-
const fileutils_1 = require("nx/src/utils/fileutils");
|
|
15
|
-
const nx_deps_cache_1 = require("nx/src/project-graph/nx-deps-cache");
|
|
16
11
|
const get_main_file_dir_1 = require("../get-main-file-dir");
|
|
17
12
|
const strip_glob_to_base_dir_1 = require("../strip-glob-to-base-dir");
|
|
18
13
|
function updatePackageJson(options, context, target, dependencies, fileMap = null) {
|
|
19
14
|
let packageJson;
|
|
20
15
|
if (fileMap == null) {
|
|
21
|
-
fileMap = (0,
|
|
16
|
+
fileMap = (0, internal_1.readFileMapCache)()?.fileMap?.projectFileMap || {};
|
|
22
17
|
}
|
|
23
18
|
if (options.updateBuildableProjectDepsInPackageJson) {
|
|
24
|
-
packageJson = (0,
|
|
19
|
+
packageJson = (0, internal_1.createPackageJson)(context.projectName, context.projectGraph, {
|
|
25
20
|
target: context.targetName,
|
|
26
21
|
root: context.root,
|
|
27
22
|
// By default we remove devDependencies since this is a production build.
|
|
@@ -34,7 +29,7 @@ function updatePackageJson(options, context, target, dependencies, fileMap = nul
|
|
|
34
29
|
}
|
|
35
30
|
else {
|
|
36
31
|
const pathToPackageJson = (0, path_1.join)(context.root, options.projectRoot, 'package.json');
|
|
37
|
-
packageJson = (0,
|
|
32
|
+
packageJson = (0, internal_1.fileExists)(pathToPackageJson)
|
|
38
33
|
? (0, devkit_1.readJsonFile)(pathToPackageJson)
|
|
39
34
|
: { name: context.projectName, version: '0.0.1' };
|
|
40
35
|
}
|
|
@@ -50,22 +45,16 @@ function updatePackageJson(options, context, target, dependencies, fileMap = nul
|
|
|
50
45
|
}
|
|
51
46
|
options.format = ['cjs'];
|
|
52
47
|
}
|
|
53
|
-
// update package specific settings
|
|
54
48
|
packageJson = getUpdatedPackageJsonContent(packageJson, options);
|
|
55
|
-
|
|
56
|
-
(0, devkit_1.writeJsonFile)(`${options.outputPath}/package.json`, packageJson);
|
|
49
|
+
const packageManager = (0, devkit_1.detectPackageManager)(context.root);
|
|
57
50
|
if (options.generateLockfile) {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const lockFile = (0, lock_file_1.createLockFile)(packageJson, context.projectGraph, packageManager);
|
|
64
|
-
(0, node_fs_1.writeFileSync)(`${options.outputPath}/${(0, lock_file_1.getLockFileName)(packageManager)}`, lockFile, {
|
|
65
|
-
encoding: 'utf-8',
|
|
66
|
-
});
|
|
67
|
-
}
|
|
51
|
+
(0, internal_1.generatePrunedDeployOutput)(packageJson, context.projectGraph, options.projectRoot, {
|
|
52
|
+
outputDirectory: options.outputPath,
|
|
53
|
+
packageManager,
|
|
54
|
+
workspaceRoot: context.root,
|
|
55
|
+
});
|
|
68
56
|
}
|
|
57
|
+
(0, devkit_1.writeJsonFile)(`${options.outputPath}/package.json`, packageJson);
|
|
69
58
|
}
|
|
70
59
|
function isNpmNode(node, graph) {
|
|
71
60
|
return !!(graph.externalNodes[node.name]?.type === 'npm');
|
|
@@ -8,8 +8,8 @@ exports.getProjectPackageManagerWorkspaceStateWarningTask = getProjectPackageMan
|
|
|
8
8
|
const devkit_1 = require("@nx/devkit");
|
|
9
9
|
const picomatch = require("picomatch");
|
|
10
10
|
const posix_1 = require("node:path/posix");
|
|
11
|
-
const package_json_1 = require("nx/src/plugins/package-json");
|
|
12
11
|
const semver_1 = require("semver");
|
|
12
|
+
const internal_1 = require("@nx/devkit/internal");
|
|
13
13
|
function getProjectPackageManagerWorkspaceState(tree, projectRoot) {
|
|
14
14
|
if (!isUsingPackageManagerWorkspaces(tree)) {
|
|
15
15
|
return 'no-workspaces';
|
|
@@ -19,7 +19,7 @@ function getProjectPackageManagerWorkspaceState(tree, projectRoot) {
|
|
|
19
19
|
return isIncluded ? 'included' : 'excluded';
|
|
20
20
|
}
|
|
21
21
|
function getPackageManagerWorkspacesPatterns(tree) {
|
|
22
|
-
return (0,
|
|
22
|
+
return (0, internal_1.getGlobPatternsFromPackageManagerWorkspaces)(tree.root, (path) => (0, devkit_1.readJson)(tree, path, { expectComments: true }), (path) => {
|
|
23
23
|
const content = tree.read(path, 'utf-8');
|
|
24
24
|
const { load } = require('@zkochan/js-yaml');
|
|
25
25
|
return load(content, { filename: path });
|