@nx/workspace 20.3.0-canary.20241214-4cd640a → 20.3.0-canary.20241218-fb40366
Sign up to get free protection for your applications and to get access to all the features.
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@nx/workspace",
|
3
|
-
"version": "20.3.0-canary.
|
3
|
+
"version": "20.3.0-canary.20241218-fb40366",
|
4
4
|
"private": false,
|
5
5
|
"description": "The Workspace plugin contains executors and generators that are useful for any Nx workspace. It should be present in every Nx workspace and other plugins build on it.",
|
6
6
|
"repository": {
|
@@ -38,12 +38,12 @@
|
|
38
38
|
}
|
39
39
|
},
|
40
40
|
"dependencies": {
|
41
|
-
"@nx/devkit": "20.3.0-canary.
|
41
|
+
"@nx/devkit": "20.3.0-canary.20241218-fb40366",
|
42
42
|
"chalk": "^4.1.0",
|
43
43
|
"enquirer": "~2.3.6",
|
44
44
|
"tslib": "^2.3.0",
|
45
45
|
"yargs-parser": "21.1.1",
|
46
|
-
"nx": "20.3.0-canary.
|
46
|
+
"nx": "20.3.0-canary.20241218-fb40366"
|
47
47
|
},
|
48
48
|
"publishConfig": {
|
49
49
|
"access": "public"
|
@@ -7,6 +7,7 @@ const get_import_path_1 = require("../../../utilities/get-import-path");
|
|
7
7
|
const ts_config_1 = require("../../../utilities/ts-config");
|
8
8
|
const typescript_1 = require("../../../utilities/typescript");
|
9
9
|
const utils_1 = require("./utils");
|
10
|
+
const ts_solution_setup_1 = require("../../../utilities/typescript/ts-solution-setup");
|
10
11
|
let tsModule;
|
11
12
|
/**
|
12
13
|
* Updates all the imports in the workspace and modifies the tsconfig appropriately.
|
@@ -19,9 +20,13 @@ function updateImports(tree, schema, project) {
|
|
19
20
|
}
|
20
21
|
const { libsDir } = (0, devkit_1.getWorkspaceLayout)(tree);
|
21
22
|
const projects = (0, devkit_1.getProjects)(tree);
|
23
|
+
const isUsingTsSolution = (0, ts_solution_setup_1.isUsingTsSolutionSetup)(tree);
|
22
24
|
// use the source root to find the from location
|
23
25
|
// this attempts to account for libs that have been created with --importPath
|
24
|
-
const tsConfigPath =
|
26
|
+
const tsConfigPath = isUsingTsSolution
|
27
|
+
? 'tsconfig.json'
|
28
|
+
: (0, ts_config_1.getRootTsConfigPathInTree)(tree);
|
29
|
+
// If we are using a ts solution setup, we need to use tsconfig.json instead of tsconfig.base.json
|
25
30
|
let tsConfig;
|
26
31
|
let mainEntryPointImportPath;
|
27
32
|
let secondaryEntryPointImportPaths;
|
@@ -84,25 +89,53 @@ function updateImports(tree, schema, project) {
|
|
84
89
|
to: schema.relativeToRootDestination,
|
85
90
|
};
|
86
91
|
if (tsConfig) {
|
87
|
-
|
88
|
-
|
89
|
-
throw new Error([
|
90
|
-
`unable to find "${projectRef.from}" in`,
|
91
|
-
`${tsConfigPath} compilerOptions.paths`,
|
92
|
-
].join(' '));
|
93
|
-
}
|
94
|
-
const updatedPath = path.map((x) => (0, devkit_1.joinPathFragments)(projectRoot.to, (0, path_1.relative)(projectRoot.from, x)));
|
95
|
-
if (schema.updateImportPath && projectRef.to) {
|
96
|
-
tsConfig.compilerOptions.paths[projectRef.to] = updatedPath;
|
97
|
-
if (projectRef.from !== projectRef.to) {
|
98
|
-
delete tsConfig.compilerOptions.paths[projectRef.from];
|
99
|
-
}
|
92
|
+
if (!isUsingTsSolution) {
|
93
|
+
updateTsConfigPaths(tsConfig, projectRef, tsConfigPath, projectRoot, schema);
|
100
94
|
}
|
101
95
|
else {
|
102
|
-
tsConfig
|
96
|
+
updateTsConfigReferences(tsConfig, projectRoot, tsConfigPath, schema);
|
103
97
|
}
|
98
|
+
(0, devkit_1.writeJson)(tree, tsConfigPath, tsConfig);
|
99
|
+
}
|
100
|
+
}
|
101
|
+
}
|
102
|
+
function updateTsConfigReferences(tsConfig, projectRoot, tsConfigPath, schema) {
|
103
|
+
// Since paths can be './path' or 'path' we check if both are the same relative path to the workspace root
|
104
|
+
const projectRefIndex = tsConfig.references.findIndex((ref) => (0, path_1.relative)(ref.path, projectRoot.from) === '');
|
105
|
+
if (projectRefIndex === -1) {
|
106
|
+
throw new Error(`unable to find "${projectRoot.from}" in ${tsConfigPath} references`);
|
107
|
+
}
|
108
|
+
const updatedPath = (0, devkit_1.joinPathFragments)(projectRoot.to, (0, path_1.relative)(projectRoot.from, tsConfig.references[projectRefIndex].path));
|
109
|
+
let normalizedPath = (0, path_1.normalize)(updatedPath);
|
110
|
+
if (!normalizedPath.startsWith('.') &&
|
111
|
+
!normalizedPath.startsWith('../') &&
|
112
|
+
!(0, path_1.isAbsolute)(normalizedPath)) {
|
113
|
+
normalizedPath = `./${normalizedPath}`;
|
114
|
+
}
|
115
|
+
if (schema.updateImportPath && projectRoot.to) {
|
116
|
+
tsConfig.references[projectRefIndex].path = normalizedPath;
|
117
|
+
}
|
118
|
+
else {
|
119
|
+
tsConfig.references.push({ path: normalizedPath });
|
120
|
+
}
|
121
|
+
}
|
122
|
+
function updateTsConfigPaths(tsConfig, projectRef, tsConfigPath, projectRoot, schema) {
|
123
|
+
const path = tsConfig.compilerOptions.paths[projectRef.from];
|
124
|
+
if (!path) {
|
125
|
+
throw new Error([
|
126
|
+
`unable to find "${projectRef.from}" in`,
|
127
|
+
`${tsConfigPath} compilerOptions.paths`,
|
128
|
+
].join(' '));
|
129
|
+
}
|
130
|
+
const updatedPath = path.map((x) => (0, devkit_1.joinPathFragments)(projectRoot.to, (0, path_1.relative)(projectRoot.from, x)));
|
131
|
+
if (schema.updateImportPath && projectRef.to) {
|
132
|
+
tsConfig.compilerOptions.paths[projectRef.to] = updatedPath;
|
133
|
+
if (projectRef.from !== projectRef.to) {
|
134
|
+
delete tsConfig.compilerOptions.paths[projectRef.from];
|
104
135
|
}
|
105
|
-
|
136
|
+
}
|
137
|
+
else {
|
138
|
+
tsConfig.compilerOptions.paths[projectRef.from] = updatedPath;
|
106
139
|
}
|
107
140
|
}
|
108
141
|
function ensureTrailingSlash(path) {
|
@@ -4,23 +4,38 @@ exports.updateTsconfig = updateTsconfig;
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
5
5
|
const ts_config_1 = require("../../../utilities/ts-config");
|
6
6
|
const find_project_for_path_1 = require("nx/src/project-graph/utils/find-project-for-path");
|
7
|
+
const ts_solution_setup_1 = require("../../../utilities/typescript/ts-solution-setup");
|
8
|
+
const path_1 = require("path");
|
7
9
|
/**
|
8
10
|
* Updates the tsconfig paths to remove the project.
|
9
11
|
*
|
10
12
|
* @param schema The options provided to the schematic
|
11
13
|
*/
|
12
14
|
async function updateTsconfig(tree, schema) {
|
13
|
-
const
|
15
|
+
const isUsingTsSolution = (0, ts_solution_setup_1.isUsingTsSolutionSetup)(tree);
|
16
|
+
const tsConfigPath = isUsingTsSolution
|
17
|
+
? 'tsconfig.json'
|
18
|
+
: (0, ts_config_1.getRootTsConfigPathInTree)(tree);
|
14
19
|
if (tree.exists(tsConfigPath)) {
|
15
20
|
const graph = await (0, devkit_1.createProjectGraphAsync)();
|
16
21
|
const projectMapping = (0, find_project_for_path_1.createProjectRootMappings)(graph.nodes);
|
17
22
|
(0, devkit_1.updateJson)(tree, tsConfigPath, (json) => {
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
23
|
+
if (isUsingTsSolution) {
|
24
|
+
const projectConfigs = (0, devkit_1.readProjectsConfigurationFromProjectGraph)(graph);
|
25
|
+
const project = projectConfigs.projects[schema.projectName];
|
26
|
+
if (!project) {
|
27
|
+
throw new Error(`Could not find project '${schema.project}'. Please choose a project that exists in the Nx Workspace.`);
|
28
|
+
}
|
29
|
+
json.references = json.references.filter((ref) => (0, path_1.relative)(ref.path, project.root) !== '');
|
30
|
+
}
|
31
|
+
else {
|
32
|
+
for (const importPath in json.compilerOptions.paths) {
|
33
|
+
for (const path of json.compilerOptions.paths[importPath]) {
|
34
|
+
const project = (0, find_project_for_path_1.findProjectForPath)((0, devkit_1.normalizePath)(path), projectMapping);
|
35
|
+
if (project === schema.projectName) {
|
36
|
+
delete json.compilerOptions.paths[importPath];
|
37
|
+
break;
|
38
|
+
}
|
24
39
|
}
|
25
40
|
}
|
26
41
|
}
|
@@ -0,0 +1,57 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.isUsingTsSolutionSetup = isUsingTsSolutionSetup;
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
5
|
+
const tree_1 = require("nx/src/generators/tree");
|
6
|
+
function isUsingPackageManagerWorkspaces(tree) {
|
7
|
+
return isWorkspacesEnabled(tree);
|
8
|
+
}
|
9
|
+
function isWorkspacesEnabled(tree) {
|
10
|
+
const packageManager = (0, devkit_1.detectPackageManager)(tree.root);
|
11
|
+
if (packageManager === 'pnpm') {
|
12
|
+
return tree.exists('pnpm-workspace.yaml');
|
13
|
+
}
|
14
|
+
// yarn and npm both use the same 'workspaces' property in package.json
|
15
|
+
if (tree.exists('package.json')) {
|
16
|
+
const packageJson = (0, devkit_1.readJson)(tree, 'package.json');
|
17
|
+
return !!packageJson?.workspaces;
|
18
|
+
}
|
19
|
+
return false;
|
20
|
+
}
|
21
|
+
function isWorkspaceSetupWithTsSolution(tree) {
|
22
|
+
if (!tree.exists('tsconfig.base.json') || !tree.exists('tsconfig.json')) {
|
23
|
+
return false;
|
24
|
+
}
|
25
|
+
const tsconfigJson = (0, devkit_1.readJson)(tree, 'tsconfig.json');
|
26
|
+
if (tsconfigJson.extends !== './tsconfig.base.json') {
|
27
|
+
return false;
|
28
|
+
}
|
29
|
+
/**
|
30
|
+
* New setup:
|
31
|
+
* - `files` is defined and set to an empty array
|
32
|
+
* - `references` is defined and set to an empty array
|
33
|
+
* - `include` is not defined or is set to an empty array
|
34
|
+
*/
|
35
|
+
if (!tsconfigJson.files ||
|
36
|
+
tsconfigJson.files.length > 0 ||
|
37
|
+
!tsconfigJson.references ||
|
38
|
+
!!tsconfigJson.include?.length) {
|
39
|
+
return false;
|
40
|
+
}
|
41
|
+
const baseTsconfigJson = (0, devkit_1.readJson)(tree, 'tsconfig.base.json');
|
42
|
+
if (!baseTsconfigJson.compilerOptions ||
|
43
|
+
!baseTsconfigJson.compilerOptions.composite ||
|
44
|
+
!baseTsconfigJson.compilerOptions.declaration) {
|
45
|
+
return false;
|
46
|
+
}
|
47
|
+
const { compilerOptions, ...rest } = baseTsconfigJson;
|
48
|
+
if (Object.keys(rest).length > 0) {
|
49
|
+
return false;
|
50
|
+
}
|
51
|
+
return true;
|
52
|
+
}
|
53
|
+
function isUsingTsSolutionSetup(tree) {
|
54
|
+
tree ??= new tree_1.FsTree(devkit_1.workspaceRoot, false);
|
55
|
+
return (isUsingPackageManagerWorkspaces(tree) &&
|
56
|
+
isWorkspaceSetupWithTsSolution(tree));
|
57
|
+
}
|