Skip to content

Commit 93b04f8

Browse files
authored
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
1 parent 6fbc5b8 commit 93b04f8

20 files changed

+385
-349
lines changed

.github/workflows/ci.yml

+25-1
Original file line numberDiff line numberDiff line change
@@ -750,11 +750,13 @@ jobs:
750750
env:
751751
PROJECT_PATH: ${{ env.PROJECT_PATH }}
752752

753-
- name: Prompt tests
753+
- name: Install expect
754754
run: |
755755
sudo apt-get update
756756
sudo apt-get install expect
757757
758+
- name: Prompt tests
759+
run: |
758760
./tests/e2e_prompts.sh
759761
./tests/e2e_prompts_git.sh
760762
./tests/e2e_prompts_m.sh
@@ -764,6 +766,28 @@ jobs:
764766
env:
765767
PROJECT_PATH: ${{ env.PROJECT_PATH }}
766768

769+
- name: ⬢ Set up Node.js
770+
uses: actions/setup-node@v4
771+
with:
772+
node-version: 18
773+
774+
- name: Prompt tests
775+
run: ./tests/e2e_prompts_node_less.sh
776+
working-directory: ./packages/create-redwood-app
777+
env:
778+
PROJECT_PATH: ${{ env.PROJECT_PATH }}
779+
780+
- name: ⬢ Set up Node.js
781+
uses: actions/setup-node@v4
782+
with:
783+
node-version: 21
784+
785+
- name: Prompt tests
786+
run: ./tests/e2e_prompts_node_greater.sh
787+
working-directory: ./packages/create-redwood-app
788+
env:
789+
PROJECT_PATH: ${{ env.PROJECT_PATH }}
790+
767791
crwa-skip:
768792
needs: detect-changes
769793
if: needs.detect-changes.outputs.onlydocs == 'true'

packages/create-redwood-app/README.md

+31-41
Original file line numberDiff line numberDiff line change
@@ -18,39 +18,35 @@
1818

1919
<h2 align="center">Ship today with architecture for tomorrow.</h2>
2020

21-
Redwood is an opinionated, edge-ready framework for modern multi-client applications, built on React, GraphQL, and Prisma with full TypeScript support and ready to go with zero config.
21+
Redwood is an opinionated framework for modern multi-client applications, built on React, GraphQL, and Prisma with full TypeScript support and ready to go with zero config.
2222

2323
Want great developer experience and easy scaling? How about an integrated front- and back-end test suite, boilerplate code generators, component design, logging, API security + auth, and serverless or traditional deploy support? Redwood is here! Redwood works with the components and development workflow you love but with simple conventions and helpers to make your experience even better.
2424

25-
<br>
26-
2725
<h2>Quick Start</h2>
2826

