Lines 1-64javascript
4// src/cli/commands/migrate/router.ts
5import { execFileSync } from "child_process";
6import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "fs";
HighChild Process
Package source references child process execution.
dist/router-TLEAOFID.jsView on unpkg · L4 7import { createServer } from "net";
8import { dirname, resolve } from "path";
10// src/cli/commands/migrate/router-codemod.ts
11import { readdirSync, statSync } from "fs";
12import { extname, join, relative, sep } from "path";
13var ROUTE_EXTENSIONS = /* @__PURE__ */ new Set([".ts", ".tsx", ".js", ".jsx"]);
14var TEST_OR_SPEC_RE = /\.(test|spec)\.[jt]sx?$/;
15var RouterMigrationCollisionError = class extends Error {
16 name = "RouterMigrationCollisionError";
19 constructor(from, to) {
21 `Router migration collision: ${from} would rename to ${to}, but that file already exists (case-insensitive match). Resolve manually.`
27function computeDepthDelta(from, to, routesDir) {
28 const depthOf = (p) => {
29 const rel = relative(routesDir, p).replace(/\\/g, "/");
30 return rel.split("/").length - 1;
32 return depthOf(to) - depthOf(from);
34function rewriteRelativeImports(source, delta) {
35 if (delta <= 0) return source;
36 const prefix = "../".repeat(delta);
37 const transformSpecifier = (specifier) => {
38 if (specifier.startsWith("./")) return `${prefix}${specifier.slice(2)}`;
39 return `${prefix}${specifier}`;
41 const fromRe = /\bfrom\s+(['"])(\.{1,2}\/[^'"]+)\1/g;
42 const dynRe = /\bimport\s*\(\s*(['"])(\.{1,2}\/[^'"]+)\1\s*\)/g;
43 const sideRe = /\bimport\s+(['"])(\.{1,2}\/[^'"]+)\1/g;
44 const fromSub = (_m, q, spec) => `from ${q}${transformSpecifier(spec)}${q}`;
45 const dynSub = (_m, q, spec) => `import(${q}${transformSpecifier(spec)}${q})`;
46 const sideSub = (_m, q, spec) => `import ${q}${transformSpecifier(spec)}${q}`;
MediumDynamic Require
Package source references dynamic require/import behavior.
dist/router-TLEAOFID.jsView on unpkg · L44 47 return source.replace(fromRe, fromSub).replace(dynRe, dynSub).replace(sideRe, sideSub);
49function isTestOrSpecFile(filePath) {
50 return TEST_OR_SPEC_RE.test(filePath);
52function hasDotOutsideBrackets(segment) {
54 for (const ch of segment) {
55 if (ch === "[") depth++;
56 else if (ch === "]") depth--;
57 else if (ch === "." && depth === 0) return true;
61function splitDottedSegmentOutsideBrackets(segment) {