Skip to content

Commit

Permalink
Move default npm deps install function into own module.
Browse files Browse the repository at this point in the history
This extraction was necessary because importing tools/cli/commands.js is
not entirely side-effect-free, and was interfering with older tests.
  • Loading branch information
Ben Newman committed Nov 2, 2016
1 parent 4bf6940 commit 643a9f1
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 31 deletions.
30 changes: 1 addition & 29 deletions tools/cli/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -1566,7 +1566,7 @@ function doTestCommand(options) {
projectContextOptions.projectDir = testRunnerAppDir;
projectContextOptions.projectDirForLocalPackages = options.appDir;

installDefaultNpmDeps(testRunnerAppDir);
require("./default-npm-deps.js").install(testRunnerAppDir);
if (buildmessage.jobHasMessages()) {
return;
}
Expand Down Expand Up @@ -1717,34 +1717,6 @@ function doTestCommand(options) {
));
}

export function installDefaultNpmDeps(appDir) {
const testAppPkgJsonPath =
files.pathJoin(appDir, "package.json");

if (! files.statOrNull(testAppPkgJsonPath)) {
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.
files.writeFile(
testAppPkgJsonPath,
JSON.stringify({ dependencies }, null, 2) + "\n",
"utf8",
);
}

const jobMessage = "installing dependencies from package.json";
buildmessage.enterJob(jobMessage, 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);
}
});
}

// Returns the "local-test:*" package names for the given package names (or for
// all local packages if packageNames is empty/unspecified).
var getTestPackageNames = function (projectContext, packageNames) {
Expand Down
39 changes: 39 additions & 0 deletions tools/cli/default-npm-deps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import buildmessage from "../utils/buildmessage.js";
import {
pathJoin,
statOrNull,
writeFile,
} from "../fs/files.js";

const INSTALL_JOB_MESSAGE = "installing dependencies from package.json";

export function install(appDir) {
const testAppPkgJsonPath = pathJoin(appDir, "package.json");

if (! statOrNull(testAppPkgJsonPath)) {
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(
testAppPkgJsonPath,
JSON.stringify({ dependencies }, null, 2) + "\n",
"utf8",
);
}

return 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;
});
}
2 changes: 1 addition & 1 deletion tools/tests/old/test-bundler-assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var makeProjectContext = function (appName) {

files.cp_r(testAppDir, projectDir);

require("../../cli/commands.js").installDefaultNpmDeps(projectDir);
require("../../cli/default-npm-deps.js").install(projectDir);

var projectContext = new projectContextModule.ProjectContext({
projectDir: projectDir
Expand Down
2 changes: 1 addition & 1 deletion tools/tool-testing/selftest.js
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ _.extend(Sandbox.prototype, {
upgradersFile.appendUpgraders(upgraders.allUpgraders());
}

require("../cli/commands.js").installDefaultNpmDeps(absoluteTo);
require("../cli/default-npm-deps.js").install(absoluteTo);

if (options.dontPrepareApp) {
return;
Expand Down

0 comments on commit 643a9f1

Please sign in to comment.