30 lines
805 B
JavaScript
30 lines
805 B
JavaScript
import { glob } from "glob";
|
|
import path from "path";
|
|
import os from "os";
|
|
import fs from "fs";
|
|
|
|
async function test() {
|
|
const tempDir = await fs.promises.mkdtemp(
|
|
path.join(os.tmpdir(), "glob-test-"),
|
|
);
|
|
const file = path.join(tempDir, "test.js");
|
|
await fs.promises.writeFile(file, "test");
|
|
|
|
const pattern = "*.js";
|
|
const globPattern = path.join(tempDir, pattern);
|
|
console.log("globPattern:", globPattern);
|
|
|
|
const files = await glob(globPattern);
|
|
console.log("found files:", files);
|
|
|
|
// Fix for windows
|
|
const fixedPattern = globPattern.replace(/\\/g, "/");
|
|
console.log("fixedPattern:", fixedPattern);
|
|
const fixedFiles = await glob(fixedPattern);
|
|
console.log("found fixed files:", fixedFiles);
|
|
|
|
await fs.promises.rm(tempDir, { recursive: true, force: true });
|
|
}
|
|
|
|
test();
|