@pkgr/utils
Advanced tools
Comparing version 2.4.2 to 3.0.0
@@ -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', |
@@ -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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
3
4
15245
14
278
+ Added@pkgr/core@^0.1.0
+ Added@pkgr/core@0.1.1(transitive)
- Removedcross-spawn@^7.0.3
- Removedopen@^9.1.0
- Removedpicocolors@^1.0.0
- Removedtslib@^2.6.0
- Removedbig-integer@1.6.52(transitive)
- Removedbplist-parser@0.2.0(transitive)
- Removedbundle-name@3.0.0(transitive)
- Removedcross-spawn@7.0.6(transitive)
- Removeddefault-browser@4.0.0(transitive)
- Removeddefault-browser-id@3.0.0(transitive)
- Removeddefine-lazy-prop@3.0.0(transitive)
- Removedexeca@5.1.17.2.0(transitive)
- Removedget-stream@6.0.1(transitive)
- Removedhuman-signals@2.1.04.3.1(transitive)
- Removedis-docker@2.2.13.0.0(transitive)
- Removedis-inside-container@1.0.0(transitive)
- Removedis-stream@2.0.13.0.0(transitive)
- Removedis-wsl@2.2.0(transitive)
- Removedisexe@2.0.0(transitive)
- Removedmerge-stream@2.0.0(transitive)
- Removedmimic-fn@2.1.04.0.0(transitive)
- Removednpm-run-path@4.0.15.3.0(transitive)
- Removedonetime@5.1.26.0.0(transitive)
- Removedopen@9.1.0(transitive)
- Removedpath-key@3.1.14.0.0(transitive)
- Removedpicocolors@1.1.1(transitive)
- Removedrun-applescript@5.0.0(transitive)
- Removedshebang-command@2.0.0(transitive)
- Removedshebang-regex@3.0.0(transitive)
- Removedsignal-exit@3.0.7(transitive)
- Removedstrip-final-newline@2.0.03.0.0(transitive)
- Removedtitleize@3.0.0(transitive)
- Removedtslib@2.8.1(transitive)
- Removeduntildify@4.0.0(transitive)
- Removedwhich@2.0.2(transitive)
Updatedfast-glob@^3.3.2