Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 38 additions & 2 deletions integration/cli-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ const helpText = dedent`
--json Print the routes as JSON
\`reveal\` Options:
--config, -c Use specified Vite config file (string)
--no-typescript Generate plain JavaScript files
--no-typescript Generate plain JavaScript files (deprecated; will be removed in v9)
\`typegen\` Options:
--watch Automatically regenerate types whenever route config (\`routes.ts\`) or route modules change

Expand Down Expand Up @@ -461,10 +461,46 @@ test.describe("cli", () => {
expect(existsSync(entryServerFile)).toBeFalsy();
expect(existsSync(entryClientFile)).toBeFalsy();

run(["reveal", "--no-typescript"], { cwd });
let { stderr, status } = run(["reveal", "--no-typescript"], {
cwd,
env: {
...process.env,
FORCE_COLOR: undefined,
NO_COLOR: "1",
},
});

expect(existsSync(entryServerFile)).toBeTruthy();
expect(existsSync(entryClientFile)).toBeTruthy();
expect(readFileSync(entryServerFile, "utf-8")).toContain(
"renderToPipeableStream",
);
expect(readFileSync(entryServerFile, "utf-8")).not.toContain(
"import type",
);
expect(stderr.toString().trim()).toBe(
"The --no-typescript flag is deprecated and will be removed in React Router v9.",
);
expect(status).toBe(0);
expect(build({ cwd }).status).toBe(0);
});

test("generates a web JavaScript server entry for non-Node projects", async () => {
const cwd = await createProject();
let packageJsonPath = path.join(cwd, "package.json");
let pkg = JSON.parse(readFileSync(packageJsonPath, "utf-8"));
delete pkg.dependencies["@react-router/express"];
delete pkg.dependencies["@react-router/node"];
delete pkg.dependencies["@react-router/serve"];
writeFileSync(packageJsonPath, JSON.stringify(pkg, null, 2));

let entryServerFile = path.join(cwd, "app", "entry.server.jsx");

run(["reveal", "entry.server", "--no-typescript"], { cwd });

expect(readFileSync(entryServerFile, "utf-8")).toContain(
"renderToReadableStream",
);
});
});

Expand Down
15 changes: 3 additions & 12 deletions packages/create-react-router/copy-template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,7 @@ function isLocalFilePath(input: string): boolean {
path.isAbsolute(input) ? input : path.resolve(process.cwd(), input),
)
);
} catch (
// eslint-disable-next-line @typescript-eslint/no-unused-vars
e
) {
} catch {
return false;
}
}
Expand Down Expand Up @@ -331,10 +328,7 @@ async function downloadAndExtractTarball(
},
}),
);
} catch (
// eslint-disable-next-line @typescript-eslint/no-unused-vars
e
) {
} catch {
throw new CopyTemplateError(
"There was a problem extracting the file from the provided template." +
` Template URL: \`${tarballUrl}\`` +
Expand Down Expand Up @@ -401,10 +395,7 @@ function isValidGithubRepoUrl(
? pathSegments[2] === "tree" && pathSegments.length >= 4
: true)
);
} catch (
// eslint-disable-next-line @typescript-eslint/no-unused-vars
e
) {
} catch {
return false;
}
}
Expand Down
5 changes: 1 addition & 4 deletions packages/create-react-router/prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,7 @@ export async function prompt<
answer = await prompts[type](Object.assign({ stdin, stdout }, question));
answers[name] = answer as any;
quit = await onSubmit(question, answer, answers);
} catch (
// eslint-disable-next-line @typescript-eslint/no-unused-vars
e
) {
} catch {
quit = !(await onCancel(question, answers));
}
if (quit) {
Expand Down
5 changes: 1 addition & 4 deletions packages/create-react-router/prompts-prompt-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,7 @@ export class Prompt extends EventEmitter {
if (a === false) {
try {
this._(str, key);
} catch (
// eslint-disable-next-line @typescript-eslint/no-unused-vars
e
) {}
} catch {}
// @ts-expect-error
} else if (typeof this[a] === "function") {
// @ts-expect-error
Expand Down
5 changes: 1 addition & 4 deletions packages/create-react-router/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,7 @@ export function isUrl(value: string | URL) {
try {
new URL(value);
return true;
} catch (
// eslint-disable-next-line @typescript-eslint/no-unused-vars
e
) {
} catch {
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Generate JavaScript entry files at package build time so `react-router reveal --no-typescript` does not require Prettier at runtime

- Deprecate the `--no-typescript` flag ahead of its removal in React Router v9
21 changes: 6 additions & 15 deletions packages/react-router-dev/cli/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import type { ViteBuildOptions } from "../vite/build";
import { hasNodeDependency, loadConfig } from "../config/config";
import { formatRoutes } from "../config/format";
import type { RoutesFormat } from "../config/format";
import { transpile as convertFileToJS } from "./useJavascript";
import * as profiler from "../vite/profiler";
import * as Typegen from "../typegen";
import { preloadVite, getVite } from "../vite/vite";
Expand Down Expand Up @@ -177,18 +176,20 @@ export async function generateEntry(
await copyFile(defaultEntry, outputFile);
} else {
let pkgJson = await readPackageJSON(rootDirectory);
let useTypeScript = flags.typescript ?? true;
let outputExtension = useTypeScript ? "tsx" : "jsx";

let defaultEntryClient = path.resolve(
defaultsDirectory,
"entry.client.tsx",
`entry.client.${outputExtension}`,
);

let defaultEntryServer = path.resolve(
defaultsDirectory,
hasNodeDependency(pkgJson.dependencies) &&
!configResult.value.future.unstable_enableNodeReadableStream
? `entry.server.node.tsx`
: `entry.server.web.tsx`,
? `entry.server.node.${outputExtension}`
: `entry.server.web.${outputExtension}`,
);

let isServerEntry = entry === "entry.server";
Expand All @@ -201,20 +202,10 @@ export async function generateEntry(
defaultEntryClient,
);

let useTypeScript = flags.typescript ?? true;
let outputExtension = useTypeScript ? "tsx" : "jsx";
let outputEntry = `${entry}.${outputExtension}`;
outputFile = path.resolve(appDirectory, outputEntry);

if (!useTypeScript) {
let javascript = await convertFileToJS(contents, {
cwd: rootDirectory,
filename: isServerEntry ? defaultEntryServer : defaultEntryClient,
});
await writeFile(outputFile, javascript, "utf-8");
} else {
await writeFile(outputFile, contents, "utf-8");
}
await writeFile(outputFile, contents, "utf-8");
}

console.log(
Expand Down
7 changes: 6 additions & 1 deletion packages/react-router-dev/cli/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ ${colors.blueBright("react-router")}
--json Print the routes as JSON
\`reveal\` Options:
--config, -c Use specified Vite config file (string)
--no-typescript Generate plain JavaScript files
--no-typescript Generate plain JavaScript files (deprecated; will be removed in v9)
\`typegen\` Options:
--watch Automatically regenerate types whenever route config (\`routes.ts\`) or route modules change

Expand Down Expand Up @@ -198,6 +198,11 @@ export async function run(

flags.interactive = flags.interactive ?? isMain;
if (values["no-typescript"]) {
console.warn(
colors.yellow(
"The --no-typescript flag is deprecated and will be removed in React Router v9.",
),
);
flags.typescript = false;
}

Expand Down
6 changes: 3 additions & 3 deletions packages/react-router-dev/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,6 @@
"@babel/core": "^7.29.7",
"@babel/generator": "^7.29.7",
"@babel/parser": "^7.29.7",
"@babel/plugin-syntax-jsx": "^7.29.7",
"@babel/preset-typescript": "^7.29.7",
"@babel/traverse": "^7.29.7",
"@babel/types": "^7.29.7",
"@react-router/node": "workspace:*",
Expand All @@ -110,14 +108,15 @@
"pathe": "^2.0.3",
"picocolors": "^1.1.1",
"pkg-types": "^2.3.1",
"prettier": "^3.8.3",
"react-refresh": "^0.18.0",
"semver": "^7.8.1",
"tinyglobby": "^0.2.16",
"valibot": "^1.4.1"
},
"devDependencies": {
"@react-router/serve": "workspace:*",
"@babel/plugin-syntax-jsx": "^7.29.7",
"@babel/preset-typescript": "^7.29.7",
"@types/babel__core": "^7.20.5",
"@types/babel__generator": "^7.27.0",
"@types/babel__traverse": "^7.28.0",
Expand All @@ -132,6 +131,7 @@
"esbuild-register": "^3.6.0",
"execa": "9.6.1",
"fast-glob": "3.3.3",
"prettier": "^3.8.3",
"react-router": "workspace:^",
"tsdown": "catalog:",
"typescript": "catalog:",
Expand Down
11 changes: 11 additions & 0 deletions packages/react-router-dev/tsdown.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { defineConfig } from "tsdown";

// @ts-ignore - out of scope
import { createBanner } from "../../build.utils.ts";
import { transpile as convertFileToJS } from "./cli/useJavascript.ts";

import pkg from "./package.json" with { type: "json" };

Expand Down Expand Up @@ -34,6 +35,16 @@ async function copyBuildAssets() {
`config/defaults/${file}`,
`dist/config/defaults/${file}`,
);
if (file.endsWith(".tsx")) {
let inputFile = `config/defaults/${file}`;
let tsx = await fsp.readFile(inputFile, "utf-8");
let jsx = await convertFileToJS(tsx, { filename: inputFile });
await fsp.writeFile(
`dist/config/defaults/${file.replace(/\.tsx$/, ".jsx")}`,
jsx,
"utf-8",
);
}
}

await fsp.mkdir("dist/config/default-rsc-entries", {
Expand Down
5 changes: 1 addition & 4 deletions packages/react-router-dev/vite/has-dependency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ export function hasDependency({
}) {
try {
return Boolean(nodeRequire.resolve(name, { paths: [rootDirectory] }));
} catch (
// eslint-disable-next-line @typescript-eslint/no-unused-vars
e
) {
} catch {
return false;
}
}
5 changes: 1 addition & 4 deletions packages/react-router-node/stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,10 +272,7 @@ class StreamPump {
if (available <= 0) {
this.pause();
}
} catch (
// eslint-disable-next-line @typescript-eslint/no-unused-vars
e
) {
} catch {
this.controller.error(
new Error(
"Could not create Buffer, chunk must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object",
Expand Down
10 changes: 2 additions & 8 deletions packages/react-router/__tests__/dom/nav-link-active-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1084,19 +1084,13 @@ function createDeferred() {
res(val);
try {
await promise;
} catch (
// eslint-disable-next-line @typescript-eslint/no-unused-vars
e
) {}
} catch {}
};
reject = async (error?: Error) => {
rej(error);
try {
await promise;
} catch (
// eslint-disable-next-line @typescript-eslint/no-unused-vars
e
) {}
} catch {}
};
});
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,10 +381,7 @@ export function setup({
await internalHelpers.dfd.resolve(redirectResponse);
}
await tick();
} catch (
// eslint-disable-next-line @typescript-eslint/no-unused-vars
e
) {}
} catch {}
return helpers;
}

Expand All @@ -404,10 +401,7 @@ export function setup({
async reject(value) {
try {
await internalHelpers.dfd.reject(value);
} catch (
// eslint-disable-next-line @typescript-eslint/no-unused-vars
e
) {}
} catch {}
},
async redirect(href, status = 301, headers = {}, shims = []) {
return _redirect(true, href, status, headers, shims);
Expand Down
10 changes: 2 additions & 8 deletions packages/react-router/__tests__/router/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,13 @@ export function createDeferred<T = unknown>() {
res(val);
try {
await promise;
} catch (
// eslint-disable-next-line @typescript-eslint/no-unused-vars
e
) {}
} catch {}
};
reject = async (error?: Error) => {
rej(error);
try {
await promise;
} catch (
// eslint-disable-next-line @typescript-eslint/no-unused-vars
e
) {}
} catch {}
};
});
return {
Expand Down
5 changes: 1 addition & 4 deletions packages/react-router/lib/dom/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,7 @@ function isFormDataSubmitterSupported() {
0,
);
_formDataSupportsSubmitter = false;
} catch (
// eslint-disable-next-line @typescript-eslint/no-unused-vars
e
) {
} catch {
_formDataSupportsSubmitter = true;
}
}
Expand Down
Loading
Loading