unplugin-isolated-decl 0.0.1-beta.2 → 0.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
@@ -2,7 +2,13 @@
2
2
 
3
3
  [![Unit Test](https://github.com/unplugin/unplugin-isolated-decl/actions/workflows/unit-test.yml/badge.svg)](https://github.com/unplugin/unplugin-isolated-decl/actions/workflows/unit-test.yml)
4
4
 
5
- Generate isolated declaration.
5
+ ⚡️ A blazing-fast tool for generating isolated declarations, powered by Oxc!
6
+
7
+ ## Features
8
+
9
+ - 🚀 **Fast**: Blazing-fast `.d.ts` generator, powered by Oxc.
10
+ - 🎯 **Isolated**: Generate isolated declarations for each file.
11
+ - ✨ **Bundler Support**: Works with Vite, Rollup, and esbuild.
6
12
 
7
13
  ## Installation
8
14
 
@@ -10,6 +16,8 @@ Generate isolated declaration.
10
16
  npm i -D unplugin-isolated-decl
11
17
  ```
12
18
 
19
+ ## Usage
20
+
13
21
  <details>
14
22
  <summary>Vite</summary><br>
15
23
 
@@ -38,6 +46,20 @@ export default {
38
46
 
39
47
  <br></details>
40
48
 
49
+ <details>
50
+ <summary>Rolldown</summary><br>
51
+
52
+ ```ts
53
+ // rolldown.config.js
54
+ import UnpluginIsolatedDecl from 'unplugin-isolated-decl/rolldown'
55
+
56
+ export default {
57
+ plugins: [UnpluginIsolatedDecl()],
58
+ }
59
+ ```
60
+
61
+ <br></details>
62
+
41
63
  <details>
42
64
  <summary>esbuild</summary><br>
43
65
 
@@ -62,4 +84,4 @@ build({
62
84
 
63
85
  ## License
64
86
 
65
- [MIT](./LICENSE) License © 2023-PRESENT [三咲智子](https://github.com/sxzz)
87
+ [MIT](./LICENSE) License © 2024-PRESENT [三咲智子](https://github.com/sxzz)
package/dist/api.cjs CHANGED
@@ -1 +1,8 @@
1
- "use strict";
1
+ "use strict";
2
+
3
+ const { __toCommonJS } = require("./chunk-J8LkbbVi.cjs");
4
+
5
+ //#region src/api.ts
6
+ var api_ns = {};
7
+
8
+ //#endregion
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+
3
+ //#region rolldown:runtime
4
+ var __create = Object.create;
5
+ var __defProp = Object.defineProperty;
6
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7
+ var __getOwnPropNames = Object.getOwnPropertyNames;
8
+ var __getProtoOf = Object.getPrototypeOf;
9
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
10
+ var __export = (target, all) => {
11
+ for (var name in all) __defProp(target, name, {
12
+ get: all[name],
13
+ enumerable: true
14
+ });
15
+ };
16
+ var __copyProps = (to, from, except, desc) => {
17
+ if (from && typeof from === 'object' || typeof from === 'function') for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
18
+ key = keys[i];
19
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
20
+ get: ((k) => from[k]).bind(null, key),
21
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
22
+ });
23
+ }
24
+ return to;
25
+ };
26
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, 'default', {
27
+ value: mod,
28
+ enumerable: true
29
+ }) : target, mod));
30
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, '__esModule', {value: true}), mod);
31
+
32
+ //#endregion
33
+
34
+ exports.__export = __export;
35
+ exports.__toCommonJS = __toCommonJS;
36
+ exports.__toESM = __toESM;
@@ -3,8 +3,6 @@ export interface Options {
3
3
  include?: FilterPattern;
4
4
  exclude?: FilterPattern;
5
5
  enforce?: (('pre') | ('post') | (undefined));
6
- outDir?: string;
7
- outExt?: string;
8
6
  }
9
7
  type Overwrite<T, U> = ((Pick<T, Exclude<keyof T, keyof U>>) & (U));
10
8
  export type OptionsResolved = Overwrite<Required<Options>, Pick<Options, 'enforce'>>;
@@ -3,8 +3,6 @@ export interface Options {
3
3
  include?: FilterPattern;
4
4
  exclude?: FilterPattern;
5
5
  enforce?: (('pre') | ('post') | (undefined));
6
- outDir?: string;
7
- outExt?: string;
8
6
  }
9
7
  type Overwrite<T, U> = ((Pick<T, Exclude<keyof T, keyof U>>) & (U));
10
8
  export type OptionsResolved = Overwrite<Required<Options>, Pick<Options, 'enforce'>>;
package/dist/esbuild.cjs CHANGED
@@ -1,11 +1,12 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});
1
+ "use strict";
2
2
 
3
- var _chunkCMR2YO7Qcjs = require('./chunk-CMR2YO7Q.cjs');
3
+ const { __export, __toCommonJS } = require("./chunk-J8LkbbVi.cjs");
4
+ const { src_index_default } = require("./src_index-ff_kRS8x.cjs");
4
5
 
5
- // src/esbuild.ts
6
- var esbuild_default = _chunkCMR2YO7Qcjs.src_default.esbuild;
6
+ //#region src/esbuild.ts
7
+ var esbuild_ns = {};
8
+ __export(esbuild_ns, {default: () => esbuild_default});
9
+ var esbuild_default = src_index_default.esbuild;
7
10
 
8
-
9
- exports.default = esbuild_default;
10
-
11
- module.exports = exports.default;
11
+ //#endregion
12
+ module.exports = __toCommonJS(esbuild_ns)
@@ -1,3 +1,3 @@
1
- import unplugin from '.';
1
+ import unplugin from './index';
2
2
  declare const _default: typeof unplugin.esbuild;
3
3
  export default _default;
package/dist/esbuild.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import unplugin from '.';
1
+ import unplugin from './index';
2
2
  declare const _default: typeof unplugin.esbuild;
3
3
  export default _default;
package/dist/esbuild.js CHANGED
@@ -1,9 +1,7 @@
1
- import {
2
- src_default
3
- } from "./chunk-O7LDO47Z.js";
1
+ import { src_index_default } from "./src_index--yc62mkz.js";
4
2
 
5
- // src/esbuild.ts
6
- var esbuild_default = src_default.esbuild;
7
- export {
8
- esbuild_default as default
9
- };
3
+ //#region src/esbuild.ts
4
+ var esbuild_default = src_index_default.esbuild;
5
+
6
+ //#endregion
7
+ export { esbuild_default as default };
package/dist/index.cjs CHANGED
@@ -1,8 +1,6 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});
1
+ "use strict";
2
2
 
3
+ const { __toCommonJS } = require("./chunk-J8LkbbVi.cjs");
4
+ const { plugin, src_index_default, src_index_ns } = require("./src_index-ff_kRS8x.cjs");
3
5
 
4
- var _chunkCMR2YO7Qcjs = require('./chunk-CMR2YO7Q.cjs');
5
-
6
-
7
-
8
- exports.default = _chunkCMR2YO7Qcjs.src_default; exports.plugin = _chunkCMR2YO7Qcjs.plugin;
6
+ module.exports = __toCommonJS(src_index_ns)
package/dist/index.js CHANGED
@@ -1,8 +1,3 @@
1
- import {
2
- plugin,
3
- src_default
4
- } from "./chunk-O7LDO47Z.js";
5
- export {
6
- src_default as default,
7
- plugin
8
- };
1
+ import { plugin, src_index_default } from "./src_index--yc62mkz.js";
2
+
3
+ export { src_index_default as default, plugin };
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+
3
+ const { __export, __toCommonJS } = require("./chunk-J8LkbbVi.cjs");
4
+ const { src_index_default } = require("./src_index-ff_kRS8x.cjs");
5
+
6
+ //#region src/rolldown.ts
7
+ var rolldown_ns = {};
8
+ __export(rolldown_ns, {default: () => rolldown_default});
9
+ var rolldown_default = src_index_default.rolldown;
10
+
11
+ //#endregion
12
+ module.exports = __toCommonJS(rolldown_ns)
@@ -0,0 +1,3 @@
1
+ import unplugin from './index';
2
+ declare const _default: typeof unplugin.rolldown;
3
+ export default _default;
@@ -0,0 +1,3 @@
1
+ import unplugin from './index';
2
+ declare const _default: typeof unplugin.rolldown;
3
+ export default _default;
@@ -0,0 +1,7 @@
1
+ import { src_index_default } from "./src_index--yc62mkz.js";
2
+
3
+ //#region src/rolldown.ts
4
+ var rolldown_default = src_index_default.rolldown;
5
+
6
+ //#endregion
7
+ export { rolldown_default as default };
package/dist/rollup.cjs CHANGED
@@ -1,11 +1,12 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});
1
+ "use strict";
2
2
 
3
- var _chunkCMR2YO7Qcjs = require('./chunk-CMR2YO7Q.cjs');
3
+ const { __export, __toCommonJS } = require("./chunk-J8LkbbVi.cjs");
4
+ const { src_index_default } = require("./src_index-ff_kRS8x.cjs");
4
5
 
5
- // src/rollup.ts
6
- var rollup_default = _chunkCMR2YO7Qcjs.src_default.rollup;
6
+ //#region src/rollup.ts
7
+ var rollup_ns = {};
8
+ __export(rollup_ns, {default: () => rollup_default});
9
+ var rollup_default = src_index_default.rollup;
7
10
 
8
-
9
- exports.default = rollup_default;
10
-
11
- module.exports = exports.default;
11
+ //#endregion
12
+ module.exports = __toCommonJS(rollup_ns)
package/dist/rollup.d.cts CHANGED
@@ -1,3 +1,3 @@
1
- import unplugin from '.';
1
+ import unplugin from './index';
2
2
  declare const _default: typeof unplugin.rollup;
3
3
  export default _default;
package/dist/rollup.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import unplugin from '.';
1
+ import unplugin from './index';
2
2
  declare const _default: typeof unplugin.rollup;
3
3
  export default _default;
package/dist/rollup.js CHANGED
@@ -1,9 +1,7 @@
1
- import {
2
- src_default
3
- } from "./chunk-O7LDO47Z.js";
1
+ import { src_index_default } from "./src_index--yc62mkz.js";
4
2
 
5
- // src/rollup.ts
6
- var rollup_default = src_default.rollup;
7
- export {
8
- rollup_default as default
9
- };
3
+ //#region src/rollup.ts
4
+ var rollup_default = src_index_default.rollup;
5
+
6
+ //#endregion
7
+ export { rollup_default as default };
@@ -0,0 +1,117 @@
1
+ import { default as path } from "node:path";
2
+ import { mkdir, writeFile } from "node:fs/promises";
3
+ import { createUnplugin } from "unplugin";
4
+ import { isolatedDeclaration } from "oxc-transform";
5
+ import { createFilter } from "@rollup/pluginutils";
6
+
7
+ //#region src/core/options.ts
8
+ function resolveOptions(options) {
9
+ return {
10
+ include: options.include || [/\.[cm]?ts$/],
11
+ exclude: options.exclude || [/node_modules/],
12
+ enforce: 'enforce'in options ? options.enforce : 'pre'
13
+ };
14
+ }
15
+
16
+ //#endregion
17
+ //#region src/index.ts
18
+ const plugin = createUnplugin((rawOptions = {}, meta) => {
19
+ const options = resolveOptions(rawOptions);
20
+ const filter = createFilter(options.include, options.exclude);
21
+ const outputFiles = {};
22
+ function addOutput(filename, source) {
23
+ outputFiles[filename.replace(/\.(.?)[jt]s$/, '')] = source;
24
+ }
25
+ const rollup = {renderStart(outputOptions, inputOptions) {
26
+ let outBase = '';
27
+ let input = inputOptions.input;
28
+ input = typeof input === 'string' ? [input] : input;
29
+ if (Array.isArray(input)) {
30
+ outBase = lowestCommonAncestor(...input);
31
+ }
32
+ if (typeof outputOptions.entryFileNames !== 'string') {
33
+ return this.error('entryFileNames must be a string');
34
+ }
35
+ const entryFileNames = outputOptions.entryFileNames.replace(/\.(.)?[jt]s$/, (_, s) => `.d.${s || ''}ts`);
36
+ for (const [filename, source] of Object.entries(outputFiles)) {
37
+ this.emitFile({
38
+ type: 'asset',
39
+ fileName: entryFileNames.replace('[name]', path.relative(outBase, filename)),
40
+ source
41
+ });
42
+ }
43
+ }};
44
+ return {
45
+ name: 'unplugin-isolated-decl',
46
+ transformInclude(id) {
47
+ return filter(id);
48
+ },
49
+ transform(code, id) {
50
+ const { sourceText, errors } = isolatedDeclaration(id, code);
51
+ if (errors.length) {
52
+ this.error(errors[0]);
53
+ return;
54
+ }
55
+ addOutput(id, sourceText);
56
+ },
57
+ async buildEnd() {
58
+ if (meta.framework === 'esbuild') {
59
+ const esbuildOptions = meta.build.initialOptions;
60
+ const entries = esbuildOptions.entryPoints;
61
+ if (!(entries && Array.isArray(entries) && entries.every((entry) => typeof entry === 'string'))) throw new Error('unsupported entryPoints, must be an string[]');
62
+ const outBase = lowestCommonAncestor(...entries);
63
+ const jsExt = esbuildOptions.outExtension?.['.js'];
64
+ let outExt;
65
+ switch (jsExt) {
66
+ case '.cjs':
67
+ outExt = 'cts';
68
+ break;
69
+ case '.mjs':
70
+ outExt = 'mts';
71
+ break;
72
+ default:
73
+ outExt = 'ts';
74
+ break;
75
+ }
76
+ const build = meta.build;
77
+ if (build.initialOptions.outdir && (build.initialOptions.write ?? true)) for (const [filename, source] of Object.entries(outputFiles)) {
78
+ const outFile = `${path.relative(outBase, filename)}.d.${outExt}`;
79
+ const filePath = path.resolve(build.initialOptions.outdir, outFile);
80
+ await mkdir(path.dirname(filePath), {recursive: true});
81
+ await writeFile(filePath, source);
82
+ }
83
+ }
84
+ },
85
+ rollup,
86
+ rolldown: rollup,
87
+ vite: {
88
+ apply: 'build',
89
+ enforce: 'pre',
90
+ ...rollup
91
+ }
92
+ };
93
+ });
94
+ var src_index_default = plugin;
95
+ function lowestCommonAncestor(...filepaths) {
96
+ if (filepaths.length === 0) return '';
97
+ if (filepaths.length === 1) return path.dirname(filepaths[0]);
98
+ const [first, ...rest] = filepaths;
99
+ let ancestor = first.split(path.sep);
100
+ for (const filepath of rest) {
101
+ const directories = filepath.split(path.sep, ancestor.length);
102
+ let index = 0;
103
+ for (const directory of directories) {
104
+ if (directory === ancestor[index]) {
105
+ index += 1;
106
+ } else {
107
+ ancestor = ancestor.slice(0, index);
108
+ break;
109
+ }
110
+ }
111
+ ancestor = ancestor.slice(0, index);
112
+ }
113
+ return ancestor.length <= 1 && ancestor[0] === '' ? path.sep + ancestor[0] : ancestor.join(path.sep);
114
+ }
115
+
116
+ //#endregion
117
+ export { plugin, src_index_default };
@@ -0,0 +1,127 @@
1
+ "use strict";
2
+
3
+ const { __export, __toESM } = require("./chunk-J8LkbbVi.cjs");
4
+ const { default: path } = __toESM(require("node:path"));
5
+ const { mkdir, writeFile } = __toESM(require("node:fs/promises"));
6
+ const { createUnplugin } = __toESM(require("unplugin"));
7
+ const { isolatedDeclaration } = __toESM(require("oxc-transform"));
8
+ const { createFilter } = __toESM(require("@rollup/pluginutils"));
9
+
10
+ //#region src/core/options.ts
11
+ function resolveOptions(options) {
12
+ return {
13
+ include: options.include || [/\.[cm]?ts$/],
14
+ exclude: options.exclude || [/node_modules/],
15
+ enforce: 'enforce'in options ? options.enforce : 'pre'
16
+ };
17
+ }
18
+
19
+ //#endregion
20
+ //#region src/index.ts
21
+ var src_index_ns = {};
22
+ __export(src_index_ns, {
23
+ default: () => src_index_default,
24
+ plugin: () => plugin
25
+ });
26
+ const plugin = createUnplugin((rawOptions = {}, meta) => {
27
+ const options = resolveOptions(rawOptions);
28
+ const filter = createFilter(options.include, options.exclude);
29
+ const outputFiles = {};
30
+ function addOutput(filename, source) {
31
+ outputFiles[filename.replace(/\.(.?)[jt]s$/, '')] = source;
32
+ }
33
+ const rollup = {renderStart(outputOptions, inputOptions) {
34
+ let outBase = '';
35
+ let input = inputOptions.input;
36
+ input = typeof input === 'string' ? [input] : input;
37
+ if (Array.isArray(input)) {
38
+ outBase = lowestCommonAncestor(...input);
39
+ }
40
+ if (typeof outputOptions.entryFileNames !== 'string') {
41
+ return this.error('entryFileNames must be a string');
42
+ }
43
+ const entryFileNames = outputOptions.entryFileNames.replace(/\.(.)?[jt]s$/, (_, s) => `.d.${s || ''}ts`);
44
+ for (const [filename, source] of Object.entries(outputFiles)) {
45
+ this.emitFile({
46
+ type: 'asset',
47
+ fileName: entryFileNames.replace('[name]', path.relative(outBase, filename)),
48
+ source
49
+ });
50
+ }
51
+ }};
52
+ return {
53
+ name: 'unplugin-isolated-decl',
54
+ transformInclude(id) {
55
+ return filter(id);
56
+ },
57
+ transform(code, id) {
58
+ const { sourceText, errors } = isolatedDeclaration(id, code);
59
+ if (errors.length) {
60
+ this.error(errors[0]);
61
+ return;
62
+ }
63
+ addOutput(id, sourceText);
64
+ },
65
+ async buildEnd() {
66
+ if (meta.framework === 'esbuild') {
67
+ const esbuildOptions = meta.build.initialOptions;
68
+ const entries = esbuildOptions.entryPoints;
69
+ if (!(entries && Array.isArray(entries) && entries.every((entry) => typeof entry === 'string'))) throw new Error('unsupported entryPoints, must be an string[]');
70
+ const outBase = lowestCommonAncestor(...entries);
71
+ const jsExt = esbuildOptions.outExtension?.['.js'];
72
+ let outExt;
73
+ switch (jsExt) {
74
+ case '.cjs':
75
+ outExt = 'cts';
76
+ break;
77
+ case '.mjs':
78
+ outExt = 'mts';
79
+ break;
80
+ default:
81
+ outExt = 'ts';
82
+ break;
83
+ }
84
+ const build = meta.build;
85
+ if (build.initialOptions.outdir && (build.initialOptions.write ?? true)) for (const [filename, source] of Object.entries(outputFiles)) {
86
+ const outFile = `${path.relative(outBase, filename)}.d.${outExt}`;
87
+ const filePath = path.resolve(build.initialOptions.outdir, outFile);
88
+ await mkdir(path.dirname(filePath), {recursive: true});
89
+ await writeFile(filePath, source);
90
+ }
91
+ }
92
+ },
93
+ rollup,
94
+ rolldown: rollup,
95
+ vite: {
96
+ apply: 'build',
97
+ enforce: 'pre',
98
+ ...rollup
99
+ }
100
+ };
101
+ });
102
+ var src_index_default = plugin;
103
+ function lowestCommonAncestor(...filepaths) {
104
+ if (filepaths.length === 0) return '';
105
+ if (filepaths.length === 1) return path.dirname(filepaths[0]);
106
+ const [first, ...rest] = filepaths;
107
+ let ancestor = first.split(path.sep);
108
+ for (const filepath of rest) {
109
+ const directories = filepath.split(path.sep, ancestor.length);
110
+ let index = 0;
111
+ for (const directory of directories) {
112
+ if (directory === ancestor[index]) {
113
+ index += 1;
114
+ } else {
115
+ ancestor = ancestor.slice(0, index);
116
+ break;
117
+ }
118
+ }
119
+ ancestor = ancestor.slice(0, index);
120
+ }
121
+ return ancestor.length <= 1 && ancestor[0] === '' ? path.sep + ancestor[0] : ancestor.join(path.sep);
122
+ }
123
+
124
+ //#endregion
125
+ exports.plugin = plugin;
126
+ exports.src_index_default = src_index_default;
127
+ exports.src_index_ns = src_index_ns;
package/dist/vite.cjs CHANGED
@@ -1,11 +1,12 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});
1
+ "use strict";
2
2
 
3
- var _chunkCMR2YO7Qcjs = require('./chunk-CMR2YO7Q.cjs');
3
+ const { __export, __toCommonJS } = require("./chunk-J8LkbbVi.cjs");
4
+ const { src_index_default } = require("./src_index-ff_kRS8x.cjs");
4
5
 
5
- // src/vite.ts
6
- var vite_default = _chunkCMR2YO7Qcjs.src_default.vite;
6
+ //#region src/vite.ts
7
+ var vite_ns = {};
8
+ __export(vite_ns, {default: () => vite_default});
9
+ var vite_default = src_index_default.vite;
7
10
 
8
-
9
- exports.default = vite_default;
10
-
11
- module.exports = exports.default;
11
+ //#endregion
12
+ module.exports = __toCommonJS(vite_ns)
package/dist/vite.d.cts CHANGED
@@ -1,3 +1,3 @@
1
- import unplugin from '.';
1
+ import unplugin from './index';
2
2
  declare const _default: typeof unplugin.vite;
3
3
  export default _default;
package/dist/vite.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import unplugin from '.';
1
+ import unplugin from './index';
2
2
  declare const _default: typeof unplugin.vite;
3
3
  export default _default;
package/dist/vite.js CHANGED
@@ -1,9 +1,7 @@
1
- import {
2
- src_default
3
- } from "./chunk-O7LDO47Z.js";
1
+ import { src_index_default } from "./src_index--yc62mkz.js";
4
2
 
5
- // src/vite.ts
6
- var vite_default = src_default.vite;
7
- export {
8
- vite_default as default
9
- };
3
+ //#region src/vite.ts
4
+ var vite_default = src_index_default.vite;
5
+
6
+ //#endregion
7
+ export { vite_default as default };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "unplugin-isolated-decl",
3
- "version": "0.0.1-beta.2",
4
- "description": "Generate isolated declaration.",
3
+ "version": "0.2.0",
4
+ "description": "A blazing-fast tool for generating isolated declarations, powered by Oxc.",
5
5
  "type": "module",
6
6
  "keywords": [
7
7
  "unplugin",
@@ -35,14 +35,14 @@
35
35
  "require": "./dist/vite.cjs",
36
36
  "import": "./dist/vite.js"
37
37
  },
38
- "./webpack": {
39
- "require": "./dist/webpack.cjs",
40
- "import": "./dist/webpack.js"
41
- },
42
38
  "./rollup": {
43
39
  "require": "./dist/rollup.cjs",
44
40
  "import": "./dist/rollup.js"
45
41
  },
42
+ "./rolldown": {
43
+ "require": "./dist/rolldown.cjs",
44
+ "import": "./dist/rolldown.js"
45
+ },
46
46
  "./esbuild": {
47
47
  "require": "./dist/esbuild.cjs",
48
48
  "import": "./dist/esbuild.js"
@@ -69,23 +69,23 @@
69
69
  },
70
70
  "dependencies": {
71
71
  "@rollup/pluginutils": "^5.1.0",
72
- "magic-string": "^0.30.10",
73
72
  "oxc-transform": "^0.15.1",
74
73
  "unplugin": "^1.10.1"
75
74
  },
76
75
  "devDependencies": {
77
76
  "@sxzz/eslint-config": "^3.13.0",
78
77
  "@sxzz/prettier-config": "^2.0.2",
79
- "@types/node": "^20.14.8",
78
+ "@types/node": "^20.14.9",
80
79
  "bumpp": "^9.4.1",
80
+ "esbuild": "^0.21.5",
81
81
  "eslint": "^9.5.0",
82
82
  "fast-glob": "^3.3.2",
83
83
  "prettier": "^3.3.2",
84
84
  "rollup": "^4.18.0",
85
- "tsup": "^8.1.0",
86
- "tsx": "^4.15.7",
85
+ "tsdown": "^0.2.2",
86
+ "tsx": "^4.15.8",
87
87
  "typescript": "^5.5.2",
88
- "vite": "^5.3.1",
88
+ "vite": "^5.3.2",
89
89
  "vitest": "^1.6.0"
90
90
  },
91
91
  "engines": {
@@ -95,8 +95,7 @@
95
95
  "scripts": {
96
96
  "lint": "eslint --cache .",
97
97
  "lint:fix": "pnpm run lint --fix",
98
- "build": "tsup",
99
- "dev": "tsup --watch",
98
+ "build": "tsdown",
100
99
  "test": "vitest",
101
100
  "typecheck": "tsc --noEmit",
102
101
  "release": "bumpp && pnpm publish"
@@ -1,124 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/index.ts
2
- var _path = require('path'); var _path2 = _interopRequireDefault(_path);
3
-
4
-
5
- var _unplugin = require('unplugin');
6
- var _oxctransform = require('oxc-transform');
7
- var _pluginutils = require('@rollup/pluginutils');
8
-
9
- // src/core/options.ts
10
- function resolveOptions(options) {
11
- return {
12
- include: options.include || [/\.[cm]?[jt]sx?$/],
13
- exclude: options.exclude || [/node_modules/],
14
- enforce: "enforce" in options ? options.enforce : "pre",
15
- outDir: options.outDir || "dist",
16
- outExt: options.outExt || "ts"
17
- };
18
- }
19
-
20
- // src/index.ts
21
- var plugin = _unplugin.createUnplugin.call(void 0, (rawOptions = {}) => {
22
- const options = resolveOptions(rawOptions);
23
- const filter = _pluginutils.createFilter.call(void 0, options.include, options.exclude);
24
- const contexts = [];
25
- let id = 0;
26
- return {
27
- name: "unplugin-isolated-decl",
28
- transformInclude(id2) {
29
- return filter(id2);
30
- },
31
- transform(code, id2) {
32
- const context = contexts[this.id || 0];
33
- const { sourceText, errors } = _oxctransform.isolatedDeclaration.call(void 0, id2, code);
34
- if (errors.length) {
35
- throw new AggregateError(
36
- errors,
37
- "TypeScript Isolated Declarations Error"
38
- );
39
- }
40
- if (!context.outDir) {
41
- throw new Error("outDir is not set");
42
- }
43
- const outFile = _path2.default.relative(context.outBase, id2).replace(/\.(.?)ts$/, `.d.${context.outExt}`);
44
- this.emitFile({
45
- type: "asset",
46
- fileName: outFile,
47
- source: sourceText
48
- });
49
- },
50
- esbuild: {
51
- config(esbuildOptions) {
52
- const entries = esbuildOptions.entryPoints;
53
- if (!(entries && Array.isArray(entries) && entries.every((entry) => typeof entry === "string")))
54
- throw new Error("unsupported entryPoints, must be an string[]");
55
- const outBase = lowestCommonAncestor(...entries);
56
- const outDir = esbuildOptions.outdir || options.outDir;
57
- if (!outDir) {
58
- throw new Error("outDir is not set");
59
- }
60
- const jsExt = _optionalChain([esbuildOptions, 'access', _ => _.outExtension, 'optionalAccess', _2 => _2[".js"]]);
61
- let outExt;
62
- switch (jsExt) {
63
- case ".cjs":
64
- outExt = "cts";
65
- break;
66
- case ".mjs":
67
- outExt = "mts";
68
- break;
69
- default:
70
- outExt = "ts";
71
- break;
72
- }
73
- this.id = id++;
74
- contexts.push({
75
- outBase,
76
- outExt,
77
- outDir
78
- });
79
- }
80
- },
81
- rollup: {
82
- options(rollupOptions) {
83
- let outBase = "";
84
- let input = rollupOptions.input;
85
- input = typeof input === "string" ? [input] : input;
86
- if (Array.isArray(input)) {
87
- outBase = lowestCommonAncestor(...input);
88
- }
89
- if (!contexts.length) contexts.push({});
90
- contexts[0] = {
91
- outExt: options.outExt,
92
- outDir: options.outDir,
93
- outBase
94
- };
95
- }
96
- }
97
- };
98
- });
99
- var src_default = plugin;
100
- function lowestCommonAncestor(...filepaths) {
101
- if (filepaths.length === 0) return "";
102
- if (filepaths.length === 1) return _path2.default.dirname(filepaths[0]);
103
- const [first, ...rest] = filepaths;
104
- let ancestor = first.split(_path2.default.sep);
105
- for (const filepath of rest) {
106
- const directories = filepath.split(_path2.default.sep, ancestor.length);
107
- let index = 0;
108
- for (const directory of directories) {
109
- if (directory === ancestor[index]) {
110
- index += 1;
111
- } else {
112
- ancestor = ancestor.slice(0, index);
113
- break;
114
- }
115
- }
116
- ancestor = ancestor.slice(0, index);
117
- }
118
- return ancestor.length <= 1 && ancestor[0] === "" ? _path2.default.sep + ancestor[0] : ancestor.join(_path2.default.sep);
119
- }
120
-
121
-
122
-
123
-
124
- exports.plugin = plugin; exports.src_default = src_default;
@@ -1,124 +0,0 @@
1
- // src/index.ts
2
- import path from "node:path";
3
- import {
4
- createUnplugin
5
- } from "unplugin";
6
- import { isolatedDeclaration } from "oxc-transform";
7
- import { createFilter } from "@rollup/pluginutils";
8
-
9
- // src/core/options.ts
10
- function resolveOptions(options) {
11
- return {
12
- include: options.include || [/\.[cm]?[jt]sx?$/],
13
- exclude: options.exclude || [/node_modules/],
14
- enforce: "enforce" in options ? options.enforce : "pre",
15
- outDir: options.outDir || "dist",
16
- outExt: options.outExt || "ts"
17
- };
18
- }
19
-
20
- // src/index.ts
21
- var plugin = createUnplugin((rawOptions = {}) => {
22
- const options = resolveOptions(rawOptions);
23
- const filter = createFilter(options.include, options.exclude);
24
- const contexts = [];
25
- let id = 0;
26
- return {
27
- name: "unplugin-isolated-decl",
28
- transformInclude(id2) {
29
- return filter(id2);
30
- },
31
- transform(code, id2) {
32
- const context = contexts[this.id || 0];
33
- const { sourceText, errors } = isolatedDeclaration(id2, code);
34
- if (errors.length) {
35
- throw new AggregateError(
36
- errors,
37
- "TypeScript Isolated Declarations Error"
38
- );
39
- }
40
- if (!context.outDir) {
41
- throw new Error("outDir is not set");
42
- }
43
- const outFile = path.relative(context.outBase, id2).replace(/\.(.?)ts$/, `.d.${context.outExt}`);
44
- this.emitFile({
45
- type: "asset",
46
- fileName: outFile,
47
- source: sourceText
48
- });
49
- },
50
- esbuild: {
51
- config(esbuildOptions) {
52
- const entries = esbuildOptions.entryPoints;
53
- if (!(entries && Array.isArray(entries) && entries.every((entry) => typeof entry === "string")))
54
- throw new Error("unsupported entryPoints, must be an string[]");
55
- const outBase = lowestCommonAncestor(...entries);
56
- const outDir = esbuildOptions.outdir || options.outDir;
57
- if (!outDir) {
58
- throw new Error("outDir is not set");
59
- }
60
- const jsExt = esbuildOptions.outExtension?.[".js"];
61
- let outExt;
62
- switch (jsExt) {
63
- case ".cjs":
64
- outExt = "cts";
65
- break;
66
- case ".mjs":
67
- outExt = "mts";
68
- break;
69
- default:
70
- outExt = "ts";
71
- break;
72
- }
73
- this.id = id++;
74
- contexts.push({
75
- outBase,
76
- outExt,
77
- outDir
78
- });
79
- }
80
- },
81
- rollup: {
82
- options(rollupOptions) {
83
- let outBase = "";
84
- let input = rollupOptions.input;
85
- input = typeof input === "string" ? [input] : input;
86
- if (Array.isArray(input)) {
87
- outBase = lowestCommonAncestor(...input);
88
- }
89
- if (!contexts.length) contexts.push({});
90
- contexts[0] = {
91
- outExt: options.outExt,
92
- outDir: options.outDir,
93
- outBase
94
- };
95
- }
96
- }
97
- };
98
- });
99
- var src_default = plugin;
100
- function lowestCommonAncestor(...filepaths) {
101
- if (filepaths.length === 0) return "";
102
- if (filepaths.length === 1) return path.dirname(filepaths[0]);
103
- const [first, ...rest] = filepaths;
104
- let ancestor = first.split(path.sep);
105
- for (const filepath of rest) {
106
- const directories = filepath.split(path.sep, ancestor.length);
107
- let index = 0;
108
- for (const directory of directories) {
109
- if (directory === ancestor[index]) {
110
- index += 1;
111
- } else {
112
- ancestor = ancestor.slice(0, index);
113
- break;
114
- }
115
- }
116
- ancestor = ancestor.slice(0, index);
117
- }
118
- return ancestor.length <= 1 && ancestor[0] === "" ? path.sep + ancestor[0] : ancestor.join(path.sep);
119
- }
120
-
121
- export {
122
- plugin,
123
- src_default
124
- };