diff --git a/src/lightweight.js b/src/lightweight.js index f2b7529..08d4eb0 100644 --- a/src/lightweight.js +++ b/src/lightweight.js @@ -46,10 +46,16 @@ const got = async (url, opts) => { } } -module.exports = factory({ +const mql = factory({ MicrolinkError, urlHttp, got, flatten, VERSION: '__MQL_VERSION__' }) + +module.exports = mql +module.exports.MicrolinkError = mql.MicrolinkError +module.exports.getApiUrl = mql.getApiUrl +module.exports.mapRules = mql.mapRules +module.exports.version = mql.version diff --git a/test/build.mjs b/test/build.mjs index 7b15bc6..36a8275 100644 --- a/test/build.mjs +++ b/test/build.mjs @@ -7,7 +7,8 @@ import test from 'ava' const require = createRequire(import.meta.url) const pkg = require('../package.json') -const evalScript = code => $`node -e ${code}` +const evalScript = (code) => $`node --eval ${code}` +evalScript.esm = (code) => $`node --input-type module -e ${code}` test('cjs', async t => { // eslint-disable-next-line no-template-curly-in-string @@ -15,3 +16,10 @@ test('cjs', async t => { const { stdout } = await evalScript(code) t.is(stdout, `mql v${pkg.version}`) }) + +test('esm', async t => { + // eslint-disable-next-line no-template-curly-in-string + const code = "import {version} from '@microlink/mql'; console.log(`mql v${version}`)" + const { stdout } = await evalScript.esm(code) + t.is(stdout, `mql v${pkg.version}`) +})