Skip to content

Commit

Permalink
chore(build): remove compiler/utils circular dep
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdbradley committed Feb 15, 2018
1 parent eb8e09f commit 916fb39
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 28 deletions.
3 changes: 2 additions & 1 deletion 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';
Expand Down
25 changes: 25 additions & 0 deletions 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;
}
3 changes: 2 additions & 1 deletion 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';
Expand Down
3 changes: 2 additions & 1 deletion 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';


Expand Down
24 changes: 0 additions & 24 deletions 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;
}


/**
Expand Down
3 changes: 2 additions & 1 deletion 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';
Expand Down

0 comments on commit 916fb39

Please sign in to comment.