1Password / op-js

A JS library powered by the 1Password CLI
https://developer.1password.com/docs/cli
MIT License
91 stars 8 forks source link

Explicitly set CJS format, inputs when compiling #154

Closed jodyheavener closed 1 year ago

jodyheavener commented 1 year ago

Fixes https://github.com/1Password/op-js/issues/153

In #152 we stopped bundling all dependencies in the package. As it turns out, bundling was ensuring an all-CJS format and it was incorporating not only external deps but relative files. By removing bundling and not explicitly marking the format as CJS we inadvertently introduced ESM syntax and omitted relative files. More info here.

When the platform is set to node:

  • When bundling is enabled the default output format is set to cjs, which stands for CommonJS (the module format used by node). ES6-style exports using export statements will be converted into getters on the CommonJS exports object.

This package doesn't support ESM yet (at least not intentionally), so this PR:

Testing

You can test that this fix works by first cloning and setting up this repo:

git clone git@github.com:1Password/op-js.git
cd ./op-js && git checkout jh/fix-cjs
yarn && yarn build

Then you can also clone this test repo I set up:

git clone git@github.com:jodyheavener/tmp-opjs-test.git
cd ./tmp-opjs-test 
yarn && yarn start

This test repo has the op-js codebase symlinked as a dependency, so if you've built it locally everything should be working as expected. By comparison, if you were to repeat these steps in the op-js repo on main, it should fail.