prebundle 1.2.0 → 1.2.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/dist/prebundle.js CHANGED
@@ -7,7 +7,7 @@ import { DEFAULT_EXTERNALS, NODE_BUILTINS } from './constant.js';
7
7
  import { findDepPath, pick } from './helper.js';
8
8
  import { dts } from 'rollup-plugin-dts';
9
9
  import { rollup } from 'rollup';
10
- import swc from '@swc/core';
10
+ import { minify } from 'terser';
11
11
  import { format } from 'prettier';
12
12
  const { logger } = rslog;
13
13
  function emitAssets(assets, distPath) {
@@ -18,12 +18,16 @@ function emitAssets(assets, distPath) {
18
18
  }
19
19
  async function emitIndex(code, distPath, prettier) {
20
20
  const distIndex = join(distPath, 'index.js');
21
+ // use terser to strip comments and use prettier to format the code
21
22
  if (prettier) {
22
- const minimized = await swc.minify(code, {
23
+ const minimized = await minify(code, {
23
24
  compress: false,
24
25
  mangle: false,
25
26
  ecma: 2019,
26
27
  });
28
+ if (!minimized.code) {
29
+ throw new Error('terser minify failed');
30
+ }
27
31
  const formatted = await format(minimized.code, {
28
32
  filepath: distIndex,
29
33
  });
@@ -167,7 +171,7 @@ function renameDistFolder(task) {
167
171
  fs.writeJSONSync(pkgPath, pkgJson);
168
172
  }
169
173
  const pkgName = process.argv[2];
170
- export async function prebundle(task, commonExternals = {}, prettier) {
174
+ export async function prebundle(task, commonExternals = {}) {
171
175
  if (pkgName && task.depName !== pkgName) {
172
176
  return;
173
177
  }
@@ -187,7 +191,7 @@ export async function prebundle(task, commonExternals = {}, prettier) {
187
191
  externals: mergedExternals,
188
192
  assetBuilds: false,
189
193
  });
190
- await emitIndex(code, task.distPath, prettier);
194
+ await emitIndex(code, task.distPath, task.prettier);
191
195
  emitAssets(assets, task.distPath);
192
196
  await emitDts(task, mergedExternals);
193
197
  emitLicense(task);
package/dist/types.d.ts CHANGED
@@ -11,6 +11,8 @@ export type DependencyConfig = {
11
11
  externals?: Record<string, string>;
12
12
  /** Externals types */
13
13
  dtsExternals?: Array<string | RegExp>;
14
+ /** Whether to prettier the code and strip comments */
15
+ prettier?: boolean;
14
16
  /** Emit extra entry files to map imports. */
15
17
  emitFiles?: ImportMap[];
16
18
  /** Copy extra fields from original package.json to target package.json. */
@@ -38,6 +40,7 @@ export type ParsedTask = {
38
40
  distPath: string;
39
41
  importPath: string;
40
42
  ignoreDts?: boolean;
43
+ prettier?: boolean;
41
44
  target: NonNullable<DependencyConfig['target']>;
42
45
  minify: NonNullable<DependencyConfig['minify']>;
43
46
  depName: NonNullable<DependencyConfig['name']>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prebundle",
3
- "version": "1.2.0",
3
+ "version": "1.2.2",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/rspack-contrib/prebundle"
@@ -15,18 +15,12 @@
15
15
  "bin.js",
16
16
  "compiled"
17
17
  ],
18
- "scripts": {
19
- "build": "tsc",
20
- "dev": "tsc --watch",
21
- "prebundle": "node ./bin.js",
22
- "prepublishOnly": "npm run build"
23
- },
24
18
  "dependencies": {
25
- "@swc/core": "^1.6.13",
26
19
  "@vercel/ncc": "0.38.1",
27
20
  "prettier": "^3.2.5",
28
21
  "rollup": "^4.17.1",
29
- "rollup-plugin-dts": "^6.1.0"
22
+ "rollup-plugin-dts": "^6.1.0",
23
+ "terser": "^5.31.2"
30
24
  },
31
25
  "devDependencies": {
32
26
  "@types/fs-extra": "^11.0.4",
@@ -36,8 +30,12 @@
36
30
  "rslog": "^1.2.2",
37
31
  "typescript": "^5.4.2"
38
32
  },
39
- "packageManager": "pnpm@9.0.5",
40
33
  "publishConfig": {
41
34
  "registry": "https://registry.npmjs.org/"
35
+ },
36
+ "scripts": {
37
+ "build": "tsc",
38
+ "dev": "tsc --watch",
39
+ "prebundle": "node ./bin.js"
42
40
  }
43
- }
41
+ }