Skip to content

Commit 3c63c24

Browse files
committed
fix: .d.mts for all
1 parent 093bf38 commit 3c63c24

File tree

5 files changed

+27
-22
lines changed

5 files changed

+27
-22
lines changed

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,19 @@
1818
"sideEffects": false,
1919
"exports": {
2020
".": {
21-
"types": "./dist/index.d.ts",
21+
"types": "./dist/index.d.mts",
2222
"import": "./dist/index.mjs"
2323
},
2424
"./core": {
25-
"types": "./dist/core.d.ts",
25+
"types": "./dist/core.d.mts",
2626
"import": "./dist/core.mjs"
2727
},
2828
"./dist/*": "./dist/*",
2929
"./*": "./dist/*"
3030
},
3131
"main": "./dist/index.mjs",
3232
"module": "./dist/index.mjs",
33-
"types": "./dist/index.d.ts",
33+
"types": "./dist/index.d.mts",
3434
"files": [
3535
"dist"
3636
],

rollup.config.mjs

+6-4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export default defineConfig([
2828
input: [
2929
'src/index.ts',
3030
'src/core.ts',
31+
'src/wasm.ts',
3132
],
3233
output: {
3334
dir: 'dist',
@@ -51,13 +52,14 @@ export default defineConfig([
5152
input: [
5253
'src/core.ts',
5354
'src/index.ts',
55+
'src/wasm.ts',
5456
'src/types.ts',
5557
],
5658
output: {
5759
dir: 'dist',
5860
format: 'esm',
59-
chunkFileNames: 'types/[name].d.ts',
60-
entryFileNames: f => `${f.name.replace('src/', '')}.d.ts`,
61+
chunkFileNames: 'types/[name].d.mts',
62+
entryFileNames: f => `${f.name.replace('src/', '')}.d.mts`,
6163
},
6264
plugins: [
6365
dts({
@@ -74,15 +76,15 @@ export default defineConfig([
7476
await Promise.all(
7577
langs.map(file => fs.writeFile(
7678
join(dirname(file), `${basename(file, '.mjs')}.d.mts`),
77-
'import { LanguageRegistration } from \'../types\';declare const reg: LanguageRegistration;export default reg',
79+
'import { LanguageRegistration } from \'../types.mjs\';declare const reg: LanguageRegistration;export default reg',
7880
'utf-8',
7981
)),
8082
)
8183
const themes = await fg('dist/themes/*.mjs', { absolute: true })
8284
await Promise.all(
8385
themes.map(file => fs.writeFile(
8486
join(dirname(file), `${basename(file, '.mjs')}.d.mts`),
85-
'import { ThemeRegisterationRaw } from \'../types\';declare const reg: ThemeRegisterationRaw;export default reg',
87+
'import { ThemeRegisterationRaw } from \'../types.mjs\';declare const reg: ThemeRegisterationRaw;export default reg',
8688
'utf-8',
8789
)),
8890
)

src/index.ts

+7-10
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,21 @@ import type { BuiltinLanguages, BuiltinThemes, LanguageInput, ThemeInput } from
22
import { themes } from './vendor/themes'
33
import { languages } from './vendor/langs'
44
import { getHighlighter as getCoreHighlighter } from './core'
5+
import { loadWasm } from './oniguruma'
6+
import { getWasmInlined } from './wasm'
57

68
export * from './types'
79

10+
export {
11+
loadWasm,
12+
getWasmInlined,
13+
}
14+
815
export interface HighlighterOptions {
916
themes?: (ThemeInput | BuiltinThemes)[]
1017
langs?: (LanguageInput | BuiltinLanguages)[]
1118
}
1219

13-
let _onigurumaPromise: Promise<{ data: ArrayBuffer }> | null = null
14-
export async function getWasmInlined(): Promise<{ data: ArrayBuffer }> {
15-
if (!_onigurumaPromise) {
16-
// @ts-expect-error anyway
17-
_onigurumaPromise = import('vscode-oniguruma/release/onig.wasm')
18-
.then(r => ({ data: r.default as ArrayBuffer }))
19-
}
20-
return _onigurumaPromise
21-
}
22-
2320
export async function getHighlighter(options: HighlighterOptions = {}) {
2421
const _themes = (options.themes ?? ['nord']).map((i) => {
2522
if (typeof i === 'string')

src/wasm.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
let _onigurumaPromise: Promise<{ data: ArrayBuffer }> | null = null
2+
export async function getWasmInlined(): Promise<{ data: ArrayBuffer }> {
3+
if (!_onigurumaPromise) {
4+
// @ts-expect-error anyway
5+
_onigurumaPromise = import('vscode-oniguruma/release/onig.wasm')
6+
.then(r => ({ data: r.default as ArrayBuffer }))
7+
}
8+
return _onigurumaPromise
9+
}

test/core.test.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
import { describe, expect, it } from 'vitest'
22
import { getHighlighter } from '../src/core'
33

4-
// @ts-expect-error no-types
54
import js from '../dist/languages/javascript.mjs'
6-
7-
// @ts-expect-error no-types
85
import nord from '../dist/themes/nord.mjs'
96

107
// @ts-expect-error no-types
@@ -13,8 +10,8 @@ import onig from '../dist/onig.mjs'
1310
describe('should', () => {
1411
it('exported', async () => {
1512
const shiki = await getHighlighter({
16-
themes: [nord as any],
17-
langs: [js as any],
13+
themes: [nord],
14+
langs: [js],
1815
loadWasm: {
1916
instantiator: obj => WebAssembly.instantiate(onig, obj),
2017
},

0 commit comments

Comments
 (0)