AI-native design editor. Open-source Figma alternative.
fix: make published packages load under Bun 1.3 and import Core's types (#1408)
Danila Poyarkovfcd4e00c5d08
diff --git a/bun.lock b/bun.lockindex 4ac4c1d5d..5751b0bda 100644--- a/bun.lock+++ b/bun.lock@@ -302,6 +302,12 @@"typescript": "~5.8.3","unplugin-raw": "^0.7.0",},+ "peerDependencies": {+ "ai": "^7.0.127",+ },+ "optionalPeers": [+ "ai",+ ],},"packages/design-jsx": {"name": "@open-pencil/design-jsx",diff --git a/changes/1408/changed.md b/changes/1408/changed.mdnew file mode 100644index 000000000..c28bbf338--- /dev/null+++ b/changes/1408/changed.md@@ -0,0 +1 @@+- `@open-pencil/core` declares `ai` as an optional peer dependency: `toolsToAI` uses the `ai` you install instead of bundling a copy of its types.diff --git a/changes/1408/fixed.md b/changes/1408/fixed.mdnew file mode 100644index 000000000..5686d8754--- /dev/null+++ b/changes/1408/fixed.md@@ -0,0 +1 @@+- `@open-pencil/dom-css`, `@open-pencil/design-jsx`, `@open-pencil/emit`, and `@open-pencil/cli` load under Bun 1.3 again, and so does `@open-pencil/core/io`, which imports Design JSX; their internal imports named files without an extension, which Bun 1.3 does not add (#1397).diff --git a/packages/cli/package.json b/packages/cli/package.jsonindex d61b01599..088fc2a5d 100644--- a/packages/cli/package.json+++ b/packages/cli/package.json@@ -4,8 +4,8 @@"license": "MIT","type": "module","imports": {- "#cli/*": "./src/*",- "#cli-tests/*": "./tests/*"+ "#cli/*": "./src/*.ts",+ "#cli-tests/*": "./tests/*.ts"},"bin": {"openpencil": "./bin/openpencil.js"diff --git a/packages/cli/tests/commands/export/app.test.ts b/packages/cli/tests/commands/export/app.test.tsindex f8f71a6a6..4f5c21dc3 100644--- a/packages/cli/tests/commands/export/app.test.ts+++ b/packages/cli/tests/commands/export/app.test.ts@@ -11,7 +11,7 @@ import * as v from 'valibot'import type { AutomationDocumentSummary } from '@open-pencil/core/rpc'import { removeDiscoveryFile, writeDiscoveryFile } from '@open-pencil/mcp/discovery'-import exportCommand from '#cli/commands/export'+import exportCommand from '#cli/commands/export/index'const rpcRequestSchema = v.pipe(v.string(),diff --git a/packages/core/package.json b/packages/core/package.jsonindex bb7733b13..12591797f 100644--- a/packages/core/package.json+++ b/packages/core/package.json@@ -221,5 +221,13 @@"@types/rbush": "^4.0.0","typescript": "~5.8.3","unplugin-raw": "^0.7.0"+ },+ "peerDependencies": {+ "ai": "^7.0.127"+ },+ "peerDependenciesMeta": {+ "ai": {+ "optional": true+ }}}diff --git a/packages/core/src/editor/create.ts b/packages/core/src/editor/create.tsindex 7ce7264e4..b28935326 100644--- a/packages/core/src/editor/create.ts+++ b/packages/core/src/editor/create.ts@@ -547,4 +547,10 @@ export function createEditor(options?: EditorOptions) {return guardReadOnly(editor, () => state.readOnly)}-export type Editor = ReturnType<typeof createEditor>+/**+ * The editor `createEditor` returns. An interface rather than an alias, so declarations that+ * mention it, such as a Vue composable's inferred return type, name it instead of spelling out+ * its members, some of whose types are internal to Core.+ */+// eslint-disable-next-line typescript/no-empty-object-type -- The interface is the point: an alias's members are spelled out in emitted declarations.+export interface Editor extends ReturnType<typeof createEditor> {}diff --git a/packages/core/src/editor/index.ts b/packages/core/src/editor/index.tsindex 6519bb7d9..3735930ff 100644--- a/packages/core/src/editor/index.ts+++ b/packages/core/src/editor/index.ts@@ -36,6 +36,13 @@ export type { PlayState } from './play/actions'export type { ShaderRasterizer } from './shaders/types'export type { ShaderPaintList } from './shaders/actions'export type { Editor } from './create'+export type {+ PageSwitchProgress,+ PreparedPage,+ PreparePageOptions,+ SwitchPageOptions+} from './pages'+export type { ExposableComponentField } from './components/authoring/context'export type { VariableTokenFields } from './variables'export { reapplyInstanceComponentProperties } from './components/properties'export { createGuideActions } from './guides'diff --git a/packages/core/tsdown.config.ts b/packages/core/tsdown.config.tsindex a479762a8..4a514e6ff 100644--- a/packages/core/tsdown.config.ts+++ b/packages/core/tsdown.config.ts@@ -5,6 +5,7 @@ import raw from 'unplugin-raw/rolldown'const packageJSON = JSON.parse(readFileSync(new URL('./package.json', import.meta.url), 'utf8')) as {dependencies?: Record<string, string>+ peerDependencies?: Record<string, string>}export default defineConfig({@@ -19,7 +20,10 @@ export default defineConfig({clean: true,outDir: './dist',deps: {- neverBundle: [...Object.keys(packageJSON.dependencies ?? {}), /^node:/],+ neverBundle: [+ ...Object.keys({ ...packageJSON.dependencies, ...packageJSON.peerDependencies }),+ /^node:/+ ],onlyBundle: false}})diff --git a/packages/design-jsx/package.json b/packages/design-jsx/package.jsonindex 1da7ff913..dc0a1423a 100644--- a/packages/design-jsx/package.json+++ b/packages/design-jsx/package.json@@ -5,9 +5,9 @@"type": "module","imports": {"#design-jsx/*": {- "types": "./src/*",- "bun": "./src/*",- "default": "./dist/*"+ "types": "./src/*.ts",+ "bun": "./src/*.ts",+ "default": "./dist/*.js"}},"exports": {diff --git a/packages/dom-css/package.json b/packages/dom-css/package.jsonindex 2f6062c6d..c411607f3 100644--- a/packages/dom-css/package.json+++ b/packages/dom-css/package.json@@ -5,9 +5,9 @@"type": "module","imports": {"#dom-css/*": {- "types": "./src/*",- "bun": "./src/*",- "default": "./dist/*"+ "types": "./src/*.ts",+ "bun": "./src/*.ts",+ "default": "./dist/*.js"},"#dom-css-tests/*": "./tests/*.ts"},diff --git a/packages/dom-css/tests/import/jsx.test.tsx b/packages/dom-css/tests/import/jsx.test.tsxindex 37ed9920a..35c8810ce 100644--- a/packages/dom-css/tests/import/jsx.test.tsx+++ b/packages/dom-css/tests/import/jsx.test.tsx@@ -1,11 +1,11 @@/** @jsxImportSource @open-pencil/dom-css */import { describe, expect, it } from 'bun:test'+import { serializeHTML } from '#dom-css/export/index'import {createHeadlessCSSRuntime,jsxToDesignDocument,jsxToSceneGraph,- serializeHTML,tailwindJSXToSceneGraph} from '#dom-css/index'diff --git a/packages/emit/package.json b/packages/emit/package.jsonindex e9e89dc2b..4ca109360 100644--- a/packages/emit/package.json+++ b/packages/emit/package.json@@ -19,9 +19,9 @@"types": "./dist/index.d.ts","imports": {"#emit/*": {- "types": "./src/*",- "bun": "./src/*",- "default": "./dist/*"+ "types": "./src/*.ts",+ "bun": "./src/*.ts",+ "default": "./dist/*.js"}},"exports": {diff --git a/packages/vue/tsconfig.build.json b/packages/vue/tsconfig.build.jsonnew file mode 100644index 000000000..b84224a13--- /dev/null+++ b/packages/vue/tsconfig.build.json@@ -0,0 +1,10 @@+{+ "extends": "./tsconfig.json",+ "compilerOptions": {+ "rootDir": "src",+ "paths": {+ "#vue/*": ["./src/*", "./src/*.vue"]+ }+ },+ "include": ["src/**/*.ts", "src/**/*.vue", "src/**/*.d.ts"]+}diff --git a/packages/vue/tsdown.config.ts b/packages/vue/tsdown.config.tsindex c2678fd5a..f4e746e44 100644--- a/packages/vue/tsdown.config.ts+++ b/packages/vue/tsdown.config.ts@@ -18,8 +18,8 @@ const external = Object.keys({ ...packageJSON.dependencies, ...packageJSON.peerD.flatMap((name) => [name, new RegExp(`^${name.replaceAll('/', '\\/')}/`)])/**- * Where an unbundled module is written: bundled packages keep their install path, and npm never- * packs a folder named `node_modules`, so they go under `vendor/` instead.+ * Where an unbundled module is written: bundled packages would keep their install path under+ * `node_modules`, which installed copies of the package did not carry, so they go under `vendor/`.*/function outputPath(chunk: { name: string }): string {// A `?raw` import is a module of its own; its query would read as a URL query to Node.@@ -138,6 +138,9 @@ export default defineConfig({'testing/index': './src/testing/index.ts','variables/index': './src/variables/index.ts'},+ // The workspace tsconfig maps Core to its source so unbuilt code runs under Bun; the build+ // resolves Core as a consumer does, so declarations import its types instead of copying them.+ tsconfig: 'tsconfig.build.json',platform: 'browser',format: ['esm'],dts: {diff --git a/tools/checks/package-quality/src/checks/contents.ts b/tools/checks/package-quality/src/checks/contents.tsnew file mode 100644index 000000000..f51345be2--- /dev/null+++ b/tools/checks/package-quality/src/checks/contents.ts@@ -0,0 +1,58 @@+import { readdir } from 'node:fs/promises'+import { join } from 'node:path'++import {+ discoverPublicPackages,+ type PackageDiagnostic+} from '@open-pencil/package-artifacts-tools'++/**+ * Build output a package must not ship: another workspace package's source, which copies that+ * package's types into this one instead of importing them, and a `node_modules` folder, a copy+ * of an installed package that should be a dependency the package imports.+ */+export function packageContentDiagnostics(+ packageName: string,+ files: readonly string[]+): PackageDiagnostic[] {+ const paths = files.map((file) => file.replaceAll('\\', '/'))+ const diagnostics: PackageDiagnostic[] = []+ if (paths.some((file) => file.startsWith('packages/'))) {+ diagnostics.push({+ packageName,+ field: 'dist',+ message: "holds another workspace package's source under dist/packages; import its types"+ })+ }+ if (paths.some((file) => file.split('/').includes('node_modules'))) {+ diagnostics.push({+ packageName,+ field: 'dist',+ message: 'holds a copy of an installed package under node_modules; declare it and import it'+ })+ }+ return diagnostics+}++async function builtFiles(directory: string): Promise<string[]> {+ try {+ const entries = await readdir(directory, { recursive: true, withFileTypes: true })+ return entries+ .filter((entry) => entry.isFile())+ .map((entry) => join(entry.parentPath, entry.name).slice(directory.length + 1))+ } catch (error) {+ // A package not built yet has nothing to check; Publint reports the missing entries.+ if (error instanceof Error && 'code' in error && error.code === 'ENOENT') return []+ throw error+ }+}++export async function validatePackageContents(root: string): Promise<PackageDiagnostic[]> {+ const packages = await discoverPublicPackages(root)+ const diagnostics = await Promise.all(+ packages.map(async ({ directory, manifest }) =>+ packageContentDiagnostics(manifest.name, await builtFiles(join(root, directory, 'dist')))+ )+ )+ return diagnostics.flat()+}diff --git a/tools/checks/package-quality/src/commands.ts b/tools/checks/package-quality/src/commands.tsindex 1f9978df3..e9bfe2120 100644--- a/tools/checks/package-quality/src/commands.ts+++ b/tools/checks/package-quality/src/commands.ts@@ -3,6 +3,7 @@ import { defineCommand } from 'citty'import { resolveWorkspaceRoot } from '@open-pencil/package-artifacts-tools'import { checkTypes } from './checks/attw'+import { validatePackageContents } from './checks/contents'import { validateEntryExports } from './checks/exports'import { formatPackageDiagnostics, validatePackageMetadata } from './checks/metadata'import { checkPublint } from './checks/publint'@@ -16,9 +17,11 @@ async function check(root: string): Promise<void> {if (diagnostics.length > 0) throw new Error(formatPackageDiagnostics(diagnostics))const exportDiagnostics = await measurePhase('exports', () => validateEntryExports(root))if (exportDiagnostics.length > 0) throw new Error(formatPackageDiagnostics(exportDiagnostics))+ const contentDiagnostics = await measurePhase('contents', () => validatePackageContents(root))+ if (contentDiagnostics.length > 0) throw new Error(formatPackageDiagnostics(contentDiagnostics))await measurePhase('Publint', () => checkPublint(root))await measurePhase('ATTW', () => checkTypes(root))- console.log('Package metadata, exports, Publint and ATTW checks passed.')+ console.log('Package metadata, exports, contents, Publint and ATTW checks passed.')}export const checkCommand = defineCommand({diff --git a/tools/checks/package-quality/tests/contents.test.ts b/tools/checks/package-quality/tests/contents.test.tsnew file mode 100644index 000000000..a1ed5a509--- /dev/null+++ b/tools/checks/package-quality/tests/contents.test.ts@@ -0,0 +1,36 @@+import { describe, expect, test } from 'bun:test'++import { packageContentDiagnostics } from '#package-quality/checks/contents'++describe('package contents', () => {+ test('a package built from its own source passes', () => {+ expect(packageContentDiagnostics('@x/a', ['index.js', 'vendor/lib/index.js'])).toEqual([])+ })++ test("another workspace package's source fails", () => {+ expect(packageContentDiagnostics('@x/a', ['packages/core/src/editor/index.d.ts'])).toEqual([+ {+ packageName: '@x/a',+ field: 'dist',+ message: "holds another workspace package's source under dist/packages; import its types"+ }+ ])+ })++ test('Windows separators are read as /', () => {+ expect(+ packageContentDiagnostics('@x/a', [+ 'packages\\core\\src\\index.d.ts',+ 'node_modules\\lib\\a.js'+ ])+ ).toHaveLength(2)+ })++ test('a node_modules folder fails', () => {+ expect(+ packageContentDiagnostics('@x/a', ['node_modules/.bun/lib/index.js']).map(+ ({ message }) => message+ )+ ).toEqual(['holds a copy of an installed package under node_modules; declare it and import it'])+ })+})diff --git a/tools/dev/unit-tests/src/shards.ts b/tools/dev/unit-tests/src/shards.tsindex 3800352a4..d881ed9a6 100644--- a/tools/dev/unit-tests/src/shards.ts+++ b/tools/dev/unit-tests/src/shards.ts@@ -138,7 +138,7 @@ async function listTestFilesInPath(path: string): Promise<string[]> {entries.map(async (entry) => {const childPath = join(path, entry.name)if (entry.isDirectory()) return listTestFilesInPath(childPath)- if (entry.isFile() && entry.name.endsWith('.test.ts')) return [normalizePath(childPath)]+ if (entry.isFile() && /\.test\.tsx?$/.test(entry.name)) return [normalizePath(childPath)]return []}))diff --git a/tools/dev/unit-tests/tests/shards.test.ts b/tools/dev/unit-tests/tests/shards.test.tsindex d5db1732d..1f15af4ee 100644--- a/tools/dev/unit-tests/tests/shards.test.ts+++ b/tools/dev/unit-tests/tests/shards.test.ts@@ -21,10 +21,10 @@ async function discover(pattern: string): Promise<string[]> {test('every app, engine and package-local test belongs to exactly one shard', async () => {const discovered = [- ...(await discover('tests/app/**/*.test.ts')),- ...(await discover('tests/integration/**/*.test.ts')),- ...(await discover('tests/engine/**/*.test.ts')),- ...(await discover('packages/*/tests/**/*.test.ts'))+ ...(await discover('tests/app/**/*.test.{ts,tsx}')),+ ...(await discover('tests/integration/**/*.test.{ts,tsx}')),+ ...(await discover('tests/engine/**/*.test.{ts,tsx}')),+ ...(await discover('packages/*/tests/**/*.test.{ts,tsx}'))].filter((file) => !OWN_SUITES.some((suite) => file.startsWith(suite)))const paths = pathsForUnitTestGroup('all')const invalidAssignments = discovered.flatMap((file) => {diff --git a/tools/release/package-artifacts/src/manifest/exports.ts b/tools/release/package-artifacts/src/manifest/exports.tsindex a380164aa..28932a779 100644--- a/tools/release/package-artifacts/src/manifest/exports.ts+++ b/tools/release/package-artifacts/src/manifest/exports.ts@@ -112,6 +112,14 @@ export function validateManifest(manifest: PackageManifest): PackageDiagnostic[]if (entry.condition === 'types') validateTypes(entry.field, entry.target)else validateRuntime(entry.field, entry.target, entry.condition)}+ // A local wildcard target is used as written: Bun 1.3 adds no extension, so `./src/*` names no+ // file. A target naming another package resolves through that package's exports instead.+ for (const entry of collectExportTargets(manifest.imports, ['imports'])) {+ const local = entry.target.startsWith('./')+ if (local && entry.target.includes('*') && !/\.[a-z]+$/i.test(entry.target)) {+ report(entry.field, `wildcard target names no extension (${entry.target})`)+ }+ }if (manifest.publishConfig &&('exports' in manifest.publishConfig ||diff --git a/tools/release/package-artifacts/tests/exports.test.ts b/tools/release/package-artifacts/tests/exports.test.tsindex ec9e284d3..e4dc913af 100644--- a/tools/release/package-artifacts/tests/exports.test.ts+++ b/tools/release/package-artifacts/tests/exports.test.ts@@ -58,4 +58,31 @@ describe('export metadata', () => {'runtime target is a declaration file (./dist/index.d.ts)'])})++ test('rejects wildcard import targets without an extension', () => {+ const diagnostics = validateManifest({+ ...validManifest,+ imports: {+ '#example/*': { types: './dist/*.d.ts', bun: './src/*', default: './dist/*.js' }+ }+ })+ expect(diagnostics.map(({ message }) => message)).toEqual([+ 'wildcard target names no extension (./src/*)'+ ])+ })++ test('accepts a wildcard import target that names an index file', () => {+ expect(+ validateManifest({+ ...validManifest,+ imports: { '#example/*': { types: './dist/*/index.d.ts', default: './dist/*/index.js' } }+ })+ ).toEqual([])+ })++ test('accepts a wildcard import target in another package', () => {+ expect(validateManifest({ ...validManifest, imports: { '#icons/*': 'icon-pack/*' } })).toEqual(+ []+ )+ })})diff --git a/tsconfig.tests.json b/tsconfig.tests.jsonindex 48a76aa00..c58803172 100644--- a/tsconfig.tests.json+++ b/tsconfig.tests.json@@ -145,6 +145,7 @@"packages/design-jsx/src/global.d.ts","tests/**/*.ts","packages/*/tests/**/*.ts",+ "packages/*/tests/**/*.tsx","tests/helpers/tauri/native-global.d.ts"],"exclude": [