@este.systems/dsc 0.1.2 → 0.1.3
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/bin/dsc.mjs +19 -6
- package/package.json +1 -1
package/bin/dsc.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { spawn } from "node:child_process";
|
|
3
3
|
import { existsSync } from "node:fs";
|
|
4
|
-
import { fileURLToPath } from "node:url";
|
|
4
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
5
5
|
import { dirname, join } from "node:path";
|
|
6
6
|
|
|
7
7
|
// Resolve the package root from this file's location. With `npm link` the
|
|
@@ -10,14 +10,22 @@ import { dirname, join } from "node:path";
|
|
|
10
10
|
const here = dirname(fileURLToPath(import.meta.url));
|
|
11
11
|
const pkgRoot = dirname(here);
|
|
12
12
|
const tsxBin = join(pkgRoot, "node_modules", ".bin", "tsx");
|
|
13
|
+
const tsxBinCmd = process.platform === "win32" ? tsxBin + ".cmd" : tsxBin;
|
|
13
14
|
const srcEntry = join(pkgRoot, "src", "index.ts");
|
|
14
15
|
const distEntry = join(pkgRoot, "dist", "index.js");
|
|
15
16
|
|
|
16
|
-
|
|
17
|
+
const tsxAvailable = existsSync(tsxBin) || existsSync(tsxBinCmd);
|
|
18
|
+
|
|
19
|
+
if (tsxAvailable && existsSync(srcEntry)) {
|
|
17
20
|
// Dev: run TS sources directly. Live changes pick up on next launch.
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
+
// On Windows, npm installs shim .cmd alongside the bare executable —
|
|
22
|
+
// spawn with shell:true so either is found, and quote argv values that
|
|
23
|
+
// might contain spaces (e.g. paths in C:\Program Files\...).
|
|
24
|
+
const child = spawn(
|
|
25
|
+
process.platform === "win32" ? tsxBinCmd : tsxBin,
|
|
26
|
+
[srcEntry, ...process.argv.slice(2)],
|
|
27
|
+
{ stdio: "inherit", shell: process.platform === "win32" },
|
|
28
|
+
);
|
|
21
29
|
child.on("exit", (code, signal) => {
|
|
22
30
|
if (signal) process.kill(process.pid, signal);
|
|
23
31
|
else process.exit(code ?? 0);
|
|
@@ -25,5 +33,10 @@ if (existsSync(tsxBin) && existsSync(srcEntry)) {
|
|
|
25
33
|
} else {
|
|
26
34
|
// Fallback: production-style install without devDeps. Use the compiled
|
|
27
35
|
// output instead. Run `npm run build` to refresh `dist/`.
|
|
28
|
-
|
|
36
|
+
//
|
|
37
|
+
// Dynamic import() requires a file:// URL on Windows (an absolute path
|
|
38
|
+
// like `C:\path\file.js` gets parsed with `c:` as a URL scheme, which
|
|
39
|
+
// fails with ERR_UNSUPPORTED_ESM_URL_SCHEME). pathToFileURL handles
|
|
40
|
+
// the conversion correctly on every platform.
|
|
41
|
+
await import(pathToFileURL(distEntry).href);
|
|
29
42
|
}
|