diff --git a/.changesets/11337.md b/.changesets/11337.md new file mode 100644 index 000000000000..04ac9939bd34 --- /dev/null +++ b/.changesets/11337.md @@ -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. diff --git a/packages/prerender/.babelrc.js b/packages/prerender/.babelrc.js deleted file mode 100644 index 3b2c815712d9..000000000000 --- a/packages/prerender/.babelrc.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = { extends: '../../babel.config.js' } diff --git a/packages/prerender/browserUtils/index.js b/packages/prerender/browserUtils/index.js deleted file mode 100644 index ab5b0031e224..000000000000 --- a/packages/prerender/browserUtils/index.js +++ /dev/null @@ -1,2 +0,0 @@ -/* eslint-env es6, commonjs */ -module.exports = require('../dist/browserUtils') diff --git a/packages/prerender/browserUtils/package.json b/packages/prerender/browserUtils/package.json deleted file mode 100644 index 9ad9aacba267..000000000000 --- a/packages/prerender/browserUtils/package.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "main": "./index.js", - "types": "../dist/browserUtils/index.d.ts" -} diff --git a/packages/prerender/build.mts b/packages/prerender/build.mts new file mode 100644 index 000000000000..16175a6725c0 --- /dev/null +++ b/packages/prerender/build.mts @@ -0,0 +1,3 @@ +import { build } from '@redwoodjs/framework-tools' + +await build() diff --git a/packages/prerender/detection/index.js b/packages/prerender/detection/index.js deleted file mode 100644 index ba249a1a85b6..000000000000 --- a/packages/prerender/detection/index.js +++ /dev/null @@ -1,2 +0,0 @@ -/* eslint-env es6, commonjs */ -module.exports = require('../dist/detection') diff --git a/packages/prerender/detection/package.json b/packages/prerender/detection/package.json deleted file mode 100644 index 5e55a1e86633..000000000000 --- a/packages/prerender/detection/package.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "main": "./index.js" -} diff --git a/packages/prerender/package.json b/packages/prerender/package.json index fd798f21f1d9..6790b9328e2c 100644 --- a/packages/prerender/package.json +++ b/packages/prerender/package.json @@ -8,24 +8,39 @@ "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:*", @@ -33,15 +48,16 @@ "@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" }, diff --git a/packages/prerender/tsconfig.build.json b/packages/prerender/tsconfig.build.json new file mode 100644 index 000000000000..89552aaef821 --- /dev/null +++ b/packages/prerender/tsconfig.build.json @@ -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" } + ] +} diff --git a/packages/prerender/tsconfig.json b/packages/prerender/tsconfig.json index 78d1d766d16e..8bf851c890fc 100644 --- a/packages/prerender/tsconfig.json +++ b/packages/prerender/tsconfig.json @@ -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"] } diff --git a/yarn.lock b/yarn.lock index 8eb78a224489..fc08d137fb29 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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:*" @@ -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: