Skip to content

Commit

Permalink
avoid checking for deps on lockfile3
Browse files Browse the repository at this point in the history
Signed-off-by: zFernand0 <37381190+zFernand0@users.noreply.github.com>
  • Loading branch information
zFernand0 committed Oct 12, 2023
1 parent 6d49a3e commit 16cb201
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
11 changes: 9 additions & 2 deletions dist/npm.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions packages/npm/src/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default async function (context: IContext, config: IPluginConfig, inDir?:
if (packageJson.scripts.preshrinkwrap != null) {
await exec.exec("npm", ["run", "preshrinkwrap"], { cwd });
}
pruneShrinkwrap(inDir);
pruneShrinkwrap(context, inDir);
}

if (config.tarballDir != null) {
Expand Down Expand Up @@ -87,10 +87,18 @@ export default async function (context: IContext, config: IPluginConfig, inDir?:
}
}

function pruneShrinkwrap(inDir?: string): void {
function pruneShrinkwrap(context: IContext, inDir?: string): void {
const shrinkwrapPath = inDir != null ? path.join(inDir, "npm-shrinkwrap.json") : "npm-shrinkwrap.json";
const lockfile = JSON.parse(fs.readFileSync(shrinkwrapPath, "utf-8"));
const filterPkgs = (obj: Record<string, any>, key: string) => {
if (obj[key] == null) {
// lockfileVersion 3 does not contain a `dependencies`
if (key === "dependencies" && lockfile.lockfileVersion === 3) {
context.logger.info("'Dependencies' is not supported in lockfileVersion 3.");
}
context.logger.info(`Property '${key}' does not exist. Skipping prune operation!`);
return;
}
for (const [pkgName, pkgData] of Object.entries(obj[key]) as any) {
if (["dev", "extraneous"].some(prop => pkgData[prop])) {
delete obj[key][pkgName];
Expand Down

0 comments on commit 16cb201

Please sign in to comment.