Skip to content

Commit

Permalink
fix(esm): ensure indvidual methods are exported (#135)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats authored Sep 6, 2023
1 parent d8739cd commit 9212276
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/lightweight.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 9 additions & 1 deletion test/build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,19 @@ 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
const code = "console.log(`mql v${require('@microlink/mql').version}`)"
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}`)
})

1 comment on commit 9212276

@vercel
Copy link

@vercel vercel bot commented on 9212276 Sep 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.