unplugin-isolated-decl 0.9.5 → 0.10.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 +0 -18
- package/dist/api.d.cts +1 -1
- package/dist/core/ast.d.cts +3 -2
- package/dist/core/ast.d.ts +3 -2
- package/dist/core/options.d.cts +0 -2
- package/dist/core/options.d.ts +0 -2
- package/dist/core/utils.d.cts +1 -1
- package/dist/core/utils.d.ts +1 -1
- package/dist/esbuild.cjs +1 -1
- package/dist/esbuild.d.cts +1 -1
- package/dist/esbuild.js +1 -1
- package/dist/farm.cjs +1 -1
- package/dist/farm.d.cts +1 -1
- package/dist/farm.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.js +1 -1
- package/dist/rolldown.cjs +1 -1
- package/dist/rolldown.d.cts +1 -1
- package/dist/rolldown.js +1 -1
- package/dist/rollup.cjs +1 -1
- package/dist/rollup.d.cts +1 -1
- package/dist/rollup.js +1 -1
- package/dist/{src-DKq4C5zO.js → src-BG0S9gFu.js} +13 -19
- package/dist/{src-1TNLOrgN.cjs → src-DPQU5TkD.cjs} +13 -19
- package/dist/vite.cjs +1 -1
- package/dist/vite.d.cts +1 -1
- package/dist/vite.js +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -123,8 +123,6 @@ export interface Options {
|
|
|
123
123
|
ignoreErrors?: boolean
|
|
124
124
|
/** An extra directory layer for output files. */
|
|
125
125
|
extraOutdir?: string
|
|
126
|
-
/** Automatically add `.js` extension to resolve in `Node16` + ESM mode. */
|
|
127
|
-
autoAddExts?: boolean
|
|
128
126
|
|
|
129
127
|
rewriteImports?: (
|
|
130
128
|
id: string,
|
|
@@ -157,22 +155,6 @@ export default {
|
|
|
157
155
|
}
|
|
158
156
|
```
|
|
159
157
|
|
|
160
|
-
### `autoAddExts`
|
|
161
|
-
|
|
162
|
-
Automatically add `.js` extension to resolve in Node 16+ ESM mode. (esbuild support is not available)
|
|
163
|
-
|
|
164
|
-
```ts
|
|
165
|
-
// index.d.ts
|
|
166
|
-
import {} from './foo'
|
|
167
|
-
```
|
|
168
|
-
|
|
169
|
-
With `autoAddExts`, it will be transformed to:
|
|
170
|
-
|
|
171
|
-
```ts
|
|
172
|
-
// index.d.ts
|
|
173
|
-
import {} from './foo.js'
|
|
174
|
-
```
|
|
175
|
-
|
|
176
158
|
### `patchCjsDefaultExport`
|
|
177
159
|
|
|
178
160
|
Patch `export default` in `.d.cts` to `export =`
|
package/dist/api.d.cts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { oxcTransform, swcTransform, tsTransform } from './core/transformer.
|
|
1
|
+
export { oxcTransform, swcTransform, tsTransform } from './core/transformer.cjs';
|
package/dist/core/ast.d.cts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import type { OptionsResolved } from './options.cjs';
|
|
1
2
|
import type * as OxcTypes from '@oxc-project/types';
|
|
2
3
|
import type MagicString from 'magic-string';
|
|
3
4
|
export type OxcImport = (OxcTypes.ImportDeclaration | OxcTypes.ExportAllDeclaration | OxcTypes.ExportNamedDeclaration) & {
|
|
4
5
|
source: OxcTypes.StringLiteral;
|
|
5
|
-
|
|
6
|
+
shouldAddIndex?: boolean;
|
|
6
7
|
};
|
|
7
8
|
export declare function filterImports(program: OxcTypes.Program): OxcImport[];
|
|
8
|
-
export declare function rewriteImports(s: MagicString, imports: OxcImport[], entryMap: Record<string, string> | undefined, inputBase: string, entryFileNames: string, srcFilename: string): string;
|
|
9
|
+
export declare function rewriteImports(s: MagicString, options: OptionsResolved, imports: OxcImport[], entryMap: Record<string, string> | undefined, inputBase: string, entryFileNames: string, srcFilename: string): string;
|
package/dist/core/ast.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import type { OptionsResolved } from './options.js';
|
|
1
2
|
import type * as OxcTypes from '@oxc-project/types';
|
|
2
3
|
import type MagicString from 'magic-string';
|
|
3
4
|
export type OxcImport = (OxcTypes.ImportDeclaration | OxcTypes.ExportAllDeclaration | OxcTypes.ExportNamedDeclaration) & {
|
|
4
5
|
source: OxcTypes.StringLiteral;
|
|
5
|
-
|
|
6
|
+
shouldAddIndex?: boolean;
|
|
6
7
|
};
|
|
7
8
|
export declare function filterImports(program: OxcTypes.Program): OxcImport[];
|
|
8
|
-
export declare function rewriteImports(s: MagicString, imports: OxcImport[], entryMap: Record<string, string> | undefined, inputBase: string, entryFileNames: string, srcFilename: string): string;
|
|
9
|
+
export declare function rewriteImports(s: MagicString, options: OptionsResolved, imports: OxcImport[], entryMap: Record<string, string> | undefined, inputBase: string, entryFileNames: string, srcFilename: string): string;
|
package/dist/core/options.d.cts
CHANGED
|
@@ -18,8 +18,6 @@ export type Options = {
|
|
|
18
18
|
ignoreErrors?: boolean;
|
|
19
19
|
/** An extra directory layer for output files. */
|
|
20
20
|
extraOutdir?: string;
|
|
21
|
-
/** Automatically add `.js` extension to resolve in `Node16` + ESM mode. */
|
|
22
|
-
autoAddExts?: boolean;
|
|
23
21
|
/** Patch `export default` in `.d.cts` to `export = ` */
|
|
24
22
|
patchCjsDefaultExport?: boolean;
|
|
25
23
|
/** Base directory for input files. */
|
package/dist/core/options.d.ts
CHANGED
|
@@ -18,8 +18,6 @@ export type Options = {
|
|
|
18
18
|
ignoreErrors?: boolean;
|
|
19
19
|
/** An extra directory layer for output files. */
|
|
20
20
|
extraOutdir?: string;
|
|
21
|
-
/** Automatically add `.js` extension to resolve in `Node16` + ESM mode. */
|
|
22
|
-
autoAddExts?: boolean;
|
|
23
21
|
/** Patch `export default` in `.d.cts` to `export = ` */
|
|
24
22
|
patchCjsDefaultExport?: boolean;
|
|
25
23
|
/** Base directory for input files. */
|
package/dist/core/utils.d.cts
CHANGED
|
@@ -6,4 +6,4 @@ export declare function resolveEntry(input: string | string[] | Record<string, s
|
|
|
6
6
|
entryMap: Record<string, string> | undefined;
|
|
7
7
|
inputBase: string;
|
|
8
8
|
};
|
|
9
|
-
export declare function
|
|
9
|
+
export declare function shouldAddIndex(id: string, resolved: string): boolean;
|
package/dist/core/utils.d.ts
CHANGED
|
@@ -6,4 +6,4 @@ export declare function resolveEntry(input: string | string[] | Record<string, s
|
|
|
6
6
|
entryMap: Record<string, string> | undefined;
|
|
7
7
|
inputBase: string;
|
|
8
8
|
};
|
|
9
|
-
export declare function
|
|
9
|
+
export declare function shouldAddIndex(id: string, resolved: string): boolean;
|
package/dist/esbuild.cjs
CHANGED
package/dist/esbuild.d.cts
CHANGED
package/dist/esbuild.js
CHANGED
package/dist/farm.cjs
CHANGED
package/dist/farm.d.cts
CHANGED
package/dist/farm.js
CHANGED
package/dist/index.cjs
CHANGED
package/dist/index.d.cts
CHANGED
package/dist/index.js
CHANGED
package/dist/rolldown.cjs
CHANGED
package/dist/rolldown.d.cts
CHANGED
package/dist/rolldown.js
CHANGED
package/dist/rollup.cjs
CHANGED
package/dist/rollup.d.cts
CHANGED
package/dist/rollup.js
CHANGED
|
@@ -43,12 +43,8 @@ function resolveEntry(input, userInputBase) {
|
|
|
43
43
|
function endsWithIndex(s) {
|
|
44
44
|
return /(?:^|[/\\])index\..+$/.test(s);
|
|
45
45
|
}
|
|
46
|
-
function
|
|
47
|
-
|
|
48
|
-
if (!endsWithIndex(id) && endsWithIndex(resolved)) suffix += "/index";
|
|
49
|
-
const ext = path$2.extname(resolved).slice(1).replace(/^([cm]?)ts/, (_, $1) => `${$1}js`);
|
|
50
|
-
if (ext) suffix += `.${ext}`;
|
|
51
|
-
return suffix;
|
|
46
|
+
function shouldAddIndex(id, resolved) {
|
|
47
|
+
return !endsWithIndex(id) && endsWithIndex(resolved);
|
|
52
48
|
}
|
|
53
49
|
|
|
54
50
|
//#endregion
|
|
@@ -56,7 +52,7 @@ function guessSuffix(id, resolved) {
|
|
|
56
52
|
function filterImports(program) {
|
|
57
53
|
return program.body.filter((node) => (node.type === "ImportDeclaration" || node.type === "ExportAllDeclaration" || node.type === "ExportNamedDeclaration") && !!node.source);
|
|
58
54
|
}
|
|
59
|
-
function rewriteImports(s, imports, entryMap, inputBase, entryFileNames, srcFilename) {
|
|
55
|
+
function rewriteImports(s, options, imports, entryMap, inputBase, entryFileNames, srcFilename) {
|
|
60
56
|
const srcRel = path$1.relative(inputBase, srcFilename);
|
|
61
57
|
const srcDir = path$1.dirname(srcFilename);
|
|
62
58
|
const srcDirRel = path$1.relative(inputBase, srcDir);
|
|
@@ -69,17 +65,16 @@ function rewriteImports(s, imports, entryMap, inputBase, entryFileNames, srcFile
|
|
|
69
65
|
const offset = path$1.relative(emitDir, srcDirRel);
|
|
70
66
|
for (const i of imports) {
|
|
71
67
|
const { source } = i;
|
|
72
|
-
|
|
68
|
+
let srcIdRel = source.value;
|
|
73
69
|
if (srcIdRel[0] !== ".") continue;
|
|
70
|
+
if (i.shouldAddIndex) srcIdRel += "/index";
|
|
74
71
|
const srcId = path$1.resolve(srcDir, srcIdRel);
|
|
75
|
-
const importAlias = entryMap?.[srcId];
|
|
72
|
+
const importAlias = entryMap?.[stripExt(srcId)];
|
|
76
73
|
let id;
|
|
77
74
|
if (importAlias) {
|
|
78
|
-
const resolved =
|
|
75
|
+
const resolved = entryFileNames.replaceAll("[name]", stripExt(importAlias));
|
|
79
76
|
id = pathRelative(srcDirRel, resolved);
|
|
80
|
-
} else id =
|
|
81
|
-
const suffix = i.suffix || guessSuffix(source.value, source.value);
|
|
82
|
-
if (suffix) id += suffix;
|
|
77
|
+
} else id = entryFileNames.replaceAll("[name]", stripExt(srcIdRel));
|
|
83
78
|
let final = path$1.normalize(path$1.join(offset, id));
|
|
84
79
|
if (final !== path$1.normalize(source.value)) {
|
|
85
80
|
debug("Patch import in", srcRel, ":", srcIdRel, "->", final);
|
|
@@ -106,7 +101,6 @@ function resolveOptions(options) {
|
|
|
106
101
|
transformer: options.transformer || "typescript",
|
|
107
102
|
ignoreErrors: options.ignoreErrors || false,
|
|
108
103
|
extraOutdir: options.extraOutdir,
|
|
109
|
-
autoAddExts: options.autoAddExts || false,
|
|
110
104
|
patchCjsDefaultExport: options.patchCjsDefaultExport || false,
|
|
111
105
|
rewriteImports: options.rewriteImports,
|
|
112
106
|
inputBase: options.inputBase
|
|
@@ -175,7 +169,7 @@ else {
|
|
|
175
169
|
const { program } = await parseAsync(id, dts);
|
|
176
170
|
const imports = filterImports(program);
|
|
177
171
|
const s = new MagicString(dts);
|
|
178
|
-
|
|
172
|
+
for (const i of imports) {
|
|
179
173
|
const { source } = i;
|
|
180
174
|
let { value } = source;
|
|
181
175
|
if (options.rewriteImports) {
|
|
@@ -185,10 +179,10 @@ else {
|
|
|
185
179
|
s.overwrite(source.start + 1, source.end - 1, result$1);
|
|
186
180
|
}
|
|
187
181
|
}
|
|
188
|
-
if (
|
|
182
|
+
if (path.isAbsolute(value) || value[0] === ".") {
|
|
189
183
|
const resolved = await resolve(context, value, stripExt(id));
|
|
190
184
|
if (!resolved || resolved.external) continue;
|
|
191
|
-
i.
|
|
185
|
+
i.shouldAddIndex = shouldAddIndex(value, resolved.id);
|
|
192
186
|
}
|
|
193
187
|
}
|
|
194
188
|
addOutput(id, {
|
|
@@ -225,7 +219,7 @@ else {
|
|
|
225
219
|
if (typeof entryFileNames !== "string") return this.error("entryFileNames must be a string");
|
|
226
220
|
if (options.extraOutdir) entryFileNames = path.join(options.extraOutdir, entryFileNames);
|
|
227
221
|
for (const [srcFilename, { s, imports, map, ext }] of Object.entries(outputFiles)) {
|
|
228
|
-
const emitName = rewriteImports(s, imports, entryMap, inputBase, entryFileNames, srcFilename);
|
|
222
|
+
const emitName = rewriteImports(s, options, imports, entryMap, inputBase, entryFileNames, srcFilename);
|
|
229
223
|
let source = s.toString();
|
|
230
224
|
if (options.patchCjsDefaultExport && emitName.endsWith(".d.cts")) source = patchCjsDefaultExport(source);
|
|
231
225
|
debug("[rollup] emit dts file:", emitName);
|
|
@@ -259,7 +253,7 @@ else {
|
|
|
259
253
|
let entryFileNames = output.entryFilename;
|
|
260
254
|
if (options.extraOutdir) entryFileNames = path.join(options.extraOutdir, entryFileNames);
|
|
261
255
|
for (const [srcFilename, { s, imports, map, ext }] of Object.entries(outputFiles)) {
|
|
262
|
-
const emitName = rewriteImports(s, imports, entryMap, inputBase, entryFileNames, srcFilename);
|
|
256
|
+
const emitName = rewriteImports(s, options, imports, entryMap, inputBase, entryFileNames, srcFilename);
|
|
263
257
|
let source = s.toString();
|
|
264
258
|
if (options.patchCjsDefaultExport && emitName.endsWith(".d.cts")) source = patchCjsDefaultExport(source);
|
|
265
259
|
debug("[farm] emit dts file:", emitName);
|
|
@@ -44,12 +44,8 @@ function resolveEntry(input, userInputBase) {
|
|
|
44
44
|
function endsWithIndex(s) {
|
|
45
45
|
return /(?:^|[/\\])index\..+$/.test(s);
|
|
46
46
|
}
|
|
47
|
-
function
|
|
48
|
-
|
|
49
|
-
if (!endsWithIndex(id) && endsWithIndex(resolved)) suffix += "/index";
|
|
50
|
-
const ext = node_path.default.extname(resolved).slice(1).replace(/^([cm]?)ts/, (_, $1) => `${$1}js`);
|
|
51
|
-
if (ext) suffix += `.${ext}`;
|
|
52
|
-
return suffix;
|
|
47
|
+
function shouldAddIndex(id, resolved) {
|
|
48
|
+
return !endsWithIndex(id) && endsWithIndex(resolved);
|
|
53
49
|
}
|
|
54
50
|
|
|
55
51
|
//#endregion
|
|
@@ -57,7 +53,7 @@ function guessSuffix(id, resolved) {
|
|
|
57
53
|
function filterImports(program) {
|
|
58
54
|
return program.body.filter((node) => (node.type === "ImportDeclaration" || node.type === "ExportAllDeclaration" || node.type === "ExportNamedDeclaration") && !!node.source);
|
|
59
55
|
}
|
|
60
|
-
function rewriteImports(s, imports, entryMap, inputBase, entryFileNames, srcFilename) {
|
|
56
|
+
function rewriteImports(s, options, imports, entryMap, inputBase, entryFileNames, srcFilename) {
|
|
61
57
|
const srcRel = node_path.default.relative(inputBase, srcFilename);
|
|
62
58
|
const srcDir = node_path.default.dirname(srcFilename);
|
|
63
59
|
const srcDirRel = node_path.default.relative(inputBase, srcDir);
|
|
@@ -70,17 +66,16 @@ function rewriteImports(s, imports, entryMap, inputBase, entryFileNames, srcFile
|
|
|
70
66
|
const offset = node_path.default.relative(emitDir, srcDirRel);
|
|
71
67
|
for (const i of imports) {
|
|
72
68
|
const { source } = i;
|
|
73
|
-
|
|
69
|
+
let srcIdRel = source.value;
|
|
74
70
|
if (srcIdRel[0] !== ".") continue;
|
|
71
|
+
if (i.shouldAddIndex) srcIdRel += "/index";
|
|
75
72
|
const srcId = node_path.default.resolve(srcDir, srcIdRel);
|
|
76
|
-
const importAlias = entryMap?.[srcId];
|
|
73
|
+
const importAlias = entryMap?.[stripExt(srcId)];
|
|
77
74
|
let id;
|
|
78
75
|
if (importAlias) {
|
|
79
|
-
const resolved =
|
|
76
|
+
const resolved = entryFileNames.replaceAll("[name]", stripExt(importAlias));
|
|
80
77
|
id = pathRelative(srcDirRel, resolved);
|
|
81
|
-
} else id =
|
|
82
|
-
const suffix = i.suffix || guessSuffix(source.value, source.value);
|
|
83
|
-
if (suffix) id += suffix;
|
|
78
|
+
} else id = entryFileNames.replaceAll("[name]", stripExt(srcIdRel));
|
|
84
79
|
let final = node_path.default.normalize(node_path.default.join(offset, id));
|
|
85
80
|
if (final !== node_path.default.normalize(source.value)) {
|
|
86
81
|
debug$1("Patch import in", srcRel, ":", srcIdRel, "->", final);
|
|
@@ -107,7 +102,6 @@ function resolveOptions(options) {
|
|
|
107
102
|
transformer: options.transformer || "typescript",
|
|
108
103
|
ignoreErrors: options.ignoreErrors || false,
|
|
109
104
|
extraOutdir: options.extraOutdir,
|
|
110
|
-
autoAddExts: options.autoAddExts || false,
|
|
111
105
|
patchCjsDefaultExport: options.patchCjsDefaultExport || false,
|
|
112
106
|
rewriteImports: options.rewriteImports,
|
|
113
107
|
inputBase: options.inputBase
|
|
@@ -176,7 +170,7 @@ else {
|
|
|
176
170
|
const { program } = await (0, oxc_parser.parseAsync)(id, dts);
|
|
177
171
|
const imports = filterImports(program);
|
|
178
172
|
const s = new magic_string.default(dts);
|
|
179
|
-
|
|
173
|
+
for (const i of imports) {
|
|
180
174
|
const { source } = i;
|
|
181
175
|
let { value } = source;
|
|
182
176
|
if (options.rewriteImports) {
|
|
@@ -186,10 +180,10 @@ else {
|
|
|
186
180
|
s.overwrite(source.start + 1, source.end - 1, result$1);
|
|
187
181
|
}
|
|
188
182
|
}
|
|
189
|
-
if (
|
|
183
|
+
if (node_path.default.isAbsolute(value) || value[0] === ".") {
|
|
190
184
|
const resolved = await resolve(context, value, stripExt(id));
|
|
191
185
|
if (!resolved || resolved.external) continue;
|
|
192
|
-
i.
|
|
186
|
+
i.shouldAddIndex = shouldAddIndex(value, resolved.id);
|
|
193
187
|
}
|
|
194
188
|
}
|
|
195
189
|
addOutput(id, {
|
|
@@ -226,7 +220,7 @@ else {
|
|
|
226
220
|
if (typeof entryFileNames !== "string") return this.error("entryFileNames must be a string");
|
|
227
221
|
if (options.extraOutdir) entryFileNames = node_path.default.join(options.extraOutdir, entryFileNames);
|
|
228
222
|
for (const [srcFilename, { s, imports, map, ext }] of Object.entries(outputFiles)) {
|
|
229
|
-
const emitName = rewriteImports(s, imports, entryMap, inputBase, entryFileNames, srcFilename);
|
|
223
|
+
const emitName = rewriteImports(s, options, imports, entryMap, inputBase, entryFileNames, srcFilename);
|
|
230
224
|
let source = s.toString();
|
|
231
225
|
if (options.patchCjsDefaultExport && emitName.endsWith(".d.cts")) source = patchCjsDefaultExport(source);
|
|
232
226
|
debug$1("[rollup] emit dts file:", emitName);
|
|
@@ -260,7 +254,7 @@ else {
|
|
|
260
254
|
let entryFileNames = output.entryFilename;
|
|
261
255
|
if (options.extraOutdir) entryFileNames = node_path.default.join(options.extraOutdir, entryFileNames);
|
|
262
256
|
for (const [srcFilename, { s, imports, map, ext }] of Object.entries(outputFiles)) {
|
|
263
|
-
const emitName = rewriteImports(s, imports, entryMap, inputBase, entryFileNames, srcFilename);
|
|
257
|
+
const emitName = rewriteImports(s, options, imports, entryMap, inputBase, entryFileNames, srcFilename);
|
|
264
258
|
let source = s.toString();
|
|
265
259
|
if (options.patchCjsDefaultExport && emitName.endsWith(".d.cts")) source = patchCjsDefaultExport(source);
|
|
266
260
|
debug$1("[farm] emit dts file:", emitName);
|
package/dist/vite.cjs
CHANGED
package/dist/vite.d.cts
CHANGED
package/dist/vite.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "unplugin-isolated-decl",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "A blazing-fast tool for generating isolated declarations.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [
|
|
@@ -101,7 +101,7 @@
|
|
|
101
101
|
"@swc/core": "^1.10.0",
|
|
102
102
|
"@sxzz/eslint-config": "^4.5.1",
|
|
103
103
|
"@sxzz/prettier-config": "^2.0.2",
|
|
104
|
-
"@sxzz/test-utils": "^0.3.
|
|
104
|
+
"@sxzz/test-utils": "^0.3.10",
|
|
105
105
|
"@types/debug": "^4.1.12",
|
|
106
106
|
"@types/node": "^22.10.1",
|
|
107
107
|
"bumpp": "^9.9.0",
|