Fetch properties of your project's
package.json
at compile time.
pkg.macro allows you to turn pkg(["name", "version"])
into
{ name: "your-package", version: "1.0.0" }
as a build time constant.
installation
yarn add --dev pkg.macro
Make sure you also have [Babel][babel] and [babel-plugin-macros][babel-plugin-macros] installed:
yarn add --dev @babel/cli @babel/core babel-plugin-macros
... and configured with Babel:
moduleexports = presets: plugins: "babel-plugin-macros"
usage
const props =
The above is transformed to:
const props = name: "your-package" version: "1.0.0" scripts: test: "test-script" dependencies: "some-package": "1.0.0"
see also
- param.macro – macro for partial application, inspired by Scala's
_
& Kotlin'sit
development
- Clone the repo:
git clone https://github.com/citycide/pkg.macro.git
- Move into the new directory:
cd pkg.macro
- Install dependencies:
yarn
ornpm install
- Build the source:
yarn build
ornpm run build
- Run tests:
yarn test
ornpm test
contributing
Pull requests and any issues found are always welcome.
- Fork the project, and preferably create a branch named something like
feat-make-better
- Follow the build steps above but using your forked repo
- Modify the source files in the
src
directory as needed - Make sure all tests continue to pass, and it never hurts to have more tests
- Push & pull request! 🎉
license
MIT © Bo Lingen / citycide