fix(lib)!: remove format prefixes for cjs and esm (#8107)

This commit is contained in:
Sachin Raja 2022-05-12 06:13:12 -07:00 committed by GitHub
parent c32e3ac502
commit ad8c3b1c77
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 17 additions and 14 deletions

View File

@ -33,7 +33,7 @@ describe('resolveLibFilename', () => {
resolve(__dirname, 'packages/name')
)
expect(filename).toBe('custom-filename.es.mjs')
expect(filename).toBe('custom-filename.mjs')
})
test('package name as filename', () => {
@ -45,7 +45,7 @@ describe('resolveLibFilename', () => {
resolve(__dirname, 'packages/name')
)
expect(filename).toBe('mylib.es.mjs')
expect(filename).toBe('mylib.mjs')
})
test('custom filename and no package name', () => {
@ -58,7 +58,7 @@ describe('resolveLibFilename', () => {
resolve(__dirname, 'packages/noname')
)
expect(filename).toBe('custom-filename.es.mjs')
expect(filename).toBe('custom-filename.mjs')
})
test('missing filename', () => {
@ -75,9 +75,9 @@ describe('resolveLibFilename', () => {
test('commonjs package extensions', () => {
const formatsToFilenames: FormatsToFileNames = [
['es', 'my-lib.es.mjs'],
['es', 'my-lib.mjs'],
['umd', 'my-lib.umd.js'],
['cjs', 'my-lib.cjs.js'],
['cjs', 'my-lib.js'],
['iife', 'my-lib.iife.js']
]
@ -94,9 +94,9 @@ describe('resolveLibFilename', () => {
test('module package extensions', () => {
const formatsToFilenames: FormatsToFileNames = [
['es', 'my-lib.es.js'],
['es', 'my-lib.js'],
['umd', 'my-lib.umd.cjs'],
['cjs', 'my-lib.cjs.cjs'],
['cjs', 'my-lib.cjs'],
['iife', 'my-lib.iife.js']
]
@ -107,7 +107,7 @@ describe('resolveLibFilename', () => {
resolve(__dirname, 'packages/module')
)
expect(filename).toBe(expectedFilename)
expect(expectedFilename).toBe(filename)
}
})
})

View File

@ -596,6 +596,10 @@ export function resolveLibFilename(
extension = format === 'es' ? 'mjs' : 'js'
}
if (format === 'cjs' || format === 'es') {
return `${name}.${extension}`
}
return `${name}.${format}.${extension}`
}

View File

@ -5,7 +5,7 @@
<div class="dynamic-import-message"></div>
<script type="module">
import myLib from './my-lib-custom-filename.es.mjs'
import myLib from './my-lib-custom-filename.mjs'
myLib('.es')
</script>

View File

@ -11,7 +11,7 @@ const build = (configName: string) => {
const getDistFile = (configName: string, extension: string) => {
return fs.readFileSync(
fromTestDir(`${configName}/dist/index.es.${extension}`),
fromTestDir(`${configName}/dist/index.${extension}`),
'utf8'
)
}

View File

@ -1,8 +1,7 @@
/* eslint-disable node/no-missing-import */
// @ts-ignore
import { CompA } from '../dist/lib/my-vue-lib.es'
import '../dist/lib/style.css'
import { createApp } from 'vue'
// @ts-ignore
import { CompA } from '../dist/lib/my-vue-lib'
import '../dist/lib/style.css'
const app = createApp(CompA)
app.mount('#app')