@snap/valdi 1.2.0 → 1.3.0

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.
Files changed (56) hide show
  1. package/.bootstrap/modules/ui_component/BUILD.bazel.template +1 -1
  2. package/.metadata/.bazelrc.template +5 -5
  3. package/.metadata/.bazelversion.template +1 -1
  4. package/.metadata/AGENTS.md.template +7 -0
  5. package/.metadata/MODULE.bazel.template +75 -6
  6. package/.metadata/README.md.template +2 -2
  7. package/.metadata/android_ide_common_30_1_3_install.json.template +1818 -0
  8. package/.metadata/android_mvn_install.json.template +2877 -0
  9. package/.metadata/maven_install.json.template +444 -0
  10. package/.metadata/rules_android_maven_install.json.template +4879 -0
  11. package/.metadata/skill-tests-README.md.template +1 -1
  12. package/README.md +12 -13
  13. package/bundled-skills/skills/valdi-async/tests/README.md +1 -1
  14. package/bundled-skills/skills/valdi-compiler/skill.md +3 -8
  15. package/bundled-skills/skills/valdi-component-tests/skill.md +1 -1
  16. package/bundled-skills/skills/valdi-component-tests/tests/README.md +1 -1
  17. package/bundled-skills/skills/valdi-custom-view/skill.md +1 -1
  18. package/bundled-skills/skills/valdi-gestures/skill.md +1 -1
  19. package/bundled-skills/skills/valdi-migrate/tests/README.md +2 -2
  20. package/bundled-skills/skills/valdi-mock-breakdown/skill.md +1 -1
  21. package/bundled-skills/skills/valdi-mock-to-module/scripts/find_icon.py +8 -8
  22. package/bundled-skills/skills/valdi-mock-to-module/scripts/test_find_icon.py +2 -2
  23. package/bundled-skills/skills/valdi-perf/skill.md +2 -2
  24. package/bundled-skills/skills/valdi-perf/tests/README.md +1 -1
  25. package/bundled-skills/skills/valdi-polyglot-module/skill.md +5 -1
  26. package/bundled-skills/skills/valdi-tsx/skill.md +6 -6
  27. package/bundled-skills/skills/valdi-tsx/tests/README.md +1 -1
  28. package/dist/commands/agentCheck.js +9 -7
  29. package/dist/commands/bootstrap.js +16 -5
  30. package/dist/commands/build.js +7 -1
  31. package/dist/commands/doctor.js +4 -7
  32. package/dist/commands/export.js +47 -16
  33. package/dist/commands/hotreload.js +247 -27
  34. package/dist/commands/install.js +92 -3
  35. package/dist/commands/newModule.js +8 -1
  36. package/dist/commands/webHotreload.js +3 -3
  37. package/dist/core/constants.js +17 -2
  38. package/dist/setup/DevSetupHelper.js +11 -2
  39. package/dist/setup/libtinfo5.js +19 -0
  40. package/dist/setup/linuxSetup.js +2 -22
  41. package/dist/utils/BazelClient.js +11 -4
  42. package/dist/utils/applicationUtils.js +17 -2
  43. package/dist/utils/buildInfo.js +5 -1
  44. package/dist/utils/cliUtils.js +2 -2
  45. package/dist/utils/directorySync.js +153 -0
  46. package/dist/utils/errorUtils.js +1 -1
  47. package/dist/utils/githubUtils.js +1 -1
  48. package/dist/utils/iosSimulator.js +136 -0
  49. package/dist/utils/nonInteractive.js +13 -0
  50. package/dist/utils/prettierCheck.js +19 -0
  51. package/dist/utils/processUtils.js +14 -0
  52. package/dist/utils/webApplicationSession.js +58 -0
  53. package/dist/utils/webHotReloadSession.js +212 -0
  54. package/dist/utils/webServerUtils.js +195 -0
  55. package/dist/utils/zipUtils.js +20 -2
  56. package/package.json +4 -2
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.startWebApplicationSession = startWebApplicationSession;
4
+ const tslib_1 = require("tslib");
5
+ const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
6
+ const node_path_1 = tslib_1.__importDefault(require("node:path"));
7
+ const webServerUtils_1 = require("./webServerUtils");
8
+ const zipUtils_1 = require("./zipUtils");
9
+ async function extractWebSite(archivePath, sitesDir, generation) {
10
+ const siteDir = node_path_1.default.join(sitesDir, String(generation));
11
+ node_fs_1.default.mkdirSync(siteDir);
12
+ try {
13
+ await (0, zipUtils_1.decompressTo)(archivePath, siteDir);
14
+ return siteDir;
15
+ }
16
+ catch (error) {
17
+ node_fs_1.default.rmSync(siteDir, { force: true, recursive: true });
18
+ throw error;
19
+ }
20
+ }
21
+ async function startWebApplicationSession(options) {
22
+ const sitesDir = node_path_1.default.join(options.workingDir, 'sites');
23
+ node_fs_1.default.mkdirSync(sitesDir);
24
+ let generation = 1;
25
+ let activeSiteDir = await extractWebSite(options.archivePath, sitesDir, generation);
26
+ const staleSiteDirs = [];
27
+ const server = await (0, webServerUtils_1.startStaticWebServer)(activeSiteDir, {
28
+ host: options.host,
29
+ liveReload: options.liveReload ?? false,
30
+ port: options.port,
31
+ });
32
+ let publicationQueue = Promise.resolve();
33
+ const publish = async () => {
34
+ const nextSiteDir = await extractWebSite(options.archivePath, sitesDir, ++generation);
35
+ const previousSiteDir = activeSiteDir;
36
+ activeSiteDir = nextSiteDir;
37
+ server.setRootDir(nextSiteDir);
38
+ server.reload();
39
+ staleSiteDirs.push(previousSiteDir);
40
+ while (staleSiteDirs.length > 1) {
41
+ const staleSiteDir = staleSiteDirs.shift();
42
+ if (staleSiteDir) {
43
+ node_fs_1.default.rmSync(staleSiteDir, { force: true, recursive: true });
44
+ }
45
+ }
46
+ };
47
+ return {
48
+ url: server.url,
49
+ close: async () => {
50
+ await publicationQueue.catch(() => { });
51
+ await server.close();
52
+ },
53
+ publish: () => {
54
+ publicationQueue = publicationQueue.then(publish, publish);
55
+ return publicationQueue;
56
+ },
57
+ };
58
+ }
@@ -0,0 +1,212 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.inferWebHotReloadTarget = inferWebHotReloadTarget;
4
+ exports.registerWebHotReloadSession = registerWebHotReloadSession;
5
+ exports.findWebHotReloadSessions = findWebHotReloadSessions;
6
+ exports.publishWebHotReloadSession = publishWebHotReloadSession;
7
+ const tslib_1 = require("tslib");
8
+ const node_crypto_1 = tslib_1.__importDefault(require("node:crypto"));
9
+ const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
10
+ const node_http_1 = tslib_1.__importDefault(require("node:http"));
11
+ const node_os_1 = tslib_1.__importDefault(require("node:os"));
12
+ const node_path_1 = tslib_1.__importDefault(require("node:path"));
13
+ const SESSION_VERSION = 1;
14
+ const PUBLISH_PATH = '/publish';
15
+ function defaultRegistryDir() {
16
+ const userId = typeof process.getuid === 'function' ? String(process.getuid()) : node_os_1.default.userInfo().username;
17
+ return node_path_1.default.join(node_os_1.default.tmpdir(), `valdi-web-sessions-${userId}`);
18
+ }
19
+ function ensureRegistryDir(registryDir) {
20
+ node_fs_1.default.mkdirSync(registryDir, { mode: 0o700, recursive: true });
21
+ const stat = node_fs_1.default.lstatSync(registryDir);
22
+ if (!stat.isDirectory() || stat.isSymbolicLink()) {
23
+ throw new Error(`Web hot reload registry is not a directory: ${registryDir}`);
24
+ }
25
+ if (typeof process.getuid === 'function' && stat.uid !== process.getuid()) {
26
+ throw new Error(`Web hot reload registry is not owned by the current user: ${registryDir}`);
27
+ }
28
+ try {
29
+ node_fs_1.default.chmodSync(registryDir, 0o700);
30
+ }
31
+ catch {
32
+ }
33
+ }
34
+ function sessionFilePath(registryDir, id) {
35
+ return node_path_1.default.join(registryDir, `${id}.json`);
36
+ }
37
+ function isProcessRunning(pid) {
38
+ try {
39
+ process.kill(pid, 0);
40
+ return true;
41
+ }
42
+ catch (error) {
43
+ return error.code === 'EPERM';
44
+ }
45
+ }
46
+ function isSessionDescriptor(value) {
47
+ if (typeof value !== 'object' || value === null) {
48
+ return false;
49
+ }
50
+ const descriptor = value;
51
+ return (descriptor.version === SESSION_VERSION &&
52
+ typeof descriptor.id === 'string' &&
53
+ Number.isInteger(descriptor.pid) &&
54
+ typeof descriptor.pid === 'number' &&
55
+ descriptor.pid > 0 &&
56
+ typeof descriptor.workspaceRoot === 'string' &&
57
+ typeof descriptor.applicationTarget === 'string' &&
58
+ typeof descriptor.hotreloadTarget === 'string' &&
59
+ typeof descriptor.bazelArgs === 'string' &&
60
+ typeof descriptor.publishUrl === 'string' &&
61
+ typeof descriptor.token === 'string' &&
62
+ typeof descriptor.startedAt === 'string');
63
+ }
64
+ function closeServer(server, sockets) {
65
+ return new Promise((resolve, reject) => {
66
+ server.close(error => {
67
+ if (error) {
68
+ reject(error);
69
+ }
70
+ else {
71
+ resolve();
72
+ }
73
+ });
74
+ for (const socket of sockets) {
75
+ socket.destroy();
76
+ }
77
+ });
78
+ }
79
+ function inferWebHotReloadTarget(applicationTarget) {
80
+ const separatorIndex = applicationTarget.lastIndexOf(':');
81
+ const targetNameStart = separatorIndex === -1 ? applicationTarget.lastIndexOf('/') + 1 : separatorIndex + 1;
82
+ const targetName = applicationTarget.slice(targetNameStart);
83
+ if (!targetName.endsWith('_web')) {
84
+ return undefined;
85
+ }
86
+ return `${applicationTarget.slice(0, targetNameStart)}${targetName.slice(0, -'_web'.length)}_hotreload`;
87
+ }
88
+ async function registerWebHotReloadSession(options) {
89
+ const registryDir = options.registryDir ?? defaultRegistryDir();
90
+ ensureRegistryDir(registryDir);
91
+ const token = node_crypto_1.default.randomBytes(32).toString('hex');
92
+ let publishQueue = Promise.resolve();
93
+ const server = node_http_1.default.createServer((request, response) => {
94
+ const requestUrl = new URL(request.url ?? '/', 'http://127.0.0.1');
95
+ if (request.method !== 'POST' || requestUrl.pathname !== PUBLISH_PATH) {
96
+ response.writeHead(404).end('not found');
97
+ return;
98
+ }
99
+ if (request.headers.authorization !== `Bearer ${token}`) {
100
+ response.writeHead(401).end('unauthorized');
101
+ return;
102
+ }
103
+ publishQueue = publishQueue.then(options.onPublish, options.onPublish);
104
+ void publishQueue.then(() => response.writeHead(204).end(), () => response.writeHead(500).end('publication failed'));
105
+ });
106
+ const sockets = new Set();
107
+ server.on('connection', socket => {
108
+ sockets.add(socket);
109
+ socket.once('close', () => sockets.delete(socket));
110
+ });
111
+ const port = await new Promise((resolve, reject) => {
112
+ server.once('error', reject);
113
+ server.listen(0, '127.0.0.1', () => {
114
+ server.off('error', reject);
115
+ const address = server.address();
116
+ if (address === null || typeof address === 'string') {
117
+ reject(new Error('Could not resolve the web hot reload control port'));
118
+ return;
119
+ }
120
+ resolve(address.port);
121
+ });
122
+ });
123
+ const descriptor = {
124
+ applicationTarget: options.applicationTarget,
125
+ bazelArgs: options.bazelArgs,
126
+ hotreloadTarget: options.hotreloadTarget,
127
+ id: node_crypto_1.default.randomUUID(),
128
+ pid: process.pid,
129
+ publishUrl: `http://127.0.0.1:${port}${PUBLISH_PATH}`,
130
+ startedAt: new Date().toISOString(),
131
+ token,
132
+ version: SESSION_VERSION,
133
+ workspaceRoot: node_fs_1.default.realpathSync(options.workspaceRoot),
134
+ };
135
+ const descriptorPath = sessionFilePath(registryDir, descriptor.id);
136
+ const temporaryPath = `${descriptorPath}.${process.pid}.tmp`;
137
+ try {
138
+ node_fs_1.default.writeFileSync(temporaryPath, JSON.stringify(descriptor), { flag: 'wx', mode: 0o600 });
139
+ node_fs_1.default.renameSync(temporaryPath, descriptorPath);
140
+ }
141
+ catch (error) {
142
+ node_fs_1.default.rmSync(temporaryPath, { force: true });
143
+ await closeServer(server, sockets);
144
+ throw error;
145
+ }
146
+ return {
147
+ descriptor,
148
+ close: async () => {
149
+ node_fs_1.default.rmSync(descriptorPath, { force: true });
150
+ await publishQueue.catch(() => { });
151
+ await closeServer(server, sockets);
152
+ },
153
+ };
154
+ }
155
+ function findWebHotReloadSessions(workspaceRoot, hotreloadTarget, registryDir = defaultRegistryDir()) {
156
+ if (!node_fs_1.default.existsSync(registryDir)) {
157
+ return [];
158
+ }
159
+ const realWorkspaceRoot = node_fs_1.default.realpathSync(workspaceRoot);
160
+ const sessions = [];
161
+ for (const entry of node_fs_1.default.readdirSync(registryDir, { withFileTypes: true })) {
162
+ if (!entry.isFile() || !entry.name.endsWith('.json')) {
163
+ continue;
164
+ }
165
+ const descriptorPath = node_path_1.default.join(registryDir, entry.name);
166
+ let descriptor;
167
+ try {
168
+ const parsed = JSON.parse(node_fs_1.default.readFileSync(descriptorPath, 'utf8'));
169
+ if (!isSessionDescriptor(parsed)) {
170
+ continue;
171
+ }
172
+ descriptor = parsed;
173
+ }
174
+ catch {
175
+ continue;
176
+ }
177
+ if (!isProcessRunning(descriptor.pid)) {
178
+ node_fs_1.default.rmSync(descriptorPath, { force: true });
179
+ continue;
180
+ }
181
+ if (descriptor.workspaceRoot === realWorkspaceRoot &&
182
+ (hotreloadTarget === undefined || descriptor.hotreloadTarget === hotreloadTarget)) {
183
+ sessions.push(descriptor);
184
+ }
185
+ }
186
+ return sessions.sort((left, right) => left.startedAt.localeCompare(right.startedAt));
187
+ }
188
+ function publishWebHotReloadSession(session) {
189
+ const publishUrl = new URL(session.publishUrl);
190
+ if (publishUrl.protocol !== 'http:' || publishUrl.hostname !== '127.0.0.1' || publishUrl.pathname !== PUBLISH_PATH) {
191
+ return Promise.reject(new Error(`Refusing non-loopback web hot reload endpoint: ${session.publishUrl}`));
192
+ }
193
+ return new Promise((resolve, reject) => {
194
+ const request = node_http_1.default.request(publishUrl, {
195
+ headers: { authorization: `Bearer ${session.token}` },
196
+ method: 'POST',
197
+ }, response => {
198
+ response.resume();
199
+ response.once('end', () => {
200
+ if (response.statusCode === 204) {
201
+ resolve();
202
+ }
203
+ else {
204
+ reject(new Error(`Web hot reload publication failed with HTTP ${String(response.statusCode)}`));
205
+ }
206
+ });
207
+ });
208
+ request.setTimeout(60_000, () => request.destroy(new Error('Web hot reload publication timed out')));
209
+ request.once('error', reject);
210
+ request.end();
211
+ });
212
+ }
@@ -0,0 +1,195 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WEB_LIVE_RELOAD_PATH = void 0;
4
+ exports.startStaticWebServer = startStaticWebServer;
5
+ exports.openUrlInDefaultBrowser = openUrlInDefaultBrowser;
6
+ const tslib_1 = require("tslib");
7
+ const child_process_1 = require("child_process");
8
+ const fs_1 = tslib_1.__importDefault(require("fs"));
9
+ const http_1 = tslib_1.__importDefault(require("http"));
10
+ const path_1 = tslib_1.__importDefault(require("path"));
11
+ exports.WEB_LIVE_RELOAD_PATH = '/__valdi_livereload';
12
+ const LIVE_RELOAD_SCRIPT = `<script>
13
+ (() => {
14
+ const events = new EventSource('${exports.WEB_LIVE_RELOAD_PATH}');
15
+ events.addEventListener('reload', () => window.location.reload());
16
+ })();
17
+ </script>`;
18
+ function contentType(filePath) {
19
+ if (filePath.endsWith('.html')) {
20
+ return 'text/html; charset=utf-8';
21
+ }
22
+ if (filePath.endsWith('.js')) {
23
+ return 'text/javascript; charset=utf-8';
24
+ }
25
+ if (filePath.endsWith('.json')) {
26
+ return 'application/json; charset=utf-8';
27
+ }
28
+ if (filePath.endsWith('.png')) {
29
+ return 'image/png';
30
+ }
31
+ if (filePath.endsWith('.jpg') || filePath.endsWith('.jpeg')) {
32
+ return 'image/jpeg';
33
+ }
34
+ if (filePath.endsWith('.svg')) {
35
+ return 'image/svg+xml';
36
+ }
37
+ if (filePath.endsWith('.webp')) {
38
+ return 'image/webp';
39
+ }
40
+ return 'application/octet-stream';
41
+ }
42
+ function sendText(response, statusCode, body) {
43
+ response.writeHead(statusCode, { 'content-type': 'text/plain; charset=utf-8' });
44
+ response.end(body);
45
+ }
46
+ function injectHtml(html, injectedHtml) {
47
+ const headEnd = html.lastIndexOf('</head>');
48
+ if (headEnd !== -1) {
49
+ return `${html.slice(0, headEnd)}${injectedHtml}\n${html.slice(headEnd)}`;
50
+ }
51
+ return `${injectedHtml}\n${html}`;
52
+ }
53
+ function serveFile(rootDir, request, response, injectedHtml, liveReload) {
54
+ if (request.method !== 'GET' && request.method !== 'HEAD') {
55
+ sendText(response, 405, 'method not allowed');
56
+ return;
57
+ }
58
+ const requestUrl = new URL(request.url ?? '/', `http://${request.headers.host ?? 'localhost'}`);
59
+ const decodedPath = decodeURIComponent(requestUrl.pathname === '/' ? '/index.html' : requestUrl.pathname);
60
+ if (decodedPath.split('/').includes('..')) {
61
+ sendText(response, 403, 'forbidden');
62
+ return;
63
+ }
64
+ const root = path_1.default.resolve(rootDir);
65
+ const relativePath = decodedPath.startsWith('/') ? decodedPath.slice(1) : decodedPath;
66
+ let filePath = path_1.default.resolve(root, relativePath);
67
+ if (!(filePath === root || filePath.startsWith(`${root}${path_1.default.sep}`))) {
68
+ sendText(response, 403, 'forbidden');
69
+ return;
70
+ }
71
+ if (fs_1.default.existsSync(filePath) && fs_1.default.statSync(filePath).isDirectory()) {
72
+ filePath = path_1.default.join(filePath, 'index.html');
73
+ }
74
+ if (!fs_1.default.existsSync(filePath) || !fs_1.default.statSync(filePath).isFile()) {
75
+ sendText(response, 404, 'not found');
76
+ return;
77
+ }
78
+ response.writeHead(200, {
79
+ 'cache-control': liveReload || injectedHtml !== '' ? 'no-store' : 'no-cache',
80
+ 'content-type': contentType(filePath),
81
+ });
82
+ if (request.method === 'HEAD') {
83
+ response.end();
84
+ return;
85
+ }
86
+ if (injectedHtml !== '' && filePath.endsWith('.html')) {
87
+ response.end(injectHtml(fs_1.default.readFileSync(filePath, 'utf8'), injectedHtml));
88
+ return;
89
+ }
90
+ fs_1.default.createReadStream(filePath).pipe(response);
91
+ }
92
+ function serveLiveReload(request, response, clients) {
93
+ if (request.method !== 'GET') {
94
+ sendText(response, 405, 'method not allowed');
95
+ return;
96
+ }
97
+ response.writeHead(200, {
98
+ 'cache-control': 'no-cache, no-transform',
99
+ connection: 'keep-alive',
100
+ 'content-type': 'text/event-stream',
101
+ });
102
+ response.write('retry: 1000\n\n');
103
+ clients.add(response);
104
+ request.once('close', () => {
105
+ clients.delete(response);
106
+ });
107
+ }
108
+ function listen(server, host, port) {
109
+ return new Promise((resolve, reject) => {
110
+ const onError = (error) => {
111
+ reject(error);
112
+ };
113
+ server.once('error', onError);
114
+ server.listen(port, host, () => {
115
+ server.off('error', onError);
116
+ const address = server.address();
117
+ if (address === null || typeof address === 'string') {
118
+ reject(new Error(`Could not resolve listening port for ${host}:${port}`));
119
+ return;
120
+ }
121
+ resolve(address.port);
122
+ });
123
+ });
124
+ }
125
+ function trackConnections(server) {
126
+ const sockets = new Set();
127
+ server.on('connection', socket => {
128
+ sockets.add(socket);
129
+ socket.on('close', () => {
130
+ sockets.delete(socket);
131
+ });
132
+ });
133
+ return sockets;
134
+ }
135
+ function close(server, sockets) {
136
+ return new Promise((resolve, reject) => {
137
+ server.close(error => {
138
+ if (error) {
139
+ reject(error);
140
+ }
141
+ else {
142
+ resolve();
143
+ }
144
+ });
145
+ for (const socket of sockets) {
146
+ socket.destroy();
147
+ }
148
+ });
149
+ }
150
+ async function startStaticWebServer(rootDir, options) {
151
+ let activeRootDir = path_1.default.resolve(rootDir);
152
+ const liveReloadClients = new Set();
153
+ const injectedHtml = options.liveReload ? LIVE_RELOAD_SCRIPT : '';
154
+ const server = http_1.default.createServer((request, response) => {
155
+ const requestUrl = new URL(request.url ?? '/', `http://${request.headers.host ?? 'localhost'}`);
156
+ if (options.liveReload && requestUrl.pathname === exports.WEB_LIVE_RELOAD_PATH) {
157
+ serveLiveReload(request, response, liveReloadClients);
158
+ return;
159
+ }
160
+ serveFile(activeRootDir, request, response, injectedHtml, options.liveReload ?? false);
161
+ });
162
+ const sockets = trackConnections(server);
163
+ const actualPort = await listen(server, options.host, options.port);
164
+ return {
165
+ url: `http://${options.host}:${actualPort}/index.html`,
166
+ close: async () => {
167
+ for (const client of liveReloadClients) {
168
+ client.end();
169
+ }
170
+ liveReloadClients.clear();
171
+ await close(server, sockets);
172
+ },
173
+ reload: () => {
174
+ for (const client of liveReloadClients) {
175
+ client.write('event: reload\ndata: {}\n\n');
176
+ }
177
+ },
178
+ setRootDir: nextRootDir => {
179
+ activeRootDir = path_1.default.resolve(nextRootDir);
180
+ },
181
+ };
182
+ }
183
+ function openUrlInDefaultBrowser(url) {
184
+ const platform = process.platform;
185
+ const command = platform === 'darwin' ? 'open' : platform === 'win32' ? 'cmd' : 'xdg-open';
186
+ const args = platform === 'win32' ? ['/c', 'start', '', url] : [url];
187
+ const child = (0, child_process_1.spawn)(command, args, {
188
+ detached: true,
189
+ stdio: 'ignore',
190
+ });
191
+ child.on('error', error => {
192
+ console.warn(`Could not open browser: ${error.message}`);
193
+ });
194
+ child.unref();
195
+ }
@@ -1,16 +1,34 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.decompressTo = decompressTo;
4
+ exports.compressDirectoryContentsTo = compressDirectoryContentsTo;
4
5
  const tslib_1 = require("tslib");
