utils
Utility functions and helpers for internal usage.
Install
yarn add --dev @tunnckocore/utils
Usage
Useful for monorepo and non-monorepo setups, usually used for passing to module resolver options like the babel-plugin-module-resolver
and eslint-import-resolver-babel-module
.
If in monorepo setup, it will pick up the packages/
or whatever you defined on lerna.json
's packages
field, or the package.json
's yarn workspaces
field. If you don't have those defined, then it will return alias: {}
and the default extensions list.
const { createAliases, getWorkspacesAndExtensions } = require('@tunnckocore/utils');
const result = createAliases(process.cwd());
If you have lerna.json
(or workspaces
field in your package.json
) with ['packages/*', '@tunnckocore/*']
then you can do the following
const { getWorkspacesAndExtensions } = require('@tunnckocore/utils');
console.log(getWorkspacesAndExtensions(process.cwd()));
If you want to support different extensions, pass extensions
field in your root package.json
.
Example
Make sure you also have eslint-import-resolver-babel-module
installed.
For example, in your .eslintrc.js
file you can do the following
const proc = require('process');
const { createAliases } = require('@tunnckocore/utils');
const config = require('my-eslint-config');
module.exports = {
...config,
settings: {
...config.settings,
'babel-module': createAliases(proc.cwd() ),
},
};