Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fixes node esm consumption of pro-gallery library which is required to run in modern front-end framework. The fixing esm consists of:
Adding explicit file extensions on every import( import ... from './file' -> import ... from './file.js') (Mandatory file extensions)[https://nodejs.org/api/esm.html#mandatory-file-extensions]
This could be done in too ways: changing the source or changing the build output. But as pro-gallery uses tsc directly
there is no possibility to modify build output.
Dropping directory imports (
import ... from './utils'
->import ... from '/utils/index.js'
)Adding 'exports' field in package json to help node find cjs & esm builds (doc)[https://nodejs.org/api/packages.html#exports]. The 'main' and 'module' fields are recognized only by bundlers, node ignores them. Using
exports
field in root package json is only way to have esm & cjs builds in one packageAdding package.json with 'type: module' in esm dist folder. Node has to know the file module type before executing it and there are too posibilities:
a. having explicit file extensions
cjs
&mjs
.b. if the file ending is
js
it will decide by looking into nearest package.json and check itstype
field. If thetype
is equal tomodule
it will interpret alljs
endings in the directory asmjs
and will fallback tocjs
in any other case (doc)[https://nodejs.org/api/esm.html#enabling]Few other things had to be done:
Its very complicated to make ts-node work with esm (its used in unit tests mainly), thus I've replaced it with tsx library. And tsx can't be loaded with mock in node-16, so the bump to node-18 had to be done.
validator build was creating mixed umd/cjs/es6 module which node doesn't support. Dropped all the transpilation with borwserify, because the library itself is provided non-minified, this should not make problems for consumers.
added
ts-jest-resolver
for jest specs so it would resolve files in typescript as typescript iteself does (allowing to import with 'js' extension even though the actual files in source directory havets
extension.