Skip to content

Commit

Permalink
cli: allow array value for --ouput-library (#559)
Browse files Browse the repository at this point in the history
* cli: allow array value for --ouput-library. Fixes #557

* tests(bin): add test case for regression
  • Loading branch information
connorjclark authored and dhruvdutt committed Aug 2, 2018
1 parent 0c3d2b4 commit 6014ec8
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 2 deletions.
2 changes: 1 addition & 1 deletion bin/config-yargs.js
Original file line number Diff line number Diff line change
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
5 changes: 4 additions & 1 deletion bin/convert-argv.js
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,10 @@ module.exports = function(...args) {

ifArg("output-library", function(value) {
ensureObject(options, "output");
options.output.library = value;
if (!options.output.library) {
options.output.library = [];
}
options.output.library.push(value);
});

ifArg("output-library-target", function(value) {
Expand Down
1 change: 1 addition & 0 deletions test/binCases/output/output-library-many/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = "index";
12 changes: 12 additions & 0 deletions test/binCases/output/output-library-many/stdin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"use strict";

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

const output = require("fs").readFileSync(require("path").join(__dirname, "../../../js/bin/output/output-library-many/bundle.js"), "utf-8");
expect(output).toContain("window.key1=window.key1||{},window.key1.key2=function");
};
5 changes: 5 additions & 0 deletions test/binCases/output/output-library-many/test.opts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
./index.js
-o ../../../js/bin/output/output-library-many/bundle.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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = "index";
12 changes: 12 additions & 0 deletions test/binCases/output/output-library-single/stdin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"use strict";

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

const output = require("fs").readFileSync(require("path").join(__dirname, "../../../js/bin/output/output-library-single/bundle.js"), "utf-8");
expect(output).toContain("window.key1=function");
};
5 changes: 5 additions & 0 deletions test/binCases/output/output-library-single/test.opts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
./index.js
-o ../../../js/bin/output/output-library-single/bundle.js
--target async-node
--output-library-target window
--output-library key1

0 comments on commit 6014ec8

Please sign in to comment.