-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
system-node.js
45 lines (37 loc) · 1.41 KB
/
system-node.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import './features/resolve.js';
import './features/registry.js';
import './features/fetch-load.js';
import './features/node-fetch.js';
import './extras/global.js';
import { REGISTRY, systemJSPrototype } from './system-core.js';
import { BASE_URL, baseUrl, resolveAndComposeImportMap, IMPORT_MAP } from './common.js';
export const System = global.System;
const IMPORT_MAP_PROMISE = Symbol();
systemJSPrototype.prepareImport = function () {
return this[IMPORT_MAP_PROMISE];
};
const originalResolve = systemJSPrototype.resolve;
systemJSPrototype.resolve = function () {
if (!this[IMPORT_MAP]) {
// Allow for basic URL resolution before applyImportMap is called
this[IMPORT_MAP] = { imports: {}, scopes: {} };
}
return originalResolve.apply(this, arguments);
};
systemJSPrototype.applyImportMap = function (newMap, mapBase){
applyImportMap(this, newMap, mapBase)
}
export function applyImportMap(loader, newMap, mapBase) {
ensureValidSystemLoader(loader);
loader[IMPORT_MAP] = loader[IMPORT_MAP] || { imports: {}, scopes: {} };
resolveAndComposeImportMap(newMap, mapBase || baseUrl, loader[IMPORT_MAP]);
loader[IMPORT_MAP_PROMISE] = Promise.resolve();
}
export function setBaseUrl(loader, url) {
ensureValidSystemLoader(loader);
loader[BASE_URL] = new URL(url).href;
}
function ensureValidSystemLoader (loader) {
if (!loader[REGISTRY])
throw new Error('A valid SystemJS instance must be provided');
}