Skip to content

Commit

Permalink
pr feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford committed Aug 11, 2018
1 parent 0193bb3 commit 8ecb1e0
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 19 deletions.
8 changes: 4 additions & 4 deletions src/Graph.ts
Expand Up @@ -16,7 +16,7 @@ import {
OutputBundle,
RollupCache,
RollupWarning,
SerialisablePluginCache,
SerializablePluginCache,
SourceDescription,
TreeshakingOptions,
WarningHandler,
Expand Down Expand Up @@ -73,8 +73,8 @@ export default class Graph {
contextParse: (code: string, acornOptions?: acorn.Options) => Program;

pluginDriver: PluginDriver;
pluginCache: Record<string, SerialisablePluginCache>;
watchFiles: string[] = [];
pluginCache: Record<string, SerializablePluginCache>;
watchFiles: Record<string, true> = Object.create(null);
cacheExpiry: number;

// deprecated
Expand Down Expand Up @@ -624,7 +624,7 @@ Try defining "${chunkName}" first in the manualChunks definitions of the Rollup

const module: Module = new Module(this, id);
this.moduleById.set(id, module);
this.watchFiles.push(id);
this.watchFiles[id] = true;

timeStart('load modules', 3);
return Promise.resolve(this.pluginDriver.hookFirst('load', [id]))
Expand Down
2 changes: 1 addition & 1 deletion src/rollup/index.ts
Expand Up @@ -369,7 +369,7 @@ export default function rollup(
const cache = rawInputOptions.cache === false ? undefined : graph.getCache();
const result: RollupSingleFileBuild | RollupBuild = {
cache,
watchFiles: graph.watchFiles,
watchFiles: Object.keys(graph.watchFiles),
generate: <any>((rawOutputOptions: GenericConfigObject) => {
const promise = generate(rawOutputOptions, false).then(
result =>
Expand Down
4 changes: 2 additions & 2 deletions src/rollup/types.d.ts
Expand Up @@ -364,14 +364,14 @@ export interface OutputChunk {
map?: SourceMap;
}

export interface SerialisablePluginCache {
export interface SerializablePluginCache {
[key: string]: [number, any];
}

export interface RollupCache {
// to be deprecated
modules?: ModuleJSON[];
plugins?: Record<string, SerialisablePluginCache>;
plugins?: Record<string, SerializablePluginCache>;
}

export interface RollupSingleFileBuild {
Expand Down
10 changes: 3 additions & 7 deletions src/utils/assetHooks.ts
Expand Up @@ -47,7 +47,7 @@ export function getAssetFileName(

export function createAssetPluginHooks(
assetsById: Map<string, Asset>,
watchFiles: string[],
watchFiles: Record<string, true>,
outputBundle?: OutputBundle,
assetFileNames?: string
) {
Expand Down Expand Up @@ -98,9 +98,7 @@ export function createAssetPluginHooks(
if (outputBundle && source !== undefined) finaliseAsset(asset, outputBundle, assetFileNames);
assetsById.set(assetId, asset);
if (!asset.transform && asset.dependencies && asset.dependencies.length) {
for (const depId of asset.dependencies) {
if (watchFiles.indexOf(depId) === -1) watchFiles.push(depId);
}
for (const depId of asset.dependencies) watchFiles[depId] = true;
}
return assetId;
},
Expand Down Expand Up @@ -139,9 +137,7 @@ export function createAssetPluginHooks(
});
asset.source = source;
if (!asset.transform && asset.dependencies && asset.dependencies.length) {
for (const depId of asset.dependencies) {
if (watchFiles.indexOf(depId) === -1) watchFiles.push(depId);
}
for (const depId of asset.dependencies) watchFiles[depId] = true;
}
if (outputBundle) finaliseAsset(asset, outputBundle, assetFileNames);
},
Expand Down
9 changes: 4 additions & 5 deletions src/utils/pluginDriver.ts
Expand Up @@ -6,13 +6,12 @@ import {
PluginContext,
RollupError,
RollupWarning,
SerialisablePluginCache,
SerializablePluginCache,
Watcher
} from '../rollup/types';
import { createAssetPluginHooks, EmitAsset } from './assetHooks';
import { getRollupDefaultPlugin } from './default-plugin';
import error from './error';
import { resolve } from './path';

export interface PluginDriver {
emitAsset: EmitAsset;
Expand Down Expand Up @@ -42,7 +41,7 @@ export type HookContext = (context: PluginContext, plugin?: Plugin) => PluginCon
export function createPluginDriver(
graph: Graph,
options: InputOptions,
pluginCache: Record<string, SerialisablePluginCache>,
pluginCache: Record<string, SerializablePluginCache>,
watcher?: Watcher
): PluginDriver {
const plugins = [...(options.plugins || []), getRollupDefaultPlugin(options)];
Expand Down Expand Up @@ -86,7 +85,7 @@ export function createPluginDriver(
const context: PluginContext = {
watcher,
addWatchFile(id: string) {
graph.watchFiles.push(resolve(id));
graph.watchFiles[id] = true;
},
cache: cacheInstance,
isExternal(id: string, parentId: string, isResolved = false) {
Expand Down Expand Up @@ -227,7 +226,7 @@ export function createPluginDriver(
return pluginDriver;
}

export function createPluginCache(cache: SerialisablePluginCache): PluginCache {
export function createPluginCache(cache: SerializablePluginCache): PluginCache {
return {
has(id: string) {
const item = cache[id];
Expand Down

0 comments on commit 8ecb1e0

Please sign in to comment.