unplugin-dts-bundle-generator 3.1.1 → 3.2.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
@@ -5,8 +5,9 @@
5
5
  [![Licence](https://img.shields.io/npm/l/unplugin-dts-bundle-generator)](./LICENCE)
6
6
  [![GitHub Actions](https://img.shields.io/github/actions/workflow/status/f-lawe/unplugin-dts-bundle-generator/pr-checks.yml)](https://github.com/f-lawe/unplugin-dts-bundle-generator/actions/workflows/pr-checks.yml)
7
7
 
8
- Ever wanted to easily package your typescript library with a bundled declaration file? Integrate [DTS Bundle Generator](https://github.com/timocov/dts-bundle-generator) within [Vite](https://github.com/vitejs/vite) or any other blundler supported by [Unplugin](https://github.com/unjs/unplugin)!
9
- (see available bundlers below)
8
+ Ever wanted to easily package your typescript library with a bundled declaration file? Integrate [DTS Bundle Generator](https://github.com/timocov/dts-bundle-generator) within your favourite bundler thanks to [Unplugin](https://github.com/unjs/unplugin)!
9
+
10
+ _(see available bundlers below)_
10
11
 
11
12
  ## Installation
12
13
  ```sh
@@ -18,22 +19,28 @@ yarn add --dev unplugin-dts-bundle-generator
18
19
  ```
19
20
 
20
21
  ## Usage
21
- Currently, only Vite and Rollup are fully supported, more bundlers to come. 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!
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.
22
30
 
23
31
  <details>
24
- <summary>Vite</summary><br>
32
+ <summary>ESBuild</summary><br>
25
33
 
26
- With Vite, add this block to your `vite.config.ts`:
34
+ With ESBuild, add this block when calling `esbuild.build()`:
27
35
 
28
36
  ```ts
29
- import path from 'node:path';
30
- import dtsBundleGenerator from 'unplugin-dts-bundle-generator/vite';
31
- import { defineConfig, normalizePath } from 'vite';
37
+ import * as esbuild from 'esbuild';
38
+ import dtsBundleGenerator from 'unplugin-dts-bundle-generator/rollup';
32
39
 
33
- export default defineConfig({
40
+ await esbuild.build({
34
41
  plugins: [
35
42
  dtsBundleGenerator({
36
- fileName: 'my-lib.d.ts',
43
+ outfile: 'my-lib.d.ts',
37
44
  output: {
38
45
  // output config
39
46
  },
@@ -43,15 +50,12 @@ export default defineConfig({
43
50
  compilation: {
44
51
  // compilation options
45
52
  }
46
- })
53
+ }),
47
54
  ],
48
- build: {
49
- lib: {
50
- entry: normalizePath('src/index.ts'),
51
- formats: ['es'],
52
- fileName: 'my-lib.js'
53
- }
54
- }
55
+ entryPoints: 'src/index.ts',
56
+ outfile: 'my-lib.js',
57
+ format: 'esm',
58
+ bundle: true,
55
59
  });
56
60
  ```
57
61
  <br></details>
@@ -67,7 +71,7 @@ import dtsBundleGenerator from 'unplugin-dts-bundle-generator/rollup';
67
71
  export default {
68
72
  plugins: [
69
73
  dtsBundleGenerator({
70
- fileName: 'my-lib.d.ts',
74
+ file: 'my-lib.d.ts',
71
75
  output: {
72
76
  // output config
73
77
  },
@@ -88,6 +92,42 @@ export default {
88
92
  ```
89
93
  <br></details>
90
94
 
95
+ <details>
96
+ <summary>Vite</summary><br>
97
+
98
+ With Vite, add this block to your `vite.config.ts`:
99
+
100
+ ```ts
101
+ import path from 'node:path';
102
+ import dtsBundleGenerator from 'unplugin-dts-bundle-generator/vite';
103
+ import { defineConfig, normalizePath } from 'vite';
104
+
105
+ export default defineConfig({
106
+ plugins: [
107
+ dtsBundleGenerator({
108
+ fileName: 'my-lib.d.ts',
109
+ output: {
110
+ // output config
111
+ },
112
+ libraries: {
113
+ // libraries config
114
+ },
115
+ compilation: {
116
+ // compilation options
117
+ }
118
+ })
119
+ ],
120
+ build: {
121
+ lib: {
122
+ entry: normalizePath('src/index.ts'),
123
+ formats: ['es'],
124
+ fileName: 'my-lib.js'
125
+ }
126
+ }
127
+ });
128
+ ```
129
+ <br></details>
130
+
91
131
  ## Configuration
92
132
 
93
133
  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.
@@ -1,11 +1,20 @@
1
1
  import { CompilationOptions, EntryPointConfig } from 'dts-bundle-generator';
2
2
 
3
- export interface Options {
4
- fileName: string | ((entryName: string) => string);
3
+ export interface DtsBundleGeneratorOptions {
5
4
  output?: EntryPointConfig["output"];
6
5
  libraries?: EntryPointConfig["libraries"];
7
6
  compilation?: CompilationOptions;
8
7
  }
8
+ export interface ESBuildOptions extends DtsBundleGeneratorOptions {
9
+ outfile?: string;
10
+ }
11
+ export interface RollupOptions extends DtsBundleGeneratorOptions {
12
+ file?: string;
13
+ }
14
+ export interface ViteOptions extends DtsBundleGeneratorOptions {
15
+ fileName: string | ((entryName: string) => string);
16
+ }
17
+ export type Options = ESBuildOptions | RollupOptions | ViteOptions;
9
18
  declare const _default: import("unplugin").UnpluginInstance<Options, false>;
10
19
 
11
20
  export {
@@ -0,0 +1 @@
1
+ "use strict";const u=require("unplugin"),e=require("./factory.cjs.js"),r=u.createEsbuildPlugin(e.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 ESBuildOptions extends DtsBundleGeneratorOptions {
9
+ outfile?: string;
10
+ }
11
+ declare const _default: (options: ESBuildOptions) => import("esbuild").Plugin;
12
+
13
+ export {
14
+ _default as default,
15
+ };
16
+
17
+ export {};
@@ -0,0 +1,6 @@
1
+ import { createEsbuildPlugin as o } from "unplugin";
2
+ import { u as r } from "./factory.es.js";
3
+ const i = o(r);
4
+ export {
5
+ i as default
6
+ };
@@ -1,2 +1,2 @@
1
- "use strict";const f=require("node:buffer"),m=require("node:fs"),u=require("node:path"),d=require("node:zlib"),b=require("dts-bundle-generator"),s=require("picocolors"),c=(i,t)=>{typeof t=="string"?Object.assign(i,{default:t}):Array.isArray(t)?t.forEach(r=>{Object.assign(i,{[u.basename(r,u.extname(r))]:r})}):Object.assign(i,t)},h=i=>{const t=[],r={},l={},g=typeof i.fileName=="string"?()=>i.fileName:i.fileName;return{name:"unplugin-dts-bundle-generator",buildEnd(){const e=Object.values(r).map(n=>({filePath:n,libraries:i.libraries,output:i.output}));b.generateDtsBundle(e,i.compilation).forEach((n,a)=>t.push({compressedSize:d.gzipSync(n).length,content:n,outFile:g(Object.keys(r)[a]),size:f.Buffer.byteLength(n)}))},writeBundle(){t.forEach(e=>m.writeFileSync(u.resolve(l.outDir??"",e.outFile),e.content))},rollup:{buildStart(e){c(r,e.input)},outputOptions(e){return l.outDir=e.dir,e}},vite:{configResolved(e){e.build.lib&&c(r,e.build.lib.entry),l.outDir=e.build.outDir},closeBundle(){const e=t.length.toString();this.environment.logger.info(`
2
- ${s.green("✓")} ${e} declaration bundles generated.`);const n={maximumFractionDigits:2,minimumFractionDigits:2},a=Math.max(...t.map(o=>o.outFile.length));t.forEach(o=>this.environment.logger.info(s.dim(`${l.outDir}/`)+s.cyan(`${o.outFile}`)+" ".repeat(a-o.outFile.length+2)+s.gray(`${(o.size/1e3).toLocaleString("en",n)} kB`)+s.dim(`gzip: ${(o.compressedSize/1e3).toLocaleString("en",n)} kB`)))}}}};exports.unpluginFactory=h;
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,67 +1,103 @@
1
1
  import { Buffer as c } from "node:buffer";
2
- import f from "node:fs";
3
- import m from "node:path";
4
- import d from "node:zlib";
5
- import { generateDtsBundle as b } from "dts-bundle-generator";
6
- import l from "picocolors";
7
- const u = (i, t) => {
8
- typeof t == "string" ? Object.assign(i, {
9
- default: t
10
- }) : Array.isArray(t) ? t.forEach((r) => {
11
- Object.assign(i, {
12
- [m.basename(r, m.extname(r))]: r
13
- });
14
- }) : Object.assign(i, t);
15
- }, z = (i) => {
16
- const t = [], r = {}, s = {}, g = typeof i.fileName == "string" ? () => i.fileName : i.fileName;
2
+ import m from "node:fs";
3
+ import f from "node:path";
4
+ import h from "node:zlib";
5
+ import { generateDtsBundle as g } from "dts-bundle-generator";
6
+ import u from "picocolors";
7
+ const E = (l) => {
8
+ const a = {}, n = [], o = [];
17
9
  return {
18
10
  name: "unplugin-dts-bundle-generator",
19
11
  buildEnd() {
20
- const e = Object.values(r).map((o) => ({
21
- filePath: o,
22
- libraries: i.libraries,
23
- output: i.output
24
- }));
25
- b(e, i.compilation).forEach((o, a) => t.push({
26
- compressedSize: d.gzipSync(o).length,
27
- content: o,
28
- outFile: g(Object.keys(r)[a]),
29
- size: c.byteLength(o)
12
+ o.forEach((e) => n.push({
13
+ entryPointConfig: {
14
+ filePath: e.in,
15
+ libraries: l.libraries,
16
+ output: l.output
17
+ },
18
+ outFile: e.out,
19
+ size: -1,
20
+ compressedSize: -1
30
21
  }));
31
22
  },
32
23
  writeBundle() {
33
- t.forEach((e) => f.writeFileSync(
34
- m.resolve(s.outDir ?? "", e.outFile),
35
- e.content
36
- ));
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;
27
+ });
28
+ },
29
+ esbuild: {
30
+ config(e) {
31
+ if (!e.entryPoints)
32
+ 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
+ in: typeof t[0] == "string" ? t[0] : t[0].in,
36
+ out: r.outfile || e.outfile
37
+ } : t.map(
38
+ (i) => typeof i != "string" ? i : {
39
+ in: i,
40
+ out: f.basename(i).split(".")[0]
41
+ }
42
+ ).forEach((i) => {
43
+ o.push({
44
+ in: i.in,
45
+ out: `${e.outdir}/${i.out}.d.ts`
46
+ });
47
+ });
48
+ }
37
49
  },
38
50
  rollup: {
39
51
  buildStart(e) {
40
- u(r, e.input);
52
+ Array.isArray(e.input) ? e.input.forEach((r, t) => o.push({
53
+ in: r,
54
+ out: `${t}`
55
+ })) : Object.entries(e.input).forEach(([r, t]) => o.push({
56
+ in: t,
57
+ out: r
58
+ }));
41
59
  },
42
60
  outputOptions(e) {
43
- return s.outDir = e.dir, 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}`;
65
+ });
44
66
  }
45
67
  },
46
68
  vite: {
47
69
  configResolved(e) {
48
- e.build.lib && u(r, e.build.lib.entry), s.outDir = e.build.outDir;
70
+ const r = l;
71
+ if (e.build.lib) {
72
+ 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({
74
+ in: e.build.lib.entry,
75
+ out: t()
76
+ }) : Array.isArray(e.build.lib.entry) ? e.build.lib.entry.forEach((i, s) => o.push({
77
+ in: i,
78
+ out: t(`${s}`)
79
+ })) : Object.entries(e.build.lib.entry).forEach(([i, s]) => o.push({
80
+ in: s,
81
+ out: t(i)
82
+ }));
83
+ }
84
+ a.outDir = e.build.outDir;
49
85
  },
50
86
  closeBundle() {
51
- const e = t.length.toString();
87
+ const e = n.length.toString();
52
88
  this.environment.logger.info(`
53
- ${l.green("✓")} ${e} declaration bundles generated.`);
54
- const o = {
89
+ ${u.green("✓")} ${e} declaration bundles generated.`);
90
+ const r = Math.max(...n.map((i) => i.outFile.length)), t = {
55
91
  maximumFractionDigits: 2,
56
92
  minimumFractionDigits: 2
57
- }, a = Math.max(...t.map((n) => n.outFile.length));
58
- t.forEach((n) => this.environment.logger.info(
59
- l.dim(`${s.outDir}/`) + l.cyan(`${n.outFile}`) + " ".repeat(a - n.outFile.length + 2) + l.gray(`${(n.size / 1e3).toLocaleString("en", o)} kB`) + l.dim(`gzip: ${(n.compressedSize / 1e3).toLocaleString("en", o)} kB`)
93
+ };
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`)
60
96
  ));
61
97
  }
62
98
  }
63
99
  };
64
100
  };
65
101
  export {
66
- z as u
102
+ E as u
67
103
  };
package/dist/rollup.d.ts CHANGED
@@ -1,12 +1,14 @@
1
1
  import { CompilationOptions, EntryPointConfig } from 'dts-bundle-generator';
2
2
 
3
- export interface Options {
4
- fileName: string | ((entryName: string) => string);
3
+ export interface DtsBundleGeneratorOptions {
5
4
  output?: EntryPointConfig["output"];
6
5
  libraries?: EntryPointConfig["libraries"];
7
6
  compilation?: CompilationOptions;
8
7
  }
9
- declare const _default: (options: Options) => import("rollup").Plugin<any> | import("rollup").Plugin<any>[];
8
+ export interface RollupOptions extends DtsBundleGeneratorOptions {
9
+ file?: string;
10
+ }
11
+ declare const _default: (options: RollupOptions) => import("rollup").Plugin<any> | import("rollup").Plugin<any>[];
10
12
 
11
13
  export {
12
14
  _default as default,
package/dist/vite.d.ts CHANGED
@@ -1,12 +1,14 @@
1
1
  import { CompilationOptions, EntryPointConfig } from 'dts-bundle-generator';
2
2
 
3
- export interface Options {
4
- fileName: string | ((entryName: string) => string);
3
+ export interface DtsBundleGeneratorOptions {
5
4
  output?: EntryPointConfig["output"];
6
5
  libraries?: EntryPointConfig["libraries"];
7
6
  compilation?: CompilationOptions;
8
7
  }
9
- declare const _default: (options: Options) => import("vite").Plugin<any> | import("vite").Plugin<any>[];
8
+ export interface ViteOptions extends DtsBundleGeneratorOptions {
9
+ fileName: string | ((entryName: string) => string);
10
+ }
11
+ declare const _default: (options: ViteOptions) => import("vite").Plugin<any> | import("vite").Plugin<any>[];
10
12
 
11
13
  export {
12
14
  _default as default,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "unplugin-dts-bundle-generator",
3
- "version": "3.1.1",
3
+ "version": "3.2.0",
4
4
  "description": "DTS bundle generator for Unplugin",
5
5
  "keywords": [
6
6
  "unplugin",
@@ -11,7 +11,10 @@
11
11
  "bundle",
12
12
  "typescript"
13
13
  ],
14
- "repository": "https://github.com/f-lawe/unplugin-dts-bundle-generator",
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "git+https://github.com/f-lawe/unplugin-dts-bundle-generator.git"
17
+ },
15
18
  "license": "MIT",
16
19
  "author": "François Lavaud-Wernert <francois@lavaud.family>",
17
20
  "type": "module",
@@ -21,6 +24,11 @@
21
24
  "import": "./dist/dts-bundle-generator.es.js",
22
25
  "require": "./dist/dts-bundle-generator.cjs.js"
23
26
  },
27
+ "./esbuild": {
28
+ "types": "./dist/esbuild.d.ts",
29
+ "import": "./dist/esbuild.es.js",
30
+ "require": "./dist/esbuild.cjs.js"
31
+ },
24
32
  "./rollup": {
25
33
  "types": "./dist/rollup.d.ts",
26
34
  "import": "./dist/rollup.es.js",
@@ -37,13 +45,13 @@
37
45
  "source": "src/index.ts",
38
46
  "types": "dist/dts-bundle-generator.d.ts",
39
47
  "scripts": {
40
- "build": "npm run build:vite",
41
- "build:rollup": "npm run build:vite & rollup --config rollup.config.ts",
42
- "build:vite": "vite build",
48
+ "build": "vite build",
43
49
  "clean": "rimraf dist",
44
50
  "lint": "eslint . --fix && sort-package-json",
45
51
  "lint:ci": "eslint . && sort-package-json --check",
46
52
  "prepack": "npm run clean && npm run build",
53
+ "test:esbuild": "npm run build & rimraf dist-esbuild & node ./test/esbuild.config.ts",
54
+ "test:rollup": "npm run build & rimraf dist-rollup & rollup --config ./test/rollup.config.ts",
47
55
  "typecheck": "tsc --noEmit",
48
56
  "typecheck:ci": "tsc --noEmit",
49
57
  "watch": "vite build --watch"
@@ -58,11 +66,11 @@
58
66
  "@nuxt/schema": "^3.17.4",
59
67
  "@rollup/plugin-typescript": "^12.1.4",
60
68
  "@types/node": "^24.0.4",
69
+ "esbuild": "^0.25.8",
61
70
  "eslint": "^9.12.0",
62
71
  "jiti": "^2.4.2",
63
72
  "rimraf": "^6.0.1",
64
73
  "rollup": "^4.41.0",
65
- "rollup-plugin-node-externals": "^8.0.0",
66
74
  "sort-package-json": "^3.3.1",
67
75
  "tslib": "^2.8.1",
68
76
  "typescript": "^5.0.2",