@automattic/vip 3.25.3-dev.0 → 4.0.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@automattic/vip",
3
- "version": "3.25.3-dev.0",
3
+ "version": "4.0.1",
4
4
  "description": "The VIP Javascript library & CLI",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -72,12 +72,13 @@
72
72
  "test": "npm run lint && npm run check-types && jest --coverage --testPathIgnorePatterns __tests__/devenv-e2e/",
73
73
  "test:e2e:dev-env": "jest -c __tests__/devenv-e2e/jest/jest.config.js",
74
74
  "clean": "node -e \"require('fs').rmSync('dist', { recursive: true, force: true })\"",
75
- "cmd:format": "prettier '**/*.(js|json|jsx|md|ts|tsx|yml|yaml)'",
75
+ "cmd:format": "prettier \"**/*.{js,json,jsx,md,ts,tsx,yml,yaml}\"",
76
76
  "cmd:lint": "eslint --ext 'js,jsx,ts,tsx'",
77
77
  "prepare": "npm run clean && npm run build",
78
78
  "check-types": "tsc",
79
79
  "postinstall": "node ./helpers/check-version.js",
80
80
  "build": "babel src -d dist --extensions=\".js,.ts\"",
81
+ "build:sea": "node ./helpers/build-sea.js",
81
82
  "build:watch": "babel src -d dist --watch --source-maps --extensions=\".js,.ts\"",
82
83
  "format": "npm run cmd:format -- --write",
83
84
  "format:check": "npm run cmd:format -- --check",
@@ -134,6 +135,7 @@
134
135
  "dockerode": "^5.0.0",
135
136
  "jest": "^30.0.0",
136
137
  "nock": "13.5.6",
138
+ "postject": "^1.0.0-alpha.6",
137
139
  "prettier": "npm:wp-prettier@3.0.3",
138
140
  "typescript": "^6.0.2"
139
141
  },
@@ -142,15 +144,16 @@
142
144
  "@automattic/vip-search-replace": "^2.0.0",
143
145
  "@json2csv/plainjs": "^7.0.3",
144
146
  "@wwa/single-line-log": "^1.1.4",
145
- "args": "5.0.3",
146
147
  "chalk": "^5.6.2",
147
148
  "check-disk-space": "3.4.0",
148
149
  "cli-columns": "^4.0.0",
149
150
  "cli-table3": "^0.6.3",
151
+ "commander": "^14.0.3",
150
152
  "configstore": "^8.0.0",
151
153
  "debug": "4.4.3",
152
154
  "ejs": "^5.0.1",
153
155
  "enquirer": "2.4.1",
156
+ "esbuild": "^0.28.0",
154
157
  "fetch-retry": "^6.0.0",
155
158
  "graphql": "16.13.2",
156
159
  "graphql-tag": "2.12.6",
