unplugin-oxc 0.2.7 → 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/dist/api.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
 
2
- export { }
2
+ export { };
package/dist/esbuild.d.ts CHANGED
@@ -24,4 +24,4 @@ import 'unplugin-utils';
24
24
  */
25
25
  declare const esbuild: typeof Oxc.esbuild;
26
26
 
27
- export { esbuild as "module.exports", esbuild as default };
27
+ export { esbuild as "\"module.exports\"", esbuild as default };
package/dist/esbuild.js CHANGED
@@ -1,4 +1,4 @@
1
- import { Oxc } from "./src-DlAKtjQu.js";
1
+ import { Oxc } from "./src-DDJ_1YNm.js";
2
2
 
3
3
  //#region src/esbuild.ts
4
4
  /**
@@ -16,4 +16,4 @@ const esbuild = Oxc.esbuild;
16
16
  var esbuild_default = esbuild;
17
17
 
18
18
  //#endregion
19
- export { esbuild_default as default, esbuild as 'module.exports' };
19
+ export { esbuild_default as default, esbuild as "module.exports" };
package/dist/farm.d.ts CHANGED
@@ -26,4 +26,4 @@ import 'unplugin-utils';
26
26
  */
27
27
  declare const farm: typeof Oxc.farm;
28
28
 
29
- export { farm as "module.exports", farm as default };
29
+ export { farm as "\"module.exports\"", farm as default };
package/dist/farm.js CHANGED
@@ -1,4 +1,4 @@
1
- import { Oxc } from "./src-DlAKtjQu.js";
1
+ import { Oxc } from "./src-DDJ_1YNm.js";
2
2
 
3
3
  //#region src/farm.ts
4
4
  /**
@@ -18,4 +18,4 @@ const farm = Oxc.farm;
18
18
  var farm_default = farm;
19
19
 
20
20
  //#endregion
21
- export { farm_default as default, farm as 'module.exports' };
21
+ export { farm_default as default, farm as "module.exports" };
package/dist/index.d.ts CHANGED
@@ -1,8 +1,14 @@
1
- import { UnpluginInstance } from 'unplugin';
2
- import { MinifyOptions } from 'oxc-minify';
3
- import { NapiResolveOptions } from 'oxc-resolver';
4
- import { TransformOptions } from 'oxc-transform';
5
- import { FilterPattern } from 'unplugin-utils';
1
+ import type { UnpluginInstance } from 'unplugin';
2
+ import type { MinifyOptions } from 'oxc-minify';
3
+ import type { NapiResolveOptions } from 'oxc-resolver';
4
+ import type { TransformOptions } from 'oxc-transform';
5
+ import type { FilterPattern } from 'unplugin-utils';
6
+
7
+
8
+
9
+
10
+
11
+
6
12
 
7
13
  interface Options {
8
14
  /**
@@ -38,6 +44,9 @@ interface Options {
38
44
  sourcemap?: boolean;
39
45
  }
40
46
 
47
+
48
+
49
+
41
50
  declare const Oxc: UnpluginInstance<Options | undefined, false>;
42
51
 
43
52
  export { Oxc };
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
- import { Oxc } from "./src-DlAKtjQu.js";
1
+ import { Oxc } from "./src-DDJ_1YNm.js";
2
2
 
3
3
  export { Oxc };
@@ -26,4 +26,4 @@ import 'unplugin-utils';
26
26
  */
27
27
  declare const rolldown: typeof Oxc.rolldown;
28
28
 
29
- export { rolldown as "module.exports", rolldown as default };
29
+ export { rolldown as "\"module.exports\"", rolldown as default };
package/dist/rolldown.js CHANGED
@@ -1,4 +1,4 @@
1
- import { Oxc } from "./src-DlAKtjQu.js";
1
+ import { Oxc } from "./src-DDJ_1YNm.js";
2
2
 
3
3
  //#region src/rolldown.ts