6
+ const node_child_process_1 = require("node:child_process");
7
+ const fs = tslib_1.__importStar(require("node:fs"));
5
8
  const node_path_1 = tslib_1.__importDefault(require("node:path"));
6
- const extract_zip_1 = tslib_1.__importDefault(require("extract-zip"));
9
+ const node_util_1 = require("node:util");
10
+ const execFileAsync = (0, node_util_1.promisify)(node_child_process_1.execFile);
7
11
  async function decompressTo(inputFilePath, outputFilePath) {
8
12
  const archive = node_path_1.default.resolve(inputFilePath);
9
13
  const destination = node_path_1.default.resolve(outputFilePath);
10
14
  try {
11
- await (0, extract_zip_1.default)(archive, { dir: destination });
15
+ await execFileAsync('unzip', ['-DD', '-q', '-o', archive, '-d', destination]);
12
16
  }
13
17
  catch (error) {
14
18
  throw new Error(`Failed to extract “${archive}” → “${destination}”: ${error.message}`);
15
19
  }
16
20
  }
21
+ async function compressDirectoryContentsTo(inputDirectoryPath, outputFilePath) {
22
+ const sourceDirectory = node_path_1.default.resolve(inputDirectoryPath);
23
+ const archive = node_path_1.default.resolve(outputFilePath);
24
+ const stat = await fs.promises.stat(sourceDirectory);
25
+ if (!stat.isDirectory()) {
26
+ throw new Error(`Expected ${sourceDirectory} to be a directory`);
27
+ }
28
+ try {
29
+ await execFileAsync('zip', ['-q', '-r', archive, '.'], { cwd: sourceDirectory });
30
+ }
31
+ catch (error) {
32
+ throw new Error(`Failed to archive ${sourceDirectory} into ${archive}: ${error.message}`);
33
+ }
34
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@snap/valdi",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "Valdi CLI tools for developers",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -14,6 +14,9 @@
14
14
  "bin": {
15
15
  "valdi": "dist/index.js"
16
16
  },
17
+ "engines": {
18
+ "node": ">=20"
19
+ },
17
20
  "files": [
18
21
  "dist",
19
22
  "debugger",
@@ -42,7 +45,6 @@
42
45
  "@bazel/bazelisk": "^1.19.0",
43
46
  "@types/inquirer": "^9.0.7",
44
47
  "@types/yargs": "^17.0.32",
45
- "extract-zip": "^2.0.1",
46
48
  "glob": "^11.0.1",
47
49
  "inquirer": "^8.0.0",
48
50
  "jsonc-parser": "^3.3.1",