From c419d46b9f8b0fc63676bc142a8f4ad79e7448e5 Mon Sep 17 00:00:00 2001 From: Josh Johnston Date: Mon, 30 Nov 2015 22:56:09 +1100 Subject: [PATCH] map sources by filename, so we can update a certain source --- src/file-system-loader.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/file-system-loader.js b/src/file-system-loader.js index 2a3f47d..e26c2c0 100644 --- a/src/file-system-loader.js +++ b/src/file-system-loader.js @@ -23,6 +23,7 @@ export default class FileSystemLoader { constructor( root, plugins ) { this.root = root this.sources = {} + this.traces = {} this.importNr = 0 this.core = new Core(plugins) this.tokensByFile = {}; @@ -51,7 +52,8 @@ export default class FileSystemLoader { if ( err ) reject( err ) this.core.load( source, rootRelativePath, trace, this.fetch.bind( this ) ) .then( ( { injectableSource, exportTokens } ) => { - this.sources[trace] = injectableSource + this.sources[fileRelativePath] = injectableSource + this.traces[trace] = fileRelativePath this.tokensByFile[fileRelativePath] = exportTokens resolve( exportTokens ) }, reject ) @@ -60,7 +62,16 @@ export default class FileSystemLoader { } get finalSource() { - return Object.keys( this.sources ).sort( traceKeySorter ).map( s => this.sources[s] ) - .join( "" ) + const traces = this.traces + const sources = this.sources + let written = new Set() + + return Object.keys( traces ).sort( traceKeySorter ).map(key => { + const filename = traces[key] + if (written.has(filename)) { return null } + written.add(filename) + + return sources[filename]; + }).join( "" ) } }