prebundle 1.5.0 → 1.6.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.
package/bin.js CHANGED
@@ -1,4 +1,28 @@
1
1
  #!/usr/bin/env node
2
+ import cac from 'cac';
3
+ import { createRequire } from 'node:module';
2
4
  import { run } from './dist/index.js';
3
5
 
4
- run();
6
+ const require = createRequire(import.meta.url);
7
+ const pkg = require('./package.json');
8
+
9
+ const cli = cac('prebundle');
10
+
11
+ cli
12
+ .command('[...packages]', 'Prebundle configured dependencies')
13
+ .option('--config <path>', 'Path to a custom config file')
14
+ .action(async (packages = [], options) => {
15
+ try {
16
+ await run({
17
+ config: options.config,
18
+ packages,
19
+ });
20
+ } catch (error) {
21
+ console.error(error);
22
+ process.exitCode = 1;
23
+ }
24
+ });
25
+
26
+ cli.help();
27
+ cli.version(pkg.version);
28
+ cli.parse();
package/dist/helper.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { Config, DependencyConfig, ParsedTask } from './types.js';
2
2
  export declare function findDepPath(name: string): string | null;
3
- export declare const resolveConfig: () => Promise<Config>;
3
+ export declare const resolveConfig: (configFile?: string) => Promise<Config>;
4
4
  export declare function parseTasks(dependencies: Array<string | DependencyConfig>, globalPrettier?: boolean): 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.d.ts CHANGED
@@ -1,2 +1,6 @@
1
- export declare function run(): Promise<void>;
1
+ export interface RunOptions {
2
+ config?: string;
3
+ packages?: string[];
4
+ }
5
+ export declare function run(options?: RunOptions): Promise<void>;
2
6
  export type { Config } from './types.js';
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { dirname, extname, join } from "node:path";
1
+ import { dirname, extname, join, resolve } from "node:path";
2
2
  import fs_extra from "../compiled/fs-extra/index.js";
3
3
  import { createRequire } from "node:module";
4
4
  import { pathToFileURL } from "node:url";
@@ -60,7 +60,7 @@ const cwd = process.cwd();
60
60
  const helper_require = createRequire(import.meta.url);
