Skip to content

Commit

Permalink
Fix publish workflow and Biome check issues
Browse files Browse the repository at this point in the history
  • Loading branch information
yanthomasdev committed Sep 9, 2024
1 parent 12d67bf commit 7d40977
Show file tree
Hide file tree
Showing 22 changed files with 131 additions and 151 deletions.
5 changes: 1 addition & 4 deletions .changeset/config.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
{
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json",
"changelog": [
"@changesets/changelog-github",
{ "repo": "yanthomasdev/lunaria" }
],
"changelog": ["@changesets/changelog-github", { "repo": "yanthomasdev/lunaria" }],

"commit": false,
"fixed": [],
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ jobs:
- name: Build Packages
run: pnpm run build

- run: pnpx pkg-pr-new publish --compact './packages/*'
- run: pnpx pkg-pr-new publish --compact './packages/core'
100 changes: 51 additions & 49 deletions biome.json
Original file line number Diff line number Diff line change
@@ -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
}
}
}
]
}
2 changes: 1 addition & 1 deletion docs/astro.config.mjs
Original file line number Diff line number Diff line change
@@ -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/';

Expand Down
4 changes: 2 additions & 2 deletions docs/src/components/ShowcaseCard.astro
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion docs/src/components/ShowcaseSites.astro
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
import Card from './ShowcaseCard.astro';
import FluidGrid from './FluidGrid.astro';
import Card from './ShowcaseCard.astro';
---

<FluidGrid>
Expand Down
2 changes: 1 addition & 1 deletion docs/src/content/config.ts
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down
2 changes: 1 addition & 1 deletion examples/nextra/theme.config.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DocsThemeConfig } from 'nextra-theme-docs';
import type { DocsThemeConfig } from 'nextra-theme-docs';

const config: DocsThemeConfig = {
logo: <span>My Project</span>,
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/config/config.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/errors/index.ts
Original file line number Diff line number Diff line change
@@ -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<T extends z.Schema>(
schema: T,
Expand Down
63 changes: 24 additions & 39 deletions packages/core/src/errors/zod-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,29 @@
* 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[];
};

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<string, TypeOrLiteralErrByPathEntry> =
new Map();
const typeOrLiteralErrByPath: Map<string, TypeOrLiteralErrByPathEntry> = 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,
Expand All @@ -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.
Expand All @@ -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,
Expand All @@ -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<unknown>) =>
[...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 = /^\./;
6 changes: 3 additions & 3 deletions packages/core/src/files/paths.ts
Original file line number Diff line number Diff line change
@@ -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 */
Expand Down
16 changes: 8 additions & 8 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/status/git.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
Loading

0 comments on commit 7d40977

Please sign in to comment.