Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(lockfile): Avoid checking for deps on lockfile3 #117

Merged
merged 1 commit into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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