prebundle 1.0.0 → 1.0.2

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
@@ -58,6 +58,18 @@ export default {
58
58
  };
59
59
  ```
60
60
 
61
+ You can also configure `externals` for all packages like this:
62
+
63
+ ```ts
64
+ // prebundle.config.mjs
65
+ export default {
66
+ externals: {
67
+ webpack: '../webpack',
68
+ },
69
+ dependencies: [{ name: 'foo' }, { name: 'foo' }],
70
+ };
71
+ ```
72
+
61
73
  ### minify
62
74
 
63
75
  Whether to minify the code, default `true`.
package/dist/helper.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import type { DependencyConfig, ParsedTask } from './types.js';
1
+ import type { Config, DependencyConfig, ParsedTask } from './types.js';
2
2
  export declare function findDepPath(name: string): string;
3
- export declare const resolveConfig: () => Promise<any>;
3
+ export declare const resolveConfig: () => Promise<Config>;
4
4
  export declare function parseTasks(dependencies: Array<string | DependencyConfig>): ParsedTask[];
5
5
  export declare function pick<T, U extends keyof T>(obj: T, keys: ReadonlyArray<U>): Pick<T, U>;
6
6
  export declare function replaceFileContent(filePath: string, replaceFn: (content: string) => string): void;
package/dist/index.js CHANGED
@@ -4,6 +4,6 @@ export async function run() {
4
4
  const config = await resolveConfig();
5
5
  const parsedTasks = parseTasks(config.dependencies);
6
6
  for (const task of parsedTasks) {
7
- await prebundle(task);
7
+ await prebundle(task, config.externals);
8
8
  }
9
9
  }
@@ -1,2 +1,2 @@
1
1
  import type { ParsedTask } from './types.js';
2
- export declare function prebundle(task: ParsedTask): Promise<void>;
2
+ export declare function prebundle(task: ParsedTask, commonExternals: Record<string, string>): Promise<void>;
package/dist/prebundle.js CHANGED
@@ -25,16 +25,12 @@ function fixTypeExternalPath(file, task, externals) {
25
25
  return newContent;
26
26
  });
27
27
  }
28
- function emitDts(task) {
28
+ function emitDts(task, externals) {
29
29
  if (task.ignoreDts) {
30
30
  fs.writeFileSync(join(task.distPath, 'index.d.ts'), 'export = any;\n');
31
31
  return;
32
32
  }
33
33
  try {
34
- const externals = {
35
- ...DEFAULT_EXTERNALS,
36
- ...task.externals,
37
- };
38
34
  const { files } = new DtsPacker({
39
35
  cwd,
40
36
  name: task.depName,
@@ -112,7 +108,7 @@ function renameDistFolder(task) {
112
108
  fs.writeJSONSync(pkgPath, pkgJson);
113
109
  }
114
110
  const pkgName = process.argv[2];
115
- export async function prebundle(task) {
111
+ export async function prebundle(task, commonExternals) {
116
112
  if (pkgName && task.depName !== pkgName) {
117
113
  return;
118
114
  }
@@ -121,18 +117,20 @@ export async function prebundle(task) {
121
117
  if (task.beforeBundle) {
122
118
  await task.beforeBundle(task);
123
119
  }
120
+ const mergedExternals = {
121
+ ...DEFAULT_EXTERNALS,
122
+ ...commonExternals,
123
+ ...task.externals,
124
+ };
124
125
  const { code, assets } = await ncc(task.depEntry, {
125
126
  minify: task.minify,
126
127
  target: 'es2019',
127
- externals: {
128
- ...DEFAULT_EXTERNALS,
129
- ...task.externals,
130
- },
128
+ externals: mergedExternals,
131
129
  assetBuilds: false,
132
130
  });
133
131
  emitIndex(code, task.distPath);
134
132
  emitAssets(assets, task.distPath);
135
- emitDts(task);
133
+ emitDts(task, mergedExternals);
136
134
  emitLicense(task);
137
135
  emitPackageJson(task);
138
136
  removeSourceMap(task);
package/dist/types.d.ts CHANGED
@@ -19,6 +19,11 @@ export type DependencyConfig = {
19
19
  afterBundle?: (task: ParsedTask) => void | Promise<void>;
20
20
  };
21
21
  export type Config = {
22
+ /**
23
+ * Configure externals for all packages,
24
+ * will be merged with dependencies[i].externals.
25
+ */
26
+ externals: Record<string, string>;
22
27
  dependencies: Array<string | DependencyConfig>;
23
28
  };
24
29
  export type ParsedTask = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prebundle",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "main": "./dist/index.js",
5
5
  "type": "module",
6
6
  "repository": {