feat(core): create the daemon socket file in the tmp dir instead of node modules
This commit is contained in:
parent
caec117288
commit
db74bc7674
@ -38,7 +38,6 @@ describe('js e2e', () => {
|
|||||||
}, 120000);
|
}, 120000);
|
||||||
|
|
||||||
it('should create libs with js executors (--compiler=tsc)', async () => {
|
it('should create libs with js executors (--compiler=tsc)', async () => {
|
||||||
//
|
|
||||||
const lib = uniq('lib');
|
const lib = uniq('lib');
|
||||||
runCLI(`generate @nrwl/js:lib ${lib} --buildable --compiler=tsc`);
|
runCLI(`generate @nrwl/js:lib ${lib} --buildable --compiler=tsc`);
|
||||||
const libPackageJson = readJson(`libs/${lib}/package.json`);
|
const libPackageJson = readJson(`libs/${lib}/package.json`);
|
||||||
|
|||||||
@ -10,7 +10,16 @@ import { isServerAvailable, stop } from '../src/daemon/client/client';
|
|||||||
if (await isServerAvailable()) {
|
if (await isServerAvailable()) {
|
||||||
await stop();
|
await stop();
|
||||||
}
|
}
|
||||||
|
const b = new Date();
|
||||||
await buildProjectGraphWithoutDaemon();
|
await buildProjectGraphWithoutDaemon();
|
||||||
|
const a = new Date();
|
||||||
|
if (process.env.NX_VERBOSE_LOGGING === 'true') {
|
||||||
|
console.log(
|
||||||
|
`Nx project graph has been precomputed in ${
|
||||||
|
a.getTime() - b.getTime()
|
||||||
|
}ms`
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// Do not error since this runs in a postinstall
|
// Do not error since this runs in a postinstall
|
||||||
|
|||||||
@ -15,10 +15,11 @@ import {
|
|||||||
DAEMON_DIR_FOR_CURRENT_WORKSPACE,
|
DAEMON_DIR_FOR_CURRENT_WORKSPACE,
|
||||||
DAEMON_OUTPUT_LOG_FILE,
|
DAEMON_OUTPUT_LOG_FILE,
|
||||||
isDaemonDisabled,
|
isDaemonDisabled,
|
||||||
|
removeSocketDir,
|
||||||
} from '../tmp-dir';
|
} from '../tmp-dir';
|
||||||
import { ProjectGraph } from '../../config/project-graph';
|
import { ProjectGraph } from '../../config/project-graph';
|
||||||
import { isCI } from '../../utils/is-ci';
|
import { isCI } from '../../utils/is-ci';
|
||||||
import { NxJsonConfiguration } from 'nx/src/config/nx-json';
|
import { NxJsonConfiguration } from '../../config/nx-json';
|
||||||
|
|
||||||
const DAEMON_ENV_SETTINGS = {
|
const DAEMON_ENV_SETTINGS = {
|
||||||
...process.env,
|
...process.env,
|
||||||
@ -205,6 +206,8 @@ export function stop(): void {
|
|||||||
stdio: 'inherit',
|
stdio: 'inherit',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
removeSocketDir();
|
||||||
|
|
||||||
output.log({ title: 'Daemon Server - Stopped' });
|
output.log({ title: 'Daemon Server - Stopped' });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -2,7 +2,6 @@ import { unlinkSync } from 'fs';
|
|||||||
import { platform } from 'os';
|
import { platform } from 'os';
|
||||||
import { resolve } from 'path';
|
import { resolve } from 'path';
|
||||||
import { DAEMON_SOCKET_PATH } from './tmp-dir';
|
import { DAEMON_SOCKET_PATH } from './tmp-dir';
|
||||||
import { ProjectGraph } from '../config/project-graph';
|
|
||||||
|
|
||||||
export const isWindows = platform() === 'win32';
|
export const isWindows = platform() === 'win32';
|
||||||
|
|
||||||
@ -22,11 +21,6 @@ export function killSocketOrPath(): void {
|
|||||||
} catch {}
|
} catch {}
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ProjectGraphServerResult {
|
|
||||||
error: Error | null;
|
|
||||||
projectGraph: ProjectGraph | null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Include the original stack trace within the serialized error so that the client can show it to the user.
|
// Include the original stack trace within the serialized error so that the client can show it to the user.
|
||||||
function serializeError(error: Error | null): string | null {
|
function serializeError(error: Error | null): string | null {
|
||||||
if (!error) {
|
if (!error) {
|
||||||
|
|||||||
@ -4,8 +4,14 @@
|
|||||||
* and where we create the actual unix socket/named pipe for the daemon.
|
* and where we create the actual unix socket/named pipe for the daemon.
|
||||||
*/
|
*/
|
||||||
import { statSync, writeFileSync } from 'fs';
|
import { statSync, writeFileSync } from 'fs';
|
||||||
|
import { ensureDirSync, rmdirSync } from 'fs-extra';
|
||||||
import { join } from 'path';
|
import { join } from 'path';
|
||||||
import { projectGraphCacheDirectory } from '../utils/cache-directory';
|
import { projectGraphCacheDirectory } from '../utils/cache-directory';
|
||||||
|
import { createHash } from 'crypto';
|
||||||
|
import { tmpdir } from 'tmp';
|
||||||
|
import { workspaceRoot } from '../utils/workspace-root';
|
||||||
|
|
||||||
|
const socketDir = createSocketDir();
|
||||||
|
|
||||||
export const DAEMON_DIR_FOR_CURRENT_WORKSPACE = join(
|
export const DAEMON_DIR_FOR_CURRENT_WORKSPACE = join(
|
||||||
projectGraphCacheDirectory,
|
projectGraphCacheDirectory,
|
||||||
@ -18,7 +24,7 @@ export const DAEMON_OUTPUT_LOG_FILE = join(
|
|||||||
);
|
);
|
||||||
|
|
||||||
export const DAEMON_SOCKET_PATH = join(
|
export const DAEMON_SOCKET_PATH = join(
|
||||||
DAEMON_DIR_FOR_CURRENT_WORKSPACE,
|
socketDir,
|
||||||
// As per notes above on socket/named pipe length limitations, we keep this intentionally short
|
// As per notes above on socket/named pipe length limitations, we keep this intentionally short
|
||||||
'd.sock'
|
'd.sock'
|
||||||
);
|
);
|
||||||
@ -41,3 +47,30 @@ export function isDaemonDisabled() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function socketDirName() {
|
||||||
|
const hasher = createHash('sha256');
|
||||||
|
hasher.update(workspaceRoot);
|
||||||
|
const unique = hasher.digest('hex').substring(0, 20);
|
||||||
|
return join(tmpdir, unique);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* We try to create a socket file in a tmp dir, but if it doesn't work because
|
||||||
|
* for instance we don't have permissions, we create it in DAEMON_DIR_FOR_CURRENT_WORKSPACE
|
||||||
|
*/
|
||||||
|
function createSocketDir() {
|
||||||
|
try {
|
||||||
|
const dir = socketDirName();
|
||||||
|
ensureDirSync(dir);
|
||||||
|
return dir;
|
||||||
|
} catch (e) {
|
||||||
|
return DAEMON_DIR_FOR_CURRENT_WORKSPACE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function removeSocketDir() {
|
||||||
|
try {
|
||||||
|
rmdirSync(socketDir);
|
||||||
|
} catch (e) {}
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user