diff --git a/demos/react-jsnation-workshop/src/components/steps/Step5.tsx b/demos/react-jsnation-workshop/src/components/steps/Step5.tsx index 70f137f5..c8b0187a 100644 --- a/demos/react-jsnation-workshop/src/components/steps/Step5.tsx +++ b/demos/react-jsnation-workshop/src/components/steps/Step5.tsx @@ -158,12 +158,12 @@ function Profile({ user }: { user: LocalUser | undefined }): JSX.Element { } class LocalUser { - #id: number; + readonly id: number; #resource: InvalidatableAsync; #invalidate: Marker; constructor(id: number, data: InvalidatableAsync, marker: Marker) { - this.#id = id; + this.id = id; this.#resource = data; this.#invalidate = marker; } diff --git a/demos/react-jsnation-workshop/src/components/steps/Step6.tsx b/demos/react-jsnation-workshop/src/components/steps/Step6.tsx index 2a7c5565..205778a2 100644 --- a/demos/react-jsnation-workshop/src/components/steps/Step6.tsx +++ b/demos/react-jsnation-workshop/src/components/steps/Step6.tsx @@ -173,12 +173,12 @@ function Profile({ user }: { user: LocalUser | undefined }): JSX.Element { } class LocalUser { - #id: number; + readonly id: number; #resource: InvalidatableAsync; #invalidate: Marker; constructor(id: number, data: InvalidatableAsync, marker: Marker) { - this.#id = id; + this.id = id; this.#resource = data; this.#invalidate = marker; } diff --git a/demos/react-jsnation/.eslintrc.json b/demos/react-jsnation/.eslintrc.json index 11124447..9fb0c333 100644 --- a/demos/react-jsnation/.eslintrc.json +++ b/demos/react-jsnation/.eslintrc.json @@ -1,5 +1,6 @@ { "root": true, + "ignorePatterns": ["node_modules", "dist", "html", "tests"], "plugins": ["@starbeam"], "overrides": [ { diff --git a/demos/react-jsnation/tests/.eslintrc.json b/demos/react-jsnation/tests/.eslintrc.json index 8c8bce75..b0b22424 100644 --- a/demos/react-jsnation/tests/.eslintrc.json +++ b/demos/react-jsnation/tests/.eslintrc.json @@ -5,7 +5,7 @@ "overrides": [ { "extends": ["plugin:@starbeam/loose"], - "files": ["**/*.ts"], + "files": ["**/*.{tsx,ts}"], "parserOptions": { "project": "tsconfig.json" } diff --git a/demos/react-jsnation/tests/package.json b/demos/react-jsnation/tests/package.json index 51b517c6..54dd7fde 100644 --- a/demos/react-jsnation/tests/package.json +++ b/demos/react-jsnation/tests/package.json @@ -5,7 +5,7 @@ "type": "module", "starbeam": { "jsx": "react", - "source": "ts", + "source": "tsx", "type": "tests" }, "scripts": { diff --git a/demos/react-stock-ticker/src/components/Header.tsx b/demos/react-stock-ticker/src/components/Header.tsx index 17290464..93c5bb19 100644 --- a/demos/react-stock-ticker/src/components/Header.tsx +++ b/demos/react-stock-ticker/src/components/Header.tsx @@ -21,7 +21,7 @@ export default function Header(): JSX.Element { event.preventDefault(); const { search } = Object.fromEntries( - new FormData(event.currentTarget) + new FormData(event.currentTarget), ) as { search: string; }; @@ -86,6 +86,6 @@ export default function Header(): JSX.Element { ), - [] + [], ); } diff --git a/packages/preact/preact-testing-utils/package.json b/packages/preact/preact-testing-utils/package.json index 26bdd32f..b67441f4 100644 --- a/packages/preact/preact-testing-utils/package.json +++ b/packages/preact/preact-testing-utils/package.json @@ -14,7 +14,9 @@ "main": "dist/index.cjs", "types": "dist/index.d.ts" }, - "starbeam:type": "library:test-support", + "starbeam": { + "type": "library:test-support" + }, "scripts": { "test:lint": "eslint . --max-warnings 0", "test:specs": "vitest --run", diff --git a/packages/preact/preact-testing-utils/tests/package.json b/packages/preact/preact-testing-utils/tests/package.json index 75e78ab8..b770a25b 100644 --- a/packages/preact/preact-testing-utils/tests/package.json +++ b/packages/preact/preact-testing-utils/tests/package.json @@ -4,7 +4,7 @@ "version": "1.0.0", "type": "module", "starbeam": { - "source": "ts", + "source": "tsx", "type": "tests" }, "scripts": { diff --git a/packages/preact/preact-utils/package.json b/packages/preact/preact-utils/package.json index 29717cbf..fcc3c8f6 100644 --- a/packages/preact/preact-utils/package.json +++ b/packages/preact/preact-utils/package.json @@ -18,7 +18,9 @@ "main": "dist/index.cjs", "types": "dist/index.d.ts" }, - "starbeam:type": "library:public", + "starbeam": { + "type": "library:public" + }, "scripts": { "test:lint": "eslint . --max-warnings 0", "test:specs": "vitest --run", diff --git a/packages/preact/preact-utils/src/plugin.ts b/packages/preact/preact-utils/src/plugin.ts index c53a30bf..a2ea28dd 100644 --- a/packages/preact/preact-utils/src/plugin.ts +++ b/packages/preact/preact-utils/src/plugin.ts @@ -266,12 +266,10 @@ class AugmentHandler implements Handler { } } - #name: string; #handled = false; #original: F; - private constructor(name: string, original: F) { - this.#name = name; + private constructor(_name: string, original: F) { this.#original = original; } diff --git a/packages/preact/preact-utils/tests/package.json b/packages/preact/preact-utils/tests/package.json index 8c8a2404..d1d7e55b 100644 --- a/packages/preact/preact-utils/tests/package.json +++ b/packages/preact/preact-utils/tests/package.json @@ -4,7 +4,7 @@ "version": "1.0.0", "type": "module", "starbeam": { - "source": "ts", + "source": "tsx", "type": "tests" }, "scripts": { diff --git a/packages/preact/preact/tests/package.json b/packages/preact/preact/tests/package.json index a5ba1690..d04af563 100644 --- a/packages/preact/preact/tests/package.json +++ b/packages/preact/preact/tests/package.json @@ -4,7 +4,7 @@ "version": "1.0.0", "type": "module", "starbeam": { - "source": "ts", + "source": "tsx", "type": "tests" }, "scripts": { diff --git a/packages/react/react/tests/package.json b/packages/react/react/tests/package.json index b8c60c57..72be6938 100644 --- a/packages/react/react/tests/package.json +++ b/packages/react/react/tests/package.json @@ -4,7 +4,7 @@ "version": "1.0.0", "type": "module", "starbeam": { - "source": "ts", + "source": "tsx", "type": "tests" }, "scripts": { diff --git a/packages/react/test-utils/package.json b/packages/react/test-utils/package.json index ce6c29cf..815eb2a1 100644 --- a/packages/react/test-utils/package.json +++ b/packages/react/test-utils/package.json @@ -18,7 +18,9 @@ "main": "dist/index.cjs", "types": "dist/index.d.ts" }, - "starbeam:type": "library:test-support", + "starbeam": { + "type": "library:test-support" + }, "scripts": { "test:lint": "eslint . --max-warnings 0", "test:types": "tsc -b" diff --git a/packages/react/test-utils/src/modes.ts b/packages/react/test-utils/src/modes.ts index 47ab22e5..fda3cb4d 100644 --- a/packages/react/test-utils/src/modes.ts +++ b/packages/react/test-utils/src/modes.ts @@ -202,6 +202,7 @@ export class SetupTestRoot { if (lastChecked === undefined || current === undefined) { if (lastChecked !== current) { + // eslint-disable-next-line no-console console.error("Expected current value to equal last checked value", { lastChecked, current, diff --git a/packages/react/use-strict-lifecycle/package.json b/packages/react/use-strict-lifecycle/package.json index 9869abf0..50c14a09 100644 --- a/packages/react/use-strict-lifecycle/package.json +++ b/packages/react/use-strict-lifecycle/package.json @@ -19,7 +19,9 @@ "main": "dist/index.cjs", "types": "dist/index.d.ts" }, - "starbeam:type": "library:public", + "starbeam": { + "type": "library:public" + }, "scripts": { "doc": "node ./scripts/doc.js", "doc:all": "node ./scripts/docs.js", diff --git a/packages/react/use-strict-lifecycle/tests/package.json b/packages/react/use-strict-lifecycle/tests/package.json index 4bb07a40..966f81d9 100644 --- a/packages/react/use-strict-lifecycle/tests/package.json +++ b/packages/react/use-strict-lifecycle/tests/package.json @@ -4,7 +4,7 @@ "version": "1.0.0", "type": "module", "starbeam": { - "source": "ts", + "source": "tsx", "type": "tests" }, "scripts": { diff --git a/packages/universal/collections/package.json b/packages/universal/collections/package.json index f5a13678..18abe0fb 100644 --- a/packages/universal/collections/package.json +++ b/packages/universal/collections/package.json @@ -19,7 +19,9 @@ "main": "dist/index.cjs", "types": "dist/index.d.ts" }, - "starbeam:type": "library:public", + "starbeam": { + "type": "library:public" + }, "scripts": { "test:lint": "eslint . --max-warnings 0", "test:specs": "vitest --run", diff --git a/packages/universal/collections/tests/package.json b/packages/universal/collections/tests/package.json index 03e0eb8c..f3f69595 100644 --- a/packages/universal/collections/tests/package.json +++ b/packages/universal/collections/tests/package.json @@ -4,7 +4,7 @@ "version": "1.0.0", "type": "module", "starbeam": { - "source": "ts", + "source": "tsx", "type": "tests" }, "scripts": { diff --git a/packages/universal/core-utils/package.json b/packages/universal/core-utils/package.json index ec753799..2b902e84 100644 --- a/packages/universal/core-utils/package.json +++ b/packages/universal/core-utils/package.json @@ -18,7 +18,9 @@ "main": "dist/index.cjs", "types": "dist/index.d.ts" }, - "starbeam:type": "library:public", + "starbeam": { + "type": "library:public" + }, "scripts": { "test:lint": "eslint . --max-warnings 0", "test:specs": "vitest --run", diff --git a/packages/universal/core-utils/tests/package.json b/packages/universal/core-utils/tests/package.json index 8b121728..c595b140 100644 --- a/packages/universal/core-utils/tests/package.json +++ b/packages/universal/core-utils/tests/package.json @@ -4,7 +4,7 @@ "version": "1.0.0", "type": "module", "starbeam": { - "source": "ts", + "source": "tsx", "type": "tests" }, "scripts": { diff --git a/packages/universal/core/index.ts b/packages/universal/core/index.ts index 776715ce..4385c715 100644 --- a/packages/universal/core/index.ts +++ b/packages/universal/core/index.ts @@ -1,4 +1,5 @@ +// eslint-disable-next-line no-console console.warn( - "WARNING: @starbeam/core has been renamed to @starbeam/universal. Please update your imports to refer to @starbeam/universal." + "WARNING: @starbeam/core has been renamed to @starbeam/universal. Please update your imports to refer to @starbeam/universal.", ); export * from "@starbeam/universal"; diff --git a/packages/universal/debug/src/logger.ts b/packages/universal/debug/src/logger.ts new file mode 100644 index 00000000..3c864614 --- /dev/null +++ b/packages/universal/debug/src/logger.ts @@ -0,0 +1,34 @@ +/** + * This API might gain additional features. For now, its primary purpose is to provide a + * sanctioned way to log to the console that is overtly different from explicit + * calls to `console.log` (which make it more difficult to identify errant console.logs). + */ +export class Logger { + static console(): Logger { + return new Logger(console); + } + + static of(logger: typeof console): Logger { + return new Logger(logger); + } + + #logger: typeof console; + + private constructor(logger: typeof console) { + this.#logger = logger; + } + + group(...args: unknown[]): void { + this.#logger.group(...args); + } + + groupEnd(): void { + this.#logger.groupEnd(); + } + + info(...args: unknown[]): void { + this.#logger.info(...args); + } +} + +export const LOGGER = Logger.console(); diff --git a/packages/universal/debug/src/tag.ts b/packages/universal/debug/src/tag.ts index 2b0f09bb..33b97b94 100644 --- a/packages/universal/debug/src/tag.ts +++ b/packages/universal/debug/src/tag.ts @@ -3,19 +3,20 @@ import type { Description, HasTag } from "@starbeam/interfaces"; import { DEBUG, UNKNOWN_REACTIVE_VALUE } from "@starbeam/reactive"; import { getDependencies, getTag, lastUpdated } from "@starbeam/tags"; +import { LOGGER } from "./logger.js"; import { Tree } from "./tree.js"; export const debugReactive = ( tag: HasTag, { implementation = false, - }: { implementation?: boolean; source?: boolean; id?: boolean } = {} + }: { implementation?: boolean; source?: boolean; id?: boolean } = {}, ): string => { const dependencies = getDependencies(tag); const descriptions = new Set( dependencies.map((dependency) => - getDesc(dependency.description, implementation) - ) + getDesc(dependency.description, implementation), + ), ); const nodes = [...descriptions] @@ -35,29 +36,31 @@ export const logReactive = ( implementation?: boolean; source?: boolean; id?: boolean; - } = {} + } = {}, ): void => { const debug = debugReactive(tag, options); if (options.label) { - console.group(options.label); + LOGGER.group(options.label); } - console.group( - describe(getTag(tag).description, { id: options.id }), - `(updated at ${lastUpdated(tag).at})` - ); - console.info(debug); - console.groupEnd(); + { + LOGGER.group( + describe(getTag(tag).description, { id: options.id }), + `(updated at ${lastUpdated(tag).at})`, + ); + LOGGER.info(debug); + LOGGER.groupEnd(); + } if (options.label) { - console.groupEnd(); + LOGGER.groupEnd(); } }; function describe( description: Description | undefined, - options?: { id: boolean | undefined } + options?: { id: boolean | undefined }, ): string { return description && DEBUG ? DEBUG.describe(description, options) @@ -66,7 +69,7 @@ function describe( function getDesc( description: Description | undefined, - showImplementation: boolean + showImplementation: boolean, ): Description | undefined { return showImplementation ? description : DEBUG?.getUserFacing(description); } diff --git a/packages/universal/debug/tests/package.json b/packages/universal/debug/tests/package.json index bec8e1b9..88060f57 100644 --- a/packages/universal/debug/tests/package.json +++ b/packages/universal/debug/tests/package.json @@ -4,7 +4,7 @@ "version": "1.0.0", "type": "module", "starbeam": { - "source": "ts", + "source": "tsx", "type": "tests" }, "scripts": { diff --git a/packages/universal/modifier/package.json b/packages/universal/modifier/package.json index fa46878b..9df0f51f 100644 --- a/packages/universal/modifier/package.json +++ b/packages/universal/modifier/package.json @@ -18,7 +18,9 @@ "main": "dist/index.cjs", "types": "dist/index.d.ts" }, - "starbeam:type": "library:public", + "starbeam": { + "type": "library:public" + }, "scripts": { "test:lint": "eslint . --max-warnings 0", "test:types": "tsc -b" diff --git a/packages/universal/reactive/package.json b/packages/universal/reactive/package.json index 3032aab9..608b53ec 100644 --- a/packages/universal/reactive/package.json +++ b/packages/universal/reactive/package.json @@ -18,7 +18,9 @@ "main": "dist/index.cjs", "types": "dist/index.d.ts" }, - "starbeam:type": "library:public", + "starbeam": { + "type": "library:public" + }, "scripts": { "test:lint": "eslint . --max-warnings 0", "test:specs": "vitest --run", diff --git a/packages/universal/reactive/tests/package.json b/packages/universal/reactive/tests/package.json index e9ccfe5f..194e0eed 100644 --- a/packages/universal/reactive/tests/package.json +++ b/packages/universal/reactive/tests/package.json @@ -4,7 +4,7 @@ "version": "1.0.0", "type": "module", "starbeam": { - "source": "ts", + "source": "tsx", "type": "tests" }, "scripts": { diff --git a/packages/universal/renderer/package.json b/packages/universal/renderer/package.json index 9792e260..729927d1 100644 --- a/packages/universal/renderer/package.json +++ b/packages/universal/renderer/package.json @@ -18,7 +18,9 @@ "main": "dist/index.cjs", "types": "dist/index.d.ts" }, - "starbeam:type": "library:public", + "starbeam": { + "type": "library:public" + }, "scripts": { "test:lint": "eslint . --max-warnings 0", "test:specs": "vitest --run", diff --git a/packages/universal/renderer/src/renderer.ts b/packages/universal/renderer/src/renderer.ts index 30a8d332..47a30259 100644 --- a/packages/universal/renderer/src/renderer.ts +++ b/packages/universal/renderer/src/renderer.ts @@ -115,13 +115,9 @@ export function managerSetupReactive( manager: M, blueprint: UseReactive, ): Reactive> { - console.log(1); const component = manager.getComponent() as object; - console.log(2); const lifecycle = new LifecycleImpl(manager, component); - console.log(3); const currentBlueprint = manager.setupRef(component, blueprint); - console.log(4); return manager.setupValue(component, () => setupFormula(currentBlueprint, lifecycle), ); diff --git a/packages/universal/renderer/tests/package.json b/packages/universal/renderer/tests/package.json index 77e1d5de..b1c69ddd 100644 --- a/packages/universal/renderer/tests/package.json +++ b/packages/universal/renderer/tests/package.json @@ -4,7 +4,7 @@ "version": "1.0.0", "type": "module", "starbeam": { - "source": "ts", + "source": "tsx", "type": "tests" }, "scripts": { diff --git a/packages/universal/resource/package.json b/packages/universal/resource/package.json index 5aa49f24..71272d71 100644 --- a/packages/universal/resource/package.json +++ b/packages/universal/resource/package.json @@ -17,7 +17,9 @@ "main": "dist/index.cjs", "types": "dist/index.d.ts" }, - "starbeam:type": "library:public", + "starbeam": { + "type": "library:public" + }, "scripts": { "test:lint": "eslint . --max-warnings 0", "test:specs": "vitest --run", diff --git a/packages/universal/resource/tests/package.json b/packages/universal/resource/tests/package.json index b7ed2311..cc6b3e16 100644 --- a/packages/universal/resource/tests/package.json +++ b/packages/universal/resource/tests/package.json @@ -4,7 +4,7 @@ "version": "1.0.0", "type": "module", "starbeam": { - "source": "ts", + "source": "tsx", "type": "tests" }, "scripts": { diff --git a/packages/universal/resource/tests/sync.spec.ts b/packages/universal/resource/tests/sync.spec.ts index 3e00a80c..c6adb547 100644 --- a/packages/universal/resource/tests/sync.spec.ts +++ b/packages/universal/resource/tests/sync.spec.ts @@ -457,19 +457,12 @@ const isInitialized = isNotEqual(UNINITIALIZED); type Change = (prev: U) => U; class Child { - readonly #events: RecordedEvents; readonly #sequence: number; readonly #value: T; #lastValue: U | UNINITIALIZED = UNINITIALIZED; #extract: (value: T) => U; - constructor( - events: RecordedEvents, - sequence: number, - value: T, - extract: (value: T) => U, - ) { - this.#events = events; + constructor(sequence: number, value: T, extract: (value: T) => U) { this.#sequence = sequence; this.#value = value; this.#extract = extract; @@ -531,9 +524,7 @@ class Children implements Iterable> { constructor(events: RecordedEvents, children: T[], extract: (value: T) => U) { this.#events = events; - this.#children = children.map( - (child, i) => new Child(events, i, child, extract), - ); + this.#children = children.map((child, i) => new Child(i, child, extract)); } expect( diff --git a/packages/universal/runtime/package.json b/packages/universal/runtime/package.json index f3f60880..3ba02863 100644 --- a/packages/universal/runtime/package.json +++ b/packages/universal/runtime/package.json @@ -18,7 +18,9 @@ "main": "dist/index.cjs", "types": "dist/index.d.ts" }, - "starbeam:type": "library:public", + "starbeam": { + "type": "library:public" + }, "scripts": { "test:lint": "eslint . --max-warnings 0", "test:specs": "vitest --run", diff --git a/packages/universal/runtime/src/lifetime/api.ts b/packages/universal/runtime/src/lifetime/api.ts index f9a4da12..66434ca0 100644 --- a/packages/universal/runtime/src/lifetime/api.ts +++ b/packages/universal/runtime/src/lifetime/api.ts @@ -4,7 +4,7 @@ import { onFinalize, } from "@starbeam/shared"; -import { ObjectLifetime, type Unsubscribe } from "./object-lifetime.js"; +import type { ObjectLifetime, Unsubscribe } from "./object-lifetime.js"; class LifetimeAPI { readonly #associations = new WeakMap(); @@ -14,15 +14,6 @@ class LifetimeAPI { if (!handler) return; onFinalize(object, handler); - - // let lifetime = this.#associations.get(object); - - // if (!lifetime) { - // lifetime = ObjectLifetime.create(object); - // this.#associations.set(object, lifetime); - // } - - // return lifetime.on.finalize(handler); }, }; @@ -34,17 +25,6 @@ class LifetimeAPI { finalize(object); } - #initialize(object: object): ObjectLifetime { - let lifetime = this.#associations.get(object); - - if (!lifetime) { - lifetime = ObjectLifetime.create(object); - this.#associations.set(object, lifetime); - } - - return lifetime; - } - link(parent: object, child: object): Unsubscribe { return linkToFinalizationScope(child, parent); } diff --git a/packages/universal/runtime/tests/package.json b/packages/universal/runtime/tests/package.json index e3d1df53..bab02cf6 100644 --- a/packages/universal/runtime/tests/package.json +++ b/packages/universal/runtime/tests/package.json @@ -4,7 +4,7 @@ "version": "1.0.0", "type": "module", "starbeam": { - "source": "ts", + "source": "tsx", "type": "tests" }, "scripts": { diff --git a/packages/universal/service/package.json b/packages/universal/service/package.json index 4e5dff5a..a6536932 100644 --- a/packages/universal/service/package.json +++ b/packages/universal/service/package.json @@ -17,7 +17,9 @@ "main": "dist/index.cjs", "types": "dist/index.d.ts" }, - "starbeam:type": "library:public", + "starbeam": { + "type": "library:public" + }, "scripts": { "test:lint": "eslint . --max-warnings 0", "test:specs": "vitest --run", diff --git a/packages/universal/service/tests/package.json b/packages/universal/service/tests/package.json index 9630b3b4..eeb66648 100644 --- a/packages/universal/service/tests/package.json +++ b/packages/universal/service/tests/package.json @@ -4,7 +4,7 @@ "version": "1.0.0", "type": "module", "starbeam": { - "source": "ts", + "source": "tsx", "type": "tests" }, "scripts": { diff --git a/packages/universal/shared/package.json b/packages/universal/shared/package.json index eae8137d..b1cd081b 100644 --- a/packages/universal/shared/package.json +++ b/packages/universal/shared/package.json @@ -19,7 +19,9 @@ "main": "dist/index.cjs", "types": "dist/index.d.ts" }, - "starbeam:type": "library:public", + "starbeam": { + "type": "library:public" + }, "scripts": { "test:lint": "eslint . --max-warnings 0", "test:specs": "vitest --run", diff --git a/packages/universal/shared/src/lifetimes.ts b/packages/universal/shared/src/lifetimes.ts index 1388e193..1cb21d74 100644 --- a/packages/universal/shared/src/lifetimes.ts +++ b/packages/universal/shared/src/lifetimes.ts @@ -13,15 +13,10 @@ let id = 0; if (!lifetime) { class LifetimeState { - readonly #object: WeakRef; readonly #finalizers = new Set<() => void>(); readonly children = new Set(); #finalized = false; - constructor(object: object) { - this.#object = new WeakRef(object); - } - add(finalizer: () => void) { this.#finalizers.add(finalizer); } @@ -164,7 +159,7 @@ if (!lifetime) { let state = this.#lifetimes.get(object); if (!state) { - state = new LifetimeState(object); + state = new LifetimeState(); this.#lifetimes.set(object, state); registry.register(object, state); } diff --git a/packages/universal/shared/tests/package.json b/packages/universal/shared/tests/package.json index 49fb96bc..d0da5289 100644 --- a/packages/universal/shared/tests/package.json +++ b/packages/universal/shared/tests/package.json @@ -4,7 +4,7 @@ "version": "1.0.0", "type": "module", "starbeam": { - "source": "ts", + "source": "tsx", "type": "tests" }, "scripts": { diff --git a/packages/universal/tags/package.json b/packages/universal/tags/package.json index 645f6be2..182e9ed7 100644 --- a/packages/universal/tags/package.json +++ b/packages/universal/tags/package.json @@ -18,7 +18,9 @@ "main": "dist/index.cjs", "types": "dist/index.d.ts" }, - "starbeam:type": "library:public", + "starbeam": { + "type": "library:public" + }, "scripts": { "test:lint": "eslint . --max-warnings 0", "test:types": "tsc -b" diff --git a/packages/universal/universal/package.json b/packages/universal/universal/package.json index e75a87b9..44ba35ec 100644 --- a/packages/universal/universal/package.json +++ b/packages/universal/universal/package.json @@ -18,7 +18,9 @@ "main": "dist/index.cjs", "types": "dist/index.d.ts" }, - "starbeam:type": "library:public", + "starbeam": { + "type": "library:public" + }, "scripts": { "test:lint": "eslint . --max-warnings 0", "test:specs": "vitest --run", diff --git a/packages/universal/universal/tests/package.json b/packages/universal/universal/tests/package.json index 9b39d2a1..80d8c6b4 100644 --- a/packages/universal/universal/tests/package.json +++ b/packages/universal/universal/tests/package.json @@ -4,7 +4,7 @@ "version": "1.0.0", "type": "module", "starbeam": { - "source": "ts", + "source": "tsx", "type": "tests" }, "scripts": { diff --git a/packages/universal/verify/package.json b/packages/universal/verify/package.json index 07103a62..1429fcd0 100644 --- a/packages/universal/verify/package.json +++ b/packages/universal/verify/package.json @@ -18,7 +18,9 @@ "main": "dist/index.cjs", "types": "dist/index.d.ts" }, - "starbeam:type": "library:public", + "starbeam": { + "type": "library:public" + }, "scripts": { "test:lint": "eslint . --max-warnings 0", "test:specs": "vitest --run", diff --git a/packages/universal/verify/tests/package.json b/packages/universal/verify/tests/package.json index 0b229c14..b562fcd9 100644 --- a/packages/universal/verify/tests/package.json +++ b/packages/universal/verify/tests/package.json @@ -4,7 +4,7 @@ "version": "1.0.0", "type": "module", "starbeam": { - "source": "ts", + "source": "tsx", "type": "tests" }, "scripts": { diff --git a/packages/vue/vue-testing-utils/package.json b/packages/vue/vue-testing-utils/package.json index 92100c9d..660b97d2 100644 --- a/packages/vue/vue-testing-utils/package.json +++ b/packages/vue/vue-testing-utils/package.json @@ -14,7 +14,9 @@ "main": "dist/index.cjs", "types": "dist/index.d.ts" }, - "starbeam:type": "library:test-support", + "starbeam": { + "type": "library:test-support" + }, "scripts": { "test:lint": "eslint . --max-warnings 0", "test:specs": "vitest --run", diff --git a/packages/vue/vue-testing-utils/tests/package.json b/packages/vue/vue-testing-utils/tests/package.json index c36726c2..9f893bfd 100644 --- a/packages/vue/vue-testing-utils/tests/package.json +++ b/packages/vue/vue-testing-utils/tests/package.json @@ -4,7 +4,7 @@ "version": "1.0.0", "type": "module", "starbeam": { - "source": "ts", + "source": "tsx", "type": "tests" }, "scripts": { diff --git a/packages/vue/vue/tests/package.json b/packages/vue/vue/tests/package.json index 88c8517f..dc487df1 100644 --- a/packages/vue/vue/tests/package.json +++ b/packages/vue/vue/tests/package.json @@ -4,7 +4,7 @@ "version": "1.0.0", "type": "module", "starbeam": { - "source": "ts", + "source": "tsx", "type": "tests" }, "scripts": { diff --git a/packages/x/devtool/src/log/describe.tsx b/packages/x/devtool/src/log/describe.tsx index 2e251eff..ee931acd 100644 --- a/packages/x/devtool/src/log/describe.tsx +++ b/packages/x/devtool/src/log/describe.tsx @@ -1,3 +1,4 @@ +/* eslint-disable no-console */ /* eslint-disable @typescript-eslint/no-unsafe-call */ /* eslint-disable @typescript-eslint/no-unsafe-member-access */ /* eslint-disable @typescript-eslint/no-unsafe-assignment */ diff --git a/packages/x/devtool/src/log/frame.tsx b/packages/x/devtool/src/log/frame.tsx index 4c3f98cd..5d5a4998 100644 --- a/packages/x/devtool/src/log/frame.tsx +++ b/packages/x/devtool/src/log/frame.tsx @@ -1,3 +1,4 @@ +/* eslint-disable no-console */ /* eslint-disable @typescript-eslint/no-unsafe-member-access */ /* eslint-disable @typescript-eslint/no-unsafe-assignment */ /* eslint-disable @typescript-eslint/no-explicit-any */ diff --git a/packages/x/headless-form/package.json b/packages/x/headless-form/package.json index 7ee834f2..b186994f 100644 --- a/packages/x/headless-form/package.json +++ b/packages/x/headless-form/package.json @@ -20,7 +20,9 @@ "main": "dist/index.cjs", "types": "dist/index.d.ts" }, - "starbeam:type": "library:public", + "starbeam": { + "type": "library:public" + }, "scripts": { "test:lint": "eslint . --max-warnings 0", "test:types": "tsc -b" diff --git a/packages/x/store/package.json b/packages/x/store/package.json index 872067b2..d40ae5da 100644 --- a/packages/x/store/package.json +++ b/packages/x/store/package.json @@ -19,7 +19,9 @@ "main": "dist/index.cjs", "types": "dist/index.d.ts" }, - "starbeam:type": "library:public", + "starbeam": { + "type": "library:public" + }, "scripts": { "test:lint": "eslint . --max-warnings 0", "test:specs": "vitest --run", diff --git a/packages/x/store/src/flat.ts b/packages/x/store/src/flat.ts index a232d236..4d568cb8 100644 --- a/packages/x/store/src/flat.ts +++ b/packages/x/store/src/flat.ts @@ -27,7 +27,7 @@ export abstract class FlatRows } groupBy( - groupBy: Grouping + groupBy: Grouping, ): GroupBy { return GroupBy.create(this, groupBy); } @@ -46,13 +46,13 @@ export abstract class FlatRows */ type Grouping = ( - row: TableTypesFor["Row"] + row: TableTypesFor["Row"], ) => { bucket: Bucket; as?: Description }; export class Group extends FlatRows { static empty( grouping: unknown, - description: unknown + description: unknown, ): Group { return new Group(grouping, description, []); } @@ -61,15 +61,11 @@ export class Group extends FlatRows { group.#rows.push(row); } - readonly #grouping: unknown; - readonly #description: unknown; readonly #rows: T["Row"][]; constructor(grouping: unknown, description: unknown, rows: T["Row"][]) { super(); this.#rows = rows; - this.#grouping = grouping; - this.#description = description; } get rows(): readonly T["Row"][] { @@ -86,7 +82,7 @@ export class Groups { groups: Groups, bucket: Bucket, description: Description, - row: T["Row"] + row: T["Row"], ): void { let group = groups.#map.get(description); @@ -116,7 +112,7 @@ export class Groups { export class GroupBy { static create( rows: FlatRows, - groupBy: Grouping, Bucket, Description> + groupBy: Grouping, Bucket, Description>, ): GroupBy { return new GroupBy(rows, groupBy); } @@ -126,7 +122,7 @@ export class GroupBy { constructor( rows: FlatRows, - groupBy: Grouping, Bucket, Description> + groupBy: Grouping, Bucket, Description>, ) { this.#rows = rows; this.#groupBy = groupBy; @@ -152,11 +148,11 @@ type Dict = Record; export class AggregateBy< U extends UserTypes, - A extends AggregatorFor> + A extends AggregatorFor>, > { static create>>( rows: FlatRows, - aggregateBy: A + aggregateBy: A, ): AggregateBy { return new AggregateBy(rows, aggregateBy); } @@ -174,10 +170,10 @@ export class AggregateBy< Object.entries(this.#aggregateBy).map((entry) => { const [key, aggregator] = entry as [ string, - { initialize: () => AggregatorInstance } + { initialize: () => AggregatorInstance }, ]; return [key, aggregator.initialize()]; - }) + }), ) as Record>; for (const row of this.#rows.rows) { @@ -190,7 +186,7 @@ export class AggregateBy< Object.entries(aggregators).map(([key, aggregator]) => [ key, aggregator.value(), - ]) + ]), ) as unknown as AggregateRow, A>[]; return { @@ -212,7 +208,7 @@ export class Query extends FlatRows { constructor( rows: FlatRows, filter: FilterInstance, - sort: SortFn | undefined + sort: SortFn | undefined, ) { super(); this.#rows = rows; @@ -254,5 +250,5 @@ export interface Sort { export type SortFn = ( a: TableTypesFor["Row"], - b: TableTypesFor["Row"] + b: TableTypesFor["Row"], ) => number; diff --git a/packages/x/store/src/table.ts b/packages/x/store/src/table.ts index 2ac9ac34..c1c48802 100644 --- a/packages/x/store/src/table.ts +++ b/packages/x/store/src/table.ts @@ -11,7 +11,7 @@ const SINGLE_ELEMENT = 1; export class Table extends FlatRows { static create( this: void, - definition: S + definition: S, ): Table<{ Columns: ReturnType["row"]; Row: ReturnType; @@ -21,7 +21,7 @@ export class Table extends FlatRows { definition: { columns: (keyof C)[]; name?: string; - } + }, ): Table; static create( this: void, @@ -29,12 +29,12 @@ export class Table extends FlatRows { columns: (keyof object)[]; model?: Model; name?: string; - } + }, ): Table { const description = DEBUG?.Desc( "collection", definition.name ?? definition.model?.name, - "Table.create" + "Table.create", ); return new Table( @@ -43,23 +43,21 @@ export class Table extends FlatRows { model: definition.model ?? ((id: string, data: object) => ({ id, ...data })), }, - description + description, ); } #id = INITIAL_ID; readonly #definition: TableDefinition>; readonly #rows: Map["Row"]>; - readonly #description: Description | undefined; private constructor( definition: TableDefinition>, - description: Description | undefined + description: Description | undefined, ) { super(); this.#rows = reactive.Map(description); this.#definition = definition; - this.#description = description; } get columns(): ColumnName["Columns"]>[] { @@ -71,7 +69,7 @@ export class Table extends FlatRows { } append( - row: TableTypesFor["Columns"] & { id?: string } + row: TableTypesFor["Columns"] & { id?: string }, ): TableTypesFor["Row"]; append(...rows: (TableTypesFor["Columns"] & { id?: string })[]): void; append( @@ -101,7 +99,7 @@ type ColumnName = keyof C; export type Model = ( id: string, - columns: T["Columns"] + columns: T["Columns"], ) => T["Row"]; export type UserTypes = object | TableTypes; diff --git a/packages/x/store/tests/package.json b/packages/x/store/tests/package.json index 9cd33f25..13f15dd6 100644 --- a/packages/x/store/tests/package.json +++ b/packages/x/store/tests/package.json @@ -4,7 +4,7 @@ "version": "1.0.0", "type": "module", "starbeam": { - "source": "ts", + "source": "tsx", "type": "tests" }, "scripts": { diff --git a/packages/x/vanilla/package.json b/packages/x/vanilla/package.json index 98a41002..9f606a08 100644 --- a/packages/x/vanilla/package.json +++ b/packages/x/vanilla/package.json @@ -19,7 +19,9 @@ "main": "dist/index.cjs", "types": "dist/index.d.ts" }, - "starbeam:type": "library:public", + "starbeam": { + "type": "library:public" + }, "scripts": { "test:lint": "eslint . --max-warnings 0", "test:specs": "vitest --run", diff --git a/packages/x/vanilla/tests/package.json b/packages/x/vanilla/tests/package.json index 8078d47a..f053ea1f 100644 --- a/packages/x/vanilla/tests/package.json +++ b/packages/x/vanilla/tests/package.json @@ -4,7 +4,7 @@ "version": "1.0.0", "type": "module", "starbeam": { - "source": "ts", + "source": "tsx", "type": "tests" }, "scripts": { diff --git a/workspace/eslint/src/base.js b/workspace/eslint/src/base.js index e0721fcd..ed4c7087 100644 --- a/workspace/eslint/src/base.js +++ b/workspace/eslint/src/base.js @@ -136,6 +136,7 @@ const TYPED_RULES = Rules.build((rules) => /** @type {Linter.RulesRecord} */ exports.rules = { ...TYPED_RULES, + "no-console": "error", "eslint-comments/no-unused-disable": "error", "eslint-comments/require-description": [ "off", // enable in a subsequent PR diff --git a/workspace/eslint/src/demos.js b/workspace/eslint/src/demos.js index cf19dace..fd7419b2 100644 --- a/workspace/eslint/src/demos.js +++ b/workspace/eslint/src/demos.js @@ -2,4 +2,6 @@ const { Linter } = require("eslint"); /** @type {Linter.RulesRecord} */ -exports.rules = {}; +exports.rules = { + "no-console": "off", +}; diff --git a/workspace/misc/src/verbose-knip-reporter.ts b/workspace/misc/src/verbose-knip-reporter.ts index 0b01cf7a..b8178fb8 100644 --- a/workspace/misc/src/verbose-knip-reporter.ts +++ b/workspace/misc/src/verbose-knip-reporter.ts @@ -1,3 +1,4 @@ +/* eslint-disable no-console */ import type { ReporterOptions } from "knip"; type Reporter = (options: ReporterOptions) => Promise; diff --git a/workspace/package/src/unions.ts b/workspace/package/src/unions.ts index 1d721f82..fff7b333 100644 --- a/workspace/package/src/unions.ts +++ b/workspace/package/src/unions.ts @@ -1,4 +1,9 @@ -import { getFirst, isSingleItemArray, stringify } from "@starbeam/core-utils"; +import { + DisplayStruct, + getFirst, + isSingleItemArray, + stringify, +} from "@starbeam/core-utils"; import type { JsonObject, JsonValue } from "@starbeam-workspace/json"; import type { Directory, RegularFile } from "@starbeam-workspace/paths"; import { Globs } from "@starbeam-workspace/paths"; @@ -274,6 +279,12 @@ export class Extensions implements Iterable { this.#extensions = extensions; } + [Symbol.for("nodejs.util.inspect.custom")](): object { + return DisplayStruct("Extensions", { + extensions: this.#extensions, + }); + } + [Symbol.iterator](): IterableIterator { return this.#extensions[Symbol.iterator](); } diff --git a/workspace/paths/src/paths.ts b/workspace/paths/src/paths.ts index ca02f83c..7808ee1d 100644 --- a/workspace/paths/src/paths.ts +++ b/workspace/paths/src/paths.ts @@ -455,6 +455,7 @@ export class Glob extends Path { } else if (dirent.isSymbolicLink()) { // TODO } else { + // eslint-disable-next-line no-console console.warn( stringify`glob pattern ${this} unexpectedly matched the ${classify( dirent, diff --git a/workspace/reporter/src/format.ts b/workspace/reporter/src/format.ts index e351efb2..ebad1692 100644 --- a/workspace/reporter/src/format.ts +++ b/workspace/reporter/src/format.ts @@ -10,16 +10,10 @@ import type { InternalLogOptions, LeadingOption } from "./reporter.js"; const INCREMENT_LEADING = 1; class Leading { - #leading: number | undefined; #spaces: number; #prefix: string | undefined; - constructor( - leading: number | undefined, - spaces: number, - prefix: string | undefined - ) { - this.#leading = leading; + constructor(spaces: number, prefix: string | undefined) { this.#spaces = spaces; this.#prefix = prefix; } @@ -45,21 +39,17 @@ class Leading { class WrappedLines { readonly #leading: Leading; - readonly #prefix: string | undefined; readonly #lines: readonly WrappedLine[]; constructor( lines: readonly WrappedLine[], { leading, - prefix, }: { leading: Leading; - prefix: string | undefined; - } + }, ) { this.#leading = leading; - this.#prefix = prefix; this.#lines = lines; } @@ -90,7 +80,7 @@ class WrappedLine { const first = `${leading.asString()}${this.#first}`; const rest = this.#rest.map( - (line) => `${leading.asString({ extra: INCREMENT_LEADING })}${line}` + (line) => `${leading.asString({ extra: INCREMENT_LEADING })}${line}`, ); return [first, ...rest]; @@ -101,7 +91,7 @@ export const NO_LEADING = 0; export function wrapLines( string: string, - options: InternalLogOptions + options: InternalLogOptions, ): WrappedLines { const lines = string.split("\n"); const width = terminalWidth(); @@ -119,21 +109,16 @@ export function wrapLines( return new WrappedLine({ first, rest }); }); - return new WrappedLines(wrapped, { leading, prefix: options.prefix }); + return new WrappedLines(wrapped, { leading }); } const EMPTY_PREFIX_SIZE = 0; function computeColumns(string: string, options: InternalLogOptions): Leading { - const { leading, columns } = computeLeading(string, options.leading); - - return new Leading(leading, columns, options.prefix); + return new Leading(computeLeading(string, options.leading), options.prefix); } -function computeLeading( - string: string, - leading: LeadingOption -): { leading: number | undefined; columns: number } { +function computeLeading(string: string, leading: LeadingOption): number { if (leading === "auto") { const leadingWS = string.split("\n").map((line) => { const match = matchPattern<[string]>(/^(\s*)/, line); @@ -141,21 +126,17 @@ function computeLeading( return leading.length; }); - const leading = Math.max(...leadingWS); - return { leading, columns: leading * SPACES_PER_TAB }; + return Math.max(...leadingWS) * SPACES_PER_TAB; } else if ("indents" in leading) { - return { - leading: leading.indents, - columns: leading.indents * SPACES_PER_TAB, - }; + return leading.indents * SPACES_PER_TAB; } else { - return { leading: undefined, columns: leading.spaces }; + return leading.spaces; } } export function wrapIndented( fragment: IntoFragment, - options: InternalLogOptions + options: InternalLogOptions, ): string { const string = String(Fragment.from(fragment)); const wrapped = wrapLines(string, options); @@ -213,7 +194,7 @@ type EntryStyle = export function format(value: string, style: FormatStyle): Fragment { return Fragment( getStyle(style), - getIndentation(style) + wrapIndented(value, { leading: "auto" }) + getIndentation(style) + wrapIndented(value, { leading: "auto" }), ); } @@ -225,13 +206,13 @@ format.entry = ([key, value]: [string, string], style?: EntryStyle): string => { stringify`${Fragment(keyStyle, key)}: ${Fragment(valueStyle, value)}`, { leading: getLeading(style), - } + }, ); }; export function getStyle( style: EntryStyle | FormatStyle, - part?: "key" | "value" + part?: "key" | "value", ): Style { if (style === undefined) { return chalk.visible; diff --git a/workspace/reporter/src/log.ts b/workspace/reporter/src/log.ts index 91d2f87d..d4975e01 100644 --- a/workspace/reporter/src/log.ts +++ b/workspace/reporter/src/log.ts @@ -64,6 +64,7 @@ export const Style = { } as const; export function log(message: string, style: Style = Style.default): void { + // eslint-disable-next-line no-console console.info(Fragment(style, message)); } diff --git a/workspace/reporter/src/logger.ts b/workspace/reporter/src/logger.ts index 688bfab3..6308e7ad 100644 --- a/workspace/reporter/src/logger.ts +++ b/workspace/reporter/src/logger.ts @@ -1,3 +1,4 @@ +/* eslint-disable no-console */ import { getLast, withoutLast } from "@starbeam/core-utils"; import { DisplayStruct, terminalWidth } from "@starbeam-workspace/shared"; @@ -170,10 +171,6 @@ abstract class InternalLoggerState { }); } - get #leadingString(): string { - return " ".repeat(this.leading * SPACES_PER_TAB); - } - begin( message: Fragment | undefined, options: { breakBefore: boolean }, @@ -205,7 +202,6 @@ abstract class InternalLoggerState { class InternalLoggerGroupState extends InternalLoggerState { readonly #state: GroupState; - readonly #options: ReporterOptions; readonly #parent: InternalLoggerState; constructor( @@ -215,7 +211,6 @@ class InternalLoggerGroupState extends InternalLoggerState { ) { super(options); this.#state = state; - this.#options = options; this.#parent = parent; } @@ -292,15 +287,8 @@ class InternalLoggerGroupState extends InternalLoggerState { } class InternalLoggerTopState extends InternalLoggerState { - readonly #options: ReporterOptions; - readonly leading = 0; - constructor(options: ReporterOptions) { - super(options); - this.#options = options; - } - get didPrint(): never { throw Error("Cannot get didPrint in top state"); } diff --git a/workspace/reporter/src/report-error.ts b/workspace/reporter/src/report-error.ts index 20a6850b..03efa53a 100644 --- a/workspace/reporter/src/report-error.ts +++ b/workspace/reporter/src/report-error.ts @@ -1,3 +1,4 @@ +/* eslint-disable no-console */ import chalk from "chalk"; import type { ReportErrorOptions } from "./error.js"; diff --git a/workspace/reporter/src/reporter.ts b/workspace/reporter/src/reporter.ts index 3032c1e7..40f1b06d 100644 --- a/workspace/reporter/src/reporter.ts +++ b/workspace/reporter/src/reporter.ts @@ -63,7 +63,6 @@ export class Reporter implements AbstractReporter { readonly #workspace: Workspace; readonly #options: ReporterOptions; - readonly #parent: Reporter | null; readonly #logger: Logger; private constructor( @@ -73,7 +72,6 @@ export class Reporter implements AbstractReporter { ) { this.#workspace = workspace; this.#options = options; - this.#parent = parent; if (parent) { this.#logger = parent.#logger; diff --git a/workspace/scripts/src/ci.ts b/workspace/scripts/src/ci.ts index 99484847..1bf0c092 100644 --- a/workspace/scripts/src/ci.ts +++ b/workspace/scripts/src/ci.ts @@ -24,8 +24,6 @@ export const CiCommand = QueryCommand("ci", "run CI checks", { const script = scripts[type]; const shouldRun = SHOULD_RUN[type]; - console.log({ packages, shouldRun }); - const results = await workspace.check( ...packages.filter(shouldRun).map((pkg) => { const { command, cwd } = hydrateScript(script, { workspace, pkg }); diff --git a/workspace/scripts/src/support/commands/data.ts b/workspace/scripts/src/support/commands/data.ts index 75e86d7a..af55c173 100644 --- a/workspace/scripts/src/support/commands/data.ts +++ b/workspace/scripts/src/support/commands/data.ts @@ -18,13 +18,10 @@ export class BooleanFlag implements CommandParameter { return new BooleanFlag(spec); }; - readonly #spec: command.FlagSpec; readonly #name: BooleanFlagName; readonly #desc: Desc; private constructor(spec: command.FlagSpec) { - this.#spec = spec; - const [long, desc] = spec; this.#name = BooleanFlagName.of(long); this.#desc = Desc.of(desc); @@ -47,14 +44,11 @@ export class ValuedOption implements CommandParameter { return new ValuedOption(spec); }; - readonly #spec: command.ValuedOptionSpec; readonly #long: LongFlag; readonly #desc: Desc; readonly #type: Type | undefined; private constructor(spec: command.ValuedOptionSpec) { - this.#spec = spec; - const [rawLong, rawDesc, rawType] = spec; this.#long = LongFlag.of(rawLong); @@ -76,13 +70,11 @@ export class Arg implements CommandParameter { return new Arg(spec); }; - readonly #spec: command.ArgSpec; readonly #desc: ArgDesc; + // eslint-disable-next-line no-unused-private-class-members -- @todo readonly #type: Type; private constructor(spec: command.ArgSpec) { - this.#spec = spec; - const [desc, type] = spec; this.#desc = ArgDesc.of(desc); this.#type = Type.of(type); @@ -160,11 +152,9 @@ class Desc { return new Desc(spec); } - readonly #spec: string; readonly #unpacked: UnpackedDescSpec; private constructor(spec: string) { - this.#spec = spec; this.#unpacked = unpackDescSpec(spec); } @@ -182,7 +172,6 @@ class LongFlag { return new LongFlag(spec); } - readonly #spec: command.ValuedOptionSpec[0]; readonly #unpacked: { long: LongFlagString; label: string; @@ -190,7 +179,6 @@ class LongFlag { }; private constructor(spec: command.ValuedOptionSpec[0]) { - this.#spec = spec; this.#unpacked = unpackLongFlagSpec(spec); } @@ -281,14 +269,11 @@ class ArgDesc { return new ArgDesc(spec); } - readonly #spec: command.ArgDesc; readonly #label: string; readonly #required: boolean; readonly #description: string; private constructor(spec: command.ArgDesc) { - this.#spec = spec; - const { label, required, description } = unpackArgDesc(spec); this.#label = label; diff --git a/workspace/scripts/src/support/commands/options.ts b/workspace/scripts/src/support/commands/options.ts index 3e8228ff..7071da7c 100644 --- a/workspace/scripts/src/support/commands/options.ts +++ b/workspace/scripts/src/support/commands/options.ts @@ -7,6 +7,7 @@ import chalk from "chalk"; import type { Command } from "commander"; declare class CompileError<_S extends string = string, In = unknown> { + // eslint-disable-next-line no-unused-private-class-members #in: In; } diff --git a/workspace/scripts/src/support/template/update-eslint.ts b/workspace/scripts/src/support/template/update-eslint.ts index d3000dde..6c5bd123 100644 --- a/workspace/scripts/src/support/template/update-eslint.ts +++ b/workspace/scripts/src/support/template/update-eslint.ts @@ -7,36 +7,46 @@ import { UpdatePackageFn } from "./updates.js"; type ConfigOverride = NonNullable[number]; -export const updateEslint = { - demo: UpdatePackageFn((updater) => { - updater.json(".eslintrc.json", () => { - return { - root: true, - plugins: ["@starbeam"], +const BASE = { + root: true, + ignorePatterns: ["node_modules", "dist", "html", "tests"], + plugins: ["@starbeam"], +}; + +export const updateEslintrc = UpdatePackageFn((updater, options) => { + const pkg = updater.pkg; + + if (pkg.type.hasCategory("demo")) { + DEMO(updater, options); + } else { + PACKAGE(updater, options); + } +}); - overrides: [ - localEslintConfig(updater), - localEslintConfig(updater, { - files: ["vite.config.ts"], - extend: "@starbeam/loose", - }), - JSON_ESLINT_CONFIG, - ], - }; - }); - }), +const DEMO = UpdatePackageFn((updater) => { + updater.json(".eslintrc.json", () => { + return { + ...BASE, + overrides: [ + localEslintConfig(updater), + localEslintConfig(updater, { + files: ["vite.config.ts"], + extend: "@starbeam/loose", + }), + JSON_ESLINT_CONFIG, + ], + }; + }); +}); - package: UpdatePackageFn((update) => { - update.json(".eslintrc.json", () => { - return { - root: true, - ignorePatterns: ["node_modules", "dist", "html", "tests"], - plugins: ["@starbeam"], - overrides: [localEslintConfig(update), JSON_ESLINT_CONFIG], - }; - }); - }), -} as const; +const PACKAGE = UpdatePackageFn((update) => { + update.json(".eslintrc.json", () => { + return { + ...BASE, + overrides: [localEslintConfig(update), JSON_ESLINT_CONFIG], + }; + }); +}); function eslintPlugin(pkg: Package): `@starbeam/${string}` { if (pkg.moduleType === "cjs") { diff --git a/workspace/scripts/src/support/template/update-package-json.ts b/workspace/scripts/src/support/template/update-package-json.ts index 56840559..085bf13d 100644 --- a/workspace/scripts/src/support/template/update-package-json.ts +++ b/workspace/scripts/src/support/template/update-package-json.ts @@ -41,17 +41,22 @@ export function updatePackageJSON(updater: LabelledUpdater): void { ) .if(categoryIs("demo"), addDevDep("@vitest/ui")) .if(typeIs("demo:react"), insert({ "starbeam:source": "tsx" })) - .if(typeIs("tests"), insert({ "starbeam:source": "tsx" })) + .if(typeIs("tests"), insert.defaults({ "starbeam:source": "tsx" })) .if(typeIs("library:interfaces"), (m) => { switch (m.main) { case "index.ts": - return m.insert({ types: "index.ts", "starbeam:source": "ts" }); + return m + .insert({ types: "index.ts" }) + .insertDefaults({ "starbeam:source": "ts" }); case "index.d.ts": - return m.insert({ - types: "index.d.ts", - "starbeam:source": "d.ts", - "publishConfig:exports": { default: "./index.d.ts" }, - }); + return m + .insert({ + types: "index.d.ts", + "publishConfig:exports": { default: "./index.d.ts" }, + }) + .insertDefaults({ + "starbeam:source": "d.ts", + }); default: return m.report( fragment`Since the package type is library:interfaces, main must either be ${Fragment.header.inverse( @@ -60,7 +65,10 @@ export function updatePackageJSON(updater: LabelledUpdater): void { ); } }) - .if(typeIs("tests"), insert({ "starbeam:source": "ts" })) + .ifLet( + (pkg) => (pkg.type.is("tests") ? pkg.starbeam.jsx : undefined), + (jsx) => insert({ "starbeam:source": jsx ? "tsx" : "ts" }), + ) .if( typeIs("library:upstream-types"), insert({ types: "index.d.ts", "starbeam:source": "d.ts" }), @@ -120,7 +128,7 @@ const addDevDep = manifest.addDevDep(name); /** - * Add an entry to the manifest. + * Insert entries into the manifest. If the entries already exist, update them. * * If the entry is specified using a colon-separated path as its key, it is * normalized to a nested JSON path when inserted. @@ -135,6 +143,17 @@ const insert = (manifest) => manifest.insert(entries); +/** + * Initialize the manifest with the given entries. If the entry already exists, + * leave it alone. + * + * The behavior of the specified entries is the same as {@linkcode insert}. + */ +insert.defaults = + (entries: Record): Action => + (manifest) => + manifest.insertDefaults(entries); + const scripts = (scripts: Record): Action => (manifest) => @@ -213,11 +232,30 @@ class ManifestBuilder { return this; } + #initializeEntry(key: string, value: JsonValue): ManifestBuilder { + if (key in this.#current) return this; + return this.addEntry(key, value); + } + addEntry(key: string, value: JsonValue): ManifestBuilder { this.#current[key] = value; return this; } + insertDefaults(entries: Record): ManifestBuilder { + for (const [key, value] of Object.entries(entries)) { + const [parentKey, childKey] = key.split(":"); + + if (parentKey && childKey) { + this.#initializeNested([parentKey, childKey], value); + } else { + this.#initializeEntry(key, value); + } + } + + return this; + } + /** * @see {insert} */ @@ -235,6 +273,29 @@ class ManifestBuilder { return this; } + #initializeNested( + [parentKey, key]: [string, string], + value: JsonValue, + ): ManifestBuilder { + let child = this.#current[parentKey]; + + if (!child) { + child = this.#current[parentKey] = { + [key]: value, + }; + } else if (typeof child === "object" && !Array.isArray(child)) { + if (!child[key]) child[key] = value; + } else { + this.#errors.push( + fragment`Invalid ${JSON.stringify( + String(key), + )} in package.json (expected object): ${this.#pkg.name}`, + ); + } + + return this; + } + addNested( [parentKey, key]: [string, string], value: JsonValue, diff --git a/workspace/scripts/src/support/template/updates.ts b/workspace/scripts/src/support/template/updates.ts index 3db83610..c8edc8cd 100644 --- a/workspace/scripts/src/support/template/updates.ts +++ b/workspace/scripts/src/support/template/updates.ts @@ -1,7 +1,6 @@ import type { Directory, Paths } from "@starbeam-workspace/paths"; import type { Workspace } from "@starbeam-workspace/reporter"; -import { updateEslint } from "./update-eslint.js"; import type { LabelledUpdater } from "../updating/update-file.js"; export type SyncUpdatePackageFn = ( @@ -30,7 +29,6 @@ export const updateRollup = UpdatePackageFn((update) => { update.template("rollup.config.mjs"); }); -export const updateDemo = UpdatePackageFn((update, options) => { +export const updateDemo = UpdatePackageFn((update) => { update.template("vite.config.ts"); - updateEslint.demo(update, options); }); diff --git a/workspace/scripts/src/support/updating/update-file.ts b/workspace/scripts/src/support/updating/update-file.ts index c6297c42..5a2e34a6 100644 --- a/workspace/scripts/src/support/updating/update-file.ts +++ b/workspace/scripts/src/support/updating/update-file.ts @@ -70,6 +70,7 @@ export class UpdatePackage { done(): void { if (this.#emittedHeader) { + // eslint-disable-next-line no-console -- @fixme console.groupEnd(); } } @@ -348,12 +349,15 @@ export class UpdatePackages { when: UpdatePackagesFn = (condition, label) => { return { - use: (updater) => { - this.#updates.push({ - condition, - updateFn: updater, - label, - }); + use: (...updaters) => { + for (const updater of updaters) { + this.#updates.push({ + condition, + updateFn: updater, + label, + }); + } + return this; }, }; @@ -418,7 +422,7 @@ export type UpdatePackagesFn = ( condition: (pkg: Package) => boolean, label: string, ) => { - use: (updater: UpdatePackageFn) => UpdatePackages; + use: (...updaters: UpdatePackageFn[]) => UpdatePackages; }; type UpdateJsonFn = ( diff --git a/workspace/scripts/src/template.ts b/workspace/scripts/src/template.ts index 47c7764d..746d2aee 100644 --- a/workspace/scripts/src/template.ts +++ b/workspace/scripts/src/template.ts @@ -1,10 +1,10 @@ import { QueryCommand } from "./support/commands/query-command"; -import { updateEslint } from "./support/template/update-eslint"; -import { UpdatePackages } from "./support/updating/update-file.js"; +import { updateEslintrc } from "./support/template/update-eslint"; import { updatePackageJSON } from "./support/template/update-package-json.js"; import { updateTests } from "./support/template/update-tests.js"; import { updateTsconfig } from "./support/template/update-tsconfig.js"; -import { updateDemo, updateRollup } from "./support/template/updates.js"; +import { updateRollup } from "./support/template/updates.js"; +import { UpdatePackages } from "./support/updating/update-file.js"; export const TemplateCommand = QueryCommand("template", "template a package", { notes: @@ -13,18 +13,18 @@ export const TemplateCommand = QueryCommand("template", "template a package", { const updater = new UpdatePackages(workspace, packages); await updater.update((when) => { - when(() => true, "all packages").use(updatePackageJSON); + when(() => true, "all packages").use(updatePackageJSON, updateEslintrc); when((pkg) => pkg.type.is("tests"), "tests").use(updateTests); when((pkg) => pkg.isTypescript, "typescript").use(updateTsconfig); when((pkg) => pkg.type.is("library:public"), "published libraries").use( updateRollup, ); - when( - (pkg) => - pkg.sources.some((s) => s.hasFiles()) && - (pkg.type.hasCategory("library") || pkg.type.is("tests")), - "libraries", - ).use(updateEslint.package); - when((pkg) => pkg.type.hasCategory("demo"), "demos").use(updateDemo); + // when( + // (pkg) => + // pkg.sources.some((s) => s.hasFiles()) && + // (pkg.type.hasCategory("library") || pkg.type.is("tests")), + // "lintable", + // ).use(updateEslint.package); + // when((pkg) => pkg.type.hasCategory("demo"), "demos").use(updateDemo); }); }); diff --git a/workspace/shared/src/type-magic.ts b/workspace/shared/src/type-magic.ts index cdb3919b..6ddfae45 100644 --- a/workspace/shared/src/type-magic.ts +++ b/workspace/shared/src/type-magic.ts @@ -525,14 +525,14 @@ export class Result { } } - map>( - callback: (value: T) => R, - ): LiftResult { + map( + callback: (value: T) => IntoResult, + ): Result { switch (this.#variant.status) { case "ok": - return Result.ok(callback(this.#variant.value)) as LiftResult; + return Result.ok(callback(this.#variant.value)) as Result; case "err": - return Result.err(this.#variant.reason) as LiftResult; + return Result.err(this.#variant.reason) as Result; } } diff --git a/workspace/test-utils/package.json b/workspace/test-utils/package.json index ca9246e7..44c6e6ce 100644 --- a/workspace/test-utils/package.json +++ b/workspace/test-utils/package.json @@ -18,7 +18,9 @@ "main": "dist/index.cjs", "types": "dist/index.d.ts" }, - "starbeam:type": "library:test-support", + "starbeam": { + "type": "library:test-support" + }, "scripts": { "test:lint": "eslint . --max-warnings 0", "test:types": "tsc -b" diff --git a/workspace/test-utils/src/actions.ts b/workspace/test-utils/src/actions.ts index c37410a3..8b94789a 100644 --- a/workspace/test-utils/src/actions.ts +++ b/workspace/test-utils/src/actions.ts @@ -113,10 +113,12 @@ export function withCause( try { return block(); } catch (e: unknown) { + // eslint-disable-next-line no-console console.warn(e); let error; if (isAssertionError(e)) { error = e; + // eslint-disable-next-line no-console console.log(error.stack); error.cause = cause(); } else if (e instanceof Error) { diff --git a/workspace/utils/src/consolidate.ts b/workspace/utils/src/consolidate.ts index 31be1e84..6e17c2a8 100644 --- a/workspace/utils/src/consolidate.ts +++ b/workspace/utils/src/consolidate.ts @@ -1,9 +1,5 @@ import type { JsonObject } from "@starbeam-workspace/json"; -import { - type AbstractReporter, - fragment, - type IntoFragment, -} from "@starbeam-workspace/reporter"; +import { fragment } from "@starbeam-workspace/reporter"; import { Result } from "@starbeam-workspace/shared"; import { fallible } from "./fallible.js"; @@ -42,18 +38,7 @@ export const consolidate = fallible((object: JsonObject, parent: string) => { if (import.meta.vitest) { const { test, expect } = import.meta.vitest; - type ReportedError = Error | IntoFragment; - - class TestReporter implements AbstractReporter { - constructor(readonly errors: ReportedError[] = []) {} - readonly reportError = (error: ReportedError): void => { - this.errors.push(error); - }; - } - test("consolidate flat keys", () => { - const reporter = new TestReporter(); - expect( consolidate( { @@ -74,13 +59,9 @@ if (import.meta.vitest) { }, }), ); - - expect(reporter.errors).toEqual([]); }); test("consolidate mixed keys", () => { - const reporter = new TestReporter(); - expect( consolidate( { @@ -101,13 +82,9 @@ if (import.meta.vitest) { }, }), ); - - expect(reporter.errors).toEqual([]); }); test("consolidate non-object keys is an error", () => { - const reporter = new TestReporter(); - expect( consolidate( { diff --git a/workspace/workspace/src/workspace.ts b/workspace/workspace/src/workspace.ts index d185b57f..11d0ce57 100644 --- a/workspace/workspace/src/workspace.ts +++ b/workspace/workspace/src/workspace.ts @@ -37,15 +37,11 @@ export class Workspace implements IWorkspace { return new Workspace(Paths.root(root), options); } - readonly #verbose: boolean; - readonly #stylish: boolean; readonly #paths: Paths; readonly #reporter: Reporter; constructor(paths: Paths, options: ReporterOptions) { this.#paths = paths; - this.#verbose = options.verbose; - this.#stylish = options.stylish; this.#reporter = Reporter.root(this, options); }