@travetto/pack 8.0.0-alpha.0 → 8.0.0-alpha.2

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
@@ -97,7 +97,7 @@ Usage: pack:zip [options] [args...:string]
97
97
  Options:
98
98
  -b, --buildDir <string> Workspace for building (default: "/tmp/<temp-folder>")
99
99
  --clean, --no-clean Clean workspace (default: true)
100
- -o, --output <string> Output location (default: "travetto_pack.zip")
100
+ -o, --output <string> Output location (default: "<module>.zip")
101
101
  --main-scripts, --no-main-scripts Create entry scripts (default: true)
102
102
  -f, --main-name <string> Main name for build artifact
103
103
  -e, --entry-point <string> Entry point (default: "@travetto/cli/support/entry.trv.ts")
@@ -139,9 +139,10 @@ 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
- -dn, --docker-name <string> Docker Image Name (default: "travetto_pack")
145
+ -dn, --docker-name <string> Docker Image Name (default: "<module>")
145
146
  -ru, --runtime-user <string> Docker Runtime user
146
147
  -rp, --runtime-package <string> Docker Runtime Packages (default: [])
147
148
  -dp, --docker-port <number> Docker Image Port (default: [])
@@ -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
 
@@ -273,6 +273,6 @@ echo "ENTRYPOINT [\"/app/todo-app.sh\"]" >> $DIST/Dockerfile
273
273
  echo "Building Docker Container latest"
274
274
 
275
275
  cd $DIST
276
- docker build -t travetto_todo-app:latest .
276
+ docker build -t <module>:latest .
277
277
  cd $ROOT
278
278
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/pack",
3
- "version": "8.0.0-alpha.0",
3
+ "version": "8.0.0-alpha.2",
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": "^8.0.0-alpha.0",
34
- "@travetto/terminal": "^8.0.0-alpha.0",
33
+ "@travetto/runtime": "^8.0.0-alpha.1",
34
+ "@travetto/terminal": "^8.0.0-alpha.1",
35
35
  "rollup": "^4.59.0"
36
36
  },
37
37
  "peerDependencies": {
38
- "@travetto/cli": "^8.0.0-alpha.0"
38
+ "@travetto/cli": "^8.0.0-alpha.2"
39
39
  },
40
40
  "peerDependenciesMeta": {
41
41
  "@travetto/cli": {
@@ -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,19 +1,21 @@
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';
9
9
  import type { DockerPackConfig } from '../src/types.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
14
 
13
15
  /**
14
16
  * Standard docker support for pack
15
17
  */
16
- @CliCommand({ with: { module: true } })
18
+ @CliCommand()
17
19
  export class PackDockerCommand extends BasePackCommand {
18
20
  /** Docker Factory source */
19
21
  @CliFlag({ short: 'df', envVars: ['PACK_DOCKER_FACTORY'] })
@@ -33,6 +35,7 @@ export class PackDockerCommand extends BasePackCommand {
33
35
  dockerRuntimePackages: string[] = [];
34
36
  /** Docker Image Port */
35
37
  @CliFlag({ short: 'dp', envVars: ['PACK_DOCKER_PORT'] })
38
+ @Min(1) @Max(65536)
36
39
  dockerPort: number[] = [];
37
40
 
38
41
  // Publish flags
@@ -64,36 +67,26 @@ export class PackDockerCommand extends BasePackCommand {
64
67
  @Ignore()
65
68
  defaultUserId = 2000;
66
69
 
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
- }
70
+ finalize(forHelp?: boolean): void {
71
+ if (forHelp) {
72
+ this.dockerName = '<module>';
77
73
  }
78
- return errs;
79
- }
80
74
 
81
- preMain(): void {
82
75
  if (this.dockerFactory.startsWith('.')) {
83
76
  this.dockerFactory = RuntimeIndex.getFromSource(path.resolve(this.dockerFactory))?.import ?? this.dockerFactory;
84
77
  }
85
- this.dockerName ??= CliUtil.getSimpleModuleName('<module>', this.module || undefined);
78
+ this.dockerName ??= CliUtil.getSimpleModuleName('<module>', this.module);
86
79
 
87
80
  // Finalize user/group and ids
88
81
  const [userOrUserId, groupOrGroupId = userOrUserId] = (this.dockerRuntimeUser ?? '').split(':');
89
- const groupIsNumber = /^\d+$/.test(groupOrGroupId);
90
- const userIsNumber = /^\d+$/.test(userOrUserId);
91
-
92
- const userId = userIsNumber ? +userOrUserId : this.defaultUserId;
93
- const groupId = groupIsNumber ? +groupOrGroupId : this.defaultUserId;
94
- const group = (!groupIsNumber ? groupOrGroupId : undefined) || this.defaultUser;
95
- const user = (!userIsNumber ? userOrUserId : undefined) || this.defaultUser;
96
- this.dockerRuntime = { user, userId, group, groupId, folder: `/${this.appFolder}`, packages: this.dockerRuntimePackages };
82
+ this.dockerRuntime = {
83
+ user: asString(userOrUserId) ?? this.defaultUser,
84
+ userId: asNumber(userOrUserId) ?? this.defaultUserId,
85
+ group: asString(groupOrGroupId) ?? this.defaultUser,
86
+ groupId: asNumber(groupOrGroupId) ?? this.defaultUserId,
87
+ folder: `/${this.appFolder}`,
88
+ packages: this.dockerRuntimePackages
89
+ };
97
90
 
98
91
  if (this.dockerStageOnly) {
99
92
  if (this.dockerRegistry) {
@@ -111,10 +104,6 @@ export class PackDockerCommand extends BasePackCommand {
111
104
  }
112
105
  }
113
106
 
114
- preHelp(): void {
115
- this.dockerName = CliUtil.getSimpleModuleName('<module>');
116
- }
117
-
118
107
  getOperations(): PackOperationShape<this>[] {
119
108
  return [
120
109
  ...super.getOperations(),
@@ -6,17 +6,16 @@ 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 {
12
+ finalize(forHelp?: boolean): void {
13
+ if (forHelp) {
14
+ this.output = '<module>.zip';
15
+ }
13
16
  this.output ??= CliUtil.getSimpleModuleName('<module>.zip', this.module);
14
17
  }
15
18
 
16
- preHelp(): void {
17
- this.output = CliUtil.getSimpleModuleName('<module>.zip');
18
- }
19
-
20
19
  getOperations(): PackOperationShape<this>[] {
21
20
  return [
22
21
  ...super.getOperations(),
@@ -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,7 +141,8 @@ 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`;