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

Allow JSX Import Source to be overwritten #47

Merged
merged 8 commits into from
Oct 13, 2023

Conversation

Interpause
Copy link
Contributor

This pull request solves #46 by adding jsxImportSource to PreactPluginOptions. As a bonus, I changed prepublishOnly to prepare, which allows the package to be installed directly via Git and should not affect its behaviour when being published to npm.

package.json Outdated Show resolved Hide resolved
@Interpause
Copy link
Contributor Author

bump

sapphi-red and others added 3 commits August 7, 2022 16:05
…actjs#48)

* add named export to improve `"module": "nodenext"` compatibility

* add proper types export

* Update src/index.ts

Co-authored-by: Jovi De Croock <decroockjovi@gmail.com>

Co-authored-by: Jovi De Croock <decroockjovi@gmail.com>
Copy link
Member

@marvinhagemeister marvinhagemeister left a comment

Choose a reason for hiding this comment

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

This PR has the right spirit, but does a whole lot more than just allowing jsxImportSource to be overwritten.

@Interpause
Copy link
Contributor Author

This PR has the right spirit, but does a whole lot more than just allowing jsxImportSource to be overwritten.

Is this referring to the additional 3 commits caused by fast forwarding the pull request to main?

@rschristian
Copy link
Member

You need to rebase your changes. The diff is quite mangled.

@Interpause
Copy link
Contributor Author

Should be fixed now.

@JoviDeCroock
Copy link
Member

JoviDeCroock commented Sep 17, 2022

@Interpause the comment to leave prePublish in still stands 😅 we want this so when we use npm publish we are sure we can't forget to use the latest build

@rschristian
Copy link
Member

rschristian commented Sep 17, 2022

@JoviDeCroock FWIW, prepare does run before a publish: https://docs.npmjs.com/cli/v8/using-npm/scripts#life-cycle-scripts

I would argue against prepare still though as there's no reason we need to run a build immediately after installing deps (which it does). That's just a nuisance, IMO.

Edit: I guess it facilitates installing from git, but meh. Do people do that often enough?

package.json Outdated
@@ -17,7 +17,8 @@
"dev": "vite demo",
"dev:build": "vite build demo",
"build": "rimraf dist && tsc && tsc -p tsconfig.cjs.json && node tools/postbuild.mjs",
"prepublishOnly": "npm run build"
"prepublishOnly": "npm run build",
"prepare": "npm run build"
Copy link
Member

Choose a reason for hiding this comment

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

This causes the build command to be run whenever a user installs our vite preset. Is this change necessary to allow JSX Import Source to be overwritten?

Copy link
Member

Choose a reason for hiding this comment

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

According to the docs, I think it's only when the preset is installed through git? Which, of course, would require build be ran.

Copy link
Member

Choose a reason for hiding this comment

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

I think it's not just that:

  • Runs on local npm install without any arguments

In either way this change doesn't seem necessary to allow JSX import source to be overwritten.

Copy link
Member

@rschristian rschristian Sep 18, 2022

Choose a reason for hiding this comment

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

I think it's not just that:

microbundle has a prepare script, for example, and it doesn't run on install (nor could it). "local" means this project, as in, if you were to clone this repo and run npm install.

Not the best wording from NPM, to be fair.

In either way this change doesn't seem necessary to allow JSX import source to be overwritten.

Yeah totally agree there, and I generally think it's a super annoying life cycle script anyways.

Copy link
Member

@marvinhagemeister marvinhagemeister Sep 18, 2022

Choose a reason for hiding this comment

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

I stand corrected! Looks like I made the wrong assumption.

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 am guessing to keep the pull request pure, you want to remove the changes to package.json?

Copy link
Member

Choose a reason for hiding this comment

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

That, but also as it stands, you haven't provided an explanation for the change. Why are we adding a new script?

While we can guess about your intentions (as we've done above), for right now, it's a change without any rhyme nor reason.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To be fair, the prepare script isn't needed if the package is installed from npm. However, as I needed to overwrite the import source for a project, and did not want to publish to npm, I added the prepare script so that installing via git would be possible.

@Interpause
Copy link
Contributor Author

Say, its been a while. Actually, I think the changes made to allow configuring jsxImportSource is quite minor, such that it probably would not be too much trouble for a maintainer to just include it in a commit. If so, would it be fine to close this PR?

@o-alexandrov
Copy link

Could you please consider to merge the PR, as the changes had been cleaned up

@@ -130,7 +135,7 @@ function preactPlugin({
: "@babel/plugin-transform-react-jsx-development",
{
runtime: "automatic",
importSource: "preact",
importSource: jsxImportSource ?? "preact",
Copy link

@o-alexandrov o-alexandrov Mar 5, 2023

Choose a reason for hiding this comment

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

nullish coalescing while having no benefit over || operator in this case, still shouldn't break anyone's environment, as it's supported in Node.js 14 (oldest version that hasn't reached EOL)

@JoviDeCroock JoviDeCroock merged commit 8223769 into preactjs:main Oct 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants