Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(remix-dev): support a TypeScript file for the remix.init index script #2803

Merged
merged 9 commits into from
Jul 22, 2022
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
1 change: 1 addition & 0 deletions contributors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
- donavon
- Dueen
- dunglas
- dvargas92495
- dwightwatson
- dwt47
- dylanplayer
Expand Down
16 changes: 16 additions & 0 deletions packages/remix-dev/__tests__/create-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,22 @@ describe("the create command", () => {
expect(fse.existsSync(path.join(projectDir, "remix.init"))).toBeFalsy();
});

it("runs remix.init script when using index.ts", async () => {
let projectDir = await getProjectDir("remix-init-ts");
await run([
"create",
projectDir,
"--template",
path.join(__dirname, "fixtures", "stack-init-ts.tar.gz"),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just copied the stack under /fixtures/stack, converting the index file to index.ts and console logging the message below in the default method exported

"--install",
"--typescript",
]);
expect(output).toContain(`Running init script on ${projectDir.replace(TEMP_DIR, "<TEMP_DIR>")}`);
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, "remix.init"))).toBeFalsy();
});

it("runs remix.init script when using `remix init`", async () => {
let projectDir = await getProjectDir("remix-init-manual");
await run([
Expand Down
Binary file not shown.
14 changes: 14 additions & 0 deletions packages/remix-dev/cli/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type { Server } from "http";
import type * as Express from "express";
import type { createApp as createAppType } from "@remix-run/serve";
import getPort, { makeRange } from "get-port";
import * as esbuild from "esbuild";

import { BuildMode, isBuildMode } from "../build";
import * as colors from "../colors";
Expand Down Expand Up @@ -64,8 +65,17 @@ export async function init(
{ deleteScript = true }: InitFlags = {}
) {
let initScriptDir = path.join(projectDir, "remix.init");
let initScriptTs = path.resolve(initScriptDir, "index.ts");
let initScript = path.resolve(initScriptDir, "index.js");

if (await fse.pathExists(initScriptTs)) {
await esbuild.build({
entryPoints: [initScriptTs],
format: "cjs",
platform: "node",
outfile: initScript,
})
}
if (!(await fse.pathExists(initScript))) {
return;
}
Expand All @@ -74,6 +84,7 @@ export async function init(
let isTypeScript = fse.existsSync(path.join(projectDir, "tsconfig.json"));
let packageManager = getPreferredPackageManager();


if (await fse.pathExists(initPackageJson)) {
execSync(`${packageManager} install`, {
cwd: initScriptDir,
Expand All @@ -82,6 +93,9 @@ export async function init(
}

let initFn = require(initScript);
if (typeof initFn !== 'function' && initFn.default) {
initFn = initFn.default;
}
try {
await initFn({ isTypeScript, packageManager, rootDirectory: projectDir });

Expand Down
3 changes: 2 additions & 1 deletion packages/remix-dev/cli/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,8 @@ async function extractLocalTarball(
throw Error(
"🚨 There was a problem extracting the file from the provided template.\n\n" +
` Template filepath: \`${filePath}\`\n` +
` Destination directory: \`${projectDir}\``
` Destination directory: \`${projectDir}\`\n` +
` ${err}`
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is passing locally and failing on this error. Happy to remove this after I find out why it's failing on GH actions, but I think the error itself should be somewhere in this error message

);
}
}
Expand Down