Commit 45519d8
authored
## What?
Add `prependPath` option to `PHP.listFiles` method, which will prepend
given folder path to every file found in it.
## Why?
It's a common need to iterate over a list of files with each file path
being an accessible path instead of only the file name. Idea mentioned
in:
-
#427 (comment)
For example, this is a common pattern:
```ts
const files = await playground.listFiles( folderPath )
for (const file of files) {
const filePath = `${folderPath}/${file}`;
...
}
```
Also expressed as:
```ts
const filePaths = (await playground.listFiles( folderPath )).map(
(name: string) => `${folderPath}/${name}`)
)
```
With the new option, the above can be simplified as:
```ts
const filePaths = await playground.listFiles(folderPath, { prependPath: true })
```
## How?
- [x] Add `prependPath` option to `BasePHP.listFiles` method
- [x] Document the option and what it does
- [x] Add test
## Testing Instructions
<!-- Please include step by step instructions on how to test this PR.
-->
1. Check out the branch.
2. Run `nx test playground-blueprints`
1 parent 069930c commit 45519d8
File tree
3 files changed
+29
-2
lines changed- packages/php-wasm
- node/src/test
- universal/src/lib
3 files changed
+29
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
152 | 152 | | |
153 | 153 | | |
154 | 154 | | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
155 | 165 | | |
156 | 166 | | |
157 | 167 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
| |||
507 | 508 | | |
508 | 509 | | |
509 | 510 | | |
510 | | - | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
511 | 515 | | |
512 | 516 | | |
513 | 517 | | |
514 | 518 | | |
515 | | - | |
| 519 | + | |
516 | 520 | | |
517 | 521 | | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
518 | 527 | | |
519 | 528 | | |
520 | 529 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
439 | 439 | | |
440 | 440 | | |
441 | 441 | | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
0 commit comments