unplugin-isolated-decl 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -0
- package/dist/core/options.d.cts +0 -2
- package/dist/core/options.d.ts +0 -2
- package/dist/esbuild.cjs +2 -2
- package/dist/esbuild.d.cts +2 -2
- package/dist/esbuild.d.ts +2 -2
- package/dist/esbuild.js +2 -2
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/rolldown.cjs +2 -2
- package/dist/rolldown.d.cts +2 -2
- package/dist/rolldown.d.ts +2 -2
- package/dist/rolldown.js +2 -2
- package/dist/rollup.cjs +2 -2
- package/dist/rollup.d.cts +2 -2
- package/dist/rollup.d.ts +2 -2
- package/dist/rollup.js +2 -2
- package/dist/src_index--o4926Ps.js +116 -0
- package/dist/src_index-1GProTgq.cjs +122 -0
- package/dist/vite.cjs +2 -2
- package/dist/vite.d.cts +2 -2
- package/dist/vite.d.ts +2 -2
- package/dist/vite.js +2 -2
- package/package.json +5 -5
- package/dist/src_index-SDbc5FOn.cjs +0 -140
- package/dist/src_index-X4PTeCWf.js +0 -130
package/README.md
CHANGED
|
@@ -16,6 +16,8 @@
|
|
|
16
16
|
npm i -D unplugin-isolated-decl
|
|
17
17
|
```
|
|
18
18
|
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
19
21
|
<details>
|
|
20
22
|
<summary>Vite</summary><br>
|
|
21
23
|
|
|
@@ -44,6 +46,20 @@ export default {
|
|
|
44
46
|
|
|
45
47
|
<br></details>
|
|
46
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
|
+
|
|
47
63
|
<details>
|
|
48
64
|
<summary>esbuild</summary><br>
|
|
49
65
|
|
package/dist/core/options.d.cts
CHANGED
|
@@ -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/core/options.d.ts
CHANGED
|
@@ -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,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
const { __export, __toCommonJS } = require("./chunk-J8LkbbVi.cjs");
|
|
4
|
-
const {
|
|
4
|
+
const { IsolatedDecl } = require("./src_index-1GProTgq.cjs");
|
|
5
5
|
|
|
6
6
|
//#region src/esbuild.ts
|
|
7
7
|
var esbuild_ns = {};
|
|
8
8
|
__export(esbuild_ns, {default: () => esbuild_default});
|
|
9
|
-
var esbuild_default =
|
|
9
|
+
var esbuild_default = IsolatedDecl.esbuild;
|
|
10
10
|
|
|
11
11
|
//#endregion
|
|
12
12
|
module.exports = __toCommonJS(esbuild_ns)
|
package/dist/esbuild.d.cts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
declare const _default: typeof
|
|
1
|
+
import { IsolatedDecl } from './index';
|
|
2
|
+
declare const _default: typeof IsolatedDecl.esbuild;
|
|
3
3
|
export default _default;
|
package/dist/esbuild.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
declare const _default: typeof
|
|
1
|
+
import { IsolatedDecl } from './index';
|
|
2
|
+
declare const _default: typeof IsolatedDecl.esbuild;
|
|
3
3
|
export default _default;
|
package/dist/esbuild.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IsolatedDecl } from "./src_index--o4926Ps.js";
|
|
2
2
|
|
|
3
3
|
//#region src/esbuild.ts
|
|
4
|
-
var esbuild_default =
|
|
4
|
+
var esbuild_default = IsolatedDecl.esbuild;
|
|
5
5
|
|
|
6
6
|
//#endregion
|
|
7
7
|
export { esbuild_default as default };
|
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
const { __toCommonJS } = require("./chunk-J8LkbbVi.cjs");
|
|
4
|
-
const {
|
|
4
|
+
const { IsolatedDecl, src_index_ns } = require("./src_index-1GProTgq.cjs");
|
|
5
5
|
|
|
6
6
|
module.exports = __toCommonJS(src_index_ns)
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { type UnpluginInstance } from 'unplugin';
|
|
2
2
|
import { type Options } from './core/options';
|
|
3
|
-
export
|
|
4
|
-
export
|
|
3
|
+
export type { Options };
|
|
4
|
+
export declare const IsolatedDecl: UnpluginInstance<((Options) | (undefined)), false>;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { type UnpluginInstance } from 'unplugin';
|
|
2
2
|
import { type Options } from './core/options';
|
|
3
|
-
export
|
|
4
|
-
export
|
|
3
|
+
export type { Options };
|
|
4
|
+
export declare const IsolatedDecl: UnpluginInstance<((Options) | (undefined)), false>;
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IsolatedDecl } from "./src_index--o4926Ps.js";
|
|
2
2
|
|
|
3
|
-
export {
|
|
3
|
+
export { IsolatedDecl };
|
package/dist/rolldown.cjs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
const { __export, __toCommonJS } = require("./chunk-J8LkbbVi.cjs");
|
|
4
|
-
const {
|
|
4
|
+
const { IsolatedDecl } = require("./src_index-1GProTgq.cjs");
|
|
5
5
|
|
|
6
6
|
//#region src/rolldown.ts
|
|
7
7
|
var rolldown_ns = {};
|
|
8
8
|
__export(rolldown_ns, {default: () => rolldown_default});
|
|
9
|
-
var rolldown_default =
|
|
9
|
+
var rolldown_default = IsolatedDecl.rolldown;
|
|
10
10
|
|
|
11
11
|
//#endregion
|
|
12
12
|
module.exports = __toCommonJS(rolldown_ns)
|
package/dist/rolldown.d.cts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
declare const _default: typeof
|
|
1
|
+
import { IsolatedDecl } from './index';
|
|
2
|
+
declare const _default: typeof IsolatedDecl.rolldown;
|
|
3
3
|
export default _default;
|
package/dist/rolldown.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
declare const _default: typeof
|
|
1
|
+
import { IsolatedDecl } from './index';
|
|
2
|
+
declare const _default: typeof IsolatedDecl.rolldown;
|
|
3
3
|
export default _default;
|
package/dist/rolldown.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IsolatedDecl } from "./src_index--o4926Ps.js";
|
|
2
2
|
|
|
3
3
|
//#region src/rolldown.ts
|
|
4
|
-
var rolldown_default =
|
|
4
|
+
var rolldown_default = IsolatedDecl.rolldown;
|
|
5
5
|
|
|
6
6
|
//#endregion
|
|
7
7
|
export { rolldown_default as default };
|
package/dist/rollup.cjs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
const { __export, __toCommonJS } = require("./chunk-J8LkbbVi.cjs");
|
|
4
|
-
const {
|
|
4
|
+
const { IsolatedDecl } = require("./src_index-1GProTgq.cjs");
|
|
5
5
|
|
|
6
6
|
//#region src/rollup.ts
|
|
7
7
|
var rollup_ns = {};
|
|
8
8
|
__export(rollup_ns, {default: () => rollup_default});
|
|
9
|
-
var rollup_default =
|
|
9
|
+
var rollup_default = IsolatedDecl.rollup;
|
|
10
10
|
|
|
11
11
|
//#endregion
|
|
12
12
|
module.exports = __toCommonJS(rollup_ns)
|
package/dist/rollup.d.cts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
declare const _default: typeof
|
|
1
|
+
import { IsolatedDecl } from './index';
|
|
2
|
+
declare const _default: typeof IsolatedDecl.rollup;
|
|
3
3
|
export default _default;
|
package/dist/rollup.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
declare const _default: typeof
|
|
1
|
+
import { IsolatedDecl } from './index';
|
|
2
|
+
declare const _default: typeof IsolatedDecl.rollup;
|
|
3
3
|
export default _default;
|
package/dist/rollup.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IsolatedDecl } from "./src_index--o4926Ps.js";
|
|
2
2
|
|
|
3
3
|
//#region src/rollup.ts
|
|
4
|
-
var rollup_default =
|
|
4
|
+
var rollup_default = IsolatedDecl.rollup;
|
|
5
5
|
|
|
6
6
|
//#endregion
|
|
7
7
|
export { rollup_default as default };
|
|
@@ -0,0 +1,116 @@
|
|
|
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 IsolatedDecl = 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
|
+
function lowestCommonAncestor(...filepaths) {
|
|
95
|
+
if (filepaths.length === 0) return '';
|
|
96
|
+
if (filepaths.length === 1) return path.dirname(filepaths[0]);
|
|
97
|
+
const [first, ...rest] = filepaths;
|
|
98
|
+
let ancestor = first.split(path.sep);
|
|
99
|
+
for (const filepath of rest) {
|
|
100
|
+
const directories = filepath.split(path.sep, ancestor.length);
|
|
101
|
+
let index = 0;
|
|
102
|
+
for (const directory of directories) {
|
|
103
|
+
if (directory === ancestor[index]) {
|
|
104
|
+
index += 1;
|
|
105
|
+
} else {
|
|
106
|
+
ancestor = ancestor.slice(0, index);
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
ancestor = ancestor.slice(0, index);
|
|
111
|
+
}
|
|
112
|
+
return ancestor.length <= 1 && ancestor[0] === '' ? path.sep + ancestor[0] : ancestor.join(path.sep);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
//#endregion
|
|
116
|
+
export { IsolatedDecl };
|
|
@@ -0,0 +1,122 @@
|
|
|
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, {IsolatedDecl: () => IsolatedDecl});
|
|
23
|
+
const IsolatedDecl = createUnplugin((rawOptions = {}, meta) => {
|
|
24
|
+
const options = resolveOptions(rawOptions);
|
|
25
|
+
const filter = createFilter(options.include, options.exclude);
|
|
26
|
+
const outputFiles = {};
|
|
27
|
+
function addOutput(filename, source) {
|
|
28
|
+
outputFiles[filename.replace(/\.(.?)[jt]s$/, '')] = source;
|
|
29
|
+
}
|
|
30
|
+
const rollup = {renderStart(outputOptions, inputOptions) {
|
|
31
|
+
let outBase = '';
|
|
32
|
+
let input = inputOptions.input;
|
|
33
|
+
input = typeof input === 'string' ? [input] : input;
|
|
34
|
+
if (Array.isArray(input)) {
|
|
35
|
+
outBase = lowestCommonAncestor(...input);
|
|
36
|
+
}
|
|
37
|
+
if (typeof outputOptions.entryFileNames !== 'string') {
|
|
38
|
+
return this.error('entryFileNames must be a string');
|
|
39
|
+
}
|
|
40
|
+
const entryFileNames = outputOptions.entryFileNames.replace(/\.(.)?[jt]s$/, (_, s) => `.d.${s || ''}ts`);
|
|
41
|
+
for (const [filename, source] of Object.entries(outputFiles)) {
|
|
42
|
+
this.emitFile({
|
|
43
|
+
type: 'asset',
|
|
44
|
+
fileName: entryFileNames.replace('[name]', path.relative(outBase, filename)),
|
|
45
|
+
source
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}};
|
|
49
|
+
return {
|
|
50
|
+
name: 'unplugin-isolated-decl',
|
|
51
|
+
transformInclude(id) {
|
|
52
|
+
return filter(id);
|
|
53
|
+
},
|
|
54
|
+
transform(code, id) {
|
|
55
|
+
const { sourceText, errors } = isolatedDeclaration(id, code);
|
|
56
|
+
if (errors.length) {
|
|
57
|
+
this.error(errors[0]);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
addOutput(id, sourceText);
|
|
61
|
+
},
|
|
62
|
+
async buildEnd() {
|
|
63
|
+
if (meta.framework === 'esbuild') {
|
|
64
|
+
const esbuildOptions = meta.build.initialOptions;
|
|
65
|
+
const entries = esbuildOptions.entryPoints;
|
|
66
|
+
if (!(entries && Array.isArray(entries) && entries.every((entry) => typeof entry === 'string'))) throw new Error('unsupported entryPoints, must be an string[]');
|
|
67
|
+
const outBase = lowestCommonAncestor(...entries);
|
|
68
|
+
const jsExt = esbuildOptions.outExtension?.['.js'];
|
|
69
|
+
let outExt;
|
|
70
|
+
switch (jsExt) {
|
|
71
|
+
case '.cjs':
|
|
72
|
+
outExt = 'cts';
|
|
73
|
+
break;
|
|
74
|
+
case '.mjs':
|
|
75
|
+
outExt = 'mts';
|
|
76
|
+
break;
|
|
77
|
+
default:
|
|
78
|
+
outExt = 'ts';
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
const build = meta.build;
|
|
82
|
+
if (build.initialOptions.outdir && (build.initialOptions.write ?? true)) for (const [filename, source] of Object.entries(outputFiles)) {
|
|
83
|
+
const outFile = `${path.relative(outBase, filename)}.d.${outExt}`;
|
|
84
|
+
const filePath = path.resolve(build.initialOptions.outdir, outFile);
|
|
85
|
+
await mkdir(path.dirname(filePath), {recursive: true});
|
|
86
|
+
await writeFile(filePath, source);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
rollup,
|
|
91
|
+
rolldown: rollup,
|
|
92
|
+
vite: {
|
|
93
|
+
apply: 'build',
|
|
94
|
+
enforce: 'pre',
|
|
95
|
+
...rollup
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
});
|
|
99
|
+
function lowestCommonAncestor(...filepaths) {
|
|
100
|
+
if (filepaths.length === 0) return '';
|
|
101
|
+
if (filepaths.length === 1) return path.dirname(filepaths[0]);
|
|
102
|
+
const [first, ...rest] = filepaths;
|
|
103
|
+
let ancestor = first.split(path.sep);
|
|
104
|
+
for (const filepath of rest) {
|
|
105
|
+
const directories = filepath.split(path.sep, ancestor.length);
|
|
106
|
+
let index = 0;
|
|
107
|
+
for (const directory of directories) {
|
|
108
|
+
if (directory === ancestor[index]) {
|
|
109
|
+
index += 1;
|
|
110
|
+
} else {
|
|
111
|
+
ancestor = ancestor.slice(0, index);
|
|
112
|
+
break;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
ancestor = ancestor.slice(0, index);
|
|
116
|
+
}
|
|
117
|
+
return ancestor.length <= 1 && ancestor[0] === '' ? path.sep + ancestor[0] : ancestor.join(path.sep);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
//#endregion
|
|
121
|
+
exports.IsolatedDecl = IsolatedDecl;
|
|
122
|
+
exports.src_index_ns = src_index_ns;
|
package/dist/vite.cjs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
const { __export, __toCommonJS } = require("./chunk-J8LkbbVi.cjs");
|
|
4
|
-
const {
|
|
4
|
+
const { IsolatedDecl } = require("./src_index-1GProTgq.cjs");
|
|
5
5
|
|
|
6
6
|
//#region src/vite.ts
|
|
7
7
|
var vite_ns = {};
|
|
8
8
|
__export(vite_ns, {default: () => vite_default});
|
|
9
|
-
var vite_default =
|
|
9
|
+
var vite_default = IsolatedDecl.vite;
|
|
10
10
|
|
|
11
11
|
//#endregion
|
|
12
12
|
module.exports = __toCommonJS(vite_ns)
|
package/dist/vite.d.cts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
declare const _default: typeof
|
|
1
|
+
import { IsolatedDecl } from './index';
|
|
2
|
+
declare const _default: typeof IsolatedDecl.vite;
|
|
3
3
|
export default _default;
|
package/dist/vite.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
declare const _default: typeof
|
|
1
|
+
import { IsolatedDecl } from './index';
|
|
2
|
+
declare const _default: typeof IsolatedDecl.vite;
|
|
3
3
|
export default _default;
|
package/dist/vite.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IsolatedDecl } from "./src_index--o4926Ps.js";
|
|
2
2
|
|
|
3
3
|
//#region src/vite.ts
|
|
4
|
-
var vite_default =
|
|
4
|
+
var vite_default = IsolatedDecl.vite;
|
|
5
5
|
|
|
6
6
|
//#endregion
|
|
7
7
|
export { vite_default as default };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "unplugin-isolated-decl",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "A blazing-fast tool for generating isolated declarations, powered by Oxc.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [
|
|
@@ -69,7 +69,6 @@
|
|
|
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
|
},
|
|
@@ -78,14 +77,15 @@
|
|
|
78
77
|
"@sxzz/prettier-config": "^2.0.2",
|
|
79
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
|
-
"tsdown": "^0.2.
|
|
86
|
-
"tsx": "^4.15.
|
|
85
|
+
"tsdown": "^0.2.2",
|
|
86
|
+
"tsx": "^4.15.8",
|
|
87
87
|
"typescript": "^5.5.2",
|
|
88
|
-
"vite": "^5.3.
|
|
88
|
+
"vite": "^5.3.2",
|
|
89
89
|
"vitest": "^1.6.0"
|
|
90
90
|
},
|
|
91
91
|
"engines": {
|
|
@@ -1,140 +0,0 @@
|
|
|
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;
|
|
@@ -1,130 +0,0 @@
|
|
|
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 };
|