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 16, 2019
1 parent 3925527 commit a439c34
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
15 changes: 15 additions & 0 deletions source/npm/util.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
'use strict';
const {existsSync} = require('fs');
const {resolve} = require('path');
const execa = require('execa');
const pTimeout = require('p-timeout');
const ow = require('ow');
const npmName = require('npm-name');
const chalk = require('chalk');
const pkgDir = require('pkg-dir');
const {verifyRequirementSatisfied} = require('../version');

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

exports.checkIgnoreStrategy = ({files}) => {
const rootDir = pkgDir.sync();
const npmignoreExists = existsSync(resolve(rootDir, '.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
Original file line number Diff line number Diff line change
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

0 comments on commit a439c34

Please sign in to comment.