@opennextjs/cloudflare 0.1.1 → 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/dist/cli/index.mjs +71 -61
- package/package.json +1 -1
package/dist/cli/index.mjs
CHANGED
|
@@ -238,8 +238,8 @@ var require_brace_expansion = __commonJS({
|
|
|
238
238
|
import path, { relative } from "node:path";
|
|
239
239
|
import { readdirSync, statSync } from "node:fs";
|
|
240
240
|
var PACKAGE_NAME = "@opennextjs/cloudflare";
|
|
241
|
-
function getConfig(
|
|
242
|
-
const dotNext = path.join(
|
|
241
|
+
function getConfig(projectOpts) {
|
|
242
|
+
const dotNext = path.join(projectOpts.outputDir, ".next");
|
|
243
243
|
const appPath = getNextjsApplicationPath(dotNext).replace(/\/$/, "");
|
|
244
244
|
const standaloneRoot = path.join(dotNext, "standalone");
|
|
245
245
|
const standaloneApp = path.join(standaloneRoot, appPath);
|
|
@@ -250,10 +250,14 @@ function getConfig(appDir, outputDir2) {
|
|
|
250
250
|
const internalTemplates = path.join(internalPackage, "cli", "templates");
|
|
251
251
|
process.env.__OPENNEXT_KV_BINDING_NAME ??= "NEXT_CACHE_WORKERS_KV";
|
|
252
252
|
return {
|
|
253
|
-
|
|
253
|
+
build: {
|
|
254
|
+
timestamp: Date.now(),
|
|
255
|
+
skipNextBuild: projectOpts.skipNextBuild,
|
|
256
|
+
shouldMinify: projectOpts.minify
|
|
257
|
+
},
|
|
254
258
|
paths: {
|
|
255
|
-
|
|
256
|
-
|
|
259
|
+
sourceDir: projectOpts.sourceDir,
|
|
260
|
+
outputDir: projectOpts.outputDir,
|
|
257
261
|
dotNext,
|
|
258
262
|
standaloneRoot,
|
|
259
263
|
standaloneApp,
|
|
@@ -403,7 +407,7 @@ function runNextBuildCommand(packager, nextAppDir2) {
|
|
|
403
407
|
cwd: nextAppDir2,
|
|
404
408
|
env: {
|
|
405
409
|
...process.env,
|
|
406
|
-
// equivalent to: https://github.com/
|
|
410
|
+
// equivalent to: https://github.com/opennextjs/opennextjs-aws/blob/f61b0e9/packages/open-next/src/build.ts#L168-L173
|
|
407
411
|
// Equivalent to setting `output: "standalone"` in next.config.js
|
|
408
412
|
NEXT_PRIVATE_STANDALONE: "true"
|
|
409
413
|
}
|
|
@@ -461,7 +465,7 @@ function copyPrerenderedRoutes(config) {
|
|
|
461
465
|
console.log("# copyPrerenderedRoutes");
|
|
462
466
|
const serverAppDirPath = join2(config.paths.standaloneAppServer, "app");
|
|
463
467
|
const prerenderManifestPath = join2(config.paths.standaloneAppDotNext, "prerender-manifest.json");
|
|
464
|
-
const outputPath = join2(config.paths.
|
|
468
|
+
const outputPath = join2(config.paths.outputDir, "assets", SEED_DATA_DIR);
|
|
465
469
|
const prerenderManifest = existsSync(prerenderManifestPath) ? JSON.parse(readFileSync(prerenderManifestPath, "utf8")) : {};
|
|
466
470
|
const prerenderedRoutes = Object.keys(prerenderManifest.routes);
|
|
467
471
|
const prerenderedAssets = readPathsRecursively(serverAppDirPath).map((fullPath) => ({ fullPath, relativePath: fullPath.replace(serverAppDirPath, "") })).filter(
|
|
@@ -472,7 +476,7 @@ function copyPrerenderedRoutes(config) {
|
|
|
472
476
|
mkdirSync(dirname(destPath), { recursive: true });
|
|
473
477
|
if (fullPath.endsWith(NEXT_META_SUFFIX)) {
|
|
474
478
|
const data = JSON.parse(readFileSync(fullPath, "utf8"));
|
|
475
|
-
writeFileSync(destPath, JSON.stringify({ ...data, lastModified: config.
|
|
479
|
+
writeFileSync(destPath, JSON.stringify({ ...data, lastModified: config.build.timestamp }));
|
|
476
480
|
} else {
|
|
477
481
|
copyFileSync(fullPath, destPath);
|
|
478
482
|
}
|
|
@@ -4334,12 +4338,12 @@ var PathBase = class {
|
|
|
4334
4338
|
/**
|
|
4335
4339
|
* Get the Path object referenced by the string path, resolved from this Path
|
|
4336
4340
|
*/
|
|
4337
|
-
resolve(
|
|
4338
|
-
if (!
|
|
4341
|
+
resolve(path13) {
|
|
4342
|
+
if (!path13) {
|
|
4339
4343
|
return this;
|
|
4340
4344
|
}
|
|
4341
|
-
const rootPath = this.getRootString(
|
|
4342
|
-
const dir =
|
|
4345
|
+
const rootPath = this.getRootString(path13);
|
|
4346
|
+
const dir = path13.substring(rootPath.length);
|
|
4343
4347
|
const dirParts = dir.split(this.splitSep);
|
|
4344
4348
|
const result = rootPath ? this.getRoot(rootPath).#resolveParts(dirParts) : this.#resolveParts(dirParts);
|
|
4345
4349
|
return result;
|
|
@@ -5091,8 +5095,8 @@ var PathWin32 = class _PathWin32 extends PathBase {
|
|
|
5091
5095
|
/**
|
|
5092
5096
|
* @internal
|
|
5093
5097
|
*/
|
|
5094
|
-
getRootString(
|
|
5095
|
-
return win32.parse(
|
|
5098
|
+
getRootString(path13) {
|
|
5099
|
+
return win32.parse(path13).root;
|
|
5096
5100
|
}
|
|
5097
5101
|
/**
|
|
5098
5102
|
* @internal
|
|
@@ -5138,8 +5142,8 @@ var PathPosix = class _PathPosix extends PathBase {
|
|
|
5138
5142
|
/**
|
|
5139
5143
|
* @internal
|
|
5140
5144
|
*/
|
|
5141
|
-
getRootString(
|
|
5142
|
-
return
|
|
5145
|
+
getRootString(path13) {
|
|
5146
|
+
return path13.startsWith("/") ? "/" : "";
|
|
5143
5147
|
}
|
|
5144
5148
|
/**
|
|
5145
5149
|
* @internal
|
|
@@ -5228,11 +5232,11 @@ var PathScurryBase = class {
|
|
|
5228
5232
|
/**
|
|
5229
5233
|
* Get the depth of a provided path, string, or the cwd
|
|
5230
5234
|
*/
|
|
5231
|
-
depth(
|
|
5232
|
-
if (typeof
|
|
5233
|
-
|
|
5235
|
+
depth(path13 = this.cwd) {
|
|
5236
|
+
if (typeof path13 === "string") {
|
|
5237
|
+
path13 = this.cwd.resolve(path13);
|
|
5234
5238
|
}
|
|
5235
|
-
return
|
|
5239
|
+
return path13.depth();
|
|
5236
5240
|
}
|
|
5237
5241
|
/**
|
|
5238
5242
|
* Return the cache of child entries. Exposed so subclasses can create
|
|
@@ -5719,9 +5723,9 @@ var PathScurryBase = class {
|
|
|
5719
5723
|
process3();
|
|
5720
5724
|
return results;
|
|
5721
5725
|
}
|
|
5722
|
-
chdir(
|
|
5726
|
+
chdir(path13 = this.cwd) {
|
|
5723
5727
|
const oldCwd = this.cwd;
|
|
5724
|
-
this.cwd = typeof
|
|
5728
|
+
this.cwd = typeof path13 === "string" ? this.cwd.resolve(path13) : path13;
|
|
5725
5729
|
this.cwd[setAsCwd](oldCwd);
|
|
5726
5730
|
}
|
|
5727
5731
|
};
|
|
@@ -6077,8 +6081,8 @@ var MatchRecord = class {
|
|
|
6077
6081
|
}
|
|
6078
6082
|
// match, absolute, ifdir
|
|
6079
6083
|
entries() {
|
|
6080
|
-
return [...this.store.entries()].map(([
|
|
6081
|
-
|
|
6084
|
+
return [...this.store.entries()].map(([path13, n]) => [
|
|
6085
|
+
path13,
|
|
6082
6086
|
!!(n & 2),
|
|
6083
6087
|
!!(n & 1)
|
|
6084
6088
|
]);
|
|
@@ -6283,9 +6287,9 @@ var GlobUtil = class {
|
|
|
6283
6287
|
signal;
|
|
6284
6288
|
maxDepth;
|
|
6285
6289
|
includeChildMatches;
|
|
6286
|
-
constructor(patterns,
|
|
6290
|
+
constructor(patterns, path13, opts) {
|
|
6287
6291
|
this.patterns = patterns;
|
|
6288
|
-
this.path =
|
|
6292
|
+
this.path = path13;
|
|
6289
6293
|
this.opts = opts;
|
|
6290
6294
|
this.#sep = !opts.posix && opts.platform === "win32" ? "\\" : "/";
|
|
6291
6295
|
this.includeChildMatches = opts.includeChildMatches !== false;
|
|
@@ -6304,11 +6308,11 @@ var GlobUtil = class {
|
|
|
6304
6308
|
});
|
|
6305
6309
|
}
|
|
6306
6310
|
}
|
|
6307
|
-
#ignored(
|
|
6308
|
-
return this.seen.has(
|
|
6311
|
+
#ignored(path13) {
|
|
6312
|
+
return this.seen.has(path13) || !!this.#ignore?.ignored?.(path13);
|
|
6309
6313
|
}
|
|
6310
|
-
#childrenIgnored(
|
|
6311
|
-
return !!this.#ignore?.childrenIgnored?.(
|
|
6314
|
+
#childrenIgnored(path13) {
|
|
6315
|
+
return !!this.#ignore?.childrenIgnored?.(path13);
|
|
6312
6316
|
}
|
|
6313
6317
|
// backpressure mechanism
|
|
6314
6318
|
pause() {
|
|
@@ -6523,8 +6527,8 @@ var GlobUtil = class {
|
|
|
6523
6527
|
};
|
|
6524
6528
|
var GlobWalker = class extends GlobUtil {
|
|
6525
6529
|
matches = /* @__PURE__ */ new Set();
|
|
6526
|
-
constructor(patterns,
|
|
6527
|
-
super(patterns,
|
|
6530
|
+
constructor(patterns, path13, opts) {
|
|
6531
|
+
super(patterns, path13, opts);
|
|
6528
6532
|
}
|
|
6529
6533
|
matchEmit(e) {
|
|
6530
6534
|
this.matches.add(e);
|
|
@@ -6561,8 +6565,8 @@ var GlobWalker = class extends GlobUtil {
|
|
|
6561
6565
|
};
|
|
6562
6566
|
var GlobStream = class extends GlobUtil {
|
|
6563
6567
|
results;
|
|
6564
|
-
constructor(patterns,
|
|
6565
|
-
super(patterns,
|
|
6568
|
+
constructor(patterns, path13, opts) {
|
|
6569
|
+
super(patterns, path13, opts);
|
|
6566
6570
|
this.results = new Minipass({
|
|
6567
6571
|
signal: this.signal,
|
|
6568
6572
|
objectMode: true
|
|
@@ -6946,14 +6950,14 @@ async function patchCache(code, config) {
|
|
|
6946
6950
|
console.log("# patchCache");
|
|
6947
6951
|
const cacheHandlerFileName = "cache-handler.mjs";
|
|
6948
6952
|
const cacheHandlerEntrypoint = join3(config.paths.internalTemplates, "cache-handler", "index.ts");
|
|
6949
|
-
const cacheHandlerOutputFile = join3(config.paths.
|
|
6953
|
+
const cacheHandlerOutputFile = join3(config.paths.outputDir, cacheHandlerFileName);
|
|
6950
6954
|
await build({
|
|
6951
6955
|
entryPoints: [cacheHandlerEntrypoint],
|
|
6952
6956
|
bundle: true,
|
|
6953
6957
|
outfile: cacheHandlerOutputFile,
|
|
6954
6958
|
format: "esm",
|
|
6955
6959
|
target: "esnext",
|
|
6956
|
-
minify:
|
|
6960
|
+
minify: config.build.shouldMinify,
|
|
6957
6961
|
define: {
|
|
6958
6962
|
"process.env.__OPENNEXT_KV_BINDING_NAME": `"${config.cache.kvBindingName}"`
|
|
6959
6963
|
}
|
|
@@ -7198,21 +7202,21 @@ async function buildWorker(config) {
|
|
|
7198
7202
|
\x1B[0m`);
|
|
7199
7203
|
await cp(
|
|
7200
7204
|
path12.join(config.paths.dotNext, "static"),
|
|
7201
|
-
path12.join(config.paths.
|
|
7205
|
+
path12.join(config.paths.outputDir, "assets", "_next", "static"),
|
|
7202
7206
|
{
|
|
7203
7207
|
recursive: true
|
|
7204
7208
|
}
|
|
7205
7209
|
);
|
|
7206
|
-
const publicDir = path12.join(config.paths.
|
|
7210
|
+
const publicDir = path12.join(config.paths.sourceDir, "public");
|
|
7207
7211
|
if (existsSync5(publicDir)) {
|
|
7208
|
-
await cp(publicDir, path12.join(config.paths.
|
|
7212
|
+
await cp(publicDir, path12.join(config.paths.outputDir, "assets"), {
|
|
7209
7213
|
recursive: true
|
|
7210
7214
|
});
|
|
7211
7215
|
}
|
|
7212
7216
|
copyPrerenderedRoutes(config);
|
|
7213
7217
|
copyPackageCliFiles(packageDistDir, config);
|
|
7214
7218
|
const workerEntrypoint = path12.join(config.paths.internalTemplates, "worker.ts");
|
|
7215
|
-
const workerOutputFile = path12.join(config.paths.
|
|
7219
|
+
const workerOutputFile = path12.join(config.paths.outputDir, "index.mjs");
|
|
7216
7220
|
const nextConfigStr = readFileSync7(path12.join(config.paths.standaloneApp, "/server.js"), "utf8")?.match(
|
|
7217
7221
|
/const nextConfig = ({.+?})\n/
|
|
7218
7222
|
)?.[1] ?? {};
|
|
@@ -7329,23 +7333,22 @@ function createFixRequiresESBuildPlugin(config) {
|
|
|
7329
7333
|
|
|
7330
7334
|
// src/cli/build/index.ts
|
|
7331
7335
|
import { cpSync as cpSync2 } from "node:fs";
|
|
7332
|
-
import
|
|
7336
|
+
import { join as join4 } from "node:path";
|
|
7333
7337
|
import { rm } from "node:fs/promises";
|
|
7334
|
-
async function build3(
|
|
7335
|
-
if (!
|
|
7336
|
-
await buildNextjsApp(
|
|
7338
|
+
async function build3(projectOpts) {
|
|
7339
|
+
if (!projectOpts.skipNextBuild) {
|
|
7340
|
+
await buildNextjsApp(projectOpts.sourceDir);
|
|
7337
7341
|
}
|
|
7338
|
-
if (!containsDotNextDir(
|
|
7339
|
-
throw new Error(`.next folder not found in ${
|
|
7342
|
+
if (!containsDotNextDir(projectOpts.sourceDir)) {
|
|
7343
|
+
throw new Error(`.next folder not found in ${projectOpts.sourceDir}`);
|
|
7340
7344
|
}
|
|
7341
|
-
|
|
7342
|
-
|
|
7343
|
-
|
|
7344
|
-
const config = getConfig(appDir, outputDir2);
|
|
7345
|
+
await cleanDirectory(projectOpts.outputDir);
|
|
7346
|
+
cpSync2(join4(projectOpts.sourceDir, ".next"), join4(projectOpts.outputDir, ".next"), { recursive: true });
|
|
7347
|
+
const config = getConfig(projectOpts);
|
|
7345
7348
|
await buildWorker(config);
|
|
7346
7349
|
}
|
|
7347
|
-
async function cleanDirectory(
|
|
7348
|
-
return await rm(
|
|
7350
|
+
async function cleanDirectory(path13) {
|
|
7351
|
+
return await rm(path13, { recursive: true, force: true });
|
|
7349
7352
|
}
|
|
7350
7353
|
|
|
7351
7354
|
// src/cli/index.ts
|
|
@@ -7357,7 +7360,7 @@ import { parseArgs } from "node:util";
|
|
|
7357
7360
|
import { resolve } from "node:path";
|
|
7358
7361
|
function getArgs() {
|
|
7359
7362
|
const {
|
|
7360
|
-
values: { skipBuild
|
|
7363
|
+
values: { skipBuild, output, noMinify }
|
|
7361
7364
|
} = parseArgs({
|
|
7362
7365
|
options: {
|
|
7363
7366
|
skipBuild: {
|
|
@@ -7368,6 +7371,10 @@ function getArgs() {
|
|
|
7368
7371
|
output: {
|
|
7369
7372
|
type: "string",
|
|
7370
7373
|
short: "o"
|
|
7374
|
+
},
|
|
7375
|
+
noMinify: {
|
|
7376
|
+
type: "boolean",
|
|
7377
|
+
default: false
|
|
7371
7378
|
}
|
|
7372
7379
|
},
|
|
7373
7380
|
allowPositionals: false
|
|
@@ -7378,18 +7385,19 @@ function getArgs() {
|
|
|
7378
7385
|
}
|
|
7379
7386
|
return {
|
|
7380
7387
|
outputDir: outputDir2,
|
|
7381
|
-
|
|
7388
|
+
skipNextBuild: skipBuild || ["1", "true", "yes"].includes(String(process.env.SKIP_NEXT_APP_BUILD)),
|
|
7389
|
+
minify: !noMinify
|
|
7382
7390
|
};
|
|
7383
7391
|
}
|
|
7384
|
-
function assertDirArg(
|
|
7392
|
+
function assertDirArg(path13, argName, make) {
|
|
7385
7393
|
let dirStats;
|
|
7386
7394
|
try {
|
|
7387
|
-
dirStats = statSync3(
|
|
7395
|
+
dirStats = statSync3(path13);
|
|
7388
7396
|
} catch {
|
|
7389
7397
|
if (!make) {
|
|
7390
7398
|
throw new Error(`Error: the provided${argName ? ` "${argName}"` : ""} input is not a valid path`);
|
|
7391
7399
|
}
|
|
7392
|
-
mkdirSync2(
|
|
7400
|
+
mkdirSync2(path13);
|
|
7393
7401
|
return;
|
|
7394
7402
|
}
|
|
7395
7403
|
if (!dirStats.isDirectory()) {
|
|
@@ -7407,8 +7415,10 @@ if (!["js", "cjs", "mjs", "ts"].some((ext2) => existsSync6(`./next.config.${ext2
|
|
|
7407
7415
|
);
|
|
7408
7416
|
process.exit(1);
|
|
7409
7417
|
}
|
|
7410
|
-
var {
|
|
7411
|
-
await build3(
|
|
7412
|
-
|
|
7413
|
-
|
|
7418
|
+
var { skipNextBuild, outputDir, minify } = getArgs();
|
|
7419
|
+
await build3({
|
|
7420
|
+
sourceDir: nextAppDir,
|
|
7421
|
+
outputDir: resolve2(outputDir ?? nextAppDir, ".worker-next"),
|
|
7422
|
+
skipNextBuild,
|
|
7423
|
+
minify
|
|
7414
7424
|
});
|