Skip to content

Commit efcc05e

Browse files
committed
Show unpublished files as warning instead of blocking prompt
Fixes #713
1 parent d8f3322 commit efcc05e

File tree

2 files changed

+39
-15
lines changed

2 files changed

+39
-15
lines changed

source/ui.js

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -81,21 +81,18 @@ const checkNewFilesAndDependencies = async (package_, rootDirectory) => {
8181
const newFiles = await util.getNewFiles(rootDirectory);
8282
const newDependencies = await util.getNewDependencies(package_, rootDirectory);
8383

84-
const noNewUnpublishedFiles = !newFiles.unpublished || newFiles.unpublished.length === 0;
8584
const noNewFirstTimeFiles = !newFiles.firstTime || newFiles.firstTime.length === 0;
86-
const noNewFiles = noNewUnpublishedFiles && noNewFirstTimeFiles;
87-
8885
const noNewDependencies = !newDependencies || newDependencies.length === 0;
8986

90-
if (noNewFiles && noNewDependencies) {
91-
return true;
87+
// Only prompt for first-time files and new dependencies (things that WILL be published)
88+
if (noNewFirstTimeFiles && noNewDependencies) {
89+
return {
90+
confirmed: true,
91+
unpublishedFiles: newFiles.unpublished || [],
92+
};
9293
}
9394

9495
const messages = [];
95-
if (newFiles.unpublished.length > 0) {
96-
messages.push(`The following new files will not be part of your published package:\n${util.groupFilesInFolders(newFiles.unpublished)}\n\nIf you intended to publish them, add them to the \`files\` field in package.json.`);
97-
}
98-
9996
if (newFiles.firstTime.length > 0) {
10097
messages.push(`The following new files will be published for the first time:\n${util.joinList(newFiles.firstTime)}\n\nPlease make sure only the intended files are listed.`);
10198
}
@@ -106,7 +103,10 @@ const checkNewFilesAndDependencies = async (package_, rootDirectory) => {
106103

107104
if (!isInteractive()) {
108105
console.log(messages.join('\n'));
109-
return true;
106+
return {
107+
confirmed: true,
108+
unpublishedFiles: newFiles.unpublished || [],
109+
};
110110
}
111111

112112
const answers = await inquirer.prompt([{
@@ -116,7 +116,26 @@ const checkNewFilesAndDependencies = async (package_, rootDirectory) => {
116116
default: false,
117117
}]);
118118

119-
return answers.confirm;
119+
return {
120+
confirmed: answers.confirm,
121+
unpublishedFiles: newFiles.unpublished || [],
122+
};
123+
};
124+
125+
const displayUnpublishedFilesWarning = unpublishedFiles => {
126+
if (!unpublishedFiles || unpublishedFiles.length === 0) {
127+
return;
128+
}
129+
130+
console.log([
131+
'',
132+
chalk.yellow('⚠ WARNING: The following new files will NOT be published:'),
133+
chalk.dim(util.groupFilesInFolders(unpublishedFiles)),
134+
'',
135+
chalk.yellow('These files are excluded by your package.json "files" field.'),
136+
chalk.yellow('If you intended to publish them, add them to the "files" field.'),
137+
'',
138+
].join('\n'));
120139
};
121140

122141
/**
@@ -131,14 +150,16 @@ const ui = async ({packageManager, ...options}, {package_, rootDirectory}) => {
131150
const {stdout: registryUrl} = await execa(...packageManager.getRegistryCommand);
132151
const releaseBranch = options.branch;
133152

153+
let unpublishedFiles;
134154
if (options.runPublish) {
135155
await npm.checkIgnoreStrategy(package_, rootDirectory);
136156

137-
const answerIgnoredFiles = await checkNewFilesAndDependencies(package_, rootDirectory);
138-
if (!answerIgnoredFiles) {
157+
const {confirmed, unpublishedFiles: files} = await checkNewFilesAndDependencies(package_, rootDirectory);
158+
unpublishedFiles = files;
159+
if (!confirmed) {
139160
return {
140161
...options,
141-
confirm: answerIgnoredFiles,
162+
confirm: confirmed,
142163
};
143164
}
144165
}
@@ -156,6 +177,9 @@ const ui = async ({packageManager, ...options}, {package_, rootDirectory}) => {
156177
const useLatestTag = !options.releaseDraftOnly;
157178
const {hasCommits, hasUnreleasedCommits, generateReleaseNotes} = await printCommitLog(repoUrl, registryUrl, useLatestTag, releaseBranch);
158179

180+
// Display unpublished files warning after commit log
181+
displayUnpublishedFilesWarning(unpublishedFiles);
182+
159183
if (hasUnreleasedCommits && options.releaseDraftOnly) {
160184
const answers = await inquirer.prompt({
161185
confirm: {

test/ui/new-files-dependencies.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const checkLines = message => (
1919
}
2020
);
2121

22-
const checkNewUnpublished = checkLines('The following new files will not be part of your published package:');
22+
const checkNewUnpublished = checkLines('⚠ WARNING: The following new files will NOT be published:');
2323
const checkFirstTimeFiles = checkLines('The following new files will be published for the first time:');
2424
const checkNewDependencies = checkLines('The following new dependencies will be part of your published package:');
2525

0 commit comments

Comments
 (0)