@travetto/pack 7.1.4 → 8.0.0-alpha.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/README.md CHANGED
@@ -139,6 +139,7 @@ Options:
139
139
  --manifest-file <string> Manifest File Name (default: "manifest.json")
140
140
  -wr, --include-workspace-resources Include workspace resources (default: false)
141
141
  -np, --npm-package <string> External NPM Packages (default: [])
142
+ -m, --module <module> Module to run for
142
143
  -df, --docker-factory <string> Docker Factory source (default: "@travetto/pack/support/pack.dockerfile.ts")
143
144
  -di, --docker-image <string> Docker Image to extend (default: "node:25-alpine")
144
145
  -dn, --docker-name <string> Docker Image Name (default: "travetto_pack")
@@ -150,7 +151,6 @@ Options:
150
151
  -dx, --docker-push Docker Push Tags (default: false)
151
152
  -db, --docker-build-platform <string> Docker Build Platform
152
153
  -dr, --docker-registry <string> Docker Registry
153
- -m, --module <module> Module to run for
154
154
  -h, --help display help for command
155
155
  ```
156
156
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/pack",
3
- "version": "7.1.4",
3
+ "version": "8.0.0-alpha.1",
4
4
  "type": "module",
5
5
  "description": "Code packing utilities",
6
6
  "keywords": [
@@ -26,16 +26,16 @@
26
26
  "directory": "module/pack"
27
27
  },
28
28
  "dependencies": {
29
- "@rollup/plugin-commonjs": "^29.0.0",
29
+ "@rollup/plugin-commonjs": "^29.0.2",
30
30
  "@rollup/plugin-json": "^6.1.0",
31
31
  "@rollup/plugin-node-resolve": "^16.0.3",
32
32
  "@rollup/plugin-terser": "^0.4.4",
33
- "@travetto/runtime": "^7.1.4",
34
- "@travetto/terminal": "^7.1.4",
35
- "rollup": "^4.55.1"
33
+ "@travetto/runtime": "^8.0.0-alpha.1",
34
+ "@travetto/terminal": "^8.0.0-alpha.1",
35
+ "rollup": "^4.59.0"
36
36
  },
37
37
  "peerDependencies": {
38
- "@travetto/cli": "^7.1.4"
38
+ "@travetto/cli": "^8.0.0-alpha.1"
39
39
  },
40
40
  "peerDependenciesMeta": {
41
41
  "@travetto/cli": {
@@ -82,7 +82,7 @@ export class DockerPackOperation {
82
82
  yield ActiveShellCommand.chdir(path.resolve());
83
83
  } else {
84
84
  await PackUtil.runCommand(cmd, { cwd: config.buildDirectory, stdio: [0, 'pipe', 2] });
85
- const [image]: [{ Size: number }] = JSONUtil.parseSafe(await PackUtil.runCommand(['docker', 'inspect', config.dockerImage]));
85
+ const [image] = await PackUtil.runCommand(['docker', 'inspect', config.dockerImage]).then(JSONUtil.fromUTF8<[{ Size: number }]>);
86
86
  yield [cliTpl`${{ title: 'Built Docker Container ' }} ${{ identifier: 'sizeMb' }}=${{ param: Math.trunc(image.Size / 2 ** 20) }}`];
87
87
  }
88
88
  }
@@ -2,7 +2,7 @@ import fs from 'node:fs/promises';
2
2
  import path from 'node:path';
3
3
 
4
4
  import { cliTpl } from '@travetto/cli';
5
- import { Env, Runtime, RuntimeIndex } from '@travetto/runtime';
5
+ import { JSONUtil, Env, Runtime, RuntimeIndex } from '@travetto/runtime';
6
6
 
7
7
  import type { CommonPackConfig } from '../../src/types.ts';
8
8
  import { PackUtil } from './util.ts';
@@ -107,12 +107,12 @@ export class PackOperation {
107
107
  if (config.ejectFile) {
108
108
  yield* ActiveShellCommand.createFile(
109
109
  path.resolve(config.buildDirectory, file),
110
- [JSON.stringify(pkg)]
110
+ [JSONUtil.toUTF8(pkg)]
111
111
  );
112
112
  } else {
113
113
  await PackUtil.writeRawFile(
114
114
  path.resolve(config.buildDirectory, file),
115
- [JSON.stringify(pkg, null, 2)]
115
+ [JSONUtil.toUTF8Pretty(pkg)]
116
116
  );
117
117
  }
118
118
  }
@@ -245,7 +245,7 @@ export class PackOperation {
245
245
  yield* PackOperation.title(config, cliTpl`${{ title: 'Compressing' }} ${{ path: config.output }}`);
246
246
 
247
247
  if (config.ejectFile) {
248
- await ActiveShellCommand.mkdir(path.dirname(config.output));
248
+ yield ActiveShellCommand.mkdir(path.dirname(config.output));
249
249
  yield ActiveShellCommand.chdir(config.buildDirectory);
250
250
  yield ActiveShellCommand.zip(config.output);
251
251
  yield ActiveShellCommand.chdir(path.resolve());
@@ -2,7 +2,7 @@ import fs from 'node:fs/promises';
2
2
  import { spawn, type SpawnOptions } from 'node:child_process';
3
3
  import path from 'node:path';
4
4
 
5
- import { AppError, ExecUtil, Runtime, RuntimeIndex } from '@travetto/runtime';
5
+ import { RuntimeError, ExecUtil, Runtime, RuntimeIndex } from '@travetto/runtime';
6
6
 
7
7
  import { ActiveShellCommand } from './shell.ts';
8
8
 
@@ -82,7 +82,7 @@ export class PackUtil {
82
82
 
83
83
  if (!valid) {
84
84
  process.exitCode = code;
85
- throw new AppError(stderr || message || 'An unexpected error has occurred');
85
+ throw new RuntimeError(stderr || message || 'An unexpected error has occurred');
86
86
  }
87
87
  return stdout;
88
88
  }
@@ -5,5 +5,5 @@ import { BasePackCommand } from './pack.base';
5
5
  /**
6
6
  * Standard pack support
7
7
  */
8
- @CliCommand({ with: { module: true } })
8
+ @CliCommand()
9
9
  export class PackCommand extends BasePackCommand { }
@@ -1,8 +1,8 @@
1
1
  import path from 'node:path';
2
2
 
3
3
  import { RuntimeIndex } from '@travetto/runtime';
4
- import { CliCommand, CliFlag, CliUtil, type CliValidationError } from '@travetto/cli';
5
- import { Ignore, Required } from '@travetto/schema';
4
+ import { CliCommand, CliFlag, CliUtil } from '@travetto/cli';
5
+ import { Ignore, Max, Min, Required } from '@travetto/schema';
6
6
 
7
7
  import { DockerPackOperation } from './bin/docker-operation.ts';
8
8
  import { BasePackCommand, type PackOperationShape } from './pack.base';
@@ -13,7 +13,7 @@ const NODE_MAJOR = process.version.match(/\d+/)?.[0] ?? '22';
13
13
  /**
14
14
  * Standard docker support for pack
15
15
  */
16
- @CliCommand({ with: { module: true } })
16
+ @CliCommand()
17
17
  export class PackDockerCommand extends BasePackCommand {
18
18
  /** Docker Factory source */
19
19
  @CliFlag({ short: 'df', envVars: ['PACK_DOCKER_FACTORY'] })
@@ -33,6 +33,7 @@ export class PackDockerCommand extends BasePackCommand {
33
33
  dockerRuntimePackages: string[] = [];
34
34
  /** Docker Image Port */
35
35
  @CliFlag({ short: 'dp', envVars: ['PACK_DOCKER_PORT'] })
36
+ @Min(1) @Max(65536)
36
37
  dockerPort: number[] = [];
37
38
 
38
39
  // Publish flags
@@ -64,25 +65,16 @@ export class PackDockerCommand extends BasePackCommand {
64
65
  @Ignore()
65
66
  defaultUserId = 2000;
66
67
 
67
- async validate(): Promise<CliValidationError[] | undefined> {
68
- const errs: CliValidationError[] = [];
69
- if (this.dockerPort?.length) {
70
- for (let i = 0; i < this.dockerPort.length; i++) {
71
- if (this.dockerPort[i] < 1) {
72
- errs.push({ source: 'flag', message: `dockerPort[${i}] is less than (1)` });
73
- } else if (this.dockerPort[i] > 65536) {
74
- errs.push({ source: 'flag', message: `dockerPort[${i}] is greater than (65536)` });
75
- }
76
- }
77
- }
78
- return errs;
79
- }
80
-
81
- preMain(): void {
68
+ finalize(forHelp?: boolean): void {
82
69
  if (this.dockerFactory.startsWith('.')) {
83
70
  this.dockerFactory = RuntimeIndex.getFromSource(path.resolve(this.dockerFactory))?.import ?? this.dockerFactory;
84
71
  }
85
- this.dockerName ??= CliUtil.getSimpleModuleName('<module>', this.module || undefined);
72
+
73
+ if (forHelp) {
74
+ this.dockerName = CliUtil.getSimpleModuleName('<module>');
75
+ } else {
76
+ this.dockerName ??= CliUtil.getSimpleModuleName('<module>', this.module || undefined);
77
+ }
86
78
 
87
79
  // Finalize user/group and ids
88
80
  const [userOrUserId, groupOrGroupId = userOrUserId] = (this.dockerRuntimeUser ?? '').split(':');
@@ -111,10 +103,6 @@ export class PackDockerCommand extends BasePackCommand {
111
103
  }
112
104
  }
113
105
 
114
- preHelp(): void {
115
- this.dockerName = CliUtil.getSimpleModuleName('<module>');
116
- }
117
-
118
106
  getOperations(): PackOperationShape<this>[] {
119
107
  return [
120
108
  ...super.getOperations(),
@@ -6,15 +6,15 @@ import { BasePackCommand, type PackOperationShape } from './pack.base';
6
6
  /**
7
7
  * Standard zip support for pack
8
8
  */
9
- @CliCommand({ with: { module: true } })
9
+ @CliCommand()
10
10
  export class PackZipCommand extends BasePackCommand {
11
11
 
12
- preMain(): void {
13
- this.output ??= CliUtil.getSimpleModuleName('<module>.zip', this.module);
14
- }
15
-
16
- preHelp(): void {
17
- this.output = CliUtil.getSimpleModuleName('<module>.zip');
12
+ finalize(forHelp?: boolean): void {
13
+ if (forHelp) {
14
+ this.output = CliUtil.getSimpleModuleName('<module>.zip');
15
+ } else {
16
+ this.output ??= CliUtil.getSimpleModuleName('<module>.zip', this.module);
17
+ }
18
18
  }
19
19
 
20
20
  getOperations(): PackOperationShape<this>[] {
@@ -1,7 +1,7 @@
1
1
  import os from 'node:os';
2
2
  import path from 'node:path';
3
3
 
4
- import { type CliCommandShape, CliFlag, type ParsedState, cliTpl } from '@travetto/cli';
4
+ import { type CliCommandShape, CliFlag, CliModuleFlag, CliParseUtil, cliTpl } from '@travetto/cli';
5
5
  import { TimeUtil, Runtime, RuntimeIndex } from '@travetto/runtime';
6
6
  import { Terminal } from '@travetto/terminal';
7
7
  import { Ignore, Method, Required, Schema } from '@travetto/schema';
@@ -24,9 +24,6 @@ export abstract class BasePackCommand implements CliCommandShape {
24
24
  .map(file => file.import.replace(/[.][^.]+s$/, ''));
25
25
  }
26
26
 
27
- @Ignore()
28
- _parsed: ParsedState;
29
-
30
27
  /** Workspace for building */
31
28
  @CliFlag({ short: 'b', full: 'buildDir' })
32
29
  buildDirectory: string = path.resolve(os.tmpdir(), Runtime.mainSourcePath.replace(/[\/\\: ]/g, '_'));
@@ -86,7 +83,7 @@ export abstract class BasePackCommand implements CliCommandShape {
86
83
  @CliFlag({ short: 'np', full: 'npm-package', envVars: ['PACK_EXTERNAL_PACKAGES'] })
87
84
  externalDependencies: string[] = [];
88
85
 
89
- @Ignore()
86
+ @CliModuleFlag({ short: 'm' })
90
87
  module: string;
91
88
 
92
89
  @Ignore()
@@ -144,13 +141,14 @@ export abstract class BasePackCommand implements CliCommandShape {
144
141
  this.buildDirectory = path.resolve(this.buildDirectory);
145
142
 
146
143
  // Update entry points
147
- this.entryArguments = [...this.entryArguments ?? [], ...args, ...this._parsed.unknown];
144
+ const parsed = CliParseUtil.getState(this);
145
+ this.entryArguments = [...this.entryArguments ?? [], ...args, ...parsed?.unknown ?? []];
148
146
  this.module ||= Runtime.main.name;
149
147
  this.mainName ??= path.basename(this.module);
150
148
  this.mainFile = `${this.mainName}.js`;
151
149
 
152
150
  // Collect binary dependencies
153
- const dependencies = await this.getBinaryDependencies();
151
+ const dependencies = this.getBinaryDependencies();
154
152
  this.externalDependencies = [...this.externalDependencies, ...dependencies];
155
153
 
156
154
  const stream = this.runOperations();
@@ -3,12 +3,12 @@ import fs from 'node:fs/promises';
3
3
 
4
4
  import type { LoadResult, Plugin, PluginContext, SourceMapInput } from 'rollup';
5
5
 
6
- import { FileLoader } from '@travetto/runtime';
6
+ import { JSONUtil, FileLoader } from '@travetto/runtime';
7
7
 
8
8
  import type { CoreRollupConfig } from '../../src/types.ts';
9
9
 
10
10
  function toString(error: unknown): string {
11
- return error instanceof Error ? error.stack ?? error.toString() : JSON.stringify(error);
11
+ return error instanceof Error ? error.stack ?? error.toString() : JSONUtil.toUTF8(error);
12
12
  }
13
13
  // Pulled from https://github.com/Azure/azure-sdk-for-js/blob/main/common/tools/dev-tool/src/config/rollup.base.config.ts#L128
14
14
  export function travettoSourcemaps(config: CoreRollupConfig): Plugin {
@@ -30,7 +30,8 @@ export function travettoSourcemaps(config: CoreRollupConfig): Plugin {
30
30
  return null;
31
31
  }
32
32
  const loader = new FileLoader([path.dirname(id)]);
33
- const map: SourceMapInput = await loader.readJSON(mapPath);
33
+ const map = await loader.readText(mapPath)
34
+ .then(JSONUtil.fromBase64<SourceMapInput>);
34
35
  return { code, map };
35
36
  }
36
37
  return { code, map: null };