@bufbuild/protoc-gen-es 0.0.1-alpha.1

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.
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env node
2
+
3
+ const { basename } = require("path");
4
+
5
+ // TODO(tstamm) shim for failed installation/yarn berry/windows/missing optional dependency
6
+
7
+ process.stderr.write(`Failed to locate the binary for ${basename(__dirname)}.
8
+ Platform: ${process.platform}
9
+ Architecture: ${process.arch}
10
+ `);
11
+ process.exit(1);
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "@bufbuild/protoc-gen-es",
3
+ "version": "0.0.1-alpha.1",
4
+ "description": "protoc-gen-es",
5
+ "license": "Apache-2.0",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/bufbuild/protobuf-es.git"
9
+ },
10
+ "bin": {
11
+ "protoc-gen-es": "bin/protoc-gen-es"
12
+ },
13
+ "scripts": {
14
+ "postinstall": "node postinstall.cjs"
15
+ },
16
+ "engines": {
17
+ "node": ">=8.5"
18
+ },
19
+ "optionalDependencies": {
20
+ "@bufbuild/protoc-gen-es-darwin-64": "0.0.1-alpha.1",
21
+ "@bufbuild/protoc-gen-es-darwin-arm64": "0.0.1-alpha.1",
22
+ "@bufbuild/protoc-gen-es-windows-64": "0.0.1-alpha.1",
23
+ "@bufbuild/protoc-gen-es-windows-arm64": "0.0.1-alpha.1",
24
+ "@bufbuild/protoc-gen-es-windows-32": "0.0.1-alpha.1",
25
+ "@bufbuild/protoc-gen-es-linux-64": "0.0.1-alpha.1",
26
+ "@bufbuild/protoc-gen-es-linux-32": "0.0.1-alpha.1",
27
+ "@bufbuild/protoc-gen-es-linux-arm": "0.0.1-alpha.1",
28
+ "@bufbuild/protoc-gen-es-linux-arm64": "0.0.1-alpha.1",
29
+ "@bufbuild/protoc-gen-es-freebsd-64": "0.0.1-alpha.1",
30
+ "@bufbuild/protoc-gen-es-freebsd-arm64": "0.0.1-alpha.1",
31
+ "@bufbuild/protoc-gen-es-netbsd-64": "0.0.1-alpha.1",
32
+ "@bufbuild/protoc-gen-es-openbsd-64": "0.0.1-alpha.1"
33
+ }
34
+ }
@@ -0,0 +1,50 @@
1
+ const { join, basename } = require("path");
2
+ const { existsSync, readFileSync, copyFileSync } = require("fs");
3
+
4
+ // TODO(tstamm) make this optional, and rely on shim for yarn berry
5
+ try {
6
+ const pkg = readBasePackage(__dirname);
7
+ const pkgBinPath =
8
+ Object.values(pkg.bin)[0] + (process.platform === "win32" ? ".exe" : "");
9
+ copyFileSync(
10
+ `${__dirname}-${process.platform}-${process.arch}/${pkgBinPath}`,
11
+ `${__dirname}/${pkgBinPath}`
12
+ );
13
+ } catch (e) {
14
+ basename(__dirname);
15
+ process.stderr.write(`Failed to install the binary for ${basename(__dirname)}.
16
+ Platform: ${process.platform}
17
+ Architecture: ${process.arch}
18
+ Error: ${e}
19
+ `);
20
+ process.exit(1);
21
+ }
22
+
23
+ function readBasePackage(npmBase) {
24
+ const pkgPath = join(npmBase, "package.json");
25
+ if (!existsSync(pkgPath)) {
26
+ throw new Error(`invalid npm-base: ${pkgPath} not found`);
27
+ }
28
+ const pkg = JSON.parse(readFileSync(pkgPath, "utf-8"));
29
+ if (!pkg.name) {
30
+ throw new Error(`${pkgPath} is missing "name"`);
31
+ }
32
+ if (!pkg.bin) {
33
+ throw new Error(`${pkgPath} is missing "bin"`);
34
+ }
35
+ if (Object.keys(pkg.bin).length !== 1) {
36
+ throw new Error(`${pkgPath} is requires exactly one entry in "bin"`);
37
+ }
38
+ const binName = Object.keys(pkg.bin)[0];
39
+ const binValue = Object.values(pkg.bin)[0];
40
+ if (
41
+ binName === undefined ||
42
+ binValue === undefined ||
43
+ binValue !== `bin/${binName}`
44
+ ) {
45
+ throw new Error(
46
+ `${pkgPath} is missing an entry in "bin" in the form of {"foo": "bin/foo"}`
47
+ );
48
+ }
49
+ return pkg;
50
+ }