Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 3 additions & 3 deletions lib/node/asar-fs-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,7 @@ export const wrapFsWithAsar = (fs: Record<string, any>) => {
nextTick(callback!, [error]);
return;
}
dirents.push(new fs.Dirent(file, stats.type));
dirents.push(getDirent(pathArgument, file, stats.type));
}
nextTick(callback!, [null, dirents]);
return;
Expand Down Expand Up @@ -942,7 +942,7 @@ export const wrapFsWithAsar = (fs: Record<string, any>) => {
if (!stats) {
throw createError(AsarError.NOT_FOUND, { asarPath, filePath: childPath });
}
dirents.push(new fs.Dirent(file, stats.type));
dirents.push(getDirent(pathArgument, file, stats.type));
}
return Promise.resolve(dirents);
}
Expand Down Expand Up @@ -985,7 +985,7 @@ export const wrapFsWithAsar = (fs: Record<string, any>) => {
if (!stats) {
throw createError(AsarError.NOT_FOUND, { asarPath, filePath: childPath });
}
dirents.push(new fs.Dirent(file, stats.type));
dirents.push(getDirent(pathArgument, file, stats.type));
}
return dirents;
}
Expand Down
25 changes: 25 additions & 0 deletions spec/asar-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1035,6 +1035,7 @@ describe('asar package', function () {
const dirs = fs.readdirSync(p, { withFileTypes: true });
for (const dir of dirs) {
expect(dir).to.be.an.instanceof(fs.Dirent);
expect(dir.parentPath).to.equal(p);
}
const names = dirs.map((a) => a.name);
expect(names).to.deep.equal(['dir1', 'dir2', 'dir3', 'file1', 'file2', 'file3', 'link1', 'link2', 'ping.js']);
Expand Down Expand Up @@ -1147,6 +1148,7 @@ describe('asar package', function () {
const dirs = await promisify(fs.readdir)(p, { withFileTypes: true });
for (const dir of dirs) {
expect(dir).to.be.an.instanceof(fs.Dirent);
expect(dir.parentPath).to.equal(p);
}

const names = dirs.map((a: any) => a.name);
Expand Down Expand Up @@ -1280,6 +1282,7 @@ describe('asar package', function () {
const dirs = await fs.promises.readdir(p, { withFileTypes: true });
for (const dir of dirs) {
expect(dir).to.be.an.instanceof(fs.Dirent);
expect(dir.parentPath).to.equal(p);
}
const names = dirs.map((a) => a.name);
expect(names).to.deep.equal(['dir1', 'dir2', 'dir3', 'file1', 'file2', 'file3', 'link1', 'link2', 'ping.js']);
Expand All @@ -1303,6 +1306,28 @@ describe('asar package', function () {
});
});

describe('fs.globSync', function () {
itremote('supports withFileTypes with a cwd inside an asar archive', function () {
const cwd = path.join(asarDir, 'a.asar');
const dirents = fs.globSync('*.js', { cwd, withFileTypes: true });
expect(dirents).to.have.lengthOf(1);
expect(dirents[0]).to.be.an.instanceof(fs.Dirent);
expect(dirents[0].name).to.equal('ping.js');
expect(dirents[0].parentPath).to.equal(cwd);
});
});

describe('fs.glob', function () {
itremote('supports withFileTypes with a cwd inside an asar archive', async function () {
const cwd = path.join(asarDir, 'a.asar');
const dirents = await promisify(fs.glob)('*.js', { cwd, withFileTypes: true });
expect(dirents).to.have.lengthOf(1);
expect(dirents[0]).to.be.an.instanceof(fs.Dirent);
expect(dirents[0].name).to.equal('ping.js');
expect(dirents[0].parentPath).to.equal(cwd);
});
});

describe('fs.openSync', function () {
itremote('opens a normal/linked/under-linked-directory file', function () {
const ref2 = ['file1', 'link1', path.join('link2', 'file1')];
Expand Down
Loading