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
Add build step for standalone version, resolves #842 #950
Conversation
Wow, this looks great! 💯 Concerning the questions:
|
None that I know of. I'd be very thankful for a better suggestion though. 😁
Absolutely. I looked that up but had already forgotten about it when I wrote down the pull request. 🙄 However putting the standalone file into Users need to be able to access the standalone build directly via So I'd stay with compiling the standalone bundle to the project root but add it to
We could definitely make this a lot easier. I could just add another Rollup config that differs slightly from the one in this PR:
The resulting bundle would be listed in the Writing it down like that, the effort should actually be pretty moderate. Would you like me to attach it to this PR directly? |
@czosel yeah- I assume it replaces characters that can't appear in a JS identifier with underscores (so |
That's what I went with on first approach. Didn't like it that much, but I have to agree that mixed case is way worse. |
👍
Sounds great! 🙂
👍 |
Done.
Done as well. I've approached this by renaming the
I don't find either of these adjustments to be solved particularly elegant, so if a more experienced Jest user knows how to solve this in a nicer way, let me know!* * Solving the first adjustment differently actually is a requirement, since using a neagive lookbehind assertion to exclude the
Alright, going to do that when the tests are fixed. 👍 |
Awesome job! Something wrong in CI test 😕 |
Any ideas how we can test this? Maybe run |
@evilebottnawi See my comment above — I've added tests already, also described how it works. Failing CI is due to Node.js v6 not supporting RegEx backreferences (which I've used to exclude the |
Side note: I've actually discovered a better way for naming. Prettier's very own parsers to be used with the standalone build (e.g. the This would be a pretty decent way for us as well, IMO. We'd go by |
Okay, so I've fixed the tests by no longer excluding the markdown tests at all. I've rather included the markdown parser in the standalone test so this is now covered as well. I had to update the snapshots of the markdown tests though since there was inconsistent behaviour between the builds: If no
This shoud definitely be streamlined, not sure which the desired behavior would be. This is a design decision. // cc @czosel @evilebottnawi For now, I've changed the markdown test's config to explicitely use 4 spaces in every environment, this should however be reverted as soon as the behavior of both builds is aligned. |
@loilo strange maybe something wrong on prettier side? |
It definitely seems to be something on Prettier's side (or in the official Markdown plugin). The Lua plugin shows the same behavior. |
/cc @suchipi |
Both docs and code look great to me! 💯 I just have one more remark, because I misunderstood an earlier comment:
Couldn't we do exactly the same as Prettier and attach ourselves to Otherwise, I'd prefer calling the global |
That's what I've done in 0bf6fa5. 👍
|
@loilo Ahh, that makes a lot of sense. Thanks for the enlightenment 😉 |
Co-Authored-By: Loilo <Florian.Reuschel@gmx.de>
Thanks to the thought-provoking impulse from @evilebottnawi, we're now back to just a single UMD build that works universally in browsers and bundlers. ❤️ I've removed traces of the other builds and updated the docs accordingly. |
@loilo Great work! Anything left to finish? |
I think we're good to go. |
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.
🎉
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.
/cc @suchipi Should we create issue about indent problem or you take care about this?
I just published Maybe someone is interested to try this with Prettier's playground? 😉 |
I was just about to say, what would you think of adding the standalone build to the Prettier playground as |
@evilebottnawi could you create the issue please? I don't have all the context |
Sure. |
I find this really hard to nail down. Gotta sleep now and won't have time tomorrow, but if anyone's curious, here's what I found out so far:
|
@loilo Maybe you can create issue in our repo so as not to forget about it when someone has time |
Yep, going to do that. Wasn't able to narrow it down myself. |
Anyway, thanks for good job and helping 👍 |
My pleasure. 🙂 |
Also that's so much better when we use the jest snapshot raw serializer... Again thanks to prettier/plugin-php#950 :)
This pull request resolves #842, adding a standalone build to the Prettier PHP plugin.
Build
The
standalone.js
in the root of the package is generated through running:Usage
The
standalone.js
is "standalone" in the sense that it is bundled into one file with no Node.js-specific dependencies left. It does however not include Prettier itself. Prettier's standalone version has to be included on its own first (order matters):The plugin registers as a global variable named
prettier_pluginPhp
. Using Prettier with it look like this:Here's a demo.
Transformations
Things I instructed Rollup to do:
prettier
module asexternal
, so essentially allrequire("prettier")
are replaced with theprettier
global variable.assert
module. I'm not sure why thestrictEqual
method should do nothing, but that's how it's done in Prettier.Buffer.isBuffer()
(used by thephp-parser
dependency).process.arch
tox32
(relevant for maximum float size).ToDo
Considerations
Name of the global?
prettier_pluginPhp
is not that catchy, suggestions are welcome.✅ Resolved: Like Prettier's built-in plugins, the plugin is registered on the global
prettierPlugins
object asprettierPlugins.php
.Minify?
Prettier doesn't do it, therefore this pull request currently doesn't either.
✅ Resolved: Prettier does actually apply minification, not to their
standalone.js
, but to each of their plugins. This PR matches this behavior and minifies the standalone plugin.Add the generated
standalone.js
to the repo?Prettier does so.
❌ Rejected: I was wrong, Prettier actually does not.
Is it reasonable to hardcode
process.arch
tox32
?Doing a quick search, I found no way to detect a machine's architecture with browser-side JS with a reasonable amount of confidence.
x32
should be a safe bet.Add documentation about how to use this plugin in bundlers?
The
standalone.js
is not really suited for usage with bundlers. To avoid confusion, an additional section about using bundlers in the readme (i.e. "rewrite allprettier
calls toprettier/standalone
") could be reasonable.✅ Resolved: No weird tips for bundler usage needed as this PR now also includes a pretty fool-proof way to integrate with bundlers.