@pnpm/prepare-package
Advanced tools
Comparing version 4.0.0 to 4.0.1
@@ -1,3 +0,5 @@ | ||
export declare function preparePackage(opts: { | ||
export interface PreparePackageOptions { | ||
rawConfig: object; | ||
}, pkgDir: string): Promise<void>; | ||
unsafePerm?: boolean; | ||
} | ||
export declare function preparePackage(opts: PreparePackageOptions, pkgDir: string): Promise<void>; |
@@ -7,8 +7,7 @@ "use strict"; | ||
exports.preparePackage = void 0; | ||
const fs_1 = __importDefault(require("fs")); | ||
const path_1 = __importDefault(require("path")); | ||
const error_1 = require("@pnpm/error"); | ||
const npm_lifecycle_1 = __importDefault(require("@pnpm/npm-lifecycle")); | ||
const lifecycle_1 = require("@pnpm/lifecycle"); | ||
const read_package_json_1 = require("@pnpm/read-package-json"); | ||
const rimraf_1 = __importDefault(require("@zkochan/rimraf")); | ||
const execa_1 = __importDefault(require("execa")); | ||
const preferred_pm_1 = __importDefault(require("preferred-pm")); | ||
@@ -25,20 +24,27 @@ const omit_1 = __importDefault(require("ramda/src/omit")); | ||
const manifest = await (0, read_package_json_1.safeReadPackageJsonFromDir)(pkgDir); | ||
if (manifest?.scripts == null || !packageShouldBeBuilt(manifest.scripts)) | ||
if (manifest?.scripts == null || !packageShouldBeBuilt(manifest, pkgDir)) | ||
return; | ||
const pm = (await (0, preferred_pm_1.default)(pkgDir))?.name ?? 'npm'; | ||
// We can't prepare a package without running its lifecycle scripts. | ||
// An alternative solution could be to throw an exception. | ||
const config = (0, omit_1.default)(['ignore-scripts'], opts.rawConfig); | ||
const env = npm_lifecycle_1.default.makeEnv(manifest, { config }); | ||
const execOpts = { cwd: pkgDir, env, extendEnv: true }; | ||
const execOpts = { | ||
depPath: `${manifest.name}@${manifest.version}`, | ||
pkgRoot: pkgDir, | ||
// We can't prepare a package without running its lifecycle scripts. | ||
// An alternative solution could be to throw an exception. | ||
rawConfig: (0, omit_1.default)(['ignore-scripts'], opts.rawConfig), | ||
rootModulesDir: pkgDir, | ||
unsafePerm: Boolean(opts.unsafePerm), | ||
}; | ||
try { | ||
await (0, execa_1.default)(pm, ['install'], execOpts); | ||
const installScriptName = `${pm}-install`; | ||
manifest.scripts[installScriptName] = `${pm} install`; | ||
await (0, lifecycle_1.runLifecycleHook)(installScriptName, manifest, execOpts); | ||
for (const scriptName of PREPUBLISH_SCRIPTS) { | ||
if (manifest.scripts[scriptName] == null || manifest.scripts[scriptName] === '') | ||
continue; | ||
await (0, execa_1.default)(pm, ['run', scriptName], execOpts); | ||
await (0, lifecycle_1.runLifecycleHook)(scriptName, manifest, execOpts); | ||
} | ||
} | ||
catch (err) { // eslint-disable-line | ||
throw new error_1.PnpmError('PREPARE_PKG_FAILURE', err.shortMessage ?? err.message); | ||
err.code = 'ERR_PNPM_PREPARE_PACKAGE'; | ||
throw err; | ||
} | ||
@@ -48,8 +54,14 @@ await (0, rimraf_1.default)(path_1.default.join(pkgDir, 'node_modules')); | ||
exports.preparePackage = preparePackage; | ||
function packageShouldBeBuilt(packageScripts) { | ||
return [ | ||
...PREPUBLISH_SCRIPTS, | ||
'prepare', | ||
].some((scriptName) => packageScripts[scriptName] != null && packageScripts[scriptName] !== ''); | ||
function packageShouldBeBuilt(manifest, pkgDir) { | ||
if (manifest.scripts == null) | ||
return false; | ||
const scripts = manifest.scripts; | ||
if (scripts.prepare != null && scripts.prepare !== '') | ||
return true; | ||
const hasPrepublishScript = PREPUBLISH_SCRIPTS.some((scriptName) => scripts[scriptName] != null && scripts[scriptName] !== ''); | ||
if (!hasPrepublishScript) | ||
return false; | ||
const mainFile = manifest.main ?? 'index.js'; | ||
return !fs_1.default.existsSync(path_1.default.join(pkgDir, mainFile)); | ||
} | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@pnpm/prepare-package", | ||
"version": "4.0.0", | ||
"version": "4.0.1", | ||
"description": "Prepares a Git-hosted package", | ||
@@ -25,8 +25,7 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"@pnpm/npm-lifecycle": "^2.0.0", | ||
"@zkochan/rimraf": "^2.1.2", | ||
"execa": "npm:safe-execa@^0.1.2", | ||
"execa": "npm:safe-execa@0.1.2", | ||
"preferred-pm": "^3.0.3", | ||
"ramda": "npm:@pnpm/ramda@0.28.1", | ||
"@pnpm/error": "4.0.0", | ||
"@pnpm/lifecycle": "14.1.4", | ||
"@pnpm/read-package-json": "7.0.4" | ||
@@ -39,3 +38,3 @@ }, | ||
"@pnpm/prepare": "0.0.59", | ||
"@pnpm/prepare-package": "4.0.0", | ||
"@pnpm/prepare-package": "4.0.1", | ||
"@pnpm/test-fixtures": "0.0.28", | ||
@@ -42,0 +41,0 @@ "@pnpm/types": "8.10.0" |
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
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
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
7663
6
68
2
+ Added@pnpm/lifecycle@14.1.4
+ Added@gwhitney/detect-indent@7.0.1(transitive)
+ Added@pnpm/core-loggers@8.0.3(transitive)
+ Added@pnpm/directory-fetcher@5.1.3(transitive)
+ Added@pnpm/fetcher-base@13.1.5(transitive)
+ Added@pnpm/graceful-fs@2.0.0(transitive)
+ Added@pnpm/lifecycle@14.1.4(transitive)
+ Added@pnpm/logger@5.2.0(transitive)
+ Added@pnpm/read-project-manifest@4.1.2(transitive)
+ Added@pnpm/resolver-base@9.1.5(transitive)
+ Added@pnpm/store-controller-types@14.2.0(transitive)
+ Added@pnpm/text.comments-parser@1.0.0(transitive)
+ Added@pnpm/write-project-manifest@4.1.2(transitive)
+ Added@types/node@22.7.4(transitive)
+ Added@types/ssri@7.1.5(transitive)
+ Addedargparse@2.0.1(transitive)
+ Addedbole@5.0.15(transitive)
+ Addedfast-deep-equal@3.1.3(transitive)
+ Addedfast-safe-stringify@2.1.1(transitive)
+ Addedignore-walk@5.0.1(transitive)
+ Addedindividual@3.0.0(transitive)
+ Addedis-plain-obj@2.1.0(transitive)
+ Addedis-typedarray@1.0.0(transitive)
+ Addedis-windows@1.0.2(transitive)
+ Addedjs-yaml@4.1.0(transitive)
+ Addedjson-stringify-safe@5.0.1(transitive)
+ Addedjson5@2.2.3(transitive)
+ Addedminimist@1.2.8(transitive)
+ Addedndjson@2.0.0(transitive)
+ Addednpm-bundled@2.0.1(transitive)
+ Addednpm-normalize-package-bin@2.0.0(transitive)
+ Addednpm-packlist@5.1.3(transitive)
+ Addedread-yaml-file@2.1.0(transitive)
+ Addedrun-groups@3.0.1(transitive)
+ Addedsafe-execa@0.1.2(transitive)
+ Addedsignal-exit@4.1.0(transitive)
+ Addedsort-keys@4.2.0(transitive)
+ Addedsplit2@3.2.2(transitive)
+ Addedstrip-comments-strings@1.2.0(transitive)
+ Addedthrough2@4.0.2(transitive)
+ Addedtypedarray-to-buffer@3.1.5(transitive)
+ Addedundici-types@6.19.8(transitive)
+ Addedwrite-file-atomic@3.0.35.0.1(transitive)
+ Addedwrite-yaml-file@4.2.0(transitive)
- Removed@pnpm/error@4.0.0
- Removed@pnpm/npm-lifecycle@^2.0.0
- Removedsafe-execa@0.1.4(transitive)
Updatedexeca@npm:safe-execa@0.1.2