Socket
Socket
Sign inDemoInstall

@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 1.0.1 to 2.0.0

lib/index.cjs

6

CHANGELOG.md
# Change Log
## 2.0.0
### Major Changes
- [#220](https://github.com/rx-ts/pkgr/pull/220) [`106aaf6`](https://github.com/rx-ts/pkgr/commit/106aaf6d7096a90742992d9e0a069f2b08e78bf7) Thanks [@JounQin](https://github.com/JounQin)! - feat: migrate to native esm
## 1.0.1

@@ -4,0 +10,0 @@

27

lib/browser.js

@@ -1,10 +0,6 @@

"use strict";
// based on https://github.com/facebook/create-react-app/blob/master/packages/react-dev-utils/openBrowser.js
Object.defineProperty(exports, "__esModule", { value: true });
exports.openBrowser = void 0;
const tslib_1 = require("tslib");
const child_process_1 = require("child_process");
const chalk_1 = tslib_1.__importDefault(require("chalk"));
const cross_spawn_1 = tslib_1.__importDefault(require("cross-spawn"));
const open_1 = tslib_1.__importDefault(require("open"));
import { execSync } from 'child_process';
import chalk from 'chalk';
import spawn from 'cross-spawn';
import open from 'open';
// https://github.com/sindresorhus/open#app

@@ -44,3 +40,3 @@ const OSX_CHROME = 'google chrome';

const extraArgs = process.argv.slice(2);
const child = cross_spawn_1.default(process.execPath, [scriptPath, ...extraArgs, url], {
const child = spawn(process.execPath, [scriptPath, ...extraArgs, url], {
stdio: 'inherit',

@@ -51,4 +47,4 @@ });

console.log();
console.log(chalk_1.default.red('The script specified as BROWSER environment variable failed.'));
console.log(`${chalk_1.default.cyan(scriptPath)} exited with code ${code}`);
console.log(chalk.red('The script specified as BROWSER environment variable failed.'));
console.log(`${chalk.cyan(scriptPath)} exited with code ${code}`);
console.log();

@@ -80,4 +76,4 @@ }

// on OSX Chromium-based browser with AppleScript
child_process_1.execSync('ps cax | grep "' + chromiumBrowser + '"');
child_process_1.execSync('osascript ../openChrome.applescript "' +
execSync('ps cax | grep "' + chromiumBrowser + '"');
execSync('osascript ../openChrome.applescript "' +
encodeURI(url) +

@@ -108,3 +104,3 @@ '" "' +

try {
open_1.default(url, {
open(url, {
app: browser

@@ -128,3 +124,3 @@ ? {

*/
function openBrowser(url) {
export function openBrowser(url) {
const { action, value, args } = getBrowserEnv();

@@ -143,3 +139,2 @@ switch (action) {

}
exports.openBrowser = openBrowser;
//# sourceMappingURL=browser.js.map

@@ -0,1 +1,3 @@

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

@@ -8,2 +10,3 @@ export declare const PROD: "production";

export declare const CWD: string;
export declare const cjsRequire: NodeRequire;
export declare const EXTENSIONS: string[];

@@ -1,14 +0,13 @@

"use strict";
var _a;
Object.defineProperty(exports, "__esModule", { value: true });
exports.EXTENSIONS = exports.CWD = exports.NODE_MODULES_REG = exports.__PROD__ = exports.__DEV__ = exports.NODE_ENV = exports.PROD = exports.DEV = void 0;
exports.DEV = 'development';
exports.PROD = 'production';
exports.NODE_ENV = (_a = process.env.NODE_ENV) !== null && _a !== void 0 ? _a : exports.DEV;
exports.__DEV__ = exports.NODE_ENV === exports.DEV;
exports.__PROD__ = exports.NODE_ENV === exports.PROD;
exports.NODE_MODULES_REG = /[/\\]node_modules[/\\]/;
exports.CWD = process.cwd();
import { createRequire } from 'module';
export const DEV = 'development';
export const PROD = 'production';
export const NODE_ENV = (_a = process.env.NODE_ENV) !== null && _a !== void 0 ? _a : DEV;
export const __DEV__ = NODE_ENV === DEV;
export const __PROD__ = NODE_ENV === PROD;
export const NODE_MODULES_REG = /[/\\]node_modules[/\\]/;
export const CWD = process.cwd();
export const cjsRequire = typeof require === 'undefined' ? createRequire(import.meta.url) : require;
// eslint-disable-next-line node/no-deprecated-api, sonar/deprecation
exports.EXTENSIONS = ['.ts', '.tsx', ...Object.keys(require.extensions)];
export const EXTENSIONS = ['.ts', '.tsx', ...Object.keys(cjsRequire.extensions)];
//# sourceMappingURL=constants.js.map

@@ -1,37 +0,29 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.arrayify = exports.findUp = exports.identify = exports.tryGlob = exports.tryExtensions = exports.tryFile = exports.isVueAvailable = exports.isSvelteAvailable = exports.isReactAvailable = exports.isMdxAvailable = exports.isAngularAvailable = exports.isTsAvailable = exports.isPkgAvailable = exports.tryRequirePkg = exports.tryPkg = void 0;
const tslib_1 = require("tslib");
const fs_1 = tslib_1.__importDefault(require("fs"));
const path_1 = tslib_1.__importDefault(require("path"));
const is_glob_1 = tslib_1.__importDefault(require("is-glob"));
const sync_1 = tslib_1.__importDefault(require("tiny-glob/sync"));
const constants_1 = require("./constants");
const tryPkg = (pkg) => {
import fs from 'fs';
import path from 'path';
import isGlob from 'is-glob';
import { CWD, EXTENSIONS, cjsRequire } from './constants.js';
export const tryPkg = (pkg) => {
try {
return require.resolve(pkg);
return cjsRequire.resolve(pkg);
}
catch (_a) { }
};
exports.tryPkg = tryPkg;
const tryRequirePkg = (pkg) => {
export const tryRequirePkg = (pkg) => {
try {
// eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-unsafe-return
return require(pkg);
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return cjsRequire(pkg);
}
catch (_a) { }
};
exports.tryRequirePkg = tryRequirePkg;
const isPkgAvailable = (pkg) => !!exports.tryPkg(pkg);
exports.isPkgAvailable = isPkgAvailable;
exports.isTsAvailable = exports.isPkgAvailable('typescript');
exports.isAngularAvailable = exports.isPkgAvailable('@angular/core');
exports.isMdxAvailable = exports.isPkgAvailable('@mdx/mdx') || exports.isPkgAvailable('@mdx/react');
exports.isReactAvailable = exports.isPkgAvailable('react');
exports.isSvelteAvailable = exports.isPkgAvailable('svelte');
exports.isVueAvailable = exports.isPkgAvailable('vue');
const tryFile = (filePath, includeDir = false) => {
export const isPkgAvailable = (pkg) => !!tryPkg(pkg);
export const isTsAvailable = isPkgAvailable('typescript');
export const isAngularAvailable = isPkgAvailable('@angular/core');
export const isMdxAvailable = isPkgAvailable('@mdx/mdx') || isPkgAvailable('@mdx/react');
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_1.default.existsSync(filePath) &&
(includeDir || fs_1.default.statSync(filePath).isFile())
return fs.existsSync(filePath) &&
(includeDir || fs.statSync(filePath).isFile())
? filePath

@@ -41,3 +33,3 @@ : '';

for (const file of filePath !== null && filePath !== void 0 ? filePath : []) {
if (exports.tryFile(file, includeDir)) {
if (tryFile(file, includeDir)) {
return file;

@@ -48,47 +40,41 @@ }

};
exports.tryFile = tryFile;
const tryExtensions = (filepath, extensions = constants_1.EXTENSIONS) => {
const ext = [...extensions, ''].find(ext => exports.tryFile(filepath + ext));
export const tryExtensions = (filepath, extensions = EXTENSIONS) => {
const ext = [...extensions, ''].find(ext => tryFile(filepath + ext));
return ext == null ? '' : filepath + ext;
};
exports.tryExtensions = tryExtensions;
const tryGlob = (paths, options = {}) => {
const { absolute = true, baseDir = constants_1.CWD } = typeof options === 'string' ? { baseDir: options } : options;
export const tryGlob = (paths, options = {}) => {
const { absolute = true, baseDir = CWD } = typeof options === 'string' ? { baseDir: options } : options;
return paths.reduce((acc, pkg) => [
...acc,
...(is_glob_1.default(pkg)
? sync_1.default(pkg, {
...(isGlob(pkg)
? tryRequirePkg('tiny-glob/sync')(pkg, {
absolute,
cwd: baseDir,
})
: [exports.tryFile(path_1.default.resolve(baseDir, pkg), true)]),
: [tryFile(path.resolve(baseDir, pkg), true)]),
].filter(Boolean), []);
};
exports.tryGlob = tryGlob;
const identify = (_) => !!_;
exports.identify = identify;
const findUp = (searchEntry, searchFile = 'package.json') => {
console.assert(path_1.default.isAbsolute(searchEntry));
if (!exports.tryFile(searchEntry, true) ||
(searchEntry !== constants_1.CWD && !searchEntry.startsWith(constants_1.CWD + path_1.default.sep))) {
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 '';
}
searchEntry = path_1.default.resolve(fs_1.default.statSync(searchEntry).isDirectory()
searchEntry = path.resolve(fs.statSync(searchEntry).isDirectory()
? searchEntry
: path_1.default.resolve(searchEntry, '..'));
: path.resolve(searchEntry, '..'));
do {
const searched = exports.tryFile(path_1.default.resolve(searchEntry, searchFile));
const searched = tryFile(path.resolve(searchEntry, searchFile));
if (searched) {
return searched;
}
searchEntry = path_1.default.resolve(searchEntry, '..');
} while (searchEntry === constants_1.CWD || searchEntry.startsWith(constants_1.CWD + path_1.default.sep));
searchEntry = path.resolve(searchEntry, '..');
} while (searchEntry === CWD || searchEntry.startsWith(CWD + path.sep));
return '';
};
exports.findUp = findUp;
const arrayify = (...args) => args.reduce((arr, curr) => {
export const arrayify = (...args) => args.reduce((arr, curr) => {
arr.push(...(Array.isArray(curr) ? curr : curr == null ? [] : [curr]));
return arr;
}, []);
exports.arrayify = arrayify;
//# sourceMappingURL=helpers.js.map

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

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

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

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
tslib_1.__exportStar(require("./browser"), exports);
tslib_1.__exportStar(require("./constants"), exports);
tslib_1.__exportStar(require("./helpers"), exports);
tslib_1.__exportStar(require("./monorepo"), exports);
export * from './browser.js';
export * from './constants.js';
export * from './helpers.js';
export * from './monorepo.js';
//# sourceMappingURL=index.js.map

@@ -1,13 +0,9 @@

"use strict";
var _a, _b, _c, _d;
Object.defineProperty(exports, "__esModule", { value: true });
exports.monorepoPkgs = exports.isMonorepo = void 0;
const tslib_1 = require("tslib");
const path_1 = tslib_1.__importDefault(require("path"));
const helpers_1 = require("./helpers");
const pkg = (_a = helpers_1.tryRequirePkg(path_1.default.resolve('package.json'))) !== null && _a !== void 0 ? _a : {};
const lernaConfig = (_b = helpers_1.tryRequirePkg(path_1.default.resolve('lerna.json'))) !== null && _b !== void 0 ? _b : {};
import path from '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 : [];
exports.isMonorepo = Array.isArray(pkgsPath) && pkgsPath.length > 0;
exports.monorepoPkgs = exports.isMonorepo ? helpers_1.tryGlob(pkgsPath) : [];
export const isMonorepo = Array.isArray(pkgsPath) && pkgsPath.length > 0;
export const monorepoPkgs = isMonorepo ? tryGlob(pkgsPath) : [];
//# sourceMappingURL=monorepo.js.map
{
"name": "@pkgr/utils",
"version": "1.0.1",
"version": "2.0.0",
"type": "module",
"description": "Shared utils for `@pkgr` packages or any package else",

@@ -12,8 +13,6 @@ "repository": "git+https://github.com/rx-ts/pkgr.git",

},
"main": "lib",
"module": "lib/esm",
"es2015": "lib/es2015",
"fesm5": "lib/esm",
"jsdelivr": "lib/umd",
"unpkg": "lib/umd",
"exports": {
"import": "./lib/index.js",
"require": "./lib/index.cjs"
},
"types": "lib",

@@ -25,8 +24,8 @@ "files": [

"dependencies": {
"chalk": "^4.1.1",
"chalk": "^4.1.2",
"cross-spawn": "^7.0.2",
"is-glob": "^4.0.1",
"open": "^8.2.0",
"open": "^8.2.1",
"tiny-glob": "^0.2.9",
"tslib": "^2.2.0"
"tslib": "^2.3.0"
},

@@ -33,0 +32,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