dinou 7.0.0 → 7.1.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.
@@ -168,8 +168,8 @@ async function buildStaticPages(onProgress = null) {
168
168
  let revalidate, getStaticPaths;
169
169
  if (pageFunctionsPath) {
170
170
  const module = await importModule(pageFunctionsPath);
171
- getStaticPaths = module.getStaticPaths;
172
- revalidate = module.revalidate;
171
+ getStaticPaths = module.getStaticPaths || module.default?.getStaticPaths;
172
+ revalidate = module.revalidate || module.default?.revalidate;
173
173
  }
174
174
  const isLocalPage =
175
175
  pagePath && path.dirname(pagePath) === dynamicPath;
@@ -313,8 +313,8 @@ async function buildStaticPages(onProgress = null) {
313
313
  let revalidate, getStaticPaths;
314
314
  if (pageFunctionsPath) {
315
315
  const module = await importModule(pageFunctionsPath);
316
- getStaticPaths = module.getStaticPaths;
317
- revalidate = module.revalidate;
316
+ getStaticPaths = module.getStaticPaths || module.default?.getStaticPaths;
317
+ revalidate = module.revalidate || module.default?.revalidate;
318
318
  }
319
319
  const isLocalPage =
320
320
  pagePath && path.dirname(pagePath) === dynamicPath;
@@ -421,8 +421,8 @@ async function buildStaticPages(onProgress = null) {
421
421
  let revalidate, getStaticPaths;
422
422
  if (pageFunctionsPath) {
423
423
  const module = await importModule(pageFunctionsPath);
424
- getStaticPaths = module.getStaticPaths;
425
- revalidate = module.revalidate;
424
+ getStaticPaths = module.getStaticPaths || module.default?.getStaticPaths;
425
+ revalidate = module.revalidate || module.default?.revalidate;
426
426
  }
427
427
  const isLocalPage =
428
428
  pagePath && path.dirname(pagePath) === dynamicPath;
@@ -548,8 +548,9 @@ async function buildStaticPages(onProgress = null) {
548
548
  let revalidate;
549
549
  if (pageFunctionsPath) {
550
550
  const module = await importModule(pageFunctionsPath);
551
- getStaticPaths = module.getStaticPaths;
552
- revalidate = module.revalidate;
551
+ const defMod = module.default?.default ? module.default.default : module.default;
552
+ getStaticPaths = module.getStaticPaths || defMod?.getStaticPaths;
553
+ revalidate = module.revalidate || defMod?.revalidate;
553
554
  }
554
555
  const { getLayoutFunctionsPath } = require("./layout-functions");
555
556
  const lfPath = getLayoutFunctionsPath(dynamicPath);
@@ -675,8 +676,9 @@ async function buildStaticPages(onProgress = null) {
675
676
  let getStaticPaths;
676
677
  if (pageFunctionsPath) {
677
678
  const module = await importModule(pageFunctionsPath);
678
- getStaticPaths = module.getStaticPaths;
679
- revalidate = module.revalidate;
679
+ const defMod = module.default?.default ? module.default.default : module.default;
680
+ getStaticPaths = module.getStaticPaths || defMod?.getStaticPaths;
681
+ revalidate = module.revalidate || defMod?.revalidate;
680
682
  }
681
683
  const isLocalPage =
682
684
  pagePath && path.dirname(pagePath) === dynamicPath;
@@ -786,7 +788,7 @@ async function buildStaticPages(onProgress = null) {
786
788
  if (pageFunctionsPath) {
787
789
  try {
788
790
  const module = await importModule(pageFunctionsPath);
789
- revalidate = module.revalidate;
791
+ revalidate = module.revalidate || module.default?.revalidate;
790
792
  } catch (e) {}
791
793
  }
792
794
 
@@ -950,9 +952,10 @@ async function buildStaticPages(onProgress = null) {
950
952
 
951
953
  if (pageFunctionsPath) {
952
954
  const pageFunctionsModule = await importModule(pageFunctionsPath);
953
- const getProps = pageFunctionsModule.getProps;
954
- revalidate = pageFunctionsModule.revalidate;
955
- const rawTags = pageFunctionsModule.getCacheTags ?? pageFunctionsModule.default?.getCacheTags;
955
+ const defMod = pageFunctionsModule.default?.default ? pageFunctionsModule.default.default : pageFunctionsModule.default;
956
+ const getProps = pageFunctionsModule.getProps || defMod?.getProps;
957
+ revalidate = pageFunctionsModule.revalidate || defMod?.revalidate;
958
+ const rawTags = pageFunctionsModule.getCacheTags ?? defMod?.getCacheTags;
956
959
  if (typeof rawTags === "function") {
957
960
  try {
958
961
  cacheTags = await rawTags(params);
@@ -1311,11 +1314,12 @@ async function buildStaticPage(reqPath, isDynamic = null) {
1311
1314
  let pageFunctionsProps;
1312
1315
  if (pageFunctionsPath) {
1313
1316
  const pageFunctionsModule = await importModule(pageFunctionsPath);
1314
- const getProps = pageFunctionsModule.getProps;
1315
- revalidate = pageFunctionsModule.revalidate;
1317
+ const defMod = pageFunctionsModule.default?.default ? pageFunctionsModule.default.default : pageFunctionsModule.default;
1318
+ const getProps = pageFunctionsModule.getProps || defMod?.getProps;
1319
+ revalidate = pageFunctionsModule.revalidate || defMod?.revalidate;
1316
1320
  if (isDynamic && (isDynamic.value = await isDynamicRoute(revalidate)))
1317
1321
  return;
1318
- const rawTags = pageFunctionsModule.getCacheTags ?? pageFunctionsModule.default?.getCacheTags;
1322
+ const rawTags = pageFunctionsModule.getCacheTags ?? defMod?.getCacheTags;
1319
1323
  if (typeof rawTags === "function") {
1320
1324
  try {
1321
1325
  cacheTags = await rawTags(dParams);
@@ -1509,5 +1513,6 @@ module.exports = {
1509
1513
  getStaticPaths,
1510
1514
  getStaticMetadata,
1511
1515
  getStaticLayouts,
1516
+ isDynamicRoute,
1512
1517
  };
1513
1518
 
@@ -128,7 +128,8 @@ async function getJSX(
128
128
  );
129
129
  if (pageFunctionsPath) {
130
130
  const pageFunctionsModule = await importModule(pageFunctionsPath);
131
- const getProps = pageFunctionsModule.getProps;
131
+ const defaultExport = pageFunctionsModule.default?.default ? pageFunctionsModule.default.default : pageFunctionsModule.default;
132
+ const getProps = pageFunctionsModule.getProps || defaultExport?.getProps;
132
133
  pageFunctionsProps = await getProps?.(dParams ?? {});
133
134
  props = { ...props, ...(pageFunctionsProps ?? {}) };
134
135
  }
@@ -164,7 +165,8 @@ async function getJSX(
164
165
  );
165
166
  if (pageFunctionsPath) {
166
167
  const pageFunctionsModule = await importModule(pageFunctionsPath);
167
- const getProps = pageFunctionsModule.getProps;
168
+ const defaultExport = pageFunctionsModule.default?.default ? pageFunctionsModule.default.default : pageFunctionsModule.default;
169
+ const getProps = pageFunctionsModule.getProps || defaultExport?.getProps;
168
170
  pageFunctionsProps = await getProps?.(dynamicParams);
169
171
  props = { ...props, ...(pageFunctionsProps ?? {}) };
170
172
  }
@@ -226,18 +226,20 @@ async function resolvePageFunctionsConfig(pagePath, reqSegments, queryObj, dynam
226
226
  const isPpr = await resolvePprForRoute(pagePath, pageFunctionsModule, reqSegments, queryObj);
227
227
 
228
228
  if (pageFunctionsModule) {
229
+ const defaultExport = pageFunctionsModule.default?.default ? pageFunctionsModule.default.default : pageFunctionsModule.default;
229
230
  const resolvedAllowISG =
230
231
  typeof pageFunctionsModule.allowISG === "function"
231
232
  ? await pageFunctionsModule.allowISG()
232
- : typeof pageFunctionsModule.default?.allowISG === "function"
233
- ? await pageFunctionsModule.default.allowISG()
234
- : (pageFunctionsModule.allowISG ?? pageFunctionsModule.default?.allowISG ?? true);
233
+ : typeof defaultExport?.allowISG === "function"
234
+ ? await defaultExport.allowISG()
235
+ : (pageFunctionsModule.allowISG ?? defaultExport?.allowISG ?? true);
235
236
 
237
+ const getStaticPathsFn = pageFunctionsModule.getStaticPaths || defaultExport?.getStaticPaths;
236
238
  let staticPathsSet = null;
237
- if (pageFunctionsModule.getStaticPaths) {
238
- const paths = await (typeof pageFunctionsModule.getStaticPaths === "function"
239
- ? pageFunctionsModule.getStaticPaths()
240
- : pageFunctionsModule.getStaticPaths);
239
+ if (getStaticPathsFn) {
240
+ const paths = await (typeof getStaticPathsFn === "function"
241
+ ? getStaticPathsFn()
242
+ : getStaticPathsFn);
241
243
  if (Array.isArray(paths)) {
242
244
  staticPathsSet = new Set(
243
245
  paths.map((pathObj) => {
@@ -253,12 +255,15 @@ async function resolvePageFunctionsConfig(pagePath, reqSegments, queryObj, dynam
253
255
  }
254
256
  }
255
257
 
256
- let revalidateVal = typeof pageFunctionsModule.revalidate === "function"
257
- ? await pageFunctionsModule.revalidate()
258
- : pageFunctionsModule.revalidate;
258
+ let revalidateVal =
259
+ typeof pageFunctionsModule.revalidate === "function"
260
+ ? await pageFunctionsModule.revalidate()
261
+ : typeof defaultExport?.revalidate === "function"
262
+ ? await defaultExport.revalidate()
263
+ : (pageFunctionsModule.revalidate ?? defaultExport?.revalidate);
259
264
 
260
265
  const isDynamic = typeof revalidateVal === "number" && revalidateVal < 1;
261
- const rawTags = pageFunctionsModule.getCacheTags ?? pageFunctionsModule.default?.getCacheTags;
266
+ const rawTags = pageFunctionsModule.getCacheTags ?? defaultExport?.getCacheTags;
262
267
  let tagsVal = [];
263
268
  if (typeof rawTags === "function") {
264
269
  try {
@@ -273,7 +278,7 @@ async function resolvePageFunctionsConfig(pagePath, reqSegments, queryObj, dynam
273
278
  cachedConfig = {
274
279
  allowISG: resolvedAllowISG,
275
280
  staticPathsSet,
276
- validateParams: pageFunctionsModule.validateParams || null,
281
+ validateParams: pageFunctionsModule.validateParams || defaultExport?.validateParams || null,
277
282
  isDynamic,
278
283
  revalidate: revalidateVal,
279
284
  tags: tagsVal,
@@ -344,6 +349,7 @@ async function resolvePageFunctionsConfig(pagePath, reqSegments, queryObj, dynam
344
349
  revalidate: cachedConfig?.revalidate,
345
350
  tags: cachedConfig?.tags || [],
346
351
  ppr: Boolean(cachedConfig?.ppr),
352
+ staticPathsSet: cachedConfig?.staticPathsSet || null,
347
353
  };
348
354
  }
349
355
 
@@ -2291,6 +2297,7 @@ async function handleRequest(request, platformContext = {}) {
2291
2297
  module.exports = {
2292
2298
  handleRequest,
2293
2299
  WebResponseBridge,
2300
+ resolvePageFunctionsConfig,
2294
2301
  };
2295
2302
  module.exports.default = handleRequest;
2296
2303
 
@@ -51,9 +51,10 @@ async function getLayoutProps(layoutPath, dParams = {}) {
51
51
 
52
52
  try {
53
53
  const mod = await importModule(layoutFunctionsPath);
54
+ const defaultExport = mod.default?.default ? mod.default.default : mod.default;
54
55
  const getPropsFn =
55
56
  mod.getProps ||
56
- mod.default?.getProps ||
57
+ defaultExport?.getProps ||
57
58
  (typeof mod.default === "function" ? mod.default : null);
58
59
  if (typeof getPropsFn === "function") {
59
60
  const res = await getPropsFn(dParams);
@@ -106,14 +107,15 @@ async function resolveLayoutFunctionsConfig(layoutPath, dParams = {}) {
106
107
  }
107
108
  }
108
109
  }
110
+ const defaultExport = mod.default?.default ? mod.default.default : mod.default;
109
111
  const resolvedAllowISG =
110
112
  typeof mod.allowISG === "function"
111
113
  ? await mod.allowISG()
112
- : typeof mod.default?.allowISG === "function"
113
- ? await mod.default.allowISG()
114
- : (mod.allowISG ?? mod.default?.allowISG ?? true);
114
+ : typeof defaultExport?.allowISG === "function"
115
+ ? await defaultExport.allowISG()
116
+ : (mod.allowISG ?? defaultExport?.allowISG ?? true);
115
117
 
116
- const getStaticPathsFn = mod.getStaticPaths || mod.default?.getStaticPaths;
118
+ const getStaticPathsFn = mod.getStaticPaths || defaultExport?.getStaticPaths;
117
119
  let staticPathsSet = null;
118
120
  if (getStaticPathsFn) {
119
121
  const paths = await (typeof getStaticPathsFn === "function" ? getStaticPathsFn() : getStaticPathsFn);
@@ -133,13 +135,13 @@ async function resolveLayoutFunctionsConfig(layoutPath, dParams = {}) {
133
135
  const revalidateVal =
134
136
  typeof mod.revalidate === "function"
135
137
  ? await mod.revalidate()
136
- : typeof mod.default?.revalidate === "function"
137
- ? await mod.default.revalidate()
138
- : (mod.revalidate ?? mod.default?.revalidate);
138
+ : typeof defaultExport?.revalidate === "function"
139
+ ? await defaultExport.revalidate()
140
+ : (mod.revalidate ?? defaultExport?.revalidate);
139
141
 
140
142
  const isDynamic = typeof revalidateVal === "number" && revalidateVal < 1;
141
143
 
142
- const rawTags = mod.getCacheTags ?? mod.default?.getCacheTags;
144
+ const rawTags = mod.getCacheTags ?? defaultExport?.getCacheTags;
143
145
  let tagsVal = [];
144
146
  if (typeof rawTags === "function") {
145
147
  try {
@@ -151,10 +153,10 @@ async function resolveLayoutFunctionsConfig(layoutPath, dParams = {}) {
151
153
  tagsVal = rawTags;
152
154
  }
153
155
 
154
- const validateParamsFn = mod.validateParams || mod.default?.validateParams;
156
+ const validateParamsFn = mod.validateParams || defaultExport?.validateParams;
155
157
  const getPropsFn =
156
158
  mod.getProps ||
157
- mod.default?.getProps ||
159
+ defaultExport?.getProps ||
158
160
  (typeof mod.default === "function" ? mod.default : null);
159
161
 
160
162
  return {
@@ -153,6 +153,46 @@ function parsePprConfigWithBabel(code) {
153
153
  }
154
154
  }
155
155
  },
156
+ ExportDefaultDeclaration(p) {
157
+ function checkObject(objNode) {
158
+ if (!objNode || objNode.type !== "ObjectExpression") return;
159
+ for (const prop of objNode.properties || []) {
160
+ const key = prop.key?.name || prop.key?.value;
161
+ if (key === "ppr") {
162
+ const val = prop.value;
163
+ if (val?.type === "BooleanLiteral") pprValue = val.value;
164
+ else if (val?.type === "StringLiteral") pprValue = val.value !== "false";
165
+ else if (val?.type === "Identifier") pprValue = val.name === "true";
166
+ else if (val?.type === "ArrowFunctionExpression" || val?.type === "FunctionExpression") {
167
+ if (val.body?.type === "BooleanLiteral") pprValue = val.body.value;
168
+ else if (val.body?.type === "BlockStatement") {
169
+ for (const s of val.body.body || []) {
170
+ if (s.type === "ReturnStatement" && s.argument) {
171
+ if (s.argument.type === "BooleanLiteral") pprValue = s.argument.value;
172
+ else if (s.argument.type === "StringLiteral") pprValue = s.argument.value !== "false";
173
+ else if (s.argument.type === "Identifier") pprValue = s.argument.name === "true";
174
+ }
175
+ }
176
+ }
177
+ if (pprValue === null) pprValue = true;
178
+ } else {
179
+ pprValue = true;
180
+ }
181
+ }
182
+ }
183
+ }
184
+
185
+ const decl = p.node.declaration;
186
+ if (!decl) return;
187
+ if (decl.type === "ObjectExpression") {
188
+ checkObject(decl);
189
+ } else if (decl.type === "Identifier") {
190
+ const binding = p.scope?.getBinding(decl.name);
191
+ if (binding && binding.path?.node?.init?.type === "ObjectExpression") {
192
+ checkObject(binding.path.node.init);
193
+ }
194
+ }
195
+ },
156
196
  });
157
197
 
158
198
  return pprValue;
@@ -172,6 +212,11 @@ function parsePprConfigWithBabel(code) {
172
212
  const val = matchArrow[1] || matchArrow[2];
173
213
  return val === "true";
174
214
  }
215
+ const matchProp = code.match(/\bppr\s*:\s*(true|false|"[^"]*"|'[^']*')/);
216
+ if (matchProp) {
217
+ const val = matchProp[1].trim();
218
+ return val !== "false" && val !== '"false"' && val !== "'false'";
219
+ }
175
220
  return null;
176
221
  }
177
222
  }
@@ -229,7 +274,7 @@ function parsePprConfig(code) {
229
274
  }
230
275
  }
231
276
  }
232
- return null;
277
+ // If SWC didn't find named ppr, fall through to Babel for default export & scope analysis
233
278
  } catch (e) {
234
279
  // Fallback to Babel
235
280
  }
@@ -17,119 +17,6 @@ function isClientComponent(type) {
17
17
  );
18
18
  }
19
19
 
20
- function renderJSXToClientJSX(jsx, key = null) {
21
- if (
22
- typeof jsx === "string" ||
23
- typeof jsx === "number" ||
24
- typeof jsx === "boolean" ||
25
- typeof jsx === "function" ||
26
- typeof jsx === "undefined" ||
27
- jsx == null
28
- ) {
29
- return jsx;
30
- } else if (Array.isArray(jsx)) {
31
- return jsx.map((child) =>
32
- renderJSXToClientJSX(
33
- child,
34
- child?.key ?? null
35
- )
36
- );
37
- } else if (typeof jsx === "symbol") {
38
- if (jsx === Symbol.for("react.fragment")) {
39
- // Handle Fragment as an empty props object
40
- return {
41
- $$typeof: Symbol.for("react.transitional.element"),
42
- type: Symbol.for("react.fragment"),
43
- props: {},
44
- key: key,
45
- };
46
- }
47
- console.error("Unsupported symbol:", String(jsx));
48
- throw new Error(`Unsupported symbol: ${String(jsx)}`);
49
- } else if (typeof jsx === "object") {
50
- if (jsx.$$typeof === Symbol.for("react.transitional.element")) {
51
- if (
52
- jsx.type === Symbol.for("react.fragment") ||
53
- jsx.type === Symbol.for("react.suspense") ||
54
- jsx.type === Symbol.for("react.view_transition") ||
55
- typeof jsx.type === "string"
56
- ) {
57
- return {
58
- ...jsx,
59
- props: renderJSXToClientJSX(jsx.props),
60
- key: key ?? jsx.key,
61
- };
62
- } else if (typeof jsx.type === "function") {
63
- const Component = jsx.type;
64
- const props = jsx.props;
65
- if (isClientComponent(Component)) {
66
- return {
67
- ...jsx,
68
- $$typeof: Symbol.for("react.transitional.element"),
69
- type: Component,
70
- props: renderJSXToClientJSX(props),
71
- key: key ?? jsx.key,
72
- };
73
- } else {
74
- // Server component: execute and process
75
- const returnedJsx = Component(props);
76
- return renderJSXToClientJSX(returnedJsx, key ?? jsx.key);
77
- }
78
- } else if (
79
- typeof jsx.type === "object" &&
80
- jsx.type !== null &&
81
- jsx.type.$$typeof === Symbol.for("react.forward_ref")
82
- ) {
83
- if (isClientComponent(jsx.type)) {
84
- return {
85
- ...jsx,
86
- $$typeof: Symbol.for("react.transitional.element"),
87
- type: jsx.type,
88
- props: renderJSXToClientJSX(jsx.props),
89
- key: key ?? jsx.key,
90
- };
91
- } else {
92
- const returnedJsx = jsx.type.render(jsx.props, jsx.ref);
93
- return renderJSXToClientJSX(returnedJsx, key ?? jsx.key);
94
- }
95
- } else if (
96
- typeof jsx.type === "object" &&
97
- jsx.type !== null &&
98
- jsx.type.$$typeof === Symbol.for("react.memo")
99
- ) {
100
- if (isClientComponent(jsx.type)) {
101
- return {
102
- ...jsx,
103
- $$typeof: Symbol.for("react.transitional.element"),
104
- type: jsx.type,
105
- props: renderJSXToClientJSX(jsx.props),
106
- key: key ?? jsx.key,
107
- };
108
- } else {
109
- const innerComp = jsx.type.type;
110
- const returnedJsx = typeof innerComp === "function" ? innerComp(jsx.props) : null;
111
- return renderJSXToClientJSX(returnedJsx, key ?? jsx.key);
112
- }
113
- } else {
114
- console.error("Unsupported JSX type:", jsx.type);
115
- throw new Error("Unsupported JSX type");
116
- }
117
- } else if (jsx instanceof Promise) {
118
- return jsx;
119
- } else {
120
- // Process object props (e.g., { className: "foo" })
121
- return Object.fromEntries(
122
- Object.entries(jsx).map(([propName, value]) => [
123
- propName,
124
- renderJSXToClientJSX(value),
125
- ])
126
- );
127
- }
128
- } else {
129
- throw new Error("Not implemented");
130
- }
131
- }
132
-
133
20
  async function asyncRenderJSXToClientJSX(jsx, key = null) {
134
21
  if (
135
22
  typeof jsx === "string" ||
@@ -290,6 +177,5 @@ async function asyncRenderJSXToClientJSX(jsx, key = null) {
290
177
  }
291
178
 
292
179
  module.exports = {
293
- renderJSXToClientJSX,
294
180
  asyncRenderJSXToClientJSX,
295
181
  };
@@ -10,6 +10,8 @@ async function resolveModulePpr(mod) {
10
10
  ? mod.ppr
11
11
  : mod.default?.ppr !== undefined
12
12
  ? mod.default.ppr
13
+ : mod.default?.default?.ppr !== undefined
14
+ ? mod.default.default.ppr
13
15
  : undefined;
14
16
 
15
17
  if (raw === undefined || raw === null) return null;
@@ -1,9 +1,9 @@
1
- export function stripNamespace(p) {
2
- if (!p) return "";
3
- if (/^[a-zA-Z]:[/\\]/.test(p)) {
4
- return p;
5
- }
6
- return p.replace(/^[a-zA-Z0-9_-]+:/, "");
7
- }
8
-
9
- export default stripNamespace;
1
+ export function stripNamespace(p) {
2
+ if (!p) return "";
3
+ if (/^[a-zA-Z]:[/\\]/.test(p)) {
4
+ return p;
5
+ }
6
+ return p.replace(/^[a-zA-Z0-9_-]+:/, "");
7
+ }
8
+
9
+ export default stripNamespace;
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dinou-ejected",
3
- "version": "7.0.0",
3
+ "version": "7.1.0",
4
4
  "main": "index.js",
5
5
  "private": true,
6
6
  "exports": {