@wular/pnext 0.1.7 → 0.1.9

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.
Files changed (172) hide show
  1. package/dist/server/_chunks/{aliases-j47a10ce.js → aliases-fhv4dt06.js} +7 -5
  2. package/dist/server/_chunks/{analyze-arswqe6s.js → analyze-09kx9q6r.js} +17 -13
  3. package/dist/server/_chunks/{boot-af0mv3dy.js → boot-8aj7efqk.js} +13 -11
  4. package/dist/server/_chunks/{build-spy3dxp4.js → build-jda155c9.js} +7 -5
  5. package/dist/server/_chunks/{build-tier-m7yvqz61.js → build-tier-qrkpfsk1.js} +59 -75
  6. package/dist/server/_chunks/{build-t9h0hec3.js → build-wspv5h60.js} +1004 -1191
  7. package/dist/server/_chunks/{compile-53j02j27.js → compile-040r79gj.js} +2 -2
  8. package/dist/server/_chunks/{config-n2z7yxps.js → config-7h84p6q8.js} +6 -4
  9. package/dist/server/_chunks/{config-1yzwexq6.js → config-d4hqyygy.js} +12 -3
  10. package/dist/server/_chunks/{create-meec9hs6.js → create-skj8wzt5.js} +4 -3
  11. package/dist/server/_chunks/{dev-fjmqg6en.js → dev-pennd36n.js} +2 -2
  12. package/dist/server/_chunks/{generate-n9sh6hzt.js → generate-d8vb1d21.js} +5 -4
  13. package/dist/server/_chunks/{index-eeaanp2e.js → index-0qt2vapb.js} +3 -3
  14. package/dist/server/_chunks/{index-91x12ykq.js → index-0r5eqfc7.js} +6 -1
  15. package/dist/server/_chunks/{index-9ych9ma8.js → index-0wm2p3ks.js} +2 -2
  16. package/dist/server/_chunks/{index-357na4a8.js → index-141vcwk6.js} +1 -1
  17. package/dist/server/_chunks/{index-2dv4y4wd.js → index-1y0cesgn.js} +16 -10
  18. package/dist/server/_chunks/{index-ytjvpbm2.js → index-26gwrm07.js} +3 -3
  19. package/dist/server/_chunks/{index-8k7pfejn.js → index-3r6qpe8a.js} +7 -7
  20. package/dist/server/_chunks/{index-rn8dyr1f.js → index-42fef2rv.js} +8 -48
  21. package/dist/server/_chunks/{index-ncnes8c6.js → index-47gx7trn.js} +2 -2
  22. package/dist/server/_chunks/{index-20ppawv7.js → index-4qsce64w.js} +3 -3
  23. package/dist/server/_chunks/{index-1011cscr.js → index-4vf121ws.js} +61 -29
  24. package/dist/server/_chunks/{index-cf4rvxv6.js → index-52k54ykj.js} +1 -1
  25. package/dist/server/_chunks/{index-nyrba2kr.js → index-53fnn598.js} +11 -11
  26. package/dist/server/_chunks/{index-4hgjrqh7.js → index-6tb725m8.js} +2 -2
  27. package/dist/server/_chunks/{index-3xbr4eyv.js → index-912z4mfx.js} +3 -3
  28. package/dist/server/_chunks/{index-sjpckxqn.js → index-9f49w76j.js} +1 -1
  29. package/dist/server/_chunks/{index-jepjvcrf.js → index-aarf1brn.js} +1 -1
  30. package/dist/server/_chunks/{index-9n2914ww.js → index-akkrvjn6.js} +1 -1
  31. package/dist/server/_chunks/index-bzd2ef7t.js +10 -0
  32. package/dist/server/_chunks/{index-sv8m6789.js → index-cqcwwxfp.js} +5 -5
  33. package/dist/server/_chunks/{index-yz54pxrh.js → index-d1jsmhhk.js} +4 -9
  34. package/dist/server/_chunks/{index-vvmmknm1.js → index-da0fphj0.js} +19 -15
  35. package/dist/server/_chunks/{index-sctcgyvv.js → index-drwv61cc.js} +2 -2
  36. package/dist/server/_chunks/{index-z84ab1w0.js → index-e176wk6x.js} +3 -3
  37. package/dist/server/_chunks/{index-9hx2641q.js → index-entm8bmz.js} +1 -1
  38. package/dist/server/_chunks/index-fpghsgb4.js +352 -0
  39. package/dist/server/_chunks/{index-jx7bqvw1.js → index-hr63fvzn.js} +1 -1
  40. package/dist/server/_chunks/{index-eajaspjk.js → index-j0m1jxqa.js} +1 -1
  41. package/dist/server/_chunks/index-jbj7ehef.js +50 -0
  42. package/dist/server/_chunks/{index-egykcqg3.js → index-jexsy9a8.js} +1 -1
  43. package/dist/server/_chunks/{index-fkp000p1.js → index-jjppzw0s.js} +2 -2
  44. package/dist/server/_chunks/index-jt8e1pje.js +12 -0
  45. package/dist/server/_chunks/{index-ggk2j965.js → index-kpdph69z.js} +56 -50
  46. package/dist/server/_chunks/{index-6e4fqv30.js → index-m63czgq5.js} +2 -0
  47. package/dist/server/_chunks/{index-c0g2wf3z.js → index-md5jchzy.js} +1 -1
  48. package/dist/server/_chunks/{index-tvqkq6e6.js → index-n814hcky.js} +1 -1
  49. package/dist/server/_chunks/{index-06nyqntx.js → index-q3r9z8mq.js} +1 -1
  50. package/dist/server/_chunks/{index-4q2gbfwk.js → index-qjrh7w2g.js} +2 -2
  51. package/dist/server/_chunks/{index-3b3at80h.js → index-s61bx2aj.js} +6 -3
  52. package/dist/server/_chunks/{index-ym67zqxp.js → index-tf4j19ge.js} +1 -1
  53. package/dist/server/_chunks/{index-qn4z5s3c.js → index-typcbcsv.js} +3 -3
  54. package/dist/server/_chunks/{index-p77b4kcx.js → index-veycp46e.js} +1 -1
  55. package/dist/server/_chunks/{index-11sfk4hb.js → index-vmr35jjw.js} +1 -1
  56. package/dist/server/_chunks/{index-kq8kpzye.js → index-vqs3rebe.js} +3 -3
  57. package/dist/server/_chunks/{index-danncfhy.js → index-wm36rj4v.js} +1 -1
  58. package/dist/server/_chunks/{index-z4z9zv3b.js → index-x9c55pzy.js} +141 -3
  59. package/dist/server/_chunks/{index-y2jr2n72.js → index-xrsg0041.js} +4 -4
  60. package/dist/server/_chunks/{index-k1g3epw0.js → index-xs3411qh.js} +10 -10
  61. package/dist/server/_chunks/{index-0374j2b9.js → index-y4d02znn.js} +1 -1
  62. package/dist/server/_chunks/{index-wpfhfbs4.js → index-y71a76dn.js} +4 -4
  63. package/dist/server/_chunks/{index-qm6kmhqs.js → index-y7mzvq2q.js} +1 -1
  64. package/dist/server/_chunks/{index-hkdfj58q.js → index-y9bygr95.js} +1 -1
  65. package/dist/server/_chunks/{index-3tf1xjsp.js → index-yghskk8w.js} +11 -11
  66. package/dist/server/_chunks/{index-5gyr4emz.js → index-yzcpr3yw.js} +4 -4
  67. package/dist/server/_chunks/{index-x93hv0sc.js → index-zedjt25v.js} +23 -10
  68. package/dist/server/_chunks/{index-tq0pc7eg.js → index-zfrwq472.js} +3 -3
  69. package/dist/server/_chunks/{loader-7yw0j98z.js → loader-w1e0n5sm.js} +12 -10
  70. package/dist/server/_chunks/{modules-jn8bmbn8.js → modules-730j14cm.js} +14 -12
  71. package/dist/server/_chunks/{pipeline-yy9jhydf.js → pipeline-yjdnwbhm.js} +25 -21
  72. package/dist/server/_chunks/{production-jar9ztm3.js → production-1xe9b7wd.js} +14 -3
  73. package/dist/server/_chunks/{proxy-config-j84dgksn.js → proxy-config-9r9e0jvn.js} +7 -5
  74. package/dist/server/_chunks/{proxy-w1d0wmsn.js → proxy-pnevsbfd.js} +12 -10
  75. package/dist/server/_chunks/{router-k1reahfn.js → router-rzge0vz8.js} +10 -7
  76. package/dist/server/_chunks/{routes-2s277fc6.js → routes-0x8wjvcj.js} +12 -10
  77. package/dist/server/_chunks/{run-pvd8bs1t.js → run-tk90r3ac.js} +5 -4
  78. package/dist/server/_chunks/{server-mt4a994c.js → server-gev78ejc.js} +38 -34
  79. package/dist/server/_chunks/{tsconfig-defaults-1nb3308g.js → tsconfig-defaults-qe9wd6ne.js} +5 -4
  80. package/dist/server/_chunks/{typegen-0qr0459b.js → typegen-0yw8sry8.js} +15 -13
  81. package/dist/server/cli/index.js +12 -15
  82. package/dist/server/cli/start.js +35 -14
  83. package/dist/server/compat/next/cache.js +5 -5
  84. package/dist/server/compat/next/config-headers.js +8 -6
  85. package/dist/server/compat/next/config-loader.js +1 -1
  86. package/dist/server/compat/next/dist/server/web/spec-extension/revalidate.js +5 -5
  87. package/dist/server/compat/next/dist/server/web/spec-extension/unstable-cache.js +5 -5
  88. package/dist/server/compat/next/dist/server/web/spec-extension/unstable-no-store.js +5 -5
  89. package/dist/server/compat/next/dynamic.js +3 -14
  90. package/dist/server/compat/next/font/cache.js +6 -4
  91. package/dist/server/compat/next/font/local.js +7 -5
  92. package/dist/server/compat/next/font/runtime.js +7 -5
  93. package/dist/server/compat/next/headers.js +4 -4
  94. package/dist/server/compat/next/image/config.js +2 -2
  95. package/dist/server/compat/next/image/optimizer.js +3 -3
  96. package/dist/server/compat/next/image/static-metadata.js +4 -4
  97. package/dist/server/compat/next/legacy-request-apis.js +3 -3
  98. package/dist/server/compat/next/link-transform.js +4 -3
  99. package/dist/server/compat/next/navigation.js +5 -4
  100. package/dist/server/compat/next/redirects.js +8 -6
  101. package/dist/server/compat/next/resource-hints.js +2 -2
  102. package/dist/server/compat/next/rewrites.js +7 -5
  103. package/dist/server/compat/next/root-params.js +3 -3
  104. package/dist/server/compat/next/route-state.js +2 -2
  105. package/dist/server/compat/next/script.js +2 -2
  106. package/dist/server/compat/next/server.js +5 -5
  107. package/dist/server/generation.json +1 -1
  108. package/package.json +1 -1
  109. package/reference/compat.md +1 -1
  110. package/reference/config.md +2 -2
  111. package/reference/dev.md +1 -1
  112. package/reference/getting-started.md +1 -1
  113. package/reference/rendering.md +4 -4
  114. package/src/api/dynamic.tsx +84 -4
  115. package/src/cli/adapters/vercel-warm.ts +40 -29
  116. package/src/cli/adapters/vercel.ts +101 -1265
  117. package/src/cli/analyze.ts +3 -2
  118. package/src/cli/build/cache.ts +6 -6
  119. package/src/cli/build.ts +33 -33
  120. package/src/cli/index.ts +4 -6
  121. package/src/cli/serve/pipeline.ts +16 -10
  122. package/src/cli/serve/standalone-worker.ts +8 -0
  123. package/src/cli/serve/standalone.ts +727 -0
  124. package/src/cli/start.ts +29 -8
  125. package/src/client/build.ts +1 -1
  126. package/src/client/reference-stub.ts +2 -34
  127. package/src/compat/actions/extensions.ts +3 -2
  128. package/src/compat/bundler/require-context.ts +2 -1
  129. package/src/compat/bundler/webpack-loaders.ts +3 -2
  130. package/src/compat/bundler/worker.ts +2 -2
  131. package/src/compat/css/inline-css.ts +1 -1
  132. package/src/compat/export/build-complete.ts +1 -1
  133. package/src/compat/export/emit.ts +4 -4
  134. package/src/compat/export/standalone.ts +30 -65
  135. package/src/compat/image-optimizer/optimize.ts +1 -1
  136. package/src/compat/lifecycle/instrumentation-client.ts +4 -3
  137. package/src/compat/metadata-artifacts.ts +1 -1
  138. package/src/compat/next/config-loader.ts +3 -0
  139. package/src/compat/next/dynamic.tsx +10 -23
  140. package/src/compat/next/font/cache.ts +2 -1
  141. package/src/compat/next/font/runtime.ts +1 -1
  142. package/src/compat/register/image.ts +1 -1
  143. package/src/compat/typecheck/check.ts +6 -4
  144. package/src/config.ts +28 -5
  145. package/src/css/assets.ts +1 -1
  146. package/src/css/build.ts +16 -9
  147. package/src/dev/client-chunk-store.ts +2 -1
  148. package/src/dev/restart/client-key.ts +2 -1
  149. package/src/dev/restart/global-css.ts +2 -1
  150. package/src/dev/restart/route-bundle-key.ts +2 -1
  151. package/src/dev/restart/route-facts.ts +2 -1
  152. package/src/dev/server.ts +8 -7
  153. package/src/out-paths.ts +10 -0
  154. package/src/render/renderer.ts +1 -1
  155. package/src/resolve/dynamic.ts +4 -0
  156. package/src/resolve/engine.ts +2 -12
  157. package/src/resolve/scan-facts.ts +185 -1
  158. package/src/routing/metadata-files.ts +1 -1
  159. package/src/runtime/loader.ts +5 -3
  160. package/src/runtime/module-cache.ts +2 -1
  161. package/src/runtime/modules.ts +50 -16
  162. package/src/runtime/prebundle.ts +23 -3
  163. package/src/runtime/production.ts +105 -40
  164. package/src/runtime/release-graph.ts +21 -13
  165. package/src/runtime/vendor-build.ts +45 -23
  166. package/src/types.ts +2 -3
  167. package/src/utils/directive.ts +40 -0
  168. package/src/utils/fs.ts +7 -2
  169. package/src/utils/resource-query.ts +12 -0
  170. package/dist/server/_chunks/index-tqn2qnnn.js +0 -241
  171. package/dist/server/_chunks/index-y36a0ybw.js +0 -57
  172. package/src/cli/serve/entry.ts +0 -52
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Whether `source` opens with the `directive` prologue string. Linear and allocation-free: a regex
3
+ * over leading comments backtracks catastrophically on files with many comments and no directive.
4
+ */
5
+ export function hasModuleDirective(source: string, directive: string) {
6
+ const isSpace = (index: number) => {
7
+ const code = source.charCodeAt(index)
8
+ return code === 32 || (code >= 9 && code <= 13) || (code > 127 && /\s/.test(source[index]!))
9
+ }
10
+ let i = 0
11
+ for (;;) {
12
+ while (i < source.length && isSpace(i)) i += 1
13
+ if (source.startsWith('//', i)) {
14
+ const newline = source.indexOf('\n', i)
15
+ if (newline === -1) return false
16
+ i = newline + 1
17
+ continue
18
+ }
19
+ if (source.startsWith('/*', i)) {
20
+ const end = source.indexOf('*/', i + 2)
21
+ if (end === -1) return false
22
+ i = end + 2
23
+ continue
24
+ }
25
+ // Anything that is not a string literal ends the prologue.
26
+ const quote = source[i]
27
+ if (quote !== '"' && quote !== "'") return false
28
+ let end = i + 1
29
+ while (end < source.length) {
30
+ const char = source[end]!
31
+ if (char === quote || char === '\n' || char === '\\') break
32
+ end += 1
33
+ }
34
+ if (source[end] !== quote) return false
35
+ if (source.slice(i + 1, end) === directive) return true
36
+ i = end + 1
37
+ while (i < source.length && isSpace(i)) i += 1
38
+ if (source[i] === ';') i += 1
39
+ }
40
+ }
package/src/utils/fs.ts CHANGED
@@ -301,11 +301,16 @@ export function serializeBuildManifest(data: BuildManifest): string {
301
301
  return `${JSON.stringify(stored, null, 2)}\n`
302
302
  }
303
303
 
304
- export function resolveManifest(data: BuildManifest, outPath: string, root: string): BuildManifest {
304
+ export function resolveManifest(
305
+ data: BuildManifest,
306
+ outPath: string,
307
+ root: string,
308
+ framework = frameworkRoot,
309
+ ): BuildManifest {
305
310
  if (path.isAbsolute(data.root)) return data
306
311
  const absolute = (file: string) =>
307
312
  file.startsWith(frameworkPrefix)
308
- ? path.join(frameworkRoot, file.slice(frameworkPrefix.length))
313
+ ? path.join(framework, file.slice(frameworkPrefix.length))
309
314
  : path.join(root, file)
310
315
  return {
311
316
  ...mapSourcePaths(data, absolute),
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Split a webpack resource specifier into its file request and its `?query#fragment` suffix - loader
3
+ * plumbing (turbopack rules, `.wasm?module`) that takes no part in the on-disk lookup. A leading `#` is a
4
+ * package-imports specifier, not a fragment.
5
+ */
6
+ export function splitResourceQuery(specifier: string): { path: string; query: string } {
7
+ const offset = specifier.startsWith('#') ? 1 : 0
8
+ const match = /[?#]/.exec(specifier.slice(offset))
9
+ if (!match) return { path: specifier, query: '' }
10
+ const index = offset + match.index
11
+ return { path: specifier.slice(0, index), query: specifier.slice(index) }
12
+ }
@@ -1,241 +0,0 @@
1
- // @bun
2
- import { join as __pnextJoin } from "node:path";
3
- const __PNEXT_PACKAGE_ROOT__ = __pnextJoin(import.meta.dirname, "../../..");
4
- // src/runtime/production.ts
5
- import { existsSync, readFileSync, readdirSync } from "fs";
6
- import { mkdir, rename, rm, writeFile } from "fs/promises";
7
- import path from "path";
8
- import { pathToFileURL } from "url";
9
- var BUILD_INDEX_VERSION = 1;
10
- var LOCATOR_FILE = "release-locator.json";
11
- var releases = new WeakMap;
12
- var WORK_UNIT_STORAGE = Symbol.for("pnext.workUnitStorage");
13
- function buildIndexFile(outPath) {
14
- return path.join(outPath, "server", "build-index.json");
15
- }
16
- function releaseModuleKey(layer, target, file) {
17
- return `${layer}:${target}:${file}`;
18
- }
19
- function productionRelease(config) {
20
- return releases.get(config);
21
- }
22
- function servedRelease() {
23
- const units = globalThis[WORK_UNIT_STORAGE];
24
- return units?.getStore()?.release;
25
- }
26
- function servedConventions() {
27
- return servedRelease()?.conventions;
28
- }
29
- function frozenDirListing(dir) {
30
- const facts = servedConventions();
31
- if (!facts || !isInsideDir(facts.appPath, dir))
32
- return;
33
- return facts.dirs.get(dir) ?? { files: new Set, dirs: [] };
34
- }
35
- function conventionFileExists(file) {
36
- return frozenDirListing(path.dirname(file))?.files.has(path.basename(file)) ?? existsSync(file);
37
- }
38
- function releaseModuleHref(release, layer, target, file) {
39
- const href = release.modules.get(releaseModuleKey(layer, target, path.resolve(file)));
40
- if (!href) {
41
- throw new Error(`pnext: ${file} (${layer}, ${target}) is not in this build's release. Run 'pnext build' again.`);
42
- }
43
- return href;
44
- }
45
- function attachRelease(config, index = readBuildIndex(config.outPath)) {
46
- const existing = releases.get(config);
47
- if (existing)
48
- return existing;
49
- const fromRoot = (file) => path.resolve(config.root, file);
50
- const modules = new Map;
51
- for (const [key, artifact] of Object.entries(index.modules)) {
52
- const second = key.indexOf(":", key.indexOf(":") + 1);
53
- modules.set(`${key.slice(0, second + 1)}${releaseSourceFile(key.slice(second + 1), config.root, config.workspaceRoot)}`, pathToFileURL(path.resolve(config.outPath, artifact)).href);
54
- }
55
- const dirs = new Map;
56
- for (const [dir, names] of Object.entries(index.conventions)) {
57
- dirs.set(fromRoot(dir), {
58
- files: new Set(names.filter((name) => !name.endsWith("/"))),
59
- dirs: names.filter((name) => name.endsWith("/")).map((name) => name.slice(0, -1))
60
- });
61
- }
62
- const release = {
63
- modules,
64
- conventions: {
65
- appPath: config.appPath,
66
- dirs,
67
- client: new Set(index.clientConventions.map(fromRoot)),
68
- documentLayouts: new Set(index.documentLayouts.map(fromRoot))
69
- },
70
- globalCss: index.globalCss.map(fromRoot),
71
- proxy: index.proxy ? { ...index.proxy, file: fromRoot(index.proxy.file) } : {},
72
- ...index.compat ? { compat: index.compat } : {},
73
- ...index.instrumentation ? {
74
- instrumentation: {
75
- file: path.resolve(config.outPath, index.instrumentation.file),
76
- ...index.instrumentation.edge ? { edge: path.resolve(config.outPath, index.instrumentation.edge) } : {}
77
- }
78
- } : {},
79
- ...index.fonts ? {
80
- fonts: Object.fromEntries(Object.entries(index.fonts).map(([key, font]) => [
81
- key,
82
- { ...font, files: font.files.map((file) => path.resolve(config.outPath, file)) }
83
- ]))
84
- } : {}
85
- };
86
- releases.set(config, release);
87
- return release;
88
- }
89
- var conventionBases = new Set([
90
- "page",
91
- "route",
92
- "layout",
93
- "template",
94
- "loading",
95
- "error",
96
- "not-found",
97
- "default",
98
- "forbidden",
99
- "unauthorized",
100
- "global-error",
101
- "global-not-found"
102
- ]);
103
- var metadataBase = /^(?:robots|sitemap|manifest|favicon|(?:apple-)?icon\d*|opengraph-image\d*|twitter-image\d*)$/;
104
- var codeFile = /\.(?:[cm]?[jt]sx?|mdx?)$/;
105
- function capturedFile(name) {
106
- const base = /^[^.]+/.exec(name)?.[0] ?? name;
107
- return conventionBases.has(base) || metadataBase.test(base);
108
- }
109
- function servedAppFiles(facts) {
110
- return [...facts.dirs].flatMap(([dir, listing]) => [...listing.files].map((name) => path.join(dir, name)));
111
- }
112
- function captureConventions(root, appPath) {
113
- const conventions = {};
114
- const files = [];
115
- const visit = (dir) => {
116
- let entries;
117
- try {
118
- entries = readdirSync(dir, { withFileTypes: true });
119
- } catch {
120
- return;
121
- }
122
- const names = [];
123
- for (const entry of entries) {
124
- if (entry.isDirectory()) {
125
- if (entry.name === "node_modules" || entry.name.startsWith("."))
126
- continue;
127
- names.push(`${entry.name}/`);
128
- visit(path.join(dir, entry.name));
129
- } else if (capturedFile(entry.name)) {
130
- names.push(entry.name);
131
- if (codeFile.test(entry.name))
132
- files.push(path.join(dir, entry.name));
133
- }
134
- }
135
- conventions[toPosix(path.relative(root, dir)) || "."] = names.sort();
136
- };
137
- visit(appPath);
138
- return { conventions, files };
139
- }
140
- var frameworkRoot = path.resolve(__PNEXT_PACKAGE_ROOT__ + "/src/runtime", "..", "..");
141
- function releaseSourceKey(file, root, workspaceRoot) {
142
- const inRoot = path.relative(root, file);
143
- if (!inRoot.startsWith("..") && !path.isAbsolute(inRoot))
144
- return `r:${toPosix(inRoot)}`;
145
- const inWorkspace = path.relative(workspaceRoot, file);
146
- if (!inWorkspace.startsWith("..") && !path.isAbsolute(inWorkspace))
147
- return `w:${toPosix(inWorkspace)}`;
148
- const inFramework = path.relative(frameworkRoot, file);
149
- if (!inFramework.startsWith("..") && !path.isAbsolute(inFramework))
150
- return `f:${toPosix(inFramework)}`;
151
- return `r:${toPosix(inRoot)}`;
152
- }
153
- function releaseSourceFile(key, root, workspaceRoot) {
154
- const value = key.slice(2);
155
- if (key.startsWith("r:"))
156
- return path.join(root, value);
157
- if (key.startsWith("w:"))
158
- return path.resolve(workspaceRoot, value);
159
- if (key.startsWith("f:"))
160
- return path.resolve(frameworkRoot, value);
161
- return path.join(root, value);
162
- }
163
- function toPosix(file) {
164
- return file.split(path.sep).join("/");
165
- }
166
- function isInsideDir(root, file) {
167
- return file === root || file.startsWith(`${root}${path.sep}`);
168
- }
169
- function readBuildIndex(outPath) {
170
- const file = buildIndexFile(outPath);
171
- let index;
172
- try {
173
- index = JSON.parse(readFileSync(file, "utf8"));
174
- } catch (error) {
175
- if (error.code !== "ENOENT")
176
- throw error;
177
- throw new Error("No production build found. Run 'pnext build' first.");
178
- }
179
- if (index.version !== BUILD_INDEX_VERSION) {
180
- throw new Error(`pnext: ${file} is from another pnext version. Run 'pnext build' again.`);
181
- }
182
- return index;
183
- }
184
- function locateRelease(root, defaultOutDir) {
185
- const outPath = path.join(root, defaultOutDir);
186
- try {
187
- const { outDir } = JSON.parse(readFileSync(path.join(outPath, LOCATOR_FILE), "utf8"));
188
- return path.resolve(root, outDir);
189
- } catch {
190
- return existsSync(buildIndexFile(outPath)) ? outPath : undefined;
191
- }
192
- }
193
- function serializeReleaseConfig(config) {
194
- const relative = (file) => path.relative(config.root, file) || ".";
195
- return JSON.parse(JSON.stringify({
196
- ...config,
197
- root: ".",
198
- workspaceRoot: relative(config.workspaceRoot),
199
- appPath: relative(config.appPath),
200
- publicPath: relative(config.publicPath),
201
- outPath: relative(config.outPath),
202
- outRootPath: relative(config.outRootPath),
203
- typesPath: relative(config.typesPath),
204
- checksPath: relative(config.checksPath)
205
- }, (_key, value) => value instanceof RegExp ? { $regexp: [value.source, value.flags] } : value));
206
- }
207
- function releaseConfig(serialized, root, outPath) {
208
- const config = JSON.parse(JSON.stringify(serialized), (_key, value) => {
209
- const pattern = value?.$regexp;
210
- return pattern ? new RegExp(pattern[0], pattern[1]) : value;
211
- });
212
- const fromRoot = (file) => path.resolve(root, file);
213
- const fromOut = (file) => path.resolve(outPath, path.relative(config.outPath, file));
214
- return {
215
- ...config,
216
- root,
217
- workspaceRoot: fromRoot(config.workspaceRoot),
218
- appPath: fromRoot(config.appPath),
219
- publicPath: fromRoot(config.publicPath),
220
- outPath,
221
- outRootPath: fromOut(config.outRootPath),
222
- typesPath: fromOut(config.typesPath),
223
- checksPath: fromOut(config.checksPath)
224
- };
225
- }
226
- async function writeBuildIndex(config, index, defaultOutDir) {
227
- const file = buildIndexFile(config.outPath);
228
- const temporary = `${file}.${process.pid}.tmp`;
229
- await writeFile(temporary, JSON.stringify(index));
230
- await rename(temporary, file);
231
- const defaultOut = path.join(config.root, defaultOutDir);
232
- if (path.resolve(config.outPath) === path.resolve(defaultOut))
233
- return;
234
- await mkdir(defaultOut, { recursive: true });
235
- const locator = path.join(defaultOut, LOCATOR_FILE);
236
- await writeFile(`${locator}.${process.pid}.tmp`, JSON.stringify({ outDir: path.relative(config.root, config.outPath) }));
237
- await rename(`${locator}.${process.pid}.tmp`, locator);
238
- await rm(buildIndexFile(defaultOut), { force: true });
239
- }
240
-
241
- export { BUILD_INDEX_VERSION, buildIndexFile, releaseModuleKey, productionRelease, servedRelease, servedConventions, frozenDirListing, conventionFileExists, releaseModuleHref, attachRelease, servedAppFiles, captureConventions, releaseSourceKey, releaseSourceFile, readBuildIndex, locateRelease, serializeReleaseConfig, releaseConfig, writeBuildIndex };
@@ -1,57 +0,0 @@
1
- // @bun
2
- import { join as __pnextJoin } from "node:path";
3
- const __PNEXT_PACKAGE_ROOT__ = __pnextJoin(import.meta.dirname, "../../..");
4
- // src/runtime/prebundle.ts
5
- import { readFileSync } from "fs";
6
- import path from "path";
7
- import { fileURLToPath } from "url";
8
- var runtimeEntryFiles = ["cli/start.ts", "index.ts", "internal.ts", "client/reference.ts"];
9
- var runtimeEntryDirs = ["api", "compat/next", "compat/react"];
10
- var PREBUNDLE_STAMP = path.join("dist", "server", "generation.json");
11
- var prebundle = typeof { version: "0.1.7", fingerprint: "3e1b3462bd8a29ed", entries: ["cli/index", "cli/start", "client/reference", "api/client-cache", "compat/next/canonical-url", "compat/next/link-transform", "compat/next/client-navigation", "compat/next/og", "compat/next/link", "compat/next/usage", "compat/next/client-script", "compat/next/headers", "compat/next/custom-server", "compat/next/legacy-image", "compat/next/router", "compat/next/navigation", "compat/next/dist/server/web/spec-extension/unstable-no-store", "compat/next/dist/server/web/spec-extension/unstable-cache", "compat/next/dist/server/web/spec-extension/revalidate", "compat/next/dist/client/components/app-router-headers", "compat/next/web-vitals", "compat/next/root-params", "compat/next/route-state", "compat/next/server-only", "compat/next/client-server", "compat/next/legacy-request-apis", "compat/next/redirects", "compat/next/resource-hints", "compat/next/svgr", "compat/next/client-only", "compat/next/image/props", "compat/next/image/optimizer", "compat/next/image/validate", "compat/next/image/shared", "compat/next/image/patterns", "compat/next/image/config", "compat/next/image/client", "compat/next/image/static-metadata", "compat/next/user-agent", "compat/next/client-cache", "compat/next/head", "compat/next/dynamic", "compat/next/telemetry", "compat/next/offline", "compat/next/cache", "compat/next/constants", "compat/next/error", "compat/next/script", "compat/next/index", "compat/next/font/shared", "compat/next/font/runtime", "compat/next/font/google", "compat/next/font/cache", "compat/next/font/runtime-client", "compat/next/font/local", "compat/next/font/index", "compat/next/config-loader", "compat/next/config", "compat/next/image", "compat/next/server", "compat/next/rewrites", "compat/next/preferred-region", "compat/next/config-headers", "compat/next/form", "compat/react/dom", "compat/react/hooks-extra", "compat/react/react-server", "compat/react/dom-client", "compat/react/style-values", "compat/react/compiler-runtime", "compat/react/router-shim", "compat/react/dom-server", "compat/react/dom-react-server", "compat/react/server-component-use", "compat/react/action-state", "compat/react/client", "compat/react/client-lite", "compat/react/server-inserted-html", "compat/react/parity", "compat/react/preact", "compat/react/use", "compat/react/view-transition", "compat/react/internals", "compat/react/server"] } === "object" ? { version: "0.1.7", fingerprint: "3e1b3462bd8a29ed", entries: ["cli/index", "cli/start", "client/reference", "api/client-cache", "compat/next/canonical-url", "compat/next/link-transform", "compat/next/client-navigation", "compat/next/og", "compat/next/link", "compat/next/usage", "compat/next/client-script", "compat/next/headers", "compat/next/custom-server", "compat/next/legacy-image", "compat/next/router", "compat/next/navigation", "compat/next/dist/server/web/spec-extension/unstable-no-store", "compat/next/dist/server/web/spec-extension/unstable-cache", "compat/next/dist/server/web/spec-extension/revalidate", "compat/next/dist/client/components/app-router-headers", "compat/next/web-vitals", "compat/next/root-params", "compat/next/route-state", "compat/next/server-only", "compat/next/client-server", "compat/next/legacy-request-apis", "compat/next/redirects", "compat/next/resource-hints", "compat/next/svgr", "compat/next/client-only", "compat/next/image/props", "compat/next/image/optimizer", "compat/next/image/validate", "compat/next/image/shared", "compat/next/image/patterns", "compat/next/image/config", "compat/next/image/client", "compat/next/image/static-metadata", "compat/next/user-agent", "compat/next/client-cache", "compat/next/head", "compat/next/dynamic", "compat/next/telemetry", "compat/next/offline", "compat/next/cache", "compat/next/constants", "compat/next/error", "compat/next/script", "compat/next/index", "compat/next/font/shared", "compat/next/font/runtime", "compat/next/font/google", "compat/next/font/cache", "compat/next/font/runtime-client", "compat/next/font/local", "compat/next/font/index", "compat/next/config-loader", "compat/next/config", "compat/next/image", "compat/next/server", "compat/next/rewrites", "compat/next/preferred-region", "compat/next/config-headers", "compat/next/form", "compat/react/dom", "compat/react/hooks-extra", "compat/react/react-server", "compat/react/dom-client", "compat/react/style-values", "compat/react/compiler-runtime", "compat/react/router-shim", "compat/react/dom-server", "compat/react/dom-react-server", "compat/react/server-component-use", "compat/react/action-state", "compat/react/client", "compat/react/client-lite", "compat/react/server-inserted-html", "compat/react/parity", "compat/react/preact", "compat/react/use", "compat/react/view-transition", "compat/react/internals", "compat/react/server"] } : undefined;
12
- var packageRoot = path.resolve(__PNEXT_PACKAGE_ROOT__ + "/src/runtime", "..", "..");
13
- var srcRoot = path.join(packageRoot, "src") + path.sep;
14
- var distRoot = path.join(packageRoot, "dist", "server");
15
- var entries = new Set(prebundle?.entries);
16
- function packageVersion(root) {
17
- return JSON.parse(readFileSync(path.join(root, "package.json"), "utf8")).version;
18
- }
19
- function readPrebundleStamp(frameworkRoot, fingerprint) {
20
- let stamp;
21
- try {
22
- stamp = JSON.parse(readFileSync(path.join(frameworkRoot, PREBUNDLE_STAMP), "utf8"));
23
- } catch {
24
- return;
25
- }
26
- return stamp.fingerprint === fingerprint && stamp.version === packageVersion(frameworkRoot) ? stamp : undefined;
27
- }
28
- function prebundledFile(file) {
29
- if (!prebundle || !file.startsWith(srcRoot))
30
- return file;
31
- const entry = file.slice(srcRoot.length).replace(/\.tsx?$/, "");
32
- return entries.has(entry) ? path.join(distRoot, `${entry}.js`) : file;
33
- }
34
- var registered = false;
35
- function registerPrebundleResolve() {
36
- if (!prebundle || registered)
37
- return;
38
- registered = true;
39
- const escaped = srcRoot.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
40
- Bun.plugin({
41
- name: "pnext-prebundle",
42
- setup(build) {
43
- build.onResolve({ filter: new RegExp(`^(?:file://)?${escaped}.*\\.tsx?$`) }, (args) => {
44
- const file = args.path.startsWith("file:") ? fileURLToPath(args.path) : args.path;
45
- const target = prebundledFile(file);
46
- return target === file ? undefined : { path: target };
47
- });
48
- build.onResolve({ filter: /^\.\.?\/.*\/src\/.*\.tsx?$/ }, (args) => {
49
- const file = path.resolve(path.dirname(args.importer), args.path);
50
- const target = prebundledFile(file);
51
- return target === file ? undefined : { path: target };
52
- });
53
- }
54
- });
55
- }
56
-
57
- export { runtimeEntryFiles, runtimeEntryDirs, readPrebundleStamp, prebundledFile, registerPrebundleResolve };
@@ -1,52 +0,0 @@
1
- /**
2
- * Server entry for hosts that serve a build through `createRequestHandler`: a thin loader that
3
- * resolves `@wular/pnext` from the output's own location (as `.next/server` loads `next`), so the
4
- * output carries no framework code and no build-machine paths.
5
- */
6
- import { readFileSync } from 'node:fs'
7
- import { mkdir, writeFile } from 'node:fs/promises'
8
- import path from 'node:path'
9
- import { frameworkFingerprint } from '../../runtime/fingerprint'
10
- import { readPrebundleStamp } from '../../runtime/prebundle'
11
-
12
- const frameworkRoot = path.resolve(import.meta.dirname, '..', '..', '..')
13
-
14
- /** Stamped into the filename so an upgraded framework never runs a stale bundle. */
15
- function frameworkVersion(): string {
16
- try {
17
- const pkg = readFileSync(path.join(frameworkRoot, 'package.json'), 'utf8')
18
- return (JSON.parse(pkg) as { version?: string }).version ?? '0'
19
- } catch {
20
- return '0'
21
- }
22
- }
23
-
24
- /**
25
- * Version AND framework fingerprint: the version alone let an edited `src` keep serving the bundle
26
- * built from the previous source, so a fix appeared to have no effect until the app was rebuilt.
27
- * The fingerprint is the same one every other compiled artifact is keyed on, taken through the
28
- * cache-root record so a restart pays one stat per file rather than re-reading the tree.
29
- */
30
- export function serverEntryDir(outPath: string): string {
31
- const generation = frameworkFingerprint(path.join(outPath, 'cache', 'server'))
32
- return path.join(outPath, 'server', `bundle-${frameworkVersion()}-${generation}`)
33
- }
34
-
35
- /**
36
- * Write `<outPath>/server/bundle-<version>-<fingerprint>/entry.js`, re-exporting the published
37
- * prebundle's cli/start.js when it was built from this source, else src/cli/start.ts.
38
- */
39
- export async function emitServerEntry(outPath: string): Promise<void> {
40
- const start = await Bun.file(path.join(import.meta.dirname, '..', 'start.ts')).text()
41
- const names = new Bun.Transpiler({ loader: 'ts' }).scan(start).exports
42
- const dir = serverEntryDir(outPath)
43
- const target = readPrebundleStamp(frameworkRoot, frameworkFingerprint())
44
- ? '../dist/server/cli/start.js'
45
- : './cli/start.ts'
46
- await mkdir(dir, { recursive: true })
47
- await writeFile(
48
- path.join(dir, 'entry.js'),
49
- `const pnext = await import(new URL('${target}', import.meta.resolve('@wular/pnext')).href)\n` +
50
- `export const { ${names.join(', ')} } = pnext\n`,
51
- )
52
- }