@travetto/pack 3.4.7 → 3.4.8

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
@@ -235,9 +235,9 @@ echo "Generating Docker File $DIST/Dockerfile @travetto/pack/support/pack.docker
235
235
  echo "FROM node:20-alpine" > $DIST/Dockerfile
236
236
  echo "RUN which useradd && (groupadd --gid 2000 app && useradd -u 2000 -g app app) || (addgroup -g 2000 app && adduser -D -G app -u 2000 app)" >> $DIST/Dockerfile
237
237
  echo "RUN mkdir /app && chown app:app /app" >> $DIST/Dockerfile
238
+ echo "COPY --chown=\"app:app\" . /app" >> $DIST/Dockerfile
238
239
  echo "USER app" >> $DIST/Dockerfile
239
240
  echo "WORKDIR /app" >> $DIST/Dockerfile
240
- echo "COPY --chown=\"app:app\" . ." >> $DIST/Dockerfile
241
241
  echo "ENTRYPOINT [\"/app/todo-app.sh\"]" >> $DIST/Dockerfile
242
242
 
243
243
  # Pulling Docker Base Image node:20-alpine
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/pack",
3
- "version": "3.4.7",
3
+ "version": "3.4.8",
4
4
  "description": "Code packing utilities",
5
5
  "keywords": [
6
6
  "travetto",
@@ -32,7 +32,7 @@
32
32
  "rollup": "^4.5.0"
33
33
  },
34
34
  "peerDependencies": {
35
- "@travetto/cli": "^3.4.5"
35
+ "@travetto/cli": "^3.4.6"
36
36
  },
