rolldown-plugin-require-cjs 0.3.2 → 0.3.3
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/index.mjs +9 -6
- package/package.json +24 -23
package/dist/index.mjs
CHANGED
|
@@ -2,11 +2,12 @@ import { createRequire, isBuiltin } from "node:module";
|
|
|
2
2
|
import { readFile } from "node:fs/promises";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import process from "node:process";
|
|
5
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
5
6
|
import { init, parse } from "cjs-module-lexer";
|
|
6
7
|
import { up } from "empathic/package";
|
|
8
|
+
import { resolve } from "import-meta-resolve";
|
|
7
9
|
import { MagicStringAST, generateTransform } from "magic-string-ast";
|
|
8
|
-
import {
|
|
9
|
-
import { parseAst } from "rolldown/parseAst";
|
|
10
|
+
import { parseSync } from "rolldown/experimental";
|
|
10
11
|
import { createFilter } from "unplugin-utils";
|
|
11
12
|
|
|
12
13
|
//#region rolldown:runtime
|
|
@@ -59,10 +60,10 @@ function RequireCJS(userOptions = {}) {
|
|
|
59
60
|
order,
|
|
60
61
|
async handler(code, { fileName }, { file, dir }) {
|
|
61
62
|
if (!filter(fileName)) return;
|
|
62
|
-
const {
|
|
63
|
+
const { program } = parseSync(fileName, code);
|
|
63
64
|
const s = new MagicStringAST(code);
|
|
64
65
|
let usingRequire = false;
|
|
65
|
-
for (const stmt of body) if (stmt.type === "ImportDeclaration") {
|
|
66
|
+
for (const stmt of program.body) if (stmt.type === "ImportDeclaration") {
|
|
66
67
|
if (stmt.importKind === "type") continue;
|
|
67
68
|
const source = stmt.source.value;
|
|
68
69
|
const isBuiltinModule = builtinNodeModules && isBuiltin(source);
|
|
@@ -113,9 +114,11 @@ const ${REQUIRE} = __cjs_createRequire(import.meta.url);\n`;
|
|
|
113
114
|
}
|
|
114
115
|
async function isPureCJS(id, importer) {
|
|
115
116
|
if (!initted) await init();
|
|
116
|
-
if (id
|
|
117
|
+
if (isBuiltin(id)) return false;
|
|
117
118
|
try {
|
|
118
|
-
|
|
119
|
+
let importResolved = resolve(id, pathToFileURL(importer).href);
|
|
120
|
+
if (!importResolved.startsWith("file://")) return false;
|
|
121
|
+
importResolved = fileURLToPath(importResolved);
|
|
119
122
|
const requireResolved = __require.resolve(id, { paths: [importer] });
|
|
120
123
|
if (path.resolve(importResolved) !== path.resolve(requireResolved)) return false;
|
|
121
124
|
if (importResolved.endsWith(".cjs")) return true;
|
package/package.json
CHANGED
|
@@ -1,59 +1,60 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rolldown-plugin-require-cjs",
|
|
3
|
-
"version": "0.3.2",
|
|
4
|
-
"description": "Transform ESM imports to CJS requires when the imported module is pure CJS.",
|
|
5
3
|
"type": "module",
|
|
4
|
+
"version": "0.3.3",
|
|
5
|
+
"description": "Transform ESM imports to CJS requires when the imported module is pure CJS.",
|
|
6
|
+
"author": "Kevin Deng <sxzz@sxzz.moe>",
|
|
6
7
|
"license": "MIT",
|
|
8
|
+
"funding": "https://github.com/sponsors/sxzz",
|
|
7
9
|
"homepage": "https://github.com/sxzz/rolldown-plugin-require-cjs#readme",
|
|
8
|
-
"bugs": {
|
|
9
|
-
"url": "https://github.com/sxzz/rolldown-plugin-require-cjs/issues"
|
|
10
|
-
},
|
|
11
10
|
"repository": {
|
|
12
11
|
"type": "git",
|
|
13
12
|
"url": "git+https://github.com/sxzz/rolldown-plugin-require-cjs.git"
|
|
14
13
|
},
|
|
15
|
-
"
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
"dist"
|
|
19
|
-
],
|
|
20
|
-
"main": "./dist/index.mjs",
|
|
21
|
-
"module": "./dist/index.mjs",
|
|
22
|
-
"types": "./dist/index.d.mts",
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/sxzz/rolldown-plugin-require-cjs/issues"
|
|
16
|
+
},
|
|
23
17
|
"exports": {
|
|
24
18
|
".": "./dist/index.mjs",
|
|
25
19
|
"./package.json": "./package.json"
|
|
26
20
|
},
|
|
21
|
+
"main": "./dist/index.mjs",
|
|
22
|
+
"module": "./dist/index.mjs",
|
|
23
|
+
"types": "./dist/index.d.mts",
|
|
24
|
+
"files": [
|
|
25
|
+
"dist"
|
|
26
|
+
],
|
|
27
27
|
"publishConfig": {
|
|
28
28
|
"access": "public"
|
|
29
29
|
},
|
|
30
|
+
"engines": {
|
|
31
|
+
"node": ">=20.19.0"
|
|
32
|
+
},
|
|
30
33
|
"peerDependencies": {
|
|
31
34
|
"rolldown": "*"
|
|
32
35
|
},
|
|
33
36
|
"dependencies": {
|
|
34
37
|
"cjs-module-lexer": "^2.1.1",
|
|
35
38
|
"empathic": "^2.0.0",
|
|
39
|
+
"import-meta-resolve": "^4.2.0",
|
|
36
40
|
"magic-string-ast": "^1.0.3",
|
|
37
|
-
"mlly": "^1.8.0",
|
|
38
41
|
"unplugin-utils": "^0.3.1"
|
|
39
42
|
},
|
|
40
43
|
"devDependencies": {
|
|
41
44
|
"@babel/parser": "^7.28.5",
|
|
42
|
-
"@sxzz/eslint-config": "^7.4.
|
|
45
|
+
"@sxzz/eslint-config": "^7.4.1",
|
|
43
46
|
"@sxzz/prettier-config": "^2.2.6",
|
|
44
47
|
"@sxzz/test-utils": "^0.5.13",
|
|
45
48
|
"@types/node": "^24.10.1",
|
|
49
|
+
"@typescript/native-preview": "7.0.0-dev.20251203.1",
|
|
46
50
|
"bumpp": "^10.3.2",
|
|
47
51
|
"eslint": "^9.39.1",
|
|
48
52
|
"eslint-plugin-vue": "^10.6.2",
|
|
49
|
-
"prettier": "^3.7.
|
|
50
|
-
"rolldown": "1.0.0-beta.
|
|
51
|
-
"tsdown": "^0.
|
|
53
|
+
"prettier": "^3.7.4",
|
|
54
|
+
"rolldown": "1.0.0-beta.53",
|
|
55
|
+
"tsdown": "^0.17.0-beta.6",
|
|
52
56
|
"typescript": "^5.9.3",
|
|
53
|
-
"vitest": "^4.0.
|
|
54
|
-
},
|
|
55
|
-
"engines": {
|
|
56
|
-
"node": ">=20.19.0"
|
|
57
|
+
"vitest": "^4.0.15"
|
|
57
58
|
},
|
|
58
59
|
"prettier": "@sxzz/prettier-config",
|
|
59
60
|
"tsdown": {
|
|
@@ -66,7 +67,7 @@
|
|
|
66
67
|
"build": "tsdown",
|
|
67
68
|
"dev": "tsdown --watch",
|
|
68
69
|
"test": "vitest",
|
|
69
|
-
"typecheck": "
|
|
70
|
+
"typecheck": "tsgo --noEmit",
|
|
70
71
|
"format": "prettier --cache --write .",
|
|
71
72
|
"release": "bumpp"
|
|
72
73
|
}
|