Skip to content

Commit

Permalink
refactor(prerender): build with esbuild and introduce conditional exp…
Browse files Browse the repository at this point in the history
…orts (#11337)

Switches the prerender package to be built with esbuild rather than
babel.

This change doesn't not use module or moduleResolution Node16 in the
build version of the tsconfig. This is because it would pick up cjs/esm
issues with apollo and vite. I will look to follow up with fixes that
can enable us to use the modern settings in the build version also.
  • Loading branch information
Josh-Walker-GM committed Aug 22, 2024
1 parent 68b37fa commit b544605
Show file tree
Hide file tree
Showing 11 changed files with 64 additions and 35 deletions.
3 changes: 3 additions & 0 deletions .changesets/11337.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- refactor(prerender): build with esbuild and introduce conditional exports (#11337) by @Josh-Walker-GM

This change restricts the available imports from the `@redwoodjs/prerender` package. You will also have to use modern `moduleResolution` settings in your tsconfig to resolve the imports correctly within TS.
1 change: 0 additions & 1 deletion packages/prerender/.babelrc.js

This file was deleted.

2 changes: 0 additions & 2 deletions packages/prerender/browserUtils/index.js

This file was deleted.

4 changes: 0 additions & 4 deletions packages/prerender/browserUtils/package.json

This file was deleted.

3 changes: 3 additions & 0 deletions packages/prerender/build.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { build } from '@redwoodjs/framework-tools'

await build()
2 changes: 0 additions & 2 deletions packages/prerender/detection/index.js

This file was deleted.

3 changes: 0 additions & 3 deletions packages/prerender/detection/package.json

This file was deleted.

36 changes: 26 additions & 10 deletions packages/prerender/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,40 +8,56 @@
"directory": "packages/prerender"
},
"license": "MIT",
"type": "commonjs",
"exports": {
".": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
},
"./browserUtils": {
"types": "./dist/browserUtils/index.d.ts",
"default": "./dist/browserUtils/index.js"
},
"./detection": {
"types": "./dist/detection/index.d.ts",
"default": "./dist/detection/index.js"
}
},
"main": "dist/index.js",
"types": "./dist/index.d.ts",
"files": [
"dist",
"browserUtils",
"detection"
"dist"
],
"scripts": {
"build": "yarn build:js && yarn build:types",
"build:js": "babel src -d dist --extensions \".js,.jsx,.ts,.tsx,.jsx\"",
"build": "tsx ./build.mts && yarn build:types",
"build:pack": "yarn pack -o redwoodjs-prerender.tgz",
"build:types": "tsc --build --verbose",
"build:types": "tsc --build --verbose ./tsconfig.build.json",
"build:watch": "nodemon --watch src --ext \"js,jsx,ts,tsx,template\" --ignore dist --exec \"yarn build\"",
"check:attw": "yarn rw-fwtools-attw",
"check:package": "concurrently npm:check:attw yarn:publint",
"prepublishOnly": "yarn build",
"test": "vitest run",
"test:watch": "vitest watch"
},
"dependencies": {
"@babel/runtime-corejs3": "7.25.0",
"@redwoodjs/babel-config": "workspace:*",
"@redwoodjs/project-config": "workspace:*",
"@redwoodjs/router": "workspace:*",
"@redwoodjs/structure": "workspace:*",
"@redwoodjs/web": "workspace:*",
"@whatwg-node/fetch": "0.9.20",
"babel-plugin-ignore-html-and-css-imports": "0.1.0",
"cheerio": "1.0.0",
"core-js": "3.38.0",
"graphql": "16.9.0",
"mime-types": "2.1.35"
},
"devDependencies": {
"@babel/cli": "7.24.8",
"@babel/core": "^7.22.20",
"@redwoodjs/framework-tools": "workspace:*",
"@types/mime-types": "2.1.4",
"babel-plugin-tester": "11.0.4",
"concurrently": "8.2.2",
"publint": "0.2.10",
"tsx": "4.17.0",
"typescript": "5.5.4",
"vitest": "2.0.5"
},
Expand Down
17 changes: 17 additions & 0 deletions packages/prerender/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"extends": "../../tsconfig.compilerOption.json",
"compilerOptions": {
"rootDir": "src",
"outDir": "dist",
"allowJs": true
},
"include": ["./src/**/*", "ambient.d.ts"],
"references": [
{ "path": "../babel-config" },
{ "path": "../project-config" },
{ "path": "../router/tsconfig.build.json" },
{ "path": "../structure" },
{ "path": "../web/tsconfig.build.json" },
{ "path": "../framework-tools" }
]
}
19 changes: 10 additions & 9 deletions packages/prerender/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
{
"extends": "../../tsconfig.compilerOption.json",
"compilerOptions": {
"rootDir": "src",
"outDir": "dist",
"module": "Node16",
"moduleResolution": "Node16",
"allowJs": true
},
"include": ["./src/**/*", "ambient.d.ts"],
"include": ["."],
"references": [
{ "path": "../web/tsconfig.build.json" },
{ "path": "../router/tsconfig.build.json" },
{ "path": "../internal" },
{ "path": "../babel-config" },
{ "path": "../project-config" },
{ "path": "../auth/tsconfig.build.json" },
{ "path": "../structure" }
]
{ "path": "../router/tsconfig.build.json" },
{ "path": "../structure" },
{ "path": "../web/tsconfig.build.json" },
{ "path": "../framework-tools" }
],
"exclude": ["dist", "node_modules", "**/__mocks__", "**/__tests__/fixtures"]
}
9 changes: 5 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8458,9 +8458,8 @@ __metadata:
version: 0.0.0-use.local
resolution: "@redwoodjs/prerender@workspace:packages/prerender"
dependencies:
"@babel/cli": "npm:7.24.8"
"@babel/core": "npm:^7.22.20"
"@babel/runtime-corejs3": "npm:7.25.0"
"@redwoodjs/babel-config": "workspace:*"
"@redwoodjs/framework-tools": "workspace:*"
"@redwoodjs/project-config": "workspace:*"
"@redwoodjs/router": "workspace:*"
"@redwoodjs/structure": "workspace:*"
Expand All @@ -8470,9 +8469,11 @@ __metadata:
babel-plugin-ignore-html-and-css-imports: "npm:0.1.0"
babel-plugin-tester: "npm:11.0.4"
cheerio: "npm:1.0.0"
core-js: "npm:3.38.0"
concurrently: "npm:8.2.2"
graphql: "npm:16.9.0"
mime-types: "npm:2.1.35"
publint: "npm:0.2.10"
tsx: "npm:4.17.0"
typescript: "npm:5.5.4"
vitest: "npm:2.0.5"
peerDependencies:
Expand Down

0 comments on commit b544605

Please sign in to comment.