vinext 0.1.4 → 0.1.6
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/README.md +2 -2
- package/dist/build/css-url-assets.d.ts +1 -1
- package/dist/build/css-url-assets.js +9 -7
- package/dist/build/google-fonts/find-font-files-in-css.d.ts +16 -0
- package/dist/build/google-fonts/find-font-files-in-css.js +28 -0
- package/dist/build/prerender.js +2 -1
- package/dist/build/report.d.ts +1 -2
- package/dist/build/report.js +2 -11
- package/dist/build/run-prerender.js +1 -1
- package/dist/cache/cache-adapters-virtual.js +1 -1
- package/dist/check.js +3 -3
- package/dist/client/pages-router-link-navigation.d.ts +10 -0
- package/dist/client/pages-router-link-navigation.js +3 -3
- package/dist/cloudflare/src/cache/kv-data-adapter.runtime.d.ts +1 -1
- package/dist/deploy.js +3 -3
- package/dist/entries/app-rsc-entry.js +25 -20
- package/dist/entries/app-rsc-manifest.js +76 -46
- package/dist/entries/pages-server-entry.js +3 -1
- package/dist/index.js +254 -198
- package/dist/init.d.ts +5 -4
- package/dist/init.js +27 -8
- package/dist/plugins/css-data-url.js +30 -26
- package/dist/plugins/extensionless-dynamic-import.js +27 -24
- package/dist/plugins/fonts.js +3 -1
- package/dist/plugins/import-meta-url.js +21 -15
- package/dist/plugins/instrumentation-client.js +1 -1
- package/dist/plugins/middleware-export-validation.d.ts +5 -0
- package/dist/plugins/middleware-export-validation.js +36 -0
- package/dist/plugins/middleware-server-only.js +7 -6
- package/dist/plugins/og-asset-ownership.d.ts +27 -0
- package/dist/plugins/og-asset-ownership.js +285 -0
- package/dist/plugins/og-assets.js +66 -46
- package/dist/plugins/optimize-imports.js +9 -3
- package/dist/plugins/remove-console.d.ts +7 -1
- package/dist/plugins/remove-console.js +4 -1
- package/dist/plugins/require-context.js +21 -20
- package/dist/plugins/strip-server-exports.d.ts +7 -1
- package/dist/plugins/strip-server-exports.js +4 -1
- package/dist/server/accept-encoding.d.ts +29 -0
- package/dist/server/accept-encoding.js +95 -0
- package/dist/server/app-bfcache-identity.d.ts +26 -0
- package/dist/server/app-bfcache-identity.js +127 -0
- package/dist/server/app-browser-entry.js +17 -11
- package/dist/server/app-browser-rsc-redirect.d.ts +2 -1
- package/dist/server/app-browser-rsc-redirect.js +8 -1
- package/dist/server/app-browser-state.d.ts +2 -21
- package/dist/server/app-browser-state.js +4 -128
- package/dist/server/app-browser-stream.js +1 -1
- package/dist/server/app-browser-visible-commit.js +3 -2
- package/dist/server/app-fallback-renderer.d.ts +1 -1
- package/dist/server/app-layout-param-observation.d.ts +1 -1
- package/dist/server/app-layout-param-observation.js +1 -1
- package/dist/server/app-middleware.d.ts +1 -0
- package/dist/server/app-middleware.js +3 -1
- package/dist/server/app-page-boundary-render.d.ts +1 -1
- package/dist/server/app-page-boundary.js +1 -1
- package/dist/server/app-page-cache-finalizer.d.ts +62 -0
- package/dist/server/app-page-cache-finalizer.js +122 -0
- package/dist/server/app-page-cache-render.d.ts +2 -2
- package/dist/server/app-page-cache-render.js +1 -1
- package/dist/server/app-page-cache.d.ts +2 -53
- package/dist/server/app-page-cache.js +5 -131
- package/dist/server/app-page-dispatch.d.ts +4 -4
- package/dist/server/app-page-dispatch.js +10 -8
- package/dist/server/app-page-head.js +2 -2
- package/dist/server/app-page-probe.js +3 -2
- package/dist/server/app-page-render-observation.js +2 -2
- package/dist/server/app-page-render.d.ts +3 -3
- package/dist/server/app-page-render.js +3 -2
- package/dist/server/app-page-request.d.ts +7 -0
- package/dist/server/app-page-request.js +19 -1
- package/dist/server/app-page-stream.d.ts +2 -9
- package/dist/server/app-page-stream.js +1 -35
- package/dist/server/app-prerender-endpoints.d.ts +3 -3
- package/dist/server/app-prerender-endpoints.js +3 -4
- package/dist/server/app-request-context.d.ts +1 -2
- package/dist/server/app-request-context.js +2 -1
- package/dist/server/app-route-handler-dispatch.js +3 -2
- package/dist/server/app-route-handler-execution.d.ts +1 -1
- package/dist/server/app-route-handler-execution.js +1 -1
- package/dist/server/app-route-handler-response.d.ts +1 -1
- package/dist/server/app-route-module-loader.d.ts +62 -14
- package/dist/server/app-route-module-loader.js +61 -10
- package/dist/server/app-router-entry.js +2 -1
- package/dist/server/app-rsc-handler.d.ts +7 -6
- package/dist/server/app-rsc-handler.js +51 -40
- package/dist/server/app-rsc-response-finalizer.js +1 -1
- package/dist/server/app-rsc-route-matching.d.ts +9 -0
- package/dist/server/app-rsc-route-matching.js +13 -0
- package/dist/server/app-server-action-execution.d.ts +1 -1
- package/dist/server/app-server-action-execution.js +5 -4
- package/dist/server/app-ssr-entry.d.ts +1 -1
- package/dist/server/app-ssr-entry.js +9 -7
- package/dist/server/app-ssr-router-instance.d.ts +6 -0
- package/dist/server/app-ssr-router-instance.js +24 -0
- package/dist/server/app-ssr-stream.js +1 -1
- package/dist/server/artifact-compatibility.js +1 -1
- package/dist/server/client-reuse-manifest.js +1 -1
- package/dist/server/defer-until-stream-consumed.d.ts +7 -0
- package/dist/server/defer-until-stream-consumed.js +34 -0
- package/dist/server/dev-server.js +1 -1
- package/dist/server/headers.d.ts +5 -1
- package/dist/server/headers.js +5 -1
- package/dist/server/instrumentation.js +1 -1
- package/dist/server/isr-cache.d.ts +1 -1
- package/dist/server/isr-cache.js +1 -1
- package/dist/server/isr-decision.d.ts +1 -1
- package/dist/server/metadata-route-response.d.ts +3 -3
- package/dist/server/middleware-matcher.js +8 -6
- package/dist/server/middleware-runtime.d.ts +2 -1
- package/dist/server/middleware-runtime.js +21 -10
- package/dist/server/middleware.d.ts +2 -2
- package/dist/server/middleware.js +26 -11
- package/dist/server/open-redirect.d.ts +12 -0
- package/dist/server/open-redirect.js +21 -0
- package/dist/server/pages-page-data.d.ts +1 -1
- package/dist/server/pages-page-response.d.ts +1 -1
- package/dist/server/pages-page-response.js +2 -2
- package/dist/server/pages-request-pipeline.d.ts +3 -1
- package/dist/server/pages-request-pipeline.js +4 -2
- package/dist/server/prod-server.d.ts +1 -1
- package/dist/server/prod-server.js +87 -73
- package/dist/server/request-pipeline.d.ts +1 -24
- package/dist/server/request-pipeline.js +1 -33
- package/dist/server/seed-cache.d.ts +1 -1
- package/dist/shims/cache-handler.d.ts +106 -0
- package/dist/shims/cache-handler.js +176 -0
- package/dist/shims/cache-request-state.d.ts +47 -0
- package/dist/shims/cache-request-state.js +126 -0
- package/dist/shims/cache-runtime.d.ts +2 -2
- package/dist/shims/cache-runtime.js +3 -14
- package/dist/shims/cache.d.ts +3 -231
- package/dist/shims/cache.js +17 -383
- package/dist/shims/cdn-cache.d.ts +1 -1
- package/dist/shims/cdn-cache.js +1 -1
- package/dist/shims/error-boundary-navigation.d.ts +7 -0
- package/dist/shims/error-boundary-navigation.js +44 -0
- package/dist/shims/error-boundary.js +10 -8
- package/dist/shims/error.js +2 -1
- package/dist/shims/fetch-cache.js +1 -1
- package/dist/shims/font-google-base.d.ts +1 -0
- package/dist/shims/font-google-base.js +6 -21
- package/dist/shims/form.js +1 -1
- package/dist/shims/image.js +67 -9
- package/dist/shims/internal/app-page-props-cache-key.d.ts +5 -0
- package/dist/shims/internal/app-page-props-cache-key.js +16 -0
- package/dist/shims/internal/interpolate-as.d.ts +25 -0
- package/dist/shims/internal/interpolate-as.js +196 -0
- package/dist/shims/internal/navigation-untracked.js +2 -1
- package/dist/shims/layout-segment-context.d.ts +1 -1
- package/dist/shims/layout-segment-context.js +2 -1
- package/dist/shims/link.js +26 -3
- package/dist/shims/navigation-context-state.d.ts +40 -0
- package/dist/shims/navigation-context-state.js +116 -0
- package/dist/shims/navigation-errors.d.ts +55 -0
- package/dist/shims/navigation-errors.js +110 -0
- package/dist/shims/navigation-server.d.ts +3 -0
- package/dist/shims/navigation-server.js +3 -0
- package/dist/shims/navigation-state.d.ts +1 -2
- package/dist/shims/navigation-state.js +2 -1
- package/dist/shims/navigation.d.ts +3 -291
- package/dist/shims/navigation.js +13 -444
- package/dist/shims/navigation.react-server.d.ts +2 -2
- package/dist/shims/navigation.react-server.js +4 -2
- package/dist/shims/request-state-types.d.ts +3 -3
- package/dist/shims/router.d.ts +1 -3
- package/dist/shims/router.js +62 -18
- package/dist/shims/script.js +1 -1
- package/dist/shims/slot.js +3 -1
- package/dist/shims/unified-request-context.d.ts +2 -2
- package/dist/typegen.js +2 -10
- package/dist/utils/project.d.ts +7 -1
- package/dist/utils/project.js +16 -2
- package/dist/utils/virtual-module.d.ts +5 -0
- package/dist/utils/virtual-module.js +0 -0
- package/package.json +7 -3
package/dist/init.d.ts
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* 4. Rename CJS config files to .cjs
|
|
11
11
|
* 5. Add vinext scripts to package.json
|
|
12
12
|
* 6. Generate vite.config.ts
|
|
13
|
-
* 7. Update .gitignore to include /dist/
|
|
13
|
+
* 7. Update .gitignore to include /dist/ and .vinext/
|
|
14
14
|
* 8. Print summary
|
|
15
15
|
*
|
|
16
16
|
* Non-destructive: does NOT modify next.config, tsconfig, or source files.
|
|
@@ -32,7 +32,7 @@ type InitResult = {
|
|
|
32
32
|
renamedConfigs: Array<[string, string]>; /** Whether scripts were added to package.json */
|
|
33
33
|
addedScripts: string[]; /** Whether vite.config.ts was generated */
|
|
34
34
|
generatedViteConfig: boolean; /** Whether vite.config.ts generation was skipped (already exists) */
|
|
35
|
-
skippedViteConfig: boolean; /** Whether .gitignore was updated to include
|
|
35
|
+
skippedViteConfig: boolean; /** Whether .gitignore was updated to include vinext-generated output */
|
|
36
36
|
updatedGitignore: boolean;
|
|
37
37
|
};
|
|
38
38
|
declare function generateViteConfig(_isAppRouter: boolean): string;
|
|
@@ -59,8 +59,9 @@ declare function isDepInstalled(root: string, dep: string): boolean;
|
|
|
59
59
|
*/
|
|
60
60
|
declare function getReactUpgradeDeps(root: string): string[];
|
|
61
61
|
/**
|
|
62
|
-
* Ensure
|
|
63
|
-
*
|
|
62
|
+
* Ensure vinext-generated output directories are listed in .gitignore.
|
|
63
|
+
* Creates the file if it doesn't exist. Returns true if the file was modified
|
|
64
|
+
* (or created), false if all entries were already present.
|
|
64
65
|
*/
|
|
65
66
|
declare function updateGitignore(root: string): boolean;
|
|
66
67
|
declare function init(options: InitOptions): Promise<InitResult>;
|
package/dist/init.js
CHANGED
|
@@ -16,7 +16,7 @@ import { execFileSync } from "node:child_process";
|
|
|
16
16
|
* 4. Rename CJS config files to .cjs
|
|
17
17
|
* 5. Add vinext scripts to package.json
|
|
18
18
|
* 6. Generate vite.config.ts
|
|
19
|
-
* 7. Update .gitignore to include /dist/
|
|
19
|
+
* 7. Update .gitignore to include /dist/ and .vinext/
|
|
20
20
|
* 8. Print summary
|
|
21
21
|
*
|
|
22
22
|
* Non-destructive: does NOT modify next.config, tsconfig, or source files.
|
|
@@ -140,20 +140,39 @@ function installDeps(root, deps, exec, { dev = true } = {}) {
|
|
|
140
140
|
});
|
|
141
141
|
}
|
|
142
142
|
/**
|
|
143
|
-
* Ensure
|
|
144
|
-
*
|
|
143
|
+
* Ensure vinext-generated output directories are listed in .gitignore.
|
|
144
|
+
* Creates the file if it doesn't exist. Returns true if the file was modified
|
|
145
|
+
* (or created), false if all entries were already present.
|
|
145
146
|
*/
|
|
146
147
|
function updateGitignore(root) {
|
|
147
148
|
const gitignorePath = path.join(root, ".gitignore");
|
|
148
|
-
const
|
|
149
|
+
const entries = [{
|
|
150
|
+
entry: "/dist/",
|
|
151
|
+
coveredBy: new Set([
|
|
152
|
+
"/dist/",
|
|
153
|
+
"/dist",
|
|
154
|
+
"dist/",
|
|
155
|
+
"dist"
|
|
156
|
+
])
|
|
157
|
+
}, {
|
|
158
|
+
entry: ".vinext/",
|
|
159
|
+
coveredBy: new Set([
|
|
160
|
+
"/.vinext/",
|
|
161
|
+
"/.vinext",
|
|
162
|
+
".vinext/",
|
|
163
|
+
".vinext"
|
|
164
|
+
])
|
|
165
|
+
}];
|
|
149
166
|
let content = "";
|
|
167
|
+
let lines = [];
|
|
150
168
|
if (fs.existsSync(gitignorePath)) {
|
|
151
169
|
content = fs.readFileSync(gitignorePath, "utf-8");
|
|
152
|
-
|
|
153
|
-
if (lines.includes(exactEntry) || lines.includes("dist/") || lines.includes("dist")) return false;
|
|
170
|
+
lines = content.split("\n").map((l) => l.trim());
|
|
154
171
|
}
|
|
172
|
+
const missingEntries = entries.filter(({ coveredBy }) => !lines.some((line) => coveredBy.has(line))).map(({ entry }) => entry);
|
|
173
|
+
if (missingEntries.length === 0) return false;
|
|
155
174
|
const separator = content.length > 0 && !content.endsWith("\n") ? "\n" : "";
|
|
156
|
-
fs.writeFileSync(gitignorePath, content + separator + "
|
|
175
|
+
fs.writeFileSync(gitignorePath, content + separator + missingEntries.join("\n") + "\n", "utf-8");
|
|
157
176
|
return true;
|
|
158
177
|
}
|
|
159
178
|
async function init(options) {
|
|
@@ -212,7 +231,7 @@ async function init(options) {
|
|
|
212
231
|
for (const script of addedScripts) console.log(` \u2713 Added ${script} script`);
|
|
213
232
|
if (generatedViteConfig) console.log(` \u2713 Generated vite.config.ts`);
|
|
214
233
|
if (skippedViteConfig) console.log(` - Skipped vite.config.ts (already exists, use --force to overwrite)`);
|
|
215
|
-
if (updatedGitignore) console.log(` \u2713 Added
|
|
234
|
+
if (updatedGitignore) console.log(` \u2713 Added vinext output directories to .gitignore`);
|
|
216
235
|
console.log(`
|
|
217
236
|
Next steps:
|
|
218
237
|
${pmName} run dev:vinext Start the vinext dev server
|
|
@@ -36,33 +36,37 @@ function dataUrlCssPlugin() {
|
|
|
36
36
|
return {
|
|
37
37
|
name: "vinext:css-data-url",
|
|
38
38
|
enforce: "pre",
|
|
39
|
-
transform
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
css
|
|
56
|
-
|
|
39
|
+
transform: {
|
|
40
|
+
filter: {
|
|
41
|
+
id: { exclude: new RegExp(`^${VIRTUAL_PREFIX}`) },
|
|
42
|
+
code: DATA_URL_HINT
|
|
43
|
+
},
|
|
44
|
+
handler(code, id) {
|
|
45
|
+
let mutated = false;
|
|
46
|
+
const rewritten = code.replace(DATA_URL_IMPORT_RE, (_match, quote, moduleFlag, base64Flag, payload) => {
|
|
47
|
+
const isModule = moduleFlag === "+module";
|
|
48
|
+
const isBase64 = base64Flag === ";base64";
|
|
49
|
+
let css;
|
|
50
|
+
try {
|
|
51
|
+
css = decode(payload, isBase64);
|
|
52
|
+
} catch (err) {
|
|
53
|
+
throw new Error(`[vinext] Failed to decode CSS data URL import in ${id}: ${err.message}`);
|
|
54
|
+
}
|
|
55
|
+
const ext = isModule ? ".module.css" : ".css";
|
|
56
|
+
const syntheticId = `${VIRTUAL_PREFIX}${hash(css + ext)}${ext}`;
|
|
57
|
+
entries.set(syntheticId, {
|
|
58
|
+
css,
|
|
59
|
+
isModule
|
|
60
|
+
});
|
|
61
|
+
mutated = true;
|
|
62
|
+
return `${quote}${syntheticId}${quote}`;
|
|
57
63
|
});
|
|
58
|
-
mutated
|
|
59
|
-
return
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
map: null
|
|
65
|
-
};
|
|
64
|
+
if (!mutated) return null;
|
|
65
|
+
return {
|
|
66
|
+
code: rewritten,
|
|
67
|
+
map: null
|
|
68
|
+
};
|
|
69
|
+
}
|
|
66
70
|
},
|
|
67
71
|
resolveId(id) {
|
|
68
72
|
if (id.startsWith(VIRTUAL_PREFIX)) return id;
|
|
@@ -29,28 +29,34 @@ function createExtensionlessDynamicImportPlugin() {
|
|
|
29
29
|
configResolved(config) {
|
|
30
30
|
moduleExtensions = getModuleExtensions(config);
|
|
31
31
|
},
|
|
32
|
-
transform
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
32
|
+
transform: {
|
|
33
|
+
filter: {
|
|
34
|
+
id: {
|
|
35
|
+
include: /\.(?:[cm]?[jt]s|[jt]sx)(?:\?.*)?$/i,
|
|
36
|
+
exclude: /[\\/]node_modules[\\/]/
|
|
37
|
+
},
|
|
38
|
+
code: /\bimport\s*\(/
|
|
39
|
+
},
|
|
40
|
+
handler(code, id) {
|
|
41
|
+
const lang = langForId(id);
|
|
42
|
+
let ast;
|
|
43
|
+
try {
|
|
44
|
+
ast = parseAst(code, { lang });
|
|
45
|
+
} catch {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
const imports = collectExtensionlessImports(ast, code, moduleExtensions);
|
|
49
|
+
if (imports.length === 0) return null;
|
|
50
|
+
const output = new MagicString(code);
|
|
51
|
+
for (const dynamicImport of imports) {
|
|
52
|
+
const source = code.slice(dynamicImport.sourceStart, dynamicImport.sourceEnd);
|
|
53
|
+
output.overwrite(dynamicImport.start, dynamicImport.end, buildReplacement(source, dynamicImport.globPattern, dynamicImport.moduleExtensions));
|
|
54
|
+
}
|
|
55
|
+
return {
|
|
56
|
+
code: output.toString(),
|
|
57
|
+
map: output.generateMap({ hires: "boundary" })
|
|
58
|
+
};
|
|
42
59
|
}
|
|
43
|
-
const imports = collectExtensionlessImports(ast, code, moduleExtensions);
|
|
44
|
-
if (imports.length === 0) return null;
|
|
45
|
-
const output = new MagicString(code);
|
|
46
|
-
for (const dynamicImport of imports) {
|
|
47
|
-
const source = code.slice(dynamicImport.sourceStart, dynamicImport.sourceEnd);
|
|
48
|
-
output.overwrite(dynamicImport.start, dynamicImport.end, buildReplacement(source, dynamicImport.globPattern, dynamicImport.moduleExtensions));
|
|
49
|
-
}
|
|
50
|
-
return {
|
|
51
|
-
code: output.toString(),
|
|
52
|
-
map: output.generateMap({ hires: "boundary" })
|
|
53
|
-
};
|
|
54
60
|
}
|
|
55
61
|
};
|
|
56
62
|
}
|
|
@@ -64,9 +70,6 @@ function langForId(id) {
|
|
|
64
70
|
if (ext === ".tsx") return "tsx";
|
|
65
71
|
return "jsx";
|
|
66
72
|
}
|
|
67
|
-
function isDependencyId(id) {
|
|
68
|
-
return id.split("?", 1)[0].replaceAll("\\", "/").includes("/node_modules/");
|
|
69
|
-
}
|
|
70
73
|
function collectExtensionlessImports(ast, code, moduleExtensions) {
|
|
71
74
|
const imports = [];
|
|
72
75
|
function visit(value) {
|
package/dist/plugins/fonts.js
CHANGED
|
@@ -4,6 +4,7 @@ import { buildFallbackFontFace, getFallbackFontOverrideMetrics } from "../build/
|
|
|
4
4
|
import { validateGoogleFontOptions } from "../build/google-fonts/validate.js";
|
|
5
5
|
import { getFontAxes } from "../build/google-fonts/get-axes.js";
|
|
6
6
|
import { buildGoogleFontsUrl } from "../build/google-fonts/build-url.js";
|
|
7
|
+
import { findFontFilesInCss } from "../build/google-fonts/find-font-files-in-css.js";
|
|
7
8
|
import { ASSET_PREFIX_URL_DIR } from "../utils/asset-prefix.js";
|
|
8
9
|
import { CONTENT_TYPES } from "../server/static-file-cache.js";
|
|
9
10
|
import fs from "node:fs";
|
|
@@ -543,11 +544,12 @@ function createGoogleFontsPlugin(fontGoogleShimPath, shimsDir) {
|
|
|
543
544
|
return;
|
|
544
545
|
}
|
|
545
546
|
const servedCSS = _rewriteCachedFontCssToServedUrls(localCSS, cacheDir, transformAssetsDir);
|
|
547
|
+
const preloadUrls = findFontFilesInCss(servedCSS, validated.preload ? validated.subsets : void 0).filter((file) => file.preloadFontFile).map((file) => file.googleFontFileUrl);
|
|
546
548
|
const fallbackMetrics = validated.adjustFontFallback === false ? void 0 : getFallbackFontOverrideMetrics(family);
|
|
547
549
|
const adjustedFallbackCSS = fallbackMetrics ? buildFallbackFontFace(family, fallbackMetrics) : void 0;
|
|
548
550
|
const validatedFontWeight = validated.weights.length === 1 && validated.weights[0] !== "variable" ? Number(validated.weights[0]) : void 0;
|
|
549
551
|
const validatedFontStyle = validated.styles.length === 1 ? validated.styles[0] : void 0;
|
|
550
|
-
const internalFontProperties = [`selfHostedCSS: ${JSON.stringify(servedCSS)}`];
|
|
552
|
+
const internalFontProperties = [`selfHostedCSS: ${JSON.stringify(servedCSS)}`, `preloadUrls: ${JSON.stringify(preloadUrls)}`];
|
|
551
553
|
if (adjustedFallbackCSS) internalFontProperties.push(`adjustedFallbackCSS: ${JSON.stringify(adjustedFallbackCSS)}`);
|
|
552
554
|
if (Number.isFinite(validatedFontWeight)) internalFontProperties.push(`fontWeight: ${validatedFontWeight}`);
|
|
553
555
|
if (validatedFontStyle) internalFontProperties.push(`fontStyle: ${JSON.stringify(validatedFontStyle)}`);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { VIRTUAL_MODULE_ID_RE } from "../utils/virtual-module.js";
|
|
1
2
|
import { collectBindingNames, forEachAstChild, hasRange, isAstRecord, isIdentifierNamed, nodeArray } from "./ast-utils.js";
|
|
2
3
|
import { tryRealpathSync } from "../build/ssr-manifest.js";
|
|
3
4
|
import path from "node:path";
|
|
@@ -32,18 +33,26 @@ function createImportMetaUrlPlugin(options) {
|
|
|
32
33
|
outputDirs = [config.build.outDir];
|
|
33
34
|
rootPaths = createRootPaths(root, { outputDirs });
|
|
34
35
|
},
|
|
35
|
-
transform
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
36
|
+
transform: {
|
|
37
|
+
filter: {
|
|
38
|
+
id: {
|
|
39
|
+
include: /\.(?:[cm]?[jt]s|[jt]sx)(?:\?.*)?$/,
|
|
40
|
+
exclude: [/[\\/]node_modules[\\/]/, VIRTUAL_MODULE_ID_RE]
|
|
41
|
+
},
|
|
42
|
+
code: /import\.meta(?:\.|\?\.)url|__filename|__dirname/
|
|
43
|
+
},
|
|
44
|
+
handler(code, id) {
|
|
45
|
+
const paths = getRootPaths();
|
|
46
|
+
if (!paths) return null;
|
|
47
|
+
const canonicalId = transformableModuleCanonicalId(cleanModuleId(id), paths);
|
|
48
|
+
if (!canonicalId) return null;
|
|
49
|
+
const rewritten = rewriteCanonicalSourceIdentity(code, canonicalId, paths, this.environment?.name === "client" ? "client" : "server");
|
|
50
|
+
if (!rewritten) return null;
|
|
51
|
+
return {
|
|
52
|
+
code: rewritten.code,
|
|
53
|
+
map: rewritten.map
|
|
54
|
+
};
|
|
55
|
+
}
|
|
47
56
|
}
|
|
48
57
|
};
|
|
49
58
|
}
|
|
@@ -120,9 +129,6 @@ function mayContainImportMetaUrl(code) {
|
|
|
120
129
|
function mayContainServerCjsGlobal(code) {
|
|
121
130
|
return code.includes("__filename") || code.includes("__dirname");
|
|
122
131
|
}
|
|
123
|
-
function mayContainSourceIdentityToken(code) {
|
|
124
|
-
return mayContainImportMetaUrl(code) || mayContainServerCjsGlobal(code);
|
|
125
|
-
}
|
|
126
132
|
function excludedRelativePrefixes(canonicalRoot, normalizedRoot, options) {
|
|
127
133
|
const prefixes = new Set([
|
|
128
134
|
".next",
|
|
@@ -8,7 +8,7 @@ function createInstrumentationClientTransformPlugin(getInstrumentationClientPath
|
|
|
8
8
|
transform(code, id) {
|
|
9
9
|
const instrumentationClientPath = getInstrumentationClientPath();
|
|
10
10
|
if (!instrumentationClientPath) return null;
|
|
11
|
-
if (normalizePath(id.split("?", 1)[0]) !==
|
|
11
|
+
if (normalizePath(id.split("?", 1)[0]) !== instrumentationClientPath) return null;
|
|
12
12
|
if (code.includes("__vinextInstrumentationClientStart")) return null;
|
|
13
13
|
const ast = parseAst(code);
|
|
14
14
|
let insertPos = 0;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
//#region src/plugins/middleware-export-validation.d.ts
|
|
2
|
+
declare function hasValidMiddlewareModuleExport(source: string, id: string, isProxy: boolean): boolean;
|
|
3
|
+
declare function validateMiddlewareModuleExports(source: string, id: string, filePath: string, isProxy: boolean): void;
|
|
4
|
+
//#endregion
|
|
5
|
+
export { hasValidMiddlewareModuleExport, validateMiddlewareModuleExports };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { stripViteModuleQuery } from "../utils/path.js";
|
|
2
|
+
import { createMiddlewareMissingExportError } from "../server/middleware-runtime.js";
|
|
3
|
+
import { parseAst } from "vite";
|
|
4
|
+
//#region src/plugins/middleware-export-validation.ts
|
|
5
|
+
function parserLanguage(id) {
|
|
6
|
+
const cleanId = stripViteModuleQuery(id).toLowerCase();
|
|
7
|
+
if (cleanId.endsWith(".tsx")) return "tsx";
|
|
8
|
+
if (cleanId.endsWith(".ts") || cleanId.endsWith(".mts") || cleanId.endsWith(".cts")) return "ts";
|
|
9
|
+
return "jsx";
|
|
10
|
+
}
|
|
11
|
+
function astName(value) {
|
|
12
|
+
if (!value) return null;
|
|
13
|
+
if (typeof value.name === "string") return value.name;
|
|
14
|
+
if (typeof value.value === "string") return value.value;
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
function hasValidMiddlewareModuleExport(source, id, isProxy) {
|
|
18
|
+
const ast = parseAst(source, { lang: parserLanguage(id) });
|
|
19
|
+
const expectedExport = isProxy ? "proxy" : "middleware";
|
|
20
|
+
for (const statement of ast.body) {
|
|
21
|
+
if (statement.type === "ExportDefaultDeclaration") return true;
|
|
22
|
+
if (statement.type !== "ExportNamedDeclaration") continue;
|
|
23
|
+
const declaration = statement.declaration;
|
|
24
|
+
if (declaration?.type === "FunctionDeclaration" && astName(declaration.id) === expectedExport) return true;
|
|
25
|
+
if (declaration?.type === "VariableDeclaration") {
|
|
26
|
+
for (const declarator of declaration.declarations ?? []) if (astName(declarator.id) === expectedExport) return true;
|
|
27
|
+
}
|
|
28
|
+
for (const specifier of statement.specifiers ?? []) if (astName(specifier.exported ?? specifier.local) === expectedExport) return true;
|
|
29
|
+
}
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
function validateMiddlewareModuleExports(source, id, filePath, isProxy) {
|
|
33
|
+
if (!hasValidMiddlewareModuleExport(source, id, isProxy)) throw createMiddlewareMissingExportError(filePath, isProxy);
|
|
34
|
+
}
|
|
35
|
+
//#endregion
|
|
36
|
+
export { hasValidMiddlewareModuleExport, validateMiddlewareModuleExports };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { normalizePathSeparators } from "../utils/path.js";
|
|
1
2
|
//#region src/plugins/middleware-server-only.ts
|
|
2
3
|
/**
|
|
3
4
|
* Allow `import 'server-only'` from middleware (and any module reachable
|
|
@@ -44,16 +45,16 @@
|
|
|
44
45
|
*/
|
|
45
46
|
function createMiddlewareServerOnlyPlugin(options) {
|
|
46
47
|
const tainted = /* @__PURE__ */ new Set();
|
|
48
|
+
function canonicalizeId(id) {
|
|
49
|
+
const queryIndex = id.indexOf("?");
|
|
50
|
+
return normalizePathSeparators(queryIndex === -1 ? id : id.slice(0, queryIndex));
|
|
51
|
+
}
|
|
47
52
|
function isTainted(id) {
|
|
48
53
|
if (!id) return false;
|
|
49
|
-
|
|
50
|
-
const queryIndex = id.indexOf("?");
|
|
51
|
-
if (queryIndex !== -1) return tainted.has(id.slice(0, queryIndex));
|
|
52
|
-
return false;
|
|
54
|
+
return tainted.has(canonicalizeId(id));
|
|
53
55
|
}
|
|
54
56
|
function addTainted(id) {
|
|
55
|
-
|
|
56
|
-
tainted.add(queryIndex === -1 ? id : id.slice(0, queryIndex));
|
|
57
|
+
tainted.add(canonicalizeId(id));
|
|
57
58
|
}
|
|
58
59
|
return {
|
|
59
60
|
name: "vinext:middleware-server-only",
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Alias } from "vite";
|
|
2
|
+
|
|
3
|
+
//#region src/plugins/og-asset-ownership.d.ts
|
|
4
|
+
type OgAssetModuleBoundary = {
|
|
5
|
+
assetRoot: string;
|
|
6
|
+
moduleDir: string;
|
|
7
|
+
};
|
|
8
|
+
declare class OgAssetOwnership {
|
|
9
|
+
private projectRoot;
|
|
10
|
+
private readonly linkedPackageRoots;
|
|
11
|
+
private readonly dependencyPackageNames;
|
|
12
|
+
private readonly stringAliasesByFirstCharacter;
|
|
13
|
+
private regularExpressionAliases;
|
|
14
|
+
private configuredAliases;
|
|
15
|
+
configure(projectRoot: string, aliases: readonly Alias[]): void;
|
|
16
|
+
reset(): void;
|
|
17
|
+
shouldTrackImport(source: string): boolean;
|
|
18
|
+
recordResolvedImport(source: string, resolvedId: string): Promise<void>;
|
|
19
|
+
resolveModuleBoundary(moduleId: string): Promise<OgAssetModuleBoundary | null>;
|
|
20
|
+
resolveContainedAsset(assetRoot: string, assetPath: string): Promise<string | null>;
|
|
21
|
+
private findAlias;
|
|
22
|
+
private getExpectedPackageName;
|
|
23
|
+
private resolveAliasPackageRoot;
|
|
24
|
+
private resolveConfiguredAliasRoot;
|
|
25
|
+
}
|
|
26
|
+
//#endregion
|
|
27
|
+
export { OgAssetModuleBoundary, OgAssetOwnership };
|