Skip to content
This repository has been archived by the owner on Dec 5, 2024. It is now read-only.

Commit

Permalink
fix: prevent resolution errors on old node versions
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Mar 23, 2021
1 parent 1a50387 commit df3e2fd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
5 changes: 2 additions & 3 deletions src/module/babel.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { NuxtOptions } from '@nuxt/types'
import type { ModuleThis } from '@nuxt/types/config/module'
import { resolveRelativePath } from './utils'

export function registerBabelPlugin(this: ModuleThis) {
const nuxtOptions: NuxtOptions = this.nuxt.options
Expand All @@ -16,9 +17,7 @@ export function registerBabelPlugin(this: ModuleThis) {
'Unable to automatically add Babel plugin. Make sure your custom `build.babel.plugins` returns `@nuxtjs/composition-api/babel`'
)
} else {
nuxtOptions.build.babel.plugins.push(
require.resolve('@nuxtjs/composition-api/babel')
)
nuxtOptions.build.babel.plugins.push(resolveRelativePath('babel'))
}

/**
Expand Down
14 changes: 13 additions & 1 deletion src/module/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,26 @@ export function isUrl(url: string) {
return ['http', '//'].some(str => url.startsWith(str))
}

export function resolveRelativePath(id: string) {
let src

try {
src = require.resolve(`@nuxtjs/composition-api/${id}`)
} catch {
src = require.resolve(join(__dirname, `./${id}`))
}

return src
}

export function addResolvedTemplate(
this: ModuleThis,
template: string,
options: Record<string, any> = {}
) {
const nuxtOptions: NuxtOptions = this.nuxt.options

const src = require.resolve(`@nuxtjs/composition-api/${template}`)
const src = resolveRelativePath(template)
const { dst } = this.addTemplate({
src,
fileName: join('composition-api', basename(src)),
Expand Down

0 comments on commit df3e2fd

Please sign in to comment.