pkgprn 0.5.5 → 0.6.0
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/prune.js +24 -1
package/package.json
CHANGED
package/prune.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { access, mkdir, readdir, readFile, rename, rm, stat, writeFile } from 'node:fs/promises';
|
|
1
|
+
import { access, glob as fsGlob, mkdir, readdir, readFile, rename, rm, stat, writeFile } from 'node:fs/promises';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
|
|
4
4
|
import { extractReferences } from './extract-references.js';
|
|
@@ -46,6 +46,10 @@ export async function prunePkg(pkg, options, logger) {
|
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
+
if (pkg.files && Array.isArray(pkg.files)) {
|
|
50
|
+
pkg.files = await expandFileGlobs(pkg.files);
|
|
51
|
+
}
|
|
52
|
+
|
|
49
53
|
if (options.cleanupFiles) {
|
|
50
54
|
await removeJunkFiles('.');
|
|
51
55
|
} else if (options.flatten) {
|
|
@@ -594,6 +598,25 @@ function isAlwaysIncludedByBasename(file) {
|
|
|
594
598
|
return alwaysIncludedBasenames.includes(basenameWithoutExtension);
|
|
595
599
|
}
|
|
596
600
|
|
|
601
|
+
function isGlobPattern(str) {
|
|
602
|
+
return /[*?[\]{}]/.test(str);
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
async function expandFileGlobs(files) {
|
|
606
|
+
|
|
607
|
+
const result = [];
|
|
608
|
+
for (const entry of files) {
|
|
609
|
+
if (isGlobPattern(entry)) {
|
|
610
|
+
for await (const match of fsGlob(entry)) {
|
|
611
|
+
result.push(normalizePath(match));
|
|
612
|
+
}
|
|
613
|
+
} else {
|
|
614
|
+
result.push(entry);
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
return [...new Set(result)];
|
|
618
|
+
}
|
|
619
|
+
|
|
597
620
|
async function cleanupDir(pkg, logger) {
|
|
598
621
|
logger.update('cleaning up files...');
|
|
599
622
|
|