NordicSemiconductor / nrf-intel-hex

Yet another parser for "Intel HEX" files.
BSD 3-Clause "New" or "Revised" License
27 stars 8 forks source link

Change format for browser module to umd. #11

Closed arekzaluski closed 6 years ago

arekzaluski commented 6 years ago

Hi @IvanSanchez . Great tool. I'm interested in using it but I have few questions that I hope you will be able to answer.

  1. It's difficult to import it in other libraries when format is set to iife. Isn't it better to change it to umd?
  2. Is there a plan to add TypeScript support ?
CLAassistant commented 6 years ago

CLA assistant check
All committers have signed the CLA.

IvanSanchez commented 6 years ago

Hey,

It's difficult to import it in other libraries when format is set to iife.

Well, the rationale is that browsers like UMD, and module bundlers like ES modules (because they look at the module property in package.json). Before providing a UMD build, I'm curious about which build toolchain are you using. Perhaps you're overlooking something that would make the build work with the ES modules.

Is there a plan to add TypeScript support ?

No.

Feel free to send a PR with some typings, though. But don't expect much in terms of maintenance if the API changes (new method or whatever).

arekzaluski commented 6 years ago

Thank you for quick answer. My library is written in Typescript and is using typescript-compiler. It has support for both Node.js and web. The problem I'm having is that web version is using intel-hex.browser.js which does not export any module inside when format is set to iife. That way I can't import or require it.

IvanSanchez commented 6 years ago

The problem I'm having is that web version is using intel-hex.browser.js

Wait, what?

I'm reading through https://www.typescriptlang.org/docs/handbook/module-resolution.html , and I can't see any indication that typescript uses the browser field in package.json to fetch the module code. Are you pulling intel-hex.browser.js manually somehow?

If you are writing import MemoryMap from 'nrf-intel-hex', then typescript should fetch the file pointed by the module field of package.json, and then let the typescript tools handle the output wrapper format (as per the -m option in https://www.typescriptlang.org/docs/handbook/compiler-options.html ). Typescript should be able to understand and transpile ES6 module syntax, like https://github.com/NordicSemiconductor/nrf-intel-hex/blob/b67c4cd16055d60f0d4c8c3cbee768374204c717/intel-hex.js#L939

If typescript is somehow using the browser field of the package.json file of the nrf-intel-hex module, then there's definitely something fishy (and undocumented) going on.

arekzaluski commented 6 years ago

I should be more specific. I'm using browserify - http://browserify.org/ to build web dependencies.

IvanSanchez commented 6 years ago

Oh, so then the problem is that browserify does use the browser field, and it fails to bundle a iife module. Now that makes sense!!

(I still suggest you to look into making typescript output a browser bundle. I myself am a fan of RollupJS, which works wonderfully for this kind of bundling)

arekzaluski commented 6 years ago

Thanks, I'll take a look into adding TypeScript support.