Skip to content

Commit 5ea1dda

Browse files
committed
docs(README): update examples, add a warning
1 parent dd6483d commit 5ea1dda

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

README.md

+10-7
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ npm install file-folder-loader
1212

1313
## Usage & Examples
1414

15+
> [!WARNING]
16+
> By default, `isImportEnabled` is `true` when using `loadModulePaths()`. The module blindly imports modules unsandboxed. Only import modules from places you know. Modules that self-invoke code as soon as they're imported can have dangerous side-effects.
17+
1518
### Example 1: Loading Folder Paths
1619

1720
```typescript
@@ -63,12 +66,12 @@ async function init() {
6366
await init();
6467
```
6568

66-
### Example 3: Loading Folder Paths Sequentially and Loading Module Paths Concurrently
69+
### Example 3: Loading Folder Paths Sequentially and Loading Module Paths Concurrently (All recursive)
6770

6871
```typescript
6972
import * as nodeUrl from "node:url";
7073
import * as nodePath from "node:path";
71-
import { getFolderPaths, getModulePaths, loadFolders, loadModulePaths } from "file-folder-loader";
74+
import { getFolderPaths, getModulePaths, loadFolderPaths, loadModulePaths } from "file-folder-loader";
7275

7376
function getDirname(moduleAbsoluteFileUrl) {
7477
const fileName = nodeUrl.fileURLToPath(moduleAbsoluteFileUrl);
@@ -78,20 +81,20 @@ function getDirname(moduleAbsoluteFileUrl) {
7881
async function init() {
7982
const dirPath = nodePath.join(getDirname(import.meta.url), "someDirectory");
8083
// getFolderPaths option isRecursive = false by default
81-
const folderPaths = await getFolderPaths(dirPath);
84+
const folderPaths = await getFolderPaths(dirPath, { isRecursive: true });
8285
if (folderPaths.length > 0) {
83-
await loadFolders(folderPaths, async (folderPath, folderName) => {
86+
await loadFolderPaths(folderPaths, async (folderPath, folderName) => {
8487
console.log(`Loaded folder ${folderName} from path: ${folderPath}`);
85-
// getFolderPaths option isRecursive = false by default
86-
const modulePaths = await getModulePaths(folderPath, false);
88+
// getModulePaths option isRecursive = false by default
89+
const modulePaths = await getModulePaths(folderPath, { isRecursive: true });
8790
if (modulePaths.length > 0) {
8891
await loadModulePaths(modulePaths, async (moduleExport, fileUrlHref, fileName) => {
8992
console.log(`Loaded module ${fileName} from path: ${fileUrlHref}`);
9093
// moduleExport will be null because isImportEnabled is false (true by default)
9194
console.log(`Module export:`, moduleExport);
9295
}, { isImportEnabled: false });
9396
}
94-
}, { isConcurrent: true });
97+
}, { isConcurrent: false });
9598
}
9699
}
97100

0 commit comments

Comments
 (0)