Skip to content

Commit 4635ce8

Browse files
authored
perf: switch to tinyglobby
Merge pull request #480 from 43081j/tinyglobby-fix
2 parents d299b09 + b5f5300 commit 4635ce8

File tree

4 files changed

+38
-68
lines changed

4 files changed

+38
-68
lines changed

packages/node-plop/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,14 @@
4343
},
4444
"dependencies": {
4545
"@types/inquirer": "^9.0.9",
46+
"@types/picomatch": "^4.0.2",
4647
"change-case": "^5.4.4",
4748
"dlv": "^1.1.3",
48-
"globby": "^14.1.0",
4949
"handlebars": "^4.7.8",
5050
"inquirer": "^9.3.8",
5151
"isbinaryfile": "^5.0.6",
5252
"resolve": "^1.22.10",
53+
"tinyglobby": "^0.2.15",
5354
"title-case": "^4.3.2"
5455
}
5556
}

packages/node-plop/src/actions/addMany.js

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import path from "path";
22
import fs from "fs";
3-
import { globbySync } from "globby";
3+
import { globSync } from "tinyglobby";
44
import actionInterfaceTest from "./_common-action-interface-check.js";
55
import addFile from "./_common-action-add-file.js";
66
import { normalizePath } from "./_common-action-utils.js";
@@ -44,14 +44,16 @@ export default async function (data, userConfig, plop) {
4444
);
4545

