unplugin-isolated-decl 0.0.1-beta.1 → 0.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 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
 
@@ -62,4 +68,4 @@ build({
62
68
 
63
69
  ## License
64
70
 
65
- [MIT](./LICENSE) License © 2023-PRESENT [三咲智子](https://github.com/sxzz)
71
+ [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;
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 _chunkXXL4LKYMcjs = require('./chunk-XXL4LKYM.cjs');
3
+ const { __export, __toCommonJS } = require("./chunk-J8LkbbVi.cjs");
4
+ const { src_index_default } = require("./src_index-SDbc5FOn.cjs");
4
5
 
5
- // src/esbuild.ts
6
- var esbuild_default = _chunkXXL4LKYMcjs.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-TQTDSJS3.js";
1
+ import { src_index_default } from "./src_index-X4PTeCWf.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-SDbc5FOn.cjs");
3
5
 
4
- var _chunkXXL4LKYMcjs = require('./chunk-XXL4LKYM.cjs');
5
-
6
-
7
-
8
- exports.default = _chunkXXL4LKYMcjs.src_default; exports.plugin = _chunkXXL4LKYMcjs.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-TQTDSJS3.js";
5
- export {
6
- src_default as default,
7
- plugin
8
- };
1
+ import { plugin, src_index_default } from "./src_index-X4PTeCWf.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-SDbc5FOn.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-X4PTeCWf.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 _chunkXXL4LKYMcjs = require('./chunk-XXL4LKYM.cjs');
3
+ const { __export, __toCommonJS } = require("./chunk-J8LkbbVi.cjs");
4
+ const { src_index_default } = require("./src_index-SDbc5FOn.cjs");
4
5
 
5
- // src/rollup.ts
6
- var rollup_default = _chunkXXL4LKYMcjs.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-TQTDSJS3.js";
1
+ import { src_index_default } from "./src_index-X4PTeCWf.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,140 @@
1
+ "use strict";
2
+
3
+ const { __export, __toESM } = require("./chunk-J8LkbbVi.cjs");
4
+ const { default: path } = __toESM(require("node:path"));
5
+ const { createUnplugin } = __toESM(require("unplugin"));
6
+ const { isolatedDeclaration } = __toESM(require("oxc-transform"));
7
+ const { createFilter } = __toESM(require("@rollup/pluginutils"));
8
+
9
+ //#region 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
+ //#endregion
21
+ //#region src/index.ts
22
+ var src_index_ns = {};
23
+ __export(src_index_ns, {
24
+ default: () => src_index_default,
25
+ plugin: () => plugin
26
+ });
27
+ const plugin = createUnplugin((rawOptions = {}, { framework }) => {
28
+ const options = resolveOptions(rawOptions);
29
+ const filter = createFilter(options.include, options.exclude);
30
+ const contexts = [];
31
+ let id = 0;
32
+ const emitFiles = {};
33
+ function emit(ctx, filename, source, outExt) {
34
+ if (framework === 'esbuild') {
35
+ ctx.emitFile({
36
+ type: 'asset',
37
+ fileName: filename.replace(/\.(.?)ts$/, `.d.${outExt}`),
38
+ source
39
+ });
40
+ } else {
41
+ emitFiles[filename.replace(/\.(.?)[jt]s$/, '')] = source;
42
+ }
43
+ }
44
+ const rollup = {
45
+ options(rollupOptions) {
46
+ let outBase = '';
47
+ let input = rollupOptions.input;
48
+ input = typeof input === 'string' ? [input] : input;
49
+ if (Array.isArray(input)) {
50
+ outBase = lowestCommonAncestor(...input);
51
+ }
52
+ if (!contexts.length) contexts.push({});
53
+ contexts[0] = {
54
+ outExt: options.outExt,
55
+ outBase
56
+ };
57
+ },
58
+ renderStart(outputOptions) {
59
+ if (typeof outputOptions.entryFileNames !== 'string') {
60
+ return this.error('entryFileNames must be a string');
61
+ }
62
+ const entryFileNames = outputOptions.entryFileNames.replace(/\.(.)?[jt]s$/, (_, s) => `.d.${s || ''}ts`);
63
+ for (const [filename, source] of Object.entries(emitFiles)) {
64
+ this.emitFile({
65
+ type: 'asset',
66
+ fileName: entryFileNames.replace('[name]', filename),
67
+ source
68
+ });
69
+ }
70
+ }
71
+ };
72
+ return {
73
+ name: 'unplugin-isolated-decl',
74
+ transformInclude(id$1) {
75
+ return filter(id$1);
76
+ },
77
+ transform(code, id$1) {
78
+ const context = contexts[this.id || 0];
79
+ const { sourceText, errors } = isolatedDeclaration(id$1, code);
80
+ if (errors.length) {
81
+ this.error(errors[0]);
82
+ return;
83
+ }
84
+ const outFile = path.relative(context.outBase, id$1);
85
+ emit(this, outFile, sourceText, context.outExt);
86
+ },
87
+ esbuild: {config(esbuildOptions) {
88
+ const entries = esbuildOptions.entryPoints;
89
+ if (!(entries && Array.isArray(entries) && entries.every((entry) => typeof entry === 'string'))) throw new Error('unsupported entryPoints, must be an string[]');
90
+ const outBase = lowestCommonAncestor(...entries);
91
+ const jsExt = esbuildOptions.outExtension?.['.js'];
92
+ let outExt;
93
+ switch (jsExt) {
94
+ case '.cjs':
95
+ outExt = 'cts';
96
+ break;
97
+ case '.mjs':
98
+ outExt = 'mts';
99
+ break;
100
+ default:
101
+ outExt = 'ts';
102
+ break;
103
+ }
104
+ this.id = id++;
105
+ contexts.push({
106
+ outBase,
107
+ outExt
108
+ });
109
+ }},
110
+ rollup,
111
+ rolldown: rollup,
112
+ vite: rollup
113
+ };
114
+ });
115
+ var src_index_default = plugin;
116
+ function lowestCommonAncestor(...filepaths) {
117
+ if (filepaths.length === 0) return '';
118
+ if (filepaths.length === 1) return path.dirname(filepaths[0]);
119
+ const [first, ...rest] = filepaths;
120
+ let ancestor = first.split(path.sep);
121
+ for (const filepath of rest) {
122
+ const directories = filepath.split(path.sep, ancestor.length);
123
+ let index = 0;
124
+ for (const directory of directories) {
125
+ if (directory === ancestor[index]) {
126
+ index += 1;
127
+ } else {
128
+ ancestor = ancestor.slice(0, index);
129
+ break;
130
+ }
131
+ }
132
+ ancestor = ancestor.slice(0, index);
133
+ }
134
+ return ancestor.length <= 1 && ancestor[0] === '' ? path.sep + ancestor[0] : ancestor.join(path.sep);
135
+ }
136
+
137
+ //#endregion
138
+ exports.plugin = plugin;
139
+ exports.src_index_default = src_index_default;
140
+ exports.src_index_ns = src_index_ns;
@@ -0,0 +1,130 @@
1
+ import { default as path } from "node:path";
2
+ import { createUnplugin } from "unplugin";
3
+ import { isolatedDeclaration } from "oxc-transform";
4
+ import { createFilter } from "@rollup/pluginutils";
5
+
6
+ //#region src/core/options.ts
7
+ function resolveOptions(options) {
8
+ return {
9
+ include: options.include || [/\.[cm]?[jt]sx?$/],
10
+ exclude: options.exclude || [/node_modules/],
11
+ enforce: 'enforce'in options ? options.enforce : 'pre',
12
+ outDir: options.outDir || 'dist',
13
+ outExt: options.outExt || 'ts'
14
+ };
15
+ }
16
+
17
+ //#endregion
18
+ //#region src/index.ts
19
+ const plugin = createUnplugin((rawOptions = {}, { framework }) => {
20
+ const options = resolveOptions(rawOptions);
21
+ const filter = createFilter(options.include, options.exclude);
22
+ const contexts = [];
23
+ let id = 0;
24
+ const emitFiles = {};
25
+ function emit(ctx, filename, source, outExt) {
26
+ if (framework === 'esbuild') {
27
+ ctx.emitFile({
28
+ type: 'asset',
29
+ fileName: filename.replace(/\.(.?)ts$/, `.d.${outExt}`),
30
+ source
31
+ });
32
+ } else {
33
+ emitFiles[filename.replace(/\.(.?)[jt]s$/, '')] = source;
34
+ }
35
+ }
36
+ const rollup = {
37
+ options(rollupOptions) {
38
+ let outBase = '';
39
+ let input = rollupOptions.input;
40
+ input = typeof input === 'string' ? [input] : input;
41
+ if (Array.isArray(input)) {
42
+ outBase = lowestCommonAncestor(...input);
43
+ }
44
+ if (!contexts.length) contexts.push({});
45
+ contexts[0] = {
46
+ outExt: options.outExt,
47
+ outBase
48
+ };
49
+ },
50
+ renderStart(outputOptions) {
51
+ if (typeof outputOptions.entryFileNames !== 'string') {
52
+ return this.error('entryFileNames must be a string');
53
+ }
54
+ const entryFileNames = outputOptions.entryFileNames.replace(/\.(.)?[jt]s$/, (_, s) => `.d.${s || ''}ts`);
55
+ for (const [filename, source] of Object.entries(emitFiles)) {
56
+ this.emitFile({
57
+ type: 'asset',
58
+ fileName: entryFileNames.replace('[name]', filename),
59
+ source
60
+ });
61
+ }
62
+ }
63
+ };
64
+ return {
65
+ name: 'unplugin-isolated-decl',
66
+ transformInclude(id$1) {
67
+ return filter(id$1);
68
+ },
69
+ transform(code, id$1) {
70
+ const context = contexts[this.id || 0];
71
+ const { sourceText, errors } = isolatedDeclaration(id$1, code);
72
+ if (errors.length) {
73
+ this.error(errors[0]);
74
+ return;
75
+ }
76
+ const outFile = path.relative(context.outBase, id$1);
77
+ emit(this, outFile, sourceText, context.outExt);
78
+ },
79
+ esbuild: {config(esbuildOptions) {
80
+ const entries = esbuildOptions.entryPoints;
81
+ if (!(entries && Array.isArray(entries) && entries.every((entry) => typeof entry === 'string'))) throw new Error('unsupported entryPoints, must be an string[]');
82
+ const outBase = lowestCommonAncestor(...entries);
83
+ const jsExt = esbuildOptions.outExtension?.['.js'];
84
+ let outExt;
85
+ switch (jsExt) {
86
+ case '.cjs':
87
+ outExt = 'cts';
88
+ break;
89
+ case '.mjs':
90
+ outExt = 'mts';
91
+ break;
92
+ default:
93
+ outExt = 'ts';
94
+ break;
95
+ }
96
+ this.id = id++;
97
+ contexts.push({
98
+ outBase,
99
+ outExt
100
+ });
101
+ }},
102
+ rollup,
103
+ rolldown: rollup,
104
+ vite: rollup
105
+ };
106
+ });
107
+ var src_index_default = plugin;
108
+ function lowestCommonAncestor(...filepaths) {
109
+ if (filepaths.length === 0) return '';
110
+ if (filepaths.length === 1) return path.dirname(filepaths[0]);
111
+ const [first, ...rest] = filepaths;
112
+ let ancestor = first.split(path.sep);
113
+ for (const filepath of rest) {
114
+ const directories = filepath.split(path.sep, ancestor.length);
115
+ let index = 0;
116
+ for (const directory of directories) {
117
+ if (directory === ancestor[index]) {
118
+ index += 1;
119
+ } else {
120
+ ancestor = ancestor.slice(0, index);
121
+ break;
122
+ }
123
+ }
124
+ ancestor = ancestor.slice(0, index);
125
+ }
126
+ return ancestor.length <= 1 && ancestor[0] === '' ? path.sep + ancestor[0] : ancestor.join(path.sep);
127
+ }
128
+
129
+ //#endregion
130
+ export { plugin, src_index_default };
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 _chunkXXL4LKYMcjs = require('./chunk-XXL4LKYM.cjs');
3
+ const { __export, __toCommonJS } = require("./chunk-J8LkbbVi.cjs");
4
+ const { src_index_default } = require("./src_index-SDbc5FOn.cjs");
4
5
 
5
- // src/vite.ts
6
- var vite_default = _chunkXXL4LKYMcjs.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-TQTDSJS3.js";
1
+ import { src_index_default } from "./src_index-X4PTeCWf.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.1",
4
- "description": "Generate isolated declaration.",
3
+ "version": "0.1.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"
@@ -76,13 +76,13 @@
76
76
  "devDependencies": {
77
77
  "@sxzz/eslint-config": "^3.13.0",
78
78
  "@sxzz/prettier-config": "^2.0.2",
79
- "@types/node": "^20.14.8",
79
+ "@types/node": "^20.14.9",
80
80
  "bumpp": "^9.4.1",
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",
85
+ "tsdown": "^0.2.0",
86
86
  "tsx": "^4.15.7",
87
87
  "typescript": "^5.5.2",
88
88
  "vite": "^5.3.1",
@@ -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
- // 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
- const input = rollupOptions.input;
85
- if (Array.isArray(input)) {
86
- outBase = lowestCommonAncestor(...input);
87
- } else if (typeof input === "string") {
88
- outBase = path.dirname(input);
89
- }
90
- if (!contexts.length) contexts.push({});
91
- contexts[0] = {
92
- outExt: options.outExt,
93
- outDir: options.outDir,
94
- outBase
95
- };
96
- }
97
- }
98
- };
99
- });
100
- var src_default = plugin;
101
- function lowestCommonAncestor(...filepaths) {
102
- if (filepaths.length <= 1) return "";
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
- };
@@ -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
- const input = rollupOptions.input;
85
- if (Array.isArray(input)) {
86
- outBase = lowestCommonAncestor(...input);
87
- } else if (typeof input === "string") {
88
- outBase = _path2.default.dirname(input);
89
- }
90
- if (!contexts.length) contexts.push({});
91
- contexts[0] = {
92
- outExt: options.outExt,
93
- outDir: options.outDir,
94
- outBase
95
- };
96
- }
97
- }
98
- };
99
- });
100
- var src_default = plugin;
101
- function lowestCommonAncestor(...filepaths) {
102
- if (filepaths.length <= 1) return "";
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;