pkgprn 0.5.2 → 0.5.4

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 (3) hide show
  1. package/README.md +1 -1
  2. package/package.json +4 -3
  3. package/prune.js +17 -5
package/README.md CHANGED
@@ -259,4 +259,4 @@ Files that npm always includes are preserved regardless of the `files` array:
259
259
 
260
260
  ## License
261
261
 
262
- [MIT](./LICENSE)
262
+ [MIT](https://github.com/kshutkin/package-prune/blob/main/LICENSE)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pkgprn",
3
- "version": "0.5.2",
3
+ "version": "0.5.4",
4
4
  "license": "MIT",
5
5
  "author": "Konstantin Shutkin",
6
6
  "bin": "./index.js",
@@ -21,13 +21,14 @@
21
21
  "pack",
22
22
  "prepack"
23
23
  ],
24
- "homepage": "https://github.com/kshutkin/package-prune#readme",
24
+ "homepage": "https://github.com/kshutkin/package-prune/blob/main/pkgprn/README.md",
25
25
  "bugs": {
26
26
  "url": "https://github.com/kshutkin/package-prune/issues"
27
27
  },
28
28
  "repository": {
29
29
  "type": "git",
30
- "url": "git+https://github.com/kshutkin/package-prune.git"
30
+ "url": "git+https://github.com/kshutkin/package-prune.git",
31
+ "directory": "pkgprn"
31
32
  },
32
33
  "main": "prune.js",
33
34
  "dependencies": {
package/prune.js CHANGED
@@ -53,7 +53,7 @@ export async function prunePkg(pkg, options, logger) {
53
53
  }
54
54
 
55
55
  if (options.flatten) {
56
- await flatten(pkg, options.flatten, logger);
56
+ await flatten(pkg, options.flatten, logger, options.removeSourcemaps);
57
57
  }
58
58
 
59
59
  if (options.removeSourcemaps) {
@@ -72,6 +72,11 @@ export async function prunePkg(pkg, options, logger) {
72
72
 
73
73
  await rm(sourceMap);
74
74
  }
75
+
76
+ if (pkg.files && sourceMaps.length > 0) {
77
+ const removedMaps = new Set(sourceMaps.map(f => normalizePath(path.relative('.', f))));
78
+ pkg.files = pkg.files.filter(f => !removedMaps.has(normalizePath(f)));
79
+ }
75
80
  }
76
81
 
77
82
  if (options.stripComments) {
@@ -209,7 +214,7 @@ export async function prunePkg(pkg, options, logger) {
209
214
  }
210
215
  }
211
216
 
212
- async function flatten(pkg, flatten, logger) {
217
+ async function flatten(pkg, flatten, logger, skipSourcemapAdjust) {
213
218
 
214
219
  const allReferences = extractReferences(pkg);
215
220
 
@@ -339,7 +344,7 @@ async function flatten(pkg, flatten, logger) {
339
344
 
340
345
  await Promise.all(renamePromises);
341
346
 
342
- if (typeof flatten === 'string') {
347
+ if (typeof flatten === 'string' && !skipSourcemapAdjust) {
343
348
 
344
349
  const oldToNew = new Map();
345
350
  for (const [newPath, oldPath] of movedFiles) {
@@ -487,8 +492,15 @@ async function isEmptyDir(dir) {
487
492
  }
488
493
 
489
494
  async function isDirectory(file) {
490
- const fileStat = await stat(file);
491
- return fileStat.isDirectory();
495
+ try {
496
+ const fileStat = await stat(file);
497
+ return fileStat.isDirectory();
498
+ } catch (e) {
499
+ if (typeof e === 'object' && e != null && 'code' in e && e.code === 'ENOENT') {
500
+ return false;
501
+ }
502
+ throw e;
503
+ }
492
504
  }
493
505
 
494
506
  async function walkDir(dir, ignoreDirs = []) {