aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/cli/scripts/npm-native-packages
diff options
context:
space:
mode:
author简律纯 <hsiangnianian@outlook.com>2023-04-28 01:36:44 +0800
committer简律纯 <hsiangnianian@outlook.com>2023-04-28 01:36:44 +0800
commitdd84b9d64fb98746a230cd24233ff50a562c39c9 (patch)
treeb583261ef00b3afe72ec4d6dacb31e57779a6faf /cli/scripts/npm-native-packages
parent0b46fcd72ac34382387b2bcf9095233efbcc52f4 (diff)
downloadHydroRoll-dd84b9d64fb98746a230cd24233ff50a562c39c9.tar.gz
HydroRoll-dd84b9d64fb98746a230cd24233ff50a562c39c9.zip
Diffstat (limited to 'cli/scripts/npm-native-packages')
-rw-r--r--cli/scripts/npm-native-packages/.gitignore1
-rw-r--r--cli/scripts/npm-native-packages/npm-native-packages.js57
-rw-r--r--cli/scripts/npm-native-packages/template/README.md3
-rw-r--r--cli/scripts/npm-native-packages/template/bin/turbo15
-rw-r--r--cli/scripts/npm-native-packages/template/template.package.json12
5 files changed, 88 insertions, 0 deletions
diff --git a/cli/scripts/npm-native-packages/.gitignore b/cli/scripts/npm-native-packages/.gitignore
new file mode 100644
index 0000000..84c048a
--- /dev/null
+++ b/cli/scripts/npm-native-packages/.gitignore
@@ -0,0 +1 @@
+/build/
diff --git a/cli/scripts/npm-native-packages/npm-native-packages.js b/cli/scripts/npm-native-packages/npm-native-packages.js
new file mode 100644
index 0000000..06ab67f
--- /dev/null
+++ b/cli/scripts/npm-native-packages/npm-native-packages.js
@@ -0,0 +1,57 @@
+#!/usr/bin/env node
+
+const fs = require("fs");
+const path = require("path");
+
+// Map to node os and arch names.
+const nodeOsLookup = {
+ darwin: "darwin",
+ linux: "linux",
+ windows: "win32",
+};
+
+const nodeArchLookup = {
+ amd64: "x64",
+ arm64: "arm64",
+};
+
+const humanizedArchLookup = {
+ amd64: "64",
+ arm64: "arm64",
+};
+
+const template = require("./template/template.package.json");
+const os = process.argv[2];
+const arch = process.argv[3];
+const version = process.argv[4];
+
+template.name = `turbo-${os}-${humanizedArchLookup[arch]}`;
+template.description = `The ${os}-${humanizedArchLookup[arch]} binary for turbo, a monorepo build system.`;
+template.os = [nodeOsLookup[os]];
+template.cpu = [nodeArchLookup[arch]];
+template.version = version;
+
+const outputPath = path.join(__dirname, "build", template.name);
+fs.rmSync(outputPath, { recursive: true, force: true });
+fs.mkdirSync(path.join(outputPath, "bin"), { recursive: true });
+
+if (os === "windows") {
+ fs.copyFileSync(
+ path.join(__dirname, "template", "bin", "turbo"),
+ path.join(outputPath, "bin", "turbo")
+ );
+}
+fs.copyFileSync(
+ path.join(__dirname, "template", "README.md"),
+ path.join(outputPath, "README.md")
+);
+fs.writeFileSync(
+ path.join(outputPath, "package.json"),
+ JSON.stringify(template, null, 2)
+);
+
+const goBin = os === "windows" ? "go-turbo.exe" : "go-turbo";
+fs.copyFileSync(
+ path.join(__dirname, "..", "..", `dist-${os}-${arch}`, goBin),
+ path.join(outputPath, "bin", goBin)
+);
diff --git a/cli/scripts/npm-native-packages/template/README.md b/cli/scripts/npm-native-packages/template/README.md
new file mode 100644
index 0000000..fcbd4c0
--- /dev/null
+++ b/cli/scripts/npm-native-packages/template/README.md
@@ -0,0 +1,3 @@
+# `turbo`
+
+This is a platform-specific binary for Turborepo, a monorepo build system. See https://github.com/vercel/turbo for details.
diff --git a/cli/scripts/npm-native-packages/template/bin/turbo b/cli/scripts/npm-native-packages/template/bin/turbo
new file mode 100644
index 0000000..4557a07
--- /dev/null
+++ b/cli/scripts/npm-native-packages/template/bin/turbo
@@ -0,0 +1,15 @@
+#!/usr/bin/env node
+
+// Unfortunately even though npm shims "bin" commands on Windows with auto-
+// generated forwarding scripts, it doesn't strip the ".exe" from the file name
+// first. So it's possible to publish executables via npm on all platforms
+// except Windows. I consider this a npm bug.
+//
+// My workaround is to add this script as another layer of indirection. It'll
+// be slower because node has to boot up just to shell out to the actual exe,
+// but Windows is somewhat of a second-class platform to npm so it's the best
+// I can do I think.
+const path = require('path');
+const turbo_exe = path.join(__dirname, 'turbo.exe');
+const child_process = require('child_process');
+child_process.spawnSync(turbo_exe, process.argv.slice(2), { stdio: 'inherit' });
diff --git a/cli/scripts/npm-native-packages/template/template.package.json b/cli/scripts/npm-native-packages/template/template.package.json
new file mode 100644
index 0000000..fdc72c0
--- /dev/null
+++ b/cli/scripts/npm-native-packages/template/template.package.json
@@ -0,0 +1,12 @@
+{
+ "name": "turbo-{{Os}}-{{Arch}}",
+ "version": "{{Version}",
+ "description": "The {{Os}}-{{Arch}} binary for turbo, a monorepo build system.",
+ "repository": "https://github.com/vercel/turbo",
+ "bugs": "https://github.com/vercel/turbo/issues",
+ "homepage": "https://turbo.build/repo",
+ "license": "MPL-2.0",
+ "os": ["{{Os}}"],
+ "cpu": ["{{Arch}}"],
+ "preferUnplugged": true
+}