Skip to content

Commit

Permalink
Merge branch 'dev' into feature/css-modules
Browse files Browse the repository at this point in the history
  • Loading branch information
chaance committed May 18, 2022
2 parents f5a1432 + b4fb6c5 commit 859eadf
Show file tree
Hide file tree
Showing 14 changed files with 82 additions and 69 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ on:
- v*
paths-ignore:
- "docs/**"
- "scripts/**"
- "**/README.md"
pull_request: {}

Expand Down
3 changes: 0 additions & 3 deletions integration/tsconfig-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ const DEFAULT_CONFIG = {
strict: true,
target: "ES2019",
baseUrl: ".",
paths: {
"~/*": ["./app/*"],
},
},
};

Expand Down
8 changes: 8 additions & 0 deletions packages/remix-deno/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ export {
isCookie,
isSession,
json,
MaxPartSizeExceededError,
redirect,
unstable_composeUploadHandlers,
unstable_createMemoryUploadHandler,
unstable_parseMultipartFormData,
} from "@remix-run/server-runtime";

export type {
Expand All @@ -42,6 +46,8 @@ export type {
LinkDescriptor,
LinksFunction,
LoaderFunction,
MemoryUploadHandlerFilterArgs,
MemoryUploadHandlerOptions,
MetaDescriptor,
MetaFunction,
PageLinkDescriptor,
Expand All @@ -54,4 +60,6 @@ export type {
SessionData,
SessionIdStorageStrategy,
SessionStorage,
UploadHandler,
UploadHandlerPart,
} from "@remix-run/server-runtime";
9 changes: 4 additions & 5 deletions packages/remix-dev/__tests__/replace-remix-imports-test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import os from "os";
import path from "path";
import fse from "fs-extra";
import os from "os";
import glob from "fast-glob";
import shell from "shelljs";
import stripAnsi from "strip-ansi";
import type { PackageJson } from "type-fest";
import shell from "shelljs";
import glob from "fast-glob";

import { run } from "../cli/run";
import { readConfig } from "../config";
Expand Down Expand Up @@ -110,6 +110,5 @@ describe("`replace-remix-imports` migration", () => {
expect(result.code).toBe(0);

expect(output).toContain("successfully migrated");
expect(output).toContain("npm install");
}, 25_000);
}, 200_000);
});
15 changes: 6 additions & 9 deletions packages/remix-dev/cli/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ import * as compiler from "../compiler";
import type { RemixConfig } from "../config";
import { readConfig } from "../config";
import { formatRoutes, RoutesFormat, isRoutesFormat } from "../config/format";
import { createApp } from "./create";
import { loadEnv } from "../env";
import { log } from "../logging";
import { createApp } from "./create";
import { getPreferredPackageManager } from "./getPreferredPackageManager";
import { setupRemix, isSetupPlatform, SetupPlatform } from "./setup";

