tomeraberbach / get-all-files Goto Github PK
View Code? Open in Web Editor NEW⚡ A blazing fast recursive directory crawler with lazy sync and async iterator support.
Home Page: https://npm.im/get-all-files
License: MIT License
⚡ A blazing fast recursive directory crawler with lazy sync and async iterator support.
Home Page: https://npm.im/get-all-files
License: MIT License
Hi,
Not sure this is the best place to ask, but I have this script.ts file:
import { getAllFilesSync } from "get-all-files";
getAllFilesSync(".")
and I run with ts-node script.ts but I get this error
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: C:\p\monorepo\node_modules\get-all-files\src\index.js
require() of ES modules is not supported.
require() of C:\p\monorepo\node_modules\get-all-files\src\index.js from C:\p\monorepo\tools\cli\prepush.ts is an ES module file as it is a .js file whose nearest
parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from C:\p\monorepo\node_modules\get-all-files\package.j
son.
Do you have any ideas? I'm on ts-node v9
Many thanks
I like the restructuring of the project in general, but moving to ESM makes it impossible / very hard to use the module for us at the moment. Could you add a parallel CommonJS build?
I've found a case where invoking getAllFiles() crashes Node 16.13.0. The log output below should have lines for start and close on "cat", but it doesn't. Furthermore, the finally block at the end of the test file should be deleting the temporary directory - and it isn't.
Test file, saved as testGetAllFiles.mjs
import { getAllFiles } from 'get-all-files';
import path from "path";
import fs from "fs/promises";
import os from "os";
const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), "test-get-all-files-"));
let tempDirResolve;
let tempDirPromise = new Promise(res => tempDirResolve = res);
tempDirPromise = tempDirPromise.then(() => fs.rm(tempDir, { recursive: true }));
/**
*
* @param {RegExp?} excludeDirFilter
*/
async function runTest(excludeDirFilter) {
const options = {};
if (excludeDirFilter instanceof RegExp) {
options.isExcludedDir = dirName => excludeDirFilter.test(dirName);
}
else if (typeof excludeDirFilter === "string") {
options.isExcludedDir = dirName => dirName.includes(excludeDirFilter);
}
try {
console.log("Start", excludeDirFilter || "no filter")
let results = await getAllFiles(tempDir, options).toArray();
console.log("Close", excludeDirFilter || "no filter", results);
}
catch (ex) {
console.log(excludeDirFilter, "exception thrown");
throw ex;
}
}
try {
await fs.mkdir(path.join(tempDir, "cat", "foo"), { recursive: true });
await fs.mkdir(path.join(tempDir, "spec", "one"), { recursive: true });
await fs.mkdir(path.join(tempDir, "spec", "two"), { recursive: true });
await fs.mkdir(path.join(tempDir, "dog", "car"), { recursive: true });
const fileList = [
"cat/foo/module1.mjs",
"cat/foo/module2.mjs",
"dog/car/module3.mjs",
"spec/one/module4.mjs",
"spec/two/module5.mjs",
"spec/two/module6.mjs",
];
await Promise.all(fileList.map(relativePath => {
return fs.writeFile(
path.join(tempDir, relativePath),
`console.log("Hello World");\n`,
{ encoding: "utf-8" }
);
}));
console.log("tempDir: " + tempDir);
await runTest();
await runTest("elephant");
await runTest("cat");
await runTest("monkey");
/*
await runTest(/elephant/);
await runTest(/cat/);
await runTest(/monkey/);
*/
console.log("Completed tests");
}
finally {
tempDirResolve();
await tempDirPromise;
console.error("exiting");
}
Resulting output:
$ node testGetAllFiles.mjs
tempDir: /tmp/test-get-all-files-1cWOqL
Start no filter
Close no filter [
'/tmp/test-get-all-files-1cWOqL/cat/foo/module2.mjs',
'/tmp/test-get-all-files-1cWOqL/cat/foo/module1.mjs',
'/tmp/test-get-all-files-1cWOqL/dog/car/module3.mjs',
'/tmp/test-get-all-files-1cWOqL/spec/one/module4.mjs',
'/tmp/test-get-all-files-1cWOqL/spec/two/module6.mjs',
'/tmp/test-get-all-files-1cWOqL/spec/two/module5.mjs'
]
Start elephant
Close elephant [
'/tmp/test-get-all-files-1cWOqL/cat/foo/module2.mjs',
'/tmp/test-get-all-files-1cWOqL/cat/foo/module1.mjs',
'/tmp/test-get-all-files-1cWOqL/spec/one/module4.mjs',
'/tmp/test-get-all-files-1cWOqL/spec/two/module6.mjs',
'/tmp/test-get-all-files-1cWOqL/spec/two/module5.mjs',
'/tmp/test-get-all-files-1cWOqL/dog/car/module3.mjs'
]
Start cat
This probably isn't your bug, but I'm filing it here so someone (hopefully not me) can reduce the testcase and file a bug against NodeJS, or (unlikely) V8.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.