Skip to content

Commit

Permalink
Warn if no files field in package.json or .npmignore file present
Browse files Browse the repository at this point in the history
  • Loading branch information
cironunes authored and Ciro Nunes committed Jun 11, 2019
1 parent 3925527 commit e8bfdd7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
16 changes: 15 additions & 1 deletion source/npm/util.js
@@ -1,9 +1,13 @@
'use strict';
const {existsSync} = require('fs');
const path = require('path');
const execa = require('execa');
const pTimeout = require('p-timeout');
const ow = require('ow');
const npmName = require('npm-name');
const {verifyRequirementSatisfied} = require('../version');
const chalk = require('chalk');
const {versionSatisfiesRequirement} = require('../version');
const {getRootDir} = require('../util');

exports.checkConnection = () => pTimeout(
(async () => {
Expand Down Expand Up @@ -87,3 +91,13 @@ exports.verifyRecentNpmVersion = async () => {
const npmVersion = await exports.version();
verifyRequirementSatisfied('npm', npmVersion);
};

exports.checkIgnoreStrategy = ({files}) => {
const npmignoreExists = existsSync(path.resolve(getRootDir(), '.npmignore'));

if (!files && !npmignoreExists) {
console.log(`
\n${chalk.bold.yellow('Warning:')} No ${chalk.bold.cyan('files')} field specified in ${chalk.bold.magenta('package.json')} nor ${chalk.bold.magenta('.npmignore')} file present. Setting one of those will prevent you from accidentally publishing development-specific files along with your package's source code to npm.
`);
}
};
4 changes: 3 additions & 1 deletion source/ui.js
Expand Up @@ -5,7 +5,7 @@ const githubUrlFromGit = require('github-url-from-git');
const isScoped = require('is-scoped');
const util = require('./util');
const git = require('./git-util');
const {prereleaseTags} = require('./npm/util');
const {prereleaseTags, checkIgnoreStrategy} = require('./npm/util');
const version = require('./version');
const prettyVersionDiff = require('./pretty-version-diff');

Expand Down Expand Up @@ -54,6 +54,8 @@ module.exports = async (options, pkg) => {
const extraBaseUrls = ['gitlab.com'];
const repoUrl = pkg.repository && githubUrlFromGit(pkg.repository.url, {extraBaseUrls});

checkIgnoreStrategy(pkg);

console.log(`\nPublish a new version of ${chalk.bold.magenta(pkg.name)} ${chalk.dim(`(current: ${oldVersion})`)}\n`);

const prompts = [
Expand Down
6 changes: 6 additions & 0 deletions source/util.js
@@ -1,4 +1,5 @@
'use strict';
const path = require('path');
const readPkgUp = require('read-pkg-up');
const issueRegex = require('issue-regex');
const terminalLink = require('terminal-link');
Expand Down Expand Up @@ -61,3 +62,8 @@ exports.getTagVersionPrefix = pMemoize(async options => {
return 'v';
}
});

exports.getRootDir = () => {
const sourceDir = path.dirname(require.main.filename);
return path.resolve(sourceDir, '..');
};

0 comments on commit e8bfdd7

Please sign in to comment.