pkgprn 0.5.1 → 0.5.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/extract-references.js +4 -23
- package/index.d.ts.map +14 -14
- package/index.js +3 -20
- package/package.json +1 -1
- package/prune.js +38 -214
- package/strip-comments.js +81 -316
package/extract-references.js
CHANGED
|
@@ -1,29 +1,17 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Extracts all file path references from a package.json object.
|
|
3
|
-
*
|
|
4
|
-
* Replaces the jsonata expression:
|
|
5
|
-
* [bin, bin.*, main, module, unpkg, umd, types, typings, exports[].*.*, typesVersions.*.*, directories.bin]
|
|
6
|
-
*
|
|
7
|
-
* @param {Record<string, unknown>} pkg
|
|
8
|
-
* @returns {unknown[]}
|
|
9
|
-
*/
|
|
10
1
|
export function extractReferences(pkg) {
|
|
11
|
-
|
|
2
|
+
|
|
12
3
|
const result = [];
|
|
13
4
|
|
|
14
|
-
// bin — included as-is (string or object; non-strings are skipped by consuming code)
|
|
15
5
|
if (pkg.bin !== undefined && pkg.bin !== null) {
|
|
16
6
|
result.push(pkg.bin);
|
|
17
7
|
}
|
|
18
8
|
|
|
19
|
-
// bin.* — all values when bin is an object
|
|
20
9
|
if (typeof pkg.bin === 'object' && pkg.bin !== null && !Array.isArray(pkg.bin)) {
|
|
21
10
|
for (const value of Object.values(pkg.bin)) {
|
|
22
11
|
result.push(value);
|
|
23
12
|
}
|
|
24
13
|
}
|
|
25
14
|
|
|
26
|
-
// simple top-level fields: main, module, unpkg, umd, types, typings
|
|
27
15
|
const topLevelFields = ['main', 'module', 'unpkg', 'umd', 'types', 'typings'];
|
|
28
16
|
for (const field of topLevelFields) {
|
|
29
17
|
if (pkg[field] !== undefined && pkg[field] !== null) {
|
|
@@ -31,15 +19,10 @@ export function extractReferences(pkg) {
|
|
|
31
19
|
}
|
|
32
20
|
}
|
|
33
21
|
|
|
34
|
-
// exports[].*.* — navigate exactly 2 levels deep into the exports object.
|
|
35
|
-
// Level 1: values of the exports object (e.g. exports["."], exports["./second"])
|
|
36
|
-
// Level 2: values of each level-1 value (if it's an object)
|
|
37
|
-
// String values at level 1 are skipped (jsonata wildcard on string yields nothing).
|
|
38
|
-
// Array values at level 2 are flattened.
|
|
39
22
|
if (typeof pkg.exports === 'object' && pkg.exports !== null && !Array.isArray(pkg.exports)) {
|
|
40
23
|
for (const level1 of Object.values(pkg.exports)) {
|
|
41
24
|
if (typeof level1 === 'object' && level1 !== null && !Array.isArray(level1)) {
|
|
42
|
-
for (const level2 of Object.values(
|
|
25
|
+
for (const level2 of Object.values( (level1))) {
|
|
43
26
|
if (Array.isArray(level2)) {
|
|
44
27
|
for (const item of level2) {
|
|
45
28
|
result.push(item);
|
|
@@ -52,11 +35,10 @@ export function extractReferences(pkg) {
|
|
|
52
35
|
}
|
|
53
36
|
}
|
|
54
37
|
|
|
55
|
-
// typesVersions.*.* — 2 levels of wildcard, arrays are flattened
|
|
56
38
|
if (typeof pkg.typesVersions === 'object' && pkg.typesVersions !== null && !Array.isArray(pkg.typesVersions)) {
|
|
57
39
|
for (const level1 of Object.values(pkg.typesVersions)) {
|
|
58
40
|
if (typeof level1 === 'object' && level1 !== null && !Array.isArray(level1)) {
|
|
59
|
-
for (const level2 of Object.values(
|
|
41
|
+
for (const level2 of Object.values( (level1))) {
|
|
60
42
|
if (Array.isArray(level2)) {
|
|
61
43
|
for (const item of level2) {
|
|
62
44
|
result.push(item);
|
|
@@ -69,9 +51,8 @@ export function extractReferences(pkg) {
|
|
|
69
51
|
}
|
|
70
52
|
}
|
|
71
53
|
|
|
72
|
-
// directories.bin
|
|
73
54
|
if (typeof pkg.directories === 'object' && pkg.directories !== null) {
|
|
74
|
-
const dirs =
|
|
55
|
+
const dirs = (pkg.directories);
|
|
75
56
|
if (dirs.bin !== undefined && dirs.bin !== null) {
|
|
76
57
|
result.push(dirs.bin);
|
|
77
58
|
}
|
package/index.d.ts.map
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
2
|
+
"version": 3,
|
|
3
|
+
"file": "index.d.ts",
|
|
4
|
+
"names": [
|
|
5
|
+
"prunePkg",
|
|
6
|
+
"Logger"
|
|
7
|
+
],
|
|
8
|
+
"sources": [
|
|
9
|
+
"prune.js"
|
|
10
|
+
],
|
|
11
|
+
"sourcesContent": [
|
|
12
|
+
null
|
|
13
|
+
],
|
|
14
|
+
"mappings": ";;;;iBAwBsBA,QAAQA;",
|
|
15
|
+
"ignoreList": []
|
|
16
16
|
}
|
package/index.js
CHANGED
|
@@ -9,7 +9,6 @@ import { createLogger } from '@niceties/logger';
|
|
|
9
9
|
|
|
10
10
|
import { prunePkg } from './prune.js';
|
|
11
11
|
|
|
12
|
-
// globals
|
|
13
12
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
14
13
|
|
|
15
14
|
const logger = createLogger();
|
|
@@ -74,39 +73,26 @@ try {
|
|
|
74
73
|
process.exit(255);
|
|
75
74
|
}
|
|
76
75
|
|
|
77
|
-
/**
|
|
78
|
-
* @returns {Promise<string>}
|
|
79
|
-
*/
|
|
80
76
|
async function getMyVersion() {
|
|
81
77
|
const pkg = await readPackage(resolve(__dirname));
|
|
82
78
|
|
|
83
79
|
return pkg && 'version' in pkg && typeof pkg.version === 'string' ? pkg.version : '<unknown>';
|
|
84
80
|
}
|
|
85
81
|
|
|
86
|
-
/**
|
|
87
|
-
* @param {string} dir
|
|
88
|
-
* @returns {Promise<import('./prune.js').PackageJson | undefined>}
|
|
89
|
-
*/
|
|
90
82
|
async function readPackage(dir) {
|
|
91
83
|
const packageFileName = resolve(dir, 'package.json');
|
|
92
84
|
try {
|
|
93
85
|
const pkgFile = await readFile(packageFileName);
|
|
94
86
|
return JSON.parse(pkgFile.toString());
|
|
95
87
|
} catch {
|
|
96
|
-
|
|
88
|
+
|
|
97
89
|
}
|
|
98
90
|
}
|
|
99
91
|
|
|
100
|
-
/**
|
|
101
|
-
* @param {import('./prune.js').PackageJson} pkg
|
|
102
|
-
*/
|
|
103
92
|
async function writePackage(pkg) {
|
|
104
93
|
await writeFile('./package.json', `${JSON.stringify(pkg, null, 2)}\n`);
|
|
105
94
|
}
|
|
106
95
|
|
|
107
|
-
/**
|
|
108
|
-
* @param {string | false} value
|
|
109
|
-
*/
|
|
110
96
|
function StripCommentsParam(value) {
|
|
111
97
|
if (value === '') {
|
|
112
98
|
return 'all';
|
|
@@ -114,12 +100,9 @@ function StripCommentsParam(value) {
|
|
|
114
100
|
return value;
|
|
115
101
|
}
|
|
116
102
|
|
|
117
|
-
/**
|
|
118
|
-
* @param {string | false} value
|
|
119
|
-
*/
|
|
120
103
|
function FlattenParam(value) {
|
|
121
104
|
if (value === '') {
|
|
122
|
-
return true;
|
|
105
|
+
return true;
|
|
123
106
|
}
|
|
124
|
-
return value;
|
|
107
|
+
return value;
|
|
125
108
|
}
|