Skip to content

Commit

Permalink
cli: allow array value for --ouput-library. Fixes #557
Browse files Browse the repository at this point in the history
  • Loading branch information
Connor Clark committed Aug 9, 2018
1 parent 72c70f2 commit 0fb0daa
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 2 deletions.
2 changes: 1 addition & 1 deletion bin/config-yargs.js
Expand Up @@ -137,7 +137,7 @@ module.exports = function(yargs) {
group: OUTPUT_GROUP
},
"output-library": {
type: "string",
type: "array",
describe: "Expose the exports of the entry point as library",
group: OUTPUT_GROUP,
requiresArg: true
Expand Down
3 changes: 2 additions & 1 deletion bin/convert-argv.js
Expand Up @@ -441,7 +441,8 @@ module.exports = function(...args) {

ifArg("output-library", function(value) {
ensureObject(options, "output");
options.output.library = value;
ensureArray(options.output, "library");
options.output.library.push(value);
});

ifArg("output-library-target", function(value) {
Expand Down
2 changes: 2 additions & 0 deletions test/BinTestCases.test.js
Expand Up @@ -68,9 +68,11 @@ const defaultArgs = loadOptsFile(path.join(casesPath, "test.opts"));

describe("BinTestCases", function() {
const tests = findTestsRecursive(casesPath);
const patternFilter = process.env.BIN_TEST_CASES_GREP ? new RegExp(process.env.BIN_TEST_CASES_GREP) : null;

tests.forEach(testDirectory => {
const testName = testDirectory.replace(casesPath, "");
if (patternFilter && !testName.match(patternFilter)) return;
const testArgs = getTestSpecificArguments(testDirectory) || defaultArgs;
const testAssertions = require(path.join(testDirectory, "stdin.js"));
const outputPath = path.join(
Expand Down
1 change: 1 addition & 0 deletions test/binCases/output/output-library-many/index.js
@@ -0,0 +1 @@
module.exports = "index";
14 changes: 14 additions & 0 deletions test/binCases/output/output-library-many/stdin.js
@@ -0,0 +1,14 @@
"use strict";

const fs = require("fs");
const path = require("path");

module.exports = function testAssertions(code, stdout, stderr) {
expect(code).toBe(0);
expect(stdout).toEqual(expect.anything());
expect(stdout[7]).toMatch(/index\.js.*\{0\}/);
expect(stderr).toHaveLength(0);

const output = fs.readFileSync(path.join(__dirname, "../../../js/bin/output/output-library-many/main.js"), "utf-8");
expect(output).toContain("window.key1=window.key1||{},window.key1.key2=function");
};
4 changes: 4 additions & 0 deletions test/binCases/output/output-library-many/test.opts
@@ -0,0 +1,4 @@
./index.js
--target async-node
--output-library-target window
--output-library key1 --output-library key2
1 change: 1 addition & 0 deletions test/binCases/output/output-library-single/index.js
@@ -0,0 +1 @@
module.exports = "index";
14 changes: 14 additions & 0 deletions test/binCases/output/output-library-single/stdin.js
@@ -0,0 +1,14 @@
"use strict";

const fs = require("fs");
const path = require("path");

module.exports = function testAssertions(code, stdout, stderr) {
expect(code).toBe(0);
expect(stdout).toEqual(expect.anything());
expect(stdout[7]).toMatch(/index\.js.*\{0\}/);
expect(stderr).toHaveLength(0);

const output = fs.readFileSync(path.join(__dirname, "../../../js/bin/output/output-library-single/main.js"), "utf-8");
expect(output).toContain("window.key1=function");
};
4 changes: 4 additions & 0 deletions test/binCases/output/output-library-single/test.opts
@@ -0,0 +1,4 @@
./index.js
--target async-node
--output-library-target window
--output-library key1

0 comments on commit 0fb0daa

Please sign in to comment.