@environment-safe/package
v0.2.0
Published
Import package data in a uniform way across commonjs/modules and node/browser
Downloads
57
Readme
@environment-safe/package
This normalizes the difference for local inclusion of package.json whether in node or the browser with no build.
Babel will merrily pass this through, while browsers won't. If you want source execution in both environments without build, there is no option. That's where this comes in.
Usage
Using modules
import { getPackage } from '@environment-safe/package';
(async ()=>{
const package = await getPackage();
//do something with the package here
})()
Using commonjs
const { getPackage } = require('@environment-safe/package');
(async ()=>{
const package = await getPackage();
//do something with the package here
})();
Testing
Run the es module tests to test the root modules
npm run import-test
to run the same test inside the browser:
npm run browser-test
to run the same test headless in chrome:
npm run headless-browser-test
to run the same test inside docker:
npm run container-test
Development
All work is done in the .mjs files and will be transpiled on commit to commonjs and tested.
If the above tests pass, then attempt a commit which will generate .d.ts files alongside the src
files and commonjs classes in dist