npm-pkgbuild 7.20.4 → 7.21.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/content/node-modules-content-provider.mjs +31 -9
- package/src/npm-shrink.mjs +124 -0
- package/src/npm-cleanup.mjs +0 -164
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { tmpdir } from "os";
|
|
2
2
|
import { join } from "path";
|
|
3
|
-
import {
|
|
3
|
+
import { mkdtemp, readFile, writeFile } from "fs/promises";
|
|
4
4
|
import { globby } from "globby";
|
|
5
5
|
import Arborist from "@npmcli/arborist";
|
|
6
|
+
import { StringContentEntry } from "content-entry";
|
|
6
7
|
import { FileSystemEntry } from "content-entry-filesystem";
|
|
7
8
|
import { ContentProvider } from "./content-provider.mjs";
|
|
8
9
|
import { utf8StreamOptions } from "../util.mjs";
|
|
9
|
-
|
|
10
|
+
import { shrinkNPM } from "../npm-shrink.mjs";
|
|
10
11
|
/**
|
|
11
12
|
* Content from node_modules
|
|
12
13
|
*/
|
|
@@ -46,7 +47,12 @@ export class NodeModulesContentProvider extends ContentProvider {
|
|
|
46
47
|
);
|
|
47
48
|
|
|
48
49
|
const arb = new Arborist({ path: tmp });
|
|
49
|
-
await arb.buildIdealTree({
|
|
50
|
+
await arb.buildIdealTree({
|
|
51
|
+
rm: ["@types/node", "@types/uuid"],
|
|
52
|
+
update: true,
|
|
53
|
+
prune: true,
|
|
54
|
+
saveType: "prod"
|
|
55
|
+
});
|
|
50
56
|
await arb.prune({ saveType: "prod" });
|
|
51
57
|
await arb.reify({ save: true });
|
|
52
58
|
|
|
@@ -54,10 +60,23 @@ export class NodeModulesContentProvider extends ContentProvider {
|
|
|
54
60
|
cwd: tmp
|
|
55
61
|
})) {
|
|
56
62
|
if (!toBeSkipped.test(name)) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
63
|
+
if (name.endsWith("package.json")) {
|
|
64
|
+
const json = shrinkNPM(
|
|
65
|
+
JSON.parse(await readFile(join(tmp, name), utf8StreamOptions))
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
if (json) {
|
|
69
|
+
yield Object.assign(
|
|
70
|
+
new StringContentEntry(name, JSON.stringify(json)),
|
|
71
|
+
this.entryProperties
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
} else {
|
|
75
|
+
yield Object.assign(
|
|
76
|
+
new FileSystemEntry(name, tmp),
|
|
77
|
+
this.entryProperties
|
|
78
|
+
);
|
|
79
|
+
}
|
|
61
80
|
}
|
|
62
81
|
}
|
|
63
82
|
}
|
|
@@ -76,6 +95,7 @@ const toBeSkipped = new RegExp(
|
|
|
76
95
|
"\\.bat",
|
|
77
96
|
"\\.gypi",
|
|
78
97
|
"\\.gyp",
|
|
98
|
+
"\\.markdown",
|
|
79
99
|
"appveyor\\.yml",
|
|
80
100
|
"yarn\\.lock",
|
|
81
101
|
"\\.DS_Store",
|
|
@@ -85,6 +105,8 @@ const toBeSkipped = new RegExp(
|
|
|
85
105
|
"\\.npm.*",
|
|
86
106
|
"\\.git.*",
|
|
87
107
|
"rollup\\.config\\.(js|mjs|cjs)",
|
|
108
|
+
"COPYING",
|
|
109
|
+
"Doxyfile",
|
|
88
110
|
"CODE_OF_CONDUCT(\\.md)?",
|
|
89
111
|
"GOVERNANCE(\\.md)?",
|
|
90
112
|
"CODEOWNERS(\\.md)?",
|
|
@@ -93,7 +115,7 @@ const toBeSkipped = new RegExp(
|
|
|
93
115
|
"CONTRIBUT(ORS|ING)(\\.md)?",
|
|
94
116
|
"CHANGELOG(\\.md)?",
|
|
95
117
|
"HISTORY(\\.md)?",
|
|
96
|
-
"LICENSE(
|
|
118
|
+
"LICENSE(\\-\\w+|\\.md|\\.txt)?",
|
|
97
119
|
"README(.*\\.md)?",
|
|
98
120
|
"\\.o",
|
|
99
121
|
"\\.a",
|
|
@@ -146,8 +168,8 @@ const toBeSkipped = new RegExp(
|
|
|
146
168
|
"LIMITS\\.md",
|
|
147
169
|
"Porting-Buffer\\.md",
|
|
148
170
|
"chains and topics\\.md",
|
|
171
|
+
"build_detect_platform"
|
|
149
172
|
].join("|") +
|
|
150
173
|
")$",
|
|
151
174
|
"i"
|
|
152
175
|
);
|
|
153
|
-
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
export function shrinkNPM(pkg) {
|
|
2
|
+
[
|
|
3
|
+
"version",
|
|
4
|
+
"name",
|
|
5
|
+
"dependencies",
|
|
6
|
+
"sideEffects",
|
|
7
|
+
"jspm",
|
|
8
|
+
"jsnext:main",
|
|
9
|
+
"man",
|
|
10
|
+
"files",
|
|
11
|
+
"directories",
|
|
12
|
+
"devDependencies",
|
|
13
|
+
"bundleDependencies",
|
|
14
|
+
"peerDependencies",
|
|
15
|
+
"peerDependenciesMeta",
|
|
16
|
+
"optionalDependencies",
|
|
17
|
+
"optionalDevDependencies",
|
|
18
|
+
"sideEffects",
|
|
19
|
+
"pika",
|
|
20
|
+
"private",
|
|
21
|
+
"publishConfig",
|
|
22
|
+
"repository",
|
|
23
|
+
"license",
|
|
24
|
+
"licenses",
|
|
25
|
+
"changelog",
|
|
26
|
+
"keywords",
|
|
27
|
+
"homepage",
|
|
28
|
+
"bugs",
|
|
29
|
+
"scripts",
|
|
30
|
+
"types",
|
|
31
|
+
"deprecated",
|
|
32
|
+
"description",
|
|
33
|
+
"decription",
|
|
34
|
+
"engine",
|
|
35
|
+
"engines",
|
|
36
|
+
"author",
|
|
37
|
+
"authors",
|
|
38
|
+
"contributors",
|
|
39
|
+
"maintainers",
|
|
40
|
+
"verb",
|
|
41
|
+
"xo",
|
|
42
|
+
"prettier",
|
|
43
|
+
"jest",
|
|
44
|
+
"remarkConfig",
|
|
45
|
+
"nyc",
|
|
46
|
+
"ava",
|
|
47
|
+
"publishConfig",
|
|
48
|
+
"typeScriptVersion",
|
|
49
|
+
"typesPublisherContentHash",
|
|
50
|
+
"typings",
|
|
51
|
+
"systemd",
|
|
52
|
+
"pacman",
|
|
53
|
+
"pkg",
|
|
54
|
+
"lintDeps",
|
|
55
|
+
"icon",
|
|
56
|
+
"config",
|
|
57
|
+
"release",
|
|
58
|
+
"template",
|
|
59
|
+
"spm",
|
|
60
|
+
"precommit.silent",
|
|
61
|
+
"greenkeeper",
|
|
62
|
+
"bundlesize",
|
|
63
|
+
"standard",
|
|
64
|
+
"ignore",
|
|
65
|
+
"ender",
|
|
66
|
+
"dojoBuild",
|
|
67
|
+
"component",
|
|
68
|
+
"eslintConfig",
|
|
69
|
+
"env",
|
|
70
|
+
"commitlint",
|
|
71
|
+
"standard-version",
|
|
72
|
+
"lint-staged",
|
|
73
|
+
"lintStaged",
|
|
74
|
+
"ci",
|
|
75
|
+
"husky",
|
|
76
|
+
"verbiage",
|
|
77
|
+
"os",
|
|
78
|
+
"gypfile",
|
|
79
|
+
"coordinates",
|
|
80
|
+
"tap",
|
|
81
|
+
"typesVersions",
|
|
82
|
+
"node-gyp-build-optional",
|
|
83
|
+
"node-gyp-build-test",
|
|
84
|
+
"gitHead",
|
|
85
|
+
"hallmark",
|
|
86
|
+
"funding",
|
|
87
|
+
"eslintIgnore",
|
|
88
|
+
"react-native",
|
|
89
|
+
"sharec",
|
|
90
|
+
"source",
|
|
91
|
+
"support",
|
|
92
|
+
"auto-changelog",
|
|
93
|
+
"readmeFilename",
|
|
94
|
+
"readme",
|
|
95
|
+
"node-gyp-build-optional",
|
|
96
|
+
"node-gyp-build-test"
|
|
97
|
+
].map(key => {
|
|
98
|
+
delete pkg[key];
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
switch (pkg.main) {
|
|
102
|
+
case "index":
|
|
103
|
+
case "./index":
|
|
104
|
+
case "index.js":
|
|
105
|
+
case "./index.js":
|
|
106
|
+
case "":
|
|
107
|
+
delete pkg.main;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
for (const key of Object.keys(pkg)) {
|
|
111
|
+
if (key[0] === "_") {
|
|
112
|
+
delete pkg[key];
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
for (const toBeRemoved of ["types", "unpkg", "shim", "browser", "testling"]) {
|
|
117
|
+
// TODO mark files as to be skipped
|
|
118
|
+
|
|
119
|
+
delete pkg[toBeRemoved];
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return Object.keys(pkg).length === 0 ? undefined : pkg
|
|
123
|
+
}
|
|
124
|
+
|
package/src/npm-cleanup.mjs
DELETED
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
import { unlink, readFile, writeFile } from "fs/promises";
|
|
2
|
-
import { globby} from "globby";
|
|
3
|
-
import { join, dirname } from "path";
|
|
4
|
-
import { utf8StreamOptions } from "./util.mjs";
|
|
5
|
-
|
|
6
|
-
async function rm(file) {
|
|
7
|
-
try {
|
|
8
|
-
console.log("rm", file);
|
|
9
|
-
return await unlink(file);
|
|
10
|
-
} catch (error) {
|
|
11
|
-
console.log(error);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
async function iterate(o, cb) {
|
|
16
|
-
switch (typeof o) {
|
|
17
|
-
case "string":
|
|
18
|
-
return cb(o);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
if (Array.isArray(o)) {
|
|
22
|
-
for (const x of o) {
|
|
23
|
-
await iterate(x, cb);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
for (const k in o) {
|
|
27
|
-
await iterate(o[k], cb);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const blacklist = new Set(["parse-client-options", "@octokit/rest"]);
|
|
32
|
-
|
|
33
|
-
export async function cleanup(context, stagingDir) {
|
|
34
|
-
for (const name of await globby(["**/package.json"], {
|
|
35
|
-
cwd: stagingDir
|
|
36
|
-
})) {
|
|
37
|
-
const pkgFile = join(stagingDir, name);
|
|
38
|
-
const pkg = JSON.parse(await readFile(pkgFile, utf8StreamOptions));
|
|
39
|
-
|
|
40
|
-
if (!blacklist.has(pkg.name)) {
|
|
41
|
-
console.log(`cleanup ${pkgFile}`);
|
|
42
|
-
|
|
43
|
-
// unused files may also be deleted
|
|
44
|
-
await Promise.all(
|
|
45
|
-
["types", "unpkg", "shim", "browser", "testling", "source"].map(
|
|
46
|
-
async key => {
|
|
47
|
-
await iterate(pkg[key], async o => rm(join(dirname(pkgFile), o)));
|
|
48
|
-
delete pkg[key];
|
|
49
|
-
}
|
|
50
|
-
)
|
|
51
|
-
);
|
|
52
|
-
|
|
53
|
-
[
|
|
54
|
-
"version",
|
|
55
|
-
"name",
|
|
56
|
-
"dependencies",
|
|
57
|
-
"sideEffects",
|
|
58
|
-
"jspm",
|
|
59
|
-
"jsnext:main",
|
|
60
|
-
"man",
|
|
61
|
-
"files",
|
|
62
|
-
"directories",
|
|
63
|
-
"devDependencies",
|
|
64
|
-
"bundleDependencies",
|
|
65
|
-
"peerDependencies",
|
|
66
|
-
"optionalDependencies",
|
|
67
|
-
"sideEffects",
|
|
68
|
-
"pika",
|
|
69
|
-
"private",
|
|
70
|
-
"publishConfig",
|
|
71
|
-
"repository",
|
|
72
|
-
"license",
|
|
73
|
-
"licenses",
|
|
74
|
-
"changelog",
|
|
75
|
-
"keywords",
|
|
76
|
-
"homepage",
|
|
77
|
-
"bugs",
|
|
78
|
-
"scripts",
|
|
79
|
-
"types",
|
|
80
|
-
"deprecated",
|
|
81
|
-
"description",
|
|
82
|
-
"decription",
|
|
83
|
-
"engine",
|
|
84
|
-
"engines",
|
|
85
|
-
"author",
|
|
86
|
-
"authors",
|
|
87
|
-
"contributors",
|
|
88
|
-
"maintainers",
|
|
89
|
-
"verb",
|
|
90
|
-
"xo",
|
|
91
|
-
"prettier",
|
|
92
|
-
"jest",
|
|
93
|
-
"remarkConfig",
|
|
94
|
-
"nyc",
|
|
95
|
-
"ava",
|
|
96
|
-
"publishConfig",
|
|
97
|
-
"typeScriptVersion",
|
|
98
|
-
"typesPublisherContentHash",
|
|
99
|
-
"typings",
|
|
100
|
-
"systemd",
|
|
101
|
-
"pacman",
|
|
102
|
-
"lintDeps",
|
|
103
|
-
"icon",
|
|
104
|
-
"config",
|
|
105
|
-
"release",
|
|
106
|
-
"template",
|
|
107
|
-
"spm",
|
|
108
|
-
"precommit.silent",
|
|
109
|
-
"greenkeeper",
|
|
110
|
-
"bundlesize",
|
|
111
|
-
"standard",
|
|
112
|
-
"ignore",
|
|
113
|
-
"ender",
|
|
114
|
-
"dojoBuild",
|
|
115
|
-
"component",
|
|
116
|
-
"eslintConfig",
|
|
117
|
-
"env",
|
|
118
|
-
"commitlint",
|
|
119
|
-
"standard-version",
|
|
120
|
-
"lint-staged",
|
|
121
|
-
"lintStaged",
|
|
122
|
-
"ci",
|
|
123
|
-
"husky",
|
|
124
|
-
"verbiage",
|
|
125
|
-
"os",
|
|
126
|
-
"gypfile",
|
|
127
|
-
"coordinates",
|
|
128
|
-
"tap",
|
|
129
|
-
"typesVersions",
|
|
130
|
-
"node-gyp-build-optional",
|
|
131
|
-
"node-gyp-build-test",
|
|
132
|
-
"gitHead",
|
|
133
|
-
"hallmark",
|
|
134
|
-
"funding",
|
|
135
|
-
"eslintIgnore",
|
|
136
|
-
"react-native",
|
|
137
|
-
"sharec"
|
|
138
|
-
].map(key => {
|
|
139
|
-
delete pkg[key];
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
for (const key of Object.keys(pkg)) {
|
|
143
|
-
if (key[0] === "_") {
|
|
144
|
-
delete pkg[key];
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
switch (pkg.main) {
|
|
149
|
-
case "index":
|
|
150
|
-
case "./index":
|
|
151
|
-
case "index.js":
|
|
152
|
-
case "./index.js":
|
|
153
|
-
case "":
|
|
154
|
-
delete pkg.main;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
if (Object.keys(pkg).length === 0 || pkg.type === "module") {
|
|
158
|
-
await unlink(pkgFile);
|
|
159
|
-
} else {
|
|
160
|
-
await writeFile(pkgFile, JSON.stringify(pkg), utf8StreamOptions);
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
}
|