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

Modernize Deno template #9932

Open
wants to merge 40 commits into
base: dev
Choose a base branch
from

Conversation

redabacha
Copy link
Contributor

@redabacha redabacha commented Sep 2, 2024

This modernizes the Deno template to use all the goodies of the releases over the past several years. It removes the need for a package.json file, any dependency on Node.js + npm and now uses Vite instead of the classic Remix compiler.

It also drops the need for the @remix-run/deno package, allowing it to be deprecated and removed in the future. I am not sure what the deprecation + removal process looks like for a remix package so I have opted to leave that out of this PR.

The new Deno template is currently setup to lint the app/ directory with eslint (which Deno can run) in order to align more closely with how the other templates are setup and provide better linting rules and flexibility which is needed for web development, e.g. eslint-plugin-react-hooks gives the rules-of-hooks lint rule that Deno does not have.

Furthermore, typechecking is now done with typescript's tsc for all files with app/. This allows again for more flexibility by being able to control the typescript version and configuration independent of Deno. In order to provide Deno API access within the app/ directory (without running into typescript errors), a task called typegen can be run to generate the Deno specific declarations.

Closes: denoland/deno#20790

  • Docs
  • Tests

Copy link

changeset-bot bot commented Sep 2, 2024

🦋 Changeset detected

Latest commit: 3907b73

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 16 packages
Name Type
create-remix Minor
@remix-run/node Minor
@remix-run/dev Minor
@remix-run/architect Minor
@remix-run/express Minor
@remix-run/react Minor
@remix-run/serve Minor
@remix-run/testing Minor
remix Minor
@remix-run/cloudflare Minor
@remix-run/cloudflare-pages Minor
@remix-run/cloudflare-workers Minor
@remix-run/css-bundle Minor
@remix-run/deno Minor
@remix-run/eslint-config Minor
@remix-run/server-runtime Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@redabacha redabacha changed the base branch from main to dev September 2, 2024 09:23
@redabacha redabacha force-pushed the modernize-deno-template branch 3 times, most recently from 5222ff2 to 7d7761a Compare September 2, 2024 19:12
integration/helpers/vite.ts Outdated Show resolved Hide resolved
Comment on lines 28 to +33
export function installGlobals({
nativeFetch,
}: { nativeFetch?: boolean } = {}) {
if (process.versions.deno) {
return;
}
Copy link
Contributor Author

@redabacha redabacha Sep 5, 2024

Choose a reason for hiding this comment

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

making installGlobals a no-op in Deno allows the @remix-run/serve cli to work without issues

@zkdiff
Copy link

zkdiff commented Sep 25, 2024

Would you mind writing a short explanation on how to test this out locally? I'm clearly not clueing into something and I can't get this to run.

@redabacha
Copy link
Contributor Author

Would you mind writing a short explanation on how to test this out locally? I'm clearly not clueing into something and I can't get this to run.

sure no worries @zkdiff, here's some instructions.

  1. pull this branch locally and run pnpm install + pnpm run build
  2. run node packages/create-remix/dist/cli.js --template templates/deno --package-manager deno and follow the instructions
  3. create an package.json file with {} in the created directory (due to the current versions of remix requiring a package.json file for no good reason, fixed in this pr)
  4. run deno task dev to launch the dev server, or run deno task build && deno task start to launch the prod server

Comment on lines +29 to +45
"dependenciesMeta": {
"@remix-run/dev": {
"injected": true
},
"@remix-run/node": {
"injected": true
},
"@remix-run/react": {
"injected": true
},
"@remix-run/serve": {
"injected": true
},
"@remix-run/server-runtime": {
"injected": true
}
}
Copy link
Contributor Author

@redabacha redabacha Oct 9, 2024

Choose a reason for hiding this comment

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

this is necessary for deno as these packages are cjs and not esm. deno will refuse to run userland cjs code which is what happens due to the workspace dependencies in node_modules being symlinked by default with pnpm. dependenciesMeta.injected tells pnpm to install these workspace dependencies without using symlinks which convinces deno that these are npm packages (as they're now inside the node_modules folder and not symlinked out of there) and enables cjs for it.

return true;
}

async function updateDenoJSON(ctx: Context) {
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 only supports a deno.json file in a template without comments for simplicity's sake

Comment on lines +37 to +38
## Deno
deno -A npm:create-remix@latest --template remix-run/remix/templates/deno
Copy link
Contributor Author

Choose a reason for hiding this comment

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

alternatively this could be npx create-remix@latest --template remix-run/remix/templates/deno --package-manager deno, but i think using deno here makes more sense as it avoids needing another runtime + package manager just to scaffold.

Comment on lines +163 to +167
(process.versions.deno
? "deno"
: // npm, pnpm, Yarn, and Bun set the user agent environment variable that can be used
// to determine which package manager ran the command.
(process.env.npm_config_user_agent ?? "npm").split("/")[0])
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@redabacha redabacha changed the title Modernize deno template Modernize Deno template Oct 16, 2024
@aarbi
Copy link

aarbi commented Nov 16, 2024

The work here is amazing, bumping this MR up to get more eyes on it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants