@docs-sdk-dev/next 0.0.0-stage → 0.4.0-next.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/LICENSE +21 -0
- package/README.md +58 -2
- package/dist/build-profile.d.ts +7 -0
- package/dist/build-profile.js +158 -0
- package/dist/build-profile.js.map +1 -0
- package/dist/build.d.ts +39 -0
- package/dist/build.js +177 -0
- package/dist/build.js.map +1 -0
- package/dist/client.d.ts +7 -0
- package/dist/client.js +69 -0
- package/dist/client.js.map +1 -0
- package/dist/dev-events.d.ts +35 -0
- package/dist/dev-events.js +117 -0
- package/dist/dev-events.js.map +1 -0
- package/dist/dev-refresh.d.ts +9 -0
- package/dist/dev-refresh.js +51 -0
- package/dist/dev-refresh.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +5 -0
- package/dist/metadata.d.ts +15 -0
- package/dist/metadata.js +48 -0
- package/dist/metadata.js.map +1 -0
- package/dist/native-routes.d.ts +9 -0
- package/dist/native-routes.js +80 -0
- package/dist/native-routes.js.map +1 -0
- package/dist/publication.d.ts +6 -0
- package/dist/publication.js +56 -0
- package/dist/publication.js.map +1 -0
- package/dist/server.d.ts +1253 -0
- package/dist/server.js +364 -0
- package/dist/server.js.map +1 -0
- package/docs/framework/hosts/next-native-preview.md +21 -0
- package/docs/framework/hosts.md +91 -0
- package/docs/index.md +8 -0
- package/docs/zh-CN/framework/hosts/next-native-preview.md +21 -0
- package/docs/zh-CN/framework/hosts.md +93 -0
- package/package.json +60 -4
- package/styles/site.css +5 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Lenso contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,59 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Docs SDK for Next.js
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Read the [installed guides](docs/index.md) for this release. The package declarations give the exact API signatures.
|
|
4
|
+
|
|
5
|
+
Run `docs init guide --framework next` to create an App Router project. `createDocs` from `@docs-sdk-dev/next/server` loads the compiled publication, and `DocsPage` from `@docs-sdk-dev/react/server` renders it.
|
|
6
|
+
|
|
7
|
+
## Development
|
|
8
|
+
|
|
9
|
+
`devNext()` from `@docs-sdk-dev/next/build` rebuilds the publication as project inputs change and starts `next dev`. Render `<DocsDevRefresh docs={docs} />` from `@docs-sdk-dev/next/server` once in the root layout. After each rebuild, open pages call `router.refresh()`, which keeps scroll and client state. A failed rebuild keeps the last good page and shows the error until a fix lands. Outside `devNext` and in production the component renders nothing, and production builds leave its client code out.
|
|
10
|
+
|
|
11
|
+
## Native pages
|
|
12
|
+
|
|
13
|
+
Pass the starter's `{ nativeRoutes }` option to `buildPublication()`, `buildNext()` and `devNext()` to generate App Router entries for public native routes. Each entry uses the same `docs` and `renderDocsPage` exports as the catch-all and loads its own Client Components. The catch-all uses a required `[...slug]` segment and `docs.generateStaticParams({ excludeNative: true })`. Keep the publication outside the public directory and the generated `app/(docs-sdk-native)` group out of version control.
|
|
14
|
+
|
|
15
|
+
For a custom host managing its own route files, `buildPublication()` also supports a server-only `.docs-sdk/next-native-views.mjs` registry. Pass its `nativeViews` to `publicPublication()` when using that integration. Next may share Client Components across routes handled by the same App Router segment.
|
|
16
|
+
|
|
17
|
+
The default public native view may be a Server Component or a Client Component. Both receive the canonical semantic body as a `children` slot and serializable document metadata. Export named `Layout` components from the server so they can call theme regions.
|
|
18
|
+
|
|
19
|
+
## Metadata and public discovery
|
|
20
|
+
|
|
21
|
+
Return `docs.getMetadata(slug)` from `generateMetadata` for the resolved Next.js metadata. Render `<DocsMetadata metadata={page.metadata} />` from `@docs-sdk-dev/next/server` in the same page to include JSON-LD and any social tags requiring exact output. These APIs use the same public publication as `getPage` for SSG, ISR, and request-time rendering. Set `htmlLimitedBots: /.*/` for blocking metadata in the initial HTML for every user agent, as the scaffold does.
|
|
22
|
+
|
|
23
|
+
Use `publicationBasePath(file)` from `@docs-sdk-dev/next/build` as the App Router `basePath` when the configured documentation URL has a path. The scaffold uses `publicationDiscoveryRewrites` and an App Router handler calling `docs.getDiscoveryAsset` to serve `robots.txt`, the sitemap, and sitemap shards. Serve generated images with the public `docs.getResourceAsset` handler. Include the public publication file in deployments. Explicitly dynamic default OG images use the Node.js runtime. Include `@takumi-rs/core` and its matching platform binding in standalone and serverless deployments that render images on request. Pre-rendered images and custom-renderer outputs travel in the publication and need the renderer only during the build.
|
|
24
|
+
|
|
25
|
+
## Request-time access
|
|
26
|
+
|
|
27
|
+
Define policies with `defineAccess` and register that definition in `docs.config.ts`. A protected publication needs a separate server file. In the application's build script, generate both files before `next build`.
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
import { buildPublication } from "@docs-sdk-dev/next/build"
|
|
31
|
+
|
|
32
|
+
await buildPublication(process.cwd(), undefined, {
|
|
33
|
+
privateOutput: ".docs-sdk/next-private.json",
|
|
34
|
+
})
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Keep both files in the server deployment. A standalone build needs them in `outputFileTracingIncludes`. Files containing restricted content belong outside `public/`. Use `protected-assets/` plus declared asset access for files served by a protected handler.
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
import { createDocs, openAccessPublication, publicPublication } from "@docs-sdk-dev/next/server"
|
|
41
|
+
import { access } from "./access"
|
|
42
|
+
|
|
43
|
+
export const docs = createDocs({
|
|
44
|
+
publicPublication: publicPublication(".docs-sdk/next-publication.json"),
|
|
45
|
+
accessPublication: openAccessPublication(".docs-sdk/next-private.json", access),
|
|
46
|
+
})
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Use `getPage`, `getMetadata`, and `generateStaticParams` for publicly cacheable routes. For App Router Server Components and metadata on protected routes, use `await docs.forPage(url)` with a URL constructed from your application's trusted origin. For Route Handlers, use `await docs.forRequest(request)`. Both give you request-scoped page, navigation, outline, Markdown, Reader, semantic facts, Agent context, search, assets, and MCP. Wrap application responses with `view.response(body, init)` to apply the private cache policy. The asset and MCP helpers already return private responses.
|
|
50
|
+
|
|
51
|
+
Use normal links for protected pages so a navigation always reaches the server. The framework marks these pages for reload when browser history restores them. Keep the routes dynamic, including metadata, and omit them from any CDN or application-level response cache. Return a generic 404 when the view lacks the requested page. Supply `DocsAccess` or the optional `DocsPage` access prop for sign-in, account and upgrade UI using presentation values selected by the host.
|
|
52
|
+
|
|
53
|
+
Protected native views use portable content by default. To render one with a Server Component, supply a revision-bound `NativeViews` registry to `openAccessPublication` or attach a trusted `readNativeView` loader to the authorized publication returned by `accessPublication`. The adapter looks up the module after access filtering and skips the native view if part of its canonical document is withheld. Keep private data in the authorized server render and mark its module with `server-only`. Next serves compiled client modules as public assets.
|
|
54
|
+
|
|
55
|
+
### Island preloading
|
|
56
|
+
|
|
57
|
+
Next owns the chunks it generates for native components and the runtime those components import. Docs SDK leaves Next Link and RSC prefetching in place. To warm a published Build Profile preview on the next-document link, use `IslandNavigationLink` from `@docs-sdk-dev/next/client` with a same-origin endpoint that calls `docs.getIslandPreloadPlan(slug)`. The plan reads only the public publication and fixed Context placements. Standard Next projects generated by `create-docs-sdk` include this route and link adapter.
|
|
58
|
+
|
|
59
|
+
Build Profiles can externalize an installed runtime when the host explicitly resolves its compatible version. An independent Profile bundle cannot import Next's private framework chunks. For native React islands, import the application's React and React DOM directly so the bundler can share the runtime. For isolated or incompatible previews, keep their framework resolution separate.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type BuildOptions } from "esbuild";
|
|
2
|
+
import type { BuildEntry, BuildInput, BuildProfile } from "@docs-sdk-dev/core/resources";
|
|
3
|
+
export { defineBuildProfile, type BuildEntry, type BuildInput, type BuildProfile, type ResourceBundle, } from "@docs-sdk-dev/core/resources";
|
|
4
|
+
type ProfileOptions = Omit<BuildProfile, "build"> & Pick<BuildOptions, "jsx" | "jsxImportSource" | "target" | "minify"> & {
|
|
5
|
+
preview?(resource: BuildInput): Omit<NonNullable<BuildEntry["preview"]>, "source">;
|
|
6
|
+
};
|
|
7
|
+
export declare function esbuildBuildProfile({ preview, jsx, jsxImportSource, target, minify, ...profile }: ProfileOptions): BuildProfile;
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { dirname, extname, posix, relative, resolve } from "node:path";
|
|
2
|
+
import { build } from "esbuild";
|
|
3
|
+
import { DocsError, isSourceAssetPath } from "@docs-sdk-dev/core";
|
|
4
|
+
import { defineBuildProfile } from "@docs-sdk-dev/core/resources";
|
|
5
|
+
|
|
6
|
+
// src/build-profile.ts
|
|
7
|
+
const loaders = /* @__PURE__ */ new Map([
|
|
8
|
+
[".js", "js"],
|
|
9
|
+
[".mjs", "js"],
|
|
10
|
+
[".cjs", "js"],
|
|
11
|
+
[".jsx", "jsx"],
|
|
12
|
+
[".ts", "ts"],
|
|
13
|
+
[".mts", "ts"],
|
|
14
|
+
[".cts", "ts"],
|
|
15
|
+
[".tsx", "tsx"],
|
|
16
|
+
[".css", "css"],
|
|
17
|
+
[".json", "json"],
|
|
18
|
+
[".txt", "text"],
|
|
19
|
+
[".svg", "file"]
|
|
20
|
+
]);
|
|
21
|
+
function esbuildBuildProfile({ preview, jsx, jsxImportSource, target, minify, ...profile }) {
|
|
22
|
+
return {
|
|
23
|
+
...profile,
|
|
24
|
+
async build(group, inputs) {
|
|
25
|
+
const entryPoints = {};
|
|
26
|
+
const entries = /* @__PURE__ */ new Map();
|
|
27
|
+
const modules = /* @__PURE__ */ new Map();
|
|
28
|
+
const ordered = [...group].sort((left, right) => left.key < right.key ? -1 : left.key > right.key ? 1 : 0);
|
|
29
|
+
for (const [index, resource] of ordered.entries()) {
|
|
30
|
+
const prefix = `/${index}/`;
|
|
31
|
+
const capture = (path, text) => {
|
|
32
|
+
if (!isSourceAssetPath(path)) throw new DocsError("DOCS_BUILD_PROFILE_INPUT", "Expected a captured relative source path.", { source: path });
|
|
33
|
+
modules.set(prefix + path, text);
|
|
34
|
+
};
|
|
35
|
+
for (const [path, text] of inputs) capture(path, text);
|
|
36
|
+
for (const { path, text } of resource.files ?? []) capture(path, text);
|
|
37
|
+
capture(resource.file, resource.text);
|
|
38
|
+
const id = prefix + resource.file;
|
|
39
|
+
entryPoints["entry-" + index] = id;
|
|
40
|
+
entries.set(id, resource);
|
|
41
|
+
}
|
|
42
|
+
const runtime = Object.keys(this.runtime ?? {});
|
|
43
|
+
const outdir = resolve(".docs-sdk", "profile-output");
|
|
44
|
+
const output = await build({
|
|
45
|
+
entryPoints,
|
|
46
|
+
outdir,
|
|
47
|
+
jsx,
|
|
48
|
+
jsxImportSource,
|
|
49
|
+
target,
|
|
50
|
+
minify,
|
|
51
|
+
bundle: true,
|
|
52
|
+
splitting: true,
|
|
53
|
+
platform: "browser",
|
|
54
|
+
format: "esm",
|
|
55
|
+
write: false,
|
|
56
|
+
metafile: true,
|
|
57
|
+
entryNames: "[name]-[hash]",
|
|
58
|
+
chunkNames: "chunks/[name]-[hash]",
|
|
59
|
+
assetNames: "assets/[name]-[hash]",
|
|
60
|
+
plugins: [{
|
|
61
|
+
name: "docs-profile-inputs",
|
|
62
|
+
setup(plugin) {
|
|
63
|
+
plugin.onResolve({ filter: /.*/ }, ({ path, importer, kind }) => {
|
|
64
|
+
if (kind === "entry-point" && entries.has(path)) return {
|
|
65
|
+
path,
|
|
66
|
+
namespace: "profile"
|
|
67
|
+
};
|
|
68
|
+
if (path.startsWith(".")) {
|
|
69
|
+
const candidate = posix.join(posix.dirname(importer), path);
|
|
70
|
+
const group = importer.split("/")[1];
|
|
71
|
+
if (candidate.startsWith("/" + group + "/") && modules.has(candidate)) return {
|
|
72
|
+
path: candidate,
|
|
73
|
+
namespace: "profile"
|
|
74
|
+
};
|
|
75
|
+
} else if (runtime.some((id) => path === id || path.startsWith(id + "/"))) return {
|
|
76
|
+
path,
|
|
77
|
+
external: true
|
|
78
|
+
};
|
|
79
|
+
if (/^(?:data:|https?:|#)/.test(path) && kind === "url-token") return {
|
|
80
|
+
path,
|
|
81
|
+
external: true
|
|
82
|
+
};
|
|
83
|
+
return { errors: [{ text: "Declare " + path + " in the build profile's captured inputs or runtime." }] };
|
|
84
|
+
});
|
|
85
|
+
plugin.onLoad({
|
|
86
|
+
filter: /.*/,
|
|
87
|
+
namespace: "profile"
|
|
88
|
+
}, ({ path }) => {
|
|
89
|
+
const loader = loaders.get(extname(path));
|
|
90
|
+
return loader ? {
|
|
91
|
+
contents: modules.get(path),
|
|
92
|
+
loader
|
|
93
|
+
} : { errors: [{ text: "Unsupported captured input " + path }] };
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
}]
|
|
97
|
+
}).catch((error) => {
|
|
98
|
+
throw new DocsError("DOCS_BUILD_PROFILE_INPUT", error instanceof Error ? error.message : String(error), { source: this.id });
|
|
99
|
+
});
|
|
100
|
+
const pathFor = (file) => relative(outdir, resolve(file)).replaceAll("\\", "/");
|
|
101
|
+
const files = output.outputFiles.map((file) => ({
|
|
102
|
+
path: pathFor(file.path),
|
|
103
|
+
bytes: file.contents
|
|
104
|
+
}));
|
|
105
|
+
const artifacts = new Map(Object.entries(output.metafile.outputs).map(([file, entry]) => [resolve(file), entry]));
|
|
106
|
+
const result = Object.create(null);
|
|
107
|
+
for (const [file, entry] of artifacts) {
|
|
108
|
+
const resource = entry.entryPoint && entries.get(entry.entryPoint.replace(/^profile:/, ""));
|
|
109
|
+
if (!resource || !file.endsWith(".js")) continue;
|
|
110
|
+
const importsOf = (file) => (artifacts.get(file)?.imports ?? []).flatMap((item) => {
|
|
111
|
+
if (item.external) return [];
|
|
112
|
+
const path = [resolve(item.path), resolve(dirname(file), item.path)].find((path) => artifacts.has(path));
|
|
113
|
+
return path ? [{
|
|
114
|
+
path,
|
|
115
|
+
kind: item.kind
|
|
116
|
+
}] : [];
|
|
117
|
+
});
|
|
118
|
+
const closure = (root, staticModules) => {
|
|
119
|
+
const visited = /* @__PURE__ */ new Set([root]);
|
|
120
|
+
function visit(file) {
|
|
121
|
+
for (const { path, kind } of importsOf(file)) {
|
|
122
|
+
if (visited.has(path) || staticModules && (kind !== "import-statement" || !/\.m?js$/.test(path))) continue;
|
|
123
|
+
visited.add(path);
|
|
124
|
+
visit(path);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
visit(root);
|
|
128
|
+
visited.delete(root);
|
|
129
|
+
return [...visited].map(pathFor);
|
|
130
|
+
};
|
|
131
|
+
const css = entry.cssBundle ? [pathFor(entry.cssBundle)] : [];
|
|
132
|
+
const assets = /* @__PURE__ */ new Set([...closure(file, false), ...entry.cssBundle ? closure(resolve(entry.cssBundle), false) : []]);
|
|
133
|
+
const source = preview && "sources/" + Object.keys(result).length + ".txt";
|
|
134
|
+
if (source) files.push({
|
|
135
|
+
path: source,
|
|
136
|
+
bytes: new TextEncoder().encode(resource.text)
|
|
137
|
+
});
|
|
138
|
+
result[resource.key] = {
|
|
139
|
+
entry: pathFor(file),
|
|
140
|
+
css,
|
|
141
|
+
assets: [...assets].filter((path) => !css.includes(path)),
|
|
142
|
+
imports: closure(file, true),
|
|
143
|
+
...source && { preview: {
|
|
144
|
+
...preview(resource),
|
|
145
|
+
source
|
|
146
|
+
} }
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
return {
|
|
150
|
+
files,
|
|
151
|
+
entries: result
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export { defineBuildProfile, esbuildBuildProfile };
|
|
158
|
+
//# sourceMappingURL=build-profile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-profile.js","names":[],"sources":["../src/build-profile.ts"],"sourcesContent":["import { dirname, relative, resolve, posix, extname } from \"node:path\"\nimport { build, type BuildOptions, type Loader } from \"esbuild\"\nimport { DocsError, isSourceAssetPath } from \"@docs-sdk-dev/core\"\nimport type { BuildEntry, BuildInput, BuildProfile } from \"@docs-sdk-dev/core/resources\"\n\nexport {\n defineBuildProfile,\n type BuildEntry,\n type BuildInput,\n type BuildProfile,\n type ResourceBundle,\n} from \"@docs-sdk-dev/core/resources\"\n\nconst loaders = new Map<string, Loader>([\n [\".js\", \"js\"],\n [\".mjs\", \"js\"],\n [\".cjs\", \"js\"],\n [\".jsx\", \"jsx\"],\n [\".ts\", \"ts\"],\n [\".mts\", \"ts\"],\n [\".cts\", \"ts\"],\n [\".tsx\", \"tsx\"],\n [\".css\", \"css\"],\n [\".json\", \"json\"],\n [\".txt\", \"text\"],\n [\".svg\", \"file\"],\n])\n\ntype ProfileOptions = Omit<BuildProfile, \"build\"> &\n Pick<BuildOptions, \"jsx\" | \"jsxImportSource\" | \"target\" | \"minify\"> & {\n preview?(resource: BuildInput): Omit<NonNullable<BuildEntry[\"preview\"]>, \"source\">\n }\n\nexport function esbuildBuildProfile({\n preview,\n jsx,\n jsxImportSource,\n target,\n minify,\n ...profile\n}: ProfileOptions): BuildProfile {\n return {\n ...profile,\n async build(group, inputs) {\n const entryPoints: Record<string, string> = {}\n const entries = new Map<string, BuildInput>()\n const modules = new Map<string, string>()\n const ordered = [...group].sort((left, right) =>\n left.key < right.key ? -1 : left.key > right.key ? 1 : 0,\n )\n for (const [index, resource] of ordered.entries()) {\n const prefix = `/${index}/`\n const capture = (path: string, text: string) => {\n if (!isSourceAssetPath(path))\n throw new DocsError(\n \"DOCS_BUILD_PROFILE_INPUT\",\n \"Expected a captured relative source path.\",\n { source: path },\n )\n modules.set(prefix + path, text)\n }\n for (const [path, text] of inputs) capture(path, text)\n for (const { path, text } of resource.files ?? []) capture(path, text)\n capture(resource.file, resource.text)\n const id = prefix + resource.file\n entryPoints[\"entry-\" + index] = id\n entries.set(id, resource)\n }\n const runtime = Object.keys(this.runtime ?? {})\n const outdir = resolve(\".docs-sdk\", \"profile-output\")\n const output = await build({\n entryPoints,\n outdir,\n jsx,\n jsxImportSource,\n target,\n minify,\n bundle: true,\n splitting: true,\n platform: \"browser\",\n format: \"esm\",\n write: false,\n metafile: true,\n entryNames: \"[name]-[hash]\",\n chunkNames: \"chunks/[name]-[hash]\",\n assetNames: \"assets/[name]-[hash]\",\n plugins: [\n {\n name: \"docs-profile-inputs\",\n setup(plugin) {\n plugin.onResolve({ filter: /.*/ }, ({ path, importer, kind }) => {\n if (kind === \"entry-point\" && entries.has(path))\n return { path, namespace: \"profile\" }\n if (path.startsWith(\".\")) {\n const candidate = posix.join(posix.dirname(importer), path)\n const group = importer.split(\"/\")[1]\n if (candidate.startsWith(\"/\" + group + \"/\") && modules.has(candidate))\n return { path: candidate, namespace: \"profile\" }\n } else if (runtime.some((id) => path === id || path.startsWith(id + \"/\")))\n return { path, external: true }\n if (/^(?:data:|https?:|#)/.test(path) && kind === \"url-token\")\n return { path, external: true }\n return {\n errors: [\n {\n text:\n \"Declare \" + path + \" in the build profile's captured inputs or runtime.\",\n },\n ],\n }\n })\n plugin.onLoad({ filter: /.*/, namespace: \"profile\" }, ({ path }) => {\n const loader = loaders.get(extname(path))\n return loader\n ? { contents: modules.get(path)!, loader }\n : { errors: [{ text: \"Unsupported captured input \" + path }] }\n })\n },\n },\n ],\n }).catch((error) => {\n throw new DocsError(\n \"DOCS_BUILD_PROFILE_INPUT\",\n error instanceof Error ? error.message : String(error),\n { source: this.id },\n )\n })\n const pathFor = (file: string) => relative(outdir, resolve(file)).replaceAll(\"\\\\\", \"/\")\n const files = output.outputFiles.map((file) => ({\n path: pathFor(file.path),\n bytes: file.contents,\n }))\n const artifacts = new Map(\n Object.entries(output.metafile.outputs).map(([file, entry]) => [resolve(file), entry]),\n )\n const result: Record<string, BuildEntry> = Object.create(null)\n for (const [file, entry] of artifacts) {\n const resource = entry.entryPoint && entries.get(entry.entryPoint.replace(/^profile:/, \"\"))\n if (!resource || !file.endsWith(\".js\")) continue\n const importsOf = (file: string) =>\n (artifacts.get(file)?.imports ?? []).flatMap((item) => {\n if (item.external) return []\n const path = [resolve(item.path), resolve(dirname(file), item.path)].find((path) =>\n artifacts.has(path),\n )\n return path ? [{ path, kind: item.kind }] : []\n })\n const closure = (root: string, staticModules: boolean) => {\n const visited = new Set([root])\n function visit(file: string) {\n for (const { path, kind } of importsOf(file)) {\n if (\n visited.has(path) ||\n (staticModules && (kind !== \"import-statement\" || !/\\.m?js$/.test(path)))\n )\n continue\n visited.add(path)\n visit(path)\n }\n }\n visit(root)\n visited.delete(root)\n return [...visited].map(pathFor)\n }\n const css = entry.cssBundle ? [pathFor(entry.cssBundle)] : []\n const assets = new Set([\n ...closure(file, false),\n ...(entry.cssBundle ? closure(resolve(entry.cssBundle), false) : []),\n ])\n const source = preview && \"sources/\" + Object.keys(result).length + \".txt\"\n if (source) files.push({ path: source, bytes: new TextEncoder().encode(resource.text) })\n result[resource.key] = {\n entry: pathFor(file),\n css,\n assets: [...assets].filter((path) => !css.includes(path)),\n imports: closure(file, true),\n ...(source && { preview: { ...preview!(resource), source } }),\n }\n }\n return { files, entries: result }\n },\n }\n}\n"],"mappings":";;;;;;AAaA,MAAM,0BAAU,IAAI,IAAoB;CACtC,CAAC,OAAO,IAAI;CACZ,CAAC,QAAQ,IAAI;CACb,CAAC,QAAQ,IAAI;CACb,CAAC,QAAQ,KAAK;CACd,CAAC,OAAO,IAAI;CACZ,CAAC,QAAQ,IAAI;CACb,CAAC,QAAQ,IAAI;CACb,CAAC,QAAQ,KAAK;CACd,CAAC,QAAQ,KAAK;CACd,CAAC,SAAS,MAAM;CAChB,CAAC,QAAQ,MAAM;CACf,CAAC,QAAQ,MAAM;AACjB,CAAC;AAOD,SAAgB,oBAAoB,EAClC,SACA,KACA,iBACA,QACA,QACA,GAAG,WAC4B;CAC/B,OAAO;EACL,GAAG;EACH,MAAM,MAAM,OAAO,QAAQ;GACzB,MAAM,cAAsC,CAAC;GAC7C,MAAM,0BAAU,IAAI,IAAwB;GAC5C,MAAM,0BAAU,IAAI,IAAoB;GACxC,MAAM,UAAU,CAAC,GAAG,KAAK,CAAC,CAAC,MAAM,MAAM,UACrC,KAAK,MAAM,MAAM,MAAM,KAAK,KAAK,MAAM,MAAM,MAAM,IAAI,CACzD;GACA,KAAK,MAAM,CAAC,OAAO,aAAa,QAAQ,QAAQ,GAAG;IACjD,MAAM,SAAS,IAAI,MAAM;IACzB,MAAM,WAAW,MAAc,SAAiB;KAC9C,IAAI,CAAC,kBAAkB,IAAI,GACzB,MAAM,IAAI,UACR,4BACA,6CACA,EAAE,QAAQ,KAAK,CACjB;KACF,QAAQ,IAAI,SAAS,MAAM,IAAI;IACjC;IACA,KAAK,MAAM,CAAC,MAAM,SAAS,QAAQ,QAAQ,MAAM,IAAI;IACrD,KAAK,MAAM,EAAE,MAAM,UAAU,SAAS,SAAS,CAAC,GAAG,QAAQ,MAAM,IAAI;IACrE,QAAQ,SAAS,MAAM,SAAS,IAAI;IACp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C,IAAI,CAAC;KAC9B,SAAS,MAAM,MAAc;MAC3B,KAAK,MAAM,EAAE,MAAM,UAAU,UAAU,IAAI,GAAG;OAC5C,IACE,QAAQ,IAAI,IAAI,KACf,kBAAkB,SAAS,sBAAsB,CAAC,UAAU,KAAK,IAAI,IAEtE;OACF,QAAQ,IAAI,IAAI;OAChB,MAAM,IAAI;MACZ;KACF;KACA,MAAM,IAAI;KACV,QAAQ,OAAO,IAAI;KACnB,OAAO,CAAC,GAAG,OAAO,CAAC,CAAC,IAAI,OAAO;IACjC;IACA,MAAM,MAAM,MAAM,YAAY,CAAC,QAAQ,MAAM,SAAS,CAAC,IAAI,CAAC;IAC5D,MAAM,yBAAS,IAAI,IAAI,CACrB,GAAG,QAAQ,MAAM,KAAK,GACtB,GAAI,MAAM,YAAY,QAAQ,QAAQ,MAAM,SAAS,GAAG,KAAK,IAAI,CAAC,CACpE,CAAC;IACD,MAAM,SAAS,WAAW,aAAa,OAAO,KAAK,MAAM,CAAC,CAAC,SAAS;IACpE,IAAI,QAAQ,MAAM,KAAK;KAAE,MAAM;KAAQ,OAAO,IAAI,YAAY,CAAC,CAAC,OAAO,SAAS,IAAI;IAAE,CAAC;IACvF,OAAO,SAAS,OAAO;KACrB,OAAO,QAAQ,IAAI;KACnB;KACA,QAAQ,CAAC,GAAG,MAAM,CAAC,CAAC,QAAQ,SAAS,CAAC,IAAI,SAAS,IAAI,CAAC;KACxD,SAAS,QAAQ,MAAM,IAAI;KAC3B,GAAI,UAAU,EAAE,SAAS;MAAE,GAAG,QAAS,QAAQ;MAAG;KAAO,EAAE;IAC7D;GACF;GACA,OAAO;IAAE;IAAO,SAAS;GAAO;EAClC;CACF;AACF"}
|
package/dist/build.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { CodeAnnotator } from "@docs-sdk-dev/core";
|
|
2
|
+
import { type NativeRoutes } from "./native-routes.js";
|
|
3
|
+
export type { NativeRoutes } from "./native-routes.js";
|
|
4
|
+
interface NextPublicationOptions {
|
|
5
|
+
privateOutput?: string;
|
|
6
|
+
nativeRoutes?: NativeRoutes;
|
|
7
|
+
/**
|
|
8
|
+
* Annotates `twoslash` code blocks while the publication is prepared, such as `createTwoslashAnnotator()` from
|
|
9
|
+
* `@docs-sdk-dev/typescript/twoslash`. Pages then show types without running TypeScript on the server.
|
|
10
|
+
*/
|
|
11
|
+
annotateCode?: CodeAnnotator;
|
|
12
|
+
}
|
|
13
|
+
type PublicationOptions = NativeRoutes | NextPublicationOptions;
|
|
14
|
+
export declare function buildPublication(root?: string, output?: string, options?: PublicationOptions): Promise<{
|
|
15
|
+
file: string;
|
|
16
|
+
documents: number;
|
|
17
|
+
buildRevision: string;
|
|
18
|
+
}>;
|
|
19
|
+
/**
|
|
20
|
+
* Run `next dev` over a publication that rebuilds as project inputs change. Each build is announced to open pages,
|
|
21
|
+
* and pages that render `DocsDevRefresh` from `@docs-sdk-dev/next/server` refresh in place.
|
|
22
|
+
*/
|
|
23
|
+
export declare function devNext(args?: readonly string[], publication?: string, options?: PublicationOptions): Promise<void>;
|
|
24
|
+
export declare function publicationRedirects(file: string): Promise<{
|
|
25
|
+
source: string;
|
|
26
|
+
destination: string;
|
|
27
|
+
permanent: true;
|
|
28
|
+
}[]>;
|
|
29
|
+
/** Mount the App Router at the public documentation URL declared by the compiled project. */
|
|
30
|
+
export declare function publicationBasePath(file: string): Promise<string>;
|
|
31
|
+
/** Give App Router discovery assets their public URLs after any host-owned files. */
|
|
32
|
+
export declare function publicationDiscoveryRewrites(): {
|
|
33
|
+
afterFiles: {
|
|
34
|
+
source: string;
|
|
35
|
+
destination: string;
|
|
36
|
+
}[];
|
|
37
|
+
};
|
|
38
|
+
export declare function checkNextRenderedAnchors(directory?: string): Promise<void>;
|
|
39
|
+
export declare function buildNext(args?: readonly string[], directory?: string, publication?: string, options?: PublicationOptions): Promise<void>;
|
package/dist/build.js
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { spawn, spawnSync } from "node:child_process";
|
|
2
|
+
import { mkdir, readFile, readdir, rename, rm, writeFile } from "node:fs/promises";
|
|
3
|
+
import { randomUUID } from "node:crypto";
|
|
4
|
+
import { createRequire } from "node:module";
|
|
5
|
+
import { dirname, join, relative, resolve, sep } from "node:path";
|
|
6
|
+
import { createWebPublicationCache, readNativeWebPublication, verifyNativeWebInputs, writeWebPublication } from "@docs-sdk-dev/node/internal/web-build";
|
|
7
|
+
import { writePackageIslands } from "@docs-sdk-dev/node";
|
|
8
|
+
import { watchProjectInputs } from "@docs-sdk-dev/node/internal/project-inputs";
|
|
9
|
+
import { checkRenderedDocumentAnchors } from "@docs-sdk-dev/web/content-anchors";
|
|
10
|
+
import { writeNativeRoutes } from "./native-routes.js";
|
|
11
|
+
import { devEventsVariable, devRefreshHint, serveDevEvents } from "./dev-events.js";
|
|
12
|
+
|
|
13
|
+
// src/build.ts
|
|
14
|
+
const defaultPublication = ".docs-sdk/next-publication.json";
|
|
15
|
+
function publicationOptions(options) {
|
|
16
|
+
return "entry" in options ? { nativeRoutes: options } : options;
|
|
17
|
+
}
|
|
18
|
+
async function buildPublication(root = process.cwd(), output = defaultPublication, options = {}) {
|
|
19
|
+
return preparePublication(root, output, publicationOptions(options));
|
|
20
|
+
}
|
|
21
|
+
async function preparePublication(root, output, { nativeRoutes, privateOutput, annotateCode }, cache) {
|
|
22
|
+
return writeWebPublication(root, output, void 0, {
|
|
23
|
+
privateOutput,
|
|
24
|
+
cache,
|
|
25
|
+
annotateCode,
|
|
26
|
+
async beforePublish(publication) {
|
|
27
|
+
await verifyNativeWebInputs(root, publication);
|
|
28
|
+
await prepareNativeViews(root, publication, nativeRoutes);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
async function prepareNativeViews(root, publication, routes) {
|
|
33
|
+
await writePackageIslands(root, publication.documents);
|
|
34
|
+
const protectedModules = new Set(publication.protectedNativeModules);
|
|
35
|
+
const documents = publication.documents.map((document) => document.nativeView && protectedModules.has(document.nativeView.module) ? {
|
|
36
|
+
...document,
|
|
37
|
+
nativeView: void 0
|
|
38
|
+
} : document);
|
|
39
|
+
if (routes) return writeNativeRoutes(root, {
|
|
40
|
+
...publication,
|
|
41
|
+
documents
|
|
42
|
+
}, routes);
|
|
43
|
+
const { manifest } = publication;
|
|
44
|
+
const target = resolve(root, ".docs-sdk/next-native-views.mjs");
|
|
45
|
+
const entries = [...new Set(documents.flatMap((page) => page.nativeView ? [page.nativeView.module] : []))].sort().map((source) => {
|
|
46
|
+
const path = "./" + relative(dirname(target), resolve(root, source)).split(sep).join("/");
|
|
47
|
+
return ` [${JSON.stringify(source)}]: () => import(${JSON.stringify(path)}),`;
|
|
48
|
+
});
|
|
49
|
+
const code = [
|
|
50
|
+
"import 'server-only'",
|
|
51
|
+
"export const nativeViews = {",
|
|
52
|
+
` revision: ${JSON.stringify(manifest.buildRevision)},`,
|
|
53
|
+
" modules: {",
|
|
54
|
+
...entries,
|
|
55
|
+
" },",
|
|
56
|
+
"}",
|
|
57
|
+
""
|
|
58
|
+
].join("\n");
|
|
59
|
+
await mkdir(dirname(target), { recursive: true });
|
|
60
|
+
if (await readFile(target, "utf8").catch((error) => {
|
|
61
|
+
if (error.code !== "ENOENT") throw error;
|
|
62
|
+
}) === code) return;
|
|
63
|
+
const staged = target + "." + randomUUID();
|
|
64
|
+
try {
|
|
65
|
+
await writeFile(staged, code, {
|
|
66
|
+
flag: "wx",
|
|
67
|
+
mode: 384
|
|
68
|
+
});
|
|
69
|
+
await rename(staged, target);
|
|
70
|
+
} finally {
|
|
71
|
+
await rm(staged, { force: true });
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Run `next dev` over a publication that rebuilds as project inputs change. Each build is announced to open pages,
|
|
76
|
+
* and pages that render `DocsDevRefresh` from `@docs-sdk-dev/next/server` refresh in place.
|
|
77
|
+
*/
|
|
78
|
+
async function devNext(args = [], publication = defaultPublication, options = {}) {
|
|
79
|
+
const root = process.cwd();
|
|
80
|
+
const cache = createWebPublicationCache();
|
|
81
|
+
const events = await serveDevEvents();
|
|
82
|
+
let builds = 0;
|
|
83
|
+
let hinted = false;
|
|
84
|
+
try {
|
|
85
|
+
const close = await watchProjectInputs(root, async () => {
|
|
86
|
+
try {
|
|
87
|
+
const result = await preparePublication(root, publication, publicationOptions(options), cache);
|
|
88
|
+
console.log(`Prepared ${result.documents} documentation pages.`);
|
|
89
|
+
events.built(result.buildRevision, result.documents);
|
|
90
|
+
if (++builds > 1 && !hinted && events.listeners() === 0) {
|
|
91
|
+
hinted = true;
|
|
92
|
+
const hint = await devRefreshHint(root);
|
|
93
|
+
if (hint) console.log(hint);
|
|
94
|
+
}
|
|
95
|
+
} catch (error) {
|
|
96
|
+
events.failed(error);
|
|
97
|
+
throw error;
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
try {
|
|
101
|
+
const next = createRequire(import.meta.url).resolve("next/dist/bin/next");
|
|
102
|
+
const child = spawn(process.execPath, [
|
|
103
|
+
next,
|
|
104
|
+
"dev",
|
|
105
|
+
...args
|
|
106
|
+
], {
|
|
107
|
+
stdio: "inherit",
|
|
108
|
+
env: {
|
|
109
|
+
...process.env,
|
|
110
|
+
[devEventsVariable]: events.url
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
const stop = () => child.kill("SIGTERM");
|
|
114
|
+
process.once("SIGINT", stop);
|
|
115
|
+
process.once("SIGTERM", stop);
|
|
116
|
+
try {
|
|
117
|
+
if (await new Promise((resolve, reject) => {
|
|
118
|
+
child.once("error", reject);
|
|
119
|
+
child.once("exit", resolve);
|
|
120
|
+
})) throw new Error("Next dev failed.");
|
|
121
|
+
} finally {
|
|
122
|
+
process.off("SIGINT", stop);
|
|
123
|
+
process.off("SIGTERM", stop);
|
|
124
|
+
}
|
|
125
|
+
} finally {
|
|
126
|
+
await close();
|
|
127
|
+
}
|
|
128
|
+
} finally {
|
|
129
|
+
await events.close();
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
async function publicationRedirects(file) {
|
|
133
|
+
const { manifest } = JSON.parse(await readFile(file, "utf8"));
|
|
134
|
+
return (manifest.redirects ?? []).map(({ from, to }) => ({
|
|
135
|
+
source: from.replace(/\/$/, "") || "/",
|
|
136
|
+
destination: to,
|
|
137
|
+
permanent: true
|
|
138
|
+
}));
|
|
139
|
+
}
|
|
140
|
+
/** Mount the App Router at the public documentation URL declared by the compiled project. */
|
|
141
|
+
async function publicationBasePath(file) {
|
|
142
|
+
const { manifest } = JSON.parse(await readFile(file, "utf8"));
|
|
143
|
+
return manifest.basePath ?? "";
|
|
144
|
+
}
|
|
145
|
+
/** Give App Router discovery assets their public URLs after any host-owned files. */
|
|
146
|
+
function publicationDiscoveryRewrites() {
|
|
147
|
+
return { afterFiles: [{
|
|
148
|
+
source: "/:asset(robots\\.txt|sitemap(?:-[1-9][0-9]*)?\\.xml)",
|
|
149
|
+
destination: "/api/docs-discovery/:asset"
|
|
150
|
+
}] };
|
|
151
|
+
}
|
|
152
|
+
async function checkNextRenderedAnchors(directory = ".next") {
|
|
153
|
+
for (const entry of await readdir(join(directory, "server/app"), {
|
|
154
|
+
recursive: true,
|
|
155
|
+
withFileTypes: true
|
|
156
|
+
})) {
|
|
157
|
+
if (!entry.isFile() || !entry.name.endsWith(".html")) continue;
|
|
158
|
+
checkRenderedDocumentAnchors(await readFile(join(entry.parentPath, entry.name), "utf8"));
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
async function buildNext(args = [], directory = ".next", publication = defaultPublication, options = {}) {
|
|
162
|
+
const { nativeRoutes, privateOutput } = publicationOptions(options);
|
|
163
|
+
await prepareNativeViews(process.cwd(), await readNativeWebPublication(process.cwd(), publication, privateOutput), nativeRoutes);
|
|
164
|
+
const next = createRequire(import.meta.url).resolve("next/dist/bin/next");
|
|
165
|
+
const result = spawnSync(process.execPath, [
|
|
166
|
+
next,
|
|
167
|
+
"build",
|
|
168
|
+
...args
|
|
169
|
+
], { stdio: "inherit" });
|
|
170
|
+
if (result.error) throw result.error;
|
|
171
|
+
if (result.status !== 0) throw new Error("Next build failed.");
|
|
172
|
+
await readNativeWebPublication(process.cwd(), publication, privateOutput);
|
|
173
|
+
await checkNextRenderedAnchors(directory);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export { buildNext, buildPublication, checkNextRenderedAnchors, devNext, publicationBasePath, publicationDiscoveryRewrites, publicationRedirects };
|
|
177
|
+
//# sourceMappingURL=build.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build.js","names":[],"sources":["../src/build.ts"],"sourcesContent":["import { spawn, spawnSync } from \"node:child_process\"\nimport { mkdir, readdir, readFile, rename, rm, writeFile } from \"node:fs/promises\"\nimport { randomUUID } from \"node:crypto\"\nimport { createRequire } from \"node:module\"\nimport { dirname, join, relative, resolve, sep } from \"node:path\"\nimport {\n createWebPublicationCache,\n readNativeWebPublication,\n verifyNativeWebInputs,\n writeWebPublication,\n type NativeWebPublication,\n} from \"@docs-sdk-dev/node/internal/web-build\"\nimport { type WebPublication } from \"@docs-sdk-dev/node/publication\"\nimport { writePackageIslands } from \"@docs-sdk-dev/node\"\nimport type { CodeAnnotator } from \"@docs-sdk-dev/core\"\nimport { watchProjectInputs } from \"@docs-sdk-dev/node/internal/project-inputs\"\nimport { checkRenderedDocumentAnchors } from \"@docs-sdk-dev/web/content-anchors\"\nimport { writeNativeRoutes, type NativeRoutes } from \"./native-routes.js\"\nimport { devEventsVariable, devRefreshHint, serveDevEvents } from \"./dev-events.js\"\n\nexport type { NativeRoutes } from \"./native-routes.js\"\n\nconst defaultPublication = \".docs-sdk/next-publication.json\"\n\ninterface NextPublicationOptions {\n privateOutput?: string\n nativeRoutes?: NativeRoutes\n /**\n * Annotates `twoslash` code blocks while the publication is prepared, such as `createTwoslashAnnotator()` from\n * `@docs-sdk-dev/typescript/twoslash`. Pages then show types without running TypeScript on the server.\n */\n annotateCode?: CodeAnnotator\n}\ntype PublicationOptions = NativeRoutes | NextPublicationOptions\n\nfunction publicationOptions(options: PublicationOptions): NextPublicationOptions {\n return \"entry\" in options ? { nativeRoutes: options } : options\n}\n\nexport async function buildPublication(\n root = process.cwd(),\n output = defaultPublication,\n options: PublicationOptions = {},\n) {\n return preparePublication(root, output, publicationOptions(options))\n}\n\nasync function preparePublication(\n root: string,\n output: string,\n { nativeRoutes, privateOutput, annotateCode }: NextPublicationOptions,\n cache?: ReturnType<typeof createWebPublicationCache>,\n) {\n return writeWebPublication(root, output, undefined, {\n privateOutput,\n cache,\n annotateCode,\n async beforePublish(publication) {\n await verifyNativeWebInputs(root, publication)\n await prepareNativeViews(root, publication, nativeRoutes)\n },\n })\n}\n\nasync function prepareNativeViews(\n root: string,\n publication: NativeWebPublication,\n routes?: NativeRoutes,\n) {\n await writePackageIslands(root, publication.documents)\n const protectedModules = new Set(publication.protectedNativeModules)\n const documents = publication.documents.map((document) =>\n document.nativeView && protectedModules.has(document.nativeView.module)\n ? { ...document, nativeView: undefined }\n : document,\n )\n if (routes) return writeNativeRoutes(root, { ...publication, documents }, routes)\n const { manifest } = publication\n const target = resolve(root, \".docs-sdk/next-native-views.mjs\")\n const modules = new Set(\n documents.flatMap((page) => (page.nativeView ? [page.nativeView.module] : [])),\n )\n const entries = [...modules].sort().map((source) => {\n const path = \"./\" + relative(dirname(target), resolve(root, source)).split(sep).join(\"/\")\n return ` [${JSON.stringify(source)}]: () => import(${JSON.stringify(path)}),`\n })\n const code = [\n \"import 'server-only'\",\n \"export const nativeViews = {\",\n ` revision: ${JSON.stringify(manifest.buildRevision)},`,\n \" modules: {\",\n ...entries,\n \" },\",\n \"}\",\n \"\",\n ].join(\"\\n\")\n await mkdir(dirname(target), { recursive: true })\n const previous = await readFile(target, \"utf8\").catch((error: NodeJS.ErrnoException) => {\n if (error.code !== \"ENOENT\") throw error\n })\n if (previous === code) return\n const staged = target + \".\" + randomUUID()\n try {\n await writeFile(staged, code, { flag: \"wx\", mode: 0o600 })\n await rename(staged, target)\n } finally {\n await rm(staged, { force: true })\n }\n}\n\n/**\n * Run `next dev` over a publication that rebuilds as project inputs change. Each build is announced to open pages,\n * and pages that render `DocsDevRefresh` from `@docs-sdk-dev/next/server` refresh in place.\n */\nexport async function devNext(\n args: readonly string[] = [],\n publication = defaultPublication,\n options: PublicationOptions = {},\n) {\n const root = process.cwd()\n const cache = createWebPublicationCache()\n const events = await serveDevEvents()\n let builds = 0\n let hinted = false\n try {\n const close = await watchProjectInputs(root, async () => {\n try {\n const result = await preparePublication(\n root,\n publication,\n publicationOptions(options),\n cache,\n )\n console.log(`Prepared ${result.documents} documentation pages.`)\n events.built(result.buildRevision, result.documents)\n // A rebuild no open page heard is the moment a missing DocsDevRefresh matters; say so once.\n if (++builds > 1 && !hinted && events.listeners() === 0) {\n hinted = true\n const hint = await devRefreshHint(root)\n if (hint) console.log(hint)\n }\n } catch (error) {\n events.failed(error)\n throw error\n }\n })\n try {\n const next = createRequire(import.meta.url).resolve(\"next/dist/bin/next\")\n const child = spawn(process.execPath, [next, \"dev\", ...args], {\n stdio: \"inherit\",\n env: { ...process.env, [devEventsVariable]: events.url },\n })\n const stop = () => child.kill(\"SIGTERM\")\n process.once(\"SIGINT\", stop)\n process.once(\"SIGTERM\", stop)\n try {\n const status = await new Promise<number | null>((resolve, reject) => {\n child.once(\"error\", reject)\n child.once(\"exit\", resolve)\n })\n if (status) throw new Error(\"Next dev failed.\")\n } finally {\n process.off(\"SIGINT\", stop)\n process.off(\"SIGTERM\", stop)\n }\n } finally {\n await close()\n }\n } finally {\n await events.close()\n }\n}\n\nexport async function publicationRedirects(file: string) {\n const { manifest }: WebPublication = JSON.parse(await readFile(file, \"utf8\"))\n return (manifest.redirects ?? []).map(({ from, to }) => ({\n source: from.replace(/\\/$/, \"\") || \"/\",\n destination: to,\n permanent: true as const,\n }))\n}\n\n/** Mount the App Router at the public documentation URL declared by the compiled project. */\nexport async function publicationBasePath(file: string) {\n const { manifest }: WebPublication = JSON.parse(await readFile(file, \"utf8\"))\n return manifest.basePath ?? \"\"\n}\n\n/** Give App Router discovery assets their public URLs after any host-owned files. */\nexport function publicationDiscoveryRewrites() {\n return {\n afterFiles: [\n {\n source: \"/:asset(robots\\\\.txt|sitemap(?:-[1-9][0-9]*)?\\\\.xml)\",\n destination: \"/api/docs-discovery/:asset\",\n },\n ],\n }\n}\n\nexport async function checkNextRenderedAnchors(directory = \".next\") {\n for (const entry of await readdir(join(directory, \"server/app\"), {\n recursive: true,\n withFileTypes: true,\n })) {\n if (!entry.isFile() || !entry.name.endsWith(\".html\")) continue\n checkRenderedDocumentAnchors(await readFile(join(entry.parentPath, entry.name), \"utf8\"))\n }\n}\n\nexport async function buildNext(\n args: readonly string[] = [],\n directory = \".next\",\n publication = defaultPublication,\n options: PublicationOptions = {},\n) {\n const { nativeRoutes, privateOutput } = publicationOptions(options)\n await prepareNativeViews(\n process.cwd(),\n await readNativeWebPublication(process.cwd(), publication, privateOutput),\n nativeRoutes,\n )\n const next = createRequire(import.meta.url).resolve(\"next/dist/bin/next\")\n const result = spawnSync(process.execPath, [next, \"build\", ...args], { stdio: \"inherit\" })\n if (result.error) throw result.error\n if (result.status !== 0) throw new Error(\"Next build failed.\")\n await readNativeWebPublication(process.cwd(), publication, privateOutput)\n await checkNextRenderedAnchors(directory)\n}\n"],"mappings":";;;;;;;;;;;;;AAsBA,MAAM,qBAAqB;AAa3B,SAAS,mBAAmB,SAAqD;CAC/E,OAAO,WAAW,UAAU,EAAE,cAAc,QAAQ,IAAI;AAC1D;AAEA,eAAsB,iBACpB,OAAO,QAAQ,IAAI,GACnB,SAAS,oBACT,UAA8B,CAAC,GAC/B;CACA,OAAO,mBAAmB,MAAM,QAAQ,mBAAmB,OAAO,CAAC;AACrE;AAEA,eAAe,mBACb,MACA,QACA,EAAE,cAAc,eAAe,gBAC/B,OACA;CACA,OAAO,oBAAoB,MAAM,QAAQ,QAAW;EAClD;EACA;EACA;EACA,MAAM,cAAc,aAAa;GAC/B,MAAM,sBAAsB,MAAM,WA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,CAAC,QAAQ,oBAAoB;CACxE,MAAM,SAAS,UAAU,QAAQ,UAAU;EAAC;EAAM;EAAS,GAAG;CAAI,GAAG,EAAE,OAAO,UAAU,CAAC;CACzF,IAAI,OAAO,OAAO,MAAM,OAAO;CAC/B,IAAI,OAAO,WAAW,GAAG,MAAM,IAAI,MAAM,oBAAoB;CAC7D,MAAM,yBAAyB,QAAQ,IAAI,GAAG,aAAa,aAAa;CACxE,MAAM,yBAAyB,SAAS;AAC1C"}
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import type { DocsLink } from "@docs-sdk-dev/react/server";
|
|
3
|
+
/** A native App Router link that can warm the next page's public resource graph after intent. */
|
|
4
|
+
export declare function IslandNavigationLink({ href, rel, endpoint, ...props }: Parameters<DocsLink>[0] & {
|
|
5
|
+
endpoint: string;
|
|
6
|
+
}): ReactNode;
|
|
7
|
+
export { PersistenceProvider } from "@docs-sdk-dev/react/client";
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import Link from "next/link.js";
|
|
4
|
+
import { createElement, useEffect, useRef } from "react";
|
|
5
|
+
import { PersistenceProvider } from "@docs-sdk-dev/react/client";
|
|
6
|
+
|
|
7
|
+
// src/client.ts
|
|
8
|
+
const NativeLink = Link;
|
|
9
|
+
/** A native App Router link that can warm the next page's public resource graph after intent. */
|
|
10
|
+
function IslandNavigationLink({ href, rel, endpoint, ...props }) {
|
|
11
|
+
const attempt = useRef(null);
|
|
12
|
+
useEffect(() => () => {
|
|
13
|
+
attempt.current?.abort();
|
|
14
|
+
attempt.current = null;
|
|
15
|
+
}, [
|
|
16
|
+
href,
|
|
17
|
+
rel,
|
|
18
|
+
endpoint
|
|
19
|
+
]);
|
|
20
|
+
function warmNext() {
|
|
21
|
+
if (rel !== "next" || attempt.current) return;
|
|
22
|
+
const route = new URL(href, location.origin);
|
|
23
|
+
const url = new URL(endpoint, location.origin);
|
|
24
|
+
if (route.origin !== location.origin || url.origin !== location.origin || url.username || url.password) return;
|
|
25
|
+
url.hash = "";
|
|
26
|
+
url.pathname = url.pathname.replace(/\/$/, "") + route.pathname.replace(/\/$/, "");
|
|
27
|
+
const lifetime = new AbortController();
|
|
28
|
+
attempt.current = lifetime;
|
|
29
|
+
import("@docs-sdk-dev/web/internal/resource-scheduler").then(async ({ scheduleResourceOperation }) => {
|
|
30
|
+
const plan = await scheduleResourceOperation(document, {
|
|
31
|
+
key: "next:public-island-plan:" + url.href,
|
|
32
|
+
bytes: 4096,
|
|
33
|
+
reason: "navigation",
|
|
34
|
+
signal: lifetime.signal
|
|
35
|
+
}, async (operation) => {
|
|
36
|
+
const response = await fetch(url, {
|
|
37
|
+
signal: AbortSignal.any([operation, AbortSignal.timeout(1e4)]),
|
|
38
|
+
credentials: "omit",
|
|
39
|
+
redirect: "error",
|
|
40
|
+
priority: "low"
|
|
41
|
+
});
|
|
42
|
+
if (response.status === 404) return null;
|
|
43
|
+
if (!response.ok) throw new Error("Preview resources unavailable.");
|
|
44
|
+
return await response.json();
|
|
45
|
+
});
|
|
46
|
+
if (plan === void 0) {
|
|
47
|
+
if (attempt.current === lifetime) attempt.current = null;
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
if (plan && !lifetime.signal.aborted) {
|
|
51
|
+
const { createIslandPreloader } = await import("@docs-sdk-dev/web/islands");
|
|
52
|
+
if (!lifetime.signal.aborted) createIslandPreloader(document, { signal: lifetime.signal }).preload(plan, "navigation");
|
|
53
|
+
}
|
|
54
|
+
}).catch(() => {
|
|
55
|
+
if (attempt.current === lifetime) attempt.current = null;
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
return createElement(NativeLink, {
|
|
59
|
+
...props,
|
|
60
|
+
href,
|
|
61
|
+
rel,
|
|
62
|
+
onPointerEnter: warmNext,
|
|
63
|
+
onFocus: warmNext,
|
|
64
|
+
onTouchStart: warmNext
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export { IslandNavigationLink, PersistenceProvider };
|
|
69
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","names":[],"sources":["../src/client.ts"],"sourcesContent":["\"use client\"\n\nimport Link, { type LinkProps } from \"next/link.js\"\nimport {\n createElement,\n useEffect,\n useRef,\n type AnchorHTMLAttributes,\n type ComponentType,\n type ReactNode,\n} from \"react\"\nimport type { DocsLink } from \"@docs-sdk-dev/react/server\"\nimport type { IslandResource } from \"@docs-sdk-dev/web/islands\"\n\n// Next exposes the same CommonJS default to NodeNext and bundlers with different declaration shapes.\nconst NativeLink = Link as unknown as ComponentType<\n LinkProps & Omit<AnchorHTMLAttributes<HTMLAnchorElement>, keyof LinkProps>\n>\n\n/** A native App Router link that can warm the next page's public resource graph after intent. */\nexport function IslandNavigationLink({\n href,\n rel,\n endpoint,\n ...props\n}: Parameters<DocsLink>[0] & { endpoint: string }): ReactNode {\n const attempt = useRef<AbortController>(null)\n useEffect(\n () => () => {\n attempt.current?.abort()\n attempt.current = null\n },\n [href, rel, endpoint],\n )\n function warmNext() {\n if (rel !== \"next\" || attempt.current) return\n const route = new URL(href, location.origin)\n const url = new URL(endpoint, location.origin)\n if (\n route.origin !== location.origin ||\n url.origin !== location.origin ||\n url.username ||\n url.password\n )\n return\n url.hash = \"\"\n url.pathname = url.pathname.replace(/\\/$/, \"\") + route.pathname.replace(/\\/$/, \"\")\n const lifetime = new AbortController()\n attempt.current = lifetime\n void import(\"@docs-sdk-dev/web/internal/resource-scheduler\")\n .then(async ({ scheduleResourceOperation }) => {\n const plan = await scheduleResourceOperation(\n document,\n {\n key: \"next:public-island-plan:\" + url.href,\n bytes: 4 * 1024,\n reason: \"navigation\",\n signal: lifetime.signal,\n },\n async (operation): Promise<IslandResource | null> => {\n const response = await fetch(url, {\n signal: AbortSignal.any([operation, AbortSignal.timeout(10_000)]),\n credentials: \"omit\",\n redirect: \"error\",\n priority: \"low\",\n })\n if (response.status === 404) return null\n if (!response.ok) throw new Error(\"Preview resources unavailable.\")\n return (await response.json()) as IslandResource\n },\n )\n if (plan === undefined) {\n if (attempt.current === lifetime) attempt.current = null\n return\n }\n if (plan && !lifetime.signal.aborted) {\n const { createIslandPreloader } = await import(\"@docs-sdk-dev/web/islands\")\n if (!lifetime.signal.aborted)\n createIslandPreloader(document, { signal: lifetime.signal }).preload(plan, \"navigation\")\n }\n })\n .catch(() => {\n if (attempt.current === lifetime) attempt.current = null\n })\n }\n return createElement(NativeLink, {\n ...props,\n href,\n rel,\n onPointerEnter: warmNext,\n onFocus: warmNext,\n onTouchStart: warmNext,\n })\n}\n\nexport { PersistenceProvider } from \"@docs-sdk-dev/react/client\"\n"],"mappings":";;;;;;;AAeA,MAAM,aAAa;;AAKnB,SAAgB,qBAAqB,EACnC,MACA,KACA,UACA,GAAG,SACyD;CAC5D,MAAM,UAAU,OAAwB,IAAI;CAC5C,sBACc;EACV,QAAQ,SAAS,MAAM;EACvB,QAAQ,UAAU;CACpB,GACA;EAAC;EAAM;EAAK;CAAQ,CACtB;CACA,SAAS,WAAW;EAClB,IAAI,QAAQ,UAAU,QAAQ,SAAS;EACvC,MAAM,QAAQ,IAAI,IAAI,MAAM,SAAS,MAAM;EAC3C,MAAM,MAAM,IAAI,IAAI,UAAU,SAAS,MAAM;EAC7C,IACE,MAAM,WAAW,SAAS,UAC1B,IAAI,WAAW,SAAS,UACxB,IAAI,YACJ,IAAI,UAEJ;EACF,IAAI,OAAO;EACX,IAAI,WAAW,IAAI,SAAS,QAAQ,OAAO,EAAE,IAAI,MAAM,SAAS,QAAQ,OAAO,EAAE;EACjF,MAAM,WAAW,IAAI,gBAAgB;EACrC,QAAQ,UAAU;EACb,OAAO,gDAAgD,CACzD,KAAK,OAAO,EAAE,gCAAgC;GAC7C,MAAM,OAAO,MAAM,0BACjB,UACA;IACE,KAAK,6BAA6B,IAAI;I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