scriptc 0.2.3 → 0.2.5
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/package.json +9 -9
- package/scripts/install-native.mjs +54 -14
- package/scripts/prepare-native.mjs +5 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "scriptc",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.5",
|
|
4
4
|
"description": "Compile ordinary TypeScript and JavaScript to small, fast native executables — no Node, no V8, no JavaScript engine in the binary",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"homepage": "https://scriptc.dev",
|
|
@@ -21,16 +21,16 @@
|
|
|
21
21
|
"node": ">=24"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"@scriptc/compiler": "0.2.
|
|
24
|
+
"@scriptc/compiler": "0.2.5"
|
|
25
25
|
},
|
|
26
26
|
"optionalDependencies": {
|
|
27
|
-
"@scriptc/cli-darwin-
|
|
28
|
-
"@scriptc/cli-darwin-
|
|
29
|
-
"@scriptc/cli-linux-arm64-gnu": "0.2.
|
|
30
|
-
"@scriptc/cli-linux-arm64-musl": "0.2.
|
|
31
|
-
"@scriptc/cli-linux-x64-gnu": "0.2.
|
|
32
|
-
"@scriptc/cli-
|
|
33
|
-
"@scriptc/cli-
|
|
27
|
+
"@scriptc/cli-darwin-arm64": "0.2.5",
|
|
28
|
+
"@scriptc/cli-darwin-x64": "0.2.5",
|
|
29
|
+
"@scriptc/cli-linux-arm64-gnu": "0.2.5",
|
|
30
|
+
"@scriptc/cli-linux-arm64-musl": "0.2.5",
|
|
31
|
+
"@scriptc/cli-linux-x64-gnu": "0.2.5",
|
|
32
|
+
"@scriptc/cli-win32-x64-msvc": "0.2.5",
|
|
33
|
+
"@scriptc/cli-linux-x64-musl": "0.2.5"
|
|
34
34
|
},
|
|
35
35
|
"scripts": {
|
|
36
36
|
"build": "node ../../node_modules/typescript/bin/tsc -p tsconfig.json",
|
|
@@ -1,4 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
constants,
|
|
3
|
+
copyFileSync,
|
|
4
|
+
chmodSync,
|
|
5
|
+
existsSync,
|
|
6
|
+
mkdirSync,
|
|
7
|
+
readFileSync,
|
|
8
|
+
realpathSync,
|
|
9
|
+
renameSync,
|
|
10
|
+
rmSync,
|
|
11
|
+
writeFileSync,
|
|
12
|
+
} from "node:fs";
|
|
2
13
|
import { createRequire } from "node:module";
|
|
3
14
|
import { dirname, isAbsolute, join, relative, resolve } from "node:path";
|
|
4
15
|
import { fileURLToPath } from "node:url";
|
|
@@ -8,7 +19,8 @@ export function nativeCliPackage(platform, architecture, libc) {
|
|
|
8
19
|
if (host === "darwin-arm64" || host === "darwin-x64") return `@scriptc/cli-${host}`;
|
|
9
20
|
if (host === "win32-x64") return "@scriptc/cli-win32-x64-msvc";
|
|
10
21
|
if (host === "linux-x64" || host === "linux-arm64") {
|
|
11
|
-
if (libc !== "glibc" && libc !== "musl")
|
|
22
|
+
if (libc !== "glibc" && libc !== "musl")
|
|
23
|
+
throw new Error("could not identify the Linux C library");
|
|
12
24
|
return `@scriptc/cli-${host}-${libc === "musl" ? "musl" : "gnu"}`;
|
|
13
25
|
}
|
|
14
26
|
throw new Error(`scriptc has no native command for ${host}`);
|
|
@@ -28,38 +40,65 @@ function hostLibc() {
|
|
|
28
40
|
export function relocateToolchain(manifest, sourceDirectory, destinationDirectory) {
|
|
29
41
|
const relocated = { ...manifest };
|
|
30
42
|
const pathFrom = (value) => relative(destinationDirectory, resolve(sourceDirectory, value));
|
|
31
|
-
for (const name of [
|
|
43
|
+
for (const name of [
|
|
44
|
+
"ts7",
|
|
45
|
+
"llvm_package",
|
|
46
|
+
"runtime_pack",
|
|
47
|
+
"runtime_sources",
|
|
48
|
+
"declarations",
|
|
49
|
+
"comptime",
|
|
50
|
+
"wasi_node_runner",
|
|
51
|
+
]) {
|
|
32
52
|
if (typeof relocated[name] === "string") relocated[name] = pathFrom(relocated[name]);
|
|
33
53
|
}
|
|
34
54
|
for (const name of ["linker", "dsymutil", "archiver", "relocatable_linker"]) {
|
|
35
55
|
const value = relocated[name];
|
|
36
|
-
if (typeof value === "string" && !isAbsolute(value) && /[/\\]/.test(value))
|
|
56
|
+
if (typeof value === "string" && !isAbsolute(value) && /[/\\]/.test(value))
|
|
57
|
+
relocated[name] = pathFrom(value);
|
|
37
58
|
}
|
|
38
|
-
if (relocated.runtime_packs)
|
|
59
|
+
if (relocated.runtime_packs)
|
|
60
|
+
relocated.runtime_packs = relocated.runtime_packs.map((pack) => ({
|
|
61
|
+
...pack,
|
|
62
|
+
path: pathFrom(pack.path),
|
|
63
|
+
}));
|
|
39
64
|
return relocated;
|
|
40
65
|
}
|
|
41
66
|
|
|
42
|
-
export function installNativeCli(
|
|
67
|
+
export function installNativeCli(
|
|
68
|
+
directory,
|
|
69
|
+
packageName = nativeCliPackage(process.platform, process.arch, hostLibc()),
|
|
70
|
+
) {
|
|
43
71
|
directory = realpathSync(directory);
|
|
44
72
|
const require = createRequire(join(directory, "package.json"));
|
|
45
73
|
const packageManifest = JSON.parse(readFileSync(join(directory, "package.json"), "utf8"));
|
|
46
74
|
const version = packageManifest.version;
|
|
47
75
|
let platformManifest;
|
|
48
|
-
try {
|
|
49
|
-
|
|
76
|
+
try {
|
|
77
|
+
platformManifest = require.resolve(`${packageName}/package.json`);
|
|
78
|
+
} catch {
|
|
79
|
+
throw new Error(
|
|
80
|
+
`scriptc requires ${packageName}@${version}; reinstall with optional dependencies enabled`,
|
|
81
|
+
);
|
|
82
|
+
}
|
|
50
83
|
const identity = JSON.parse(readFileSync(platformManifest, "utf8"));
|
|
51
|
-
if (identity.name !== packageName || identity.version !== version)
|
|
84
|
+
if (identity.name !== packageName || identity.version !== version)
|
|
85
|
+
throw new Error(`scriptc requires ${packageName}@${version}, found ${identity.version}`);
|
|
52
86
|
const sourceDirectory = join(dirname(platformManifest), "dist", "bin");
|
|
53
87
|
const source = join(sourceDirectory, process.platform === "win32" ? "scriptc.exe" : "scriptc");
|
|
54
88
|
const original = JSON.parse(readFileSync(source + ".json", "utf8"));
|
|
55
|
-
if (original.schema !== "scriptc.native-toolchain.v1" || original.compiler_version !== version)
|
|
89
|
+
if (original.schema !== "scriptc.native-toolchain.v1" || original.compiler_version !== version)
|
|
90
|
+
throw new Error("native compiler toolchain version does not match this installation");
|
|
56
91
|
const bin = join(directory, "bin");
|
|
57
92
|
mkdirSync(bin, { recursive: true });
|
|
58
93
|
const manifest = relocateToolchain(original, sourceDirectory, bin);
|
|
59
94
|
// npm normalizes modes for payloads outside package bin entries. These
|
|
60
95
|
// tools are launched directly by the compiler after installation.
|
|
61
96
|
if (process.platform !== "win32") {
|
|
62
|
-
for (const path of [
|
|
97
|
+
for (const path of [
|
|
98
|
+
manifest.ts7,
|
|
99
|
+
manifest.comptime,
|
|
100
|
+
join(manifest.llvm_package, "bin/scriptc-llvm-codegen"),
|
|
101
|
+
]) {
|
|
63
102
|
chmodSync(resolve(bin, path), 0o755);
|
|
64
103
|
}
|
|
65
104
|
}
|
|
@@ -86,10 +125,11 @@ if (process.argv[1] && resolve(process.argv[1]) === fileURLToPath(import.meta.ur
|
|
|
86
125
|
const manifest = JSON.parse(readFileSync(join(directory, "package.json"), "utf8"));
|
|
87
126
|
// A source checkout builds the native distribution separately. pnpm pack
|
|
88
127
|
// replaces workspace ranges with release versions before publication.
|
|
89
|
-
const workspace = Object.values(manifest.optionalDependencies ?? {}).some((value) =>
|
|
128
|
+
const workspace = Object.values(manifest.optionalDependencies ?? {}).some((value) =>
|
|
129
|
+
String(value).startsWith("workspace:"),
|
|
130
|
+
);
|
|
90
131
|
if (!workspace) installNativeCli(directory);
|
|
91
|
-
}
|
|
92
|
-
catch (error) {
|
|
132
|
+
} catch (error) {
|
|
93
133
|
process.stderr.write(`scriptc: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
94
134
|
process.exitCode = 1;
|
|
95
135
|
}
|
|
@@ -8,8 +8,11 @@ export function prepareNativeCommand(directory) {
|
|
|
8
8
|
// npm creates bin links before postinstall. The payload must exist in the
|
|
9
9
|
// tarball, and no shebang may pin the Windows shim to an interpreter.
|
|
10
10
|
// Installation replaces this placeholder with the platform executable.
|
|
11
|
-
writeFileSync(
|
|
12
|
-
"
|
|
11
|
+
writeFileSync(
|
|
12
|
+
join(bin, "scriptc.exe"),
|
|
13
|
+
"echo 'scriptc: native installation is incomplete; enable install scripts and reinstall scriptc' >&2\nexit 1\n",
|
|
14
|
+
{ mode: 0o755 },
|
|
15
|
+
);
|
|
13
16
|
rmSync(join(bin, "scriptc.exe.json"), { force: true });
|
|
14
17
|
}
|
|
15
18
|
|