diff --git a/src/compiler/build/build.ts b/src/compiler/build/build.ts index b9697964167..38b4a18145c 100644 --- a/src/compiler/build/build.ts +++ b/src/compiler/build/build.ts @@ -1,9 +1,10 @@ import { BuildResults, CompilerCtx, Config, WatcherResults } from '../../declarations'; import { bundle } from '../bundle/bundle'; -import { catchError, getCompilerCtx } from '../util'; +import { catchError } from '../util'; import { copyTasks } from '../copy/copy-tasks'; import { emptyDestDir, writeBuildFiles } from './write-build'; import { getBuildContext } from './build-utils'; +import { getCompilerCtx } from './compiler-ctx'; import { generateAppFiles } from '../app/generate-app-files'; import { generateBundles } from '../bundle/generate-bundles'; import { generateEntryModules } from '../entries/entry-modules'; diff --git a/src/compiler/build/compiler-ctx.ts b/src/compiler/build/compiler-ctx.ts new file mode 100644 index 00000000000..262eb658b38 --- /dev/null +++ b/src/compiler/build/compiler-ctx.ts @@ -0,0 +1,25 @@ +import { BuildEvents } from '../events'; +import { Cache } from '../cache'; +import { CompilerCtx, Config } from '../../declarations'; +import { InMemoryFileSystem } from '../../util/in-memory-fs'; + + +export function getCompilerCtx(config: Config, compilerCtx?: CompilerCtx) { + // reusable data between builds + compilerCtx = compilerCtx || {}; + compilerCtx.fs = compilerCtx.fs || new InMemoryFileSystem(config.sys.fs, config.sys.path); + compilerCtx.cache = compilerCtx.cache || new Cache(config, new InMemoryFileSystem(config.sys.fs, config.sys.path), config.sys.tmpdir()); + compilerCtx.events = compilerCtx.events || new BuildEvents(config); + compilerCtx.appFiles = compilerCtx.appFiles || {}; + compilerCtx.moduleFiles = compilerCtx.moduleFiles || {}; + compilerCtx.rollupCache = compilerCtx.rollupCache || {}; + compilerCtx.collections = compilerCtx.collections || {}; + compilerCtx.compiledModuleJsText = compilerCtx.compiledModuleJsText || {}; + compilerCtx.compiledModuleLegacyJsText = compilerCtx.compiledModuleLegacyJsText || {}; + + if (typeof compilerCtx.activeBuildId !== 'number') { + compilerCtx.activeBuildId = -1; + } + + return compilerCtx; +} diff --git a/src/compiler/compiler.ts b/src/compiler/compiler.ts index aa8ea08a9e7..ffeb6328f12 100644 --- a/src/compiler/compiler.ts +++ b/src/compiler/compiler.ts @@ -1,7 +1,8 @@ import { BuildResults, CompilerCtx, CompilerEventName, Config, Diagnostic } from '../declarations'; import { build } from './build/build'; -import { catchError, getCompilerCtx } from './util'; +import { catchError } from './util'; import { docs } from './docs/docs'; +import { getCompilerCtx } from './build/compiler-ctx'; import { InMemoryFileSystem } from '../util/in-memory-fs'; import { validateBuildConfig } from '../compiler/config/validate-config'; import { validatePrerenderConfig } from './prerender/validate-prerender-config'; diff --git a/src/compiler/docs/docs.ts b/src/compiler/docs/docs.ts index 320a114add1..dca1e54a971 100644 --- a/src/compiler/docs/docs.ts +++ b/src/compiler/docs/docs.ts @@ -1,8 +1,9 @@ import { CompilerCtx, Config } from '../../declarations'; -import { catchError, getCompilerCtx, hasError } from '../util'; +import { catchError, hasError } from '../util'; import { cleanDiagnostics } from '../../util/logger/logger-util'; import { generateReadmes } from './generate-readmes'; import { getBuildContext } from '../build/build-utils'; +import { getCompilerCtx } from '../build/compiler-ctx'; import { transpileAppModules } from '../transpile/transpile-app-modules'; diff --git a/src/compiler/util.ts b/src/compiler/util.ts index 7c6783b7952..ef953eeed68 100644 --- a/src/compiler/util.ts +++ b/src/compiler/util.ts @@ -1,29 +1,5 @@ import { BANNER } from '../util/constants'; -import { BuildEvents } from './events'; -import { Cache } from './cache'; import { CompilerCtx, Config, Diagnostic, SourceTarget } from '../declarations'; -import { InMemoryFileSystem } from '../util/in-memory-fs'; - - -export function getCompilerCtx(config: Config, compilerCtx?: CompilerCtx) { - // reusable data between builds - compilerCtx = compilerCtx || {}; - compilerCtx.fs = compilerCtx.fs || new InMemoryFileSystem(config.sys.fs, config.sys.path); - compilerCtx.cache = compilerCtx.cache || new Cache(config, new InMemoryFileSystem(config.sys.fs, config.sys.path), config.sys.tmpdir()); - compilerCtx.events = compilerCtx.events || new BuildEvents(config); - compilerCtx.appFiles = compilerCtx.appFiles || {}; - compilerCtx.moduleFiles = compilerCtx.moduleFiles || {}; - compilerCtx.rollupCache = compilerCtx.rollupCache || {}; - compilerCtx.collections = compilerCtx.collections || {}; - compilerCtx.compiledModuleJsText = compilerCtx.compiledModuleJsText || {}; - compilerCtx.compiledModuleLegacyJsText = compilerCtx.compiledModuleLegacyJsText || {}; - - if (typeof compilerCtx.activeBuildId !== 'number') { - compilerCtx.activeBuildId = -1; - } - - return compilerCtx; -} /** diff --git a/src/server/renderer.ts b/src/server/renderer.ts index aabf72f715d..bf482aeda06 100644 --- a/src/server/renderer.ts +++ b/src/server/renderer.ts @@ -1,5 +1,6 @@ import { CompilerCtx, ComponentRegistry, Config, HydrateOptions, HydrateResults } from '../declarations'; -import { catchError, getCompilerCtx } from '../compiler/util'; +import { catchError } from '../compiler/util'; +import { getCompilerCtx } from '../compiler/build/compiler-ctx'; import { getGlobalWWW } from '../compiler/app/app-file-naming'; import { hydrateHtml } from './hydrate-html'; import { InMemoryFileSystem } from '../util/in-memory-fs';