pkgprn 0.4.1 → 0.5.1

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.
@@ -0,0 +1,81 @@
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
+ export function extractReferences(pkg) {
11
+ /** @type {unknown[]} */
12
+ const result = [];
13
+
14
+ // bin — included as-is (string or object; non-strings are skipped by consuming code)
15
+ if (pkg.bin !== undefined && pkg.bin !== null) {
16
+ result.push(pkg.bin);
17
+ }
18
+
19
+ // bin.* — all values when bin is an object
20
+ if (typeof pkg.bin === 'object' && pkg.bin !== null && !Array.isArray(pkg.bin)) {
21
+ for (const value of Object.values(pkg.bin)) {
22
+ result.push(value);
23
+ }
24
+ }
25
+
26
+ // simple top-level fields: main, module, unpkg, umd, types, typings
27
+ const topLevelFields = ['main', 'module', 'unpkg', 'umd', 'types', 'typings'];
28
+ for (const field of topLevelFields) {
29
+ if (pkg[field] !== undefined && pkg[field] !== null) {
30
+ result.push(pkg[field]);
31
+ }
32
+ }
33
+
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
+ if (typeof pkg.exports === 'object' && pkg.exports !== null && !Array.isArray(pkg.exports)) {
40
+ for (const level1 of Object.values(pkg.exports)) {
41
+ if (typeof level1 === 'object' && level1 !== null && !Array.isArray(level1)) {
42
+ for (const level2 of Object.values(/** @type {Record<string, unknown>} */ (level1))) {
43
+ if (Array.isArray(level2)) {
44
+ for (const item of level2) {
45
+ result.push(item);
46
+ }
47
+ } else {
48
+ result.push(level2);
49
+ }
50
+ }
51
+ }
52
+ }
53
+ }
54
+
55
+ // typesVersions.*.* — 2 levels of wildcard, arrays are flattened
56
+ if (typeof pkg.typesVersions === 'object' && pkg.typesVersions !== null && !Array.isArray(pkg.typesVersions)) {
57
+ for (const level1 of Object.values(pkg.typesVersions)) {
58
+ if (typeof level1 === 'object' && level1 !== null && !Array.isArray(level1)) {
59
+ for (const level2 of Object.values(/** @type {Record<string, unknown>} */ (level1))) {
60
+ if (Array.isArray(level2)) {
61
+ for (const item of level2) {
62
+ result.push(item);
63
+ }
64
+ } else {
65
+ result.push(level2);
66
+ }
67
+ }
68
+ }
69
+ }
70
+ }
71
+
72
+ // directories.bin
73
+ if (typeof pkg.directories === 'object' && pkg.directories !== null) {
74
+ const dirs = /** @type {Record<string, unknown>} */ (pkg.directories);
75
+ if (dirs.bin !== undefined && dirs.bin !== null) {
76
+ result.push(dirs.bin);
77
+ }
78
+ }
79
+
80
+ return result;
81
+ }
package/index.d.ts.map CHANGED
@@ -11,6 +11,6 @@
11
11
  "sourcesContent": [
12
12
  null
13
13
  ],
14
- "mappings": ";;;;iBAsEsBA,QAAQA;aAhCUC,MAAMA",
14
+ "mappings": ";;;;iBAuEsBA,QAAQA;aAhCUC,MAAMA",
15
15
  "ignoreList": []
16
16
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pkgprn",
3
- "version": "0.4.1",
3
+ "version": "0.5.1",
4
4
  "license": "MIT",
5
5
  "author": "Konstantin Shutkin",
6
6
  "bin": "./index.js",
@@ -33,7 +33,6 @@
33
33
  "dependencies": {
34
34
  "@jridgewell/sourcemap-codec": "^1.5.5",
35
35
  "@niceties/logger": "^1.1.13",
36
- "cleye": "2.2.1",
37
- "jsonata": "^2.1.0"
36
+ "cleye": "2.2.1"
38
37
  }
39
38
  }
package/prune.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { access, mkdir, readdir, readFile, rename, rm, stat, writeFile } from 'node:fs/promises';
2
2
  import path from 'node:path';
3
3
 
4
+ import { extractReferences } from './extract-references.js';
4
5
  import { adjustSourcemapLineMappings, isStrippableFile, parseCommentTypes, stripCommentsWithLineMap } from './strip-comments.js';
5
6
 
6
7
  /**
@@ -270,12 +271,9 @@ export async function prunePkg(pkg, options, logger) {
270
271
  * @param {Logger} logger
271
272
  */
272
273
  async function flatten(pkg, flatten, logger) {
273
- const { default: jsonata } = await import('jsonata');
274
-
275
274
  // find out where is the dist folder
276
275
 
277
- const expression = jsonata('[bin, bin.*, main, module, unpkg, umd, types, typings, exports[].*.*, typesVersions.*.*, directories.bin]');
278
- const allReferences = await expression.evaluate(pkg);
276
+ const allReferences = extractReferences(pkg);
279
277
 
280
278
  /** @type {string[]} */
281
279
  let distDirs;