61
61
  function findDepPath(name) {
62
62
  try {
63
- let entry = dirname(helper_require.resolve(join(name), {
63
+ let entry = dirname(helper_require.resolve(name, {
64
64
  paths: [
65
65
  cwd
66
66
  ]
@@ -72,20 +72,20 @@ function findDepPath(name) {
72
72
  return null;
73
73
  }
74
74
  }
75
- const resolveConfig = async ()=>{
76
- const configFiles = [
75
+ const resolveConfig = async (configFile)=>{
76
+ const configFiles = configFile ? [
77
+ resolve(cwd, configFile)
78
+ ] : [
77
79
  'prebundle.config.ts',
78
80
  'prebundle.config.mts',
79
81
  'prebundle.config.mjs',
80
82
  'prebundle.config.js'
81
- ];
82
- for (const filename of configFiles){
83
- const configPath = join(cwd, filename);
84
- if (fs_extra.existsSync(configPath)) {
85
- const config = await import(pathToFileURL(configPath).href);
86
- return config.default;
87
- }
83
+ ].map((filename)=>join(cwd, filename));
84
+ for (const filename of configFiles)if (fs_extra.existsSync(filename)) {
85
+ const config = await import(pathToFileURL(filename).href);
86
+ return config.default ?? config;
88
87
  }
88
+ if (configFile) throw new Error(`Unable to locate prebundle config file at: ${configFile}`);
89
89
  throw new Error('Unable to locate prebundle config file.');
90
90
  };
91
91
  function parseTasks(dependencies, globalPrettier) {
@@ -202,10 +202,7 @@ async function emitIndex(code, distPath, prettier) {
202
202
  await fs_extra.outputFile(distIndex, formatted);
203
203
  } else await fs_extra.outputFile(distIndex, code);
204
204
  }
205
- const getTypes = (json)=>{
206
- var _json_exports;
207
- return json && (json.types || json.typing || json.typings || getTypes(null == (_json_exports = json.exports) ? void 0 : _json_exports['.'])) || null;
208
- };
205
+ const getTypes = (json)=>json && (json.types || json.typing || json.typings || getTypes(json.exports?.['.'])) || null;
209
206
  async function emitDts(task, externals) {
210
207
  const outputDefaultDts = ()=>{
211
208
  fs_extra.outputFileSync(join(task.distPath, 'index.d.ts'), 'export = any;\n');
@@ -317,20 +314,15 @@ function renameDistFolder(task) {
317
314
  'types',
318
315
  'typing',
319
316
  'typings'
320
- ]){
321
- var _pkgJson_key;
322
- if (null == (_pkgJson_key = pkgJson[key]) ? void 0 : _pkgJson_key.startsWith('dist/')) {
323
- pkgJson[key] = pkgJson[key].replace('dist/', 'types/');
324
- const distFolder = join(task.distPath, 'dist');
325
- const typesFolder = join(task.distPath, 'types');
326
- if (fs_extra.existsSync(distFolder)) fs_extra.renameSync(distFolder, typesFolder);
327
- }
317
+ ])if (pkgJson[key]?.startsWith('dist/')) {
318
+ pkgJson[key] = pkgJson[key].replace('dist/', 'types/');
319
+ const distFolder = join(task.distPath, 'dist');
320
+ const typesFolder = join(task.distPath, 'types');
321
+ if (fs_extra.existsSync(distFolder)) fs_extra.renameSync(distFolder, typesFolder);
328
322
  }
329
323
  fs_extra.writeJSONSync(pkgPath, pkgJson);
330
324
  }
331
- const pkgName = process.argv[2];
332
325
  async function prebundle(task, commonExternals = {}) {
333
- if (pkgName && task.depName !== pkgName) return;
334
326
  logger.start(`prebundle: ${task.depName}`);
335
327
  fs_extra.removeSync(task.distPath);
336
328
  if (task.beforeBundle) await task.beforeBundle(task);
@@ -362,9 +354,10 @@ async function prebundle(task, commonExternals = {}) {
362
354
  if (task.afterBundle) await task.afterBundle(task);
363
355
  logger.success(`prebundle: ${task.depName}\n\n`);
364
356
  }
365
- async function run() {
366
- const config = await resolveConfig();
357
+ async function run(options = {}) {
358
+ const config = await resolveConfig(options.config);
367
359
  const parsedTasks = parseTasks(config.dependencies, config.prettier);
368
- for (const task of parsedTasks)await prebundle(task, config.externals);
360
+ const filters = options.packages?.length ? new Set(options.packages) : null;
361
+ for (const task of parsedTasks)if (!filters || filters.has(task.depName)) await prebundle(task, config.externals);
369
362
  }
370
363
  export { run };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prebundle",
3
- "version": "1.5.0",
3
+ "version": "1.6.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/rspack-contrib/prebundle"
@@ -20,25 +20,30 @@
20
20
  "dev": "rslib build --watch",
21
21
  "prebundle": "node ./bin.js",
22
22
  "prepare": "npm run build",
23
- "bump": "npx bumpp"
23
+ "bump": "npx bumpp",
24
+ "test": "rstest"
24
25
  },
25
26
  "dependencies": {
27
+ "cac": "^6.7.14",
26
28
  "@vercel/ncc": "0.38.4",
27
29
  "prettier": "^3.6.2",
28
- "rollup": "^4.52.3",
30
+ "rollup": "^4.52.5",
29
31
  "rollup-plugin-dts": "^6.2.3",
30
32
  "terser": "^5.44.0"
31
33
  },
32
34
  "devDependencies": {
33
- "@rslib/core": "0.15.0",
35
+ "@astrojs/sitemap": "^3.6.0",
36
+ "@rslib/core": "0.17.0",
37
+ "@rstest/core": "^0.6.5",
34
38
  "@types/fs-extra": "^11.0.4",
35
- "@types/node": "22.18.8",
39
+ "@types/node": "22.18.13",
40
+ "chalk": "^5.6.2",
36
41
  "fast-glob": "^3.3.3",
37
42
  "fs-extra": "^11.3.2",
38
- "rslog": "^1.2.11",
43
+ "rslog": "^1.3.0",
39
44
  "typescript": "^5.9.3"
40
45
  },
41
- "packageManager": "pnpm@10.17.1",
46
+ "packageManager": "pnpm@10.20.0",
42
47
  "publishConfig": {
43
48
  "access": "public",
44
49
  "registry": "https://registry.npmjs.org/",