@nx/js 22.5.2 → 22.5.3
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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/js",
|
|
3
|
-
"version": "22.5.
|
|
3
|
+
"version": "22.5.3",
|
|
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,8 +39,8 @@
|
|
|
39
39
|
"@babel/preset-env": "^7.23.2",
|
|
40
40
|
"@babel/preset-typescript": "^7.22.5",
|
|
41
41
|
"@babel/runtime": "^7.22.6",
|
|
42
|
-
"@nx/devkit": "22.5.
|
|
43
|
-
"@nx/workspace": "22.5.
|
|
42
|
+
"@nx/devkit": "22.5.3",
|
|
43
|
+
"@nx/workspace": "22.5.3",
|
|
44
44
|
"@zkochan/js-yaml": "0.0.7",
|
|
45
45
|
"babel-plugin-const-enum": "^1.0.1",
|
|
46
46
|
"babel-plugin-macros": "^3.1.0",
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"tslib": "^2.3.0"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
|
-
"nx": "22.5.
|
|
63
|
+
"nx": "22.5.3"
|
|
64
64
|
},
|
|
65
65
|
"peerDependencies": {
|
|
66
66
|
"verdaccio": "^6.0.5"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"library.d.ts","sourceRoot":"","sources":["../../../../../../packages/js/src/generators/library/library.ts"],"names":[],"mappings":"AAAA,OAAO,EAML,iBAAiB,EAUjB,IAAI,EAKL,MAAM,YAAY,CAAC;AAyCpB,OAAO,KAAK,EAEV,sBAAsB,EACtB,iCAAiC,EAClC,MAAM,UAAU,CAAC;AASlB,wBAAsB,gBAAgB,CACpC,IAAI,EAAE,IAAI,EACV,MAAM,EAAE,sBAAsB,8BAO/B;AAED,wBAAsB,wBAAwB,CAC5C,IAAI,EAAE,IAAI,EACV,MAAM,EAAE,sBAAsB,
|
|
1
|
+
{"version":3,"file":"library.d.ts","sourceRoot":"","sources":["../../../../../../packages/js/src/generators/library/library.ts"],"names":[],"mappings":"AAAA,OAAO,EAML,iBAAiB,EAUjB,IAAI,EAKL,MAAM,YAAY,CAAC;AAyCpB,OAAO,KAAK,EAEV,sBAAsB,EACtB,iCAAiC,EAClC,MAAM,UAAU,CAAC;AASlB,wBAAsB,gBAAgB,CACpC,IAAI,EAAE,IAAI,EACV,MAAM,EAAE,sBAAsB,8BAO/B;AAED,wBAAsB,wBAAwB,CAC5C,IAAI,EAAE,IAAI,EACV,MAAM,EAAE,sBAAsB,8BAqK/B;AA2HD,MAAM,MAAM,cAAc,GAAG,IAAI,CAC/B,iCAAiC,EAC/B,MAAM,GACN,QAAQ,GACR,aAAa,GACb,gBAAgB,GAChB,IAAI,GACJ,yBAAyB,GACzB,aAAa,GACb,SAAS,GACT,WAAW,GACX,yBAAyB,CAC5B,CAAC;AAEF,wBAAsB,OAAO,CAC3B,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,cAAc,GACtB,OAAO,CAAC,iBAAiB,CAAC,CA4G5B;AA6uBD,eAAe,gBAAgB,CAAC"}
|
|
@@ -99,7 +99,6 @@ async function libraryGeneratorInternal(tree, schema) {
|
|
|
99
99
|
else if (options.unitTestRunner === 'vitest' &&
|
|
100
100
|
options.bundler !== 'vite' // Test would have been set up already
|
|
101
101
|
) {
|
|
102
|
-
const { createOrEditViteConfig } = (0, devkit_1.ensurePackage)('@nx/vite', versions_1.nxVersion);
|
|
103
102
|
(0, devkit_1.ensurePackage)('@nx/vitest', versions_1.nxVersion);
|
|
104
103
|
// nx-ignore-next-line
|
|
105
104
|
const { configurationGenerator } = require('@nx/vitest/generators');
|
|
@@ -114,12 +113,6 @@ async function libraryGeneratorInternal(tree, schema) {
|
|
|
114
113
|
addPlugin: options.addPlugin,
|
|
115
114
|
});
|
|
116
115
|
tasks.push(vitestTask);
|
|
117
|
-
createOrEditViteConfig(tree, {
|
|
118
|
-
project: options.name,
|
|
119
|
-
includeLib: false,
|
|
120
|
-
includeVitest: true,
|
|
121
|
-
testEnvironment: options.testEnvironment,
|
|
122
|
-
}, true);
|
|
123
116
|
}
|
|
124
117
|
if (!schema.skipTsConfig && !options.isUsingTsSolutionConfig) {
|
|
125
118
|
(0, ts_config_1.addTsConfigPath)(tree, options.importPath, [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../../../../../packages/js/src/plugins/typescript/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAQL,KAAK,kBAAkB,EAEvB,KAAK,aAAa,EAInB,MAAM,YAAY,CAAC;AAgCpB,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;IAC1B,SAAS,CAAC,EACN,OAAO,GACP;QACE,UAAU,CAAC,EAAE,MAAM,CAAC;KACrB,CAAC;IACN,KAAK,CAAC,EACF,OAAO,GACP;QACE,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,aAAa,CAAC,EAAE,MAAM,CAAC;QACvB,aAAa,CAAC,EAAE,MAAM,CAAC;QACvB,cAAc,CAAC,EAAE,OAAO,CAAC;KAC1B,CAAC;IACN,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../../../../../packages/js/src/plugins/typescript/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAQL,KAAK,kBAAkB,EAEvB,KAAK,aAAa,EAInB,MAAM,YAAY,CAAC;AAgCpB,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;IAC1B,SAAS,CAAC,EACN,OAAO,GACP;QACE,UAAU,CAAC,EAAE,MAAM,CAAC;KACrB,CAAC;IACN,KAAK,CAAC,EACF,OAAO,GACP;QACE,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,aAAa,CAAC,EAAE,MAAM,CAAC;QACvB,aAAa,CAAC,EAAE,MAAM,CAAC;QACvB,cAAc,CAAC,EAAE,OAAO,CAAC;KAC1B,CAAC;IACN,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AA0KD;;GAEG;AACH,eAAO,MAAM,kBAAkB,EAAE,kBAEhC,CAAC;AAEF,eAAO,MAAM,WAAW,sBAAsB,CAAC;AAI/C,eAAO,MAAM,aAAa,EAAE,aAAa,CAAC,gBAAgB,CA0FzD,CAAC;AAEF,eAAO,MAAM,WAAW,iCAAgB,CAAC"}
|
|
@@ -16,8 +16,11 @@ let ts;
|
|
|
16
16
|
const pmc = (0, devkit_1.getPackageManagerCommand)();
|
|
17
17
|
const TSCONFIG_CACHE_VERSION = 1;
|
|
18
18
|
const TS_CONFIG_CACHE_PATH = (0, node_path_1.join)(cache_directory_1.workspaceDataDirectory, 'tsconfig-files.hash');
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
// Module-level cache store — each invocation gets a unique Symbol key
|
|
20
|
+
const cacheStore = new Map();
|
|
21
|
+
// Shared tsconfig cache — initialized once per batch, persisted to disk
|
|
22
|
+
let tsConfigCacheData = {};
|
|
23
|
+
let tsConfigCacheInitialized = false;
|
|
21
24
|
function readFromCache(cachePath) {
|
|
22
25
|
try {
|
|
23
26
|
return process.env.NX_CACHE_PROJECT_GRAPH !== 'false'
|
|
@@ -71,7 +74,7 @@ function createConfigContext(configFilePath, workspaceRoot, projectContext) {
|
|
|
71
74
|
project: projectContext,
|
|
72
75
|
};
|
|
73
76
|
}
|
|
74
|
-
function getConfigContext(configPath, workspaceRoot) {
|
|
77
|
+
function getConfigContext(configPath, workspaceRoot, cache) {
|
|
75
78
|
const absolutePath = configPath.startsWith('/') || configPath.startsWith(workspaceRoot)
|
|
76
79
|
? (0, node_path_1.normalize)(configPath)
|
|
77
80
|
: (0, node_path_1.join)(workspaceRoot, configPath);
|
|
@@ -107,7 +110,9 @@ exports.createNodesV2 = [
|
|
|
107
110
|
const optionsHash = (0, file_hasher_1.hashObject)(options);
|
|
108
111
|
const targetsCachePath = (0, node_path_1.join)(cache_directory_1.workspaceDataDirectory, `tsc-${optionsHash}.hash`);
|
|
109
112
|
const targetsCache = readFromCache(targetsCachePath);
|
|
110
|
-
|
|
113
|
+
// Each invocation gets a unique Symbol key — guaranteed no collisions
|
|
114
|
+
const cacheKey = Symbol('tsc-invocation');
|
|
115
|
+
cacheStore.set(cacheKey, {
|
|
111
116
|
fileHashes: {},
|
|
112
117
|
rawFiles: {},
|
|
113
118
|
picomatchMatchers: {},
|
|
@@ -115,19 +120,20 @@ exports.createNodesV2 = [
|
|
|
115
120
|
configOwners: new Map(),
|
|
116
121
|
projectContexts: new Map(),
|
|
117
122
|
configContexts: new Map(),
|
|
118
|
-
};
|
|
119
|
-
|
|
123
|
+
});
|
|
124
|
+
const cache = cacheStore.get(cacheKey);
|
|
125
|
+
initializeTsConfigCache(configFilePaths, context.workspaceRoot, cache);
|
|
120
126
|
const normalizedOptions = normalizePluginOptions(options);
|
|
121
|
-
const { configFilePaths: validConfigFilePaths, hashes, projectRoots, } = await resolveValidConfigFilesAndHashes(configFilePaths, normalizedOptions, optionsHash, context);
|
|
127
|
+
const { configFilePaths: validConfigFilePaths, hashes, projectRoots, } = await resolveValidConfigFilesAndHashes(configFilePaths, normalizedOptions, optionsHash, context, cache);
|
|
122
128
|
try {
|
|
123
129
|
return await (0, devkit_1.createNodesFromFiles)((configFilePath, options, context, idx) => {
|
|
124
130
|
const projectRoot = projectRoots[idx];
|
|
125
131
|
const hash = hashes[idx];
|
|
126
|
-
const
|
|
132
|
+
const targetsCacheKey = `${hash}_${configFilePath}`;
|
|
127
133
|
const absolutePath = (0, node_path_1.join)(context.workspaceRoot, configFilePath);
|
|
128
|
-
const configContext = getConfigContext(absolutePath, context.workspaceRoot);
|
|
129
|
-
targetsCache[
|
|
130
|
-
const { targets } = targetsCache[
|
|
134
|
+
const configContext = getConfigContext(absolutePath, context.workspaceRoot, cache);
|
|
135
|
+
targetsCache[targetsCacheKey] ??= buildTscTargets(configContext, options, context, validConfigFilePaths, cache);
|
|
136
|
+
const { targets } = targetsCache[targetsCacheKey];
|
|
131
137
|
return {
|
|
132
138
|
projects: {
|
|
133
139
|
[projectRoot]: {
|
|
@@ -140,13 +146,18 @@ exports.createNodesV2 = [
|
|
|
140
146
|
finally {
|
|
141
147
|
writeToCache(targetsCachePath, targetsCache);
|
|
142
148
|
writeTsConfigCache(toRelativePaths(tsConfigCacheData, context.workspaceRoot));
|
|
143
|
-
//
|
|
144
|
-
|
|
149
|
+
// Delete this invocation's cache — unique Symbol means no cross-invocation impact
|
|
150
|
+
cacheStore.delete(cacheKey);
|
|
151
|
+
// Reset shared tsconfig cache when all invocations are done
|
|
152
|
+
if (cacheStore.size === 0) {
|
|
153
|
+
tsConfigCacheData = {};
|
|
154
|
+
tsConfigCacheInitialized = false;
|
|
155
|
+
}
|
|
145
156
|
}
|
|
146
157
|
},
|
|
147
158
|
];
|
|
148
159
|
exports.createNodes = exports.createNodesV2;
|
|
149
|
-
async function resolveValidConfigFilesAndHashes(configFilePaths, options, optionsHash, context) {
|
|
160
|
+
async function resolveValidConfigFilesAndHashes(configFilePaths, options, optionsHash, context, cache) {
|
|
150
161
|
const lockFileHash = (0, file_hasher_1.hashFile)((0, node_path_1.join)(context.workspaceRoot, (0, lock_file_1.getLockFileName)((0, devkit_1.detectPackageManager)(context.workspaceRoot)))) ?? '';
|
|
151
162
|
const validConfigFilePaths = [];
|
|
152
163
|
const hashes = [];
|
|
@@ -154,19 +165,19 @@ async function resolveValidConfigFilesAndHashes(configFilePaths, options, option
|
|
|
154
165
|
for await (const configFilePath of configFilePaths) {
|
|
155
166
|
const projectRoot = (0, node_path_1.dirname)(configFilePath);
|
|
156
167
|
const absolutePath = (0, node_path_1.join)(context.workspaceRoot, configFilePath);
|
|
157
|
-
const configContext = getConfigContext(absolutePath, context.workspaceRoot);
|
|
168
|
+
const configContext = getConfigContext(absolutePath, context.workspaceRoot, cache);
|
|
158
169
|
// Skip configs that can't produce any targets based on plugin options
|
|
159
170
|
const isTypecheckConfig = configContext.basename === 'tsconfig.json';
|
|
160
171
|
const isBuildConfig = options.build && configContext.basename === options.build.configName;
|
|
161
172
|
if (!isTypecheckConfig && !isBuildConfig) {
|
|
162
173
|
continue;
|
|
163
174
|
}
|
|
164
|
-
if (!checkIfConfigFileShouldBeProject(configContext)) {
|
|
175
|
+
if (!checkIfConfigFileShouldBeProject(configContext, cache)) {
|
|
165
176
|
continue;
|
|
166
177
|
}
|
|
167
178
|
projectRoots.push(projectRoot);
|
|
168
179
|
validConfigFilePaths.push(configFilePath);
|
|
169
|
-
hashes.push(await getConfigFileHash(configFilePath, context.workspaceRoot, configContext.project, optionsHash, lockFileHash));
|
|
180
|
+
hashes.push(await getConfigFileHash(configFilePath, context.workspaceRoot, configContext.project, optionsHash, lockFileHash, cache));
|
|
170
181
|
}
|
|
171
182
|
return { configFilePaths: validConfigFilePaths, hashes, projectRoots };
|
|
172
183
|
}
|
|
@@ -182,12 +193,12 @@ async function resolveValidConfigFilesAndHashes(configFilePaths, options, option
|
|
|
182
193
|
* - hash of the plugin options
|
|
183
194
|
* - current config file path
|
|
184
195
|
*/
|
|
185
|
-
async function getConfigFileHash(configFilePath, workspaceRoot, project, optionsHash, lockFileHash) {
|
|
196
|
+
async function getConfigFileHash(configFilePath, workspaceRoot, project, optionsHash, lockFileHash, cache) {
|
|
186
197
|
const fullConfigPath = (0, node_path_1.join)(workspaceRoot, configFilePath);
|
|
187
|
-
const tsConfig = retrieveTsConfigFromCache(fullConfigPath, workspaceRoot);
|
|
188
|
-
const extendedConfigFiles = getExtendedConfigFiles(tsConfig, workspaceRoot);
|
|
189
|
-
const internalReferencedFiles = resolveInternalProjectReferences(tsConfig, workspaceRoot, project);
|
|
190
|
-
const externalProjectReferences = resolveShallowExternalProjectReferences(tsConfig, workspaceRoot, project);
|
|
198
|
+
const tsConfig = retrieveTsConfigFromCache(fullConfigPath, workspaceRoot, cache);
|
|
199
|
+
const extendedConfigFiles = getExtendedConfigFiles(tsConfig, workspaceRoot, cache);
|
|
200
|
+
const internalReferencedFiles = resolveInternalProjectReferences(tsConfig, workspaceRoot, project, cache);
|
|
201
|
+
const externalProjectReferences = resolveShallowExternalProjectReferences(tsConfig, workspaceRoot, project, cache);
|
|
191
202
|
let packageJson = null;
|
|
192
203
|
try {
|
|
193
204
|
packageJson = (0, devkit_1.readJsonFile)((0, node_path_1.join)(workspaceRoot, project.root, 'package.json'));
|
|
@@ -199,14 +210,14 @@ async function getConfigFileHash(configFilePath, workspaceRoot, project, options
|
|
|
199
210
|
...extendedConfigFiles.files.sort(),
|
|
200
211
|
...Object.keys(internalReferencedFiles).sort(),
|
|
201
212
|
...Object.keys(externalProjectReferences).sort(),
|
|
202
|
-
].map((file) => getFileHash(file, workspaceRoot)),
|
|
213
|
+
].map((file) => getFileHash(file, workspaceRoot, cache)),
|
|
203
214
|
...extendedConfigFiles.packages.sort(),
|
|
204
215
|
lockFileHash,
|
|
205
216
|
optionsHash,
|
|
206
217
|
...(packageJson ? [(0, file_hasher_1.hashObject)(packageJson)] : []),
|
|
207
218
|
]);
|
|
208
219
|
}
|
|
209
|
-
function checkIfConfigFileShouldBeProject(config) {
|
|
220
|
+
function checkIfConfigFileShouldBeProject(config, cache) {
|
|
210
221
|
// Do not create a project for the workspace root tsconfig files.
|
|
211
222
|
if (config.project.root === '.') {
|
|
212
223
|
return false;
|
|
@@ -233,16 +244,16 @@ function checkIfConfigFileShouldBeProject(config) {
|
|
|
233
244
|
}
|
|
234
245
|
return true;
|
|
235
246
|
}
|
|
236
|
-
function buildTscTargets(config, options, context, configFiles) {
|
|
247
|
+
function buildTscTargets(config, options, context, configFiles, cache) {
|
|
237
248
|
const targets = {};
|
|
238
249
|
const namedInputs = (0, get_named_inputs_1.getNamedInputs)(config.project.root, context);
|
|
239
|
-
const tsConfig = retrieveTsConfigFromCache(config.absolutePath, context.workspaceRoot);
|
|
250
|
+
const tsConfig = retrieveTsConfigFromCache(config.absolutePath, context.workspaceRoot, cache);
|
|
240
251
|
let internalProjectReferences;
|
|
241
252
|
if (config.basename === 'tsconfig.json' &&
|
|
242
253
|
options.typecheck &&
|
|
243
254
|
tsConfig.raw?.['nx']?.addTypecheckTarget !== false) {
|
|
244
|
-
internalProjectReferences = resolveInternalProjectReferences(tsConfig, context.workspaceRoot, config.project);
|
|
245
|
-
const externalProjectReferences = resolveShallowExternalProjectReferences(tsConfig, context.workspaceRoot, config.project);
|
|
255
|
+
internalProjectReferences = resolveInternalProjectReferences(tsConfig, context.workspaceRoot, config.project, cache);
|
|
256
|
+
const externalProjectReferences = resolveShallowExternalProjectReferences(tsConfig, context.workspaceRoot, config.project, cache);
|
|
246
257
|
const targetName = options.typecheck.targetName;
|
|
247
258
|
const compiler = options.compiler;
|
|
248
259
|
if (!targets[targetName]) {
|
|
@@ -263,7 +274,7 @@ function buildTscTargets(config, options, context, configFiles) {
|
|
|
263
274
|
const buildConfigPath = (0, devkit_1.joinPathFragments)(config.project.root, options.build.configName);
|
|
264
275
|
if (configFiles.some((f) => f === buildConfigPath) &&
|
|
265
276
|
(options.build.skipBuildCheck ||
|
|
266
|
-
(0, util_1.isValidPackageJsonBuildConfig)(retrieveTsConfigFromCache(buildConfigPath, context.workspaceRoot), context.workspaceRoot, config.project.root))) {
|
|
277
|
+
(0, util_1.isValidPackageJsonBuildConfig)(retrieveTsConfigFromCache(buildConfigPath, context.workspaceRoot, cache), context.workspaceRoot, config.project.root))) {
|
|
267
278
|
dependsOn.unshift(options.build.targetName);
|
|
268
279
|
}
|
|
269
280
|
}
|
|
@@ -272,7 +283,7 @@ function buildTscTargets(config, options, context, configFiles) {
|
|
|
272
283
|
command,
|
|
273
284
|
options: { cwd: config.project.root },
|
|
274
285
|
cache: true,
|
|
275
|
-
inputs: getInputs(namedInputs, config, tsConfig, internalProjectReferences, context.workspaceRoot),
|
|
286
|
+
inputs: getInputs(namedInputs, config, tsConfig, internalProjectReferences, context.workspaceRoot, cache),
|
|
276
287
|
outputs: getOutputs(config, tsConfig, internalProjectReferences, context.workspaceRoot,
|
|
277
288
|
/* emitDeclarationOnly */ true),
|
|
278
289
|
syncGenerators: ['@nx/js:typescript-sync'],
|
|
@@ -294,7 +305,7 @@ function buildTscTargets(config, options, context, configFiles) {
|
|
|
294
305
|
config.basename === options.build.configName &&
|
|
295
306
|
(options.build.skipBuildCheck ||
|
|
296
307
|
(0, util_1.isValidPackageJsonBuildConfig)(tsConfig, context.workspaceRoot, config.project.root))) {
|
|
297
|
-
internalProjectReferences ??= resolveInternalProjectReferences(tsConfig, context.workspaceRoot, config.project);
|
|
308
|
+
internalProjectReferences ??= resolveInternalProjectReferences(tsConfig, context.workspaceRoot, config.project, cache);
|
|
298
309
|
const targetName = options.build.targetName;
|
|
299
310
|
const compiler = options.compiler;
|
|
300
311
|
targets[targetName] = {
|
|
@@ -302,7 +313,7 @@ function buildTscTargets(config, options, context, configFiles) {
|
|
|
302
313
|
command: `${compiler} --build ${options.build.configName}${options.verboseOutput ? ' --verbose' : ''}`,
|
|
303
314
|
options: { cwd: config.project.root },
|
|
304
315
|
cache: true,
|
|
305
|
-
inputs: getInputs(namedInputs, config, tsConfig, internalProjectReferences, context.workspaceRoot),
|
|
316
|
+
inputs: getInputs(namedInputs, config, tsConfig, internalProjectReferences, context.workspaceRoot, cache),
|
|
306
317
|
outputs: getOutputs(config, tsConfig, internalProjectReferences, context.workspaceRoot,
|
|
307
318
|
// should be false for build target, but providing it just in case is set to true
|
|
308
319
|
tsConfig.options.emitDeclarationOnly),
|
|
@@ -325,12 +336,12 @@ function buildTscTargets(config, options, context, configFiles) {
|
|
|
325
336
|
}
|
|
326
337
|
return { targets };
|
|
327
338
|
}
|
|
328
|
-
function getInputs(namedInputs, config, tsConfig, internalProjectReferences, workspaceRoot) {
|
|
339
|
+
function getInputs(namedInputs, config, tsConfig, internalProjectReferences, workspaceRoot, cache) {
|
|
329
340
|
const configFiles = new Set();
|
|
330
341
|
// TODO(leo): temporary disable external dependencies until we support hashing
|
|
331
342
|
// glob patterns from external dependencies
|
|
332
343
|
// const externalDependencies = ['typescript'];
|
|
333
|
-
const extendedConfigFiles = getExtendedConfigFiles(tsConfig, workspaceRoot);
|
|
344
|
+
const extendedConfigFiles = getExtendedConfigFiles(tsConfig, workspaceRoot, cache);
|
|
334
345
|
extendedConfigFiles.files.forEach((configPath) => {
|
|
335
346
|
configFiles.add(configPath);
|
|
336
347
|
});
|
|
@@ -445,7 +456,7 @@ function getInputs(namedInputs, config, tsConfig, internalProjectReferences, wor
|
|
|
445
456
|
if (excludePaths.size) {
|
|
446
457
|
inputs.push(...Array.from(excludePaths).map((p) => `!${pathToInputOrOutput((0, devkit_1.joinPathFragments)(config.project.root, p), workspaceRoot, config.project)}`));
|
|
447
458
|
}
|
|
448
|
-
if (hasExternalProjectReferences(config.originalPath, tsConfig, workspaceRoot, config.project)) {
|
|
459
|
+
if (hasExternalProjectReferences(config.originalPath, tsConfig, workspaceRoot, config.project, cache)) {
|
|
449
460
|
// Importing modules from a referenced project will load its output declaration files (d.ts)
|
|
450
461
|
// https://www.typescriptlang.org/docs/handbook/project-references.html#what-is-a-project-reference
|
|
451
462
|
inputs.push({ dependentTasksOutputFiles: '**/*.d.ts' });
|
|
@@ -540,14 +551,14 @@ function pathToInputOrOutput(path, workspaceRoot, project) {
|
|
|
540
551
|
}
|
|
541
552
|
return (0, devkit_1.joinPathFragments)('{projectRoot}', pathRelativeToProjectRoot);
|
|
542
553
|
}
|
|
543
|
-
function getExtendedConfigFiles(tsConfig, workspaceRoot, extendedConfigFiles = new Set(), extendedExternalPackages = new Set()) {
|
|
554
|
+
function getExtendedConfigFiles(tsConfig, workspaceRoot, cache, extendedConfigFiles = new Set(), extendedExternalPackages = new Set()) {
|
|
544
555
|
for (const extendedConfigFile of tsConfig.extendedConfigFiles) {
|
|
545
556
|
if (extendedConfigFile.externalPackage) {
|
|
546
557
|
extendedExternalPackages.add(extendedConfigFile.externalPackage);
|
|
547
558
|
}
|
|
548
559
|
else if (extendedConfigFile.filePath) {
|
|
549
560
|
extendedConfigFiles.add(extendedConfigFile.filePath);
|
|
550
|
-
getExtendedConfigFiles(retrieveTsConfigFromCache(extendedConfigFile.filePath, workspaceRoot), workspaceRoot, extendedConfigFiles, extendedExternalPackages);
|
|
561
|
+
getExtendedConfigFiles(retrieveTsConfigFromCache(extendedConfigFile.filePath, workspaceRoot, cache), workspaceRoot, cache, extendedConfigFiles, extendedExternalPackages);
|
|
551
562
|
}
|
|
552
563
|
}
|
|
553
564
|
return {
|
|
@@ -555,7 +566,7 @@ function getExtendedConfigFiles(tsConfig, workspaceRoot, extendedConfigFiles = n
|
|
|
555
566
|
packages: Array.from(extendedExternalPackages),
|
|
556
567
|
};
|
|
557
568
|
}
|
|
558
|
-
function resolveInternalProjectReferences(tsConfig, workspaceRoot, project, projectReferences = {}) {
|
|
569
|
+
function resolveInternalProjectReferences(tsConfig, workspaceRoot, project, cache, projectReferences = {}) {
|
|
559
570
|
if (!tsConfig.projectReferences?.length) {
|
|
560
571
|
return {};
|
|
561
572
|
}
|
|
@@ -570,16 +581,16 @@ function resolveInternalProjectReferences(tsConfig, workspaceRoot, project, proj
|
|
|
570
581
|
if (!refConfigPath.endsWith('.json')) {
|
|
571
582
|
refConfigPath = (0, node_path_1.join)(refConfigPath, 'tsconfig.json');
|
|
572
583
|
}
|
|
573
|
-
const refContext = getConfigContext(refConfigPath, workspaceRoot);
|
|
574
|
-
if (isExternalProjectReference(refContext, project, workspaceRoot)) {
|
|
584
|
+
const refContext = getConfigContext(refConfigPath, workspaceRoot, cache);
|
|
585
|
+
if (isExternalProjectReference(refContext, project, workspaceRoot, cache)) {
|
|
575
586
|
continue;
|
|
576
587
|
}
|
|
577
|
-
projectReferences[refConfigPath] = retrieveTsConfigFromCache(refConfigPath, workspaceRoot);
|
|
578
|
-
resolveInternalProjectReferences(projectReferences[refConfigPath], workspaceRoot, project, projectReferences);
|
|
588
|
+
projectReferences[refConfigPath] = retrieveTsConfigFromCache(refConfigPath, workspaceRoot, cache);
|
|
589
|
+
resolveInternalProjectReferences(projectReferences[refConfigPath], workspaceRoot, project, cache, projectReferences);
|
|
579
590
|
}
|
|
580
591
|
return projectReferences;
|
|
581
592
|
}
|
|
582
|
-
function resolveShallowExternalProjectReferences(tsConfig, workspaceRoot, project, projectReferences = {}) {
|
|
593
|
+
function resolveShallowExternalProjectReferences(tsConfig, workspaceRoot, project, cache, projectReferences = {}) {
|
|
583
594
|
if (!tsConfig.projectReferences?.length) {
|
|
584
595
|
return projectReferences;
|
|
585
596
|
}
|
|
@@ -594,14 +605,14 @@ function resolveShallowExternalProjectReferences(tsConfig, workspaceRoot, projec
|
|
|
594
605
|
if (!refConfigPath.endsWith('.json')) {
|
|
595
606
|
refConfigPath = (0, node_path_1.join)(refConfigPath, 'tsconfig.json');
|
|
596
607
|
}
|
|
597
|
-
const refContext = getConfigContext(refConfigPath, workspaceRoot);
|
|
598
|
-
if (isExternalProjectReference(refContext, project, workspaceRoot)) {
|
|
599
|
-
projectReferences[refConfigPath] = retrieveTsConfigFromCache(refConfigPath, workspaceRoot);
|
|
608
|
+
const refContext = getConfigContext(refConfigPath, workspaceRoot, cache);
|
|
609
|
+
if (isExternalProjectReference(refContext, project, workspaceRoot, cache)) {
|
|
610
|
+
projectReferences[refConfigPath] = retrieveTsConfigFromCache(refConfigPath, workspaceRoot, cache);
|
|
600
611
|
}
|
|
601
612
|
}
|
|
602
613
|
return projectReferences;
|
|
603
614
|
}
|
|
604
|
-
function hasExternalProjectReferences(tsConfigPath, tsConfig, workspaceRoot, project, seen = new Set()) {
|
|
615
|
+
function hasExternalProjectReferences(tsConfigPath, tsConfig, workspaceRoot, project, cache, seen = new Set()) {
|
|
605
616
|
if (!tsConfig.projectReferences?.length) {
|
|
606
617
|
return false;
|
|
607
618
|
}
|
|
@@ -617,19 +628,19 @@ function hasExternalProjectReferences(tsConfigPath, tsConfig, workspaceRoot, pro
|
|
|
617
628
|
if (!refConfigPath.endsWith('.json')) {
|
|
618
629
|
refConfigPath = (0, node_path_1.join)(refConfigPath, 'tsconfig.json');
|
|
619
630
|
}
|
|
620
|
-
const refContext = getConfigContext(refConfigPath, workspaceRoot);
|
|
621
|
-
if (isExternalProjectReference(refContext, project, workspaceRoot)) {
|
|
631
|
+
const refContext = getConfigContext(refConfigPath, workspaceRoot, cache);
|
|
632
|
+
if (isExternalProjectReference(refContext, project, workspaceRoot, cache)) {
|
|
622
633
|
return true;
|
|
623
634
|
}
|
|
624
|
-
const refTsConfig = retrieveTsConfigFromCache(refConfigPath, workspaceRoot);
|
|
625
|
-
const result = hasExternalProjectReferences(refConfigPath, refTsConfig, workspaceRoot, project, seen);
|
|
635
|
+
const refTsConfig = retrieveTsConfigFromCache(refConfigPath, workspaceRoot, cache);
|
|
636
|
+
const result = hasExternalProjectReferences(refConfigPath, refTsConfig, workspaceRoot, project, cache, seen);
|
|
626
637
|
if (result) {
|
|
627
638
|
return true;
|
|
628
639
|
}
|
|
629
640
|
}
|
|
630
641
|
return false;
|
|
631
642
|
}
|
|
632
|
-
function isExternalProjectReference(refConfig, project, workspaceRoot) {
|
|
643
|
+
function isExternalProjectReference(refConfig, project, workspaceRoot, cache) {
|
|
633
644
|
const owner = cache.configOwners.get(refConfig.relativePath);
|
|
634
645
|
if (owner !== undefined) {
|
|
635
646
|
return owner !== project.normalized;
|
|
@@ -649,34 +660,37 @@ function isExternalProjectReference(refConfig, project, workspaceRoot) {
|
|
|
649
660
|
}
|
|
650
661
|
return false;
|
|
651
662
|
}
|
|
652
|
-
function retrieveTsConfigFromCache(tsConfigPath, workspaceRoot) {
|
|
663
|
+
function retrieveTsConfigFromCache(tsConfigPath, workspaceRoot, cache) {
|
|
653
664
|
const relativePath = posixRelative(workspaceRoot, tsConfigPath);
|
|
654
665
|
// we don't need to check the hash if it's in the cache, because we've already
|
|
655
666
|
// checked it when we initially populated the cache
|
|
656
667
|
return tsConfigCacheData[relativePath]
|
|
657
668
|
? tsConfigCacheData[relativePath].data
|
|
658
|
-
: readTsConfigAndCache(tsConfigPath, workspaceRoot);
|
|
669
|
+
: readTsConfigAndCache(tsConfigPath, workspaceRoot, cache);
|
|
659
670
|
}
|
|
660
|
-
function initializeTsConfigCache(configFilePaths, workspaceRoot) {
|
|
661
|
-
|
|
671
|
+
function initializeTsConfigCache(configFilePaths, workspaceRoot, cache) {
|
|
672
|
+
if (!tsConfigCacheInitialized) {
|
|
673
|
+
tsConfigCacheData = toAbsolutePaths(readTsConfigCacheData(), workspaceRoot);
|
|
674
|
+
tsConfigCacheInitialized = true;
|
|
675
|
+
}
|
|
662
676
|
// ensure hashes are checked and the cache is invalidated and populated as needed
|
|
663
677
|
for (const configFilePath of configFilePaths) {
|
|
664
678
|
const fullConfigPath = (0, node_path_1.join)(workspaceRoot, configFilePath);
|
|
665
|
-
readTsConfigAndCache(fullConfigPath, workspaceRoot);
|
|
679
|
+
readTsConfigAndCache(fullConfigPath, workspaceRoot, cache);
|
|
666
680
|
}
|
|
667
681
|
}
|
|
668
|
-
function readTsConfigAndCache(tsConfigPath, workspaceRoot) {
|
|
682
|
+
function readTsConfigAndCache(tsConfigPath, workspaceRoot, cache) {
|
|
669
683
|
const relativePath = posixRelative(workspaceRoot, tsConfigPath);
|
|
670
|
-
const hash = getFileHash(tsConfigPath, workspaceRoot);
|
|
684
|
+
const hash = getFileHash(tsConfigPath, workspaceRoot, cache);
|
|
671
685
|
let extendedFilesHash;
|
|
672
686
|
if (tsConfigCacheData[relativePath] &&
|
|
673
687
|
tsConfigCacheData[relativePath].hash === hash) {
|
|
674
|
-
extendedFilesHash = getExtendedFilesHash(tsConfigCacheData[relativePath].data.extendedConfigFiles, workspaceRoot);
|
|
688
|
+
extendedFilesHash = getExtendedFilesHash(tsConfigCacheData[relativePath].data.extendedConfigFiles, workspaceRoot, cache);
|
|
675
689
|
if (tsConfigCacheData[relativePath].extendedFilesHash === extendedFilesHash) {
|
|
676
690
|
return tsConfigCacheData[relativePath].data;
|
|
677
691
|
}
|
|
678
692
|
}
|
|
679
|
-
const tsConfig = readTsConfig(tsConfigPath, workspaceRoot);
|
|
693
|
+
const tsConfig = readTsConfig(tsConfigPath, workspaceRoot, cache);
|
|
680
694
|
const extendedConfigFiles = [];
|
|
681
695
|
if (tsConfig.raw?.extends) {
|
|
682
696
|
const extendsArray = typeof tsConfig.raw.extends === 'string'
|
|
@@ -689,7 +703,7 @@ function readTsConfigAndCache(tsConfigPath, workspaceRoot) {
|
|
|
689
703
|
}
|
|
690
704
|
}
|
|
691
705
|
}
|
|
692
|
-
extendedFilesHash ??= getExtendedFilesHash(extendedConfigFiles, workspaceRoot);
|
|
706
|
+
extendedFilesHash ??= getExtendedFilesHash(extendedConfigFiles, workspaceRoot, cache);
|
|
693
707
|
tsConfigCacheData[relativePath] = {
|
|
694
708
|
data: {
|
|
695
709
|
options: tsConfig.options,
|
|
@@ -702,7 +716,7 @@ function readTsConfigAndCache(tsConfigPath, workspaceRoot) {
|
|
|
702
716
|
};
|
|
703
717
|
return tsConfigCacheData[relativePath].data;
|
|
704
718
|
}
|
|
705
|
-
function getExtendedFilesHash(extendedConfigFiles, workspaceRoot) {
|
|
719
|
+
function getExtendedFilesHash(extendedConfigFiles, workspaceRoot, cache) {
|
|
706
720
|
if (!extendedConfigFiles.length) {
|
|
707
721
|
return '';
|
|
708
722
|
}
|
|
@@ -721,22 +735,21 @@ function getExtendedFilesHash(extendedConfigFiles, workspaceRoot) {
|
|
|
721
735
|
hashes.push(extendedConfigFile.externalPackage);
|
|
722
736
|
}
|
|
723
737
|
else if (extendedConfigFile.filePath) {
|
|
724
|
-
hashes.push(getFileHash(extendedConfigFile.filePath, workspaceRoot));
|
|
725
|
-
hashes.push(getExtendedFilesHash(readTsConfigAndCache(extendedConfigFile.filePath, workspaceRoot)
|
|
726
|
-
.extendedConfigFiles, workspaceRoot));
|
|
738
|
+
hashes.push(getFileHash(extendedConfigFile.filePath, workspaceRoot, cache));
|
|
739
|
+
hashes.push(getExtendedFilesHash(readTsConfigAndCache(extendedConfigFile.filePath, workspaceRoot, cache).extendedConfigFiles, workspaceRoot, cache));
|
|
727
740
|
}
|
|
728
741
|
}
|
|
729
742
|
const hash = hashes.join('|');
|
|
730
743
|
cache.extendedFilesHashes.set(cacheKey, hash);
|
|
731
744
|
return hash;
|
|
732
745
|
}
|
|
733
|
-
function readTsConfig(tsConfigPath, workspaceRoot) {
|
|
746
|
+
function readTsConfig(tsConfigPath, workspaceRoot, cache) {
|
|
734
747
|
if (!ts) {
|
|
735
748
|
ts = require('typescript');
|
|
736
749
|
}
|
|
737
750
|
const tsSys = {
|
|
738
751
|
...ts.sys,
|
|
739
|
-
readFile: (path) => readFile(path, workspaceRoot),
|
|
752
|
+
readFile: (path) => readFile(path, workspaceRoot, cache),
|
|
740
753
|
readDirectory: () => [],
|
|
741
754
|
};
|
|
742
755
|
const readResult = ts.readConfigFile(tsConfigPath, tsSys.readFile);
|
|
@@ -808,15 +821,15 @@ function resolveExtendedTsConfigPath(tsConfigPath, directory) {
|
|
|
808
821
|
return null;
|
|
809
822
|
}
|
|
810
823
|
}
|
|
811
|
-
function getFileHash(filePath, workspaceRoot) {
|
|
824
|
+
function getFileHash(filePath, workspaceRoot, cache) {
|
|
812
825
|
const relativePath = posixRelative(workspaceRoot, filePath);
|
|
813
826
|
if (!cache.fileHashes[relativePath]) {
|
|
814
|
-
const content = readFile(filePath, workspaceRoot);
|
|
827
|
+
const content = readFile(filePath, workspaceRoot, cache);
|
|
815
828
|
cache.fileHashes[relativePath] = (0, file_hasher_1.hashArray)([content]);
|
|
816
829
|
}
|
|
817
830
|
return cache.fileHashes[relativePath];
|
|
818
831
|
}
|
|
819
|
-
function readFile(filePath, workspaceRoot) {
|
|
832
|
+
function readFile(filePath, workspaceRoot, cache) {
|
|
820
833
|
const relativePath = posixRelative(workspaceRoot, filePath);
|
|
821
834
|
if (!cache.rawFiles[relativePath]) {
|
|
822
835
|
const content = (0, node_fs_1.readFileSync)(filePath, 'utf8');
|