Last active
June 8, 2020 18:54
-
-
Save jkrems/42ffe551614a2c41200f1e9055efcac5 to your computer and use it in GitHub Desktop.
Exports Hash
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
module.exports = '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
module.exports = 42; |
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
{ | |
"name": "exports-hash", | |
"exports": { | |
"./#foo": "./ok.js", | |
"./module": "./ok.js", | |
"./๐": "./ok.js", | |
"./%F0%9F%8E%89": "./other.js", | |
"./bar#foo": "./ok.js", | |
"./#zapp/": "./" | |
} | |
} |
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
import {createRequire} from 'module'; | |
const requireSync = createRequire(import.meta.url); | |
async function require(specifier) { | |
return {default: requireSync(specifier)}; | |
} | |
const specifiers = [ | |
// Does resolve (exact match) | |
'exports-hash/#foo', | |
'exports-hash/bar#foo', | |
'exports-hash/module', | |
// Does resolve (prefix matching) | |
'exports-hash/#zapp/ok.js#abc', | |
'exports-hash/#zapp/ok.js?abc', | |
// Does resolve, since it's prefix-matched, it gives the same result. | |
'exports-hash/#zapp/๐.js', | |
'exports-hash/#zapp/%F0%9F%8E%89.js', | |
// Does resolve but no URL-style normalization, different result! | |
'exports-hash/๐', | |
'exports-hash/%F0%9F%8E%89', | |
// Does *not* resolve (exact match) | |
'exports-hash/module#foo', | |
'exports-hash/module?foo', | |
]; | |
function log(specifier, promise) { | |
promise.then(value => { | |
console.error('loaded %j', specifier, value); | |
}).catch(e => { | |
console.error('failed %j', specifier, e); | |
}); | |
} | |
async function main() { | |
for (const specifier of specifiers) { | |
log(specifier, import(specifier)); | |
log(specifier, require(specifier)); | |
} | |
} | |
main(); |
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
module.exports = 'tada'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment