Skip to content

Commit

Permalink
feat: do some very dodgy things to improve dx
Browse files Browse the repository at this point in the history
actually closes #334 this time
  • Loading branch information
danielroe committed Feb 12, 2021
1 parent 2157afc commit 0998d66
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
import { resolve, join } from 'upath'
import { readdirSync, copyFileSync, existsSync, mkdirpSync } from 'fs-extra'

import { withTrailingSlash } from 'ufo'

import type { Module } from '@nuxt/types'

const foolWebpack = (id: string) => require(id)

const loadUtils = () => {
try {
// Try to load nuxt edge utils first
return require('@nuxt/utils-edge')
return foolWebpack('@nuxt/utils-edge')
} catch {
// if it fails, fall back to normal nuxt utils
return require('@nuxt/utils')
return foolWebpack('@nuxt/utils')
}
}

const utils = loadUtils()

const isUrl = function isUrl(url: string) {
return ['http', '//'].some(str => url.startsWith(str))
}

const compositionApiModule: Module<any> = function compositionApiModule() {
const utils = loadUtils()
const { readdirSync, copyFileSync, existsSync, mkdirpSync } = foolWebpack(
'fs-extra'
) as typeof import('fs-extra')

let corejsPolyfill = this.nuxt.options.build.corejs
? String(this.nuxt.options.build.corejs)
: undefined
Expand Down Expand Up @@ -158,3 +161,19 @@ export default compositionApiModule
// eslint-disable-next-line
// @ts-ignore
compositionApiModule.meta = require('../package.json')

const warnToAddModule = () => {
console.error(
'You need to add `@nuxtjs/composition-api` to your buildModules in order to use it. See https://composition-api.nuxtjs.org/getting-started/setup.'
)
throw new Error(
'You need to add `@nuxtjs/composition-api` to your buildModules in order to use it. See https://composition-api.nuxtjs.org/getting-started/setup.'
)
}

// eslint-disable-next-line
Object.keys(require('./entrypoint')).forEach(helper => {
// eslint-disable-next-line
// @ts-ignore
compositionApiModule[helper] = warnToAddModule
})

1 comment on commit 0998d66

@vercel
Copy link

@vercel vercel bot commented on 0998d66 Feb 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.