Skip to content

Commit c419d46

Browse files
committed
map sources by filename, so we can update a certain source
1 parent 214d82c commit c419d46

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/file-system-loader.js

+14-3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export default class FileSystemLoader {
2323
constructor( root, plugins ) {
2424
this.root = root
2525
this.sources = {}
26+
this.traces = {}
2627
this.importNr = 0
2728
this.core = new Core(plugins)
2829
this.tokensByFile = {};
@@ -51,7 +52,8 @@ export default class FileSystemLoader {
5152
if ( err ) reject( err )
5253
this.core.load( source, rootRelativePath, trace, this.fetch.bind( this ) )
5354
.then( ( { injectableSource, exportTokens } ) => {
54-
this.sources[trace] = injectableSource
55+
this.sources[fileRelativePath] = injectableSource
56+
this.traces[trace] = fileRelativePath
5557
this.tokensByFile[fileRelativePath] = exportTokens
5658
resolve( exportTokens )
5759
}, reject )
@@ -60,7 +62,16 @@ export default class FileSystemLoader {
6062
}
6163

6264
get finalSource() {
63-
return Object.keys( this.sources ).sort( traceKeySorter ).map( s => this.sources[s] )
64-
.join( "" )
65+
const traces = this.traces
66+
const sources = this.sources
67+
let written = new Set()
68+
69+
return Object.keys( traces ).sort( traceKeySorter ).map(key => {
70+
const filename = traces[key]
71+
if (written.has(filename)) { return null }
72+
written.add(filename)
73+
74+
return sources[filename];
75+
}).join( "" )
6576
}
6677
}

0 commit comments

Comments
 (0)