protoc 1.1.2 → 21.0.0-rc1

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 CHANGED
@@ -1,34 +1,11 @@
1
- # Protocol Buffers for Node
2
- A wrapper in Node for the compiled protoc from https://github.com/protocolbuffers/protobuf.
3
-
4
- ## Version
5
- It's currently using Protocol Buffers `v3.20.3`.
6
-
7
- ## Platforms
8
- Google only provides binary files for Windows, Linux and OSX in x86_64 and x86_32.
9
-
10
- ## Examples
11
- There's currently no documentation. Hopefully this example will help.
12
-
13
- ```JavaScript
14
- var protoc = require("protoc");
15
-
16
- protoc.library(["path/to/file.proto", "path/to/file2.proto"], function(err, files) {
17
- if (err) {
18
- console.error(err);
19
- return;
20
- }
21
-
22
- // Handle the JavaScript Vinyl files.
23
- // These files can be used in Google Closure Compiler,
24
- // but they require the files in
25
- // https://github.com/google/protobuf/tree/master/js
26
-
27
- // ...
28
- });
29
- ```
30
-
31
- It's also possible to directly call the protoc binary file:
32
- ```
33
- npx protoc --help
34
- ```
1
+ protoc
2
+ ======
3
+
4
+ This package provides the Protobuf compiler `protoc` <!-- inject: release.tag_name -->v21.0-rc1<!-- end -->.
5
+
6
+ ```shell script
7
+ npm install --save-dev protoc
8
+ npx protoc --version
9
+ ```
10
+
11
+ This is an unofficial distribution of the protoc binary from https://github.com/protocolbuffers/protobuf/releases.
package/assets.json ADDED
@@ -0,0 +1,42 @@
1
+ [
2
+ {
3
+ "name": "protoc-21.0-rc-1-linux-aarch_64.zip",
4
+ "browser_download_url": "https://github.com/protocolbuffers/protobuf/releases/download/v21.0-rc1/protoc-21.0-rc-1-linux-aarch_64.zip",
5
+ "platform": "linux",
6
+ "arch": "arm64",
7
+ "dotExe": false,
8
+ "executable": "protoc-linux-aarch_64"
9
+ },
10
+ {
11
+ "name": "protoc-21.0-rc-1-linux-x86_64.zip",
12
+ "browser_download_url": "https://github.com/protocolbuffers/protobuf/releases/download/v21.0-rc1/protoc-21.0-rc-1-linux-x86_64.zip",
13
+ "platform": "linux",
14
+ "arch": "x64",
15
+ "dotExe": false,
16
+ "executable": "protoc-linux-x86_64"
17
+ },
18
+ {
19
+ "name": "protoc-21.0-rc-1-osx-aarch_64.zip",
20
+ "browser_download_url": "https://github.com/protocolbuffers/protobuf/releases/download/v21.0-rc1/protoc-21.0-rc-1-osx-aarch_64.zip",
21
+ "platform": "darwin",
22
+ "arch": "arm64",
23
+ "dotExe": false,
24
+ "executable": "protoc-osx-aarch_64"
25
+ },
26
+ {
27
+ "name": "protoc-21.0-rc-1-osx-x86_64.zip",
28
+ "browser_download_url": "https://github.com/protocolbuffers/protobuf/releases/download/v21.0-rc1/protoc-21.0-rc-1-osx-x86_64.zip",
29
+ "platform": "darwin",
30
+ "arch": "x64",
31
+ "dotExe": false,
32
+ "executable": "protoc-osx-x86_64"
33
+ },
34
+ {
35
+ "name": "protoc-21.0-rc-1-win64.zip",
36
+ "browser_download_url": "https://github.com/protocolbuffers/protobuf/releases/download/v21.0-rc1/protoc-21.0-rc-1-win64.zip",
37
+ "platform": "win32",
38
+ "arch": "x64",
39
+ "dotExe": true,
40
+ "executable": "protoc-win64.exe"
41
+ }
42
+ ]
Binary file
Binary file
Binary file
Binary file
Binary file
package/package.json CHANGED
@@ -1,28 +1,42 @@
1
1
  {
2
2
  "name": "protoc",
3
- "version": "1.1.2",
4
- "description": "A tool for converting proto buffers (.proto) files into javascript files usable in Closure Compiler with Closure Library.",
5
- "main": "index.js",
3
+ "version": "21.0.0-rc1",
4
+ "upstreamVersion": "v21.0-rc1",
5
+ "description": "Installs the protocol buffer compiler \"protoc\" for you.",
6
+ "bin": {
7
+ "protoc": "protoc.cjs"
8
+ },
9
+ "engines": {
10
+ "node": ">=20.0.0"
11
+ },
6
12
  "scripts": {
7
- "postinstall": "node scripts/postinstall.js",
8
- "test": "node scripts/test.js"
13
+ "build": "npm run build:protoc && npm run build:tsc",
14
+ "build:protoc": "esbuild src/protoc.ts --bundle --platform=node --outfile=protoc.cjs",
15
+ "build:tsc": "tsc --noEmit",
16
+ "test": "tsx --test src/*.test.ts",
17
+ "lint": "biome lint",
18
+ "format": "biome format --write"
9
19
  },
10
- "bin": {
11
- "protoc": "./bin/protoc.js"
20
+ "type": "commonjs",
21
+ "publishConfig": {
22
+ "access": "public"
12
23
  },
13
- "author": "Jeppe Rune Mortensen <jepperm@gmail.com>",
14
- "license": "MIT",
24
+ "license": "Apache-2.0",
25
+ "author": "Timo Stamm <ts@timostamm.com>",
26
+ "homepage": "https://github.com/timostamm/protobuf-npm",
15
27
  "repository": {
16
28
  "type": "git",
17
- "url": "git+https://github.com/YePpHa/node-protoc.git"
29
+ "url": "https://github.com/timostamm/protobuf-npm",
30
+ "directory": "packages/protoc"
18
31
  },
19
- "dependencies": {
20
- "glob": "^7.2.3",
21
- "mkdirp": "^0.5.6",
22
- "node-fetch": "^3.2.10",
23
- "rimraf": "^3.0.2",
24
- "unzipper": "^0.10.11",
25
- "uuid": "^9.0.0",
26
- "vinyl": "^2.2.1"
32
+ "keywords": [
33
+ "Protocol Buffers",
34
+ "protobuf",
35
+ "protoc",
36
+ "installation"
37
+ ],
38
+ "devDependencies": {
39
+ "tsx": "^4.20.3",
40
+ "fflate": "^0.8.2"
27
41
  }
28
42
  }
package/protoc.cjs ADDED
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+
4
+ // src/protoc.ts
5
+ var import_node_path = require("node:path");
6
+ var import_node_child_process = require("node:child_process");
7
+ var import_node_fs = require("node:fs");
8
+ var rootDir = __dirname.endsWith("src") ? (0, import_node_path.dirname)(__dirname) : __dirname;
9
+ var assets = JSON.parse(
10
+ (0, import_node_fs.readFileSync)((0, import_node_path.join)(rootDir, "assets.json"), "utf-8")
11
+ );
12
+ var asset = assets.find(
13
+ (asset2) => asset2.arch === process.arch && asset2.platform === process.platform
14
+ );
15
+ if (!asset) {
16
+ throw new Error(
17
+ `No protoc executable available for your platform (${process.platform}) and architecture (${process.arch})`
18
+ );
19
+ }
20
+ var command = (0, import_node_path.join)(rootDir, "bin", asset.executable);
21
+ var p = (0, import_node_child_process.spawnSync)(command, process.argv.slice(2), {
22
+ stdio: "inherit"
23
+ });
24
+ if (p.error !== void 0) {
25
+ throw p.error;
26
+ }
27
+ process.exit(p.status ?? 0);
package/bin/protoc.js DELETED
@@ -1,19 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- const { protoc } = require("../");
4
-
5
- protoc(process.argv.slice(2), {}, (err, stdout, stderr) => {
6
- if (err) {
7
- console.error(err);
8
- process.exit(1);
9
- return;
10
- }
11
-
12
- if (stdout) {
13
- console.info(stdout);
14
- }
15
-
16
- if (stderr) {
17
- console.error(stderr);
18
- }
19
- })
package/index.js DELETED
@@ -1,130 +0,0 @@
1
- const path = require("path");
2
- const cp = require("child_process");
3
- const fs = require("fs");
4
- const protoc = require("./protoc.js");
5
- const Vinyl = require("vinyl");
6
- const uuid = require("uuid");
7
- const mkdirp = require("mkdirp");
8
- const glob = require("glob");
9
-
10
- exports.protoc = function(args, options, callback) {
11
- cp.execFile(protoc, args, options, callback);
12
- };
13
-
14
- exports.closure = function(files, options, callback) {
15
- if (!callback) {
16
- callback = options;
17
- options = null;
18
- }
19
-
20
- options.imports = options.imports || [];
21
- options.outputPath = options.outputPath || "./";
22
-
23
- const cwd = process.cwd();
24
- const absoluteOutputPath = path.resolve(cwd, options.outputPath);
25
- const relative = path.relative(absoluteOutputPath, cwd);
26
-
27
- const args = [
28
- "--js_out=one_output_file_per_input_file,binary:."
29
- ];
30
-
31
- for (var i = 0; i < options.imports.length; i++) {
32
- args.push("-I", path.join(relative, options.imports[i]));
33
- }
34
-
35
- for (var i = 0; i < files.length; i++) {
36
- args.push(path.join(relative, files[i]));
37
- }
38
-
39
- mkdirp(options.outputPath, function(err) {
40
- if (err) {
41
- callback(err);
42
- return;
43
- }
44
-
45
- exports.protoc(args, {
46
- "cwd": options.outputPath
47
- }, callback);
48
- });
49
- };
50
-
51
- /**
52
- * Converts .proto files to .js files that can be used in Google Closure
53
- * Compiler.
54
- * The generated .js files require the files in
55
- * https://github.com/protocolbuffers/protobuf/tree/v3.20.3/js.
56
- * @param {?Array<string>} files the proto files.
57
- * @param {?function(?Error, ?Array<Vinyl>)} callback the callback method.
58
- */
59
- exports.library = function(files, callback) {
60
- var dirpath = "tmp";
61
- var filename = uuid.v4();
62
- var jsFile = path.join(dirpath, filename);
63
- mkdirp("tmp", function(err) {
64
- if (err) {
65
- callback(err);
66
- return;
67
- }
68
-
69
- exports.protoc(["--js_out=library=" + jsFile + ",binary:."].concat(files), function(err, stdout, stderr) {
70
- if (err) {
71
- callback(err);
72
- return;
73
- }
74
-
75
- if (fs.existsSync(jsFile + ".js")) {
76
- fs.readFile(jsFile + ".js", function(err, contents) {
77
- if (err) {
78
- callback(err);
79
- return;
80
- }
81
-
82
- fs.unlink(jsFile + ".js", function(err) {
83
- if (err) {
84
- callback(err);
85
- return;
86
- }
87
-
88
- fs.rmdir(dirpath, function() {
89
- callback(null, [new Vinyl({
90
- "cwd": "/",
91
- "base": "/",
92
- "path": filename + ".js",
93
- "contents": contents
94
- })]);
95
- });
96
- });
97
- });
98
- } else {
99
- glob("**/*.js", {
100
- "cwd": jsFile
101
- }, function(err, matches) {
102
- if (err) {
103
- callback(err, null);
104
- return;
105
- }
106
-
107
- var files = matches.map(function(match) {
108
- return new Vinyl({
109
- "cwd": "/",
110
- "base": "/",
111
- "path": match,
112
- "contents": fs.readFileSync(path.join(jsFile, match))
113
- });
114
- });
115
-
116
- rimraf(jsFile, function(err) {
117
- if (err) {
118
- callback(err);
119
- return;
120
- }
121
-
122
- fs.rmdir(dirpath, function() {
123
- callback(null, files);
124
- });
125
- });
126
- });
127
- }
128
- });
129
- });
130
- };
package/protoc.js DELETED
@@ -1,5 +0,0 @@
1
- const path = require("path");
2
-
3
- const protoc_bin = path.join(__dirname, "protoc", "bin");
4
-
5
- module.exports = path.join(protoc_bin, "protoc" + (process.platform === "win32" ? ".exe" : ""));
@@ -1,58 +0,0 @@
1
- const fs = require("fs");
2
- const path = require("path");
3
- const unzip = require("unzipper");
4
- const mkdirp = require("mkdirp");
5
- const protoc = require("../protoc.js");
6
-
7
- const protoVersion = "3.20.3";
8
-
9
- const releases = {
10
- "win32_x86_32": `https://github.com/protocolbuffers/protobuf/releases/download/v${protoVersion}/protoc-${protoVersion}-win32.zip`,
11
- "win32_x86_64": `https://github.com/protocolbuffers/protobuf/releases/download/v${protoVersion}/protoc-${protoVersion}-win32.zip`,
12
- "linux_x86_32": `https://github.com/protocolbuffers/protobuf/releases/download/v${protoVersion}/protoc-${protoVersion}-linux-x86_32.zip`,
13
- "linux_x86_64": `https://github.com/protocolbuffers/protobuf/releases/download/v${protoVersion}/protoc-${protoVersion}-linux-x86_64.zip`,
14
- "darwin_x86_64": `https://github.com/protocolbuffers/protobuf/releases/download/v${protoVersion}/protoc-${protoVersion}-osx-x86_64.zip`
15
- };
16
-
17
- const platform = process.platform;
18
- const arch = process.arch === "x64" ? "x86_64" : "x86_32";
19
- const release = platform + "_" + arch;
20
- const protocDirectory = path.join(__dirname, "..", "protoc");
21
-
22
- (async () => {
23
- if (!releases[release]) {
24
- throw new Error(`Unsupported platform: ${release}. Was not able to find a proper protoc version.`);
25
- }
26
-
27
- fs.rmSync(protocDirectory, { recursive: true, force: true });
28
-
29
- const fetch = await import("node-fetch");
30
- const response = await fetch.default(releases[release]);
31
- response
32
- .body
33
- .pipe(unzip.Parse())
34
- .on("entry", entry => {
35
- const isFile = "File" === entry.type;
36
- const isDir = "Directory" === entry.type;
37
- const fullpath = path.join(protocDirectory, entry.path);
38
- const directory = isDir ? fullpath : path.dirname(fullpath);
39
-
40
- mkdirp(directory, err => {
41
- if (err) {
42
- throw err;
43
- }
44
- if (isFile) {
45
- entry.pipe(fs.createWriteStream(fullpath))
46
- .on("finish", function() {
47
- if (protoc === fullpath) {
48
- fs.chmod(fullpath, 0o755, function(err) {
49
- if (err) {
50
- throw err;
51
- }
52
- });
53
- }
54
- });
55
- }
56
- });
57
- });
58
- })();
package/scripts/test.js DELETED
@@ -1,7 +0,0 @@
1
- const protoc = require("../index.js");
2
- protoc.library(["protoc/include/google/protobuf/timestamp.proto"], function(err, files) {
3
- if (err) {
4
- console.error(err);
5
- return;
6
- }
7
- });