knip 2.7.0 → 2.7.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.
- package/README.md +21 -1
- package/dist/util/glob.js +14 -6
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -646,7 +646,27 @@ Many thanks to some of the early adopters of Knip:
|
|
|
646
646
|
- [release-it][27]
|
|
647
647
|
- [Template TypeScript Node Package][28]
|
|
648
648
|
|
|
649
|
-
##
|
|
649
|
+
## 🐣 Super Secret Easter Egg Boost 🚀
|
|
650
|
+
|
|
651
|
+
Running Knip on large workspaces with many packages may feel a bit sluggish. Knip looks up `.gitignore` files and uses
|
|
652
|
+
them to filter out matching entry and project files. This increases correctness. However, you might want to disable that
|
|
653
|
+
with `--no-gitignore` and enjoy a significant performance boost. Depending on the contents of the `.gitignore` files,
|
|
654
|
+
the reported issues may be the same. To help determine whether this trade-off might be worth it for you, first check the
|
|
655
|
+
difference in unused files:
|
|
656
|
+
|
|
657
|
+
```shell
|
|
658
|
+
diff <(knip --no-gitignore --include files) <(knip --include files)
|
|
659
|
+
```
|
|
660
|
+
|
|
661
|
+
And to measure the difference of this flag in seconds:
|
|
662
|
+
|
|
663
|
+
```shell
|
|
664
|
+
SECONDS=0; knip > /dev/null; t1=$SECONDS; SECONDS=0; knip --no-gitignore > /dev/null; t2=$SECONDS; echo "Difference: $((t1 - t2)) seconds"
|
|
665
|
+
```
|
|
666
|
+
|
|
667
|
+
⏲️ Analysis on a large project went from 33 down to 9 seconds (that's >70% faster). Happy Easter! 🐣
|
|
668
|
+
|
|
669
|
+
## Knip
|
|
650
670
|
|
|
651
671
|
Knip is Dutch for a "cut". A Dutch expression is "to be ge**knip**t for something", which means to be perfectly suited
|
|
652
672
|
for the job. I'm motivated to make Knip perfectly suited for the job of cutting projects to perfection! ✂️
|
package/dist/util/glob.js
CHANGED
|
@@ -16,9 +16,13 @@ export const hasNoProductionSuffix = (pattern) => !pattern.endsWith('!');
|
|
|
16
16
|
const removeProductionSuffix = (pattern) => pattern.replace(/!$/, '');
|
|
17
17
|
const negatedLast = (pattern) => (pattern.startsWith('!') ? 1 : -1);
|
|
18
18
|
const glob = async ({ cwd, workingDir = cwd, patterns, ignore = [], gitignore = true }) => {
|
|
19
|
+
if (patterns.length === 0)
|
|
20
|
+
return [];
|
|
19
21
|
const relativePath = relative(cwd, workingDir);
|
|
20
22
|
const prepend = (pattern) => prependDirToPattern(relativePath, pattern);
|
|
21
23
|
const globPatterns = compact([patterns].flat().map(prepend).map(removeProductionSuffix)).sort(negatedLast);
|
|
24
|
+
if (globPatterns[0].startsWith('!'))
|
|
25
|
+
return [];
|
|
22
26
|
const ignorePatterns = compact([...ignore, '**/node_modules/**']);
|
|
23
27
|
debugLogObject(`Globbing (${relativePath || ROOT_WORKSPACE_NAME})`, { cwd, globPatterns, ignorePatterns });
|
|
24
28
|
return globby(globPatterns, {
|
|
@@ -29,12 +33,16 @@ const glob = async ({ cwd, workingDir = cwd, patterns, ignore = [], gitignore =
|
|
|
29
33
|
dot: true,
|
|
30
34
|
});
|
|
31
35
|
};
|
|
32
|
-
const pureGlob = async ({ cwd, patterns, ignore = [], gitignore = true }) =>
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
const pureGlob = async ({ cwd, patterns, ignore = [], gitignore = true }) => {
|
|
37
|
+
if (patterns.length === 0)
|
|
38
|
+
return [];
|
|
39
|
+
return globby(patterns, {
|
|
40
|
+
cwd,
|
|
41
|
+
ignore: [...ignore, '**/node_modules/**'],
|
|
42
|
+
gitignore,
|
|
43
|
+
absolute: true,
|
|
44
|
+
});
|
|
45
|
+
};
|
|
38
46
|
const firstGlob = async ({ cwd, patterns }) => {
|
|
39
47
|
const stream = fg.stream(patterns.map(removeProductionSuffix), { cwd, ignore: ['**/node_modules/**'] });
|
|
40
48
|
for await (const entry of stream) {
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "2.7.
|
|
1
|
+
export declare const version = "2.7.1";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '2.7.
|
|
1
|
+
export const version = '2.7.1';
|
package/package.json
CHANGED