Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix recursing to find files in Node <18.17 #332

Merged
merged 3 commits into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node: [18, 20, 22]
node: ['18.16.0', 20, 22]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's update the engines field in package.json to match.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh or maybe with this change we actually end up supporting back more so we can leave engines where it is at now.

name: Node ${{ matrix.node }}
steps:
- uses: actions/checkout@v4
Expand Down
28 changes: 15 additions & 13 deletions src/deterministicArchive.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Writable } from 'stream';
import crypto from 'crypto';
import fs from 'fs';
import path from 'path';
import { glob } from 'glob';

import Archiver from 'archiver';

Expand All @@ -22,20 +23,21 @@ async function resolveFilesRecursiveForDir(dirOrFile) {
const isDir = (await fs.promises.lstat(resolvedDirOrFile)).isDirectory();

if (isDir) {
const files = await fs.promises.readdir(resolvedDirOrFile, {
withFileTypes: true,
recursive: true,
const files = Array.from(
await glob.sync('**/*', {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

await glob.sync is a bit strange for a couple of reasons:

  1. globSync is a named export of the glob package, that I think we'd want instead of this if we want synchronous mode
  2. await a sync function is unnecessary
  3. Since we are in an async function can we use the async glob?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I kept glob.sync because of issues locally. Turns out I hadn't yarn installed in a while.

cwd: resolvedDirOrFile,
nodir: true,
absolute: true,
dot: true,
}),
);

return files.map((fullPath) => {
return {
name: path.relative(resolvedDirOrFile, fullPath),
stream: fs.createReadStream(fullPath),
};
});

return files
.filter((dirent) => dirent.isFile())
.map((dirent) => {
const fullPath = path.join(dirent.path, dirent.name);
return {
name: fullPath.slice(resolvedDirOrFile.length + 1),
stream: fs.createReadStream(fullPath),
};
});
}

return [
Expand Down