Skip to content

Commit

Permalink
fix(core): fix build-wasm
Browse files Browse the repository at this point in the history
  • Loading branch information
AgentEnder committed Jan 16, 2025
1 parent a35a726 commit 16db699
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 30 deletions.
19 changes: 11 additions & 8 deletions packages/nx/src/native/nx.wasi-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,18 @@ function __napi_rs_initialize_modules(__napiInstance) {
__napiInstance.exports['__napi_register__ExternalDependenciesInput_struct_36']?.()
__napiInstance.exports['__napi_register__DepsOutputsInput_struct_37']?.()
__napiInstance.exports['__napi_register__NxJson_struct_38']?.()
__napiInstance.exports['__napi_register__WorkspaceContext_struct_39']?.()
__napiInstance.exports['__napi_register__WorkspaceContext_impl_48']?.()
__napiInstance.exports['__napi_register__WorkspaceErrors_49']?.()
__napiInstance.exports['__napi_register__NxWorkspaceFiles_struct_50']?.()
__napiInstance.exports['__napi_register__NxWorkspaceFilesExternals_struct_51']?.()
__napiInstance.exports['__napi_register__UpdatedWorkspaceFiles_struct_52']?.()
__napiInstance.exports['__napi_register__FileMap_struct_53']?.()
__napiInstance.exports['__napi_register____test_only_transfer_file_map_54']?.()
__napiInstance.exports['__napi_register__FileLock_struct_39']?.()
__napiInstance.exports['__napi_register__FileLock_impl_41']?.()
__napiInstance.exports['__napi_register__WorkspaceContext_struct_42']?.()
__napiInstance.exports['__napi_register__WorkspaceContext_impl_51']?.()
__napiInstance.exports['__napi_register__WorkspaceErrors_52']?.()
__napiInstance.exports['__napi_register__NxWorkspaceFiles_struct_53']?.()
__napiInstance.exports['__napi_register__NxWorkspaceFilesExternals_struct_54']?.()
__napiInstance.exports['__napi_register__UpdatedWorkspaceFiles_struct_55']?.()
__napiInstance.exports['__napi_register__FileMap_struct_56']?.()
__napiInstance.exports['__napi_register____test_only_transfer_file_map_57']?.()
}
export const FileLock = __napiModule.exports.FileLock
export const HashPlanner = __napiModule.exports.HashPlanner
export const ImportResult = __napiModule.exports.ImportResult
export const TaskHasher = __napiModule.exports.TaskHasher
Expand Down
19 changes: 11 additions & 8 deletions packages/nx/src/native/nx.wasi.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,18 @@ function __napi_rs_initialize_modules(__napiInstance) {
__napiInstance.exports['__napi_register__ExternalDependenciesInput_struct_36']?.()
__napiInstance.exports['__napi_register__DepsOutputsInput_struct_37']?.()
__napiInstance.exports['__napi_register__NxJson_struct_38']?.()
__napiInstance.exports['__napi_register__WorkspaceContext_struct_39']?.()
__napiInstance.exports['__napi_register__WorkspaceContext_impl_48']?.()
__napiInstance.exports['__napi_register__WorkspaceErrors_49']?.()
__napiInstance.exports['__napi_register__NxWorkspaceFiles_struct_50']?.()
__napiInstance.exports['__napi_register__NxWorkspaceFilesExternals_struct_51']?.()
__napiInstance.exports['__napi_register__UpdatedWorkspaceFiles_struct_52']?.()
__napiInstance.exports['__napi_register__FileMap_struct_53']?.()
__napiInstance.exports['__napi_register____test_only_transfer_file_map_54']?.()
__napiInstance.exports['__napi_register__FileLock_struct_39']?.()
__napiInstance.exports['__napi_register__FileLock_impl_41']?.()
__napiInstance.exports['__napi_register__WorkspaceContext_struct_42']?.()
__napiInstance.exports['__napi_register__WorkspaceContext_impl_51']?.()
__napiInstance.exports['__napi_register__WorkspaceErrors_52']?.()
__napiInstance.exports['__napi_register__NxWorkspaceFiles_struct_53']?.()
__napiInstance.exports['__napi_register__NxWorkspaceFilesExternals_struct_54']?.()
__napiInstance.exports['__napi_register__UpdatedWorkspaceFiles_struct_55']?.()
__napiInstance.exports['__napi_register__FileMap_struct_56']?.()
__napiInstance.exports['__napi_register____test_only_transfer_file_map_57']?.()
}
module.exports.FileLock = __napiModule.exports.FileLock
module.exports.HashPlanner = __napiModule.exports.HashPlanner
module.exports.ImportResult = __napiModule.exports.ImportResult
module.exports.TaskHasher = __napiModule.exports.TaskHasher
Expand Down
4 changes: 2 additions & 2 deletions packages/nx/src/native/tests/file-lock.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { join } from 'path';
describe('withLock', () => {
it('should block the second call until the first one is done', async () => {
let combinedOutputs = [];
let a = fork(join(__dirname, './fixtures/file-lock-fixture.spec.js'), {
let a = fork(join(__dirname, './__fixtures__/file-lock.fixture.js'), {
env: {
LABEL: 'a',
NX_NATIVE_LOGGING: 'trace',
Expand All @@ -17,7 +17,7 @@ describe('withLock', () => {
// if both start at the same time, its hard to guarantee that a will get the lock before b.
await new Promise((r) => setTimeout(r, 500));

let b = fork(join(__dirname, './fixtures/file-lock-fixture.spec.js'), {
let b = fork(join(__dirname, './__fixtures__/file-lock.fixture.js'), {
env: {
LABEL: 'b',
NX_NATIVE_LOGGING: 'trace',
Expand Down
14 changes: 13 additions & 1 deletion packages/nx/src/native/utils/file_lock.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
use fs4::fs_std::FileExt;
use napi::bindgen_prelude::*;
use std::{
fs::{self, OpenOptions},
path::Path,
};
use tracing::trace;

#[cfg(not(target_arch = "wasm32"))]
use fs4::fs_std::FileExt;

#[napi]
pub struct FileLock {
#[napi]
Expand All @@ -26,6 +28,7 @@ pub struct FileLock {
/// }
#[napi]
#[cfg(not(target_arch = "wasm32"))]
impl FileLock {
#[napi(constructor)]
pub fn new(lock_file_path: String) -> anyhow::Result<Self> {
Expand Down Expand Up @@ -104,6 +107,15 @@ impl FileLock {
}
}

#[napi]
#[cfg(target_arch = "wasm32")]
impl FileLock {
#[napi(constructor)]
pub fn new(lock_file_path: String) -> anyhow::Result<Self> {
anyhow::bail!("FileLock is not supported on WASM")
}
}

// TODO: Fix the tests
#[cfg(test)]
mod test {
Expand Down
18 changes: 7 additions & 11 deletions packages/nx/src/project-graph/project-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import {
} from './utils/retrieve-workspace-files';
import { getPlugins } from './plugins/get-plugins';
import { logger } from '../utils/logger';
import { FileLock } from '../native';
import { FileLock, IS_WASM } from '../native';
import { join } from 'path';
import { workspaceDataDirectory } from '../utils/cache-directory';
import { DelayedSpinner } from '../utils/delayed-spinner';
Expand Down Expand Up @@ -282,13 +282,11 @@ export async function createProjectGraphAndSourceMapsAsync(
performance.mark('create-project-graph-async:start');

if (!daemonClient.enabled()) {
const lock = new FileLock(
join(workspaceDataDirectory, 'project-graph.lock')
);
const initiallyLocked = lock.locked;
let locked = lock.locked;

while (lock.locked) {
const lock = !IS_WASM
? new FileLock(join(workspaceDataDirectory, 'project-graph.lock'))
: null;
let locked = lock?.locked;
while (locked) {
logger.verbose(
'Waiting for graph construction in another process to complete'
);
Expand Down Expand Up @@ -324,9 +322,7 @@ export async function createProjectGraphAndSourceMapsAsync(
}
locked = lock.check();
}
// if (!initiallyLocked) {
lock.lock();
// }
lock?.lock();
try {
const res = await buildProjectGraphAndSourceMapsWithoutDaemon();
performance.measure(
Expand Down
2 changes: 2 additions & 0 deletions packages/nx/tsconfig.spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
"**/*.spec.tsx",
"**/*.spec.js",
"**/*.spec.jsx",
"**/*.fixture.js",
"**/*.fixture.ts",
"**/*.d.ts",
"./src/internal-testing-utils/**/*.ts",
"jest.config.ts"
Expand Down

0 comments on commit 16db699

Please sign in to comment.