mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
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.
49 lines
1.2 KiB
JavaScript
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;
|
|
}
|