Skip to content
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

Fix: more loosened React lib version check #7484

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1 @@
module.exports = <div />;
@@ -0,0 +1,6 @@
{
"private": true,
"dependencies": {
"preact": "https://pkg.csb.dev/preactjs/preact/commit/96082866/preact"
}
}
9 changes: 9 additions & 0 deletions packages/core/integration-tests/test/transpilation.js
Expand Up @@ -130,6 +130,15 @@ describe('transpilation', function () {
assert(file.includes('h("div"'));
});

it('should support compiling JSX in JS files with Preact url dependency', async function () {
await bundle(
path.join(__dirname, '/integration/jsx-preact-with-url/index.js'),
);

let file = await outputFS.readFile(path.join(distDir, 'index.js'), 'utf8');
assert(file.includes('h("div"'));
});

it('should support compiling JSX in TS files with Preact dependency', async function () {
let b = await bundle(
path.join(__dirname, '/integration/jsx-preact-ts/index.tsx'),
Expand Down
5 changes: 4 additions & 1 deletion packages/transformers/js/src/JSTransformer.js
Expand Up @@ -209,8 +209,11 @@ export default (new Transformer({
pkg?.dependencies?.[effectiveReactLib] ||
pkg?.devDependencies?.[effectiveReactLib] ||
pkg?.peerDependencies?.[effectiveReactLib];
reactLibVersion = reactLibVersion
? semver.validRange(reactLibVersion)
: null;
let minReactLibVersion =
reactLibVersion != null && reactLibVersion !== '*'
reactLibVersion !== null && reactLibVersion !== '*'
Comment on lines +212 to +216
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I use semver.validRange instead of semver.valid, because semver.valid returns null with the input such as 17 so some test case will be failed. I use semver.validRange to avoid this. If you have another idea about this, I would appreciate it if you tell me.

? semver.minVersion(reactLibVersion)?.toString()
: null;

Expand Down