Skip to content

Commit

Permalink
fix(core): fix hashing of external dependencies (#22865)
Browse files Browse the repository at this point in the history
  • Loading branch information
FrozenPandaz committed Apr 18, 2024
1 parent 125c1d2 commit 2d20ad8
Show file tree
Hide file tree
Showing 10 changed files with 162 additions and 188 deletions.
2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ packages/nx/src/plugins/js/lock-file/__fixtures__/**/*.*
packages/**/schematics/**/files/**/*.html
packages/**/generators/**/files/**/*.html
packages/nx/src/native/**/*.rs
packages/nx/src/native/index.js
packages/nx/src/native/native-bindings.js
packages/nx/src/native/index.d.ts
nx-dev/nx-dev/.next/
nx-dev/nx-dev/public/documentation
Expand Down
4 changes: 3 additions & 1 deletion packages/nx/src/native/hasher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ pub fn hash_file_path<P: AsRef<Path>>(path: P) -> Option<String> {
trace!("Failed to read file: {:?}", path);
return None;
};
let hash = hash(&content);
trace!("Hashed file {:?} - {:?}", path, hash);

Some(hash(&content))
Some(hash)
}

#[cfg(test)]
Expand Down
5 changes: 1 addition & 4 deletions packages/nx/src/native/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,8 @@ export function findImports(projectFileMap: Record<string, Array<string>>): Arra
* This wont be needed once the project graph is created in Rust
*/
export function transferProjectGraph(projectGraph: ProjectGraph): ExternalObject<ProjectGraph>
export interface ExternalNodeData {
version: string
hash?: string
}
export interface ExternalNode {
packageName?: string
version: string
hash?: string
}
Expand Down
11 changes: 5 additions & 6 deletions packages/nx/src/native/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const { join, basename } = require('path');
const { join, basename } = require('path');
const { copyFileSync, existsSync, mkdirSync } = require('fs');
const Module = require('module');
const { nxVersion} = require("../utils/versions")
const { cacheDir} = require("../utils/cache-directory")
const { nxVersion } = require('../utils/versions');
const { cacheDir } = require('../utils/cache-directory');

const nxPackages = new Set([
'@nx/nx-android-arm64',
Expand Down Expand Up @@ -40,7 +40,7 @@ const localNodeFiles = [

const originalLoad = Module._load;

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


module.exports = indexModule;
Module._load = originalLoad;

0 comments on commit 2d20ad8

Please sign in to comment.