4
4
  /**
@@ -18,4 +18,4 @@ const rolldown = Oxc.rolldown;
18
18
  var rolldown_default = rolldown;
19
19
 
20
20
  //#endregion
21
- export { rolldown_default as default, rolldown as 'module.exports' };
21
+ export { rolldown_default as default, rolldown as "module.exports" };
package/dist/rollup.d.ts CHANGED
@@ -26,4 +26,4 @@ import 'unplugin-utils';
26
26
  */
27
27
  declare const rollup: typeof Oxc.rollup;
28
28
 
29
- export { rollup as "module.exports", rollup as default };
29
+ export { rollup as "\"module.exports\"", rollup as default };
package/dist/rollup.js CHANGED
@@ -1,4 +1,4 @@
1
- import { Oxc } from "./src-DlAKtjQu.js";
1
+ import { Oxc } from "./src-DDJ_1YNm.js";
2
2
 
3
3
  //#region src/rollup.ts
4
4
  /**
@@ -18,4 +18,4 @@ const rollup = Oxc.rollup;
18
18
  var rollup_default = rollup;
19
19
 
20
20
  //#endregion
21
- export { rollup_default as default, rollup as 'module.exports' };
21
+ export { rollup_default as default, rollup as "module.exports" };
package/dist/rspack.d.ts CHANGED
@@ -26,4 +26,4 @@ import 'unplugin-utils';
26
26
  */
27
27
  declare const rspack: typeof Oxc.rspack;
28
28
 
29
- export { rspack as "module.exports", rspack as default };
29
+ export { rspack as "\"module.exports\"", rspack as default };
package/dist/rspack.js CHANGED
@@ -1,4 +1,4 @@
1
- import { Oxc } from "./src-DlAKtjQu.js";
1
+ import { Oxc } from "./src-DDJ_1YNm.js";
2
2
 
3
3
  //#region src/rspack.ts
