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