assemblyscript icon indicating copy to clipboard operation
assemblyscript copied to clipboard

Make loader more compatible with plain ESM

Open trusktr opened this issue 4 years ago • 5 comments

This makes it possible to also write import {...} from "@assemblyscript/loader/index.js". Some people need to write this because some tools (for example TypeScript compiler) do not yet understand how to read the exports field from package.json. These tools that don't know exports will work fine with paths like "@assemblyscript/loader/index.js", regardless if there's an exports field or not.

However, without adding this line, the same code that imports from "@assemblyscript/loader/index.js" will not work in a system that uses Node ESM (Node or Webpack) and they will throw an error that index.js exists but it is not exported therefore not importable.

TLDR: this allows us to write code that works in more places.

⯈ ⯈ ⯈

  • [ ] I've read the contributing guidelines

trusktr avatar Feb 22 '21 03:02 trusktr

Adding to the commit message, the error people will currently get if they import from @assemblyscript/loader/index.js is ERR_PACKAGE_PATH_NOT_EXPORTED.

trusktr avatar Feb 22 '21 03:02 trusktr

For now, I published this fork of AS Loader at http://npmjs.com/@lume/as-loader so we can use it in lume/glas.

trusktr avatar Feb 22 '21 06:02 trusktr

Iirc there is a fallback notation to allow this, for everything that isn't otherwise defined. Something involving forwards to *.js or so, don't remember exactly.

dcodeIO avatar Feb 22 '21 16:02 dcodeIO

Yeah, that format would be "./*": "./*" if you want to unblock everything. Also useful for like when you have a dist/ folder and want to make the dist/ folder not part of the import path: "./*": "./dist/*" so import from foo/some/file.js would actually import from foo/dist/some/file.js, but note that this re-mapping to omit folders breaks compatibility with any tools that don't know exports.

trusktr avatar Feb 23 '21 06:02 trusktr

I'm still using this fork in lume/glas. I'll circle back around to clean this up...

trusktr avatar Aug 16 '21 16:08 trusktr

This PR has been automatically marked as stale because it has not had recent activity. It will be closed in one week if no further activity occurs. Thank you for your contributions!

github-actions[bot] avatar Dec 06 '23 23:12 github-actions[bot]

This PR has been automatically closed due to lack of recent activity, but feel free to reopen it as long as you merge in the main branch afterwards.

github-actions[bot] avatar Dec 14 '23 23:12 github-actions[bot]