@vercel/remix-builder 2.0.2 → 2.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/utils.js CHANGED
@@ -1,349 +1,333 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
24
11
  };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
27
19
  };
28
- var _a;
29
- Object.defineProperty(exports, "__esModule", { value: true });
30
- exports.isESM = exports.ensureResolvable = exports.resolveSemverMinMax = exports.addDependencies = exports.chdirAndReadConfig = exports.syncEnv = exports.getRegExpFromPath = exports.getPathFromRoute = exports.getRouteIterator = exports.isLayoutRoute = exports.calculateRouteConfigHash = exports.getResolvedRouteConfig = exports.findConfig = exports.findEntry = exports._require = void 0;
31
- const semver_1 = __importDefault(require("semver"));
32
- const child_process_1 = require("child_process");
33
- const fs_1 = require("fs");
34
- const path_1 = require("path");
35
- const path_to_regexp_1 = require("path-to-regexp");
36
- const build_utils_1 = require("@vercel/build-utils");
37
- const build_utils_2 = require("@vercel/build-utils");
38
- exports._require = eval('require');
39
- const SPLAT_PATH = '/:params*';
40
- const entryExts = ['.js', '.jsx', '.ts', '.tsx'];
41
- function findEntry(dir, basename) {
42
- for (const ext of entryExts) {
43
- const file = (0, path_1.resolve)(dir, basename + ext);
44
- if ((0, fs_1.existsSync)(file))
45
- return (0, path_1.relative)(dir, file);
46
- }
47
- return undefined;
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var utils_exports = {};
30
+ __export(utils_exports, {
31
+ _require: () => _require,
32
+ addDependencies: () => addDependencies,
33
+ calculateRouteConfigHash: () => calculateRouteConfigHash,
34
+ chdirAndReadConfig: () => chdirAndReadConfig,
35
+ ensureResolvable: () => ensureResolvable,
36
+ findConfig: () => findConfig,
37
+ findEntry: () => findEntry,
38
+ getPathFromRoute: () => getPathFromRoute,
39
+ getRegExpFromPath: () => getRegExpFromPath,
40
+ getResolvedRouteConfig: () => getResolvedRouteConfig,
41
+ getRouteIterator: () => getRouteIterator,
42
+ isESM: () => isESM,
43
+ isLayoutRoute: () => isLayoutRoute,
44
+ resolveSemverMinMax: () => resolveSemverMinMax,
45
+ syncEnv: () => syncEnv
46
+ });
47
+ module.exports = __toCommonJS(utils_exports);
48
+ var import_semver = __toESM(require("semver"));
49
+ var import_child_process = require("child_process");
50
+ var import_fs = require("fs");
51
+ var import_path = require("path");
52
+ var import_path_to_regexp = require("path-to-regexp");
53
+ var import_build_utils = require("@vercel/build-utils");
54
+ var import_build_utils2 = require("@vercel/build-utils");
55
+ const _require = eval("require");
56
+ const SPLAT_PATH = "/:params*";
57
+ const entryExts = [".js", ".jsx", ".ts", ".tsx"];
58
+ function findEntry(dir, basename2) {
59
+ for (const ext of entryExts) {
60
+ const file = (0, import_path.resolve)(dir, basename2 + ext);
61
+ if ((0, import_fs.existsSync)(file))
62
+ return (0, import_path.relative)(dir, file);
63
+ }
64
+ return void 0;
48
65
  }
49
- exports.findEntry = findEntry;
50
- const configExts = ['.js', '.cjs', '.mjs'];
51
- function findConfig(dir, basename) {
52
- for (const ext of configExts) {
53
- const name = basename + ext;
54
- const file = (0, path_1.join)(dir, name);
55
- if ((0, fs_1.existsSync)(file))
56
- return file;
57
- }
58
- return undefined;
66
+ const configExts = [".js", ".cjs", ".mjs"];
67
+ function findConfig(dir, basename2) {
68
+ for (const ext of configExts) {
69
+ const name = basename2 + ext;
70
+ const file = (0, import_path.join)(dir, name);
71
+ if ((0, import_fs.existsSync)(file))
72
+ return file;
73
+ }
74
+ return void 0;
59
75
  }
60
- exports.findConfig = findConfig;
61
76
  function isEdgeRuntime(runtime) {
62
- return runtime === 'edge' || runtime === 'experimental-edge';
77
+ return runtime === "edge" || runtime === "experimental-edge";
63
78
  }
64
79
  function getResolvedRouteConfig(route, routes, configs, isHydrogen2) {
65
- let runtime;
66
- let regions;
67
- let maxDuration;
68
- let memory;
69
- for (const currentRoute of getRouteIterator(route, routes)) {
70
- const staticConfig = configs.get(currentRoute);
71
- if (staticConfig) {
72
- if (typeof runtime === 'undefined' && staticConfig.runtime) {
73
- runtime = isEdgeRuntime(staticConfig.runtime) ? 'edge' : 'nodejs';
74
- }
75
- if (typeof regions === 'undefined') {
76
- regions = staticConfig.regions;
77
- }
78
- if (typeof maxDuration === 'undefined') {
79
- maxDuration = staticConfig.maxDuration;
80
- }
81
- if (typeof memory === 'undefined') {
82
- memory = staticConfig.memory;
83
- }
84
- }
85
- }
86
- if (Array.isArray(regions)) {
87
- regions = Array.from(new Set(regions)).sort();
88
- }
89
- if (isHydrogen2 || runtime === 'edge') {
90
- return { runtime: 'edge', regions };
91
- }
92
- if (regions && !Array.isArray(regions)) {
93
- throw new Error(`"regions" for route "${route.id}" must be an array of strings`);
80
+ let runtime;
81
+ let regions;
82
+ let maxDuration;
83
+ let memory;
84
+ for (const currentRoute of getRouteIterator(route, routes)) {
85
+ const staticConfig = configs.get(currentRoute);
86
+ if (staticConfig) {
87
+ if (typeof runtime === "undefined" && staticConfig.runtime) {
88
+ runtime = isEdgeRuntime(staticConfig.runtime) ? "edge" : "nodejs";
89
+ }
90
+ if (typeof regions === "undefined") {
91
+ regions = staticConfig.regions;
92
+ }
93
+ if (typeof maxDuration === "undefined") {
94
+ maxDuration = staticConfig.maxDuration;
95
+ }
96
+ if (typeof memory === "undefined") {
97
+ memory = staticConfig.memory;
98
+ }
94
99
  }
95
- return { runtime: 'nodejs', regions, maxDuration, memory };
100
+ }
101
+ if (Array.isArray(regions)) {
102
+ regions = Array.from(new Set(regions)).sort();
103
+ }
104
+ if (isHydrogen2 || runtime === "edge") {
105
+ return { runtime: "edge", regions };
106
+ }
107
+ if (regions && !Array.isArray(regions)) {
108
+ throw new Error(
109
+ `"regions" for route "${route.id}" must be an array of strings`
110
+ );
111
+ }
112
+ return { runtime: "nodejs", regions, maxDuration, memory };
96
113
  }
97
- exports.getResolvedRouteConfig = getResolvedRouteConfig;
98
114
  function calculateRouteConfigHash(config) {
99
- const str = JSON.stringify(config);
100
- return Buffer.from(str).toString('base64url');
115
+ const str = JSON.stringify(config);
116
+ return Buffer.from(str).toString("base64url");
101
117
  }
102
- exports.calculateRouteConfigHash = calculateRouteConfigHash;
103
118
  function isLayoutRoute(routeId, routes) {
104
- return routes.some(r => r.parentId === routeId);
119
+ return routes.some((r) => r.parentId === routeId);
105
120
  }
106
- exports.isLayoutRoute = isLayoutRoute;
107
121
  function* getRouteIterator(route, routes) {
108
- let currentRoute = route;
109
- do {
110
- yield currentRoute;
111
- if (currentRoute.parentId) {
112
- currentRoute = routes[currentRoute.parentId];
113
- }
114
- else {
115
- break;
116
- }
117
- } while (currentRoute);
122
+ let currentRoute = route;
123
+ do {
124
+ yield currentRoute;
125
+ if (currentRoute.parentId) {
126
+ currentRoute = routes[currentRoute.parentId];
127
+ } else {
128
+ break;
129
+ }
130
+ } while (currentRoute);
118
131
  }
119
- exports.getRouteIterator = getRouteIterator;
120
132
  function getPathFromRoute(route, routes) {
121
- if (route.id === 'root' ||
122
- (route.parentId === 'root' && !route.path && route.index)) {
123
- return { path: 'index', rePath: '/index' };
124
- }
125
- const pathParts = [];
126
- const rePathParts = [];
127
- for (const currentRoute of getRouteIterator(route, routes)) {
128
- if (!currentRoute.path)
129
- continue;
130
- const currentRouteParts = currentRoute.path.split('/').reverse();
131
- for (const part of currentRouteParts) {
132
- if (part.endsWith('?')) {
133
- if (part.startsWith(':')) {
134
- // Optional path parameter
135
- pathParts.push(`(${part.substring(0, part.length - 1)})`);
136
- rePathParts.push(part);
137
- }
138
- else {
139
- // Optional static segment
140
- const p = `(${part.substring(0, part.length - 1)})`;
141
- pathParts.push(p);
142
- rePathParts.push(`${p}?`);
143
- }
144
- }
145
- else {
146
- pathParts.push(part);
147
- rePathParts.push(part);
148
- }
133
+ if (route.id === "root" || route.parentId === "root" && !route.path && route.index) {
134
+ return { path: "index", rePath: "/index" };
135
+ }
136
+ const pathParts = [];
137
+ const rePathParts = [];
138
+ for (const currentRoute of getRouteIterator(route, routes)) {
139
+ if (!currentRoute.path)
140
+ continue;
141
+ const currentRouteParts = currentRoute.path.split("/").reverse();
142
+ for (const part of currentRouteParts) {
143
+ if (part.endsWith("?")) {
144
+ if (part.startsWith(":")) {
145
+ pathParts.push(`(${part.substring(0, part.length - 1)})`);
146
+ rePathParts.push(part);
147
+ } else {
148
+ const p = `(${part.substring(0, part.length - 1)})`;
149
+ pathParts.push(p);
150
+ rePathParts.push(`${p}?`);
149
151
  }
152
+ } else {
153
+ pathParts.push(part);
154
+ rePathParts.push(part);
155
+ }
150
156
  }
151
- const path = pathParts.reverse().join('/');
152
- // Replace "/*" at the end to handle "splat routes"
153
- let rePath = rePathParts.reverse().join('/');
154
- rePath =
155
- rePath === '*' ? SPLAT_PATH : `/${rePath.replace(/\/\*$/, SPLAT_PATH)}`;
156
- return { path, rePath };
157
+ }
158
+ const path = pathParts.reverse().join("/");
159
+ let rePath = rePathParts.reverse().join("/");
160
+ rePath = rePath === "*" ? SPLAT_PATH : `/${rePath.replace(/\/\*$/, SPLAT_PATH)}`;
161
+ return { path, rePath };
157
162
  }
158
- exports.getPathFromRoute = getPathFromRoute;
159
163
  function getRegExpFromPath(rePath) {
160
- const keys = [];
161
- const re = (0, path_to_regexp_1.pathToRegexp)(rePath, keys);
162
- return keys.length > 0 ? re : false;
164
+ const keys = [];
165
+ const re = (0, import_path_to_regexp.pathToRegexp)(rePath, keys);
166
+ return keys.length > 0 ? re : false;
163
167
  }
164
- exports.getRegExpFromPath = getRegExpFromPath;
165
- /**
166
- * Updates the `dest` process.env object to match the `source` one.
167
- * A function is returned to restore the the `dest` env back to how
168
- * it was originally.
169
- */
170
168
  function syncEnv(source, dest) {
171
- const originalDest = { ...dest };
172
- Object.assign(dest, source);
173
- for (const key of Object.keys(dest)) {
174
- if (!(key in source)) {
175
- delete dest[key];
176
- }
169
+ const originalDest = { ...dest };
170
+ Object.assign(dest, source);
171
+ for (const key of Object.keys(dest)) {
172
+ if (!(key in source)) {
173
+ delete dest[key];
177
174
  }
178
- return () => syncEnv(originalDest, dest);
175
+ }
176
+ return () => syncEnv(originalDest, dest);
179
177
  }
180
- exports.syncEnv = syncEnv;
181
178
  async function chdirAndReadConfig(remixRunDevPath, dir, packageJsonPath) {
182
- const { readConfig } = await (_a = (0, path_1.join)(remixRunDevPath, 'dist/config.js'), Promise.resolve().then(() => __importStar(require(_a))));
183
- const originalCwd = process.cwd();
184
- // As of Remix v1.14.0, reading the config may trigger adding
185
- // "isbot" as a dependency, and `npm`/`pnpm`/`yarn` may be invoked.
186
- // We want to prevent that behavior, so trick `readConfig()`
187
- // into thinking that "isbot" is already installed.
188
- let modifiedPackageJson = false;
189
- const pkgRaw = await fs_1.promises.readFile(packageJsonPath, 'utf8');
190
- const pkg = JSON.parse(pkgRaw);
191
- if (!pkg.dependencies?.['isbot']) {
192
- pkg.dependencies.isbot = 'latest';
193
- await fs_1.promises.writeFile(packageJsonPath, JSON.stringify(pkg));
194
- modifiedPackageJson = true;
195
- }
196
- // Suppress any warnings emitted from `readConfig()` to avoid
197
- // printing them > 1 time. They will already be printed during
198
- // `remix build` when invoking the Build Command.
199
- const warn = console.warn;
200
- console.warn = build_utils_1.debug;
201
- let remixConfig;
202
- try {
203
- process.chdir(dir);
204
- remixConfig = await readConfig(dir);
205
- }
206
- finally {
207
- console.warn = warn;
208
- process.chdir(originalCwd);
209
- if (modifiedPackageJson) {
210
- await fs_1.promises.writeFile(packageJsonPath, pkgRaw);
211
- }
179
+ const { readConfig } = await import((0, import_path.join)(remixRunDevPath, "dist/config.js"));
180
+ const originalCwd = process.cwd();
181
+ let modifiedPackageJson = false;
182
+ const pkgRaw = await import_fs.promises.readFile(packageJsonPath, "utf8");
183
+ const pkg = JSON.parse(pkgRaw);
184
+ if (!pkg.dependencies?.["isbot"]) {
185
+ pkg.dependencies.isbot = "latest";
186
+ await import_fs.promises.writeFile(packageJsonPath, JSON.stringify(pkg));
187
+ modifiedPackageJson = true;
188
+ }
189
+ const warn = console.warn;
190
+ console.warn = import_build_utils.debug;
191
+ let remixConfig;
192
+ try {
193
+ process.chdir(dir);
194
+ remixConfig = await readConfig(dir);
195
+ } finally {
196
+ console.warn = warn;
197
+ process.chdir(originalCwd);
198
+ if (modifiedPackageJson) {
199
+ await import_fs.promises.writeFile(packageJsonPath, pkgRaw);
212
200
  }
213
- return remixConfig;
201
+ }
202
+ return remixConfig;
214
203
  }
215
- exports.chdirAndReadConfig = chdirAndReadConfig;
216
- /**
217
- * Runs `npm i ${name}` / `pnpm i ${name}` / `yarn add ${name}`.
218
- */
219
204
  function addDependencies(cliType, names, opts = {}) {
220
- (0, build_utils_1.debug)('Installing additional dependencies:');
221
- for (const name of names) {
222
- (0, build_utils_1.debug)(` - ${name}`);
205
+ (0, import_build_utils.debug)("Installing additional dependencies:");
206
+ for (const name of names) {
207
+ (0, import_build_utils.debug)(` - ${name}`);
208
+ }
209
+ const args = [];
210
+ if (cliType === "npm" || cliType === "pnpm") {
211
+ args.push("install");
212
+ if (opts.saveDev) {
213
+ args.push("--save-dev");
223
214
  }
224
- const args = [];
225
- if (cliType === 'npm' || cliType === 'pnpm') {
226
- args.push('install');
227
- if (opts.saveDev) {
228
- args.push('--save-dev');
229
- }
215
+ } else {
216
+ args.push("add");
217
+ if (opts.saveDev) {
218
+ args.push("--dev");
230
219
  }
231
- else {
232
- // 'yarn'
233
- args.push('add');
234
- if (opts.saveDev) {
235
- args.push('--dev');
236
- }
237
- const yarnVersion = (0, child_process_1.execSync)('yarn -v', { encoding: 'utf8' }).trim();
238
- const isYarnV1 = semver_1.default.satisfies(yarnVersion, '1');
239
- if (isYarnV1) {
240
- // Ignoring workspace check is only needed on Yarn v1
241
- args.push('--ignore-workspace-root-check');
242
- }
220
+ const yarnVersion = (0, import_child_process.execSync)("yarn -v", { encoding: "utf8" }).trim();
221
+ const isYarnV1 = import_semver.default.satisfies(yarnVersion, "1");
222
+ if (isYarnV1) {
223
+ args.push("--ignore-workspace-root-check");
243
224
  }
244
- // Don't fail if pnpm is being run at the workspace root
245
- if (cliType === 'pnpm' && opts.cwd) {
246
- if ((0, fs_1.existsSync)((0, path_1.join)(opts.cwd, 'pnpm-workspace.yaml'))) {
247
- args.push('--workspace-root');
248
- }
225
+ }
226
+ if (cliType === "pnpm" && opts.cwd) {
227
+ if ((0, import_fs.existsSync)((0, import_path.join)(opts.cwd, "pnpm-workspace.yaml"))) {
228
+ args.push("--workspace-root");
249
229
  }
250
- return (0, build_utils_1.spawnAsync)(cliType, args.concat(names), opts);
230
+ }
231
+ return (0, import_build_utils.spawnAsync)(cliType, args.concat(names), opts);
251
232
  }
252
- exports.addDependencies = addDependencies;
253
233
  function resolveSemverMinMax(min, max, version) {
254
- const floored = semver_1.default.intersects(version, `>= ${min}`) ? version : min;
255
- return semver_1.default.intersects(floored, `<= ${max}`) ? floored : max;
234
+ const floored = import_semver.default.intersects(version, `>= ${min}`) ? version : min;
235
+ return import_semver.default.intersects(floored, `<= ${max}`) ? floored : max;
256
236
  }
257
- exports.resolveSemverMinMax = resolveSemverMinMax;
258
237
  async function ensureResolvable(start, base, pkgName) {
259
- try {
260
- const resolvedPkgPath = exports._require.resolve(`${pkgName}/package.json`, {
261
- paths: [start],
262
- });
263
- const resolvedPath = (0, path_1.dirname)(resolvedPkgPath);
264
- if (!(0, path_1.relative)(base, resolvedPath).startsWith(`..${path_1.sep}`)) {
265
- // Resolved path is within the root of the project, so all good
266
- (0, build_utils_1.debug)(`"${pkgName}" resolved to '${resolvedPath}'`);
267
- return resolvedPath;
268
- }
238
+ try {
239
+ const resolvedPkgPath = _require.resolve(`${pkgName}/package.json`, {
240
+ paths: [start]
241
+ });
242
+ const resolvedPath = (0, import_path.dirname)(resolvedPkgPath);
243
+ if (!(0, import_path.relative)(base, resolvedPath).startsWith(`..${import_path.sep}`)) {
244
+ (0, import_build_utils.debug)(`"${pkgName}" resolved to '${resolvedPath}'`);
245
+ return resolvedPath;
269
246
  }
270
- catch (err) {
271
- if (err.code !== 'MODULE_NOT_FOUND') {
272
- throw err;
273
- }
247
+ } catch (err) {
248
+ if (err.code !== "MODULE_NOT_FOUND") {
249
+ throw err;
274
250
  }
275
- // If we got to here then `pkgName` was not resolvable up to the root
276
- // of the project. Try a couple symlink tricks, otherwise we'll bail.
277
- // Attempt to find the package in `node_modules/.pnpm` (pnpm)
278
- const pnpmDir = await (0, build_utils_2.walkParentDirs)({
279
- base,
280
- start,
281
- filename: 'node_modules/.pnpm',
282
- });
283
- if (pnpmDir) {
284
- const prefix = `${pkgName.replace('/', '+')}@`;
285
- const packages = await fs_1.promises.readdir(pnpmDir);
286
- const match = packages.find(p => p.startsWith(prefix));
287
- if (match) {
288
- const pkgDir = (0, path_1.join)(pnpmDir, match, 'node_modules', pkgName);
289
- await ensureSymlink(pkgDir, (0, path_1.join)(start, 'node_modules'), pkgName);
290
- return pkgDir;
291
- }
251
+ }
252
+ const pnpmDir = await (0, import_build_utils2.walkParentDirs)({
253
+ base,
254
+ start,
255
+ filename: "node_modules/.pnpm"
256
+ });
257
+ if (pnpmDir) {
258
+ const prefix = `${pkgName.replace("/", "+")}@`;
259
+ const packages = await import_fs.promises.readdir(pnpmDir);
260
+ const match = packages.find((p) => p.startsWith(prefix));
261
+ if (match) {
262
+ const pkgDir = (0, import_path.join)(pnpmDir, match, "node_modules", pkgName);
263
+ await ensureSymlink(pkgDir, (0, import_path.join)(start, "node_modules"), pkgName);
264
+ return pkgDir;
292
265
  }
293
- // Attempt to find the package in `node_modules/.store` (npm 9+ linked mode)
294
- const npmDir = await (0, build_utils_2.walkParentDirs)({
295
- base,
296
- start,
297
- filename: 'node_modules/.store',
298
- });
299
- if (npmDir) {
300
- const prefix = `${(0, path_1.basename)(pkgName)}@`;
301
- const prefixDir = (0, path_1.join)(npmDir, (0, path_1.dirname)(pkgName));
302
- const packages = await fs_1.promises.readdir(prefixDir);
303
- const match = packages.find(p => p.startsWith(prefix));
304
- if (match) {
305
- const pkgDir = (0, path_1.join)(prefixDir, match, 'node_modules', pkgName);
306
- await ensureSymlink(pkgDir, (0, path_1.join)(start, 'node_modules'), pkgName);
307
- return pkgDir;
308
- }
266
+ }
267
+ const npmDir = await (0, import_build_utils2.walkParentDirs)({
268
+ base,
269
+ start,
270
+ filename: "node_modules/.store"
271
+ });
272
+ if (npmDir) {
273
+ const prefix = `${(0, import_path.basename)(pkgName)}@`;
274
+ const prefixDir = (0, import_path.join)(npmDir, (0, import_path.dirname)(pkgName));
275
+ const packages = await import_fs.promises.readdir(prefixDir);
276
+ const match = packages.find((p) => p.startsWith(prefix));
277
+ if (match) {
278
+ const pkgDir = (0, import_path.join)(prefixDir, match, "node_modules", pkgName);
279
+ await ensureSymlink(pkgDir, (0, import_path.join)(start, "node_modules"), pkgName);
280
+ return pkgDir;
309
281
  }
310
- throw new Error(`Failed to resolve "${pkgName}". To fix this error, add "${pkgName}" to "dependencies" in your \`package.json\` file.`);
282
+ }
283
+ throw new Error(
284
+ `Failed to resolve "${pkgName}". To fix this error, add "${pkgName}" to "dependencies" in your \`package.json\` file.`
285
+ );
311
286
  }
312
- exports.ensureResolvable = ensureResolvable;
313
287
  async function ensureSymlink(target, nodeModulesDir, pkgName) {
314
- const symlinkPath = (0, path_1.join)(nodeModulesDir, pkgName);
315
- const symlinkDir = (0, path_1.dirname)(symlinkPath);
316
- const relativeTarget = (0, path_1.relative)(symlinkDir, target);
317
- try {
318
- const existingTarget = await fs_1.promises.readlink(symlinkPath);
319
- if (existingTarget === relativeTarget) {
320
- // Symlink is already the expected value, so do nothing
321
- return;
322
- }
323
- else {
324
- // If a symlink already exists then delete it if the target doesn't match
325
- await fs_1.promises.unlink(symlinkPath);
326
- }
288
+ const symlinkPath = (0, import_path.join)(nodeModulesDir, pkgName);
289
+ const symlinkDir = (0, import_path.dirname)(symlinkPath);
290
+ const relativeTarget = (0, import_path.relative)(symlinkDir, target);
291
+ try {
292
+ const existingTarget = await import_fs.promises.readlink(symlinkPath);
293
+ if (existingTarget === relativeTarget) {
294
+ return;
295
+ } else {
296
+ await import_fs.promises.unlink(symlinkPath);
327
297
  }
328
- catch (err) {
329
- // Ignore when path does not exist or is not a symlink
330
- if (err.code !== 'ENOENT' && err.code !== 'EINVAL') {
331
- throw err;
332
- }
298
+ } catch (err) {
299
+ if (err.code !== "ENOENT" && err.code !== "EINVAL") {
300
+ throw err;
333
301
  }
334
- await fs_1.promises.symlink(relativeTarget, symlinkPath);
335
- (0, build_utils_1.debug)(`Created symlink for "${pkgName}"`);
302
+ }
303
+ await import_fs.promises.symlink(relativeTarget, symlinkPath);
304
+ (0, import_build_utils.debug)(`Created symlink for "${pkgName}"`);
336
305
  }
337
306
  function isESM(path) {
338
- // Figure out if the `remix.config` file is using ESM syntax
339
- let isESM = false;
340
- try {
341
- (0, exports._require)(path);
342
- }
343
- catch (err) {
344
- isESM = err.code === 'ERR_REQUIRE_ESM';
345
- }
346
- return isESM;
307
+ let isESM2 = false;
308
+ try {
309
+ _require(path);
310
+ } catch (err) {
311
+ isESM2 = err.code === "ERR_REQUIRE_ESM";
312
+ }
313
+ return isESM2;
347
314
  }
348
- exports.isESM = isESM;
349
- //# sourceMappingURL=utils.js.map
315
+ // Annotate the CommonJS export names for ESM import in node:
316
+ 0 && (module.exports = {
317
+ _require,
318
+ addDependencies,
319
+ calculateRouteConfigHash,
320
+ chdirAndReadConfig,
321
+ ensureResolvable,
322
+ findConfig,
323
+ findEntry,
324
+ getPathFromRoute,
325
+ getRegExpFromPath,
326
+ getResolvedRouteConfig,
327
+ getRouteIterator,
328
+ isESM,
329
+ isLayoutRoute,
330
+ resolveSemverMinMax,
331
+ syncEnv
332
+ });
333
+ //# sourceMappingURL=utils.js.map