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): add option to remove typescript types during project creation #2317

Merged
merged 28 commits into from
Mar 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
eda5a74
chore: use name as given
mcansh Mar 21, 2022
82632de
test: add test for converting a project to javascript
mcansh Mar 15, 2022
228dc0c
chore: default useTypeScript to true
mcansh Mar 15, 2022
9f292a2
update extension used in test
mcansh Mar 15, 2022
d234472
test: add globalSetup to remix-dev
mcansh Mar 15, 2022
0edbe5e
chore: import babel preset and plugin
mcansh Mar 15, 2022
c62ae0a
chore: review changes
mcansh Mar 16, 2022
93aad02
test: add subfolder to tmp for each type of test
mcansh Mar 16, 2022
49fb048
test: re-add test for file URL to a tarball on disk, and separate str…
mcansh Mar 16, 2022
022d86a
test: update CLI output
mcansh Mar 16, 2022
8900894
fix: exclude typescript dep
mcansh Mar 16, 2022
481cbb1
test: add template options for createFixture
mcansh Mar 21, 2022
d33188c
fix: pass projectDir to babel
mcansh Mar 21, 2022
8d96140
chore: remove javascript templates
mcansh Mar 21, 2022
45a98da
feat: convert template to js
mcansh Mar 21, 2022
1906eea
test: update afterAll hook
mcansh Mar 21, 2022
9d72055
chore: update template names
mcansh Mar 21, 2022
7be390a
test: update opt out dep message
mcansh Mar 22, 2022
4c84d25
test: update template URL until this PR is merged
mcansh Mar 22, 2022
44a10ef
test: update js conversion test
mcansh Mar 22, 2022
db12a71
test: updated the url so i didnt have to skip it lol
mcansh Mar 22, 2022
704d8ad
test: update beforeAll
mcansh Mar 22, 2022
2145618
chore: code review
mcansh Mar 22, 2022
5b1e52a
test: skip test instead of adding a todo
mcansh Mar 22, 2022
2cbbd26
chore: emptyDir will create the dir if it doesnt exist
mcansh Mar 22, 2022
2c6225c
Merge branch 'dev' into logan/ts-strip-types
mcansh Mar 22, 2022
dc179ea
chore: code review
mcansh Mar 22, 2022
e4a89e0
Merge branch 'dev' into logan/ts-strip-types
mcansh Mar 22, 2022
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
11 changes: 10 additions & 1 deletion integration/helpers/create-fixture.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,16 @@ const REMIX_SOURCE_BUILD_DIR = path.join(process.cwd(), "build");

interface FixtureInit {
files: { [filename: string]: string };
template?: string;
template?:
| "arc"
| "cloudflare-pages"
| "cloudflare-workers"
| "deno"
| "express"
| "fly"
| "netlify"
| "remix"
| "vercel";
}

export type Fixture = Awaited<ReturnType<typeof createFixture>>;
Expand Down
10 changes: 3 additions & 7 deletions integration/helpers/global-setup.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
import fs from "fs/promises";
import fse from "fs-extra";
import path from "path";
import setupPuppeteer from "jest-environment-puppeteer/setup";

export const TMP_DIR = path.join(process.cwd(), ".tmp");
export const TMP_DIR = path.join(process.cwd(), ".tmp", "integration");

// TODO: get rid of React Router `console.warn` when no routes match when testing
console.warn = () => {};

export default async function setup(globalConfig: any) {
await setupPuppeteer(globalConfig);
await fs.rm(TMP_DIR, {
force: true,
recursive: true,
});
await fs.mkdir(TMP_DIR);
await fse.emptyDir(TMP_DIR);
}
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ module.exports = {
setupFilesAfterEnv: [
"<rootDir>/packages/remix-dev/__tests__/setupAfterEnv.ts",
],
globalSetup: process.env.CI ? undefined : "<rootDir>/jest/buildRemix.ts",
},
{
displayName: "remix-express",
Expand Down
179 changes: 136 additions & 43 deletions packages/remix-dev/__tests__/cli-test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import childProcess from "child_process";
import fs from "fs";
import fsp from "fs/promises";
import fse from "fs-extra";
import path from "path";
import util from "util";
import { pathToFileURL } from "url";
Expand All @@ -16,13 +15,14 @@ const remix = path.resolve(
"../../../build/node_modules/@remix-run/dev/cli.js"
);

const TEMP_DIR = path.join(process.cwd(), ".tmp", "create-remix");

describe("remix cli", () => {
beforeAll(() => {
if (!fs.existsSync(remix)) {
if (!fse.existsSync(remix)) {
throw new Error(`Cannot run Remix CLI tests w/out building Remix`);
}
});

describe("the --help flag", () => {
it("prints help info", async () => {
let { stdout } = await execFile("node", [remix, "--help"], {
Expand Down Expand Up @@ -134,6 +134,10 @@ describe("remix cli", () => {
});

describe("the create command", () => {
beforeAll(async () => {
await fse.emptyDir(TEMP_DIR);
});

afterAll(() => {
/**
* This prevents the console for spitting out a bunch of junk like this for
Expand All @@ -147,22 +151,21 @@ describe("remix cli", () => {
*/
async function renamePkgJsonApp(dir: string) {
let pkgPath = path.join(dir, "package.json");
let pkg = await fsp.readFile(pkgPath);
let pkg = await fse.readFile(pkgPath);
let obj = JSON.parse(pkg.toString());
obj.name = path.basename(dir);
await fsp.writeFile(pkgPath, JSON.stringify(obj, null, 2) + "\n");
await fse.writeFile(pkgPath, JSON.stringify(obj, null, 2) + "\n");
}

let dirs = fs.readdirSync(path.join(process.cwd(), ".tmp"));
let dirs = fse.readdirSync(TEMP_DIR);
for (let dir of dirs) {
renamePkgJsonApp(path.join(process.cwd(), ".tmp", dir));
renamePkgJsonApp(path.join(TEMP_DIR, dir));
}
});

function getProjectDir(name: string) {
return path.join(
process.cwd(),
".tmp",
TEMP_DIR,
`${name}-${Math.random().toString(32).slice(2)}`
);
}
Expand All @@ -181,8 +184,12 @@ describe("remix cli", () => {
expect(stdout.trim()).toBe(
`💿 That's it! \`cd\` into "${projectDir}" and check the README for development and deploy instructions!`
);
expect(fs.existsSync(path.join(projectDir, "package.json"))).toBeTruthy();
expect(fs.existsSync(path.join(projectDir, "app/root.tsx"))).toBeTruthy();
expect(
fse.existsSync(path.join(projectDir, "package.json"))
).toBeTruthy();
expect(
fse.existsSync(path.join(projectDir, "app/root.tsx"))
).toBeTruthy();
});

it("works for templates in the remix org", async () => {
Expand All @@ -199,8 +206,12 @@ describe("remix cli", () => {
`💿 You've opted out of installing dependencies so we won't run the remix.init/index.js script for you just yet. Once you've installed dependencies, you can run it manually with \`npx remix init\`
💿 That's it! \`cd\` into "${projectDir}" and check the README for development and deploy instructions!`
);
expect(fs.existsSync(path.join(projectDir, "package.json"))).toBeTruthy();
expect(fs.existsSync(path.join(projectDir, "app/root.tsx"))).toBeTruthy();
expect(
fse.existsSync(path.join(projectDir, "package.json"))
).toBeTruthy();
expect(
fse.existsSync(path.join(projectDir, "app/root.tsx"))
).toBeTruthy();
});

it("works for GitHub username/repo combo", async () => {
Expand All @@ -216,8 +227,12 @@ describe("remix cli", () => {
expect(stdout.trim()).toBe(
`💿 That's it! \`cd\` into "${projectDir}" and check the README for development and deploy instructions!`
);
expect(fs.existsSync(path.join(projectDir, "package.json"))).toBeTruthy();
expect(fs.existsSync(path.join(projectDir, "app/root.tsx"))).toBeTruthy();
expect(
fse.existsSync(path.join(projectDir, "package.json"))
).toBeTruthy();
expect(
fse.existsSync(path.join(projectDir, "app/root.tsx"))
).toBeTruthy();
});

it("works for remote tarballs", async () => {
Expand All @@ -233,11 +248,15 @@ describe("remix cli", () => {
expect(stdout.trim()).toBe(
`💿 That's it! \`cd\` into "${projectDir}" and check the README for development and deploy instructions!`
);
expect(fs.existsSync(path.join(projectDir, "package.json"))).toBeTruthy();
expect(fs.existsSync(path.join(projectDir, "app/root.tsx"))).toBeTruthy();
expect(
fse.existsSync(path.join(projectDir, "package.json"))
).toBeTruthy();
expect(
fse.existsSync(path.join(projectDir, "app/root.tsx"))
).toBeTruthy();
});

it("works for different branches", async () => {
it.skip("works for different branches", async () => {
let projectDir = getProjectDir("diff-branch");
let { stdout } = await execFile("node", [
remix,
Expand All @@ -250,8 +269,12 @@ describe("remix cli", () => {
expect(stdout.trim()).toBe(
`💿 That's it! \`cd\` into "${projectDir}" and check the README for development and deploy instructions!`
);
expect(fs.existsSync(path.join(projectDir, "package.json"))).toBeTruthy();
expect(fs.existsSync(path.join(projectDir, "app/root.jsx"))).toBeTruthy();
expect(
fse.existsSync(path.join(projectDir, "package.json"))
).toBeTruthy();
expect(
fse.existsSync(path.join(projectDir, "app/root.tsx"))
).toBeTruthy();
});

it("works for a path to a tarball on disk", async () => {
Expand All @@ -267,8 +290,12 @@ describe("remix cli", () => {
expect(stdout.trim()).toBe(
`💿 That's it! \`cd\` into "${projectDir}" and check the README for development and deploy instructions!`
);
expect(fs.existsSync(path.join(projectDir, "package.json"))).toBeTruthy();
expect(fs.existsSync(path.join(projectDir, "app/root.tsx"))).toBeTruthy();
expect(
fse.existsSync(path.join(projectDir, "package.json"))
).toBeTruthy();
expect(
fse.existsSync(path.join(projectDir, "app/root.tsx"))
).toBeTruthy();
});

it("works for a file URL to a tarball on disk", async () => {
Expand All @@ -286,8 +313,50 @@ describe("remix cli", () => {
expect(stdout.trim()).toBe(
`💿 That's it! \`cd\` into "${projectDir}" and check the README for development and deploy instructions!`
);
expect(fs.existsSync(path.join(projectDir, "package.json"))).toBeTruthy();
expect(fs.existsSync(path.join(projectDir, "app/root.tsx"))).toBeTruthy();
expect(
fse.existsSync(path.join(projectDir, "package.json"))
).toBeTruthy();
expect(
fse.existsSync(path.join(projectDir, "app/root.tsx"))
).toBeTruthy();
});

it("converts a template to javascript", async () => {
let projectDir = getProjectDir("template-to-js");
let { stdout } = await execFile("node", [
remix,
"create",
projectDir,
"--template",
"blues-stack",
"--no-install",
"--no-typescript",
]);
expect(stdout.trim()).toBe(
`💿 You've opted out of installing dependencies so we won't run the remix.init/index.js script for you just yet. Once you've installed dependencies, you can run it manually with \`npx remix init\`
💿 That's it! \`cd\` into "${projectDir}" and check the README for development and deploy instructions!`
);
expect(
fse.existsSync(path.join(projectDir, "package.json"))
).toBeTruthy();
expect(
fse.existsSync(path.join(projectDir, "app/root.jsx"))
).toBeTruthy();
expect(fse.existsSync(path.join(projectDir, "app/root.tsx"))).toBeFalsy();
expect(
fse.existsSync(path.join(projectDir, "tsconfig.json"))
).toBeFalsy();
expect(
fse.existsSync(path.join(projectDir, "jsconfig.json"))
).toBeTruthy();
expect(
fse.existsSync(path.join(projectDir, "app/session.server.js"))
).toBeTruthy();
let pkgJSON = JSON.parse(
fse.readFileSync(path.join(projectDir, "package.json"), "utf-8")
);
expect(Object.keys(pkgJSON.devDependencies)).not.toContain("typescript");
expect(Object.keys(pkgJSON.scripts)).not.toContain("typecheck");
});

it("works for a file path to a directory on disk", async () => {
Expand All @@ -303,8 +372,12 @@ describe("remix cli", () => {
expect(stdout.trim()).toBe(
`💿 That's it! \`cd\` into "${projectDir}" and check the README for development and deploy instructions!`
);
expect(fs.existsSync(path.join(projectDir, "package.json"))).toBeTruthy();
expect(fs.existsSync(path.join(projectDir, "app/root.tsx"))).toBeTruthy();
expect(
fse.existsSync(path.join(projectDir, "package.json"))
).toBeTruthy();
expect(
fse.existsSync(path.join(projectDir, "app/root.tsx"))
).toBeTruthy();
});

it("works for a file URL to a directory on disk", async () => {
Expand All @@ -320,8 +393,12 @@ describe("remix cli", () => {
expect(stdout.trim()).toBe(
`💿 That's it! \`cd\` into "${projectDir}" and check the README for development and deploy instructions!`
);
expect(fs.existsSync(path.join(projectDir, "package.json"))).toBeTruthy();
expect(fs.existsSync(path.join(projectDir, "app/root.tsx"))).toBeTruthy();
expect(
fse.existsSync(path.join(projectDir, "package.json"))
).toBeTruthy();
expect(
fse.existsSync(path.join(projectDir, "app/root.tsx"))
).toBeTruthy();
});

it("runs remix.init script when installing dependencies", async () => {
Expand All @@ -338,10 +415,14 @@ describe("remix cli", () => {
`💿 That's it! \`cd\` into "${projectDir}" and check the README for development and deploy instructions!`
);
expect(stdout.trim()).toContain(`💿 Running remix.init script`);
expect(fs.existsSync(path.join(projectDir, "package.json"))).toBeTruthy();
expect(fs.existsSync(path.join(projectDir, "app/root.tsx"))).toBeTruthy();
expect(fs.existsSync(path.join(projectDir, "test.txt"))).toBeTruthy();
expect(fs.existsSync(path.join(projectDir, "remix.init"))).toBeFalsy();
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();
expect(fse.existsSync(path.join(projectDir, "remix.init"))).toBeFalsy();
// deps can take a bit to install
}, 60_000);

Expand All @@ -364,11 +445,15 @@ describe("remix cli", () => {
});

expect(initResult.stdout.trim()).toBe("");
expect(fs.existsSync(path.join(projectDir, "package.json"))).toBeTruthy();
expect(fs.existsSync(path.join(projectDir, "app/root.tsx"))).toBeTruthy();
expect(fs.existsSync(path.join(projectDir, "test.txt"))).toBeTruthy();
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(fs.existsSync(path.join(projectDir, "remix.init"))).toBeTruthy();
expect(fse.existsSync(path.join(projectDir, "remix.init"))).toBeTruthy();
// deps can take a bit to install
}, 60_000);

Expand All @@ -385,10 +470,14 @@ describe("remix cli", () => {
])
).rejects.toThrowError(`🚨 Oops, remix.init failed`);

expect(fs.existsSync(path.join(projectDir, "package.json"))).toBeTruthy();
expect(fs.existsSync(path.join(projectDir, "app/root.tsx"))).toBeTruthy();
expect(
fse.existsSync(path.join(projectDir, "package.json"))
).toBeTruthy();
expect(
fse.existsSync(path.join(projectDir, "app/root.tsx"))
).toBeTruthy();
// we should keep remix.init around if the init script fails
expect(fs.existsSync(path.join(projectDir, "remix.init"))).toBeTruthy();
expect(fse.existsSync(path.join(projectDir, "remix.init"))).toBeTruthy();
// deps can take a bit to install
}, 60_000);

Expand All @@ -412,10 +501,14 @@ describe("remix cli", () => {
cwd: projectDir,
})
).rejects.toThrowError(`🚨 Oops, remix.init failed`);
expect(fs.existsSync(path.join(projectDir, "package.json"))).toBeTruthy();
expect(fs.existsSync(path.join(projectDir, "app/root.tsx"))).toBeTruthy();
expect(
fse.existsSync(path.join(projectDir, "package.json"))
).toBeTruthy();
expect(
fse.existsSync(path.join(projectDir, "app/root.tsx"))
).toBeTruthy();
// we should keep remix.init around if the init script fails
expect(fs.existsSync(path.join(projectDir, "remix.init"))).toBeTruthy();
expect(fse.existsSync(path.join(projectDir, "remix.init"))).toBeTruthy();
// deps can take a bit to install
}, 60_000);
});
Expand Down
Loading