-
Notifications
You must be signed in to change notification settings - Fork 199
chore: improve the configuration to build the npm package #87
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
Conversation
Root and all package.json files
- Fix license, version and authors
- Remove the non-relevant .npmignore file at the project. It was designed for mxgraph, the whole directory structure
changed, and we don't plan to publish the root package
`core` package
- Generate type definition and javascript files for ESM output
- dedicated folder for `esm` and `types` in the `dist` folder to clearly separate concerns
- exported in the package.json
- Add npm script for `npm pack` configuration
- Drop the `postinstall` npm script that built the `core` bundle. It would have been run when the package is installed
in dependent projects at dependencies install. And it would have failed as it tries to build the project from TypeScript
sources that are not available in the npm package.
fix: ConstraintHandler now loads image as everywhere else in the code using `Client.imageBasePath`
Using import doesn't work as the image is not available in the npm package. It generated error like this in ViteJS
project:
Failed to resolve import "../../../images/point.gif" from "../core/dist/esm/view/handler/ConstraintHandler.js". Does the file exist?
This gif import had been introduced to make `Anchors.stories.js` retrieve the gif file. Configuring `imageBasePath` as
already done in other stories fixes the issue.
Don't export EditorCodec and StylesheetCodec as they generate errors.
This is a temporary solution to avoid error in dependent project (at least, with ViteJS projects).
Let test the mxgraph core npm package in a TypeScript project. This ensures that the types and the esm code is correctly configured in the package and available for integration.
Drop npm scripts in the root package.json file that only apply to the `core` package
48c5258 to
e5b3756
Compare
|
Great work! I agree with the gif import removal. I don't know what I was thinking... |
Thanks, I am still working on testing the package with other bundler/build-tools to have a more complete coverage.
About Vite, I choose it here because it allows to check the npm package in 2 ways
It also provides a lot of features not needed here (CSS modules, JSX/TSX, ...) with convenient defaults and a large plugins ecosystem. I like it also for simple project and prototyping because the default configuration lets you start very quickly (a single html page and an JS/TS file) |
…tead of relative paths
|
Hi all, today I have been able to test the npm package produced by this Pull Request in an external repository: https://github.com/tbouffard/maxgraph-integration-examples. I have been able to use the npm package in TypeScript projects built with Parcel, Rollup and ViteJS. I planned to add more integration projects in the future, but IMHO, the 3 existing projects already show that the integration is working. During the tests, I have seen some problems with existing function signatures and types, but I won't list them all here. I will create issues or Pull Requests to try to fix them later. There are some comments in the code of my repository. I have detected some issues on the generated types, that require the TS projects set I put this Pull Request in review; I consider this is a good first step to let people built the package locally and test it in their project. Generated types errors> @maxgraph/ts-example-built-with-vite@0.0.0 build > tsc && vite build |
|
cc @lalicw, @Seebiscuit, @wrw1997, @cd-yang for testing as you noticed interest for a relase or the npm package |
- custom shapes - activate rubberband - panning and overflow hidden - bump vite to 2.9.12
| * Contains the current version of the maxGraph library. | ||
| */ | ||
| static VERSION = '4.2.2'; | ||
| static VERSION = '0.1.0'; |
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.
ℹ️ in the future, we will automate the value update during release
|
I am going to merge this Pull Request to let people build the npm package locally and test it in their projects. |
Root and all package.json files
changed, and we don't plan to publish the root package
corepackageesmandtypesin thedistfolder to clearly separate concernsnpm packconfigurationpostinstallnpm script that built thecorebundle. It would have been run when the package is installedin dependent projects at dependencies install. And it would have failed as it tries to build the project from TypeScript
sources that are not available in the npm package.
fix: ConstraintHandler now loads image as everywhere else in the code using
Client.imageBasePathUsing import doesn't work as the image is not available in the npm package. It generated error like this in ViteJS
project:
Failed to resolve import "../../../images/point.gif" from "../core/dist/esm/view/handler/ConstraintHandler.js". Does the file exist?
This gif import had been introduced to make
Anchors.stories.jsretrieve the gif file. ConfiguringimageBasePathasalready done in other stories fixes the issue.
Don't export EditorCodec and StylesheetCodec as they generate errors.
This is a temporary solution to avoid error in dependent project (at least, with ViteJS projects).
closes #84
Notes
This contribution is done under the terms of the Apache 2.0 license as stated in https://www.apache.org/licenses/LICENSE-2.0.
How to use
Run
npm installnpm packcorefolder or the packagetgzfile in an external project (usingnpm linkornpm install)Testing project
This Pull Request initially add a TypeScript integration example built with ViteJS.
It allows testing the maxgraph core npm package in a TypeScript project. This ensures that the types and the esm code is correctly configured in the package and available for integration.
I don't know if we should keep this project in the repository or if it deserves its own repository. Feel free to comment about it.
About the gif import removal
The gif import was introduced to fix the Anchors example in b2bb10e#diff-1ef320fff9bb7fc4d6aa19a32348357901420e1724b8288d9a22f1f51fad34cc
Restoring the original
Client.imageBasePathusage only required to configure the value in the story.Commented exports
EditorCodec and StylesheetCodec are no more exported. I will test the package with a Rollup project and probably with other build tools/bundlers to see if they have issues when these 2 classes are exported.
In the meantime, if you find a way to restore the exports, feel free to comment.