Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@tunnckocore/utils

Package Overview
Dependencies
Maintainers
1
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tunnckocore/utils

Utility functions and helpers for internal usage

  • 0.3.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
10
Maintainers
1
Weekly downloads
 
Created
Source

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' */),
  },
};

Keywords

FAQs

Package last updated on 11 Aug 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc