@distilled.cloud/cloudflare-rolldown-plugin 0.1.2 → 0.2.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/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Plugin } from "rolldown";
|
|
2
2
|
import type { CloudflarePluginOptions } from "../plugin.js";
|
|
3
|
-
export declare function makeNodejsCompatPlugin(options: CloudflarePluginOptions):
|
|
3
|
+
export declare function makeNodejsCompatPlugin(options: CloudflarePluginOptions): Plugin | Array<Plugin>;
|
|
4
4
|
//# sourceMappingURL=nodejs-compat.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nodejs-compat.d.ts","sourceRoot":"","sources":["../../src/plugins/nodejs-compat.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"nodejs-compat.d.ts","sourceRoot":"","sources":["../../src/plugins/nodejs-compat.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAGvC,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AAM5D,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,uBAAuB,GAAG,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,CAK/F"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { getCloudflarePreset, nonPrefixedNodeModules } from "@cloudflare/unenv-preset";
|
|
2
2
|
import assert from "node:assert";
|
|
3
3
|
import { createRequire } from "node:module";
|
|
4
|
+
import path from "node:path";
|
|
4
5
|
import { esmExternalRequirePlugin } from "rolldown/plugins";
|
|
5
6
|
import { defineEnv } from "unenv";
|
|
6
7
|
import { hasNodejsCompat } from "../utils.js";
|
|
@@ -91,21 +92,24 @@ function makeUnenvPlugin(options) {
|
|
|
91
92
|
}
|
|
92
93
|
function makeNodeJsImportWarningPlugin() {
|
|
93
94
|
const imports = new Map();
|
|
95
|
+
let root = process.cwd();
|
|
94
96
|
return {
|
|
95
|
-
name: "rolldown-plugin-cloudflare:nodejs-
|
|
97
|
+
name: "rolldown-plugin-cloudflare:nodejs-import-warnings",
|
|
98
|
+
options(options) {
|
|
99
|
+
if (options.cwd) {
|
|
100
|
+
root = options.cwd;
|
|
101
|
+
}
|
|
102
|
+
},
|
|
96
103
|
resolveId: {
|
|
97
104
|
filter: { id: NODE_BUILTIN_MODULES_REGEXP },
|
|
98
|
-
async handler(id, importer
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
if (!imports.has(id)) {
|
|
103
|
-
imports.set(id, new Set());
|
|
104
|
-
}
|
|
105
|
-
imports.get(id)?.add(importer);
|
|
105
|
+
async handler(id, importer) {
|
|
106
|
+
if (importer) {
|
|
107
|
+
if (!imports.has(id)) {
|
|
108
|
+
imports.set(id, new Set());
|
|
106
109
|
}
|
|
107
|
-
|
|
110
|
+
imports.get(id)?.add(importer);
|
|
108
111
|
}
|
|
112
|
+
return { id, external: true };
|
|
109
113
|
},
|
|
110
114
|
},
|
|
111
115
|
buildStart() {
|
|
@@ -113,12 +117,15 @@ function makeNodeJsImportWarningPlugin() {
|
|
|
113
117
|
},
|
|
114
118
|
buildEnd() {
|
|
115
119
|
if (imports.size > 0) {
|
|
120
|
+
let message = `Unexpected Node.js imports. ` +
|
|
121
|
+
`Do you need to enable the "nodejs_compat" compatibility flag? ` +
|
|
122
|
+
"Refer to https://developers.cloudflare.com/workers/runtime-apis/nodejs/ for more details.\n";
|
|
116
123
|
for (const [id, importers] of imports.entries()) {
|
|
117
|
-
|
|
118
|
-
`
|
|
119
|
-
|
|
120
|
-
].join("\n"));
|
|
124
|
+
for (const importer of importers) {
|
|
125
|
+
message += ` - "${id}" imported from "${path.relative(root, importer)}"\n`;
|
|
126
|
+
}
|
|
121
127
|
}
|
|
128
|
+
this.warn(message);
|
|
122
129
|
}
|
|
123
130
|
},
|
|
124
131
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nodejs-compat.js","sourceRoot":"","sources":["../../src/plugins/nodejs-compat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AACvF,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"nodejs-compat.js","sourceRoot":"","sources":["../../src/plugins/nodejs-compat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AACvF,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAElC,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,MAAM,2BAA2B,GAAG,IAAI,MAAM,CAAC,KAAK,sBAAsB,CAAC,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;AAClG,MAAM,wBAAwB,GAAG,oCAAoC,CAAC;AAEtE,MAAM,UAAU,sBAAsB,CAAC,OAAgC;IACrE,IAAI,eAAe,CAAC,OAAO,CAAC,kBAAkB,CAAC,EAAE,CAAC;QAChD,OAAO,eAAe,CAAC,OAAO,CAAC,CAAC;IAClC,CAAC;IACD,OAAO,6BAA6B,EAAE,CAAC;AACzC,CAAC;AAED,SAAS,eAAe,CAAC,OAAgC;IACvD,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,SAAS,CAAC;QACtD,OAAO,EAAE;YACP,mBAAmB,CAAC;gBAClB,iBAAiB,EAAE,OAAO,CAAC,iBAAiB;g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AAO,CAAC,MAAM,CAAC,EAAE,CAAC;QACrE,wFAAwF;QACxF,6DAA6D;QAC7D,MAAM,CAAC,OAAO,eAAe,KAAK,QAAQ,EAAE,yCAAyC,CAAC,CAAC;QACvF,cAAc,CAAC,GAAG,CAChB,qBAAqB,CAAC,YAAY,CAAC,EACnC,8BAA8B,eAAe,iBAAiB,YAAY,mBAAmB,CAC9F,CAAC;IACJ,CAAC;IACD,OAAO,cAAc,CAAC;AACxB,CAAC;AAED,SAAS,qBAAqB,CAAC,MAAc;IAC3C,OAAO,gCAAgC,MAAM,EAAW,CAAC;AAC3D,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@distilled.cloud/cloudflare-rolldown-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Rolldown plugin for Cloudflare Workers.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cloudflare",
|
|
7
7
|
"rolldown",
|
|
8
8
|
"workers"
|
|
9
9
|
],
|
|
10
|
-
"homepage": "https://github.com/alchemy-run/cloudflare-tools/tree/main/packages/rolldown-plugin
|
|
10
|
+
"homepage": "https://github.com/alchemy-run/cloudflare-tools/tree/main/packages/cloudflare-rolldown-plugin#readme",
|
|
11
11
|
"bugs": {
|
|
12
12
|
"url": "https://github.com/alchemy-run/cloudflare-tools/issues"
|
|
13
13
|
},
|
|
@@ -43,6 +43,7 @@
|
|
|
43
43
|
"scripts": {
|
|
44
44
|
"build": "tsc",
|
|
45
45
|
"clean": "rm -rf dist tsconfig.tsbuildinfo",
|
|
46
|
+
"dev": "tsc --watch",
|
|
46
47
|
"test": "vitest run",
|
|
47
48
|
"test:watch": "vitest",
|
|
48
49
|
"typecheck": "tsc --noEmit",
|
|
@@ -53,9 +54,9 @@
|
|
|
53
54
|
"unenv": "^2.0.0-rc.24"
|
|
54
55
|
},
|
|
55
56
|
"devDependencies": {
|
|
56
|
-
"@cloudflare/workers-types": "
|
|
57
|
+
"@cloudflare/workers-types": "^4.20260310.1",
|
|
57
58
|
"miniflare": "^4.20260329.0",
|
|
58
|
-
"vitest": "
|
|
59
|
+
"vitest": "^4.1.1"
|
|
59
60
|
},
|
|
60
61
|
"peerDependencies": {
|
|
61
62
|
"rolldown": "^1.0.0-rc.9"
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { getCloudflarePreset, nonPrefixedNodeModules } from "@cloudflare/unenv-preset";
|
|
2
2
|
import assert from "node:assert";
|
|
3
3
|
import { createRequire } from "node:module";
|
|
4
|
-
import
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import type { Plugin } from "rolldown";
|
|
5
6
|
import { esmExternalRequirePlugin } from "rolldown/plugins";
|
|
6
7
|
import { defineEnv } from "unenv";
|
|
7
8
|
import type { CloudflarePluginOptions } from "../plugin.js";
|
|
@@ -10,14 +11,14 @@ import { hasNodejsCompat } from "../utils.js";
|
|
|
10
11
|
const NODE_BUILTIN_MODULES_REGEXP = new RegExp(`^(${nonPrefixedNodeModules.join("|")}|node:.+)$`);
|
|
11
12
|
const VIRTUAL_MODULE_ID_REGEXP = /^virtual:nodejs-global-inject\/.+$/;
|
|
12
13
|
|
|
13
|
-
export function makeNodejsCompatPlugin(options: CloudflarePluginOptions):
|
|
14
|
+
export function makeNodejsCompatPlugin(options: CloudflarePluginOptions): Plugin | Array<Plugin> {
|
|
14
15
|
if (hasNodejsCompat(options.compatibilityFlags)) {
|
|
15
16
|
return makeUnenvPlugin(options);
|
|
16
17
|
}
|
|
17
18
|
return makeNodeJsImportWarningPlugin();
|
|
18
19
|
}
|
|
19
20
|
|
|
20
|
-
function makeUnenvPlugin(options: CloudflarePluginOptions):
|
|
21
|
+
function makeUnenvPlugin(options: CloudflarePluginOptions): Array<Plugin> {
|
|
21
22
|
const { alias, inject, external, polyfill } = defineEnv({
|
|
22
23
|
presets: [
|
|
23
24
|
getCloudflarePreset({
|
|
@@ -96,23 +97,26 @@ function makeUnenvPlugin(options: CloudflarePluginOptions): RolldownPluginOption
|
|
|
96
97
|
];
|
|
97
98
|
}
|
|
98
99
|
|
|
99
|
-
function makeNodeJsImportWarningPlugin():
|
|
100
|
+
function makeNodeJsImportWarningPlugin(): Plugin {
|
|
100
101
|
const imports = new Map<string, Set<string>>();
|
|
102
|
+
let root = process.cwd();
|
|
101
103
|
return {
|
|
102
|
-
name: "rolldown-plugin-cloudflare:nodejs-
|
|
104
|
+
name: "rolldown-plugin-cloudflare:nodejs-import-warnings",
|
|
105
|
+
options(options) {
|
|
106
|
+
if (options.cwd) {
|
|
107
|
+
root = options.cwd;
|
|
108
|
+
}
|
|
109
|
+
},
|
|
103
110
|
resolveId: {
|
|
104
111
|
filter: { id: NODE_BUILTIN_MODULES_REGEXP },
|
|
105
|
-
async handler(id, importer
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
if (!imports.has(id)) {
|
|
110
|
-
imports.set(id, new Set());
|
|
111
|
-
}
|
|
112
|
-
imports.get(id)?.add(importer);
|
|
112
|
+
async handler(id, importer) {
|
|
113
|
+
if (importer) {
|
|
114
|
+
if (!imports.has(id)) {
|
|
115
|
+
imports.set(id, new Set());
|
|
113
116
|
}
|
|
114
|
-
|
|
117
|
+
imports.get(id)?.add(importer);
|
|
115
118
|
}
|
|
119
|
+
return { id, external: true };
|
|
116
120
|
},
|
|
117
121
|
},
|
|
118
122
|
buildStart() {
|
|
@@ -120,14 +124,16 @@ function makeNodeJsImportWarningPlugin(): RolldownPluginOption {
|
|
|
120
124
|
},
|
|
121
125
|
buildEnd() {
|
|
122
126
|
if (imports.size > 0) {
|
|
127
|
+
let message =
|
|
128
|
+
`Unexpected Node.js imports. ` +
|
|
129
|
+
`Do you need to enable the "nodejs_compat" compatibility flag? ` +
|
|
130
|
+
"Refer to https://developers.cloudflare.com/workers/runtime-apis/nodejs/ for more details.\n";
|
|
123
131
|
for (const [id, importers] of imports.entries()) {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
...Array.from(importers).map((importer) => `- ${importer}`),
|
|
128
|
-
].join("\n"),
|
|
129
|
-
);
|
|
132
|
+
for (const importer of importers) {
|
|
133
|
+
message += ` - "${id}" imported from "${path.relative(root, importer)}"\n`;
|
|
134
|
+
}
|
|
130
135
|
}
|
|
136
|
+
this.warn(message);
|
|
131
137
|
}
|
|
132
138
|
},
|
|
133
139
|
};
|