Skip to content

Commit

Permalink
fix(remix-dev/cli/init): always remove remix.init folder (#3571)
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelDeBoey authored Jun 25, 2022
1 parent bbd2894 commit 19b32f4
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 23 deletions.
3 changes: 1 addition & 2 deletions packages/remix-dev/__tests__/create-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -476,8 +476,7 @@ describe("the create command", () => {
expect(fse.existsSync(path.join(projectDir, "package.json"))).toBeTruthy();
expect(fse.existsSync(path.join(projectDir, "app/root.tsx"))).toBeTruthy();
expect(fse.existsSync(path.join(projectDir, "test.txt"))).toBeTruthy();
// if you run `remix init` keep around the remix.init directory for future use
expect(fse.existsSync(path.join(projectDir, "remix.init"))).toBeTruthy();
expect(fse.existsSync(path.join(projectDir, "remix.init"))).toBeFalsy();
});

it("throws an error when invalid remix.init script when automatically ran", async () => {
Expand Down
43 changes: 23 additions & 20 deletions packages/remix-dev/cli/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,31 +59,34 @@ export async function create({
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))) {
return;
}

if (await fse.pathExists(initScript)) {
let packageManager = getPreferredPackageManager();
let initPackageJson = path.resolve(initScriptDir, "package.json");
let isTypeScript = fse.existsSync(path.join(projectDir, "tsconfig.json"));
let packageManager = getPreferredPackageManager();

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

let initFn = require(initScript);
try {
await initFn({ isTypeScript, packageManager, rootDirectory: projectDir });
} catch (error) {
if (error instanceof Error) {
error.message = `${colors.error("🚨 Oops, remix.init failed")}\n\n${
error.message
}`;
}
throw error;
let initFn = require(initScript);
try {
await initFn({ isTypeScript, packageManager, rootDirectory: projectDir });

await fse.remove(initScriptDir);
} catch (error) {
if (error instanceof Error) {
error.message = `${colors.error("🚨 Oops, remix.init failed")}\n\n${
error.message
}`;
}
throw error;
}
}

Expand Down
1 change: 0 additions & 1 deletion packages/remix-dev/cli/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,6 @@ export async function run(argv: string[] = process.argv.slice(2)) {
if (installDeps) {
console.log("💿 Running remix.init script");
await commands.init(projectDir);
await fse.remove(initScriptDir);
} else {
console.log();
console.log(
Expand Down

0 comments on commit 19b32f4

Please sign in to comment.