@travetto/pack 2.2.2 → 3.0.0-rc.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.
package/README.md CHANGED
@@ -22,8 +22,8 @@ Options:
22
22
 
23
23
  Available Pack Modes:
24
24
  * default [support/pack.config.ts]
25
- * rest/aws-lambda [@travetto/rest/support/pack.aws-lambda.ts]
26
25
  * rest/docker [@travetto/rest/support/pack.docker.ts]
26
+ * rest-aws-lambda/main [@travetto/rest-aws-lambda/support/pack.aws-lambda.ts]
27
27
  ```
28
28
 
29
29
  This command line operation will compile your project, and produce a ready to use workspace as a deliverable. The pack operation is actually a wrapper around multiple sub-operations that are run in series to produce the desired final structure for deployment. The currently support operations are:
@@ -96,8 +96,8 @@ Options:
96
96
 
97
97
  Available Pack Modes:
98
98
  * default [support/pack.config.ts]
99
- * rest/aws-lambda [@travetto/rest/support/pack.aws-lambda.ts]
100
99
  * rest/docker [@travetto/rest/support/pack.docker.ts]
100
+ * rest-aws-lambda/main [@travetto/rest-aws-lambda/support/pack.aws-lambda.ts]
101
101
  ```
102
102
 
103
103
  ### CLI - pack:zip
@@ -125,8 +125,8 @@ Options:
125
125
 
126
126
  Available Pack Modes:
127
127
  * default [support/pack.config.ts]
128
- * rest/aws-lambda [@travetto/rest/support/pack.aws-lambda.ts]
129
128
  * rest/docker [@travetto/rest/support/pack.docker.ts]
129
+ * rest-aws-lambda/main [@travetto/rest-aws-lambda/support/pack.aws-lambda.ts]
130
130
  ```
131
131
 
132
132
  ### CLI - pack:docker
@@ -159,8 +159,8 @@ Options:
159
159
 
160
160
  Available Pack Modes:
161
161
  * default [support/pack.config.ts]
162
- * rest/aws-lambda [@travetto/rest/support/pack.aws-lambda.ts]
163
162
  * rest/docker [@travetto/rest/support/pack.docker.ts]
163
+ * rest-aws-lambda/main [@travetto/rest-aws-lambda/support/pack.aws-lambda.ts]
164
164
  ```
165
165
 
166
166
  ### Modes
@@ -174,7 +174,7 @@ import { PathUtil } from '@travetto/boot';
174
174
  import type { AllConfigPartial } from '@travetto/pack';
175
175
 
