unplugin-oxc 0.2.8 → 0.3.1

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-CE68RyH8.js";
1
+ import { Oxc } from "./src-Bw_izk11.js";
2
2
 
3
3
  //#region src/esbuild.ts
4
4
  /**
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-CE68RyH8.js";
1
+ import { Oxc } from "./src-Bw_izk11.js";
2
2
 
3
3
  //#region src/farm.ts
4
4
  /**
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-CE68RyH8.js";
1
+ import { Oxc } from "./src-Bw_izk11.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-CE68RyH8.js";
1
+ import { Oxc } from "./src-Bw_izk11.js";
2
2
 
3
3
  //#region src/rolldown.ts
4
4
  /**
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-CE68RyH8.js";
1
+ import { Oxc } from "./src-Bw_izk11.js";
2
2
 
3
3
  //#region src/rollup.ts
4
4
  /**
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-CE68RyH8.js";
1
+ import { Oxc } from "./src-Bw_izk11.js";
2
2
 
3
3
  //#region src/rspack.ts
4
4
  /**
@@ -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 }) => {
@@ -39,8 +51,8 @@ const Oxc = createUnplugin((rawOptions = {}, { framework }) => {
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;
83
+ if (resolved.path) {
84
+ const format = getModuleFormat(resolved.path) || resolved.moduleType || "commonjs";
85
+ return {
86
+ id: resolved.path,
87
+ format
88
+ };
89
+ }
72
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"));
@@ -91,14 +111,20 @@ 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
+ const moduleFormat = getModuleFormat(id);
126
+ if (moduleFormat) return moduleFormat === "module" ? "module" : "script";
127
+ }
102
128
 
103
129
  //#endregion
104
130
  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-CE68RyH8.js";
1
+ import { Oxc } from "./src-Bw_izk11.js";
2
2
 
3
3
  //#region src/unloader.ts
4
4
  /**
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-CE68RyH8.js";
1
+ import { Oxc } from "./src-Bw_izk11.js";
2
2
 
3
3
  //#region src/vite.ts
4
4
  /**
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-CE68RyH8.js";
1
+ import { Oxc } from "./src-Bw_izk11.js";
2
2
 
3
3
  //#region src/webpack.ts
4
4
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "unplugin-oxc",
3
- "version": "0.2.8",
3
+ "version": "0.3.1",
4
4
  "description": "Oxc integration for unplugin.",
5
5
  "type": "module",
6
6
  "keywords": [
@@ -63,10 +63,10 @@
63
63
  }
64
64
  },
65
65
  "dependencies": {
66
- "oxc-minify": "^0.57.0",
67
- "oxc-resolver": "^5.0.0",
68
- "oxc-transform": "^0.57.0",
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": {
@@ -74,17 +74,17 @@
74
74
  "@sxzz/prettier-config": "^2.2.1",
75
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.8",
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"