diff --git a/index.ts b/index.ts new file mode 100644 index 0000000..816c8be --- /dev/null +++ b/index.ts @@ -0,0 +1,12 @@ +/* + * youch + * + * (c) Poppinss + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +export { Youch } from './src/youch.js' +export { Metadata } from './src/metadata.js' +export { BaseComponent } from './src/component.js' diff --git a/package.json b/package.json index a82c882..4c7962d 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "youch", - "description": "", - "version": "", + "description": "Pretty print JavaScript errors on the Web and the Terminal", + "version": "3.3.4", "engines": { "node": ">=20.6.0" }, @@ -9,11 +9,14 @@ "files": [ "build", "!build/bin", + "!build/example", "!build/tests" ], "main": "build/index.js", "exports": { - ".": "./build/index.js" + ".": "./build/index.js", + "./types": "./build/src/types.js", + "./templates/*": "./build/templates/*" }, "scripts": { "pretest": "npm run lint", @@ -22,8 +25,9 @@ "format": "prettier --write .", "typecheck": "tsc --noEmit", "precompile": "npm run lint", + "copy:assets": "copyfiles --up=1 src/public/**/* build", "compile": "tsup-node && tsc --emitDeclarationOnly --declaration", - "build": "npm run compile", + "build": "npm run compile && npm run copy:assets", "version": "npm run build", "prepublishOnly": "npm run build", "release": "release-it", @@ -50,6 +54,7 @@ "axios": "^1.7.7", "c8": "^10.1.2", "cookie": "^1.0.1", + "copyfiles": "^2.4.1", "eslint": "^9.14.0", "flydrive": "^1.1.0", "jsdom": "^25.0.1", @@ -77,13 +82,15 @@ }, "tsup": { "entry": [ - "index.ts" + "index.ts", + "src/types.ts", + "src/templates/**/*.ts" ], "outDir": "./build", "clean": true, "format": "esm", "dts": false, - "sourcemap": true, + "sourcemap": false, "target": "esnext" }, "release-it": { diff --git a/src/templates/error-cause/style.css b/src/public/error_cause/style.css similarity index 100% rename from src/templates/error-cause/style.css rename to src/public/error_cause/style.css diff --git a/src/templates/error-info/style.css b/src/public/error_info/style.css similarity index 100% rename from src/templates/error-info/style.css rename to src/public/error_info/style.css diff --git a/src/templates/error-stack/script.js b/src/public/error_stack/script.js similarity index 100% rename from src/templates/error-stack/script.js rename to src/public/error_stack/script.js diff --git a/src/templates/error-stack/style.css b/src/public/error_stack/style.css similarity index 100% rename from src/templates/error-stack/style.css rename to src/public/error_stack/style.css diff --git a/src/templates/error-stack-source/style.css b/src/public/error_stack_source/style.css similarity index 100% rename from src/templates/error-stack-source/style.css rename to src/public/error_stack_source/style.css diff --git a/src/templates/header/script.js b/src/public/header/script.js similarity index 100% rename from src/templates/header/script.js rename to src/public/header/script.js diff --git a/src/templates/header/style.css b/src/public/header/style.css similarity index 100% rename from src/templates/header/style.css rename to src/public/header/style.css diff --git a/src/templates/layout/script.js b/src/public/layout/script.js similarity index 100% rename from src/templates/layout/script.js rename to src/public/layout/script.js diff --git a/src/templates/layout/style.css b/src/public/layout/style.css similarity index 100% rename from src/templates/layout/style.css rename to src/public/layout/style.css diff --git a/src/public_dir.ts b/src/public_dir.ts new file mode 100644 index 0000000..a864ad7 --- /dev/null +++ b/src/public_dir.ts @@ -0,0 +1,10 @@ +/* + * youch + * + * (c) Poppinss + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +export const publicDirURL = new URL('./public/', import.meta.url) diff --git a/src/templates.ts b/src/templates.ts index efc8c1d..f39964b 100644 --- a/src/templates.ts +++ b/src/templates.ts @@ -12,35 +12,14 @@ import { createScript, createStyleSheet } from '@poppinss/dumper/html' import { Metadata } from './metadata.js' import { BaseComponent } from './component.js' +import type { YouchTemplates } from './types.js' import { Header } from './templates/header/main.js' import { Layout } from './templates/layout/main.js' -import { ErrorInfo } from './templates/error-info/main.js' -import { ErrorCause } from './templates/error-cause/main.js' -import { ErrorStack } from './templates/error-stack/main.js' +import { ErrorInfo } from './templates/error_info/main.js' +import { ErrorCause } from './templates/error_cause/main.js' +import { ErrorStack } from './templates/error_stack/main.js' import { ErrorMetadata } from './templates/error_metadata/main.js' -import { ErrorStackSource } from './templates/error-stack-source/main.js' -import type { - LayoutProps, - ErrorInfoProps, - ErrorCauseProps, - ErrorStackProps, - ErrorMetadataProps, - ErrorStackSourceProps, -} from './types.js' - -/** - * Collection of known templates. Only these templates can be - * rendered using the Templates collection - */ -export type KnownTemplates = { - header: BaseComponent - layout: BaseComponent - errorInfo: BaseComponent - errorStack: BaseComponent - errorStackSource: BaseComponent - errorCause: BaseComponent - errorMetadata: BaseComponent -} +import { ErrorStackSource } from './templates/error_stack_source/main.js' /** * A super lightweight templates collection that allows composing @@ -66,7 +45,7 @@ export type KnownTemplates = { * ``` */ export class Templates { - #knownTemplates: KnownTemplates + #knownTemplates: YouchTemplates #styles: Map = new Map([['global', createStyleSheet()]]) #scripts: Map = new Map([['global', createScript()]]) @@ -114,7 +93,7 @@ export class Templates { * Collects styles and scripts for components as we render * them. */ - async #collectStylesAndScripts(templateName: keyof KnownTemplates) { + async #collectStylesAndScripts(templateName: keyof YouchTemplates) { /** * Collect styles only once for a given template */ @@ -139,9 +118,9 @@ export class Templates { /** * Renders a known template by its name */ - async #renderTmpl( + async #renderTmpl( templateName: K, - props: KnownTemplates[K]['$props'] + props: YouchTemplates[K]['$props'] ): Promise { const component: BaseComponent = this.#knownTemplates[templateName] if (!component) { @@ -157,7 +136,7 @@ export class Templates { * Overriding components allows you control the HTML layout, styles and * the frontend scripts of an HTML fragment. */ - use(templateName: K, component: KnownTemplates[K]): this { + use(templateName: K, component: YouchTemplates[K]): this { this.#knownTemplates[templateName] = component return this } diff --git a/src/templates/error-cause/main.ts b/src/templates/error_cause/main.ts similarity index 89% rename from src/templates/error-cause/main.ts rename to src/templates/error_cause/main.ts index 2fbb418..acd00c7 100644 --- a/src/templates/error-cause/main.ts +++ b/src/templates/error_cause/main.ts @@ -10,13 +10,14 @@ import { dump, themes } from '@poppinss/dumper/html' import { BaseComponent } from '../../component.js' +import { publicDirURL } from '../../public_dir.js' import type { ErrorCauseProps } from '../../types.js' /** * Displays the Error cause as a formatted value */ export class ErrorCause extends BaseComponent { - cssFile = new URL('./style.css', import.meta.url) + cssFile = new URL('./error_cause/style.css', publicDirURL) async render(props: ErrorCause['$props']): Promise { if (!props.error.cause) { diff --git a/src/templates/error-info/main.ts b/src/templates/error_info/main.ts similarity index 94% rename from src/templates/error-info/main.ts rename to src/templates/error_info/main.ts index e291aa1..430f9a6 100644 --- a/src/templates/error-info/main.ts +++ b/src/templates/error_info/main.ts @@ -8,6 +8,7 @@ */ import { BaseComponent } from '../../component.js' +import { publicDirURL } from '../../public_dir.js' import type { ErrorInfoProps } from '../../types.js' const ERROR_ICON_SVG = `` @@ -19,7 +20,7 @@ const HINT_ICON_SVG = `` @@ -18,8 +19,8 @@ const LIGHT_MODE_SVG = ` diff --git a/src/templates/layout/main.ts b/src/templates/layout/main.ts index b5fa2a0..28df4e7 100644 --- a/src/templates/layout/main.ts +++ b/src/templates/layout/main.ts @@ -8,6 +8,7 @@ */ import { BaseComponent } from '../../component.js' +import { publicDirURL } from '../../public_dir.js' import type { LayoutProps } from '../../types.js' /** @@ -18,8 +19,8 @@ import type { LayoutProps } from '../../types.js' * structure or the CSS variables for the colors. */ export class Layout extends BaseComponent { - cssFile = new URL('./style.css', import.meta.url) - scriptFile = new URL('./script.js', import.meta.url) + cssFile = new URL('./layout/style.css', publicDirURL) + scriptFile = new URL('./layout/script.js', publicDirURL) async render(props: LayoutProps): Promise { return ` diff --git a/src/types.ts b/src/types.ts index cb1d1ed..55ab1cf 100644 --- a/src/types.ts +++ b/src/types.ts @@ -9,6 +9,7 @@ import type { ParsedError, StackFrame } from 'youch-core/types' import type { Metadata } from './metadata.js' +import type { BaseComponent } from './component.js' export * from 'youch-core/types' @@ -119,3 +120,17 @@ export type YouchOptions = { */ ide?: string } + +/** + * Collection of known templates. Only these templates can be + * rendered using the Templates collection + */ +export type YouchTemplates = { + header: BaseComponent + layout: BaseComponent + errorInfo: BaseComponent + errorStack: BaseComponent + errorStackSource: BaseComponent + errorCause: BaseComponent + errorMetadata: BaseComponent +}