@knighted/duel 4.0.0-rc.0 → 4.0.0-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -1
- package/dist/cjs/duel.cjs +287 -93
- package/dist/cjs/init.cjs +2 -1
- package/dist/cjs/init.d.cts +23 -14
- package/dist/cjs/util.cjs +84 -3
- package/dist/cjs/util.d.cts +15 -4
- package/dist/esm/duel.js +290 -96
- package/dist/esm/init.js +2 -1
- package/dist/esm/util.d.ts +9 -0
- package/dist/esm/util.js +84 -5
- package/package.json +9 -7
package/dist/cjs/util.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.runExportsValidationBlock = exports.maybeLinkNodeModules = exports.exitOnDiagnostics = exports.processDiagnosticsForFile = exports.ensureDotSlash = exports.stripKnownExt = exports.generateExports = exports.getSubpath = exports.readExportsConfig = exports.getCompileFiles = exports.getRealPathAsFileUrl = exports.logWarn = exports.logSuccess = exports.logError = exports.log = void 0;
|
|
3
|
+
exports.runExportsValidationBlock = exports.maybeLinkNodeModules = exports.exitOnDiagnostics = exports.processDiagnosticsForFile = exports.registerCleanupHandlers = exports.createTempCleanup = exports.ensureDotSlash = exports.stripKnownExt = exports.generateExports = exports.getSubpath = exports.readExportsConfig = exports.getCompileFiles = exports.getRealPathAsFileUrl = exports.logWarn = exports.logSuccess = exports.logError = exports.log = void 0;
|
|
4
4
|
const node_url_1 = require("node:url");
|
|
5
5
|
const promises_1 = require("node:fs/promises");
|
|
6
6
|
const node_fs_1 = require("node:fs");
|
|
@@ -42,6 +42,85 @@ const logWarn = msg => log(msg, 'warn');
|
|
|
42
42
|
exports.logWarn = logWarn;
|
|
43
43
|
const logError = msg => log(msg, 'error');
|
|
44
44
|
exports.logError = logError;
|
|
45
|
+
const createTempCleanup = ({ subDir, keepTemp = false, logWarnFn = logWarn }) => {
|
|
46
|
+
let cleaned = false;
|
|
47
|
+
let cleanupPromise = null;
|
|
48
|
+
// Marks cleanup as started; returns false when already running or completed.
|
|
49
|
+
const beginCleanup = () => {
|
|
50
|
+
if (cleaned)
|
|
51
|
+
return false;
|
|
52
|
+
cleaned = true;
|
|
53
|
+
return true;
|
|
54
|
+
};
|
|
55
|
+
const cleanupTempSync = () => {
|
|
56
|
+
if (!beginCleanup())
|
|
57
|
+
return;
|
|
58
|
+
if (keepTemp) {
|
|
59
|
+
logWarnFn(`DUEL_KEEP_TEMP=1 set; temp workspace preserved at ${subDir}`);
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
try {
|
|
63
|
+
(0, node_fs_1.rmSync)(subDir, { force: true, recursive: true });
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
/* ignore */
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
const cleanupTemp = async () => {
|
|
70
|
+
if (cleanupPromise)
|
|
71
|
+
return cleanupPromise;
|
|
72
|
+
const runCleanup = async () => {
|
|
73
|
+
if (!beginCleanup())
|
|
74
|
+
return;
|
|
75
|
+
if (keepTemp) {
|
|
76
|
+
logWarnFn(`DUEL_KEEP_TEMP=1 set; temp workspace preserved at ${subDir}`);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
try {
|
|
80
|
+
await (0, promises_1.rm)(subDir, { force: true, recursive: true });
|
|
81
|
+
}
|
|
82
|
+
catch {
|
|
83
|
+
/* ignore */
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
cleanupPromise = runCleanup();
|
|
87
|
+
return cleanupPromise;
|
|
88
|
+
};
|
|
89
|
+
return { cleanupTempSync, cleanupTemp };
|
|
90
|
+
};
|
|
91
|
+
exports.createTempCleanup = createTempCleanup;
|
|
92
|
+
const registerCleanupHandlers = cleanupTempSync => {
|
|
93
|
+
const onExit = () => cleanupTempSync();
|
|
94
|
+
const onSigint = () => {
|
|
95
|
+
cleanupTempSync();
|
|
96
|
+
process.exit(1);
|
|
97
|
+
};
|
|
98
|
+
const onSigterm = () => {
|
|
99
|
+
cleanupTempSync();
|
|
100
|
+
process.exit(1);
|
|
101
|
+
};
|
|
102
|
+
const onUncaught = err => {
|
|
103
|
+
cleanupTempSync();
|
|
104
|
+
throw err;
|
|
105
|
+
};
|
|
106
|
+
const onUnhandled = reason => {
|
|
107
|
+
cleanupTempSync();
|
|
108
|
+
throw reason instanceof Error ? reason : new Error(String(reason));
|
|
109
|
+
};
|
|
110
|
+
process.once('exit', onExit);
|
|
111
|
+
process.once('SIGINT', onSigint);
|
|
112
|
+
process.once('SIGTERM', onSigterm);
|
|
113
|
+
process.once('uncaughtException', onUncaught);
|
|
114
|
+
process.once('unhandledRejection', onUnhandled);
|
|
115
|
+
return () => {
|
|
116
|
+
process.removeListener('exit', onExit);
|
|
117
|
+
process.removeListener('SIGINT', onSigint);
|
|
118
|
+
process.removeListener('SIGTERM', onSigterm);
|
|
119
|
+
process.removeListener('uncaughtException', onUncaught);
|
|
120
|
+
process.removeListener('unhandledRejection', onUnhandled);
|
|
121
|
+
};
|
|
122
|
+
};
|
|
123
|
+
exports.registerCleanupHandlers = registerCleanupHandlers;
|
|
45
124
|
const getRealPathAsFileUrl = async (path) => {
|
|
46
125
|
const realPath = await (0, promises_1.realpath)(path);
|
|
47
126
|
const asFileUrl = (0, node_url_1.pathToFileURL)(realPath).href;
|
|
@@ -348,8 +427,10 @@ const maybeLinkNodeModules = async (projectRoot, subDir, symlinkFn = promises_1.
|
|
|
348
427
|
try {
|
|
349
428
|
await symlinkFn(nodeModules, (0, node_path_1.join)(subDir, 'node_modules'), 'junction');
|
|
350
429
|
}
|
|
351
|
-
catch {
|
|
352
|
-
|
|
430
|
+
catch (err) {
|
|
431
|
+
if (err?.code === 'EEXIST')
|
|
432
|
+
return;
|
|
433
|
+
logWarn(`Failed to link node_modules into temp workspace (falling back to existing resolution): ${err.message}`);
|
|
353
434
|
}
|
|
354
435
|
}
|
|
355
436
|
};
|
package/dist/cjs/util.d.cts
CHANGED
|
@@ -2,8 +2,8 @@ export function log(msg?: string, level?: string, opts?: {}): void;
|
|
|
2
2
|
export function logError(msg: any): void;
|
|
3
3
|
export function logSuccess(msg: any): void;
|
|
4
4
|
export function logWarn(msg: any): void;
|
|
5
|
-
export function getRealPathAsFileUrl(path: any): Promise<
|
|
6
|
-
export function getCompileFiles(tscPath: any, options?: {}):
|
|
5
|
+
export function getRealPathAsFileUrl(path: any): Promise<string>;
|
|
6
|
+
export function getCompileFiles(tscPath: any, options?: {}): string[];
|
|
7
7
|
export function readExportsConfig(configPath: any, pkgDir: any): Promise<{
|
|
8
8
|
entries: any[];
|
|
9
9
|
main: any;
|
|
@@ -18,7 +18,18 @@ export function generateExports(options: any): Promise<{
|
|
|
18
18
|
}>;
|
|
19
19
|
export function stripKnownExt(path: any): any;
|
|
20
20
|
export function ensureDotSlash(path: any): any;
|
|
21
|
+
export function createTempCleanup({ subDir, keepTemp, logWarnFn }: {
|
|
22
|
+
subDir: any;
|
|
23
|
+
keepTemp?: boolean | undefined;
|
|
24
|
+
logWarnFn?: ((msg: any) => void) | undefined;
|
|
25
|
+
}): {
|
|
26
|
+
cleanupTempSync: () => void;
|
|
27
|
+
cleanupTemp: () => Promise<any>;
|
|
28
|
+
};
|
|
29
|
+
export function registerCleanupHandlers(cleanupTempSync: any): () => void;
|
|
21
30
|
export function processDiagnosticsForFile(diagnostics: any, projectDir: any, logDiagnosticsFn: any): any;
|
|
22
|
-
export function exitOnDiagnostics(hasError: any, exitFn?:
|
|
23
|
-
export function maybeLinkNodeModules(projectRoot: any, subDir: any, symlinkFn?:
|
|
31
|
+
export function exitOnDiagnostics(hasError: any, exitFn?: (code?: number | string | null) => never): void;
|
|
32
|
+
export function maybeLinkNodeModules(projectRoot: any, subDir: any, symlinkFn?: typeof symlink, findUpFn?: typeof findUp): Promise<void>;
|
|
24
33
|
export function runExportsValidationBlock(options: any): Promise<any>;
|
|
34
|
+
import { symlink } from 'node:fs/promises';
|
|
35
|
+
import { findUp } from 'find-up';
|