@travetto/pack 3.0.0-rc.8 → 3.0.0-rc.9

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/pack",
3
- "version": "3.0.0-rc.8",
3
+ "version": "3.0.0-rc.9",
4
4
  "description": "Code packing utilities",
5
5
  "keywords": [
6
6
  "travetto",
@@ -27,12 +27,12 @@
27
27
  "@rollup/plugin-json": "^6.0.0",
28
28
  "@rollup/plugin-terser": "^0.4.0",
29
29
  "@rollup/plugin-node-resolve": "^15.0.1",
30
- "@travetto/base": "^3.0.0-rc.8",
30
+ "@travetto/base": "^3.0.0-rc.9",
31
31
  "rollup": "^3.12.1",
32
32
  "rollup-plugin-sourcemaps": "^0.6.3"
33
33
  },
34
34
  "peerDependencies": {
35
- "@travetto/cli": "^3.0.0-rc.9"
35
+ "@travetto/cli": "^3.0.0-rc.10"
36
36
  },
37
37
  "peerDependenciesMeta": {
38
38
  "@travetto/cli": {
@@ -1,11 +1,11 @@
1
1
  import fs from 'fs/promises';
2
2
 
3
- import { path } from '@travetto/manifest';
3
+ import { path, RootIndex } from '@travetto/manifest';
4
4
  import { ExecUtil } from '@travetto/base';
5
5
  import { cliTpl } from '@travetto/cli';
6
6
 
7
7
  import { ActiveShellCommand } from './shell';
8
- import { DockerPackConfig } from './types';
8
+ import { DockerPackConfig, DockerPackFactoryModule } from './types';
9
9
 
10
10
  export class DockerPackOperation {
11
11
 
@@ -19,13 +19,9 @@ export class DockerPackOperation {
19
19
  static async* writeDockerFile(cfg: DockerPackConfig): AsyncIterable<string[]> {
20
20
  const dockerFile = path.resolve(cfg.workspace, 'Dockerfile');
21
21
  const title = cliTpl`${{ title: 'Generating Docker File' }} ${{ path: dockerFile }}`;
22
- const content = `
23
- FROM ${cfg.dockerImage}
24
- WORKDIR /app
25
- COPY . .
26
- ${(cfg.dockerPort ?? []).map(x => `EXPOSE ${x}`).join('\n')}
27
- ENTRYPOINT ["/app/${cfg.entryCommand}.sh"]
28
- `;
22
+ const mod: DockerPackFactoryModule = await import(RootIndex.getFromImport(cfg.dockerFactory)!.import);
23
+ const content = (await mod.factory(cfg)).trim();
24
+
29
25
  if (cfg.ejectFile) {
30
26
  yield ActiveShellCommand.comment(title);
31
27
  yield* ActiveShellCommand.createFile(dockerFile, content.split(/\n/));
@@ -122,7 +122,7 @@ export class PackOperation {
122
122
  static async * writeEntryScript(cfg: CommonPackConfig): AsyncIterable<string[]> {
123
123
  const title = 'Writing entry scripts';
124
124
 
125
- const files = ([['posix', 'sh'], ['win32', 'bat']] as const)
125
+ const files = ([['posix', 'sh'], ['win32', 'cmd']] as const)
126
126
  .map(([type, ext]) => ({
127
127
  fileTitle: cliTpl`${{ title }} ${{ path: `${cfg.entryCommand}.${ext}` }} args=(${{ param: cfg.entryArguments.join(' ') }})`,
128
128
  file: `${cfg.entryCommand}.${ext}`,
@@ -10,6 +10,8 @@ import { RootIndex } from '@travetto/manifest';
10
10
  import { getEntry, getOutput, getTerserConfig, getFiles } from './config';
11
11
  import { travettoImportPlugin } from './rollup-esm-dynamic-import';
12
12
 
13
+ const NEVER_INCLUDE = new Set(['node-forge', '@parcel/watcher']);
14
+
13
15
  export default function buildConfig(): RollupOptions {
14
16
  const output = getOutput();
15
17
  const entry = getEntry();
@@ -18,10 +20,10 @@ export default function buildConfig(): RollupOptions {
18
20
  return {
19
21
  input: [entry],
20
22
  output,
21
- external: ['node-forge', '@parcel/watcher'],
22
23
  plugins: [
23
24
  jsonImport(),
24
25
  commonjsRequire({
26
+ ignore: id => NEVER_INCLUDE.has(id),
25
27
  dynamicRequireRoot: RootIndex.manifest.workspacePath,
26
28
  dynamicRequireTargets: (output.format === 'commonjs' ? files : [])
27
29
  }),
@@ -31,6 +31,7 @@ export type CommonPackOptions = {
31
31
  };
32
32
 
33
33
  export type DockerPackConfig = {
34
+ dockerFactory: string;
34
35
  dockerImage: string;
35
36
  dockerName: string;
36
37
  dockerTag: string[];
@@ -40,6 +41,7 @@ export type DockerPackConfig = {
40
41
  } & CommonPackConfig;
41
42
 
42
43
  export type DockerPackOptions = {
44
+ dockerFactory: OptionConfig<string>;
43
45
  dockerImage: OptionConfig<string>;
44
46
  dockerName: OptionConfig<string>;
45
47
  dockerTag: ListOptionConfig<string>;
@@ -62,4 +64,7 @@ export type ShellCommandImpl = {
62
64
  chdir(dest: string): string[];
63
65
  comment(message: string): string[];
64
66
  zip(output: string): string[];
65
- };
67
+ };
68
+
69
+ export type DockerPackFactory = (cfg: DockerPackConfig) => (string | Promise<string>);
70
+ export type DockerPackFactoryModule = { factory: DockerPackFactory };
@@ -14,6 +14,7 @@ export class PackDockerCommand extends BasePackCommand<DockerPackOptions, Docker
14
14
  const opts = this.getCommonOptions();
15
15
  return {
16
16
  ...opts,
17
+ dockerFactory: this.option({ short: 'df', desc: 'Docker Factory source', def: '@travetto/pack/support/pack.dockerfile' }),
17
18
  dockerImage: this.option({ short: 'di', desc: 'Docker Image to extend', def: 'node:18-alpine3.16' }),
18
19
  dockerName: this.option({ short: 'dn', desc: 'Docker Image Name', def: this.monoRoot ? '<module>' : this.getSimpleModuleName() }),
19
20
  dockerTag: this.listOption({ short: 'dt', desc: 'Docker Image Tag', def: ['latest'] }),
@@ -96,13 +96,15 @@ export abstract class BasePackCommand<T extends CommonPackOptions, S extends Com
96
96
  module = this.getModule(module);
97
97
 
98
98
  const cfg = await this.buildConfig();
99
- cfg.entryArguments = args;
99
+ cfg.entryArguments = Array.isArray(args) ? args : [];
100
100
 
101
101
  for (const k in this.cmd) {
102
- const v = this.cmd[k];
103
- if (typeof v === 'string' && /<module>/.test(v)) {
104
- // @ts-expect-error
105
- this.cmd[k] = v.replace(/<module>/g, this.getSimpleModuleName());
102
+ if (Object.hasOwn(this.cmd, k)) {
103
+ const v = this.cmd[k];
104
+ if (typeof v === 'string' && /<module>/.test(v)) {
105
+ // @ts-expect-error
106
+ this.cmd[k] = v.replace(/<module>/g, this.getSimpleModuleName());
107
+ }
106
108
  }
107
109
  }
108
110
 
@@ -0,0 +1,9 @@
1
+ import { DockerPackFactory } from './bin/types';
2
+
3
+ export const factory: DockerPackFactory = cfg => `
4
+ FROM ${cfg.dockerImage}
5
+ WORKDIR /app
6
+ COPY . .
7
+ ${cfg.dockerPort.map(port => `EXPOSE ${port}`).join('\n')}
8
+ ENTRYPOINT ["/app/${cfg.entryCommand}.sh"]
9
+ `;