nitropack-nightly 2.11.0-20250303-201505.ba9bebc7 → 2.11.0-20250303-213503.3cd9b5f5
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/meta/index.d.mts
CHANGED
package/dist/meta/index.d.ts
CHANGED
package/dist/meta/index.mjs
CHANGED
|
@@ -15,27 +15,27 @@ export interface CloudflarePagesRoutes {
|
|
|
15
15
|
}
|
|
16
16
|
export interface CloudflareOptions {
|
|
17
17
|
/**
|
|
18
|
-
* Configuration for the Cloudflare Deployments
|
|
18
|
+
* Configuration for the Cloudflare Deployments.
|
|
19
|
+
*
|
|
20
|
+
* **NOTE:** This option is only effective if `deployConfig` is enabled.
|
|
19
21
|
*/
|
|
20
22
|
wrangler?: WranglerConfig;
|
|
21
23
|
/**
|
|
22
|
-
* Enable
|
|
24
|
+
* Enable automatic generation of `.wrangler/deploy/config.json`.
|
|
23
25
|
*
|
|
24
|
-
*
|
|
26
|
+
* **IMPORTANT:** Enabling this option will cause settings from cloudflare dashboard (including environment variables) to be disabled and discarded.
|
|
25
27
|
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
* Enabled by default with `compatibilityDate` >= `2025-03-01`.
|
|
28
|
+
* More info: https://developers.cloudflare.com/workers/wrangler/configuration#generated-wrangler-configuration
|
|
29
29
|
*/
|
|
30
|
-
|
|
30
|
+
deployConfig?: boolean;
|
|
31
31
|
/**
|
|
32
|
-
*
|
|
32
|
+
* Enable native Node.js compatibility support.
|
|
33
33
|
*
|
|
34
|
-
*
|
|
34
|
+
* If this option disabled, pure unenv polyfills will be used instead.
|
|
35
35
|
*
|
|
36
|
-
*
|
|
36
|
+
* If not set, will be auto enabled if `nodejs_compat` or `nodejs_compat_v2` is detected in `wrangler.toml` or `wrangler.json`.
|
|
37
37
|
*/
|
|
38
|
-
|
|
38
|
+
nodeCompat?: boolean;
|
|
39
39
|
pages?: {
|
|
40
40
|
/**
|
|
41
41
|
* Nitro will automatically generate a `_routes.json` that controls which files get served statically and
|
|
@@ -3,7 +3,7 @@ import { readFile } from "node:fs/promises";
|
|
|
3
3
|
import { relative, dirname } from "node:path";
|
|
4
4
|
import { writeFile } from "nitropack/kit";
|
|
5
5
|
import { parseTOML } from "confbox";
|
|
6
|
-
import { readGitConfig, readPackageJSON } from "pkg-types";
|
|
6
|
+
import { readGitConfig, readPackageJSON, findNearestFile } from "pkg-types";
|
|
7
7
|
import { defu } from "defu";
|
|
8
8
|
import { globby } from "globby";
|
|
9
9
|
import { join, resolve } from "pathe";
|
|
@@ -138,31 +138,44 @@ export async function writeCFPagesRedirects(nitro) {
|
|
|
138
138
|
}
|
|
139
139
|
await writeFile(redirectsPath, contents.join("\n"), true);
|
|
140
140
|
}
|
|
141
|
-
const wranglerConfigAndUnenv2CompatDate = "2025-03-01";
|
|
142
141
|
export async function enableNodeCompat(nitro) {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
142
|
+
if (nitro.options.cloudflare?.nodeCompat === void 0) {
|
|
143
|
+
const { config } = await readWranglerConfig(nitro);
|
|
144
|
+
const userCompatibilityFlags = new Set(config?.compatibility_flags || []);
|
|
145
|
+
if (userCompatibilityFlags.has("nodejs_compat") || userCompatibilityFlags.has("nodejs_compat_v2")) {
|
|
146
|
+
nitro.options.cloudflare ??= {};
|
|
147
|
+
nitro.options.cloudflare.nodeCompat = true;
|
|
148
|
+
}
|
|
149
149
|
}
|
|
150
|
-
if (
|
|
151
|
-
nitro.options.
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
);
|
|
150
|
+
if (!nitro.options.cloudflare?.nodeCompat) {
|
|
151
|
+
if (nitro.options.cloudflare?.nodeCompat === void 0) {
|
|
152
|
+
nitro.logger.warn("[cloudflare] Node.js compatibility is not enabled.");
|
|
153
|
+
}
|
|
154
|
+
return;
|
|
156
155
|
}
|
|
157
|
-
nitro.options.
|
|
158
|
-
nitro.options.
|
|
156
|
+
nitro.options.unenv.push(unenvWorkerdWithNodeCompat);
|
|
157
|
+
nitro.options.rollupConfig.plugins ??= [];
|
|
158
|
+
nitro.options.rollupConfig.plugins.push(
|
|
159
|
+
workerdHybridNodeCompatPlugin
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
async function readWranglerConfig(nitro) {
|
|
163
|
+
const configPath = await findNearestFile(["wrangler.json", "wrangler.toml"], {
|
|
164
|
+
startingFrom: nitro.options.rootDir
|
|
165
|
+
}).catch(() => void 0);
|
|
166
|
+
if (!configPath) {
|
|
167
|
+
return {};
|
|
168
|
+
}
|
|
169
|
+
const userConfigText = await readFile(configPath, "utf8");
|
|
170
|
+
const config = configPath.endsWith(".toml") ? parseTOML(userConfigText) : JSON.parse(userConfigText);
|
|
171
|
+
return { configPath, config };
|
|
159
172
|
}
|
|
160
173
|
export async function writeWranglerConfig(nitro, cfTarget) {
|
|
161
174
|
const wranglerConfigDir = nitro.options.output.serverDir;
|
|
162
175
|
const wranglerConfigPath = join(wranglerConfigDir, "wrangler.json");
|
|
163
176
|
const defaults = {};
|
|
164
177
|
const overrides = {};
|
|
165
|
-
|
|
178
|
+
defaults.compatibility_date = nitro.options.compatibilityDate.cloudflare || nitro.options.compatibilityDate.default;
|
|
166
179
|
if (cfTarget === "pages") {
|
|
167
180
|
overrides.pages_build_output_dir = relative(
|
|
168
181
|
wranglerConfigDir,
|
|
@@ -178,7 +191,7 @@ export async function writeWranglerConfig(nitro, cfTarget) {
|
|
|
178
191
|
directory: relative(wranglerConfigDir, nitro.options.output.publicDir)
|
|
179
192
|
};
|
|
180
193
|
}
|
|
181
|
-
const userConfig = await
|
|
194
|
+
const { config: userConfig = {} } = await readWranglerConfig(nitro);
|
|
182
195
|
const ctxConfig = nitro.options.cloudflare?.wrangler || {};
|
|
183
196
|
for (const key in overrides) {
|
|
184
197
|
if (key in userConfig || key in ctxConfig) {
|
|
@@ -222,40 +235,17 @@ export async function writeWranglerConfig(nitro, cfTarget) {
|
|
|
222
235
|
JSON.stringify(wranglerConfig, null, 2),
|
|
223
236
|
true
|
|
224
237
|
);
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
)
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
JSON.stringify({
|
|
237
|
-
configPath: relative(dirname(configPath), wranglerConfigPath)
|
|
238
|
-
}),
|
|
239
|
-
true
|
|
240
|
-
);
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
async function resolveWranglerConfig(dir) {
|
|
244
|
-
const jsonConfig = join(dir, "wrangler.json");
|
|
245
|
-
if (existsSync(jsonConfig)) {
|
|
246
|
-
const config = JSON.parse(
|
|
247
|
-
await readFile(join(dir, "wrangler.json"), "utf8")
|
|
248
|
-
);
|
|
249
|
-
return config;
|
|
250
|
-
}
|
|
251
|
-
const tomlConfig = join(dir, "wrangler.toml");
|
|
252
|
-
if (existsSync(tomlConfig)) {
|
|
253
|
-
const config = parseTOML(
|
|
254
|
-
await readFile(join(dir, "wrangler.toml"), "utf8")
|
|
255
|
-
);
|
|
256
|
-
return config;
|
|
257
|
-
}
|
|
258
|
-
return {};
|
|
238
|
+
const configPath = join(
|
|
239
|
+
nitro.options.rootDir,
|
|
240
|
+
".wrangler/deploy/config.json"
|
|
241
|
+
);
|
|
242
|
+
await writeFile(
|
|
243
|
+
configPath,
|
|
244
|
+
JSON.stringify({
|
|
245
|
+
configPath: relative(dirname(configPath), wranglerConfigPath)
|
|
246
|
+
}),
|
|
247
|
+
true
|
|
248
|
+
);
|
|
259
249
|
}
|
|
260
250
|
async function generateWorkerName(nitro) {
|
|
261
251
|
const gitConfig = await readGitConfig(nitro.options.rootDir).catch(
|
|
@@ -267,5 +257,5 @@ async function generateWorkerName(nitro) {
|
|
|
267
257
|
);
|
|
268
258
|
const pkgName = pkgJSON?.name;
|
|
269
259
|
const subpath = relative(nitro.options.workspaceDir, nitro.options.rootDir);
|
|
270
|
-
return `${gitRepo || pkgName}/${subpath}`.replace(/[^a-zA-Z0-9-]/g, "-");
|
|
260
|
+
return `${gitRepo || pkgName}/${subpath}`.replace(/[^a-zA-Z0-9-]/g, "-").replace(/-$/, "");
|
|
271
261
|
}
|
package/package.json
CHANGED