unplugin-isolated-decl 0.4.5 → 0.4.7

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/dist/api.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- const require_transformer = require('./transformer-oh0-JTHH.cjs');
2
+ const require_transformer = require('./transformer-wFl7-Qrk.cjs');
3
3
 
4
4
  Object.defineProperty(exports, 'oxcTransform', {
5
5
  enumerable: true,
package/dist/api.js CHANGED
@@ -1,3 +1,3 @@
1
- import { oxcTransform, swcTransform, tsTransform } from "./transformer-ScZEjI0h.js";
1
+ import { oxcTransform, swcTransform, tsTransform } from "./transformer-69vts78l.js";
2
2
 
3
3
  export { oxcTransform, swcTransform, tsTransform };
package/dist/esbuild.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
- const require_transformer = require('./transformer-oh0-JTHH.cjs');
3
- const require_src_index = require('./src_index-5Xl2iCUQ.cjs');
2
+ require('./transformer-wFl7-Qrk.cjs');
3
+ const require_src_index = require('./src_index-t9_prpkU.cjs');
4
4
 
5
5
  //#region src/esbuild.ts
6
6
  var esbuild_default = require_src_index.IsolatedDecl.esbuild;
package/dist/esbuild.js CHANGED
@@ -1,5 +1,5 @@
1
- import "./transformer-ScZEjI0h.js";
2
- import { IsolatedDecl } from "./src_index-QT5bMpQf.js";
1
+ import "./transformer-69vts78l.js";
2
+ import { IsolatedDecl } from "./src_index-IB8kj2gH.js";
3
3
 
4
4
  //#region src/esbuild.ts
5
5
  var esbuild_default = IsolatedDecl.esbuild;
package/dist/index.cjs CHANGED
@@ -1,10 +1,16 @@
1
1
  "use strict";
2
- const require_transformer = require('./transformer-oh0-JTHH.cjs');
3
- const require_src_index = require('./src_index-5Xl2iCUQ.cjs');
2
+ require('./transformer-wFl7-Qrk.cjs');
3
+ const require_src_index = require('./src_index-t9_prpkU.cjs');
4
4
 
5
5
  Object.defineProperty(exports, 'IsolatedDecl', {
6
6
  enumerable: true,
7
7
  get: function () {
8
8
  return require_src_index.IsolatedDecl;
9
9
  }
10
+ });
11
+ Object.defineProperty(exports, 'lowestCommonAncestor', {
12
+ enumerable: true,
13
+ get: function () {
14
+ return require_src_index.lowestCommonAncestor;
15
+ }
10
16
  });
package/dist/index.d.cts CHANGED
@@ -2,3 +2,4 @@ import { type UnpluginInstance } from "unplugin";
2
2
  import { type Options } from "./core/options";
3
3
  export type { Options };
4
4
  export declare const IsolatedDecl: UnpluginInstance<Options | undefined, false>;
5
+ export declare function lowestCommonAncestor(...filepaths: string[]): string;
package/dist/index.d.ts CHANGED
@@ -2,3 +2,4 @@ import { type UnpluginInstance } from "unplugin";
2
2
  import { type Options } from "./core/options";
3
3
  export type { Options };
4
4
  export declare const IsolatedDecl: UnpluginInstance<Options | undefined, false>;
5
+ export declare function lowestCommonAncestor(...filepaths: string[]): string;
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import "./transformer-ScZEjI0h.js";
2
- import { IsolatedDecl } from "./src_index-QT5bMpQf.js";
1
+ import "./transformer-69vts78l.js";
2
+ import { IsolatedDecl, lowestCommonAncestor } from "./src_index-IB8kj2gH.js";
3
3
 
4
- export { IsolatedDecl };
4
+ export { IsolatedDecl, lowestCommonAncestor };
package/dist/rolldown.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
- const require_transformer = require('./transformer-oh0-JTHH.cjs');
3
- const require_src_index = require('./src_index-5Xl2iCUQ.cjs');
2
+ require('./transformer-wFl7-Qrk.cjs');
3
+ const require_src_index = require('./src_index-t9_prpkU.cjs');
4
4
 
5
5
  //#region src/rolldown.ts
6
6
  var rolldown_default = require_src_index.IsolatedDecl.rolldown;
package/dist/rolldown.js CHANGED
@@ -1,5 +1,5 @@
1
- import "./transformer-ScZEjI0h.js";
2
- import { IsolatedDecl } from "./src_index-QT5bMpQf.js";
1
+ import "./transformer-69vts78l.js";
2
+ import { IsolatedDecl } from "./src_index-IB8kj2gH.js";
3
3
 
4
4
  //#region src/rolldown.ts
5
5
  var rolldown_default = IsolatedDecl.rolldown;
package/dist/rollup.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
- const require_transformer = require('./transformer-oh0-JTHH.cjs');
3
- const require_src_index = require('./src_index-5Xl2iCUQ.cjs');
2
+ require('./transformer-wFl7-Qrk.cjs');
3
+ const require_src_index = require('./src_index-t9_prpkU.cjs');
4
4
 
5
5
  //#region src/rollup.ts
6
6
  var rollup_default = require_src_index.IsolatedDecl.rollup;
package/dist/rollup.js CHANGED
@@ -1,5 +1,5 @@
1
- import "./transformer-ScZEjI0h.js";
2
- import { IsolatedDecl } from "./src_index-QT5bMpQf.js";
1
+ import "./transformer-69vts78l.js";
2
+ import { IsolatedDecl } from "./src_index-IB8kj2gH.js";
3
3
 
4
4
  //#region src/rollup.ts
5
5
  var rollup_default = IsolatedDecl.rollup;
@@ -1,7 +1,8 @@
1
- import { oxcTransform, swcTransform, tsTransform } from "./transformer-ScZEjI0h.js";
2
- import { mkdir, writeFile } from "node:fs/promises";
1
+ import { oxcTransform, swcTransform, tsTransform } from "./transformer-69vts78l.js";
2
+ import { mkdir, readFile, writeFile } from "node:fs/promises";
3
3
  import { default as path } from "node:path";
4
4
  import { createFilter } from "@rollup/pluginutils";
5
+ import { parseAsync } from "oxc-parser";
5
6
  import { createUnplugin } from "unplugin";
6
7
 
7
8
  //#region src/core/options.ts
@@ -17,12 +18,15 @@ function resolveOptions(options) {
17
18
 
18
19
  //#endregion
19
20
  //#region src/index.ts
20
- const IsolatedDecl = createUnplugin((rawOptions = {}) => {
21
+ const IsolatedDecl = createUnplugin((rawOptions = {}, meta) => {
21
22
  const options = resolveOptions(rawOptions);
22
23
  const filter = createFilter(options.include, options.exclude);
23
24
  const outputFiles = {};
25
+ function stripExt(filename) {
26
+ return filename.replace(/\.(.?)[jt]s$/, "");
27
+ }
24
28
  function addOutput(filename, source) {
25
- outputFiles[filename.replace(/\.(.?)[jt]s$/, "")] = source;
29
+ outputFiles[stripExt(filename)] = source;
26
30
  }
27
31
  const rollup = { renderStart(outputOptions, inputOptions) {
28
32
  let outBase = "";
@@ -48,27 +52,8 @@ const IsolatedDecl = createUnplugin((rawOptions = {}) => {
48
52
  transformInclude(id) {
49
53
  return filter(id);
50
54
  },
51
- async transform(code, id) {
52
- let result;
53
- switch (options.transformer) {
54
- case "oxc":
55
- result = oxcTransform(id, code);
56
- break;
57
- case "swc":
58
- result = await swcTransform(id, code);
59
- break;
60
- case "typescript": result = await tsTransform(id, code, options.transformOptions);
61
- }
62
- const { sourceText, errors } = result;
63
- if (errors.length) {
64
- if (options.ignoreErrors) {
65
- this.warn(errors[0]);
66
- } else {
67
- this.error(errors[0]);
68
- return;
69
- }
70
- }
71
- addOutput(id, sourceText);
55
+ transform(code, id) {
56
+ return transform.call(this, code, id);
72
57
  },
73
58
  esbuild: { setup(build) {
74
59
  build.onEnd(async (result) => {
@@ -122,14 +107,70 @@ const IsolatedDecl = createUnplugin((rawOptions = {}) => {
122
107
  ...rollup
123
108
  }
124
109
  };
110
+ async function transform(code, id) {
111
+ let result;
112
+ switch (options.transformer) {
113
+ case "oxc":
114
+ result = oxcTransform(id, code);
115
+ break;
116
+ case "swc":
117
+ result = await swcTransform(id, code);
118
+ break;
119
+ case "typescript": result = await tsTransform(id, code, options.transformOptions);
120
+ }
121
+ const { sourceText, errors } = result;
122
+ if (errors.length) {
123
+ if (options.ignoreErrors) {
124
+ this.warn(errors[0]);
125
+ } else {
126
+ this.error(errors[0]);
127
+ return;
128
+ }
129
+ }
130
+ addOutput(id, sourceText);
131
+ let program;
132
+ try {
133
+ program = JSON.parse((await parseAsync(code, { sourceFilename: id })).program);
134
+ } catch {
135
+ return;
136
+ }
137
+ const typeImports = program.body.filter((node) => {
138
+ if (node.type !== "ImportDeclaration") return false;
139
+ if (node.importKind === "type") return true;
140
+ return (node.specifiers || []).every((spec) => spec.type === "ImportSpecifier" && spec.importKind === "type");
141
+ });
142
+ const resolve = async (id$1, importer) => {
143
+ if (meta.framework === "esbuild") {
144
+ return (await meta.build.resolve(id$1, {
145
+ importer,
146
+ resolveDir: path.dirname(importer),
147
+ kind: "import-statement"
148
+ })).path;
149
+ }
150
+ return (await this.resolve(id$1, importer))?.id;
151
+ };
152
+ for (const i of typeImports) {
153
+ const resolved = await resolve(i.source.value, id);
154
+ if (resolved && filter(resolved) && !outputFiles[stripExt(resolved)]) {
155
+ let source;
156
+ try {
157
+ source = await readFile(resolved, "utf8");
158
+ } catch {
159
+ continue;
160
+ }
161
+ await transform.call(this, source, resolved);
162
+ }
163
+ }
164
+ }
125
165
  });
126
166
  function lowestCommonAncestor(...filepaths) {
127
167
  if (filepaths.length === 0) return "";
128
168
  if (filepaths.length === 1) return path.dirname(filepaths[0]);
169
+ filepaths = filepaths.map((p) => p.replaceAll("\\", "/"));
129
170
  const [first, ...rest] = filepaths;
130
- let ancestor = first.split(path.sep);
171
+ let ancestor = first.split("/");
131
172
  for (const filepath of rest) {
132
- const directories = filepath.split(path.sep, ancestor.length);
173
+ const directories = filepath.split("/", ancestor.length);
133
174
  let index = 0;
134
175
  for (const directory of directories) {
135
176
  if (directory === ancestor[index]) {
@@ -141,8 +182,8 @@ function lowestCommonAncestor(...filepaths) {
141
182
  }
142
183
  ancestor = ancestor.slice(0, index);
143
184
  }
144
- return ancestor.length <= 1 && ancestor[0] === "" ? path.sep + ancestor[0] : ancestor.join(path.sep);
185
+ return ancestor.length <= 1 && ancestor[0] === "" ? `/${ancestor[0]}` : ancestor.join("/");
145
186
  }
146
187
 
147
188
  //#endregion
148
- export { IsolatedDecl };
189
+ export { IsolatedDecl, lowestCommonAncestor };
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
- const require_transformer = require('./transformer-oh0-JTHH.cjs');
3
- const { mkdir, writeFile } = __toESM(require("node:fs/promises"));
2
+ const require_transformer = require('./transformer-wFl7-Qrk.cjs');
3
+ const { mkdir, readFile, writeFile } = __toESM(require("node:fs/promises"));
4
4
  const { default: path } = __toESM(require("node:path"));
5
5
  const { createFilter } = __toESM(require("@rollup/pluginutils"));
6
+ const { parseAsync } = __toESM(require("oxc-parser"));
6
7
  const { createUnplugin } = __toESM(require("unplugin"));
7
8
 
8
9
  //#region src/core/options.ts
@@ -18,12 +19,15 @@ function resolveOptions(options) {
18
19
 
19
20
  //#endregion
20
21
  //#region src/index.ts
21
- const IsolatedDecl = createUnplugin((rawOptions = {}) => {
22
+ const IsolatedDecl = createUnplugin((rawOptions = {}, meta) => {
22
23
  const options = resolveOptions(rawOptions);
23
24
  const filter = createFilter(options.include, options.exclude);
24
25
  const outputFiles = {};
26
+ function stripExt(filename) {
27
+ return filename.replace(/\.(.?)[jt]s$/, "");
28
+ }
25
29
  function addOutput(filename, source) {
26
- outputFiles[filename.replace(/\.(.?)[jt]s$/, "")] = source;
30
+ outputFiles[stripExt(filename)] = source;
27
31
  }
28
32
  const rollup = { renderStart(outputOptions, inputOptions) {
29
33
  let outBase = "";
@@ -49,27 +53,8 @@ const IsolatedDecl = createUnplugin((rawOptions = {}) => {
49
53
  transformInclude(id) {
50
54
  return filter(id);
51
55
  },
52
- async transform(code, id) {
53
- let result;
54
- switch (options.transformer) {
55
- case "oxc":
56
- result = require_transformer.oxcTransform(id, code);
57
- break;
58
- case "swc":
59
- result = await require_transformer.swcTransform(id, code);
60
- break;
61
- case "typescript": result = await require_transformer.tsTransform(id, code, options.transformOptions);
62
- }
63
- const { sourceText, errors } = result;
64
- if (errors.length) {
65
- if (options.ignoreErrors) {
66
- this.warn(errors[0]);
67
- } else {
68
- this.error(errors[0]);
69
- return;
70
- }
71
- }
72
- addOutput(id, sourceText);
56
+ transform(code, id) {
57
+ return transform.call(this, code, id);
73
58
  },
74
59
  esbuild: { setup(build) {
75
60
  build.onEnd(async (result) => {
@@ -123,14 +108,70 @@ const IsolatedDecl = createUnplugin((rawOptions = {}) => {
123
108
  ...rollup
124
109
  }
125
110
  };
111
+ async function transform(code, id) {
112
+ let result;
113
+ switch (options.transformer) {
114
+ case "oxc":
115
+ result = require_transformer.oxcTransform(id, code);
116
+ break;
117
+ case "swc":
118
+ result = await require_transformer.swcTransform(id, code);
119
+ break;
120
+ case "typescript": result = await require_transformer.tsTransform(id, code, options.transformOptions);
121
+ }
122
+ const { sourceText, errors } = result;
123
+ if (errors.length) {
124
+ if (options.ignoreErrors) {
125
+ this.warn(errors[0]);
126
+ } else {
127
+ this.error(errors[0]);
128
+ return;
129
+ }
130
+ }
131
+ addOutput(id, sourceText);
132
+ let program;
133
+ try {
134
+ program = JSON.parse((await parseAsync(code, { sourceFilename: id })).program);
135
+ } catch {
136
+ return;
137
+ }
138
+ const typeImports = program.body.filter((node) => {
139
+ if (node.type !== "ImportDeclaration") return false;
140
+ if (node.importKind === "type") return true;
141
+ return (node.specifiers || []).every((spec) => spec.type === "ImportSpecifier" && spec.importKind === "type");
142
+ });
143
+ const resolve = async (id$1, importer) => {
144
+ if (meta.framework === "esbuild") {
145
+ return (await meta.build.resolve(id$1, {
146
+ importer,
147
+ resolveDir: path.dirname(importer),
148
+ kind: "import-statement"
149
+ })).path;
150
+ }
151
+ return (await this.resolve(id$1, importer))?.id;
152
+ };
153
+ for (const i of typeImports) {
154
+ const resolved = await resolve(i.source.value, id);
155
+ if (resolved && filter(resolved) && !outputFiles[stripExt(resolved)]) {
156
+ let source;
157
+ try {
158
+ source = await readFile(resolved, "utf8");
159
+ } catch {
160
+ continue;
161
+ }
162
+ await transform.call(this, source, resolved);
163
+ }
164
+ }
165
+ }
126
166
  });
127
167
  function lowestCommonAncestor(...filepaths) {
128
168
  if (filepaths.length === 0) return "";
129
169
  if (filepaths.length === 1) return path.dirname(filepaths[0]);
170
+ filepaths = filepaths.map((p) => p.replaceAll("\\", "/"));
130
171
  const [first, ...rest] = filepaths;
131
- let ancestor = first.split(path.sep);
172
+ let ancestor = first.split("/");
132
173
  for (const filepath of rest) {
133
- const directories = filepath.split(path.sep, ancestor.length);
174
+ const directories = filepath.split("/", ancestor.length);
134
175
  let index = 0;
135
176
  for (const directory of directories) {
136
177
  if (directory === ancestor[index]) {
@@ -142,7 +183,7 @@ function lowestCommonAncestor(...filepaths) {
142
183
  }
143
184
  ancestor = ancestor.slice(0, index);
144
185
  }
145
- return ancestor.length <= 1 && ancestor[0] === "" ? path.sep + ancestor[0] : ancestor.join(path.sep);
186
+ return ancestor.length <= 1 && ancestor[0] === "" ? `/${ancestor[0]}` : ancestor.join("/");
146
187
  }
147
188
 
148
189
  //#endregion
@@ -151,4 +192,9 @@ Object.defineProperty(exports, 'IsolatedDecl', {
151
192
  get: function () {
152
193
  return IsolatedDecl;
153
194
  }
195
+ });Object.defineProperty(exports, 'lowestCommonAncestor', {
196
+ enumerable: true,
197
+ get: function () {
198
+ return lowestCommonAncestor;
199
+ }
154
200
  });
package/dist/vite.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
- const require_transformer = require('./transformer-oh0-JTHH.cjs');
3
- const require_src_index = require('./src_index-5Xl2iCUQ.cjs');
2
+ require('./transformer-wFl7-Qrk.cjs');
3
+ const require_src_index = require('./src_index-t9_prpkU.cjs');
4
4
 
5
5
  //#region src/vite.ts
6
6
  var vite_default = require_src_index.IsolatedDecl.vite;
package/dist/vite.js CHANGED
@@ -1,5 +1,5 @@
1
- import "./transformer-ScZEjI0h.js";
2
- import { IsolatedDecl } from "./src_index-QT5bMpQf.js";
1
+ import "./transformer-69vts78l.js";
2
+ import { IsolatedDecl } from "./src_index-IB8kj2gH.js";
3
3
 
4
4
  //#region src/vite.ts
5
5
  var vite_default = IsolatedDecl.vite;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "unplugin-isolated-decl",
3
- "version": "0.4.5",
3
+ "version": "0.4.7",
4
4
  "description": "A blazing-fast tool for generating isolated declarations, powered by Oxc.",
5
5
  "type": "module",
6
6
  "keywords": [
@@ -81,24 +81,27 @@
81
81
  },
82
82
  "dependencies": {
83
83
  "@rollup/pluginutils": "^5.1.0",
84
- "oxc-transform": "^0.24.1",
85
- "unplugin": "^1.12.1"
84
+ "oxc-parser": "^0.25.0",
85
+ "oxc-transform": "^0.24.3",
86
+ "unplugin": "^1.12.2"
86
87
  },
87
88
  "devDependencies": {
88
- "@swc/core": "^1.7.10",
89
- "@sxzz/eslint-config": "^3.17.0",
89
+ "@swc/core": "^1.7.11",
90
+ "@sxzz/eslint-config": "^3.17.2",
90
91
  "@sxzz/prettier-config": "^2.0.2",
91
- "@types/node": "^20.14.15",
92
- "bumpp": "^9.4.2",
93
- "esbuild": "^0.23.0",
92
+ "@types/node": "^20.16.0",
93
+ "bumpp": "^9.5.1",
94
+ "esbuild": "^0.23.1",
94
95
  "eslint": "^9.9.0",
95
96
  "fast-glob": "^3.3.2",
96
97
  "prettier": "^3.3.3",
97
- "rollup": "^4.20.0",
98
- "tsdown": "^0.2.5",
98
+ "rolldown": "nightly",
99
+ "rollup": "^4.21.0",
100
+ "rollup-plugin-esbuild": "^6.1.1",
101
+ "tsdown": "^0.2.6",
99
102
  "tsx": "^4.17.0",
100
103
  "typescript": "^5.5.4",
101
- "vite": "^5.4.0",
104
+ "vite": "^5.4.1",
102
105
  "vitest": "^2.0.5"
103
106
  },
104
107
  "engines": {