Files
meteor/tools/cli/default-npm-deps.js
Ben Newman ac86594346 Install npm dependencies automatically when creating apps.
Although I have said I do not think Meteor should run `npm install`
automatically to update application node_modules, my real concern is that
Meteor should not interfere with your preferred node_modules-related
workflow, be it npm, npm-shinkwrap.json, yarn, yarn.lock, checking your
node_modules into git/mercurial/cvs, or whatever other scheme you have.

Automatically installing node_modules from the default package.json file
when a new app is created will eliminate real confusion, and should not
interfere with any workflows, because there is no opportunity to establish
another workflow before Meteor runs `npm install` the very first time.
2016-11-28 12:11:59 -05:00

49 lines
1.2 KiB
JavaScript

import buildmessage from "../utils/buildmessage.js";
import {
pathJoin,
statOrNull,
writeFile,
unlink,
} from "../fs/files.js";
const INSTALL_JOB_MESSAGE = "installing npm dependencies";
export function install(appDir) {
const packageJsonPath = pathJoin(appDir, "package.json");
const needTempPackageJson = ! statOrNull(packageJsonPath);
if (needTempPackageJson) {
const { dependencies } = require("../static-assets/skel/package.json");
// Write a minimial package.json with the same dependencies as the
// default new-app package.json file.
writeFile(
packageJsonPath,
JSON.stringify({ dependencies }, null, 2) + "\n",
"utf8",
);
}
const ok = buildmessage.enterJob(INSTALL_JOB_MESSAGE, function () {
const { runNpmCommand } = require("../isobuild/meteor-npm.js");
const installResult = runNpmCommand(["install"], appDir);
if (! installResult.success) {
buildmessage.error(
"Could not install npm dependencies for test-packages: " +
installResult.error);
return false;
}
return true;
});
if (needTempPackageJson) {
// Clean up the temporary package.json file created above.
unlink(packageJsonPath);
}
return ok;
}