Skip to content
This repository was archived by the owner on Jul 13, 2020. It is now read-only.

Commit 9cc4230

Browse files
committed
0.3.0
1 parent 9bc3f7f commit 9cc4230

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ import {fn} from './local-es-module.js';
3131

3232
Note that only the default import form for CommonJS modules is supported.
3333

34-
Also supports dynamic loading via a `loader` global (note that this will change in future when the dynamic loader spec is available);
34+
Also supports dynamic loading via the dynamic import syntax:
3535

3636
```javascript
3737
export function lazyLoad(path) {
38-
return loader.import(path);
38+
return import(path);
3939
}
4040
```
4141

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
{
22
"name": "node-es-module-loader",
3-
"version": "0.2.0",
3+
"version": "0.3.0",
44
"description": "Loads ES modules with CJS interop in Node",
55
"main": "dist/node-es-module-loader.js",
66
"bin": {
77
"node-esml": "bin/node-esml.js"
88
},
99
"dependencies": {
1010
"babel-core": "^6.17.0",
11-
"babel-plugin-transform-es2015-modules-systemjs": "^6.14.0"
11+
"babel-plugin-syntax-dynamic-import": "^6.18.0",
12+
"babel-plugin-transform-es2015-modules-systemjs": "^6.19.0"
1213
},
1314
"author": "Guy Bedford",
1415
"license": "MIT",

src/node-es-module-loader.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import RegisterLoader from 'es-module-loader/core/register-loader.js';
2-
import { InternalModuleNamespace as ModuleNamespace } from 'es-module-loader/core/loader-polyfill.js';
2+
import { ModuleNamespace } from 'es-module-loader/core/loader-polyfill.js';
33

44
import { isNode, baseURI, pathToFileUrl, fileUrlToPath } from 'es-module-loader/core/common.js';
5-
import { resolveUrlToParentIfNotPlain } from 'es-module-loader/core/resolve.js';
5+
import { resolveIfNotPlain } from 'es-module-loader/core/resolve.js';
66

77
var babel = require('babel-core');
8+
var modulesRegister = require('babel-plugin-transform-es2015-modules-systemjs');
9+
var importSyntax = require('babel-plugin-syntax-dynamic-import');
810
var path = require('path');
911
var Module = require('module');
1012
var fs = require('fs');
@@ -28,7 +30,7 @@ function NodeESModuleLoader(baseKey, rcPath) {
2830
throw new Error('Node module loader can only be used in Node');
2931

3032
if (baseKey)
31-
baseKey = resolveUrlToParentIfNotPlain(baseKey, baseURI) || resolveUrlToParentIfNotPlain('./' + baseKey, baseURI);
33+
baseKey = resolveIfNotPlain(baseKey, baseURI) || resolveIfNotPlain('./' + baseKey, baseURI);
3234

3335
if (rcPath) {
3436
if (typeof rcPath !== 'string')
@@ -49,8 +51,9 @@ function NodeESModuleLoader(baseKey, rcPath) {
4951
NodeESModuleLoader.prototype = Object.create(RegisterLoader.prototype);
5052

5153
// normalize is never given a relative name like "./x", that part is already handled
52-
NodeESModuleLoader.prototype[RegisterLoader.resolve] = function(key, parent, metadata) {
53-
key = RegisterLoader.prototype[RegisterLoader.resolve].call(this, key, parent, metadata) || key;
54+
NodeESModuleLoader.prototype[RegisterLoader.resolve] = function(key, parent) {
55+
parent = parent || baseURI;
56+
key = RegisterLoader.prototype[RegisterLoader.resolve].call(this, key, parent) || key;
5457

5558
return Promise.resolve()
5659
.then(function() {
@@ -66,7 +69,7 @@ NodeESModuleLoader.prototype[RegisterLoader.resolve] = function(key, parent, met
6669

6770
// instantiate just needs to run System.register
6871
// so we fetch the source, convert into the Babel System module format, then evaluate it
69-
NodeESModuleLoader.prototype[RegisterLoader.instantiate] = function(key, metadata, processAnonRegister) {
72+
NodeESModuleLoader.prototype[RegisterLoader.instantiate] = function(key, processAnonRegister) {
7073
var loader = this;
7174

7275
// first, try to load the module as CommonJS
@@ -90,7 +93,7 @@ NodeESModuleLoader.prototype[RegisterLoader.instantiate] = function(key, metadat
9093
sourceFileName: key,
9194
moduleIds: false,
9295
sourceMaps: 'both',
93-
plugins: [require('babel-plugin-transform-es2015-modules-systemjs')],
96+
plugins: [importSyntax, modulesRegister],
9497
extends: loader.rcPath
9598
});
9699

0 commit comments

Comments
 (0)