@brrock/oj 0.0.0-stage → 0.0.0
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/oj.js +27 -0
- package/index.js +62 -0
- package/package.json +25 -4
- package/README.md +0 -3
package/bin/oj.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
const { spawnSync } = require("child_process");
|
|
5
|
+
const { binaryPath, vendoredRolldownDir } = require("..");
|
|
6
|
+
|
|
7
|
+
let bin;
|
|
8
|
+
try {
|
|
9
|
+
bin = binaryPath();
|
|
10
|
+
} catch (e) {
|
|
11
|
+
console.error(e.message);
|
|
12
|
+
process.exit(1);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const env = { ...process.env };
|
|
16
|
+
if (env.OJ_VENDORED_ROLLDOWN === undefined) {
|
|
17
|
+
const dir = vendoredRolldownDir();
|
|
18
|
+
if (dir) env.OJ_VENDORED_ROLLDOWN = dir;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const result = spawnSync(bin, process.argv.slice(2), { stdio: "inherit", env });
|
|
22
|
+
if (result.error) {
|
|
23
|
+
console.error(`@brrock/oj: failed to run ${bin}: ${result.error.message}`);
|
|
24
|
+
process.exit(1);
|
|
25
|
+
}
|
|
26
|
+
if (result.signal) process.kill(process.pid, result.signal);
|
|
27
|
+
process.exit(result.status ?? 1);
|
package/index.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const fs = require("fs");
|
|
4
|
+
const path = require("path");
|
|
5
|
+
|
|
6
|
+
const PLATFORMS = {
|
|
7
|
+
"linux-x64": "@brrock/oj-linux-x64-gnu",
|
|
8
|
+
"linux-arm64": "@brrock/oj-linux-arm64-gnu",
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
/** Absolute path to the oj binary for this machine. Throws if unsupported. */
|
|
12
|
+
function binaryPath() {
|
|
13
|
+
if (process.env.OJ_BINARY_PATH) return process.env.OJ_BINARY_PATH;
|
|
14
|
+
|
|
15
|
+
const key = `${process.platform}-${process.arch}`;
|
|
16
|
+
const pkg = PLATFORMS[key];
|
|
17
|
+
if (!pkg) {
|
|
18
|
+
throw new Error(
|
|
19
|
+
`@brrock/oj: no prebuilt oj for ${key}. Supported: ${Object.keys(PLATFORMS).join(", ")}.\n` +
|
|
20
|
+
"On other platforms install oj with `cargo install oj --locked` and set OJ_BINARY_PATH.",
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
let bin;
|
|
25
|
+
try {
|
|
26
|
+
bin = require.resolve(`${pkg}/bin/oj`);
|
|
27
|
+
} catch {
|
|
28
|
+
throw new Error(
|
|
29
|
+
`@brrock/oj: the platform package "${pkg}" is not installed.\n` +
|
|
30
|
+
"It is an optionalDependency; make sure optional dependencies are not omitted " +
|
|
31
|
+
"(--omit=optional / --no-optional) and that your lockfile was not created on a different platform only.",
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// npm normally keeps the exec bit, but some installers/caches drop it.
|
|
36
|
+
try {
|
|
37
|
+
fs.accessSync(bin, fs.constants.X_OK);
|
|
38
|
+
} catch {
|
|
39
|
+
try {
|
|
40
|
+
fs.chmodSync(bin, 0o755);
|
|
41
|
+
} catch {}
|
|
42
|
+
}
|
|
43
|
+
return bin;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Directory holding node_modules/rolldown, for OJ_VENDORED_ROLLDOWN: oj runs
|
|
48
|
+
* its own TanStack Start bundles on the rolldown it was tested against
|
|
49
|
+
* (the upstream nix build vendors it the same way). Returns undefined if
|
|
50
|
+
* rolldown can't be found, in which case oj falls back to the app's copy.
|
|
51
|
+
*/
|
|
52
|
+
function vendoredRolldownDir() {
|
|
53
|
+
try {
|
|
54
|
+
const pkgJson = fs.realpathSync(require.resolve("rolldown/package.json"));
|
|
55
|
+
// .../<dir>/node_modules/rolldown/package.json -> <dir>
|
|
56
|
+
return path.dirname(path.dirname(path.dirname(pkgJson)));
|
|
57
|
+
} catch {
|
|
58
|
+
return undefined;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
module.exports = { binaryPath, vendoredRolldownDir };
|
package/package.json
CHANGED
|
@@ -1,6 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@brrock/oj",
|
|
3
|
-
"version": "0.0.0
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "Prebuilt Linux binaries of oj (lovablelabs/oj), e.g. for running oj on Vercel",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/brrock/oj-builds.git"
|
|
9
|
+
},
|
|
10
|
+
"homepage": "https://github.com/lovablelabs/oj",
|
|
11
|
+
"keywords": ["oj", "vite", "bundler", "vercel"],
|
|
12
|
+
"bin": {
|
|
13
|
+
"oj": "bin/oj.js"
|
|
14
|
+
},
|
|
15
|
+
"main": "index.js",
|
|
16
|
+
"files": ["bin", "index.js", "README.md"],
|
|
17
|
+
"engines": {
|
|
18
|
+
"node": ">=18"
|
|
19
|
+
},
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"rolldown": "1.2.1"
|
|
22
|
+
},
|
|
23
|
+
"optionalDependencies": {
|
|
24
|
+
"@brrock/oj-linux-x64-gnu": "0.0.0",
|
|
25
|
+
"@brrock/oj-linux-arm64-gnu": "0.0.0"
|
|
26
|
+
}
|
|
27
|
+
}
|
package/README.md
DELETED