Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): fix hashing of external dependencies #22865

Merged
merged 1 commit into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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;