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

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/protoc-gen-es CHANGED
@@ -1,11 +1,95 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- const { basename } = require("path");
3
+ const {basename, join, dirname} = require("path");
4
+ const {existsSync, readFileSync} = require("fs");
5
+ const {execFileSync} = require("child_process");
4
6
 
5
- // TODO(tstamm) shim for failed installation/yarn berry/windows/missing optional dependency
7
+ const baseDir = dirname(__dirname);
8
+ let basePkg;
9
+ try {
10
+ basePkg = readPackage(baseDir);
11
+ } catch (e) {
12
+ exitReadBasePackage(e);
13
+ }
14
+ const wantName = findPlatformPackageName(basePkg);
15
+ if (!basePkg.optionalDependencies[wantName]) {
16
+ exitUnsupportedPlatform(basePkg);
17
+ }
18
+ const binPath = Object.values(basePkg.bin)[0];
19
+ let absBinPath;
20
+ try {
21
+ absBinPath = require.resolve(join(wantName, binPath));
22
+ } catch (e) {
23
+ exitMissingPlatformBinary(basePkg);
24
+ }
25
+ execFileSync(absBinPath, process.argv.slice(2), {stdio: 'inherit', cwd: process.cwd(), env: process.env});
6
26
 
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);
27
+ function exitReadBasePackage(error) {
28
+ const message = error instanceof Error ? error.message : String(error);
29
+ process.stderr.write(`${basename(__filename)}: ${message}\n`);
30
+ process.exit(1);
31
+ }
32
+
33
+ function exitUnsupportedPlatform(basePkg) {
34
+ process.stderr.write(`${basePkg.name}: unsupported platform/architecture: ${process.platform}/${process.arch}\n`);
35
+ process.exit(1);
36
+ }
37
+
38
+ function exitMissingPlatformBinary(basePkg) {
39
+ process.stderr.write(`${basePkg.name}: binary for ${process.platform}/${process.arch} is missing\n`);
40
+ process.exit(1);
41
+ }
42
+
43
+ function readPackage(dir) {
44
+ const pkgPath = join(dir, "package.json");
45
+ if (!existsSync(pkgPath)) {
46
+ throw new Error(`invalid npm-base: ${pkgPath} not found`);
47
+ }
48
+ const pkg = JSON.parse(readFileSync(pkgPath, "utf-8"));
49
+ if (!pkg.name) {
50
+ throw new Error(`${pkgPath} is missing "name"`);
51
+ }
52
+ if (!pkg.bin) {
53
+ throw new Error(`${pkgPath} is missing "bin"`);
54
+ }
55
+ if (Object.keys(pkg.bin).length !== 1) {
56
+ throw new Error(`${pkgPath} is requires exactly one entry in "bin"`);
57
+ }
58
+ const binName = Object.keys(pkg.bin)[0];
59
+ const binValue = Object.values(pkg.bin)[0];
60
+ if (
61
+ binName === undefined ||
62
+ binValue === undefined ||
63
+ binValue !== `bin/${binName}`
64
+ ) {
65
+ throw new Error(
66
+ `${pkgPath} is missing an entry in "bin" in the form of {"foo": "bin/foo"}`
67
+ );
68
+ }
69
+ return pkg;
70
+ }
71
+
72
+ function findPlatformPackageName() {
73
+ // prettier-ignore
74
+ const platforms = [
75
+ { name: "darwin-64", npmOs: "darwin", npmCpu: "x64", },
76
+ { name: "darwin-64", npmOs: "darwin", npmCpu: "x64", },
77
+ { name: "darwin-arm64", npmOs: "darwin", npmCpu: "arm64", },
78
+ { name: "windows-64", npmOs: "win32", npmCpu: "x64", },
79
+ { name: "windows-arm64", npmOs: "win32", npmCpu: "arm64", },
80
+ { name: "windows-32", npmOs: "win32", npmCpu: "ia32", },
81
+ { name: "linux-64", npmOs: "linux", npmCpu: "x64", },
82
+ { name: "linux-32", npmOs: "linux", npmCpu: "ia32", },
83
+ { name: "linux-arm", npmOs: "linux", npmCpu: "arm", },
84
+ { name: "linux-arm64", npmOs: "linux", npmCpu: "arm64", },
85
+ { name: "freebsd-64", npmOs: "freebsd", npmCpu: "x64", },
86
+ { name: "freebsd-arm64", npmOs: "freebsd", npmCpu: "arm64", },
87
+ { name: "netbsd-64", npmOs: "netbsd", npmCpu: "x64", },
88
+ { name: "openbsd-64", npmOs: "openbsd", npmCpu: "x64", },
89
+ ];
90
+ const platform = platforms.find(p => p.npmOs === process.platform && p.npmCpu === process.arch);
91
+ if (!platform) {
92
+ return undefined;
93
+ }
94
+ return `${basePkg.name}-${platform.name}`;
95
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bufbuild/protoc-gen-es",
3
- "version": "0.0.1-alpha.1",
3
+ "version": "0.0.1-alpha.4",
4
4
  "description": "protoc-gen-es",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -10,25 +10,19 @@
10
10
  "bin": {
11
11
  "protoc-gen-es": "bin/protoc-gen-es"
12
12
  },
13
- "scripts": {
14
- "postinstall": "node postinstall.cjs"
15
- },
16
- "engines": {
17
- "node": ">=8.5"
18
- },
19
13
  "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"
14
+ "@bufbuild/protoc-gen-es-darwin-64": "0.0.1-alpha.4",
15
+ "@bufbuild/protoc-gen-es-darwin-arm64": "0.0.1-alpha.4",
16
+ "@bufbuild/protoc-gen-es-windows-64": "0.0.1-alpha.4",
17
+ "@bufbuild/protoc-gen-es-windows-arm64": "0.0.1-alpha.4",
18
+ "@bufbuild/protoc-gen-es-windows-32": "0.0.1-alpha.4",
19
+ "@bufbuild/protoc-gen-es-linux-64": "0.0.1-alpha.4",
20
+ "@bufbuild/protoc-gen-es-linux-32": "0.0.1-alpha.4",
21
+ "@bufbuild/protoc-gen-es-linux-arm": "0.0.1-alpha.4",
22
+ "@bufbuild/protoc-gen-es-linux-arm64": "0.0.1-alpha.4",
23
+ "@bufbuild/protoc-gen-es-freebsd-64": "0.0.1-alpha.4",
24
+ "@bufbuild/protoc-gen-es-freebsd-arm64": "0.0.1-alpha.4",
25
+ "@bufbuild/protoc-gen-es-netbsd-64": "0.0.1-alpha.4",
26
+ "@bufbuild/protoc-gen-es-openbsd-64": "0.0.1-alpha.4"
33
27
  }
34
28
  }
package/postinstall.cjs DELETED
@@ -1,50 +0,0 @@
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
- }