Skip to content
This repository was archived by the owner on May 25, 2025. It is now read-only.

Commit 76dc3bc

Browse files
fix: kpy to properly expand directories (like globby did)
1 parent 882897c commit 76dc3bc

File tree

4 files changed

+38
-6
lines changed

4 files changed

+38
-6
lines changed

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
"secrets-gen-key-debug": "tsn ./src/bin/secrets-gen-key.ts",
1515
"secrets-encrypt-debug": "tsn ./src/bin/secrets-encrypt.ts",
1616
"secrets-decrypt-debug": "tsn ./src/bin/secrets-decrypt.ts",
17-
"kpy-debug": "tsn ./src/bin/kpy.ts node_modules dist",
17+
"kpy-debug": "tsn ./src/bin/kpy.ts --verbose scripts tmp/scripts",
18+
"kpy-debug2": "tsn ./src/bin/kpy.ts --verbose scripts bench non-ex non-ex/** colors* tmp/scripts",
19+
"kpy-debug3": "tsn ./src/bin/kpy.ts --verbose src colors csv stream non-ex non-ex/** tmp/src",
1820
"json2env-debug": "tsn ./src/bin/json2env.ts ./src/test/someFile.json"
1921
},
2022
"dependencies": {

src/bin/kpy.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ runScript(() => {
1111
} = yargs.demandCommand(2).options({
1212
silent: {
1313
type: 'boolean',
14-
descr: 'Suppress all text output', // todo: desc!
14+
desc: 'Suppress all text output',
1515
},
1616
verbose: {
1717
type: 'boolean',
18-
descr: 'Report progress on every file',
18+
desc: 'Report progress on every file',
1919
},
2020
overwrite: {
2121
type: 'boolean',

src/fs/fs2.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,21 @@ class FS2 {
299299
await this.removePathAsync(src)
300300
}
301301

302+
/**
303+
* Returns true if the path is a directory.
304+
* Otherwise returns false.
305+
* Doesn't throw, returns false instead.
306+
*/
307+
isDirectory(filePath: string): boolean {
308+
return (
309+
fs2
310+
.stat(filePath, {
311+
throwIfNoEntry: false,
312+
})
313+
?.isDirectory() || false
314+
)
315+
}
316+
302317
// Re-export the whole fs/fsp, for the edge cases where they are needed
303318
fs = fs
304319
fsp = fsp

src/fs/kpy.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import path from 'node:path'
2-
import { _since, UnixTimestampMillis } from '@naturalcycles/js-lib'
2+
import { _since, localTime, UnixTimestampMillis } from '@naturalcycles/js-lib'
33
import { boldWhite, dimGrey, grey, yellow } from '../colors/colors'
44
import { fastGlob, fs2 } from '../index'
55

@@ -43,7 +43,7 @@ export interface KpyOptions {
4343
}
4444

4545
export async function kpy(opt: KpyOptions): Promise<void> {
46-
const started = Date.now() as UnixTimestampMillis
46+
const started = localTime.nowUnixMillis()
4747

4848
kpyPrepare(opt)
4949

@@ -82,7 +82,7 @@ export async function kpy(opt: KpyOptions): Promise<void> {
8282
}
8383

8484
export function kpySync(opt: KpyOptions): void {
85-
const started = Date.now() as UnixTimestampMillis
85+
const started = localTime.nowUnixMillis()
8686

8787
kpyPrepare(opt)
8888

@@ -130,6 +130,21 @@ function kpyPrepare(opt: KpyOptions): void {
130130
}
131131

132132
fs2.ensureDir(opt.outputDir)
133+
134+
// Expand directories (ex-globby feature), experimental!
135+
const extraPatterns: string[] = []
136+
137+
for (const pattern of opt.inputPatterns) {
138+
if (pattern.includes('*')) continue
139+
if (fs2.isDirectory(path.resolve(opt.baseDir, pattern))) {
140+
extraPatterns.push(`${pattern}/**`)
141+
}
142+
}
143+
144+
if (opt.verbose) {
145+
console.log({ extraPatterns })
146+
}
147+
opt.inputPatterns.push(...extraPatterns)
133148
}
134149

135150
function kpyLogFilenames(opt: KpyOptions, filenames: string[]): void {

0 commit comments

Comments
 (0)