4646
const filesAdded = [];
47+
const plopFilePath = path.resolve(plop.getPlopfilePath());
48+
const absBasePath = path.resolve(plopFilePath, cfg.base || "");
4749
for (let templateFile of templateFiles) {
48-
const absTemplatePath = path.resolve(plop.getPlopfilePath(), templateFile);
50+
const relativeTemplatePath = path.relative(absBasePath, templateFile);
4951
const fileCfg = Object.assign({}, cfg, {
5052
path: stripExtensions(
5153
cfg.stripExtensions,
52-
resolvePath(cfg.destination, templateFile, cfg.base),
54+
resolvePath(cfg.destination, relativeTemplatePath, cfg.base),
5355
),
54-
templateFile: absTemplatePath,
56+
templateFile: templateFile,
5557
});
5658
const addedPath = await addFile(data, fileCfg, plop);
5759
filesAdded.push(addedPath);
@@ -63,21 +65,25 @@ export default async function (data, userConfig, plop) {
6365
}
6466

6567
function resolveTemplateFiles(templateFilesGlob, basePath, globOptions, plop) {
66-
globOptions = Object.assign({ cwd: plop.getPlopfilePath() }, globOptions);
67-
return globbySync(
68-
templateFilesGlob,
69-
Object.assign({ braceExpansion: false }, globOptions),
70-
)
71-
.filter(isUnder(basePath))
72-
.filter(isAbsoluteOrRelativeFileTo(plop.getPlopfilePath()));
68+
const absPlopfilePath = path.resolve(plop.getPlopfilePath());
69+
const absBasePath = path.resolve(absPlopfilePath, basePath || "");
70+
return globSync(templateFilesGlob, {
71+
cwd: absPlopfilePath,
72+
braceExpansion: false,
73+
expandDirectories: true,
74+
absolute: true,
75+
...globOptions,
76+
})
77+
.filter(isUnder(absBasePath))
78+
.filter(isAbsoluteOrRelativeFileTo(absPlopfilePath));
7379
}
74-
function isAbsoluteOrRelativeFileTo(relativePath) {
75-
const isFile = (file) => fs.existsSync(file) && fs.lstatSync(file).isFile();
76-
return (file) => isFile(file) || isFile(path.join(relativePath, file));
80+
function isAbsoluteOrRelativeFileTo(basePath) {
81+
return (file) => fs.existsSync(file) && fs.lstatSync(file).isFile();
7782
}
7883

7984
function isUnder(basePath = "") {
80-
return (path) => path.startsWith(basePath);
85+
const normalizedBasePath = basePath.replace(/\\/g, "/");
86+
return (file) => file.startsWith(normalizedBasePath);
8187
}
8288

8389
function resolvePath(destination, file, rootPath) {

packages/node-plop/types/index.d.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@ import inquirer, {
1515

1616
type Inquirer = typeof inquirer;
1717

18-
// @types/globby doesn't export types for GlobOptions, so we have to work a little bit to extract them:
19-
// GlobOptions is the second parameter of the sync function, which can be extracted with the Parameters<T> type
20-
import { globbySync } from "globby";
21-
type GlobOptions = Parameters<typeof globbySync>[1];
18+
import { type GlobOptions } from "tinyglobby";
2219
import { HelperDelegate as HelperFunction } from "handlebars";
2320

2421
export interface IncludeDefinitionConfig {

yarn.lock

Lines changed: 14 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,13 +1170,6 @@ __metadata:
11701170
languageName: node
11711171
linkType: hard
11721172

1173-
"@sindresorhus/merge-streams@npm:^2.1.0":
1174-
version: 2.3.0
1175-
resolution: "@sindresorhus/merge-streams@npm:2.3.0"
1176-
checksum: 10/798bcb53cd1ace9df84fcdd1ba86afdc9e0cd84f5758d26ae9b1eefd8e8887e5fc30051132b9e74daf01bb41fa5a2faf1369361f83d76a3b3d7ee938058fd71c
1177-
languageName: node
1178-
linkType: hard
1179-
11801173
"@tootallnate/once@npm:2":
11811174
version: 2.0.0
11821175
resolution: "@tootallnate/once@npm:2.0.0"
@@ -1297,6 +1290,13 @@ __metadata:
12971290
languageName: node
12981291
linkType: hard
12991292

1293+
"@types/picomatch@npm:^4.0.2":
1294+
version: 4.0.2
1295+
resolution: "@types/picomatch@npm:4.0.2"
1296+
checksum: 10/7b74f860c4c2bf30f7952254717df2dd78441b0add79858dffe7f6a30c9dd6da6c3d7769d2a9f0c499bc5ffe820c629bffc7c5128948febfc2b935800169b1c3
1297+
languageName: node
1298+
linkType: hard
1299+
13001300
"@types/through@npm:*":
13011301
version: 0.0.30
13021302
resolution: "@types/through@npm:0.0.30"
@@ -2094,9 +2094,9 @@ __metadata:
20942094
linkType: hard
20952095

20962096
"chalk@npm:^5.6.0":
2097-
version: 5.6.2
2098-
resolution: "chalk@npm:5.6.2"
2099-
checksum: 10/1b2f48f6fba1370670d5610f9cd54c391d6ede28f4b7062dd38244ea5768777af72e5be6b74fb6c6d54cb84c4a2dff3f3afa9b7cb5948f7f022cfd3d087989e0
2097+
version: 5.6.0
2098+
resolution: "chalk@npm:5.6.0"
2099+
checksum: 10/f0e0646a72adbd0f6e73441d3872d7f2f40ba98052924f08a30c10634ec6b1e2cd19cc3c40cc21081dad640e2a1a2749030418571690b89bd7782babf7f89866
21002100
languageName: node
21012101
linkType: hard
21022102

@@ -3062,7 +3062,7 @@ __metadata:
30623062
languageName: node
30633063
linkType: hard
30643064

3065-
"fast-glob@npm:^3.3.2, fast-glob@npm:^3.3.3":
3065+
"fast-glob@npm:^3.3.2":
30663066
version: 3.3.3
30673067
resolution: "fast-glob@npm:3.3.3"
30683068
dependencies:
@@ -3593,20 +3593,6 @@ __metadata:
35933593
languageName: node
35943594
linkType: hard
35953595

3596-
"globby@npm:^14.1.0":
3597-
version: 14.1.0
3598-
resolution: "globby@npm:14.1.0"
3599-
dependencies:
3600-
"@sindresorhus/merge-streams": "npm:^2.1.0"
3601-
fast-glob: "npm:^3.3.3"
3602-
ignore: "npm:^7.0.3"
3603-
path-type: "npm:^6.0.0"
3604-
slash: "npm:^5.1.0"
3605-
unicorn-magic: "npm:^0.3.0"
3606-
checksum: 10/e527ff54f0dddf60abfabd0d9e799768619d957feecd8b13ef60481f270bfdce0d28f6b09267c60f8064798fb3003b8ec991375f7fe0233fbce5304e1741368c
3607-
languageName: node
3608-
linkType: hard
3609-
36103596
"graceful-fs@npm:^4.1.15, graceful-fs@npm:^4.1.2, graceful-fs@npm:^4.1.6, graceful-fs@npm:^4.2.0, graceful-fs@npm:^4.2.4":
36113597
version: 4.2.9
36123598
resolution: "graceful-fs@npm:4.2.9"
@@ -3869,7 +3855,7 @@ __metadata:
38693855
languageName: node
38703856
linkType: hard
38713857

3872-
"ignore@npm:^7.0.0, ignore@npm:^7.0.3":
3858+
"ignore@npm:^7.0.0":
38733859
version: 7.0.5
38743860
resolution: "ignore@npm:7.0.5"
38753861
checksum: 10/f134b96a4de0af419196f52c529d5c6120c4456ff8a6b5a14ceaaa399f883e15d58d2ce651c9b69b9388491d4669dda47285d307e827de9304a53a1824801bc6
@@ -4994,15 +4980,16 @@ __metadata:
49944980
"@types/inquirer": "npm:^9.0.9"
49954981
"@types/inquirer-autocomplete-prompt": "npm:^3.0.3"
49964982
"@types/node": "npm:^20.19.17"
4983+
"@types/picomatch": "npm:^4.0.2"
49974984
change-case: "npm:^5.4.4"
49984985
dlv: "npm:^1.1.3"
49994986
dtslint: "npm:^4.2.1"
5000-
globby: "npm:^14.1.0"
50014987
handlebars: "npm:^4.7.8"
50024988
inquirer: "npm:^9.3.8"
50034989
isbinaryfile: "npm:^5.0.6"
50044990
plop-pack-fancy-comments: "npm:^0.2.1"
50054991
resolve: "npm:^1.22.10"
4992+
tinyglobby: "npm:^0.2.15"
50064993
title-case: "npm:^4.3.2"
50074994
typescript: "npm:^5.9.2"
50084995
vitest: "npm:^3.2.4"
@@ -5441,13 +5428,6 @@ __metadata:
54415428
languageName: node
54425429
linkType: hard
54435430

5444-
"path-type@npm:^6.0.0":
5445-
version: 6.0.0
5446-
resolution: "path-type@npm:6.0.0"
5447-
checksum: 10/b9f6eaf7795c48d5c9bc4c6bc3ac61315b8d36975a73497ab2e02b764c0836b71fb267ea541863153f633a069a1c2ed3c247cb781633842fc571c655ac57c00e
5448-
languageName: node
5449-
linkType: hard
5450-
54515431
"pathe@npm:^2.0.3":
54525432
version: 2.0.3
54535433
resolution: "pathe@npm:2.0.3"
@@ -6213,13 +6193,6 @@ __metadata:
62136193
languageName: node
62146194
linkType: hard
62156195

6216-
"slash@npm:^5.1.0":
6217-
version: 5.1.0
6218-
resolution: "slash@npm:5.1.0"
6219-
checksum: 10/2c41ec6fb1414cd9bba0fa6b1dd00e8be739e3fe85d079c69d4b09ca5f2f86eafd18d9ce611c0c0f686428638a36c272a6ac14799146a8295f259c10cc45cde4
6220-
languageName: node
6221-
linkType: hard
6222-
62236196
"slice-ansi@npm:^7.1.0":
62246197
version: 7.1.2
62256198
resolution: "slice-ansi@npm:7.1.2"
@@ -7016,13 +6989,6 @@ __metadata:
70166989
languageName: node
70176990
linkType: hard
70186991

7019-
"unicorn-magic@npm:^0.3.0":
7020-
version: 0.3.0
7021-
resolution: "unicorn-magic@npm:0.3.0"
7022-
checksum: 10/bdd7d7c522f9456f32a0b77af23f8854f9a7db846088c3868ec213f9550683ab6a2bdf3803577eacbafddb4e06900974385841ccb75338d17346ccef45f9cb01
7023-
languageName: node
7024-
linkType: hard
7025-
70266992
"unique-filename@npm:^3.0.0":
70276993
version: 3.0.0
70286994
resolution: "unique-filename@npm:3.0.0"

0 commit comments

Comments
 (0)