nx 19.1.0-canary.20240515-a2a7d7e → 19.1.0-canary.20240517-312b271

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.
@@ -30,7 +30,8 @@ exports.readJson = readJson;
30
30
  * @param options Optional JSON Serialize Options
31
31
  */
32
32
  function writeJson(tree, path, value, options) {
33
- tree.write(path, (0, json_1.serializeJson)(value, options));
33
+ const serialized = (0, json_1.serializeJson)(value, options);
34
+ tree.write(path, `${serialized}\n`);
34
35
  }
35
36
  exports.writeJson = writeJson;
36
37
  /**
@@ -2,7 +2,7 @@ const { join, basename } = require('path');
2
2
  const { copyFileSync, existsSync, mkdirSync } = require('fs');
3
3
  const Module = require('module');
4
4
  const { nxVersion } = require('../utils/versions');
5
- const { cacheDir } = require('../utils/cache-directory');
5
+ const { nativeFileCacheLocation } = require('./native-file-cache-location');
6
6
 
7
7
  const nxPackages = new Set([
8
8
  '@nx/nx-android-arm64',
@@ -52,13 +52,14 @@ Module._load = function (request, parent, isMain) {
52
52
  ) {
53
53
  const nativeLocation = require.resolve(modulePath);
54
54
  const fileName = basename(nativeLocation);
55
- // we copy the file to the cache directory (.nx/cache by default) and prefix with nxVersion to avoid stale files being loaded
56
- const tmpFile = join(cacheDir, nxVersion + '-' + fileName);
55
+
56
+ // we copy the file to a workspace-scoped tmp directory and prefix with nxVersion to avoid stale files being loaded
57
+ const tmpFile = join(nativeFileCacheLocation, nxVersion + '-' + fileName);
57
58
  if (existsSync(tmpFile)) {
58
59
  return originalLoad.apply(this, [tmpFile, parent, isMain]);
59
60
  }
60
- if (!existsSync(cacheDir)) {
61
- mkdirSync(cacheDir, { recursive: true });
61
+ if (!existsSync(nativeFileCacheLocation)) {
62
+ mkdirSync(nativeFileCacheLocation, { recursive: true });
62
63
  }
63
64
  copyFileSync(nativeLocation, tmpFile);
64
65
  return originalLoad.apply(this, [tmpFile, parent, isMain]);
@@ -0,0 +1 @@
1
+ export declare const nativeFileCacheLocation: string;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.nativeFileCacheLocation = void 0;
4
+ const os_1 = require("os");
5
+ const path_1 = require("path");
6
+ const crypto_1 = require("crypto");
7
+ const workspace_root_1 = require("../utils/workspace-root");
8
+ exports.nativeFileCacheLocation = (0, path_1.join)((0, os_1.tmpdir)(), 'nx-native-file-cache', (0, crypto_1.createHash)('sha256').update(workspace_root_1.workspaceRoot).digest('hex'));
@@ -9,12 +9,12 @@ import { LoadedNxPlugin } from '../plugins/internal-api';
9
9
  * @param nxJson
10
10
  */
11
11
  export declare function retrieveWorkspaceFiles(workspaceRoot: string, projectRootMap: Record<string, string>): Promise<{
12
- allWorkspaceFiles: import("nx/src/devkit-exports").FileData[];
12
+ allWorkspaceFiles: import("../file-utils").FileData[];
13
13
  fileMap: {
14
14
  projectFileMap: ProjectFiles;
15
- nonProjectFiles: import("nx/src/native").FileData[];
15
+ nonProjectFiles: import("../../native").FileData[];
16
16
  };
17
- rustReferences: import("nx/src/native").NxWorkspaceFilesExternals;
17
+ rustReferences: import("../../native").NxWorkspaceFilesExternals;
18
18
  }>;
19
19
  /**
20
20
  * Walk through the workspace and return `ProjectConfigurations`. Only use this if the projectFileMap is not needed.
@@ -22,15 +22,6 @@ function findMatchingProjects(patterns = [], projects) {
22
22
  }
23
23
  const projectNames = Object.keys(projects);
24
24
  const matchedProjects = new Set();
25
- // If the first pattern is an exclude pattern,
26
- // we add a wildcard pattern at the first to select
27
- // all projects, except the ones that match the exclude pattern.
28
- // e.g. ['!tag:someTag', 'project2'] will match all projects except
29
- // the ones with the tag 'someTag', and also match the project 'project2',
30
- // regardless of its tags.
31
- if (isExcludePattern(patterns[0])) {
32
- patterns.unshift('*');
33
- }
34
25
  for (const stringPattern of patterns) {
35
26
  if (!stringPattern.length) {
36
27
  continue;
@@ -148,11 +139,8 @@ function addMatchingProjectsByTag(projectNames, projects, pattern, matchedProjec
148
139
  }
149
140
  }
150
141
  }
151
- function isExcludePattern(pattern) {
152
- return pattern.startsWith('!');
153
- }
154
142
  function parseStringPattern(pattern, projects) {
155
- const isExclude = isExcludePattern(pattern);
143
+ const isExclude = pattern.startsWith('!');
156
144
  // Support for things like: `!{type}:value`
157
145
  if (isExclude) {
158
146
  pattern = pattern.substring(1);
package/src/utils/json.js CHANGED
@@ -57,6 +57,6 @@ function formatParseError(input, parseError) {
57
57
  * @returns the formatted JSON representation of the object
58
58
  */
59
59
  function serializeJson(input, options) {
60
- return JSON.stringify(input, null, options?.spaces ?? 2) + '\n';
60
+ return JSON.stringify(input, null, options?.spaces ?? 2);
61
61
  }
62
62
  exports.serializeJson = serializeJson;
@@ -254,11 +254,20 @@ async function resolvePackageVersionUsingRegistry(packageName, version) {
254
254
  if (!result) {
255
255
  throw new Error(`Unable to resolve version ${packageName}@${version}.`);
256
256
  }
257
- // get the last line of the output, strip the package version and quotes
258
- const resolvedVersion = result
259
- .split('\n')
260
- .pop()
261
- .split(' ')
257
+ const lines = result.split('\n');
258
+ if (lines.length === 1) {
259
+ return lines[0];
260
+ }
261
+ /**
262
+ * The output contains multiple lines ordered by release date, so the last
263
+ * version might not be the last one in the list. We need to sort it. Each
264
+ * line looks like:
265
+ *
266
+ * <package>@<version> '<version>'
267
+ */
268
+ const resolvedVersion = lines
269
+ .map((line) => line.split(' ')[1])
270
+ .sort()
262
271
  .pop()
263
272
  .replace(/'/g, '');
264
273
  return resolvedVersion;