176
176
  export const config: AllConfigPartial = {
177
- name: 'rest/aws-lambda',
177
+ name: 'rest-aws-lambda/main',
178
178
  assemble: {
179
179
  active: true,
180
180
  keepSource: false,
package/bin/cli-pack.ts CHANGED
@@ -1,10 +1,10 @@
1
- import { BaseOptions, BasePackPlugin } from './pack-base';
1
+ import { BaseOptions, BasePackCommand } from './pack-base';
2
2
  import { Pack, AllConfig } from './operation/pack';
3
3
 
4
- export class PackPlugin extends BasePackPlugin<BaseOptions, AllConfig> {
4
+ export class PackCommand extends BasePackCommand<BaseOptions, AllConfig> {
5
5
  operation = Pack;
6
6
 
7
7
  getOptions(): BaseOptions {
8
- return this.defaultOptions();
8
+ return this.commonOptions();
9
9
  }
10
10
  }
@@ -1,6 +1,6 @@
1
- import { OptionConfig } from '@travetto/cli/src/plugin-base';
1
+ import { OptionConfig } from '@travetto/cli/src/command';
2
2
 
3
- import { BaseOptions, BasePackPlugin } from './pack-base';
3
+ import { BaseOptions, BasePackCommand } from './pack-base';
4
4
  import { Assemble, AssembleConfig } from './operation/assemble';
5
5
 
6
6
  type Options = BaseOptions & {
@@ -8,12 +8,12 @@ type Options = BaseOptions & {
8
8
  readonly: OptionConfig<boolean>;
9
9
  };
10
10
 
11
- export class PackAssemblePlugin extends BasePackPlugin<Options, AssembleConfig> {
11
+ export class PackAssembleCommand extends BasePackCommand<Options, AssembleConfig> {
12
12
  operation = Assemble;
13
13
 
14
14
  getOptions(): Options {
15
15
  return {
16
- ...this.defaultOptions(),
16
+ ...this.commonOptions(),
17
17
  keepSource: this.boolOption({ desc: 'Should source be preserved' }),
18
18
  readonly: this.boolOption({ desc: 'Build a readonly deployable' })
19
19
  };
@@ -1,17 +1,17 @@
1
1
  import * as fs from 'fs/promises';
2
2
 
3
3
  import { FsUtil, PathUtil } from '@travetto/boot';
4
- import { BasePlugin, OptionConfig } from '@travetto/cli/src/plugin-base';
4
+ import { CliCommand, OptionConfig, ListOptionConfig } from '@travetto/cli/src/command';
5
5
 
6
6
  type Options = {
7
7
  app: OptionConfig<string>;
8
8
  image: OptionConfig<string>;
9
9
  port: OptionConfig<number>;
10
- add: OptionConfig<string[]>;
10
+ add: ListOptionConfig<string>;
11
11
  output: OptionConfig<string>;
12
12
  };
13
13
 
14
- export class PackDockerExportPlugin extends BasePlugin<Options> {
14
+ export class PackDockerExportCommand extends CliCommand<Options> {
15
15
 
16
16
  name = 'pack:docker-export';
17
17
 
@@ -1,23 +1,23 @@
1
- import { OptionConfig } from '@travetto/cli/src/plugin-base';
1
+ import { OptionConfig, ListOptionConfig } from '@travetto/cli/src/command';
2
2
 
3
- import { BaseOptions, BasePackPlugin } from './pack-base';
3
+ import { BaseOptions, BasePackCommand } from './pack-base';
4
4
  import { Docker, DockerConfig } from './operation/docker';
5
5
 
6
6
  type Options = BaseOptions & {
7
7
  image: OptionConfig<string>;
8
8
  name: OptionConfig<string>;
9
- tag: OptionConfig<string[]>;
10
- port: OptionConfig<string[]>;
9
+ tag: ListOptionConfig<string>;
10
+ port: ListOptionConfig<string>;
11
11
  push: OptionConfig<boolean>;
12
12
  registry: OptionConfig<string>;
13
13
  };
14
14
 
15
- export class PackDockerPlugin extends BasePackPlugin<Options, DockerConfig> {
15
+ export class PackDockerCommand extends BasePackCommand<Options, DockerConfig> {
16
16
  operation = Docker;
17
17
 
18
18
  getOptions(): Options {
19
19
  return {
20
- ...this.defaultOptions(),
20
+ ...this.commonOptions(),
21
21
  image: this.option({ desc: 'Docker Image to extend' }),
22
22
  name: this.option({ desc: 'Image Name' }),
23
23
  tag: this.listOption({ desc: 'Image Tag' }),
@@ -1,18 +1,18 @@
1
- import { OptionConfig } from '@travetto/cli/src/plugin-base';
1
+ import { OptionConfig } from '@travetto/cli/src/command';
2
2
 
3
- import { BaseOptions, BasePackPlugin } from './pack-base';
3
+ import { BaseOptions, BasePackCommand } from './pack-base';
4
4
  import { Zip, ZipConfig } from './operation/zip';
5
5
 
6
6
  type Options = BaseOptions & {
7
7
  output: OptionConfig<string>;
8
8
  };
9
9
 
10
- export class PackZipPlugin extends BasePackPlugin<Options, ZipConfig> {
10
+ export class PackZipCommand extends BasePackCommand<Options, ZipConfig> {
11
11
  operation = Zip;
12
12
 
13
13
  getOptions(): Options {
14
14
  return {
15
- ...this.defaultOptions(),
15
+ ...this.commonOptions(),
16
16
  output: this.option({ desc: 'Output File' })
17
17
  };
18
18
  }
@@ -18,13 +18,30 @@ export class AssembleUtil {
18
18
  */
19
19
  static async cleanCache(cache: string): Promise<void> {
20
20
  for (const el of await fs.readdir(cache)) {
21
- if (el.endsWith('.ts')) {
21
+ if (el.endsWith('.ts') || el.endsWith('.js')) {
22
22
  const content = (await fs.readFile(`${cache}/${el}`, 'utf8')).replace(/\/\/# sourceMap.*/g, '');
23
23
  await fs.writeFile(`${cache}/${el}`, content);
24
24
  }
25
25
  }
26
26
  }
27
27
 
28
+ /**
29
+ * Minimize cached source files, by removing source mapping info
30
+ */
31
+ static async cleanBoot(ws: string): Promise<void> {
32
+ for (const el of await ScanFs.scanDir({
33
+ testFile: f => f.endsWith('.js') || f.endsWith('.d.ts'),
34
+ testDir: x => true
35
+ }, `${ws}/node_modules/@travetto/boot`)) {
36
+ if (el.file.endsWith('.d.ts')) {
37
+ await fs.writeFile(el.file, '');
38
+ } else if (el.file.endsWith('.js')) {
39
+ const content = (await fs.readFile(el.file, 'utf8')).replace(/\/\/# sourceMap.*/g, '');
40
+ await fs.writeFile(el.file, content);
41
+ }
42
+ }
43
+ }
44
+
28
45
  /**
29
46
  * Truncate all app source files, and framework source files
30
47
  */
@@ -73,7 +90,7 @@ export class AssembleUtil {
73
90
  /**
74
91
  * Copy over all prod dependencies
75
92
  */
76
- static async copyDependencies(workspace: string, types: DepType[] = ['prod', 'opt', 'optPeer']): Promise<void> {
93
+ static async copyDependencies(workspace: string, types: DepType[] = ['prod', 'opt', 'peer']): Promise<void> {
77
94
 
78
95
  for (const el of await DependenciesUtil.resolveDependencies({ types })) {
79
96
  const sub = PathUtil.normalizeFrameworkPath(el.file, 'node_modules/')
@@ -3,7 +3,7 @@ import * as path from 'path';
3
3
  import { FsUtil, PathUtil } from '@travetto/boot';
4
4
 
5
5
  export type ResolvedDep = { file: string, type: DepType, dep: string, version: string };
6
- export type DepType = 'prod' | 'dev' | 'opt' | 'peer' | 'optPeer';
6
+ export type DepType = 'prod' | 'dev' | 'opt' | 'peer';
7
7
 
8
8
  type DepResolveConfig = { root?: string, types?: DepType[] | (readonly DepType[]), maxDepth?: number };
9
9
 
@@ -12,8 +12,7 @@ const DEP_MAPPING = {
12
12
  dev: 'devDependencies',
13
13
  opt: 'optionalDependencies',
14
14
  peer: 'peerDependencies',
15
- optPeer: 'optionalPeerDependencies'
16
- };
15
+ } as const;
17
16
 
18
17
  type PackageShape = {
19
18
  name: string;
@@ -77,7 +76,10 @@ export class DependenciesUtil {
77
76
  type !== 'dev' ||
78
77
  maxDepth === 0
79
78
  ) {
80
- deps.push(...Object.entries(p[DEP_MAPPING[type]] ?? {}).map(([name, version]) => [name, type, version] as const));
79
+ deps.push(...Object
80
+ .entries<Record<string, string>>(p[DEP_MAPPING[type]] ?? {})
81
+ .map(([name, version]) => [name, type, version] as const)
82
+ );
81
83
  }
82
84
  }
83
85
  for (const [dep, type, version] of deps) {
@@ -90,7 +92,7 @@ export class DependenciesUtil {
90
92
  pending.push([resolved, depth + 1]);
91
93
  }
92
94
  } catch {
93
- if (!dep.startsWith('@types') && type !== 'opt' && type !== 'optPeer') {
95
+ if (!dep.startsWith('@types') && type !== 'opt' && type !== 'peer') {
94
96
  console.error('Unable to resolve', { type, dependency: dep });
95
97
  }
96
98
  }
package/bin/lib/types.ts CHANGED
@@ -7,11 +7,13 @@ export type CommonConfig = {
7
7
  preProcess?: { [key: string]: (<T extends CommonConfig>(cfg: T) => Promise<void>) }[];
8
8
  };
9
9
 
10
- export type PackOperation<T extends CommonConfig> = {
11
- key: string;
10
+ export type PackOperation<T extends CommonConfig, K extends string> = {
11
+ key: K;
12
12
  title: string;
13
+ defaults?: Partial<T>;
13
14
  overrides?: Partial<T>;
14
- extend(a: T, b: Partial<T>): T;
15
+ extend?(src: Partial<T>, dest: Partial<T>): Partial<T>;
15
16
  context(cfg: T): Promise<string> | string;
16
17
  exec(cfg: T): AsyncGenerator<string>;
18
+ buildConfig(configs: Partial<T>[]): T;
17
19
  };
package/bin/lib/util.ts CHANGED
@@ -17,15 +17,32 @@ export class PackUtil {
17
17
 
18
18
  static #modes: Partial<CommonConfig>[];
19
19
 
20
- static commonExtend<T extends CommonConfig>(a: T, b: Partial<T>): T {
20
+ /**
21
+ * Build configuration object for an operation with a set of configs
22
+ */
23
+ static buildConfig<T extends CommonConfig>(
24
+ op: { defaults?: Partial<T>, overrides?: Partial<T>, extend?(src: Partial<T>, dest: Partial<T>): Partial<T> },
25
+ configs: Partial<T>[]
26
+ ): T {
27
+ const inputs = [
28
+ op.defaults! ?? {},
29
+ ...configs,
30
+ op.overrides! ?? {}
31
+ ].filter(x => Object.keys(x).length > 0);
32
+
33
+ const res = inputs.reduce((out: Partial<T>, config: Partial<T>): Partial<T> => {
34
+ const final = {
35
+ active: config.active ?? out.active,
36
+ workspace: config.workspace ?? out.workspace,
37
+ preProcess: [...(config.preProcess! ?? []), ...(out.preProcess ?? [])],
38
+ postProcess: [...(config.postProcess! ?? []), ...(out.postProcess ?? [])],
39
+ ...op.extend?.(config, out)
40
+ };
41
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
42
+ return final as Partial<T>;
43
+ }, {});
21
44
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
22
- const out = {
23
- active: b.active ?? a.active,
24
- workspace: b.workspace ?? a.workspace,
25
- preProcess: [...(b.preProcess ?? []), ...(a.preProcess ?? [])],
26
- postProcess: [...(b.postProcess ?? []), ...(a.postProcess ?? [])],
27
- } as unknown as T;
28
- return out;
45
+ return res as T;
29
46
  }
30
47
 
31
48
  /**
@@ -104,7 +121,7 @@ export class PackUtil {
104
121
  /**
105
122
  * Run operation with logging
106
123
  */
107
- static async runOperation<T extends CommonConfig>(op: PackOperation<T>, cfg: T, indent = 0): Promise<void> {
124
+ static async runOperation<T extends CommonConfig>(op: PackOperation<T, string>, cfg: T, indent = 0): Promise<void> {
108
125
  const spacer = ' '.repeat(indent);
109
126
  const ctx = await op.context(cfg);
110
127
  const title = color`${{ title: op.title }} ${ctx}`;
@@ -123,7 +140,8 @@ export class PackUtil {
123
140
  async function runPhase(phase: 'preProcess' | 'postProcess'): Promise<void> {
124
141
  for (const el of cfg[phase] ?? []) {
125
142
  const [name, fn] = Object.entries(el)[0];
126
- await stdout(name);
143
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
144
+ await stdout(name as string);
127
145
  await fn(cfg);
128
146
  }
129
147
  }
@@ -19,32 +19,34 @@ export interface AssembleConfig extends CommonConfig {
19
19
  /**
20
20
  * Utils for packing source code and minimizing space usage
21
21
  */
22
- export const Assemble: PackOperation<AssembleConfig> = {
22
+ export const Assemble: PackOperation<AssembleConfig, 'assemble'> = {
23
23
  key: 'assemble',
24
24
  title: 'Assembling',
25
25
  context(cfg: AssembleConfig) {
26
- return `[readonly=${cfg.readonly},cache=${cfg.cacheDir}]`;
26
+ return `[readonly=${cfg.readonly},cache=${cfg.cacheDir},source=${cfg.keepSource}]`;
27
27
  },
28
28
  overrides: {
29
29
  keepSource: CliUtil.toBool(process.env.PACK_ASSEMBLE_KEEP_SOURCE),
30
30
  readonly: CliUtil.toBool(process.env.PACK_ASSEMBLE_READONLY)
31
31
  },
32
- extend(a: AssembleConfig, b: Partial<AssembleConfig>) {
32
+ extend(src: Partial<AssembleConfig>, dest: Partial<AssembleConfig>): Partial<AssembleConfig> {
33
33
  return {
34
- ...PackUtil.commonExtend(a, b),
35
- keepSource: b.keepSource ?? a.keepSource,
36
- readonly: b.readonly ?? a.readonly,
37
- cacheDir: b.cacheDir ?? a.cacheDir,
38
- add: [...(b.add ?? []), ...(a.add ?? [])],
39
- exclude: [...(b.exclude ?? []), ...(a.exclude ?? [])],
40
- excludeCompile: [...(b.excludeCompile ?? []), ...(a.excludeCompile ?? [])],
41
- env: { ...(b.env ?? {}), ...(a.env ?? {}) },
34
+ keepSource: src.keepSource ?? dest.keepSource,
35
+ readonly: src.readonly ?? dest.readonly,
36
+ cacheDir: src.cacheDir ?? dest.cacheDir,
37
+ add: [...(src.add ?? []), ...(dest.add ?? [])],
38
+ exclude: [...(src.exclude ?? []), ...(dest.exclude ?? [])],
39
+ excludeCompile: [...(src.excludeCompile ?? []), ...(dest.excludeCompile ?? [])],
40
+ env: { ...(src.env ?? {}), ...(dest.env ?? {}) },
42
41
  };
43
42
  },
43
+ buildConfig(configs: Partial<AssembleConfig>[]): AssembleConfig {
44
+ return PackUtil.buildConfig(this, configs);
45
+ },
44
46
  /**
45
47
  * Assemble the project into a workspace directory, optimized for space and runtime
46
48
  */
47
- async* exec({ workspace, cacheDir, add, exclude, excludeCompile, env, keepSource, readonly }: AssembleConfig) {
49
+ async * exec({ workspace, cacheDir, add, exclude, excludeCompile, env, keepSource, readonly }: AssembleConfig) {
48
50
  const fullCacheDir = PathUtil.resolveUnix(workspace!, cacheDir);
49
51
  const ws = PathUtil.resolveUnix(workspace!);
50
52
 
@@ -63,6 +65,7 @@ export const Assemble: PackOperation<AssembleConfig> = {
63
65
  });
64
66
 
65
67
  if (!keepSource) {
68
+ yield 'Clean Boot'; await AssembleUtil.cleanBoot(ws);
66
69
  yield 'Remove Source Maps'; await AssembleUtil.cleanCache(fullCacheDir);
67
70
  yield 'Emptying .ts Files'; await AssembleUtil.purgeSource([`${ws}/node_modules/@travetto`, `${ws}/src`]);
68
71
  }
@@ -28,12 +28,18 @@ ${(port ?? []).map(x => `EXPOSE ${x}`).join('\n')}
28
28
  CMD ["node", "./node_modules/@travetto/cli/bin/trv", "run", "${app}"]
29
29
  `;
30
30
 
31
- export const Docker: PackOperation<DockerConfig> = {
31
+ export const Docker: PackOperation<DockerConfig, 'docker'> = {
32
32
  key: 'docker',
33
33
  title: 'Docker-izing',
34
34
  context(cfg: DockerConfig) {
35
35
  return `[image=${cfg.image}, port=${cfg.port}]`;
36
36
  },
37
+ defaults: {
38
+ name: Package.name.replace('@', ''),
39
+ builder: dockerFileBuilder,
40
+ port: [],
41
+ tag: ['latest']
42
+ },
37
43
  overrides: {
38
44
  image: process.env.PACK_DOCKER_IMAGE || undefined,
39
45
  name: process.env.PACK_DOCKER_NAME || undefined,
@@ -43,20 +49,22 @@ export const Docker: PackOperation<DockerConfig> = {
43
49
  push: CliUtil.toBool(process.env.PACK_DOCKER_PUSH),
44
50
  tag: process.env.PACK_DOCKER_TAG ? [process.env.PACK_DOCKER_TAG] : undefined
45
51
  },
46
- extend(a: DockerConfig, b: Partial<DockerConfig>) {
52
+ extend(src: Partial<DockerConfig>, dest: Partial<DockerConfig>): Partial<DockerConfig> {
47
53
  return {
48
- ...PackUtil.commonExtend(a, b),
49
- image: b.image ?? a.image,
50
- app: b.app ?? a.app,
51
- name: b.name ?? a.name ?? Package.name.replace('@', ''),
52
- builder: b.builder ?? a.builder ?? dockerFileBuilder,
53
- tag: b.tag ?? a.tag ?? ['latest'],
54
- port: b.port ?? a.port ?? [],
55
- registry: b.registry ?? a.registry,
56
- env: { ...(b.env ?? {}), ...a.env },
57
- push: b.push ?? a.push
54
+ image: src.image ?? dest.image,
55
+ app: src.app ?? dest.app,
56
+ name: src.name ?? dest.name,
57
+ builder: src.builder ?? dest.builder,
58
+ tag: src.tag ?? dest.tag,
59
+ port: src.port ?? dest.port,
60
+ registry: src.registry ?? dest.registry,
61
+ env: { ...(src.env ?? {}), ...(dest.env ?? {}) },
62
+ push: src.push ?? dest.push
58
63
  };
59
64
  },
65
+ buildConfig(configs: Partial<DockerConfig>[]): DockerConfig {
66
+ return PackUtil.buildConfig(this, configs);
67
+ },
60
68
  /**
61
69
  * Dockerize workspace with flags
62
70
  */
@@ -28,16 +28,16 @@ export type AllConfigPartial = DeepPartial<AllConfig>;
28
28
 
29
29
  type DefaultOpType = ['assemble', typeof Assemble];
30
30
 
31
- export const Pack: PackOperation<AllConfig> = {
31
+ export const Pack: PackOperation<AllConfig, ''> = {
32
32
  key: '',
33
33
  title: 'Packing',
34
- extend(a: AllConfig, b: Partial<AllConfig>) {
34
+ buildConfig(configs: Partial<AllConfig>[]): AllConfig {
35
35
  const ret: Partial<AllConfig> = {
36
- workspace: b.workspace ?? a.workspace,
36
+ workspace: configs[0].workspace,
37
37
  };
38
38
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
39
39
  for (const [k, op] of (Object.entries(ops) as DefaultOpType[])) {
40
- ret[k] = op.extend(op.extend(a[k] ?? {}, b[k] ?? {}), op.overrides ?? {});
40
+ ret[k] = op.buildConfig(configs.map(config => config[k] ?? {}));
41
41
  }
42
42
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
43
43
  return ret as AllConfig;
@@ -1,7 +1,7 @@
1
1
  import * as path from 'path';
2
2
  import * as fs from 'fs/promises';
3
3
 
4
- import { ExecUtil, PathUtil } from '@travetto/boot';
4
+ import { ExecUtil, FsUtil, PathUtil } from '@travetto/boot';
5
5
  import { color } from '@travetto/cli/src/color';
6
6
 
7
7
  import { CommonConfig, PackOperation } from '../lib/types';
@@ -11,7 +11,7 @@ export interface ZipConfig extends CommonConfig {
11
11
  output: string;
12
12
  }
13
13
 
14
- export const Zip: PackOperation<ZipConfig> = {
14
+ export const Zip: PackOperation<ZipConfig, 'zip'> = {
15
15
  key: 'zip',
16
16
  title: 'Zipping',
17
17
  context(cfg: ZipConfig) {
@@ -20,22 +20,24 @@ export const Zip: PackOperation<ZipConfig> = {
20
20
  overrides: {
21
21
  output: process.env.PACK_ZIP_OUTPUT || undefined
22
22
  },
23
- extend(a: ZipConfig, b: Partial<ZipConfig>) {
24
- return {
25
- ...PackUtil.commonExtend(a, b),
26
- output: b.output ?? a.output
27
- };
23
+ extend(src: Partial<ZipConfig>, dest: Partial<ZipConfig>): Partial<ZipConfig> {
24
+ return { output: src.output ?? dest.output };
25
+ },
26
+ buildConfig(configs: Partial<ZipConfig>[]): ZipConfig {
27
+ return PackUtil.buildConfig(this, configs);
28
28
  },
29
29
  /**
30
30
  * Zip workspace with flags
31
31
  */
32
- async* exec({ workspace, output }: ZipConfig) {
32
+ async * exec({ workspace, output }: ZipConfig) {
33
33
  const ws = PathUtil.resolveUnix(workspace);
34
34
  const zipFile = PathUtil.resolveUnix(output);
35
35
 
36
36
  yield 'Preparing Target';
37
37
  await fs.mkdir(path.dirname(zipFile), { recursive: true });
38
- await fs.unlink(zipFile); // Unlink
38
+ if (await FsUtil.exists(zipFile)) {
39
+ await fs.unlink(zipFile); // Unlink
40
+ }
39
41
 
40
42
  yield 'Compressing';
41
43
  if (/win/i.test(process.platform)) {
package/bin/pack-base.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as os from 'os';
2
2
 
3
- import { BasePlugin, OptionConfig } from '@travetto/cli/src/plugin-base';
3
+ import { CliCommand, OptionConfig } from '@travetto/cli/src/command';
4
4
  import { color } from '@travetto/cli/src/color';
5
5
  import { PathUtil, Package, FsUtil } from '@travetto/boot';
6
6
 
@@ -16,26 +16,35 @@ export type BaseOptions = {
16
16
  workspace: OptionConfig<string>;
17
17
  };
18
18
 
19
+ function getConfigFromOperationOrGlobal<C extends CommonConfig, K extends string>(key: K, config: Partial<C> | Record<K, Partial<C>> | undefined): Partial<C> | undefined {
20
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
21
+ return !config ? config : (key && key in config ? (config as Record<K, C>)[key] : config) as C;
22
+ }
23
+
19
24
  /**
20
25
  * Supports packing a project into a directory, ready for archiving
21
26
  */
22
- export abstract class BasePackPlugin<V extends BaseOptions, C extends CommonConfig> extends BasePlugin<V> {
27
+ export abstract class BasePackCommand<V extends BaseOptions, C extends CommonConfig, K extends string> extends CliCommand<V> {
23
28
 
24
29
  /**
25
30
  * Package stage name
26
31
  */
27
- abstract get operation(): PackOperation<C>;
32
+ abstract get operation(): PackOperation<C, K>;
33
+
34
+ get cmdOptions(): Partial<C> {
35
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
36
+ return this.cmd as Partial<C>;
37
+ }
28
38
 
29
39
  get name(): string {
30
40
  return this.operation.key ? `pack:${this.operation.key}` : 'pack';
31
41
  }
32
42
 
33
- defaultOptions(): BaseOptions {
43
+ commonOptions(): BaseOptions {
34
44
  return { workspace: this.option({ desc: 'Working directory' }) } as const;
35
45
  }
36
46
 
37
47
  async resolveConfigs(): Promise<C> {
38
- const extra = this.operation.key ? { [this.operation.key]: this.cmd } : this.cmd;
39
48
  const list = (await PackUtil.modeList());
40
49
  if (!this.args[0]) {
41
50
  this.showHelp('Missing config mode');
@@ -45,14 +54,18 @@ export abstract class BasePackPlugin<V extends BaseOptions, C extends CommonConf
45
54
  this.showHelp(`Unknown config mode: ${this.args[0]}`);
46
55
  }
47
56
  const def = list.find(c => c.name === 'default');
48
- const out = [def, cfg, extra]
49
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
50
- .map(x => this.operation.key && this.operation.key in (x ?? {}) ? ((x as Record<string, C>)[this.operation.key] as C) : x as C)
51
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
52
- .reduce<C>((acc, l) => this.operation.extend(acc, l ?? {}), (this.operation.overrides ?? {}) as C);
53
- out.workspace ??= PathUtil.resolveUnix(os.tmpdir(), packName);
54
- out.active = true;
55
- return out;
57
+
58
+ const configs = [
59
+ { workspace: PathUtil.resolveUnix(os.tmpdir(), packName) },
60
+ def,
61
+ cfg,
62
+ this.cmdOptions,
63
+ { active: true }
64
+ ]
65
+ .map(x => getConfigFromOperationOrGlobal(this.operation.key, x))
66
+ .filter((x): x is C => x !== undefined);
67
+
68
+ return this.operation.buildConfig(configs);
56
69
  }
57
70
 
58
71
  getArgs(): string {
@@ -62,7 +75,7 @@ export abstract class BasePackPlugin<V extends BaseOptions, C extends CommonConf
62
75
  async help(): Promise<string> {
63
76
  const lines = await PackUtil.modeList();
64
77
 
65
- const out = [];
78
+ const out: string[] = [];
66
79
  if (lines.length) {
67
80
  out.push('', color`${{ title: 'Available Pack Modes:' }}`);
68
81
  for (const { name, file } of lines) {
@@ -78,7 +91,7 @@ export abstract class BasePackPlugin<V extends BaseOptions, C extends CommonConf
78
91
  }
79
92
 
80
93
  async action(): Promise<void> {
81
- const resolved: C = await this.resolveConfigs();
94
+ const resolved = await this.resolveConfigs();
82
95
  if (await FsUtil.exists(PathUtil.resolveUnix(resolved.workspace, '.git'))) {
83
96
  throw new Error('Refusing to use workspace with a .git directory');
84
97
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@travetto/pack",
3
3
  "displayName": "Pack",
4
- "version": "2.2.2",
4
+ "version": "3.0.0-rc.0",
5
5
  "description": "Code packing utilities",
6
6
  "keywords": [
7
7
  "travetto",
@@ -25,15 +25,21 @@
25
25
  "directory": "module/pack"
26
26
  },
27
27
  "dependencies": {
28
- "@travetto/base": "^2.2.2",
28
+ "@travetto/base": "^3.0.0-rc.0",
29
29
  "@types/picomatch": "^2.3.0",
30
30
  "picomatch": "^2.3.1"
31
31
  },
32
- "optionalPeerDependencies": {
33
- "@travetto/cli": "^2.2.2"
32
+ "peerDependencies": {
33
+ "@travetto/cli": "^3.0.0-rc.0"
34
+ },
35
+ "peerDependenciesMeta": {
36
+ "@travetto/cli": {
37
+ "optional": true
38
+ }
34
39
  },
35
40
  "docDependencies": {
36
- "@travetto/rest": true
41
+ "@travetto/rest": true,
42
+ "@travetto/rest-aws-lambda": true
37
43
  },
38
44
  "publishConfig": {
39
45
  "access": "public"
@@ -39,6 +39,7 @@ export const config: AllConfigPartial = {
39
39
  '.npmignore',
40
40
  '.*.yml',
41
41
  'cache/compiler.*.log',
42
+ mod('faker'),
42
43
  mod('lodash/lodash.min.js'),
43
44
  mod('source-map-support/node_modules/source-map'),
44
45
  mod('source-map-support/browser-source-map-support.js'),