Skip to content

Commit

Permalink
Merge branch 'fix-jscodeshift-tests' of github.com:jenseng/remix into…
Browse files Browse the repository at this point in the history
… jenseng-fix-jscodeshift-tests
  • Loading branch information
chaance committed Oct 28, 2022
2 parents e44bfbf + a2c0583 commit 438a98e
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const TEMP_DIR = join(
`remix-tests-${Math.random().toString(32).slice(2)}`
);

jest.setTimeout(30_000);
beforeEach(() => {
output = "";
console.log = mockLog;
Expand Down
1 change: 1 addition & 0 deletions packages/remix-dev/__tests__/replace-remix-imports-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const TEMP_DIR = path.join(
`remix-tests-${Math.random().toString(32).slice(2)}`
);

jest.setTimeout(30_000);
beforeEach(async () => {
output = "";
console.log = mockLog;
Expand Down
8 changes: 5 additions & 3 deletions packages/remix-dev/cli.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { cli } from "./index";
import { cli, CliError } from "./index";

cli.run().then(
() => {
process.exit(0);
},
(error: Error) => {
console.error(error);
(error: unknown) => {
// for expected errors we only show the message (if any), no stack trace
if (error instanceof CliError) error = error.message;
if (error) console.error(error);
process.exit(1);
}
);
2 changes: 2 additions & 0 deletions packages/remix-dev/cli/error.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/** An expected error, for aborting the CLI */
export class CliError extends Error {}
2 changes: 1 addition & 1 deletion packages/remix-dev/cli/migrate/jscodeshift.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const run = async <TransformOptions extends Options = Options>({
babel: true, // without this, `jscodeshift` will not be able to parse TS transforms
dry,
extensions: "tsx,ts,jsx,js",
failOnError: true,
failOnError: false,
ignorePattern: ["**/node_modules/**", "**/.cache/**", "**/build/**"],
parser: "tsx",
print,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type { MigrationFunction } from "../../types";
import { cleanupPackageJson } from "./cleanupPackageJson";
import { convertTSConfigs } from "./convertTSConfigs";
import { convertTSFilesToJS } from "./convertTSFilesToJS";
import { CliError } from "../../../error";

const TRANSFORM_PATH = join(__dirname, "transform");

Expand Down Expand Up @@ -39,8 +40,7 @@ export const convertToJavaScript: MigrationFunction = async (
if (flags.interactive && !flags.debug) {
console.log("👉 Try again with the `--debug` flag to see what failed.");
}

process.exit(1);
throw new CliError();
}

// 4. Convert all .ts files to .js
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,19 @@ import {
} from "./remixSetup";
import { resolveTransformOptions } from "./resolveTransformOptions";
import type { Options } from "./transform/options";
import { CliError } from "../../../error";

const TRANSFORM_PATH = join(__dirname, "transform");

const getRemixVersionSpec = (remixDeps: Dependency[]): string => {
let candidate = maxBy(remixDeps, (dep) => semver.minVersion(dep.versionSpec));
if (candidate === undefined) {
console.error("❌ I couldn't find versions for your Remix packages.");
process.exit(1);
throw new CliError("❌ I couldn't find versions for your Remix packages.");
}

let candidateMin = semver.minVersion(candidate.versionSpec);
if (candidateMin === null) {
console.error("❌ I couldn't find versions for your Remix packages.");
process.exit(1);
throw new CliError("❌ I couldn't find versions for your Remix packages.");
}

if (semver.lt(candidateMin, "1.3.3")) {
Expand Down Expand Up @@ -175,7 +174,7 @@ export const replaceRemixImports: MigrationFunction = async (
if (!flags.debug) {
console.log("👉 Try again with the `--debug` flag to see what failed.");
}
process.exit(1);
throw new CliError();
}
console.log("✅ Your Remix imports look good!");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { PackageJson } from "@npmcli/package-json";
import inquirer from "inquirer";

import * as colors from "../../../../colors";
import { CliError } from "../../../error";
import { depsToEntries, isRemixPackage } from "./dependency";
import { because, detected } from "./messages";
import { remixSetup, remixSetupRuntime } from "./remixSetup";
Expand Down Expand Up @@ -109,7 +110,7 @@ const resolveAdapter = (packageJson: PackageJson): Adapter | undefined => {
adapters.map((adapter) => ` - @remix-run/${adapter}`).join("\n")
);
console.log("👉 Uninstall unused adapters and try again.");
process.exit(1);
throw new CliError();
}

if (adapters.length === 1) {
Expand Down
1 change: 1 addition & 0 deletions packages/remix-dev/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ export type { AppConfig } from "./config";

export * as cli from "./cli/index";
export { createApp } from "./cli/create";
export { CliError } from "./cli/error";

export { getDependenciesToBundle } from "./compiler/dependencies";

0 comments on commit 438a98e

Please sign in to comment.