Skip to content

Commit

Permalink
style(bundle): update inMemoryFsRead
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdbradley committed Feb 15, 2018
1 parent d78bcc4 commit e7f97c5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/compiler/app/app-global-scripts.ts
Expand Up @@ -3,8 +3,8 @@ import { buildExpressionReplacer } from '../build/replacer';
import { createOnWarnFn, loadRollupDiagnostics } from '../../util/logger/logger-rollup';
import { generatePreamble, minifyJs } from '../util';
import { getAppPublicPath, getGlobalDist, getGlobalFileName, getGlobalWWW } from './app-file-naming';
import inMemoryFsRead from '../bundle/rollup-plugins/in-memory-fs-read';
import { transpileToEs5 } from '../transpile/core-build';
import transpiledInMemoryPlugin from '../bundle/rollup-plugins/transpiled-in-memory';


export async function generateAppGlobalScript(config: Config, compilerCtx: CompilerCtx, buildCtx: BuildCtx, appRegistry: AppRegistry, sourceTarget?: SourceTarget) {
Expand Down Expand Up @@ -109,7 +109,7 @@ async function bundleProjectGlobal(config: Config, compilerCtx: CompilerCtx, bui
include: 'node_modules/**',
sourceMap: false
}),
transpiledInMemoryPlugin(config, compilerCtx),
inMemoryFsRead(config, compilerCtx),
...config.plugins
],
onwarn: createOnWarnFn(config, buildCtx.diagnostics)
Expand Down
10 changes: 5 additions & 5 deletions src/compiler/bundle/rollup-bundle.ts
@@ -1,14 +1,14 @@
import { BuildCtx, CompilerCtx, Config, EntryModule, JSModuleList } from '../../declarations';
import bundleEntryFile from './rollup-plugins/bundle-entry-file';
import bundleJson from './rollup-plugins/json';
import { createOnWarnFn, loadRollupDiagnostics } from '../../util/logger/logger-rollup';
import { generatePreamble, hasError } from '../util';
import { getBundleIdPlaceholder } from '../../util/data-serialize';
import pathsResolution from './rollup-plugins/paths-resolution';
import localResolution from './rollup-plugins/local-resolution';
import transpiledInMemoryPlugin from './rollup-plugins/transpiled-in-memory';
import bundleEntryFile from './rollup-plugins/bundle-entry-file';
import inMemoryFsRead from './rollup-plugins/in-memory-fs-read';
import { InputOptions, OutputChunk, rollup } from 'rollup';
import nodeEnvVars from './rollup-plugins/node-env-vars';
import bundleJson from './rollup-plugins/json';
import pathsResolution from './rollup-plugins/paths-resolution';


export async function createBundle(config: Config, compilerCtx: CompilerCtx, buildCtx: BuildCtx, entryModules: EntryModule[]) {
Expand All @@ -33,7 +33,7 @@ export async function createBundle(config: Config, compilerCtx: CompilerCtx, bui
globals(),
builtins(),
bundleEntryFile(config, entryModules),
transpiledInMemoryPlugin(config, compilerCtx),
inMemoryFsRead(config, compilerCtx),
await pathsResolution(config, compilerCtx),
localResolution(config, compilerCtx),
nodeEnvVars(config),
Expand Down
@@ -1,14 +1,15 @@
import { CompilerCtx, Config, FilesMap } from '../../../util/interfaces';
import { CompilerCtx, Config, FilesMap } from '../../../declarations';
import { normalizePath } from '../../util';

export default function transpiledInMemoryPlugin(config: Config, ctx: CompilerCtx) {

export default function inMemoryFsRead(config: Config, compilerCtx: CompilerCtx) {
const sys = config.sys;
const assetsCache: FilesMap = {};

return {
name: 'transpiledInMemoryPlugin',
name: 'inMemoryFsRead',

resolveId(importee: string, importer: string): string {
async resolveId(importee: string, importer: string) {
if (!sys.path.isAbsolute(importee)) {
importee = normalizePath(sys.path.resolve(importer ? sys.path.dirname(importer) : sys.path.resolve(), importee));

Expand All @@ -19,15 +20,15 @@ export default function transpiledInMemoryPlugin(config: Config, ctx: CompilerCt

// it's possible the importee is a file pointing directly to the source ts file
// if it is a ts file path, then we're good to go
var moduleFile = ctx.moduleFiles[importee];
if (ctx.moduleFiles[importee]) {
var moduleFile = compilerCtx.moduleFiles[importee];
if (compilerCtx.moduleFiles[importee]) {
return moduleFile.jsFilePath;
}

const tsFileNames = Object.keys(ctx.moduleFiles);
const tsFileNames = Object.keys(compilerCtx.moduleFiles);
for (var i = 0; i < tsFileNames.length; i++) {
// see if we can find by importeE
moduleFile = ctx.moduleFiles[tsFileNames[i]];
moduleFile = compilerCtx.moduleFiles[tsFileNames[i]];
if (moduleFile.jsFilePath === importee) {
// awesome, there's a module file for this js file, we're good here
return importee;
Expand All @@ -41,7 +42,7 @@ export default function transpiledInMemoryPlugin(config: Config, ctx: CompilerCt
// think slide's swiper dependency
for (i = 0; i < tsFileNames.length; i++) {
// see if we can find by importeR
moduleFile = ctx.moduleFiles[tsFileNames[i]];
moduleFile = compilerCtx.moduleFiles[tsFileNames[i]];
if (moduleFile.jsFilePath === importer) {
// awesome, there's a module file for this js file via importeR
// now let's check if this module has an assets directory
Expand All @@ -54,7 +55,7 @@ export default function transpiledInMemoryPlugin(config: Config, ctx: CompilerCt
// ok, we've got a potential absolute path where the file "could" be
try {
// let's see if it actually exists, but with readFileSync :(
assetsCache[assetsFilePath] = ctx.fs.readFileSync(assetsFilePath);
assetsCache[assetsFilePath] = compilerCtx.fs.readFileSync(assetsFilePath);
if (typeof assetsCache[assetsFilePath] === 'string') {
return assetsFilePath;
}
Expand All @@ -77,7 +78,7 @@ export default function transpiledInMemoryPlugin(config: Config, ctx: CompilerCt
return assetsCache[sourcePath];
}

return ctx.fs.readFile(sourcePath);
return compilerCtx.fs.readFile(sourcePath);
}
};
}

0 comments on commit e7f97c5

Please sign in to comment.