From fd4c5573e2c5853b68dd3fc1b4298f9d10be8b39 Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Tue, 13 Dec 2022 15:14:12 -0500 Subject: [PATCH 1/3] fix: allow assets to be false --- lib/prepare.js | 47 +++++++++++++++++++++++--------------------- test/prepare.test.js | 30 ++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 22 deletions(-) diff --git a/lib/prepare.js b/lib/prepare.js index cbac855e..b331cc9c 100644 --- a/lib/prepare.js +++ b/lib/prepare.js @@ -32,29 +32,32 @@ module.exports = async (pluginConfig, context) => { const modifiedFiles = await getModifiedFiles({env, cwd}); - const filesToCommit = uniq( - await pReduce( - assets.map((asset) => (!isArray(asset) && isPlainObject(asset) ? asset.path : asset)), - async (result, asset) => { - const glob = castArray(asset); - let nonegate; - // Skip solo negated pattern (avoid to include every non js file with `!**/*.js`) - if (glob.length <= 1 && glob[0].startsWith('!')) { - nonegate = true; - debug( - 'skipping the negated glob %o as its alone in its group and would retrieve a large amount of files ', - glob[0] - ); - } + const filesToCommit = + assets && assets.length > 0 + ? uniq( + await pReduce( + assets.map((asset) => (!isArray(asset) && isPlainObject(asset) ? asset.path : asset)), + async (result, asset) => { + const glob = castArray(asset); + let nonegate; + // Skip solo negated pattern (avoid to include every non js file with `!**/*.js`) + if (glob.length <= 1 && glob[0].startsWith('!')) { + nonegate = true; + debug( + 'skipping the negated glob %o as its alone in its group and would retrieve a large amount of files ', + glob[0] + ); + } - return [ - ...result, - ...micromatch(modifiedFiles, await dirGlob(glob, {cwd}), {dot: true, nonegate, cwd, expand: true}), - ]; - }, - [] - ) - ); + return [ + ...result, + ...micromatch(modifiedFiles, await dirGlob(glob, {cwd}), {dot: true, nonegate, cwd, expand: true}), + ]; + }, + [] + ) + ) + : []; if (filesToCommit.length > 0) { logger.log('Found %d file(s) to commit', filesToCommit.length); diff --git a/test/prepare.test.js b/test/prepare.test.js index 8e7d97a1..4864bf3a 100644 --- a/test/prepare.test.js +++ b/test/prepare.test.js @@ -123,6 +123,36 @@ test('Commit files matching the patterns in "assets"', async (t) => { t.deepEqual(t.context.log.args[0], ['Found %d file(s) to commit', 5]); }); +test('Commit no files when "assets" is false', async (t) => { + const {cwd, repositoryUrl} = await gitRepo(true); + const pluginConfig = { + assets: false, + }; + const branch = {name: 'master'}; + const options = {repositoryUrl}; + const env = {}; + const lastRelease = {}; + const nextRelease = {version: '2.0.0', gitTag: 'v2.0.0'}; + // Create .gitignore to ignore file5.js + await outputFile(path.resolve(cwd, '.gitignore'), 'file5.js'); + await outputFile(path.resolve(cwd, 'file1.js'), 'Test content'); + await outputFile(path.resolve(cwd, 'dir/file2.js'), 'Test content'); + await outputFile(path.resolve(cwd, 'dir/file3.css'), 'Test content'); + await outputFile(path.resolve(cwd, 'file4.js'), 'Test content'); + await outputFile(path.resolve(cwd, 'file5.js'), 'Test content'); + await outputFile(path.resolve(cwd, 'dir2/file6.js'), 'Test content'); + await outputFile(path.resolve(cwd, 'dir2/file7.css'), 'Test content'); + + await prepare(pluginConfig, {cwd, env, options, branch, lastRelease, nextRelease, logger: t.context.logger}); + + // Verify file2 and file1 have been commited + // file4.js is excluded as no glob matching + // file3.css is ignored due to the negative glob '!dir/*.css' + // file5.js is not ignored even if it's in the .gitignore + // file6.js and file7.css are included because dir2 is expanded + t.deepEqual((await gitCommitedFiles('HEAD', {cwd, env})).sort(), []); +}); + test('Commit files matching the patterns in "assets" as Objects', async (t) => { const {cwd, repositoryUrl} = await gitRepo(true); const pluginConfig = { From cdde211b9e0f58168fa15e42fcd7cfc0028c2e58 Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Tue, 13 Dec 2022 15:16:16 -0500 Subject: [PATCH 2/3] remove some unnecessary test data --- test/prepare.test.js | 9 --------- 1 file changed, 9 deletions(-) diff --git a/test/prepare.test.js b/test/prepare.test.js index 4864bf3a..acda3d92 100644 --- a/test/prepare.test.js +++ b/test/prepare.test.js @@ -133,15 +133,6 @@ test('Commit no files when "assets" is false', async (t) => { const env = {}; const lastRelease = {}; const nextRelease = {version: '2.0.0', gitTag: 'v2.0.0'}; - // Create .gitignore to ignore file5.js - await outputFile(path.resolve(cwd, '.gitignore'), 'file5.js'); - await outputFile(path.resolve(cwd, 'file1.js'), 'Test content'); - await outputFile(path.resolve(cwd, 'dir/file2.js'), 'Test content'); - await outputFile(path.resolve(cwd, 'dir/file3.css'), 'Test content'); - await outputFile(path.resolve(cwd, 'file4.js'), 'Test content'); - await outputFile(path.resolve(cwd, 'file5.js'), 'Test content'); - await outputFile(path.resolve(cwd, 'dir2/file6.js'), 'Test content'); - await outputFile(path.resolve(cwd, 'dir2/file7.css'), 'Test content'); await prepare(pluginConfig, {cwd, env, options, branch, lastRelease, nextRelease, logger: t.context.logger}); From 81e477d0174674175b6e5458b3ae6bd7de68fec6 Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Tue, 13 Dec 2022 15:16:40 -0500 Subject: [PATCH 3/3] even less test stuff --- test/prepare.test.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/test/prepare.test.js b/test/prepare.test.js index acda3d92..82110ff8 100644 --- a/test/prepare.test.js +++ b/test/prepare.test.js @@ -136,11 +136,6 @@ test('Commit no files when "assets" is false', async (t) => { await prepare(pluginConfig, {cwd, env, options, branch, lastRelease, nextRelease, logger: t.context.logger}); - // Verify file2 and file1 have been commited - // file4.js is excluded as no glob matching - // file3.css is ignored due to the negative glob '!dir/*.css' - // file5.js is not ignored even if it's in the .gitignore - // file6.js and file7.css are included because dir2 is expanded t.deepEqual((await gitCommitedFiles('HEAD', {cwd, env})).sort(), []); });