29-
Redwood requires Node.js >=14.x <=16.x and Yarn v1.15 (or newer).
30-
```console
31-
yarn create redwood-app redwood-project
32-
cd redwood-project
27+
Redwood requires Node.js =20.x.
28+
29+
```bash
30+
yarn create redwood-app my-redwood-app
31+
cd my-redwood-app
32+
yarn install
3333
yarn redwood dev
3434
```
3535

3636
<h3>Resources</h3>
3737

38-
- The [Redwood Tutorial](https://redwoodjs.com/docs/tutorial): The best way to learn Redwood
38+
- The [Redwood Tutorial](https://redwoodjs.com/docs/tutorial): the best way to learn Redwood
3939
- The [Redwood CLI](https://redwoodjs.com/docs/cli-commands): code generators, DB helpers, setup commands, and more
4040
- [Documentation](https://redwoodjs.com/docs) and [How To's](https://redwoodjs.com/how-to/custom-function)
4141
- Join the Community [Forums](https://community.redwoodjs.com) and [Chat](https://discord.gg/redwoodjs)
4242

43-
<br>
44-
45-
<h1>Contributing to create-redwood-app</h1>
43+
<h2>Contributing to create-redwood-app</h2>
4644

47-
_Contributors are Welcome! Get started [here](https://redwoodjs.com/docs/contributing). And don't hesitate to ask for help on the forums and chat_
45+
_Contributors are Welcome! Get started [here](https://redwoodjs.com/docs/contributing). And don't hesitate to ask for help on the forums and chat_.
4846

4947
**Table of Contents**
5048
<!-- toc -->
5149
- [Description](#description)
52-
- [Package Leads](#package-leads)
53-
- [Roadmap](#roadmap)
5450
- [Local Development](#local-development)
5551
- [Installation Script](#installation-script)
5652
- [Template Codebase](#template-codebase)
@@ -60,55 +56,45 @@ _Contributors are Welcome! Get started [here](https://redwoodjs.com/docs/contrib
6056
## Description
6157

6258
This package creates and installs a Redwood project, which is the entry point for anyone using Redwood. It has two parts:
63-
- The installation script `create-redwood-app.js`
64-
- Project template code in the `template/` directory
65-
66-
> _For information about contributing to the Redwood Framework in general, [please start here](https://redwoodjs.com/docs/contributing)._
67-
68-
## Package Leads
69-
- [@peterp](https://github.com/peterp)
70-
- [@thedavidprice](https://github.com/thedavidprice)
71-
72-
## Roadmap
73-
74-
v1 Priorities:
75-
- convert `template/` codebase to TypeScript
76-
- add option to install as either TypeScript or JavaScript project (defaults to TypeScript)
77-
- add package tests, which may be accomplished by including in Cypress E2E CI
59+
- The installation script [`src/create-redwood-app.js`](./src/create-redwood-app.js)
60+
- Project template code in the [`templates/`](./templates/) directory
7861

7962
## Local Development
8063

8164
### Installation Script
82-
The installation script is built with [Yargs](https://github.com/yargs/yargs)
65+
66+
The installation script is built with [Yargs](https://github.com/yargs/yargs).
8367

8468
### Template Codebase
85-
The project codebase in `template/` uses [Yarn Workspace v1](https://classic.yarnpkg.com/en/docs/workspaces/) for a monorepo project containing the API and Web Sides. Redwood packages are included in `template/package.json`, `template/web/package.json`, and `template/api/package.json`, respectively.
8669

87-
### How to run create-redwood-app from your local repo and create a project
70+
The project codebase in [`templates/`](./templates/) uses [Yarn Workspaces](https://yarnpkg.com/features/workspaces) for a monorepo project containing the API and Web Sides. Redwood packages are included in `templates/ts/package.json`, `templates/ts/web/package.json`, and `templates/ts/api/package.json`, respectively.
71+
72+
### How to run `create-redwood-app` from your local repo and create a project
73+
8874
First, run the following commands in the root of the monorepo:
75+
8976
```bash
9077
yarn install
9178
yarn build
9279
```
9380

94-
Then, we need to navigate to the create redwood app package and build the script:
81+
Then, navigate to the create redwood app package:
82+
9583
```bash
9684
cd packages/create-redwood-app
97-
yarn build
9885
```
9986

100-
_Note:_ You can also use `yarn build:watch` instead of `yarn build` to watch for changes and rebuild automatically.
101-
102-
This will generate the `create-redwood-app.js` file inside the `dist` directory.
87+
Run `yarn node` on the built file (`dist/create-redwood-app.js`) and pass in the path to the new project:
10388

104-
To use the script, run `node` on that file (dist/create-redwood-app.js) and pass in the path to the new project:
10589
```bash
106-
node dist/create-redwood-app.js /path/to/new/redwood-app
90+
yarn node ./dist/create-redwood-app.js /path/to/new/redwood-app
10791
```
10892

109-
> Note: the new project will install with the most recent major Redwood package version by default
93+
> [!NOTE]
94+
> the new project will install with the most recent major Redwood package version by default.
11095
11196
### How to run other published versions for debugging
97+
11298
By default yarn create will pick the latest stable version to run, but you can specify a different version via yarn too!
11399

114100
To try the canary version, run:
@@ -121,12 +107,16 @@ Note that this will still create a project with the latest stable version, but r
121107
You can specify any tag or version instead of `@canary`
122108

123109
### Develop using the new project
110+
124111
There are three options for developing with the installed project:
125112

126113
**1. Upgrade the project to use the latest canary release**
114+
127115
```bash
128116
cd /path/to/new/redwood-app
129117
yarn rw upgrade -t canary
130118
```
119+
131120
**2. Use the workflow and tools for local package development**
132-
- [Local Development Instructions](https://github.com/redwoodjs/redwood/blob/main/CONTRIBUTING.md#local-development)
121+
122+
- [Local Development Instructions](https://github.com/redwoodjs/redwood/blob/main/CONTRIBUTING.md)

packages/create-redwood-app/build.mjs

-23
This file was deleted.
+1-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
/** @type {import('jest').Config} */
2-
const config = {
3-
testMatch: ['<rootDir>/tests/*.test.mjs'],
2+
export default {
43
testPathIgnorePatterns: ['/node_modules/', '<rootDir>/templates/'],
54
transform: {},
65
}
7-
8-
module.exports = config

packages/create-redwood-app/package.json

+11-12
Original file line numberDiff line numberDiff line change
@@ -7,48 +7,47 @@
77
"directory": "packages/create-redwood-app"
88
},
99
"license": "MIT",
10+
"type": "module",
1011
"bin": "./dist/create-redwood-app.js",
1112
"files": [
1213
"dist",
1314
"templates"
1415
],
1516
"scripts": {
16-
"build": "yarn node ./build.mjs",
17+
"build": "node ./scripts/build.js",
1718
"build:pack": "yarn pack -o create-redwood-app.tgz",
1819
"build:watch": "nodemon --watch src --ignore dist,template --exec \"yarn build\"",
1920
"prepublishOnly": "NODE_ENV=production yarn build",
20-
"set-up-test-project": "node ./scripts/setUpTestProject.mjs",
21+
"set-up-test-project": "node ./scripts/setUpTestProject.js",
2122
"test": "node --experimental-vm-modules $(yarn bin jest) templates",
2223
"test:e2e": "node --experimental-vm-modules $(yarn bin jest) e2e",
23-
"ts-to-js": "yarn node ./scripts/tsToJS.mjs"
24+
"ts-to-js": "yarn node ./scripts/tsToJS.js"
2425
},
25-
"dependencies": {
26+
"devDependencies": {
27+
"@babel/core": "^7.22.20",
28+
"@babel/plugin-transform-typescript": "^7.22.15",
2629
"@opentelemetry/api": "1.7.0",
2730
"@opentelemetry/exporter-trace-otlp-http": "0.45.1",
2831
"@opentelemetry/resources": "1.18.1",
2932
"@opentelemetry/sdk-trace-node": "1.18.1",
3033
"@opentelemetry/semantic-conventions": "1.18.1",
3134
"@redwoodjs/tui": "6.0.7",
35+
"@types/babel__core": "7.20.4",
3236
"chalk": "4.1.2",
3337
"check-node-version": "4.2.1",
3438
"ci-info": "4.0.0",
3539
"envinfo": "7.11.0",
40+
"esbuild": "0.19.9",
3641
"execa": "5.1.1",
3742
"fs-extra": "11.2.0",
43+
"jest": "29.7.0",
44+
"klaw-sync": "6.0.0",
3845
"semver": "7.5.4",
3946
"systeminformation": "5.21.20",
4047
"terminal-link": "2.1.1",
4148
"untildify": "4.0.0",
4249
"uuid": "9.0.1",
4350
"yargs": "17.7.2"
4451
},
45-
"devDependencies": {
46-
"@babel/core": "^7.22.20",
47-
"@babel/plugin-transform-typescript": "^7.22.15",
48-
"@types/babel__core": "7.20.4",
49-
"esbuild": "0.19.9",
50-
"jest": "29.7.0",
51-
"klaw-sync": "6.0.0"
52-
},
5352
"gitHead": "3905ed045508b861b495f8d5630d76c7a157d8f1"
5453
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/* eslint-env node */
2+
3+
import * as esbuild from 'esbuild'
4+
import fs from 'fs-extra'
5+
6+
const jsBanner = `\
7+
#!/usr/bin/env node
8+
9+
const require = (await import("node:module")).createRequire(import.meta.url);
10+
const __filename = (await import("node:url")).fileURLToPath(import.meta.url);
11+
const __dirname = (await import("node:path")).dirname(__filename);
12+
`
13+
14+
const result = await esbuild.build({
15+
entryPoints: ['src/create-redwood-app.js'],
16+
outdir: 'dist',
17+
18+
platform: 'node',
19+
target: ['node20'],
20+
format: 'esm',
21+
bundle: true,
22+
banner: {
23+
js: jsBanner,
24+
},
25+
26+
minify: true,
27+
28+
logLevel: 'info',
29+
metafile: true,
30+
})
31+
32+
await fs.writeJSON(new URL('./meta.json', import.meta.url), result.metafile, {
33+
spaces: 2,
34+
})

0 commit comments

Comments
 (0)