Skip to content
This repository has been archived by the owner on Sep 12, 2019. It is now read-only.

Commit

Permalink
wrap jsdetect in a check for empty scripts and fix netlify/cli#290
Browse files Browse the repository at this point in the history
  • Loading branch information
sw-yx committed Apr 9, 2019
1 parent fa041af commit f58a6b0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/commands/dev/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ class DevCommand extends Command {
}
process.env.NETLIFY_DEV = "true";

let settings = await serverSettings(Object.assign(config.dev, flags));
let settings = await serverSettings(Object.assign({}, config.dev, flags));

if (!(settings && settings.command)) {
this.log(
Expand Down
29 changes: 20 additions & 9 deletions src/detectors/utils/jsdetect.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,22 @@
*
*/
const { existsSync, readFileSync } = require("fs");
let pkgJSON = null,
yarnExists = false;
let pkgJSON = null;
let yarnExists = false;
let warnedAboutEmptyScript = false;
const { NETLIFYDEVWARN } = require("../../cli-logo.js");

/** hold package.json in a singleton so we dont do expensive parsing repeatedly */
function getPkgJSON() {
if (pkgJSON) {
return pkgJSON;
} else {
if (!existsSync("package.json"))
throw new Error(
"dont call this method unless you already checked for pkg json"
);
pkgJSON = JSON.parse(readFileSync("package.json", { encoding: "utf8" }));
return pkgJSON;
}
if (!existsSync("package.json"))
throw new Error(
"dont call this method unless you already checked for pkg json"
);
pkgJSON = JSON.parse(readFileSync("package.json", { encoding: "utf8" }));
return pkgJSON;
}
function getYarnOrNPMCommand() {
if (!yarnExists) {
Expand Down Expand Up @@ -56,6 +57,16 @@ function hasRequiredFiles(filenameArr) {
function scanScripts({ preferredScriptsArr, preferredCommand }) {
const { scripts } = getPkgJSON();

if (!scripts && !warnedAboutEmptyScript) {
console.log(
`${NETLIFYDEVWARN} You have a package.json without any npm scripts.`
);
console.log(
`${NETLIFYDEVWARN} Netlify Dev's detector system works best with a script, or you can specify a command to run in the netlify.toml [[dev]] block `
);
warnedAboutEmptyScript = true; // dont spam message with every detector
return []; // not going to match any scripts anyway
}
/**
*
* NOTE: we return an array of arrays (args)
Expand Down

0 comments on commit f58a6b0

Please sign in to comment.