add npm as default module loader
This commit is contained in:
parent
e5d18a75f8
commit
fa85e689df
22
dist/index.js
vendored
22
dist/index.js
vendored
@ -3,7 +3,6 @@ require("typings-global");
|
||||
const path = require("path");
|
||||
const q = require("q");
|
||||
const lik_1 = require("lik");
|
||||
let systemjs = require('systemjs');
|
||||
class Smartsystem {
|
||||
constructor() {
|
||||
this.lazyModules = new lik_1.Objectmap();
|
||||
@ -39,18 +38,21 @@ class LazyModule {
|
||||
load() {
|
||||
let done = q.defer();
|
||||
let loadedModule;
|
||||
let loadingPath;
|
||||
if (this.loader === 'npm') {
|
||||
loadingPath = require.resolve(this.name);
|
||||
loadedModule = require(this.name);
|
||||
done.resolve(loadedModule);
|
||||
}
|
||||
else if (this.loader === 'systemjs') {
|
||||
let systemjs = require('systemjs');
|
||||
systemjs.import(this.name).then((m) => {
|
||||
loadedModule = m;
|
||||
this.whenLoadedDeferred.resolve(loadedModule);
|
||||
done.resolve(loadedModule);
|
||||
}).catch(err => { console.log(err); });
|
||||
}
|
||||
else {
|
||||
loadingPath = this.name;
|
||||
throw Error('loader not supported');
|
||||
}
|
||||
systemjs.import(loadingPath).then((m) => {
|
||||
loadedModule = m;
|
||||
this.whenLoadedDeferred.resolve(loadedModule);
|
||||
done.resolve(loadedModule);
|
||||
}).catch(err => { console.log(err); });
|
||||
return done.promise;
|
||||
}
|
||||
/**
|
||||
@ -60,4 +62,4 @@ class LazyModule {
|
||||
}
|
||||
}
|
||||
exports.LazyModule = LazyModule;
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsMEJBQXVCO0FBRXZCLDZCQUE0QjtBQUM1Qix1QkFBc0I7QUFDdEIsNkJBQStCO0FBQy9CLElBQUksUUFBUSxHQUFHLE9BQU8sQ0FBQyxVQUFVL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MsQ0FBQyxDQUFDLEtBQUssQ0FBQyxHQUFHLE1BQU0sT0FBTyxDQUFDLEdBQUcsQ0FBQyxHQUFHLENBQUMsQ0FBQSxDQUFDLENBQUMsQ0FBQyxDQUFBO1FBQ3pDLENBQUM7UUFBQyxJQUFJLENBQUMsQ0FBQztZQUNKLE1BQU0sS0FBSyxDQUFDLHNCQUFzQixDQUFDLENBQUE7UUFDdkMsQ0FBQztRQUNELE1BQU0sQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFBO0lBQ3ZCLENBQUM7SUFFRDs7T0FFRztJQUNILFFBQVEsQ0FBQyxHQUFHLElBQXVCO0lBRW5DLENBQUM7Q0FDSjtBQW5ERCxnQ0FtREMifQ==
|
21
ts/index.ts
21
ts/index.ts
@ -3,7 +3,6 @@ import 'typings-global'
|
||||
import * as path from 'path'
|
||||
import * as q from 'q'
|
||||
import { Objectmap } from 'lik'
|
||||
let systemjs = require('systemjs')
|
||||
|
||||
class Smartsystem {
|
||||
lazyModules = new Objectmap<LazyModule<any>>()
|
||||
@ -54,17 +53,19 @@ export class LazyModule<T> {
|
||||
load(): q.Promise<T> {
|
||||
let done = q.defer<T>()
|
||||
let loadedModule: T
|
||||
let loadingPath: string
|
||||
if (this.loader === 'npm') {
|
||||
loadingPath = require.resolve(this.name)
|
||||
} else {
|
||||
loadingPath = this.name
|
||||
}
|
||||
systemjs.import(loadingPath).then((m) => {
|
||||
loadedModule = m
|
||||
this.whenLoadedDeferred.resolve(loadedModule)
|
||||
loadedModule = require(this.name)
|
||||
done.resolve(loadedModule)
|
||||
}).catch(err => { console.log(err) })
|
||||
} else if (this.loader === 'systemjs') {
|
||||
let systemjs = require('systemjs')
|
||||
systemjs.import(this.name).then((m) => {
|
||||
loadedModule = m
|
||||
this.whenLoadedDeferred.resolve(loadedModule)
|
||||
done.resolve(loadedModule)
|
||||
}).catch(err => { console.log(err) })
|
||||
} else {
|
||||
throw Error('loader not supported')
|
||||
}
|
||||
return done.promise
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user