export * as migrate from "./migrate";
Expand All @@ -29,7 +30,6 @@ export async function create({
projectDir,
remixVersion,
installDeps,
packageManager,
useTypeScript,
githubToken,
debug,
Expand All @@ -38,7 +38,6 @@ export async function create({
projectDir: string;
remixVersion?: string;
installDeps: boolean;
packageManager: "npm" | "yarn" | "pnpm";
useTypeScript: boolean;
githubToken?: string;
debug?: boolean;
Expand All @@ -49,7 +48,6 @@ export async function create({
projectDir,
remixVersion,
installDeps,
packageManager,
useTypeScript,
githubToken,
debug,
Expand All @@ -58,21 +56,20 @@ export async function create({
spinner.clear();
}

export async function init(
projectDir: string,
packageManager: "npm" | "yarn" | "pnpm"
) {
export async function init(projectDir: string) {
let initScriptDir = path.join(projectDir, "remix.init");
let initScript = path.resolve(initScriptDir, "index.js");
let initPackageJson = path.resolve(initScriptDir, "package.json");

let isTypeScript = fse.existsSync(path.join(projectDir, "tsconfig.json"));

if (await fse.pathExists(initScript)) {
let packageManager = getPreferredPackageManager();

if (await fse.pathExists(initPackageJson)) {
execSync(`${packageManager} install`, {
stdio: "ignore",
cwd: initScriptDir,
stdio: "ignore",
});
}

Expand Down
7 changes: 4 additions & 3 deletions packages/remix-dev/cli/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import sortPackageJSON from "sort-package-json";
import * as colors from "../colors";
import packageJson from "../package.json";
import { convertTemplateToJavaScript } from "./convert-to-javascript";
import { getPreferredPackageManager } from "./getPreferredPackageManager";

const remixDevPackageVersion = packageJson.version;

Expand All @@ -22,7 +23,6 @@ interface CreateAppArgs {
projectDir: string;
remixVersion?: string;
installDeps: boolean;
packageManager: "npm" | "yarn" | "pnpm";
useTypeScript: boolean;
githubToken?: string;
debug?: boolean;
Expand All @@ -33,7 +33,6 @@ export async function createApp({
projectDir,
remixVersion = remixDevPackageVersion,
installDeps,
packageManager,
useTypeScript = true,
githubToken = process.env.GITHUB_TOKEN,
debug,
Expand Down Expand Up @@ -197,6 +196,8 @@ export async function createApp({
}

if (installDeps) {
let packageManager = getPreferredPackageManager();

let npmConfig = execSync(
`${packageManager} config get @remix-run:registry`,
{
Expand All @@ -212,8 +213,8 @@ export async function createApp({
}

execSync(`${packageManager} install`, {
stdio: "inherit",
cwd: projectDir,
stdio: "inherit",
});
}
}
Expand Down
12 changes: 12 additions & 0 deletions packages/remix-dev/cli/getPreferredPackageManager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
type PackageManager = "npm" | "pnpm" | "yarn";

/**
* Determine which package manager the user prefers.
*
* npm, pnpm and Yarn set the user agent environment variable
* that can be used to determine which package manager ran
* the command.
*/
export const getPreferredPackageManager = () =>
((process.env.npm_config_user_agent ?? "").split("/")[0] ||
"npm") as PackageManager;
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { execSync } from "child_process";
import { join } from "path";
import NpmCliPackageJson from "@npmcli/package-json";
import glob from "fast-glob";
Expand All @@ -6,6 +7,7 @@ import semver from "semver";

import * as colors from "../../../../colors";
import { readConfig } from "../../../../config";
import { getPreferredPackageManager } from "../../../getPreferredPackageManager";
import * as jscodeshift from "../../jscodeshift";
import type { MigrationFunction } from "../../types";
import type { Dependency } from "./dependency";
Expand Down Expand Up @@ -74,13 +76,13 @@ const shouldKeepPostinstall = (original?: string): boolean => {
};

export const replaceRemixImports: MigrationFunction = async ({
projectDir,
flags,
projectDir,
}) => {
let pkg = await NpmCliPackageJson.load(projectDir);

// 0. resolve runtime and adapter
let { runtime, adapter } = await resolveTransformOptions(pkg.content);
let { adapter, runtime } = await resolveTransformOptions(pkg.content);

let deps = depsToEntries(pkg.content.dependencies);
let remixDeps = deps.filter(({ name }) => isRemixPackage(name));
Expand Down Expand Up @@ -142,13 +144,20 @@ export const replaceRemixImports: MigrationFunction = async ({
// write updates to package.json
await pkg.save();

// 3. Run codemod
// 3. Update lockfile for new dependencies by reinstalling
console.log("\n💿 I'm updating your lockfile");
console.log(because("your dependencies changed."));
let packageManager = getPreferredPackageManager();
execSync(`${packageManager} install`, { cwd: projectDir, stdio: "inherit" });
console.log("✅ Your lockfile looks good!");

// 4. Run codemod
console.log("\n💿 I'm replacing any `remix` imports");
console.log(because("importing from `remix` is deprecated."));
let config = await readConfig(projectDir);
let files = glob.sync("**/*.+(js|jsx|ts|tsx)", {
cwd: config.appDirectory,
absolute: true,
cwd: config.appDirectory,
});
let codemodOk = await jscodeshift.run<Options>({
files,
Expand All @@ -166,8 +175,4 @@ export const replaceRemixImports: MigrationFunction = async ({
console.log("✅ Your Remix imports look good!");

console.log("\n🚚 I've successfully migrated your project! 🎉");
console.log(
"\n👉 Reinstall from your updated `package.json` to update your lockfile"
);
console.log(` ${colors.blue("npm install")}`);
};
7 changes: 4 additions & 3 deletions packages/remix-dev/cli/migrate/run.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import fse from "fs-extra";

import * as colors from "../../colors";
import type { Flags } from "./flags";
import { migrations } from "./migrations";
import type { Migration } from "./types";
import * as colors from "../../colors";

const parseMigration = (migrationId: string): Migration => {
let migration = migrations.find(({ id }) => id === migrationId);
Expand All @@ -27,11 +27,12 @@ const checkProjectDir = (projectDir: string): string => {
};

export const run = async (input: {
flags: Flags;
migrationId: string;
projectDir: string;
flags: Flags;
}) => {
let projectDir = checkProjectDir(input.projectDir);
let migration = parseMigration(input.migrationId);
return migration.function({ projectDir, flags: input.flags });

return migration.function({ flags: input.flags, projectDir });
};
2 changes: 1 addition & 1 deletion packages/remix-dev/cli/migrate/types.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { Flags } from "./flags";

export type MigrationFunction = (args: {
projectDir: string;
flags: Flags;
projectDir: string;
}) => Promise<void>;

export interface Migration {
Expand Down
37 changes: 9 additions & 28 deletions packages/remix-dev/cli/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,7 @@ import * as colors from "../colors";
import * as commands from "./commands";
import { convertTemplateToJavaScript } from "./convert-to-javascript";
import { validateNewProjectPath, validateTemplate } from "./create";

/**
* Determine which package manager the user prefers.
*
* npm, Yarn and pnpm set the user agent environment variable
* that can be used to determine which package manager ran
* the command.
*/
const getPreferredPackageManager = () =>
((process.env.npm_config_user_agent ?? "").split("/")[0] || "npm") as
| "npm"
| "yarn"
| "pnpm";
import { getPreferredPackageManager } from "./getPreferredPackageManager";

const helpText = `
${colors.logoBlue("R")} ${colors.logoGreen("E")} ${colors.logoYellow(
Expand Down Expand Up @@ -241,7 +229,7 @@ export async function run(argv: string[] = process.argv.slice(2)) {
return;
}

let pm = getPreferredPackageManager();
let packageManager = getPreferredPackageManager();
let answers = await inquirer
.prompt<{
appType: "template" | "stack";
Expand Down Expand Up @@ -307,7 +295,7 @@ export async function run(argv: string[] = process.argv.slice(2)) {
{
name: "install",
type: "confirm",
message: `Do you want me to run \`${pm} install\`?`,
message: `Do you want me to run \`${packageManager} install\`?`,
when() {
return flags.install === undefined;
},
Expand All @@ -321,7 +309,7 @@ export async function run(argv: string[] = process.argv.slice(2)) {
"🚨 Your terminal doesn't support interactivity; using default " +
"configuration.\n\n" +
"If you'd like to use different settings, try passing them " +
`as arguments. Run \`${pm} create remix@latest --help\` to see ` +
`as arguments. Run \`${packageManager} create remix@latest --help\` to see ` +
"available options."
)
);
Expand All @@ -342,7 +330,6 @@ export async function run(argv: string[] = process.argv.slice(2)) {
projectDir,
remixVersion: flags.remixVersion,
installDeps,
packageManager: pm,
useTypeScript: flags.typescript !== false,
githubToken: process.env.GITHUB_TOKEN,
debug: flags.debug,
Expand Down Expand Up @@ -378,7 +365,7 @@ export async function run(argv: string[] = process.argv.slice(2)) {
if (hasInitScript) {
if (installDeps) {
console.log("💿 Running remix.init script");
await commands.init(projectDir, pm);
await commands.init(projectDir);
await fse.remove(initScriptDir);
} else {
console.log();
Expand All @@ -387,7 +374,7 @@ export async function run(argv: string[] = process.argv.slice(2)) {
"💿 You've opted out of installing dependencies so we won't run the " +
path.join("remix.init", "index.js") +
" script for you just yet. Once you've installed " +
`dependencies, you can run it manually with \`${npxInterop[pm]} remix init\``
`dependencies, you can run it manually with \`${npxInterop[packageManager]} remix init\``
)
);
console.log();
Expand All @@ -413,10 +400,7 @@ export async function run(argv: string[] = process.argv.slice(2)) {
break;
}
case "init":
await commands.init(
input[1] || process.env.REMIX_ROOT || process.cwd(),
getPreferredPackageManager()
);
await commands.init(input[1] || process.env.REMIX_ROOT || process.cwd());
break;
case "routes":
await commands.routes(input[1], flags.json ? "json" : "jsx");
Expand All @@ -434,13 +418,10 @@ export async function run(argv: string[] = process.argv.slice(2)) {
break;
case "migrate": {
let { projectDir, migrationId } = await commands.migrate.resolveInput(
{
projectId: input[1],
migrationId: flags.migration,
},
{ migrationId: flags.migration, projectId: input[1] },
flags
);
await commands.migrate.run({ migrationId, projectDir, flags });
await commands.migrate.run({ flags, migrationId, projectDir });
break;
}
case "dev":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ let suggestedCompilerOptions: TsConfigJson.CompilerOptions = {
allowJs: true,
forceConsistentCasingInFileNames: true,
lib: ["DOM", "DOM.Iterable", "ES2019"],
paths: {
"~/*": ["./app/*"],
},
strict: true,
target: "ES2019",
};
Expand Down

0 comments on commit 859eadf

Please sign in to comment.