JSPM

  • Created
  • Published
  • Downloads 4
  • Score
    100M100P100Q57669F
  • License MPL-2.0

Utility functions and helpers for internal usage

Package Exports

  • @tunnckocore/utils

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@tunnckocore/utils) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

utils

Utility functions and helpers for internal usage.

npm version Mozilla Public License 2.0 Keybase Twitter Become a Patron

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());

// => {
//   cwd,
//   alias: {},
//   extensions: ['.js', '.jsx', '.ts', '.tsx', '.mjs'],
//   exts: ['js', 'jsx', 'ts', 'tsx', 'mjs'],
// }

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()));
// => {
//   workspaces: ['packages', '@tunnckore'],
//   extensions: ['.js', '.jsx', '.ts', '.tsx', '.mjs'],
//   exts: ['js', 'jsx', 'ts', 'tsx', 'mjs'],
// }

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,

    // by default we assuome your source code is in the package root's src/ dir
    // if you have annother structure pass the name of your source directory.
    'babel-module': createAliases(proc.cwd() /* , 'source' */),
  },
};