Skip to content

Commit

Permalink
fix: ensure glob handles dot files correctly (#373)
Browse files Browse the repository at this point in the history
This ensures we support globbing files/folders that start with a `.`
properly as this is valid to trace.

x-ref: [slack
thread](https://vercel.slack.com/archives/C03S8ED1DKM/p1700210671195669)
  • Loading branch information
ijjk authored Dec 2, 2023
1 parent 40e890a commit 7317ee2
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/analyze.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ export default async function analyze(id: string, code: string, job: Job): Promi
if (job.log)
console.log('Globbing ' + assetDirPath + wildcardPattern);
const files = (await new Promise<string[]>((resolve, reject) =>
glob(assetDirPath + wildcardPattern, { mark: true, ignore: assetDirPath + '/**/node_modules/**/*' }, (err, files) => err ? reject(err) : resolve(files))
glob(assetDirPath + wildcardPattern, { mark: true, ignore: assetDirPath + '/**/node_modules/**/*', dot: true }, (err, files) => err ? reject(err) : resolve(files))
));
files
.filter(name =>
Expand Down
2 changes: 1 addition & 1 deletion src/utils/sharedlib-emit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export async function sharedLibEmit(path: string, job: Job) {
return;

const files = await new Promise<string[]>((resolve, reject) =>
glob(pkgPath + sharedlibGlob, { ignore: pkgPath + '/**/node_modules/**/*' }, (err, files) => err ? reject(err) : resolve(files))
glob(pkgPath + sharedlibGlob, { ignore: pkgPath + '/**/node_modules/**/*', dot: true }, (err, files) => err ? reject(err) : resolve(files))
);
await Promise.all(files.map(file => job.emitFile(file, 'sharedlib', path)));
};
16 changes: 16 additions & 0 deletions test/unit/glob-dot/input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const fs = require('fs');

const dotFiles = fs.readdirSync(
__dirname,
'with-dot'
)

const nonDotFiles = fs.readdirSync(
__dirname,
'without-dot'
)

console.log({
dotFiles,
nonDotFiles
});
7 changes: 7 additions & 0 deletions test/unit/glob-dot/output.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
"package.json",
"test/unit/glob-dot/input.js",
"test/unit/glob-dot/output.js",
"test/unit/glob-dot/with-dot/.dot/first.txt",
"test/unit/glob-dot/without-dot/normal/first.txt"
]
1 change: 1 addition & 0 deletions test/unit/glob-dot/with-dot/.dot/first.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hello
1 change: 1 addition & 0 deletions test/unit/glob-dot/without-dot/normal/first.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hello

0 comments on commit 7317ee2

Please sign in to comment.