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

Add transpiled ES Module build with microbundle #9

Merged
merged 5 commits into from
Feb 8, 2019
Merged

Add transpiled ES Module build with microbundle #9

merged 5 commits into from
Feb 8, 2019

Conversation

romanzoller
Copy link

  • Add module entrypoint (index.js)
  • Use whitelist of files (/src, /dist/sources.*) instead of .npmignore
  • Add build target using microbundle and rename existing example builds

See geoblocks/base#4

- Add module entrypoint (index.js)
- Use whitelist of files (/src, /dist/sources.*) instead of .npmignore
- Add build target using microbundle and rename existing example builds

See geoblocks/base#4
@@ -1,4 +1,5 @@
/node_modules/
/package-lock.json
/dist/api
/dist/main.js
/dist/main.*
/dist/sources.*
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not just /dist/?

Copy link
Author

@romanzoller romanzoller Feb 4, 2019

Choose a reason for hiding this comment

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

Because dist/index.html is (and was already before) part of the git source, it's the example entry point, so it should not be ignored. Ideally it should not be in dist IMHO, I can change that in a follow-up PR if you agree.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 :-)

"doc": "typedoc --out dist/api --theme minimal --readme none --hideGenerator --listInvalidSymbolLinks --toc none"
},
"files": [
"/src",
"/dist/sources.*"
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not just /dist?

Copy link
Author

Choose a reason for hiding this comment

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

Same here, /dist/index.html and /dist/main.js[.map] are example / example build files that don't need to be included in the npm package.

package.json Outdated
"start": "webpack-dev-server --mode development --content-base dist/ --watch",
"typecheck": "tsc --pretty",
"lint": "npm run eslint && npm run typecheck",
"test": "npm run lint && npm run build && npm run build-debug",
"test": "npm run lint && npm run build-example && npm run build-example-debug",
Copy link
Contributor

Choose a reason for hiding this comment

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

In order for the microbundle build to be tested by travis, you should also add it here, right?

Copy link
Author

@romanzoller romanzoller Feb 4, 2019

Choose a reason for hiding this comment

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

Yes, good point, I added it.

package.json Show resolved Hide resolved
@gberaudo
Copy link
Contributor

gberaudo commented Feb 4, 2019

@romanzoller, I pushed a commit to make "npm link" work.

@gberaudo
Copy link
Contributor

gberaudo commented Feb 4, 2019

@romanzoller, the code is still importing proj directly from the src files. You need to change that tp benefit from your changes in @geoblocks/proj.

So I did:

diff --git a/src/Swisstopo.js b/src/Swisstopo.js
index 9240e56..f9f8a37 100644
--- a/src/Swisstopo.js
+++ b/src/Swisstopo.js
@@ -1,7 +1,7 @@
 import olSourceWMTS from 'ol/source/WMTS.js';
 import olTilegridWMTS from 'ol/tilegrid/WMTS.js';
-import EPSG_2056 from '@geoblocks/proj/src/EPSG_2056.js';
-import EPSG_21781 from '@geoblocks/proj/src/EPSG_21781.js';
+import {EPSG_2056} from '@geoblocks/proj';
+import {EPSG_21781} from '@geoblocks/proj';
 
 
 /**

Then ran npm run start but it failed.

I think the reason is that:

  • I am using npm link;
  • I did not build the proj repo;
  • webpack is resolving the import to @geoblocks/proj/dist/proj.js due to the module entry and it does not exist.

If I build the proj project I guess it will succeed but then updating a proj file will not live reload the code anymore. Do you see a solution that keeps npm link working?

@romanzoller
Copy link
Author

the code is still importing proj directly from the src files. You need to change that tp benefit from your changes in @geoblocks/proj.

This should not be required, I was trying to make only minimal changes in order to get things merged asap. The changes in @geoblocks/proj are only relevant for using proj somewhere else, we should be able to keep importing source files here.

See also https://github.com/camptocamp/ti-oerebviewer/pull/67/commits/f48961ac480a766272d4ae0164c37119a983e2d0 about npm link, I think the easiest way to get around the npm link mess would be to publish new versions of geoblocks/proj and geoblocks/sources.

@gberaudo
Copy link
Contributor

gberaudo commented Feb 4, 2019

@romanzoller, you are using the source here: https://github.com/camptocamp/ti-oerebviewer/pull/67/files#diff-ef47f283833c2e4c42778c3038ed1278L6. Since it depends on the non-transpiled ES6 sources from proj it will not fix your IE11 issue, right?

@gberaudo
Copy link
Contributor

gberaudo commented Feb 4, 2019

@romanzoller, I think having paths pointing to dist in the package.json we commit to github is wrong. We should (in @geoblocks/proj):

  • use module: src/index.js in the commited package.json;
  • modify it to module: dist/proj.js in the published package.json.

@gberaudo
Copy link
Contributor

gberaudo commented Feb 5, 2019

@romanzoller, @sbrunner, @fredj, would you be interested in a small (?) meeting this afternoon to:

  • discuss the status of Roman's PRs;
  • what works, what does not work yet;
  • take the decisions/compromise we need to accomodate all use cases (Ngeo, Ng-cli, geoblock, ...)

@romanzoller
Copy link
Author

Since it depends on the non-transpiled ES6 sources from proj it will not fix your IE11 issue, right?

You are technically right, but I was lucky, because in geoblocks/sources, only 2 strings are imported from geoblocks/proj, so there is nothing that breaks IE11. I guess I should change it anyway.

I think having paths pointing to dist in the package.json we commit to github is wrong. We should (in @geoblocks/proj):

  • use module: src/index.js in the commited package.json;
  • modify it to module: dist/proj.js in the published package.json.

Pointing to dist for files that are built and included in the package published on npm is perfectly normal IMHO.

Unfortunately the meaning of "module" is only documented in a proposal and not standardized (yet), but I think your problem would be solved best by setting "modules.root": "src" as described here.

would you be interested in a small (?) meeting this afternoon

Sure!

@gberaudo
Copy link
Contributor

gberaudo commented Feb 7, 2019

@romanzoller, you need to release a geoblocks/proj package on npm and test it here.
You also need to change the imports here:

import EPSG_2056 from '@geoblocks/proj/src/EPSG_2056.js';
import EPSG_21781 from '@geoblocks/proj/src/EPSG_21781.js';

Please also add the "geoblocks_src: src/index.js" entry in package.json and I think it will be ready for merging.

@gberaudo
Copy link
Contributor

gberaudo commented Feb 7, 2019

Since it depends on the non-transpiled ES6 sources from proj it will not fix your IE11 issue, right?

You are technically right, but I was lucky, because in geoblocks/sources, only 2 strings are imported > from geoblocks/proj, so there is nothing that breaks IE11. I guess I should change it anyway.

I think it was even more luck as the registration of the projection is done as a side effect of the import.
It was luck that this code does not use (yet! ;)) some ES6 sugar.

@romanzoller
Copy link
Author

romanzoller commented Feb 7, 2019

you need to release a geoblocks/proj package on npm and test it here.

done 👍

Please also add the "geoblocks_src: src/index.js" entry in package.json and I think it will be ready for merging.

@gberaudo I don't really understand this part... Would you then remove the "source" entry? Is it causing any problems? And what is the purpose of adding "geoblocks_src"?

@gberaudo
Copy link
Contributor

gberaudo commented Feb 7, 2019

@romanzoller,

  • we should remove the source entry because people does not understand it is non standard;
  • we should add a "geoblocks_src" entry so that people wanting to transpile themselves can point to the sources.

@romanzoller
Copy link
Author

Well, it's not standard, but it's used by microbundle, parcel, and maybe others, and might be standard in the future, whereas "geoblocks_src" is used by nobody and will for sure never be a standard, and (AFAIK) is also not necessary if you want to include sources in another project, you could already do that before without any "source" or "geoblocks_src" field and you can still do it now that "source" is there.

@gberaudo
Copy link
Contributor

gberaudo commented Feb 8, 2019

@romanzoller, I checked parcel and found it has 3 ways of using the source entry: https://en.parceljs.org/transforms.html#third-party-modules
Microbundle only recognize one, when the value is a path to a single file.
It makes even clearer my point that if something is not standard, relying on it will bring issues.

That is why I ask we use a custom entry for the geoblocks project that no one else will use inadvertently, and which semantics we can define clearly: geoblocks_src points to a single file entry point of standard Ecmascript (no esnext, no proposal, only the rock solid standard).

Regarding your second point:

if you want to include sources in another project, you could already do that before without any "source" or "geoblocks_src" field

In an application A, how would you depend on source version of the source and proj geoblocks without those fields? My understanding is that even if you import @geoblocks/source/src/Swisstopo.js that block depends on the transpiled @geoblocks/proj so it would not work like you expect.

@romanzoller
Copy link
Author

romanzoller commented Feb 8, 2019

In an application A, how would you depend on source version of the source and proj geoblocks without those fields? My understanding is that even if you import @geoblocks/source/src/Swisstopo.js that block depends on the transpiled @geoblocks/proj so it would not work like you expect.

Do you mean something like this? (tested and works in an empty temp folder, no "geoblocks_src" in the latest @geoblocks/proj)

npm i @geoblocks/proj esm proj4 ol
node -r esm
> import EPSG_2056 from '@geoblocks/proj/src/EPSG_2056';
undefined
> EPSG_2056
'EPSG:2056'

@gberaudo
Copy link
Contributor

gberaudo commented Feb 8, 2019

No, I am saying:

A

import Swisstopo from '@geoblocks/source/src/Swisstopo.js';
import EPSG_2056 from '@geoblocks/proj/src/EPSG_2056'.js;

My understanding is that in this snippet the @geoblocks/proj code is included 2 times:

  • as a transpiled dependency of @geoblocks/source (since source depends on the microbundle version of proj);
  • as a source dependency (since we directly import it from A).

The only way to avoid this is to have weback use entries like `geoblocks_src'.

No need to change anything with microbundle, it turns out that it
already looks for ./src/index.js or ./index.js (in that order)
by default.
@romanzoller
Copy link
Author

Ok, thank you for the explanations @gberaudo, I added a commit => good to merge?

@romanzoller romanzoller merged commit 8af650d into geoblocks:master Feb 8, 2019
@romanzoller romanzoller deleted the transpiled-build branch February 8, 2019 14:32
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.

3 participants