@react-router/dev 0.0.0-experimental-b7b187661 → 0.0.0-experimental-e988dc602
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/CHANGELOG.md +0 -19
- package/dist/cli/index.js +345 -647
- package/dist/config.d.ts +0 -27
- package/dist/config.js +1 -1
- package/dist/routes.js +1 -1
- package/dist/vite/cloudflare.js +89 -232
- package/dist/vite.js +487 -762
- package/package.json +6 -6
package/dist/vite.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @react-router/dev v0.0.0-experimental-
|
|
2
|
+
* @react-router/dev v0.0.0-experimental-e988dc602
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -47,7 +47,7 @@ module.exports = __toCommonJS(vite_exports);
|
|
|
47
47
|
// vite/plugin.ts
|
|
48
48
|
var import_node_crypto = require("crypto");
|
|
49
49
|
var fs3 = __toESM(require("fs"));
|
|
50
|
-
var
|
|
50
|
+
var path6 = __toESM(require("path"));
|
|
51
51
|
var url = __toESM(require("url"));
|
|
52
52
|
var fse = __toESM(require("fs-extra"));
|
|
53
53
|
var babel = __toESM(require("@babel/core"));
|
|
@@ -59,9 +59,10 @@ var import_picocolors3 = __toESM(require("picocolors"));
|
|
|
59
59
|
var import_kebabCase = __toESM(require("lodash/kebabCase"));
|
|
60
60
|
|
|
61
61
|
// typegen/index.ts
|
|
62
|
-
var
|
|
62
|
+
var import_node_fs2 = __toESM(require("fs"));
|
|
63
|
+
var import_dedent2 = __toESM(require("dedent"));
|
|
63
64
|
var Path4 = __toESM(require("pathe"));
|
|
64
|
-
var import_picocolors2 = require("picocolors");
|
|
65
|
+
var import_picocolors2 = __toESM(require("picocolors"));
|
|
65
66
|
|
|
66
67
|
// config/config.ts
|
|
67
68
|
var import_node_fs = __toESM(require("fs"));
|
|
@@ -135,15 +136,13 @@ var ssrExternals = isReactRouterRepo() ? [
|
|
|
135
136
|
// vite/vite-node.ts
|
|
136
137
|
async function createContext({
|
|
137
138
|
root,
|
|
138
|
-
mode
|
|
139
|
-
customLogger
|
|
139
|
+
mode
|
|
140
140
|
}) {
|
|
141
141
|
await preloadVite();
|
|
142
142
|
const vite2 = getVite();
|
|
143
143
|
const devServer = await vite2.createServer({
|
|
144
144
|
root,
|
|
145
145
|
mode,
|
|
146
|
-
customLogger,
|
|
147
146
|
server: {
|
|
148
147
|
preTransformRequests: false,
|
|
149
148
|
hmr: false,
|
|
@@ -155,15 +154,6 @@ async function createContext({
|
|
|
155
154
|
optimizeDeps: {
|
|
156
155
|
noDiscovery: true
|
|
157
156
|
},
|
|
158
|
-
css: {
|
|
159
|
-
// This empty PostCSS config object prevents the PostCSS config file from
|
|
160
|
-
// being loaded. We don't need it in a React Router config context, and
|
|
161
|
-
// there's also an issue in Vite 5 when using a .ts PostCSS config file in
|
|
162
|
-
// an ESM project: https://github.com/vitejs/vite/issues/15869. Consumers
|
|
163
|
-
// can work around this in their own Vite config file, but they can't
|
|
164
|
-
// configure this internal usage of vite-node.
|
|
165
|
-
postcss: {}
|
|
166
|
-
},
|
|
167
157
|
configFile: false,
|
|
168
158
|
envFile: false,
|
|
169
159
|
plugins: []
|
|
@@ -241,7 +231,7 @@ function validateRouteConfig({
|
|
|
241
231
|
`Route config in "${routeConfigFile}" is invalid.`,
|
|
242
232
|
root ? `${root}` : [],
|
|
243
233
|
nested ? Object.entries(nested).map(
|
|
244
|
-
([
|
|
234
|
+
([path7, message]) => `Path: routes.${path7}
|
|
245
235
|
${message}`
|
|
246
236
|
) : []
|
|
247
237
|
].flat().join("\n\n")
|
|
@@ -357,8 +347,7 @@ function err(error) {
|
|
|
357
347
|
async function resolveConfig({
|
|
358
348
|
root,
|
|
359
349
|
viteNodeContext,
|
|
360
|
-
reactRouterConfigFile
|
|
361
|
-
skipRoutes
|
|
350
|
+
reactRouterConfigFile
|
|
362
351
|
}) {
|
|
363
352
|
let reactRouterUserConfig = {};
|
|
364
353
|
if (reactRouterConfigFile) {
|
|
@@ -407,17 +396,12 @@ async function resolveConfig({
|
|
|
407
396
|
serverModuleFormat: "esm",
|
|
408
397
|
ssr: true
|
|
409
398
|
};
|
|
410
|
-
let userAndPresetConfigs = mergeReactRouterConfig(
|
|
411
|
-
...presets,
|
|
412
|
-
reactRouterUserConfig
|
|
413
|
-
);
|
|
414
399
|
let {
|
|
415
400
|
appDirectory: userAppDirectory,
|
|
416
|
-
basename:
|
|
401
|
+
basename: basename2,
|
|
417
402
|
buildDirectory: userBuildDirectory,
|
|
418
403
|
buildEnd,
|
|
419
404
|
prerender,
|
|
420
|
-
routeDiscovery: userRouteDiscovery,
|
|
421
405
|
serverBuildFile,
|
|
422
406
|
serverBundles,
|
|
423
407
|
serverModuleFormat,
|
|
@@ -425,7 +409,7 @@ async function resolveConfig({
|
|
|
425
409
|
} = {
|
|
426
410
|
...defaults,
|
|
427
411
|
// Default values should be completely overridden by user/preset config, not merged
|
|
428
|
-
...
|
|
412
|
+
...mergeReactRouterConfig(...presets, reactRouterUserConfig)
|
|
429
413
|
};
|
|
430
414
|
if (!ssr && serverBundles) {
|
|
431
415
|
serverBundles = void 0;
|
|
@@ -436,32 +420,6 @@ async function resolveConfig({
|
|
|
436
420
|
"The `prerender` config must be a boolean, an array of string paths, or a function returning a boolean or array of string paths"
|
|
437
421
|
);
|
|
438
422
|
}
|
|
439
|
-
let routeDiscovery;
|
|
440
|
-
if (userRouteDiscovery == null) {
|
|
441
|
-
if (ssr) {
|
|
442
|
-
routeDiscovery = {
|
|
443
|
-
mode: "lazy",
|
|
444
|
-
manifestPath: "/__manifest"
|
|
445
|
-
};
|
|
446
|
-
} else {
|
|
447
|
-
routeDiscovery = { mode: "initial" };
|
|
448
|
-
}
|
|
449
|
-
} else if (userRouteDiscovery.mode === "initial") {
|
|
450
|
-
routeDiscovery = userRouteDiscovery;
|
|
451
|
-
} else if (userRouteDiscovery.mode === "lazy") {
|
|
452
|
-
if (!ssr) {
|
|
453
|
-
return err(
|
|
454
|
-
'The `routeDiscovery.mode` config cannot be set to "lazy" when setting `ssr:false`'
|
|
455
|
-
);
|
|
456
|
-
}
|
|
457
|
-
let { manifestPath } = userRouteDiscovery;
|
|
458
|
-
if (manifestPath != null && !manifestPath.startsWith("/")) {
|
|
459
|
-
return err(
|
|
460
|
-
'The `routeDiscovery.manifestPath` config must be a root-relative pathname beginning with a slash (i.e., "/__manifest")'
|
|
461
|
-
);
|
|
462
|
-
}
|
|
463
|
-
routeDiscovery = userRouteDiscovery;
|
|
464
|
-
}
|
|
465
423
|
let appDirectory = import_pathe3.default.resolve(root, userAppDirectory || "app");
|
|
466
424
|
let buildDirectory = import_pathe3.default.resolve(root, userBuildDirectory);
|
|
467
425
|
let rootRouteFile = findEntry(appDirectory, "root");
|
|
@@ -474,50 +432,45 @@ async function resolveConfig({
|
|
|
474
432
|
`Could not find a root route module in the app directory as "${rootRouteDisplayPath}"`
|
|
475
433
|
);
|
|
476
434
|
}
|
|
477
|
-
let routes = {
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
root,
|
|
487
|
-
import_pathe3.default.join(appDirectory, "routes.ts")
|
|
488
|
-
);
|
|
489
|
-
return err(
|
|
490
|
-
`Route config file not found at "${routeConfigDisplayPath}".`
|
|
491
|
-
);
|
|
492
|
-
}
|
|
493
|
-
setAppDirectory(appDirectory);
|
|
494
|
-
let routeConfigExport = (await viteNodeContext.runner.executeFile(
|
|
495
|
-
import_pathe3.default.join(appDirectory, routeConfigFile)
|
|
496
|
-
)).default;
|
|
497
|
-
let routeConfig = await routeConfigExport;
|
|
498
|
-
let result = validateRouteConfig({
|
|
499
|
-
routeConfigFile,
|
|
500
|
-
routeConfig
|
|
501
|
-
});
|
|
502
|
-
if (!result.valid) {
|
|
503
|
-
return err(result.message);
|
|
504
|
-
}
|
|
505
|
-
routes = {
|
|
506
|
-
...routes,
|
|
507
|
-
...configRoutesToRouteManifest(appDirectory, routeConfig)
|
|
508
|
-
};
|
|
509
|
-
} catch (error) {
|
|
510
|
-
return err(
|
|
511
|
-
[
|
|
512
|
-
import_picocolors.default.red(`Route config in "${routeConfigFile}" is invalid.`),
|
|
513
|
-
"",
|
|
514
|
-
error.loc?.file && error.loc?.column && error.frame ? [
|
|
515
|
-
import_pathe3.default.relative(appDirectory, error.loc.file) + ":" + error.loc.line + ":" + error.loc.column,
|
|
516
|
-
error.frame.trim?.()
|
|
517
|
-
] : error.stack
|
|
518
|
-
].flat().join("\n")
|
|
435
|
+
let routes = {
|
|
436
|
+
root: { path: "", id: "root", file: rootRouteFile }
|
|
437
|
+
};
|
|
438
|
+
let routeConfigFile = findEntry(appDirectory, "routes");
|
|
439
|
+
try {
|
|
440
|
+
if (!routeConfigFile) {
|
|
441
|
+
let routeConfigDisplayPath = import_pathe3.default.relative(
|
|
442
|
+
root,
|
|
443
|
+
import_pathe3.default.join(appDirectory, "routes.ts")
|
|
519
444
|
);
|
|
445
|
+
return err(`Route config file not found at "${routeConfigDisplayPath}".`);
|
|
520
446
|
}
|
|
447
|
+
setAppDirectory(appDirectory);
|
|
448
|
+
let routeConfigExport = (await viteNodeContext.runner.executeFile(
|
|
449
|
+
import_pathe3.default.join(appDirectory, routeConfigFile)
|
|
450
|
+
)).default;
|
|
451
|
+
let routeConfig = await routeConfigExport;
|
|
452
|
+
let result = validateRouteConfig({
|
|
453
|
+
routeConfigFile,
|
|
454
|
+
routeConfig
|
|
455
|
+
});
|
|
456
|
+
if (!result.valid) {
|
|
457
|
+
return err(result.message);
|
|
458
|
+
}
|
|
459
|
+
routes = {
|
|
460
|
+
...routes,
|
|
461
|
+
...configRoutesToRouteManifest(appDirectory, routeConfig)
|
|
462
|
+
};
|
|
463
|
+
} catch (error) {
|
|
464
|
+
return err(
|
|
465
|
+
[
|
|
466
|
+
import_picocolors.default.red(`Route config in "${routeConfigFile}" is invalid.`),
|
|
467
|
+
"",
|
|
468
|
+
error.loc?.file && error.loc?.column && error.frame ? [
|
|
469
|
+
import_pathe3.default.relative(appDirectory, error.loc.file) + ":" + error.loc.line + ":" + error.loc.column,
|
|
470
|
+
error.frame.trim?.()
|
|
471
|
+
] : error.stack
|
|
472
|
+
].flat().join("\n")
|
|
473
|
+
);
|
|
521
474
|
}
|
|
522
475
|
let future = {
|
|
523
476
|
unstable_middleware: reactRouterUserConfig.future?.unstable_middleware ?? false,
|
|
@@ -528,13 +481,12 @@ async function resolveConfig({
|
|
|
528
481
|
};
|
|
529
482
|
let reactRouterConfig = deepFreeze({
|
|
530
483
|
appDirectory,
|
|
531
|
-
basename:
|
|
484
|
+
basename: basename2,
|
|
532
485
|
buildDirectory,
|
|
533
486
|
buildEnd,
|
|
534
487
|
future,
|
|
535
488
|
prerender,
|
|
536
489
|
routes,
|
|
537
|
-
routeDiscovery,
|
|
538
490
|
serverBuildFile,
|
|
539
491
|
serverBundles,
|
|
540
492
|
serverModuleFormat,
|
|
@@ -547,35 +499,24 @@ async function resolveConfig({
|
|
|
547
499
|
}
|
|
548
500
|
async function createConfigLoader({
|
|
549
501
|
rootDirectory: root,
|
|
550
|
-
watch: watch2
|
|
551
|
-
mode,
|
|
552
|
-
skipRoutes
|
|
502
|
+
watch: watch2
|
|
553
503
|
}) {
|
|
554
|
-
root =
|
|
555
|
-
let vite2 = await import("vite");
|
|
504
|
+
root = root ?? process.env.REACT_ROUTER_ROOT ?? process.cwd();
|
|
556
505
|
let viteNodeContext = await createContext({
|
|
557
506
|
root,
|
|
558
|
-
mode
|
|
559
|
-
// Filter out any info level logs from vite-node
|
|
560
|
-
customLogger: vite2.createLogger("warn", {
|
|
561
|
-
prefix: "[react-router]"
|
|
562
|
-
})
|
|
507
|
+
mode: watch2 ? "development" : "production"
|
|
563
508
|
});
|
|
564
|
-
let reactRouterConfigFile
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
});
|
|
569
|
-
};
|
|
570
|
-
updateReactRouterConfigFile();
|
|
571
|
-
let getConfig = () => resolveConfig({ root, viteNodeContext, reactRouterConfigFile, skipRoutes });
|
|
509
|
+
let reactRouterConfigFile = findEntry(root, "react-router.config", {
|
|
510
|
+
absolute: true
|
|
511
|
+
});
|
|
512
|
+
let getConfig = () => resolveConfig({ root, viteNodeContext, reactRouterConfigFile });
|
|
572
513
|
let appDirectory;
|
|
573
514
|
let initialConfigResult = await getConfig();
|
|
574
515
|
if (!initialConfigResult.ok) {
|
|
575
516
|
throw new Error(initialConfigResult.error);
|
|
576
517
|
}
|
|
577
|
-
appDirectory =
|
|
578
|
-
let
|
|
518
|
+
appDirectory = initialConfigResult.value.appDirectory;
|
|
519
|
+
let lastConfig = initialConfigResult.value;
|
|
579
520
|
let fsWatcher;
|
|
580
521
|
let changeHandlers = [];
|
|
581
522
|
return {
|
|
@@ -588,71 +529,41 @@ async function createConfigLoader({
|
|
|
588
529
|
}
|
|
589
530
|
changeHandlers.push(handler);
|
|
590
531
|
if (!fsWatcher) {
|
|
591
|
-
fsWatcher = import_chokidar.default.watch(
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
dirname4 !== root;
|
|
599
|
-
}
|
|
600
|
-
});
|
|
532
|
+
fsWatcher = import_chokidar.default.watch(
|
|
533
|
+
[
|
|
534
|
+
...reactRouterConfigFile ? [reactRouterConfigFile] : [],
|
|
535
|
+
appDirectory
|
|
536
|
+
],
|
|
537
|
+
{ ignoreInitial: true }
|
|
538
|
+
);
|
|
601
539
|
fsWatcher.on("all", async (...args) => {
|
|
602
540
|
let [event, rawFilepath] = args;
|
|
603
541
|
let filepath = import_pathe3.default.normalize(rawFilepath);
|
|
604
|
-
let
|
|
605
|
-
let
|
|
606
|
-
let rootRelativeFilepath = import_pathe3.default.relative(root, filepath);
|
|
607
|
-
let configFileAddedOrRemoved = fileAddedOrRemoved && isEntryFile("react-router.config", rootRelativeFilepath);
|
|
608
|
-
if (configFileAddedOrRemoved) {
|
|
609
|
-
updateReactRouterConfigFile();
|
|
610
|
-
}
|
|
611
|
-
let moduleGraphChanged = configFileAddedOrRemoved || Boolean(
|
|
542
|
+
let appFileAddedOrRemoved = appDirectory && (event === "add" || event === "unlink") && filepath.startsWith(import_pathe3.default.normalize(appDirectory));
|
|
543
|
+
let configCodeUpdated = Boolean(
|
|
612
544
|
viteNodeContext.devServer?.moduleGraph.getModuleById(filepath)
|
|
613
545
|
);
|
|
614
|
-
if (
|
|
615
|
-
|
|
546
|
+
if (configCodeUpdated || appFileAddedOrRemoved) {
|
|
547
|
+
viteNodeContext.devServer?.moduleGraph.invalidateAll();
|
|
548
|
+
viteNodeContext.runner?.moduleCache.clear();
|
|
616
549
|
}
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
absolute: true
|
|
635
|
-
}) : void 0;
|
|
636
|
-
let routeConfigCodeChanged = routeConfigFile !== void 0 && isEntryFileDependency(
|
|
637
|
-
viteNodeContext.devServer.moduleGraph,
|
|
638
|
-
routeConfigFile,
|
|
639
|
-
filepath
|
|
640
|
-
);
|
|
641
|
-
let configChanged = result.ok && !(0, import_isEqual.default)(omitRoutes(currentConfig), omitRoutes(result.value));
|
|
642
|
-
let routeConfigChanged = result.ok && !(0, import_isEqual.default)(currentConfig?.routes, result.value.routes);
|
|
643
|
-
for (let handler2 of changeHandlers) {
|
|
644
|
-
handler2({
|
|
645
|
-
result,
|
|
646
|
-
configCodeChanged,
|
|
647
|
-
routeConfigCodeChanged,
|
|
648
|
-
configChanged,
|
|
649
|
-
routeConfigChanged,
|
|
650
|
-
path: filepath,
|
|
651
|
-
event
|
|
652
|
-
});
|
|
653
|
-
}
|
|
654
|
-
if (result.ok) {
|
|
655
|
-
currentConfig = result.value;
|
|
550
|
+
if (appFileAddedOrRemoved || configCodeUpdated) {
|
|
551
|
+
let result = await getConfig();
|
|
552
|
+
let configChanged = result.ok && !(0, import_isEqual.default)(lastConfig, result.value);
|
|
553
|
+
let routeConfigChanged = result.ok && !(0, import_isEqual.default)(lastConfig?.routes, result.value.routes);
|
|
554
|
+
for (let handler2 of changeHandlers) {
|
|
555
|
+
handler2({
|
|
556
|
+
result,
|
|
557
|
+
configCodeUpdated,
|
|
558
|
+
configChanged,
|
|
559
|
+
routeConfigChanged,
|
|
560
|
+
path: filepath,
|
|
561
|
+
event
|
|
562
|
+
});
|
|
563
|
+
}
|
|
564
|
+
if (result.ok) {
|
|
565
|
+
lastConfig = result.value;
|
|
566
|
+
}
|
|
656
567
|
}
|
|
657
568
|
});
|
|
658
569
|
}
|
|
@@ -684,18 +595,7 @@ async function resolveEntryFiles({
|
|
|
684
595
|
let userEntryServerFile = findEntry(appDirectory, "entry.server");
|
|
685
596
|
let entryServerFile;
|
|
686
597
|
let entryClientFile = userEntryClientFile || "entry.client.tsx";
|
|
687
|
-
let
|
|
688
|
-
extensions: [".json"],
|
|
689
|
-
absolute: true,
|
|
690
|
-
walkParents: true
|
|
691
|
-
});
|
|
692
|
-
if (!packageJsonPath) {
|
|
693
|
-
throw new Error(
|
|
694
|
-
`Could not find package.json in ${rootDirectory} or any of its parent directories`
|
|
695
|
-
);
|
|
696
|
-
}
|
|
697
|
-
let packageJsonDirectory = import_pathe3.default.dirname(packageJsonPath);
|
|
698
|
-
let pkgJson = await import_package_json.default.load(packageJsonDirectory);
|
|
598
|
+
let pkgJson = await import_package_json.default.load(rootDirectory);
|
|
699
599
|
let deps = pkgJson.content.dependencies ?? {};
|
|
700
600
|
if (userEntryServerFile) {
|
|
701
601
|
entryServerFile = userEntryServerFile;
|
|
@@ -718,7 +618,7 @@ async function resolveEntryFiles({
|
|
|
718
618
|
await pkgJson.save();
|
|
719
619
|
let packageManager = detectPackageManager() ?? "npm";
|
|
720
620
|
(0, import_node_child_process.execSync)(`${packageManager} install`, {
|
|
721
|
-
cwd:
|
|
621
|
+
cwd: rootDirectory,
|
|
722
622
|
stdio: "inherit"
|
|
723
623
|
});
|
|
724
624
|
}
|
|
@@ -728,85 +628,17 @@ async function resolveEntryFiles({
|
|
|
728
628
|
let entryServerFilePath = userEntryServerFile ? import_pathe3.default.resolve(reactRouterConfig.appDirectory, userEntryServerFile) : import_pathe3.default.resolve(defaultsDirectory, entryServerFile);
|
|
729
629
|
return { entryClientFilePath, entryServerFilePath };
|
|
730
630
|
}
|
|
731
|
-
function omitRoutes(config) {
|
|
732
|
-
return {
|
|
733
|
-
...config,
|
|
734
|
-
routes: {}
|
|
735
|
-
};
|
|
736
|
-
}
|
|
737
631
|
var entryExts = [".js", ".jsx", ".ts", ".tsx"];
|
|
738
|
-
function
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
let { root } = import_pathe3.default.parse(currentDir);
|
|
744
|
-
while (true) {
|
|
745
|
-
for (let ext of options?.extensions ?? entryExts) {
|
|
746
|
-
let file = import_pathe3.default.resolve(currentDir, basename3 + ext);
|
|
747
|
-
if (import_node_fs.default.existsSync(file)) {
|
|
748
|
-
return options?.absolute ?? false ? file : import_pathe3.default.relative(dir, file);
|
|
749
|
-
}
|
|
750
|
-
}
|
|
751
|
-
if (!options?.walkParents) {
|
|
752
|
-
return void 0;
|
|
753
|
-
}
|
|
754
|
-
let parentDir = import_pathe3.default.dirname(currentDir);
|
|
755
|
-
if (currentDir === root || parentDir === currentDir) {
|
|
756
|
-
return void 0;
|
|
757
|
-
}
|
|
758
|
-
currentDir = parentDir;
|
|
759
|
-
}
|
|
760
|
-
}
|
|
761
|
-
function isEntryFileDependency(moduleGraph, entryFilepath, filepath, visited = /* @__PURE__ */ new Set()) {
|
|
762
|
-
entryFilepath = import_pathe3.default.normalize(entryFilepath);
|
|
763
|
-
filepath = import_pathe3.default.normalize(filepath);
|
|
764
|
-
if (visited.has(filepath)) {
|
|
765
|
-
return false;
|
|
766
|
-
}
|
|
767
|
-
visited.add(filepath);
|
|
768
|
-
if (filepath === entryFilepath) {
|
|
769
|
-
return true;
|
|
770
|
-
}
|
|
771
|
-
let mod = moduleGraph.getModuleById(filepath);
|
|
772
|
-
if (!mod) {
|
|
773
|
-
return false;
|
|
774
|
-
}
|
|
775
|
-
for (let importer of mod.importers) {
|
|
776
|
-
if (!importer.id) {
|
|
777
|
-
continue;
|
|
778
|
-
}
|
|
779
|
-
if (importer.id === entryFilepath || isEntryFileDependency(moduleGraph, entryFilepath, importer.id, visited)) {
|
|
780
|
-
return true;
|
|
632
|
+
function findEntry(dir, basename2, options) {
|
|
633
|
+
for (let ext of entryExts) {
|
|
634
|
+
let file = import_pathe3.default.resolve(dir, basename2 + ext);
|
|
635
|
+
if (import_node_fs.default.existsSync(file)) {
|
|
636
|
+
return options?.absolute ?? false ? file : import_pathe3.default.relative(dir, file);
|
|
781
637
|
}
|
|
782
638
|
}
|
|
783
|
-
return
|
|
639
|
+
return void 0;
|
|
784
640
|
}
|
|
785
641
|
|
|
786
|
-
// typegen/context.ts
|
|
787
|
-
async function createContext2({
|
|
788
|
-
rootDirectory,
|
|
789
|
-
watch: watch2,
|
|
790
|
-
mode
|
|
791
|
-
}) {
|
|
792
|
-
const configLoader = await createConfigLoader({ rootDirectory, mode, watch: watch2 });
|
|
793
|
-
const configResult = await configLoader.getConfig();
|
|
794
|
-
if (!configResult.ok) {
|
|
795
|
-
throw new Error(configResult.error);
|
|
796
|
-
}
|
|
797
|
-
const config = configResult.value;
|
|
798
|
-
return {
|
|
799
|
-
configLoader,
|
|
800
|
-
rootDirectory,
|
|
801
|
-
config
|
|
802
|
-
};
|
|
803
|
-
}
|
|
804
|
-
|
|
805
|
-
// typegen/generate.ts
|
|
806
|
-
var import_dedent = __toESM(require("dedent"));
|
|
807
|
-
var Path3 = __toESM(require("pathe"));
|
|
808
|
-
var Pathe = __toESM(require("pathe/utils"));
|
|
809
|
-
|
|
810
642
|
// vite/babel.ts
|
|
811
643
|
var babel_exports = {};
|
|
812
644
|
__export(babel_exports, {
|
|
@@ -820,6 +652,26 @@ var t = __toESM(require("@babel/types"));
|
|
|
820
652
|
var traverse = require("@babel/traverse").default;
|
|
821
653
|
var generate = require("@babel/generator").default;
|
|
822
654
|
|
|
655
|
+
// typegen/generate.ts
|
|
656
|
+
var import_dedent = __toESM(require("dedent"));
|
|
657
|
+
var Path3 = __toESM(require("pathe"));
|
|
658
|
+
var Pathe2 = __toESM(require("pathe/utils"));
|
|
659
|
+
|
|
660
|
+
// typegen/paths.ts
|
|
661
|
+
var Path2 = __toESM(require("pathe"));
|
|
662
|
+
var Pathe = __toESM(require("pathe/utils"));
|
|
663
|
+
function getTypesDir(ctx) {
|
|
664
|
+
return Path2.join(ctx.rootDirectory, ".react-router/types");
|
|
665
|
+
}
|
|
666
|
+
function getTypesPath(ctx, route) {
|
|
667
|
+
return Path2.join(
|
|
668
|
+
getTypesDir(ctx),
|
|
669
|
+
Path2.relative(ctx.rootDirectory, ctx.config.appDirectory),
|
|
670
|
+
Path2.dirname(route.file),
|
|
671
|
+
"+types/" + Pathe.filename(route.file) + ".ts"
|
|
672
|
+
);
|
|
673
|
+
}
|
|
674
|
+
|
|
823
675
|
// typegen/params.ts
|
|
824
676
|
function parse2(fullpath2) {
|
|
825
677
|
const result = {};
|
|
@@ -850,330 +702,194 @@ function lineage(routes, route) {
|
|
|
850
702
|
}
|
|
851
703
|
function fullpath(lineage2) {
|
|
852
704
|
if (lineage2.length === 1 && lineage2[0].id === "root") return "/";
|
|
853
|
-
return "/" + lineage2.map((route) => route.path?.replace(/^\//, "")?.replace(/\/$/, "")).filter((
|
|
705
|
+
return "/" + lineage2.map((route) => route.path?.replace(/^\//, "")?.replace(/\/$/, "")).filter((path7) => path7 !== void 0 && path7 !== "").join("/");
|
|
854
706
|
}
|
|
855
707
|
|
|
856
708
|
// typegen/generate.ts
|
|
857
|
-
function
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
const
|
|
862
|
-
const
|
|
863
|
-
|
|
709
|
+
function generate2(ctx, route) {
|
|
710
|
+
const lineage2 = lineage(ctx.config.routes, route);
|
|
711
|
+
const fullpath2 = fullpath(lineage2);
|
|
712
|
+
const typesPath = getTypesPath(ctx, route);
|
|
713
|
+
const parents = lineage2.slice(0, -1);
|
|
714
|
+
const parentTypeImports = parents.map((parent, i) => {
|
|
715
|
+
const rel = Path3.relative(
|
|
716
|
+
Path3.dirname(typesPath),
|
|
717
|
+
getTypesPath(ctx, parent)
|
|
718
|
+
);
|
|
719
|
+
const indent = i === 0 ? "" : " ".repeat(2);
|
|
720
|
+
let source = noExtension(rel);
|
|
721
|
+
if (!source.startsWith("../")) source = "./" + source;
|
|
722
|
+
return `${indent}import type { Info as Parent${i} } from "${source}.js"`;
|
|
723
|
+
}).join("\n");
|
|
724
|
+
return import_dedent.default`
|
|
725
|
+
// React Router generated types for route:
|
|
726
|
+
// ${route.file}
|
|
864
727
|
|
|
865
|
-
import "react-router"
|
|
728
|
+
import type * as T from "react-router/route-module"
|
|
866
729
|
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
730
|
+
${parentTypeImports}
|
|
731
|
+
|
|
732
|
+
type Module = typeof import("../${Pathe2.filename(route.file)}.js")
|
|
733
|
+
|
|
734
|
+
export type Info = {
|
|
735
|
+
parents: [${parents.map((_, i) => `Parent${i}`).join(", ")}],
|
|
736
|
+
id: "${route.id}"
|
|
737
|
+
file: "${route.file}"
|
|
738
|
+
path: "${route.path}"
|
|
739
|
+
params: {${formatParamProperties(
|
|
740
|
+
fullpath2
|
|
741
|
+
)}} & { [key: string]: string | undefined }
|
|
742
|
+
module: Module
|
|
743
|
+
loaderData: T.CreateLoaderData<Module>
|
|
744
|
+
actionData: T.CreateActionData<Module>
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
export namespace Route {
|
|
748
|
+
export type LinkDescriptors = T.LinkDescriptors
|
|
749
|
+
export type LinksFunction = () => LinkDescriptors
|
|
750
|
+
|
|
751
|
+
export type MetaArgs = T.CreateMetaArgs<Info>
|
|
752
|
+
export type MetaDescriptors = T.MetaDescriptors
|
|
753
|
+
export type MetaFunction = (args: MetaArgs) => MetaDescriptors
|
|
754
|
+
|
|
755
|
+
export type HeadersArgs = T.HeadersArgs
|
|
756
|
+
export type HeadersFunction = (args: HeadersArgs) => Headers | HeadersInit
|
|
757
|
+
|
|
758
|
+
export type unstable_MiddlewareFunction = T.CreateServerMiddlewareFunction<Info>
|
|
759
|
+
export type unstable_ClientMiddlewareFunction = T.CreateClientMiddlewareFunction<Info>
|
|
760
|
+
export type LoaderArgs = T.CreateServerLoaderArgs<Info>
|
|
761
|
+
export type ClientLoaderArgs = T.CreateClientLoaderArgs<Info>
|
|
762
|
+
export type ActionArgs = T.CreateServerActionArgs<Info>
|
|
763
|
+
export type ClientActionArgs = T.CreateClientActionArgs<Info>
|
|
764
|
+
|
|
765
|
+
export type HydrateFallbackProps = T.CreateHydrateFallbackProps<Info>
|
|
766
|
+
export type ComponentProps = T.CreateComponentProps<Info>
|
|
767
|
+
export type ErrorBoundaryProps = T.CreateErrorBoundaryProps<Info>
|
|
871
768
|
}
|
|
872
769
|
`;
|
|
873
|
-
return { filename: filename2, content };
|
|
874
770
|
}
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
const
|
|
878
|
-
|
|
771
|
+
var noExtension = (path7) => Path3.join(Path3.dirname(path7), Pathe2.filename(path7));
|
|
772
|
+
function formatParamProperties(fullpath2) {
|
|
773
|
+
const params = parse2(fullpath2);
|
|
774
|
+
const properties = Object.entries(params).map(
|
|
775
|
+
([name, isRequired]) => isRequired ? `"${name}": string` : `"${name}"?: string`
|
|
776
|
+
);
|
|
777
|
+
return properties.join("; ");
|
|
778
|
+
}
|
|
879
779
|
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
export const publicPath: ServerBuild["publicPath"];
|
|
890
|
-
export const routeDiscovery: ServerBuild["routeDiscovery"];
|
|
891
|
-
export const routes: ServerBuild["routes"];
|
|
892
|
-
export const ssr: ServerBuild["ssr"];
|
|
893
|
-
export const unstable_getCriticalCss: ServerBuild["unstable_getCriticalCss"];
|
|
780
|
+
// typegen/index.ts
|
|
781
|
+
async function watch(rootDirectory, { logger } = {}) {
|
|
782
|
+
const ctx = await createContext2({ rootDirectory, watch: true });
|
|
783
|
+
await writeAll(ctx);
|
|
784
|
+
logger?.info(import_picocolors2.default.green("generated types"), { timestamp: true, clear: true });
|
|
785
|
+
ctx.configLoader.onChange(async ({ result, routeConfigChanged }) => {
|
|
786
|
+
if (!result.ok) {
|
|
787
|
+
logger?.error(import_picocolors2.default.red(result.error), { timestamp: true, clear: true });
|
|
788
|
+
return;
|
|
894
789
|
}
|
|
895
|
-
|
|
896
|
-
|
|
790
|
+
ctx.config = result.value;
|
|
791
|
+
if (routeConfigChanged) {
|
|
792
|
+
await writeAll(ctx);
|
|
793
|
+
logger?.info(import_picocolors2.default.green("regenerated types"), {
|
|
794
|
+
timestamp: true,
|
|
795
|
+
clear: true
|
|
796
|
+
});
|
|
797
|
+
}
|
|
798
|
+
});
|
|
799
|
+
return {
|
|
800
|
+
close: async () => await ctx.configLoader.close()
|
|
801
|
+
};
|
|
897
802
|
}
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
803
|
+
async function createContext2({
|
|
804
|
+
rootDirectory,
|
|
805
|
+
watch: watch2
|
|
806
|
+
}) {
|
|
807
|
+
const configLoader = await createConfigLoader({ rootDirectory, watch: watch2 });
|
|
808
|
+
const configResult = await configLoader.getConfig();
|
|
809
|
+
if (!configResult.ok) {
|
|
810
|
+
throw new Error(configResult.error);
|
|
811
|
+
}
|
|
812
|
+
const config = configResult.value;
|
|
813
|
+
return {
|
|
814
|
+
configLoader,
|
|
815
|
+
rootDirectory,
|
|
816
|
+
config
|
|
817
|
+
};
|
|
818
|
+
}
|
|
819
|
+
async function writeAll(ctx) {
|
|
820
|
+
const typegenDir = getTypesDir(ctx);
|
|
821
|
+
import_node_fs2.default.rmSync(typegenDir, { recursive: true, force: true });
|
|
902
822
|
Object.values(ctx.config.routes).forEach((route) => {
|
|
903
|
-
|
|
904
|
-
const
|
|
905
|
-
|
|
906
|
-
|
|
823
|
+
const typesPath = getTypesPath(ctx, route);
|
|
824
|
+
const content = generate2(ctx, route);
|
|
825
|
+
import_node_fs2.default.mkdirSync(Path4.dirname(typesPath), { recursive: true });
|
|
826
|
+
import_node_fs2.default.writeFileSync(typesPath, content);
|
|
907
827
|
});
|
|
908
|
-
const
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
t2.tsTypeLiteral([
|
|
917
|
-
t2.tsPropertySignature(
|
|
918
|
-
t2.identifier("params"),
|
|
919
|
-
t2.tsTypeAnnotation(paramsType(fullpath2))
|
|
920
|
-
)
|
|
921
|
-
])
|
|
922
|
-
)
|
|
923
|
-
);
|
|
924
|
-
})
|
|
925
|
-
)
|
|
926
|
-
);
|
|
927
|
-
const content = import_dedent.default`
|
|
928
|
-
// Generated by React Router
|
|
929
|
-
|
|
930
|
-
import "react-router"
|
|
828
|
+
const registerPath = Path4.join(typegenDir, "+register.ts");
|
|
829
|
+
import_node_fs2.default.writeFileSync(registerPath, register(ctx));
|
|
830
|
+
const virtualPath = Path4.join(typegenDir, "+virtual.d.ts");
|
|
831
|
+
import_node_fs2.default.writeFileSync(virtualPath, virtual);
|
|
832
|
+
}
|
|
833
|
+
function register(ctx) {
|
|
834
|
+
const register2 = import_dedent2.default`
|
|
835
|
+
import "react-router";
|
|
931
836
|
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
}
|
|
837
|
+
declare module "react-router" {
|
|
838
|
+
interface Register {
|
|
839
|
+
params: Params;
|
|
936
840
|
}
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
}
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
841
|
+
}
|
|
842
|
+
`;
|
|
843
|
+
const { t: t2 } = babel_exports;
|
|
844
|
+
const indexPaths = new Set(
|
|
845
|
+
Object.values(ctx.config.routes).filter((route) => route.index).map((route) => route.path)
|
|
846
|
+
);
|
|
847
|
+
const typeParams = t2.tsTypeAliasDeclaration(
|
|
848
|
+
t2.identifier("Params"),
|
|
944
849
|
null,
|
|
945
850
|
t2.tsTypeLiteral(
|
|
946
851
|
Object.values(ctx.config.routes).map((route) => {
|
|
852
|
+
if (route.id !== "root" && !route.path) return void 0;
|
|
853
|
+
if (!route.index && indexPaths.has(route.path)) return void 0;
|
|
854
|
+
const lineage2 = lineage(ctx.config.routes, route);
|
|
855
|
+
const fullpath2 = fullpath(lineage2);
|
|
856
|
+
const params = parse2(fullpath2);
|
|
947
857
|
return t2.tsPropertySignature(
|
|
948
|
-
t2.stringLiteral(
|
|
858
|
+
t2.stringLiteral(fullpath2),
|
|
949
859
|
t2.tsTypeAnnotation(
|
|
950
|
-
t2.tsTypeLiteral(
|
|
951
|
-
|
|
952
|
-
t2.
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
)
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
route.path ? t2.tsLiteralType(t2.stringLiteral(route.path)) : t2.tsUndefinedKeyword()
|
|
961
|
-
)
|
|
962
|
-
),
|
|
963
|
-
t2.tsPropertySignature(
|
|
964
|
-
t2.identifier("params"),
|
|
965
|
-
t2.tsTypeAnnotation(paramsType(route.path ?? ""))
|
|
966
|
-
),
|
|
967
|
-
t2.tsPropertySignature(
|
|
968
|
-
t2.identifier("index"),
|
|
969
|
-
t2.tsTypeAnnotation(
|
|
970
|
-
t2.tsLiteralType(t2.booleanLiteral(route.index ?? false))
|
|
971
|
-
)
|
|
972
|
-
),
|
|
973
|
-
t2.tsPropertySignature(
|
|
974
|
-
t2.identifier("file"),
|
|
975
|
-
t2.tsTypeAnnotation(t2.tsLiteralType(t2.stringLiteral(route.file)))
|
|
976
|
-
)
|
|
977
|
-
])
|
|
860
|
+
t2.tsTypeLiteral(
|
|
861
|
+
Object.entries(params).map(([param, isRequired]) => {
|
|
862
|
+
const property = t2.tsPropertySignature(
|
|
863
|
+
t2.stringLiteral(param),
|
|
864
|
+
t2.tsTypeAnnotation(t2.tsStringKeyword())
|
|
865
|
+
);
|
|
866
|
+
property.optional = !isRequired;
|
|
867
|
+
return property;
|
|
868
|
+
})
|
|
869
|
+
)
|
|
978
870
|
)
|
|
979
871
|
);
|
|
980
|
-
})
|
|
872
|
+
}).filter((x) => x !== void 0)
|
|
981
873
|
)
|
|
982
874
|
);
|
|
983
|
-
|
|
984
|
-
// Generated by React Router
|
|
985
|
-
|
|
986
|
-
import "react-router"
|
|
987
|
-
|
|
988
|
-
declare module "react-router" {
|
|
989
|
-
interface Register {
|
|
990
|
-
routesPre: routesPre
|
|
991
|
-
}
|
|
992
|
-
}
|
|
993
|
-
` + "\n\n" + generate(routesType).code;
|
|
994
|
-
return { filename: filename2, content };
|
|
995
|
-
}
|
|
996
|
-
function generateRouteModuleAnnotations(ctx) {
|
|
997
|
-
return Object.values(ctx.config.routes).filter((route) => isRouteInAppDirectory(ctx, route)).map((route) => {
|
|
998
|
-
const filename2 = getRouteModuleAnnotationsFilepath(ctx, route);
|
|
999
|
-
const parents = getParents(ctx, route);
|
|
1000
|
-
const content = import_dedent.default`
|
|
1001
|
-
// Generated by React Router
|
|
1002
|
-
|
|
1003
|
-
import type {
|
|
1004
|
-
Params,
|
|
1005
|
-
RouteModuleAnnotations,
|
|
1006
|
-
CreateLoaderData,
|
|
1007
|
-
CreateActionData,
|
|
1008
|
-
} from "react-router/internal";
|
|
1009
|
-
|
|
1010
|
-
${parents.map((parent) => parent.import).join("\n" + " ".repeat(3))}
|
|
1011
|
-
type Parents = [${parents.map((parent) => parent.name).join(", ")}]
|
|
1012
|
-
|
|
1013
|
-
type Id = "${route.id}"
|
|
1014
|
-
type Module = typeof import("../${Pathe.filename(route.file)}.js")
|
|
1015
|
-
|
|
1016
|
-
export type unstable_Props = {
|
|
1017
|
-
params: Params[Id]
|
|
1018
|
-
loaderData: CreateLoaderData<Module>
|
|
1019
|
-
actionData: CreateActionData<Module>
|
|
1020
|
-
}
|
|
1021
|
-
|
|
1022
|
-
type Annotations = RouteModuleAnnotations<unstable_Props & {
|
|
1023
|
-
parents: Parents,
|
|
1024
|
-
module: Module,
|
|
1025
|
-
}>;
|
|
1026
|
-
|
|
1027
|
-
export namespace Route {
|
|
1028
|
-
// links
|
|
1029
|
-
export type LinkDescriptors = Annotations["LinkDescriptors"];
|
|
1030
|
-
export type LinksFunction = Annotations["LinksFunction"];
|
|
1031
|
-
|
|
1032
|
-
// meta
|
|
1033
|
-
export type MetaArgs = Annotations["MetaArgs"];
|
|
1034
|
-
export type MetaDescriptors = Annotations["MetaDescriptors"];
|
|
1035
|
-
export type MetaFunction = Annotations["MetaFunction"];
|
|
1036
|
-
|
|
1037
|
-
// headers
|
|
1038
|
-
export type HeadersArgs = Annotations["HeadersArgs"];
|
|
1039
|
-
export type HeadersFunction = Annotations["HeadersFunction"];
|
|
1040
|
-
|
|
1041
|
-
// unstable_middleware
|
|
1042
|
-
export type unstable_MiddlewareFunction = Annotations["unstable_MiddlewareFunction"];
|
|
1043
|
-
|
|
1044
|
-
// unstable_clientMiddleware
|
|
1045
|
-
export type unstable_ClientMiddlewareFunction = Annotations["unstable_ClientMiddlewareFunction"];
|
|
1046
|
-
|
|
1047
|
-
// loader
|
|
1048
|
-
export type LoaderArgs = Annotations["LoaderArgs"];
|
|
1049
|
-
|
|
1050
|
-
// clientLoader
|
|
1051
|
-
export type ClientLoaderArgs = Annotations["ClientLoaderArgs"];
|
|
1052
|
-
|
|
1053
|
-
// action
|
|
1054
|
-
export type ActionArgs = Annotations["ActionArgs"];
|
|
1055
|
-
|
|
1056
|
-
// clientAction
|
|
1057
|
-
export type ClientActionArgs = Annotations["ClientActionArgs"];
|
|
1058
|
-
|
|
1059
|
-
// HydrateFallback
|
|
1060
|
-
export type HydrateFallbackProps = Annotations["HydrateFallbackProps"];
|
|
1061
|
-
|
|
1062
|
-
// Component
|
|
1063
|
-
export type ComponentProps = Annotations["ComponentProps"];
|
|
1064
|
-
|
|
1065
|
-
// ErrorBoundary
|
|
1066
|
-
export type ErrorBoundaryProps = Annotations["ErrorBoundaryProps"];
|
|
1067
|
-
}
|
|
1068
|
-
`;
|
|
1069
|
-
return { filename: filename2, content };
|
|
1070
|
-
});
|
|
1071
|
-
}
|
|
1072
|
-
function isRouteInAppDirectory(ctx, route) {
|
|
1073
|
-
const absoluteRoutePath = Path3.resolve(ctx.config.appDirectory, route.file);
|
|
1074
|
-
return absoluteRoutePath.startsWith(ctx.config.appDirectory);
|
|
1075
|
-
}
|
|
1076
|
-
function getRouteModuleAnnotationsFilepath(ctx, route) {
|
|
1077
|
-
return Path3.join(
|
|
1078
|
-
typesDirectory(ctx),
|
|
1079
|
-
Path3.relative(ctx.rootDirectory, ctx.config.appDirectory),
|
|
1080
|
-
Path3.dirname(route.file),
|
|
1081
|
-
"+types/" + Pathe.filename(route.file) + ".ts"
|
|
1082
|
-
);
|
|
1083
|
-
}
|
|
1084
|
-
function getParents(ctx, route) {
|
|
1085
|
-
const typesPath = getRouteModuleAnnotationsFilepath(ctx, route);
|
|
1086
|
-
const lineage2 = lineage(ctx.config.routes, route);
|
|
1087
|
-
const parents = lineage2.slice(0, -1);
|
|
1088
|
-
return parents.map((parent, i) => {
|
|
1089
|
-
const rel = Path3.relative(
|
|
1090
|
-
Path3.dirname(typesPath),
|
|
1091
|
-
getRouteModuleAnnotationsFilepath(ctx, parent)
|
|
1092
|
-
);
|
|
1093
|
-
let source = noExtension(rel);
|
|
1094
|
-
if (!source.startsWith("../")) source = "./" + source;
|
|
1095
|
-
const name = `Parent${i}`;
|
|
1096
|
-
return {
|
|
1097
|
-
name,
|
|
1098
|
-
import: `import type { unstable_Props as ${name} } from "${source}.js"`
|
|
1099
|
-
};
|
|
1100
|
-
});
|
|
1101
|
-
}
|
|
1102
|
-
function noExtension(path6) {
|
|
1103
|
-
return Path3.join(Path3.dirname(path6), Pathe.filename(path6));
|
|
1104
|
-
}
|
|
1105
|
-
function paramsType(path6) {
|
|
1106
|
-
const params = parse2(path6);
|
|
1107
|
-
return t2.tsTypeLiteral(
|
|
1108
|
-
Object.entries(params).map(([param, isRequired]) => {
|
|
1109
|
-
const property = t2.tsPropertySignature(
|
|
1110
|
-
t2.stringLiteral(param),
|
|
1111
|
-
t2.tsTypeAnnotation(t2.tsStringKeyword())
|
|
1112
|
-
);
|
|
1113
|
-
property.optional = !isRequired;
|
|
1114
|
-
return property;
|
|
1115
|
-
})
|
|
1116
|
-
);
|
|
1117
|
-
}
|
|
1118
|
-
|
|
1119
|
-
// typegen/index.ts
|
|
1120
|
-
async function clearRouteModuleAnnotations(ctx) {
|
|
1121
|
-
await import_promises.default.rm(
|
|
1122
|
-
Path4.join(typesDirectory(ctx), Path4.basename(ctx.config.appDirectory)),
|
|
1123
|
-
{ recursive: true, force: true }
|
|
1124
|
-
);
|
|
1125
|
-
}
|
|
1126
|
-
async function write(...files) {
|
|
1127
|
-
return Promise.all(
|
|
1128
|
-
files.map(async ({ filename: filename2, content }) => {
|
|
1129
|
-
await import_promises.default.mkdir(Path4.dirname(filename2), { recursive: true });
|
|
1130
|
-
await import_promises.default.writeFile(filename2, content);
|
|
1131
|
-
})
|
|
1132
|
-
);
|
|
1133
|
-
}
|
|
1134
|
-
async function watch(rootDirectory, { mode, logger }) {
|
|
1135
|
-
const ctx = await createContext2({ rootDirectory, mode, watch: true });
|
|
1136
|
-
await import_promises.default.rm(typesDirectory(ctx), { recursive: true, force: true });
|
|
1137
|
-
await write(
|
|
1138
|
-
generateFuture(ctx),
|
|
1139
|
-
generatePages(ctx),
|
|
1140
|
-
generateRoutes(ctx),
|
|
1141
|
-
generateServerBuild(ctx),
|
|
1142
|
-
...generateRouteModuleAnnotations(ctx)
|
|
1143
|
-
);
|
|
1144
|
-
logger?.info((0, import_picocolors2.green)("generated types"), { timestamp: true, clear: true });
|
|
1145
|
-
ctx.configLoader.onChange(
|
|
1146
|
-
async ({ result, configChanged, routeConfigChanged }) => {
|
|
1147
|
-
if (!result.ok) {
|
|
1148
|
-
logger?.error((0, import_picocolors2.red)(result.error), { timestamp: true, clear: true });
|
|
1149
|
-
return;
|
|
1150
|
-
}
|
|
1151
|
-
ctx.config = result.value;
|
|
1152
|
-
if (configChanged) {
|
|
1153
|
-
await write(generateFuture(ctx));
|
|
1154
|
-
logger?.info((0, import_picocolors2.green)("regenerated types"), {
|
|
1155
|
-
timestamp: true,
|
|
1156
|
-
clear: true
|
|
1157
|
-
});
|
|
1158
|
-
}
|
|
1159
|
-
if (routeConfigChanged) {
|
|
1160
|
-
await clearRouteModuleAnnotations(ctx);
|
|
1161
|
-
await write(
|
|
1162
|
-
generatePages(ctx),
|
|
1163
|
-
generateRoutes(ctx),
|
|
1164
|
-
...generateRouteModuleAnnotations(ctx)
|
|
1165
|
-
);
|
|
1166
|
-
logger?.info((0, import_picocolors2.green)("regenerated types"), {
|
|
1167
|
-
timestamp: true,
|
|
1168
|
-
clear: true
|
|
1169
|
-
});
|
|
1170
|
-
}
|
|
1171
|
-
}
|
|
1172
|
-
);
|
|
1173
|
-
return {
|
|
1174
|
-
close: async () => await ctx.configLoader.close()
|
|
1175
|
-
};
|
|
875
|
+
return [register2, generate(typeParams).code].join("\n\n");
|
|
1176
876
|
}
|
|
877
|
+
var virtual = import_dedent2.default`
|
|
878
|
+
declare module "virtual:react-router/server-build" {
|
|
879
|
+
import { ServerBuild } from "react-router";
|
|
880
|
+
export const assets: ServerBuild["assets"];
|
|
881
|
+
export const assetsBuildDirectory: ServerBuild["assetsBuildDirectory"];
|
|
882
|
+
export const basename: ServerBuild["basename"];
|
|
883
|
+
export const entry: ServerBuild["entry"];
|
|
884
|
+
export const future: ServerBuild["future"];
|
|
885
|
+
export const isSpaMode: ServerBuild["isSpaMode"];
|
|
886
|
+
export const prerender: ServerBuild["prerender"];
|
|
887
|
+
export const publicPath: ServerBuild["publicPath"];
|
|
888
|
+
export const routes: ServerBuild["routes"];
|
|
889
|
+
export const ssr: ServerBuild["ssr"];
|
|
890
|
+
export const unstable_getCriticalCss: ServerBuild["unstable_getCriticalCss"];
|
|
891
|
+
}
|
|
892
|
+
`;
|
|
1177
893
|
|
|
1178
894
|
// vite/node-adapter.ts
|
|
1179
895
|
var import_node_events = require("events");
|
|
@@ -1229,9 +945,7 @@ function fromNodeRequest(nodeReq, nodeRes) {
|
|
|
1229
945
|
}
|
|
1230
946
|
async function toNodeRequest(res, nodeRes) {
|
|
1231
947
|
nodeRes.statusCode = res.status;
|
|
1232
|
-
|
|
1233
|
-
nodeRes.statusMessage = res.statusText;
|
|
1234
|
-
}
|
|
948
|
+
nodeRes.statusMessage = res.statusText;
|
|
1235
949
|
let cookiesStrings = [];
|
|
1236
950
|
for (let [name, value] of res.headers) {
|
|
1237
951
|
if (name === "set-cookie") {
|
|
@@ -1252,17 +966,17 @@ async function toNodeRequest(res, nodeRes) {
|
|
|
1252
966
|
}
|
|
1253
967
|
|
|
1254
968
|
// vite/styles.ts
|
|
1255
|
-
var
|
|
969
|
+
var path5 = __toESM(require("path"));
|
|
1256
970
|
var import_react_router = require("react-router");
|
|
1257
971
|
|
|
1258
972
|
// vite/resolve-file-url.ts
|
|
1259
|
-
var
|
|
973
|
+
var path4 = __toESM(require("path"));
|
|
1260
974
|
var resolveFileUrl = ({ rootDirectory }, filePath) => {
|
|
1261
975
|
let vite2 = getVite();
|
|
1262
|
-
let relativePath =
|
|
1263
|
-
let isWithinRoot = !relativePath.startsWith("..") && !
|
|
976
|
+
let relativePath = path4.relative(rootDirectory, filePath);
|
|
977
|
+
let isWithinRoot = !relativePath.startsWith("..") && !path4.isAbsolute(relativePath);
|
|
1264
978
|
if (!isWithinRoot) {
|
|
1265
|
-
return
|
|
979
|
+
return path4.posix.join("/@fs", vite2.normalizePath(filePath));
|
|
1266
980
|
}
|
|
1267
981
|
return "/" + vite2.normalizePath(relativePath);
|
|
1268
982
|
};
|
|
@@ -1299,7 +1013,7 @@ var getStylesForFiles = async ({
|
|
|
1299
1013
|
let deps = /* @__PURE__ */ new Set();
|
|
1300
1014
|
try {
|
|
1301
1015
|
for (let file of files) {
|
|
1302
|
-
let normalizedPath =
|
|
1016
|
+
let normalizedPath = path5.resolve(rootDirectory, file).replace(/\\/g, "/");
|
|
1303
1017
|
let node = await viteDevServer.moduleGraph.getModuleById(normalizedPath);
|
|
1304
1018
|
if (!node) {
|
|
1305
1019
|
try {
|
|
@@ -1400,9 +1114,9 @@ var getStylesForPathname = async ({
|
|
|
1400
1114
|
return void 0;
|
|
1401
1115
|
}
|
|
1402
1116
|
let routesWithChildren = createRoutesWithChildren(reactRouterConfig.routes);
|
|
1403
|
-
let appPath =
|
|
1117
|
+
let appPath = path5.relative(process.cwd(), reactRouterConfig.appDirectory);
|
|
1404
1118
|
let documentRouteFiles = (0, import_react_router.matchRoutes)(routesWithChildren, pathname, reactRouterConfig.basename)?.map(
|
|
1405
|
-
(match) =>
|
|
1119
|
+
(match) => path5.resolve(appPath, reactRouterConfig.routes[match.route.id].file)
|
|
1406
1120
|
) ?? [];
|
|
1407
1121
|
let styles = await getStylesForFiles({
|
|
1408
1122
|
viteDevServer,
|
|
@@ -1410,27 +1124,13 @@ var getStylesForPathname = async ({
|
|
|
1410
1124
|
loadCssContents,
|
|
1411
1125
|
files: [
|
|
1412
1126
|
// Always include the client entry file when crawling the module graph for CSS
|
|
1413
|
-
|
|
1127
|
+
path5.relative(rootDirectory, entryClientFilePath),
|
|
1414
1128
|
// Then include any styles from the matched routes
|
|
1415
1129
|
...documentRouteFiles
|
|
1416
1130
|
]
|
|
1417
1131
|
});
|
|
1418
1132
|
return styles;
|
|
1419
1133
|
};
|
|
1420
|
-
var getCssStringFromViteDevModuleCode = (code) => {
|
|
1421
|
-
let cssContent = void 0;
|
|
1422
|
-
const ast = import_parser.parse(code, { sourceType: "module" });
|
|
1423
|
-
traverse(ast, {
|
|
1424
|
-
VariableDeclaration(path6) {
|
|
1425
|
-
const declaration = path6.node.declarations[0];
|
|
1426
|
-
if (declaration?.id?.type === "Identifier" && declaration.id.name === "__vite__css" && declaration.init?.type === "StringLiteral") {
|
|
1427
|
-
cssContent = declaration.init.value;
|
|
1428
|
-
path6.stop();
|
|
1429
|
-
}
|
|
1430
|
-
}
|
|
1431
|
-
});
|
|
1432
|
-
return cssContent;
|
|
1433
|
-
};
|
|
1434
1134
|
|
|
1435
1135
|
// vite/virtual-module.ts
|
|
1436
1136
|
function create(name) {
|
|
@@ -1454,10 +1154,10 @@ var removeExports = (ast, exportsToRemove) => {
|
|
|
1454
1154
|
let exportsFiltered = false;
|
|
1455
1155
|
let markedForRemoval = /* @__PURE__ */ new Set();
|
|
1456
1156
|
traverse(ast, {
|
|
1457
|
-
ExportDeclaration(
|
|
1458
|
-
if (
|
|
1459
|
-
if (
|
|
1460
|
-
|
|
1157
|
+
ExportDeclaration(path7) {
|
|
1158
|
+
if (path7.node.type === "ExportNamedDeclaration") {
|
|
1159
|
+
if (path7.node.specifiers.length) {
|
|
1160
|
+
path7.node.specifiers = path7.node.specifiers.filter((specifier) => {
|
|
1461
1161
|
if (specifier.type === "ExportSpecifier" && specifier.exported.type === "Identifier") {
|
|
1462
1162
|
if (exportsToRemove.includes(specifier.exported.name)) {
|
|
1463
1163
|
exportsFiltered = true;
|
|
@@ -1466,12 +1166,12 @@ var removeExports = (ast, exportsToRemove) => {
|
|
|
1466
1166
|
}
|
|
1467
1167
|
return true;
|
|
1468
1168
|
});
|
|
1469
|
-
if (
|
|
1470
|
-
markedForRemoval.add(
|
|
1169
|
+
if (path7.node.specifiers.length === 0) {
|
|
1170
|
+
markedForRemoval.add(path7);
|
|
1471
1171
|
}
|
|
1472
1172
|
}
|
|
1473
|
-
if (
|
|
1474
|
-
let declaration =
|
|
1173
|
+
if (path7.node.declaration?.type === "VariableDeclaration") {
|
|
1174
|
+
let declaration = path7.node.declaration;
|
|
1475
1175
|
declaration.declarations = declaration.declarations.filter(
|
|
1476
1176
|
(declaration2) => {
|
|
1477
1177
|
if (declaration2.id.type === "Identifier" && exportsToRemove.includes(declaration2.id.name)) {
|
|
@@ -1485,30 +1185,30 @@ var removeExports = (ast, exportsToRemove) => {
|
|
|
1485
1185
|
}
|
|
1486
1186
|
);
|
|
1487
1187
|
if (declaration.declarations.length === 0) {
|
|
1488
|
-
markedForRemoval.add(
|
|
1188
|
+
markedForRemoval.add(path7);
|
|
1489
1189
|
}
|
|
1490
1190
|
}
|
|
1491
|
-
if (
|
|
1492
|
-
let id =
|
|
1191
|
+
if (path7.node.declaration?.type === "FunctionDeclaration") {
|
|
1192
|
+
let id = path7.node.declaration.id;
|
|
1493
1193
|
if (id && exportsToRemove.includes(id.name)) {
|
|
1494
|
-
markedForRemoval.add(
|
|
1194
|
+
markedForRemoval.add(path7);
|
|
1495
1195
|
}
|
|
1496
1196
|
}
|
|
1497
|
-
if (
|
|
1498
|
-
let id =
|
|
1197
|
+
if (path7.node.declaration?.type === "ClassDeclaration") {
|
|
1198
|
+
let id = path7.node.declaration.id;
|
|
1499
1199
|
if (id && exportsToRemove.includes(id.name)) {
|
|
1500
|
-
markedForRemoval.add(
|
|
1200
|
+
markedForRemoval.add(path7);
|
|
1501
1201
|
}
|
|
1502
1202
|
}
|
|
1503
1203
|
}
|
|
1504
|
-
if (
|
|
1505
|
-
markedForRemoval.add(
|
|
1204
|
+
if (path7.node.type === "ExportDefaultDeclaration" && exportsToRemove.includes("default")) {
|
|
1205
|
+
markedForRemoval.add(path7);
|
|
1506
1206
|
}
|
|
1507
1207
|
}
|
|
1508
1208
|
});
|
|
1509
1209
|
if (markedForRemoval.size > 0 || exportsFiltered) {
|
|
1510
|
-
for (let
|
|
1511
|
-
|
|
1210
|
+
for (let path7 of markedForRemoval) {
|
|
1211
|
+
path7.remove();
|
|
1512
1212
|
}
|
|
1513
1213
|
(0, import_babel_dead_code_elimination.deadCodeElimination)(ast, previouslyReferencedIdentifiers);
|
|
1514
1214
|
}
|
|
@@ -1579,28 +1279,28 @@ function codeToAst(code, cache, cacheKey) {
|
|
|
1579
1279
|
)
|
|
1580
1280
|
);
|
|
1581
1281
|
}
|
|
1582
|
-
function assertNodePath(
|
|
1282
|
+
function assertNodePath(path7) {
|
|
1583
1283
|
invariant(
|
|
1584
|
-
|
|
1585
|
-
`Expected a Path, but got ${Array.isArray(
|
|
1284
|
+
path7 && !Array.isArray(path7),
|
|
1285
|
+
`Expected a Path, but got ${Array.isArray(path7) ? "an array" : path7}`
|
|
1586
1286
|
);
|
|
1587
1287
|
}
|
|
1588
|
-
function assertNodePathIsStatement(
|
|
1288
|
+
function assertNodePathIsStatement(path7) {
|
|
1589
1289
|
invariant(
|
|
1590
|
-
|
|
1591
|
-
`Expected a Statement path, but got ${Array.isArray(
|
|
1290
|
+
path7 && !Array.isArray(path7) && t.isStatement(path7.node),
|
|
1291
|
+
`Expected a Statement path, but got ${Array.isArray(path7) ? "an array" : path7?.node?.type}`
|
|
1592
1292
|
);
|
|
1593
1293
|
}
|
|
1594
|
-
function assertNodePathIsVariableDeclarator(
|
|
1294
|
+
function assertNodePathIsVariableDeclarator(path7) {
|
|
1595
1295
|
invariant(
|
|
1596
|
-
|
|
1597
|
-
`Expected an Identifier path, but got ${Array.isArray(
|
|
1296
|
+
path7 && !Array.isArray(path7) && t.isVariableDeclarator(path7.node),
|
|
1297
|
+
`Expected an Identifier path, but got ${Array.isArray(path7) ? "an array" : path7?.node?.type}`
|
|
1598
1298
|
);
|
|
1599
1299
|
}
|
|
1600
|
-
function assertNodePathIsPattern(
|
|
1300
|
+
function assertNodePathIsPattern(path7) {
|
|
1601
1301
|
invariant(
|
|
1602
|
-
|
|
1603
|
-
`Expected a Pattern path, but got ${Array.isArray(
|
|
1302
|
+
path7 && !Array.isArray(path7) && t.isPattern(path7.node),
|
|
1303
|
+
`Expected a Pattern path, but got ${Array.isArray(path7) ? "an array" : path7?.node?.type}`
|
|
1604
1304
|
);
|
|
1605
1305
|
}
|
|
1606
1306
|
function getExportDependencies(code, cache, cacheKey) {
|
|
@@ -1636,8 +1336,8 @@ function getExportDependencies(code, cache, cacheKey) {
|
|
|
1636
1336
|
}
|
|
1637
1337
|
let isWithinExportDestructuring = Boolean(
|
|
1638
1338
|
identifier.findParent(
|
|
1639
|
-
(
|
|
1640
|
-
|
|
1339
|
+
(path7) => Boolean(
|
|
1340
|
+
path7.isPattern() && path7.parentPath?.isVariableDeclarator() && path7.parentPath.parentPath?.parentPath?.isExportNamedDeclaration()
|
|
1641
1341
|
)
|
|
1642
1342
|
)
|
|
1643
1343
|
);
|
|
@@ -1715,7 +1415,7 @@ function getExportDependencies(code, cache, cacheKey) {
|
|
|
1715
1415
|
for (let specifier of node.specifiers) {
|
|
1716
1416
|
if (t.isIdentifier(specifier.exported)) {
|
|
1717
1417
|
let name = specifier.exported.name;
|
|
1718
|
-
let specifierPath = exportPath.get("specifiers").find((
|
|
1418
|
+
let specifierPath = exportPath.get("specifiers").find((path7) => path7.node === specifier);
|
|
1719
1419
|
invariant(
|
|
1720
1420
|
specifierPath,
|
|
1721
1421
|
`Expected to find specifier path for ${name}`
|
|
@@ -1732,22 +1432,22 @@ function getExportDependencies(code, cache, cacheKey) {
|
|
|
1732
1432
|
}
|
|
1733
1433
|
);
|
|
1734
1434
|
}
|
|
1735
|
-
function getDependentIdentifiersForPath(
|
|
1435
|
+
function getDependentIdentifiersForPath(path7, state) {
|
|
1736
1436
|
let { visited, identifiers } = state ?? {
|
|
1737
1437
|
visited: /* @__PURE__ */ new Set(),
|
|
1738
1438
|
identifiers: /* @__PURE__ */ new Set()
|
|
1739
1439
|
};
|
|
1740
|
-
if (visited.has(
|
|
1440
|
+
if (visited.has(path7)) {
|
|
1741
1441
|
return identifiers;
|
|
1742
1442
|
}
|
|
1743
|
-
visited.add(
|
|
1744
|
-
|
|
1745
|
-
Identifier(
|
|
1746
|
-
if (identifiers.has(
|
|
1443
|
+
visited.add(path7);
|
|
1444
|
+
path7.traverse({
|
|
1445
|
+
Identifier(path8) {
|
|
1446
|
+
if (identifiers.has(path8)) {
|
|
1747
1447
|
return;
|
|
1748
1448
|
}
|
|
1749
|
-
identifiers.add(
|
|
1750
|
-
let binding =
|
|
1449
|
+
identifiers.add(path8);
|
|
1450
|
+
let binding = path8.scope.getBinding(path8.node.name);
|
|
1751
1451
|
if (!binding) {
|
|
1752
1452
|
return;
|
|
1753
1453
|
}
|
|
@@ -1769,7 +1469,7 @@ function getDependentIdentifiersForPath(path6, state) {
|
|
|
1769
1469
|
}
|
|
1770
1470
|
}
|
|
1771
1471
|
});
|
|
1772
|
-
let topLevelStatement = getTopLevelStatementPathForPath(
|
|
1472
|
+
let topLevelStatement = getTopLevelStatementPathForPath(path7);
|
|
1773
1473
|
let withinImportStatement = topLevelStatement.isImportDeclaration();
|
|
1774
1474
|
let withinExportStatement = topLevelStatement.isExportDeclaration();
|
|
1775
1475
|
if (!withinImportStatement && !withinExportStatement) {
|
|
@@ -1778,9 +1478,9 @@ function getDependentIdentifiersForPath(path6, state) {
|
|
|
1778
1478
|
identifiers
|
|
1779
1479
|
});
|
|
1780
1480
|
}
|
|
1781
|
-
if (withinExportStatement &&
|
|
1782
|
-
t.isPattern(
|
|
1783
|
-
let variableDeclarator =
|
|
1481
|
+
if (withinExportStatement && path7.isIdentifier() && (t.isPattern(path7.parentPath.node) || // [foo]
|
|
1482
|
+
t.isPattern(path7.parentPath.parentPath?.node))) {
|
|
1483
|
+
let variableDeclarator = path7.findParent((p) => p.isVariableDeclarator());
|
|
1784
1484
|
assertNodePath(variableDeclarator);
|
|
1785
1485
|
getDependentIdentifiersForPath(variableDeclarator, {
|
|
1786
1486
|
visited,
|
|
@@ -1789,16 +1489,16 @@ function getDependentIdentifiersForPath(path6, state) {
|
|
|
1789
1489
|
}
|
|
1790
1490
|
return identifiers;
|
|
1791
1491
|
}
|
|
1792
|
-
function getTopLevelStatementPathForPath(
|
|
1793
|
-
let ancestry =
|
|
1492
|
+
function getTopLevelStatementPathForPath(path7) {
|
|
1493
|
+
let ancestry = path7.getAncestry();
|
|
1794
1494
|
let topLevelStatement = ancestry[ancestry.length - 2];
|
|
1795
1495
|
assertNodePathIsStatement(topLevelStatement);
|
|
1796
1496
|
return topLevelStatement;
|
|
1797
1497
|
}
|
|
1798
1498
|
function getTopLevelStatementsForPaths(paths) {
|
|
1799
1499
|
let topLevelStatements = /* @__PURE__ */ new Set();
|
|
1800
|
-
for (let
|
|
1801
|
-
let topLevelStatement = getTopLevelStatementPathForPath(
|
|
1500
|
+
for (let path7 of paths) {
|
|
1501
|
+
let topLevelStatement = getTopLevelStatementPathForPath(path7);
|
|
1802
1502
|
topLevelStatements.add(topLevelStatement.node);
|
|
1803
1503
|
}
|
|
1804
1504
|
return topLevelStatements;
|
|
@@ -2161,7 +1861,7 @@ function getRouteChunkNameFromModuleId(id) {
|
|
|
2161
1861
|
}
|
|
2162
1862
|
|
|
2163
1863
|
// vite/with-props.ts
|
|
2164
|
-
var
|
|
1864
|
+
var import_dedent3 = __toESM(require("dedent"));
|
|
2165
1865
|
var vmod = create("with-props");
|
|
2166
1866
|
var NAMED_COMPONENT_EXPORTS = ["HydrateFallback", "ErrorBoundary"];
|
|
2167
1867
|
var plugin = {
|
|
@@ -2172,7 +1872,7 @@ var plugin = {
|
|
|
2172
1872
|
},
|
|
2173
1873
|
async load(id) {
|
|
2174
1874
|
if (id !== vmod.resolvedId) return;
|
|
2175
|
-
return
|
|
1875
|
+
return import_dedent3.default`
|
|
2176
1876
|
import { createElement as h } from "react";
|
|
2177
1877
|
import { useActionData, useLoaderData, useMatches, useParams, useRouteError } from "react-router";
|
|
2178
1878
|
|
|
@@ -2215,24 +1915,24 @@ var plugin = {
|
|
|
2215
1915
|
};
|
|
2216
1916
|
var transform = (ast) => {
|
|
2217
1917
|
const hocs = [];
|
|
2218
|
-
function getHocUid(
|
|
2219
|
-
const uid =
|
|
1918
|
+
function getHocUid(path7, hocName) {
|
|
1919
|
+
const uid = path7.scope.generateUidIdentifier(hocName);
|
|
2220
1920
|
hocs.push([hocName, uid]);
|
|
2221
1921
|
return uid;
|
|
2222
1922
|
}
|
|
2223
1923
|
traverse(ast, {
|
|
2224
|
-
ExportDeclaration(
|
|
2225
|
-
if (
|
|
2226
|
-
const declaration =
|
|
1924
|
+
ExportDeclaration(path7) {
|
|
1925
|
+
if (path7.isExportDefaultDeclaration()) {
|
|
1926
|
+
const declaration = path7.get("declaration");
|
|
2227
1927
|
const expr = declaration.isExpression() ? declaration.node : declaration.isFunctionDeclaration() ? toFunctionExpression(declaration.node) : void 0;
|
|
2228
1928
|
if (expr) {
|
|
2229
|
-
const uid = getHocUid(
|
|
1929
|
+
const uid = getHocUid(path7, "withComponentProps");
|
|
2230
1930
|
declaration.replaceWith(t.callExpression(uid, [expr]));
|
|
2231
1931
|
}
|
|
2232
1932
|
return;
|
|
2233
1933
|
}
|
|
2234
|
-
if (
|
|
2235
|
-
const decl =
|
|
1934
|
+
if (path7.isExportNamedDeclaration()) {
|
|
1935
|
+
const decl = path7.get("declaration");
|
|
2236
1936
|
if (decl.isVariableDeclaration()) {
|
|
2237
1937
|
decl.get("declarations").forEach((varDeclarator) => {
|
|
2238
1938
|
const id = varDeclarator.get("id");
|
|
@@ -2242,7 +1942,7 @@ var transform = (ast) => {
|
|
|
2242
1942
|
if (!id.isIdentifier()) return;
|
|
2243
1943
|
const { name } = id.node;
|
|
2244
1944
|
if (!NAMED_COMPONENT_EXPORTS.includes(name)) return;
|
|
2245
|
-
const uid = getHocUid(
|
|
1945
|
+
const uid = getHocUid(path7, `with${name}Props`);
|
|
2246
1946
|
init.replaceWith(t.callExpression(uid, [expr]));
|
|
2247
1947
|
});
|
|
2248
1948
|
return;
|
|
@@ -2252,7 +1952,7 @@ var transform = (ast) => {
|
|
|
2252
1952
|
if (!id) return;
|
|
2253
1953
|
const { name } = id;
|
|
2254
1954
|
if (!NAMED_COMPONENT_EXPORTS.includes(name)) return;
|
|
2255
|
-
const uid = getHocUid(
|
|
1955
|
+
const uid = getHocUid(path7, `with${name}Props`);
|
|
2256
1956
|
decl.replaceWith(
|
|
2257
1957
|
t.variableDeclaration("const", [
|
|
2258
1958
|
t.variableDeclarator(
|
|
@@ -2317,6 +2017,7 @@ var SSR_BUNDLE_PREFIX = "ssrBundle_";
|
|
|
2317
2017
|
function isSsrBundleEnvironmentName(name) {
|
|
2318
2018
|
return name.startsWith(SSR_BUNDLE_PREFIX);
|
|
2319
2019
|
}
|
|
2020
|
+
var CSS_DEV_HELPER_ENVIRONMENT_NAME = "__react_router_css_dev_helper__";
|
|
2320
2021
|
function getServerEnvironmentEntries(ctx, record) {
|
|
2321
2022
|
return Object.entries(record).filter(
|
|
2322
2023
|
([name]) => ctx.buildManifest?.serverBundles ? isSsrBundleEnvironmentName(name) : name === "ssr"
|
|
@@ -2332,7 +2033,7 @@ var isRouteVirtualModule = (id) => {
|
|
|
2332
2033
|
return isRouteEntryModuleId(id) || isRouteChunkModuleId(id);
|
|
2333
2034
|
};
|
|
2334
2035
|
var isServerBuildVirtualModuleId = (id) => {
|
|
2335
|
-
return id.split("?")[0] ===
|
|
2036
|
+
return id.split("?")[0] === virtual2.serverBuild.id;
|
|
2336
2037
|
};
|
|
2337
2038
|
var getServerBuildFile = (viteManifest) => {
|
|
2338
2039
|
let serverBuildIds = Object.keys(viteManifest).filter(
|
|
@@ -2352,23 +2053,23 @@ var virtualHmrRuntime = create("hmr-runtime");
|
|
|
2352
2053
|
var virtualInjectHmrRuntime = create("inject-hmr-runtime");
|
|
2353
2054
|
var normalizeRelativeFilePath = (file, reactRouterConfig) => {
|
|
2354
2055
|
let vite2 = getVite();
|
|
2355
|
-
let fullPath =
|
|
2356
|
-
let relativePath =
|
|
2056
|
+
let fullPath = path6.resolve(reactRouterConfig.appDirectory, file);
|
|
2057
|
+
let relativePath = path6.relative(reactRouterConfig.appDirectory, fullPath);
|
|
2357
2058
|
return vite2.normalizePath(relativePath).split("?")[0];
|
|
2358
2059
|
};
|
|
2359
2060
|
var resolveRelativeRouteFilePath = (route, reactRouterConfig) => {
|
|
2360
2061
|
let vite2 = getVite();
|
|
2361
2062
|
let file = route.file;
|
|
2362
|
-
let fullPath =
|
|
2063
|
+
let fullPath = path6.resolve(reactRouterConfig.appDirectory, file);
|
|
2363
2064
|
return vite2.normalizePath(fullPath);
|
|
2364
2065
|
};
|
|
2365
|
-
var
|
|
2066
|
+
var virtual2 = {
|
|
2366
2067
|
serverBuild: create("server-build"),
|
|
2367
2068
|
serverManifest: create("server-manifest"),
|
|
2368
2069
|
browserManifest: create("browser-manifest")
|
|
2369
2070
|
};
|
|
2370
2071
|
var invalidateVirtualModules = (viteDevServer) => {
|
|
2371
|
-
Object.values(
|
|
2072
|
+
Object.values(virtual2).forEach((vmod2) => {
|
|
2372
2073
|
let mod = viteDevServer.moduleGraph.getModuleById(vmod2.resolvedId);
|
|
2373
2074
|
if (mod) {
|
|
2374
2075
|
viteDevServer.moduleGraph.invalidateModule(mod);
|
|
@@ -2382,7 +2083,7 @@ var getHash = (source, maxLength) => {
|
|
|
2382
2083
|
var resolveChunk = (ctx, viteManifest, absoluteFilePath) => {
|
|
2383
2084
|
let vite2 = getVite();
|
|
2384
2085
|
let rootRelativeFilePath = vite2.normalizePath(
|
|
2385
|
-
|
|
2086
|
+
path6.relative(ctx.rootDirectory, absoluteFilePath)
|
|
2386
2087
|
);
|
|
2387
2088
|
let entryChunk = viteManifest[rootRelativeFilePath];
|
|
2388
2089
|
if (!entryChunk) {
|
|
@@ -2446,7 +2147,7 @@ function dedupe(array2) {
|
|
|
2446
2147
|
return [...new Set(array2)];
|
|
2447
2148
|
}
|
|
2448
2149
|
var writeFileSafe = async (file, contents) => {
|
|
2449
|
-
await fse.ensureDir(
|
|
2150
|
+
await fse.ensureDir(path6.dirname(file));
|
|
2450
2151
|
await fse.writeFile(file, contents);
|
|
2451
2152
|
};
|
|
2452
2153
|
var getExportNames = (code) => {
|
|
@@ -2472,7 +2173,7 @@ var compileRouteFile = async (viteChildCompiler, ctx, routeFile, readRouteFile)
|
|
|
2472
2173
|
}
|
|
2473
2174
|
let ssr = true;
|
|
2474
2175
|
let { pluginContainer, moduleGraph } = viteChildCompiler;
|
|
2475
|
-
let routePath =
|
|
2176
|
+
let routePath = path6.resolve(ctx.reactRouterConfig.appDirectory, routeFile);
|
|
2476
2177
|
let url2 = resolveFileUrl(ctx, routePath);
|
|
2477
2178
|
let resolveId = async () => {
|
|
2478
2179
|
let result = await pluginContainer.resolveId(url2, void 0, { ssr });
|
|
@@ -2514,12 +2215,12 @@ var resolveEnvironmentBuildContext = ({
|
|
|
2514
2215
|
};
|
|
2515
2216
|
return resolvedBuildContext;
|
|
2516
2217
|
};
|
|
2517
|
-
var getServerBuildDirectory = (reactRouterConfig, { serverBundleId } = {}) =>
|
|
2218
|
+
var getServerBuildDirectory = (reactRouterConfig, { serverBundleId } = {}) => path6.join(
|
|
2518
2219
|
reactRouterConfig.buildDirectory,
|
|
2519
2220
|
"server",
|
|
2520
2221
|
...serverBundleId ? [serverBundleId] : []
|
|
2521
2222
|
);
|
|
2522
|
-
var getClientBuildDirectory = (reactRouterConfig) =>
|
|
2223
|
+
var getClientBuildDirectory = (reactRouterConfig) => path6.join(reactRouterConfig.buildDirectory, "client");
|
|
2523
2224
|
var getServerBundleRouteIds = (vitePluginContext, ctx) => {
|
|
2524
2225
|
if (!ctx.buildManifest) {
|
|
2525
2226
|
return void 0;
|
|
@@ -2537,13 +2238,14 @@ var getServerBundleRouteIds = (vitePluginContext, ctx) => {
|
|
|
2537
2238
|
);
|
|
2538
2239
|
return Object.keys(serverBundleRoutes);
|
|
2539
2240
|
};
|
|
2540
|
-
var
|
|
2541
|
-
|
|
2241
|
+
var injectQuery = (url2, query) => url2.includes("?") ? url2.replace("?", `?${query}&`) : `${url2}?${query}`;
|
|
2242
|
+
var defaultEntriesDir = path6.resolve(
|
|
2243
|
+
path6.dirname(require.resolve("@react-router/dev/package.json")),
|
|
2542
2244
|
"dist",
|
|
2543
2245
|
"config",
|
|
2544
2246
|
"defaults"
|
|
2545
2247
|
);
|
|
2546
|
-
var defaultEntries = fse.readdirSync(defaultEntriesDir).map((
|
|
2248
|
+
var defaultEntries = fse.readdirSync(defaultEntriesDir).map((filename3) => path6.join(defaultEntriesDir, filename3));
|
|
2547
2249
|
invariant(defaultEntries.length > 0, "No default entries found");
|
|
2548
2250
|
var reactRouterDevLoadContext = () => void 0;
|
|
2549
2251
|
var reactRouterVitePlugin = () => {
|
|
@@ -2639,10 +2341,10 @@ var reactRouterVitePlugin = () => {
|
|
|
2639
2341
|
}
|
|
2640
2342
|
}).join("\n")}
|
|
2641
2343
|
export { default as assets } from ${JSON.stringify(
|
|
2642
|
-
|
|
2344
|
+
virtual2.serverManifest.id
|
|
2643
2345
|
)};
|
|
2644
2346
|
export const assetsBuildDirectory = ${JSON.stringify(
|
|
2645
|
-
|
|
2347
|
+
path6.relative(
|
|
2646
2348
|
ctx.rootDirectory,
|
|
2647
2349
|
getClientBuildDirectory(ctx.reactRouterConfig)
|
|
2648
2350
|
)
|
|
@@ -2652,9 +2354,6 @@ var reactRouterVitePlugin = () => {
|
|
|
2652
2354
|
export const ssr = ${ctx.reactRouterConfig.ssr};
|
|
2653
2355
|
export const isSpaMode = ${isSpaMode};
|
|
2654
2356
|
export const prerender = ${JSON.stringify(prerenderPaths)};
|
|
2655
|
-
export const routeDiscovery = ${JSON.stringify(
|
|
2656
|
-
ctx.reactRouterConfig.routeDiscovery
|
|
2657
|
-
)};
|
|
2658
2357
|
export const publicPath = ${JSON.stringify(ctx.publicPath)};
|
|
2659
2358
|
export const entry = { module: entryServer };
|
|
2660
2359
|
export const routes = {
|
|
@@ -2681,7 +2380,7 @@ var reactRouterVitePlugin = () => {
|
|
|
2681
2380
|
};
|
|
2682
2381
|
let loadViteManifest = async (directory) => {
|
|
2683
2382
|
let manifestContents = await fse.readFile(
|
|
2684
|
-
|
|
2383
|
+
path6.resolve(directory, ".vite", "manifest.json"),
|
|
2685
2384
|
"utf-8"
|
|
2686
2385
|
);
|
|
2687
2386
|
return JSON.parse(manifestContents);
|
|
@@ -2712,7 +2411,7 @@ var reactRouterVitePlugin = () => {
|
|
|
2712
2411
|
let contents;
|
|
2713
2412
|
try {
|
|
2714
2413
|
contents = await fse.readFile(
|
|
2715
|
-
|
|
2414
|
+
path6.join(entry.path, entry.name),
|
|
2716
2415
|
"utf-8"
|
|
2717
2416
|
);
|
|
2718
2417
|
} catch (e) {
|
|
@@ -2721,7 +2420,7 @@ var reactRouterVitePlugin = () => {
|
|
|
2721
2420
|
}
|
|
2722
2421
|
let hash = (0, import_node_crypto.createHash)("sha384").update(contents).digest().toString("base64");
|
|
2723
2422
|
let filepath = getVite().normalizePath(
|
|
2724
|
-
|
|
2423
|
+
path6.relative(clientBuildDirectory, path6.join(entry.path, entry.name))
|
|
2725
2424
|
);
|
|
2726
2425
|
sriManifest[`${ctx2.publicPath}${filepath}`] = `sha384-${hash}`;
|
|
2727
2426
|
}
|
|
@@ -2748,7 +2447,7 @@ var reactRouterVitePlugin = () => {
|
|
|
2748
2447
|
);
|
|
2749
2448
|
let enforceSplitRouteModules = ctx.reactRouterConfig.future.unstable_splitRouteModules === "enforce";
|
|
2750
2449
|
for (let route of Object.values(ctx.reactRouterConfig.routes)) {
|
|
2751
|
-
let routeFile =
|
|
2450
|
+
let routeFile = path6.join(ctx.reactRouterConfig.appDirectory, route.file);
|
|
2752
2451
|
let sourceExports = routeManifestExports[route.id];
|
|
2753
2452
|
let isRootRoute = route.parentId === void 0;
|
|
2754
2453
|
let hasClientAction = sourceExports.includes("clientAction");
|
|
@@ -2824,7 +2523,7 @@ var reactRouterVitePlugin = () => {
|
|
|
2824
2523
|
}
|
|
2825
2524
|
let fingerprintedValues = { entry, routes: browserRoutes };
|
|
2826
2525
|
let version = getHash(JSON.stringify(fingerprintedValues), 8);
|
|
2827
|
-
let manifestPath =
|
|
2526
|
+
let manifestPath = path6.posix.join(
|
|
2828
2527
|
viteConfig.build.assetsDir,
|
|
2829
2528
|
`manifest-${version}.js`
|
|
2830
2529
|
);
|
|
@@ -2836,7 +2535,7 @@ var reactRouterVitePlugin = () => {
|
|
|
2836
2535
|
sri: void 0
|
|
2837
2536
|
};
|
|
2838
2537
|
await writeFileSafe(
|
|
2839
|
-
|
|
2538
|
+
path6.join(getClientBuildDirectory(ctx.reactRouterConfig), manifestPath),
|
|
2840
2539
|
`window.__reactRouterManifest=${JSON.stringify(
|
|
2841
2540
|
reactRouterBrowserManifest
|
|
2842
2541
|
)};`
|
|
@@ -2921,7 +2620,7 @@ var reactRouterVitePlugin = () => {
|
|
|
2921
2620
|
let sri = void 0;
|
|
2922
2621
|
let reactRouterManifestForDev = {
|
|
2923
2622
|
version: String(Math.random()),
|
|
2924
|
-
url: combineURLs(ctx.publicPath,
|
|
2623
|
+
url: combineURLs(ctx.publicPath, virtual2.browserManifest.url),
|
|
2925
2624
|
hmr: {
|
|
2926
2625
|
runtime: combineURLs(ctx.publicPath, virtualInjectHmrRuntime.url)
|
|
2927
2626
|
},
|
|
@@ -2946,17 +2645,31 @@ var reactRouterVitePlugin = () => {
|
|
|
2946
2645
|
if (dep.file && isCssModulesFile(dep.file)) {
|
|
2947
2646
|
return cssModulesManifest[dep.file];
|
|
2948
2647
|
}
|
|
2949
|
-
|
|
2648
|
+
const vite2 = getVite();
|
|
2649
|
+
const viteMajor = parseInt(vite2.version.split(".")[0], 10);
|
|
2650
|
+
const url2 = viteMajor >= 6 ? (
|
|
2651
|
+
// We need the ?inline query in Vite v6 when loading CSS in SSR
|
|
2652
|
+
// since it does not expose the default export for CSS in a
|
|
2653
|
+
// server environment. This is to align with non-SSR
|
|
2654
|
+
// environments. For backwards compatibility with v5 we keep
|
|
2655
|
+
// using the URL without ?inline query because the HMR code was
|
|
2656
|
+
// relying on the implicit SSR-client module graph relationship.
|
|
2657
|
+
injectQuery(dep.url, "inline")
|
|
2658
|
+
) : dep.url;
|
|
2659
|
+
let cssMod;
|
|
2660
|
+
if (ctx.reactRouterConfig.future.unstable_viteEnvironmentApi) {
|
|
2661
|
+
const cssDevHelperEnvironment = viteDevServer.environments[CSS_DEV_HELPER_ENVIRONMENT_NAME];
|
|
2662
|
+
invariant(cssDevHelperEnvironment, "Missing CSS dev helper environment");
|
|
2663
|
+
invariant(vite2.isRunnableDevEnvironment(cssDevHelperEnvironment));
|
|
2664
|
+
cssMod = await cssDevHelperEnvironment.runner.import(url2);
|
|
2665
|
+
} else {
|
|
2666
|
+
cssMod = await viteDevServer.ssrLoadModule(url2);
|
|
2667
|
+
}
|
|
2950
2668
|
invariant(
|
|
2951
|
-
|
|
2669
|
+
typeof cssMod === "object" && cssMod !== null && "default" in cssMod && typeof cssMod.default === "string",
|
|
2952
2670
|
`Failed to load CSS for ${dep.file ?? dep.url}`
|
|
2953
2671
|
);
|
|
2954
|
-
|
|
2955
|
-
invariant(
|
|
2956
|
-
typeof cssString === "string",
|
|
2957
|
-
`Failed to extract CSS for ${dep.file ?? dep.url}`
|
|
2958
|
-
);
|
|
2959
|
-
return cssString;
|
|
2672
|
+
return cssMod.default;
|
|
2960
2673
|
};
|
|
2961
2674
|
return [
|
|
2962
2675
|
{
|
|
@@ -2974,17 +2687,14 @@ var reactRouterVitePlugin = () => {
|
|
|
2974
2687
|
prefix: "[react-router]"
|
|
2975
2688
|
});
|
|
2976
2689
|
rootDirectory = viteUserConfig.root ?? process.env.REACT_ROUTER_ROOT ?? process.cwd();
|
|
2977
|
-
let mode = viteConfigEnv.mode;
|
|
2978
2690
|
if (viteCommand === "serve") {
|
|
2979
2691
|
typegenWatcherPromise = watch(rootDirectory, {
|
|
2980
|
-
mode,
|
|
2981
2692
|
// ignore `info` logs from typegen since they are redundant when Vite plugin logs are active
|
|
2982
2693
|
logger: vite2.createLogger("warn", { prefix: "[react-router]" })
|
|
2983
2694
|
});
|
|
2984
2695
|
}
|
|
2985
2696
|
reactRouterConfigLoader = await createConfigLoader({
|
|
2986
2697
|
rootDirectory,
|
|
2987
|
-
mode,
|
|
2988
2698
|
watch: viteCommand === "serve"
|
|
2989
2699
|
});
|
|
2990
2700
|
await updatePluginContext();
|
|
@@ -3242,8 +2952,7 @@ var reactRouterVitePlugin = () => {
|
|
|
3242
2952
|
reactRouterConfigLoader.onChange(
|
|
3243
2953
|
async ({
|
|
3244
2954
|
result,
|
|
3245
|
-
|
|
3246
|
-
routeConfigCodeChanged,
|
|
2955
|
+
configCodeUpdated,
|
|
3247
2956
|
configChanged,
|
|
3248
2957
|
routeConfigChanged
|
|
3249
2958
|
}) => {
|
|
@@ -3255,13 +2964,19 @@ var reactRouterVitePlugin = () => {
|
|
|
3255
2964
|
});
|
|
3256
2965
|
return;
|
|
3257
2966
|
}
|
|
3258
|
-
|
|
3259
|
-
|
|
3260
|
-
|
|
3261
|
-
|
|
3262
|
-
|
|
2967
|
+
if (routeConfigChanged) {
|
|
2968
|
+
logger.info(import_picocolors3.default.green("Route config changed."), {
|
|
2969
|
+
clear: true,
|
|
2970
|
+
timestamp: true
|
|
2971
|
+
});
|
|
2972
|
+
} else if (configCodeUpdated) {
|
|
2973
|
+
logger.info(import_picocolors3.default.green("Config updated."), {
|
|
2974
|
+
clear: true,
|
|
2975
|
+
timestamp: true
|
|
2976
|
+
});
|
|
2977
|
+
}
|
|
3263
2978
|
await updatePluginContext();
|
|
3264
|
-
if (configChanged
|
|
2979
|
+
if (configChanged) {
|
|
3265
2980
|
invalidateVirtualModules(viteDevServer);
|
|
3266
2981
|
}
|
|
3267
2982
|
}
|
|
@@ -3302,11 +3017,11 @@ var reactRouterVitePlugin = () => {
|
|
|
3302
3017
|
return;
|
|
3303
3018
|
}
|
|
3304
3019
|
build = await ssrEnvironment.runner.import(
|
|
3305
|
-
|
|
3020
|
+
virtual2.serverBuild.id
|
|
3306
3021
|
);
|
|
3307
3022
|
} else {
|
|
3308
3023
|
build = await viteDevServer.ssrLoadModule(
|
|
3309
|
-
|
|
3024
|
+
virtual2.serverBuild.id
|
|
3310
3025
|
);
|
|
3311
3026
|
}
|
|
3312
3027
|
let handler = (0, import_react_router2.createRequestHandler)(build, "development");
|
|
@@ -3343,8 +3058,8 @@ var reactRouterVitePlugin = () => {
|
|
|
3343
3058
|
let ssrAssetPaths = getViteManifestAssetPaths(ssrViteManifest);
|
|
3344
3059
|
let movedAssetPaths = [];
|
|
3345
3060
|
for (let ssrAssetPath of ssrAssetPaths) {
|
|
3346
|
-
let src =
|
|
3347
|
-
let dest =
|
|
3061
|
+
let src = path6.join(serverBuildDirectory, ssrAssetPath);
|
|
3062
|
+
let dest = path6.join(clientBuildDirectory, ssrAssetPath);
|
|
3348
3063
|
if (!fse.existsSync(dest)) {
|
|
3349
3064
|
await fse.move(src, dest);
|
|
3350
3065
|
movedAssetPaths.push(dest);
|
|
@@ -3357,7 +3072,7 @@ var reactRouterVitePlugin = () => {
|
|
|
3357
3072
|
);
|
|
3358
3073
|
await Promise.all(
|
|
3359
3074
|
ssrCssPaths.map(
|
|
3360
|
-
(cssPath) => fse.remove(
|
|
3075
|
+
(cssPath) => fse.remove(path6.join(serverBuildDirectory, cssPath))
|
|
3361
3076
|
)
|
|
3362
3077
|
);
|
|
3363
3078
|
if (movedAssetPaths.length) {
|
|
@@ -3366,13 +3081,12 @@ var reactRouterVitePlugin = () => {
|
|
|
3366
3081
|
"",
|
|
3367
3082
|
`${import_picocolors3.default.green("\u2713")} ${movedAssetPaths.length} asset${movedAssetPaths.length > 1 ? "s" : ""} moved from React Router server build to client assets.`,
|
|
3368
3083
|
...movedAssetPaths.map(
|
|
3369
|
-
(movedAssetPath) => import_picocolors3.default.dim(
|
|
3084
|
+
(movedAssetPath) => import_picocolors3.default.dim(path6.relative(ctx.rootDirectory, movedAssetPath))
|
|
3370
3085
|
),
|
|
3371
3086
|
""
|
|
3372
3087
|
].join("\n")
|
|
3373
3088
|
);
|
|
3374
3089
|
}
|
|
3375
|
-
process.env.IS_RR_BUILD_REQUEST = "yes";
|
|
3376
3090
|
if (isPrerenderingEnabled(ctx.reactRouterConfig)) {
|
|
3377
3091
|
await handlePrerender(
|
|
3378
3092
|
viteConfig,
|
|
@@ -3445,7 +3159,7 @@ var reactRouterVitePlugin = () => {
|
|
|
3445
3159
|
);
|
|
3446
3160
|
let isMainChunkExport = (name) => !chunkedExports.includes(name);
|
|
3447
3161
|
let mainChunkReexports = sourceExports.filter(isMainChunkExport).join(", ");
|
|
3448
|
-
let chunkBasePath = `./${
|
|
3162
|
+
let chunkBasePath = `./${path6.basename(id)}`;
|
|
3449
3163
|
return [
|
|
3450
3164
|
`export { ${mainChunkReexports} } from "${getRouteChunkModuleId(
|
|
3451
3165
|
chunkBasePath,
|
|
@@ -3465,7 +3179,7 @@ var reactRouterVitePlugin = () => {
|
|
|
3465
3179
|
async transform(code, id, options) {
|
|
3466
3180
|
if (!id.endsWith(BUILD_CLIENT_ROUTE_QUERY_STRING)) return;
|
|
3467
3181
|
let routeModuleId = id.replace(BUILD_CLIENT_ROUTE_QUERY_STRING, "");
|
|
3468
|
-
let routeFileName =
|
|
3182
|
+
let routeFileName = path6.basename(routeModuleId);
|
|
3469
3183
|
let sourceExports = await getRouteModuleExports(
|
|
3470
3184
|
viteChildCompiler,
|
|
3471
3185
|
ctx,
|
|
@@ -3531,16 +3245,16 @@ var reactRouterVitePlugin = () => {
|
|
|
3531
3245
|
name: "react-router:virtual-modules",
|
|
3532
3246
|
enforce: "pre",
|
|
3533
3247
|
resolveId(id) {
|
|
3534
|
-
const vmod2 = Object.values(
|
|
3248
|
+
const vmod2 = Object.values(virtual2).find((vmod3) => vmod3.id === id);
|
|
3535
3249
|
if (vmod2) return vmod2.resolvedId;
|
|
3536
3250
|
},
|
|
3537
3251
|
async load(id) {
|
|
3538
3252
|
switch (id) {
|
|
3539
|
-
case
|
|
3253
|
+
case virtual2.serverBuild.resolvedId: {
|
|
3540
3254
|
let routeIds = getServerBundleRouteIds(this, ctx);
|
|
3541
3255
|
return await getServerEntry({ routeIds });
|
|
3542
3256
|
}
|
|
3543
|
-
case
|
|
3257
|
+
case virtual2.serverManifest.resolvedId: {
|
|
3544
3258
|
let routeIds = getServerBundleRouteIds(this, ctx);
|
|
3545
3259
|
let reactRouterManifest = viteCommand === "build" ? (await generateReactRouterManifestsForBuild({
|
|
3546
3260
|
routeIds
|
|
@@ -3558,7 +3272,7 @@ var reactRouterVitePlugin = () => {
|
|
|
3558
3272
|
es6: true
|
|
3559
3273
|
})};`;
|
|
3560
3274
|
}
|
|
3561
|
-
case
|
|
3275
|
+
case virtual2.browserManifest.resolvedId: {
|
|
3562
3276
|
if (viteCommand === "build") {
|
|
3563
3277
|
throw new Error("This module only exists in development");
|
|
3564
3278
|
}
|
|
@@ -3592,7 +3306,7 @@ var reactRouterVitePlugin = () => {
|
|
|
3592
3306
|
}
|
|
3593
3307
|
let vite2 = getVite();
|
|
3594
3308
|
let importerShort = vite2.normalizePath(
|
|
3595
|
-
|
|
3309
|
+
path6.relative(ctx.rootDirectory, importer)
|
|
3596
3310
|
);
|
|
3597
3311
|
if (isRoute(ctx.reactRouterConfig, importer)) {
|
|
3598
3312
|
let serverOnlyExports = SERVER_ONLY_ROUTE_EXPORTS.map(
|
|
@@ -3715,10 +3429,10 @@ var reactRouterVitePlugin = () => {
|
|
|
3715
3429
|
},
|
|
3716
3430
|
async load(id) {
|
|
3717
3431
|
if (id !== virtualHmrRuntime.resolvedId) return;
|
|
3718
|
-
let reactRefreshDir =
|
|
3432
|
+
let reactRefreshDir = path6.dirname(
|
|
3719
3433
|
require.resolve("react-refresh/package.json")
|
|
3720
3434
|
);
|
|
3721
|
-
let reactRefreshRuntimePath =
|
|
3435
|
+
let reactRefreshRuntimePath = path6.join(
|
|
3722
3436
|
reactRefreshDir,
|
|
3723
3437
|
"cjs/react-refresh-runtime.development.js"
|
|
3724
3438
|
);
|
|
@@ -3899,7 +3613,7 @@ if (import.meta.hot && !inWebWorker) {
|
|
|
3899
3613
|
function getRoute(pluginConfig, file) {
|
|
3900
3614
|
let vite2 = getVite();
|
|
3901
3615
|
let routePath = vite2.normalizePath(
|
|
3902
|
-
|
|
3616
|
+
path6.relative(pluginConfig.appDirectory, file)
|
|
3903
3617
|
);
|
|
3904
3618
|
let route = Object.values(pluginConfig.routes).find(
|
|
3905
3619
|
(r) => vite2.normalizePath(r.file) === routePath
|
|
@@ -3938,7 +3652,7 @@ async function getRouteMetadata(cache, ctx, viteChildCompiler, route, readRouteF
|
|
|
3938
3652
|
caseSensitive: route.caseSensitive,
|
|
3939
3653
|
url: combineURLs(
|
|
3940
3654
|
ctx.publicPath,
|
|
3941
|
-
"/" +
|
|
3655
|
+
"/" + path6.relative(
|
|
3942
3656
|
ctx.rootDirectory,
|
|
3943
3657
|
resolveRelativeRouteFilePath(route, ctx.reactRouterConfig)
|
|
3944
3658
|
)
|
|
@@ -3966,7 +3680,7 @@ function isSpaModeEnabled(reactRouterConfig) {
|
|
|
3966
3680
|
return reactRouterConfig.ssr === false && !isPrerenderingEnabled(reactRouterConfig);
|
|
3967
3681
|
}
|
|
3968
3682
|
async function getPrerenderBuildAndHandler(viteConfig, serverBuildDirectory, serverBuildFile) {
|
|
3969
|
-
let serverBuildPath =
|
|
3683
|
+
let serverBuildPath = path6.join(serverBuildDirectory, serverBuildFile);
|
|
3970
3684
|
let build = await import(url.pathToFileURL(serverBuildPath).toString());
|
|
3971
3685
|
let { createRequestHandler: createHandler } = await import("react-router");
|
|
3972
3686
|
return {
|
|
@@ -3989,16 +3703,16 @@ async function handleSpaMode(viteConfig, reactRouterConfig, serverBuildDirectory
|
|
|
3989
3703
|
let response = await handler(request);
|
|
3990
3704
|
let html = await response.text();
|
|
3991
3705
|
let isPrerenderSpaFallback = build.prerender.includes("/");
|
|
3992
|
-
let
|
|
3706
|
+
let filename3 = isPrerenderSpaFallback ? "__spa-fallback.html" : "index.html";
|
|
3993
3707
|
if (response.status !== 200) {
|
|
3994
3708
|
if (isPrerenderSpaFallback) {
|
|
3995
3709
|
throw new Error(
|
|
3996
|
-
`Prerender: Received a ${response.status} status code from \`entry.server.tsx\` while prerendering your \`${
|
|
3710
|
+
`Prerender: Received a ${response.status} status code from \`entry.server.tsx\` while prerendering your \`${filename3}\` file.
|
|
3997
3711
|
` + html
|
|
3998
3712
|
);
|
|
3999
3713
|
} else {
|
|
4000
3714
|
throw new Error(
|
|
4001
|
-
`SPA Mode: Received a ${response.status} status code from \`entry.server.tsx\` while prerendering your \`${
|
|
3715
|
+
`SPA Mode: Received a ${response.status} status code from \`entry.server.tsx\` while prerendering your \`${filename3}\` file.
|
|
4002
3716
|
` + html
|
|
4003
3717
|
);
|
|
4004
3718
|
}
|
|
@@ -4008,9 +3722,9 @@ async function handleSpaMode(viteConfig, reactRouterConfig, serverBuildDirectory
|
|
|
4008
3722
|
"SPA Mode: Did you forget to include `<Scripts/>` in your root route? Your pre-rendered HTML cannot hydrate without `<Scripts />`."
|
|
4009
3723
|
);
|
|
4010
3724
|
}
|
|
4011
|
-
await fse.writeFile(
|
|
4012
|
-
let prettyDir =
|
|
4013
|
-
let prettyPath =
|
|
3725
|
+
await fse.writeFile(path6.join(clientBuildDirectory, filename3), html);
|
|
3726
|
+
let prettyDir = path6.relative(process.cwd(), clientBuildDirectory);
|
|
3727
|
+
let prettyPath = path6.join(prettyDir, filename3);
|
|
4014
3728
|
if (build.prerender.length > 0) {
|
|
4015
3729
|
viteConfig.logger.info(
|
|
4016
3730
|
`Prerender (html): SPA Fallback -> ${import_picocolors3.default.bold(prettyPath)}`
|
|
@@ -4026,17 +3740,22 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
|
|
|
4026
3740
|
serverBuildPath
|
|
4027
3741
|
);
|
|
4028
3742
|
let routes = createPrerenderRoutes(reactRouterConfig.routes);
|
|
4029
|
-
for (let
|
|
4030
|
-
let matches = (0, import_react_router2.matchRoutes)(routes, `/${
|
|
3743
|
+
for (let path7 of build.prerender) {
|
|
3744
|
+
let matches = (0, import_react_router2.matchRoutes)(routes, `/${path7}/`.replace(/^\/\/+/, "/"));
|
|
4031
3745
|
if (!matches) {
|
|
4032
3746
|
throw new Error(
|
|
4033
|
-
`Unable to prerender path because it does not match any routes: ${
|
|
3747
|
+
`Unable to prerender path because it does not match any routes: ${path7}`
|
|
4034
3748
|
);
|
|
4035
3749
|
}
|
|
4036
3750
|
}
|
|
4037
3751
|
let buildRoutes = createPrerenderRoutes(build.routes);
|
|
4038
|
-
|
|
4039
|
-
|
|
3752
|
+
let headers = {
|
|
3753
|
+
// Header that can be used in the loader to know if you're running at
|
|
3754
|
+
// build time or runtime
|
|
3755
|
+
"X-React-Router-Prerender": "yes"
|
|
3756
|
+
};
|
|
3757
|
+
for (let path7 of build.prerender) {
|
|
3758
|
+
let matches = (0, import_react_router2.matchRoutes)(buildRoutes, `/${path7}/`.replace(/^\/\/+/, "/"));
|
|
4040
3759
|
if (!matches) {
|
|
4041
3760
|
continue;
|
|
4042
3761
|
}
|
|
@@ -4049,18 +3768,20 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
|
|
|
4049
3768
|
if (manifestRoute.loader) {
|
|
4050
3769
|
await prerenderData(
|
|
4051
3770
|
handler,
|
|
4052
|
-
|
|
3771
|
+
path7,
|
|
4053
3772
|
[leafRoute.id],
|
|
4054
3773
|
clientBuildDirectory,
|
|
4055
3774
|
reactRouterConfig,
|
|
4056
|
-
viteConfig
|
|
3775
|
+
viteConfig,
|
|
3776
|
+
{ headers }
|
|
4057
3777
|
);
|
|
4058
3778
|
await prerenderResourceRoute(
|
|
4059
3779
|
handler,
|
|
4060
|
-
|
|
3780
|
+
path7,
|
|
4061
3781
|
clientBuildDirectory,
|
|
4062
3782
|
reactRouterConfig,
|
|
4063
|
-
viteConfig
|
|
3783
|
+
viteConfig,
|
|
3784
|
+
{ headers }
|
|
4064
3785
|
);
|
|
4065
3786
|
} else {
|
|
4066
3787
|
viteConfig.logger.warn(
|
|
@@ -4075,24 +3796,26 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
|
|
|
4075
3796
|
if (!isResourceRoute && hasLoaders) {
|
|
4076
3797
|
data = await prerenderData(
|
|
4077
3798
|
handler,
|
|
4078
|
-
|
|
3799
|
+
path7,
|
|
4079
3800
|
null,
|
|
4080
3801
|
clientBuildDirectory,
|
|
4081
3802
|
reactRouterConfig,
|
|
4082
|
-
viteConfig
|
|
3803
|
+
viteConfig,
|
|
3804
|
+
{ headers }
|
|
4083
3805
|
);
|
|
4084
3806
|
}
|
|
4085
3807
|
await prerenderRoute(
|
|
4086
3808
|
handler,
|
|
4087
|
-
|
|
3809
|
+
path7,
|
|
4088
3810
|
clientBuildDirectory,
|
|
4089
3811
|
reactRouterConfig,
|
|
4090
3812
|
viteConfig,
|
|
4091
3813
|
data ? {
|
|
4092
3814
|
headers: {
|
|
3815
|
+
...headers,
|
|
4093
3816
|
"X-React-Router-Prerender-Data": encodeURI(data)
|
|
4094
3817
|
}
|
|
4095
|
-
} :
|
|
3818
|
+
} : { headers }
|
|
4096
3819
|
);
|
|
4097
3820
|
}
|
|
4098
3821
|
}
|
|
@@ -4137,9 +3860,9 @@ async function prerenderData(handler, prerenderPath, onlyRoutes, clientBuildDire
|
|
|
4137
3860
|
${normalizedPath}`
|
|
4138
3861
|
);
|
|
4139
3862
|
}
|
|
4140
|
-
let outdir =
|
|
4141
|
-
let outfile =
|
|
4142
|
-
await fse.ensureDir(
|
|
3863
|
+
let outdir = path6.relative(process.cwd(), clientBuildDirectory);
|
|
3864
|
+
let outfile = path6.join(outdir, ...normalizedPath.split("/"));
|
|
3865
|
+
await fse.ensureDir(path6.dirname(outfile));
|
|
4143
3866
|
await fse.outputFile(outfile, data);
|
|
4144
3867
|
viteConfig.logger.info(
|
|
4145
3868
|
`Prerender (data): ${prerenderPath} -> ${import_picocolors3.default.bold(outfile)}`
|
|
@@ -4176,9 +3899,9 @@ async function prerenderRoute(handler, prerenderPath, clientBuildDirectory, reac
|
|
|
4176
3899
|
${html}`
|
|
4177
3900
|
);
|
|
4178
3901
|
}
|
|
4179
|
-
let outdir =
|
|
4180
|
-
let outfile =
|
|
4181
|
-
await fse.ensureDir(
|
|
3902
|
+
let outdir = path6.relative(process.cwd(), clientBuildDirectory);
|
|
3903
|
+
let outfile = path6.join(outdir, ...normalizedPath.split("/"), "index.html");
|
|
3904
|
+
await fse.ensureDir(path6.dirname(outfile));
|
|
4182
3905
|
await fse.outputFile(outfile, html);
|
|
4183
3906
|
viteConfig.logger.info(
|
|
4184
3907
|
`Prerender (html): ${prerenderPath} -> ${import_picocolors3.default.bold(outfile)}`
|
|
@@ -4195,9 +3918,9 @@ async function prerenderResourceRoute(handler, prerenderPath, clientBuildDirecto
|
|
|
4195
3918
|
${content.toString("utf8")}`
|
|
4196
3919
|
);
|
|
4197
3920
|
}
|
|
4198
|
-
let outdir =
|
|
4199
|
-
let outfile =
|
|
4200
|
-
await fse.ensureDir(
|
|
3921
|
+
let outdir = path6.relative(process.cwd(), clientBuildDirectory);
|
|
3922
|
+
let outfile = path6.join(outdir, ...normalizedPath.split("/"));
|
|
3923
|
+
await fse.ensureDir(path6.dirname(outfile));
|
|
4201
3924
|
await fse.outputFile(outfile, content);
|
|
4202
3925
|
viteConfig.logger.info(
|
|
4203
3926
|
`Prerender (resource): ${prerenderPath} -> ${import_picocolors3.default.bold(outfile)}`
|
|
@@ -4273,14 +3996,14 @@ async function validateSsrFalsePrerenderExports(viteConfig, ctx, manifest, viteC
|
|
|
4273
3996
|
}
|
|
4274
3997
|
let prerenderRoutes = createPrerenderRoutes(manifest.routes);
|
|
4275
3998
|
let prerenderedRoutes = /* @__PURE__ */ new Set();
|
|
4276
|
-
for (let
|
|
3999
|
+
for (let path7 of prerenderPaths) {
|
|
4277
4000
|
let matches = (0, import_react_router2.matchRoutes)(
|
|
4278
4001
|
prerenderRoutes,
|
|
4279
|
-
`/${
|
|
4002
|
+
`/${path7}/`.replace(/^\/\/+/, "/")
|
|
4280
4003
|
);
|
|
4281
4004
|
invariant(
|
|
4282
4005
|
matches,
|
|
4283
|
-
`Unable to prerender path because it does not match any routes: ${
|
|
4006
|
+
`Unable to prerender path because it does not match any routes: ${path7}`
|
|
4284
4007
|
);
|
|
4285
4008
|
matches.forEach((m) => prerenderedRoutes.add(m.route.id));
|
|
4286
4009
|
}
|
|
@@ -4447,8 +4170,8 @@ function validateRouteChunks({
|
|
|
4447
4170
|
async function cleanBuildDirectory(viteConfig, ctx) {
|
|
4448
4171
|
let buildDirectory = ctx.reactRouterConfig.buildDirectory;
|
|
4449
4172
|
let isWithinRoot = () => {
|
|
4450
|
-
let relativePath =
|
|
4451
|
-
return !relativePath.startsWith("..") && !
|
|
4173
|
+
let relativePath = path6.relative(ctx.rootDirectory, buildDirectory);
|
|
4174
|
+
return !relativePath.startsWith("..") && !path6.isAbsolute(relativePath);
|
|
4452
4175
|
};
|
|
4453
4176
|
if (viteConfig.build.emptyOutDir ?? isWithinRoot()) {
|
|
4454
4177
|
await fse.remove(buildDirectory);
|
|
@@ -4459,7 +4182,7 @@ async function cleanViteManifests(environmentsOptions, ctx) {
|
|
|
4459
4182
|
([environmentName, options]) => {
|
|
4460
4183
|
let outDir = options.build?.outDir;
|
|
4461
4184
|
invariant(outDir, `Expected build.outDir for ${environmentName}`);
|
|
4462
|
-
return
|
|
4185
|
+
return path6.join(outDir, ".vite/manifest.json");
|
|
4463
4186
|
}
|
|
4464
4187
|
);
|
|
4465
4188
|
await Promise.all(
|
|
@@ -4469,7 +4192,7 @@ async function cleanViteManifests(environmentsOptions, ctx) {
|
|
|
4469
4192
|
if (!ctx.viteManifestEnabled) {
|
|
4470
4193
|
await fse.remove(viteManifestPath);
|
|
4471
4194
|
}
|
|
4472
|
-
let viteDir =
|
|
4195
|
+
let viteDir = path6.dirname(viteManifestPath);
|
|
4473
4196
|
let viteDirFiles = await fse.readdir(viteDir);
|
|
4474
4197
|
if (viteDirFiles.length === 0) {
|
|
4475
4198
|
await fse.remove(viteDir);
|
|
@@ -4487,12 +4210,12 @@ async function getBuildManifest({
|
|
|
4487
4210
|
}
|
|
4488
4211
|
let { normalizePath } = await import("vite");
|
|
4489
4212
|
let serverBuildDirectory = getServerBuildDirectory(reactRouterConfig);
|
|
4490
|
-
let resolvedAppDirectory =
|
|
4213
|
+
let resolvedAppDirectory = path6.resolve(rootDirectory, appDirectory);
|
|
4491
4214
|
let rootRelativeRoutes = Object.fromEntries(
|
|
4492
4215
|
Object.entries(routes).map(([id, route]) => {
|
|
4493
|
-
let filePath =
|
|
4216
|
+
let filePath = path6.join(resolvedAppDirectory, route.file);
|
|
4494
4217
|
let rootRelativeFilePath = normalizePath(
|
|
4495
|
-
|
|
4218
|
+
path6.relative(rootDirectory, filePath)
|
|
4496
4219
|
);
|
|
4497
4220
|
return [id, { ...route, file: rootRelativeFilePath }];
|
|
4498
4221
|
})
|
|
@@ -4510,7 +4233,7 @@ async function getBuildManifest({
|
|
|
4510
4233
|
(route2) => configRouteToBranchRoute({
|
|
4511
4234
|
...route2,
|
|
4512
4235
|
// Ensure absolute paths are passed to the serverBundles function
|
|
4513
|
-
file:
|
|
4236
|
+
file: path6.join(resolvedAppDirectory, route2.file)
|
|
4514
4237
|
})
|
|
4515
4238
|
)
|
|
4516
4239
|
});
|
|
@@ -4534,10 +4257,10 @@ async function getBuildManifest({
|
|
|
4534
4257
|
buildManifest.serverBundles[serverBundleId] ??= {
|
|
4535
4258
|
id: serverBundleId,
|
|
4536
4259
|
file: normalizePath(
|
|
4537
|
-
|
|
4538
|
-
|
|
4260
|
+
path6.join(
|
|
4261
|
+
path6.relative(
|
|
4539
4262
|
rootDirectory,
|
|
4540
|
-
|
|
4263
|
+
path6.join(serverBuildDirectory, serverBundleId)
|
|
4541
4264
|
),
|
|
4542
4265
|
reactRouterConfig.serverBuildFile
|
|
4543
4266
|
)
|
|
@@ -4556,10 +4279,10 @@ function mergeEnvironmentOptions(base, ...overrides) {
|
|
|
4556
4279
|
}
|
|
4557
4280
|
async function getEnvironmentOptionsResolvers(ctx, viteCommand) {
|
|
4558
4281
|
let { serverBuildFile, serverModuleFormat } = ctx.reactRouterConfig;
|
|
4559
|
-
let packageRoot =
|
|
4282
|
+
let packageRoot = path6.dirname(
|
|
4560
4283
|
require.resolve("@react-router/dev/package.json")
|
|
4561
4284
|
);
|
|
4562
|
-
let { moduleSyncEnabled } = await import(`file:///${
|
|
4285
|
+
let { moduleSyncEnabled } = await import(`file:///${path6.join(packageRoot, "module-sync-enabled/index.mjs")}`);
|
|
4563
4286
|
let vite2 = getVite();
|
|
4564
4287
|
let viteServerConditions = [
|
|
4565
4288
|
...vite2.defaultServerConditions ?? [],
|
|
@@ -4616,7 +4339,7 @@ async function getEnvironmentOptionsResolvers(ctx, viteCommand) {
|
|
|
4616
4339
|
copyPublicDir: false,
|
|
4617
4340
|
// Assets in the public directory are only used by the client
|
|
4618
4341
|
rollupOptions: {
|
|
4619
|
-
input: (ctx.reactRouterConfig.future.unstable_viteEnvironmentApi ? viteUserConfig.environments?.ssr?.build?.rollupOptions?.input : viteUserConfig.build?.rollupOptions?.input) ??
|
|
4342
|
+
input: (ctx.reactRouterConfig.future.unstable_viteEnvironmentApi ? viteUserConfig.environments?.ssr?.build?.rollupOptions?.input : viteUserConfig.build?.rollupOptions?.input) ?? virtual2.serverBuild.id,
|
|
4620
4343
|
output: {
|
|
4621
4344
|
entryFileNames: serverBuildFile,
|
|
4622
4345
|
format: serverModuleFormat
|
|
@@ -4633,7 +4356,7 @@ async function getEnvironmentOptionsResolvers(ctx, viteCommand) {
|
|
|
4633
4356
|
ctx.entryClientFilePath,
|
|
4634
4357
|
...Object.values(ctx.reactRouterConfig.routes).flatMap(
|
|
4635
4358
|
(route) => {
|
|
4636
|
-
let routeFilePath =
|
|
4359
|
+
let routeFilePath = path6.resolve(
|
|
4637
4360
|
ctx.reactRouterConfig.appDirectory,
|
|
4638
4361
|
route.file
|
|
4639
4362
|
);
|
|
@@ -4656,9 +4379,8 @@ async function getEnvironmentOptionsResolvers(ctx, viteCommand) {
|
|
|
4656
4379
|
""
|
|
4657
4380
|
) : null;
|
|
4658
4381
|
let routeChunkSuffix = routeChunkName ? `-${(0, import_kebabCase.default)(routeChunkName)}` : "";
|
|
4659
|
-
|
|
4660
|
-
|
|
4661
|
-
assetsDir,
|
|
4382
|
+
return path6.posix.join(
|
|
4383
|
+
(ctx.reactRouterConfig.future.unstable_viteEnvironmentApi ? viteUserConfig?.environments?.client?.build?.assetsDir : viteUserConfig?.build?.assetsDir) ?? "assets",
|
|
4662
4384
|
`[name]${routeChunkSuffix}-[hash].js`
|
|
4663
4385
|
);
|
|
4664
4386
|
}
|
|
@@ -4693,6 +4415,9 @@ async function getEnvironmentOptionsResolvers(ctx, viteCommand) {
|
|
|
4693
4415
|
}
|
|
4694
4416
|
});
|
|
4695
4417
|
}
|
|
4418
|
+
if (ctx.reactRouterConfig.future.unstable_viteEnvironmentApi && viteCommand === "serve") {
|
|
4419
|
+
environmentOptionsResolvers[CSS_DEV_HELPER_ENVIRONMENT_NAME] = () => ({});
|
|
4420
|
+
}
|
|
4696
4421
|
return environmentOptionsResolvers;
|
|
4697
4422
|
}
|
|
4698
4423
|
function resolveEnvironmentsOptions(environmentResolvers, resolverOptions) {
|