Skip to content

Commit becd93d

Browse files
committed
fix(core): fix hashing of external dependencies (#22865)
(cherry picked from commit 2d20ad8)
1 parent d21fd01 commit becd93d

File tree

10 files changed

+162
-188
lines changed

10 files changed

+162
-188
lines changed

.prettierignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ packages/nx/src/plugins/js/lock-file/__fixtures__/**/*.*
1717
packages/**/schematics/**/files/**/*.html
1818
packages/**/generators/**/files/**/*.html
1919
packages/nx/src/native/**/*.rs
20-
packages/nx/src/native/index.js
20+
packages/nx/src/native/native-bindings.js
2121
packages/nx/src/native/index.d.ts
2222
nx-dev/nx-dev/.next/
2323
nx-dev/nx-dev/public/documentation

packages/nx/src/native/hasher.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@ pub fn hash_file_path<P: AsRef<Path>>(path: P) -> Option<String> {
2626
trace!("Failed to read file: {:?}", path);
2727
return None;
2828
};
29+
let hash = hash(&content);
30+
trace!("Hashed file {:?} - {:?}", path, hash);
2931

30-
Some(hash(&content))
32+
Some(hash)
3133
}
3234

3335
#[cfg(test)]

packages/nx/src/native/index.d.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,8 @@ export function findImports(projectFileMap: Record<string, Array<string>>): Arra
2929
* This wont be needed once the project graph is created in Rust
3030
*/
3131
export function transferProjectGraph(projectGraph: ProjectGraph): ExternalObject<ProjectGraph>
32-
export interface ExternalNodeData {
33-
version: string
34-
hash?: string
35-
}
3632
export interface ExternalNode {
33+
packageName?: string
3734
version: string
3835
hash?: string
3936
}

packages/nx/src/native/index.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
const { join, basename } = require('path');
1+
const { join, basename } = require('path');
22
const { copyFileSync, existsSync, mkdirSync } = require('fs');
33
const Module = require('module');
4-
const { nxVersion} = require("../utils/versions")
5-
const { cacheDir} = require("../utils/cache-directory")
4+
const { nxVersion } = require('../utils/versions');
5+
const { cacheDir } = require('../utils/cache-directory');
66

77
const nxPackages = new Set([
88
'@nx/nx-android-arm64',
@@ -40,7 +40,7 @@ const localNodeFiles = [
4040

4141
const originalLoad = Module._load;
4242

43-
// We override the _load function so that when a native file is required,
43+
// We override the _load function so that when a native file is required,
4444
// we copy it to a cache directory and require it from there.
4545
// This prevents the file being loaded from node_modules and causing file locking issues.
4646
// Will only be called once because the require cache takes over afterwards.
@@ -51,7 +51,7 @@ Module._load = function (request, parent, isMain) {
5151
localNodeFiles.some((f) => modulePath.endsWith(f))
5252
) {
5353
const nativeLocation = require.resolve(modulePath);
54-
const fileName = basename(nativeLocation)
54+
const fileName = basename(nativeLocation);
5555
// we copy the file to the cache directory (.nx/cache by default) and prefix with nxVersion to avoid stale files being loaded
5656
const tmpFile = join(cacheDir, nxVersion + '-' + fileName);
5757
if (existsSync(tmpFile)) {
@@ -72,6 +72,5 @@ const indexModulePath = require.resolve('./native-bindings.js');
7272
delete require.cache[indexModulePath];
7373
const indexModule = require('./native-bindings.js');
7474

75-
7675
module.exports = indexModule;
7776
Module._load = originalLoad;

0 commit comments

Comments
 (0)