unplugin-dts-bundle-generator 3.0.0 → 3.1.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 +38 -6
- package/dist/dts-bundle-generator.cjs.js +1 -0
- package/dist/dts-bundle-generator.es.js +6 -0
- package/dist/factory.cjs.js +2 -0
- package/dist/factory.es.js +67 -0
- package/dist/rollup.cjs.js +1 -0
- package/dist/rollup.d.ts +15 -0
- package/dist/rollup.es.js +6 -0
- package/dist/vite.cjs.js +1 -0
- package/dist/{vite.mjs → vite.es.js} +1 -2
- package/dist-rollup/factory.es.js +82 -0
- package/dist-rollup/index.d.ts +15 -0
- package/dist-rollup/index.js +12 -0
- package/dist-rollup/rollup.d.ts +15 -0
- package/dist-rollup/rollup.js +12 -0
- package/dist-rollup/vite.d.ts +15 -0
- package/dist-rollup/vite.js +12 -0
- package/package.json +16 -7
- package/dist/dts-bundle-generator.cjs +0 -2
- package/dist/dts-bundle-generator.cjs.map +0 -1
- package/dist/dts-bundle-generator.mjs +0 -7
- package/dist/dts-bundle-generator.mjs.map +0 -1
- package/dist/factory-D34KlQ_a.js +0 -57
- package/dist/factory-D34KlQ_a.js.map +0 -1
- package/dist/factory-v7XFnpMY.cjs +0 -3
- package/dist/factory-v7XFnpMY.cjs.map +0 -1
- package/dist/vite.cjs +0 -2
- package/dist/vite.cjs.map +0 -1
- package/dist/vite.mjs.map +0 -1
package/README.md
CHANGED
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
[](./LICENCE)
|
|
6
6
|
[](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)!
|
|
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)
|
|
9
10
|
|
|
10
11
|
## Installation
|
|
11
12
|
```sh
|
|
@@ -17,6 +18,10 @@ yarn add --dev unplugin-dts-bundle-generator
|
|
|
17
18
|
```
|
|
18
19
|
|
|
19
20
|
## 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
|
+
|
|
23
|
+
<details>
|
|
24
|
+
<summary>Vite</summary><br>
|
|
20
25
|
With Vite, add this block to your `vite.config.ts`:
|
|
21
26
|
|
|
22
27
|
```ts
|
|
@@ -41,19 +46,46 @@ export default defineConfig({
|
|
|
41
46
|
],
|
|
42
47
|
build: {
|
|
43
48
|
lib: {
|
|
44
|
-
entry: normalizePath(
|
|
49
|
+
entry: normalizePath('src/index.ts'),
|
|
45
50
|
formats: ['es'],
|
|
46
51
|
fileName: 'my-lib.js'
|
|
47
52
|
}
|
|
48
53
|
}
|
|
49
54
|
});
|
|
50
55
|
```
|
|
56
|
+
<br></details>
|
|
57
|
+
|
|
58
|
+
<details>
|
|
59
|
+
<summary>Rollup</summary><br>
|
|
60
|
+
With Rollup, add this block to your `rollup.config.ts`:
|
|
51
61
|
|
|
52
|
-
|
|
62
|
+
```ts
|
|
63
|
+
import dtsBundleGenerator from 'unplugin-dts-bundle-generator/rollup';
|
|
64
|
+
|
|
65
|
+
export default {
|
|
66
|
+
plugins: [
|
|
67
|
+
dtsBundleGenerator({
|
|
68
|
+
fileName: 'my-lib.d.ts',
|
|
69
|
+
output: {
|
|
70
|
+
// output config
|
|
71
|
+
},
|
|
72
|
+
libraries: {
|
|
73
|
+
// libraries config
|
|
74
|
+
},
|
|
75
|
+
compilation: {
|
|
76
|
+
// compilation options
|
|
77
|
+
}
|
|
78
|
+
}),
|
|
79
|
+
],
|
|
80
|
+
input: 'src/index.ts',
|
|
81
|
+
output: {
|
|
82
|
+
dir: 'dist',
|
|
83
|
+
format: 'es',
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
```
|
|
87
|
+
<br></details>
|
|
53
88
|
|
|
54
89
|
## Configuration
|
|
55
90
|
|
|
56
91
|
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.
|
|
57
|
-
|
|
58
|
-
## Disclaimer
|
|
59
|
-
As this package is originally a Vite plugin, that's the only available export and supported bundler. Please open a PR or an issue if you need another export, so we can work it out.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const n=require("unplugin"),e=require("./factory.cjs.js"),r=n.createUnplugin(e.unpluginFactory);module.exports=r;
|
|
@@ -0,0 +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;
|
|
@@ -0,0 +1,67 @@
|
|
|
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;
|
|
17
|
+
return {
|
|
18
|
+
name: "unplugin-dts-bundle-generator",
|
|
19
|
+
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)
|
|
30
|
+
}));
|
|
31
|
+
},
|
|
32
|
+
writeBundle() {
|
|
33
|
+
t.forEach((e) => f.writeFileSync(
|
|
34
|
+
m.resolve(s.outDir ?? "", e.outFile),
|
|
35
|
+
e.content
|
|
36
|
+
));
|
|
37
|
+
},
|
|
38
|
+
rollup: {
|
|
39
|
+
buildStart(e) {
|
|
40
|
+
u(r, e.input);
|
|
41
|
+
},
|
|
42
|
+
outputOptions(e) {
|
|
43
|
+
return s.outDir = e.dir, e;
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
vite: {
|
|
47
|
+
configResolved(e) {
|
|
48
|
+
e.build.lib && u(r, e.build.lib.entry), s.outDir = e.build.outDir;
|
|
49
|
+
},
|
|
50
|
+
closeBundle() {
|
|
51
|
+
const e = t.length.toString();
|
|
52
|
+
this.environment.logger.info(`
|
|
53
|
+
${l.green("✓")} ${e} declaration bundles generated.`);
|
|
54
|
+
const o = {
|
|
55
|
+
maximumFractionDigits: 2,
|
|
56
|
+
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`)
|
|
60
|
+
));
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
export {
|
|
66
|
+
z as u
|
|
67
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const r=require("unplugin"),u=require("./factory.cjs.js"),t=r.createRollupPlugin(u.unpluginFactory);module.exports=t;
|
package/dist/rollup.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { CompilationOptions, EntryPointConfig } from 'dts-bundle-generator';
|
|
2
|
+
|
|
3
|
+
export interface Options {
|
|
4
|
+
fileName: string | ((entryName: string) => string);
|
|
5
|
+
output?: EntryPointConfig["output"];
|
|
6
|
+
libraries?: EntryPointConfig["libraries"];
|
|
7
|
+
compilation?: CompilationOptions;
|
|
8
|
+
}
|
|
9
|
+
declare const _default: (options: Options) => import("rollup").Plugin<any> | import("rollup").Plugin<any>[];
|
|
10
|
+
|
|
11
|
+
export {
|
|
12
|
+
_default as default,
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export {};
|
package/dist/vite.cjs.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const t=require("unplugin"),e=require("./factory.cjs.js"),r=t.createVitePlugin(e.unpluginFactory);module.exports=r;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { Buffer } from 'node:buffer';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import zlib from 'node:zlib';
|
|
5
|
+
import { generateDtsBundle } from 'dts-bundle-generator';
|
|
6
|
+
import colors from 'picocolors';
|
|
7
|
+
|
|
8
|
+
const assignEntry = (entry, input) => {
|
|
9
|
+
if (typeof input == 'string') {
|
|
10
|
+
Object.assign(entry, {
|
|
11
|
+
default: input,
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
else if (Array.isArray(input)) {
|
|
15
|
+
input.forEach((i) => {
|
|
16
|
+
Object.assign(entry, {
|
|
17
|
+
[path.basename(i, path.extname(i))]: i,
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
Object.assign(entry, input);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
const unpluginFactory = (options) => {
|
|
26
|
+
const bundles = [];
|
|
27
|
+
const entry = {};
|
|
28
|
+
const buildConfig = {};
|
|
29
|
+
const fileName = typeof options.fileName == 'string' ? () => options.fileName : options.fileName;
|
|
30
|
+
return {
|
|
31
|
+
name: 'unplugin-dts-bundle-generator',
|
|
32
|
+
buildEnd() {
|
|
33
|
+
const entryPointConfigs = Object.values(entry).map((entryPath) => ({
|
|
34
|
+
filePath: entryPath,
|
|
35
|
+
libraries: options.libraries,
|
|
36
|
+
output: options.output,
|
|
37
|
+
}));
|
|
38
|
+
generateDtsBundle(entryPointConfigs, options.compilation).forEach((content, i) => bundles.push({
|
|
39
|
+
compressedSize: zlib.gzipSync(content).length,
|
|
40
|
+
content,
|
|
41
|
+
outFile: fileName(Object.keys(entry)[i]),
|
|
42
|
+
size: Buffer.byteLength(content),
|
|
43
|
+
}));
|
|
44
|
+
},
|
|
45
|
+
writeBundle() {
|
|
46
|
+
bundles.forEach((bundle) => fs.writeFileSync(path.resolve(buildConfig.outDir ?? '', bundle.outFile), bundle.content));
|
|
47
|
+
},
|
|
48
|
+
rollup: {
|
|
49
|
+
buildStart(options) {
|
|
50
|
+
assignEntry(entry, options.input);
|
|
51
|
+
},
|
|
52
|
+
outputOptions(outputOptions) {
|
|
53
|
+
buildConfig.outDir = outputOptions.dir;
|
|
54
|
+
return outputOptions;
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
vite: {
|
|
58
|
+
configResolved(config) {
|
|
59
|
+
if (config.build.lib) {
|
|
60
|
+
assignEntry(entry, config.build.lib.entry);
|
|
61
|
+
}
|
|
62
|
+
buildConfig.outDir = config.build.outDir;
|
|
63
|
+
},
|
|
64
|
+
closeBundle() {
|
|
65
|
+
const length = bundles.length.toString();
|
|
66
|
+
this.environment.logger.info(`\n${colors.green('✓')} ${length} declaration bundles generated.`);
|
|
67
|
+
const options = {
|
|
68
|
+
maximumFractionDigits: 2,
|
|
69
|
+
minimumFractionDigits: 2,
|
|
70
|
+
};
|
|
71
|
+
const outFileLength = Math.max(...bundles.map((bundle) => bundle.outFile.length));
|
|
72
|
+
bundles.forEach((bundle) => this.environment.logger.info(colors.dim(`${buildConfig.outDir}/`)
|
|
73
|
+
+ colors.cyan(`${bundle.outFile}`)
|
|
74
|
+
+ ' '.repeat(outFileLength - bundle.outFile.length + 2)
|
|
75
|
+
+ colors.gray(`${(bundle.size / 1000).toLocaleString('en', options)} kB │ `)
|
|
76
|
+
+ colors.dim(`gzip: ${(bundle.compressedSize / 1000).toLocaleString('en', options)} kB`)));
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
export { unpluginFactory as u };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { CompilationOptions, EntryPointConfig } from 'dts-bundle-generator';
|
|
2
|
+
|
|
3
|
+
export interface Options {
|
|
4
|
+
fileName: string | ((entryName: string) => string);
|
|
5
|
+
output?: EntryPointConfig["output"];
|
|
6
|
+
libraries?: EntryPointConfig["libraries"];
|
|
7
|
+
compilation?: CompilationOptions;
|
|
8
|
+
}
|
|
9
|
+
declare const _default: import("unplugin").UnpluginInstance<Options, false>;
|
|
10
|
+
|
|
11
|
+
export {
|
|
12
|
+
_default as default,
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { createUnplugin } from 'unplugin';
|
|
2
|
+
import { u as unpluginFactory } from './factory.es.js';
|
|
3
|
+
import 'node:buffer';
|
|
4
|
+
import 'node:fs';
|
|
5
|
+
import 'node:path';
|
|
6
|
+
import 'node:zlib';
|
|
7
|
+
import 'dts-bundle-generator';
|
|
8
|
+
import 'picocolors';
|
|
9
|
+
|
|
10
|
+
var index = createUnplugin(unpluginFactory);
|
|
11
|
+
|
|
12
|
+
export { index as default };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { CompilationOptions, EntryPointConfig } from 'dts-bundle-generator';
|
|
2
|
+
|
|
3
|
+
export interface Options {
|
|
4
|
+
fileName: string | ((entryName: string) => string);
|
|
5
|
+
output?: EntryPointConfig["output"];
|
|
6
|
+
libraries?: EntryPointConfig["libraries"];
|
|
7
|
+
compilation?: CompilationOptions;
|
|
8
|
+
}
|
|
9
|
+
declare const _default: (options: Options) => import("rollup").Plugin<any> | import("rollup").Plugin<any>[];
|
|
10
|
+
|
|
11
|
+
export {
|
|
12
|
+
_default as default,
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { createRollupPlugin } from 'unplugin';
|
|
2
|
+
import { u as unpluginFactory } from './factory.es.js';
|
|
3
|
+
import 'node:buffer';
|
|
4
|
+
import 'node:fs';
|
|
5
|
+
import 'node:path';
|
|
6
|
+
import 'node:zlib';
|
|
7
|
+
import 'dts-bundle-generator';
|
|
8
|
+
import 'picocolors';
|
|
9
|
+
|
|
10
|
+
var rollup = createRollupPlugin(unpluginFactory);
|
|
11
|
+
|
|
12
|
+
export { rollup as default };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { CompilationOptions, EntryPointConfig } from 'dts-bundle-generator';
|
|
2
|
+
|
|
3
|
+
export interface Options {
|
|
4
|
+
fileName: string | ((entryName: string) => string);
|
|
5
|
+
output?: EntryPointConfig["output"];
|
|
6
|
+
libraries?: EntryPointConfig["libraries"];
|
|
7
|
+
compilation?: CompilationOptions;
|
|
8
|
+
}
|
|
9
|
+
declare const _default: (options: Options) => import("vite").Plugin<any> | import("vite").Plugin<any>[];
|
|
10
|
+
|
|
11
|
+
export {
|
|
12
|
+
_default as default,
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { createVitePlugin } from 'unplugin';
|
|
2
|
+
import { u as unpluginFactory } from './factory.es.js';
|
|
3
|
+
import 'node:buffer';
|
|
4
|
+
import 'node:fs';
|
|
5
|
+
import 'node:path';
|
|
6
|
+
import 'node:zlib';
|
|
7
|
+
import 'dts-bundle-generator';
|
|
8
|
+
import 'picocolors';
|
|
9
|
+
|
|
10
|
+
var vite = createVitePlugin(unpluginFactory);
|
|
11
|
+
|
|
12
|
+
export { vite as default };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "unplugin-dts-bundle-generator",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"description": "DTS bundle generator for Unplugin",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"unplugin",
|
|
@@ -18,13 +18,18 @@
|
|
|
18
18
|
"exports": {
|
|
19
19
|
".": {
|
|
20
20
|
"types": "./dist/dts-bundle-generator.d.ts",
|
|
21
|
-
"import": "./dist/dts-bundle-generator.
|
|
22
|
-
"require": "./dist/dts-bundle-generator.cjs"
|
|
21
|
+
"import": "./dist/dts-bundle-generator.es.js",
|
|
22
|
+
"require": "./dist/dts-bundle-generator.cjs.js"
|
|
23
|
+
},
|
|
24
|
+
"./rollup": {
|
|
25
|
+
"types": "./dist/rollup.d.ts",
|
|
26
|
+
"import": "./dist/rollup.es.js",
|
|
27
|
+
"require": "./dist/rollup.cjs.js"
|
|
23
28
|
},
|
|
24
29
|
"./vite": {
|
|
25
30
|
"types": "./dist/vite.d.ts",
|
|
26
|
-
"import": "./dist/vite.
|
|
27
|
-
"require": "./dist/vite.cjs"
|
|
31
|
+
"import": "./dist/vite.es.js",
|
|
32
|
+
"require": "./dist/vite.cjs.js"
|
|
28
33
|
}
|
|
29
34
|
},
|
|
30
35
|
"main": "dist/dts-bundle-generator.cjs",
|
|
@@ -32,7 +37,9 @@
|
|
|
32
37
|
"source": "src/index.ts",
|
|
33
38
|
"types": "dist/dts-bundle-generator.d.ts",
|
|
34
39
|
"scripts": {
|
|
35
|
-
"build": "
|
|
40
|
+
"build": "npm run build:vite",
|
|
41
|
+
"build:rollup": "npm run build:vite & rollup --config rollup.config.ts",
|
|
42
|
+
"build:vite": "vite build",
|
|
36
43
|
"clean": "rimraf dist",
|
|
37
44
|
"lint": "eslint . --fix && sort-package-json",
|
|
38
45
|
"lint:ci": "eslint . && sort-package-json --check",
|
|
@@ -49,6 +56,7 @@
|
|
|
49
56
|
"@antfu/eslint-config": "^4.16.1",
|
|
50
57
|
"@nuxt/kit": "^3.17.4",
|
|
51
58
|
"@nuxt/schema": "^3.17.4",
|
|
59
|
+
"@rollup/plugin-typescript": "^12.1.4",
|
|
52
60
|
"@types/node": "^24.0.4",
|
|
53
61
|
"eslint": "^9.12.0",
|
|
54
62
|
"jiti": "^2.4.2",
|
|
@@ -56,6 +64,7 @@
|
|
|
56
64
|
"rollup": "^4.41.0",
|
|
57
65
|
"rollup-plugin-node-externals": "^8.0.0",
|
|
58
66
|
"sort-package-json": "^3.3.1",
|
|
67
|
+
"tslib": "^2.8.1",
|
|
59
68
|
"typescript": "^5.0.2",
|
|
60
69
|
"vite": "^7.0.0",
|
|
61
70
|
"webpack": "^5.99.9"
|
|
@@ -64,7 +73,7 @@
|
|
|
64
73
|
"@nuxt/kit": "^3",
|
|
65
74
|
"@nuxt/schema": "^3",
|
|
66
75
|
"esbuild": "*",
|
|
67
|
-
"rollup": "
|
|
76
|
+
"rollup": ">=3",
|
|
68
77
|
"vite": ">=3",
|
|
69
78
|
"webpack": "^4 || ^5"
|
|
70
79
|
},
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dts-bundle-generator.cjs","sources":["../src/index.ts"],"sourcesContent":["import { createUnplugin } from 'unplugin';\n\nimport { unpluginFactory } from './core';\n\nexport default createUnplugin(unpluginFactory);\n"],"names":["index","createUnplugin","unpluginFactory"],"mappings":"6EAIAA,EAAeC,EAAAA,eAAeC,EAAAA,eAAe"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dts-bundle-generator.mjs","sources":["../src/index.ts"],"sourcesContent":["import { createUnplugin } from 'unplugin';\n\nimport { unpluginFactory } from './core';\n\nexport default createUnplugin(unpluginFactory);\n"],"names":["index","createUnplugin","unpluginFactory"],"mappings":";;AAIA,MAAAA,IAAeC,EAAeC,CAAe;"}
|
package/dist/factory-D34KlQ_a.js
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { Buffer as c } from "node:buffer";
|
|
2
|
-
import f from "node:fs";
|
|
3
|
-
import a from "node:path";
|
|
4
|
-
import u from "node:zlib";
|
|
5
|
-
import { generateDtsBundle as g } from "dts-bundle-generator";
|
|
6
|
-
import s from "picocolors";
|
|
7
|
-
const d = (e, i) => {
|
|
8
|
-
typeof i == "string" ? Object.assign(e, {
|
|
9
|
-
default: i
|
|
10
|
-
}) : Array.isArray(i) ? i.forEach((o) => {
|
|
11
|
-
Object.assign(e, {
|
|
12
|
-
[a.basename(o, a.extname(o))]: o
|
|
13
|
-
});
|
|
14
|
-
}) : Object.assign(e, i);
|
|
15
|
-
}, F = (e) => {
|
|
16
|
-
const i = [], o = {}, l = {}, m = typeof e.fileName == "function" ? e.fileName : () => e.fileName;
|
|
17
|
-
return {
|
|
18
|
-
name: "unplugin-dts-bundle-generator",
|
|
19
|
-
buildEnd() {
|
|
20
|
-
const t = Object.values(o).map((r) => ({
|
|
21
|
-
filePath: r,
|
|
22
|
-
libraries: e.libraries,
|
|
23
|
-
output: e.output
|
|
24
|
-
}));
|
|
25
|
-
g(t, e.compilation).forEach((r, n) => i.push({
|
|
26
|
-
compressedSize: u.gzipSync(r).length,
|
|
27
|
-
content: r,
|
|
28
|
-
outFile: m(Object.keys(o)[n]),
|
|
29
|
-
size: c.byteLength(r)
|
|
30
|
-
}));
|
|
31
|
-
},
|
|
32
|
-
writeBundle() {
|
|
33
|
-
i.forEach((t) => f.writeFileSync(a.resolve(l.outDir, t.outFile), t.content));
|
|
34
|
-
},
|
|
35
|
-
vite: {
|
|
36
|
-
configResolved(t) {
|
|
37
|
-
t.build.lib && d(o, t.build.lib.entry), l.outDir = t.build.outDir;
|
|
38
|
-
},
|
|
39
|
-
closeBundle() {
|
|
40
|
-
const t = i.length.toString();
|
|
41
|
-
this.environment.logger.info(`
|
|
42
|
-
${s.green("✓")} ${t} declaration bundles generated.`);
|
|
43
|
-
const r = {
|
|
44
|
-
maximumFractionDigits: 2,
|
|
45
|
-
minimumFractionDigits: 2
|
|
46
|
-
};
|
|
47
|
-
i.forEach((n) => this.environment.logger.info(
|
|
48
|
-
s.dim(`${l.outDir}/`) + s.cyan(`${n.outFile} `) + s.dim(`${(n.size / 1e3).toLocaleString("en", r)} kB │ `) + s.dim(`gzip: ${(n.compressedSize / 1e3).toLocaleString("en", r)} kB`)
|
|
49
|
-
));
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
};
|
|
54
|
-
export {
|
|
55
|
-
F as u
|
|
56
|
-
};
|
|
57
|
-
//# sourceMappingURL=factory-D34KlQ_a.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"factory-D34KlQ_a.js","sources":["../src/core/factory.ts"],"sourcesContent":["import type { CompilationOptions, EntryPointConfig } from 'dts-bundle-generator';\nimport type { InputOption } from 'rollup';\nimport type { UnpluginFactory } from 'unplugin';\n\nimport { Buffer } from 'node:buffer';\nimport fs from 'node:fs';\nimport path from 'node:path';\nimport zlib from 'node:zlib';\n\nimport { generateDtsBundle } from 'dts-bundle-generator';\nimport colors from 'picocolors';\n\nexport interface Options {\n fileName: string | ((entryName: string) => string);\n output?: EntryPointConfig['output'];\n libraries?: EntryPointConfig['libraries'];\n compilation?: CompilationOptions;\n}\n\ninterface DeclarationBundle {\n compressedSize: number;\n content: string;\n outFile: string;\n size: number;\n}\n\ninterface BuildConfig {\n outDir: string;\n}\n\nconst assignEntry = (entry: Record<string, string>, input: InputOption): void => {\n if (typeof input == 'string') {\n Object.assign(entry, {\n default: input,\n });\n }\n else if (Array.isArray(input)) {\n input.forEach((i) => {\n Object.assign(entry, {\n [path.basename(i, path.extname(i))]: i,\n });\n });\n }\n else {\n Object.assign(entry, input);\n }\n};\n\nexport const unpluginFactory: UnpluginFactory<Options, false> = (options) => {\n const bundles: Array<DeclarationBundle> = [];\n const entry: Record<string, string> = {};\n const buildConfig: BuildConfig = {} as BuildConfig;\n\n const fileName = typeof options.fileName == 'function'\n ? options.fileName\n : () => options.fileName as string;\n\n return {\n name: 'unplugin-dts-bundle-generator',\n buildEnd() {\n const entryPointConfigs: Array<EntryPointConfig> = Object.values(entry).map((entryPath) => ({\n filePath: entryPath,\n libraries: options.libraries,\n output: options.output,\n }));\n\n generateDtsBundle(entryPointConfigs, options.compilation).forEach((content, i) => bundles.push({\n compressedSize: zlib.gzipSync(content).length,\n content,\n outFile: fileName(Object.keys(entry)[i]),\n size: Buffer.byteLength(content),\n }));\n },\n writeBundle() {\n bundles.forEach((bundle) => fs.writeFileSync(path.resolve(buildConfig.outDir, bundle.outFile), bundle.content));\n },\n vite: {\n configResolved(config) {\n if (config.build.lib) {\n assignEntry(entry, config.build.lib.entry);\n }\n\n buildConfig.outDir = config.build.outDir;\n },\n closeBundle() {\n const length = bundles.length.toString();\n this.environment.logger.info(`\\n${colors.green('✓')} ${length} declaration bundles generated.`);\n\n const options = {\n maximumFractionDigits: 2,\n minimumFractionDigits: 2,\n };\n\n bundles.forEach((bundle) => this.environment.logger.info(\n colors.dim(`${buildConfig.outDir}/`)\n + colors.cyan(`${bundle.outFile} `)\n + colors.dim(`${(bundle.size / 1000).toLocaleString('en', options)} kB │ `)\n + colors.dim(`gzip: ${(bundle.compressedSize / 1000).toLocaleString('en', options)} kB`),\n ));\n },\n },\n };\n};\n"],"names":["assignEntry","entry","input","i","path","unpluginFactory","options","bundles","buildConfig","fileName","entryPointConfigs","entryPath","generateDtsBundle","content","zlib","Buffer","bundle","fs","config","length","colors"],"mappings":";;;;;;AA8BA,MAAMA,IAAc,CAACC,GAA+BC,MAA6B;AAC/E,EAAI,OAAOA,KAAS,WAClB,OAAO,OAAOD,GAAO;AAAA,IACnB,SAASC;AAAA,EAAA,CACV,IAEM,MAAM,QAAQA,CAAK,IAC1BA,EAAM,QAAQ,CAACC,MAAM;AACnB,WAAO,OAAOF,GAAO;AAAA,MACnB,CAACG,EAAK,SAASD,GAAGC,EAAK,QAAQD,CAAC,CAAC,CAAC,GAAGA;AAAA,IAAA,CACtC;AAAA,EAAA,CACF,IAGD,OAAO,OAAOF,GAAOC,CAAK;AAE9B,GAEaG,IAAmD,CAACC,MAAY;AAC3E,QAAMC,IAAoC,CAAA,GACpCN,IAAgC,CAAA,GAChCO,IAA2B,CAAA,GAE3BC,IAAW,OAAOH,EAAQ,YAAY,aACxCA,EAAQ,WACR,MAAMA,EAAQ;AAElB,SAAO;AAAA,IACL,MAAM;AAAA,IACN,WAAW;AACT,YAAMI,IAA6C,OAAO,OAAOT,CAAK,EAAE,IAAI,CAACU,OAAe;AAAA,QAC1F,UAAUA;AAAA,QACV,WAAWL,EAAQ;AAAA,QACnB,QAAQA,EAAQ;AAAA,MAAA,EAChB;AAEF,MAAAM,EAAkBF,GAAmBJ,EAAQ,WAAW,EAAE,QAAQ,CAACO,GAASV,MAAMI,EAAQ,KAAK;AAAA,QAC7F,gBAAgBO,EAAK,SAASD,CAAO,EAAE;AAAA,QACvC,SAAAA;AAAA,QACA,SAASJ,EAAS,OAAO,KAAKR,CAAK,EAAEE,CAAC,CAAC;AAAA,QACvC,MAAMY,EAAO,WAAWF,CAAO;AAAA,MAAA,CAChC,CAAC;AAAA,IAAA;AAAA,IAEJ,cAAc;AACZ,MAAAN,EAAQ,QAAQ,CAACS,MAAWC,EAAG,cAAcb,EAAK,QAAQI,EAAY,QAAQQ,EAAO,OAAO,GAAGA,EAAO,OAAO,CAAC;AAAA,IAAA;AAAA,IAEhH,MAAM;AAAA,MACJ,eAAeE,GAAQ;AACrB,QAAIA,EAAO,MAAM,OACflB,EAAYC,GAAOiB,EAAO,MAAM,IAAI,KAAK,GAG3CV,EAAY,SAASU,EAAO,MAAM;AAAA,MAAA;AAAA,MAEpC,cAAc;AACZ,cAAMC,IAASZ,EAAQ,OAAO,SAAA;AAC9B,aAAK,YAAY,OAAO,KAAK;AAAA,EAAKa,EAAO,MAAM,GAAG,CAAC,IAAID,CAAM,iCAAiC;AAE9F,cAAMb,IAAU;AAAA,UACd,uBAAuB;AAAA,UACvB,uBAAuB;AAAA,QAAA;AAGzB,QAAAC,EAAQ,QAAQ,CAACS,MAAW,KAAK,YAAY,OAAO;AAAA,UAClDI,EAAO,IAAI,GAAGZ,EAAY,MAAM,GAAG,IACjCY,EAAO,KAAK,GAAGJ,EAAO,OAAO,IAAI,IACjCI,EAAO,IAAI,IAAIJ,EAAO,OAAO,KAAM,eAAe,MAAMV,CAAO,CAAC,SAAS,IACzEc,EAAO,IAAI,UAAUJ,EAAO,iBAAiB,KAAM,eAAe,MAAMV,CAAO,CAAC,KAAK;AAAA,QAAA,CACxF;AAAA,MAAA;AAAA,IACH;AAAA,EACF;AAEJ;"}
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
"use strict";const u=require("node:buffer"),g=require("node:fs"),a=require("node:path"),f=require("node:zlib"),d=require("dts-bundle-generator"),s=require("picocolors"),m=(e,i)=>{typeof i=="string"?Object.assign(e,{default:i}):Array.isArray(i)?i.forEach(r=>{Object.assign(e,{[a.basename(r,a.extname(r))]:r})}):Object.assign(e,i)},b=e=>{const i=[],r={},l={},c=typeof e.fileName=="function"?e.fileName:()=>e.fileName;return{name:"unplugin-dts-bundle-generator",buildEnd(){const t=Object.values(r).map(n=>({filePath:n,libraries:e.libraries,output:e.output}));d.generateDtsBundle(t,e.compilation).forEach((n,o)=>i.push({compressedSize:f.gzipSync(n).length,content:n,outFile:c(Object.keys(r)[o]),size:u.Buffer.byteLength(n)}))},writeBundle(){i.forEach(t=>g.writeFileSync(a.resolve(l.outDir,t.outFile),t.content))},vite:{configResolved(t){t.build.lib&&m(r,t.build.lib.entry),l.outDir=t.build.outDir},closeBundle(){const t=i.length.toString();this.environment.logger.info(`
|
|
2
|
-
${s.green("✓")} ${t} declaration bundles generated.`);const n={maximumFractionDigits:2,minimumFractionDigits:2};i.forEach(o=>this.environment.logger.info(s.dim(`${l.outDir}/`)+s.cyan(`${o.outFile} `)+s.dim(`${(o.size/1e3).toLocaleString("en",n)} kB │ `)+s.dim(`gzip: ${(o.compressedSize/1e3).toLocaleString("en",n)} kB`)))}}}};exports.unpluginFactory=b;
|
|
3
|
-
//# sourceMappingURL=factory-v7XFnpMY.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"factory-v7XFnpMY.cjs","sources":["../src/core/factory.ts"],"sourcesContent":["import type { CompilationOptions, EntryPointConfig } from 'dts-bundle-generator';\nimport type { InputOption } from 'rollup';\nimport type { UnpluginFactory } from 'unplugin';\n\nimport { Buffer } from 'node:buffer';\nimport fs from 'node:fs';\nimport path from 'node:path';\nimport zlib from 'node:zlib';\n\nimport { generateDtsBundle } from 'dts-bundle-generator';\nimport colors from 'picocolors';\n\nexport interface Options {\n fileName: string | ((entryName: string) => string);\n output?: EntryPointConfig['output'];\n libraries?: EntryPointConfig['libraries'];\n compilation?: CompilationOptions;\n}\n\ninterface DeclarationBundle {\n compressedSize: number;\n content: string;\n outFile: string;\n size: number;\n}\n\ninterface BuildConfig {\n outDir: string;\n}\n\nconst assignEntry = (entry: Record<string, string>, input: InputOption): void => {\n if (typeof input == 'string') {\n Object.assign(entry, {\n default: input,\n });\n }\n else if (Array.isArray(input)) {\n input.forEach((i) => {\n Object.assign(entry, {\n [path.basename(i, path.extname(i))]: i,\n });\n });\n }\n else {\n Object.assign(entry, input);\n }\n};\n\nexport const unpluginFactory: UnpluginFactory<Options, false> = (options) => {\n const bundles: Array<DeclarationBundle> = [];\n const entry: Record<string, string> = {};\n const buildConfig: BuildConfig = {} as BuildConfig;\n\n const fileName = typeof options.fileName == 'function'\n ? options.fileName\n : () => options.fileName as string;\n\n return {\n name: 'unplugin-dts-bundle-generator',\n buildEnd() {\n const entryPointConfigs: Array<EntryPointConfig> = Object.values(entry).map((entryPath) => ({\n filePath: entryPath,\n libraries: options.libraries,\n output: options.output,\n }));\n\n generateDtsBundle(entryPointConfigs, options.compilation).forEach((content, i) => bundles.push({\n compressedSize: zlib.gzipSync(content).length,\n content,\n outFile: fileName(Object.keys(entry)[i]),\n size: Buffer.byteLength(content),\n }));\n },\n writeBundle() {\n bundles.forEach((bundle) => fs.writeFileSync(path.resolve(buildConfig.outDir, bundle.outFile), bundle.content));\n },\n vite: {\n configResolved(config) {\n if (config.build.lib) {\n assignEntry(entry, config.build.lib.entry);\n }\n\n buildConfig.outDir = config.build.outDir;\n },\n closeBundle() {\n const length = bundles.length.toString();\n this.environment.logger.info(`\\n${colors.green('✓')} ${length} declaration bundles generated.`);\n\n const options = {\n maximumFractionDigits: 2,\n minimumFractionDigits: 2,\n };\n\n bundles.forEach((bundle) => this.environment.logger.info(\n colors.dim(`${buildConfig.outDir}/`)\n + colors.cyan(`${bundle.outFile} `)\n + colors.dim(`${(bundle.size / 1000).toLocaleString('en', options)} kB │ `)\n + colors.dim(`gzip: ${(bundle.compressedSize / 1000).toLocaleString('en', options)} kB`),\n ));\n },\n },\n };\n};\n"],"names":["assignEntry","entry","input","i","path","unpluginFactory","options","bundles","buildConfig","fileName","entryPointConfigs","entryPath","generateDtsBundle","content","zlib","Buffer","bundle","fs","config","length","colors"],"mappings":"yKA8BMA,EAAc,CAACC,EAA+BC,IAA6B,CAC3E,OAAOA,GAAS,SAClB,OAAO,OAAOD,EAAO,CACnB,QAASC,CAAA,CACV,EAEM,MAAM,QAAQA,CAAK,EAC1BA,EAAM,QAASC,GAAM,CACnB,OAAO,OAAOF,EAAO,CACnB,CAACG,EAAK,SAASD,EAAGC,EAAK,QAAQD,CAAC,CAAC,CAAC,EAAGA,CAAA,CACtC,CAAA,CACF,EAGD,OAAO,OAAOF,EAAOC,CAAK,CAE9B,EAEaG,EAAoDC,GAAY,CAC3E,MAAMC,EAAoC,CAAA,EACpCN,EAAgC,CAAA,EAChCO,EAA2B,CAAA,EAE3BC,EAAW,OAAOH,EAAQ,UAAY,WACxCA,EAAQ,SACR,IAAMA,EAAQ,SAElB,MAAO,CACL,KAAM,gCACN,UAAW,CACT,MAAMI,EAA6C,OAAO,OAAOT,CAAK,EAAE,IAAKU,IAAe,CAC1F,SAAUA,EACV,UAAWL,EAAQ,UACnB,OAAQA,EAAQ,MAAA,EAChB,EAEFM,oBAAkBF,EAAmBJ,EAAQ,WAAW,EAAE,QAAQ,CAACO,EAASV,IAAMI,EAAQ,KAAK,CAC7F,eAAgBO,EAAK,SAASD,CAAO,EAAE,OACvC,QAAAA,EACA,QAASJ,EAAS,OAAO,KAAKR,CAAK,EAAEE,CAAC,CAAC,EACvC,KAAMY,EAAAA,OAAO,WAAWF,CAAO,CAAA,CAChC,CAAC,CAAA,EAEJ,aAAc,CACZN,EAAQ,QAASS,GAAWC,EAAG,cAAcb,EAAK,QAAQI,EAAY,OAAQQ,EAAO,OAAO,EAAGA,EAAO,OAAO,CAAC,CAAA,EAEhH,KAAM,CACJ,eAAeE,EAAQ,CACjBA,EAAO,MAAM,KACflB,EAAYC,EAAOiB,EAAO,MAAM,IAAI,KAAK,EAG3CV,EAAY,OAASU,EAAO,MAAM,MAAA,EAEpC,aAAc,CACZ,MAAMC,EAASZ,EAAQ,OAAO,SAAA,EAC9B,KAAK,YAAY,OAAO,KAAK;AAAA,EAAKa,EAAO,MAAM,GAAG,CAAC,IAAID,CAAM,iCAAiC,EAE9F,MAAMb,EAAU,CACd,sBAAuB,EACvB,sBAAuB,CAAA,EAGzBC,EAAQ,QAASS,GAAW,KAAK,YAAY,OAAO,KAClDI,EAAO,IAAI,GAAGZ,EAAY,MAAM,GAAG,EACjCY,EAAO,KAAK,GAAGJ,EAAO,OAAO,IAAI,EACjCI,EAAO,IAAI,IAAIJ,EAAO,KAAO,KAAM,eAAe,KAAMV,CAAO,CAAC,SAAS,EACzEc,EAAO,IAAI,UAAUJ,EAAO,eAAiB,KAAM,eAAe,KAAMV,CAAO,CAAC,KAAK,CAAA,CACxF,CAAA,CACH,CACF,CAEJ"}
|
package/dist/vite.cjs
DELETED
package/dist/vite.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"vite.cjs","sources":["../src/vite.ts"],"sourcesContent":["import { createVitePlugin } from 'unplugin';\nimport { unpluginFactory } from './core';\n\nexport default createVitePlugin(unpluginFactory);\n"],"names":["vite","createVitePlugin","unpluginFactory"],"mappings":"6EAGAA,EAAeC,EAAAA,iBAAiBC,EAAAA,eAAe"}
|
package/dist/vite.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"vite.mjs","sources":["../src/vite.ts"],"sourcesContent":["import { createVitePlugin } from 'unplugin';\nimport { unpluginFactory } from './core';\n\nexport default createVitePlugin(unpluginFactory);\n"],"names":["vite","createVitePlugin","unpluginFactory"],"mappings":";;AAGA,MAAAA,IAAeC,EAAiBC,CAAe;"}
|