workerd 0.0.1 → 0.20221111.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/README.md +6 -0
- package/bin/workerd +137 -0
- package/install.js +218 -0
- package/lib/main.js +156 -0
- package/package.json +20 -5
package/README.md
ADDED
package/bin/workerd
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (let key of __getOwnPropNames(from))
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
12
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
+
}
|
|
14
|
+
return to;
|
|
15
|
+
};
|
|
16
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
17
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
18
|
+
mod
|
|
19
|
+
));
|
|
20
|
+
|
|
21
|
+
// npm/lib/node-platform.ts
|
|
22
|
+
var import_fs = __toESM(require("fs"));
|
|
23
|
+
var import_os = __toESM(require("os"));
|
|
24
|
+
var import_path = __toESM(require("path"));
|
|
25
|
+
var knownPackages = {
|
|
26
|
+
"darwin arm64 LE": "@cloudflare/workerd-darwin-arm64",
|
|
27
|
+
"darwin x64 LE": "@cloudflare/workerd-darwin-64",
|
|
28
|
+
"linux arm64 LE": "@cloudflare/workerd-linux-arm64",
|
|
29
|
+
"linux x64 LE": "@cloudflare/workerd-linux-64",
|
|
30
|
+
"win32 x64 LE": "@cloudflare/workerd-linux-64"
|
|
31
|
+
};
|
|
32
|
+
function pkgAndSubpathForCurrentPlatform() {
|
|
33
|
+
let pkg;
|
|
34
|
+
let subpath;
|
|
35
|
+
let platformKey = `${process.platform} ${import_os.default.arch()} ${import_os.default.endianness()}`;
|
|
36
|
+
if (platformKey in knownPackages) {
|
|
37
|
+
pkg = knownPackages[platformKey];
|
|
38
|
+
subpath = "bin/workerd";
|
|
39
|
+
} else {
|
|
40
|
+
throw new Error(`Unsupported platform: ${platformKey}`);
|
|
41
|
+
}
|
|
42
|
+
return { pkg, subpath };
|
|
43
|
+
}
|
|
44
|
+
function pkgForSomeOtherPlatform() {
|
|
45
|
+
const libMain = require.resolve("workerd");
|
|
46
|
+
const nodeModulesDirectory = import_path.default.dirname(
|
|
47
|
+
import_path.default.dirname(import_path.default.dirname(libMain))
|
|
48
|
+
);
|
|
49
|
+
if (import_path.default.basename(nodeModulesDirectory) === "node_modules") {
|
|
50
|
+
for (const unixKey in knownPackages) {
|
|
51
|
+
try {
|
|
52
|
+
const pkg = knownPackages[unixKey];
|
|
53
|
+
if (import_fs.default.existsSync(import_path.default.join(nodeModulesDirectory, pkg)))
|
|
54
|
+
return pkg;
|
|
55
|
+
} catch {
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
function downloadedBinPath(pkg, subpath) {
|
|
62
|
+
const libDir = import_path.default.dirname(require.resolve("workerd"));
|
|
63
|
+
return import_path.default.join(libDir, `downloaded-${pkg}-${import_path.default.basename(subpath)}`);
|
|
64
|
+
}
|
|
65
|
+
function generateBinPath() {
|
|
66
|
+
const { pkg, subpath } = pkgAndSubpathForCurrentPlatform();
|
|
67
|
+
let binPath2;
|
|
68
|
+
try {
|
|
69
|
+
binPath2 = require.resolve(`${pkg}/${subpath}`);
|
|
70
|
+
} catch (e) {
|
|
71
|
+
binPath2 = downloadedBinPath(pkg, subpath);
|
|
72
|
+
if (!import_fs.default.existsSync(binPath2)) {
|
|
73
|
+
try {
|
|
74
|
+
require.resolve(pkg);
|
|
75
|
+
} catch {
|
|
76
|
+
const otherPkg = pkgForSomeOtherPlatform();
|
|
77
|
+
if (otherPkg) {
|
|
78
|
+
throw new Error(`
|
|
79
|
+
You installed workerd on another platform than the one you're currently using.
|
|
80
|
+
This won't work because workerd is written with native code and needs to
|
|
81
|
+
install a platform-specific binary executable.
|
|
82
|
+
|
|
83
|
+
Specifically the "${otherPkg}" package is present but this platform
|
|
84
|
+
needs the "${pkg}" package instead. People often get into this
|
|
85
|
+
situation by installing workerd on macOS and copying "node_modules"
|
|
86
|
+
into a Docker image that runs Linux.
|
|
87
|
+
|
|
88
|
+
If you are installing with npm, you can try not copying the "node_modules"
|
|
89
|
+
directory when you copy the files over, and running "npm ci" or "npm install"
|
|
90
|
+
on the destination platform after the copy. Or you could consider using yarn
|
|
91
|
+
instead which has built-in support for installing a package on multiple
|
|
92
|
+
platforms simultaneously.
|
|
93
|
+
|
|
94
|
+
If you are installing with yarn, you can try listing both this platform and the
|
|
95
|
+
other platform in your ".yarnrc.yml" file using the "supportedArchitectures"
|
|
96
|
+
feature: https://yarnpkg.com/configuration/yarnrc/#supportedArchitectures
|
|
97
|
+
Keep in mind that this means multiple copies of workerd will be present.
|
|
98
|
+
`);
|
|
99
|
+
}
|
|
100
|
+
throw new Error(`The package "${pkg}" could not be found, and is needed by workerd.
|
|
101
|
+
|
|
102
|
+
If you are installing workerd with npm, make sure that you don't specify the
|
|
103
|
+
"--no-optional" flag. The "optionalDependencies" package.json feature is used
|
|
104
|
+
by workerd to install the correct binary executable for your current platform.`);
|
|
105
|
+
}
|
|
106
|
+
throw e;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
let pnpapi;
|
|
110
|
+
try {
|
|
111
|
+
pnpapi = require("pnpapi");
|
|
112
|
+
} catch (e) {
|
|
113
|
+
}
|
|
114
|
+
if (pnpapi) {
|
|
115
|
+
const root = pnpapi.getPackageInformation(pnpapi.topLevel).packageLocation;
|
|
116
|
+
const binTargetPath = import_path.default.join(
|
|
117
|
+
root,
|
|
118
|
+
"node_modules",
|
|
119
|
+
".cache",
|
|
120
|
+
"workerd",
|
|
121
|
+
`pnpapi-${pkg}-${WORKERD_VERSION}-${import_path.default.basename(subpath)}`
|
|
122
|
+
);
|
|
123
|
+
if (!import_fs.default.existsSync(binTargetPath)) {
|
|
124
|
+
import_fs.default.mkdirSync(import_path.default.dirname(binTargetPath), { recursive: true });
|
|
125
|
+
import_fs.default.copyFileSync(binPath2, binTargetPath);
|
|
126
|
+
import_fs.default.chmodSync(binTargetPath, 493);
|
|
127
|
+
}
|
|
128
|
+
return { binPath: binTargetPath };
|
|
129
|
+
}
|
|
130
|
+
return { binPath: binPath2 };
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// npm/lib/node-shim.ts
|
|
134
|
+
var { binPath } = generateBinPath();
|
|
135
|
+
require("child_process").execFileSync(binPath, process.argv.slice(2), {
|
|
136
|
+
stdio: "inherit"
|
|
137
|
+
});
|
package/install.js
ADDED
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __copyProps = (to, from, except, desc) => {
|
|
8
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
9
|
+
for (let key of __getOwnPropNames(from))
|
|
10
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
11
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
12
|
+
}
|
|
13
|
+
return to;
|
|
14
|
+
};
|
|
15
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
16
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
17
|
+
mod
|
|
18
|
+
));
|
|
19
|
+
|
|
20
|
+
// npm/lib/node-platform.ts
|
|
21
|
+
var import_os = __toESM(require("os"));
|
|
22
|
+
var import_path = __toESM(require("path"));
|
|
23
|
+
var knownPackages = {
|
|
24
|
+
"darwin arm64 LE": "@cloudflare/workerd-darwin-arm64",
|
|
25
|
+
"darwin x64 LE": "@cloudflare/workerd-darwin-64",
|
|
26
|
+
"linux arm64 LE": "@cloudflare/workerd-linux-arm64",
|
|
27
|
+
"linux x64 LE": "@cloudflare/workerd-linux-64",
|
|
28
|
+
"win32 x64 LE": "@cloudflare/workerd-linux-64"
|
|
29
|
+
};
|
|
30
|
+
function pkgAndSubpathForCurrentPlatform() {
|
|
31
|
+
let pkg;
|
|
32
|
+
let subpath;
|
|
33
|
+
let platformKey = `${process.platform} ${import_os.default.arch()} ${import_os.default.endianness()}`;
|
|
34
|
+
if (platformKey in knownPackages) {
|
|
35
|
+
pkg = knownPackages[platformKey];
|
|
36
|
+
subpath = "bin/workerd";
|
|
37
|
+
} else {
|
|
38
|
+
throw new Error(`Unsupported platform: ${platformKey}`);
|
|
39
|
+
}
|
|
40
|
+
return { pkg, subpath };
|
|
41
|
+
}
|
|
42
|
+
function downloadedBinPath(pkg, subpath) {
|
|
43
|
+
const libDir = import_path.default.dirname(require.resolve("workerd"));
|
|
44
|
+
return import_path.default.join(libDir, `downloaded-${pkg}-${import_path.default.basename(subpath)}`);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// npm/lib/node-install.ts
|
|
48
|
+
var import_fs = __toESM(require("fs"));
|
|
49
|
+
var import_path2 = __toESM(require("path"));
|
|
50
|
+
var import_zlib = __toESM(require("zlib"));
|
|
51
|
+
var import_https = __toESM(require("https"));
|
|
52
|
+
var import_child_process = __toESM(require("child_process"));
|
|
53
|
+
var toPath = import_path2.default.join(__dirname, "bin", "workerd");
|
|
54
|
+
var isToPathJS = true;
|
|
55
|
+
function validateBinaryVersion(...command) {
|
|
56
|
+
command.push("--version");
|
|
57
|
+
const stdout = import_child_process.default.execFileSync(command.shift(), command, {
|
|
58
|
+
stdio: "pipe"
|
|
59
|
+
}).toString().trim();
|
|
60
|
+
if (stdout !== `workerd ${"2022-11-11"}`) {
|
|
61
|
+
throw new Error(
|
|
62
|
+
`Expected ${JSON.stringify(
|
|
63
|
+
"2022-11-11"
|
|
64
|
+
)} but got ${JSON.stringify(stdout)}`
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
function isYarn() {
|
|
69
|
+
const { npm_config_user_agent } = process.env;
|
|
70
|
+
if (npm_config_user_agent) {
|
|
71
|
+
return /\byarn\//.test(npm_config_user_agent);
|
|
72
|
+
}
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
function fetch(url) {
|
|
76
|
+
return new Promise((resolve, reject) => {
|
|
77
|
+
import_https.default.get(url, (res) => {
|
|
78
|
+
if ((res.statusCode === 301 || res.statusCode === 302) && res.headers.location)
|
|
79
|
+
return fetch(res.headers.location).then(resolve, reject);
|
|
80
|
+
if (res.statusCode !== 200)
|
|
81
|
+
return reject(new Error(`Server responded with ${res.statusCode}`));
|
|
82
|
+
let chunks = [];
|
|
83
|
+
res.on("data", (chunk) => chunks.push(chunk));
|
|
84
|
+
res.on("end", () => resolve(Buffer.concat(chunks)));
|
|
85
|
+
}).on("error", reject);
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
function extractFileFromTarGzip(buffer, subpath) {
|
|
89
|
+
try {
|
|
90
|
+
buffer = import_zlib.default.unzipSync(buffer);
|
|
91
|
+
} catch (err) {
|
|
92
|
+
throw new Error(
|
|
93
|
+
`Invalid gzip data in archive: ${err && err.message || err}`
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
let str = (i, n) => String.fromCharCode(...buffer.subarray(i, i + n)).replace(/\0.*$/, "");
|
|
97
|
+
let offset = 0;
|
|
98
|
+
subpath = `package/${subpath}`;
|
|
99
|
+
while (offset < buffer.length) {
|
|
100
|
+
let name = str(offset, 100);
|
|
101
|
+
let size = parseInt(str(offset + 124, 12), 8);
|
|
102
|
+
offset += 512;
|
|
103
|
+
if (!isNaN(size)) {
|
|
104
|
+
if (name === subpath)
|
|
105
|
+
return buffer.subarray(offset, offset + size);
|
|
106
|
+
offset += size + 511 & ~511;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
throw new Error(`Could not find ${JSON.stringify(subpath)} in archive`);
|
|
110
|
+
}
|
|
111
|
+
function installUsingNPM(pkg, subpath, binPath) {
|
|
112
|
+
const env = { ...process.env, npm_config_global: void 0 };
|
|
113
|
+
const libDir = import_path2.default.dirname(require.resolve("workerd"));
|
|
114
|
+
const installDir = import_path2.default.join(libDir, "npm-install");
|
|
115
|
+
import_fs.default.mkdirSync(installDir);
|
|
116
|
+
try {
|
|
117
|
+
import_fs.default.writeFileSync(import_path2.default.join(installDir, "package.json"), "{}");
|
|
118
|
+
import_child_process.default.execSync(
|
|
119
|
+
`npm install --loglevel=error --prefer-offline --no-audit --progress=false ${pkg}@${"0.20221111.0"}`,
|
|
120
|
+
{ cwd: installDir, stdio: "pipe", env }
|
|
121
|
+
);
|
|
122
|
+
const installedBinPath = import_path2.default.join(
|
|
123
|
+
installDir,
|
|
124
|
+
"node_modules",
|
|
125
|
+
pkg,
|
|
126
|
+
subpath
|
|
127
|
+
);
|
|
128
|
+
import_fs.default.renameSync(installedBinPath, binPath);
|
|
129
|
+
} finally {
|
|
130
|
+
try {
|
|
131
|
+
removeRecursive(installDir);
|
|
132
|
+
} catch {
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
function removeRecursive(dir) {
|
|
137
|
+
for (const entry of import_fs.default.readdirSync(dir)) {
|
|
138
|
+
const entryPath = import_path2.default.join(dir, entry);
|
|
139
|
+
let stats;
|
|
140
|
+
try {
|
|
141
|
+
stats = import_fs.default.lstatSync(entryPath);
|
|
142
|
+
} catch {
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
if (stats.isDirectory())
|
|
146
|
+
removeRecursive(entryPath);
|
|
147
|
+
else
|
|
148
|
+
import_fs.default.unlinkSync(entryPath);
|
|
149
|
+
}
|
|
150
|
+
import_fs.default.rmdirSync(dir);
|
|
151
|
+
}
|
|
152
|
+
function maybeOptimizePackage(binPath) {
|
|
153
|
+
if (!isYarn()) {
|
|
154
|
+
const tempPath = import_path2.default.join(__dirname, "bin-workerd");
|
|
155
|
+
try {
|
|
156
|
+
import_fs.default.linkSync(binPath, tempPath);
|
|
157
|
+
import_fs.default.renameSync(tempPath, toPath);
|
|
158
|
+
isToPathJS = false;
|
|
159
|
+
import_fs.default.unlinkSync(tempPath);
|
|
160
|
+
} catch {
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
async function downloadDirectlyFromNPM(pkg, subpath, binPath) {
|
|
165
|
+
const url = `https://registry.npmjs.org/${pkg}/-/${pkg}-${"0.20221111.0"}.tgz`;
|
|
166
|
+
console.error(`[workerd] Trying to download ${JSON.stringify(url)}`);
|
|
167
|
+
try {
|
|
168
|
+
import_fs.default.writeFileSync(
|
|
169
|
+
binPath,
|
|
170
|
+
extractFileFromTarGzip(await fetch(url), subpath)
|
|
171
|
+
);
|
|
172
|
+
import_fs.default.chmodSync(binPath, 493);
|
|
173
|
+
} catch (e) {
|
|
174
|
+
console.error(
|
|
175
|
+
`[workerd] Failed to download ${JSON.stringify(url)}: ${e && e.message || e}`
|
|
176
|
+
);
|
|
177
|
+
throw e;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
async function checkAndPreparePackage() {
|
|
181
|
+
const { pkg, subpath } = pkgAndSubpathForCurrentPlatform();
|
|
182
|
+
let binPath;
|
|
183
|
+
try {
|
|
184
|
+
binPath = require.resolve(`${pkg}/${subpath}`);
|
|
185
|
+
} catch (e) {
|
|
186
|
+
console.error(`[workerd] Failed to find package "${pkg}" on the file system
|
|
187
|
+
|
|
188
|
+
This can happen if you use the "--no-optional" flag. The "optionalDependencies"
|
|
189
|
+
package.json feature is used by workerd to install the correct binary executable
|
|
190
|
+
for your current platform. This install script will now attempt to work around
|
|
191
|
+
this. If that fails, you need to remove the "--no-optional" flag to use workerd.
|
|
192
|
+
`);
|
|
193
|
+
binPath = downloadedBinPath(pkg, subpath);
|
|
194
|
+
try {
|
|
195
|
+
console.error(`[workerd] Trying to install package "${pkg}" using npm`);
|
|
196
|
+
installUsingNPM(pkg, subpath, binPath);
|
|
197
|
+
} catch (e2) {
|
|
198
|
+
console.error(
|
|
199
|
+
`[workerd] Failed to install package "${pkg}" using npm: ${e2 && e2.message || e2}`
|
|
200
|
+
);
|
|
201
|
+
try {
|
|
202
|
+
await downloadDirectlyFromNPM(pkg, subpath, binPath);
|
|
203
|
+
} catch (e3) {
|
|
204
|
+
throw new Error(`Failed to install package "${pkg}"`);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
maybeOptimizePackage(binPath);
|
|
209
|
+
}
|
|
210
|
+
checkAndPreparePackage().then(() => {
|
|
211
|
+
if (process.platform !== "win32") {
|
|
212
|
+
if (isToPathJS) {
|
|
213
|
+
validateBinaryVersion(process.execPath, toPath);
|
|
214
|
+
} else {
|
|
215
|
+
validateBinaryVersion(toPath);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
});
|
package/lib/main.js
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
24
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
|
+
|
|
26
|
+
// npm/lib/node-path.ts
|
|
27
|
+
var node_path_exports = {};
|
|
28
|
+
__export(node_path_exports, {
|
|
29
|
+
compatibilityDate: () => compatibilityDate,
|
|
30
|
+
default: () => node_path_default,
|
|
31
|
+
version: () => version
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(node_path_exports);
|
|
34
|
+
|
|
35
|
+
// npm/lib/node-platform.ts
|
|
36
|
+
var import_fs = __toESM(require("fs"));
|
|
37
|
+
var import_os = __toESM(require("os"));
|
|
38
|
+
var import_path = __toESM(require("path"));
|
|
39
|
+
var knownPackages = {
|
|
40
|
+
"darwin arm64 LE": "@cloudflare/workerd-darwin-arm64",
|
|
41
|
+
"darwin x64 LE": "@cloudflare/workerd-darwin-64",
|
|
42
|
+
"linux arm64 LE": "@cloudflare/workerd-linux-arm64",
|
|
43
|
+
"linux x64 LE": "@cloudflare/workerd-linux-64",
|
|
44
|
+
"win32 x64 LE": "@cloudflare/workerd-linux-64"
|
|
45
|
+
};
|
|
46
|
+
function pkgAndSubpathForCurrentPlatform() {
|
|
47
|
+
let pkg;
|
|
48
|
+
let subpath;
|
|
49
|
+
let platformKey = `${process.platform} ${import_os.default.arch()} ${import_os.default.endianness()}`;
|
|
50
|
+
if (platformKey in knownPackages) {
|
|
51
|
+
pkg = knownPackages[platformKey];
|
|
52
|
+
subpath = "bin/workerd";
|
|
53
|
+
} else {
|
|
54
|
+
throw new Error(`Unsupported platform: ${platformKey}`);
|
|
55
|
+
}
|
|
56
|
+
return { pkg, subpath };
|
|
57
|
+
}
|
|
58
|
+
function pkgForSomeOtherPlatform() {
|
|
59
|
+
const libMain = require.resolve("workerd");
|
|
60
|
+
const nodeModulesDirectory = import_path.default.dirname(
|
|
61
|
+
import_path.default.dirname(import_path.default.dirname(libMain))
|
|
62
|
+
);
|
|
63
|
+
if (import_path.default.basename(nodeModulesDirectory) === "node_modules") {
|
|
64
|
+
for (const unixKey in knownPackages) {
|
|
65
|
+
try {
|
|
66
|
+
const pkg = knownPackages[unixKey];
|
|
67
|
+
if (import_fs.default.existsSync(import_path.default.join(nodeModulesDirectory, pkg)))
|
|
68
|
+
return pkg;
|
|
69
|
+
} catch {
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
function downloadedBinPath(pkg, subpath) {
|
|
76
|
+
const libDir = import_path.default.dirname(require.resolve("workerd"));
|
|
77
|
+
return import_path.default.join(libDir, `downloaded-${pkg}-${import_path.default.basename(subpath)}`);
|
|
78
|
+
}
|
|
79
|
+
function generateBinPath() {
|
|
80
|
+
const { pkg, subpath } = pkgAndSubpathForCurrentPlatform();
|
|
81
|
+
let binPath2;
|
|
82
|
+
try {
|
|
83
|
+
binPath2 = require.resolve(`${pkg}/${subpath}`);
|
|
84
|
+
} catch (e) {
|
|
85
|
+
binPath2 = downloadedBinPath(pkg, subpath);
|
|
86
|
+
if (!import_fs.default.existsSync(binPath2)) {
|
|
87
|
+
try {
|
|
88
|
+
require.resolve(pkg);
|
|
89
|
+
} catch {
|
|
90
|
+
const otherPkg = pkgForSomeOtherPlatform();
|
|
91
|
+
if (otherPkg) {
|
|
92
|
+
throw new Error(`
|
|
93
|
+
You installed workerd on another platform than the one you're currently using.
|
|
94
|
+
This won't work because workerd is written with native code and needs to
|
|
95
|
+
install a platform-specific binary executable.
|
|
96
|
+
|
|
97
|
+
Specifically the "${otherPkg}" package is present but this platform
|
|
98
|
+
needs the "${pkg}" package instead. People often get into this
|
|
99
|
+
situation by installing workerd on macOS and copying "node_modules"
|
|
100
|
+
into a Docker image that runs Linux.
|
|
101
|
+
|
|
102
|
+
If you are installing with npm, you can try not copying the "node_modules"
|
|
103
|
+
directory when you copy the files over, and running "npm ci" or "npm install"
|
|
104
|
+
on the destination platform after the copy. Or you could consider using yarn
|
|
105
|
+
instead which has built-in support for installing a package on multiple
|
|
106
|
+
platforms simultaneously.
|
|
107
|
+
|
|
108
|
+
If you are installing with yarn, you can try listing both this platform and the
|
|
109
|
+
other platform in your ".yarnrc.yml" file using the "supportedArchitectures"
|
|
110
|
+
feature: https://yarnpkg.com/configuration/yarnrc/#supportedArchitectures
|
|
111
|
+
Keep in mind that this means multiple copies of workerd will be present.
|
|
112
|
+
`);
|
|
113
|
+
}
|
|
114
|
+
throw new Error(`The package "${pkg}" could not be found, and is needed by workerd.
|
|
115
|
+
|
|
116
|
+
If you are installing workerd with npm, make sure that you don't specify the
|
|
117
|
+
"--no-optional" flag. The "optionalDependencies" package.json feature is used
|
|
118
|
+
by workerd to install the correct binary executable for your current platform.`);
|
|
119
|
+
}
|
|
120
|
+
throw e;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
let pnpapi;
|
|
124
|
+
try {
|
|
125
|
+
pnpapi = require("pnpapi");
|
|
126
|
+
} catch (e) {
|
|
127
|
+
}
|
|
128
|
+
if (pnpapi) {
|
|
129
|
+
const root = pnpapi.getPackageInformation(pnpapi.topLevel).packageLocation;
|
|
130
|
+
const binTargetPath = import_path.default.join(
|
|
131
|
+
root,
|
|
132
|
+
"node_modules",
|
|
133
|
+
".cache",
|
|
134
|
+
"workerd",
|
|
135
|
+
`pnpapi-${pkg}-${"0.20221111.0"}-${import_path.default.basename(subpath)}`
|
|
136
|
+
);
|
|
137
|
+
if (!import_fs.default.existsSync(binTargetPath)) {
|
|
138
|
+
import_fs.default.mkdirSync(import_path.default.dirname(binTargetPath), { recursive: true });
|
|
139
|
+
import_fs.default.copyFileSync(binPath2, binTargetPath);
|
|
140
|
+
import_fs.default.chmodSync(binTargetPath, 493);
|
|
141
|
+
}
|
|
142
|
+
return { binPath: binTargetPath };
|
|
143
|
+
}
|
|
144
|
+
return { binPath: binPath2 };
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// npm/lib/node-path.ts
|
|
148
|
+
var { binPath } = generateBinPath();
|
|
149
|
+
var node_path_default = binPath;
|
|
150
|
+
var compatibilityDate = "2022-11-11";
|
|
151
|
+
var version = "0.20221111.0";
|
|
152
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
153
|
+
0 && (module.exports = {
|
|
154
|
+
compatibilityDate,
|
|
155
|
+
version
|
|
156
|
+
});
|
package/package.json
CHANGED
|
@@ -1,8 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "workerd",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
|
|
3
|
+
"version": "0.20221111.0",
|
|
4
|
+
"description": "👷 workerd, Cloudflare's JavaScript/Wasm Runtime",
|
|
5
|
+
"repository": "https://github.com/cloudflare/workerd",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"postinstall": "node install.js"
|
|
8
|
+
},
|
|
9
|
+
"main": "lib/main.js",
|
|
10
|
+
"engines": {
|
|
11
|
+
"node": ">=16"
|
|
12
|
+
},
|
|
13
|
+
"bin": {
|
|
14
|
+
"workerd": "bin/workerd"
|
|
15
|
+
},
|
|
16
|
+
"optionalDependencies": {
|
|
17
|
+
"@cloudflare/workerd-darwin-arm64": "0.20221111.0",
|
|
18
|
+
"@cloudflare/workerd-darwin-64": "0.20221111.0",
|
|
19
|
+
"@cloudflare/workerd-linux-arm64": "0.20221111.0",
|
|
20
|
+
"@cloudflare/workerd-linux-64": "0.20221111.0"
|
|
21
|
+
},
|
|
22
|
+
"license": "Apache-2.0"
|
|
8
23
|
}
|