initial commit of actions
This commit is contained in:
commit
949ece5785
44660 changed files with 12034344 additions and 0 deletions
174
github/codeql-action-v2/node_modules/@protobuf-ts/protoc/LICENSE
generated
vendored
Normal file
174
github/codeql-action-v2/node_modules/@protobuf-ts/protoc/LICENSE
generated
vendored
Normal file
|
|
@ -0,0 +1,174 @@
|
|||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
64
github/codeql-action-v2/node_modules/@protobuf-ts/protoc/README.md
generated
vendored
Normal file
64
github/codeql-action-v2/node_modules/@protobuf-ts/protoc/README.md
generated
vendored
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
@protobuf-ts/protoc
|
||||
===================
|
||||
|
||||
|
||||
Installs the protocol buffer compiler "protoc" for you.
|
||||
|
||||
|
||||
Installation (not necessary if you use the [protobuf-ts plugin](https://github.com/timostamm/protobuf-ts/tree/master/packages/plugin)):
|
||||
|
||||
```shell script
|
||||
# with npm:
|
||||
npm install @protobuf-ts/protoc
|
||||
|
||||
# with yarn:
|
||||
yarn add @protobuf-ts/protoc
|
||||
```
|
||||
|
||||
Now you can run protoc as usual, you just have to prefix your command with
|
||||
`npx` or `yarn`:
|
||||
|
||||
```shell script
|
||||
# with npm:
|
||||
npx protoc --version
|
||||
|
||||
# with yarn:
|
||||
yarn protoc --version
|
||||
```
|
||||
|
||||
If you do not already have protoc in your `$PATH`, this will automatically
|
||||
download the latest release of protoc for your platform from the github
|
||||
release page, then run the executable with your arguments.
|
||||
|
||||
|
||||
#### Yarn berry
|
||||
|
||||
This package is not compatible with Yarn berry. Please use
|
||||
[node-protoc](https://www.npmjs.com/package/node-protoc).
|
||||
|
||||
|
||||
#### Installing a specific version
|
||||
|
||||
Add the following to your package json:
|
||||
|
||||
```
|
||||
"config": {
|
||||
"protocVersion": "3.11.0"
|
||||
}
|
||||
```
|
||||
|
||||
#### Prevent using protoc from `$PATH`
|
||||
|
||||
Add a `protocVersion` to your package json, see above.
|
||||
|
||||
|
||||
#### Added arguments
|
||||
|
||||
The script passes all given arguments to protoc and adds the
|
||||
following arguments:
|
||||
|
||||
1. `--proto_path` that points to the `include/` directory of the
|
||||
downloaded release (skipped when found on `$PATH`)
|
||||
2. `--plugin` argument for all plugins found in `node_modules/.bin/`
|
||||
3. `--proto_path` argument for `node_modules/@protobuf-ts/plugin`
|
||||
|
||||
2
github/codeql-action-v2/node_modules/@protobuf-ts/protoc/installed/.npmignore
generated
vendored
Normal file
2
github/codeql-action-v2/node_modules/@protobuf-ts/protoc/installed/.npmignore
generated
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
*
|
||||
!.gitignore
|
||||
26
github/codeql-action-v2/node_modules/@protobuf-ts/protoc/package.json
generated
vendored
Normal file
26
github/codeql-action-v2/node_modules/@protobuf-ts/protoc/package.json
generated
vendored
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
{
|
||||
"name": "@protobuf-ts/protoc",
|
||||
"version": "2.9.4",
|
||||
"description": "Installs the protocol buffer compiler \"protoc\" for you.",
|
||||
"license": "Apache-2.0",
|
||||
"author": "Timo Stamm <ts@timostamm.com>",
|
||||
"homepage": "https://github.com/timostamm/protobuf-ts",
|
||||
"keywords": [
|
||||
"Protocol Buffers",
|
||||
"protobuf",
|
||||
"protoc",
|
||||
"installation"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/timostamm/protobuf-ts.git",
|
||||
"directory": "packages/protoc"
|
||||
},
|
||||
"bin": {
|
||||
"protoc": "./protoc.js"
|
||||
},
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"gitHead": "1798e0d43c31eafb4b5877ef72f05abb87456823"
|
||||
}
|
||||
137
github/codeql-action-v2/node_modules/@protobuf-ts/protoc/protoc.js
generated
vendored
Executable file
137
github/codeql-action-v2/node_modules/@protobuf-ts/protoc/protoc.js
generated
vendored
Executable file
|
|
@ -0,0 +1,137 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
// Automatically installs protoc if not found on $PATH, then
|
||||
// runs it transiently.
|
||||
|
||||
const {spawnSync} = require('child_process');
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const os = require('os');
|
||||
const {findProtocVersionConfig, listInstalled, findProtocPlugins, findProtobufTs, unzip, makeReleaseName, httpGetRedirect, httpDownload, mkDirRecursive, findProtocInPath, standardInstallDirectory} = require('./util');
|
||||
|
||||
|
||||
main().catch(err => {
|
||||
console.error((err instanceof Error) ? err.message : err);
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
|
||||
async function main() {
|
||||
|
||||
// the full path to the protoc executable
|
||||
let command;
|
||||
// the full path to the include files of a protoc release (well-known-types)
|
||||
let includePath;
|
||||
|
||||
// does the nearest package.json have a config.protocVersion?
|
||||
const configuredVersion = findProtocVersionConfig(process.cwd());
|
||||
|
||||
if (configuredVersion) {
|
||||
// we prefer the configured protoc version and install it
|
||||
let release = await ensureInstalled(configuredVersion);
|
||||
command = release.protocPath;
|
||||
includePath = release.includePath;
|
||||
} else {
|
||||
// there is no configured protoc version. do we have protoc in the $PATH?
|
||||
command = findProtocInPath(process.env.PATH)
|
||||
if (!command) {
|
||||
// no protoc in $PATH, install the latest version
|
||||
let release = await ensureInstalled(configuredVersion);
|
||||
command = release.protocPath;
|
||||
includePath = release.includePath;
|
||||
}
|
||||
}
|
||||
|
||||
let args = [
|
||||
// pass all arguments to the process
|
||||
...process.argv.slice(2),
|
||||
];
|
||||
|
||||
if (includePath) {
|
||||
// add the "include" directory of the installed protoc to the proto path
|
||||
// do this last, otherwise it can shadow a user input
|
||||
args.push("--proto_path", includePath);
|
||||
}
|
||||
|
||||
// search for @protobuf-ts/plugin in node_modules and add --proto_path argument
|
||||
let protobufTs = findProtobufTs(process.cwd());
|
||||
if (protobufTs) {
|
||||
args.push("--proto_path", protobufTs);
|
||||
}
|
||||
|
||||
// search for any protoc-gen-xxx plugins in .bin and add --plugin arguments for them
|
||||
for (let plugin of findProtocPlugins(process.cwd())) {
|
||||
args.unshift("--plugin", plugin);
|
||||
}
|
||||
|
||||
let child = spawnSync(command, args, {
|
||||
// protoc accepts stdin for some commands, pipe all IO
|
||||
stdio: [process.stdin, process.stdout, process.stderr],
|
||||
shell: false
|
||||
});
|
||||
|
||||
if (child.error) {
|
||||
throw new Error("@protobuf-ts/protoc was unable to spawn protoc. " + child.error);
|
||||
}
|
||||
process.exit(child.status);
|
||||
}
|
||||
|
||||
|
||||
async function ensureInstalled(version) {
|
||||
// resolve the latest release version number if necessary
|
||||
if (version === "latest" || version === undefined) {
|
||||
let latestLocation;
|
||||
try {
|
||||
latestLocation = await httpGetRedirect("https://github.com/protocolbuffers/protobuf/releases/latest");
|
||||
} catch (e) {
|
||||
throw new Error(`@protobuf-ts/protoc failed to retrieve latest protoc version number: ${e}`);
|
||||
}
|
||||
version = latestLocation.split("/v").pop();
|
||||
}
|
||||
|
||||
// make the release name for the current platform and the requested version number
|
||||
let releaseName = makeReleaseName({
|
||||
platform: os.platform(),
|
||||
arch: os.arch(),
|
||||
version: version
|
||||
});
|
||||
|
||||
// if this release is already installed, we are done here
|
||||
let alreadyInstalled = listInstalled().find(i => i.name === releaseName);
|
||||
if (alreadyInstalled) {
|
||||
return alreadyInstalled;
|
||||
}
|
||||
|
||||
// download the release
|
||||
let archive;
|
||||
try {
|
||||
archive = await httpDownload(`https://github.com/protocolbuffers/protobuf/releases/download/v${version}/${releaseName}.zip`);
|
||||
} catch (e) {
|
||||
throw new Error(`@protobuf-ts/protoc failed to download protoc v${version}. \nDid you misspell the version number? The version number must look like "3.0.12", without a leading "v".\n${e}`);
|
||||
}
|
||||
|
||||
// unzip the archive
|
||||
let archivePath = path.join(standardInstallDirectory, releaseName);
|
||||
try {
|
||||
unzip(archive, (data, header) => {
|
||||
let filename = path.join(archivePath, header.filename);
|
||||
mkDirRecursive(path.dirname(filename));
|
||||
fs.writeFileSync(filename, data, {
|
||||
mode: header.filename.includes("bin/") ? 0o755 : 0o666
|
||||
});
|
||||
});
|
||||
} catch (e) {
|
||||
throw new Error(`@protobuf-ts/protoc failed unzip the downloaded protoc release v${version}: ${e}`);
|
||||
}
|
||||
|
||||
// sanity check
|
||||
let installed = listInstalled().find(i => i.name === releaseName);
|
||||
if (!installed) {
|
||||
throw new Error(`@protobuf-ts/protoc failed to install protoc v${version}.`);
|
||||
}
|
||||
|
||||
// finished
|
||||
console.info(`@protobuf-ts/protoc installed protoc v${installed.version}.`);
|
||||
return installed;
|
||||
}
|
||||
|
||||
426
github/codeql-action-v2/node_modules/@protobuf-ts/protoc/util.js
generated
vendored
Normal file
426
github/codeql-action-v2/node_modules/@protobuf-ts/protoc/util.js
generated
vendored
Normal file
|
|
@ -0,0 +1,426 @@
|
|||
const path = require("path");
|
||||
const fs = require("fs");
|
||||
const os = require("os");
|
||||
const assert = require("assert");
|
||||
|
||||
const standardInstallDirectory = path.join(__dirname, "installed");
|
||||
module.exports.standardInstallDirectory = standardInstallDirectory;
|
||||
|
||||
|
||||
/**
|
||||
* Make directory, creating missing parent directories as well.
|
||||
* Equivalent to fs.mkdirSync(p, {recursive: true});
|
||||
* @param {string} dirname
|
||||
*/
|
||||
module.exports.mkDirRecursive = function mkDirRecursive(dirname) {
|
||||
if (!path.isAbsolute(dirname)) {
|
||||
dirname = path.join(process.cwd(), dirname);
|
||||
}
|
||||
dirname = path.normalize(dirname);
|
||||
let parts = dirname.split(path.sep);
|
||||
for (let i = 2; i <= parts.length; i++) {
|
||||
let p = parts.slice(0, i).join(path.sep);
|
||||
if (fs.existsSync(p)) {
|
||||
let i = fs.lstatSync(p);
|
||||
if (!i.isDirectory()) {
|
||||
throw new Error("cannot mkdir '" + dirname + "'. '" + p + "' is not a directory.");
|
||||
}
|
||||
} else {
|
||||
fs.mkdirSync(p);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {Object} DistEntry
|
||||
* @property {string} name
|
||||
* @property {string} version
|
||||
* @property {string} protocPath
|
||||
* @property {string} includePath
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param {string} installDir
|
||||
* @return {DistEntry[]}
|
||||
*/
|
||||
module.exports.listInstalled = function listInstalled(installDir = standardInstallDirectory) {
|
||||
let entries = [];
|
||||
for (let name of fs.readdirSync(installDir)) {
|
||||
let abs = path.join(installDir, name);
|
||||
if (!fs.lstatSync(abs).isDirectory()) {
|
||||
continue;
|
||||
}
|
||||
// looking for directory names "protoc-3.13.0-win32"
|
||||
if (!name.startsWith("protoc-")) {
|
||||
continue;
|
||||
}
|
||||
let version = name.split("-")[1];
|
||||
let protocPath = path.join(abs, "bin/protoc.exe");
|
||||
if (!fs.existsSync(protocPath)) {
|
||||
protocPath = path.join(abs, "bin/protoc");
|
||||
}
|
||||
let includePath = path.join(abs, "include/")
|
||||
entries.push({name, version, protocPath, includePath});
|
||||
}
|
||||
return entries;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Download url into path. Returns path.
|
||||
* @param {string} url
|
||||
* @returns {Promise<Buffer>}
|
||||
*/
|
||||
module.exports.httpDownload = function download(url) {
|
||||
assert(typeof url === "string" && url.length > 0);
|
||||
assert(url.startsWith("https://") || url.startsWith("http://"));
|
||||
const chunks = [];
|
||||
return new Promise((resolve, reject) => {
|
||||
httpGet(url, []).then(
|
||||
response => {
|
||||
response.setEncoding("binary");
|
||||
response.on("data", chunk => {
|
||||
chunks.push(Buffer.from(chunk, "binary"))
|
||||
});
|
||||
response.on("end", () => {
|
||||
resolve(Buffer.concat(chunks));
|
||||
})
|
||||
},
|
||||
reason => reject(reason)
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string} url
|
||||
* @return {Promise<string>}
|
||||
*/
|
||||
module.exports.httpGetRedirect = function httpGetRedirect(url) {
|
||||
assert(typeof url === "string" && url.length > 0);
|
||||
assert(url.startsWith("https://") || url.startsWith("http://"));
|
||||
const client = url.startsWith("https") ? require("https") : require("http");
|
||||
return new Promise((resolve, reject) => {
|
||||
const request = client.get(url, (response) => {
|
||||
if (response.statusCode >= 300 && response.statusCode < 400) {
|
||||
let location = response.headers.location;
|
||||
assert(location && location.length > 0);
|
||||
resolve(location);
|
||||
} else if (response.statusCode !== 200) {
|
||||
reject(new Error(`HTTP ${response.statusCode} for ${url}`));
|
||||
} else {
|
||||
reject(new Error(`Did not get expected redirect for ${url}`));
|
||||
}
|
||||
});
|
||||
request.on("error", reject);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* HTTP GET, follows up to 3 redirects
|
||||
* @param {string} url
|
||||
* @param {string[]} redirects
|
||||
* @returns {Promise<IncomingMessage>}
|
||||
*/
|
||||
function httpGet(url, redirects) {
|
||||
assert(typeof url === "string" && url.length > 0);
|
||||
assert(url.startsWith("https://") || url.startsWith("http://"));
|
||||
assert(Array.isArray(redirects));
|
||||
assert(redirects.length <= 3);
|
||||
const client = url.startsWith("https") ? require("https") : require("http");
|
||||
return new Promise((resolve, reject) => {
|
||||
const request = client.get(url, (response) => {
|
||||
if (response.statusCode >= 300 && response.statusCode < 400) {
|
||||
let location = response.headers.location;
|
||||
assert(location && location.length > 0);
|
||||
let follow = httpGet(location, redirects.concat(location));
|
||||
resolve(follow);
|
||||
} else if (response.statusCode !== 200) {
|
||||
reject(new Error(`HTTP ${response.statusCode} for ${url}`));
|
||||
} else {
|
||||
resolve(response);
|
||||
}
|
||||
});
|
||||
request.on("error", reject);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {Object} ReleaseParameters
|
||||
* @property {NodeJS.Platform} platform
|
||||
* @property {CPUArchitecture} arch
|
||||
* @property {string} version - without leading "v"
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {("arm" | "arm64" | "ia32" | "mips" | "mipsel" | "ppc" | "ppc64" | "s390" | "s390x" | "x32" | "x64")} CPUArchitecture
|
||||
*/
|
||||
|
||||
/**
|
||||
* protoc-22.3-linux-aarch_64.zip
|
||||
* protoc-22.3-linux-ppcle_64.zip
|
||||
* protoc-22.3-linux-s390_64.zip
|
||||
* protoc-22.3-linux-x86_32.zip
|
||||
* protoc-22.3-linux-x86_64.zip
|
||||
* protoc-22.3-osx-aarch_64.zip
|
||||
* protoc-22.3-osx-universal_binary.zip
|
||||
* protoc-22.3-osx-x86_64.zip
|
||||
* protoc-22.3-win32.zip
|
||||
+ protoc-22.3-win64.zip
|
||||
*
|
||||
* @param {ReleaseParameters} params
|
||||
* @return {string}
|
||||
*/
|
||||
module.exports.makeReleaseName = function makeReleaseName(params) {
|
||||
let build = `${params.platform}-${params.arch}`;
|
||||
switch (params.platform) {
|
||||
case "darwin":
|
||||
if (params.arch === "arm64") {
|
||||
build = 'osx-aarch_64'
|
||||
} else if (params.arch === "x64") {
|
||||
build = 'osx-x86_64'
|
||||
} else {
|
||||
build = 'osx-universal_binary'
|
||||
}
|
||||
break;
|
||||
case "linux":
|
||||
if (params.arch === "x64") {
|
||||
build = 'linux-x86_64'
|
||||
} else if (params.arch === "x32") {
|
||||
build = 'linux-x86_32'
|
||||
} else if (params.arch === "arm64") {
|
||||
build = 'linux-aarch_64'
|
||||
}
|
||||
break;
|
||||
case "win32":
|
||||
if (params.arch === "x64") {
|
||||
build = 'win64'
|
||||
} else if (params.arch === "x32" || params.arch === "ia32") {
|
||||
build = 'win32'
|
||||
}
|
||||
break;
|
||||
}
|
||||
return `protoc-${params.version}-${build}`;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Reads the package json from the given path if it exists and
|
||||
* looks for config.protocVersion.
|
||||
*
|
||||
* If the package.json does not exist or does not specify a
|
||||
* config.protocVersion value, walk the file system up until
|
||||
* a package.json with a config.protocVersion is found.
|
||||
*
|
||||
* If nothing was found, return undefined.
|
||||
*
|
||||
* @param {string} cwd
|
||||
* @returns {string | undefined}
|
||||
*/
|
||||
module.exports.findProtocVersionConfig = function findProtocVersionConfig(cwd) {
|
||||
let version = undefined;
|
||||
let dirname = cwd;
|
||||
while (true) {
|
||||
version = tryReadProtocVersion(path.join(dirname, "package.json"));
|
||||
if (version !== undefined) {
|
||||
break;
|
||||
}
|
||||
let parent = path.dirname(dirname);
|
||||
if (parent === dirname) {
|
||||
break;
|
||||
}
|
||||
dirname = parent;
|
||||
}
|
||||
return version;
|
||||
};
|
||||
|
||||
function tryReadProtocVersion(pkgPath) {
|
||||
if (!fs.existsSync(pkgPath)) {
|
||||
return undefined;
|
||||
}
|
||||
let json = fs.readFileSync(pkgPath, "utf8");
|
||||
let pkg;
|
||||
try {
|
||||
pkg = JSON.parse(json);
|
||||
} catch (e) {
|
||||
return undefined;
|
||||
}
|
||||
if (typeof pkg === "object" && typeof pkg.config === "object" && pkg.config !== null) {
|
||||
if (pkg.config.hasOwnProperty("protocVersion") && typeof pkg.config.protocVersion == "string") {
|
||||
let version = pkg.config.protocVersion;
|
||||
if (typeof version === "string") {
|
||||
return version;
|
||||
}
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {string} cwd
|
||||
* @returns {string|undefined}
|
||||
*/
|
||||
module.exports.findProtobufTs = function (cwd) {
|
||||
let plugin = path.join(cwd, "node_modules", "@protobuf-ts", "plugin");
|
||||
return fs.existsSync(plugin) ? plugin : undefined;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {string} cwd
|
||||
* @returns {string[]}
|
||||
*/
|
||||
module.exports.findProtocPlugins = function (cwd) {
|
||||
let plugins = [];
|
||||
let binDir = path.join(cwd, "node_modules", ".bin");
|
||||
if (!fs.existsSync(binDir)) {
|
||||
return plugins;
|
||||
}
|
||||
if (!fs.lstatSync(binDir).isDirectory()) {
|
||||
return plugins;
|
||||
}
|
||||
for (let name of fs.readdirSync(binDir)) {
|
||||
if (!name.startsWith("protoc-gen-")) {
|
||||
continue;
|
||||
}
|
||||
let plugin = path.join("node_modules", ".bin", name);
|
||||
plugins.push(plugin);
|
||||
}
|
||||
return plugins;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {string|undefined} envPath from process.env.PATH
|
||||
* @returns {string|undefined}
|
||||
*/
|
||||
module.exports.findProtocInPath = function (envPath) {
|
||||
if (typeof envPath !== "string") {
|
||||
return undefined;
|
||||
}
|
||||
const candidates = envPath.split(path.delimiter)
|
||||
.filter(p => !p.endsWith(`node_modules${path.sep}.bin`)) // make sure to exlude ...
|
||||
.filter(p => !p.endsWith(`.npm-global${path.sep}bin`)) // ...
|
||||
.map(p => path.join(p, os.platform() === "win32" ? "protoc.exe" : "protoc")) // we are looking for "protoc"
|
||||
.map(p => p[0] === "~" ? path.join(os.homedir(), p.slice(1)) : p) // try expand "~"
|
||||
;
|
||||
for (let c of candidates) {
|
||||
if (fs.existsSync(c)) {
|
||||
return c;
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @callback fileCallback
|
||||
* @param {Buffer} data
|
||||
* @param {LocalHeader} header
|
||||
*/
|
||||
/**
|
||||
* @param {Buffer} buffer
|
||||
* @param {fileCallback} onFile
|
||||
*/
|
||||
module.exports.unzip = function unzip(buffer, onFile) {
|
||||
const
|
||||
zlib = require("zlib"),
|
||||
localHeaderSig = 0x04034b50, // Local file header signature
|
||||
centralHeaderSig = 0x02014b50, // Central directory file header signature
|
||||
eocdRecordSig = 0x06054b50, // End of central directory record (EOCD)
|
||||
optDataDescSig = 0x08074b50, // Optional data descriptor signature
|
||||
methodStored = 0,
|
||||
methodDeflated = 8;
|
||||
let pos = 0;
|
||||
let cenFound = false;
|
||||
while (pos < buffer.byteLength && !cenFound) {
|
||||
if (buffer.byteLength - pos < 2) {
|
||||
throw new Error("Signature too short at " + pos);
|
||||
}
|
||||
let sig = buffer.readUInt32LE(pos);
|
||||
switch (sig) {
|
||||
|
||||
case localHeaderSig:
|
||||
let header = readLocalHeader();
|
||||
let compressedData = buffer.subarray(pos, pos + header.compressedSize);
|
||||
let uncompressedData;
|
||||
switch (header.compressionMethod) {
|
||||
case methodDeflated:
|
||||
uncompressedData = zlib.inflateRawSync(compressedData);
|
||||
break;
|
||||
case methodStored:
|
||||
uncompressedData = compressedData;
|
||||
break;
|
||||
default:
|
||||
throw new Error("Unsupported compression method " + header.compressionMethod);
|
||||
}
|
||||
if (header.filename[header.filename.length - 1] !== "/") {
|
||||
onFile(uncompressedData, header);
|
||||
}
|
||||
pos += header.compressedSize;
|
||||
break;
|
||||
|
||||
case centralHeaderSig:
|
||||
cenFound = true;
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new Error("Unexpected signature " + sig);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {Object} LocalHeader
|
||||
* @property {number} version
|
||||
* @property {number} generalPurposeFlags
|
||||
* @property {number} compressionMethod
|
||||
* @property {number} lastModificationTime
|
||||
* @property {number} lastModificationDate
|
||||
* @property {number} crc32
|
||||
* @property {number} compressedSize
|
||||
* @property {number} uncompressedSize
|
||||
* @property {string} filename
|
||||
* @property {Buffer} extraField
|
||||
*
|
||||
* @returns {undefined|LocalHeader}
|
||||
*/
|
||||
function readLocalHeader() {
|
||||
let sig = buffer.readUInt32LE(pos);
|
||||
if (sig !== localHeaderSig) {
|
||||
throw new Error("Unexpected local header signature " + sig.toString(16) + " at " + pos);
|
||||
}
|
||||
if (buffer.byteLength - pos < 30) {
|
||||
throw new Error("Local header too short at " + pos);
|
||||
}
|
||||
let version = buffer.readUInt32LE(pos + 4);
|
||||
let generalPurposeFlags = buffer.readUInt16LE(pos + 6);
|
||||
let compressionMethod = buffer.readUInt16LE(pos + 8);
|
||||
let lastModificationTime = buffer.readUInt16LE(pos + 10);
|
||||
let lastModificationDate = buffer.readUInt16LE(pos + 12);
|
||||
let crc32 = buffer.readUInt32LE(pos + 14);
|
||||
let compressedSize = buffer.readUInt32LE(pos + 18);
|
||||
let uncompressedSize = buffer.readUInt32LE(pos + 22);
|
||||
let filenameLength = buffer.readUInt16LE(pos + 26);
|
||||
let extraFieldLength = buffer.readUInt16LE(pos + 28);
|
||||
let filename = buffer.subarray(pos + 30, pos + 30 + filenameLength).toString();
|
||||
let extraField = buffer.subarray(pos + 30 + filenameLength, pos + 30 + filenameLength + extraFieldLength);
|
||||
pos += 30 + filenameLength + extraFieldLength;
|
||||
return {
|
||||
version,
|
||||
generalPurposeFlags,
|
||||
compressionMethod,
|
||||
lastModificationTime,
|
||||
lastModificationDate,
|
||||
crc32,
|
||||
compressedSize,
|
||||
uncompressedSize,
|
||||
filename,
|
||||
extraField
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue