@travetto/pack 8.0.0-alpha.9 → 8.0.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.
@@ -1,13 +1,13 @@
1
1
  import commonjsRequire from '@rollup/plugin-commonjs';
2
+ import jsonImport from '@rollup/plugin-json';
2
3
  import nodeResolve from '@rollup/plugin-node-resolve';
3
4
  import terser from '@rollup/plugin-terser';
4
- import jsonImport from '@rollup/plugin-json';
5
5
  import type { RollupOptions } from 'rollup';
6
6
 
7
7
  import { getCoreConfig } from './config.ts';
8
+ import { travettoEntryPlugin } from './rollup-travetto-entry.ts';
8
9
  import { travettoImportPlugin } from './rollup-travetto-import.ts';
9
10
  import { travettoSourcemaps } from './rollup-travetto-sourcemaps.ts';
10
- import { travettoEntryPlugin } from './rollup-travetto-entry.ts';
11
11
 
12
12
  export default function buildConfig(): RollupOptions {
13
13
  // Load up if not defined
@@ -27,4 +27,4 @@ export default function buildConfig(): RollupOptions {
27
27
  ...(config.output.compact ? [terser(config.minify)] : [])
28
28
  ]
29
29
  };
30
- }
30
+ }
@@ -1,7 +1,7 @@
1
1
  import path from 'node:path';
2
2
 
3
- import type { OutputOptions } from 'rollup';
4
3
  import type terser from '@rollup/plugin-terser';
4
+ import type { OutputOptions } from 'rollup';
5
5
 
6
6
  import { type ManifestModule, ManifestModuleUtil } from '@travetto/manifest';
7
7
  import { EnvProp, Runtime, RuntimeIndex } from '@travetto/runtime';
@@ -10,11 +10,10 @@ import type { CoreRollupConfig } from '../../src/types.ts';
10
10
 
11
11
  function getFilesFromModule(module: ManifestModule): string[] {
12
12
  return [
13
- ...module.files.$index ?? [],
14
- ...module.files.src ?? [],
13
+ ...(module.files.$index ?? []),
14
+ ...(module.files.src ?? []),
15
15
  ...(module.files.bin ?? []).filter(file => !(/bin\/trv[.]js$/.test(file[0]) && module.name === '@travetto/cli')),
16
- ...(module.files.support ?? [])
17
- .filter(file => !/support\/(test|doc|pack)/.test(file[0]))
16
+ ...(module.files.support ?? []).filter(file => !/support\/(test|doc|pack)/.test(file[0]))
18
17
  ]
19
18
  .filter(([, type]) => type === 'ts' || type === 'js' || type === 'json')
20
19
  .filter(([, , , role]) => (role ?? 'std') === 'std') // Only include standard files
@@ -26,8 +25,7 @@ export function getOutput(): OutputOptions {
26
25
  const mainFile = process.env.BUNDLE_MAIN_FILE!;
27
26
  return {
28
27
  format: 'module',
29
- sourcemapPathTransform: (source, map): string =>
30
- Runtime.stripWorkspacePath(path.resolve(path.dirname(map), source)),
28
+ sourcemapPathTransform: (source, map): string => Runtime.stripWorkspacePath(path.resolve(path.dirname(map), source)),
31
29
  sourcemap: new EnvProp('BUNDLE_SOURCEMAP').bool ?? false,
32
30
  sourcemapExcludeSources: !(new EnvProp('BUNDLE_SOURCES').bool ?? false),
33
31
  compact: new EnvProp('BUNDLE_COMPRESS').bool ?? true,
@@ -49,9 +47,7 @@ export function getFiles(entry?: string): string[] {
49
47
  }
50
48
 
51
49
  export function getIgnoredModules(): ManifestModule[] {
52
- return [...RuntimeIndex.getModuleList('all')]
53
- .map(name => RuntimeIndex.getManifestModule(name))
54
- .filter(module => !module.production);
50
+ return [...RuntimeIndex.getModuleList('all')].map(name => RuntimeIndex.getManifestModule(name)).filter(module => !module.production);
55
51
  }
56
52
 
57
53
  export function getMinifyConfig(): Parameters<typeof terser>[0] {
@@ -63,7 +59,7 @@ export function getMinifyConfig(): Parameters<typeof terser>[0] {
63
59
  compress: {},
64
60
  output: {
65
61
  shebang: false,
66
- comments: false,
62
+ comments: false
67
63
  }
68
64
  };
69
65
  }
@@ -79,7 +75,12 @@ export function getCoreConfig(): CoreRollupConfig {
79
75
  const external = new EnvProp('BUNDLE_EXTERNAL').list ?? [];
80
76
 
81
77
  return {
82
- output, entry, files, envFile, minify, external,
83
- ignore: new Set([...ignoreModules.map(module => module.name), ...ignoreFiles]),
78
+ output,
79
+ entry,
80
+ files,
81
+ envFile,
82
+ minify,
83
+ external,
84
+ ignore: new Set([...ignoreModules.map(module => module.name), ...ignoreFiles])
84
85
  };
85
- }
86
+ }
@@ -1,4 +1,5 @@
1
1
  import { readFileSync } from 'node:fs';
2
+
2
3
  import type { Plugin } from 'rollup';
3
4
 
4
5
  import { RuntimeIndex } from '@travetto/runtime';
@@ -10,7 +11,7 @@ export const GLOBAL_IMPORT = '__trv_imp';
10
11
  export function travettoEntryPlugin(config: CoreRollupConfig): Plugin {
11
12
  const imports = config.files
12
13
  .map(file => file.split('node_modules/').pop()!)
13
- .flatMap(file => file.endsWith('/__index__.js') ? [file.replace('/__index__.js', ''), file] : [file]);
14
+ .flatMap(file => (file.endsWith('/__index__.js') ? [file.replace('/__index__.js', ''), file] : [file]));
14
15
 
15
16
  const importer = `
16
17
  function trvImp(path) {
@@ -39,4 +40,4 @@ globalThis.${GLOBAL_IMPORT} = trvImp;
39
40
  };
40
41
 
41
42
  return out;
42
- }
43
+ }
@@ -1,12 +1,12 @@
1
- import type { AstNode, Plugin } from 'rollup';
2
1
  // @ts-expect-error - This module lacks types
3
2
  import { walk } from 'estree-walker';
4
3
  import magicString from 'magic-string';
4
+ import type { AstNode, Plugin } from 'rollup';
5
5
 
6
- import { GLOBAL_IMPORT } from './rollup-travetto-entry.ts';
7
6
  import type { CoreRollupConfig } from '../../src/types.ts';
7
+ import { GLOBAL_IMPORT } from './rollup-travetto-entry.ts';
8
8
 
9
- type TNode = AstNode & { source?: { type: string }, callee?: TNode & { name?: string }, args?: TNode[] };
9
+ type TNode = AstNode & { source?: { type: string }; callee?: TNode & { name?: string }; args?: TNode[] };
10
10
 
11
11
  /**
12
12
  * Handles importing via non-static strings (e.g. ClassSource)
@@ -59,4 +59,4 @@ export function travettoImportPlugin(config: CoreRollupConfig): Plugin {
59
59
  };
60
60
 
61
61
  return out;
62
- }
62
+ }
@@ -1,14 +1,14 @@
1
- import path from 'node:path';
2
1
  import fs from 'node:fs/promises';
2
+ import path from 'node:path';
3
3
 
4
4
  import type { LoadResult, Plugin, PluginContext, SourceMapInput } from 'rollup';
5
5
 
6
- import { JSONUtil, FileLoader } from '@travetto/runtime';
6
+ import { FileLoader, JSONUtil } from '@travetto/runtime';
7
7
 
8
8
  import type { CoreRollupConfig } from '../../src/types.ts';
9
9
 
10
- function toString(error: unknown): string {
11
- return error instanceof Error ? error.stack ?? error.toString() : JSONUtil.toUTF8(error);
10
+ function errorString(error: unknown): string {
11
+ return error instanceof Error ? (error.stack ?? error.toString()) : JSONUtil.toUTF8(error);
12
12
  }
13
13
  // Pulled from https://github.com/Azure/azure-sdk-for-js/blob/main/common/tools/dev-tool/src/config/rollup.base.config.ts#L128
14
14
  export function travettoSourcemaps(config: CoreRollupConfig): Plugin {
@@ -30,18 +30,16 @@ export function travettoSourcemaps(config: CoreRollupConfig): Plugin {
30
30
  return null;
31
31
  }
32
32
  const loader = new FileLoader([path.dirname(id)]);
33
- const map = await loader.readText(mapPath)
34
- .then(value => value.startsWith('{') ?
35
- JSONUtil.fromUTF8<SourceMapInput>(value) :
36
- JSONUtil.fromBase64<SourceMapInput>(value)
37
- );
33
+ const map = await loader
34
+ .readUTF8(mapPath)
35
+ .then(value => (value.startsWith('{') ? JSONUtil.fromUTF8<SourceMapInput>(value) : JSONUtil.fromBase64<SourceMapInput>(value)));
38
36
  return { code, map };
39
37
  }
40
38
  return { code, map: null };
41
39
  } catch (error) {
42
- this.warn({ message: toString(error), id });
40
+ this.warn({ message: errorString(error), id });
43
41
  return null;
44
42
  }
45
- },
43
+ }
46
44
  };
47
45
  }