This repository has been archived by the owner on Apr 16, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
41 changed files
with
461 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// Flags: --experimental-modules --loader ./test/fixtures/es-module-loaders/example-loader.mjs | ||
/* eslint-disable node-core/required-modules */ | ||
import assert from 'assert'; | ||
import ok from '../fixtures/es-modules/test-esm-ok.mjs'; | ||
|
||
assert(ok); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// Flags: --experimental-modules --loader ./test/fixtures/es-module-loaders/loader-with-dep.mjs | ||
/* eslint-disable node-core/required-modules */ | ||
import '../fixtures/es-modules/test-esm-ok.mjs'; | ||
|
||
// We just test that this module doesn't fail loading |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Flags: --experimental-modules --loader ./test/fixtures/es-module-loaders/loader-invalid-format.mjs | ||
/* eslint-disable node-core/required-modules */ | ||
import { expectsError, mustCall } from '../common/index.mjs'; | ||
import assert from 'assert'; | ||
|
||
import('../fixtures/es-modules/test-esm-ok.mjs') | ||
.then(assert.fail, expectsError({ | ||
code: 'ERR_INVALID_RETURN_PROPERTY_VALUE', | ||
message: 'Expected string to be returned for the "format" from the ' + | ||
'"loader resolve" function but got type undefined.' | ||
})) | ||
.then(mustCall()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Flags: --experimental-modules --loader ./test/fixtures/es-module-loaders/loader-invalid-url.mjs | ||
/* eslint-disable node-core/required-modules */ | ||
|
||
import { expectsError, mustCall } from '../common/index.mjs'; | ||
import assert from 'assert'; | ||
|
||
import('../fixtures/es-modules/test-esm-ok.mjs') | ||
.then(assert.fail, expectsError({ | ||
code: 'ERR_INVALID_RETURN_PROPERTY', | ||
message: 'Expected a valid url to be returned for the "url" from the ' + | ||
'"loader resolve" function but got ' + | ||
'../fixtures/es-modules/test-esm-ok.mjs.' | ||
})) | ||
.then(mustCall()); |
10 changes: 10 additions & 0 deletions
10
test/es-module/test-esm-loader-missing-dynamic-instantiate-hook.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// Flags: --experimental-modules --loader ./test/fixtures/es-module-loaders/missing-dynamic-instantiate-hook.mjs | ||
/* eslint-disable node-core/required-modules */ | ||
|
||
import { expectsError } from '../common/index.mjs'; | ||
|
||
import('test').catch(expectsError({ | ||
code: 'ERR_MISSING_DYNAMIC_INSTANTIATE_HOOK', | ||
message: 'The ES Module loader may not return a format of \'dynamic\' ' + | ||
'when no dynamicInstantiate function was provided' | ||
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Flags: --experimental-modules --loader ./test/fixtures/es-module-loaders/builtin-named-exports-loader.mjs | ||
/* eslint-disable node-core/required-modules */ | ||
import '../common/index.mjs'; | ||
import { readFile } from 'fs'; | ||
import assert from 'assert'; | ||
import ok from '../fixtures/es-modules/test-esm-ok.mjs'; | ||
|
||
assert(ok); | ||
assert(readFile); |
3 changes: 3 additions & 0 deletions
3
test/es-module/test-esm-preserve-symlinks-not-found-plain.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Flags: --experimental-modules --loader ./test/fixtures/es-module-loaders/not-found-assert-loader.mjs | ||
/* eslint-disable node-core/required-modules */ | ||
import './not-found.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Flags: --experimental-modules --loader ./test/fixtures/es-module-loaders/not-found-assert-loader.mjs | ||
/* eslint-disable node-core/required-modules */ | ||
import './not-found.mjs'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// Flags: --experimental-modules --loader ./test/fixtures/es-module-loaders/js-loader.mjs | ||
/* eslint-disable node-core/required-modules */ | ||
import { namedExport } from '../fixtures/es-module-loaders/js-as-esm.js'; | ||
import assert from 'assert'; | ||
import ok from '../fixtures/es-modules/test-esm-ok.mjs'; | ||
|
||
assert(ok); | ||
assert(namedExport); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Flags: --experimental-modules --loader ./test/fixtures/es-module-loaders/loader-shared-dep.mjs | ||
/* eslint-disable node-core/required-modules */ | ||
import { createRequire } from '../common/index.mjs'; | ||
|
||
import assert from 'assert'; | ||
import '../fixtures/es-modules/test-esm-ok.mjs'; | ||
|
||
const require = createRequire(import.meta.url); | ||
const dep = require('../fixtures/es-module-loaders/loader-dep.js'); | ||
|
||
assert.strictEqual(dep.format, 'module'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Flags: --experimental-modules | ||
/* eslint-disable node-core/required-modules */ | ||
|
||
import '../common/index.mjs'; | ||
import assert from 'assert'; | ||
|
||
async function doTest() { | ||
await assert.rejects( | ||
async () => { | ||
await import('../fixtures/es-module-loaders/throw-undefined.mjs'); | ||
}, | ||
(e) => e === undefined | ||
); | ||
} | ||
|
||
doTest(); |
24 changes: 24 additions & 0 deletions
24
test/fixtures/es-module-loaders/builtin-named-exports-loader.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import module from 'module'; | ||
|
||
export function dynamicInstantiate(url) { | ||
const builtinInstance = module._load(url.substr(5)); | ||
const builtinExports = ['default', ...Object.keys(builtinInstance)]; | ||
return { | ||
exports: builtinExports, | ||
execute: exports => { | ||
for (let name of builtinExports) | ||
exports[name].set(builtinInstance[name]); | ||
exports.default.set(builtinInstance); | ||
} | ||
}; | ||
} | ||
|
||
export function resolve(specifier, base, defaultResolver) { | ||
if (module.builtinModules.includes(specifier)) { | ||
return { | ||
url: `node:${specifier}`, | ||
format: 'dynamic' | ||
}; | ||
} | ||
return defaultResolver(specifier, base); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import url from 'url'; | ||
import path from 'path'; | ||
import process from 'process'; | ||
import { builtinModules } from 'module'; | ||
|
||
const JS_EXTENSIONS = new Set(['.js', '.mjs']); | ||
|
||
const baseURL = new url.URL('file://'); | ||
baseURL.pathname = process.cwd() + '/'; | ||
|
||
export function resolve(specifier, parentModuleURL = baseURL /*, defaultResolve */) { | ||
if (builtinModules.includes(specifier)) { | ||
return { | ||
url: specifier, | ||
format: 'builtin' | ||
}; | ||
} | ||
if (/^\.{0,2}[/]/.test(specifier) !== true && !specifier.startsWith('file:')) { | ||
// For node_modules support: | ||
// return defaultResolve(specifier, parentModuleURL); | ||
throw new Error( | ||
`imports must begin with '/', './', or '../'; '${specifier}' does not`); | ||
} | ||
const resolved = new url.URL(specifier, parentModuleURL); | ||
const ext = path.extname(resolved.pathname); | ||
if (!JS_EXTENSIONS.has(ext)) { | ||
throw new Error( | ||
`Cannot load file with non-JavaScript file extension ${ext}.`); | ||
} | ||
return { | ||
url: resolved.href, | ||
format: 'module' | ||
}; | ||
} |
Oops, something went wrong.