@@ -1,184 +0,0 @@
1
- "use strict";
2
-
3
- exports.__esModule = true;
4
- exports.InvalidChecksumError = exports.DownloadError = void 0;
5
- exports.download = download;
6
- exports.getExeName = getExeName;
7
- exports.getInstallDir = getInstallDir;
8
- exports.getReleaseUrl = getReleaseUrl;
9
- exports.installBinary = installBinary;
10
- exports.updateDomains = updateDomains;
11
- var _nodeFetch = _interopRequireDefault(require("node-fetch"));
12
- var _nodeChild_process = require("node:child_process");
13
- var _nodeCrypto = require("node:crypto");
14
- var _nodeFs = require("node:fs");
15
- var _promises = require("node:fs/promises");
16
- var _nodeOs = require("node:os");
17
- var _nodePath = require("node:path");
18
- var _nodeStream = require("node:stream");
19
- var _promises2 = require("node:stream/promises");
20
- var _nodeUtil = require("node:util");
21
- var _nodeZlib = require("node:zlib");
22
- var _proxyAgent = require("../http/proxy-agent");
23
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
24
- class DownloadError extends Error {
25
- constructor(url, code, options) {
26
- super((0, _nodeUtil.format)('Failed to download file: %s (status code: %d)', url, code), options);
27
- this.name = 'DownloadError';
28
- }
29
- }
30
- exports.DownloadError = DownloadError;
31
- class InvalidChecksumError extends Error {
32
- constructor(message, options) {
33
- super(message, options);
34
- this.name = 'InvalidChecksumError';
35
- }
36
- }
37
- exports.InvalidChecksumError = InvalidChecksumError;
38
- const archMap = {
39
- ia32: '386',
40
- x64: 'amd64',
41
- arm64: 'arm64'
42
- };
43
- const platformMap = {
44
- win32: 'windows',
45
- darwin: 'darwin',
46
- linux: 'linux'
47
- };
48
- function getReleaseUrl(version = 'latest', arch = process.arch, platform = process.platform) {
49
- const resolvedArch = archMap[arch];
50
- const resolvedPlatform = platformMap[platform];
51
- if (!resolvedArch || !resolvedPlatform) {
52
- throw new Error('Unsupported platform or architecture');
53
- }
54
- const suffix = 'windows' === resolvedPlatform ? '.exe' : '';
55
- if (version !== 'latest') {
56
- const binary = `https://github.com/Automattic/dev-env-update-hosts/releases/download/${version}/dev-env-update-hosts-${resolvedPlatform}-${resolvedArch}${suffix}.gz`;
57
- const checksum = `${binary}.sum`;
58
- return [binary, checksum];
59
- }
60
- const binary = `https://github.com/Automattic/dev-env-update-hosts/releases/latest/download/dev-env-update-hosts-${resolvedPlatform}-${resolvedArch}${suffix}.gz`;
61
- const checksum = `${binary}.sum`;
62
- return [binary, checksum];
63
- }
64
- async function download(url, asText, timeout = 0) {
65
- const controller = new AbortController();
66
- const timeoutId = timeout > 0 ? setTimeout(() => controller.abort(), timeout) : null;
67
- const clearTimer = () => {
68
- if (timeoutId) {
69
- clearTimeout(timeoutId);
70
- }
71
- };
72
- const proxyAgent = (0, _proxyAgent.createProxyAgent)(url.toString());
73
- let response;
74
- try {
75
- response = await (0, _nodeFetch.default)(url, {
76
- signal: controller.signal,
77
- redirect: 'follow',
78
- agent: proxyAgent ?? undefined
79
- });
80
- } catch (err) {
81
- clearTimer();
82
- throw err;
83
- }
84
- if (!response.ok) {
85
- clearTimer();
86
- throw new DownloadError(url, response.status);
87
- }
88
- if (asText) {
89
- try {
90
- return await response.text();
91
- } finally {
92
- clearTimer();
93
- }
94
- }
95
-
96
- // For streams: unref the timer so it will not prevent process exit once the
97
- // body has been fully consumed, but it will still abort a stalled read while
98
- // the event loop is kept alive by the active stream pipeline.
99
- timeoutId?.unref();
100
- return response.body;
101
- }
102
- function getExeName(platform = process.platform, arch = process.arch) {
103
- const exeSuffix = platform === 'win32' ? '.exe' : '';
104
- return `dev-env-update-host-${platform}-${arch}${exeSuffix}`;
105
- }
106
- async function installBinary(version, dest, timeout = 0, arch = process.arch, platform = process.platform) {
107
- const [binaryUrl, checksumUrl] = getReleaseUrl(version, arch, platform);
108
- const checksum = (await download(new URL(checksumUrl), true, timeout)).trim();
109
- const compressedStream = await download(new URL(binaryUrl), false, timeout);
110
- if (!compressedStream) {
111
- throw new Error('Failed to download binary');
112
- }
113
- const hash = (0, _nodeCrypto.createHash)('sha256');
114
- const hashTap = new _nodeStream.Transform({
115
- transform(chunk, _encoding, callback) {
116
- hash.update(chunk);
117
- callback(null, chunk);
118
- }
119
- });
120
- const destFilename = (0, _nodePath.join)(dest, getExeName(platform, arch));
121
- // Use a unique temp name to avoid collisions when multiple processes install concurrently.
122
- const tempFilename = `${destFilename}.${(0, _nodeCrypto.randomBytes)(8).toString('hex')}.tmp`;
123
- const outStream = (0, _nodeFs.createWriteStream)(tempFilename, {
124
- mode: 0o755
125
- });
126
- let removeTmp = true;
127
- try {
128
- await (0, _promises2.pipeline)(compressedStream, hashTap, (0, _nodeZlib.createGunzip)(), outStream);
129
- const calculatedChecksum = hash.digest('hex');
130
- if (!(0, _nodeCrypto.timingSafeEqual)(Buffer.from(calculatedChecksum, 'hex'), Buffer.from(checksum, 'hex'))) {
131
- throw new InvalidChecksumError((0, _nodeUtil.format)('Downloaded file checksum does not match expected value (expected: %s, got: %s)', checksum, calculatedChecksum));
132
- }
133
- await (0, _promises.rename)(tempFilename, destFilename);
134
- removeTmp = false;
135
- } finally {
136
- if (removeTmp) {
137
- await (0, _promises.rm)(tempFilename, {
138
- force: true
139
- }).catch(err => {
140
- console.warn('Error removing temporary file %s: %s', tempFilename, err);
141
- });
142
- }
143
- }
144
- return destFilename;
145
- }
146
- async function getInstallDir() {
147
- const binDir = (0, _nodePath.join)((0, _nodePath.dirname)(__dirname), 'bin');
148
- try {
149
- await (0, _promises.mkdir)(binDir, {
150
- recursive: true
151
- });
152
- await (0, _promises.access)(binDir, _promises.constants.W_OK);
153
- return binDir;
154
- } catch {
155
- // Swallow errors and fall back to a temporary directory
156
- }
157
- const tmpDir = await (0, _promises.mkdtemp)((0, _nodePath.join)((0, _nodeOs.tmpdir)(), 'dev-env-update-hosts-'));
158
- process.once('exit', () => {
159
- try {
160
- (0, _nodeFs.rmSync)(tmpDir, {
161
- recursive: true,
162
- force: true
163
- });
164
- } catch (err) {
165
- console.warn('Error removing temporary dir: %s', err);
166
- }
167
- });
168
- return tmpDir;
169
- }
170
- function updateDomains(binary, domains) {
171
- return new Promise((resolve, reject) => {
172
- const child = (0, _nodeChild_process.spawn)(binary, domains, {
173
- stdio: 'inherit'
174
- });
175
- child.on('error', err => reject(err));
176
- child.on('exit', code => {
177
- if (code === 0) {
178
- resolve();
179
- } else {
180
- reject(new Error(`Binary exited with code ${code}`));
181
- }
182
- });
183
- });
184
- }