@travetto/pack 8.0.0-alpha.9 → 8.0.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.
@@ -2,18 +2,17 @@ import fs from 'node:fs/promises';
2
2
  import path from 'node:path';
3
3
 
4
4
  import { cliTpl } from '@travetto/cli';
5
- import { JSONUtil, Env, Runtime, RuntimeIndex } from '@travetto/runtime';
5
+ import { Env, JSONUtil, Runtime, RuntimeIndex } from '@travetto/runtime';
6
6
 
7
7
  import type { CommonPackConfig } from '../../src/types.ts';
8
- import { PackUtil } from './util.ts';
9
8
  import { ActiveShellCommand, ShellCommands } from './shell.ts';
9
+ import { PackUtil } from './util.ts';
10
10
 
11
11
  /**
12
12
  * General pack operations
13
13
  */
14
14
  export class PackOperation {
15
-
16
- static async * title(config: CommonPackConfig, title: string): AsyncIterable<string[]> {
15
+ static async *title(config: CommonPackConfig, title: string): AsyncIterable<string[]> {
17
16
  if (config.ejectFile) {
18
17
  yield ActiveShellCommand.comment(title);
19
18
  yield ActiveShellCommand.echo(title);
@@ -25,7 +24,7 @@ export class PackOperation {
25
24
  /**
26
25
  * Clean out pack workspace, removing all content
27
26
  */
28
- static async * clean(config: CommonPackConfig): AsyncIterable<string[]> {
27
+ static async *clean(config: CommonPackConfig): AsyncIterable<string[]> {
29
28
  if (!config.clean) {
30
29
  return;
31
30
  }
@@ -50,39 +49,47 @@ export class PackOperation {
50
49
  /**
51
50
  * Invoke bundler (rollup) to produce output in workspace folder
52
51
  */
53
- static async * bundle(config: CommonPackConfig): AsyncIterable<string[]> {
52
+ static async *bundle(config: CommonPackConfig): AsyncIterable<string[]> {
54
53
  const cwd = RuntimeIndex.outputRoot;
55
54
  const out = RuntimeIndex.manifest.build.outputFolder;
56
55
 
57
- const bundleCommand = [process.argv0, RuntimeIndex.resolvePackageCommand('rollup'), '-c', RuntimeIndex.resolveFileImport(config.rollupConfiguration)];
56
+ const bundleCommand = [
57
+ process.argv0,
58
+ RuntimeIndex.resolvePackageCommand('rollup'),
59
+ '-c',
60
+ RuntimeIndex.resolveFileImport(config.rollupConfiguration)
61
+ ];
58
62
 
59
63
  const entryPointFile = RuntimeIndex.getFromImport(config.entryPoint)!.outputFile.split(`${out}/`)[1];
60
64
 
61
65
  const env = {
62
- ...Object.fromEntries(([
63
- ['BUNDLE_ENTRY', entryPointFile],
64
- ['BUNDLE_MAIN_FILE', config.mainFile],
65
- ['BUNDLE_COMPRESS', config.minify],
66
- ['BUNDLE_SOURCEMAP', config.sourcemap],
67
- ['BUNDLE_SOURCES', config.includeSources],
68
- ['BUNDLE_OUTPUT', config.buildDirectory],
69
- ['BUNDLE_ENV_FILE', config.envFile],
70
- ['BUNDLE_EXTERNAL', config.externalDependencies.map(module => module.split(':')[0]).join(',')]
71
- ] as const)
72
- .filter(pair => pair[1] === false || pair[1])
73
- .map(pair => [pair[0], `${pair[1]}`])
66
+ ...Object.fromEntries(
67
+ (
68
+ [
69
+ ['BUNDLE_ENTRY', entryPointFile],
70
+ ['BUNDLE_MAIN_FILE', config.mainFile],
71
+ ['BUNDLE_COMPRESS', config.minify],
72
+ ['BUNDLE_SOURCEMAP', config.sourcemap],
73
+ ['BUNDLE_SOURCES', config.includeSources],
74
+ ['BUNDLE_OUTPUT', config.buildDirectory],
75
+ ['BUNDLE_ENV_FILE', config.envFile],
76
+ ['BUNDLE_EXTERNAL', config.externalDependencies.map(module => module.split(':')[0]).join(',')]
77
+ ] as const
78
+ )
79
+ .filter(pair => pair[1] === false || pair[1])
80
+ .map(pair => [pair[0], `${pair[1]}`])
74
81
  ),
75
- ...Env.TRV_MANIFEST.export(RuntimeIndex.getModule(config.module)!.outputPath),
82
+ ...Env.TRV_MANIFEST.export(RuntimeIndex.getModule(config.module)!.outputPath)
76
83
  };
77
84
 
78
85
  const properties = (['minify', 'sourcemap', 'entryPoint'] as const)
79
- .map(key => cliTpl`${{ subtitle: key }}=${{ param: config[key] }}`).join(' ');
86
+ .map(key => cliTpl`${{ subtitle: key }}=${{ param: config[key] }}`)
87
+ .join(' ');
80
88
 
81
89
  yield* PackOperation.title(config, cliTpl`${{ title: 'Bundling Output' }} ${properties}`);
82
90
 
83
91
  if (config.ejectFile) {
84
- yield* Object
85
- .entries(env)
92
+ yield* Object.entries(env)
86
93
  .filter(pair => !!pair[1])
87
94
  .map(pair => ActiveShellCommand.export(pair[0], pair[1]));
88
95
  yield ActiveShellCommand.chdir(cwd);
@@ -98,29 +105,23 @@ export class PackOperation {
98
105
  /**
99
106
  * Write out package.json, to help define how output .js file should be interpreted
100
107
  */
101
- static async * writePackageJson(config: CommonPackConfig): AsyncIterable<string[]> {
108
+ static async *writePackageJson(config: CommonPackConfig): AsyncIterable<string[]> {
102
109
  const file = 'package.json';
103
110
  const pkg = { type: 'module', main: config.mainFile };
104
111
 
105
112
  yield* PackOperation.title(config, cliTpl`${{ title: 'Writing' }} ${{ path: file }}`);
106
113
 
107
114
  if (config.ejectFile) {
108
- yield* ActiveShellCommand.createFile(
109
- path.resolve(config.buildDirectory, file),
110
- [JSONUtil.toUTF8(pkg)]
111
- );
115
+ yield* ActiveShellCommand.createFile(path.resolve(config.buildDirectory, file), [JSONUtil.toUTF8(pkg)]);
112
116
  } else {
113
- await PackUtil.writeRawFile(
114
- path.resolve(config.buildDirectory, file),
115
- [JSONUtil.toUTF8Pretty(pkg)]
116
- );
117
+ await PackUtil.writeRawFile(path.resolve(config.buildDirectory, file), [JSONUtil.toUTF8Pretty(pkg)]);
117
118
  }
118
119
  }
119
120
 
120
121
  /**
121
122
  * Define .env.js file to control manifest location
122
123
  */
123
- static async * writeEnv(config: CommonPackConfig): AsyncIterable<string[]> {
124
+ static async *writeEnv(config: CommonPackConfig): AsyncIterable<string[]> {
124
125
  const file = path.resolve(config.buildDirectory, config.envFile);
125
126
  const env = {
126
127
  ...Env.NODE_ENV.export('production'),
@@ -129,40 +130,34 @@ export class PackOperation {
129
130
  ...Env.TRV_CLI_IPC.export(undefined),
130
131
  ...Env.TRV_RESOURCE_OVERRIDES.export({
131
132
  '@#resources': '@@#resources',
132
- ...(config.includeWorkspaceResources ? {
133
- '@@#resources': `@@#${config.workspaceResourceFolder}`
134
- } : {})
133
+ ...(config.includeWorkspaceResources
134
+ ? {
135
+ '@@#resources': `@@#${config.workspaceResourceFolder}`
136
+ }
137
+ : {})
135
138
  })
136
139
  };
137
140
 
138
141
  yield* PackOperation.title(config, cliTpl`${{ title: 'Writing' }} ${{ path: file }}`);
139
142
 
140
143
  if (config.ejectFile) {
141
- yield* ActiveShellCommand.createFile(
142
- path.resolve(config.buildDirectory, file),
143
- PackUtil.buildEnvFile(env)
144
- );
144
+ yield* ActiveShellCommand.createFile(path.resolve(config.buildDirectory, file), PackUtil.buildEnvFile(env));
145
145
  } else {
146
- await PackUtil.writeRawFile(
147
- path.resolve(config.buildDirectory, file),
148
- PackUtil.buildEnvFile(env)
149
- );
146
+ await PackUtil.writeRawFile(path.resolve(config.buildDirectory, file), PackUtil.buildEnvFile(env));
150
147
  }
151
148
  }
152
149
 
153
150
  /**
154
151
  * Create launcher scripts (.sh, .cmd) to run output
155
152
  */
156
- static async * writeEntryScript(config: CommonPackConfig): AsyncIterable<string[]> {
153
+ static async *writeEntryScript(config: CommonPackConfig): AsyncIterable<string[]> {
157
154
  if (!config.mainScripts && !config.entryPoint.includes('@travetto/cli')) {
158
155
  return;
159
156
  }
160
157
 
161
158
  const title = 'Writing entry scripts';
162
159
  for (const sh of [ShellCommands.posix, ShellCommands.win32]) {
163
- const { ext, contents } = sh.script(
164
- sh.callCommandWithAllArgs('node', config.mainFile, ...config.entryArguments), true
165
- );
160
+ const { ext, contents } = sh.script(sh.callCommandWithAllArgs('node', config.mainFile, ...config.entryArguments), true);
166
161
  const file = `${config.mainName}${ext}`;
167
162
  const args = config.entryArguments.join(' ');
168
163
 
@@ -170,7 +165,6 @@ export class PackOperation {
170
165
 
171
166
  if (config.ejectFile) {
172
167
  yield* ActiveShellCommand.createFile(path.resolve(config.buildDirectory, file), contents, '755');
173
-
174
168
  } else {
175
169
  await PackUtil.writeRawFile(path.resolve(config.buildDirectory, file), contents, '755');
176
170
  }
@@ -180,7 +174,7 @@ export class PackOperation {
180
174
  /**
181
175
  * Copy over repo /resources folder into workspace, will get packaged into final output
182
176
  */
183
- static async * copyMonoRepoResources(config: CommonPackConfig): AsyncIterable<string[]> {
177
+ static async *copyMonoRepoResources(config: CommonPackConfig): AsyncIterable<string[]> {
184
178
  if (!config.includeWorkspaceResources) {
185
179
  return;
186
180
  }
@@ -200,7 +194,7 @@ export class PackOperation {
200
194
  /**
201
195
  * Copy over /resources folder into workspace, will get packaged into final output
202
196
  */
203
- static async * copyResources(config: CommonPackConfig): AsyncIterable<string[]> {
197
+ static async *copyResources(config: CommonPackConfig): AsyncIterable<string[]> {
204
198
  const resources = {
205
199
  count: RuntimeIndex.mainModule.files.resources?.length ?? 0,
206
200
  sourceDirectory: path.resolve(Runtime.mainSourcePath, 'resources'),
@@ -223,7 +217,7 @@ export class PackOperation {
223
217
  /**
224
218
  * Produce the output manifest, only including production dependencies
225
219
  */
226
- static async * writeManifest(config: CommonPackConfig): AsyncIterable<string[]> {
220
+ static async *writeManifest(config: CommonPackConfig): AsyncIterable<string[]> {
227
221
  const out = path.resolve(config.buildDirectory, config.manifestFile);
228
222
  const cmd = [process.argv0, RuntimeIndex.resolvePackageCommand('trvc'), 'manifest:production', out];
229
223
  const env = { ...Env.TRV_MODULE.export(config.module) };
@@ -240,8 +234,7 @@ export class PackOperation {
240
234
  /**
241
235
  * Generate ZIP file for workspace
242
236
  */
243
- static async * compress(config: CommonPackConfig): AsyncIterable<string[]> {
244
-
237
+ static async *compress(config: CommonPackConfig): AsyncIterable<string[]> {
245
238
  yield* PackOperation.title(config, cliTpl`${{ title: 'Compressing' }} ${{ path: config.output }}`);
246
239
 
247
240
  if (config.ejectFile) {
@@ -254,4 +247,4 @@ export class PackOperation {
254
247
  await PackUtil.runCommand(ActiveShellCommand.zip(config.output), { cwd: config.buildDirectory });
255
248
  }
256
249
  }
257
- }
250
+ }
@@ -1,10 +1,15 @@
1
1
  import { readFileSync as readSyncPreamble } from 'node:fs';
2
2
 
3
3
  // @ts-expect-error -- Lock to prevent __proto__ pollution in JSON
4
+ // biome-ignore lint/suspicious/noProto: Lock to prevent __proto__ pollution in JSON
4
5
  const objectProto = Object.prototype.__proto__;
5
6
  Object.defineProperty(Object.prototype, '__proto__', {
6
- get() { return objectProto; },
7
- set(value) { Object.setPrototypeOf(this, value); }
7
+ get() {
8
+ return objectProto;
9
+ },
10
+ set(value) {
11
+ Object.setPrototypeOf(this, value);
12
+ }
8
13
  });
9
14
 
10
15
  if (!process.env.TRV_MODULE && '%%ENV_FILE%%') {
@@ -13,6 +18,8 @@ if (!process.env.TRV_MODULE && '%%ENV_FILE%%') {
13
18
  .split('\n')
14
19
  .map(line => line.match(/\s*(?<key>[^ =]+)\s*=\s*(?<value>\S+)/)?.groups)
15
20
  .filter(pair => !!pair)
16
- .forEach(pair => process.env[pair.key] = pair.value);
17
- } catch { }
18
- }
21
+ .forEach(pair => {
22
+ process.env[pair.key] = pair.value;
23
+ });
24
+ } catch {}
25
+ }
@@ -1,18 +1,14 @@
1
- import util from 'node:util';
2
1
  import path from 'node:path';
2
+ import util from 'node:util';
3
3
 
4
4
  import type { ShellCommandProvider } from '../../src/types.ts';
5
5
 
6
- const escape = (text: string): string =>
7
- text
8
- .replaceAll('"', '\\"')
9
- .replaceAll('$', '\\$');
6
+ const shellEscape = (text: string): string => text.replaceAll('"', '\\"').replaceAll('$', '\\$');
10
7
 
11
- const escapedArgs = (args: string[]): string[] => args.map(arg =>
12
- arg.includes(' ') || arg.includes('"') ? `'${arg}'` : (arg.includes("'") ? `"${arg}"` : arg)
13
- );
8
+ const escapedArgs = (args: string[]): string[] =>
9
+ args.map(arg => (arg.includes(' ') || arg.includes('"') ? `'${arg}'` : arg.includes("'") ? `"${arg}"` : arg));
14
10
 
15
- const toWin = (file: string): string => file.replace(/[\\\/]+/g, path.win32.sep);
11
+ const toWin = (file: string): string => file.replace(/[/\\]+/g, path.win32.sep);
16
12
 
17
13
  export const ShellCommands: Record<'win32' | 'posix', ShellCommandProvider> = {
18
14
  win32: {
@@ -20,55 +16,56 @@ export const ShellCommands: Record<'win32' | 'posix', ShellCommandProvider> = {
20
16
  callCommandWithAllArgs: (cmd, ...args) => [[cmd, ...escapedArgs(args), '%*'].join(' ')],
21
17
  createFile: (file, text) => [
22
18
  ['@echo', 'off'],
23
- ...text.map((line, i) =>
24
- ['echo', `"${escape(line)}"`, i === 0 ? '>' : '>>', file]
25
- )
19
+ ...text.map((line, i) => ['echo', `"${shellEscape(line)}"`, i === 0 ? '>' : '>>', file])
26
20
  ],
27
21
  copy: (sourceFile, destinationFile) => ['copy', sourceFile, destinationFile],
28
- copyRecursive: (sourceDirectory, destinationDirectory, inclusive) =>
29
- ['xcopy', '/y', '/h', '/s', inclusive ? `${toWin(sourceDirectory)}\\*.*` : toWin(sourceDirectory), toWin(destinationDirectory)],
30
- rmRecursive: (destinationDirectory) => ['rmdir', '/Q', '/S', destinationDirectory],
31
- mkdir: (destinationDirectory) => ['md', destinationDirectory],
22
+ copyRecursive: (sourceDirectory, destinationDirectory, inclusive) => [
23
+ 'xcopy',
24
+ '/y',
25
+ '/h',
26
+ '/s',
27
+ inclusive ? `${toWin(sourceDirectory)}\\*.*` : toWin(sourceDirectory),
28
+ toWin(destinationDirectory)
29
+ ],
30
+ rmRecursive: destinationDirectory => ['rmdir', '/Q', '/S', destinationDirectory],
31
+ mkdir: destinationDirectory => ['md', destinationDirectory],
32
32
  export: (key, value) => ['set', `${key}=${value}`],
33
- chdir: (destinationDirectory) => ['cd', destinationDirectory],
34
- comment: (message) => ['\nREM', util.stripVTControlCharacters(message), '\n'],
35
- echo: (message) => ['echo', `"${escape(util.stripVTControlCharacters(message))}"\n`],
36
- zip: (outputFile) => ['powershell', 'Compress-Archive', '-Path', '.', '-DestinationPath', outputFile],
33
+ chdir: destinationDirectory => ['cd', destinationDirectory],
34
+ comment: message => ['\nREM', util.stripVTControlCharacters(message), '\n'],
35
+ echo: message => ['echo', `"${shellEscape(util.stripVTControlCharacters(message))}"\n`],
36
+ zip: outputFile => ['powershell', 'Compress-Archive', '-Path', '.', '-DestinationPath', outputFile],
37
37
  script: (lines: string[], changeDirectory: boolean = false) => ({
38
38
  ext: '.cmd',
39
- contents: [
40
- ...(changeDirectory ? ['cd %~p0'] : []),
41
- ...lines,
42
- ]
39
+ contents: [...(changeDirectory ? ['cd %~p0'] : []), ...lines]
43
40
  })
44
41
  },
45
42
  posix: {
46
43
  var: (name: string) => `$${name}`,
47
44
  callCommandWithAllArgs: (cmd, ...args) => [[cmd, ...escapedArgs(args), '$@'].join(' ')],
48
45
  createFile: (file, text, mode) => [
49
- ...text.map((line, i) =>
50
- ['echo', `"${escape(line)}"`, i === 0 ? '>' : '>>', file]),
46
+ ...text.map((line, i) => ['echo', `"${shellEscape(line)}"`, i === 0 ? '>' : '>>', file]),
51
47
  ...(mode ? [['chmod', mode, file]] : [])
52
48
  ],
53
49
  copy: (sourceFile, destinationFile) => ['cp', sourceFile, destinationFile],
54
- copyRecursive: (sourceDirectory, destinationDirectory, inclusive) =>
55
- ['cp', '-r', '-p', inclusive ? `${sourceDirectory}/*` : sourceDirectory, destinationDirectory],
56
- rmRecursive: (destinationDirectory) => ['rm', '-rf', destinationDirectory],
57
- mkdir: (destinationDirectory) => ['mkdir', '-p', destinationDirectory],
50
+ copyRecursive: (sourceDirectory, destinationDirectory, inclusive) => [
51
+ 'cp',
52
+ '-r',
53
+ '-p',
54
+ inclusive ? `${sourceDirectory}/*` : sourceDirectory,
55
+ destinationDirectory
56
+ ],
57
+ rmRecursive: destinationDirectory => ['rm', '-rf', destinationDirectory],
58
+ mkdir: destinationDirectory => ['mkdir', '-p', destinationDirectory],
58
59
  export: (key, value) => ['export', `${key}=${value}`],
59
- chdir: (destinationDirectory) => ['cd', destinationDirectory],
60
- comment: (message) => ['\n#', util.stripVTControlCharacters(message), '\n'],
61
- echo: (message) => ['echo', `"${escape(util.stripVTControlCharacters(message))}"\n`],
62
- zip: (outputFile) => ['zip', '-r', outputFile, '.'],
60
+ chdir: destinationDirectory => ['cd', destinationDirectory],
61
+ comment: message => ['\n#', util.stripVTControlCharacters(message), '\n'],
62
+ echo: message => ['echo', `"${shellEscape(util.stripVTControlCharacters(message))}"\n`],
63
+ zip: outputFile => ['zip', '-r', outputFile, '.'],
63
64
  script: (lines: string[], changeDirectory: boolean = false) => ({
64
65
  ext: '.sh',
65
- contents: [
66
- '#!/bin/sh',
67
- ...(changeDirectory ? ['cd $(dirname "$0")'] : []),
68
- ...lines,
69
- ]
66
+ contents: ['#!/bin/sh', ...(changeDirectory ? ['cd $(dirname "$0")'] : []), ...lines]
70
67
  })
71
- },
68
+ }
72
69
  };
73
70
 
74
- export const ActiveShellCommand = ShellCommands[process.platform === 'win32' ? 'win32' : 'posix'];
71
+ export const ActiveShellCommand = ShellCommands[process.platform === 'win32' ? 'win32' : 'posix'];
@@ -1,8 +1,8 @@
1
+ import { type SpawnOptions, spawn } from 'node:child_process';
1
2
  import fs from 'node:fs/promises';
2
- import { spawn, type SpawnOptions } from 'node:child_process';
3
3
  import path from 'node:path';
4
4
 
5
- import { RuntimeError, ExecUtil, Runtime, RuntimeIndex } from '@travetto/runtime';
5
+ import { ExecUtil, Runtime, RuntimeError, RuntimeIndex } from '@travetto/runtime';
6
6
 
7
7
  import { ActiveShellCommand } from './shell.ts';
8
8
 
@@ -12,7 +12,7 @@ export class PackUtil {
12
12
  */
13
13
  static buildEnvFile(env: Record<string, string | number | boolean | undefined>): string[] {
14
14
  return Object.entries(env)
15
- .filter(([, value]) => (value !== undefined))
15
+ .filter(([, value]) => value !== undefined)
16
16
  .map(([key, value]) => `${key}=${value}`);
17
17
  }
18
18
 
@@ -21,7 +21,12 @@ export class PackUtil {
21
21
  * @param sourceDirectory The folder to copy
22
22
  * @param destinationDirectory The folder to copy to
23
23
  */
24
- static async copyRecursive(sourceDirectory: string, destinationDirectory: string, inclusive: boolean = false, ignoreFailure = false): Promise<void> {
24
+ static async copyRecursive(
25
+ sourceDirectory: string,
26
+ destinationDirectory: string,
27
+ inclusive: boolean = false,
28
+ ignoreFailure = false
29
+ ): Promise<void> {
25
30
  try {
26
31
  let final = destinationDirectory;
27
32
  if (!inclusive) {
@@ -43,11 +48,11 @@ export class PackUtil {
43
48
  const repoRoot = Runtime.workspaceRelative('.');
44
49
  const vars = { ROOT: path.resolve(), TRV_OUT: RuntimeIndex.outputRoot, REPO_ROOT: repoRoot, DIST: workspace, MODULE: module };
45
50
 
46
- const replaceArgs = (text: string): string => Object.entries(vars)
47
- .reduce((result, [key, value]) => result.replaceAll(value, ActiveShellCommand.var(key)), text);
51
+ const replaceArgs = (text: string): string =>
52
+ Object.entries(vars).reduce((result, [key, value]) => result.replaceAll(value, ActiveShellCommand.var(key)), text);
48
53
 
49
54
  const preamble = ActiveShellCommand.script(
50
- Object.entries(vars).map(([key, value]) => ActiveShellCommand.export(key, value).join(' ')),
55
+ Object.entries(vars).map(([key, value]) => ActiveShellCommand.export(key, value).join(' '))
51
56
  ).contents;
52
57
 
53
58
  let stream: fs.FileHandle | undefined;
@@ -58,7 +63,7 @@ export class PackUtil {
58
63
  stream = await fs.open(file, 'w', 0o755);
59
64
  }
60
65
 
61
- const write = (text: string): Promise<unknown> | unknown => stream ? stream.write(`${text}\n`) : process.stdout.write(`${text}\n`);
66
+ const write = (text: string): Promise<unknown> | unknown => (stream ? stream.write(`${text}\n`) : process.stdout.write(`${text}\n`));
62
67
 
63
68
  for (const line of preamble) {
64
69
  write(line);
@@ -75,10 +80,13 @@ export class PackUtil {
75
80
  * Track result response
76
81
  */
77
82
  static async runCommand(cmd: string[], options: SpawnOptions = {}): Promise<string> {
78
- const { valid, code, stderr, message, stdout } = await ExecUtil.getResult(spawn(cmd[0], cmd.slice(1), {
79
- stdio: [0, 'pipe', 'pipe'],
80
- ...options,
81
- }), { catch: true });
83
+ const { valid, code, stderr, message, stdout } = await ExecUtil.getResult(
84
+ spawn(cmd[0], cmd.slice(1), {
85
+ stdio: [0, 'pipe', 'pipe'],
86
+ ...options
87
+ }),
88
+ { catch: true }
89
+ );
82
90
 
83
91
  if (!valid) {
84
92
  process.exitCode = code;
@@ -93,4 +101,4 @@ export class PackUtil {
93
101
  static async writeRawFile(file: string, contents: string[], mode?: string): Promise<void> {
94
102
  await fs.writeFile(file, contents.join('\n'), { encoding: 'utf8', mode });
95
103
  }
96
- }
104
+ }
@@ -1,9 +1,12 @@
1
1
  import { CliCommand } from '@travetto/cli';
2
2
 
3
- import { BasePackCommand } from './pack.base';
3
+ import { BasePackCommand } from './pack.base.ts';
4
4
 
5
5
  /**
6
- * Standard pack support
6
+ * Build a standard module package artifact.
7
+ *
8
+ * This base command produces the default packaged output and serves as the
9
+ * common entry point for module packaging workflows.
7
10
  */
8
11
  @CliCommand()
9
- export class PackCommand extends BasePackCommand { }
12
+ export class PackCommand extends BasePackCommand {}
@@ -1,19 +1,22 @@
1
1
  import path from 'node:path';
2
2
 
3
- import { RuntimeIndex } from '@travetto/runtime';
4
3
  import { CliCommand, CliFlag, CliUtil } from '@travetto/cli';
4
+ import { RuntimeIndex } from '@travetto/runtime';
5
5
  import { Ignore, Max, Min, Required } from '@travetto/schema';
6
6
 
7
- import { DockerPackOperation } from './bin/docker-operation.ts';
8
- import { BasePackCommand, type PackOperationShape } from './pack.base';
9
7
  import type { DockerPackConfig } from '../src/types.ts';
8
+ import { DockerPackOperation } from './bin/docker-operation.ts';
9
+ import { BasePackCommand, type PackOperationShape } from './pack.base.ts';
10
10
 
11
11
  const NODE_MAJOR = process.version.match(/\d+/)?.[0] ?? '22';
12
- const asNumber = (input?: string): number | undefined => (!input || isNaN(+input)) ? undefined : +input;
13
- const asString = (input?: string): string | undefined => (input && asNumber(input)) ? input : undefined;
12
+ const asNumber = (input?: string): number | undefined => (!input || Number.isNaN(+input) ? undefined : +input);
13
+ const asString = (input?: string): string | undefined => (input && asNumber(input) ? input : undefined);
14
14
 
15
15
  /**
16
- * Standard docker support for pack
16
+ * Build container-ready artifacts and optionally publish Docker images.
17
+ *
18
+ * Extends the core pack pipeline with Dockerfile generation and image build/
19
+ * push operations, including runtime user and registry customization.
17
20
  */
18
21
  @CliCommand()
19
22
  export class PackDockerCommand extends BasePackCommand {
@@ -35,7 +38,8 @@ export class PackDockerCommand extends BasePackCommand {
35
38
  dockerRuntimePackages: string[] = [];
36
39
  /** Docker Image Port */
37
40
  @CliFlag({ short: 'dp', envVars: ['PACK_DOCKER_PORT'] })
38
- @Min(1) @Max(65536)
41
+ @Min(1)
42
+ @Max(65536)
39
43
  dockerPort: number[] = [];
40
44
 
41
45
  // Publish flags
@@ -110,10 +114,7 @@ export class PackDockerCommand extends BasePackCommand {
110
114
  DockerPackOperation.pullDockerBaseImage,
111
115
  DockerPackOperation.detectDockerImageOs,
112
116
  DockerPackOperation.writeDockerFile,
113
- ...this.dockerStageOnly ? [] : [
114
- DockerPackOperation.buildDockerContainer,
115
- DockerPackOperation.pushDockerContainer
116
- ]
117
+ ...(this.dockerStageOnly ? [] : [DockerPackOperation.buildDockerContainer, DockerPackOperation.pushDockerContainer])
117
118
  ];
118
119
  }
119
- }
120
+ }
@@ -1,14 +1,16 @@
1
1
  import { CliCommand, CliUtil } from '@travetto/cli';
2
2
 
3
3
  import { PackOperation } from './bin/operation.ts';
4
- import { BasePackCommand, type PackOperationShape } from './pack.base';
4
+ import { BasePackCommand, type PackOperationShape } from './pack.base.ts';
5
5
 
6
6
  /**
7
- * Standard zip support for pack
7
+ * Build a deployable zip artifact using the standard pack pipeline.
8
+ *
9
+ * This command runs base packing operations and then compresses the generated
10
+ * output into a single archive file.
8
11
  */
9
12
  @CliCommand()
10
13
  export class PackZipCommand extends BasePackCommand {
11
-
12
14
  finalize(forHelp?: boolean): void {
13
15
  if (forHelp) {
14
16
  this.output = '<module>.zip';
@@ -17,9 +19,6 @@ export class PackZipCommand extends BasePackCommand {
17
19
  }
18
20
 
19
21
  getOperations(): PackOperationShape<this>[] {
20
- return [
21
- ...super.getOperations(),
22
- PackOperation.compress
23
- ];
22
+ return [...super.getOperations(), PackOperation.compress];
24
23
  }
25
- }
24
+ }
@@ -2,31 +2,29 @@ import os from 'node:os';
2
2
  import path from 'node:path';
3
3
 
4
4
  import { type CliCommandShape, CliFlag, CliModuleFlag, CliParseUtil, cliTpl } from '@travetto/cli';
5
- import { TimeUtil, Runtime, RuntimeIndex } from '@travetto/runtime';
6
- import { Terminal } from '@travetto/terminal';
5
+ import { type IndexedModule, PackageUtil } from '@travetto/manifest';
6
+ import { Runtime, RuntimeIndex, TimeUtil } from '@travetto/runtime';
7
7
  import { Ignore, Method, Required, Schema } from '@travetto/schema';
8
- import { PackageUtil, type IndexedModule } from '@travetto/manifest';
8
+ import { Terminal } from '@travetto/terminal';
9
9
 
10
10
  import { PackOperation } from './bin/operation.ts';
11
11
  import { PackUtil } from './bin/util.ts';
12
12
 
13
- export type PackOperationShape<T> = ((config: T) => AsyncIterable<string[]>);
13
+ export type PackOperationShape<T> = (config: T) => AsyncIterable<string[]>;
14
14
 
15
15
  @Schema()
16
16
  export abstract class BasePackCommand implements CliCommandShape {
17
-
18
17
  static get entryPoints(): string[] {
19
18
  return RuntimeIndex.find({
20
19
  module: module => module.production,
21
20
  folder: folder => folder === 'support',
22
21
  file: file => file.sourceFile.includes('entry.')
23
- })
24
- .map(file => file.import.replace(/[.][^.]+s$/, ''));
22
+ }).map(file => file.import.replace(/[.][^.]+s$/, ''));
25
23
  }
26
24
 
27
25
  /** Workspace for building */
28
26
  @CliFlag({ short: 'b', full: 'buildDir' })
29
- buildDirectory: string = path.resolve(os.tmpdir(), Runtime.mainSourcePath.replace(/[\/\\: ]/g, '_'));
27
+ buildDirectory: string = path.resolve(os.tmpdir(), Runtime.mainSourcePath.replace(/[/\\: ]/g, '_'));
30
28
 
31
29
  /** Clean workspace */
32
30
  clean = true;
@@ -105,14 +103,14 @@ export abstract class BasePackCommand implements CliCommandShape {
105
103
  PackOperation.copyMonoRepoResources,
106
104
  PackOperation.copyResources,
107
105
  PackOperation.writeManifest,
108
- PackOperation.bundle,
106
+ PackOperation.bundle
109
107
  ];
110
108
  }
111
109
 
112
110
  /**
113
111
  * Run all operations
114
112
  */
115
- async * runOperations(): AsyncIterable<string> {
113
+ async *runOperations(): AsyncIterable<string> {
116
114
  for (const operation of this.getOperations()) {
117
115
  for await (const message of operation(this)) {
118
116
  yield message.join(' ');
@@ -121,15 +119,14 @@ export abstract class BasePackCommand implements CliCommandShape {
121
119
  }
122
120
 
123
121
  /**
124
- * Get all binary dependencies
122
+ * Get all external dependencies
125
123
  */
126
- getBinaryDependencies(): string[] {
124
+ getModuleExternalDependencies(): string[] {
127
125
  return [...RuntimeIndex.getModuleList('all')]
128
126
  .map(name => RuntimeIndex.getModule(name))
129
127
  .filter((module): module is IndexedModule => !!module?.production)
130
128
  .map(module => PackageUtil.readPackage(module?.sourcePath))
131
- .map(pkg => pkg?.travetto?.build?.binaryDependencies ?? [])
132
- .flat();
129
+ .flatMap(pkg => pkg?.travetto?.build?.externalDependencies ?? []);
133
130
  }
134
131
 
135
132
  @Method()
@@ -141,13 +138,13 @@ export abstract class BasePackCommand implements CliCommandShape {
141
138
 
142
139
  // Update entry points
143
140
  const parsed = CliParseUtil.getState(this);
144
- this.entryArguments = [...this.entryArguments ?? [], ...args, ...parsed?.unknown ?? []];
141
+ this.entryArguments = [...(this.entryArguments ?? []), ...args, ...(parsed?.unknown ?? [])];
145
142
  this.module ||= Runtime.main.name;
146
143
  this.mainName ??= path.basename(this.module);
147
144
  this.mainFile = `${this.mainName}.js`;
148
145
 
149
- // Collect binary dependencies
150
- const dependencies = this.getBinaryDependencies();
146
+ // Collect unmanaged dependencies
147
+ const dependencies = this.getModuleExternalDependencies();
151
148
  this.externalDependencies = [...this.externalDependencies, ...dependencies];
152
149
 
153
150
  const stream = this.runOperations();
@@ -168,4 +165,4 @@ export abstract class BasePackCommand implements CliCommandShape {
168
165
  await term.writer.writeLine(message).commit();
169
166
  }
170
167
  }
171
- }
168
+ }
@@ -1,4 +1,4 @@
1
- import type { DockerPackFactory } from '../src/types.ts';
2
1
  import { PackConfigUtil } from '../src/config-util.ts';
2
+ import type { DockerPackFactory } from '../src/types.ts';
3
3
 
4
- export const factory: DockerPackFactory = config => PackConfigUtil.dockerStandardFile(config);
4
+ export const factory: DockerPackFactory = config => PackConfigUtil.dockerStandardFile(config);