@travetto/pack 2.2.4 → 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,
@@ -90,7 +90,7 @@ export class AssembleUtil {
90
90
  /**
91
91
  * Copy over all prod dependencies
92
92
  */
93
- 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> {
94
94
 
95
95
  for (const el of await DependenciesUtil.resolveDependencies({ types })) {
96
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,8 +7,8 @@ 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
13
  defaults?: Partial<T>;
14
14
  overrides?: Partial<T>;
package/bin/lib/util.ts CHANGED
@@ -25,19 +25,17 @@ export class PackUtil {
25
25
  configs: Partial<T>[]
26
26
  ): T {
27
27
  const inputs = [
28
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
29
- op.defaults ?? {} as Partial<T>,
28
+ op.defaults! ?? {},
30
29
  ...configs,
31
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
32
- op.overrides ?? {} as Partial<T>
30
+ op.overrides! ?? {}
33
31
  ].filter(x => Object.keys(x).length > 0);
34
32
 
35
33
  const res = inputs.reduce((out: Partial<T>, config: Partial<T>): Partial<T> => {
36
34
  const final = {
37
35
  active: config.active ?? out.active,
38
36
  workspace: config.workspace ?? out.workspace,
39
- preProcess: [...(config.preProcess ?? []), ...(out.preProcess ?? [])],
40
- postProcess: [...(config.postProcess ?? []), ...(out.postProcess ?? [])],
37
+ preProcess: [...(config.preProcess! ?? []), ...(out.preProcess ?? [])],
38
+ postProcess: [...(config.postProcess! ?? []), ...(out.postProcess ?? [])],
41
39
  ...op.extend?.(config, out)
42
40
  };
43
41
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
@@ -123,7 +121,7 @@ export class PackUtil {
123
121
  /**
124
122
  * Run operation with logging
125
123
  */
126
- 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> {
127
125
  const spacer = ' '.repeat(indent);
128
126
  const ctx = await op.context(cfg);
129
127
  const title = color`${{ title: op.title }} ${ctx}`;
@@ -19,7 +19,7 @@ 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) {
@@ -28,7 +28,7 @@ ${(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) {
@@ -28,7 +28,7 @@ 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
34
  buildConfig(configs: Partial<AllConfig>[]): AllConfig {
@@ -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) {
package/bin/pack-base.ts CHANGED
@@ -16,15 +16,25 @@ 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 BasePackCommand<V extends BaseOptions, C extends CommonConfig> extends CliCommand<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';
@@ -35,7 +45,6 @@ export abstract class BasePackCommand<V extends BaseOptions, C extends CommonCon
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,17 +54,18 @@ export abstract class BasePackCommand<V extends BaseOptions, C extends CommonCon
45
54
  this.showHelp(`Unknown config mode: ${this.args[0]}`);
46
55
  }
47
56
  const def = list.find(c => c.name === 'default');
48
- const configs = [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
-
52
- return this.operation.buildConfig([
53
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
54
- { workspace: PathUtil.resolveUnix(os.tmpdir(), packName) } as C,
55
- ...configs,
56
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
57
- { active: true } as C
58
- ]);
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);
59
69
  }
60
70
 
61
71
  getArgs(): string {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@travetto/pack",
3
3
  "displayName": "Pack",
4
- "version": "2.2.4",
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.4",
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.4"
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"