@nx/js 23.0.0-beta.18 → 23.0.0-beta.19
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.
|
@@ -91,19 +91,34 @@ function collectCallExpressionRewrites(sourceFile, changes) {
|
|
|
91
91
|
shouldRewriteSpecifier(node.arguments[0].text)) {
|
|
92
92
|
replaceSpecifier(sourceFile, node.arguments[0], changes);
|
|
93
93
|
}
|
|
94
|
+
else if (ts.isImportTypeNode(node)) {
|
|
95
|
+
// `typeof import('...')` parses as an `ImportTypeNode`, not a
|
|
96
|
+
// CallExpression — its argument is `LiteralTypeNode<StringLiteral>`.
|
|
97
|
+
// The whole module is referenced, so it can't be symbol-split.
|
|
98
|
+
const literal = getImportTypeStringLiteral(node);
|
|
99
|
+
if (literal && shouldRewriteSpecifier(literal.text)) {
|
|
100
|
+
replaceSpecifier(sourceFile, literal, changes);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
94
103
|
ts.forEachChild(node, visit);
|
|
95
104
|
};
|
|
96
105
|
visit(sourceFile);
|
|
97
106
|
}
|
|
107
|
+
function getImportTypeStringLiteral(node) {
|
|
108
|
+
const arg = node.argument;
|
|
109
|
+
if (arg && ts.isLiteralTypeNode(arg) && ts.isStringLiteral(arg.literal)) {
|
|
110
|
+
return arg.literal;
|
|
111
|
+
}
|
|
112
|
+
return undefined;
|
|
113
|
+
}
|
|
98
114
|
function shouldRewriteCallExpression(call) {
|
|
99
115
|
const callee = call.expression;
|
|
100
116
|
// `require('...')`
|
|
101
117
|
if (ts.isIdentifier(callee) && callee.text === 'require')
|
|
102
118
|
return true;
|
|
103
119
|
// dynamic `import('...')` (runtime form parses as a CallExpression whose
|
|
104
|
-
// callee is the `import` keyword). The type-position
|
|
105
|
-
//
|
|
106
|
-
// we don't touch it.
|
|
120
|
+
// callee is the `import` keyword). The `typeof import('...')` type-position
|
|
121
|
+
// form is an `ImportTypeNode` (handled in `collectCallExpressionRewrites`).
|
|
107
122
|
if (callee.kind === ts.SyntaxKind.ImportKeyword)
|
|
108
123
|
return true;
|
|
109
124
|
// `jest.mock(...)` / `vi.mock(...)` and friends.
|
|
@@ -10,8 +10,20 @@ const picomatch = require("picomatch");
|
|
|
10
10
|
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
|
|
11
11
|
const lock_file_1 = require("nx/src/plugins/js/lock-file/lock-file");
|
|
12
12
|
const cache_directory_1 = require("nx/src/utils/cache-directory");
|
|
13
|
+
const installation_directory_1 = require("nx/src/utils/installation-directory");
|
|
13
14
|
const util_1 = require("./util");
|
|
14
15
|
let ts;
|
|
16
|
+
const resolvedTypescriptPaths = {};
|
|
17
|
+
function resolveTypescriptPath(projectRoot, workspaceRoot) {
|
|
18
|
+
// Resolve from projectRoot first, then workspace paths, with __dirname as a
|
|
19
|
+
// last resort. Required so the lookup works under layouts where @nx/js's real
|
|
20
|
+
// path is outside the workspace tree (e.g. pnpm's enableGlobalVirtualStore),
|
|
21
|
+
// since typescript is not a declared dep.
|
|
22
|
+
resolvedTypescriptPaths[projectRoot] ??= require.resolve('typescript', {
|
|
23
|
+
paths: [projectRoot, ...(0, installation_directory_1.getNxRequirePaths)(workspaceRoot), __dirname],
|
|
24
|
+
});
|
|
25
|
+
return resolvedTypescriptPaths[projectRoot];
|
|
26
|
+
}
|
|
15
27
|
const TSCONFIG_CACHE_VERSION = 2;
|
|
16
28
|
const TS_CONFIG_CACHE_PATH = (0, node_path_1.join)(cache_directory_1.workspaceDataDirectory, 'tsconfig-files.hash');
|
|
17
29
|
// Module-level cache store — each invocation gets a unique Symbol key
|
|
@@ -356,7 +368,7 @@ function getInputs(namedInputs, config, tsConfig, internalProjectReferences, wor
|
|
|
356
368
|
];
|
|
357
369
|
const absoluteProjectRoot = config.project.absolute;
|
|
358
370
|
if (!ts) {
|
|
359
|
-
ts = require(
|
|
371
|
+
ts = require(resolveTypescriptPath(absoluteProjectRoot, workspaceRoot));
|
|
360
372
|
}
|
|
361
373
|
// https://github.com/microsoft/TypeScript/blob/19b777260b26aac5707b1efd34202054164d4a9d/src/compiler/utilities.ts#L9869
|
|
362
374
|
const supportedTSExtensions = [
|
|
@@ -821,7 +833,7 @@ function getExtendedFilesHash(extendedConfigFiles, workspaceRoot, cache) {
|
|
|
821
833
|
}
|
|
822
834
|
function readTsConfig(tsConfigPath, workspaceRoot, cache) {
|
|
823
835
|
if (!ts) {
|
|
824
|
-
ts = require(
|
|
836
|
+
ts = require(resolveTypescriptPath(workspaceRoot, workspaceRoot));
|
|
825
837
|
}
|
|
826
838
|
// Normalize to forward slashes for TypeScript compatibility on Windows.
|
|
827
839
|
// TypeScript's parser normalizes paths inconsistently — diagnostics use
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/js",
|
|
3
|
-
"version": "23.0.0-beta.
|
|
3
|
+
"version": "23.0.0-beta.19",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"files": [
|
|
@@ -136,11 +136,11 @@
|
|
|
136
136
|
"source-map-support": "0.5.19",
|
|
137
137
|
"tinyglobby": "^0.2.12",
|
|
138
138
|
"tslib": "^2.3.0",
|
|
139
|
-
"@nx/
|
|
140
|
-
"@nx/
|
|
139
|
+
"@nx/workspace": "23.0.0-beta.19",
|
|
140
|
+
"@nx/devkit": "23.0.0-beta.19"
|
|
141
141
|
},
|
|
142
142
|
"devDependencies": {
|
|
143
|
-
"nx": "23.0.0-beta.
|
|
143
|
+
"nx": "23.0.0-beta.19"
|
|
144
144
|
},
|
|
145
145
|
"peerDependencies": {
|
|
146
146
|
"@swc/cli": ">=0.6.0 <0.9.0",
|