-
Notifications
You must be signed in to change notification settings - Fork 22
Fix: HMR for Non-Module Systems #483
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
6fe5ec9
f9f07ef
eb51b02
49f92fc
5fc6234
23a7856
7df699f
f7ca85d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "10up-toolkit": minor | ||
| --- | ||
|
|
||
| Fix HMR for non-script module based installations and support better peer dependency management |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -69,7 +69,6 @@ | |||||
| "url-loader": "^4.1.1", | ||||||
| "webpack": "^5.89.0", | ||||||
| "webpack-bundle-analyzer": "^4.10.1", | ||||||
| "webpack-dev-server": "^5.2.2", | ||||||
| "webpack-sources": "^3.2.3", | ||||||
| "webpackbar": "^6.0.0", | ||||||
| "yaml": "^2.4.1" | ||||||
|
|
@@ -85,7 +84,8 @@ | |||||
| "@10up/stylelint-config": ">=3.0.0", | ||||||
| "@linaria/babel-preset": ">=4.3.3", | ||||||
| "@linaria/webpack-loader": ">=4.1.11", | ||||||
| "typescript": ">=5.0.0" | ||||||
| "typescript": ">=5.0.0", | ||||||
| "webpack-dev-server": "^5.2.2" | ||||||
|
||||||
| "webpack-dev-server": "^5.2.2" | |
| "webpack-dev-server": "^4.0.0 || ^5.2.2" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can update the engines declaration for this package, perhaps that update was missed when the overall .nvmrc was updated to use v18?
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,6 +38,25 @@ const getPackageVersion = async () => { | |
| return pkg.version; | ||
| }; | ||
|
|
||
| /** | ||
| * Returns the version of an installed npm package by name. | ||
| * Resolves the package's package.json so it works without importing the package. | ||
| * Uses read-pkg to read and parse the package.json. | ||
| * | ||
| * @param {string} packageName - The name of the npm package (e.g. 'webpack-dev-server'). | ||
| * @param {string} [fallback='0'] - Value to return if the package is not installed or version is unreadable. | ||
| * @returns {string} The package version string or the fallback. | ||
| */ | ||
| const getInstalledPackageVersion = (packageName, fallback = '0') => { | ||
| try { | ||
| const pkgPath = require.resolve(`${packageName}/package.json`); | ||
| const pkg = readPkg.sync({ cwd: path.dirname(pkgPath) }); | ||
| return typeof pkg.version === 'string' ? pkg.version : fallback; | ||
| } catch { | ||
| return fallback; | ||
| } | ||
| }; | ||
|
|
||
| /** | ||
| * Checks whether the passed package name is installed in the project. | ||
| * | ||
|
|
@@ -55,10 +74,38 @@ const isPackageInstalled = (packageName) => { | |
| return false; | ||
| }; | ||
|
|
||
| /** | ||
| * Compares two semver-like version strings (e.g. "5.2.2", "1.0.0-beta.1"). | ||
| * Only the numeric segments are compared; non-numeric segments are treated as 0. | ||
| * | ||
| * @param {string} actual - The resolved version (e.g. from a package). | ||
| * @param {string} min - The minimum required version. | ||
| * @returns {boolean} True if actual >= min, false otherwise. | ||
| */ | ||
| const isMinimumPackageVersion = (actual, min) => { | ||
| const actualVersions = actual.split('.').map(Number); | ||
| const minimumVersions = min.split('.').map(Number); | ||
|
|
||
| for (let i = 0; i < Math.max(actualVersions.length, minimumVersions.length); i++) { | ||
| const actualVersionLevel = actualVersions[i] || 0; | ||
| const minimumVersionLevel = minimumVersions[i] || 0; | ||
| if (actualVersionLevel > minimumVersionLevel) { | ||
| return true; | ||
| } | ||
| if (actualVersionLevel < minimumVersionLevel) { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| return true; | ||
|
Comment on lines
+77
to
+100
|
||
| }; | ||
|
|
||
| module.exports = { | ||
| isPackageInstalled, | ||
| getPackagePath, | ||
| hasPackageProp, | ||
| getInstalledPackageVersion, | ||
| getPackage, | ||
| getPackagePath, | ||
| getPackageVersion, | ||
| hasPackageProp, | ||
| isMinimumPackageVersion, | ||
| isPackageInstalled, | ||
| }; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changing Changesets
baseBranchfromtrunktodevelopis likely to break the existing release automation that runs on bothdevelopandtrunk(see.github/workflows/release.ymland CONTRIBUTING, which describe stable releases fromtrunk). If the intent is to targetdeveloponly for@next, consider handling that in the workflow/action inputs instead of globally changingbaseBranch, or confirm Changesets can still open the correct PRs/publish when running ontrunk.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unsure on this one, I have not used
changesetthat much before. It did fail when I tried to run it withtrunkset as thebaseBranch.