-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(esm): convert crwa to esm and bundle (#9786)
Follow up to #9783. This PR converts the `create-redwood-app` package to ESM and bundles all its dependencies. I started with `create-redwood-app` because the requirements for making it ESM were relatively trivial compared to the other packages since it just needs to be run by `yarn create`, and yarn create just runs a bin. For `create-redwood-app` I'm just using esbuild. Why not use tsup? 1. We're just distributing a bin. We're not distributing a dual-module package with types 2. tsup hasn't been committed to in over a month and a half, whereas esbuild releases often and is committed to more-or-less daily. That doesn't automatically disqualify it (OSS is hard), but makes me wary. I'll consider it for packages that distribute more than a bin More on bundling. Bundling this package has benefits, namely decreasing the install time—yarn doesn't have to fetch its dependencies, there are none. But I'm mostly doing it as an exercise because we need to do it more. For background on the shims (`jsBanner`) see evanw/esbuild#1921. It's nothing bespoke and it's what tsup[^tsup] and Vite[^vite] would've done anyway. Other notes: - Updates the package's `README.md`; this could be updated more but I didn't want to spend too much time on it - Adds e2e tests for the node version check Two new e2e tests make sure we're checking node version correctly. I can't use nvm since 1. it's not easily scriptable (it's a shell built-in or something) and 2. it doesn't seem like we all use it, so I just added these tests to CI and use the GitHub action to change the node version - Fixes a bug I introduced in #9728 The node version check would throw if it didn't pass because `engines.yarn` was removed. This wasn't released - Converted files to just `.js` since Node recognized them as ESM from `type` in `package.json` - Reordered `yarn create-redwood-app`'s options in help; I tried to put the ones that were more likely to be used first - Removed the header from `--help` and `--version` [^tsup]: https://github.com/egoist/tsup/blob/8c26e63c92711d60c05aedd3cdc358530ba266c5/assets/esm_shims.js [^vite]: https://github.com/vitejs/vite/blob/8de7bd2b68db27b83d9484cc8d4e26436615168e/packages/vite/rollup.config.ts#L288-L295
- Loading branch information
Showing
20 changed files
with
385 additions
and
349 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,5 @@ | ||
/** @type {import('jest').Config} */ | ||
const config = { | ||
testMatch: ['<rootDir>/tests/*.test.mjs'], | ||
export default { | ||
testPathIgnorePatterns: ['/node_modules/', '<rootDir>/templates/'], | ||
transform: {}, | ||
} | ||
|
||
module.exports = config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* eslint-env node */ | ||
|
||
import * as esbuild from 'esbuild' | ||
import fs from 'fs-extra' | ||
|
||
const jsBanner = `\ | ||
#!/usr/bin/env node | ||
const require = (await import("node:module")).createRequire(import.meta.url); | ||
const __filename = (await import("node:url")).fileURLToPath(import.meta.url); | ||
const __dirname = (await import("node:path")).dirname(__filename); | ||
` | ||
|
||
const result = await esbuild.build({ | ||
entryPoints: ['src/create-redwood-app.js'], | ||
outdir: 'dist', | ||
|
||
platform: 'node', | ||
target: ['node20'], | ||
format: 'esm', | ||
bundle: true, | ||
banner: { | ||
js: jsBanner, | ||
}, | ||
|
||
minify: true, | ||
|
||
logLevel: 'info', | ||
metafile: true, | ||
}) | ||
|
||
await fs.writeJSON(new URL('./meta.json', import.meta.url), result.metafile, { | ||
spaces: 2, | ||
}) |
File renamed without changes.
Oops, something went wrong.