mxgraph icon indicating copy to clipboard operation
mxgraph copied to clipboard

NPM publishing

Open lgleim opened this issue 8 years ago • 34 comments

The current package published to NPM is seriously broken.

Based on your publishing script, what you are publishing to NPM here is the full mxgraph distribution. That is all source code, all build files, all resources in all languages. Additionally the package.json incorrectly contains webpack, grunt etc. as dependencies instead of devDependencies. Thus installing just the mxgraph package as a dependency in a newly created empty folder results in a total of 92 MB of files.

The package.json further defines "main": "./javascript/dist/build.js" to be the entry point of the package. The dist folder is however excluded through the .gitignore file. Thus the mxgraph library actually cannot be included from npm in its current form - the package is broken. The github repository recently received a .npmignore file (https://github.com/jgraph/mxgraph/commit/78a73184b0fd0fcb138bc8ba425d47047282faa6) which mitigates this issue, this is however not in the bitbucket repository yet (although referenced in the deploy script).

Your build script actually also pushes the js code to a separate mxgraph-js repository. This looks a bit more like what an npm package should contain but is also incompatible with npm usage. In order to be compatible with your documentation, the main file should include the UMD loader code you add during the grunt build process. Nevertheless it is of course a cleaner solution to directly publish to npm from the original code.

In order to fix these issues I created a fork with a single additional commit on bitbucket: https://bitbucket.org/lgleim/mxgraph2

Unfortunately I cannot create pull requests there and the github repo has a somewhat different structure.

Since I am not familiar with all the other requirements to be fulfilled in order to execute the build.sh script, I was not able to test the code with your build script. The build does complete successfully with the following steps:

git clone [email protected]:lgleim/mxgraph2.git
cd mxgraph2
sed "s/@VERSION@/3.9.2/" etc/build/mxgraph-package.json > package.json
npm install
# npm publish

So I kindly ask you to review and manually merge my patch and (hopefully) to subsequently publish a working version of mxgraph to the npm registry.

lgleim avatar Feb 28 '18 18:02 lgleim

Thanks, I'll pull the changes in and release. Please that we don't use NPM, so we'll just pull in your changes and release as-is without testing.

davidjgraph avatar Feb 28 '18 20:02 davidjgraph

Thanks for the quick reaction. Unfortunately the buildstep still seems to fail. It appears that mxgraph-distro.zip does not actually contain all the required source files.

I guess they might be there after the code moving/copying/juggling logic in line 49-60 of deploy.sh. However again, I cannot test it.

So in order to clear things up a bit - is there a reason not to simply do the following to publish?

git clone [email protected]:jgraph/mxgraph2.git
cd mxgraph2
sed "s/@VERSION@/3.9.2/" etc/build/mxgraph-package.json > package.json
npm install
npm publish  --access public

Or alternatively following the current clone step:

cd mxgraph
sed "s/@VERSION@/$DOTVERSION/" $BUILD/../etc/build/mxgraph-package.json > package.json
npm install
npm publish  --access public

This could also be a chance to clean up the current deploy process a bit.

lgleim avatar Mar 01 '18 10:03 lgleim

In the spirit of harmonization I also created pull request https://github.com/jgraph/mxgraph/pull/170 for the github repo to include the proper .npmignore

lgleim avatar Mar 01 '18 11:03 lgleim

I'll pull anything we're given. Neither of us have any understanding of NPM, as long as it doesn't break it for us, you guys can break it as many times as you like :).

davidjgraph avatar Mar 01 '18 11:03 davidjgraph

Allright - is there a reason for the complicated deployment procedure of mxgraph-js? Is that package used at all? To me it actually rather adds to the confusion...

lgleim avatar Mar 01 '18 11:03 lgleim

Some users requested it.

davidjgraph avatar Mar 01 '18 11:03 davidjgraph

Allright. I'll try hard to not break anything.

lgleim avatar Mar 01 '18 11:03 lgleim

Do you rebuild the entire mxgraph repository on purpose during each build? In order to avoid divergence between the repositories?

lgleim avatar Mar 01 '18 11:03 lgleim

It's a master/slave arrangement, yes. This is how it evolved historically. Bitbucket was the only repo and closed source. Then we open sourced and pushed out the open source version on each release from BB to GH. I know there's options to use CI to build on a push to a repo, but, as I say, the build/deploy isn't broken for us and there's no resources for a re-work.

davidjgraph avatar Mar 01 '18 11:03 davidjgraph

I understand how these things evolve. In order to not break the pull request workflow in the future - how do you merge pull requests to the open source variant into your private repo? Allways manually?

lgleim avatar Mar 01 '18 11:03 lgleim

It's not private any more, https://bitbucket.org/jgraph/mxgraph2, I think submitting a PR should be possible on BB.

davidjgraph avatar Mar 01 '18 11:03 davidjgraph

In that case - how about just keeping both repositories synchronized?

lgleim avatar Mar 01 '18 11:03 lgleim

then we'd have noise like this NPM stuff in the root of our repo, that's not happening :)

davidjgraph avatar Mar 01 '18 13:03 davidjgraph

Alright, I think this will likely keep being a pain point for you in the future though.

I restructured the deploy script (basically no changes, just reordering lines) in a way that should finally fix the npm build without changing anything else.

Please find the patch in my fork: https://bitbucket.org/lgleim/mxgraph2

lgleim avatar Mar 01 '18 16:03 lgleim

I just noticed that there was one too many exclusion in the .npmignore. Updated my repo accordingly.

lgleim avatar Mar 01 '18 16:03 lgleim

By the way - the settings of your bitbucket repository do not allow to submit public pull requests.

lgleim avatar Mar 02 '18 12:03 lgleim

Not sure about BB, my understanding was anyone with read access can submit a PR, but I could be wrong. I've deployed, does it work now?

davidjgraph avatar Mar 05 '18 17:03 davidjgraph

Regarding BB: Unfortunately not. I cannot create pull requests there.

Regarding redeployment: Also Unfortunately not. While you included parts of my changes to the deploy script, the relevant restructuring of the deployment process and what is published to npm did not make it into your code base. The changes still missing in the current version of your deploy script are directly apparent in a side-by-side diff. Nevertheless, I was still not able to test the script.

Edit: updated link to diff to reflect changes from comment below

lgleim avatar Mar 06 '18 10:03 lgleim

And just now I noticed another issue with the .npmignore file, which is that it will never be copied over by the cp -rf tmp/mxgraph/* mxgraph/ command, since it is a hidden file. Thus an additional change is required. C.f. resulting side-by-side diff

lgleim avatar Mar 06 '18 10:03 lgleim

@davidjgraph any updates on this issue? Is it fixed?

I am using mxgraph version 3.9.3.

But when i tried to run ng serve , I get error as follows:

Module not found: Error: Can't resolve 'mxgraph' in 'path to my file where I have imported and used mxgraph'

ViksYelapale avatar Apr 19 '18 16:04 ViksYelapale