Skip to content

Commit

Permalink
fix(sys): set ts.getExecutingFilePath() from stencil sys
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdbradley committed Aug 11, 2020
1 parent e74d04e commit 2b21f2d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
12 changes: 7 additions & 5 deletions src/compiler/sys/typescript/typescript-sys.ts
@@ -1,6 +1,6 @@
import type * as d from '../../../declarations';
import { basename, resolve } from 'path';
import { exit, getCurrentDirectory, getExecutingFilePath, IS_CASE_SENSITIVE_FILE_NAMES, IS_WEB_WORKER_ENV, isRemoteUrl, isString, normalizePath, noop } from '@utils';
import { getCurrentDirectory, IS_CASE_SENSITIVE_FILE_NAMES, IS_WEB_WORKER_ENV, isRemoteUrl, isString, normalizePath, noop } from '@utils';
import { fetchUrlSync } from '../fetch/fetch-module-sync';
import { patchTypeScriptResolveModule } from './typescript-resolve-module';
import ts from 'typescript';
Expand Down Expand Up @@ -41,8 +41,6 @@ export const patchTsSystemFileSystem = (config: d.Config, stencilSys: d.Compiler
}
};

tsSys.getCurrentDirectory = stencilSys.getCurrentDirectory;

tsSys.createDirectory = p => {
stencilSys.createDirSync(p, { recursive: true });
};
Expand All @@ -65,6 +63,10 @@ export const patchTsSystemFileSystem = (config: d.Config, stencilSys: d.Compiler
return !!(s && s.isFile);
};

tsSys.getCurrentDirectory = stencilSys.getCurrentDirectory;

tsSys.getExecutingFilePath = stencilSys.getCompilerExecutingPath;

tsSys.getDirectories = p => {
const items = stencilSys.readDirSync(p);
return items.filter(itemPath => {
Expand Down Expand Up @@ -163,11 +165,11 @@ const patchTypeScriptSysMinimum = () => {
args: [],
createDirectory: noop,
directoryExists: () => false,
exit,
exit: noop,
fileExists: () => false,
getCurrentDirectory,
getDirectories: () => [],
getExecutingFilePath,
getExecutingFilePath: () => './',
readDirectory: () => [],
readFile: noop,
newLine: '\n',
Expand Down
11 changes: 2 additions & 9 deletions src/utils/environment.ts
Expand Up @@ -10,15 +10,12 @@ export const IS_NODE_ENV =
typeof __filename === 'string' &&
(!((global as any) as Window).origin || typeof ((global as any) as Window).origin !== 'string');

export const OS_PLATFORM = IS_NODE_ENV ? global.process.platform : IS_DENO_ENV ? (globalThis as any).Deno.build.os : '';

export const IS_DENO_WINDOWS_ENV = IS_DENO_ENV && Deno.build.os === 'windows';
export const OS_PLATFORM = IS_NODE_ENV ? process.platform : IS_DENO_ENV ? Deno.build.os : '';

export const IS_WINDOWS_ENV = OS_PLATFORM === 'win32' || OS_PLATFORM === 'windows';

export const IS_CASE_SENSITIVE_FILE_NAMES = !IS_WINDOWS_ENV;

/** Either browser main thread or web worker */
export const IS_BROWSER_ENV = typeof location !== 'undefined' && typeof navigator !== 'undefined' && typeof XMLHttpRequest !== 'undefined';

export const IS_WEB_WORKER_ENV = IS_BROWSER_ENV && typeof self !== 'undefined' && typeof (self as any).importScripts === 'function';
Expand All @@ -29,10 +26,6 @@ export const IS_FETCH_ENV = typeof fetch === 'function';

export const requireFunc = IS_NODE_ENV ? require : noop;

export const getCurrentDirectory: () => string = IS_NODE_ENV ? process.cwd : IS_DENO_ENV ? (globalThis as any).Deno.cwd : () => '/';

export const getExecutingFilePath = () => (IS_NODE_ENV ? __filename : IS_BROWSER_ENV ? location.href : './');

export const exit: (exitCode?: number) => void = IS_NODE_ENV ? global.process.exit : IS_DENO_ENV ? (globalThis as any).Deno.exit : noop;
export const getCurrentDirectory: () => string = IS_NODE_ENV ? process.cwd : IS_DENO_ENV ? Deno.cwd : () => '/';

declare const Deno: any;

0 comments on commit 2b21f2d

Please sign in to comment.