Socket
Socket
Sign inDemoInstall

@pnpm/lifecycle

Package Overview
Dependencies
10
Maintainers
2
Versions
147
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.0-2020821233223 to 0.0.0-20230605-20230605142810

lib/index.js.map

22

lib/index.d.ts

@@ -1,15 +0,7 @@

import runLifecycleHook, { RunLifecycleHookOptions } from './runLifecycleHook';
import runLifecycleHooksConcurrently from './runLifecycleHooksConcurrently';
export default runLifecycleHook;
export { runLifecycleHooksConcurrently, RunLifecycleHookOptions };
export declare function runPostinstallHooks(opts: {
depPath: string;
extraBinPaths?: string[];
optional?: boolean;
pkgRoot: string;
prepare?: boolean;
rawConfig: object;
rootModulesDir: string;
shellEmulator?: boolean;
unsafePerm: boolean;
}): Promise<boolean>;
import { runLifecycleHook, type RunLifecycleHookOptions } from './runLifecycleHook';
import { runLifecycleHooksConcurrently, type RunLifecycleHooksConcurrentlyOptions } from './runLifecycleHooksConcurrently';
export declare function makeNodeRequireOption(modulePath: string): {
NODE_OPTIONS: string;
};
export { runLifecycleHook, runLifecycleHooksConcurrently, type RunLifecycleHookOptions, type RunLifecycleHooksConcurrentlyOptions, };
export declare function runPostinstallHooks(opts: RunLifecycleHookOptions): Promise<boolean>;

