@depot/cli 0.0.1-cli.2.36.3
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/LICENSE +22 -0
- package/README.md +43 -0
- package/bin/depot +194 -0
- package/install.js +280 -0
- package/lib/main.d.ts +415 -0
- package/lib/main.js +2378 -0
- package/package.json +32 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Depot Technologies Inc <contact@depot.dev>
|
|
4
|
+
Copyright (c) 2020 Evan Wallace
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# `@depot/cli`
|
|
2
|
+
|
|
3
|
+
[](https://github.com/depot/cli/actions/workflows/ci.yml)
|
|
4
|
+
[](https://www.npmjs.com/package/@depot/cli)
|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
A Node.js package for downloading and interacting with the [Depot CLI](https://github.com/depot/cli).
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
Use [pnpm](https://pnpm.io) or your favorite package manager:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pnpm add @depot/cli
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
#### `depot(...)`
|
|
20
|
+
|
|
21
|
+
Call the Depot CLI with the given arguments - the `depot(...)` function accepts the same arguments as [execa](https://github.com/sindresorhus/execa), automatically injecting the Depot CLI binary as the first argument.
|
|
22
|
+
|
|
23
|
+
#### `depotBinaryPath()`
|
|
24
|
+
|
|
25
|
+
Returns the path to the Depot CLI binary.
|
|
26
|
+
|
|
27
|
+
### Example
|
|
28
|
+
|
|
29
|
+
```typescript
|
|
30
|
+
import {depot, depotBinaryPath} from '@depot/cli'
|
|
31
|
+
|
|
32
|
+
async function example() {
|
|
33
|
+
console.log(depotBinaryPath())
|
|
34
|
+
|
|
35
|
+
await depot('build', ['-t', 'org/repo:tag', '.'])
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## License
|
|
40
|
+
|
|
41
|
+
MIT License, see `LICENSE`.
|
|
42
|
+
|
|
43
|
+
Code from ESBuild, copyright (c) 2020 Evan Wallace
|
package/bin/depot
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
18
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
19
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
20
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
21
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
22
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
23
|
+
mod
|
|
24
|
+
));
|
|
25
|
+
|
|
26
|
+
// src/platform.ts
|
|
27
|
+
var fs = __toESM(require("fs"));
|
|
28
|
+
var os = __toESM(require("os"));
|
|
29
|
+
var path = __toESM(require("path"));
|
|
30
|
+
var DEPOT_BINARY_PATH = process.env.DEPOT_BINARY_PATH || DEPOT_BINARY_PATH;
|
|
31
|
+
var isValidBinaryPath = (x) => !!x;
|
|
32
|
+
var packageDarwin_arm64 = "@depot/cli-darwin-arm64";
|
|
33
|
+
var packageDarwin_x64 = "@depot/cli-darwin-x64";
|
|
34
|
+
var knownWindowsPackages = {
|
|
35
|
+
"win32 arm LE": "@depot/cli-win32-arm",
|
|
36
|
+
"win32 arm64 LE": "@depot/cli-win32-arm64",
|
|
37
|
+
"win32 ia32 LE": "@depot/cli-win32-ia32",
|
|
38
|
+
"win32 x64 LE": "@depot/cli-win32-x64"
|
|
39
|
+
};
|
|
40
|
+
var knownUnixlikePackages = {
|
|
41
|
+
"darwin arm64 LE": "@depot/cli-darwin-arm64",
|
|
42
|
+
"darwin x64 LE": "@depot/cli-darwin-x64",
|
|
43
|
+
"linux arm LE": "@depot/cli-linux-arm",
|
|
44
|
+
"linux arm64 LE": "@depot/cli-linux-arm64",
|
|
45
|
+
"linux ia32 LE": "@depot/cli-linux-ia32",
|
|
46
|
+
"linux x64 LE": "@depot/cli-linux-x64"
|
|
47
|
+
};
|
|
48
|
+
function pkgAndSubpathForCurrentPlatform() {
|
|
49
|
+
let pkg;
|
|
50
|
+
let subpath;
|
|
51
|
+
let platformKey = `${process.platform} ${os.arch()} ${os.endianness()}`;
|
|
52
|
+
if (platformKey in knownWindowsPackages) {
|
|
53
|
+
pkg = knownWindowsPackages[platformKey];
|
|
54
|
+
subpath = "bin/depot.exe";
|
|
55
|
+
} else if (platformKey in knownUnixlikePackages) {
|
|
56
|
+
pkg = knownUnixlikePackages[platformKey];
|
|
57
|
+
subpath = "bin/depot";
|
|
58
|
+
} else {
|
|
59
|
+
throw new Error(`Unsupported platform: ${platformKey}`);
|
|
60
|
+
}
|
|
61
|
+
return { pkg, subpath };
|
|
62
|
+
}
|
|
63
|
+
function pkgForSomeOtherPlatform() {
|
|
64
|
+
const libMainJS = require.resolve("@depot/cli");
|
|
65
|
+
const nodeModulesDirectory = path.dirname(path.dirname(path.dirname(libMainJS)));
|
|
66
|
+
if (path.basename(nodeModulesDirectory) === "node_modules") {
|
|
67
|
+
for (const unixKey in knownUnixlikePackages) {
|
|
68
|
+
try {
|
|
69
|
+
const pkg = knownUnixlikePackages[unixKey];
|
|
70
|
+
if (fs.existsSync(path.join(nodeModulesDirectory, pkg)))
|
|
71
|
+
return pkg;
|
|
72
|
+
} catch {
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
for (const windowsKey in knownWindowsPackages) {
|
|
76
|
+
try {
|
|
77
|
+
const pkg = knownWindowsPackages[windowsKey];
|
|
78
|
+
if (fs.existsSync(path.join(nodeModulesDirectory, pkg)))
|
|
79
|
+
return pkg;
|
|
80
|
+
} catch {
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
function downloadedBinPath(pkg, subpath) {
|
|
87
|
+
const libDir = path.dirname(require.resolve("@depot/cli"));
|
|
88
|
+
return path.join(libDir, `downloaded-${pkg.replace("/", "-")}-${path.basename(subpath)}`);
|
|
89
|
+
}
|
|
90
|
+
function generateBinPath() {
|
|
91
|
+
if (isValidBinaryPath(DEPOT_BINARY_PATH)) {
|
|
92
|
+
if (!fs.existsSync(DEPOT_BINARY_PATH)) {
|
|
93
|
+
console.warn(`[@depot/cli] Ignoring bad configuration: DEPOT_BINARY_PATH=${DEPOT_BINARY_PATH}`);
|
|
94
|
+
} else {
|
|
95
|
+
return { binPath: DEPOT_BINARY_PATH };
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
const { pkg, subpath } = pkgAndSubpathForCurrentPlatform();
|
|
99
|
+
let binPath2;
|
|
100
|
+
try {
|
|
101
|
+
binPath2 = require.resolve(`${pkg}/${subpath}`);
|
|
102
|
+
} catch (e) {
|
|
103
|
+
binPath2 = downloadedBinPath(pkg, subpath);
|
|
104
|
+
if (!fs.existsSync(binPath2)) {
|
|
105
|
+
try {
|
|
106
|
+
require.resolve(pkg);
|
|
107
|
+
} catch {
|
|
108
|
+
const otherPkg = pkgForSomeOtherPlatform();
|
|
109
|
+
if (otherPkg) {
|
|
110
|
+
let suggestions = `
|
|
111
|
+
Specifically the "${otherPkg}" package is present but this platform
|
|
112
|
+
needs the "${pkg}" package instead. People often get into this
|
|
113
|
+
situation by installing @depot/cli on Windows or macOS and copying "node_modules"
|
|
114
|
+
into a Docker image that runs Linux, or by copying "node_modules" between
|
|
115
|
+
Windows and WSL environments.
|
|
116
|
+
|
|
117
|
+
If you are installing with npm, you can try not copying the "node_modules"
|
|
118
|
+
directory when you copy the files over, and running "npm ci" or "npm install"
|
|
119
|
+
on the destination platform after the copy. Or you could consider using yarn
|
|
120
|
+
instead of npm which has built-in support for installing a package on multiple
|
|
121
|
+
platforms simultaneously.
|
|
122
|
+
|
|
123
|
+
If you are installing with yarn, you can try listing both this platform and the
|
|
124
|
+
other platform in your ".yarnrc.yml" file using the "supportedArchitectures"
|
|
125
|
+
feature: https://yarnpkg.com/configuration/yarnrc/#supportedArchitectures
|
|
126
|
+
Keep in mind that this means multiple copies of @depot/cli will be present.
|
|
127
|
+
`;
|
|
128
|
+
if (pkg === packageDarwin_x64 && otherPkg === packageDarwin_arm64 || pkg === packageDarwin_arm64 && otherPkg === packageDarwin_x64) {
|
|
129
|
+
suggestions = `
|
|
130
|
+
Specifically the "${otherPkg}" package is present but this platform
|
|
131
|
+
needs the "${pkg}" package instead. People often get into this
|
|
132
|
+
situation by installing @depot/cli with npm running inside of Rosetta 2 and then
|
|
133
|
+
trying to use it with node running outside of Rosetta 2, or vice versa (Rosetta
|
|
134
|
+
2 is Apple's on-the-fly x86_64-to-arm64 translation service).
|
|
135
|
+
|
|
136
|
+
If you are installing with npm, you can try ensuring that both npm and node are
|
|
137
|
+
not running under Rosetta 2 and then reinstalling @depot/cli. This likely involves
|
|
138
|
+
changing how you installed npm and/or node. For example, installing node with
|
|
139
|
+
the universal installer here should work: https://nodejs.org/en/download/. Or
|
|
140
|
+
you could consider using yarn instead of npm which has built-in support for
|
|
141
|
+
installing a package on multiple platforms simultaneously.
|
|
142
|
+
|
|
143
|
+
If you are installing with yarn, you can try listing both "arm64" and "x64"
|
|
144
|
+
in your ".yarnrc.yml" file using the "supportedArchitectures" feature:
|
|
145
|
+
https://yarnpkg.com/configuration/yarnrc/#supportedArchitectures
|
|
146
|
+
Keep in mind that this means multiple copies of @depot/cli will be present.
|
|
147
|
+
`;
|
|
148
|
+
}
|
|
149
|
+
throw new Error(`
|
|
150
|
+
You installed @depot/cli for another platform than the one you're currently using.
|
|
151
|
+
This won't work because @depot/cli is written with native code and needs to
|
|
152
|
+
install a platform-specific binary executable.
|
|
153
|
+
${suggestions}
|
|
154
|
+
`);
|
|
155
|
+
}
|
|
156
|
+
throw new Error(`The package "${pkg}" could not be found, and is needed by @depot/cli.
|
|
157
|
+
|
|
158
|
+
If you are installing @depot/cli with npm, make sure that you don't specify the
|
|
159
|
+
"--no-optional" or "--omit=optional" flags. The "optionalDependencies" feature
|
|
160
|
+
of "package.json" is used by @depot/cli to install the correct binary executable
|
|
161
|
+
for your current platform.`);
|
|
162
|
+
}
|
|
163
|
+
throw e;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
if (/\.zip\//.test(binPath2)) {
|
|
167
|
+
let pnpapi;
|
|
168
|
+
try {
|
|
169
|
+
pnpapi = require("pnpapi");
|
|
170
|
+
} catch (e) {
|
|
171
|
+
}
|
|
172
|
+
if (pnpapi) {
|
|
173
|
+
const root = pnpapi.getPackageInformation(pnpapi.topLevel).packageLocation;
|
|
174
|
+
const binTargetPath = path.join(
|
|
175
|
+
root,
|
|
176
|
+
"node_modules",
|
|
177
|
+
".cache",
|
|
178
|
+
"@depot/cli",
|
|
179
|
+
`pnpapi-${pkg.replace("/", "-")}-${"2.36.3"}-${path.basename(subpath)}`
|
|
180
|
+
);
|
|
181
|
+
if (!fs.existsSync(binTargetPath)) {
|
|
182
|
+
fs.mkdirSync(path.dirname(binTargetPath), { recursive: true });
|
|
183
|
+
fs.copyFileSync(binPath2, binTargetPath);
|
|
184
|
+
fs.chmodSync(binTargetPath, 493);
|
|
185
|
+
}
|
|
186
|
+
return { binPath: binTargetPath };
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
return { binPath: binPath2 };
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// src/shim.ts
|
|
193
|
+
var { binPath } = generateBinPath();
|
|
194
|
+
require("child_process").execFileSync(binPath, process.argv.slice(2), { stdio: "inherit" });
|
package/install.js
ADDED
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (let key of __getOwnPropNames(from))
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
12
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
+
}
|
|
14
|
+
return to;
|
|
15
|
+
};
|
|
16
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
17
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
18
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
19
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
20
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
24
|
+
|
|
25
|
+
// src/install.ts
|
|
26
|
+
var child_process = __toESM(require("child_process"));
|
|
27
|
+
var fs = __toESM(require("fs"));
|
|
28
|
+
var https = __toESM(require("https"));
|
|
29
|
+
var os2 = __toESM(require("os"));
|
|
30
|
+
var path2 = __toESM(require("path"));
|
|
31
|
+
var zlib = __toESM(require("zlib"));
|
|
32
|
+
|
|
33
|
+
// src/platform.ts
|
|
34
|
+
var os = __toESM(require("os"));
|
|
35
|
+
var path = __toESM(require("path"));
|
|
36
|
+
var DEPOT_BINARY_PATH = process.env.DEPOT_BINARY_PATH || DEPOT_BINARY_PATH;
|
|
37
|
+
var isValidBinaryPath = (x) => !!x;
|
|
38
|
+
var knownWindowsPackages = {
|
|
39
|
+
"win32 arm LE": "@depot/cli-win32-arm",
|
|
40
|
+
"win32 arm64 LE": "@depot/cli-win32-arm64",
|
|
41
|
+
"win32 ia32 LE": "@depot/cli-win32-ia32",
|
|
42
|
+
"win32 x64 LE": "@depot/cli-win32-x64"
|
|
43
|
+
};
|
|
44
|
+
var knownUnixlikePackages = {
|
|
45
|
+
"darwin arm64 LE": "@depot/cli-darwin-arm64",
|
|
46
|
+
"darwin x64 LE": "@depot/cli-darwin-x64",
|
|
47
|
+
"linux arm LE": "@depot/cli-linux-arm",
|
|
48
|
+
"linux arm64 LE": "@depot/cli-linux-arm64",
|
|
49
|
+
"linux ia32 LE": "@depot/cli-linux-ia32",
|
|
50
|
+
"linux x64 LE": "@depot/cli-linux-x64"
|
|
51
|
+
};
|
|
52
|
+
function pkgAndSubpathForCurrentPlatform() {
|
|
53
|
+
let pkg;
|
|
54
|
+
let subpath;
|
|
55
|
+
let platformKey = `${process.platform} ${os.arch()} ${os.endianness()}`;
|
|
56
|
+
if (platformKey in knownWindowsPackages) {
|
|
57
|
+
pkg = knownWindowsPackages[platformKey];
|
|
58
|
+
subpath = "bin/depot.exe";
|
|
59
|
+
} else if (platformKey in knownUnixlikePackages) {
|
|
60
|
+
pkg = knownUnixlikePackages[platformKey];
|
|
61
|
+
subpath = "bin/depot";
|
|
62
|
+
} else {
|
|
63
|
+
throw new Error(`Unsupported platform: ${platformKey}`);
|
|
64
|
+
}
|
|
65
|
+
return { pkg, subpath };
|
|
66
|
+
}
|
|
67
|
+
function downloadedBinPath(pkg, subpath) {
|
|
68
|
+
const libDir = path.dirname(require.resolve("@depot/cli"));
|
|
69
|
+
return path.join(libDir, `downloaded-${pkg.replace("/", "-")}-${path.basename(subpath)}`);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// src/install.ts
|
|
73
|
+
var versionFromPackageJSON = require(path2.join(__dirname, "package.json")).version.split("-cli.")[1];
|
|
74
|
+
var toPath = path2.join(__dirname, "bin", "depot");
|
|
75
|
+
var isToPathJS = true;
|
|
76
|
+
function validateBinaryVersion(...command) {
|
|
77
|
+
command.push("--version");
|
|
78
|
+
let stdout;
|
|
79
|
+
try {
|
|
80
|
+
stdout = child_process.execFileSync(command.shift(), command, {
|
|
81
|
+
// Without this, this install script strangely crashes with the error
|
|
82
|
+
// "EACCES: permission denied, write" but only on Ubuntu Linux when node is
|
|
83
|
+
// installed from the Snap Store. This is not a problem when you download
|
|
84
|
+
// the official version of node. The problem appears to be that stderr
|
|
85
|
+
// (i.e. file descriptor 2) isn't writable?
|
|
86
|
+
//
|
|
87
|
+
// More info:
|
|
88
|
+
// - https://snapcraft.io/ (what the Snap Store is)
|
|
89
|
+
// - https://nodejs.org/dist/ (download the official version of node)
|
|
90
|
+
// - https://github.com/evanw/esbuild/issues/1711#issuecomment-1027554035
|
|
91
|
+
//
|
|
92
|
+
stdio: "pipe"
|
|
93
|
+
}).toString().trim();
|
|
94
|
+
} catch (err) {
|
|
95
|
+
if (os2.platform() === "darwin" && /_SecTrustEvaluateWithError/.test(err + "")) {
|
|
96
|
+
let os3 = "this version of macOS";
|
|
97
|
+
try {
|
|
98
|
+
os3 = "macOS " + child_process.execFileSync("sw_vers", ["-productVersion"]).toString().trim();
|
|
99
|
+
} catch {
|
|
100
|
+
}
|
|
101
|
+
throw new Error(`The "@depot/cli" package cannot be installed because ${os3} is too outdated.
|
|
102
|
+
|
|
103
|
+
The Go compiler (which depot relies on) no longer supports ${os3},
|
|
104
|
+
which means the "depot" binary executable can't be run. You can either:
|
|
105
|
+
|
|
106
|
+
* Update your version of macOS to one that the Go compiler supports
|
|
107
|
+
* Build depot yourself using an older version of the Go compiler
|
|
108
|
+
`);
|
|
109
|
+
}
|
|
110
|
+
throw err;
|
|
111
|
+
}
|
|
112
|
+
const matches = stdout.match(/version ([^\s]+)\b/);
|
|
113
|
+
const versionFromStdout = matches == null ? void 0 : matches[1];
|
|
114
|
+
if (!versionFromStdout) {
|
|
115
|
+
throw new Error(
|
|
116
|
+
`Expected "depot --version" to print something like "version ${versionFromPackageJSON}" but got ${JSON.stringify(
|
|
117
|
+
stdout
|
|
118
|
+
)}`
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
if (stdout !== versionFromPackageJSON) {
|
|
122
|
+
throw new Error(`Expected ${JSON.stringify(versionFromPackageJSON)} but got ${JSON.stringify(stdout)}`);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
function isYarn() {
|
|
126
|
+
const { npm_config_user_agent } = process.env;
|
|
127
|
+
if (npm_config_user_agent) {
|
|
128
|
+
return /\byarn\//.test(npm_config_user_agent);
|
|
129
|
+
}
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
function fetch(url) {
|
|
133
|
+
return new Promise((resolve, reject) => {
|
|
134
|
+
https.get(url, (res) => {
|
|
135
|
+
if ((res.statusCode === 301 || res.statusCode === 302) && res.headers.location)
|
|
136
|
+
return fetch(res.headers.location).then(resolve, reject);
|
|
137
|
+
if (res.statusCode !== 200)
|
|
138
|
+
return reject(new Error(`Server responded with ${res.statusCode}`));
|
|
139
|
+
let chunks = [];
|
|
140
|
+
res.on("data", (chunk) => chunks.push(chunk));
|
|
141
|
+
res.on("end", () => resolve(Buffer.concat(chunks)));
|
|
142
|
+
}).on("error", reject);
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
function extractFileFromTarGzip(buffer, subpath) {
|
|
146
|
+
try {
|
|
147
|
+
buffer = zlib.unzipSync(buffer);
|
|
148
|
+
} catch (err) {
|
|
149
|
+
throw new Error(`Invalid gzip data in archive: ${err && err.message || err}`);
|
|
150
|
+
}
|
|
151
|
+
let str = (i, n) => String.fromCharCode(...buffer.subarray(i, i + n)).replace(/\0.*$/, "");
|
|
152
|
+
let offset = 0;
|
|
153
|
+
subpath = `package/${subpath}`;
|
|
154
|
+
while (offset < buffer.length) {
|
|
155
|
+
let name = str(offset, 100);
|
|
156
|
+
let size = parseInt(str(offset + 124, 12), 8);
|
|
157
|
+
offset += 512;
|
|
158
|
+
if (!isNaN(size)) {
|
|
159
|
+
if (name === subpath)
|
|
160
|
+
return buffer.subarray(offset, offset + size);
|
|
161
|
+
offset += size + 511 & ~511;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
throw new Error(`Could not find ${JSON.stringify(subpath)} in archive`);
|
|
165
|
+
}
|
|
166
|
+
function installUsingNPM(pkg, subpath, binPath) {
|
|
167
|
+
const env = { ...process.env, npm_config_global: void 0 };
|
|
168
|
+
const libDir = path2.dirname(require.resolve("@depot/cli"));
|
|
169
|
+
const installDir = path2.join(libDir, "npm-install");
|
|
170
|
+
fs.mkdirSync(installDir);
|
|
171
|
+
try {
|
|
172
|
+
fs.writeFileSync(path2.join(installDir, "package.json"), "{}");
|
|
173
|
+
child_process.execSync(
|
|
174
|
+
`npm install --loglevel=error --prefer-offline --no-audit --progress=false ${pkg}@${versionFromPackageJSON}`,
|
|
175
|
+
{ cwd: installDir, stdio: "pipe", env }
|
|
176
|
+
);
|
|
177
|
+
const installedBinPath = path2.join(installDir, "node_modules", pkg, subpath);
|
|
178
|
+
fs.renameSync(installedBinPath, binPath);
|
|
179
|
+
} finally {
|
|
180
|
+
try {
|
|
181
|
+
removeRecursive(installDir);
|
|
182
|
+
} catch {
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
function removeRecursive(dir) {
|
|
187
|
+
for (const entry of fs.readdirSync(dir)) {
|
|
188
|
+
const entryPath = path2.join(dir, entry);
|
|
189
|
+
let stats;
|
|
190
|
+
try {
|
|
191
|
+
stats = fs.lstatSync(entryPath);
|
|
192
|
+
} catch {
|
|
193
|
+
continue;
|
|
194
|
+
}
|
|
195
|
+
if (stats.isDirectory())
|
|
196
|
+
removeRecursive(entryPath);
|
|
197
|
+
else
|
|
198
|
+
fs.unlinkSync(entryPath);
|
|
199
|
+
}
|
|
200
|
+
fs.rmdirSync(dir);
|
|
201
|
+
}
|
|
202
|
+
function applyManualBinaryPathOverride(overridePath) {
|
|
203
|
+
const pathString = JSON.stringify(overridePath);
|
|
204
|
+
fs.writeFileSync(
|
|
205
|
+
toPath,
|
|
206
|
+
`#!/usr/bin/env node
|
|
207
|
+
require('child_process').execFileSync(${pathString}, process.argv.slice(2), { stdio: 'inherit' });
|
|
208
|
+
`
|
|
209
|
+
);
|
|
210
|
+
const libMain = path2.join(__dirname, "lib", "main.js");
|
|
211
|
+
const code = fs.readFileSync(libMain, "utf8");
|
|
212
|
+
fs.writeFileSync(libMain, `var DEPOT_BINARY_PATH = ${pathString};
|
|
213
|
+
${code}`);
|
|
214
|
+
}
|
|
215
|
+
function maybeOptimizePackage(binPath) {
|
|
216
|
+
if (os2.platform() !== "win32" && !isYarn()) {
|
|
217
|
+
const tempPath = path2.join(__dirname, "bin-depot");
|
|
218
|
+
try {
|
|
219
|
+
fs.linkSync(binPath, tempPath);
|
|
220
|
+
fs.renameSync(tempPath, toPath);
|
|
221
|
+
isToPathJS = false;
|
|
222
|
+
fs.unlinkSync(tempPath);
|
|
223
|
+
} catch {
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
async function downloadDirectlyFromNPM(pkg, subpath, binPath) {
|
|
228
|
+
const url = `https://registry.npmjs.org/${pkg}/-/${pkg.replace("@depot/cli-", "")}-${versionFromPackageJSON}.tgz`;
|
|
229
|
+
console.error(`[@depot/cli] Trying to download ${JSON.stringify(url)}`);
|
|
230
|
+
try {
|
|
231
|
+
fs.writeFileSync(binPath, extractFileFromTarGzip(await fetch(url), subpath));
|
|
232
|
+
fs.chmodSync(binPath, 493);
|
|
233
|
+
} catch (e) {
|
|
234
|
+
console.error(`[@depot/cli] Failed to download ${JSON.stringify(url)}: ${e && e.message || e}`);
|
|
235
|
+
throw e;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
async function checkAndPreparePackage() {
|
|
239
|
+
if (isValidBinaryPath(DEPOT_BINARY_PATH)) {
|
|
240
|
+
if (!fs.existsSync(DEPOT_BINARY_PATH)) {
|
|
241
|
+
console.warn(`[@depot/cli] Ignoring bad configuration: DEPOT_BINARY_PATH=${DEPOT_BINARY_PATH}`);
|
|
242
|
+
} else {
|
|
243
|
+
applyManualBinaryPathOverride(DEPOT_BINARY_PATH);
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
const { pkg, subpath } = pkgAndSubpathForCurrentPlatform();
|
|
248
|
+
let binPath;
|
|
249
|
+
try {
|
|
250
|
+
binPath = require.resolve(`${pkg}/${subpath}`);
|
|
251
|
+
} catch (e) {
|
|
252
|
+
console.error(`[@depot/cli] Failed to find package "${pkg}" on the file system
|
|
253
|
+
|
|
254
|
+
This can happen if you use the "--no-optional" flag. The "optionalDependencies"
|
|
255
|
+
package.json feature is used by @depot/cli to install the correct binary executable
|
|
256
|
+
for your current platform. This install script will now attempt to work around
|
|
257
|
+
this. If that fails, you need to remove the "--no-optional" flag to use @depot/cli.
|
|
258
|
+
`);
|
|
259
|
+
binPath = downloadedBinPath(pkg, subpath);
|
|
260
|
+
try {
|
|
261
|
+
console.error(`[@depot/cli] Trying to install package "${pkg}" using npm`);
|
|
262
|
+
installUsingNPM(pkg, subpath, binPath);
|
|
263
|
+
} catch (e2) {
|
|
264
|
+
console.error(`[@depot/cli] Failed to install package "${pkg}" using npm: ${e2 && e2.message || e2}`);
|
|
265
|
+
try {
|
|
266
|
+
await downloadDirectlyFromNPM(pkg, subpath, binPath);
|
|
267
|
+
} catch (e3) {
|
|
268
|
+
throw new Error(`Failed to install package "${pkg}"`);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
maybeOptimizePackage(binPath);
|
|
273
|
+
}
|
|
274
|
+
checkAndPreparePackage().then(() => {
|
|
275
|
+
if (isToPathJS) {
|
|
276
|
+
validateBinaryVersion(process.execPath, toPath);
|
|
277
|
+
} else {
|
|
278
|
+
validateBinaryVersion(toPath);
|
|
279
|
+
}
|
|
280
|
+
});
|