unplugin-dts-bundle-generator 3.2.0 → 3.3.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/README.md CHANGED
@@ -20,13 +20,6 @@ yarn add --dev unplugin-dts-bundle-generator
20
20
 
21
21
  ## Usage
22
22
  Only those bundlers are supported at the moment:
23
- - [Vite](https://github.com/vitejs/vite)
24
- - [Rollup](https://github.com/rollup/rollup)
25
- - [ESBuild](https://github.com/evanw/esbuild)
26
-
27
- Please open a PR or an issue if you need another export and want to speed up the process, so we can work it out!
28
-
29
- ⚠️ Be careful! Plugin options may vary according to the bundler you are using.
30
23
 
31
24
  <details>
32
25
  <summary>ESBuild</summary><br>
@@ -60,6 +53,38 @@ await esbuild.build({
60
53
  ```
61
54
  <br></details>
62
55
 
56
+ <details>
57
+ <summary>Rolldown</summary><br>
58
+
59
+ With Rolldown, add this block to your `rolldown.config.ts`:
60
+
61
+ ```ts
62
+ import dtsBundleGenerator from 'unplugin-dts-bundle-generator/rolldown';
63
+
64
+ export default {
65
+ plugins: [
66
+ dtsBundleGenerator({
67
+ file: 'my-lib.d.ts',
68
+ output: {
69
+ // output config
70
+ },
71
+ libraries: {
72
+ // libraries config
73
+ },
74
+ compilation: {
75
+ // compilation options
76
+ }
77
+ }),
78
+ ],
79
+ input: 'src/index.ts',
80
+ output: {
81
+ dir: 'dist',
82
+ format: 'es',
83
+ },
84
+ };
85
+ ```
86
+ <br></details>
87
+
63
88
  <details>
64
89
  <summary>Rollup</summary><br>
65
90
 
@@ -128,6 +153,10 @@ export default defineConfig({
128
153
  ```
129
154
  <br></details>
130
155
 
156
+ ⚠️ Be careful! Plugin options may vary depending on the bundler you are using.
157
+
158
+ Feel free to open a PR or an issue if you need another export and want to speed up the process, so we can work it out.
159
+
131
160
  ## Configuration
132
161
 
133
162
  This library handle both single and multiple entrypoints. You can use any of the output, libraries and compilation options available in the [config file](https://github.com/timocov/dts-bundle-generator/blob/master/src/config-file/README.md) of DTS Bundle Generator.
@@ -5,16 +5,16 @@ export interface DtsBundleGeneratorOptions {
5
5
  libraries?: EntryPointConfig["libraries"];
6
6
  compilation?: CompilationOptions;
7
7
  }
8
- export interface ESBuildOptions extends DtsBundleGeneratorOptions {
8
+ export interface OptionsForESBuild extends DtsBundleGeneratorOptions {
9
9
  outfile?: string;
10
10
  }
11
- export interface RollupOptions extends DtsBundleGeneratorOptions {
11
+ export interface OptionsForRollup extends DtsBundleGeneratorOptions {
12
12
  file?: string;
13
13
  }
14
- export interface ViteOptions extends DtsBundleGeneratorOptions {
14
+ export interface OptionsForVite extends DtsBundleGeneratorOptions {
15
15
  fileName: string | ((entryName: string) => string);
16
16
  }
17
- export type Options = ESBuildOptions | RollupOptions | ViteOptions;
17
+ export type Options = OptionsForESBuild | OptionsForRollup | OptionsForVite;
18
18
  declare const _default: import("unplugin").UnpluginInstance<Options, false>;
19
19
 
20
20
  export {
package/dist/esbuild.d.ts CHANGED
@@ -5,10 +5,10 @@ export interface DtsBundleGeneratorOptions {
5
5
  libraries?: EntryPointConfig["libraries"];
6
6
  compilation?: CompilationOptions;
7
7
  }
8
- export interface ESBuildOptions extends DtsBundleGeneratorOptions {
8
+ export interface OptionsForESBuild extends DtsBundleGeneratorOptions {
9
9
  outfile?: string;
10
10
  }
11
- declare const _default: (options: ESBuildOptions) => import("esbuild").Plugin;
11
+ declare const _default: (options: OptionsForESBuild) => import("esbuild").Plugin;
12
12
 
13
13
  export {
14
14
  _default as default,
@@ -1,2 +1,2 @@
1
- "use strict";const f=require("node:buffer"),g=require("node:fs"),c=require("node:path"),h=require("node:zlib"),y=require("dts-bundle-generator"),u=require("picocolors"),d=l=>{const a={},n=[],o=[];return{name:"unplugin-dts-bundle-generator",buildEnd(){o.forEach(e=>n.push({entryPointConfig:{filePath:e.in,libraries:l.libraries,output:l.output},outFile:e.out,size:-1,compressedSize:-1}))},writeBundle(){n.forEach((e,r)=>{const t=y.generateDtsBundle([e.entryPointConfig],l.compilation)[0];g.writeFileSync(e.outFile,t),n[r].size=f.Buffer.byteLength(t),n[r].compressedSize=h.gzipSync(t).length})},esbuild:{config(e){if(!e.entryPoints)return;const r=l,t=typeof e.entryPoints=="string"?[e.entryPoints]:Array.isArray(e.entryPoints)?e.entryPoints:Object.values(e.entryPoints);t.length===1&&(r.outfile||e.outfile)?o[0]={in:typeof t[0]=="string"?t[0]:t[0].in,out:r.outfile||e.outfile}:t.map(i=>typeof i!="string"?i:{in:i,out:c.basename(i).split(".")[0]}).forEach(i=>{o.push({in:i.in,out:`${e.outdir}/${i.out}.d.ts`})})}},rollup:{buildStart(e){Array.isArray(e.input)?e.input.forEach((r,t)=>o.push({in:r,out:`${t}`})):Object.entries(e.input).forEach(([r,t])=>o.push({in:t,out:r}))},outputOptions(e){const r=l;n.length===1&&(r.file||e.file)?n[0].outFile=r.file??e.file.replace(/\.js$/,".d.ts"):n.forEach((t,i)=>{const s=`${c.basename(t.entryPointConfig.filePath).split(".")[0]}.d.ts`;n[i].outFile=`${e.dir}/${s}`})}},vite:{configResolved(e){const r=l;if(e.build.lib){const t=(i="default")=>typeof r.fileName=="string"?`${e.build.outDir}/${r.fileName}`:`${e.build.outDir}/${r.fileName(i)}`;typeof e.build.lib.entry=="string"?o.push({in:e.build.lib.entry,out:t()}):Array.isArray(e.build.lib.entry)?e.build.lib.entry.forEach((i,s)=>o.push({in:i,out:t(`${s}`)})):Object.entries(e.build.lib.entry).forEach(([i,s])=>o.push({in:s,out:t(i)}))}a.outDir=e.build.outDir},closeBundle(){const e=n.length.toString();this.environment.logger.info(`
2
- ${u.green("✓")} ${e} declaration bundles generated.`);const r=Math.max(...n.map(i=>i.outFile.length)),t={maximumFractionDigits:2,minimumFractionDigits:2};n.forEach(i=>this.environment.logger.info(u.dim(`${a.outDir}`)+u.cyan(i.outFile.replace(a.outDir??"",""))+" ".repeat(r-i.outFile.length+2)+u.gray(`${(i.size/1e3).toLocaleString("en",t)} kB`)+u.dim(` │ gzip: ${(i.compressedSize/1e3).toLocaleString("en",t)} kB`)))}}}};exports.unpluginFactory=d;
1
+ "use strict";const f=require("node:buffer"),h=require("node:fs"),c=require("node:path"),g=require("node:zlib"),y=require("dts-bundle-generator"),a=require("picocolors"),d=s=>{const o={},n=[],l=[];return{name:"unplugin-dts-bundle-generator",buildEnd(){l.forEach(e=>n.push({entryPointConfig:{filePath:e.in,libraries:s.libraries,output:s.output},outFile:e.out,size:-1,compressedSize:-1}))},writeBundle(){n.forEach((e,r)=>{if(e.size===-1){const t=y.generateDtsBundle([e.entryPointConfig],s.compilation)[0];h.writeFileSync(e.outFile,t),n[r].size=f.Buffer.byteLength(t),n[r].compressedSize=g.gzipSync(t).length}})},esbuild:{config(e){if(!e.entryPoints)return;const r=s,t=typeof e.entryPoints=="string"?[e.entryPoints]:Array.isArray(e.entryPoints)?e.entryPoints:Object.values(e.entryPoints);t.length===1&&(r.outfile||e.outfile)?l[0]={in:typeof t[0]=="string"?t[0]:t[0].in,out:r.outfile||e.outfile}:t.map(i=>typeof i!="string"?i:{in:i,out:c.basename(i).split(".")[0]}).forEach(i=>{l.push({in:i.in,out:`${e.outdir}/${i.out}.d.ts`})})}},rollup:{buildStart(e){Array.isArray(e.input)?e.input.length===1?e.input.forEach((r,t)=>l.push({in:r,out:o.outFile??`${t}`})):e.input.forEach((r,t)=>l.push({in:r,out:o.outDir?`${o.outDir}/${c.basename(r).split(".")[0]}.d.ts`:`${t}`})):Object.entries(e.input).forEach(([r,t])=>l.push({in:t,out:o.outDir?`${o.outDir}/${c.basename(t).split(".")[0]}.d.ts`:r}))},outputOptions(e){if(n.length===0){o.outFile=e.file,o.outDir=e.dir;return}const r=s;n.length===1&&(r.file||e.file)?n[0].outFile=r.file??e.file.replace(/\.js$/,".d.ts"):n.forEach((t,i)=>{const u=`${c.basename(t.entryPointConfig.filePath).split(".")[0]}.d.ts`;n[i].outFile=`${e.dir}/${u}`})}},vite:{configResolved(e){const r=s;if(e.build.lib){const t=(i="default")=>typeof r.fileName=="string"?`${e.build.outDir}/${r.fileName}`:`${e.build.outDir}/${r.fileName(i)}`;typeof e.build.lib.entry=="string"?l.push({in:e.build.lib.entry,out:t()}):Array.isArray(e.build.lib.entry)?e.build.lib.entry.forEach((i,u)=>l.push({in:i,out:t(`${u}`)})):Object.entries(e.build.lib.entry).forEach(([i,u])=>l.push({in:u,out:t(i)}))}o.outDir=e.build.outDir},closeBundle(){const e=n.length.toString();this.environment.logger.info(`
2
+ ${a.green("✓")} ${e} declaration bundles generated.`);const r=Math.max(...n.map(i=>i.outFile.length)),t={maximumFractionDigits:2,minimumFractionDigits:2};n.forEach(i=>this.environment.logger.info(a.dim(`${o.outDir}`)+a.cyan(i.outFile.replace(o.outDir??"",""))+" ".repeat(r-i.outFile.length+2)+a.gray(`${(i.size/1e3).toLocaleString("en",t)} kB`)+a.dim(` │ gzip: ${(i.compressedSize/1e3).toLocaleString("en",t)} kB`)))}}}};exports.unpluginFactory=d;
@@ -3,17 +3,17 @@ import m from "node:fs";
3
3
  import f from "node:path";
4
4
  import h from "node:zlib";
5
5
  import { generateDtsBundle as g } from "dts-bundle-generator";
6
- import u from "picocolors";
7
- const E = (l) => {
8
- const a = {}, n = [], o = [];
6
+ import a from "picocolors";
7
+ const F = (s) => {
8
+ const n = {}, o = [], l = [];
9
9
  return {
10
10
  name: "unplugin-dts-bundle-generator",
11
11
  buildEnd() {
12
- o.forEach((e) => n.push({
12
+ l.forEach((e) => o.push({
13
13
  entryPointConfig: {
14
14
  filePath: e.in,
15
- libraries: l.libraries,
16
- output: l.output
15
+ libraries: s.libraries,
16
+ output: s.output
17
17
  },
18
18
  outFile: e.out,
19
19
  size: -1,
@@ -21,17 +21,19 @@ const E = (l) => {
21
21
  }));
22
22
  },
23
23
  writeBundle() {
24
- n.forEach((e, r) => {
25
- const t = g([e.entryPointConfig], l.compilation)[0];
26
- m.writeFileSync(e.outFile, t), n[r].size = c.byteLength(t), n[r].compressedSize = h.gzipSync(t).length;
24
+ o.forEach((e, r) => {
25
+ if (e.size === -1) {
26
+ const t = g([e.entryPointConfig], s.compilation)[0];
27
+ m.writeFileSync(e.outFile, t), o[r].size = c.byteLength(t), o[r].compressedSize = h.gzipSync(t).length;
28
+ }
27
29
  });
28
30
  },
29
31
  esbuild: {
30
32
  config(e) {
31
33
  if (!e.entryPoints)
32
34
  return;
33
- const r = l, t = typeof e.entryPoints == "string" ? [e.entryPoints] : Array.isArray(e.entryPoints) ? e.entryPoints : Object.values(e.entryPoints);
34
- t.length === 1 && (r.outfile || e.outfile) ? o[0] = {
35
+ const r = s, t = typeof e.entryPoints == "string" ? [e.entryPoints] : Array.isArray(e.entryPoints) ? e.entryPoints : Object.values(e.entryPoints);
36
+ t.length === 1 && (r.outfile || e.outfile) ? l[0] = {
35
37
  in: typeof t[0] == "string" ? t[0] : t[0].in,
36
38
  out: r.outfile || e.outfile
37
39
  } : t.map(
@@ -40,7 +42,7 @@ const E = (l) => {
40
42
  out: f.basename(i).split(".")[0]
41
43
  }
42
44
  ).forEach((i) => {
43
- o.push({
45
+ l.push({
44
46
  in: i.in,
45
47
  out: `${e.outdir}/${i.out}.d.ts`
46
48
  });
@@ -49,55 +51,62 @@ const E = (l) => {
49
51
  },
50
52
  rollup: {
51
53
  buildStart(e) {
52
- Array.isArray(e.input) ? e.input.forEach((r, t) => o.push({
54
+ Array.isArray(e.input) ? e.input.length === 1 ? e.input.forEach((r, t) => l.push({
55
+ in: r,
56
+ out: n.outFile ?? `${t}`
57
+ })) : e.input.forEach((r, t) => l.push({
53
58
  in: r,
54
- out: `${t}`
55
- })) : Object.entries(e.input).forEach(([r, t]) => o.push({
59
+ out: n.outDir ? `${n.outDir}/${f.basename(r).split(".")[0]}.d.ts` : `${t}`
60
+ })) : Object.entries(e.input).forEach(([r, t]) => l.push({
56
61
  in: t,
57
- out: r
62
+ out: n.outDir ? `${n.outDir}/${f.basename(t).split(".")[0]}.d.ts` : r
58
63
  }));
59
64
  },
60
65
  outputOptions(e) {
61
- const r = l;
62
- n.length === 1 && (r.file || e.file) ? n[0].outFile = r.file ?? e.file.replace(/\.js$/, ".d.ts") : n.forEach((t, i) => {
63
- const s = `${f.basename(t.entryPointConfig.filePath).split(".")[0]}.d.ts`;
64
- n[i].outFile = `${e.dir}/${s}`;
66
+ if (o.length === 0) {
67
+ n.outFile = e.file, n.outDir = e.dir;
68
+ return;
69
+ }
70
+ const r = s;
71
+ o.length === 1 && (r.file || e.file) ? o[0].outFile = r.file ?? e.file.replace(/\.js$/, ".d.ts") : o.forEach((t, i) => {
72
+ const u = `${f.basename(t.entryPointConfig.filePath).split(".")[0]}.d.ts`;
73
+ o[i].outFile = `${e.dir}/${u}`;
65
74
  });
66
75
  }
67
76
  },
68
77
  vite: {
69
78
  configResolved(e) {
70
- const r = l;
79
+ const r = s;
71
80
  if (e.build.lib) {
72
81
  const t = (i = "default") => typeof r.fileName == "string" ? `${e.build.outDir}/${r.fileName}` : `${e.build.outDir}/${r.fileName(i)}`;
73
- typeof e.build.lib.entry == "string" ? o.push({
82
+ typeof e.build.lib.entry == "string" ? l.push({
74
83
  in: e.build.lib.entry,
75
84
  out: t()
76
- }) : Array.isArray(e.build.lib.entry) ? e.build.lib.entry.forEach((i, s) => o.push({
85
+ }) : Array.isArray(e.build.lib.entry) ? e.build.lib.entry.forEach((i, u) => l.push({
77
86
  in: i,
78
- out: t(`${s}`)
79
- })) : Object.entries(e.build.lib.entry).forEach(([i, s]) => o.push({
80
- in: s,
87
+ out: t(`${u}`)
88
+ })) : Object.entries(e.build.lib.entry).forEach(([i, u]) => l.push({
89
+ in: u,
81
90
  out: t(i)
82
91
  }));
83
92
  }
84
- a.outDir = e.build.outDir;
93
+ n.outDir = e.build.outDir;
85
94
  },
86
95
  closeBundle() {
87
- const e = n.length.toString();
96
+ const e = o.length.toString();
88
97
  this.environment.logger.info(`
89
- ${u.green("✓")} ${e} declaration bundles generated.`);
90
- const r = Math.max(...n.map((i) => i.outFile.length)), t = {
98
+ ${a.green("✓")} ${e} declaration bundles generated.`);
99
+ const r = Math.max(...o.map((i) => i.outFile.length)), t = {
91
100
  maximumFractionDigits: 2,
92
101
  minimumFractionDigits: 2
93
102
  };
94
- n.forEach((i) => this.environment.logger.info(
95
- u.dim(`${a.outDir}`) + u.cyan(i.outFile.replace(a.outDir ?? "", "")) + " ".repeat(r - i.outFile.length + 2) + u.gray(`${(i.size / 1e3).toLocaleString("en", t)} kB`) + u.dim(` │ gzip: ${(i.compressedSize / 1e3).toLocaleString("en", t)} kB`)
103
+ o.forEach((i) => this.environment.logger.info(
104
+ a.dim(`${n.outDir}`) + a.cyan(i.outFile.replace(n.outDir ?? "", "")) + " ".repeat(r - i.outFile.length + 2) + a.gray(`${(i.size / 1e3).toLocaleString("en", t)} kB`) + a.dim(` │ gzip: ${(i.compressedSize / 1e3).toLocaleString("en", t)} kB`)
96
105
  ));
97
106
  }
98
107
  }
99
108
  };
100
109
  };
101
110
  export {
102
- E as u
111
+ F as u
103
112
  };
@@ -0,0 +1 @@
1
+ "use strict";const n=require("unplugin"),o=require("./factory.cjs.js"),r=n.createRolldownPlugin(o.unpluginFactory);module.exports=r;
@@ -0,0 +1,17 @@
1
+ import { CompilationOptions, EntryPointConfig } from 'dts-bundle-generator';
2
+
3
+ export interface DtsBundleGeneratorOptions {
4
+ output?: EntryPointConfig["output"];
5
+ libraries?: EntryPointConfig["libraries"];
6
+ compilation?: CompilationOptions;
7
+ }
8
+ export interface OptionsForRolldown extends DtsBundleGeneratorOptions {
9
+ file?: string;
10
+ }
11
+ declare const _default: (options: OptionsForRolldown) => any;
12
+
13
+ export {
14
+ _default as default,
15
+ };
16
+
17
+ export {};
@@ -0,0 +1,6 @@
1
+ import { createRolldownPlugin as o } from "unplugin";
2
+ import { u as r } from "./factory.es.js";
3
+ const n = o(r);
4
+ export {
5
+ n as default
6
+ };
package/dist/rollup.d.ts CHANGED
@@ -5,10 +5,10 @@ export interface DtsBundleGeneratorOptions {
5
5
  libraries?: EntryPointConfig["libraries"];
6
6
  compilation?: CompilationOptions;
7
7
  }
8
- export interface RollupOptions extends DtsBundleGeneratorOptions {
8
+ export interface OptionsForRollup extends DtsBundleGeneratorOptions {
9
9
  file?: string;
10
10
  }
11
- declare const _default: (options: RollupOptions) => import("rollup").Plugin<any> | import("rollup").Plugin<any>[];
11
+ declare const _default: (options: OptionsForRollup) => import("rollup").Plugin<any> | import("rollup").Plugin<any>[];
12
12
 
13
13
  export {
14
14
  _default as default,
package/dist/vite.d.ts CHANGED
@@ -5,10 +5,10 @@ export interface DtsBundleGeneratorOptions {
5
5
  libraries?: EntryPointConfig["libraries"];
6
6
  compilation?: CompilationOptions;
7
7
  }
8
- export interface ViteOptions extends DtsBundleGeneratorOptions {
8
+ export interface OptionsForVite extends DtsBundleGeneratorOptions {
9
9
  fileName: string | ((entryName: string) => string);
10
10
  }
11
- declare const _default: (options: ViteOptions) => import("vite").Plugin<any> | import("vite").Plugin<any>[];
11
+ declare const _default: (options: OptionsForVite) => import("vite").Plugin<any> | import("vite").Plugin<any>[];
12
12
 
13
13
  export {
14
14
  _default as default,
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "unplugin-dts-bundle-generator",
3
- "version": "3.2.0",
3
+ "version": "3.3.0",
4
4
  "description": "DTS bundle generator for Unplugin",
5
5
  "keywords": [
6
6
  "unplugin",
7
- "vite",
8
- "webpack",
7
+ "esbuild",
8
+ "rolldown",
9
9
  "rollup",
10
+ "vite",
10
11
  "dts",
11
12
  "bundle",
12
13
  "typescript"
@@ -29,6 +30,11 @@
29
30
  "import": "./dist/esbuild.es.js",
30
31
  "require": "./dist/esbuild.cjs.js"
31
32
  },
33
+ "./rolldown": {
34
+ "types": "./dist/rolldown.d.ts",
35
+ "import": "./dist/rolldown.es.js",
36
+ "require": "./dist/rolldown.cjs.js"
37
+ },
32
38
  "./rollup": {
33
39
  "types": "./dist/rollup.d.ts",
34
40
  "import": "./dist/rollup.es.js",
@@ -51,6 +57,7 @@
51
57
  "lint:ci": "eslint . && sort-package-json --check",
52
58
  "prepack": "npm run clean && npm run build",
53
59
  "test:esbuild": "npm run build & rimraf dist-esbuild & node ./test/esbuild.config.ts",
60
+ "test:rolldown": "npm run build & rimraf dist-rollup & rolldown --config ./test/rollup.config.ts",
54
61
  "test:rollup": "npm run build & rimraf dist-rollup & rollup --config ./test/rollup.config.ts",
55
62
  "typecheck": "tsc --noEmit",
56
63
  "typecheck:ci": "tsc --noEmit",
@@ -70,6 +77,7 @@
70
77
  "eslint": "^9.12.0",
71
78
  "jiti": "^2.4.2",
72
79
  "rimraf": "^6.0.1",
80
+ "rolldown": "^1.0.0-beta.32",
73
81
  "rollup": "^4.41.0",
74
82
  "sort-package-json": "^3.3.1",
75
83
  "tslib": "^2.8.1",