@@ -6,30 +6,38 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.runPostinstallHooks = exports.runLifecycleHooksConcurrently = void 0;
exports.runPostinstallHooks = exports.runLifecycleHooksConcurrently = exports.runLifecycleHook = exports.makeNodeRequireOption = void 0;
const path_1 = __importDefault(require("path"));
const read_package_json_1 = require("@pnpm/read-package-json");
const runLifecycleHook_1 = __importDefault(require("./runLifecycleHook"));
const runLifecycleHooksConcurrently_1 = __importDefault(require("./runLifecycleHooksConcurrently"));
exports.runLifecycleHooksConcurrently = runLifecycleHooksConcurrently_1.default;
const path = require("path");
const exists = require("path-exists");
exports.default = runLifecycleHook_1.default;
const path_exists_1 = __importDefault(require("path-exists"));
const runLifecycleHook_1 = require("./runLifecycleHook");
Object.defineProperty(exports, "runLifecycleHook", { enumerable: true, get: function () { return runLifecycleHook_1.runLifecycleHook; } });
const runLifecycleHooksConcurrently_1 = require("./runLifecycleHooksConcurrently");
Object.defineProperty(exports, "runLifecycleHooksConcurrently", { enumerable: true, get: function () { return runLifecycleHooksConcurrently_1.runLifecycleHooksConcurrently; } });
function makeNodeRequireOption(modulePath) {
let { NODE_OPTIONS } = process.env;
NODE_OPTIONS = `${NODE_OPTIONS ?? ''} --require=${modulePath}`.trim();
return { NODE_OPTIONS };
}
exports.makeNodeRequireOption = makeNodeRequireOption;
async function runPostinstallHooks(opts) {
var _a;
const pkg = await read_package_json_1.fromDir(opts.pkgRoot);
const scripts = (_a = pkg === null || pkg === void 0 ? void 0 : pkg.scripts) !== null && _a !== void 0 ? _a : {};
if (!scripts.install) {
await checkBindingGyp(opts.pkgRoot, scripts);
const pkg = await (0, read_package_json_1.safeReadPackageJsonFromDir)(opts.pkgRoot);
if (pkg == null)
return false;
if (pkg.scripts == null) {
pkg.scripts = {};
}
if (scripts.preinstall) {
await runLifecycleHook_1.default('preinstall', pkg, opts);
if (!pkg.scripts.install) {
await checkBindingGyp(opts.pkgRoot, pkg.scripts);
}
if (scripts.install) {
await runLifecycleHook_1.default('install', pkg, opts);
if (pkg.scripts.preinstall) {
await (0, runLifecycleHook_1.runLifecycleHook)('preinstall', pkg, opts);
}
if (scripts.postinstall) {
await runLifecycleHook_1.default('postinstall', pkg, opts);
if (pkg.scripts.install) {
await (0, runLifecycleHook_1.runLifecycleHook)('install', pkg, opts);
}
if (opts.prepare && scripts.prepare) {
await runLifecycleHook_1.default('prepare', pkg, opts);
if (pkg.scripts.postinstall) {
await (0, runLifecycleHook_1.runLifecycleHook)('postinstall', pkg, opts);
}
return !!scripts.preinstall || !!scripts.install || !!scripts.postinstall;
return pkg.scripts.preinstall != null ||
pkg.scripts.install != null ||
pkg.scripts.postinstall != null;
}

@@ -42,6 +50,6 @@ exports.runPostinstallHooks = runPostinstallHooks;

async function checkBindingGyp(root, scripts) {
if (await exists(path.join(root, 'binding.gyp'))) {
scripts['install'] = 'node-gyp rebuild'; // eslint-disable-line @typescript-eslint/dot-notation
if (await (0, path_exists_1.default)(path_1.default.join(root, 'binding.gyp'))) {
scripts.install = 'node-gyp rebuild';
}
}
//# sourceMappingURL=index.js.map

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

import { DependencyManifest, ProjectManifest } from '@pnpm/types';
import { type DependencyManifest, type ProjectManifest } from '@pnpm/types';
export interface RunLifecycleHookOptions {

@@ -6,2 +6,4 @@ args?: string[];

extraBinPaths?: string[];
extraEnv?: Record<string, string>;
initCwd?: string;
optional?: boolean;

@@ -11,3 +13,5 @@ pkgRoot: string;

rootModulesDir: string;
scriptShell?: string;
silent?: boolean;
scriptsPrependNodePath?: boolean | 'warn-only';
shellEmulator?: boolean;

@@ -17,2 +21,2 @@ stdio?: string;

}
export default function runLifecycleHook(stage: string, manifest: ProjectManifest | DependencyManifest, opts: RunLifecycleHookOptions): Promise<void>;
export declare function runLifecycleHook(stage: string, manifest: ProjectManifest | DependencyManifest, opts: RunLifecycleHookOptions): Promise<void>;
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.runLifecycleHook = void 0;
const core_loggers_1 = require("@pnpm/core-loggers");
const lifecycle = require("@zkochan/npm-lifecycle");
const logger_1 = require("@pnpm/logger");
const npm_lifecycle_1 = __importDefault(require("@pnpm/npm-lifecycle"));
const error_1 = require("@pnpm/error");
const fs_1 = require("fs");
function noop() { } // eslint-disable-line:no-empty
async function runLifecycleHook(stage, manifest, opts) {
var _a, _b, _c, _d;
const optional = opts.optional === true;

@@ -12,6 +18,10 @@ const m = { _id: getId(manifest), ...manifest };

if (stage === 'start' && !m.scripts.start) {
if (!(0, fs_1.existsSync)('server.js')) {
throw new error_1.PnpmError('NO_SCRIPT_OR_SERVER', 'Missing script start or file server.js');
}
m.scripts.start = 'node server.js';
}
if (((_a = opts.args) === null || _a === void 0 ? void 0 : _a.length) && ((_b = m.scripts) === null || _b === void 0 ? void 0 : _b[stage])) {
m.scripts[stage] = `${m.scripts[stage]} ${opts.args.map((arg) => `"${arg}"`).join(' ')}`;
if (opts.args?.length && m.scripts?.[stage]) {
const escapedArgs = opts.args.map((arg) => JSON.stringify(arg));
m.scripts[stage] = `${m.scripts[stage]} ${escapedArgs.join(' ')}`;
}

@@ -32,8 +42,13 @@ // This script is used to prevent the usage of npm or Yarn.

const logLevel = (opts.stdio !== 'inherit' || opts.silent)
? 'silent' : undefined;
await lifecycle(m, stage, opts.pkgRoot, {
? 'silent'
: undefined;
await (0, npm_lifecycle_1.default)(m, stage, opts.pkgRoot, {
config: opts.rawConfig,
dir: opts.rootModulesDir,
extraBinPaths: (_c = opts.extraBinPaths) !== null && _c !== void 0 ? _c : [],
extraEnv: { PNPM_SCRIPT_SRC_DIR: opts.pkgRoot },
extraBinPaths: opts.extraBinPaths ?? [],
extraEnv: {
...opts.extraEnv,
INIT_CWD: opts.initCwd ?? process.cwd(),
PNPM_SCRIPT_SRC_DIR: opts.pkgRoot,
},
log: {

@@ -48,7 +63,11 @@ clearProgress: noop,

verbose: npmLog,
warn: noop,
warn: (...msg) => {
(0, logger_1.globalWarn)(msg.join(' '));
},
},
runConcurrently: true,
scriptsPrependNodePath: opts.scriptsPrependNodePath,
scriptShell: opts.scriptShell,
shellEmulator: opts.shellEmulator,
stdio: (_d = opts.stdio) !== null && _d !== void 0 ? _d : 'pipe',
stdio: opts.stdio ?? 'pipe',
unsafePerm: opts.unsafePerm,

@@ -73,3 +92,3 @@ });

}
const code = arguments[3];
const code = arguments[3] ?? 1;
core_loggers_1.lifecycleLogger.debug({

@@ -86,7 +105,6 @@ depPath: opts.depPath,

}
exports.default = runLifecycleHook;
exports.runLifecycleHook = runLifecycleHook;
function getId(manifest) {
var _a, _b;
return `${(_a = manifest.name) !== null && _a !== void 0 ? _a : ''}@${(_b = manifest.version) !== null && _b !== void 0 ? _b : ''}`;
return `${manifest.name ?? ''}@${manifest.version ?? ''}`;
}
//# sourceMappingURL=runLifecycleHook.js.map

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

import { ProjectManifest } from '@pnpm/types';
export default function runLifecycleHooksConcurrently(stages: string[], importers: Array<{
import { type StoreController } from '@pnpm/store-controller-types';
import { type ProjectManifest } from '@pnpm/types';
import { type RunLifecycleHookOptions } from './runLifecycleHook';
export type RunLifecycleHooksConcurrentlyOptions = Omit<RunLifecycleHookOptions, 'depPath' | 'pkgRoot' | 'rootModulesDir'> & {
resolveSymlinksInInjectedDirs?: boolean;
storeController: StoreController;
};
export interface Importer {
buildIndex: number;

@@ -7,8 +13,5 @@ manifest: ProjectManifest;

modulesDir: string;
}>, childConcurrency: number, opts: {
extraBinPaths?: string[];
rawConfig: object;
shellEmulator?: boolean;
stdio?: string;
unsafePerm: boolean;
}): Promise<void>;
stages?: string[];
targetDirs?: string[];
}
export declare function runLifecycleHooksConcurrently(stages: string[], importers: Importer[], childConcurrency: number, opts: RunLifecycleHooksConcurrentlyOptions): Promise<void>;

@@ -6,4 +6,8 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.runLifecycleHooksConcurrently = void 0;
const fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
const directory_fetcher_1 = require("@pnpm/directory-fetcher");
const run_groups_1 = __importDefault(require("run-groups"));
const runLifecycleHook_1 = __importDefault(require("./runLifecycleHook"));
const runLifecycleHook_1 = require("./runLifecycleHook");
async function runLifecycleHooksConcurrently(stages, importers, childConcurrency, opts) {

@@ -19,26 +23,63 @@ const importersByBuildIndex = new Map();

}
const sortedBuildIndexes = Array.from(importersByBuildIndex.keys()).sort();
const sortedBuildIndexes = Array.from(importersByBuildIndex.keys()).sort((a, b) => a - b);
const groups = sortedBuildIndexes.map((buildIndex) => {
const importers = importersByBuildIndex.get(buildIndex);
return importers.map(({ manifest, modulesDir, rootDir }) => async () => {
return importers.map(({ manifest, modulesDir, rootDir, stages: importerStages, targetDirs }) => async () => {
const runLifecycleHookOpts = {
...opts,
depPath: rootDir,
extraBinPaths: opts.extraBinPaths,
pkgRoot: rootDir,
rawConfig: opts.rawConfig,
rootModulesDir: modulesDir,
shellEmulator: opts.shellEmulator,
stdio: opts.stdio,
unsafePerm: opts.unsafePerm,
};
for (const stage of stages) {
if (!manifest.scripts || !manifest.scripts[stage])
let isBuilt = false;
for (const stage of (importerStages ?? stages)) {
if ((manifest.scripts == null) || !manifest.scripts[stage])
continue;
await runLifecycleHook_1.default(stage, manifest, runLifecycleHookOpts);
await (0, runLifecycleHook_1.runLifecycleHook)(stage, manifest, runLifecycleHookOpts); // eslint-disable-line no-await-in-loop
isBuilt = true;
}
if (targetDirs == null || targetDirs.length === 0 || !isBuilt)
return;
const filesResponse = await (0, directory_fetcher_1.fetchFromDir)(rootDir, { resolveSymlinks: opts.resolveSymlinksInInjectedDirs });
await Promise.all(targetDirs.map(async (targetDir) => {
const targetModulesDir = path_1.default.join(targetDir, 'node_modules');
const nodeModulesIndex = {};
if (fs_1.default.existsSync(targetModulesDir)) {
// If the target directory contains a node_modules directory
// (it may happen when the hoisted node linker is used)
// then we need to preserve this node_modules.
// So we scan this node_modules directory and pass it as part of the new package.
await scanDir('node_modules', targetModulesDir, targetModulesDir, nodeModulesIndex);
}
return opts.storeController.importPackage(targetDir, {
filesResponse: {
fromStore: false,
...filesResponse,
filesIndex: {
...filesResponse.filesIndex,
...nodeModulesIndex,
},
},
force: false,
});
}));
});
});
await run_groups_1.default(childConcurrency, groups);
await (0, run_groups_1.default)(childConcurrency, groups);
}
exports.default = runLifecycleHooksConcurrently;
exports.runLifecycleHooksConcurrently = runLifecycleHooksConcurrently;
async function scanDir(prefix, rootDir, currentDir, index) {
const files = await fs_1.default.promises.readdir(currentDir);
await Promise.all(files.map(async (file) => {
const fullPath = path_1.default.join(currentDir, file);
const stat = await fs_1.default.promises.stat(fullPath);
if (stat.isDirectory()) {
return scanDir(prefix, rootDir, fullPath, index);
}
if (stat.isFile()) {
const relativePath = path_1.default.relative(rootDir, fullPath);
index[path_1.default.join(prefix, relativePath)] = fullPath;
}
}));
}
//# sourceMappingURL=runLifecycleHooksConcurrently.js.map
{
"name": "@pnpm/lifecycle",
"version": "0.0.0-2020821233223",
"description": "Package lifecycle hook runner",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
"files": [
"lib",
"!*.map"
],
"engines": {
"node": ">=10.13"
},
"scripts": {
"lint": "eslint -c ../../eslint.json src/**/*.ts test/**/*.ts",
"_test": "cd ../.. && c8 --reporter lcov --reports-dir packages/lifecycle/coverage ts-node packages/lifecycle/test --type-check",
"test": "pnpm run compile && pnpm run _test",
"prepublishOnly": "pnpm run compile",
"fix": "tslint -c tslint.json src/**/*.ts test/**/*.ts --fix",
"compile": "rimraf lib tsconfig.tsbuildinfo && tsc --build"
},
"repository": "https://github.com/pnpm/pnpm/blob/master/packages/lifecycle",
"keywords": [
"pnpm",
"lifecycle",
"scripts"
],
"author": "Zoltan Kochan <z@kochan.io> (https://www.kochan.io/)",
"license": "MIT",
"bugs": {
"url": "https://github.com/pnpm/pnpm/issues"
},
"homepage": "https://github.com/pnpm/pnpm/blob/master/packages/lifecycle#readme",
"peerDependencies": {
"@pnpm/logger": "^3.1.0"
},
"dependencies": {
"@pnpm/core-loggers": "5.0.0",
"@pnpm/read-package-json": "3.1.5",
"@pnpm/types": "6.2.0",
"@zkochan/npm-lifecycle": "4.1.0-0",
"path-exists": "^4.0.0",
"run-groups": "^3.0.1"
},
"devDependencies": {
"@pnpm/lifecycle": "link:",
"@pnpm/logger": "^3.2.2",
"@types/rimraf": "^3.0.0",
"json-append": "1.1.1",
"load-json-file": "^6.2.0"
},
"funding": "https://opencollective.com/pnpm"
}
"name": "@pnpm/lifecycle",
"version": "0.0.0-20230605-20230605142810",
"description": "Package lifecycle hook runner",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"files": [
"lib",
"!*.map"
],
"engines": {
"node": ">=16.14"
},
"repository": "https://github.com/pnpm/pnpm/blob/main/exec/lifecycle",
"keywords": [
"pnpm8",
"pnpm",
"lifecycle",
"scripts"
],
"license": "MIT",
"bugs": {
"url": "https://github.com/pnpm/pnpm/issues"
},
"homepage": "https://github.com/pnpm/pnpm/blob/main/exec/lifecycle#readme",
"peerDependencies": {
"@pnpm/logger": "^5.0.0"
},
"dependencies": {
"@pnpm/npm-lifecycle": "^2.0.1",
"path-exists": "^4.0.0",
"run-groups": "^3.0.1",
"@pnpm/core-loggers": "9.0.1",
"@pnpm/directory-fetcher": "0.0.0-20230605-20230605142810",
"@pnpm/store-controller-types": "15.0.1",
"@pnpm/read-package-json": "0.0.0-20230605-20230605142810",
"@pnpm/types": "9.1.0",
"@pnpm/error": "0.0.0-20230605-20230605142810"
},
"devDependencies": {
"@types/rimraf": "^3.0.2",
"@zkochan/rimraf": "^2.1.2",
"json-append": "1.1.1",
"load-json-file": "^6.2.0",
"@pnpm/lifecycle": "0.0.0-20230605-20230605142810",
"@pnpm/test-fixtures": "0.0.0-20230605-20230605142810"
},
"funding": "https://opencollective.com/pnpm",
"exports": {
".": "./lib/index.js"
},
"scripts": {
"lint": "eslint \"src/**/*.ts\" \"test/**/*.ts\"",
"_test": "jest",
"test": "pnpm run compile && pnpm run _test",
"fix": "tslint -c tslint.json src/**/*.ts test/**/*.ts --fix",
"compile": "tsc --build && pnpm run lint --fix"
}
}

@@ -12,3 +12,3 @@ # @pnpm/lifecycle

```sh
<pnpm|npm|yarn> add @pnpm/logger @pnpm/lifecycle
pnpm add @pnpm/logger @pnpm/lifecycle
```

@@ -51,2 +51,2 @@

MIT © [Zoltan Kochan](https://www.kochan.io/)
MIT

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc