@travetto/pack 5.0.0-rc.1 → 5.0.0-rc.10

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": "5.0.0-rc.1",
3
+ "version": "5.0.0-rc.10",
4
4
  "description": "Code packing utilities",
5
5
  "keywords": [
6
6
  "travetto",
@@ -29,12 +29,12 @@
29
29
  "@rollup/plugin-json": "^6.1.0",
30
30
  "@rollup/plugin-node-resolve": "^15.2.3",
31
31
  "@rollup/plugin-terser": "^0.4.4",
32
- "@travetto/base": "^5.0.0-rc.1",
33
- "@travetto/terminal": "^5.0.0-rc.0",
34
- "rollup": "^4.18.0"
32
+ "@travetto/runtime": "^5.0.0-rc.10",
33
+ "@travetto/terminal": "^5.0.0-rc.10",
34
+ "rollup": "^4.20.0"
35
35
  },
36
36
  "peerDependencies": {
37
- "@travetto/cli": "^5.0.0-rc.1"
37
+ "@travetto/cli": "^5.0.0-rc.11"
38
38
  },
39
39
  "peerDependenciesMeta": {
40
40
  "@travetto/cli": {
@@ -74,7 +74,7 @@ export class PackConfigUtil {
74
74
  }
75
75
 
76
76
  /**
77
- * Docker app files copied and permissioned
77
+ * Docker app files copied with proper permissions
78
78
  */
79
79
  static dockerAppFiles(cfg: DockerPackConfig): string {
80
80
  const { user, group, folder } = cfg.dockerRuntime;
@@ -1,7 +1,7 @@
1
1
  import fs from 'node:fs/promises';
2
2
  import path from 'node:path';
3
3
 
4
- import { RuntimeIndex } from '@travetto/manifest';
4
+ import { Runtime } from '@travetto/runtime';
5
5
  import { cliTpl } from '@travetto/cli';
6
6
 
7
7
  import { ActiveShellCommand } from './shell';
@@ -22,8 +22,13 @@ export class DockerPackOperation {
22
22
  // Read os before writing
23
23
  cfg.dockerRuntime.os = await PackUtil.runCommand(
24
24
  ['docker', 'run', '--entrypoint', '/bin/sh', cfg.dockerImage, '-c', 'cat /etc/*release*']
25
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
26
- ).then(out => out.match(/\b(?:debian|alpine|centos)\b/i)?.[0].toLowerCase() as 'alpine' ?? 'unknown');
25
+ ).then(out => {
26
+ const found = out.match(/\b(?:debian|alpine|centos)\b/i)?.[0].toLowerCase();
27
+ switch (found) {
28
+ case 'debian': case 'alpine': case 'centos': return found;
29
+ default: return 'unknown';
30
+ }
31
+ });
27
32
  yield* PackOperation.title(cfg, cliTpl`${{ title: 'Detected Image OS' }} ${{ param: cfg.dockerImage }} as ${{ param: cfg.dockerRuntime.os }}`);
28
33
  }
29
34
 
@@ -32,12 +37,7 @@ export class DockerPackOperation {
32
37
  */
33
38
  static async* writeDockerFile(cfg: DockerPackConfig): AsyncIterable<string[]> {
34
39
  const dockerFile = path.resolve(cfg.buildDir, 'Dockerfile');
35
-
36
- const factory = RuntimeIndex.getFromImport(cfg.dockerFactory);
37
- if (!factory) {
38
- throw new Error(`Unable to resolve docker factory at ${cfg.dockerFactory}`);
39
- }
40
- const mod: DockerPackFactoryModule = await import(factory.import);
40
+ const mod = await Runtime.importFrom<DockerPackFactoryModule>(cfg.dockerFactory);
41
41
  const content = (await mod.factory(cfg)).trim();
42
42
 
43
43
  yield* PackOperation.title(cfg, cliTpl`${{ title: 'Generating Docker File' }} ${{ path: dockerFile }} ${{ param: cfg.dockerFactory }}`);
@@ -1,9 +1,8 @@
1
1
  import fs from 'node:fs/promises';
2
2
  import path from 'node:path';
3
3
 
4
- import { RuntimeIndex } from '@travetto/manifest';
5
4
  import { cliTpl } from '@travetto/cli';
6
- import { Env, RuntimeContext } from '@travetto/base';
5
+ import { Env, Runtime, RuntimeIndex } from '@travetto/runtime';
7
6
 
8
7
  import { CommonPackConfig } from '../../src/types';
9
8
  import { PackUtil } from './util';
@@ -67,7 +66,7 @@ export class PackOperation {
67
66
  ['BUNDLE_SOURCEMAP', cfg.sourcemap],
68
67
  ['BUNDLE_SOURCES', cfg.includeSources],
69
68
  ['BUNDLE_OUTPUT', cfg.buildDir],
70
- ['BUNDLE_FORMAT', RuntimeContext.workspace.type],
69
+ ['BUNDLE_FORMAT', Runtime.workspace.type],
71
70
  ['BUNDLE_ENV_FILE', cfg.envFile]
72
71
  ] as const)
73
72
  .filter(x => x[1] === false || x[1])
@@ -100,7 +99,7 @@ export class PackOperation {
100
99
  */
101
100
  static async * writePackageJson(cfg: CommonPackConfig): AsyncIterable<string[]> {
102
101
  const file = 'package.json';
103
- const pkg = { type: RuntimeContext.workspace.type, main: cfg.mainFile };
102
+ const pkg = { type: Runtime.workspace.type, main: cfg.mainFile };
104
103
 
105
104
  yield* PackOperation.title(cfg, cliTpl`${{ title: 'Writing' }} ${{ path: file }}`);
106
105
 
@@ -189,7 +188,7 @@ export class PackOperation {
189
188
  yield* PackOperation.title(cfg, cliTpl`${{ title: 'Copying over workspace resources' }}`);
190
189
 
191
190
  const dest = path.resolve(cfg.buildDir, cfg.workspaceResourceFolder);
192
- const src = RuntimeContext.workspaceRelative('resources');
191
+ const src = Runtime.workspaceRelative('resources');
193
192
 
194
193
  if (cfg.ejectFile) {
195
194
  yield ActiveShellCommand.copyRecursive(src, dest, true);
@@ -204,7 +203,7 @@ export class PackOperation {
204
203
  static async * copyResources(cfg: CommonPackConfig): AsyncIterable<string[]> {
205
204
  const resources = {
206
205
  count: RuntimeIndex.mainModule.files.resources?.length ?? 0,
207
- src: path.resolve(RuntimeContext.mainSourcePath, 'resources'),
206
+ src: path.resolve(Runtime.mainSourcePath, 'resources'),
208
207
  dest: path.resolve(cfg.buildDir, 'resources')
209
208
  };
210
209
 
@@ -2,8 +2,7 @@ import fs from 'node:fs/promises';
2
2
  import { spawn, SpawnOptions } from 'node:child_process';
3
3
  import path from 'node:path';
4
4
 
5
- import { RuntimeIndex } from '@travetto/manifest';
6
- import { AppError, ExecUtil } from '@travetto/base';
5
+ import { AppError, ExecUtil, RuntimeIndex } from '@travetto/runtime';
7
6
 
8
7
  import { ActiveShellCommand } from './shell';
9
8
 
@@ -30,7 +29,7 @@ export class PackUtil {
30
29
  }
31
30
  await fs.mkdir(final, { recursive: true });
32
31
  await fs.cp(src, final, { recursive: true });
33
- } catch (err) {
32
+ } catch {
34
33
  if (!ignoreFailure) {
35
34
  throw new Error(`Failed to copy ${src} to ${dest}`);
36
35
  }
@@ -5,5 +5,5 @@ import { BasePackCommand } from './pack.base';
5
5
  /**
6
6
  * Standard pack support
7
7
  */
8
- @CliCommand({ addModule: true })
8
+ @CliCommand({ with: { module: true } })
9
9
  export class PackCommand extends BasePackCommand { }
@@ -1,6 +1,6 @@
1
1
  import path from 'node:path';
2
2
 
3
- import { RuntimeIndex } from '@travetto/manifest';
3
+ import { RuntimeIndex } from '@travetto/runtime';
4
4
  import { CliCommand, CliFlag, CliUtil, CliValidationError } from '@travetto/cli';
5
5
  import { Ignore, Required } from '@travetto/schema';
6
6
 
@@ -13,7 +13,7 @@ const NODE_MAJOR = process.version.match(/\d+/)?.[0] ?? '22';
13
13
  /**
14
14
  * Standard docker support for pack
15
15
  */
16
- @CliCommand({ addModule: true })
16
+ @CliCommand({ with: { module: true } })
17
17
  export class PackDockerCommand extends BasePackCommand {
18
18
  @CliFlag({ desc: 'Docker Factory source', short: 'df', envVars: ['PACK_DOCKER_FACTORY'] })
19
19
  dockerFactory = '@travetto/pack/support/pack.dockerfile';
@@ -6,7 +6,7 @@ import { BasePackCommand, PackOperationShape } from './pack.base';
6
6
  /**
7
7
  * Standard zip support for pack
8
8
  */
9
- @CliCommand({ addModule: true })
9
+ @CliCommand({ with: { module: true } })
10
10
  export class PackZipCommand extends BasePackCommand {
11
11
 
12
12
  preMain(): void {
@@ -2,8 +2,7 @@ import os from 'node:os';
2
2
  import path from 'node:path';
3
3
 
4
4
  import { CliCommandShape, CliFlag, ParsedState, cliTpl } from '@travetto/cli';
5
- import { RuntimeIndex } from '@travetto/manifest';
6
- import { TimeUtil, RuntimeContext } from '@travetto/base';
5
+ import { TimeUtil, Runtime, RuntimeIndex } from '@travetto/runtime';
7
6
  import { Terminal } from '@travetto/terminal';
8
7
  import { Ignore, Required, Schema } from '@travetto/schema';
9
8
 
@@ -28,7 +27,7 @@ export abstract class BasePackCommand implements CliCommandShape {
28
27
  _parsed: ParsedState;
29
28
 
30
29
  @CliFlag({ desc: 'Workspace for building', short: 'b' })
31
- buildDir: string = path.resolve(os.tmpdir(), RuntimeContext.mainSourcePath.replace(/[\/\\: ]/g, '_'));
30
+ buildDir: string = path.resolve(os.tmpdir(), Runtime.mainSourcePath.replace(/[\/\\: ]/g, '_'));
32
31
 
33
32
  @CliFlag({ desc: 'Clean workspace' })
34
33
  clean = true;
@@ -117,7 +116,7 @@ export abstract class BasePackCommand implements CliCommandShape {
117
116
 
118
117
  // Update entry points
119
118
  this.entryArguments = [...this.entryArguments ?? [], ...args, ...this._parsed.unknown];
120
- this.module ||= RuntimeContext.main.name;
119
+ this.module ||= Runtime.main.name;
121
120
  this.mainName ??= path.basename(this.module);
122
121
  this.mainFile = `${this.mainName}.js`;
123
122
 
@@ -3,8 +3,9 @@ import path from 'node:path';
3
3
  import type { OutputOptions } from 'rollup';
4
4
  import type terser from '@rollup/plugin-terser';
5
5
 
6
- import { type ManifestModule, ManifestModuleUtil, type NodeModuleType, RuntimeIndex } from '@travetto/manifest';
7
- import { EnvProp, RuntimeContext } from '@travetto/base';
6
+ import { type ManifestModule, ManifestModuleUtil, type NodeModuleType } from '@travetto/manifest';
7
+ import { EnvProp, Runtime, RuntimeIndex } from '@travetto/runtime';
8
+
8
9
  import { CoreRollupConfig } from '../../src/types';
9
10
 
10
11
  function getFilesFromModule(m: ManifestModule): string[] {
@@ -17,19 +18,26 @@ function getFilesFromModule(m: ManifestModule): string[] {
17
18
  ]
18
19
  .filter(([, t]) => t === 'ts' || t === 'js' || t === 'json')
19
20
  .filter(f => (f[3] ?? 'std') === 'std') // Only include standard files
20
- .map(([f]) => ManifestModuleUtil.sourceToOutputExt(path.resolve(m.outputFolder, f)));
21
+ .map(([f]) => ManifestModuleUtil.withOutputExtension(path.resolve(m.outputFolder, f)));
22
+ }
23
+
24
+ function getFormat(value: string = 'commonjs'): NodeModuleType {
25
+ switch (value) {
26
+ case 'module':
27
+ case 'commonjs': return value;
28
+ default: return 'commonjs';
29
+ }
21
30
  }
22
31
 
23
32
  export function getOutput(): OutputOptions {
24
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
25
- const format = (process.env.BUNDLE_FORMAT ?? 'commonjs') as NodeModuleType;
33
+ const format = getFormat(process.env.BUNDLE_FORMAT);
26
34
  const dir = process.env.BUNDLE_OUTPUT!;
27
35
  const mainFile = process.env.BUNDLE_MAIN_FILE!;
28
36
  return {
29
37
  format,
30
38
  interop: format === 'commonjs' ? 'auto' : undefined,
31
39
  sourcemapPathTransform: (src, map): string =>
32
- RuntimeContext.stripWorkspacePath(path.resolve(path.dirname(map), src)),
40
+ Runtime.stripWorkspacePath(path.resolve(path.dirname(map), src)),
33
41
  sourcemap: new EnvProp('BUNDLE_SOURCEMAP').bool ?? false,
34
42
  sourcemapExcludeSources: !(new EnvProp('BUNDLE_SOURCES').bool ?? false),
35
43
  compact: new EnvProp('BUNDLE_COMPRESS').bool ?? true,
@@ -1,7 +1,7 @@
1
1
  import { readFileSync } from 'node:fs';
2
2
  import { Plugin } from 'rollup';
3
3
 
4
- import { RuntimeIndex } from '@travetto/manifest';
4
+ import { RuntimeIndex } from '@travetto/runtime';
5
5
 
6
6
  import { CoreRollupConfig } from '../../src/types';
7
7