From faefab9e5d2ed3bf487581f20502720b171b8e1a Mon Sep 17 00:00:00 2001 From: Yan <61414485+yanthomasdev@users.noreply.github.com> Date: Sun, 8 Sep 2024 21:42:56 -0300 Subject: [PATCH] Fix publish workflow and Biome check issues --- .changeset/config.json | 5 +- .github/workflows/publish-preview.yml | 4 +- biome.json | 100 +++++++++--------- docs/astro.config.mjs | 2 +- docs/src/components/ShowcaseCard.astro | 4 +- docs/src/components/ShowcaseSites.astro | 2 +- docs/src/content/config.ts | 2 +- examples/nextra/theme.config.tsx | 2 +- package.json | 3 +- packages/core/src/config/config.ts | 6 +- packages/core/src/errors/index.ts | 2 +- packages/core/src/errors/zod-map.ts | 63 +++++------ packages/core/src/files/paths.ts | 6 +- packages/core/src/index.ts | 16 +-- packages/core/src/status/git.ts | 4 +- packages/core/src/status/status.ts | 6 +- .../core/tests/unit/config-validation.test.ts | 2 +- .../core/tests/unit/path-resolver.test.ts | 2 +- packages/starlight/src/cache.ts | 4 +- .../starlight/src/components/Dashboard.astro | 2 +- packages/starlight/src/index.ts | 12 +-- turbo.json | 35 +++--- 22 files changed, 132 insertions(+), 152 deletions(-) diff --git a/.changeset/config.json b/.changeset/config.json index 27e21a7..501908b 100644 --- a/.changeset/config.json +++ b/.changeset/config.json @@ -1,9 +1,6 @@ { "$schema": "https://unpkg.com/@changesets/config@2.3.1/schema.json", - "changelog": [ - "@changesets/changelog-github", - { "repo": "yanthomasdev/lunaria" } - ], + "changelog": ["@changesets/changelog-github", { "repo": "yanthomasdev/lunaria" }], "commit": false, "fixed": [], diff --git a/.github/workflows/publish-preview.yml b/.github/workflows/publish-preview.yml index 8fbbab3..b30021f 100644 --- a/.github/workflows/publish-preview.yml +++ b/.github/workflows/publish-preview.yml @@ -31,6 +31,6 @@ jobs: run: pnpm i - name: Build Packages - run: pnpm run build + run: pnpm run build:core - - run: pnpx pkg-pr-new publish --compact './packages/*' \ No newline at end of file + - run: pnpx pkg-pr-new publish --compact './packages/core' \ No newline at end of file diff --git a/biome.json b/biome.json index d396241..b62f8d5 100644 --- a/biome.json +++ b/biome.json @@ -1,51 +1,53 @@ { - "$schema": "https://biomejs.dev/schemas/1.8.3/schema.json", - "organizeImports": { - "enabled": true - }, - "formatter": { - "indentStyle": "tab", - "indentWidth": 2, - "lineWidth": 100, - "formatWithErrors": true - }, - "linter": { - "enabled": true, - "rules": { - "recommended": true, - "style": { - "useNodejsImportProtocol": "error" - } - } - }, - "javascript": { - "formatter": { - "trailingCommas": "all", - "quoteStyle": "single", - "semicolons": "always" - } - }, - "json": { - "parser": { - "allowComments": true, - "allowTrailingCommas": true - }, - "formatter": { - "trailingCommas": "none" - } - },"vcs": { - "clientKind": "git", - "enabled": true, - "useIgnoreFile": true - }, - "overrides": [ - { - "include": ["package.json"], - "json": { - "formatter": { - "lineWidth": 1 - } - } - } - ] + "$schema": "https://biomejs.dev/schemas/1.8.3/schema.json", + "organizeImports": { + "enabled": true + }, + "formatter": { + "indentStyle": "tab", + "indentWidth": 2, + "lineWidth": 100, + "formatWithErrors": true + }, + "linter": { + "enabled": true, + "rules": { + "recommended": true, + "style": { + "useNodejsImportProtocol": "error" + } + } + }, + "javascript": { + "formatter": { + "trailingCommas": "all", + "quoteStyle": "single", + "semicolons": "always" + } + }, + "json": { + "parser": { + "allowComments": true, + "allowTrailingCommas": true + }, + "formatter": { + "indentStyle": "space", + "trailingCommas": "none" + } + }, + "vcs": { + "clientKind": "git", + "enabled": true, + "useIgnoreFile": true + }, + "overrides": [ + { + "include": ["package.json"], + "json": { + "formatter": { + "lineWidth": 1 + } + } + } + ] } diff --git a/docs/astro.config.mjs b/docs/astro.config.mjs index 6fb2e77..1a11465 100644 --- a/docs/astro.config.mjs +++ b/docs/astro.config.mjs @@ -1,7 +1,7 @@ import starlight from '@astrojs/starlight'; import { defineConfig } from 'astro/config'; -import starlightLinksValidator from 'starlight-links-validator'; import starlightBlog from 'starlight-blog'; +import starlightLinksValidator from 'starlight-links-validator'; const site = 'https://lunaria.dev/'; diff --git a/docs/src/components/ShowcaseCard.astro b/docs/src/components/ShowcaseCard.astro index 849ff44..3a84ff3 100644 --- a/docs/src/components/ShowcaseCard.astro +++ b/docs/src/components/ShowcaseCard.astro @@ -1,6 +1,6 @@ --- -import type { ImageMetadata } from 'astro'; import { Image } from 'astro:assets'; +import type { ImageMetadata } from 'astro'; import MediaCard from './MediaCard.astro'; interface Props { @@ -11,7 +11,7 @@ interface Props { const { href, title } = Astro.props; const thumbnails = import.meta.glob<{ default: ImageMetadata }>( - '../assets/showcase/*{.png,.jpg,.jpeg,.webp,.avif}' + '../assets/showcase/*{.png,.jpg,.jpeg,.webp,.avif}', ); const thumbnail = thumbnails[`../assets/showcase/${Astro.props.thumbnail}`]; if (!thumbnail) { diff --git a/docs/src/components/ShowcaseSites.astro b/docs/src/components/ShowcaseSites.astro index 4d19e80..a82c107 100644 --- a/docs/src/components/ShowcaseSites.astro +++ b/docs/src/components/ShowcaseSites.astro @@ -1,6 +1,6 @@ --- -import Card from './ShowcaseCard.astro'; import FluidGrid from './FluidGrid.astro'; +import Card from './ShowcaseCard.astro'; --- diff --git a/docs/src/content/config.ts b/docs/src/content/config.ts index e4c1f55..cdb83fc 100644 --- a/docs/src/content/config.ts +++ b/docs/src/content/config.ts @@ -1,5 +1,5 @@ -import { docsSchema, i18nSchema } from '@astrojs/starlight/schema'; import { defineCollection } from 'astro:content'; +import { docsSchema, i18nSchema } from '@astrojs/starlight/schema'; import { blogSchema } from 'starlight-blog/schema'; export const collections = { diff --git a/examples/nextra/theme.config.tsx b/examples/nextra/theme.config.tsx index a49f89a..2a78796 100644 --- a/examples/nextra/theme.config.tsx +++ b/examples/nextra/theme.config.tsx @@ -1,4 +1,4 @@ -import { DocsThemeConfig } from 'nextra-theme-docs'; +import type { DocsThemeConfig } from 'nextra-theme-docs'; const config: DocsThemeConfig = { logo: My Project, diff --git a/package.json b/package.json index c32f95a..69f122a 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,8 @@ "license": "MIT", "scripts": { "build": "pnpm turbo build --filter=!lunaria-docs", - "dev": "pnpm turbo dev --filter=!lunaria-docs", + "build:core": "pnpm turbo build --filter=@lunariajs/core", + "dev": "pnpm turbo dev --filter=lunaria-docs", "test": "pnpm turbo test", "docs": "pnpm --filter lunaria-docs dev" }, diff --git a/packages/core/src/config/config.ts b/packages/core/src/config/config.ts index d72acf0..b31e819 100644 --- a/packages/core/src/config/config.ts +++ b/packages/core/src/config/config.ts @@ -1,8 +1,8 @@ -import { ConfigNotFound } from '../errors/errors.js'; -import { LunariaConfigSchema } from './schema.js'; import * as find from 'empathic/find'; -import { moduleLoader } from '../files/loaders.js'; +import { ConfigNotFound } from '../errors/errors.js'; import { parseWithFriendlyErrors } from '../errors/index.js'; +import { moduleLoader } from '../files/loaders.js'; +import { LunariaConfigSchema } from './schema.js'; import type { LunariaConfig, LunariaUserConfig } from './types.js'; // Paths to search for the Lunaria config file, diff --git a/packages/core/src/errors/index.ts b/packages/core/src/errors/index.ts index d800f14..1785fd1 100644 --- a/packages/core/src/errors/index.ts +++ b/packages/core/src/errors/index.ts @@ -1,6 +1,6 @@ import type { z } from 'zod'; -import { errorMap } from './zod-map.js'; import { ConfigValidationError } from './errors.js'; +import { errorMap } from './zod-map.js'; export function parseWithFriendlyErrors( schema: T, diff --git a/packages/core/src/errors/zod-map.ts b/packages/core/src/errors/zod-map.ts index 84d2a64..f4f0295 100644 --- a/packages/core/src/errors/zod-map.ts +++ b/packages/core/src/errors/zod-map.ts @@ -3,10 +3,10 @@ * Source: https://github.com/withastro/starlight/blob/main/packages/starlight/utils/error-map.ts */ -import type { z } from "zod"; +import type { z } from 'zod'; type TypeOrLiteralErrByPathEntry = { - code: "invalid_type" | "invalid_literal"; + code: 'invalid_type' | 'invalid_literal'; received: unknown; expected: unknown[]; }; @@ -14,24 +14,18 @@ type TypeOrLiteralErrByPathEntry = { export const errorMap: z.ZodErrorMap = (baseError, ctx) => { const baseErrorPath = flattenErrorPath(baseError.path); - if (baseError.code === "invalid_union") { + if (baseError.code === 'invalid_union') { // Optimization: Combine type and literal errors for keys that are common across ALL union types // Ex. a union between `{ type: z.literal('universal') }` and `{ type: z.literal('dictionary') }` will // raise a single error when `type` does not match: // > Did not match union. // > key: Expected `'universal' | 'dictionary'`, received 'foo' - const typeOrLiteralErrByPath: Map = - new Map(); + const typeOrLiteralErrByPath: Map = new Map(); for (const unionError of baseError.unionErrors.flatMap((e) => e.errors)) { - if ( - unionError.code === "invalid_type" || - unionError.code === "invalid_literal" - ) { + if (unionError.code === 'invalid_type' || unionError.code === 'invalid_literal') { const flattenedErrorPath = flattenErrorPath(unionError.path); if (typeOrLiteralErrByPath.has(flattenedErrorPath)) { - typeOrLiteralErrByPath - .get(flattenedErrorPath) - ?.expected.push(unionError.expected); + typeOrLiteralErrByPath.get(flattenedErrorPath)?.expected.push(unionError.expected); } else { typeOrLiteralErrByPath.set(flattenedErrorPath, { code: unionError.code, @@ -41,13 +35,11 @@ export const errorMap: z.ZodErrorMap = (baseError, ctx) => { } } } - const messages: string[] = [prefix(baseErrorPath, "Did not match union.")]; + const messages: string[] = [prefix(baseErrorPath, 'Did not match union.')]; const details: string[] = [...typeOrLiteralErrByPath.entries()] // If type or literal error isn't common to ALL union types, // filter it out. Can lead to confusing noise. - .filter( - ([, error]) => error.expected.length === baseError.unionErrors.length, - ) + .filter(([, error]) => error.expected.length === baseError.unionErrors.length) .map(([key, error]) => key === baseErrorPath ? // Avoid printing the key again if it's a base error. @@ -62,39 +54,34 @@ export const errorMap: z.ZodErrorMap = (baseError, ctx) => { for (const issue of unionError.issues) { // If the issue is a nested union error, show the associated error message instead of the // base error message. - if (issue.code === "invalid_union") { + if (issue.code === 'invalid_union') { return errorMap(issue, ctx); } const relativePath = flattenErrorPath(issue.path) - .replace(baseErrorPath, "") - .replace(leadingPeriod, ""); - if ("expected" in issue && typeof issue.expected === "string") { + .replace(baseErrorPath, '') + .replace(leadingPeriod, ''); + if ('expected' in issue && typeof issue.expected === 'string') { expectedShape.push( - relativePath - ? `${relativePath}: ${issue.expected}` - : issue.expected, + relativePath ? `${relativePath}: ${issue.expected}` : issue.expected, ); } else { expectedShape.push(relativePath); } } - expectedShapes.push(`{ ${expectedShape.join("; ")} }`); + expectedShapes.push(`{ ${expectedShape.join('; ')} }`); } if (expectedShapes.length) { - details.push(`> Expected type \`${expectedShapes.join(" | ")}\``); + details.push(`> Expected type \`${expectedShapes.join(' | ')}\``); details.push(`> Received \`${stringify(ctx.data)}\``); } } return { - message: messages.concat(details).join("\n"), + message: messages.concat(details).join('\n'), }; } - if ( - baseError.code === "invalid_literal" || - baseError.code === "invalid_type" - ) { + if (baseError.code === 'invalid_literal' || baseError.code === 'invalid_type') { return { message: prefix( baseErrorPath, @@ -115,31 +102,29 @@ export const errorMap: z.ZodErrorMap = (baseError, ctx) => { }; const getTypeOrLiteralMsg = (error: TypeOrLiteralErrByPathEntry): string => { - if (error.received === "undefined") return "Required"; + if (error.received === 'undefined') return 'Required'; const expectedDeduped = new Set(error.expected); switch (error.code) { - case "invalid_type": + case 'invalid_type': return `Expected type \`${unionExpectedVals(expectedDeduped)}\`, received \`${stringify( error.received, )}\``; - case "invalid_literal": + case 'invalid_literal': return `Expected \`${unionExpectedVals(expectedDeduped)}\`, received \`${stringify( error.received, )}\``; } }; -const prefix = (key: string, msg: string) => - key.length ? `${key}: ${msg}` : msg; +const prefix = (key: string, msg: string) => (key.length ? `${key}: ${msg}` : msg); const unionExpectedVals = (expectedVals: Set) => - [...expectedVals].map((expectedVal) => stringify(expectedVal)).join(" | "); + [...expectedVals].map((expectedVal) => stringify(expectedVal)).join(' | '); -const flattenErrorPath = (errorPath: (string | number)[]) => - errorPath.join("."); +const flattenErrorPath = (errorPath: (string | number)[]) => errorPath.join('.'); /** `JSON.stringify()` a value with spaces around object/array entries. */ const stringify = (val: unknown) => - JSON.stringify(val, null, 1).split(newlinePlusWhitespace).join(" "); + JSON.stringify(val, null, 1).split(newlinePlusWhitespace).join(' '); const newlinePlusWhitespace = /\n\s*/; const leadingPeriod = /^\./; diff --git a/packages/core/src/files/paths.ts b/packages/core/src/files/paths.ts index 1880285..eced866 100644 --- a/packages/core/src/files/paths.ts +++ b/packages/core/src/files/paths.ts @@ -1,7 +1,7 @@ -import { compile, match, type MatchResult } from 'path-to-regexp'; -import { stringFromFormat } from '../utils/utils.js'; -import { InvalidFilesPattern } from '../errors/errors.js'; +import { type MatchResult, compile, match } from 'path-to-regexp'; import type { LunariaConfig, Pattern } from '../config/types.js'; +import { InvalidFilesPattern } from '../errors/errors.js'; +import { stringFromFormat } from '../utils/utils.js'; import type { PathResolver } from './types.js'; /** Returns any missing parameters found for the specified pattern */ diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 69259d6..e3d5689 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -1,15 +1,15 @@ -import { loadConfig, validateConfig } from './config/config.js'; -import { createConsola, type ConsolaInstance } from 'consola'; -import glob from 'fast-glob'; -import { createPathResolver } from './files/paths.js'; -import { FileConfigNotFound } from './errors/errors.js'; import { existsSync } from 'node:fs'; +import { get } from 'node:http'; import { resolve } from 'node:path'; -import { getDictionaryCompletion, isFileLocalizable } from './status/status.js'; -import { LunariaGitInstance } from './status/git.js'; +import { type ConsolaInstance, createConsola } from 'consola'; +import glob from 'fast-glob'; +import { loadConfig, validateConfig } from './config/config.js'; import type { LunariaConfig, Pattern } from './config/types.js'; +import { FileConfigNotFound } from './errors/errors.js'; +import { createPathResolver } from './files/paths.js'; +import { LunariaGitInstance } from './status/git.js'; +import { getDictionaryCompletion, isFileLocalizable } from './status/status.js'; import type { LunariaStatus, StatusLocalizationEntry } from './status/types.js'; -import { get } from 'node:http'; // Additional data to ensure we can force rebuild the cache. // Bump this whenever there are breaking changes to the status output. diff --git a/packages/core/src/status/git.ts b/packages/core/src/status/git.ts index 2bd4360..a4c3f6f 100644 --- a/packages/core/src/status/git.ts +++ b/packages/core/src/status/git.ts @@ -1,10 +1,10 @@ import { cpus } from 'node:os'; import { resolve } from 'node:path'; -import { simpleGit, type DefaultLogFields, type ListLogLine } from 'simple-git'; import type { ConsolaInstance } from 'consola'; -import { FileCommitsNotFound, UncommittedFileFound } from '../errors/errors.js'; import micromatch from 'micromatch'; +import { type DefaultLogFields, type ListLogLine, simpleGit } from 'simple-git'; import type { LunariaConfig } from '../config/types.js'; +import { FileCommitsNotFound, UncommittedFileFound } from '../errors/errors.js'; import type { RegExpGroups } from '../utils/types.js'; export class LunariaGitInstance { diff --git a/packages/core/src/status/status.ts b/packages/core/src/status/status.ts index 66832ce..4a435cc 100644 --- a/packages/core/src/status/status.ts +++ b/packages/core/src/status/status.ts @@ -1,9 +1,9 @@ +import { Traverse } from 'neotraverse/modern'; import type { OptionalKeys } from '../config/types.js'; +import { InvalidDictionaryFormat } from '../errors/errors.js'; import { fileSupportsFrontmatterRe, frontmatterLoader, universalLoader } from '../files/loaders.js'; -import { Traverse } from 'neotraverse/modern'; -import type { Dictionary } from './types.js'; import { DictionarySchema } from './schema.js'; -import { InvalidDictionaryFormat } from '../errors/errors.js'; +import type { Dictionary } from './types.js'; export function isFileLocalizable(path: string, localizableProperty: string | undefined) { // If no localizableProperty is specified, all files are supposed to be localizable. diff --git a/packages/core/tests/unit/config-validation.test.ts b/packages/core/tests/unit/config-validation.test.ts index e329789..e6243c2 100644 --- a/packages/core/tests/unit/config-validation.test.ts +++ b/packages/core/tests/unit/config-validation.test.ts @@ -1,5 +1,5 @@ -import { describe, it } from 'node:test'; import { strict as assert } from 'node:assert'; +import { describe, it } from 'node:test'; import { validateConfig } from '../../dist/config/config.js'; import { sampleValidConfig } from '../utils.js'; diff --git a/packages/core/tests/unit/path-resolver.test.ts b/packages/core/tests/unit/path-resolver.test.ts index ba14307..b9c33ee 100644 --- a/packages/core/tests/unit/path-resolver.test.ts +++ b/packages/core/tests/unit/path-resolver.test.ts @@ -1,5 +1,5 @@ -import { describe, it } from 'node:test'; import { strict as assert } from 'node:assert'; +import { describe, it } from 'node:test'; import { createPathResolver } from '../../dist/status/paths.js'; describe('Path resolver', () => { diff --git a/packages/starlight/src/cache.ts b/packages/starlight/src/cache.ts index 14d900e..01c82b2 100644 --- a/packages/starlight/src/cache.ts +++ b/packages/starlight/src/cache.ts @@ -1,8 +1,8 @@ +import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'; +import { join, resolve } from 'node:path'; import type { LunariaConfig } from '@lunariajs/core/config'; import { git } from '@lunariajs/core/git'; import { getLocalizationStatus } from '@lunariajs/core/status'; -import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'; -import { join, resolve } from 'node:path'; let lastExecutionDate: string | undefined; const cacheDir = resolve('./node_modules/.cache/lunaria/'); diff --git a/packages/starlight/src/components/Dashboard.astro b/packages/starlight/src/components/Dashboard.astro index eef22cf..b390faf 100644 --- a/packages/starlight/src/components/Dashboard.astro +++ b/packages/starlight/src/components/Dashboard.astro @@ -1,7 +1,7 @@ --- +import { isShallowRepo, pluginConfig } from 'virtual:lunaria-starlight'; import { loadConfig } from '@lunariajs/core/config'; import { generateDashboard } from '@lunariajs/core/dashboard'; -import { pluginConfig, isShallowRepo } from 'virtual:lunaria-starlight'; import { getStatusFromCache } from '../cache'; const { userConfig, rendererConfig } = await loadConfig(pluginConfig.configPath); diff --git a/packages/starlight/src/index.ts b/packages/starlight/src/index.ts index a4149b1..20610cb 100644 --- a/packages/starlight/src/index.ts +++ b/packages/starlight/src/index.ts @@ -1,10 +1,10 @@ import type { StarlightPlugin } from '@astrojs/starlight/types'; import { + type Locale, + type LunariaUserConfig, loadConfig, readConfig, writeConfig, - type Locale, - type LunariaUserConfig, } from '@lunariajs/core/config'; import { handleShallowRepo } from '@lunariajs/core/git'; import type { ViteUserConfig } from 'astro'; @@ -66,7 +66,7 @@ export default function lunariaStarlight(userConfig?: LunariaStarlightUserConfig // Filter out the file entry added by sync. const otherFiles = lunariaConfig?.files?.filter( - (file: { location: string }) => file.location !== starlightFilesEntry.location + (file: { location: string }) => file.location !== starlightFilesEntry.location, ) ?? []; const locEntries = Object.entries(config.locales); @@ -82,7 +82,7 @@ export default function lunariaStarlight(userConfig?: LunariaStarlightUserConfig })) as [Locale, ...Locale[]]; const [defaultKey, defaultValue] = locEntries.find( - ([key]) => key === config.defaultLocale || key === 'root' + ([key]) => key === config.defaultLocale || key === 'root', )!; // Since the defaultLocale can be root which does not include // the proper path part, we infer one from the lang (required) @@ -101,7 +101,7 @@ export default function lunariaStarlight(userConfig?: LunariaStarlightUserConfig logger.info('Sync complete.'); } else { logger.warn( - 'Sync is only supported when your Starlight config includes the locales field.' + 'Sync is only supported when your Starlight config includes the locales field.', ); } } @@ -136,7 +136,7 @@ type VitePlugin = NonNullable[number]; function vitePluginLunariaStarlight( pluginConfig: LunariaStarlightUserConfig, - isShallowRepo: boolean + isShallowRepo: boolean, ): VitePlugin { const moduleId = 'virtual:lunaria-starlight'; const resolvedModuleId = `\0${moduleId}`; diff --git a/turbo.json b/turbo.json index 76825ea..e3d4de3 100644 --- a/turbo.json +++ b/turbo.json @@ -1,21 +1,16 @@ { - "$schema": "https://turbo.build/schema.json", - "tasks": { - "build": { - "dependsOn": ["^build"], - "inputs": [ - "**/*", - "!test/**/*" - ], - "outputs": [ - "dist/**/*" - ], - "outputLogs": "new-only" - }, - "dev": { - "cache": false, - "persistent": true - }, - "test" : {} - } -} \ No newline at end of file + "$schema": "https://turbo.build/schema.json", + "tasks": { + "build": { + "dependsOn": ["^build"], + "inputs": ["**/*", "!test/**/*"], + "outputs": ["dist/**/*"], + "outputLogs": "new-only" + }, + "dev": { + "cache": false, + "persistent": true + }, + "test": {} + } +}