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

@pkgr/utils

Package Overview
Dependencies
Maintainers
2
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@pkgr/utils - npm Package Compare versions

Comparing version 2.4.2 to 3.0.0

4

lib/constants.d.ts

@@ -1,2 +0,1 @@

/// <reference types="node" />
export declare const DEV: "development";

@@ -8,5 +7,2 @@ export declare const PROD: "production";

export declare const NODE_MODULES_REG: RegExp;
export declare const CWD: string;
export declare const cjsRequire: NodeRequire;
export declare const EXTENSIONS: string[];
export declare const SCRIPT_RUNNERS: {

@@ -13,0 +9,0 @@ readonly npm: "npx";

var _a;
import { createRequire } from 'node:module';
export const DEV = 'development';

@@ -9,5 +8,2 @@ export const PROD = 'production';

export const NODE_MODULES_REG = /[/\\]node_modules[/\\]/;
export const CWD = process.cwd();
export const cjsRequire = typeof require === 'undefined' ? createRequire(import.meta.url) : require;
export const EXTENSIONS = ['.ts', '.tsx', ...Object.keys(cjsRequire.extensions)];
export const SCRIPT_RUNNERS = {

@@ -14,0 +10,0 @@ npm: 'npx',

17

lib/helpers.d.ts

@@ -1,12 +0,8 @@

export declare const tryPkg: (pkg: string) => string | undefined;
export declare const tryRequirePkg: <T>(pkg: string) => T | undefined;
export declare const isPkgAvailable: (pkg: string) => boolean;
export declare const isTsAvailable: boolean;
export declare const isAngularAvailable: boolean;
export declare const isMdxAvailable: boolean;
export declare const isReactAvailable: boolean;
export declare const isSvelteAvailable: boolean;
export declare const isVueAvailable: boolean;
export declare const tryFile: (filePath?: string[] | string, includeDir?: boolean) => string;
export declare const tryExtensions: (filepath: string, extensions?: string[]) => string;
export declare const isTsAvailable: () => boolean;
export declare const isAngularAvailable: () => boolean;
export declare const isMdxAvailable: () => boolean;
export declare const isReactAvailable: () => boolean;
export declare const isSvelteAvailable: () => boolean;
export declare const isVueAvailable: () => boolean;
export declare const tryGlob: (paths: string[], options?: string | {

@@ -18,3 +14,2 @@ absolute?: boolean;

export declare const identify: <T>(_: T) => _ is Exclude<T, "" | (T extends boolean ? false : boolean) | null | undefined>;
export declare const findUp: (searchEntry: string, searchFile?: string) => string;
export declare const arrayify: <T, R = T extends (infer S)[] ? NonNullable<S> : NonNullable<T>>(...args: (R | R[])[]) => R[];

@@ -21,0 +16,0 @@ export declare const getPackageManager: () => "pnpm" | "yarn" | "npm" | undefined;

@@ -1,11 +0,5 @@

import fs from 'node:fs';
import path from 'node:path';
import { CWD, cjsRequire, isPkgAvailable, tryFile } from '@pkgr/core';
import isGlob from 'is-glob';
import { CWD, EXTENSIONS, cjsRequire, SCRIPT_RUNNERS, SCRIPT_EXECUTORS, } from './constants.js';
export const tryPkg = (pkg) => {
try {
return cjsRequire.resolve(pkg);
}
catch (_a) { }
};
import { SCRIPT_RUNNERS, SCRIPT_EXECUTORS } from './constants.js';
export const tryRequirePkg = (pkg) => {

@@ -17,28 +11,8 @@ try {

};
export const isPkgAvailable = (pkg) => !!tryPkg(pkg);
export const isTsAvailable = isPkgAvailable('typescript');
export const isAngularAvailable = isPkgAvailable('@angular/core/package.json');
export const isMdxAvailable = isPkgAvailable('@mdx-js/mdx/package.json') ||
isPkgAvailable('@mdx-js/react/package.json');
export const isReactAvailable = isPkgAvailable('react');
export const isSvelteAvailable = isPkgAvailable('svelte');
export const isVueAvailable = isPkgAvailable('vue');
export const tryFile = (filePath, includeDir = false) => {
if (typeof filePath === 'string') {
return fs.existsSync(filePath) &&
(includeDir || fs.statSync(filePath).isFile())
? filePath
: '';
}
for (const file of filePath !== null && filePath !== void 0 ? filePath : []) {
if (tryFile(file, includeDir)) {
return file;
}
}
return '';
};
export const tryExtensions = (filepath, extensions = EXTENSIONS) => {
const ext = [...extensions, ''].find(ext => tryFile(filepath + ext));
return ext == null ? '' : filepath + ext;
};
export const isTsAvailable = () => isPkgAvailable('typescript');
export const isAngularAvailable = () => isPkgAvailable('@angular/core');
export const isMdxAvailable = () => isPkgAvailable('@mdx-js/mdx') || isPkgAvailable('@mdx-js/react');
export const isReactAvailable = () => isPkgAvailable('react');
export const isSvelteAvailable = () => isPkgAvailable('svelte');
export const isVueAvailable = () => isPkgAvailable('vue');
export const tryGlob = (paths, options = {}) => {

@@ -60,22 +34,6 @@ const { absolute = true, baseDir = CWD, ignore = ['**/node_modules/**'], } = typeof options === 'string' ? { baseDir: options } : options;

export const identify = (_) => !!_;
export const findUp = (searchEntry, searchFile = 'package.json') => {
console.assert(path.isAbsolute(searchEntry));
if (!tryFile(searchEntry, true) ||
(searchEntry !== CWD && !searchEntry.startsWith(CWD + path.sep))) {
return '';
export const arrayify = (...args) => args.reduce((arr, curr) => {
if (curr != null) {
arr.push(...(Array.isArray(curr) ? curr.filter(it => it != null) : [curr]));
}
searchEntry = path.resolve(fs.statSync(searchEntry).isDirectory()
? searchEntry
: path.resolve(searchEntry, '..'));
do {
const searched = tryFile(path.resolve(searchEntry, searchFile));
if (searched) {
return searched;
}
searchEntry = path.resolve(searchEntry, '..');
} while (searchEntry === CWD || searchEntry.startsWith(CWD + path.sep));
return '';
};
export const arrayify = (...args) => args.reduce((arr, curr) => {
arr.push(...(Array.isArray(curr) ? curr : curr == null ? [] : [curr]));
return arr;

@@ -82,0 +40,0 @@ }, []);

@@ -1,4 +0,4 @@

export * from './browser.js';
export * from './constants.js';
export * from './helpers.js';
export * from './monorepo.js';
export * from '@pkgr/core';

@@ -1,5 +0,5 @@

export * from './browser.js';
export * from './constants.js';
export * from './helpers.js';
export * from './monorepo.js';
export * from '@pkgr/core';
//# sourceMappingURL=index.js.map

@@ -1,2 +0,2 @@

export declare const isMonorepo: boolean;
export declare const monorepoPkgs: string[];
export declare const isMonorepo: () => boolean;
export declare const getMonorepoPkgs: () => string[];

@@ -1,11 +0,16 @@

var _a, _b, _c, _d;
import path from 'node:path';
import { tryGlob, tryRequirePkg } from './helpers.js';
const pkg = (_a = tryRequirePkg(path.resolve('package.json'))) !== null && _a !== void 0 ? _a : {};
const lernaConfig = (_b = tryRequirePkg(path.resolve('lerna.json'))) !== null && _b !== void 0 ? _b : {};
const pkgsPath = (_d = (_c = lernaConfig.packages) !== null && _c !== void 0 ? _c : pkg.workspaces) !== null && _d !== void 0 ? _d : [];
export const isMonorepo = Array.isArray(pkgsPath) && pkgsPath.length > 0;
export const monorepoPkgs = isMonorepo
? tryGlob(pkgsPath.map(pkg => pkg.endsWith('/package.json') ? pkg : `${pkg}/package.json`))
const getPkgPaths = () => {
var _a, _b, _c, _d;
const pkg = (_a = tryRequirePkg(path.resolve('package.json'))) !== null && _a !== void 0 ? _a : {};
const lernaConfig = (_b = tryRequirePkg(path.resolve('lerna.json'))) !== null && _b !== void 0 ? _b : {};
return (_d = (_c = lernaConfig.packages) !== null && _c !== void 0 ? _c : pkg.workspaces) !== null && _d !== void 0 ? _d : [];
};
export const isMonorepo = () => {
const pkgPaths = getPkgPaths();
return Array.isArray(pkgPaths) && pkgPaths.length > 0;
};
export const getMonorepoPkgs = () => isMonorepo()
? tryGlob(getPkgPaths().map(pkg => pkg.endsWith('/package.json') ? pkg : `${pkg}/package.json`))
: [];
//# sourceMappingURL=monorepo.js.map
{
"name": "@pkgr/utils",
"version": "2.4.2",
"version": "3.0.0",
"type": "module",

@@ -23,12 +23,8 @@ "description": "Shared utils for `@pkgr` packages or any package else",

"files": [
"lib",
"openChrome.applescript"
"lib"
],
"dependencies": {
"cross-spawn": "^7.0.3",
"fast-glob": "^3.3.0",
"is-glob": "^4.0.3",
"open": "^9.1.0",
"picocolors": "^1.0.0",
"tslib": "^2.6.0"
"@pkgr/core": "^0.1.0",
"fast-glob": "^3.3.2",
"is-glob": "^4.0.3"
},

@@ -35,0 +31,0 @@ "publishConfig": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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