Strip dev deps from new lock file format
This commit is contained in:
1 parent
f24111ea9f
commit
c4754a9b55
1 file changed
+11
@@ -74,6 +74,7 @@ function rmDirSync(dirPath): void {
|
|||||||
fs.rmdirSync(dirPath);
|
fs.rmdirSync(dirPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// For lockfileVersion = 1
|
||||||
function stripDevDeps(deps): void {
|
function stripDevDeps(deps): void {
|
||||||
if (!deps["dependencies"]) return;
|
if (!deps["dependencies"]) return;
|
||||||
for (const [k, v] of Object.entries(deps["dependencies"])) {
|
for (const [k, v] of Object.entries(deps["dependencies"])) {
|
||||||
@@ -83,6 +84,15 @@ function stripDevDeps(deps): void {
|
|||||||
if (!Object.keys(deps["dependencies"]).length) delete deps["dependencies"];
|
if (!Object.keys(deps["dependencies"]).length) delete deps["dependencies"];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// For lockfileVersion = 2
|
||||||
|
function stripDevDeps2(deps): void {
|
||||||
|
if (!deps["packages"]) return;
|
||||||
|
for (const [k, v] of Object.entries(deps["packages"])) {
|
||||||
|
delete v["devDependencies"];
|
||||||
|
if (v["dev"]) delete deps["packages"][k];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function xmlTostring(xml): string {
|
function xmlTostring(xml): string {
|
||||||
const children = [];
|
const children = [];
|
||||||
for (const c of xml.children || []) children.push(xmlTostring(c));
|
for (const c of xml.children || []) children.push(xmlTostring(c));
|
||||||
@@ -140,6 +150,7 @@ async function init(): Promise<string[]> {
|
|||||||
);
|
);
|
||||||
npmShrinkwrapJson["version"] = packageJson["version"];
|
npmShrinkwrapJson["version"] = packageJson["version"];
|
||||||
stripDevDeps(npmShrinkwrapJson);
|
stripDevDeps(npmShrinkwrapJson);
|
||||||
|
stripDevDeps2(npmShrinkwrapJson);
|
||||||
fs.writeFileSync(
|
fs.writeFileSync(
|
||||||
path.resolve(OUTPUT_DIR, "npm-shrinkwrap.json"),
|
path.resolve(OUTPUT_DIR, "npm-shrinkwrap.json"),
|
||||||
JSON.stringify(npmShrinkwrapJson, null, 2)
|
JSON.stringify(npmShrinkwrapJson, null, 2)
|
||||||
|
|||||||
Reference in new issue
Block a user