@travetto/pack 3.4.0-rc.1 → 3.4.0-rc.11

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.4.0-rc.1",
3
+ "version": "3.4.0-rc.11",
4
4
  "description": "Code packing utilities",
5
5
  "keywords": [
6
6
  "travetto",
@@ -27,14 +27,12 @@
27
27
  "@rollup/plugin-commonjs": "^25.0.7",
28
28
  "@rollup/plugin-json": "^6.0.1",
29
29
  "@rollup/plugin-node-resolve": "^15.2.3",
30
- "@rollup/plugin-replace": "^5.0.5",
31
30
  "@rollup/plugin-terser": "^0.4.4",
32
- "@travetto/base": "^3.4.0-rc.0",
33
- "rollup": "^4.1.5",
34
- "rollup-plugin-sourcemaps": "^0.6.3"
31
+ "@travetto/base": "^3.4.0-rc.4",
32
+ "rollup": "^4.3.0"
35
33
  },
36
34
  "peerDependencies": {
37
- "@travetto/cli": "^3.4.0-rc.0"
35
+ "@travetto/cli": "^3.4.0-rc.5"
38
36
  },
39
37
  "peerDependenciesMeta": {
40
38
  "@travetto/cli": {
@@ -43,7 +41,7 @@
43
41
  },
44
42
  "travetto": {
45
43
  "displayName": "Pack",
46
- "profiles": [
44
+ "roles": [
47
45
  "build"
48
46
  ]
49
47
  },
@@ -24,7 +24,8 @@ function getFilesFromModule(m: ManifestModule): string[] {
24
24
  return [
25
25
  ...m.files.$index ?? [],
26
26
  ...m.files.src ?? [],
27
- ...m.files.bin ?? [],
27
+ ...(m.files.bin ?? [])
28
+ .filter(f => !(/bin\/trv[.]js$/.test(f[0]) && m.name === '@travetto/cli')),
28
29
  ...(m.files.support ?? [])
29
30
  .filter(f => !/support\/(test|doc)/.test(f[0]))
30
31
  ]
@@ -61,10 +62,17 @@ export function getEntry(): string {
61
62
  export function getFiles(): string[] {
62
63
  return [...RootIndex.getModuleList('all')]
63
64
  .map(x => RootIndex.manifest.modules[x])
64
- .filter(m => m.profiles.includes('std'))
65
+ .filter(m => m.prod)
65
66
  .flatMap(getFilesFromModule);
66
67
  }
67
68
 
69
+ export function getIgnoredModules(): string[] {
70
+ return [...RootIndex.getModuleList('all')]
71
+ .map(x => RootIndex.manifest.modules[x])
72
+ .filter(m => !m.prod)
73
+ .map(m => m.name);
74
+ }
75
+
68
76
  export function getTerserConfig(): Parameters<typeof terser>[0] {
69
77
  return {
70
78
  mangle: true,
@@ -65,6 +65,8 @@ export class DockerPackOperation {
65
65
  yield ActiveShellCommand.chdir(path.cwd());
66
66
  } else {
67
67
  await PackUtil.runCommand(cmd, { cwd: cfg.workspace, stdio: [0, 'pipe', 2] });
68
+ const [image] = JSON.parse(await PackUtil.runCommand(['docker', 'inspect', cfg.dockerImage]));
69
+ yield [cliTpl`${{ title: 'Built Docker Container ' }} ${{ identifier: 'sizeMb' }}=${{ param: Math.trunc(image.Size / 2 ** 20) }}`];
68
70
  }
69
71
  }
70
72
 
@@ -88,6 +88,8 @@ export class PackOperation {
88
88
  yield ActiveShellCommand.chdir(path.cwd());
89
89
  } else {
90
90
  await PackUtil.runCommand(bundleCommand, { cwd, env });
91
+ const stat = await fs.stat(path.resolve(cfg.workspace, `${cfg.mainName}.js`));
92
+ yield [cliTpl`${{ title: 'Bundled Output ' }} ${{ identifier: 'sizeKb' }}=${{ param: Math.trunc(stat.size / 2 ** 10) }}`];
91
93
  }
92
94
  }
93
95
 
@@ -1,6 +1,6 @@
1
- import { AcornNode, Plugin } from 'rollup';
1
+ import { AstNode, Plugin } from 'rollup';
2
2
  import { walk } from 'estree-walker';
3
- import MagicString from 'magic-string';
3
+ import magicString from 'magic-string';
4
4
 
5
5
  const BRAND = '__imp';
6
6
 
@@ -23,20 +23,20 @@ export function travettoImportPlugin(entry: string, files: string[]): Plugin {
23
23
  transform(code, id) {
24
24
  const parsed = this.parse(code);
25
25
 
26
- let ms: MagicString | undefined;
26
+ let ms: magicString | undefined;
27
27
 
28
28
  if (id.includes(entry)) {
29
- (ms ??= new MagicString(code).append(DYNAMIC_IMPORT(imports)));
29
+ (ms ??= new magicString(code).append(DYNAMIC_IMPORT(imports)));
30
30
  }
31
31
 
32
32
  walk(parsed, {
33
33
  enter: (node) => {
34
34
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
35
- const impNode = node as AcornNode & { source?: { type: string } };
35
+ const impNode = node as AstNode & { source?: { type: string } };
36
36
  if (impNode.type !== 'ImportExpression' || impNode.source?.type === 'Literal') {
37
37
  return;
38
38
  }
39
- (ms ??= new MagicString(code)).overwrite(impNode.start, impNode.start + 6, BRAND);
39
+ (ms ??= new magicString(code)).overwrite(impNode.start, impNode.start + 6, BRAND);
40
40
  }
41
41
  });
42
42
 
@@ -0,0 +1,37 @@
1
+ import path from 'path';
2
+ import fs from 'fs/promises';
3
+
4
+ import { LoadResult, Plugin, PluginContext } from 'rollup';
5
+
6
+ function toString(error: unknown): string {
7
+ return error instanceof Error ? error.stack ?? error.toString() : JSON.stringify(error);
8
+ }
9
+ // Pulled from https://github.com/Azure/azure-sdk-for-js/blob/main/common/tools/dev-tool/src/config/rollup.base.config.ts#L128
10
+ export function sourcemaps(): Plugin {
11
+ return {
12
+ name: 'load-source-maps',
13
+ async load(this: PluginContext, id: string): Promise<LoadResult> {
14
+ if (!id.endsWith('.js')) {
15
+ return null;
16
+ }
17
+ try {
18
+ const code = await fs.readFile(id, 'utf8');
19
+ if (code.includes('sourceMappingURL')) {
20
+ const mapPath = code.match(/sourceMappingURL=(.*)/)?.[1];
21
+ if (!mapPath) {
22
+ this.warn({ message: `Could not find map path in file ${id}`, id });
23
+ return null;
24
+ }
25
+ const basePath = path.dirname(id);
26
+ const absoluteMapPath = path.join(basePath, mapPath);
27
+ const map = JSON.parse(await fs.readFile(absoluteMapPath, 'utf8'));
28
+ return { code, map };
29
+ }
30
+ return { code, map: null };
31
+ } catch (e) {
32
+ this.warn({ message: toString(e), id });
33
+ return null;
34
+ }
35
+ },
36
+ };
37
+ }
@@ -2,40 +2,36 @@ import commonjsRequire from '@rollup/plugin-commonjs';
2
2
  import nodeResolve from '@rollup/plugin-node-resolve';
3
3
  import terser from '@rollup/plugin-terser';
4
4
  import jsonImport from '@rollup/plugin-json';
5
- import sourceMaps from 'rollup-plugin-sourcemaps';
6
- import replace from '@rollup/plugin-replace';
7
5
  import type { RollupOptions } from 'rollup';
8
6
 
9
7
  import { RootIndex } from '@travetto/manifest';
10
8
 
11
- import { getEntry, getOutput, getTerserConfig, getFiles } from './config';
9
+ import { getEntry, getOutput, getTerserConfig, getFiles, getIgnoredModules } from './config';
12
10
  import { travettoImportPlugin } from './rollup-esm-dynamic-import';
11
+ import { sourcemaps } from './rollup-sourcemaps';
13
12
 
14
- const NEVER_INCLUDE = new Set(['@parcel/watcher']);
13
+ const NEVER_INCLUDE = new Set<string>([]);
15
14
 
16
15
  export default function buildConfig(): RollupOptions {
17
16
  const output = getOutput();
18
17
  const entry = getEntry();
19
18
  const files = getFiles();
19
+ const ignore = getIgnoredModules();
20
+ const ignoreRe = new RegExp(`^(${ignore.join('|')})`);
20
21
 
21
22
  return {
22
23
  input: [entry],
23
24
  output,
24
25
  plugins: [
25
26
  jsonImport(),
26
- replace({
27
- values: {
28
- ['#!' + '/usr/bin/env node']: '' // Strip out shebang
29
- }
30
- }),
31
27
  commonjsRequire({
32
- ignore: id => NEVER_INCLUDE.has(id),
28
+ ignore: id => ignoreRe.test(id) || NEVER_INCLUDE.has(id),
33
29
  dynamicRequireRoot: RootIndex.manifest.workspacePath,
34
30
  dynamicRequireTargets: (output.format === 'commonjs' ? files : [])
35
31
  }),
36
32
  ...(output.format === 'module' ? [travettoImportPlugin(entry, files)] : []),
37
33
  nodeResolve({ preferBuiltins: true }),
38
- ...(output.sourcemap !== 'hidden' && output.sourcemap !== false ? [sourceMaps({})] : []),
34
+ ...(output.sourcemap !== 'hidden' && output.sourcemap !== false ? [sourcemaps()] : []),
39
35
  ...(output.compact ? [terser(getTerserConfig())] : [])
40
36
  ]
41
37
  };
@@ -66,8 +66,8 @@ export class PackUtil {
66
66
  /**
67
67
  * Track result response
68
68
  */
69
- static async runCommand(cmd: string[], opts: ExecutionOptions = {}): Promise<void> {
70
- const { valid, code, stderr, message } = await ExecUtil.spawn(cmd[0], cmd.slice(1), {
69
+ static async runCommand(cmd: string[], opts: ExecutionOptions = {}): Promise<string> {
70
+ const { valid, code, stderr, message, stdout } = await ExecUtil.spawn(cmd[0], cmd.slice(1), {
71
71
  stdio: [0, 'pipe', 'pipe', 'ipc'],
72
72
  ...opts,
73
73
  catchAsResult: true
@@ -76,5 +76,6 @@ export class PackUtil {
76
76
  process.exitCode = code;
77
77
  throw new AppError(stderr || message || 'An unexpected error has occurred');
78
78
  }
79
+ return stdout;
79
80
  }
80
81
  }
@@ -15,7 +15,11 @@ export type PackOperationShape<T> = ((config: T) => AsyncIterable<string[]>);
15
15
  export abstract class BasePackCommand implements CliCommandShape {
16
16
 
17
17
  static get entryPoints(): string[] {
18
- return RootIndex.findSupport({ filter: x => x.includes('entry.') })
18
+ return RootIndex.find({
19
+ module: m => m.prod,
20
+ folder: f => f === 'support',
21
+ file: f => f.sourceFile.includes('entry.')
22
+ })
19
23
  .map(x => x.import.replace(/[.][^.]+s$/, ''));
20
24
  }
21
25