Skip to content

Commit

Permalink
[fixexternals] Fix how react-dom/server is imported (#2272)
Browse files Browse the repository at this point in the history
## Summary:
Turns out that the rollup plugin, autoexternals, doesn't handle sub-package improts, like `react-dom/server`. However, reading the issue report on that package, [I saw a link to another](stevenbenisek/rollup-plugin-auto-external#16 (comment)), more up-to-date package, that does handle this. So I switched to that package, and now everything works as expected.

I did have to explicitly use the `mjs` extension for the rollup config, but that's a small price to pay for the benefits of the new package.

Issue: XXX-XXXX

## Test plan:
`yarn build` to see that the build works.

I'll also verify the packages in webapp to check everything else is fine, though the storybook should also check out.

Author: somewhatabstract

Reviewers: jandrade

Required Reviewers:

Approved By: jandrade

Checks: ✅ codecov/project, ✅ Chromatic - Get results on regular PRs (ubuntu-latest, 20.x), ✅ Test (ubuntu-latest, 20.x, 2/2), ✅ Check build sizes (ubuntu-latest, 20.x), ✅ Test (ubuntu-latest, 20.x, 1/2), ✅ Lint (ubuntu-latest, 20.x), ✅ Test (ubuntu-latest, 20.x, 2/2), ✅ Lint (ubuntu-latest, 20.x), ✅ Test (ubuntu-latest, 20.x, 1/2), ✅ Check build sizes (ubuntu-latest, 20.x), ✅ Chromatic - Build on regular PRs / chromatic (ubuntu-latest, 20.x), ⏭️  Chromatic - Skip on Release PR (changesets), 🚫 Chromatic - Get results on regular PRs, ✅ Prime node_modules cache for primary configuration (ubuntu-latest, 20.x), ✅ Check for .changeset entries for all changed files (ubuntu-latest, 20.x), ✅ gerald, ✅ Publish npm snapshot (ubuntu-latest, 20.x), 🚫 Chromatic - Build on regular PRs / chromatic (ubuntu-latest, 20.x), ✅ Publish npm snapshot (ubuntu-latest, 20.x), ⏭️  Chromatic - Skip on Release PR (changesets), ✅ Check for .changeset entries for all changed files (ubuntu-latest, 20.x), ✅ gerald, ✅ Prime node_modules cache for primary configuration (ubuntu-latest, 20.x), ⏭️  dependabot

Pull Request URL: #2272
  • Loading branch information
somewhatabstract authored Jul 12, 2024
1 parent 928cb0e commit c954464
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 34 deletions.
6 changes: 6 additions & 0 deletions .changeset/gentle-houses-listen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@khanacademy/wb-dev-build-settings": patch
"@khanacademy/wonder-blocks-testing-core": patch
---

Fix how react-dom/server is imported in Wonder Blocks Testing Core
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
/* eslint-disable import/no-commonjs */
import fs from "fs";
import path from "path";
import autoExternal from "rollup-plugin-auto-external";
import {nodeExternals} from "rollup-plugin-node-externals";
import babel from "rollup-plugin-babel";
import resolve from "@rollup/plugin-node-resolve";
// eslint-disable-next-line import/extensions
import makeBabelConfig from "./babel.config.js";

const {presets, plugins} = require("./babel.config")({env: () => false});
const {presets, plugins} = makeBabelConfig({env: () => false});

const createConfig = (pkgName) => {
const packageJsonPath = path.join("packages", pkgName, "package.json");
Expand Down Expand Up @@ -47,7 +49,7 @@ const createConfig = (pkgName) => {
browser: true,
extensions,
}),
autoExternal({
nodeExternals({
packagePath: `packages/${pkgName}/package.json`,
}),
],
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"scripts": {
"alex": "alex packages/",
"build": "rollup -c ./build-settings/rollup.config.js",
"build": "rollup -c ./build-settings/rollup.config.mjs",
"build:types": "yarn tsc --build tsconfig-build.json && node -r @swc-node/register build-settings/remove-test-types-from-dist.ts",
"build:storybook": "storybook build --stats-json",
"clean": "rm -rf packages/wonder-blocks-*/dist && rm -rf packages/wonder-blocks-*/node_modules && rm -f packages/*/*.tsbuildinfo && rm -f utils/tsconfig.tsbuildinfo",
Expand Down Expand Up @@ -111,8 +111,8 @@
"prettier": "^2.8.1",
"react-refresh": "^0.14.0",
"rollup": "^2.79.1",
"rollup-plugin-auto-external": "^2.0.0",
"rollup-plugin-babel": "^4.0.0-beta.2",
"rollup-plugin-node-externals": "^7.1.2",
"storybook": "^8.2.1",
"storybook-addon-pseudo-states": "^3.1.1",
"typescript": "^4.9.5",
Expand Down
36 changes: 7 additions & 29 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5520,12 +5520,6 @@ builtin-modules@^3.3.0:
resolved "https://registry.yarnpkg.com/builtin-modules/-/builtin-modules-3.3.0.tgz#cae62812b89801e9656336e46223e030386be7b6"
integrity sha512-zhaCDicdLuWN5UbN5IMnFqNMhNfo919sH85y2/ea+5Yg9TsTkeZxpL+JLbp6cgYFS4sRLp3YV4S6yDuqVWHYOw==

builtins@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/builtins/-/builtins-2.0.0.tgz#018999641e11252188652dbb2db01ad386fcdc46"
dependencies:
semver "^5.4.1"

builtins@^5.0.0:
version "5.0.1"
resolved "https://registry.yarnpkg.com/builtins/-/builtins-5.0.1.tgz#87f6db9ab0458be728564fa81d876d8d74552fa9"
Expand Down Expand Up @@ -11008,7 +11002,7 @@ nopt@^7.0.0:
dependencies:
abbrev "^2.0.0"

normalize-package-data@^2.3.2, normalize-package-data@^2.5.0:
normalize-package-data@^2.5.0:
version "2.5.0"
resolved "https://registry.yarnpkg.com/normalize-package-data/-/normalize-package-data-2.5.0.tgz#e66db1838b200c1dfc233225d12cb36520e234a8"
integrity sha512-/5CMN3T0R4XTj4DcGaexo+roZSdSFW/0AOOTROrjxzCG1wrWXEsGbRKevjlIL+ZDE4sZlJr5ED4YW0yqmkK+eA==
Expand Down Expand Up @@ -12011,14 +12005,6 @@ read-pkg-up@^9.1.0:
read-pkg "^7.1.0"
type-fest "^2.5.0"

read-pkg@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/read-pkg/-/read-pkg-3.0.0.tgz#9cbc686978fee65d16c00e2b19c237fcf6e38389"
dependencies:
load-json-file "^4.0.0"
normalize-package-data "^2.3.2"
path-type "^3.0.0"

read-pkg@^5.2.0:
version "5.2.0"
resolved "https://registry.yarnpkg.com/read-pkg/-/read-pkg-5.2.0.tgz#7bf295438ca5a33e56cd30e053b34ee7250c93cc"
Expand Down Expand Up @@ -12510,15 +12496,6 @@ rimraf@~2.6.2:
dependencies:
glob "^7.1.3"

rollup-plugin-auto-external@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/rollup-plugin-auto-external/-/rollup-plugin-auto-external-2.0.0.tgz#98fd137d66c1cbe0f4e245b31560a72dbde896aa"
dependencies:
builtins "^2.0.0"
read-pkg "^3.0.0"
safe-resolve "^1.0.0"
semver "^5.5.0"

rollup-plugin-babel@^4.0.0-beta.2:
version "4.4.0"
resolved "https://registry.yarnpkg.com/rollup-plugin-babel/-/rollup-plugin-babel-4.4.0.tgz#d15bd259466a9d1accbdb2fe2fff17c52d030acb"
Expand All @@ -12527,6 +12504,11 @@ rollup-plugin-babel@^4.0.0-beta.2:
"@babel/helper-module-imports" "^7.0.0"
rollup-pluginutils "^2.8.1"

rollup-plugin-node-externals@^7.1.2:
version "7.1.2"
resolved "https://registry.yarnpkg.com/rollup-plugin-node-externals/-/rollup-plugin-node-externals-7.1.2.tgz#19808d2b7ba6e5fc7d1c3bde1930fbcc4a5fe4a8"
integrity sha512-cVJFKs+ulZxpMmn/s+oi431d93Jq5+G7Sc5ixWDrL2k+Gj+MqXg0KMNWgKf8Mw5qpaG4jVDpsvuqFfiCvRcGeA==

rollup-pluginutils@^2.8.1:
version "2.8.2"
resolved "https://registry.yarnpkg.com/rollup-pluginutils/-/rollup-pluginutils-2.8.2.tgz#72f2af0748b592364dbd3389e600e5a9444a351e"
Expand Down Expand Up @@ -12578,10 +12560,6 @@ safe-regex-test@^1.0.0:
get-intrinsic "^1.1.3"
is-regex "^1.1.4"

safe-resolve@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/safe-resolve/-/safe-resolve-1.0.0.tgz#fe34f8d29d7a3becfd249d0aa8a799b5c3cf6559"

"safer-buffer@>= 2.1.2 < 3", "safer-buffer@>= 2.1.2 < 3.0.0":
version "2.1.2"
resolved "https://registry.yarnpkg.com/safer-buffer/-/safer-buffer-2.1.2.tgz#44fa161b0187b9549dd84bb91802f9bd8385cd6a"
Expand Down Expand Up @@ -12641,7 +12619,7 @@ semver-diff@^4.0.0:
dependencies:
semver "^7.3.5"

"semver@2 || 3 || 4 || 5", semver@^5.4.1, semver@^5.5.0:
"semver@2 || 3 || 4 || 5", semver@^5.4.1:
version "5.7.1"
resolved "https://registry.yarnpkg.com/semver/-/semver-5.7.1.tgz#a954f931aeba508d307bbf069eff0c01c96116f7"
integrity sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==
Expand Down

0 comments on commit c954464

Please sign in to comment.