Unverified Commit 62f0d467 authored by Sebastian "Sebbie" Silbermann's avatar Sebastian "Sebbie" Silbermann Committed by GitHub

Only log partytown setup error once (#93378)

parent acb41ed6
...@@ -56,7 +56,6 @@ fn is_error_class_name(name: &str) -> bool { ...@@ -56,7 +56,6 @@ fn is_error_class_name(name: &str) -> bool {
|| name == "DecodeError" || name == "DecodeError"
|| name == "DynamicServerError" || name == "DynamicServerError"
|| name == "ExportError" || name == "ExportError"
|| name == "FatalError"
|| name == "ImageError" || name == "ImageError"
|| name == "InstantValidationError" || name == "InstantValidationError"
|| name == "InvariantError" || name == "InvariantError"
......
export class FatalError extends Error {}
...@@ -3,7 +3,6 @@ import os from 'os' ...@@ -3,7 +3,6 @@ import os from 'os'
import path from 'path' import path from 'path'
import semver from 'next/dist/compiled/semver' import semver from 'next/dist/compiled/semver'
import { FatalError } from '../fatal-error'
import isError from '../is-error' import isError from '../is-error'
function resolvePathAliasTarget(baseUrl: string, target: string): string { function resolvePathAliasTarget(baseUrl: string, target: string): string {
...@@ -92,9 +91,7 @@ export async function getTypeScriptConfiguration( ...@@ -92,9 +91,7 @@ export async function getTypeScriptConfiguration(
typescript.sys.readFile typescript.sys.readFile
) )
if (error) { if (error) {
throw new FatalError( throw new Error(typescript.formatDiagnostic(error, formatDiagnosticsHost))
typescript.formatDiagnostic(error, formatDiagnosticsHost)
)
} }
let configToParse: any = config let configToParse: any = config
...@@ -185,7 +182,8 @@ export async function getTypeScriptConfiguration( ...@@ -185,7 +182,8 @@ export async function getTypeScriptConfiguration(
} }
if (result.errors?.length) { if (result.errors?.length) {
throw new FatalError( // TODO: Throw AggregateError for all diagnostics.
throw new Error(
typescript.formatDiagnostic(result.errors[0], formatDiagnosticsHost) typescript.formatDiagnostic(result.errors[0], formatDiagnosticsHost)
) )
} }
...@@ -194,7 +192,7 @@ export async function getTypeScriptConfiguration( ...@@ -194,7 +192,7 @@ export async function getTypeScriptConfiguration(
} catch (err) { } catch (err) {
if (isError(err) && err.name === 'SyntaxError') { if (isError(err) && err.name === 'SyntaxError') {
const reason = '\n' + (err.message ?? '') const reason = '\n' + (err.message ?? '')
throw new FatalError( throw new Error(
bold( bold(
'Could not parse' + 'Could not parse' +
cyan('tsconfig.json') + cyan('tsconfig.json') +
......
...@@ -2,7 +2,6 @@ import { bold, cyan, red } from '../picocolors' ...@@ -2,7 +2,6 @@ import { bold, cyan, red } from '../picocolors'
import { getOxfordCommaList } from '../oxford-comma-list' import { getOxfordCommaList } from '../oxford-comma-list'
import type { MissingDependency } from '../has-necessary-dependencies' import type { MissingDependency } from '../has-necessary-dependencies'
import { FatalError } from '../fatal-error'
import { getPkgManager } from '../helpers/get-pkg-manager' import { getPkgManager } from '../helpers/get-pkg-manager'
export function missingDepsError( export function missingDepsError(
...@@ -21,7 +20,7 @@ export function missingDepsError( ...@@ -21,7 +20,7 @@ export function missingDepsError(
' file from your package root (and any TypeScript files in your app and pages directories).' ' file from your package root (and any TypeScript files in your app and pages directories).'
) )
throw new FatalError( throw new Error(
bold( bold(
red( red(
`It looks like you're trying to use TypeScript but do not have the required package(s) installed.` `It looks like you're trying to use TypeScript but do not have the required package(s) installed.`
......
...@@ -5,14 +5,13 @@ import path from 'path' ...@@ -5,14 +5,13 @@ import path from 'path'
import { hasNecessaryDependencies } from './has-necessary-dependencies' import { hasNecessaryDependencies } from './has-necessary-dependencies'
import type { NecessaryDependencies } from './has-necessary-dependencies' import type { NecessaryDependencies } from './has-necessary-dependencies'
import { fileExists, FileType } from './file-exists' import { fileExists, FileType } from './file-exists'
import { FatalError } from './fatal-error'
import * as Log from '../build/output/log' import * as Log from '../build/output/log'
import { getPkgManager } from './helpers/get-pkg-manager' import { getPkgManager } from './helpers/get-pkg-manager'
async function missingDependencyError(dir: string) { async function missingDependencyError(dir: string) {
const packageManager = getPkgManager(dir) const packageManager = getPkgManager(dir)
throw new FatalError( throw new Error(
bold( bold(
red( red(
"It looks like you're trying to use Partytown with next/script but do not have the required package(s) installed." "It looks like you're trying to use Partytown with next/script but do not have the required package(s) installed."
...@@ -65,35 +64,25 @@ export async function verifyPartytownSetup( ...@@ -65,35 +64,25 @@ export async function verifyPartytownSetup(
dir: string, dir: string,
targetDir: string targetDir: string
): Promise<void> { ): Promise<void> {
try { const partytownDeps: NecessaryDependencies = hasNecessaryDependencies(dir, [
const partytownDeps: NecessaryDependencies = hasNecessaryDependencies(dir, [ {
{ file: '@builder.io/partytown',
file: '@builder.io/partytown', pkg: '@builder.io/partytown',
pkg: '@builder.io/partytown', exportsRestrict: false,
exportsRestrict: false, },
}, ])
])
if (partytownDeps.missing?.length > 0) { if (partytownDeps.missing?.length > 0) {
await missingDependencyError(dir) await missingDependencyError(dir)
} else { } else {
try { try {
await copyPartytownStaticFiles(partytownDeps, targetDir) await copyPartytownStaticFiles(partytownDeps, targetDir)
} catch (err) { } catch (err) {
Log.warn( Log.warn(
`Partytown library files could not be copied to the static directory. Please ensure that ${bold( `Partytown library files could not be copied to the static directory. Please ensure that ${bold(
cyan('@builder.io/partytown') cyan('@builder.io/partytown')
)} is installed as a dependency.` )} is installed as a dependency.`
) )
}
}
} catch (err) {
// Don't show a stack trace when there is an error due to missing dependencies
if (err instanceof FatalError) {
console.error(err.message)
// Throw to allow finally blocks to run (e.g., telemetry flush)
throw err
} }
throw err
} }
} }
...@@ -243,7 +243,6 @@ async function readNormalizedNFT(next, name) { ...@@ -243,7 +243,6 @@ async function readNormalizedNFT(next, name) {
"/node_modules/next/dist/lib/download-swc.js", "/node_modules/next/dist/lib/download-swc.js",
"/node_modules/next/dist/lib/error-telemetry-utils.js", "/node_modules/next/dist/lib/error-telemetry-utils.js",
"/node_modules/next/dist/lib/fallback.js", "/node_modules/next/dist/lib/fallback.js",
"/node_modules/next/dist/lib/fatal-error.js",
"/node_modules/next/dist/lib/file-exists.js", "/node_modules/next/dist/lib/file-exists.js",
"/node_modules/next/dist/lib/find-config.js", "/node_modules/next/dist/lib/find-config.js",
"/node_modules/next/dist/lib/find-pages-dir.js", "/node_modules/next/dist/lib/find-pages-dir.js",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment