@nx/js 22.7.0-beta.12 → 22.7.0-beta.14
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 +4 -4
- package/src/executors/release-publish/release-publish.impl.d.ts.map +1 -1
- package/src/executors/release-publish/release-publish.impl.js +13 -1
- package/src/generators/init/files/non-ts-solution/__fileName__ +0 -1
- package/src/generators/library/files/tsconfig-lib/ts-solution/tsconfig.lib.json__tmpl__ +0 -1
- package/src/utils/buildable-libs-utils.d.ts.map +1 -1
- package/src/utils/buildable-libs-utils.js +20 -5
- package/src/utils/find-npm-dependencies.js +24 -3
- package/src/utils/typescript/create-ts-config.d.ts +0 -1
- package/src/utils/typescript/create-ts-config.d.ts.map +1 -1
- package/src/utils/typescript/create-ts-config.js +0 -5
- package/src/utils/typescript/ts-config.d.ts +14 -0
- package/src/utils/typescript/ts-config.d.ts.map +1 -1
- package/src/utils/typescript/ts-config.js +112 -11
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/js",
|
|
3
|
-
"version": "22.7.0-beta.
|
|
3
|
+
"version": "22.7.0-beta.14",
|
|
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": {
|
|
@@ -40,8 +40,8 @@
|
|
|
40
40
|
"@babel/preset-env": "^7.23.2",
|
|
41
41
|
"@babel/preset-typescript": "^7.22.5",
|
|
42
42
|
"@babel/runtime": "^7.22.6",
|
|
43
|
-
"@nx/devkit": "22.7.0-beta.
|
|
44
|
-
"@nx/workspace": "22.7.0-beta.
|
|
43
|
+
"@nx/devkit": "22.7.0-beta.14",
|
|
44
|
+
"@nx/workspace": "22.7.0-beta.14",
|
|
45
45
|
"@zkochan/js-yaml": "0.0.7",
|
|
46
46
|
"babel-plugin-const-enum": "^1.0.1",
|
|
47
47
|
"babel-plugin-macros": "^3.1.0",
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
"tslib": "^2.3.0"
|
|
62
62
|
},
|
|
63
63
|
"devDependencies": {
|
|
64
|
-
"nx": "22.7.0-beta.
|
|
64
|
+
"nx": "22.7.0-beta.14"
|
|
65
65
|
},
|
|
66
66
|
"peerDependencies": {
|
|
67
67
|
"verdaccio": "^6.0.5"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"release-publish.impl.d.ts","sourceRoot":"","sources":["../../../../../../packages/js/src/executors/release-publish/release-publish.impl.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,eAAe,EAEhB,MAAM,YAAY,CAAC;AAQpB,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAiBjD,wBAA8B,WAAW,CACvC,OAAO,EAAE,qBAAqB,EAC9B,OAAO,EAAE,eAAe;;
|
|
1
|
+
{"version":3,"file":"release-publish.impl.d.ts","sourceRoot":"","sources":["../../../../../../packages/js/src/executors/release-publish/release-publish.impl.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,eAAe,EAEhB,MAAM,YAAY,CAAC;AAQpB,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAiBjD,wBAA8B,WAAW,CACvC,OAAO,EAAE,qBAAqB,EAC9B,OAAO,EAAE,eAAe;;GA6dzB"}
|
|
@@ -349,7 +349,19 @@ Please update the local dependency on "${depName}" to be a valid semantic versio
|
|
|
349
349
|
success: false,
|
|
350
350
|
};
|
|
351
351
|
}
|
|
352
|
-
|
|
352
|
+
// stdout is not guaranteed to be JSON (e.g. lifecycle script failures).
|
|
353
|
+
// If parsing fails, print raw stderr/stdout so the underlying error is visible to the user.
|
|
354
|
+
let stdoutData;
|
|
355
|
+
try {
|
|
356
|
+
stdoutData = JSON.parse(err.stdout?.toString() || '{}');
|
|
357
|
+
}
|
|
358
|
+
catch {
|
|
359
|
+
console.error(err.stderr?.toString() || '');
|
|
360
|
+
console.error(err.stdout?.toString() || '');
|
|
361
|
+
return {
|
|
362
|
+
success: false,
|
|
363
|
+
};
|
|
364
|
+
}
|
|
353
365
|
console.error(`${pm} publish error:`);
|
|
354
366
|
// npm returns error.summary and error.detail
|
|
355
367
|
if (stdoutData.error?.summary) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildable-libs-utils.d.ts","sourceRoot":"","sources":["../../../../../packages/js/src/utils/buildable-libs-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,wBAAwB,EACxB,uBAAuB,EACvB,SAAS,EACV,MAAM,YAAY,CAAC;AAYpB,OAAO,KAAK,KAAK,EAAE,MAAM,YAAY,CAAC;AAgBtC,MAAM,MAAM,6BAA6B,GAAG;IAC1C,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,IAAI,EAAE,uBAAuB,GAAG,wBAAwB,CAAC;CAC1D,CAAC;AAEF,wBAAgB,qCAAqC,CACnD,SAAS,EAAE,SAAS,GAAG,SAAS,EAChC,SAAS,EAAE,YAAY,EACvB,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,MAAM,EAClB,iBAAiB,EAAE,MAAM,EACzB,OAAO,CAAC,EAAE,OAAO,GAChB;IACD,MAAM,EAAE,uBAAuB,CAAC;IAChC,YAAY,EAAE,6BAA6B,EAAE,CAAC;IAC9C,wBAAwB,EAAE,MAAM,EAAE,CAAC;IACnC,oBAAoB,EAAE,6BAA6B,EAAE,CAAC;CACvD,CAqBA;AAED,wBAAgB,4BAA4B,CAC1C,SAAS,EAAE,YAAY,EACvB,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,MAAM,EAClB,iBAAiB,EAAE,MAAM,EACzB,OAAO,CAAC,EAAE,OAAO,GAChB;IACD,MAAM,EAAE,uBAAuB,CAAC;IAChC,YAAY,EAAE,6BAA6B,EAAE,CAAC;IAC9C,wBAAwB,EAAE,MAAM,EAAE,CAAC;IACnC,oBAAoB,EAAE,6BAA6B,EAAE,CAAC;CACvD,CA+EA;
|
|
1
|
+
{"version":3,"file":"buildable-libs-utils.d.ts","sourceRoot":"","sources":["../../../../../packages/js/src/utils/buildable-libs-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,wBAAwB,EACxB,uBAAuB,EACvB,SAAS,EACV,MAAM,YAAY,CAAC;AAYpB,OAAO,KAAK,KAAK,EAAE,MAAM,YAAY,CAAC;AAgBtC,MAAM,MAAM,6BAA6B,GAAG;IAC1C,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,IAAI,EAAE,uBAAuB,GAAG,wBAAwB,CAAC;CAC1D,CAAC;AAEF,wBAAgB,qCAAqC,CACnD,SAAS,EAAE,SAAS,GAAG,SAAS,EAChC,SAAS,EAAE,YAAY,EACvB,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,MAAM,EAClB,iBAAiB,EAAE,MAAM,EACzB,OAAO,CAAC,EAAE,OAAO,GAChB;IACD,MAAM,EAAE,uBAAuB,CAAC;IAChC,YAAY,EAAE,6BAA6B,EAAE,CAAC;IAC9C,wBAAwB,EAAE,MAAM,EAAE,CAAC;IACnC,oBAAoB,EAAE,6BAA6B,EAAE,CAAC;CACvD,CAqBA;AAED,wBAAgB,4BAA4B,CAC1C,SAAS,EAAE,YAAY,EACvB,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,MAAM,EAClB,iBAAiB,EAAE,MAAM,EACzB,OAAO,CAAC,EAAE,OAAO,GAChB;IACD,MAAM,EAAE,uBAAuB,CAAC;IAChC,YAAY,EAAE,6BAA6B,EAAE,CAAC;IAC9C,wBAAwB,EAAE,MAAM,EAAE,CAAC;IACnC,oBAAoB,EAAE,6BAA6B,EAAE,CAAC;CACvD,CA+EA;AA0ED,wBAAgB,kCAAkC,CAChD,SAAS,EAAE,SAAS,EACpB,YAAY,EAAE,YAAY,EAC1B,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,MAAM,EAClB,iBAAiB,EAAE,MAAM,EACzB,OAAO,CAAC,EAAE,OAAO,GAChB;IACD,MAAM,EAAE,uBAAuB,CAAC;IAChC,YAAY,EAAE,6BAA6B,EAAE,CAAC;IAC9C,wBAAwB,EAAE,MAAM,EAAE,CAAC;IACnC,oBAAoB,EAAE,6BAA6B,EAAE,CAAC;CACvD,CA8EA;AAkGD;;;;;;;GAOG;AACH,wBAAgB,2BAA2B,CACzC,QAAQ,EAAE,MAAM,GAAG,EAAE,CAAC,iBAAiB,EACvC,YAAY,EAAE,6BAA6B,EAAE,wBAK9C;AAED,wBAAgB,iBAAiB,CAC/B,YAAY,EAAE,MAAM,EACpB,aAAa,EAAE,MAAM,EACrB,WAAW,EAAE,MAAM,EACnB,YAAY,EAAE,6BAA6B,EAAE,EAC7C,qBAAqB,GAAE,OAAe,UAsBvC;AAUD,wBAAgB,WAAW,CACzB,YAAY,EAAE,6BAA6B,EAAE,EAC7C,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,QA6DhC;AAED;;;GAGG;AACH,wBAAgB,6CAA6C,CAC3D,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,MAAM,EAClB,iBAAiB,EAAE,MAAM,EACzB,IAAI,EAAE,uBAAuB,EAC7B,YAAY,EAAE,6BAA6B,EAAE,EAC7C,gBAAgB,GAAE,cAAc,GAAG,kBAAmC,QAkFvE"}
|
|
@@ -114,7 +114,20 @@ function readTsConfigWithRemappedPaths(originalTsconfigPath, generatedTsconfigPa
|
|
|
114
114
|
const normalizedTsConfig = (0, path_1.resolve)(workspaceRoot, originalTsconfigPath);
|
|
115
115
|
const normalizedGeneratedTsConfigDir = (0, path_1.resolve)(workspaceRoot, (0, path_1.dirname)(generatedTsconfigPath));
|
|
116
116
|
generatedTsConfig.extends = (0, path_1.relative)(normalizedGeneratedTsConfigDir, normalizedTsConfig);
|
|
117
|
-
|
|
117
|
+
const paths = computeCompilerOptionsPaths(normalizedTsConfig, dependencies);
|
|
118
|
+
// Resolve paths to absolute so they work regardless of the tmp tsconfig
|
|
119
|
+
// location and without needing baseUrl (deprecated in TS 6, removed in TS 7).
|
|
120
|
+
const pathsBase = (0, ts_config_1.resolvePathsBaseUrl)(normalizedTsConfig);
|
|
121
|
+
for (const key of Object.keys(paths)) {
|
|
122
|
+
paths[key] = paths[key].map((p) => {
|
|
123
|
+
if ((0, path_1.isAbsolute)(p)) {
|
|
124
|
+
return p;
|
|
125
|
+
}
|
|
126
|
+
const stripped = p.startsWith('./') ? p.slice(2) : p;
|
|
127
|
+
return (0, path_1.resolve)(pathsBase, stripped).replace(/\\/g, '/');
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
generatedTsConfig.compilerOptions.paths = paths;
|
|
118
131
|
if (process.env.NX_VERBOSE_LOGGING_PATH_MAPPINGS === 'true') {
|
|
119
132
|
output_1.output.log({
|
|
120
133
|
title: 'TypeScript path mappings have been rewritten.',
|
|
@@ -235,10 +248,6 @@ function createTmpTsConfig(tsconfigPath, workspaceRoot, projectRoot, dependencie
|
|
|
235
248
|
}
|
|
236
249
|
const parsedTSConfig = readTsConfigWithRemappedPaths(tsconfigPath, tmpTsConfigPath, dependencies, workspaceRoot);
|
|
237
250
|
process.on('exit', () => cleanupTmpTsConfigFile(tmpTsConfigPath));
|
|
238
|
-
if (useWorkspaceAsBaseUrl) {
|
|
239
|
-
parsedTSConfig.compilerOptions ??= {};
|
|
240
|
-
parsedTSConfig.compilerOptions.baseUrl = workspaceRoot;
|
|
241
|
-
}
|
|
242
251
|
(0, devkit_1.writeJsonFile)(tmpTsConfigPath, parsedTSConfig);
|
|
243
252
|
return (0, path_1.join)(tmpTsConfigPath);
|
|
244
253
|
}
|
|
@@ -285,6 +294,12 @@ function updatePaths(dependencies, paths) {
|
|
|
285
294
|
}
|
|
286
295
|
}
|
|
287
296
|
});
|
|
297
|
+
// Ensure all path values use ./ prefix for TS 6+ compatibility (no baseUrl)
|
|
298
|
+
for (const key of Object.keys(paths)) {
|
|
299
|
+
paths[key] = paths[key].map((p) => p.startsWith('./') || p.startsWith('../') || p.startsWith('/')
|
|
300
|
+
? p
|
|
301
|
+
: `./${p}`);
|
|
302
|
+
}
|
|
288
303
|
}
|
|
289
304
|
/**
|
|
290
305
|
* Updates the peerDependencies section in the `dist/lib/xyz/package.json` with
|
|
@@ -151,9 +151,9 @@ function collectHelperDependencies(workspaceRoot, sourceProject, projectGraph, b
|
|
|
151
151
|
// For inferred targets or manually added run-commands, check if user is using `tsc` in build target.
|
|
152
152
|
if (target.executor === 'nx:run-commands' &&
|
|
153
153
|
/\b(tsc|tsgo)\b/.test(target.options.command)) {
|
|
154
|
-
const
|
|
155
|
-
if (
|
|
156
|
-
const tsConfig = (0, ts_config_1.readTsConfig)(
|
|
154
|
+
const tsConfigPath = resolveTsConfigForRunCommandsTarget(workspaceRoot, sourceProject, target.options);
|
|
155
|
+
if (tsConfigPath) {
|
|
156
|
+
const tsConfig = (0, ts_config_1.readTsConfig)(tsConfigPath);
|
|
157
157
|
if (tsConfig?.options['importHelpers'] &&
|
|
158
158
|
projectGraph.externalNodes['npm:tslib']?.type === 'npm') {
|
|
159
159
|
npmDeps['tslib'] = projectGraph.externalNodes['npm:tslib'].data.version;
|
|
@@ -161,3 +161,24 @@ function collectHelperDependencies(workspaceRoot, sourceProject, projectGraph, b
|
|
|
161
161
|
}
|
|
162
162
|
}
|
|
163
163
|
}
|
|
164
|
+
function resolveTsConfigForRunCommandsTarget(workspaceRoot, sourceProject, targetOptions) {
|
|
165
|
+
const commandTsConfig = extractTsConfigFromCommand(targetOptions.command);
|
|
166
|
+
if (commandTsConfig) {
|
|
167
|
+
const cwd = targetOptions.cwd ?? sourceProject.data.root;
|
|
168
|
+
const cwdAbsolute = (0, path_1.isAbsolute)(cwd) ? cwd : (0, path_1.join)(workspaceRoot, cwd);
|
|
169
|
+
const resolved = (0, path_1.isAbsolute)(commandTsConfig)
|
|
170
|
+
? commandTsConfig
|
|
171
|
+
: (0, path_1.join)(cwdAbsolute, commandTsConfig);
|
|
172
|
+
if ((0, fileutils_1.fileExists)(resolved))
|
|
173
|
+
return resolved;
|
|
174
|
+
}
|
|
175
|
+
// Preserves prior behavior when the tsconfig can't be determined from the command.
|
|
176
|
+
return (0, ts_config_1.getRootTsConfigPath)();
|
|
177
|
+
}
|
|
178
|
+
// Matches the `<compiler> --build <configName>` shape emitted by the
|
|
179
|
+
// `@nx/js/typescript` plugin. Other shapes fall through to the workspace root
|
|
180
|
+
// tsconfig in the caller.
|
|
181
|
+
function extractTsConfigFromCommand(command) {
|
|
182
|
+
const match = command.match(/(?:^|\s)--build\s+([^\s-]\S*)/);
|
|
183
|
+
return match ? match[1] : null;
|
|
184
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-ts-config.d.ts","sourceRoot":"","sources":["../../../../../../packages/js/src/utils/typescript/create-ts-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAG9C,eAAO,MAAM,mBAAmB
|
|
1
|
+
{"version":3,"file":"create-ts-config.d.ts","sourceRoot":"","sources":["../../../../../../packages/js/src/utils/typescript/create-ts-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAG9C,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;CAc/B,CAAC;AAEF,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,IAAI,QA+B7C"}
|
|
@@ -16,7 +16,6 @@ exports.tsConfigBaseOptions = {
|
|
|
16
16
|
lib: ['es2020', 'dom'],
|
|
17
17
|
skipLibCheck: true,
|
|
18
18
|
skipDefaultLibCheck: true,
|
|
19
|
-
baseUrl: '.',
|
|
20
19
|
paths: {},
|
|
21
20
|
};
|
|
22
21
|
function extractTsConfigBase(host) {
|
|
@@ -31,10 +30,6 @@ function extractTsConfigBase(host) {
|
|
|
31
30
|
delete tsconfig.compilerOptions[compilerOption];
|
|
32
31
|
}
|
|
33
32
|
}
|
|
34
|
-
// If we don't set baseDir then builds will fail when more than one projects exist.
|
|
35
|
-
if (typeof baseCompilerOptions.baseUrl === 'undefined') {
|
|
36
|
-
baseCompilerOptions.baseUrl = '.';
|
|
37
|
-
}
|
|
38
33
|
(0, json_1.writeJson)(host, 'tsconfig.base.json', {
|
|
39
34
|
compileOnSave: false,
|
|
40
35
|
compilerOptions: baseCompilerOptions,
|
|
@@ -7,5 +7,19 @@ export declare function getRelativePathToRootTsConfig(tree: Tree, targetPath: st
|
|
|
7
7
|
export declare function getRootTsConfigPath(): string | null;
|
|
8
8
|
export declare function getRootTsConfigFileName(tree?: Tree): string | null;
|
|
9
9
|
export declare function addTsConfigPath(tree: Tree, importPath: string, lookupPaths: string[]): void;
|
|
10
|
+
/**
|
|
11
|
+
* When `baseUrl` is not set and `paths` are inherited via `extends`,
|
|
12
|
+
* tools like `tsconfig-paths` resolve from the loaded file's directory
|
|
13
|
+
* instead of the file where `paths` is defined. This walks the `extends`
|
|
14
|
+
* chain to find the correct resolution base.
|
|
15
|
+
*
|
|
16
|
+
* Returns the directory that `paths` values should be resolved relative to.
|
|
17
|
+
* Walks the tsconfig `extends` chain to find where `paths` is defined, then
|
|
18
|
+
* looks for the applicable `baseUrl` from that point toward the root of the
|
|
19
|
+
* chain (ignoring child overrides that don't apply to the paths-defining
|
|
20
|
+
* tsconfig). When no `baseUrl` applies, returns the directory of the
|
|
21
|
+
* tsconfig that defines `paths`.
|
|
22
|
+
*/
|
|
23
|
+
export declare function resolvePathsBaseUrl(tsconfigPath: string): string;
|
|
10
24
|
export declare function readTsConfigPaths(tsConfig?: string | ts.ParsedCommandLine): ts.MapLike<string[]>;
|
|
11
25
|
//# sourceMappingURL=ts-config.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ts-config.d.ts","sourceRoot":"","sources":["../../../../../../packages/js/src/utils/typescript/ts-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,IAAI,EAA6B,MAAM,YAAY,CAAC;AAG7E,OAAO,KAAK,KAAK,EAAE,MAAM,YAAY,CAAC;AAKtC,wBAAgB,YAAY,CAC1B,YAAY,EAAE,MAAM,EACpB,GAAG,CAAC,EAAE,EAAE,CAAC,MAAM,GACd,EAAE,CAAC,iBAAiB,CAatB;AAED,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,IAAI,EACV,YAAY,EAAE,MAAM,GACnB,EAAE,CAAC,iBAAiB,CAWtB;AAED,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,GAAG,IAAI,CAQnE;AAED,wBAAgB,6BAA6B,CAC3C,IAAI,EAAE,IAAI,EACV,UAAU,EAAE,MAAM,GACjB,MAAM,CAER;AAED,wBAAgB,mBAAmB,IAAI,MAAM,GAAG,IAAI,CAInD;AAED,wBAAgB,uBAAuB,CAAC,IAAI,CAAC,EAAE,IAAI,GAAG,MAAM,GAAG,IAAI,CAYlE;AAED,wBAAgB,eAAe,CAC7B,IAAI,EAAE,IAAI,EACV,UAAU,EAAE,MAAM,EAClB,WAAW,EAAE,MAAM,EAAE,QAiBtB;
|
|
1
|
+
{"version":3,"file":"ts-config.d.ts","sourceRoot":"","sources":["../../../../../../packages/js/src/utils/typescript/ts-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,IAAI,EAA6B,MAAM,YAAY,CAAC;AAG7E,OAAO,KAAK,KAAK,EAAE,MAAM,YAAY,CAAC;AAKtC,wBAAgB,YAAY,CAC1B,YAAY,EAAE,MAAM,EACpB,GAAG,CAAC,EAAE,EAAE,CAAC,MAAM,GACd,EAAE,CAAC,iBAAiB,CAatB;AAED,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,IAAI,EACV,YAAY,EAAE,MAAM,GACnB,EAAE,CAAC,iBAAiB,CAWtB;AAED,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,GAAG,IAAI,CAQnE;AAED,wBAAgB,6BAA6B,CAC3C,IAAI,EAAE,IAAI,EACV,UAAU,EAAE,MAAM,GACjB,MAAM,CAER;AAED,wBAAgB,mBAAmB,IAAI,MAAM,GAAG,IAAI,CAInD;AAED,wBAAgB,uBAAuB,CAAC,IAAI,CAAC,EAAE,IAAI,GAAG,MAAM,GAAG,IAAI,CAYlE;AAED,wBAAgB,eAAe,CAC7B,IAAI,EAAE,IAAI,EACV,UAAU,EAAE,MAAM,EAClB,WAAW,EAAE,MAAM,EAAE,QAiBtB;AASD;;;;;;;;;;;;GAYG;AACH,wBAAgB,mBAAmB,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAmDhE;AAgCD,wBAAgB,iBAAiB,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,EAAE,CAAC,iBAAiB,wBA+BzE"}
|
|
@@ -7,6 +7,7 @@ exports.getRelativePathToRootTsConfig = getRelativePathToRootTsConfig;
|
|
|
7
7
|
exports.getRootTsConfigPath = getRootTsConfigPath;
|
|
8
8
|
exports.getRootTsConfigFileName = getRootTsConfigFileName;
|
|
9
9
|
exports.addTsConfigPath = addTsConfigPath;
|
|
10
|
+
exports.resolvePathsBaseUrl = resolvePathsBaseUrl;
|
|
10
11
|
exports.readTsConfigPaths = readTsConfigPaths;
|
|
11
12
|
const devkit_1 = require("@nx/devkit");
|
|
12
13
|
const fs_1 = require("fs");
|
|
@@ -65,30 +66,130 @@ function addTsConfigPath(tree, importPath, lookupPaths) {
|
|
|
65
66
|
if (c.paths[importPath]) {
|
|
66
67
|
throw new Error(`You already have a library using the import path "${importPath}". Make sure to specify a unique one.`);
|
|
67
68
|
}
|
|
68
|
-
c.paths[importPath] = lookupPaths;
|
|
69
|
+
c.paths[importPath] = lookupPaths.map(ensureRelativePath);
|
|
69
70
|
return json;
|
|
70
71
|
});
|
|
71
72
|
}
|
|
73
|
+
function ensureRelativePath(p) {
|
|
74
|
+
if (p.startsWith('./') || p.startsWith('../') || p.startsWith('/')) {
|
|
75
|
+
return p;
|
|
76
|
+
}
|
|
77
|
+
return `./${p}`;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* When `baseUrl` is not set and `paths` are inherited via `extends`,
|
|
81
|
+
* tools like `tsconfig-paths` resolve from the loaded file's directory
|
|
82
|
+
* instead of the file where `paths` is defined. This walks the `extends`
|
|
83
|
+
* chain to find the correct resolution base.
|
|
84
|
+
*
|
|
85
|
+
* Returns the directory that `paths` values should be resolved relative to.
|
|
86
|
+
* Walks the tsconfig `extends` chain to find where `paths` is defined, then
|
|
87
|
+
* looks for the applicable `baseUrl` from that point toward the root of the
|
|
88
|
+
* chain (ignoring child overrides that don't apply to the paths-defining
|
|
89
|
+
* tsconfig). When no `baseUrl` applies, returns the directory of the
|
|
90
|
+
* tsconfig that defines `paths`.
|
|
91
|
+
*/
|
|
92
|
+
function resolvePathsBaseUrl(tsconfigPath) {
|
|
93
|
+
const chain = [];
|
|
94
|
+
const queue = [tsconfigPath];
|
|
95
|
+
while (queue.length > 0) {
|
|
96
|
+
const absolute = (0, path_1.resolve)(queue.shift());
|
|
97
|
+
const dir = (0, path_1.dirname)(absolute);
|
|
98
|
+
try {
|
|
99
|
+
const raw = JSON.parse((0, fs_1.readFileSync)(absolute, 'utf-8'));
|
|
100
|
+
chain.push({ dir, raw });
|
|
101
|
+
const exts = raw.extends
|
|
102
|
+
? Array.isArray(raw.extends)
|
|
103
|
+
? raw.extends
|
|
104
|
+
: [raw.extends]
|
|
105
|
+
: [];
|
|
106
|
+
for (const ext of exts) {
|
|
107
|
+
const resolved = resolveExtendsPath(ext, dir);
|
|
108
|
+
if (resolved) {
|
|
109
|
+
queue.push(resolved);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
catch {
|
|
114
|
+
// skip unreadable files
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
// Find where paths is defined.
|
|
118
|
+
let pathsIndex = -1;
|
|
119
|
+
for (let i = 0; i < chain.length; i++) {
|
|
120
|
+
if (chain[i].raw.compilerOptions?.paths &&
|
|
121
|
+
Object.keys(chain[i].raw.compilerOptions.paths).length > 0) {
|
|
122
|
+
pathsIndex = i;
|
|
123
|
+
break;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
// Find the applicable baseUrl: search from the paths-defining tsconfig
|
|
127
|
+
// toward the root. Child overrides before the paths-defining tsconfig
|
|
128
|
+
// are ignored — they don't apply to the paths that were written for a
|
|
129
|
+
// different baseUrl context.
|
|
130
|
+
const searchStart = pathsIndex >= 0 ? pathsIndex : 0;
|
|
131
|
+
for (let i = searchStart; i < chain.length; i++) {
|
|
132
|
+
if (chain[i].raw.compilerOptions?.baseUrl) {
|
|
133
|
+
return (0, path_1.resolve)(chain[i].dir, chain[i].raw.compilerOptions.baseUrl);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return pathsIndex >= 0
|
|
137
|
+
? chain[pathsIndex].dir
|
|
138
|
+
: (0, path_1.dirname)((0, path_1.resolve)(tsconfigPath));
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Resolves a tsconfig `extends` entry to an absolute path.
|
|
142
|
+
* Handles relative paths, absolute paths, and package names
|
|
143
|
+
* (e.g., `@tsconfig/node20/tsconfig.json` or `@tsconfig/strictest`).
|
|
144
|
+
* Mirrors TypeScript's resolution: relative/absolute paths are resolved
|
|
145
|
+
* directly (with `.json` fallback), package names use `require.resolve`
|
|
146
|
+
* with a `tsconfig.json` fallback for bare package names.
|
|
147
|
+
*/
|
|
148
|
+
function resolveExtendsPath(ext, fromDir) {
|
|
149
|
+
if (ext.startsWith('.') || (0, path_1.isAbsolute)(ext)) {
|
|
150
|
+
let resolved = (0, path_1.resolve)(fromDir, ext);
|
|
151
|
+
if ((0, fs_1.existsSync)(resolved))
|
|
152
|
+
return resolved;
|
|
153
|
+
if (!resolved.endsWith('.json')) {
|
|
154
|
+
resolved += '.json';
|
|
155
|
+
if ((0, fs_1.existsSync)(resolved))
|
|
156
|
+
return resolved;
|
|
157
|
+
}
|
|
158
|
+
return null;
|
|
159
|
+
}
|
|
160
|
+
// Package name — try as-is, then with /tsconfig.json appended
|
|
161
|
+
try {
|
|
162
|
+
return require.resolve(ext, { paths: [fromDir] });
|
|
163
|
+
}
|
|
164
|
+
catch {
|
|
165
|
+
try {
|
|
166
|
+
return require.resolve(`${ext}/tsconfig.json`, { paths: [fromDir] });
|
|
167
|
+
}
|
|
168
|
+
catch {
|
|
169
|
+
return null;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
72
173
|
function readTsConfigPaths(tsConfig) {
|
|
73
174
|
tsConfig ??= getRootTsConfigPath();
|
|
74
175
|
try {
|
|
75
|
-
if (!tsModule) {
|
|
76
|
-
tsModule = (0, ensure_typescript_1.ensureTypescript)();
|
|
77
|
-
}
|
|
78
176
|
let config;
|
|
79
177
|
if (typeof tsConfig === 'string') {
|
|
178
|
+
if (!tsModule) {
|
|
179
|
+
tsModule = (0, ensure_typescript_1.ensureTypescript)();
|
|
180
|
+
}
|
|
80
181
|
const configFile = tsModule.readConfigFile(tsConfig, tsModule.sys.readFile);
|
|
81
|
-
|
|
182
|
+
// Stub `readDirectory` to skip the source-file scan — only `paths` is consumed.
|
|
183
|
+
const parseConfigHost = {
|
|
184
|
+
...tsModule.sys,
|
|
185
|
+
readDirectory: () => [],
|
|
186
|
+
};
|
|
187
|
+
config = tsModule.parseJsonConfigFileContent(configFile.config, parseConfigHost, (0, path_1.dirname)(tsConfig));
|
|
82
188
|
}
|
|
83
189
|
else {
|
|
84
190
|
config = tsConfig;
|
|
85
191
|
}
|
|
86
|
-
|
|
87
|
-
return config.options.paths;
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
90
|
-
return null;
|
|
91
|
-
}
|
|
192
|
+
return config.options?.paths ?? null;
|
|
92
193
|
}
|
|
93
194
|
catch (e) {
|
|
94
195
|
return null;
|