Skip to content

Commit

Permalink
Option for replacing modules with a stub in the bundle, "bundlerOptio…
Browse files Browse the repository at this point in the history
…ns.ignore", #53, #57
  • Loading branch information
erikbarke committed Dec 29, 2016
1 parent 25df6ba commit 2d06bb0
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 27 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ Valid options are the same as for the `compilerOptions` section in `tsconfig.jso

* `karmaTypescriptConfig.bundlerOptions.exclude` - An array of npm module names that will be excluded from the bundle.

* `karmaTypescriptConfig.bundlerOptions.ignore` - An array of npm module names that will be bundled as stubs, `module.exports = {};`.

* `karmaTypescriptConfig.bundlerOptions.nodeGlobals` - Boolean indicating whether the global variables `process` and `Buffer` should be included in the bundle. Defaults to `true`.

* `karmaTypescriptConfig.bundlerOptions.noParse` - An array of module names that will be bunded as-is, without being parsed for dependencies.
Expand Down
6 changes: 3 additions & 3 deletions integration-tests@latest/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ module.exports = function(config) {
{ pattern: "src/misc/no-module-tester.spec.ts" },
{ pattern: "src/misc/!(emptyfile)/**/*.ts" },
{ pattern: "src/node/**/*.ts" },
{ pattern: "src/socket.io/*.ts" },
{ pattern: "src/typescript/**/*.ts" },
{ pattern: "src/x-performance/**/*.ts" }
],
Expand All @@ -36,9 +35,10 @@ module.exports = function(config) {
include: ["**/*.ts", "**/*.tsx"],
exclude: ["broken"],
bundlerOptions: {
exclude: ["react/addons"],
ignore: ["ws"],
nodeGlobals: true,
noParse: ["jquery"],
exclude: ["ws"]
noParse: ["jquery"]
},
disableCodeCoverageInstrumentation: false,
excludeFromCoverage: /\.(d|spec|test)\.ts/,
Expand Down
11 changes: 11 additions & 0 deletions integration-tests@latest/src/bundling/ignore/ignore-tester.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { IgnoreTester } from "./ignore-tester";

describe("IgnoreTester", () => {

let tester = new IgnoreTester();

it("should be required without ignored dependencies", () => {

expect(tester.testRequire()).not.toBeUndefined();
});
});
10 changes: 10 additions & 0 deletions integration-tests@latest/src/bundling/ignore/ignore-tester.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import * as io from "socket.io";

export class IgnoreTester {

public testRequire(): boolean {

// socket.io requires ws which has dependencies that are incompatible
return io !== undefined;
}
}
11 changes: 0 additions & 11 deletions integration-tests@latest/src/socket.io/component.spec.ts

This file was deleted.

9 changes: 0 additions & 9 deletions integration-tests@latest/src/socket.io/component.ts

This file was deleted.

14 changes: 10 additions & 4 deletions lib/bundlers/builtin/bundler.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ var acorn = require("acorn"),
entrypointFilenames = [],
exclude,
filenameCache = [],
ignore,
log,
lookupNameCache = {},
nodeGlobals,
Expand All @@ -37,6 +38,7 @@ function Bundler() {

bundlerOptions = bundlerOptions || {};
exclude = bundlerOptions.exclude || [];
ignore = bundlerOptions.ignore || [];
nodeGlobals = bundlerOptions.nodeGlobals !== undefined ? bundlerOptions.nodeGlobals : true;
noParse = bundlerOptions.noParse || [];

Expand Down Expand Up @@ -227,8 +229,7 @@ function Bundler() {
function resolveModules(requiringModule, requiredModule) {

if(exclude.indexOf(requiredModule.moduleName) !== -1) {

log.error("Excluding module %s", requiredModule.moduleName);
log.debug("Excluding module %s", requiredModule.moduleName);
return requiredModule.moduleName;
}

Expand Down Expand Up @@ -271,8 +272,13 @@ function Bundler() {

function readSource(requiredModule) {

requiredModule.source = fs.readFileSync(requiredModule.filename).toString();
requiredModule.source = removeSourceMapUrl(requiredModule.source);
if(ignore.indexOf(requiredModule.moduleName) !== -1) {
requiredModule.source = "module.exports={};";
}
else {
requiredModule.source = fs.readFileSync(requiredModule.filename).toString();
requiredModule.source = removeSourceMapUrl(requiredModule.source);
}
}

function addDependencies(requiredModule) {
Expand Down

0 comments on commit 2d06bb0

Please sign in to comment.