Skip to content

Commit

Permalink
Fixed it perhaps again?
Browse files Browse the repository at this point in the history
  • Loading branch information
Hugos68 committed Dec 15, 2024
1 parent 158a69b commit 16a7c9b
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 38 deletions.
28 changes: 0 additions & 28 deletions packages/twoslash-svelte/build.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { copyFileSync, mkdirSync } from 'node:fs'
import { dirname, resolve } from 'node:path'
import { defineBuildConfig } from 'unbuild'

export default defineBuildConfig({
Expand All @@ -11,30 +9,4 @@ export default defineBuildConfig({
rollup: {
emitCJS: true,
},
hooks: {
'build:done': () => {
const typeFiles = [
'svelte-jsx.d.ts',
'svelte-jsx-v4.d.ts',
'svelte-shims.d.ts',
'svelte-shims-v4.d.ts',
]
const svelte2tsxPath = dirname(require.resolve('svelte2tsx/svelte-jsx.d.ts'))
// eslint-disable-next-line node/prefer-global/process
const destPath = resolve(process.cwd(), 'dist/types')
mkdirSync(destPath, { recursive: true })
typeFiles.forEach((file) => {
const sourcePath = resolve(svelte2tsxPath, file)
const destFilePath = resolve(destPath, file)

try {
copyFileSync(sourcePath, destFilePath)
console.log(`Copied ${file} to dist/types`)
}
catch (error) {
console.error(`Failed to copy ${file}:`, error)
}
})
},
},
})
2 changes: 1 addition & 1 deletion packages/twoslash-svelte/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@
"start": "esno src/index.ts"
},
"peerDependencies": {
"svelte2tsx": "*",
"typescript": "*"
},
"dependencies": {
"@jridgewell/sourcemap-codec": "catalog:",
"@volar/language-core": "catalog:",
"svelte2tsx": "catalog:",
"twoslash": "workspace:*",
"twoslash-protocol": "workspace:*"
},
Expand Down
12 changes: 7 additions & 5 deletions packages/twoslash-svelte/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { CodeMapping } from '@volar/language-core'
import type { CompilerOptionDeclaration, CreateTwoslashOptions, HandbookOptions, Range, TwoslashExecuteOptions, TwoslashInstance, TwoslashReturnMeta } from 'twoslash'
import { createRequire } from 'node:module'
import { join } from 'node:path'
import { decode } from '@jridgewell/sourcemap-codec'
import { SourceMap } from '@volar/language-core'
Expand All @@ -21,6 +22,7 @@ export interface CreateTwoslashSvelteOptions extends CreateTwoslashOptions {
* Create a twoslasher instance that add additional support for Svelte
*/
export function createTwoslasher(createOptions: CreateTwoslashSvelteOptions = {}): TwoslashInstance {
const require = createRequire(import.meta.url)
const _twoslasher = _createTwoSlasher(createOptions)

function twoslasher(code: string, extension?: string, options: TwoslashExecuteOptions = {}) {
Expand Down Expand Up @@ -86,15 +88,15 @@ export function createTwoslasher(createOptions: CreateTwoslashSvelteOptions = {}
}
return offsets[offsets.length - 1]?.[0]
}

const svelte2tsxPath = require.resolve('svelte2tsx')
const result = _twoslasher(compiled.code, 'tsx', {
...options,
compilerOptions: {
types: [
join(import.meta.dirname, 'types', 'svelte-jsx'),
join(import.meta.dirname, 'types', 'svelte-jsx-v4'),
join(import.meta.dirname, 'types', 'svelte-shims'),
join(import.meta.dirname, 'types', 'svelte-shims-v4'),
join(svelte2tsxPath, '..', 'svelte-jsx'),
join(svelte2tsxPath, '..', 'svelte-jsx-v4'),
join(svelte2tsxPath, '..', 'svelte-shims'),
join(svelte2tsxPath, '..', 'svelte-shims-v4'),
],
...compilerOptions,
},
Expand Down
5 changes: 1 addition & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 16a7c9b

Please sign in to comment.