Skip to content
Permalink
Browse files

Warn if no `files` field in package.json or .npmignore file is present (

  • Loading branch information
cironunes authored and sindresorhus committed Jul 3, 2019
1 parent 589dc8f commit c790d37fe5d9662577c8aaeed8b0dfec96ab5e9d
Showing with 19 additions and 1 deletion.
  1. +1 −0 readme.md
  2. +15 −0 source/npm/util.js
  3. +3 −1 source/ui.js
@@ -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
@@ -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(
@@ -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.
`);
}
};
@@ -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');

@@ -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 = [

0 comments on commit c790d37

Please sign in to comment.
You can’t perform that action at this time.