Skip to content

Commit

Permalink
add debug
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikolay Matrosov committed Jul 5, 2023
1 parent b18db19 commit bd70ddb
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 27 deletions.
44 changes: 21 additions & 23 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ test.skip('test runs', () => {
console.log(res?.toString());
});

describe('zipSources', function() {
describe('zipSources', function () {
test('it should add files from include', async () => {
const archive = archiver('zip', {zlib: {level: 9}});
const inputs: ZipInputs = {
Expand Down Expand Up @@ -99,28 +99,26 @@ describe('zipSources', function() {
expect(entries.length).toEqual(9);
});

test.each([
['./src'],
['./src/'],
['src'],
],
)('it should respect source root and include only needed files with root %s', async (sourceRoot) => {
const archive = archiver('zip', {zlib: {level: 9}});
const inputs: ZipInputs = {
include: ['./*.js', 'foo/1.txt'],
excludePattern: [],
sourceRoot,
};

const entries: archiver.EntryData[] = [];
archive.on('entry', e => entries.push(e));
await zipSources(inputs, archive);

const noneStartWithSrc = entries.every(e => !e.name.includes('src'));
expect(noneStartWithSrc).toBeTruthy();
expect(entries.length).toBe(2);
expect(entries[0].name).toBe('func.js');
});
test.each([['./src'], ['./src/'], ['src']])(
'it should respect source root and include only needed files with root %s',
async sourceRoot => {
const archive = archiver('zip', {zlib: {level: 9}});
const inputs: ZipInputs = {
include: ['./*.js', 'foo/1.txt'],
excludePattern: [],
sourceRoot,
};

const entries: archiver.EntryData[] = [];
archive.on('entry', e => entries.push(e));
await zipSources(inputs, archive);

const noneStartWithSrc = entries.every(e => !e.name.includes('src'));
expect(noneStartWithSrc).toBeTruthy();
expect(entries.length).toBe(2);
expect(entries[0].name).toBe('func.js');
},
);

test('it should add folders', async () => {
const archive = archiver('zip', {zlib: {level: 9}});
Expand Down
34 changes: 31 additions & 3 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,11 +268,13 @@ export async function zipSources(inputs: ZipInputs, archive: archiver.Archiver):
const matches = glob.sync(pathFromSourceRoot, {absolute: false});
for (const match of matches) {
if (fs.lstatSync(match).isDirectory()) {
core.debug(`match: dir ${match}`);
archive.directory(pathFromSourceRoot, include, data => {
const res = !patterns.map(p => minimatch(data.name, p)).some(x => x);
return res ? data : false;
});
} else {
core.debug(`match: file ${match}`);
archive.file(match, {name: path.relative(root, match)});
}
}
Expand Down

0 comments on commit bd70ddb

Please sign in to comment.