unplugin-isolated-decl 0.10.7 → 0.11.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.
@@ -1,162 +0,0 @@
1
- "use strict";
2
- //#region rolldown:runtime
3
- var __create = Object.create;
4
- var __defProp = Object.defineProperty;
5
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
- var __getOwnPropNames = Object.getOwnPropertyNames;
7
- var __getProtoOf = Object.getPrototypeOf;
8
- var __hasOwnProp = Object.prototype.hasOwnProperty;
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
- key = keys[i];
12
- if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
13
- get: ((k) => from[k]).bind(null, key),
14
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
15
- });
16
- }
17
- return to;
18
- };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
20
- value: mod,
21
- enumerable: true
22
- }) : target, mod));
23
-
24
- //#endregion
25
- const node_path = __toESM(require("node:path"));
26
-
27
- //#region src/core/transformer.ts
28
- function tryImport(pkg) {
29
- return import(pkg).catch(() => null);
30
- }
31
- async function oxcTransform(id, code, sourceMap) {
32
- const oxc = await tryImport("oxc-transform");
33
- if (!oxc) return {
34
- code: "",
35
- errors: ["oxc-transform is required for transforming TypeScript, please install `oxc-transform`."]
36
- };
37
- const result = oxc.isolatedDeclaration(id, code, { sourcemap: sourceMap });
38
- return {
39
- ...result,
40
- map: result.map?.mappings,
41
- errors: result.errors.map((error) => error.message)
42
- };
43
- }
44
- async function swcTransform(id, code) {
45
- const swc = await tryImport("@swc/core");
46
- if (!swc) return {
47
- code: "",
48
- errors: ["SWC is required for transforming TypeScript, please install `@swc/core`."]
49
- };
50
- try {
51
- const result = await swc.transform(code, {
52
- filename: id,
53
- jsc: {
54
- parser: {
55
- syntax: "typescript",
56
- tsx: false
57
- },
58
- experimental: { emitIsolatedDts: true }
59
- }
60
- });
61
- const output = JSON.parse(result.output);
62
- return {
63
- code: output.__swc_isolated_declarations__,
64
- errors: []
65
- };
66
- } catch (error) {
67
- return {
68
- code: "",
69
- errors: [error.toString()]
70
- };
71
- }
72
- }
73
- async function tsTransform(id, code, transformOptions, sourceMap) {
74
- const ts = await tryImport("typescript");
75
- if (!ts) return {
76
- code: "",
77
- errors: ["TypeScript is required for transforming TypeScript, please install `typescript`."]
78
- };
79
- if (!ts.transpileDeclaration) return {
80
- code: "",
81
- errors: ["TypeScript version is too low, please upgrade to TypeScript 5.5.2+."]
82
- };
83
- const compilerOptions = {
84
- declarationMap: sourceMap,
85
- ...transformOptions?.compilerOptions
86
- };
87
- let { outputText, diagnostics, sourceMapText } = ts.transpileDeclaration(code, {
88
- fileName: id,
89
- reportDiagnostics: true,
90
- ...transformOptions,
91
- compilerOptions
92
- });
93
- if (compilerOptions.declarationMap) outputText = stripMapUrl(outputText);
94
- const errors = diagnostics?.length ? [ts.formatDiagnostics(diagnostics, {
95
- getCanonicalFileName: (fileName) => ts.sys.useCaseSensitiveFileNames ? fileName : fileName.toLowerCase(),
96
- getCurrentDirectory: () => ts.sys.getCurrentDirectory(),
97
- getNewLine: () => ts.sys.newLine
98
- })] : [];
99
- if (sourceMapText) sourceMapText = JSON.parse(sourceMapText).mappings;
100
- return {
101
- code: outputText,
102
- errors,
103
- map: sourceMapText
104
- };
105
- }
106
- function stripMapUrl(code) {
107
- const lines = code.split("\n");
108
- const lastLine = lines.at(-1);
109
- if (lastLine?.startsWith("//# sourceMappingURL=")) return lines.slice(0, -1).join("\n");
110
- return code;
111
- }
112
- function appendMapUrl(map, filename) {
113
- return `${map}\n//# sourceMappingURL=${node_path.default.basename(filename)}.map`;
114
- }
115
- function generateDtsMap(mappings, src, dts) {
116
- return JSON.stringify({
117
- version: 3,
118
- file: node_path.default.basename(dts),
119
- sourceRoot: "",
120
- sources: [node_path.default.relative(node_path.default.dirname(dts), src).replaceAll("\\", "/")],
121
- names: [],
122
- mappings
123
- });
124
- }
125
-
126
- //#endregion
127
- Object.defineProperty(exports, '__toESM', {
128
- enumerable: true,
129
- get: function () {
130
- return __toESM;
131
- }
132
- });
133
- Object.defineProperty(exports, 'appendMapUrl', {
134
- enumerable: true,
135
- get: function () {
136
- return appendMapUrl;
137
- }
138
- });
139
- Object.defineProperty(exports, 'generateDtsMap', {
140
- enumerable: true,
141
- get: function () {
142
- return generateDtsMap;
143
- }
144
- });
145
- Object.defineProperty(exports, 'oxcTransform', {
146
- enumerable: true,
147
- get: function () {
148
- return oxcTransform;
149
- }
150
- });
151
- Object.defineProperty(exports, 'swcTransform', {
152
- enumerable: true,
153
- get: function () {
154
- return swcTransform;
155
- }
156
- });
157
- Object.defineProperty(exports, 'tsTransform', {
158
- enumerable: true,
159
- get: function () {
160
- return tsTransform;
161
- }
162
- });
package/dist/vite.cjs DELETED
@@ -1,9 +0,0 @@
1
- "use strict";
2
- require('./transformer-DzpBM_tn.cjs');
3
- const require_src = require('./src-CimtWZd6.cjs');
4
-
5
- //#region src/vite.ts
6
- var vite_default = require_src.IsolatedDecl.vite;
7
-
8
- //#endregion
9
- module.exports = vite_default;
package/dist/vite.d.cts DELETED
@@ -1,21 +0,0 @@
1
- /**
2
- * This entry file is for Vite plugin.
3
- *
4
- * @module
5
- */
6
- import { IsolatedDecl } from './index.cjs';
7
- /**
8
- * Vite plugin
9
- *
10
- * @example
11
- * ```ts
12
- * // vite.config.js
13
- * import IsolatedDecl from 'unplugin-isolated-decl/vite'
14
- *
15
- * export default {
16
- * plugins: [IsolatedDecl()],
17
- * }
18
- * ```
19
- */
20
- declare const _default: typeof IsolatedDecl.vite;
21
- export = _default;