nitro-nightly 3.0.1-20251024-104739-fa2c167d → 3.1.0-20251024-135426-4da5803f
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_chunks/build.mjs +1 -0
- package/dist/_chunks/build3.mjs +1 -1
- package/dist/_chunks/index.mjs +1 -1
- package/dist/_chunks/index3.mjs +1 -1
- package/dist/_chunks/info.mjs +2 -2
- package/dist/_chunks/plugin.mjs +579 -6
- package/dist/index.mjs +1 -1
- package/dist/presets.mjs +1 -1
- package/dist/vite.d.mts +5 -0
- package/dist/vite.mjs +1 -0
- package/package.json +2 -1
package/dist/_chunks/build.mjs
CHANGED
package/dist/_chunks/build3.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createRequire } from 'node:module';
|
|
2
2
|
import defu$1, { defu } from 'defu';
|
|
3
|
-
import {
|
|
3
|
+
import { F as Builder, M as MagicString, s as sanitizeFilePath, a as scanHandlers, f as formatCompatibilityDate } from './index.mjs';
|
|
4
4
|
import { runtimeDir } from 'nitro/runtime/meta';
|
|
5
5
|
import { a as alias, i as inject } from './index2.mjs';
|
|
6
6
|
import sysPath__default, { resolve as resolve$2, relative, join, dirname, extname, basename, sep, normalize } from 'path';
|
package/dist/_chunks/index.mjs
CHANGED
|
@@ -22268,4 +22268,4 @@ function genRawValue(value, indent = "", options = {}) {
|
|
|
22268
22268
|
return value.toString();
|
|
22269
22269
|
}
|
|
22270
22270
|
|
|
22271
|
-
export {
|
|
22271
|
+
export { isDirectory as A, loadOptions as B, C, runTask as D, listTasks as E, Builder as F, pm$1 as G, decode as H, encode as I, createUnimport as J, genSafeVariableName as K, genImport as L, MagicString as M, N$1 as N, genString as O, Parser as P, genObjectFromRaw as Q, findNearestFile as R, readGitConfig as S, readPackageJSON as T, findFile as U, fileURLToPath as V, resolveCompatibilityDatesFromEnv as W, index as X, scanHandlers as a, glob as b, snapshotStorage as c, copyPublicAssets as d, prettyPath as e, formatCompatibilityDate as f, getMagicString as g, h, stripLiteral as i, prepare as j, createNitro as k, addRoute as l, mime as m, scanUnprefixedPublicAssets as n, compressPublicAssets as o, parse$1 as p, findAllRoutes as q, resolveModulePath as r, sanitizeFilePath as s, createRouter as t, genObjectKey as u, resolveNitroPath as v, writeFile as w, toExports as x, parseNodeModulePath as y, lookupNodeModuleSubpath as z };
|
package/dist/_chunks/index3.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { k as createNitro, l as addRoute, n as scanUnprefixedPublicAssets, o as compressPublicAssets, m as mime, w as writeFile, q as findAllRoutes, t as createRouter, u as genObjectKey, v as resolveNitroPath, x as toExports, r as resolveModulePath, y as parseNodeModulePath, z as lookupNodeModuleSubpath, A as isDirectory } from './index.mjs';
|
|
2
2
|
import { pathToFileURL } from 'node:url';
|
|
3
3
|
import { colors } from 'consola/utils';
|
|
4
4
|
import { defu } from 'defu';
|
package/dist/_chunks/info.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { G as pm, M as MagicString, P as Parser, H as decode, I as encode, J as createUnimport, K as genSafeVariableName, L as genImport, O as genString, Q as genObjectFromRaw, b as glob, m as mime, r as resolveModulePath, w as writeFile } from './index.mjs';
|
|
2
2
|
import sysPath__default, { win32, posix, isAbsolute, resolve as resolve$1 } from 'path';
|
|
3
3
|
import { defineEnv } from 'unenv';
|
|
4
4
|
import { runtimeDir, runtimeDependencies } from 'nitro/runtime/meta';
|
|
@@ -9892,7 +9892,7 @@ async function getWasmImports(asset, _opts) {
|
|
|
9892
9892
|
resolved: true
|
|
9893
9893
|
};
|
|
9894
9894
|
}
|
|
9895
|
-
const { readPackageJSON } = await import('./index.mjs').then(function (n) { return n.
|
|
9895
|
+
const { readPackageJSON } = await import('./index.mjs').then(function (n) { return n.X; });
|
|
9896
9896
|
const pkgJSON = await readPackageJSON(asset.id);
|
|
9897
9897
|
let resolved = true;
|
|
9898
9898
|
const imports = [];
|
package/dist/_chunks/plugin.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { s as sanitizeFilePath, f as formatCompatibilityDate, d as copyPublicAssets, a as scanHandlers, r as resolveModulePath, e as prettyPath, i as
|
|
2
|
-
import 'node:url';
|
|
1
|
+
import { s as sanitizeFilePath, f as formatCompatibilityDate, d as copyPublicAssets, a as scanHandlers, r as resolveModulePath, e as prettyPath, M as MagicString, i as stripLiteral, j as prepare, k as createNitro } from './index.mjs';
|
|
2
|
+
import { fileURLToPath } from 'node:url';
|
|
3
3
|
import { colors } from 'consola/utils';
|
|
4
4
|
import { defu } from 'defu';
|
|
5
5
|
import 'ufo';
|
|
6
|
-
import { existsSync, watch as watch$1 } from 'node:fs';
|
|
6
|
+
import fs, { existsSync, watch as watch$1 } from 'node:fs';
|
|
7
7
|
import { readFile, rm, mkdir, writeFile, readlink } from 'node:fs/promises';
|
|
8
8
|
import 'node:zlib';
|
|
9
9
|
import 'node:worker_threads';
|
|
@@ -25,14 +25,17 @@ import 'jiti';
|
|
|
25
25
|
import 'klona';
|
|
26
26
|
import 'unstorage';
|
|
27
27
|
import 'ohash';
|
|
28
|
-
import { resolve as resolve$1, join as join$1 } from 'node:path';
|
|
28
|
+
import path, { resolve as resolve$1, join as join$1 } from 'node:path';
|
|
29
29
|
import 'youch-core';
|
|
30
30
|
import 'youch';
|
|
31
31
|
import 'source-map';
|
|
32
32
|
import 'srvx';
|
|
33
|
-
import { DevEnvironment } from 'vite';
|
|
33
|
+
import { DevEnvironment, normalizePath, isCSSRequest } from 'vite';
|
|
34
34
|
import { getRandomPort } from 'get-port-please';
|
|
35
35
|
import { spawn } from 'node:child_process';
|
|
36
|
+
import assert from 'node:assert/strict';
|
|
37
|
+
import 'node:assert';
|
|
38
|
+
import { createHash } from 'node:crypto';
|
|
36
39
|
|
|
37
40
|
const getViteRollupConfig = (ctx) => {
|
|
38
41
|
const nitro = ctx.nitro;
|
|
@@ -221,6 +224,7 @@ async function buildEnvironments(ctx, builder) {
|
|
|
221
224
|
nitroOptions.renderer.template = tmp;
|
|
222
225
|
}
|
|
223
226
|
}
|
|
227
|
+
await builder.writeAssetsManifest?.();
|
|
224
228
|
if (!isTest && !isCI) console.log();
|
|
225
229
|
const buildInfo = [
|
|
226
230
|
["preset", nitro.options.preset],
|
|
@@ -635,6 +639,569 @@ function nitroPreviewPlugin(ctx) {
|
|
|
635
639
|
};
|
|
636
640
|
}
|
|
637
641
|
|
|
642
|
+
//#region src/plugins/shared.ts
|
|
643
|
+
function parseIdQuery(id) {
|
|
644
|
+
if (!id.includes("?")) return {
|
|
645
|
+
filename: id,
|
|
646
|
+
query: {}
|
|
647
|
+
};
|
|
648
|
+
const [filename, rawQuery] = id.split(`?`, 2);
|
|
649
|
+
const query = Object.fromEntries(new URLSearchParams(rawQuery));
|
|
650
|
+
return {
|
|
651
|
+
filename,
|
|
652
|
+
query
|
|
653
|
+
};
|
|
654
|
+
}
|
|
655
|
+
function toAssetsVirtual(options) {
|
|
656
|
+
return `virtual:fullstack/assets?${new URLSearchParams(options)}&lang.js`;
|
|
657
|
+
}
|
|
658
|
+
function parseAssetsVirtual(id) {
|
|
659
|
+
if (id.startsWith("\0virtual:fullstack/assets?")) return parseIdQuery(id).query;
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
//#endregion
|
|
663
|
+
//#region src/plugins/utils.ts
|
|
664
|
+
function createVirtualPlugin(name, load) {
|
|
665
|
+
name = "virtual:" + name;
|
|
666
|
+
return {
|
|
667
|
+
name: `rsc:virtual-${name}`,
|
|
668
|
+
resolveId: { handler(source, _importer, _options) {
|
|
669
|
+
return source === name ? "\0" + name : void 0;
|
|
670
|
+
} },
|
|
671
|
+
load: { handler(id, options) {
|
|
672
|
+
if (id === "\0" + name) return load.apply(this, [id, options]);
|
|
673
|
+
} }
|
|
674
|
+
};
|
|
675
|
+
}
|
|
676
|
+
function normalizeRelativePath(s) {
|
|
677
|
+
s = normalizePath(s);
|
|
678
|
+
return s[0] === "." ? s : "./" + s;
|
|
679
|
+
}
|
|
680
|
+
function hashString(v) {
|
|
681
|
+
return createHash("sha256").update(v).digest().toString("hex").slice(0, 12);
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
//#endregion
|
|
685
|
+
//#region src/plugins/vite-utils.ts
|
|
686
|
+
const VALID_ID_PREFIX = `/@id/`;
|
|
687
|
+
const NULL_BYTE_PLACEHOLDER = `__x00__`;
|
|
688
|
+
const FS_PREFIX = `/@fs/`;
|
|
689
|
+
function wrapId(id) {
|
|
690
|
+
return id.startsWith(VALID_ID_PREFIX) ? id : VALID_ID_PREFIX + id.replace("\0", NULL_BYTE_PLACEHOLDER);
|
|
691
|
+
}
|
|
692
|
+
function withTrailingSlash(path$1) {
|
|
693
|
+
if (path$1[path$1.length - 1] !== "/") return `${path$1}/`;
|
|
694
|
+
return path$1;
|
|
695
|
+
}
|
|
696
|
+
const postfixRE = /[?#].*$/;
|
|
697
|
+
function cleanUrl(url) {
|
|
698
|
+
return url.replace(postfixRE, "");
|
|
699
|
+
}
|
|
700
|
+
function splitFileAndPostfix(path$1) {
|
|
701
|
+
const file = cleanUrl(path$1);
|
|
702
|
+
return {
|
|
703
|
+
file,
|
|
704
|
+
postfix: path$1.slice(file.length)
|
|
705
|
+
};
|
|
706
|
+
}
|
|
707
|
+
const windowsSlashRE = /\\/g;
|
|
708
|
+
function slash(p) {
|
|
709
|
+
return p.replace(windowsSlashRE, "/");
|
|
710
|
+
}
|
|
711
|
+
const isWindows = typeof process !== "undefined" && process.platform === "win32";
|
|
712
|
+
function injectQuery(url, queryToInject) {
|
|
713
|
+
const { file, postfix } = splitFileAndPostfix(url);
|
|
714
|
+
const normalizedFile = isWindows ? slash(file) : file;
|
|
715
|
+
return `${normalizedFile}?${queryToInject}${postfix[0] === "?" ? `&${postfix.slice(1)}` : postfix}`;
|
|
716
|
+
}
|
|
717
|
+
function normalizeResolvedIdToUrl(environment, url, resolved) {
|
|
718
|
+
const root = environment.config.root;
|
|
719
|
+
const depsOptimizer = environment.depsOptimizer;
|
|
720
|
+
if (resolved.id.startsWith(withTrailingSlash(root))) url = resolved.id.slice(root.length);
|
|
721
|
+
else if (depsOptimizer?.isOptimizedDepFile(resolved.id) || resolved.id !== "/@react-refresh" && path.isAbsolute(resolved.id) && fs.existsSync(cleanUrl(resolved.id))) url = path.posix.join(FS_PREFIX, resolved.id);
|
|
722
|
+
else url = resolved.id;
|
|
723
|
+
if (url[0] !== "." && url[0] !== "/") url = wrapId(resolved.id);
|
|
724
|
+
return url;
|
|
725
|
+
}
|
|
726
|
+
function normalizeViteImportAnalysisUrl(environment, id) {
|
|
727
|
+
let url = normalizeResolvedIdToUrl(environment, id, { id });
|
|
728
|
+
if (environment.config.consumer === "client") {
|
|
729
|
+
const mod = environment.moduleGraph.getModuleById(id);
|
|
730
|
+
if (mod && mod.lastHMRTimestamp > 0) url = injectQuery(url, `t=${mod.lastHMRTimestamp}`);
|
|
731
|
+
}
|
|
732
|
+
return url;
|
|
733
|
+
}
|
|
734
|
+
function evalValue(rawValue) {
|
|
735
|
+
const fn = new Function(`
|
|
736
|
+
var console, exports, global, module, process, require
|
|
737
|
+
return (\n${rawValue}\n)
|
|
738
|
+
`);
|
|
739
|
+
return fn();
|
|
740
|
+
}
|
|
741
|
+
const directRequestRE = /(\?|&)direct=?(?:&|$)/;
|
|
742
|
+
function assetsPlugin(pluginOpts) {
|
|
743
|
+
let server;
|
|
744
|
+
let resolvedConfig;
|
|
745
|
+
const importAssetsMetaMap = {};
|
|
746
|
+
const bundleMap = {};
|
|
747
|
+
async function processAssetsImport(ctx, id, options) {
|
|
748
|
+
if (ctx.environment.mode === "dev") {
|
|
749
|
+
const result = {
|
|
750
|
+
entry: void 0,
|
|
751
|
+
js: [],
|
|
752
|
+
css: []
|
|
753
|
+
};
|
|
754
|
+
const environment = server.environments[options.environment];
|
|
755
|
+
assert(environment, `Unknown environment: ${options.environment}`);
|
|
756
|
+
if (options.environment === "client") result.entry = normalizeViteImportAnalysisUrl(environment, id);
|
|
757
|
+
if (environment.name !== "client") {
|
|
758
|
+
const collected = await collectCss(environment, id, { eager: pluginOpts?.experimental?.devEagerTransform ?? true });
|
|
759
|
+
result.css = collected.hrefs.map((href, i) => ({
|
|
760
|
+
href,
|
|
761
|
+
"data-vite-dev-id": collected.ids[i]
|
|
762
|
+
}));
|
|
763
|
+
}
|
|
764
|
+
return JSON.stringify(result);
|
|
765
|
+
} else {
|
|
766
|
+
const map = importAssetsMetaMap[options.environment] ??= {};
|
|
767
|
+
const meta = {
|
|
768
|
+
id,
|
|
769
|
+
key: path.relative(resolvedConfig.root, id),
|
|
770
|
+
importerEnvironment: ctx.environment.name,
|
|
771
|
+
isEntry: !!(map[id]?.isEntry || options.isEntry)
|
|
772
|
+
};
|
|
773
|
+
map[id] = meta;
|
|
774
|
+
return `__assets_manifest[${JSON.stringify(options.environment)}][${JSON.stringify(meta.key)}]`;
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
let writeAssetsManifestCalled = false;
|
|
778
|
+
async function writeAssetsManifest(builder) {
|
|
779
|
+
if (writeAssetsManifestCalled) return;
|
|
780
|
+
writeAssetsManifestCalled = true;
|
|
781
|
+
const manifest = {};
|
|
782
|
+
for (const [environmentName, metas] of Object.entries(importAssetsMetaMap)) {
|
|
783
|
+
const bundle = bundleMap[environmentName];
|
|
784
|
+
const assetDepsMap = collectAssetDeps(bundle);
|
|
785
|
+
for (const [id, meta] of Object.entries(metas)) {
|
|
786
|
+
const found = assetDepsMap[id];
|
|
787
|
+
if (!found) {
|
|
788
|
+
builder.config.logger.error(`[vite-plugin-fullstack] failed to find built chunk for ${meta.id} imported by ${meta.importerEnvironment} environment`);
|
|
789
|
+
return;
|
|
790
|
+
}
|
|
791
|
+
const result = {
|
|
792
|
+
js: [],
|
|
793
|
+
css: []
|
|
794
|
+
};
|
|
795
|
+
const { chunk, deps } = found;
|
|
796
|
+
if (environmentName === "client") {
|
|
797
|
+
result.entry = `/${chunk.fileName}`;
|
|
798
|
+
result.js = deps.js.map((fileName) => ({ href: `/${fileName}` }));
|
|
799
|
+
}
|
|
800
|
+
result.css = deps.css.map((fileName) => ({ href: `/${fileName}` }));
|
|
801
|
+
if (!builder.environments[environmentName].config.build.cssCodeSplit) {
|
|
802
|
+
const singleCss = Object.values(bundle).find((v) => v.type === "asset" && v.originalFileNames.includes("style.css"));
|
|
803
|
+
if (singleCss) result.css.push({ href: `/${singleCss.fileName}` });
|
|
804
|
+
}
|
|
805
|
+
(manifest[environmentName] ??= {})[meta.key] = result;
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
const importerEnvironments = new Set(Object.values(importAssetsMetaMap).flatMap((metas) => Object.values(metas)).flatMap((meta) => meta.importerEnvironment));
|
|
809
|
+
for (const environmentName of importerEnvironments) {
|
|
810
|
+
const outDir = builder.environments[environmentName].config.build.outDir;
|
|
811
|
+
fs.writeFileSync(path.join(outDir, BUILD_ASSETS_MANIFEST_NAME), `export default ${JSON.stringify(manifest, null, 2)};`);
|
|
812
|
+
const clientOutDir = builder.environments["client"].config.build.outDir;
|
|
813
|
+
for (const asset of Object.values(bundleMap[environmentName])) if (asset.type === "asset") {
|
|
814
|
+
const srcFile = path.join(outDir, asset.fileName);
|
|
815
|
+
const destFile = path.join(clientOutDir, asset.fileName);
|
|
816
|
+
fs.mkdirSync(path.dirname(destFile), { recursive: true });
|
|
817
|
+
fs.copyFileSync(srcFile, destFile);
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
return [
|
|
822
|
+
{
|
|
823
|
+
name: "fullstack:assets",
|
|
824
|
+
sharedDuringBuild: true,
|
|
825
|
+
configureServer(server_) {
|
|
826
|
+
server = server_;
|
|
827
|
+
},
|
|
828
|
+
configResolved(config) {
|
|
829
|
+
resolvedConfig = config;
|
|
830
|
+
},
|
|
831
|
+
configEnvironment(name) {
|
|
832
|
+
const serverEnvironments = pluginOpts?.serverEnvironments ?? ["ssr"];
|
|
833
|
+
if (serverEnvironments.includes(name)) return { build: { emitAssets: true } };
|
|
834
|
+
},
|
|
835
|
+
transform: { async handler(code, id, _options) {
|
|
836
|
+
if (!code.includes("import.meta.vite.assets")) return;
|
|
837
|
+
const output = new MagicString(code);
|
|
838
|
+
const strippedCode = stripLiteral(code);
|
|
839
|
+
const newImports = /* @__PURE__ */ new Set();
|
|
840
|
+
for (const match of code.matchAll(/import\.meta\.vite\.assets\(([\s\S]*?)\)/dg)) {
|
|
841
|
+
const [start, end] = match.indices[0];
|
|
842
|
+
if (!strippedCode.slice(start, end).includes("import.meta.vite.assets")) continue;
|
|
843
|
+
if (this.environment.name === "client") {
|
|
844
|
+
const replacement$1 = `(${JSON.stringify(EMPTY_ASSETS)})`;
|
|
845
|
+
output.update(start, end, replacement$1);
|
|
846
|
+
continue;
|
|
847
|
+
}
|
|
848
|
+
const argCode = match[1].trim();
|
|
849
|
+
const options = {
|
|
850
|
+
import: id,
|
|
851
|
+
environment: void 0,
|
|
852
|
+
asEntry: false
|
|
853
|
+
};
|
|
854
|
+
if (argCode) {
|
|
855
|
+
const argValue = evalValue(argCode);
|
|
856
|
+
Object.assign(options, argValue);
|
|
857
|
+
}
|
|
858
|
+
const environments = options.environment ? [options.environment] : ["client", this.environment.name];
|
|
859
|
+
const importedNames = [];
|
|
860
|
+
for (const environment of environments) {
|
|
861
|
+
const importSource = toAssetsVirtual({
|
|
862
|
+
import: options.import,
|
|
863
|
+
importer: id,
|
|
864
|
+
environment,
|
|
865
|
+
entry: options.asEntry ? "1" : ""
|
|
866
|
+
});
|
|
867
|
+
const hash = hashString(importSource);
|
|
868
|
+
const importedName = `__assets_${hash}`;
|
|
869
|
+
newImports.add(`;import ${importedName} from ${JSON.stringify(importSource)};\n`);
|
|
870
|
+
importedNames.push(importedName);
|
|
871
|
+
}
|
|
872
|
+
let replacement = importedNames[0];
|
|
873
|
+
if (importedNames.length > 1) {
|
|
874
|
+
newImports.add(`;import * as __assets_runtime from "virtual:fullstack/runtime";\n`);
|
|
875
|
+
replacement = `__assets_runtime.mergeAssets(${importedNames.join(", ")})`;
|
|
876
|
+
}
|
|
877
|
+
output.update(start, end, `(${replacement})`);
|
|
878
|
+
}
|
|
879
|
+
if (output.hasChanged()) {
|
|
880
|
+
for (const newImport of newImports) output.append(newImport);
|
|
881
|
+
return {
|
|
882
|
+
code: output.toString(),
|
|
883
|
+
map: output.generateMap({ hires: "boundary" })
|
|
884
|
+
};
|
|
885
|
+
}
|
|
886
|
+
} },
|
|
887
|
+
resolveId: { handler(source) {
|
|
888
|
+
if (source.startsWith("virtual:fullstack/assets?")) return "\0" + source;
|
|
889
|
+
if (source === "virtual:fullstack/assets-manifest") {
|
|
890
|
+
assert.notEqual(this.environment.name, "client");
|
|
891
|
+
assert.equal(this.environment.mode, "build");
|
|
892
|
+
return {
|
|
893
|
+
id: source,
|
|
894
|
+
external: true
|
|
895
|
+
};
|
|
896
|
+
}
|
|
897
|
+
if (source === "virtual:fullstack/runtime") return { id: source };
|
|
898
|
+
} },
|
|
899
|
+
load: { async handler(id) {
|
|
900
|
+
if (id === "virtual:fullstack/runtime") return runtimeUtils();
|
|
901
|
+
const parsed = parseAssetsVirtual(id);
|
|
902
|
+
if (!parsed) return;
|
|
903
|
+
assert.notEqual(this.environment.name, "client");
|
|
904
|
+
const resolved = await this.resolve(parsed.import, parsed.importer);
|
|
905
|
+
assert(resolved, `Failed to resolve: ${parsed.import}`);
|
|
906
|
+
const s = new MagicString("");
|
|
907
|
+
const code = await processAssetsImport(this, resolved.id, {
|
|
908
|
+
environment: parsed.environment,
|
|
909
|
+
isEntry: !!parsed.entry
|
|
910
|
+
});
|
|
911
|
+
s.append(`export default ${code};\n`);
|
|
912
|
+
if (this.environment.mode === "build") s.prepend(`import __assets_manifest from "virtual:fullstack/assets-manifest";\n`);
|
|
913
|
+
return s.toString();
|
|
914
|
+
} },
|
|
915
|
+
renderChunk(code, chunk) {
|
|
916
|
+
if (code.includes("virtual:fullstack/assets-manifest")) {
|
|
917
|
+
const replacement = normalizeRelativePath(path.relative(path.join(chunk.fileName, ".."), BUILD_ASSETS_MANIFEST_NAME));
|
|
918
|
+
code = code.replaceAll("virtual:fullstack/assets-manifest", () => replacement);
|
|
919
|
+
return { code };
|
|
920
|
+
}
|
|
921
|
+
return;
|
|
922
|
+
},
|
|
923
|
+
writeBundle(_options, bundle) {
|
|
924
|
+
bundleMap[this.environment.name] = bundle;
|
|
925
|
+
},
|
|
926
|
+
buildStart() {
|
|
927
|
+
if (this.environment.mode == "build" && this.environment.name === "client") {
|
|
928
|
+
const metas = importAssetsMetaMap["client"];
|
|
929
|
+
if (metas) {
|
|
930
|
+
for (const meta of Object.values(importAssetsMetaMap["client"])) if (meta.isEntry) this.emitFile({
|
|
931
|
+
type: "chunk",
|
|
932
|
+
id: meta.id,
|
|
933
|
+
preserveSignature: "exports-only"
|
|
934
|
+
});
|
|
935
|
+
}
|
|
936
|
+
}
|
|
937
|
+
},
|
|
938
|
+
buildApp: {
|
|
939
|
+
order: "pre",
|
|
940
|
+
async handler(builder) {
|
|
941
|
+
builder.writeAssetsManifest = async () => {
|
|
942
|
+
await writeAssetsManifest(builder);
|
|
943
|
+
};
|
|
944
|
+
}
|
|
945
|
+
}
|
|
946
|
+
},
|
|
947
|
+
{
|
|
948
|
+
name: "fullstack:write-assets-manifest-post",
|
|
949
|
+
buildApp: {
|
|
950
|
+
order: "post",
|
|
951
|
+
async handler(builder) {
|
|
952
|
+
await builder.writeAssetsManifest();
|
|
953
|
+
}
|
|
954
|
+
}
|
|
955
|
+
},
|
|
956
|
+
{
|
|
957
|
+
name: "fullstack:assets-query",
|
|
958
|
+
sharedDuringBuild: true,
|
|
959
|
+
resolveId: {
|
|
960
|
+
order: "pre",
|
|
961
|
+
handler(source) {
|
|
962
|
+
const { query } = parseIdQuery(source);
|
|
963
|
+
const value = query["assets"];
|
|
964
|
+
if (typeof value !== "undefined") {
|
|
965
|
+
if (this.environment.name === "client") return `\0virtual:fullstack/empty-assets`;
|
|
966
|
+
}
|
|
967
|
+
if (source === "virtual:fullstack/runtime") return source;
|
|
968
|
+
}
|
|
969
|
+
},
|
|
970
|
+
load: { async handler(id) {
|
|
971
|
+
if (id === "\0virtual:fullstack/empty-assets") return `export default ${JSON.stringify(EMPTY_ASSETS)}`;
|
|
972
|
+
if (id === "virtual:fullstack/runtime") return runtimeUtils();
|
|
973
|
+
const { filename, query } = parseIdQuery(id);
|
|
974
|
+
const value = query["assets"];
|
|
975
|
+
if (typeof value !== "undefined") {
|
|
976
|
+
const s = new MagicString("");
|
|
977
|
+
const codes = [];
|
|
978
|
+
if (value) {
|
|
979
|
+
const code = await processAssetsImport(this, filename, {
|
|
980
|
+
environment: value,
|
|
981
|
+
isEntry: value === "client"
|
|
982
|
+
});
|
|
983
|
+
codes.push(code);
|
|
984
|
+
} else {
|
|
985
|
+
const code1 = await processAssetsImport(this, filename, {
|
|
986
|
+
environment: "client",
|
|
987
|
+
isEntry: false
|
|
988
|
+
});
|
|
989
|
+
const code2 = await processAssetsImport(this, filename, {
|
|
990
|
+
environment: this.environment.name,
|
|
991
|
+
isEntry: false
|
|
992
|
+
});
|
|
993
|
+
codes.push(code1, code2);
|
|
994
|
+
}
|
|
995
|
+
s.append(`
|
|
996
|
+
import * as __assets_runtime from "virtual:fullstack/runtime";\n
|
|
997
|
+
export default __assets_runtime.mergeAssets(${codes.join(", ")});
|
|
998
|
+
`);
|
|
999
|
+
if (this.environment.mode === "build") s.prepend(`import __assets_manifest from "virtual:fullstack/assets-manifest";\n`);
|
|
1000
|
+
return {
|
|
1001
|
+
code: s.toString(),
|
|
1002
|
+
moduleSideEffects: false
|
|
1003
|
+
};
|
|
1004
|
+
}
|
|
1005
|
+
} },
|
|
1006
|
+
hotUpdate(ctx) {
|
|
1007
|
+
if (this.environment.name === "rsc") {
|
|
1008
|
+
const mods = collectModuleDependents(ctx.modules);
|
|
1009
|
+
for (const mod of mods) if (mod.id) {
|
|
1010
|
+
const ids = [
|
|
1011
|
+
`${mod.id}?assets`,
|
|
1012
|
+
`${mod.id}?assets=client`,
|
|
1013
|
+
`${mod.id}?assets=${this.environment.name}`
|
|
1014
|
+
];
|
|
1015
|
+
for (const id of ids) invalidteModuleById(this.environment, id);
|
|
1016
|
+
}
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
1019
|
+
},
|
|
1020
|
+
{
|
|
1021
|
+
...createVirtualPlugin("fullstack/client-fallback", () => "export {}"),
|
|
1022
|
+
configEnvironment: {
|
|
1023
|
+
order: "post",
|
|
1024
|
+
handler(name, config, _env) {
|
|
1025
|
+
if (name === "client") {
|
|
1026
|
+
const clientBuildFallback = pluginOpts?.experimental?.clientBuildFallback ?? true;
|
|
1027
|
+
if (clientBuildFallback && !config.build?.rollupOptions?.input) return { build: { rollupOptions: { input: { __fallback: "virtual:fullstack/client-fallback" } } } };
|
|
1028
|
+
}
|
|
1029
|
+
}
|
|
1030
|
+
},
|
|
1031
|
+
generateBundle(_optoins, bundle) {
|
|
1032
|
+
if (this.environment.name !== "client") return;
|
|
1033
|
+
for (const [k, v] of Object.entries(bundle)) if (v.type === "chunk" && v.name === "__fallback") delete bundle[k];
|
|
1034
|
+
}
|
|
1035
|
+
},
|
|
1036
|
+
patchViteClientPlugin(),
|
|
1037
|
+
patchVueScopeCssHmr(),
|
|
1038
|
+
patchCssLinkSelfAccept()
|
|
1039
|
+
];
|
|
1040
|
+
}
|
|
1041
|
+
const EMPTY_ASSETS = {
|
|
1042
|
+
js: [],
|
|
1043
|
+
css: []
|
|
1044
|
+
};
|
|
1045
|
+
const BUILD_ASSETS_MANIFEST_NAME = "__fullstack_assets_manifest.js";
|
|
1046
|
+
async function collectCss(environment, entryId, options) {
|
|
1047
|
+
const visited = /* @__PURE__ */ new Set();
|
|
1048
|
+
const cssIds = /* @__PURE__ */ new Set();
|
|
1049
|
+
async function recurse(id) {
|
|
1050
|
+
if (visited.has(id) || parseAssetsVirtual(id) || "assets" in parseIdQuery(id).query) return;
|
|
1051
|
+
visited.add(id);
|
|
1052
|
+
const mod = environment.moduleGraph.getModuleById(id);
|
|
1053
|
+
if (!mod) return;
|
|
1054
|
+
if (options.eager && !mod?.transformResult) try {
|
|
1055
|
+
await environment.transformRequest(id);
|
|
1056
|
+
} catch (e) {
|
|
1057
|
+
console.error(`[collectCss] Failed to transform '${id}'`, e);
|
|
1058
|
+
}
|
|
1059
|
+
for (const next of mod?.importedModules ?? []) if (next.id) if (isCSSRequest(next.id)) {
|
|
1060
|
+
if (hasSpecialCssQuery(next.id)) continue;
|
|
1061
|
+
cssIds.add(next.id);
|
|
1062
|
+
} else await recurse(next.id);
|
|
1063
|
+
}
|
|
1064
|
+
await recurse(entryId);
|
|
1065
|
+
const hrefs = [...cssIds].map((id) => normalizeViteImportAnalysisUrl(environment, id));
|
|
1066
|
+
return {
|
|
1067
|
+
ids: [...cssIds],
|
|
1068
|
+
hrefs
|
|
1069
|
+
};
|
|
1070
|
+
}
|
|
1071
|
+
function invalidteModuleById(environment, id) {
|
|
1072
|
+
const mod = environment.moduleGraph.getModuleById(id);
|
|
1073
|
+
if (mod) environment.moduleGraph.invalidateModule(mod);
|
|
1074
|
+
return mod;
|
|
1075
|
+
}
|
|
1076
|
+
function collectModuleDependents(mods) {
|
|
1077
|
+
const visited = /* @__PURE__ */ new Set();
|
|
1078
|
+
function recurse(mod) {
|
|
1079
|
+
if (visited.has(mod)) return;
|
|
1080
|
+
visited.add(mod);
|
|
1081
|
+
for (const importer of mod.importers) recurse(importer);
|
|
1082
|
+
}
|
|
1083
|
+
for (const mod of mods) recurse(mod);
|
|
1084
|
+
return [...visited];
|
|
1085
|
+
}
|
|
1086
|
+
function hasSpecialCssQuery(id) {
|
|
1087
|
+
return /[?&](url|inline|raw)(\b|=|&|$)/.test(id);
|
|
1088
|
+
}
|
|
1089
|
+
function collectAssetDeps(bundle) {
|
|
1090
|
+
const chunkToDeps = /* @__PURE__ */ new Map();
|
|
1091
|
+
for (const chunk of Object.values(bundle)) if (chunk.type === "chunk") chunkToDeps.set(chunk, collectAssetDepsInner(chunk.fileName, bundle));
|
|
1092
|
+
const idToDeps = {};
|
|
1093
|
+
for (const [chunk, deps] of chunkToDeps.entries()) for (const id of chunk.moduleIds) idToDeps[id] = {
|
|
1094
|
+
chunk,
|
|
1095
|
+
deps
|
|
1096
|
+
};
|
|
1097
|
+
return idToDeps;
|
|
1098
|
+
}
|
|
1099
|
+
function collectAssetDepsInner(fileName, bundle) {
|
|
1100
|
+
const visited = /* @__PURE__ */ new Set();
|
|
1101
|
+
const css = [];
|
|
1102
|
+
function recurse(k) {
|
|
1103
|
+
if (visited.has(k)) return;
|
|
1104
|
+
visited.add(k);
|
|
1105
|
+
const v = bundle[k];
|
|
1106
|
+
assert(v, `Not found '${k}' in the bundle`);
|
|
1107
|
+
if (v.type === "chunk") {
|
|
1108
|
+
css.push(...v.viteMetadata?.importedCss ?? []);
|
|
1109
|
+
for (const k2 of v.imports) if (k2 in bundle) recurse(k2);
|
|
1110
|
+
}
|
|
1111
|
+
}
|
|
1112
|
+
recurse(fileName);
|
|
1113
|
+
return {
|
|
1114
|
+
js: [...visited],
|
|
1115
|
+
css: [...new Set(css)]
|
|
1116
|
+
};
|
|
1117
|
+
}
|
|
1118
|
+
function patchViteClientPlugin() {
|
|
1119
|
+
const viteClientPath = normalizePath(fileURLToPath(import.meta.resolve("vite/dist/client/client.mjs")));
|
|
1120
|
+
function endIndexOf(code, searchValue) {
|
|
1121
|
+
const i = code.lastIndexOf(searchValue);
|
|
1122
|
+
return i === -1 ? i : i + searchValue.length;
|
|
1123
|
+
}
|
|
1124
|
+
return {
|
|
1125
|
+
name: "fullstack:patch-vite-client",
|
|
1126
|
+
transform: { handler(code, id) {
|
|
1127
|
+
if (id === viteClientPath) {
|
|
1128
|
+
if (code.includes("linkSheetsMap")) return;
|
|
1129
|
+
const s = new MagicString(code);
|
|
1130
|
+
s.prependLeft(code.indexOf("const sheetsMap"), `\
|
|
1131
|
+
const linkSheetsMap = new Map();
|
|
1132
|
+
document
|
|
1133
|
+
.querySelectorAll('link[rel="stylesheet"][data-vite-dev-id]')
|
|
1134
|
+
.forEach((el) => {
|
|
1135
|
+
linkSheetsMap.set(el.getAttribute('data-vite-dev-id'), el)
|
|
1136
|
+
});
|
|
1137
|
+
`);
|
|
1138
|
+
s.appendLeft(endIndexOf(code, `function updateStyle(id, content) {`), `if (linkSheetsMap.has(id)) { return }`);
|
|
1139
|
+
s.appendLeft(endIndexOf(code, `function removeStyle(id) {`), `
|
|
1140
|
+
const link = linkSheetsMap.get(id);
|
|
1141
|
+
if (link) {
|
|
1142
|
+
document
|
|
1143
|
+
.querySelectorAll(
|
|
1144
|
+
'link[rel="stylesheet"][data-vite-dev-id]',
|
|
1145
|
+
)
|
|
1146
|
+
.forEach((el) => {
|
|
1147
|
+
if (el.getAttribute('data-vite-dev-id') === id) {
|
|
1148
|
+
el.remove()
|
|
1149
|
+
}
|
|
1150
|
+
})
|
|
1151
|
+
linkSheetsMap.delete(id)
|
|
1152
|
+
}
|
|
1153
|
+
`);
|
|
1154
|
+
return s.toString();
|
|
1155
|
+
}
|
|
1156
|
+
} }
|
|
1157
|
+
};
|
|
1158
|
+
}
|
|
1159
|
+
function patchVueScopeCssHmr() {
|
|
1160
|
+
return {
|
|
1161
|
+
name: "fullstack:patch-vue-scoped-css-hmr",
|
|
1162
|
+
configureServer(server) {
|
|
1163
|
+
server.middlewares.use((req, _res, next) => {
|
|
1164
|
+
if (req.headers.accept?.includes("text/css") && req.url?.includes("&lang.css=")) req.url = req.url.replace("&lang.css=", "?lang.css");
|
|
1165
|
+
next();
|
|
1166
|
+
});
|
|
1167
|
+
}
|
|
1168
|
+
};
|
|
1169
|
+
}
|
|
1170
|
+
function patchCssLinkSelfAccept() {
|
|
1171
|
+
return {
|
|
1172
|
+
name: "fullstack:patch-css-link-self-accept",
|
|
1173
|
+
apply: "serve",
|
|
1174
|
+
transform: {
|
|
1175
|
+
order: "post",
|
|
1176
|
+
handler(_code, id, _options) {
|
|
1177
|
+
if (this.environment.name === "client" && this.environment.mode === "dev" && isCSSRequest(id) && directRequestRE.test(id)) {
|
|
1178
|
+
const mod = this.environment.moduleGraph.getModuleById(id);
|
|
1179
|
+
if (mod && !mod.isSelfAccepting) mod.isSelfAccepting = true;
|
|
1180
|
+
}
|
|
1181
|
+
}
|
|
1182
|
+
}
|
|
1183
|
+
};
|
|
1184
|
+
}
|
|
1185
|
+
function runtimeUtils() {
|
|
1186
|
+
return `
|
|
1187
|
+
export function mergeAssets(...args) {
|
|
1188
|
+
const js = uniqBy(args.flatMap((h) => h.js), (a) => a.href);
|
|
1189
|
+
const css = uniqBy(args.flatMap((h) => h.css), (a) => a.href);
|
|
1190
|
+
const entry = args.filter((arg) => arg.entry)?.[0]?.entry;
|
|
1191
|
+
const raw = { entry, js, css };
|
|
1192
|
+
return { ...raw, merge: (...args$1) => mergeAssets(raw, ...args$1) };
|
|
1193
|
+
}
|
|
1194
|
+
function uniqBy(array, key) {
|
|
1195
|
+
const seen = new Set();
|
|
1196
|
+
return array.filter((item) => {
|
|
1197
|
+
const k = key(item);
|
|
1198
|
+
if (seen.has(k)) return false;
|
|
1199
|
+
seen.add(k);
|
|
1200
|
+
return true;
|
|
1201
|
+
});
|
|
1202
|
+
}`;
|
|
1203
|
+
}
|
|
1204
|
+
|
|
638
1205
|
const DEFAULT_EXTENSIONS = [".ts", ".js", ".mts", ".mjs", ".tsx", ".jsx"];
|
|
639
1206
|
const debug = process.env.NITRO_DEBUG ? (...args) => console.log("[nitro]", ...args) : () => {
|
|
640
1207
|
};
|
|
@@ -646,7 +1213,13 @@ function nitro(pluginConfig = {}) {
|
|
|
646
1213
|
nitroMain(ctx),
|
|
647
1214
|
nitroPrepare(ctx),
|
|
648
1215
|
nitroService(ctx),
|
|
649
|
-
nitroPreviewPlugin()
|
|
1216
|
+
nitroPreviewPlugin(),
|
|
1217
|
+
pluginConfig.experimental?.assetsImport !== false && assetsPlugin({
|
|
1218
|
+
experimental: {
|
|
1219
|
+
// See https://github.com/hi-ogawa/vite-plugins/pull/1289
|
|
1220
|
+
clientBuildFallback: false
|
|
1221
|
+
}
|
|
1222
|
+
})
|
|
650
1223
|
];
|
|
651
1224
|
}
|
|
652
1225
|
function nitroInit(ctx) {
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { d as copyPublicAssets,
|
|
1
|
+
export { d as copyPublicAssets, k as createNitro, E as listTasks, B as loadOptions, j as prepare, D as runTask } from './_chunks/index.mjs';
|
|
2
2
|
export { b as build, p as prerender, w as writeTypes } from './_chunks/index3.mjs';
|
|
3
3
|
export { c as createDevServer } from './_chunks/server.mjs';
|
|
4
4
|
import 'consola';
|
package/dist/presets.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { b as glob,
|
|
1
|
+
import { b as glob, R as findNearestFile, h, S as readGitConfig, T as readPackageJSON, r as resolveModulePath, U as findFile, V as fileURLToPath, W as resolveCompatibilityDatesFromEnv, f as formatCompatibilityDate } from './_chunks/index.mjs';
|
|
2
2
|
import { kebabCase } from 'scule';
|
|
3
3
|
import { provider, isTest } from 'std-env';
|
|
4
4
|
import { presetsDir, runtimeDir } from 'nitro/runtime/meta';
|
package/dist/vite.d.mts
CHANGED
|
@@ -28,6 +28,11 @@ interface NitroPluginConfig {
|
|
|
28
28
|
* @note This is unsafe if plugins rely on temporary files on the filesystem.
|
|
29
29
|
*/
|
|
30
30
|
virtualBundle?: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* @experimental Enable `?assets` import proposed by https://github.com/vitejs/vite/discussions/20913
|
|
33
|
+
* @default true
|
|
34
|
+
*/
|
|
35
|
+
assetsImport?: boolean;
|
|
31
36
|
};
|
|
32
37
|
}
|
|
33
38
|
interface ServiceConfig {
|
package/dist/vite.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nitro-nightly",
|
|
3
|
-
"version": "3.0
|
|
3
|
+
"version": "3.1.0-20251024-135426-4da5803f",
|
|
4
4
|
"description": "Build and Deploy Universal JavaScript Servers",
|
|
5
5
|
"homepage": "https://nitro.build",
|
|
6
6
|
"repository": "nitrojs/nitro",
|
|
@@ -75,6 +75,7 @@
|
|
|
75
75
|
"@azure/static-web-apps-cli": "^2.0.7",
|
|
76
76
|
"@cloudflare/workers-types": "^4.20251014.0",
|
|
77
77
|
"@deno/types": "^0.0.1",
|
|
78
|
+
"@hiogawa/vite-plugin-fullstack": "npm:@pi0/vite-plugin-fullstack",
|
|
78
79
|
"@netlify/edge-functions": "^3.0.1",
|
|
79
80
|
"@netlify/functions": "^5.0.1",
|
|
80
81
|
"@rollup/plugin-alias": "^5.1.1",
|