-
Notifications
You must be signed in to change notification settings - Fork 7
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 NPM package #6
Conversation
I wasn't sure what to do with the readme in the NPM package, so I left it out. https://github.com/JackuB/diff-match-patch ships what I think is a copy of the wiki API from google. |
@TheSpyder I'll be on vacation during the next week, but I'll try and get to this once I'm back. some initial thoughts:
this is impressive I can tell even at a glance. great work. |
Hard to say. For anyone using the NPM package, it's equivalent, but I did see one person in the issues of that repo asking for a simple change to keep it running in browsers where a
That's definitely a good thought. I wanted to get something published for an internal deadline, but I might link the project to a branch of my fork rather than try to rush this.
Fair point. I'll roll back the branch to remove the test change commit and wait until the NPM package settles to submit it. I removed the minified version mostly I figured both should be equivalent and I don't have the tools installed to generate it from the uncompressed changes I made. I can bring it back and set the NPM package to publish without it.
thank you 😁 |
55921b4
to
f651143
Compare
@dmsnell I've done a few things:
|
@dmsnell will you have time to look at deploying this to NPM soon? I'm not trying to pressure you, just curious. |
sorry @TheSpyder - I should have anticipated this, but I'm currently held up by some work in the current WordPress release, which is happening right now. please allot me another week and I'll try to prioritize it starting on Monday, if not over the weekend. |
Monday is fine - I think by Wednesday we might have to look at an internal deployment. We're currently using a git link to a branch of my repo (from before I rolled back the tests). |
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.
@TheSpyder I'll beg your patience with me as we work through this. I'm a very slow person, and I can only fit a few things in my head at any given time.
there's a number of unrelated changes in this PR. I don't see much of a problem with most of them but I'd prefer we split them apart.
- making the
Diff
iterable seems like a good independent change in its own right. the only concern there I have is what happens in old environments whereSymbol.iterator
isn't defined. maybe we should conditionally define the iterator function. - adding
index.mjs
and creating the dual export format seems awesome. we need to ensure that the existing Closure compiler process still works properly with that.
this all reminds me how important it feels to get a CI job established for building the JS module. if you want to speed things up, you can work on that before I get to it. that is, start by automating the build process of the existing repo, then once that's in place, modify it so that it builds the npm
package automatically.
or we could do this in one step, but only when ensuring that nothing breaks backwards compatbility.
maybe I'm drawing a blank, but I don't think this repository has any existing distribution channel for JavaScript other than by every project vendoring the script from source/from here.
@NeilFraser did you have any official distribution for the JS code or did you expect people to download it from the Google repo?
The code changes are all coming from https://github.com/JackuB/diff-match-patch which was adjusted to better suit use embedded in a JavaScript application, as NPM developers expect, where the Google code is based on globals and standalone use. I don't have much knowledge about them other than this setup works in our application. The
I admit I have no idea what that is 😂 I have only looked seriously at the javascript folder. |
on second thought this change of repo is a great opportunity to break from all the constraints from let's see if we can get a CI job setup which produces a minified build, and let's compare that output to what Closure Compiler has been producing. I'm inclined to try something like biomejs which doesn't pull in a bunch of dependencies. |
That's the key I'm focusing on - anyone using this library on NPM is doing |
@TheSpyder In #9 I eagerly added the |
@dmsnell I think I've covered most of the feedback now - it's just the ESM question (whether to make it the default, whether to make it a new PR) that I'm not sure about. |
@TheSpyder I'll try and get back to this in the next few days after thinking more about ESM. I'm tempted to be a bit aggressive and focus more on the future direction and letting new code accept this. Seems like most projects today can and should be able to handle an ESM package. If it's not clear, we can merge and iterate later. Thanks for your patience with me again. It's been a very busy couple months on my end and I didn't mean to let this go so long. |
@dmsnell ok, what I might do in the meantime is update the testing code I pulled out of this PR and make a new PR with it. There's not really a rush on publishing this, although my team has been asking me why we're still deploying production code that depends on my personal github fork of this project 😅 |
So, bad news. What I haven't mentioned is that my team started using Unfortunately while integrating this latest change into our code it turns out the library is more or less built on the assumption that the I can't link you to our fork, but the original code is still available. It's plausible that all this can all still work with a swap to |
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.
If I were to publish this today as a brand new package, I think I'd stick with ESM-only and skip all the CJS work. That seems like eagerly taking on technical debt when there's an opportunity to avoid it.
If sufficient demand for a CJS version were to manifest, that could always be explored later.
It wasn't hard to do and seems to work, so I'm happy to go with the object. |
@dmsnell in an earlier comment you mentioned perhaps the ESM change should be a separate PR. I'm happy to do that, if you decide that's the path forward, or extract it to a new PR. I've created new branches to add types and tests, as separate PRs, once this change is approved and merged. They're working very well on my team's project. |
1c338a3
to
78d9ff9
Compare
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.
Nice. I like what you did with the tests, and actually I think the whitespace is fine. I'll merge this after another final review and we can move forward with a new base.
Awesome work!
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.
This looks good in general, well done, thanks for persevering.
I've left some minor notes but nothing big.
One interesting thing I noticed when exploring the tests is that Diff
objects behave like arrays in some ways, but are not arrays. There are a lot of test assertions that abuse this and compare tuples with diff objects, e.g. [ DIFF_EQUAL, "" ] === new Diff( DIFF_EQUAL, "" )
. If we replace the array shorthand with Diff
object creation, then we can replace the recursive equality check function with deepEqual
.
It's a result of a change that was made years ago; the diff used to be an array, google changed it to an object. The tests haven't changed since then. For this PR, I want the absolute minimal changes to get it on NPM - perhaps log that as a new issue? |
…JackuB/diff-match-patch. Swap to ESM. Fixes dmsnell#3. Co-authored-by: Jon Surrell <[email protected]>
Co-authored-by: Jon Surrell <[email protected]>
@dmsnell I have a github action that will run the node tests, and it's path constrained so it won't run for other changes. Do you want me to save that for a new PR? 🤔 code: https://github.com/TheSpyder/diff-match-patch/blob/add-ci/.github/workflows/javascript.yml |
Yeah @TheSpyder let's suggest those CI runs in a separate PR. Bravo! Thank you for staying persistent with this. https://www.npmjs.com/package/@dmsnell/diff-match-patch Feel free to start using it, and let's continue making it better! |
Fantastic! thank you! I forgot to add a readme, might put that in with CI. It will be easier for my team to use with types, I might make two PRs 🫣 |
Fixes #3
The basics should make sense but there are some possibly unexpected changes:
@dmsnell/diff-match-patch
because https://github.com/JackuB/diff-match-patch took the top-leveldiff-match-patch
name on NPM. Feel free to rename it.I'd like to also add the types from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/diff-match-patch but they're technically MIT. The types are very simple, and there's probably no legal issue with copying them, but I don't know if you want to deal with potentially mixed licensing 🤔