diff --git a/.gitignore b/.gitignore index 64a1d279ec12..f25523693531 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,6 @@ blog-test-project/* .pnp.* *.code-workspace .nova + +# For esbuild. +**/meta.json diff --git a/packages/create-redwood-app/.babelrc.js b/packages/create-redwood-app/.babelrc.js deleted file mode 100644 index 3b2c815712d9..000000000000 --- a/packages/create-redwood-app/.babelrc.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = { extends: '../../babel.config.js' } diff --git a/packages/create-redwood-app/build.mjs b/packages/create-redwood-app/build.mjs new file mode 100644 index 000000000000..9fbf8d0a0ab9 --- /dev/null +++ b/packages/create-redwood-app/build.mjs @@ -0,0 +1,24 @@ +import fs from 'node:fs' + +import * as esbuild from 'esbuild' + +// There's minimal bundling going on here by design. Only "src/create-redwood-app.js" and "src/telemetry.js" +// are bundled into a single "dist/create-redwood-app.js" file. +// As we audit more of this package's dependencies, we'll remove them from a handcrafted "external" list, +// instead of using the catch-all `packages: 'external'` option. +const result = await esbuild.build({ + entryPoints: ['src/create-redwood-app.js'], + bundle: true, + platform: 'node', + target: ['node18'], + // See https://esbuild.github.io/getting-started/#bundling-for-node. + packages: 'external', + outfile: 'dist/create-redwood-app.js', + minify: true, + + // For visualizing the bundle. + // See https://esbuild.github.io/api/#metafile and https://esbuild.github.io/analyze/. + metafile: true, +}) + +fs.writeFileSync('meta.json', JSON.stringify(result.metafile)) diff --git a/packages/create-redwood-app/jest.config.js b/packages/create-redwood-app/jest.config.js deleted file mode 100644 index 7ff8f7d4bdf5..000000000000 --- a/packages/create-redwood-app/jest.config.js +++ /dev/null @@ -1,9 +0,0 @@ -/** @type {import('@jest/types').Config.InitialOptions} */ -module.exports = { - testMatch: ['**/__tests__/**/*.[jt]s?(x)', '**/*.test.[jt]s?(x)'], - testPathIgnorePatterns: ['fixtures', 'api/src', 'web/src'], - moduleNameMapper: { - '^src/(.*)': '/src/$1', - }, - testTimeout: 15000, -} diff --git a/packages/create-redwood-app/package.json b/packages/create-redwood-app/package.json index 2c1bcca90111..ac2eafe9b957 100644 --- a/packages/create-redwood-app/package.json +++ b/packages/create-redwood-app/package.json @@ -13,15 +13,11 @@ "template" ], "scripts": { - "build": "yarn build:js", - "build:js": "babel src -d dist", + "build": "yarn node ./build.mjs", "build:watch": "nodemon --watch src --ignore dist,template --exec \"yarn build\"", - "prepublishOnly": "NODE_ENV=production yarn build", - "test": "jest src", - "test:watch": "yarn test --watch" + "prepublishOnly": "NODE_ENV=production yarn build" }, "dependencies": { - "@babel/runtime-corejs3": "7.21.0", "@opentelemetry/api": "1.4.1", "@opentelemetry/exporter-trace-otlp-http": "0.37.0", "@opentelemetry/resources": "1.11.0", @@ -31,7 +27,6 @@ "chalk": "4.1.2", "check-node-version": "4.2.1", "ci-info": "3.8.0", - "core-js": "3.30.0", "envinfo": "7.8.1", "execa": "5.1.1", "fs-extra": "11.1.1", @@ -40,9 +35,7 @@ "yargs": "17.7.1" }, "devDependencies": { - "@babel/cli": "7.21.0", - "@babel/node": "7.20.7", - "jest": "29.5.0" + "esbuild": "0.17.15" }, "gitHead": "3905ed045508b861b495f8d5630d76c7a157d8f1" } diff --git a/packages/create-redwood-app/src/__tests__/web-template.test.js b/packages/create-redwood-app/src/__tests__/web-template.test.js deleted file mode 100644 index 06c4fc340247..000000000000 --- a/packages/create-redwood-app/src/__tests__/web-template.test.js +++ /dev/null @@ -1,14 +0,0 @@ -import fs from 'fs' -import path from 'path' - -test('Web/src/App should contain App', () => { - // This test is here to ensure we don't accidentally break auth setup commands - // They rely on the presence of certain strings, so if we change them - // packages/cli/src/commands/setup/auth/auth.js should also be changed - - const indexContent = fs - .readFileSync(path.join(__dirname, '../../template/web/src/App.tsx')) - .toString() - - expect(indexContent).toContain('const App = () => (') -}) diff --git a/packages/tui/.babelrc.js b/packages/tui/.babelrc.js deleted file mode 100644 index 3b2c815712d9..000000000000 --- a/packages/tui/.babelrc.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = { extends: '../../babel.config.js' } diff --git a/packages/tui/build.mjs b/packages/tui/build.mjs new file mode 100644 index 000000000000..e03cfb6f86b4 --- /dev/null +++ b/packages/tui/build.mjs @@ -0,0 +1,19 @@ +import fs from 'node:fs' + +import * as esbuild from 'esbuild' + +// Since this is a library, there's no bundling going on here by design. +// Instead we plan for this library to be bundled by leaf packages so-to-speak like create-redwood-app. +const result = await esbuild.build({ + entryPoints: ['src/index.ts'], + format: 'cjs', + platform: 'node', + target: ['node18'], + outfile: 'dist/index.js', + + // For visualizing the bundle. + // See https://esbuild.github.io/api/#metafile and https://esbuild.github.io/analyze/. + metafile: true, +}) + +fs.writeFileSync('meta.json', JSON.stringify(result.metafile)) diff --git a/packages/tui/package.json b/packages/tui/package.json index 4daa004c9e45..6ba9bfe1a775 100644 --- a/packages/tui/package.json +++ b/packages/tui/package.json @@ -13,8 +13,7 @@ "dist" ], "scripts": { - "build": "yarn build:js && yarn build:types", - "build:js": "babel src -d dist --extensions \".js,.ts,.tsx\"", + "build": "yarn node ./build.mjs && yarn build:types", "build:types": "tsc --build --verbose", "build:watch": "nodemon --watch src --ext \"js,ts,tsx\" --ignore dist --exec \"yarn build\"", "prepublishOnly": "NODE_ENV=production yarn build", @@ -28,16 +27,13 @@ }, "gitHead": "3905ed045508b861b495f8d5630d76c7a157d8f1", "dependencies": { - "@babel/runtime-corejs3": "7.21.0", "boxen": "5.1.2", "chalk": "4.1.2", - "core-js": "3.30.0", "enquirer": "2.3.6", "stdout-update": "1.6.8" }, "devDependencies": { - "@babel/cli": "7.21.0", - "@babel/core": "7.21.3", + "esbuild": "0.17.15", "jest": "29.5.0", "typescript": "5.0.3" } diff --git a/tasks/run-e2e b/tasks/run-e2e index 1f13dbb4b05b..d1eb7cef73bf 100755 --- a/tasks/run-e2e +++ b/tasks/run-e2e @@ -52,7 +52,7 @@ const buildRedwoodFramework = () => { const createRedwoodJSApp = ({ yarn1 }) => { try { execa.sync( - 'yarn babel-node src/create-redwood-app.js', + 'yarn node dist/create-redwood-app.js', [ REDWOOD_PROJECT_DIRECTORY, '--no-yarn-install', diff --git a/yarn.lock b/yarn.lock index b9e76c3d6d8a..1c503e44dc02 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7319,13 +7319,10 @@ __metadata: version: 0.0.0-use.local resolution: "@redwoodjs/tui@workspace:packages/tui" dependencies: - "@babel/cli": 7.21.0 - "@babel/core": 7.21.3 - "@babel/runtime-corejs3": 7.21.0 boxen: 5.1.2 chalk: 4.1.2 - core-js: 3.30.0 enquirer: 2.3.6 + esbuild: 0.17.15 jest: 29.5.0 stdout-update: 1.6.8 typescript: 5.0.3 @@ -14430,9 +14427,6 @@ __metadata: version: 0.0.0-use.local resolution: "create-redwood-app@workspace:packages/create-redwood-app" dependencies: - "@babel/cli": 7.21.0 - "@babel/node": 7.20.7 - "@babel/runtime-corejs3": 7.21.0 "@opentelemetry/api": 1.4.1 "@opentelemetry/exporter-trace-otlp-http": 0.37.0 "@opentelemetry/resources": 1.11.0 @@ -14442,11 +14436,10 @@ __metadata: chalk: 4.1.2 check-node-version: 4.2.1 ci-info: 3.8.0 - core-js: 3.30.0 envinfo: 7.8.1 + esbuild: 0.17.15 execa: 5.1.1 fs-extra: 11.1.1 - jest: 29.5.0 systeminformation: 5.17.12 terminal-link: 2.1.1 yargs: 17.7.1