Skip to content

Commit

Permalink
feat(core): load native files from tmp location instead of node_modul…
Browse files Browse the repository at this point in the history
…es (#22648)

(cherry picked from commit da1808d)
  • Loading branch information
MaxKless authored and FrozenPandaz committed Apr 18, 2024
1 parent 7ac5ca5 commit d21fd01
Show file tree
Hide file tree
Showing 16 changed files with 508 additions and 377 deletions.
4 changes: 4 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
{
"group": ["nx/src/plugins/js*"],
"message": "Imports from 'nx/src/plugins/js' are not allowed. Use '@nx/js' instead"
},
{
"group": ["**/native-bindings", "**/native-bindings.js", ""],
"message": "Direct imports from native-bindings.js are not allowed. Import from index.js instead."
}
]
}
Expand Down
4 changes: 4 additions & 0 deletions packages/nx/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
{
"group": ["nx/*"],
"message": "Circular import in 'nx' found. Use relative path."
},
{
"group": ["**/native-bindings", "**/native-bindings.js"],
"message": "Direct imports from native-bindings.js are not allowed. Import from index.js instead."
}
]
}
Expand Down
3 changes: 2 additions & 1 deletion packages/nx/bin/nx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ function main() {
if (
process.argv[2] !== 'report' &&
process.argv[2] !== '--version' &&
process.argv[2] !== '--help'
process.argv[2] !== '--help' &&
process.argv[2] !== 'reset'
) {
assertSupportedPlatform();
}
Expand Down
2 changes: 1 addition & 1 deletion packages/nx/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"executor": "@monodon/rust:napi",
"options": {
"dist": "packages/nx/src/native",
"jsFile": "packages/nx/src/native/index.js",
"jsFile": "packages/nx/src/native/native-bindings.js",
"release": true
},
"configurations": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import { execSync } from 'child_process';

export function checkForUncommittedChanges() {
const gitResult = execSync(`git status --porcelain`);
if (gitResult.length > 0) {
const gitResult = execSync('git status --porcelain').toString();

const filteredResults = gitResult
.split('\n')
.filter((line) => !line.includes('.nx') && line.trim().length > 0);

if (filteredResults.length > 0) {
console.log('❗️ Careful!');
console.log('You have uncommitted changes in your repository.');
console.log('');
console.log(gitResult.toString());
console.log(filteredResults.join('\n').toString());
console.log('Please commit your changes before running the migrator!');
process.exit(1);
}
Expand Down
19 changes: 19 additions & 0 deletions packages/nx/src/daemon/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,25 @@ export async function safelyCleanUpExistingProcess(): Promise<void> {
if (daemonProcessJson && daemonProcessJson.processId) {
try {
process.kill(daemonProcessJson.processId);
// we wait for the process to actually shut down before returning
await new Promise<void>((resolve, reject) => {
let count = 0;
const interval = setInterval(() => {
try {
// sending a signal 0 to a process checks if the process is running instead of actually killing it
process.kill(daemonProcessJson.processId, 0);
} catch (e) {
clearInterval(interval);
resolve();
}
if ((count += 1) > 200) {
clearInterval(interval);
reject(
`Daemon process ${daemonProcessJson.processId} didn't exit after 2 seconds.`
);
}
}, 10);
});
} catch {}
}
deleteDaemonJsonProcessCache();
Expand Down
6 changes: 4 additions & 2 deletions packages/nx/src/daemon/client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ import { safelyCleanUpExistingProcess } from '../cache';
import { Hash } from '../../hasher/task-hasher';
import { Task, TaskGraph } from '../../config/task-graph';
import { ConfigurationSourceMaps } from '../../project-graph/utils/project-configuration-utils';
import { DaemonProjectGraphError } from '../daemon-project-graph-error';
import { ProjectGraphError } from '../../project-graph/project-graph';
import {
DaemonProjectGraphError,
ProjectGraphError,
} from '../../project-graph/error-types';

const DAEMON_ENV_SETTINGS = {
NX_PROJECT_GLOB_CACHE: 'false',
Expand Down
15 changes: 0 additions & 15 deletions packages/nx/src/daemon/daemon-project-graph-error.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/nx/src/daemon/server/handle-hash-tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Task, TaskGraph } from '../../config/task-graph';
import { getCachedSerializedProjectGraphPromise } from './project-graph-incremental-recomputation';
import { InProcessTaskHasher } from '../../hasher/task-hasher';
import { readNxJson } from '../../config/configuration';
import { DaemonProjectGraphError } from '../daemon-project-graph-error';
import { DaemonProjectGraphError } from '../../project-graph/error-types';

/**
* We use this not to recreated hasher for every hash operation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ import { notifyFileWatcherSockets } from './file-watching/file-watcher-sockets';
import { serverLogger } from './logger';
import { NxWorkspaceFilesExternals } from '../../native';
import { ConfigurationResult } from '../../project-graph/utils/project-configuration-utils';
import { DaemonProjectGraphError } from '../daemon-project-graph-error';
import { LoadedNxPlugin } from '../../project-graph/plugins/internal-api';
import { getPlugins } from './plugins';
import { ProjectConfigurationsError } from '../../project-graph/error-types';
import {
DaemonProjectGraphError,
ProjectConfigurationsError,
} from '../../project-graph/error-types';

interface SerializedProjectGraph {
error: Error | null;
Expand Down
2 changes: 1 addition & 1 deletion packages/nx/src/daemon/socket-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { unlinkSync } from 'fs';
import { platform } from 'os';
import { join, resolve } from 'path';
import { DAEMON_SOCKET_PATH, socketDir } from './tmp-dir';
import { DaemonProjectGraphError } from './daemon-project-graph-error';
import { DaemonProjectGraphError } from '../project-graph/error-types';

export const isWindows = platform() === 'win32';

Expand Down
Loading

0 comments on commit d21fd01

Please sign in to comment.