Skip to content
Permalink
Browse files

fix(sys): set ts.getExecutingFilePath() from stencil sys

  • Loading branch information
adamdbradley committed Aug 11, 2020
1 parent e74d04e commit 2b21f2d01af313be32310de29f297172a1318b56
Showing with 9 additions and 14 deletions.
  1. +7 −5 src/compiler/sys/typescript/typescript-sys.ts
  2. +2 −9 src/utils/environment.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';
@@ -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 });
};
@@ -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 => {
@@ -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',
@@ -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';
@@ -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.
You can’t perform that action at this time.