@nx/js 21.0.0-beta.2 → 21.0.0-beta.4

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": "21.0.0-beta.2",
3
+ "version": "21.0.0-beta.4",
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": "21.0.0-beta.2",
43
- "@nx/workspace": "21.0.0-beta.2",
42
+ "@nx/devkit": "21.0.0-beta.4",
43
+ "@nx/workspace": "21.0.0-beta.4",
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",
@@ -14,8 +14,9 @@ const cache_directory_1 = require("nx/src/utils/cache-directory");
14
14
  const util_1 = require("./util");
15
15
  let ts;
16
16
  const pmc = (0, devkit_1.getPackageManagerCommand)();
17
- let tsConfigCache;
18
- const tsConfigCachePath = (0, node_path_1.join)(cache_directory_1.workspaceDataDirectory, 'tsconfig-files.hash');
17
+ const TSCONFIG_CACHE_VERSION = 1;
18
+ const TS_CONFIG_CACHE_PATH = (0, node_path_1.join)(cache_directory_1.workspaceDataDirectory, 'tsconfig-files.hash');
19
+ let tsConfigCacheData;
19
20
  let cache;
20
21
  function readFromCache(cachePath) {
21
22
  try {
@@ -27,9 +28,22 @@ function readFromCache(cachePath) {
27
28
  return {};
28
29
  }
29
30
  }
31
+ function readTsConfigCacheData() {
32
+ const cache = readFromCache(TS_CONFIG_CACHE_PATH);
33
+ if (cache.version !== TSCONFIG_CACHE_VERSION) {
34
+ return {};
35
+ }
36
+ return cache.data;
37
+ }
30
38
  function writeToCache(cachePath, data) {
31
39
  (0, devkit_1.writeJsonFile)(cachePath, data, { spaces: 0 });
32
40
  }
41
+ function writeTsConfigCache(data) {
42
+ writeToCache(TS_CONFIG_CACHE_PATH, {
43
+ version: TSCONFIG_CACHE_VERSION,
44
+ data,
45
+ });
46
+ }
33
47
  /**
34
48
  * @deprecated The 'createDependencies' function is now a no-op. This functionality is included in 'createNodesV2'.
35
49
  */
@@ -68,7 +82,7 @@ exports.createNodesV2 = [
68
82
  }
69
83
  finally {
70
84
  writeToCache(targetsCachePath, targetsCache);
71
- writeToCache(tsConfigCachePath, toRelativePaths(tsConfigCache, context.workspaceRoot));
85
+ writeTsConfigCache(toRelativePaths(tsConfigCacheData, context.workspaceRoot));
72
86
  }
73
87
  },
74
88
  ];
@@ -84,7 +98,7 @@ exports.createNodes = [
84
98
  cache = { fileHashes: {}, rawFiles: {}, isExternalProjectReference: {} };
85
99
  initializeTsConfigCache([configFilePath], context.workspaceRoot);
86
100
  const { targets } = buildTscTargets((0, node_path_1.join)(context.workspaceRoot, configFilePath), projectRoot, normalizedOptions, context);
87
- writeToCache(tsConfigCachePath, toRelativePaths(tsConfigCache, context.workspaceRoot));
101
+ writeTsConfigCache(toRelativePaths(tsConfigCacheData, context.workspaceRoot));
88
102
  return {
89
103
  projects: {
90
104
  [projectRoot]: {
@@ -587,12 +601,12 @@ function retrieveTsConfigFromCache(tsConfigPath, workspaceRoot) {
587
601
  const relativePath = posixRelative(workspaceRoot, tsConfigPath);
588
602
  // we don't need to check the hash if it's in the cache, because we've already
589
603
  // checked it when we initially populated the cache
590
- return tsConfigCache[relativePath]
591
- ? tsConfigCache[relativePath].data
604
+ return tsConfigCacheData[relativePath]
605
+ ? tsConfigCacheData[relativePath].data
592
606
  : readTsConfigAndCache(tsConfigPath, workspaceRoot);
593
607
  }
594
608
  function initializeTsConfigCache(configFilePaths, workspaceRoot) {
595
- tsConfigCache = toAbsolutePaths(readFromCache(tsConfigCachePath), workspaceRoot);
609
+ tsConfigCacheData = toAbsolutePaths(readTsConfigCacheData(), workspaceRoot);
596
610
  // ensure hashes are checked and the cache is invalidated and populated as needed
597
611
  for (const configFilePath of configFilePaths) {
598
612
  const fullConfigPath = (0, node_path_1.join)(workspaceRoot, configFilePath);
@@ -603,11 +617,11 @@ function readTsConfigAndCache(tsConfigPath, workspaceRoot) {
603
617
  const relativePath = posixRelative(workspaceRoot, tsConfigPath);
604
618
  const hash = getFileHash(tsConfigPath, workspaceRoot);
605
619
  let extendedFilesHash;
606
- if (tsConfigCache[relativePath] &&
607
- tsConfigCache[relativePath].hash === hash) {
608
- extendedFilesHash = getExtendedFilesHash(tsConfigCache[relativePath].data.extendedConfigFiles, workspaceRoot);
609
- if (tsConfigCache[relativePath].extendedFilesHash === extendedFilesHash) {
610
- return tsConfigCache[relativePath].data;
620
+ if (tsConfigCacheData[relativePath] &&
621
+ tsConfigCacheData[relativePath].hash === hash) {
622
+ extendedFilesHash = getExtendedFilesHash(tsConfigCacheData[relativePath].data.extendedConfigFiles, workspaceRoot);
623
+ if (tsConfigCacheData[relativePath].extendedFilesHash === extendedFilesHash) {
624
+ return tsConfigCacheData[relativePath].data;
611
625
  }
612
626
  }
613
627
  const tsConfig = readTsConfig(tsConfigPath, workspaceRoot);
@@ -624,7 +638,7 @@ function readTsConfigAndCache(tsConfigPath, workspaceRoot) {
624
638
  }
625
639
  }
626
640
  extendedFilesHash ??= getExtendedFilesHash(extendedConfigFiles, workspaceRoot);
627
- tsConfigCache[relativePath] = {
641
+ tsConfigCacheData[relativePath] = {
628
642
  data: {
629
643
  options: tsConfig.options,
630
644
  projectReferences: tsConfig.projectReferences,
@@ -634,7 +648,7 @@ function readTsConfigAndCache(tsConfigPath, workspaceRoot) {
634
648
  hash,
635
649
  extendedFilesHash,
636
650
  };
637
- return tsConfigCache[relativePath].data;
651
+ return tsConfigCacheData[relativePath].data;
638
652
  }
639
653
  function getExtendedFilesHash(extendedConfigFiles, workspaceRoot) {
640
654
  const hashes = [];