pkgprn 0.5.3 → 0.5.5

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/prune.js +14 -7
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pkgprn",
3
- "version": "0.5.3",
3
+ "version": "0.5.5",
4
4
  "license": "MIT",
5
5
  "author": "Konstantin Shutkin",
6
6
  "bin": "./index.js",
package/prune.js CHANGED
@@ -52,8 +52,12 @@ export async function prunePkg(pkg, options, logger) {
52
52
  logger('cleanup is disabled, junk files may cause flatten to fail', 2);
53
53
  }
54
54
 
55
+ if (pkg.files && Array.isArray(pkg.files) && pkg.files.length > 0 && options.cleanupFiles) {
56
+ await cleanupDir(pkg, logger);
57
+ }
58
+
55
59
  if (options.flatten) {
56
- await flatten(pkg, options.flatten, logger);
60
+ await flatten(pkg, options.flatten, logger, options.removeSourcemaps);
57
61
  }
58
62
 
59
63
  if (options.removeSourcemaps) {
@@ -72,6 +76,11 @@ export async function prunePkg(pkg, options, logger) {
72
76
 
73
77
  await rm(sourceMap);
74
78
  }
79
+
80
+ if (pkg.files && sourceMaps.length > 0) {
81
+ const removedMaps = new Set(sourceMaps.map(f => normalizePath(path.relative('.', f))));
82
+ pkg.files = pkg.files.filter(f => !removedMaps.has(normalizePath(f)));
83
+ }
75
84
  }
76
85
 
77
86
  if (options.stripComments) {
@@ -204,12 +213,12 @@ export async function prunePkg(pkg, options, logger) {
204
213
  }
205
214
  }
206
215
 
207
- if (pkg.files && Array.isArray(pkg.files) && options.cleanupFiles) {
208
- await cleanupDir(pkg, logger);
216
+ if (options.cleanupFiles) {
217
+ pkg.files = undefined;
209
218
  }
210
219
  }
211
220
 
212
- async function flatten(pkg, flatten, logger) {
221
+ async function flatten(pkg, flatten, logger, skipSourcemapAdjust) {
213
222
 
214
223
  const allReferences = extractReferences(pkg);
215
224
 
@@ -339,7 +348,7 @@ async function flatten(pkg, flatten, logger) {
339
348
 
340
349
  await Promise.all(renamePromises);
341
350
 
342
- if (typeof flatten === 'string') {
351
+ if (typeof flatten === 'string' && !skipSourcemapAdjust) {
343
352
 
344
353
  const oldToNew = new Map();
345
354
  for (const [newPath, oldPath] of movedFiles) {
@@ -620,8 +629,6 @@ async function cleanupDir(pkg, logger) {
620
629
 
621
630
  await rm(entry, { recursive: true, force: true });
622
631
  }
623
-
624
- pkg.files = undefined;
625
632
  }
626
633
 
627
634
  async function cleanupSubDir(dir, filesEntries, alwaysIncludedFiles) {