unrun 0.2.5 → 0.2.6
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/dist/index.d.mts +10 -4
- package/dist/index.mjs +1 -1
- package/dist/{src-Cy5isIwp.mjs → src-BW3bFBxp.mjs} +15 -8
- package/dist/sync/worker.mjs +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -33,11 +33,17 @@ interface Options {
|
|
|
33
33
|
}
|
|
34
34
|
//#endregion
|
|
35
35
|
//#region src/types.d.ts
|
|
36
|
-
interface Result {
|
|
36
|
+
interface Result<T = unknown> {
|
|
37
37
|
/**
|
|
38
38
|
* The module that was loaded.
|
|
39
|
+
* You can specify the type of the module by providing a type argument when using the `unrun` function.
|
|
39
40
|
*/
|
|
40
|
-
module:
|
|
41
|
+
module: T;
|
|
42
|
+
/**
|
|
43
|
+
* The dependencies involved when loading the targeted module.
|
|
44
|
+
* Note: this only includes local file dependencies, npm-resolved dependencies are excluded.
|
|
45
|
+
*/
|
|
46
|
+
dependencies: string[];
|
|
41
47
|
}
|
|
42
48
|
interface CliResult {
|
|
43
49
|
/**
|
|
@@ -53,7 +59,7 @@ interface CliResult {
|
|
|
53
59
|
* @param options - The options for loading the module.
|
|
54
60
|
* @returns A promise that resolves to the loaded module.
|
|
55
61
|
*/
|
|
56
|
-
declare function unrun(options: Options): Promise<Result
|
|
62
|
+
declare function unrun<T>(options: Options): Promise<Result<T>>;
|
|
57
63
|
/**
|
|
58
64
|
* Loads a module with JIT transpilation based on the provided options.
|
|
59
65
|
* This function runs synchronously using a worker thread.
|
|
@@ -61,7 +67,7 @@ declare function unrun(options: Options): Promise<Result>;
|
|
|
61
67
|
* @param options - The options for loading the module.
|
|
62
68
|
* @returns The loaded module.
|
|
63
69
|
*/
|
|
64
|
-
declare function unrunSync(options: Options): Result
|
|
70
|
+
declare function unrunSync<T>(options: Options): Result<T>;
|
|
65
71
|
/**
|
|
66
72
|
* Runs a given module with JIT transpilation based on the provided options.
|
|
67
73
|
* This function does not return the module, as it simply executes it.
|
package/dist/index.mjs
CHANGED
|
@@ -403,7 +403,11 @@ async function bundle(options) {
|
|
|
403
403
|
};
|
|
404
404
|
const rolldownOutput = await bundle$1.generate(outputOptions);
|
|
405
405
|
if (!rolldownOutput.output[0]) throw new Error("[unrun] No output chunk found");
|
|
406
|
-
|
|
406
|
+
const files = await bundle$1.watchFiles;
|
|
407
|
+
return {
|
|
408
|
+
chunk: rolldownOutput.output[0],
|
|
409
|
+
dependencies: files
|
|
410
|
+
};
|
|
407
411
|
}
|
|
408
412
|
|
|
409
413
|
//#endregion
|
|
@@ -539,14 +543,17 @@ async function loadModule(code, options) {
|
|
|
539
543
|
*/
|
|
540
544
|
async function unrun(options) {
|
|
541
545
|
const resolvedOptions = resolveOptions(options);
|
|
542
|
-
const
|
|
546
|
+
const output = await bundle(resolvedOptions);
|
|
543
547
|
let module;
|
|
544
548
|
try {
|
|
545
|
-
module = await loadModule(
|
|
549
|
+
module = await loadModule(output.chunk.code, resolvedOptions);
|
|
546
550
|
} catch (error) {
|
|
547
|
-
throw new Error(`[unrun] Import failed (code length: ${
|
|
551
|
+
throw new Error(`[unrun] Import failed (code length: ${output.chunk.code.length}): ${error.message}`);
|
|
548
552
|
}
|
|
549
|
-
return {
|
|
553
|
+
return {
|
|
554
|
+
module: preset(resolvedOptions, module),
|
|
555
|
+
dependencies: output.dependencies
|
|
556
|
+
};
|
|
550
557
|
}
|
|
551
558
|
/**
|
|
552
559
|
* Loads a module with JIT transpilation based on the provided options.
|
|
@@ -569,13 +576,13 @@ function unrunSync(options) {
|
|
|
569
576
|
*/
|
|
570
577
|
async function unrunCli(options, args = []) {
|
|
571
578
|
const resolvedOptions = resolveOptions(options);
|
|
572
|
-
const
|
|
573
|
-
const moduleUrl = writeModule(
|
|
579
|
+
const output = await bundle(resolvedOptions);
|
|
580
|
+
const moduleUrl = writeModule(output.chunk.code, resolvedOptions);
|
|
574
581
|
let cliResult;
|
|
575
582
|
try {
|
|
576
583
|
cliResult = await execModule(moduleUrl, args);
|
|
577
584
|
} catch (error) {
|
|
578
|
-
throw new Error(`[unrun] Run failed (code length: ${
|
|
585
|
+
throw new Error(`[unrun] Run failed (code length: ${output.chunk.code.length}): ${error.message}`);
|
|
579
586
|
}
|
|
580
587
|
cleanModule(moduleUrl, resolvedOptions);
|
|
581
588
|
return cliResult;
|
package/dist/sync/worker.mjs
CHANGED