Skip to content
Permalink
Browse files

fix(treeshaking): move environment helpers out of utils

Node and Deno globals are not easily treeshaken, and client imports utils. Move all environment helpers to just the compiler, not shared utils.
  • Loading branch information
adamdbradley committed Aug 16, 2020
1 parent abae5d1 commit c9306b9f3d359620f10b5a756bd717b1a210a576
@@ -1,6 +1,7 @@
import type { Config } from '../declarations';
import type { CoreCompiler } from './load-compiler';
import { IS_NODE_ENV, validateComponentTag } from '@utils';
import { IS_NODE_ENV } from '../compiler/sys/environment';
import { validateComponentTag } from '@utils';

/**
* Task to generate component boilerplate.
@@ -1,5 +1,5 @@
import type { Config, TestingRunOptions } from '../declarations';
import { IS_NODE_ENV } from '@utils';
import { IS_NODE_ENV } from '../compiler/sys/environment';

export const taskTest = async (config: Config) => {
if (!IS_NODE_ENV) {
@@ -1,6 +1,7 @@
import type * as d from '../../declarations';
import { generateBuildResults } from './build-results';
import { IS_NODE_ENV, isFunction, isRemoteUrl } from '@utils';
import { isFunction, isRemoteUrl } from '@utils';
import { IS_NODE_ENV } from '../sys/environment';
import { relative } from 'path';

export const buildFinish = async (buildCtx: d.BuildCtx) => {
@@ -1,8 +1,9 @@
import type { CompilerSystem, Config, Diagnostic, LoadConfigInit, LoadConfigResults } from '../../declarations';
import { buildError, catchError, isString, normalizePath, hasError, IS_NODE_ENV } from '@utils';
import { buildError, catchError, isString, normalizePath, hasError } from '@utils';
import { createLogger } from '../sys/logger/console-logger';
import { createSystem } from '../sys/stencil-sys';
import { dirname, resolve } from 'path';
import { IS_NODE_ENV } from '../sys/environment';
import { validateConfig } from './validate-config';
import { validateTsConfig } from '../sys/typescript/typescript-config';
import ts from 'typescript';
@@ -1,6 +1,7 @@
import type { TranspileOptions, TranspileResults, Config, TransformOptions, TransformCssToEsmInput, ImportData, CompilerSystem } from '../../declarations';
import { createSystem } from '../sys/stencil-sys';
import { isString, IS_NODE_ENV, requireFunc, IS_DENO_ENV } from '@utils';
import { IS_DENO_ENV, IS_NODE_ENV, requireFunc } from '../sys/environment';
import { isString } from '@utils';
import { parseImportPath } from '../transformers/stencil-import-path';
import { STENCIL_INTERNAL_CLIENT_ID } from '../bundle/entry-alias-ids';
import type { CompilerOptions } from 'typescript';
@@ -1,7 +1,7 @@
import { IS_WEB_WORKER_ENV } from '@utils';
import { createSystem } from './sys/stencil-sys';
import { createWorkerMessageHandler } from './worker/worker-thread';
import { initWebWorkerThread } from './sys/worker/web-worker-thread';
import { IS_WEB_WORKER_ENV } from './sys/environment';
import ts from 'typescript';

if (IS_WEB_WORKER_ENV) {
@@ -1,5 +1,5 @@
import type * as d from '../../declarations';
import { IS_NODE_ENV, requireFunc } from '@utils';
import { IS_NODE_ENV, requireFunc } from '../sys/environment';

let cssProcessor: any;

@@ -1,5 +1,6 @@
import type * as d from '../../declarations';
import { catchError, requireFunc, loadTypeScriptDiagnostics, IS_NODE_ENV } from '@utils';
import { catchError, loadTypeScriptDiagnostics } from '@utils';
import { IS_NODE_ENV, requireFunc } from '../sys/environment';
import { resolve } from 'path';

export const getPrerenderConfig = (diagnostics: d.Diagnostic[], prerenderConfigPath: string) => {
@@ -1,9 +1,10 @@
import type * as d from '../../declarations';
import { addModulePreloads, excludeStaticComponents, minifyScriptElements, minifyStyleElements, removeModulePreloads, removeStencilScripts } from './prerender-optimize';
import { catchError, isPromise, isRootPath, normalizePath, requireFunc, isFunction } from '@utils';
import { catchError, isPromise, isRootPath, normalizePath, isFunction } from '@utils';
import { crawlAnchorsForNextUrls } from './crawl-urls';
import { getHydrateOptions } from './prerender-hydrate-options';
import { getPrerenderConfig } from './prerender-config';
import { requireFunc } from '../sys/environment';

const prerenderCtx = {
componentGraph: null as Map<string, string[]>,
@@ -1,5 +1,3 @@
import { noop } from './helpers';

export const IS_DENO_ENV = typeof Deno !== 'undefined';

export const IS_NODE_ENV =
@@ -24,7 +22,7 @@ export const HAS_WEB_WORKER = IS_BROWSER_ENV && typeof Worker === 'function';

export const IS_FETCH_ENV = typeof fetch === 'function';

export const requireFunc = IS_NODE_ENV ? require : noop;
export const requireFunc = IS_NODE_ENV ? require : () => {};

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

@@ -1,5 +1,5 @@
import type * as d from '../../../declarations';
import { IS_BROWSER_ENV } from '@utils';
import { IS_BROWSER_ENV } from '../environment';

export const createLogger = () => {
let useColors = IS_BROWSER_ENV;
@@ -1,4 +1,4 @@
import { OS_PLATFORM } from '@utils';
import { OS_PLATFORM } from '../environment';

export const EOL = '\n';

@@ -1,5 +1,6 @@
import type * as d from '../../../declarations';
import { normalizePath, IS_NODE_ENV, requireFunc } from '@utils';
import { IS_NODE_ENV, requireFunc } from '../environment';
import { normalizePath } from '@utils';
import pathBrowserify from 'path-browserify';

export let basename: any;
@@ -2,7 +2,8 @@ import type * as d from '../../../declarations';
import { COMMON_DIR_FILENAMES, getCommonDirName, isCommonDirModuleFile, shouldFetchModule } from './resolve-utils';
import { fetchModuleSync } from '../fetch/fetch-module-sync';
import { getCommonDirUrl, getNodeModuleFetchUrl, packageVersions } from '../fetch/fetch-utils';
import { isString, IS_WEB_WORKER_ENV, normalizeFsPath, normalizePath } from '@utils';
import { isString, normalizeFsPath, normalizePath } from '@utils';
import { IS_WEB_WORKER_ENV } from '../environment';
import { basename, dirname } from 'path';
import resolve, { SyncOpts } from 'resolve';

@@ -1,5 +1,6 @@
import type * as d from '../../../declarations';
import { IS_BROWSER_ENV, IS_FETCH_ENV, normalizePath } from '@utils';
import { IS_BROWSER_ENV, IS_FETCH_ENV } from '../environment';
import { normalizePath } from '@utils';

const COMMON_DIR_MODULE_EXTS = ['.tsx', '.ts', '.mjs', '.js', '.jsx', '.json', '.md'];

@@ -19,7 +19,8 @@ import { basename, dirname, join } from 'path';
import { buildEvents } from '../events';
import { createLogger } from './logger/console-logger';
import { createWebWorkerMainController } from './worker/web-worker-main';
import { HAS_WEB_WORKER, IS_BROWSER_ENV, IS_WEB_WORKER_ENV, isRootPath, normalizePath } from '@utils';
import { HAS_WEB_WORKER, IS_BROWSER_ENV, IS_WEB_WORKER_ENV } from './environment';
import { isRootPath, normalizePath } from '@utils';
import { resolveModuleIdAsync } from './resolve/resolve-module-async';
import { version } from '../../version';

@@ -1,7 +1,8 @@
import type * as d from '../../../declarations';
import { basename, dirname, isAbsolute, join, resolve } from 'path';
import { isDtsFile, isJsFile, isJsxFile, isLocalModule, isStencilCoreImport, isTsxFile, isTsFile, isJsonFile } from '../resolve/resolve-utils';
import { isRemoteUrl, isString, IS_BROWSER_ENV, IS_NODE_ENV, normalizePath } from '@utils';
import { IS_BROWSER_ENV, IS_NODE_ENV } from '../environment';
import { isRemoteUrl, isString, normalizePath } from '@utils';
import { patchTsSystemFileSystem } from './typescript-sys';
import { resolveRemoteModuleIdSync } from '../resolve/resolve-module-sync';
import { version } from '../../../version';
@@ -1,7 +1,8 @@
import type * as d from '../../../declarations';
import { basename, resolve } from 'path';
import { getCurrentDirectory, IS_CASE_SENSITIVE_FILE_NAMES, IS_WEB_WORKER_ENV, isRemoteUrl, isString, normalizePath, noop } from '@utils';
import { isRemoteUrl, isString, normalizePath, noop } from '@utils';
import { fetchUrlSync } from '../fetch/fetch-module-sync';
import { getCurrentDirectory, IS_CASE_SENSITIVE_FILE_NAMES, IS_WEB_WORKER_ENV } from '../environment';
import { patchTypeScriptResolveModule } from './typescript-resolve-module';
import ts from 'typescript';

@@ -4,7 +4,8 @@ import { CompilerContext } from '../build/compiler-ctx';
import { convertDecoratorsToStatic } from '../transformers/decorators-to-static/convert-decorators';
import { convertStaticToMeta } from '../transformers/static-to-meta/visitor';
import { createLogger } from '../sys/logger/console-logger';
import { isNumber, isString, loadTypeScriptDiagnostics, normalizePath, getCurrentDirectory } from '@utils';
import { getCurrentDirectory } from '../sys/environment';
import { isNumber, isString, loadTypeScriptDiagnostics, normalizePath } from '@utils';
import { lazyComponentTransform } from '../transformers/component-lazy/transform-lazy-component';
import { nativeComponentTransform } from '../transformers/component-native/tranform-to-native-component';
import { updateStencilCoreImports } from '../transformers/update-stencil-core-import';
@@ -1,5 +1,4 @@
export * from './constants';
export * from './environment';
export * from './format-component-runtime-meta';
export * from './helpers';
export * from './is-glob';

0 comments on commit c9306b9

Please sign in to comment.
You can’t perform that action at this time.