4
4
  /**
@@ -18,4 +18,4 @@ const rspack = Oxc.rspack;
18
18
  var rspack_default = rspack;
19
19
 
20
20
  //#endregion
21
- export { rspack_default as default, rspack as 'module.exports' };
21
+ export { rspack_default as default, rspack as "module.exports" };
@@ -1,4 +1,4 @@
1
- import { readFile } from "node:fs/promises";
1
+ import { readFileSync } from "node:fs";
2
2
  import path from "node:path";
3
3
  import process from "node:process";
4
4
  import { ResolverFactory } from "oxc-resolver";
@@ -20,6 +20,18 @@ function resolveOptions(options, framework) {
20
20
  };
21
21
  }
22
22
 
23
+ //#endregion
24
+ //#region src/core/utils.ts
25
+ function getModuleFormat(id) {
26
+ const ext = path.extname(id);
27
+ switch (ext) {
28
+ case ".mjs":
29
+ case ".mts": return "module";
30
+ case ".cjs":
31
+ case ".cts": return "commonjs";
32
+ }
33
+ }
34
+
23
35
  //#endregion
24
36
  //#region src/index.ts
25
37
  const Oxc = createUnplugin((rawOptions = {}, { framework }) => {
@@ -35,12 +47,12 @@ const Oxc = createUnplugin((rawOptions = {}, { framework }) => {
35
47
  code: result.code,
36
48
  map: result.map
37
49
  };
38
- } : undefined;
50
+ } : void 0;
39
51
  return {
40
52
  name: "unplugin-oxc",
41
53
  enforce: options.enforce,
42
- resolveId: options.resolve !== false ? async (id, importer) => {
43
- if (!options.resolveNodeModules && id[0] !== "." && id[0] !== "/") return;
54
+ resolveId: options.resolve !== false ? (id, importer, resolveOptions$1) => {
55
+ if (!options.resolveNodeModules && id[0] !== "." && !path.isAbsolute(id)) return;
44
56
  const resolver = new ResolverFactory({
45
57
  extensions: [
46
58
  ".mjs",
@@ -51,7 +63,7 @@ const Oxc = createUnplugin((rawOptions = {}, { framework }) => {
51
63
  ".json",
52
64
  ".node"
53
65
  ],
54
- conditionNames: [
66
+ conditionNames: resolveOptions$1?.conditions ? Array.from(resolveOptions$1.conditions) : [
55
67
  "import",
56
68
  "require",
57
69
  "browser",
@@ -62,20 +74,28 @@ const Oxc = createUnplugin((rawOptions = {}, { framework }) => {
62
74
  ...options.resolve
63
75
  });
64
76
  const directory = importer ? path.dirname(importer) : process.cwd();
65
- const resolved = await resolver.async(directory, id);
77
+ const resolved = resolver.sync(directory, id);
66
78
  if (resolved.error?.startsWith("Builtin module")) return {
67
79
  id,
68
80
  external: true,
69
81
  moduleSideEffects: false
70
82
  };
71
- if (resolved.path) return resolved.path;
72
- } : undefined,
83
+ if (resolved.path) {
84
+ const format = getModuleFormat(resolved.path) || resolved.moduleType || "commonjs";
85
+ return {
86
+ id: resolved.path,
87
+ format
88
+ };
89
+ }
90
+ } : void 0,
73
91
  transformInclude(id) {
74
92
  return filter(id);
75
93
  },
76
- transform: options.transform !== false ? (code, id) => {
94
+ transform: options.transform !== false ? (code, id, ...args) => {
95
+ const [transformOptions] = args;
77
96
  const result = transform(id, code, {
78
97
  ...options.transform,
98
+ sourceType: guessSourceType(id, transformOptions?.format),
79
99
  sourcemap: options.sourcemap
80
100
  });
81
101
  if (result.errors.length) throw new SyntaxError(result.errors.map((error) => error.message).join("\n"));
@@ -83,7 +103,7 @@ const Oxc = createUnplugin((rawOptions = {}, { framework }) => {
83
103
  code: result.code,
84
104
  map: result.map
85
105
  };
86
- } : undefined,
106
+ } : void 0,
87
107
  rollup: { renderChunk },
88
108
  rolldown: { renderChunk },
89
109
  vite: { renderChunk },
@@ -91,14 +111,19 @@ const Oxc = createUnplugin((rawOptions = {}, { framework }) => {
91
111
  options(config) {
92
112
  config.sourcemap ||= options.sourcemap;
93
113
  },
94
- async load(id) {
114
+ load(id) {
95
115
  if (!filter(id)) return;
96
- const contents = await readFile(id, "utf8");
116
+ const contents = readFileSync(id, "utf8");
97
117
  return contents;
98
118
  }
99
119
  }
100
120
  };
101
121
  });
122
+ function guessSourceType(id, format) {
123
+ if (format === "module" || format === "module-typescript") return "module";
124
+ else if (format === "commonjs" || format === "commonjs-typescript") return "script";
125
+ else return getModuleFormat(id) === "module" ? "module" : "script";
126
+ }
102
127
 
103
128
  //#endregion
104
129
  export { Oxc };
@@ -26,4 +26,4 @@ import 'unplugin-utils';
26
26
  */
27
27
  declare const unloader: typeof Oxc.unloader;
28
28
 
29
- export { unloader as "module.exports", unloader as default };
29
+ export { unloader as "\"module.exports\"", unloader as default };
package/dist/unloader.js CHANGED
@@ -1,4 +1,4 @@
1
- import { Oxc } from "./src-DlAKtjQu.js";
1
+ import { Oxc } from "./src-DDJ_1YNm.js";
2
2
 
3
3
  //#region src/unloader.ts
4
4
  /**
@@ -18,4 +18,4 @@ const unloader = Oxc.unloader;
18
18
  var unloader_default = unloader;
19
19
 
20
20
  //#endregion
21
- export { unloader_default as default, unloader as 'module.exports' };
21
+ export { unloader_default as default, unloader as "module.exports" };
package/dist/vite.d.ts CHANGED
@@ -26,4 +26,4 @@ import 'unplugin-utils';
26
26
  */
