@opennextjs/cloudflare 1.2.1 → 1.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/cli/args.d.ts +2 -0
- package/dist/cli/args.js +37 -19
- package/dist/cli/build/build.d.ts +2 -2
- package/dist/cli/build/build.js +3 -0
- package/dist/cli/build/bundle-server.d.ts +1 -1
- package/dist/cli/build/bundle-server.js +4 -7
- package/dist/cli/build/open-next/compile-images.d.ts +5 -0
- package/dist/cli/build/open-next/compile-images.js +29 -0
- package/dist/cli/build/open-next/createServerBundle.js +0 -1
- package/dist/cli/build/patches/plugins/next-server.d.ts +0 -2
- package/dist/cli/build/patches/plugins/next-server.js +0 -19
- package/dist/cli/build/{patches/investigated → utils}/copy-package-cli-files.js +1 -1
- package/dist/cli/build/utils/index.d.ts +1 -1
- package/dist/cli/build/utils/index.js +1 -1
- package/dist/cli/build/utils/test-patch.d.ts +9 -0
- package/dist/cli/build/utils/test-patch.js +14 -0
- package/dist/cli/build/utils/workerd.js +3 -1
- package/dist/cli/templates/images.d.ts +24 -0
- package/dist/cli/templates/images.js +82 -0
- package/dist/cli/templates/worker.js +3 -3
- package/package.json +5 -2
- package/dist/api/durable-objects/bucket-cache-purge.spec.d.ts +0 -1
- package/dist/api/durable-objects/bucket-cache-purge.spec.js +0 -121
- package/dist/api/durable-objects/queue.spec.d.ts +0 -1
- package/dist/api/durable-objects/queue.spec.js +0 -287
- package/dist/api/durable-objects/sharded-tag-cache.spec.d.ts +0 -1
- package/dist/api/durable-objects/sharded-tag-cache.spec.js +0 -37
- package/dist/api/overrides/queue/memory-queue.spec.d.ts +0 -1
- package/dist/api/overrides/queue/memory-queue.spec.js +0 -76
- package/dist/api/overrides/queue/queue-cache.spec.d.ts +0 -1
- package/dist/api/overrides/queue/queue-cache.spec.js +0 -92
- package/dist/api/overrides/tag-cache/do-sharded-tag-cache.spec.d.ts +0 -1
- package/dist/api/overrides/tag-cache/do-sharded-tag-cache.spec.js +0 -413
- package/dist/api/overrides/tag-cache/tag-cache-filter.spec.d.ts +0 -1
- package/dist/api/overrides/tag-cache/tag-cache-filter.spec.js +0 -97
- package/dist/cli/build/patches/ast/patch-vercel-og-library.spec.d.ts +0 -1
- package/dist/cli/build/patches/ast/patch-vercel-og-library.spec.js +0 -50
- package/dist/cli/build/patches/ast/vercel-og.spec.d.ts +0 -1
- package/dist/cli/build/patches/ast/vercel-og.spec.js +0 -22
- package/dist/cli/build/patches/ast/webpack-runtime.spec.d.ts +0 -1
- package/dist/cli/build/patches/ast/webpack-runtime.spec.js +0 -102
- package/dist/cli/build/patches/index.d.ts +0 -1
- package/dist/cli/build/patches/index.js +0 -1
- package/dist/cli/build/patches/investigated/index.d.ts +0 -2
- package/dist/cli/build/patches/investigated/index.js +0 -2
- package/dist/cli/build/patches/investigated/patch-require.d.ts +0 -4
- package/dist/cli/build/patches/investigated/patch-require.js +0 -6
- package/dist/cli/build/patches/plugins/instrumentation.spec.d.ts +0 -1
- package/dist/cli/build/patches/plugins/instrumentation.spec.js +0 -91
- package/dist/cli/build/patches/plugins/next-server.spec.d.ts +0 -1
- package/dist/cli/build/patches/plugins/next-server.spec.js +0 -429
- package/dist/cli/build/patches/plugins/patch-depd-deprecations.spec.d.ts +0 -1
- package/dist/cli/build/patches/plugins/patch-depd-deprecations.spec.js +0 -29
- package/dist/cli/build/patches/plugins/res-revalidate.spec.d.ts +0 -1
- package/dist/cli/build/patches/plugins/res-revalidate.spec.js +0 -141
- package/dist/cli/build/patches/plugins/use-cache.spec.d.ts +0 -1
- package/dist/cli/build/patches/plugins/use-cache.spec.js +0 -156
- package/dist/cli/build/utils/apply-patches.d.ts +0 -12
- package/dist/cli/build/utils/apply-patches.js +0 -22
- package/dist/cli/build/utils/extract-project-env-vars.spec.d.ts +0 -1
- package/dist/cli/build/utils/extract-project-env-vars.spec.js +0 -67
- package/dist/cli/build/utils/workerd.spec.d.ts +0 -1
- package/dist/cli/build/utils/workerd.spec.js +0 -188
- package/dist/cli/commands/populate-cache.spec.d.ts +0 -1
- package/dist/cli/commands/populate-cache.spec.js +0 -61
- /package/dist/cli/build/{patches/investigated → utils}/copy-package-cli-files.d.ts +0 -0
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import { patchCode } from "@opennextjs/aws/build/patch/astCodePatcher.js";
|
|
2
|
-
import { describe, expect, test } from "vitest";
|
|
3
|
-
import { buildMultipleChunksRule, singleChunkRule } from "./webpack-runtime.js";
|
|
4
|
-
describe("webpack runtime", () => {
|
|
5
|
-
describe("multiple chunks", () => {
|
|
6
|
-
test("patch runtime", () => {
|
|
7
|
-
const code = `
|
|
8
|
-
/******/ // require() chunk loading for javascript
|
|
9
|
-
/******/ __webpack_require__.f.require = (chunkId, promises) => {
|
|
10
|
-
/******/ // "1" is the signal for "already loaded"
|
|
11
|
-
/******/ if (!installedChunks[chunkId]) {
|
|
12
|
-
/******/ if (658 != chunkId) {
|
|
13
|
-
/******/ installChunk(require("./chunks/" + __webpack_require__.u(chunkId)));
|
|
14
|
-
/******/
|
|
15
|
-
} else installedChunks[chunkId] = 1;
|
|
16
|
-
/******/
|
|
17
|
-
}
|
|
18
|
-
/******/
|
|
19
|
-
};
|
|
20
|
-
`;
|
|
21
|
-
expect(patchCode(code, buildMultipleChunksRule([1, 2, 3]))).toMatchInlineSnapshot(`
|
|
22
|
-
"/******/ // require() chunk loading for javascript
|
|
23
|
-
/******/ __webpack_require__.f.require = (chunkId, _) => {
|
|
24
|
-
if (!installedChunks[chunkId]) {
|
|
25
|
-
switch (chunkId) {
|
|
26
|
-
case 1: installChunk(require("./chunks/1.js")); break;
|
|
27
|
-
case 2: installChunk(require("./chunks/2.js")); break;
|
|
28
|
-
case 3: installChunk(require("./chunks/3.js")); break;
|
|
29
|
-
case 658: installedChunks[chunkId] = 1; break;
|
|
30
|
-
default: throw new Error(\`Unknown chunk \${chunkId}\`);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
;
|
|
35
|
-
"
|
|
36
|
-
`);
|
|
37
|
-
});
|
|
38
|
-
test("patch minified runtime", () => {
|
|
39
|
-
const code = `
|
|
40
|
-
t.f.require=(o,n)=>{e[o]||(658!=o?r(require("./chunks/"+t.u(o))):e[o]=1)}
|
|
41
|
-
`;
|
|
42
|
-
expect(patchCode(code, buildMultipleChunksRule([1, 2, 3]))).toMatchInlineSnapshot(`
|
|
43
|
-
"t.f.require=(o, _) => {
|
|
44
|
-
if (!e[o]) {
|
|
45
|
-
switch (o) {
|
|
46
|
-
case 1: r(require("./chunks/1.js")); break;
|
|
47
|
-
case 2: r(require("./chunks/2.js")); break;
|
|
48
|
-
case 3: r(require("./chunks/3.js")); break;
|
|
49
|
-
case 658: e[o] = 1; break;
|
|
50
|
-
default: throw new Error(\`Unknown chunk \${o}\`);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
"
|
|
56
|
-
`);
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
describe("single chunk", () => {
|
|
60
|
-
test("patch runtime", () => {
|
|
61
|
-
const code = `
|
|
62
|
-
/******/ // require() chunk loading for javascript
|
|
63
|
-
/******/ __webpack_require__.f.require = (chunkId, promises) => {
|
|
64
|
-
/******/ // "1" is the signal for "already loaded"
|
|
65
|
-
/******/ if(!installedChunks[chunkId]) {
|
|
66
|
-
/******/ if(710 == chunkId) {
|
|
67
|
-
/******/ installChunk(require("./chunks/" + __webpack_require__.u(chunkId)));
|
|
68
|
-
/******/ } else installedChunks[chunkId] = 1;
|
|
69
|
-
/******/ }
|
|
70
|
-
/******/ };
|
|
71
|
-
`;
|
|
72
|
-
expect(patchCode(code, singleChunkRule)).toMatchInlineSnapshot(`
|
|
73
|
-
"/******/ // require() chunk loading for javascript
|
|
74
|
-
/******/ __webpack_require__.f.require = (chunkId, _) => {
|
|
75
|
-
if (!installedChunks[chunkId]) {
|
|
76
|
-
try {
|
|
77
|
-
installChunk(require("./chunks/710.js"));
|
|
78
|
-
} catch {}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
;
|
|
82
|
-
"
|
|
83
|
-
`);
|
|
84
|
-
});
|
|
85
|
-
test("patch minified runtime", () => {
|
|
86
|
-
const code = `
|
|
87
|
-
o.f.require=(t,a)=>{e[t]||(710==t?r(require("./chunks/"+o.u(t))):e[t]=1)}
|
|
88
|
-
`;
|
|
89
|
-
expect(patchCode(code, singleChunkRule)).toMatchInlineSnapshot(`
|
|
90
|
-
"o.f.require=(t, _) => {
|
|
91
|
-
if (!e[t]) {
|
|
92
|
-
try {
|
|
93
|
-
r(require("./chunks/710.js"));
|
|
94
|
-
} catch {}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
"
|
|
99
|
-
`);
|
|
100
|
-
});
|
|
101
|
-
});
|
|
102
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./investigated/index.js";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./investigated/index.js";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import { patchCode } from "@opennextjs/aws/build/patch/astCodePatcher.js";
|
|
2
|
-
import { describe, expect, test } from "vitest";
|
|
3
|
-
import { getNext14Rule, getNext15Rule } from "./instrumentation.js";
|
|
4
|
-
describe("LoadInstrumentationModule (Next15)", () => {
|
|
5
|
-
const code = `
|
|
6
|
-
export default class NextNodeServer extends BaseServer {
|
|
7
|
-
protected async loadInstrumentationModule() {
|
|
8
|
-
if (!this.serverOptions.dev) {
|
|
9
|
-
try {
|
|
10
|
-
this.instrumentation = await dynamicRequire(
|
|
11
|
-
resolve(
|
|
12
|
-
this.serverOptions.dir || '.',
|
|
13
|
-
this.serverOptions.conf.distDir!,
|
|
14
|
-
'server',
|
|
15
|
-
INSTRUMENTATION_HOOK_FILENAME
|
|
16
|
-
)
|
|
17
|
-
)
|
|
18
|
-
} catch (err: any) {
|
|
19
|
-
if (err.code !== 'MODULE_NOT_FOUND') {
|
|
20
|
-
throw new Error(
|
|
21
|
-
'An error occurred while loading the instrumentation hook',
|
|
22
|
-
{ cause: err }
|
|
23
|
-
)
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
return this.instrumentation
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
`;
|
|
31
|
-
test("patch when an instrumentation file is not present", async () => {
|
|
32
|
-
expect(patchCode(code, getNext15Rule(null))).toMatchInlineSnapshot(`
|
|
33
|
-
"export default class NextNodeServer extends BaseServer {
|
|
34
|
-
async loadInstrumentationModule() { this.instrumentation = null; return this.instrumentation; }
|
|
35
|
-
}
|
|
36
|
-
"
|
|
37
|
-
`);
|
|
38
|
-
});
|
|
39
|
-
test("patch when an instrumentation file is present", async () => {
|
|
40
|
-
expect(patchCode(code, getNext15Rule("/_file_exists_/instrumentation.js"))).toMatchInlineSnapshot(`
|
|
41
|
-
"export default class NextNodeServer extends BaseServer {
|
|
42
|
-
async loadInstrumentationModule() { this.instrumentation = require('/_file_exists_/instrumentation.js'); return this.instrumentation; }
|
|
43
|
-
}
|
|
44
|
-
"
|
|
45
|
-
`);
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
describe("prepareImpl (Next14)", () => {
|
|
49
|
-
const code = `
|
|
50
|
-
export default class NextNodeServer extends BaseServer {
|
|
51
|
-
async prepareImpl() {
|
|
52
|
-
await super.prepareImpl();
|
|
53
|
-
if (!this.serverOptions.dev && this.nextConfig.experimental.instrumentationHook) {
|
|
54
|
-
try {
|
|
55
|
-
const instrumentationHook = await dynamicRequire((0, _path.resolve)(this.serverOptions.dir || ".", this.serverOptions.conf.distDir, "server", _constants1.INSTRUMENTATION_HOOK_FILENAME));
|
|
56
|
-
await (instrumentationHook.register == null ? void 0 : instrumentationHook.register.call(instrumentationHook));
|
|
57
|
-
} catch (err2) {
|
|
58
|
-
if (err2.code !== "MODULE_NOT_FOUND") {
|
|
59
|
-
err2.message = \`An error occurred while loading instrumentation hook: \${err2.message}\`;
|
|
60
|
-
throw err2;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
`;
|
|
67
|
-
test("patch when an instrumentation file is not present", async () => {
|
|
68
|
-
expect(patchCode(code, getNext14Rule(null))).toMatchInlineSnapshot(`
|
|
69
|
-
"export default class NextNodeServer extends BaseServer {
|
|
70
|
-
async prepareImpl() {
|
|
71
|
-
await super.prepareImpl();
|
|
72
|
-
const instrumentationHook = {};
|
|
73
|
-
await (instrumentationHook.register == null ? void 0 : instrumentationHook.register.call(instrumentationHook));
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
"
|
|
77
|
-
`);
|
|
78
|
-
});
|
|
79
|
-
test("patch when an instrumentation file is present", async () => {
|
|
80
|
-
expect(patchCode(code, getNext14Rule("/_file_exists_/instrumentation.js"))).toMatchInlineSnapshot(`
|
|
81
|
-
"export default class NextNodeServer extends BaseServer {
|
|
82
|
-
async prepareImpl() {
|
|
83
|
-
await super.prepareImpl();
|
|
84
|
-
const instrumentationHook = require('/_file_exists_/instrumentation.js');
|
|
85
|
-
await (instrumentationHook.register == null ? void 0 : instrumentationHook.register.call(instrumentationHook));
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
"
|
|
89
|
-
`);
|
|
90
|
-
});
|
|
91
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,429 +0,0 @@
|
|
|
1
|
-
import { patchCode } from "@opennextjs/aws/build/patch/astCodePatcher.js";
|
|
2
|
-
import { describe, expect, test } from "vitest";
|
|
3
|
-
import { buildIdRule, createCacheHandlerRule, createComposableCacheHandlersRule, createMiddlewareManifestRule, } from "./next-server.js";
|
|
4
|
-
describe("Next Server", () => {
|
|
5
|
-
const nextServerCode = `
|
|
6
|
-
class NextNodeServer extends _baseserver.default {
|
|
7
|
-
constructor(options){
|
|
8
|
-
// Initialize super class
|
|
9
|
-
super(options);
|
|
10
|
-
this.handleNextImageRequest = async (req, res, parsedUrl) => { /* ... */ };
|
|
11
|
-
}
|
|
12
|
-
async handleUpgrade() {
|
|
13
|
-
// The web server does not support web sockets, it's only used for HMR in
|
|
14
|
-
// development.
|
|
15
|
-
}
|
|
16
|
-
loadEnvConfig({ dev, forceReload, silent }) {
|
|
17
|
-
(0, _env.loadEnvConfig)(this.dir, dev, silent ? {
|
|
18
|
-
info: ()=>{},
|
|
19
|
-
error: ()=>{}
|
|
20
|
-
} : _log, forceReload);
|
|
21
|
-
}
|
|
22
|
-
async hasPage(pathname) {
|
|
23
|
-
var _this_nextConfig_i18n;
|
|
24
|
-
return !!(0, _require.getMaybePagePath)(pathname, this.distDir, (_this_nextConfig_i18n = this.nextConfig.i18n) == null ? void 0 : _this_nextConfig_i18n.locales, this.enabledDirectories.app);
|
|
25
|
-
}
|
|
26
|
-
getBuildId() {
|
|
27
|
-
const buildIdFile = (0, _path.join)(this.distDir, _constants.BUILD_ID_FILE);
|
|
28
|
-
try {
|
|
29
|
-
return _fs.default.readFileSync(buildIdFile, "utf8").trim();
|
|
30
|
-
} catch (err) {
|
|
31
|
-
if (err.code === "ENOENT") {
|
|
32
|
-
throw new Error(\`Could not find a production build in the '\${this.distDir}' directory. Try building your app with 'next build' before starting the production server. https://nextjs.org/docs/messages/production-start-no-build-id\`);
|
|
33
|
-
}
|
|
34
|
-
throw err;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
getMiddlewareManifest() {
|
|
38
|
-
if (this.minimalMode) return null;
|
|
39
|
-
const manifest = require(this.middlewareManifestPath);
|
|
40
|
-
return manifest;
|
|
41
|
-
}
|
|
42
|
-
async loadCustomCacheHandlers() {
|
|
43
|
-
const { cacheHandlers } = this.nextConfig.experimental;
|
|
44
|
-
if (!cacheHandlers) return;
|
|
45
|
-
// If we've already initialized the cache handlers interface, don't do it
|
|
46
|
-
// again.
|
|
47
|
-
if (!(0, _handlers.initializeCacheHandlers)()) return;
|
|
48
|
-
for (const [kind, handler] of Object.entries(cacheHandlers)){
|
|
49
|
-
if (!handler) continue;
|
|
50
|
-
(0, _handlers.setCacheHandler)(kind, (0, _interopdefault.interopDefault)(await dynamicImportEsmDefault((0, _formatdynamicimportpath.formatDynamicImportPath)(this.distDir, handler))));
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
async getIncrementalCache({ requestHeaders, requestProtocol }) {
|
|
54
|
-
const dev = !!this.renderOpts.dev;
|
|
55
|
-
let CacheHandler;
|
|
56
|
-
const { cacheHandler } = this.nextConfig;
|
|
57
|
-
if (cacheHandler) {
|
|
58
|
-
CacheHandler = (0, _interopdefault.interopDefault)(await dynamicImportEsmDefault((0, _formatdynamicimportpath.formatDynamicImportPath)(this.distDir, cacheHandler)));
|
|
59
|
-
}
|
|
60
|
-
await this.loadCustomCacheHandlers();
|
|
61
|
-
// incremental-cache is request specific
|
|
62
|
-
// although can have shared caches in module scope
|
|
63
|
-
// per-cache handler
|
|
64
|
-
return new _incrementalcache.IncrementalCache({
|
|
65
|
-
fs: this.getCacheFilesystem(),
|
|
66
|
-
dev,
|
|
67
|
-
requestHeaders,
|
|
68
|
-
requestProtocol,
|
|
69
|
-
allowedRevalidateHeaderKeys: this.nextConfig.experimental.allowedRevalidateHeaderKeys,
|
|
70
|
-
minimalMode: this.minimalMode,
|
|
71
|
-
serverDistDir: this.serverDistDir,
|
|
72
|
-
fetchCacheKeyPrefix: this.nextConfig.experimental.fetchCacheKeyPrefix,
|
|
73
|
-
maxMemoryCacheSize: this.nextConfig.cacheMaxMemorySize,
|
|
74
|
-
flushToDisk: !this.minimalMode && this.nextConfig.experimental.isrFlushToDisk,
|
|
75
|
-
getPrerenderManifest: ()=>this.getPrerenderManifest(),
|
|
76
|
-
CurCacheHandler: CacheHandler
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
getEnabledDirectories(dev) {
|
|
80
|
-
const dir = dev ? this.dir : this.serverDistDir;
|
|
81
|
-
return {
|
|
82
|
-
app: (0, _findpagesdir.findDir)(dir, "app") ? true : false,
|
|
83
|
-
pages: (0, _findpagesdir.findDir)(dir, "pages") ? true : false
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
// ...
|
|
87
|
-
}`;
|
|
88
|
-
test("build ID", () => {
|
|
89
|
-
expect(patchCode(nextServerCode, buildIdRule)).toMatchInlineSnapshot(`
|
|
90
|
-
"class NextNodeServer extends _baseserver.default {
|
|
91
|
-
constructor(options){
|
|
92
|
-
// Initialize super class
|
|
93
|
-
super(options);
|
|
94
|
-
this.handleNextImageRequest = async (req, res, parsedUrl) => { /* ... */ };
|
|
95
|
-
}
|
|
96
|
-
async handleUpgrade() {
|
|
97
|
-
// The web server does not support web sockets, it's only used for HMR in
|
|
98
|
-
// development.
|
|
99
|
-
}
|
|
100
|
-
loadEnvConfig({ dev, forceReload, silent }) {
|
|
101
|
-
(0, _env.loadEnvConfig)(this.dir, dev, silent ? {
|
|
102
|
-
info: ()=>{},
|
|
103
|
-
error: ()=>{}
|
|
104
|
-
} : _log, forceReload);
|
|
105
|
-
}
|
|
106
|
-
async hasPage(pathname) {
|
|
107
|
-
var _this_nextConfig_i18n;
|
|
108
|
-
return !!(0, _require.getMaybePagePath)(pathname, this.distDir, (_this_nextConfig_i18n = this.nextConfig.i18n) == null ? void 0 : _this_nextConfig_i18n.locales, this.enabledDirectories.app);
|
|
109
|
-
}
|
|
110
|
-
getBuildId() {
|
|
111
|
-
return process.env.NEXT_BUILD_ID;
|
|
112
|
-
}
|
|
113
|
-
getMiddlewareManifest() {
|
|
114
|
-
if (this.minimalMode) return null;
|
|
115
|
-
const manifest = require(this.middlewareManifestPath);
|
|
116
|
-
return manifest;
|
|
117
|
-
}
|
|
118
|
-
async loadCustomCacheHandlers() {
|
|
119
|
-
const { cacheHandlers } = this.nextConfig.experimental;
|
|
120
|
-
if (!cacheHandlers) return;
|
|
121
|
-
// If we've already initialized the cache handlers interface, don't do it
|
|
122
|
-
// again.
|
|
123
|
-
if (!(0, _handlers.initializeCacheHandlers)()) return;
|
|
124
|
-
for (const [kind, handler] of Object.entries(cacheHandlers)){
|
|
125
|
-
if (!handler) continue;
|
|
126
|
-
(0, _handlers.setCacheHandler)(kind, (0, _interopdefault.interopDefault)(await dynamicImportEsmDefault((0, _formatdynamicimportpath.formatDynamicImportPath)(this.distDir, handler))));
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
async getIncrementalCache({ requestHeaders, requestProtocol }) {
|
|
130
|
-
const dev = !!this.renderOpts.dev;
|
|
131
|
-
let CacheHandler;
|
|
132
|
-
const { cacheHandler } = this.nextConfig;
|
|
133
|
-
if (cacheHandler) {
|
|
134
|
-
CacheHandler = (0, _interopdefault.interopDefault)(await dynamicImportEsmDefault((0, _formatdynamicimportpath.formatDynamicImportPath)(this.distDir, cacheHandler)));
|
|
135
|
-
}
|
|
136
|
-
await this.loadCustomCacheHandlers();
|
|
137
|
-
// incremental-cache is request specific
|
|
138
|
-
// although can have shared caches in module scope
|
|
139
|
-
// per-cache handler
|
|
140
|
-
return new _incrementalcache.IncrementalCache({
|
|
141
|
-
fs: this.getCacheFilesystem(),
|
|
142
|
-
dev,
|
|
143
|
-
requestHeaders,
|
|
144
|
-
requestProtocol,
|
|
145
|
-
allowedRevalidateHeaderKeys: this.nextConfig.experimental.allowedRevalidateHeaderKeys,
|
|
146
|
-
minimalMode: this.minimalMode,
|
|
147
|
-
serverDistDir: this.serverDistDir,
|
|
148
|
-
fetchCacheKeyPrefix: this.nextConfig.experimental.fetchCacheKeyPrefix,
|
|
149
|
-
maxMemoryCacheSize: this.nextConfig.cacheMaxMemorySize,
|
|
150
|
-
flushToDisk: !this.minimalMode && this.nextConfig.experimental.isrFlushToDisk,
|
|
151
|
-
getPrerenderManifest: ()=>this.getPrerenderManifest(),
|
|
152
|
-
CurCacheHandler: CacheHandler
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
getEnabledDirectories(dev) {
|
|
156
|
-
const dir = dev ? this.dir : this.serverDistDir;
|
|
157
|
-
return {
|
|
158
|
-
app: (0, _findpagesdir.findDir)(dir, "app") ? true : false,
|
|
159
|
-
pages: (0, _findpagesdir.findDir)(dir, "pages") ? true : false
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
|
-
// ...
|
|
163
|
-
}"
|
|
164
|
-
`);
|
|
165
|
-
});
|
|
166
|
-
test("middleware manifest", () => {
|
|
167
|
-
expect(patchCode(nextServerCode, createMiddlewareManifestRule("manifest"))).toMatchInlineSnapshot(`
|
|
168
|
-
"class NextNodeServer extends _baseserver.default {
|
|
169
|
-
constructor(options){
|
|
170
|
-
// Initialize super class
|
|
171
|
-
super(options);
|
|
172
|
-
this.handleNextImageRequest = async (req, res, parsedUrl) => { /* ... */ };
|
|
173
|
-
}
|
|
174
|
-
async handleUpgrade() {
|
|
175
|
-
// The web server does not support web sockets, it's only used for HMR in
|
|
176
|
-
// development.
|
|
177
|
-
}
|
|
178
|
-
loadEnvConfig({ dev, forceReload, silent }) {
|
|
179
|
-
(0, _env.loadEnvConfig)(this.dir, dev, silent ? {
|
|
180
|
-
info: ()=>{},
|
|
181
|
-
error: ()=>{}
|
|
182
|
-
} : _log, forceReload);
|
|
183
|
-
}
|
|
184
|
-
async hasPage(pathname) {
|
|
185
|
-
var _this_nextConfig_i18n;
|
|
186
|
-
return !!(0, _require.getMaybePagePath)(pathname, this.distDir, (_this_nextConfig_i18n = this.nextConfig.i18n) == null ? void 0 : _this_nextConfig_i18n.locales, this.enabledDirectories.app);
|
|
187
|
-
}
|
|
188
|
-
getBuildId() {
|
|
189
|
-
const buildIdFile = (0, _path.join)(this.distDir, _constants.BUILD_ID_FILE);
|
|
190
|
-
try {
|
|
191
|
-
return _fs.default.readFileSync(buildIdFile, "utf8").trim();
|
|
192
|
-
} catch (err) {
|
|
193
|
-
if (err.code === "ENOENT") {
|
|
194
|
-
throw new Error(\`Could not find a production build in the '\${this.distDir}' directory. Try building your app with 'next build' before starting the production server. https://nextjs.org/docs/messages/production-start-no-build-id\`);
|
|
195
|
-
}
|
|
196
|
-
throw err;
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
getMiddlewareManifest() {
|
|
200
|
-
return "manifest";
|
|
201
|
-
}
|
|
202
|
-
async loadCustomCacheHandlers() {
|
|
203
|
-
const { cacheHandlers } = this.nextConfig.experimental;
|
|
204
|
-
if (!cacheHandlers) return;
|
|
205
|
-
// If we've already initialized the cache handlers interface, don't do it
|
|
206
|
-
// again.
|
|
207
|
-
if (!(0, _handlers.initializeCacheHandlers)()) return;
|
|
208
|
-
for (const [kind, handler] of Object.entries(cacheHandlers)){
|
|
209
|
-
if (!handler) continue;
|
|
210
|
-
(0, _handlers.setCacheHandler)(kind, (0, _interopdefault.interopDefault)(await dynamicImportEsmDefault((0, _formatdynamicimportpath.formatDynamicImportPath)(this.distDir, handler))));
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
async getIncrementalCache({ requestHeaders, requestProtocol }) {
|
|
214
|
-
const dev = !!this.renderOpts.dev;
|
|
215
|
-
let CacheHandler;
|
|
216
|
-
const { cacheHandler } = this.nextConfig;
|
|
217
|
-
if (cacheHandler) {
|
|
218
|
-
CacheHandler = (0, _interopdefault.interopDefault)(await dynamicImportEsmDefault((0, _formatdynamicimportpath.formatDynamicImportPath)(this.distDir, cacheHandler)));
|
|
219
|
-
}
|
|
220
|
-
await this.loadCustomCacheHandlers();
|
|
221
|
-
// incremental-cache is request specific
|
|
222
|
-
// although can have shared caches in module scope
|
|
223
|
-
// per-cache handler
|
|
224
|
-
return new _incrementalcache.IncrementalCache({
|
|
225
|
-
fs: this.getCacheFilesystem(),
|
|
226
|
-
dev,
|
|
227
|
-
requestHeaders,
|
|
228
|
-
requestProtocol,
|
|
229
|
-
allowedRevalidateHeaderKeys: this.nextConfig.experimental.allowedRevalidateHeaderKeys,
|
|
230
|
-
minimalMode: this.minimalMode,
|
|
231
|
-
serverDistDir: this.serverDistDir,
|
|
232
|
-
fetchCacheKeyPrefix: this.nextConfig.experimental.fetchCacheKeyPrefix,
|
|
233
|
-
maxMemoryCacheSize: this.nextConfig.cacheMaxMemorySize,
|
|
234
|
-
flushToDisk: !this.minimalMode && this.nextConfig.experimental.isrFlushToDisk,
|
|
235
|
-
getPrerenderManifest: ()=>this.getPrerenderManifest(),
|
|
236
|
-
CurCacheHandler: CacheHandler
|
|
237
|
-
});
|
|
238
|
-
}
|
|
239
|
-
getEnabledDirectories(dev) {
|
|
240
|
-
const dir = dev ? this.dir : this.serverDistDir;
|
|
241
|
-
return {
|
|
242
|
-
app: (0, _findpagesdir.findDir)(dir, "app") ? true : false,
|
|
243
|
-
pages: (0, _findpagesdir.findDir)(dir, "pages") ? true : false
|
|
244
|
-
};
|
|
245
|
-
}
|
|
246
|
-
// ...
|
|
247
|
-
}"
|
|
248
|
-
`);
|
|
249
|
-
});
|
|
250
|
-
test("cache handler", () => {
|
|
251
|
-
expect(patchCode(nextServerCode, createCacheHandlerRule("manifest"))).toMatchInlineSnapshot(`
|
|
252
|
-
"class NextNodeServer extends _baseserver.default {
|
|
253
|
-
constructor(options){
|
|
254
|
-
// Initialize super class
|
|
255
|
-
super(options);
|
|
256
|
-
this.handleNextImageRequest = async (req, res, parsedUrl) => { /* ... */ };
|
|
257
|
-
}
|
|
258
|
-
async handleUpgrade() {
|
|
259
|
-
// The web server does not support web sockets, it's only used for HMR in
|
|
260
|
-
// development.
|
|
261
|
-
}
|
|
262
|
-
loadEnvConfig({ dev, forceReload, silent }) {
|
|
263
|
-
(0, _env.loadEnvConfig)(this.dir, dev, silent ? {
|
|
264
|
-
info: ()=>{},
|
|
265
|
-
error: ()=>{}
|
|
266
|
-
} : _log, forceReload);
|
|
267
|
-
}
|
|
268
|
-
async hasPage(pathname) {
|
|
269
|
-
var _this_nextConfig_i18n;
|
|
270
|
-
return !!(0, _require.getMaybePagePath)(pathname, this.distDir, (_this_nextConfig_i18n = this.nextConfig.i18n) == null ? void 0 : _this_nextConfig_i18n.locales, this.enabledDirectories.app);
|
|
271
|
-
}
|
|
272
|
-
getBuildId() {
|
|
273
|
-
const buildIdFile = (0, _path.join)(this.distDir, _constants.BUILD_ID_FILE);
|
|
274
|
-
try {
|
|
275
|
-
return _fs.default.readFileSync(buildIdFile, "utf8").trim();
|
|
276
|
-
} catch (err) {
|
|
277
|
-
if (err.code === "ENOENT") {
|
|
278
|
-
throw new Error(\`Could not find a production build in the '\${this.distDir}' directory. Try building your app with 'next build' before starting the production server. https://nextjs.org/docs/messages/production-start-no-build-id\`);
|
|
279
|
-
}
|
|
280
|
-
throw err;
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
getMiddlewareManifest() {
|
|
284
|
-
if (this.minimalMode) return null;
|
|
285
|
-
const manifest = require(this.middlewareManifestPath);
|
|
286
|
-
return manifest;
|
|
287
|
-
}
|
|
288
|
-
async loadCustomCacheHandlers() {
|
|
289
|
-
const { cacheHandlers } = this.nextConfig.experimental;
|
|
290
|
-
if (!cacheHandlers) return;
|
|
291
|
-
// If we've already initialized the cache handlers interface, don't do it
|
|
292
|
-
// again.
|
|
293
|
-
if (!(0, _handlers.initializeCacheHandlers)()) return;
|
|
294
|
-
for (const [kind, handler] of Object.entries(cacheHandlers)){
|
|
295
|
-
if (!handler) continue;
|
|
296
|
-
(0, _handlers.setCacheHandler)(kind, (0, _interopdefault.interopDefault)(await dynamicImportEsmDefault((0, _formatdynamicimportpath.formatDynamicImportPath)(this.distDir, handler))));
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
async getIncrementalCache({ requestHeaders, requestProtocol }) {
|
|
300
|
-
const dev = !!this.renderOpts.dev;
|
|
301
|
-
let CacheHandler;
|
|
302
|
-
const cacheHandler = null;
|
|
303
|
-
CacheHandler = require('manifest').default;
|
|
304
|
-
if (cacheHandler) {
|
|
305
|
-
CacheHandler = (0, _interopdefault.interopDefault)(await dynamicImportEsmDefault((0, _formatdynamicimportpath.formatDynamicImportPath)(this.distDir, cacheHandler)));
|
|
306
|
-
}
|
|
307
|
-
await this.loadCustomCacheHandlers();
|
|
308
|
-
// incremental-cache is request specific
|
|
309
|
-
// although can have shared caches in module scope
|
|
310
|
-
// per-cache handler
|
|
311
|
-
return new _incrementalcache.IncrementalCache({
|
|
312
|
-
fs: this.getCacheFilesystem(),
|
|
313
|
-
dev,
|
|
314
|
-
requestHeaders,
|
|
315
|
-
requestProtocol,
|
|
316
|
-
allowedRevalidateHeaderKeys: this.nextConfig.experimental.allowedRevalidateHeaderKeys,
|
|
317
|
-
minimalMode: this.minimalMode,
|
|
318
|
-
serverDistDir: this.serverDistDir,
|
|
319
|
-
fetchCacheKeyPrefix: this.nextConfig.experimental.fetchCacheKeyPrefix,
|
|
320
|
-
maxMemoryCacheSize: this.nextConfig.cacheMaxMemorySize,
|
|
321
|
-
flushToDisk: !this.minimalMode && this.nextConfig.experimental.isrFlushToDisk,
|
|
322
|
-
getPrerenderManifest: ()=>this.getPrerenderManifest(),
|
|
323
|
-
CurCacheHandler: CacheHandler
|
|
324
|
-
});
|
|
325
|
-
}
|
|
326
|
-
getEnabledDirectories(dev) {
|
|
327
|
-
const dir = dev ? this.dir : this.serverDistDir;
|
|
328
|
-
return {
|
|
329
|
-
app: (0, _findpagesdir.findDir)(dir, "app") ? true : false,
|
|
330
|
-
pages: (0, _findpagesdir.findDir)(dir, "pages") ? true : false
|
|
331
|
-
};
|
|
332
|
-
}
|
|
333
|
-
// ...
|
|
334
|
-
}"
|
|
335
|
-
`);
|
|
336
|
-
});
|
|
337
|
-
test("composable cache handler", () => {
|
|
338
|
-
expect(patchCode(nextServerCode, createComposableCacheHandlersRule("manifest"))).toMatchInlineSnapshot(`
|
|
339
|
-
"class NextNodeServer extends _baseserver.default {
|
|
340
|
-
constructor(options){
|
|
341
|
-
// Initialize super class
|
|
342
|
-
super(options);
|
|
343
|
-
this.handleNextImageRequest = async (req, res, parsedUrl) => { /* ... */ };
|
|
344
|
-
}
|
|
345
|
-
async handleUpgrade() {
|
|
346
|
-
// The web server does not support web sockets, it's only used for HMR in
|
|
347
|
-
// development.
|
|
348
|
-
}
|
|
349
|
-
loadEnvConfig({ dev, forceReload, silent }) {
|
|
350
|
-
(0, _env.loadEnvConfig)(this.dir, dev, silent ? {
|
|
351
|
-
info: ()=>{},
|
|
352
|
-
error: ()=>{}
|
|
353
|
-
} : _log, forceReload);
|
|
354
|
-
}
|
|
355
|
-
async hasPage(pathname) {
|
|
356
|
-
var _this_nextConfig_i18n;
|
|
357
|
-
return !!(0, _require.getMaybePagePath)(pathname, this.distDir, (_this_nextConfig_i18n = this.nextConfig.i18n) == null ? void 0 : _this_nextConfig_i18n.locales, this.enabledDirectories.app);
|
|
358
|
-
}
|
|
359
|
-
getBuildId() {
|
|
360
|
-
const buildIdFile = (0, _path.join)(this.distDir, _constants.BUILD_ID_FILE);
|
|
361
|
-
try {
|
|
362
|
-
return _fs.default.readFileSync(buildIdFile, "utf8").trim();
|
|
363
|
-
} catch (err) {
|
|
364
|
-
if (err.code === "ENOENT") {
|
|
365
|
-
throw new Error(\`Could not find a production build in the '\${this.distDir}' directory. Try building your app with 'next build' before starting the production server. https://nextjs.org/docs/messages/production-start-no-build-id\`);
|
|
366
|
-
}
|
|
367
|
-
throw err;
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
getMiddlewareManifest() {
|
|
371
|
-
if (this.minimalMode) return null;
|
|
372
|
-
const manifest = require(this.middlewareManifestPath);
|
|
373
|
-
return manifest;
|
|
374
|
-
}
|
|
375
|
-
async loadCustomCacheHandlers() {
|
|
376
|
-
const cacheHandlers = null;
|
|
377
|
-
const handlersSymbol = Symbol.for('@next/cache-handlers');
|
|
378
|
-
const handlersMapSymbol = Symbol.for('@next/cache-handlers-map');
|
|
379
|
-
const handlersSetSymbol = Symbol.for('@next/cache-handlers-set');
|
|
380
|
-
globalThis[handlersMapSymbol] = new Map();
|
|
381
|
-
globalThis[handlersMapSymbol].set("default", require('manifest').default);
|
|
382
|
-
globalThis[handlersSetSymbol] = new Set(globalThis[handlersMapSymbol].values());
|
|
383
|
-
if (!cacheHandlers) return;
|
|
384
|
-
// If we've already initialized the cache handlers interface, don't do it
|
|
385
|
-
// again.
|
|
386
|
-
if (!(0, _handlers.initializeCacheHandlers)()) return;
|
|
387
|
-
for (const [kind, handler] of Object.entries(cacheHandlers)){
|
|
388
|
-
if (!handler) continue;
|
|
389
|
-
(0, _handlers.setCacheHandler)(kind, (0, _interopdefault.interopDefault)(await dynamicImportEsmDefault((0, _formatdynamicimportpath.formatDynamicImportPath)(this.distDir, handler))));
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
async getIncrementalCache({ requestHeaders, requestProtocol }) {
|
|
393
|
-
const dev = !!this.renderOpts.dev;
|
|
394
|
-
let CacheHandler;
|
|
395
|
-
const { cacheHandler } = this.nextConfig;
|
|
396
|
-
if (cacheHandler) {
|
|
397
|
-
CacheHandler = (0, _interopdefault.interopDefault)(await dynamicImportEsmDefault((0, _formatdynamicimportpath.formatDynamicImportPath)(this.distDir, cacheHandler)));
|
|
398
|
-
}
|
|
399
|
-
await this.loadCustomCacheHandlers();
|
|
400
|
-
// incremental-cache is request specific
|
|
401
|
-
// although can have shared caches in module scope
|
|
402
|
-
// per-cache handler
|
|
403
|
-
return new _incrementalcache.IncrementalCache({
|
|
404
|
-
fs: this.getCacheFilesystem(),
|
|
405
|
-
dev,
|
|
406
|
-
requestHeaders,
|
|
407
|
-
requestProtocol,
|
|
408
|
-
allowedRevalidateHeaderKeys: this.nextConfig.experimental.allowedRevalidateHeaderKeys,
|
|
409
|
-
minimalMode: this.minimalMode,
|
|
410
|
-
serverDistDir: this.serverDistDir,
|
|
411
|
-
fetchCacheKeyPrefix: this.nextConfig.experimental.fetchCacheKeyPrefix,
|
|
412
|
-
maxMemoryCacheSize: this.nextConfig.cacheMaxMemorySize,
|
|
413
|
-
flushToDisk: !this.minimalMode && this.nextConfig.experimental.isrFlushToDisk,
|
|
414
|
-
getPrerenderManifest: ()=>this.getPrerenderManifest(),
|
|
415
|
-
CurCacheHandler: CacheHandler
|
|
416
|
-
});
|
|
417
|
-
}
|
|
418
|
-
getEnabledDirectories(dev) {
|
|
419
|
-
const dir = dev ? this.dir : this.serverDistDir;
|
|
420
|
-
return {
|
|
421
|
-
app: (0, _findpagesdir.findDir)(dir, "app") ? true : false,
|
|
422
|
-
pages: (0, _findpagesdir.findDir)(dir, "pages") ? true : false
|
|
423
|
-
};
|
|
424
|
-
}
|
|
425
|
-
// ...
|
|
426
|
-
}"
|
|
427
|
-
`);
|
|
428
|
-
});
|
|
429
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|