-
Notifications
You must be signed in to change notification settings - Fork 18
handle exception when dependencies are not installed #191
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Nuxt dev/build outputs | ||
.output | ||
.data | ||
.nuxt | ||
.nitro | ||
.cache | ||
dist | ||
|
||
# Node dependencies | ||
node_modules | ||
|
||
# Logs | ||
logs | ||
*.log | ||
|
||
# Misc | ||
.DS_Store | ||
.fleet | ||
.idea | ||
|
||
# Local env files | ||
.env | ||
.env.* | ||
!.env.example |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# Nuxt Minimal Starter | ||
|
||
Look at the [Nuxt documentation](https://nuxt.com/docs/getting-started/introduction) to learn more. | ||
|
||
## Setup | ||
|
||
Make sure to install dependencies: | ||
|
||
```bash | ||
# npm | ||
npm install | ||
|
||
# pnpm | ||
pnpm install | ||
|
||
# yarn | ||
yarn install | ||
|
||
# bun | ||
bun install | ||
``` | ||
|
||
## Development Server | ||
|
||
Start the development server on `http://localhost:3000`: | ||
|
||
```bash | ||
# npm | ||
npm run dev | ||
|
||
# pnpm | ||
pnpm dev | ||
|
||
# yarn | ||
yarn dev | ||
|
||
# bun | ||
bun run dev | ||
``` | ||
|
||
## Production | ||
|
||
Build the application for production: | ||
|
||
```bash | ||
# npm | ||
npm run build | ||
|
||
# pnpm | ||
pnpm build | ||
|
||
# yarn | ||
yarn build | ||
|
||
# bun | ||
bun run build | ||
``` | ||
|
||
Locally preview production build: | ||
|
||
```bash | ||
# npm | ||
npm run preview | ||
|
||
# pnpm | ||
pnpm preview | ||
|
||
# yarn | ||
yarn preview | ||
|
||
# bun | ||
bun run preview | ||
``` | ||
|
||
Check out the [deployment documentation](https://nuxt.com/docs/getting-started/deployment) for more information. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<template> | ||
<div> | ||
<NuxtRouteAnnouncer /> | ||
<NuxtWelcome /> | ||
</div> | ||
</template> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// https://nuxt.com/docs/api/configuration/nuxt-config | ||
export default defineNuxtConfig({ | ||
compatibilityDate: '2024-11-01', | ||
devtools: { enabled: true }, | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"name": "nuxt-app", | ||
"private": true, | ||
"type": "module", | ||
"scripts": { | ||
"build": "nuxt build", | ||
"dev": "nuxt dev", | ||
"generate": "nuxt generate", | ||
"preview": "nuxt preview", | ||
"postinstall": "nuxt prepare" | ||
}, | ||
"dependencies": { | ||
"nuxt": "^3.16.2", | ||
"vue": "^3.5.13", | ||
"vue-router": "^4.5.0" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
User-Agent: * | ||
Disallow: |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"extends": "../.nuxt/tsconfig.server.json" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
// https://nuxt.com/docs/guide/concepts/typescript | ||
"extends": "./.nuxt/tsconfig.json" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { readFileSync } from 'fs' | ||
import { join } from 'path' | ||
import { TSConfckParseError } from 'tsconfck' | ||
import { Folder } from '@steiger/types' | ||
|
||
interface ErrorContext { | ||
vfs: Folder | ||
} | ||
|
||
interface PackageJson { | ||
dependencies?: Record<string, string> | ||
devDependencies?: Record<string, string> | ||
} | ||
|
||
const readPackageJSON = (path: string) => JSON.parse(readFileSync(join(path, 'package.json'), 'utf-8')) as PackageJson | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue: it might be the case that suggestion: let's use
|
||
|
||
async function checkNuxtConfigError(error: unknown, { vfs }: ErrorContext) { | ||
if (!(error instanceof TSConfckParseError)) return false | ||
if (error.code !== 'EXTENDS_RESOLVE') return false | ||
if (!error.cause?.message?.includes('.nuxt/tsconfig')) return false | ||
|
||
try { | ||
const projectRootPath = vfs.path | ||
const packageJson = readPackageJSON(projectRootPath) | ||
const hasNuxt = !!(packageJson.dependencies?.nuxt || packageJson.devDependencies?.nuxt) | ||
if (!hasNuxt) return false | ||
|
||
console.error('\n\x1b[31mError: Unable to find Nuxt TypeScript configuration\x1b[0m') | ||
console.error('\nThis appears to be a Nuxt project, but the TypeScript configuration files are missing.') | ||
console.error('These files are auto-generated when you install dependencies.') | ||
console.error('\nTo fix this:') | ||
console.error('1. Run \x1b[36mnpm install\x1b[0m or \x1b[36myarn\x1b[0m or \x1b[36mpnpm install\x1b[0m') | ||
console.error('2. Then run Steiger again\n') | ||
Comment on lines
+28
to
+33
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: we have |
||
return true | ||
} catch { | ||
return false | ||
} | ||
} | ||
|
||
export function handleError(error: unknown, context: ErrorContext): never { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue: it takes a bit of code reading to understand what this function does, especially since its return type is suggestion: let's add a docstring that explains that this function attempts to gracefully handle the error using one of the known error checkers, and rethrows it if it can't |
||
const isHandled = [checkNuxtConfigError].some((checker) => checker(error, context)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. praise: interesting architecture! I'm not sure how many more of those there will be, but thanks for building with extensibility in mind :) |
||
|
||
if (isHandled) { | ||
process.exit(1) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue: not a big fan of handling process exits from within the code of the linter app. This is more the responsibility of the CLI — to print the error message and exit with an error code suggestion: maybe we can redo this function to instead throw a known error, and also export a separate function that would handle the error message printing? The way I see it working is like this:
In this solution, I think it would also make sense to make |
||
} | ||
|
||
throw error | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: let's remove this and some other unnecessary template files:
README.md
,robots.txt