From 2d5924f567f35fe1aec13165d8a8c601bddf5bd9 Mon Sep 17 00:00:00 2001 From: Jacob Ebey Date: Wed, 23 Oct 2024 13:37:55 -0700 Subject: [PATCH] feat: configure export conditions properly (#12136) feat: nuke rollup into oblivion in favor of tsup feat: add ESM build for architect, express and node packages chore: update HMR test to ignore warning log feat: add module-sync export condition fix: react-router should not reference itself, that's weird (use tsconfig paths) chore: update e2e test warning assertion chore: add vite ignore comment for dynamic import fix: update optimizeDeps chore: add wireit for caching chore: add cache to workflows --------- Co-authored-by: Matt Brophy --- .github/workflows/shared-build.yml | 2 + .github/workflows/shared-integration.yml | 2 + .github/workflows/test.yml | 2 + .gitignore | 1 + build.utils.ts | 12 + integration/helpers/playwright-fixture.ts | 6 +- integration/vite-spa-mode-test.ts | 11 +- package.json | 10 +- packages/react-router-architect/package.json | 35 +- .../react-router-architect/rollup.config.js | 56 - .../react-router-architect/tsup.config.ts | 21 + packages/react-router-cloudflare/package.json | 32 +- .../react-router-cloudflare/rollup.config.js | 55 - .../react-router-cloudflare/tsup.config.ts | 21 + packages/react-router-dev/config/routes.ts | 10 +- packages/react-router-dev/package.json | 23 +- packages/react-router-dev/rollup.config.js | 78 -- packages/react-router-dev/tsup.config.ts | 53 + packages/react-router-dev/vite/plugin.ts | 4 +- packages/react-router-dom/node-main.js | 7 - packages/react-router-dom/package.json | 37 +- packages/react-router-dom/rollup.config.js | 223 --- packages/react-router-dom/tsup.config.ts | 21 + packages/react-router-express/package.json | 34 +- .../react-router-express/rollup.config.js | 55 - packages/react-router-express/tsup.config.ts | 21 + packages/react-router-fs-routes/package.json | 19 +- .../react-router-fs-routes/rollup.config.js | 55 - .../react-router-fs-routes/tsup.config.ts | 21 + packages/react-router-node/package.json | 52 +- packages/react-router-node/rollup.config.js | 55 - packages/react-router-node/tsconfig.json | 2 + packages/react-router-node/tsup.config.ts | 21 + .../package.json | 19 +- .../rollup.config.js | 55 - .../tsup.config.ts | 21 + packages/react-router-serve/package.json | 21 +- packages/react-router-serve/rollup.config.js | 63 - packages/react-router-serve/tsup.config.ts | 21 + .../{dom-export.tsx => dom-export.ts} | 0 packages/react-router/index.ts | 2 +- .../lib/dom-export/dom-router-provider.tsx | 2 - packages/react-router/lib/dom/lib.tsx | 7 +- packages/react-router/lib/dom/ssr/data.ts | 3 +- .../react-router/lib/dom/ssr/routeModules.ts | 8 +- packages/react-router/package.json | 60 +- packages/react-router/rollup.config.js | 468 ------- packages/react-router/tsconfig.json | 7 +- packages/react-router/tsup.config.ts | 44 + pnpm-lock.yaml | 1213 ++++++++++++----- 50 files changed, 1481 insertions(+), 1590 deletions(-) create mode 100644 build.utils.ts delete mode 100644 packages/react-router-architect/rollup.config.js create mode 100644 packages/react-router-architect/tsup.config.ts delete mode 100644 packages/react-router-cloudflare/rollup.config.js create mode 100644 packages/react-router-cloudflare/tsup.config.ts delete mode 100644 packages/react-router-dev/rollup.config.js create mode 100644 packages/react-router-dev/tsup.config.ts delete mode 100644 packages/react-router-dom/node-main.js delete mode 100644 packages/react-router-dom/rollup.config.js create mode 100644 packages/react-router-dom/tsup.config.ts delete mode 100644 packages/react-router-express/rollup.config.js create mode 100644 packages/react-router-express/tsup.config.ts delete mode 100644 packages/react-router-fs-routes/rollup.config.js create mode 100644 packages/react-router-fs-routes/tsup.config.ts delete mode 100644 packages/react-router-node/rollup.config.js create mode 100644 packages/react-router-node/tsup.config.ts delete mode 100644 packages/react-router-remix-config-routes-adapter/rollup.config.js create mode 100644 packages/react-router-remix-config-routes-adapter/tsup.config.ts delete mode 100644 packages/react-router-serve/rollup.config.js create mode 100644 packages/react-router-serve/tsup.config.ts rename packages/react-router/{dom-export.tsx => dom-export.ts} (100%) delete mode 100644 packages/react-router/rollup.config.js create mode 100644 packages/react-router/tsup.config.ts diff --git a/.github/workflows/shared-build.yml b/.github/workflows/shared-build.yml index 0a38fe9d0..7c34bfe08 100644 --- a/.github/workflows/shared-build.yml +++ b/.github/workflows/shared-build.yml @@ -22,6 +22,8 @@ jobs: node-version-file: ".nvmrc" cache: "pnpm" + - uses: google/wireit@setup-github-actions-caching/v2 + - name: Disable GitHub Actions Annotations run: | echo "::remove-matcher owner=tsc::" diff --git a/.github/workflows/shared-integration.yml b/.github/workflows/shared-integration.yml index cc2c3e0cc..270db1990 100644 --- a/.github/workflows/shared-integration.yml +++ b/.github/workflows/shared-integration.yml @@ -45,6 +45,8 @@ jobs: node-version: ${{ matrix.node }} cache: "pnpm" + - uses: google/wireit@setup-github-actions-caching/v2 + - name: Disable GitHub Actions Annotations run: | echo "::remove-matcher owner=tsc::" diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e19ec5116..d7e7abd2a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -45,6 +45,8 @@ jobs: cache: pnpm check-latest: true + - uses: google/wireit@setup-github-actions-caching/v2 + - name: Disable GitHub Actions Annotations run: | echo "::remove-matcher owner=tsc::" diff --git a/.gitignore b/.gitignore index 83d226e94..5266e033b 100644 --- a/.gitignore +++ b/.gitignore @@ -22,6 +22,7 @@ node_modules/ /packages/*/dist/ /packages/*/LICENSE.md +.wireit .eslintcache .tmp /.env diff --git a/build.utils.ts b/build.utils.ts new file mode 100644 index 000000000..83cb783cc --- /dev/null +++ b/build.utils.ts @@ -0,0 +1,12 @@ +export function createBanner(packageName: string, version: string) { + return `/** + * ${packageName} v${version} + * + * Copyright (c) Remix Software Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE.md file in the root directory of this source tree. + * + * @license MIT + */`; +} diff --git a/integration/helpers/playwright-fixture.ts b/integration/helpers/playwright-fixture.ts index 0e8dbf609..07bfa2b92 100644 --- a/integration/helpers/playwright-fixture.ts +++ b/integration/helpers/playwright-fixture.ts @@ -1,9 +1,11 @@ import cp from "node:child_process"; import type { Page, Response, Request } from "@playwright/test"; import { test } from "@playwright/test"; -import cheerio from "cheerio"; +import { load } from "cheerio"; import prettier from "prettier"; +let cheerio = load(""); + import type { AppFixture } from "./create-fixture.js"; export class PlaywrightFixture { @@ -239,7 +241,7 @@ export function selectHtml(source: string, selector: string) { return prettyHtml(cheerio.html(el)).trim(); } -export function prettyHtml(source: string): string { +export function prettyHtml(source: string) { return prettier.format(source, { parser: "html" }); } diff --git a/integration/vite-spa-mode-test.ts b/integration/vite-spa-mode-test.ts index 4420e6798..c6c4d96ee 100644 --- a/integration/vite-spa-mode-test.ts +++ b/integration/vite-spa-mode-test.ts @@ -567,8 +567,15 @@ test.describe("SPA Mode", () => { expect(await page.locator("[data-root]").textContent()).toBe("Root"); expect(await page.locator("[data-index]").textContent()).toBe("Index"); - // Hydrates without issues - expect(logs).toEqual([]); + // Hydrates without issues - this message is expected due to the nested + expect(logs).toEqual([ + 'You rendered descendant (or called `useRoutes()`) at "/" ' + + '(under ) but the parent route path has no trailing "*". ' + + "This means if you navigate deeper, the parent won't match anymore and " + + "therefore the child routes will never render." + + "\n\n" + + 'Please change the parent to .', + ]); }); test("wraps default root HydrateFallback in user-provided Layout", async ({ diff --git a/package.json b/package.json index e3fb9b90d..e2558e678 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "@remix-run/react-router", "private": true, "scripts": { - "build": "rollup -c", + "build": "pnpm run --filter=\"./packages/**/*\" build", "clean": "git clean -fdX .", "clean:build": "git clean -fdx -e node_modules .", "clean:integration": "node ./integration/helpers/cleanup.mjs", @@ -57,10 +57,6 @@ "@octokit/rest": "^18.12.0", "@playwright/test": "^1.33.0", "@remix-run/changelog-github": "^0.0.5", - "@rollup/plugin-babel": "^5.3.1", - "@rollup/plugin-node-resolve": "^11.0.1", - "@rollup/plugin-replace": "^4.0.0", - "@rollup/plugin-typescript": "^8.5.0", "@testing-library/jest-dom": "5.17.0", "@testing-library/react": "^13.4.0", "@testing-library/user-event": "^14.5.2", @@ -104,10 +100,6 @@ "remark-gfm": "3.0.1", "remark-parse": "^10.0.1", "remark-stringify": "^10.0.2", - "rollup": "^2.79.1", - "rollup-plugin-copy": "^3.4.0", - "rollup-plugin-prettier": "^2.3.0", - "rollup-plugin-terser": "^7.0.2", "semver": "^7.5.4", "tslib": "^2.6.2", "type-fest": "^2.19.0", diff --git a/packages/react-router-architect/package.json b/packages/react-router-architect/package.json index 0029467b2..db9234aff 100644 --- a/packages/react-router-architect/package.json +++ b/packages/react-router-architect/package.json @@ -15,13 +15,38 @@ "typings": "dist/index.d.ts", "exports": { ".": { - "types": "./dist/index.d.ts", - "default": "./dist/index.js" + "node": { + "types": "./dist/index.d.ts", + "module-sync": "./dist/index.mjs", + "default": "./dist/index.js" + }, + "import": { + "types": "./dist/index.d.mts", + "default": "./dist/index.mjs" + }, + "default": { + "types": "./dist/index.d.ts", + "default": "./dist/index.js" + } }, "./package.json": "./package.json" }, "scripts": { - "tsc": "tsc" + "build": "wireit" + }, + "wireit": { + "build": { + "command": "tsup", + "files": [ + "sessions/**", + "*.ts", + "tsconfig.json", + "package.json" + ], + "output": [ + "dist/**" + ] + } }, "dependencies": { "@architect/functions": "^5.2.0", @@ -35,7 +60,9 @@ "react": "^18.2.0", "react-dom": "^18.2.0", "react-router": "workspace:*", - "typescript": "^5.1.0" + "tsup": "^8.3.0", + "typescript": "^5.1.6", + "wireit": "0.14.9" }, "peerDependencies": { "@react-router/node": "workspace:^", diff --git a/packages/react-router-architect/rollup.config.js b/packages/react-router-architect/rollup.config.js deleted file mode 100644 index 666442b06..000000000 --- a/packages/react-router-architect/rollup.config.js +++ /dev/null @@ -1,56 +0,0 @@ -const path = require("node:path"); - -const babel = require("@rollup/plugin-babel").default; -const nodeResolve = require("@rollup/plugin-node-resolve").default; -const typescript = require("@rollup/plugin-typescript"); -const copy = require("rollup-plugin-copy"); - -const { - isBareModuleId, - getBuildDirectories, - createBanner, - WATCH, - remixBabelConfig, -} = require("../../rollup.utils"); -const { name: packageName, version } = require("./package.json"); - -/** @returns {import("rollup").RollupOptions[]} */ -module.exports = function rollup() { - const { SOURCE_DIR, OUTPUT_DIR } = getBuildDirectories( - packageName, - // We don't live in a folder matching our package name - "react-router-architect" - ); - - return [ - { - external: (id) => isBareModuleId(id), - input: `${SOURCE_DIR}/index.ts`, - output: { - banner: createBanner(packageName, version), - dir: OUTPUT_DIR, - format: "cjs", - preserveModules: true, - exports: "auto", - }, - plugins: [ - babel({ - babelHelpers: "bundled", - exclude: /node_modules/, - extensions: [".ts"], - ...remixBabelConfig, - }), - typescript({ - tsconfig: path.join(__dirname, "tsconfig.json"), - exclude: ["__tests__"], - noEmitOnError: !WATCH, - noForceEmit: true, - }), - nodeResolve({ extensions: [".ts"] }), - copy({ - targets: [{ src: "LICENSE.md", dest: SOURCE_DIR }], - }), - ], - }, - ]; -}; diff --git a/packages/react-router-architect/tsup.config.ts b/packages/react-router-architect/tsup.config.ts new file mode 100644 index 000000000..f698117df --- /dev/null +++ b/packages/react-router-architect/tsup.config.ts @@ -0,0 +1,21 @@ +import { defineConfig } from "tsup"; + +// @ts-ignore - out of scope +import { createBanner } from "../../build.utils.js"; + +import pkg from "./package.json"; + +const entry = ["index.ts"]; + +export default defineConfig([ + { + clean: true, + entry, + format: ["cjs", "esm"], + outDir: "dist", + dts: true, + banner: { + js: createBanner(pkg.name, pkg.version), + }, + }, +]); diff --git a/packages/react-router-cloudflare/package.json b/packages/react-router-cloudflare/package.json index f261eb781..aa6925b13 100644 --- a/packages/react-router-cloudflare/package.json +++ b/packages/react-router-cloudflare/package.json @@ -15,23 +15,45 @@ "typings": "dist/index.d.ts", "exports": { ".": { - "types": "./dist/index.d.ts", - "default": "./dist/index.js" + "import": { + "types": "./dist/index.d.mts", + "default": "./dist/index.mjs" + }, + "default": { + "types": "./dist/index.d.ts", + "default": "./dist/index.js" + } }, "./package.json": "./package.json" }, "scripts": { - "build": "rollup -c", - "tsc": "tsc" + "build": "wireit" + }, + "wireit": { + "build": { + "command": "tsup", + "files": [ + "sessions/**", + "*.ts", + "tsconfig.json", + "package.json" + ], + "output": [ + "dist/**" + ] + } }, "devDependencies": { "@cloudflare/workers-types": "^4.20230518.0", "react-router": "workspace:*", - "typescript": "^5.1.0" + "tsup": "^8.3.0", + "typescript": "^5.1.6", + "wireit": "0.14.9" }, "peerDependencies": { "@cloudflare/workers-types": "^4.0.0", "react-router": "workspace:^", + "tsup": "^8.3.0", "typescript": "^5.1.0" }, "peerDependenciesMeta": { diff --git a/packages/react-router-cloudflare/rollup.config.js b/packages/react-router-cloudflare/rollup.config.js deleted file mode 100644 index 578f3ad89..000000000 --- a/packages/react-router-cloudflare/rollup.config.js +++ /dev/null @@ -1,55 +0,0 @@ -const path = require("node:path"); - -const babel = require("@rollup/plugin-babel").default; -const nodeResolve = require("@rollup/plugin-node-resolve").default; -const typescript = require("@rollup/plugin-typescript"); -const copy = require("rollup-plugin-copy"); - -const { - isBareModuleId, - getBuildDirectories, - createBanner, - remixBabelConfig, - WATCH, -} = require("../../rollup.utils"); -const { name: packageName, version } = require("./package.json"); - -/** @returns {import("rollup").RollupOptions[]} */ -module.exports = function rollup() { - const { SOURCE_DIR, OUTPUT_DIR } = getBuildDirectories( - packageName, - // We don't live in a folder matching our package name - "react-router-cloudflare" - ); - - return [ - { - external: (id) => isBareModuleId(id), - input: `${SOURCE_DIR}/index.ts`, - output: { - banner: createBanner(packageName, version), - dir: OUTPUT_DIR, - format: "cjs", - preserveModules: true, - exports: "named", - }, - plugins: [ - babel({ - babelHelpers: "bundled", - exclude: /node_modules/, - extensions: [".ts"], - ...remixBabelConfig, - }), - typescript({ - tsconfig: path.join(__dirname, "tsconfig.json"), - noEmitOnError: !WATCH, - noForceEmit: true, - }), - nodeResolve({ extensions: [".ts"] }), - copy({ - targets: [{ src: "LICENSE.md", dest: SOURCE_DIR }], - }), - ], - }, - ]; -}; diff --git a/packages/react-router-cloudflare/tsup.config.ts b/packages/react-router-cloudflare/tsup.config.ts new file mode 100644 index 000000000..f698117df --- /dev/null +++ b/packages/react-router-cloudflare/tsup.config.ts @@ -0,0 +1,21 @@ +import { defineConfig } from "tsup"; + +// @ts-ignore - out of scope +import { createBanner } from "../../build.utils.js"; + +import pkg from "./package.json"; + +const entry = ["index.ts"]; + +export default defineConfig([ + { + clean: true, + entry, + format: ["cjs", "esm"], + outDir: "dist", + dts: true, + banner: { + js: createBanner(pkg.name, pkg.version), + }, + }, +]); diff --git a/packages/react-router-dev/config/routes.ts b/packages/react-router-dev/config/routes.ts index 2595d4da7..f8cd7c864 100644 --- a/packages/react-router-dev/config/routes.ts +++ b/packages/react-router-dev/config/routes.ts @@ -3,10 +3,12 @@ import * as v from "valibot"; import pick from "lodash/pick"; import invariant from "../invariant"; -let appDirectory: string; +declare global { + var __reactRouterAppDirectory: string; +} export function setAppDirectory(directory: string) { - appDirectory = directory; + globalThis.__reactRouterAppDirectory = directory; } /** @@ -14,8 +16,8 @@ export function setAppDirectory(directory: string) { * This is designed to support resolving file system routes. */ export function getAppDirectory() { - invariant(appDirectory); - return appDirectory; + invariant(globalThis.__reactRouterAppDirectory); + return globalThis.__reactRouterAppDirectory; } export interface RouteManifestEntry { diff --git a/packages/react-router-dev/package.json b/packages/react-router-dev/package.json index c9abd90fd..2ff41ff1c 100644 --- a/packages/react-router-dev/package.json +++ b/packages/react-router-dev/package.json @@ -32,7 +32,25 @@ "react-router": "bin.js" }, "scripts": { - "tsc": "tsc" + "build": "wireit" + }, + "wireit": { + "build": { + "command": "tsup", + "files": [ + "cli/**", + "config/**", + "typescript/**", + "vite/**", + "*.ts", + "bin.js", + "tsconfig.json", + "package.json" + ], + "output": [ + "dist/**" + ] + } }, "dependencies": { "@babel/core": "^7.21.8", @@ -90,7 +108,10 @@ "react-router": "workspace:^", "strip-ansi": "^6.0.1", "tiny-invariant": "^1.2.0", + "tsup": "^8.3.0", + "typescript": "^5.1.6", "vite": "^5.1.0", + "wireit": "0.14.9", "wrangler": "^3.28.2" }, "peerDependencies": { diff --git a/packages/react-router-dev/rollup.config.js b/packages/react-router-dev/rollup.config.js deleted file mode 100644 index f5f36f8ad..000000000 --- a/packages/react-router-dev/rollup.config.js +++ /dev/null @@ -1,78 +0,0 @@ -const path = require("node:path"); -const babel = require("@rollup/plugin-babel").default; -const typescript = require("@rollup/plugin-typescript"); -const nodeResolve = require("@rollup/plugin-node-resolve").default; -const copy = require("rollup-plugin-copy"); - -const { - createBanner, - isBareModuleId, - getBuildDirectories, - remixBabelConfig, - WATCH, -} = require("../../rollup.utils"); -const { name, version } = require("./package.json"); - -/** @returns {import("rollup").RollupOptions[]} */ -module.exports = function rollup() { - const { SOURCE_DIR, OUTPUT_DIR } = getBuildDirectories( - name, - // We don't live in a folder matching our package name - "react-router-dev" - ); - - return [ - { - external: isBareModuleId, - input: [ - `${SOURCE_DIR}/cli/index.ts`, - `${SOURCE_DIR}/routes.ts`, - `${SOURCE_DIR}/vite.ts`, - `${SOURCE_DIR}/vite/cloudflare.ts`, - `${SOURCE_DIR}/typescript/plugin.ts`, - ], - output: { - banner: createBanner("@react-router/dev", version), - dir: OUTPUT_DIR, - format: "cjs", - preserveModules: true, - exports: "auto", - }, - plugins: [ - babel({ - babelHelpers: "bundled", - exclude: /node_modules/, - extensions: [".ts"], - ...remixBabelConfig, - }), - typescript({ - tsconfig: path.join(__dirname, "tsconfig.json"), - exclude: ["__tests__"], - noEmitOnError: !WATCH, - }), - nodeResolve({ extensions: [".ts"] }), - copy({ - targets: [ - { src: "LICENSE.md", dest: SOURCE_DIR }, - { src: `${SOURCE_DIR}/vite/static`, dest: `${OUTPUT_DIR}/vite` }, - { - src: `${SOURCE_DIR}/config/defaults`, - dest: `${OUTPUT_DIR}/config`, - }, - ], - }), - // Allow dynamic imports in CJS code to allow us to utilize - // ESM modules as part of the compiler. - { - name: "dynamic-import-polyfill", - renderDynamicImport() { - return { - left: "import(", - right: ")", - }; - }, - }, - ], - }, - ]; -}; diff --git a/packages/react-router-dev/tsup.config.ts b/packages/react-router-dev/tsup.config.ts new file mode 100644 index 000000000..d42806a5c --- /dev/null +++ b/packages/react-router-dev/tsup.config.ts @@ -0,0 +1,53 @@ +import * as fsp from "fs/promises"; + +import { defineConfig } from "tsup"; + +// @ts-ignore - out of scope +import { createBanner } from "../../build.utils.js"; + +import pkg from "./package.json"; + +const entry = [ + "cli/index.ts", + "routes.ts", + "vite.ts", + "vite/cloudflare.ts", + "typescript/plugin.ts", +]; + +const external = ["./static/refresh-utils.cjs"]; + +export default defineConfig([ + { + clean: true, + entry, + format: ["cjs"], + outDir: "dist", + dts: true, + external, + banner: { + js: createBanner(pkg.name, pkg.version), + }, + plugins: [ + { + name: "copy", + async buildEnd() { + await fsp.mkdir("dist/static", { recursive: true }); + await fsp.copyFile( + "vite/static/refresh-utils.cjs", + "dist/static/refresh-utils.cjs" + ); + + await fsp.mkdir("dist/config/defaults", { recursive: true }); + const files = await fsp.readdir("config/defaults"); + for (const file of files) { + await fsp.copyFile( + `config/defaults/${file}`, + `dist/config/defaults/${file}` + ); + } + }, + }, + ], + }, +]); diff --git a/packages/react-router-dev/vite/plugin.ts b/packages/react-router-dev/vite/plugin.ts index 3f0bc19a3..4ea3beb41 100644 --- a/packages/react-router-dev/vite/plugin.ts +++ b/packages/react-router-dev/vite/plugin.ts @@ -5,7 +5,7 @@ import { type BinaryLike, createHash } from "node:crypto"; import * as path from "node:path"; import * as url from "node:url"; import * as fse from "fs-extra"; -import babel from "@babel/core"; +import * as babel from "@babel/core"; import { unstable_setDevServerHooks as setDevServerHooks, createRequestHandler, @@ -831,6 +831,7 @@ export const reactRouterVitePlugin: ReactRouterVitePlugin = (_config) => { // Pre-bundle router dependencies to avoid router duplicates. // Mismatching routers cause `Error: You must render this element inside a element`. "react-router", + "react-router/dom", // Check to avoid "Failed to resolve dependency: react-router-dom, present in 'optimizeDeps.include'" ...(hasDependency("react-router-dom") ? ["react-router-dom"] @@ -849,6 +850,7 @@ export const reactRouterVitePlugin: ReactRouterVitePlugin = (_config) => { // see description for `optimizeDeps.include` "react-router", + "react-router/dom", "react-router-dom", ], }, diff --git a/packages/react-router-dom/node-main.js b/packages/react-router-dom/node-main.js deleted file mode 100644 index ed05df121..000000000 --- a/packages/react-router-dom/node-main.js +++ /dev/null @@ -1,7 +0,0 @@ -/* eslint-env node */ - -if (process.env.NODE_ENV === "production") { - module.exports = require("./umd/react-router-dom.production.min.js"); -} else { - module.exports = require("./umd/react-router-dom.development.js"); -} diff --git a/packages/react-router-dom/package.json b/packages/react-router-dom/package.json index 66576cf45..d1739391b 100644 --- a/packages/react-router-dom/package.json +++ b/packages/react-router-dom/package.json @@ -24,18 +24,47 @@ "types": "./dist/index.d.ts", "exports": { ".": { - "types": "./dist/index.d.ts", - "import": "./dist/index.mjs", - "require": "./dist/main.js" + "node": { + "types": "./dist/index.d.ts", + "module-sync": "./dist/index.mjs", + "default": "./dist/index.js" + }, + "import": { + "types": "./dist/index.d.mts", + "default": "./dist/index.mjs" + }, + "default": { + "types": "./dist/index.d.ts", + "default": "./dist/index.js" + } }, "./package.json": "./package.json" }, + "scripts": { + "build": "wireit" + }, + "wireit": { + "build": { + "command": "tsup", + "files": [ + "*.ts", + "tsconfig.json", + "package.json" + ], + "output": [ + "dist/**" + ] + } + }, "dependencies": { "react-router": "workspace:*" }, "devDependencies": { "react": "^18.2.0", - "react-dom": "^18.2.0" + "react-dom": "^18.2.0", + "tsup": "^8.3.0", + "typescript": "^5.1.6", + "wireit": "0.14.9" }, "peerDependencies": { "react": ">=18", diff --git a/packages/react-router-dom/rollup.config.js b/packages/react-router-dom/rollup.config.js deleted file mode 100644 index d4b037fd1..000000000 --- a/packages/react-router-dom/rollup.config.js +++ /dev/null @@ -1,223 +0,0 @@ -const path = require("path"); -const babel = require("@rollup/plugin-babel").default; -const copy = require("rollup-plugin-copy"); -const nodeResolve = require("@rollup/plugin-node-resolve").default; -const prettier = require("rollup-plugin-prettier"); -const replace = require("@rollup/plugin-replace"); -const { terser } = require("rollup-plugin-terser"); -const typescript = require("@rollup/plugin-typescript"); -const { - createBanner, - isBareModuleId, - getBuildDirectories, - PRETTY, - WATCH, -} = require("../../rollup.utils"); -const { name, version } = require("./package.json"); - -module.exports = function rollup() { - const { SOURCE_DIR, OUTPUT_DIR } = getBuildDirectories(name); - - // JS modules for bundlers - const modules = [ - { - input: `${SOURCE_DIR}/index.ts`, - output: { - file: `${OUTPUT_DIR}/index.mjs`, - format: "esm", - sourcemap: !PRETTY, - banner: createBanner("React Router DOM", version), - }, - external: (id) => isBareModuleId(id), - plugins: [ - nodeResolve({ extensions: [".tsx", ".ts"] }), - babel({ - babelHelpers: "bundled", - exclude: /node_modules/, - presets: [ - ["@babel/preset-env", { loose: true }], - "@babel/preset-react", - "@babel/preset-typescript", - ], - plugins: ["babel-plugin-dev-expression"], - extensions: [".ts", ".tsx"], - }), - typescript({ - tsconfig: path.join(__dirname, "tsconfig.json"), - exclude: ["__tests__"], - noEmitOnError: !WATCH, - }), - copy({ - targets: [{ src: "LICENSE.md", dest: SOURCE_DIR }], - verbose: true, - }), - ].concat(PRETTY ? prettier({ parser: "babel" }) : []), - }, - ]; - - // JS modules for