Skip to content

Commit

Permalink
fix: oxc-parser wasm issue (#484)
Browse files Browse the repository at this point in the history
  • Loading branch information
Saeid-Za authored Apr 13, 2024
1 parent f51a8da commit 798aa0e
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 83 deletions.
2 changes: 1 addition & 1 deletion apps/www/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"@iconify-json/simple-icons": "^1.1.94",
"@iconify-json/tabler": "^1.1.106",
"@iconify/vue": "^4.1.1",
"@oxc-parser/wasm": "^0.1.0",
"@shikijs/transformers": "^1.3.0",
"@types/lodash.template": "^4.5.3",
"@types/node": "^20.12.7",
Expand All @@ -60,7 +61,6 @@
"@vue/tsconfig": "^0.5.1",
"autoprefixer": "^10.4.19",
"lodash.template": "^4.5.0",
"oxc-parser": "^0.8.0",
"pathe": "^1.1.2",
"rimraf": "^5.0.5",
"shiki": "^1.3.0",
Expand Down
6 changes: 3 additions & 3 deletions apps/www/src/lib/registry/registry.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { readFile, readdir } from 'node:fs/promises'
import { join, normalize, resolve } from 'pathe'
import { compileScript, parse } from 'vue/compiler-sfc'
import oxc from 'oxc-parser'
import { parseSync } from '@oxc-parser/wasm'

import type { Registry } from '../../lib/registry'

Expand Down Expand Up @@ -162,12 +162,12 @@ async function getDependencies(filename: string) {
}

if (filename.endsWith('.ts')) {
const ast = oxc.parseSync(code, {
const ast = parseSync(code, {
sourceType: 'module',
sourceFilename: filename,
})

const sources = JSON.parse(ast.program).body.filter((i: any) => i.type === 'ImportDeclaration').map((i: any) => i.source)
const sources = ast.program.body.filter((i: any) => i.type === 'ImportDeclaration').map((i: any) => i.source)
sources.forEach((source: any) => {
populateDeps(source.value)
})
Expand Down
2 changes: 1 addition & 1 deletion packages/module/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
},
"dependencies": {
"@nuxt/kit": "^3.11.2",
"oxc-parser": "^0.8.0"
"@oxc-parser/wasm": "^0.1.0"
},
"devDependencies": {
"@nuxt/devtools": "latest",
Expand Down
8 changes: 3 additions & 5 deletions packages/module/src/module.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { readFileSync, readdirSync } from 'node:fs'
import { join } from 'node:path'
import { addComponent, createResolver, defineNuxtModule } from '@nuxt/kit'
import oxc from 'oxc-parser'
import { parseSync } from '@oxc-parser/wasm'

// TODO: add test to make sure all registry is being parse correctly
// Module options TypeScript interface definition
Expand Down Expand Up @@ -44,14 +44,12 @@ export default defineNuxtModule<ModuleOptions>({
try {
const filePath = await resolvePath(join(COMPONENT_DIR_PATH, dir, 'index'), { extensions: ['.ts', '.js'] })
const content = readFileSync(filePath, { encoding: 'utf8' })
const ast = oxc.parseSync(content, {
const ast = parseSync(content, {
sourceType: 'module',
sourceFilename: filePath,
})
const program = JSON.parse(ast.program)

const exportedKeys: string[] = program.body
// @ts-expect-error parse return any
const exportedKeys: string[] = ast.program.body
.filter(node => node.type === 'ExportNamedDeclaration')
// @ts-expect-error parse return any
.flatMap(node => node.specifiers.map(specifier => specifier.exported.name))
Expand Down
81 changes: 8 additions & 73 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 798aa0e

Please sign in to comment.