Skip to content
This repository has been archived by the owner on Oct 1, 2020. It is now read-only.

Commit

Permalink
Merge pull request #199 from electron/add-compiler-bypass
Browse files Browse the repository at this point in the history
Add method to bypass the compilers completely
  • Loading branch information
anaisbetts authored Apr 6, 2017
2 parents cd21a48 + 2a3ce4f commit bf72072
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as configParser from './config-parser';
import CompilerHost from './compiler-host';
import FileChangedCache from './file-change-cache';
import CompileCache from './compile-cache';
import {addBypassChecker} from './protocol-hook';
//import {enableLiveReload} from './live-reload';
//import {watchPath} from './pathwatcher-rx';

Expand All @@ -21,5 +22,5 @@ module.exports = Object.assign({
},
},
configParser,
{ CompilerHost, FileChangedCache, CompileCache }
{ CompilerHost, FileChangedCache, CompileCache, addBypassChecker }
);
21 changes: 21 additions & 0 deletions src/protocol-hook.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,19 @@ function requestFileJob(filePath, finish) {
});
}

const bypassCheckers = [];

/**
* Adds a function that will be called on electron-compile's protocol hook
* used to intercept file requests. Use this to bypass electron-compile
* entirely for certain URI's.
*
* @param {Function} bypassChecker Function that will be called with the file path to determine whether to bypass or not
*/
export function addBypassChecker(bypassChecker) {
bypassCheckers.push(bypassChecker);
}

/**
* Initializes the protocol hook on file: that allows us to intercept files
* loaded by Chromium and rewrite them. This method along with
Expand Down Expand Up @@ -163,6 +176,14 @@ export function initializeProtocolHook(compilerHost) {
return;
}

for (const bypassChecker of bypassCheckers) {
if (bypassChecker(filePath)) {
d('bypassing compilers for:', filePath);
requestFileJob(filePath, finish);
return;
}
}

try {
let result = await compilerHost.compile(filePath);

Expand Down

0 comments on commit bf72072

Please sign in to comment.