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 - npm Package Compare versions

Comparing version 0.4.1 to 0.5.0

CHANGELOG.md

44

package.json
{
"version": "0.4.1",
"version": "0.5.0",
"name": "@tunnckocore/utils",
"description": "Utility functions and helpers for internal usage",
"description": "Thin layer on top of `execa` that allows executing multiple commands in parallel or in sequence with control for concurrency",
"author": "Charlike Mike Reagent <opensource@tunnckocore.com>",
"homepage": "https://github.com/tunnckocorehq/hela",
"homepage": "https://github.com/tunnckoCore/opensource",
"license": "MPL-2.0",
"licenseStart": 2019,
"main": "src/index.js",
"module": "src/index.js",
"types": "dist/types/index.d.ts",
"scripts": {},

@@ -14,21 +17,38 @@ "publishConfig": {

},
"engines": {
"node": ">=8.11"
},
"repository": {
"type": "git",
"url": "https://github.com/tunnckoCoreHQ/hela.git",
"url": "https://github.com/tunnckoCore/opensource.git",
"directory": "@tunnckocore/utils"
},
"files": [
"src"
"dist"
],
"keywords": [
"tunnckocorehq",
"devest",
"hela",
"jest",
"env",
"develop",
"utils"
"parallel",
"series",
"concurrency",
"sequence",
"exec",
"child",
"process",
"execute",
"fork",
"execfile",
"execa",
"spawn",
"file",
"shell",
"bin",
"binary",
"binaries",
"npm",
"path",
"local"
],
"dependencies": {},
"devDependencies": {}
"gitHead": "cdd74cf426c386836697113bf2865b3eabccf886"
}

@@ -1,10 +0,18 @@

'use strict';
const fs = require('fs');
const path = require('path');
const Module = require('module');
module.exports = { createAliases, getWorkspacesAndExtensions };
// eslint-disable-next-line no-underscore-dangle
const EXTENSIONS = Object.keys(Module._extensions).filter(
(x) => x !== '.json' && x !== '.node',
);
/* eslint-disable global-require, import/no-dynamic-require */
module.exports = { createAliases, getWorkspacesAndExtensions, isMonorepo };
function isMonorepo(cwd = process.cwd()) {
const { workspaces } = getWorkspacesAndExtensions(cwd);
return workspaces.length > 0;
}
/**

@@ -19,5 +27,7 @@ * Create explicit alias key/value pair from the current

*/
function createAliases(cwd, sourceDir) {
const { workspaces, extensions, exts } = getWorkspacesAndExtensions(cwd);
const alias = workspaces
function createAliases(cwd = process.cwd(), sourceDirectory) {
// const { workspaces, extensions, exts } = getWorkspacesAndExtensions(cwd);
const result = getWorkspacesAndExtensions(cwd);
const alias = result.workspaces
.filter(Boolean)

@@ -29,12 +39,19 @@ .reduce((acc, ws) => {

.readdirSync(workspace)
.map((dir) => {
const pkgDir = path.join(workspace, dir);
const pkgJsonPath = path.join(pkgDir, 'package.json');
.map((directory) => {
const pkgDirectory = path.join(workspace, directory);
const pkgJsonPath = path.join(pkgDirectory, 'package.json');
return { pkgDir, pkgJsonPath };
return { pkgDirectory, pkgJsonPath };
})
.map(({ pkgDir, pkgJsonPath }) => {
.map(({ pkgDirectory, pkgJsonPath }) => {
// package specific package.json
const pkgJson = require(pkgJsonPath);
return [pkgDir, pkgJson];
const packageJson = parseJson(pkgJsonPath, 'utf8');
/* istanbul ignore next */
if (Object.keys(packageJson).length === 0) {
throw new Error(
`Cannot find package.json or cannot parse it: ${pkgJsonPath}`,
);
}
return [pkgDirectory, packageJson];
});

@@ -44,19 +61,28 @@

}, [])
.reduce((acc, [pkgDir, pkgJson]) => {
acc[pkgJson.name] = path.join(pkgDir, sourceDir || 'src');
.reduce((acc, [pkgDirectory, packageJson]) => {
if (typeof sourceDirectory === 'string') {
acc[packageJson.name] = path.join(pkgDirectory, sourceDirectory);
} else {
const source = path.join(pkgDirectory, 'src');
acc[packageJson.name] = fs.existsSync(source) ? source : pkgDirectory;
}
return acc;
}, {});
return { cwd, extensions, exts, alias };
return { ...result, alias };
}
function getWorkspacesAndExtensions(cwd) {
function parseJson(fp) {
return fs.existsSync(fp) ? JSON.parse(fs.readFileSync(fp, 'utf8')) : {};
}
function getWorkspacesAndExtensions(cwd = process.cwd()) {
const fromRoot = (...x) => path.resolve(cwd, ...x);
const rootPkg = require(fromRoot('package.json'));
const rootLerna = fs.existsSync(fromRoot('lerna.json'))
? require(fromRoot('lerna.json'))
: {};
const packagePath = fromRoot('package.json');
const lernaPath = fromRoot('lerna.json');
const pkg = parseJson(packagePath);
const lerna = parseJson(lernaPath);
const workspaces = []
.concat(rootLerna.packages || (rootPkg.workspaces || []))
.concat(lerna.packages || (pkg.workspaces || []))
.filter((x) => typeof x === 'string')

@@ -67,9 +93,14 @@ .filter(Boolean)

let exts = [].concat(rootPkg.extensions).filter(Boolean);
exts = exts.length > 0 ? exts : ['js', 'jsx', 'ts', 'tsx', 'mjs'];
exts = exts.map((ext) => (ext.startsWith('.') ? ext.slice(1) : ext));
let exts = [].concat(pkg.extensions).filter(Boolean);
if (exts.length === 0) {
exts = ['tsx', 'ts', 'jsx', ...EXTENSIONS];
}
exts = exts.map((extension) =>
extension.startsWith('.') ? extension.slice(1) : extension,
);
const extensions = exts.map((x) => `.${x}`);
return { workspaces, extensions, exts };
return { workspaces, extensions, exts, lerna, lernaPath, pkg, packagePath };
}
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