27
27
  declare const vite: typeof Oxc.vite;
28
28
 
29
- export { vite as "module.exports", vite as default };
29
+ export { vite as "\"module.exports\"", vite as default };
package/dist/vite.js CHANGED
@@ -1,4 +1,4 @@
1
- import { Oxc } from "./src-DlAKtjQu.js";
1
+ import { Oxc } from "./src-DDJ_1YNm.js";
2
2
 
3
3
  //#region src/vite.ts
4
4
  /**
@@ -18,4 +18,4 @@ const vite = Oxc.vite;
18
18
  var vite_default = vite;
19
19
 
20
20
  //#endregion
21
- export { vite_default as default, vite as 'module.exports' };
21
+ export { vite_default as default, vite as "module.exports" };
package/dist/webpack.d.ts CHANGED
@@ -26,4 +26,4 @@ import 'unplugin-utils';
26
26
  */
27
27
  declare const webpack: typeof Oxc.webpack;
28
28
 
29
- export { webpack as "module.exports", webpack as default };
29
+ export { webpack as "\"module.exports\"", webpack as default };
package/dist/webpack.js CHANGED
@@ -1,4 +1,4 @@
1
- import { Oxc } from "./src-DlAKtjQu.js";
1
+ import { Oxc } from "./src-DDJ_1YNm.js";
2
2
 
3
3
  //#region src/webpack.ts
4
4
  /**
@@ -18,4 +18,4 @@ const webpack = Oxc.webpack;
18
18
  var webpack_default = webpack;
19
19
 
20
20
  //#endregion
21
- export { webpack_default as default, webpack as 'module.exports' };
21
+ export { webpack_default as default, webpack as "module.exports" };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "unplugin-oxc",
3
- "version": "0.2.7",
3
+ "version": "0.3.0",
4
4
  "description": "Oxc integration for unplugin.",
5
5
  "type": "module",
6
6
  "keywords": [
@@ -63,28 +63,28 @@
63
63
  }
64
64
  },
65
65
  "dependencies": {
66
- "oxc-minify": "^0.56.5",
67
- "oxc-resolver": "^5.0.0",
68
- "oxc-transform": "^0.56.5",
69
- "unplugin": "^2.2.0",
66
+ "oxc-minify": "^0.60.0",
67
+ "oxc-resolver": "^5.0.1",
68
+ "oxc-transform": "^0.60.0",
69
+ "unplugin": "^2.2.1",
70
70
  "unplugin-utils": "^0.2.4"
71
71
  },
72
72
  "devDependencies": {
73
- "@sxzz/eslint-config": "^5.3.0",
73
+ "@sxzz/eslint-config": "^6.0.2",
74
74
  "@sxzz/prettier-config": "^2.2.1",
75
- "@sxzz/test-utils": "^0.5.1",
75
+ "@sxzz/test-utils": "^0.5.2",
76
76
  "@types/node": "^22.13.10",
77
- "bumpp": "^10.0.3",
77
+ "bumpp": "^10.1.0",
78
78
  "eslint": "^9.22.0",
79
79
  "prettier": "^3.5.3",
80
- "rollup": "^4.35.0",
81
- "tinyexec": "^0.3.2",
82
- "tsdown": "^0.6.4",
80
+ "rollup": "^4.36.0",
81
+ "tinyexec": "^1.0.0",
82
+ "tsdown": "^0.6.9",
83
83
  "tsx": "^4.19.3",
84
84
  "typescript": "^5.8.2",
85
- "unloader": "^0.3.0",
86
- "vite": "^6.2.1",
87
- "vitest": "^3.0.8"
85
+ "unloader": "^0.4.1",
86
+ "vite": "^6.2.2",
87
+ "vitest": "^3.0.9"
88
88
  },
89
89
  "engines": {
90
90
  "node": ">=18.12.0"