Skip to content

Commit

Permalink
Warn if no files field in package.json or .npmignore file is present (
Browse files Browse the repository at this point in the history
  • Loading branch information
cironunes authored and sindresorhus committed Jul 3, 2019
1 parent 589dc8f commit c790d37
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions readme.md
Expand Up @@ -31,6 +31,7 @@
- Supports [two-factor authentication](https://docs.npmjs.com/getting-started/using-two-factor-authentication)
- Enables two-factor authentication on new repositories
- Opens a prefilled GitHub Releases draft after publish
- Warns about the possibility of extraneous files being published


## Prerequisite
Expand Down
15 changes: 15 additions & 0 deletions source/npm/util.js
@@ -1,8 +1,12 @@
'use strict';
const fs = 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 chalk = require('chalk');
const pkgDir = require('pkg-dir');
const {verifyRequirementSatisfied} = require('../version');

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

exports.checkIgnoreStrategy = ({files}) => {
const rootDir = pkgDir.sync();
const npmignoreExists = fs.existsSync(path.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 is a ${chalk.bold.magenta('.npmignore')} file present. Having 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

0 comments on commit c790d37

Please sign in to comment.