@react-router/dev 0.0.0-experimental-312bddb22 → 0.0.0-experimental-7de693505

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.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @react-router/dev v0.0.0-experimental-312bddb22
2
+ * @react-router/dev v0.0.0-experimental-7de693505
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @react-router/dev v0.0.0-experimental-312bddb22
2
+ * @react-router/dev v0.0.0-experimental-7de693505
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
package/dist/cli/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @react-router/dev v0.0.0-experimental-312bddb22
2
+ * @react-router/dev v0.0.0-experimental-7de693505
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
package/dist/cli/run.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @react-router/dev v0.0.0-experimental-312bddb22
2
+ * @react-router/dev v0.0.0-experimental-7de693505
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @react-router/dev v0.0.0-experimental-312bddb22
2
+ * @react-router/dev v0.0.0-experimental-7de693505
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
package/dist/colors.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @react-router/dev v0.0.0-experimental-312bddb22
2
+ * @react-router/dev v0.0.0-experimental-7de693505
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @react-router/dev v0.0.0-experimental-312bddb22
2
+ * @react-router/dev v0.0.0-experimental-7de693505
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @react-router/dev v0.0.0-experimental-312bddb22
2
+ * @react-router/dev v0.0.0-experimental-7de693505
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -49,7 +49,7 @@ function setAppDirectory(directory) {
49
49
  * This is designed to support resolving file system routes.
50
50
  */
51
51
  function getAppDirectory() {
52
- invariant["default"](appDirectory);
52
+ invariant(appDirectory);
53
53
  return appDirectory;
54
54
  }
55
55
  const routeConfigEntrySchema = v__namespace.pipe(v__namespace.custom(value => {
package/dist/invariant.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @react-router/dev v0.0.0-experimental-312bddb22
2
+ * @react-router/dev v0.0.0-experimental-7de693505
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -10,8 +10,6 @@
10
10
  */
11
11
  'use strict';
12
12
 
13
- Object.defineProperty(exports, '__esModule', { value: true });
14
-
15
13
  function invariant(value, message) {
16
14
  if (value === false || value === null || typeof value === "undefined") {
17
15
  console.error("The following error is a bug in Remix; please open an issue! https://github.com/remix-run/remix/issues/new");
@@ -19,4 +17,4 @@ function invariant(value, message) {
19
17
  }
20
18
  }
21
19
 
22
- exports["default"] = invariant;
20
+ module.exports = invariant;
package/dist/routes.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @react-router/dev v0.0.0-experimental-312bddb22
2
+ * @react-router/dev v0.0.0-experimental-7de693505
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -0,0 +1,6 @@
1
+ import type ts from "typescript/lib/tsserverlibrary";
2
+ export default function init(modules: {
3
+ typescript: typeof ts;
4
+ }): {
5
+ create: (info: ts.server.PluginCreateInfo) => ts.LanguageService;
6
+ };
@@ -0,0 +1,56 @@
1
+ /**
2
+ * @react-router/dev v0.0.0-experimental-7de693505
3
+ *
4
+ * Copyright (c) Remix Software Inc.
5
+ *
6
+ * This source code is licensed under the MIT license found in the
7
+ * LICENSE.md file in the root directory of this source tree.
8
+ *
9
+ * @license MIT
10
+ */
11
+ 'use strict';
12
+
13
+ var Path = require('pathe');
14
+ var typegen = require('./typegen.js');
15
+
16
+ function _interopNamespace(e) {
17
+ if (e && e.__esModule) return e;
18
+ var n = Object.create(null);
19
+ if (e) {
20
+ Object.keys(e).forEach(function (k) {
21
+ if (k !== 'default') {
22
+ var d = Object.getOwnPropertyDescriptor(e, k);
23
+ Object.defineProperty(n, k, d.get ? d : {
24
+ enumerable: true,
25
+ get: function () { return e[k]; }
26
+ });
27
+ }
28
+ });
29
+ }
30
+ n["default"] = e;
31
+ return Object.freeze(n);
32
+ }
33
+
34
+ var Path__namespace = /*#__PURE__*/_interopNamespace(Path);
35
+
36
+ // For compatibility with the TS language service plugin API, this entrypoint:
37
+ function init(modules) {
38
+ function create(info) {
39
+ const {
40
+ logger
41
+ } = info.project.projectService;
42
+ logger.info("[react-router] setup");
43
+ const rootDirectory = Path__namespace.normalize(info.project.getCurrentDirectory());
44
+ const ctx = {
45
+ rootDirectory,
46
+ appDirectory: Path__namespace.join(rootDirectory, "app")
47
+ };
48
+ typegen.watch(ctx);
49
+ return info.languageService;
50
+ }
51
+ return {
52
+ create
53
+ };
54
+ }
55
+
56
+ module.exports = init;
@@ -0,0 +1,9 @@
1
+ import { type RouteManifest, type RouteManifestEntry } from "../config/routes";
2
+ type Context = {
3
+ rootDirectory: string;
4
+ appDirectory: string;
5
+ };
6
+ export declare function getPath(ctx: Context, route: RouteManifestEntry): string;
7
+ export declare function watch(ctx: Context): Promise<void>;
8
+ export declare function typegenAll(ctx: Context, routes: RouteManifest): Promise<void>;
9
+ export {};
@@ -0,0 +1,165 @@
1
+ /**
2
+ * @react-router/dev v0.0.0-experimental-7de693505
3
+ *
4
+ * Copyright (c) Remix Software Inc.
5
+ *
6
+ * This source code is licensed under the MIT license found in the
7
+ * LICENSE.md file in the root directory of this source tree.
8
+ *
9
+ * @license MIT
10
+ */
11
+ 'use strict';
12
+
13
+ Object.defineProperty(exports, '__esModule', { value: true });
14
+
15
+ var fs = require('node:fs');
16
+ var Chokidar = require('chokidar');
17
+ var dedent = require('dedent');
18
+ var Path = require('pathe');
19
+ var Pathe = require('pathe/utils');
20
+ var routes = require('../config/routes.js');
21
+ var viteNode = require('../vite/vite-node.js');
22
+
23
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
24
+
25
+ function _interopNamespace(e) {
26
+ if (e && e.__esModule) return e;
27
+ var n = Object.create(null);
28
+ if (e) {
29
+ Object.keys(e).forEach(function (k) {
30
+ if (k !== 'default') {
31
+ var d = Object.getOwnPropertyDescriptor(e, k);
32
+ Object.defineProperty(n, k, d.get ? d : {
33
+ enumerable: true,
34
+ get: function () { return e[k]; }
35
+ });
36
+ }
37
+ });
38
+ }
39
+ n["default"] = e;
40
+ return Object.freeze(n);
41
+ }
42
+
43
+ var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
44
+ var Chokidar__default = /*#__PURE__*/_interopDefaultLegacy(Chokidar);
45
+ var dedent__default = /*#__PURE__*/_interopDefaultLegacy(dedent);
46
+ var Path__namespace = /*#__PURE__*/_interopNamespace(Path);
47
+ var Pathe__namespace = /*#__PURE__*/_interopNamespace(Pathe);
48
+
49
+ function getDirectory(ctx) {
50
+ return Path__namespace.join(ctx.rootDirectory, ".react-router/types");
51
+ }
52
+ function getPath(ctx, route) {
53
+ return Path__namespace.join(getDirectory(ctx), "app", Path__namespace.dirname(route.file), "+types." + Path__namespace.basename(route.file));
54
+ }
55
+ async function watch(ctx) {
56
+ const appDirectory = Path__namespace.normalize(ctx.appDirectory);
57
+ const routesTsPath = Path__namespace.join(appDirectory, "routes.ts");
58
+ const routesViteNodeContext = await viteNode.createContext();
59
+ async function getRoutes() {
60
+ routesViteNodeContext.devServer.moduleGraph.invalidateAll();
61
+ routesViteNodeContext.runner.moduleCache.clear();
62
+ const result = await routesViteNodeContext.runner.executeFile(routesTsPath);
63
+ return routes.configRoutesToRouteManifest(result.routes);
64
+ }
65
+ const initialRoutes = await getRoutes();
66
+ await typegenAll(ctx, initialRoutes);
67
+ const watcher = Chokidar__default["default"].watch(appDirectory, {
68
+ ignoreInitial: true
69
+ });
70
+ watcher.on("all", async (event, path) => {
71
+ path = Path__namespace.normalize(path);
72
+ const routes = await getRoutes();
73
+ const routeConfigChanged = Boolean(routesViteNodeContext.devServer.moduleGraph.getModuleById(path));
74
+ if (routeConfigChanged) {
75
+ await typegenAll(ctx, routes);
76
+ return;
77
+ }
78
+ const isRoute = Object.values(routes).find(route => path === Path__namespace.join(ctx.appDirectory, route.file));
79
+ if (isRoute && (event === "add" || event === "unlink")) {
80
+ await typegenAll(ctx, routes);
81
+ return;
82
+ }
83
+ });
84
+ }
85
+ async function typegenAll(ctx, routes) {
86
+ fs__default["default"].rmSync(getDirectory(ctx), {
87
+ recursive: true,
88
+ force: true
89
+ });
90
+ Object.values(routes).forEach(route => {
91
+ const typesPath = getPath(ctx, route);
92
+ const content = getModule(routes, route);
93
+ fs__default["default"].mkdirSync(Path__namespace.dirname(typesPath), {
94
+ recursive: true
95
+ });
96
+ fs__default["default"].writeFileSync(typesPath, content);
97
+ });
98
+ }
99
+ function getModule(routes, route) {
100
+ return dedent__default["default"]`
101
+ // typegen: ${route.file}
102
+ import * as T from "react-router/types"
103
+
104
+ export type Params = {${formattedParamsProperties(routes, route)}}
105
+
106
+ type Route = typeof import("./${Pathe__namespace.filename(route.file)}")
107
+
108
+ export type LoaderData = T.LoaderData<Route>
109
+ export type ActionData = T.ActionData<Route>
110
+
111
+ export type LoaderArgs = T.ServerLoaderArgs<Params>
112
+ export type ClientLoaderArgs = T.ClientLoaderArgs<Params, Route>
113
+ export type ActionArgs = T.ServerActionArgs<Params>
114
+ export type ClientActionArgs = T.ClientActionArgs<Params, Route>
115
+
116
+ export type HydrateFallbackProps = T.HydrateFallbackProps<Params>
117
+ export type DefaultProps = T.DefaultProps<Params, LoaderData, ActionData>
118
+ export type ErrorBoundaryProps = T.ErrorBoundaryProps<Params, LoaderData, ActionData>
119
+ `;
120
+ }
121
+ function formattedParamsProperties(routes, route) {
122
+ const urlpath = routeLineage(routes, route).map(route => route.path).join("/");
123
+ const params = parseParams(urlpath);
124
+ const indent = " ".repeat(3);
125
+ const properties = Object.entries(params).map(([name, values]) => {
126
+ if (values.length === 1) {
127
+ const isOptional = values[0];
128
+ return indent + (isOptional ? `${name}?: string` : `${name}: string`);
129
+ }
130
+ const items = values.map(isOptional => isOptional ? "string | undefined" : "string");
131
+ return indent + `${name}: [${items.join(", ")}]`;
132
+ });
133
+ // prettier-ignore
134
+ const body = properties.length === 0 ? "" : "\n" + properties.join("\n") + "\n";
135
+ return body;
136
+ }
137
+ function routeLineage(routes, route) {
138
+ const result = [];
139
+ while (route) {
140
+ result.push(route);
141
+ if (!route.parentId) break;
142
+ route = routes[route.parentId];
143
+ }
144
+ result.reverse();
145
+ return result;
146
+ }
147
+ function parseParams(urlpath) {
148
+ const result = {};
149
+ let segments = urlpath.split("/");
150
+ segments.filter(s => s.startsWith(":")).forEach(param => {
151
+ param = param.slice(1); // omit leading `:`
152
+ let isOptional = param.endsWith("?");
153
+ if (isOptional) {
154
+ param = param.slice(0, -1); // omit trailing `?`
155
+ }
156
+ result[param] ??= [];
157
+ result[param].push(isOptional);
158
+ return;
159
+ });
160
+ return result;
161
+ }
162
+
163
+ exports.getPath = getPath;
164
+ exports.typegenAll = typegenAll;
165
+ exports.watch = watch;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @react-router/dev v0.0.0-experimental-312bddb22
2
+ * @react-router/dev v0.0.0-experimental-7de693505
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @react-router/dev v0.0.0-experimental-312bddb22
2
+ * @react-router/dev v0.0.0-experimental-7de693505
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -32,7 +32,7 @@ function getAddressableRoutes(routes) {
32
32
  let route = routes[id];
33
33
  // We omit the parent route of index routes since the index route takes ownership of its parent's path
34
34
  if (route.index) {
35
- invariant["default"](route.parentId, `Expected index route "${route.id}" to have "parentId" set`);
35
+ invariant(route.parentId, `Expected index route "${route.id}" to have "parentId" set`);
36
36
  nonAddressableIds.add(route.parentId);
37
37
  }
38
38
  // We omit pathless routes since they can only be addressed via descendant routes
@@ -47,7 +47,7 @@ function getRouteBranch(routes, routeId) {
47
47
  let currentRouteId = routeId;
48
48
  while (currentRouteId) {
49
49
  let route = routes[currentRouteId];
50
- invariant["default"](route, `Missing route for ${currentRouteId}`);
50
+ invariant(route, `Missing route for ${currentRouteId}`);
51
51
  branch.push(route);
52
52
  currentRouteId = route.parentId;
53
53
  }
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @react-router/dev v0.0.0-experimental-312bddb22
2
+ * @react-router/dev v0.0.0-experimental-7de693505
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @react-router/dev v0.0.0-experimental-312bddb22
2
+ * @react-router/dev v0.0.0-experimental-7de693505
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @react-router/dev v0.0.0-experimental-312bddb22
2
+ * @react-router/dev v0.0.0-experimental-7de693505
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1,5 +1,5 @@
1
1
  import type * as Vite from "vite";
2
- import type { ViteNodeRunner } from "vite-node/client";
2
+ import type * as ViteNode from "./vite-node";
3
3
  import { type RouteManifest, type RouteManifestEntry } from "../config/routes";
4
4
  declare const excludedConfigPresetKeys: readonly ["presets"];
5
5
  type ExcludedConfigPresetKey = (typeof excludedConfigPresetKeys)[number];
@@ -160,13 +160,13 @@ export type ResolvedReactRouterConfig = Readonly<{
160
160
  ssr: boolean;
161
161
  }>;
162
162
  export declare function resolvePublicPath(viteUserConfig: Vite.UserConfig): string;
163
- export declare function resolveReactRouterConfig({ rootDirectory, reactRouterUserConfig, routeConfigChanged, viteUserConfig, viteCommand, viteNodeRunner, }: {
163
+ export declare function resolveReactRouterConfig({ rootDirectory, reactRouterUserConfig, routeConfigChanged, viteUserConfig, viteCommand, routesViteNodeContext, }: {
164
164
  rootDirectory: string;
165
165
  reactRouterUserConfig: ReactRouterConfig;
166
166
  routeConfigChanged: boolean;
167
167
  viteUserConfig: Vite.UserConfig;
168
168
  viteCommand: Vite.ConfigEnv["command"];
169
- viteNodeRunner: ViteNodeRunner;
169
+ routesViteNodeContext: ViteNode.Context;
170
170
  }): Promise<Readonly<{
171
171
  /**
172
172
  * The absolute path to the application source directory.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @react-router/dev v0.0.0-experimental-312bddb22
2
+ * @react-router/dev v0.0.0-experimental-7de693505
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -84,7 +84,7 @@ async function resolveReactRouterConfig({
84
84
  routeConfigChanged,
85
85
  viteUserConfig,
86
86
  viteCommand,
87
- viteNodeRunner
87
+ routesViteNodeContext
88
88
  }) {
89
89
  var _viteUserConfig$serve;
90
90
  let vite = importViteEsmSync.importViteEsmSync();
@@ -165,7 +165,7 @@ async function resolveReactRouterConfig({
165
165
  throw new FriendlyError(`Route config file not found at "${routeConfigDisplayPath}".`);
166
166
  }
167
167
  routes.setAppDirectory(appDirectory);
168
- let routeConfigExport = (await viteNodeRunner.executeFile(path__default["default"].join(appDirectory, routeConfigFile))).routes;
168
+ let routeConfigExport = (await routesViteNodeContext.runner.executeFile(path__default["default"].join(appDirectory, routeConfigFile))).routes;
169
169
  let routeConfig = await routeConfigExport;
170
170
  let result = routes.validateRouteConfig({
171
171
  routeConfigFile,
package/dist/vite/dev.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @react-router/dev v0.0.0-experimental-312bddb22
2
+ * @react-router/dev v0.0.0-experimental-7de693505
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @react-router/dev v0.0.0-experimental-312bddb22
2
+ * @react-router/dev v0.0.0-experimental-7de693505
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -20,7 +20,7 @@ async function preloadViteEsm() {
20
20
  vite = await import('vite');
21
21
  }
22
22
  function importViteEsmSync() {
23
- invariant["default"](vite, "importViteEsmSync() called before preloadViteEsm()");
23
+ invariant(vite, "importViteEsmSync() called before preloadViteEsm()");
24
24
  return vite;
25
25
  }
26
26
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @react-router/dev v0.0.0-experimental-312bddb22
2
+ * @react-router/dev v0.0.0-experimental-7de693505
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -37,7 +37,7 @@ function fromNodeHeaders(nodeHeaders) {
37
37
  function fromNodeRequest(nodeReq, nodeRes) {
38
38
  let origin = nodeReq.headers.origin && "null" !== nodeReq.headers.origin ? nodeReq.headers.origin : `http://${nodeReq.headers.host}`;
39
39
  // Use `req.originalUrl` so React Router is aware of the full path
40
- invariant["default"](nodeReq.originalUrl, "Expected `nodeReq.originalUrl` to be defined");
40
+ invariant(nodeReq.originalUrl, "Expected `nodeReq.originalUrl` to be defined");
41
41
  let url = new URL(nodeReq.originalUrl, origin);
42
42
  // Abort action/loaders once we can no longer write a response
43
43
  let controller = new AbortController();
@@ -6,7 +6,7 @@ export declare function resolveViteConfig({ configFile, mode, root, }: {
6
6
  configFile?: string;
7
7
  mode?: string;
8
8
  root: string;
9
- }): Promise<Readonly<Omit<Vite.UserConfig, "plugins" | "css" | "assetsInclude" | "optimizeDeps" | "worker" | "build"> & {
9
+ }): Promise<Readonly<Omit<Vite.UserConfig, "optimizeDeps" | "plugins" | "css" | "assetsInclude" | "worker" | "build"> & {
10
10
  configFile: string | undefined;
11
11
  configFileDependencies: string[];
12
12
  inlineConfig: Vite.InlineConfig;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @react-router/dev v0.0.0-experimental-312bddb22
2
+ * @react-router/dev v0.0.0-experimental-7de693505
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -15,9 +15,6 @@ Object.defineProperty(exports, '__esModule', { value: true });
15
15
  var node_crypto = require('node:crypto');
16
16
  var path = require('node:path');
17
17
  var url = require('node:url');
18
- var server = require('vite-node/server');
19
- var client = require('vite-node/client');
20
- var sourceMap = require('vite-node/source-map');
21
18
  var fse = require('fs-extra');
22
19
  var babel$1 = require('@babel/core');
23
20
  var reactRouter = require('react-router');
@@ -35,6 +32,7 @@ var removeExports = require('./remove-exports.js');
35
32
  var importViteEsmSync = require('./import-vite-esm-sync.js');
36
33
  var config = require('./config.js');
37
34
  var withProps = require('./with-props.js');
35
+ var viteNode = require('./vite-node.js');
38
36
  var parser = require('@babel/parser');
39
37
 
40
38
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
@@ -241,7 +239,7 @@ let getServerBuildDirectory = ctx => path__namespace.join(ctx.reactRouterConfig.
241
239
  let getClientBuildDirectory = reactRouterConfig => path__namespace.join(reactRouterConfig.buildDirectory, "client");
242
240
  let defaultEntriesDir = path__namespace.resolve(__dirname, "..", "config", "defaults");
243
241
  let defaultEntries = fse__namespace.readdirSync(defaultEntriesDir).map(filename => path__namespace.join(defaultEntriesDir, filename));
244
- invariant["default"](defaultEntries.length > 0, "No default entries found");
242
+ invariant(defaultEntries.length > 0, "No default entries found");
245
243
  let reactRouterDevLoadContext = () => ({});
246
244
  // Inlined from https://github.com/jsdf/deep-freeze
247
245
  let deepFreeze = o => {
@@ -268,8 +266,7 @@ const reactRouterVitePlugin = _config => {
268
266
  let viteConfig;
269
267
  let cssModulesManifest = {};
270
268
  let viteChildCompiler = null;
271
- let routeConfigViteServer = null;
272
- let viteNodeRunner = null;
269
+ let routesViteNodeContext = null;
273
270
  let ssrExternals = isInReactRouterMonorepo() ? [
274
271
  // This is only needed within this repo because these packages
275
272
  // are linked to a directory outside of node_modules so Vite
@@ -286,14 +283,14 @@ const reactRouterVitePlugin = _config => {
286
283
  } = {}) => {
287
284
  var _viteUserConfig$build;
288
285
  let rootDirectory = viteUserConfig.root ?? process.env.REACT_ROUTER_ROOT ?? process.cwd();
289
- invariant["default"](viteNodeRunner);
286
+ invariant(routesViteNodeContext);
290
287
  let reactRouterConfig = await config.resolveReactRouterConfig({
291
288
  rootDirectory,
292
289
  reactRouterUserConfig,
293
290
  routeConfigChanged,
294
291
  viteUserConfig,
295
292
  viteCommand,
296
- viteNodeRunner
293
+ routesViteNodeContext
297
294
  });
298
295
  let {
299
296
  entryClientFilePath,
@@ -322,11 +319,11 @@ const reactRouterVitePlugin = _config => {
322
319
  };
323
320
  };
324
321
  let pluginIndex = pluginName => {
325
- invariant["default"](viteConfig);
322
+ invariant(viteConfig);
326
323
  return viteConfig.plugins.findIndex(plugin => plugin.name === pluginName);
327
324
  };
328
325
  let getServerEntry = async () => {
329
- invariant["default"](viteConfig, "viteconfig required to generate the server entry");
326
+ invariant(viteConfig, "viteconfig required to generate the server entry");
330
327
  let routes = ctx.serverBundleBuildConfig ?
331
328
  // For server bundle builds, the server build should only import the
332
329
  // routes for this bundle rather than importing all routes
@@ -381,7 +378,7 @@ const reactRouterVitePlugin = _config => {
381
378
  return new Set([...cssUrlPaths, ...chunkAssetPaths]);
382
379
  };
383
380
  let generateReactRouterManifestsForBuild = async () => {
384
- invariant["default"](viteConfig);
381
+ invariant(viteConfig);
385
382
  let viteManifest = await loadViteManifest(getClientBuildDirectory(ctx.reactRouterConfig));
386
383
  let entry = getReactRouterManifestBuildAssets(ctx, viteManifest, ctx.entryClientFilePath);
387
384
  let browserRoutes = {};
@@ -489,36 +486,13 @@ const reactRouterVitePlugin = _config => {
489
486
  viteUserConfig = _viteUserConfig;
490
487
  viteConfigEnv = _viteConfigEnv;
491
488
  viteCommand = viteConfigEnv.command;
492
- routeConfigViteServer = await vite.createServer({
489
+ routesViteNodeContext = await viteNode.createContext({
493
490
  mode: viteConfigEnv.mode,
494
491
  server: {
495
- watch: viteCommand === "build" ? null : undefined,
496
- preTransformRequests: false,
497
- hmr: false
492
+ watch: viteCommand === "build" ? null : undefined
498
493
  },
499
494
  ssr: {
500
495
  external: ssrExternals
501
- },
502
- optimizeDeps: {
503
- noDiscovery: true
504
- },
505
- configFile: false,
506
- envFile: false,
507
- plugins: []
508
- });
509
- await routeConfigViteServer.pluginContainer.buildStart({});
510
- let viteNodeServer = new server.ViteNodeServer(routeConfigViteServer);
511
- sourceMap.installSourcemapsSupport({
512
- getSourceMap: source => viteNodeServer.getSourceMap(source)
513
- });
514
- viteNodeRunner = new client.ViteNodeRunner({
515
- root: routeConfigViteServer.config.root,
516
- base: routeConfigViteServer.config.base,
517
- fetchModule(id) {
518
- return viteNodeServer.fetchModule(id);
519
- },
520
- resolveId(id, importer) {
521
- return viteNodeServer.resolveId(id, importer);
522
496
  }
523
497
  });
524
498
  await updatePluginContext();
@@ -630,7 +604,7 @@ const reactRouterVitePlugin = _config => {
630
604
  async configResolved(resolvedViteConfig) {
631
605
  await esModuleLexer.init;
632
606
  viteConfig = resolvedViteConfig;
633
- invariant["default"](viteConfig);
607
+ invariant(viteConfig);
634
608
  // We load the same Vite config file again for the child compiler so
635
609
  // that both parent and child compiler's plugins have independent state.
636
610
  // If we re-used the `viteUserConfig.plugins` array for the child
@@ -648,7 +622,7 @@ const reactRouterVitePlugin = _config => {
648
622
  mode: viteConfig.mode,
649
623
  isSsrBuild: ctx.isSsrBuild
650
624
  }, viteConfig.configFile);
651
- invariant["default"](childCompilerConfigFile, "Vite config file was unable to be resolved for React Router child compiler");
625
+ invariant(childCompilerConfigFile, "Vite config file was unable to be resolved for React Router child compiler");
652
626
  // Validate that commonly used Rollup plugins that need to run before
653
627
  // ours are in the correct order. This is because Rollup plugins can't
654
628
  // set `enforce: "pre"` like Vite plugins can. Explicitly validating
@@ -691,7 +665,7 @@ const reactRouterVitePlugin = _config => {
691
665
  }
692
666
  },
693
667
  buildStart() {
694
- invariant["default"](viteConfig);
668
+ invariant(viteConfig);
695
669
  if (viteCommand === "build" && viteConfig.mode === "production" && !viteConfig.build.ssr && viteConfig.build.sourcemap) {
696
670
  viteConfig.logger.warn(colors__default["default"].yellow("\n" + colors__default["default"].bold(" ⚠️ Source maps are enabled in production\n") + ["This makes your server code publicly", "visible in the browser. This is highly", "discouraged! If you insist, ensure that", "you are using environment variables for", "secrets and not hard-coding them in", "your source code."].map(line => " " + line).join("\n") + "\n"));
697
671
  }
@@ -721,19 +695,19 @@ const reactRouterVitePlugin = _config => {
721
695
  });
722
696
  // Invalidate virtual modules and update cached plugin config via file watcher
723
697
  viteDevServer.watcher.on("all", async (eventName, rawFilepath) => {
724
- var _viteConfig, _routeConfigViteServe;
698
+ var _viteConfig, _routesViteNodeContex, _routesViteNodeContex2;
725
699
  let {
726
700
  normalizePath
727
701
  } = importViteEsmSync.importViteEsmSync();
728
702
  let filepath = normalizePath(rawFilepath);
729
703
  let appFileAddedOrRemoved = (eventName === "add" || eventName === "unlink") && filepath.startsWith(normalizePath(ctx.reactRouterConfig.appDirectory));
730
- invariant["default"]((_viteConfig = viteConfig) === null || _viteConfig === void 0 ? void 0 : _viteConfig.configFile);
704
+ invariant((_viteConfig = viteConfig) === null || _viteConfig === void 0 ? void 0 : _viteConfig.configFile);
731
705
  let viteConfigChanged = eventName === "change" && filepath === normalizePath(viteConfig.configFile);
732
- let routeConfigChanged = Boolean((_routeConfigViteServe = routeConfigViteServer) === null || _routeConfigViteServe === void 0 ? void 0 : _routeConfigViteServe.moduleGraph.getModuleById(filepath));
706
+ let routeConfigChanged = Boolean((_routesViteNodeContex = routesViteNodeContext) === null || _routesViteNodeContex === void 0 ? void 0 : (_routesViteNodeContex2 = _routesViteNodeContex.devServer) === null || _routesViteNodeContex2 === void 0 ? void 0 : _routesViteNodeContex2.moduleGraph.getModuleById(filepath));
733
707
  if (routeConfigChanged || appFileAddedOrRemoved) {
734
- var _routeConfigViteServe2, _viteNodeRunner;
735
- (_routeConfigViteServe2 = routeConfigViteServer) === null || _routeConfigViteServe2 === void 0 ? void 0 : _routeConfigViteServe2.moduleGraph.invalidateAll();
736
- (_viteNodeRunner = viteNodeRunner) === null || _viteNodeRunner === void 0 ? void 0 : _viteNodeRunner.moduleCache.clear();
708
+ var _routesViteNodeContex3, _routesViteNodeContex4, _routesViteNodeContex5, _routesViteNodeContex6;
709
+ (_routesViteNodeContex3 = routesViteNodeContext) === null || _routesViteNodeContex3 === void 0 ? void 0 : (_routesViteNodeContex4 = _routesViteNodeContex3.devServer) === null || _routesViteNodeContex4 === void 0 ? void 0 : _routesViteNodeContex4.moduleGraph.invalidateAll();
710
+ (_routesViteNodeContex5 = routesViteNodeContext) === null || _routesViteNodeContex5 === void 0 ? void 0 : (_routesViteNodeContex6 = _routesViteNodeContex5.runner) === null || _routesViteNodeContex6 === void 0 ? void 0 : _routesViteNodeContex6.moduleCache.clear();
737
711
  }
738
712
  if (appFileAddedOrRemoved || viteConfigChanged || routeConfigChanged) {
739
713
  let lastReactRouterConfig = ctx.reactRouterConfig;
@@ -773,7 +747,7 @@ const reactRouterVitePlugin = _config => {
773
747
  if (!ctx.isSsrBuild) {
774
748
  return;
775
749
  }
776
- invariant["default"](viteConfig);
750
+ invariant(viteConfig);
777
751
  let clientBuildDirectory = getClientBuildDirectory(ctx.reactRouterConfig);
778
752
  let serverBuildDirectory = getServerBuildDirectory(ctx);
779
753
  let ssrViteManifest = await loadViteManifest(serverBuildDirectory);
@@ -819,9 +793,9 @@ const reactRouterVitePlugin = _config => {
819
793
  }
820
794
  },
821
795
  async buildEnd() {
822
- var _viteChildCompiler, _routeConfigViteServe3;
796
+ var _viteChildCompiler, _routesViteNodeContex7, _routesViteNodeContex8;
823
797
  await ((_viteChildCompiler = viteChildCompiler) === null || _viteChildCompiler === void 0 ? void 0 : _viteChildCompiler.close());
824
- await ((_routeConfigViteServe3 = routeConfigViteServer) === null || _routeConfigViteServe3 === void 0 ? void 0 : _routeConfigViteServe3.close());
798
+ await ((_routesViteNodeContex7 = routesViteNodeContext) === null || _routesViteNodeContex7 === void 0 ? void 0 : (_routesViteNodeContex8 = _routesViteNodeContex7.devServer) === null || _routesViteNodeContex8 === void 0 ? void 0 : _routesViteNodeContex8.close());
825
799
  }
826
800
  }, {
827
801
  name: "react-router-route-entry",
@@ -1170,7 +1144,7 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
1170
1144
  let routes = createPrerenderRoutes(build.routes);
1171
1145
  let routesToPrerender;
1172
1146
  if (typeof reactRouterConfig.prerender === "boolean") {
1173
- invariant["default"](reactRouterConfig.prerender, "Expected prerender:true");
1147
+ invariant(reactRouterConfig.prerender, "Expected prerender:true");
1174
1148
  routesToPrerender = determineStaticPrerenderRoutes(routes, viteConfig, true);
1175
1149
  } else if (typeof reactRouterConfig.prerender === "function") {
1176
1150
  routesToPrerender = await reactRouterConfig.prerender({
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @react-router/dev v0.0.0-experimental-312bddb22
2
+ * @react-router/dev v0.0.0-experimental-7de693505
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @react-router/dev v0.0.0-experimental-312bddb22
2
+ * @react-router/dev v0.0.0-experimental-7de693505
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @react-router/dev v0.0.0-experimental-312bddb22
2
+ * @react-router/dev v0.0.0-experimental-7de693505
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @react-router/dev v0.0.0-experimental-312bddb22
2
+ * @react-router/dev v0.0.0-experimental-7de693505
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -0,0 +1,9 @@
1
+ import { ViteNodeServer } from "vite-node/server";
2
+ import { ViteNodeRunner } from "vite-node/client";
3
+ import type * as Vite from "vite";
4
+ export type Context = {
5
+ devServer: Vite.ViteDevServer;
6
+ server: ViteNodeServer;
7
+ runner: ViteNodeRunner;
8
+ };
9
+ export declare function createContext(viteConfig?: Vite.InlineConfig): Promise<Context>;
@@ -0,0 +1,57 @@
1
+ /**
2
+ * @react-router/dev v0.0.0-experimental-7de693505
3
+ *
4
+ * Copyright (c) Remix Software Inc.
5
+ *
6
+ * This source code is licensed under the MIT license found in the
7
+ * LICENSE.md file in the root directory of this source tree.
8
+ *
9
+ * @license MIT
10
+ */
11
+ 'use strict';
12
+
13
+ Object.defineProperty(exports, '__esModule', { value: true });
14
+
15
+ var server = require('vite-node/server');
16
+ var client = require('vite-node/client');
17
+ var sourceMap = require('vite-node/source-map');
18
+ var importViteEsmSync = require('./import-vite-esm-sync.js');
19
+
20
+ async function createContext(viteConfig = {}) {
21
+ await importViteEsmSync.preloadViteEsm();
22
+ const vite = importViteEsmSync.importViteEsmSync();
23
+ const devServer = await vite.createServer(vite.mergeConfig({
24
+ server: {
25
+ preTransformRequests: false,
26
+ hmr: false
27
+ },
28
+ optimizeDeps: {
29
+ noDiscovery: true
30
+ },
31
+ configFile: false,
32
+ envFile: false,
33
+ plugins: []
34
+ }, viteConfig));
35
+ await devServer.pluginContainer.buildStart({});
36
+ const server$1 = new server.ViteNodeServer(devServer);
37
+ sourceMap.installSourcemapsSupport({
38
+ getSourceMap: source => server$1.getSourceMap(source)
39
+ });
40
+ const runner = new client.ViteNodeRunner({
41
+ root: devServer.config.root,
42
+ base: devServer.config.base,
43
+ fetchModule(id) {
44
+ return server$1.fetchModule(id);
45
+ },
46
+ resolveId(id, importer) {
47
+ return server$1.resolveId(id, importer);
48
+ }
49
+ });
50
+ return {
51
+ devServer,
52
+ server: server$1,
53
+ runner
54
+ };
55
+ }
56
+
57
+ exports.createContext = createContext;
package/dist/vite/vmod.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @react-router/dev v0.0.0-experimental-312bddb22
2
+ * @react-router/dev v0.0.0-experimental-7de693505
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @react-router/dev v0.0.0-experimental-312bddb22
2
+ * @react-router/dev v0.0.0-experimental-7de693505
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
package/dist/vite.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @react-router/dev v0.0.0-experimental-312bddb22
2
+ * @react-router/dev v0.0.0-experimental-7de693505
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-router/dev",
3
- "version": "0.0.0-experimental-312bddb22",
3
+ "version": "0.0.0-experimental-7de693505",
4
4
  "description": "Dev tools and CLI for React Router",
5
5
  "homepage": "https://reactrouter.com",
6
6
  "bugs": {
@@ -12,6 +12,7 @@
12
12
  "directory": "packages/react-router-dev"
13
13
  },
14
14
  "license": "MIT",
15
+ "main": "./dist/typescript/plugin.ts",
15
16
  "exports": {
16
17
  "./routes": {
17
18
  "types": "./dist/routes.d.ts",
@@ -43,6 +44,7 @@
43
44
  "arg": "^5.0.1",
44
45
  "babel-dead-code-elimination": "^1.0.6",
45
46
  "chalk": "^4.1.2",
47
+ "chokidar": "^4.0.0",
46
48
  "dedent": "^1.5.3",
47
49
  "es-module-lexer": "^1.3.1",
48
50
  "exit-hook": "2.2.1",
@@ -50,15 +52,16 @@
50
52
  "gunzip-maybe": "^1.4.2",
51
53
  "jsesc": "3.0.2",
52
54
  "lodash": "^4.17.21",
55
+ "pathe": "^1.1.2",
53
56
  "picocolors": "^1.0.0",
54
57
  "picomatch": "^2.3.1",
55
58
  "prettier": "^2.7.1",
56
59
  "react-refresh": "^0.14.0",
57
60
  "semver": "^7.3.7",
58
61
  "set-cookie-parser": "^2.6.0",
59
- "vite-node": "^1.6.0",
60
62
  "valibot": "^0.41.0",
61
- "@react-router/node": "0.0.0-experimental-312bddb22"
63
+ "vite-node": "^1.6.0",
64
+ "@react-router/node": "0.0.0-experimental-7de693505"
62
65
  },
63
66
  "devDependencies": {
64
67
  "@types/babel__core": "^7.20.5",
@@ -84,15 +87,15 @@
84
87
  "tiny-invariant": "^1.2.0",
85
88
  "vite": "^5.1.0",
86
89
  "wrangler": "^3.28.2",
87
- "@react-router/serve": "0.0.0-experimental-312bddb22",
88
- "react-router": "^0.0.0-experimental-312bddb22"
90
+ "@react-router/serve": "0.0.0-experimental-7de693505",
91
+ "react-router": "^0.0.0-experimental-7de693505"
89
92
  },
90
93
  "peerDependencies": {
91
94
  "typescript": "^5.1.0",
92
95
  "vite": "^5.1.0",
93
96
  "wrangler": "^3.28.2",
94
- "@react-router/serve": "^0.0.0-experimental-312bddb22",
95
- "react-router": "^0.0.0-experimental-312bddb22"
97
+ "@react-router/serve": "^0.0.0-experimental-7de693505",
98
+ "react-router": "^0.0.0-experimental-7de693505"
96
99
  },
97
100
  "peerDependenciesMeta": {
98
101
  "@react-router/serve": {