Skip to content

Commit

Permalink
Fix archiver task ignore options
Browse files Browse the repository at this point in the history
  • Loading branch information
sibiraj-s committed Jun 27, 2021
1 parent 5c6f84b commit 019f8da
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/actions/archive.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ const archive = async (task, { logger }) => {
const destFile = path.basename(absoluteDestination);
const destDir = path.dirname(absoluteDestination);

const ignore = Array.isArray(options.ignore) ? [...options.ignore, destFile] : [destFile];
const fileToIgnore = typeof options.ignore === 'string' ? [...ignore, options.ignore] : ignore;
const inputGlobOptions = options.globOptions || {};

const archiverOptions = { ...(options.globOptions || {}), ignore: fileToIgnore };
const ignore = Array.isArray(inputGlobOptions.ignore) ? [...inputGlobOptions.ignore, destFile] : [destFile];
const fileToIgnore = typeof inputGlobOptions.ignore === 'string' ? [...ignore, inputGlobOptions.ignore] : ignore;
const globOptions = { ...inputGlobOptions, ignore: fileToIgnore };

await fsExtra.ensureDir(destDir);

Expand All @@ -29,7 +30,7 @@ const archive = async (task, { logger }) => {

if (isGlob(source)) {
const opts = {
...archiverOptions,
...globOptions,
cwd: context,
};

Expand All @@ -39,7 +40,7 @@ const archive = async (task, { logger }) => {

if (sStat.isDirectory()) {
const opts = {
...archiverOptions,
...globOptions,
cwd: absoluteSource,
};

Expand Down
72 changes: 72 additions & 0 deletions tests/archive.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,3 +203,75 @@ test('should include files in the archive', async (t) => {
t.true(await zipHasFile(zipPath, 'file1'));
t.true(await zipHasFile(zipPath, 'file2'));
});

test('should ignore files in the archive correclty if ignore is an array', async (t) => {
const { tmpdir } = t.context;
await tempy.file(tmpdir, 'file1');
await tempy.file(tmpdir, 'file2');

const zipName = tempy.getZipName();

const config = {
context: tmpdir,
events: {
onEnd: {
archive: [
{
source: './',
destination: zipName,
options: {
globOptions: {
ignore: ['**/**/file2'],
},
},
},
],
},
},
};

const compiler = getCompiler();
new FileManagerPlugin(config).apply(compiler);
await compile(compiler);

const zipPath = join(tmpdir, zipName);

t.true(await zipHasFile(zipPath, 'file1'));
t.false(await zipHasFile(zipPath, 'file2'));
});

test('should ignore files in the archive correclty if ignore is a string', async (t) => {
const { tmpdir } = t.context;
await tempy.file(tmpdir, 'file1');
await tempy.file(tmpdir, 'file2');

const zipName = tempy.getZipName();

const config = {
context: tmpdir,
events: {
onEnd: {
archive: [
{
source: './',
destination: zipName,
options: {
globOptions: {
ignore: '**/**/file2',
},
},
},
],
},
},
};

const compiler = getCompiler();
new FileManagerPlugin(config).apply(compiler);
await compile(compiler);

const zipPath = join(tmpdir, zipName);

t.true(await zipHasFile(zipPath, 'file1'));
t.false(await zipHasFile(zipPath, 'file2'));
});

0 comments on commit 019f8da

Please sign in to comment.