From 5e0833421af1902c6d5ffa08e79659303b8e962f Mon Sep 17 00:00:00 2001 From: William Chargin Date: Tue, 4 Sep 2018 22:01:22 -0700 Subject: [PATCH] Make `execDependencyGraph` a CommonJS module (#767) Summary: This simplifies interfaces everywhere. See also #216, which did the opposite of this as a temporary fix due to a Babel/Webpack interaction that no longer exists as of #766. Test Plan: Note that `node bin/sourcecred.js load sourcecred/example-git` still works (after `yarn backend`). Note that `yarn test` still works. These demonstrate that the module works from both a Webpack context and a Node context. Note that `git grep --name-only execDependencyGraph` yields exactly those files touched in this commit. Note that `yarn test --full` passes. wchargin-branch: commonjs-execDependencyGraph --- config/test.js | 2 +- src/cli/load.js | 3 +-- src/cli/load.test.js | 7 ++----- src/tools/execDependencyGraph.js | 2 +- 4 files changed, 5 insertions(+), 9 deletions(-) diff --git a/config/test.js b/config/test.js index 83152c5..176a392 100644 --- a/config/test.js +++ b/config/test.js @@ -1,6 +1,6 @@ // @flow -const execDependencyGraph = require("../src/tools/execDependencyGraph").default; +const execDependencyGraph = require("../src/tools/execDependencyGraph"); main(); diff --git a/src/cli/load.js b/src/cli/load.js index 6fcd25b..c4e288b 100644 --- a/src/cli/load.js +++ b/src/cli/load.js @@ -12,11 +12,10 @@ import dedent from "../util/dedent"; import type {Command} from "./command"; import * as Common from "./common"; +import execDependencyGraph from "../tools/execDependencyGraph"; import {loadGithubData} from "../plugins/github/loadGithubData"; import {loadGitData} from "../plugins/git/loadGitData"; -const execDependencyGraph = require("../tools/execDependencyGraph").default; - function usage(print: (string) => void): void { print( dedent`\ diff --git a/src/cli/load.test.js b/src/cli/load.test.js index 50cdb09..be31363 100644 --- a/src/cli/load.test.js +++ b/src/cli/load.test.js @@ -10,9 +10,7 @@ import load, {help} from "./load"; import * as RepoRegistry from "../app/credExplorer/repoRegistry"; import {stringToRepo} from "../core/repo"; -jest.mock("../tools/execDependencyGraph", () => ({ - default: jest.fn(), -})); +jest.mock("../tools/execDependencyGraph", () => jest.fn()); jest.mock("../plugins/github/loadGithubData", () => ({ loadGithubData: jest.fn(), })); @@ -21,8 +19,7 @@ jest.mock("../plugins/git/loadGitData", () => ({ })); type JestMockFn = $Call; -const execDependencyGraph: JestMockFn = (require("../tools/execDependencyGraph") - .default: any); +const execDependencyGraph: JestMockFn = (require("../tools/execDependencyGraph"): any); const loadGithubData: JestMockFn = (require("../plugins/github/loadGithubData") .loadGithubData: any); const loadGitData: JestMockFn = (require("../plugins/git/loadGitData") diff --git a/src/tools/execDependencyGraph.js b/src/tools/execDependencyGraph.js index 0c82f63..72b1f76 100644 --- a/src/tools/execDependencyGraph.js +++ b/src/tools/execDependencyGraph.js @@ -48,7 +48,7 @@ const defaultOptions = { overallFailLabel: "FAILURE", }; -exports.default = async function execDependencyGraph( +module.exports = async function execDependencyGraph( tasks /*: $ReadOnlyArray */, options /*:: ?: RunOptions */ ) /*: Promise */ {