Skip to content

Commit

Permalink
Backend location test refactoring
Browse files Browse the repository at this point in the history
Signed-off-by: Paul Maréchal <paul.marechal@ericsson.com>
  • Loading branch information
paul-marechal committed Jul 24, 2018
1 parent de890b0 commit 4d07884
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
5 changes: 5 additions & 0 deletions packages/core/src/browser/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ export const isNative = typeof (window as any).process !== 'undefined';
// tslint:disable-next-line:no-any
export const isBasicWasmSupported = typeof (window as any).WebAssembly !== 'undefined';

// Current protocol in use to display the application
export const isHttps = /^https:/.test(self.location.href);
export const isHttp = /^http:/.test(self.location.href);
export const isFile = /^file:/.test(self.location.href);

/**
* Parse a magnitude value (e.g. width, height, left, top) from a CSS attribute value.
* Returns the given default value (or undefined) if the value cannot be determined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import { isFile } from '../../browser';

export type ElectronBackendLocation = 'local' | 'remote';
export namespace ElectronBackendLocation {

export const location: ElectronBackendLocation = /^file:/.test(self.location.href) ? 'local' : 'remote';
export const location: ElectronBackendLocation = isFile ? 'local' : 'remote';

export function getLocation(): ElectronBackendLocation {
return location;
Expand Down
16 changes: 8 additions & 8 deletions packages/monaco/src/electron-browser/monaco-electron-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import { loadVsRequire, loadMonaco } from "../browser/monaco-loader";

export { ContainerModule };

const s = <any>self;
// tslint:disable-next-line:no-any
const globals = <any>self;

/**
* We cannot use `FileUri#create` because URIs with file scheme cannot be properly decoded via the AMD loader.
Expand All @@ -35,21 +36,20 @@ const uriFromPath = (filePath: string) => {
return encodeURI('file://' + pathName);
};

const isHttp = /https?:/.test(self.location.href);

export default loadVsRequire(global)
.then(vsRequire => {
const baseUrl = isHttp ? self.location.href : uriFromPath(__dirname);
const isRemote = !/^file:/.test(self.location.href);
const baseUrl = isRemote ? self.location.href : uriFromPath(__dirname);
vsRequire.config({ baseUrl });

// workaround monaco-css not understanding the environment
s.module = undefined;
globals.module = undefined;
// workaround monaco-typescript not understanding the environment
s.process.browser = true;
globals.process.browser = true;

// vscode-loader patching: https://github.com/Microsoft/vscode-loader/issues/12
if (isHttp) {
Object.defineProperty(s.AMDLoader.Environment.prototype, 'isNode', {
if (isRemote) {
Object.defineProperty(globals.AMDLoader.Environment.prototype, 'isNode', {
get: () => false
});
}
Expand Down

0 comments on commit 4d07884

Please sign in to comment.