37
37
  "peerDependenciesMeta": {
38
38
  "@travetto/cli": {
@@ -8,12 +8,16 @@ const escape = (text: string): string =>
8
8
  .replaceAll('"', '\\"')
9
9
  .replaceAll('$', '\\$');
10
10
 
11
+ const escapedArgs = (args: string[]): string[] => args.map(x =>
12
+ x.includes(' ') || x.includes('"') ? `'${x}'` : (x.includes("'") ? `"${x}"` : x)
13
+ );
14
+
11
15
  export const ShellCommands: Record<'win32' | 'posix', ShellCommandImpl> = {
12
16
  win32: {
13
17
  var: (name: string) => `%${name}%`,
14
18
  scriptOpen: () => [],
15
19
  chdirScript: () => ['cd', '%~p0'],
16
- callCommandWithAllArgs: (cmd, ...args) => [cmd, ...args, '%*'],
20
+ callCommandWithAllArgs: (cmd, ...args) => [cmd, ...escapedArgs(args), '%*'],
17
21
  createFile: (file, text) => [
18
22
  ['@echo', 'off'],
19
23
  ...text.map((line, i) =>
@@ -34,7 +38,7 @@ export const ShellCommands: Record<'win32' | 'posix', ShellCommandImpl> = {
34
38
  var: (name: string) => `$${name}`,
35
39
  scriptOpen: () => ['#!/bin/sh'],
36
40
  chdirScript: () => ['cd', '$(dirname "$0")'],
37
- callCommandWithAllArgs: (cmd, ...args) => [cmd, ...args, '$@'],
41
+ callCommandWithAllArgs: (cmd, ...args) => [cmd, ...escapedArgs(args), '$@'],
38
42
  createFile: (file, text, mode) => [
39
43
  ...text.map((line, i) =>
40
44
  ['echo', `"${escape(line)}"`, i === 0 ? '>' : '>>', file]),
@@ -1,7 +1,7 @@
1
1
  import { path, RootIndex } from '@travetto/manifest';
2
2
  import { CliCommand, CliFlag, CliUtil, CliValidationError } from '@travetto/cli';
3
3
  import { GlobalEnv } from '@travetto/base';
4
- import { Ignore } from '@travetto/schema';
4
+ import { Ignore, Required } from '@travetto/schema';
5
5
 
6
6
  import { DockerPackOperation } from './bin/docker-operation';
7
7
  import { BasePackCommand, PackOperationShape } from './pack.base';
@@ -20,7 +20,8 @@ export class PackDockerCommand extends BasePackCommand {
20
20
  @CliFlag({ desc: 'Docker Image to extend ', short: 'di', envVars: ['PACK_DOCKER_IMAGE'] })
21
21
  dockerImage = `node:${GlobalEnv.nodeVersion}-alpine`;
22
22
  @CliFlag({ desc: 'Docker Image Name ', short: 'dn', envVars: ['PACK_DOCKER_IMAGE'] })
23
- dockerName = CliUtil.monoRoot ? '<module>' : CliUtil.getSimpleModuleName();
23
+ @Required(false)
24
+ dockerName: string;
24
25
  @CliFlag({ desc: 'Docker Image Tag ', short: 'dt', envVars: ['PACK_DOCKER_TAGS'] })
25
26
  dockerTag: string[] = ['latest'];
26
27
  @CliFlag({ desc: 'Docker Image Port ', short: 'dp', envVars: ['PACK_DOCKER_PORT'] })
@@ -37,7 +38,7 @@ export class PackDockerCommand extends BasePackCommand {
37
38
  @Ignore()
38
39
  dockerRuntime: DockerPackConfig['dockerRuntime'];
39
40
 
40
- async validate(...unknownArgs: string[]): Promise<CliValidationError[] | undefined> {
41
+ async validate(...args: string[]): Promise<CliValidationError[] | undefined> {
41
42
  const errs: CliValidationError[] = [];
42
43
  if (this.dockerPort?.length) {
43
44
  for (let i = 0; i < this.dockerPort.length; i++) {
@@ -51,12 +52,11 @@ export class PackDockerCommand extends BasePackCommand {
51
52
  return errs;
52
53
  }
53
54
 
54
- finalize(unknownArgs: string[]): void {
55
- super.finalize(unknownArgs);
55
+ preMain(): void {
56
56
  if (this.dockerFactory.startsWith('.')) {
57
57
  this.dockerFactory = RootIndex.getFromSource(path.resolve(this.dockerFactory))?.import ?? this.dockerFactory;
58
58
  }
59
- this.dockerName = this.dockerName.replace('<module>', CliUtil.getSimpleModuleName(this.module ?? ''));
59
+ this.dockerName ??= CliUtil.getSimpleModuleName('<module>', this.module || undefined);
60
60
 
61
61
  // Finalize user/group and ids
62
62
  const [userOrUid, groupOrGid = userOrUid] = (this.dockerRuntimeUserSrc ?? '').split(':');
@@ -70,6 +70,10 @@ export class PackDockerCommand extends BasePackCommand {
70
70
  this.dockerRuntime = { user, uid, group, gid, folder: `/${DEFAULT_USER}` };
71
71
  }
72
72
 
73
+ preHelp(): void {
74
+ this.dockerName = CliUtil.getSimpleModuleName('<module>');
75
+ }
76
+
73
77
  getOperations(): PackOperationShape<this>[] {
74
78
  return [
75
79
  ...super.getOperations(),
@@ -9,8 +9,12 @@ import { BasePackCommand, PackOperationShape } from './pack.base';
9
9
  @CliCommand({ addModule: true })
10
10
  export class PackZipCommand extends BasePackCommand {
11
11
 
12
- initialize(): void {
13
- this.output = CliUtil.monoRoot ? '<module>.zip' : `${CliUtil.getSimpleModuleName()}.zip`;
12
+ preMain(): void {
13
+ this.output ??= CliUtil.getSimpleModuleName('<module>.zip', this.module);
14
+ }
15
+
16
+ preHelp(): void {
17
+ this.output = CliUtil.getSimpleModuleName('<module>.zip');
14
18
  }
15
19
 
16
20
  getOperations(): PackOperationShape<this>[] {
@@ -1,6 +1,6 @@
1
1
  import os from 'os';
2
2
 
3
- import { CliCommandShape, CliFlag, cliTpl, CliUtil } from '@travetto/cli';
3
+ import { CliCommandShape, CliFlag, CliParseUtil, cliTpl } from '@travetto/cli';
4
4
  import { path, RootIndex } from '@travetto/manifest';
5
5
  import { TimeUtil } from '@travetto/base';
6
6
  import { GlobalTerminal } from '@travetto/terminal';
@@ -23,8 +23,6 @@ export abstract class BasePackCommand implements CliCommandShape {
23
23
  .map(x => x.import.replace(/[.][^.]+s$/, ''));
24
24
  }
25
25
 
26
- #unknownArgs?: string[];
27
-
28
26
  @CliFlag({ desc: 'Workspace for building', short: 'w' })
29
27
  workspace: string = path.resolve(os.tmpdir(), RootIndex.mainModule.sourcePath.replace(/[\/\\: ]/g, '_'));
30
28
 
@@ -91,23 +89,14 @@ export abstract class BasePackCommand implements CliCommandShape {
91
89
  }
92
90
  }
93
91
 
94
- finalize(unknown: string[]): void {
95
- this.#unknownArgs = unknown;
96
-
97
- this.output = this.output?.replace('<module>', CliUtil.getSimpleModuleName(this.module ?? ''));
98
-
92
+ async main(args: string[] = []): Promise<void> {
99
93
  // Resolve all files to absolute paths
100
- if (this.output) {
101
- this.output = path.resolve(this.output);
102
- }
103
- if (this.ejectFile) {
104
- this.ejectFile = path.resolve(this.ejectFile);
105
- }
94
+ this.output = this.output ? path.resolve(this.output) : undefined!;
95
+ this.ejectFile = this.ejectFile ? path.resolve(this.ejectFile) : undefined;
106
96
  this.workspace = path.resolve(this.workspace);
107
- }
108
97
 
109
- async main(args: string[] = []): Promise<void> {
110
- this.entryArguments = [...args, ...this.#unknownArgs ?? []];
98
+ // Update entry points
99
+ this.entryArguments = [...this.entryArguments ?? [], ...args, ...CliParseUtil.getState(this)?.unknown ?? []];
111
100
  this.module ||= RootIndex.mainModuleName;
112
101
  this.mainName ??= path.basename(this.module);
113
102