Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove nuxi dependency and prompt to install when needed #907

Merged
merged 7 commits into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions packages/bridge/bin/nuxt.mjs

This file was deleted.

6 changes: 6 additions & 0 deletions packages/bridge/bin/nuxt2.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env node
require('@nuxt/cli').run()
.catch((error) => {
require('consola').fatal(error)
require('exit')(2)
})
5 changes: 3 additions & 2 deletions packages/bridge/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"dist"
],
"bin": {
"nuxi": "./bin/nuxt.mjs"
"nuxt2": "./bin/nuxt2.cjs"
},
"scripts": {
"build": "pnpm prepack",
Expand Down Expand Up @@ -51,11 +51,12 @@
"mlly": "^1.4.2",
"nitropack": "^2.6.3",
"node-fetch": "^3.3.2",
"nuxi": "3.8.3",
"nypm": "^0.3.3",
"ofetch": "^1.3.3",
"ohash": "^1.1.3",
"pathe": "^1.1.1",
"perfect-debounce": "^1.0.0",
"pkg-types": "^1.0.3",
"postcss": "^8.4.29",
"postcss-import": "^15.1.0",
"postcss-import-resolver": "^2.0.0",
Expand Down
42 changes: 42 additions & 0 deletions packages/bridge/src/features.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { addDependency } from 'nypm'
import { resolvePackageJSON } from 'pkg-types'
import { logger } from '@nuxt/kit'
import { isCI } from 'std-env'

export async function ensurePackageInstalled (
rootDir: string,
name: string,
searchPaths?: string[]
) {
if (await resolvePackageJSON(name, { url: searchPaths }).catch(() => null)) {
return true
}

logger.info(`Package ${name} is missing`)
if (isCI) {
return false
}

const confirm = await logger.prompt(`Do you want to install ${name} package?`, {
type: 'confirm',
name: 'confirm',
initial: true
})

if (!confirm) {
return false
}

logger.info(`Installing ${name}...`)
try {
await addDependency(name, {
cwd: rootDir,
dev: true
})
logger.success(`Installed ${name}`)
return true
} catch (err) {
logger.error(err)
return false
}
}
3 changes: 3 additions & 0 deletions packages/bridge/src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ export default defineNuxtModule({
}

if (opts.nitro) {
if (!await import('./features').then(r => r.ensurePackageInstalled(nuxt.options.rootDir, 'nuxi', nuxt.options.modulesDir))) {
logger.warn('Failed to install `nuxi`, please install it manually, or change the `nitro` option to false in `nuxt.config`')
}
// @ts-ignore router.base is legacy
nuxt.options.router.base = nuxt.options.app.baseURL || '/'

Expand Down
1 change: 1 addition & 0 deletions playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
},
"devDependencies": {
"@nuxt/bridge": "latest",
"nuxi": "3.7.3",
"nuxt": "^2.17.1"
}
}
71 changes: 59 additions & 12 deletions pnpm-lock.yaml

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

Loading