Skip to content

Commit 7505f5c

Browse files
committed
Handle race condition with plugins
1 parent d7e6975 commit 7505f5c

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

index.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,38 @@ var systemNormalize = System.normalize;
33
System.normalize = function (path, importFrom) {
44
var promise = systemNormalize.apply(this, arguments);
55
promise.then(function (normalizedPath) {
6-
imports[normalizedPath] = {
6+
updateData(normalizedPath, {
77
importPath: path,
88
path: normalizedPath,
99
from: importFrom,
1010
deps: []
11-
};
11+
});
1212
});
1313
return promise;
1414
};
1515

1616
var systemLocate = System.locate;
1717
System.locate = function (load) {
18-
var importData = imports[load.name];
19-
importData.metadata = load.metadata;
18+
var importData = updateData(load.name, {
19+
metadata: load.metadata
20+
})
2021
var fromData = imports[importData.from];
2122
if (fromData) {
2223
fromData.deps.push(importData);
2324
}
2425
return systemLocate.apply(this, arguments);
2526
};
2627

28+
function updateData(normalizedPath, data) {
29+
// create data if doesn't exist
30+
var currData = imports[normalizedPath] = imports[normalizedPath] || {};
31+
// extend data
32+
for(var key in data) {
33+
currData[key] = data[key];
34+
}
35+
return currData;
36+
}
37+
2738
export function logImport (importData) {
2839
console.groupCollapsed(importData.importPath);
2940
console.log('path: ', importData.path);

0 commit comments

Comments
 (0)