diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 53d37803fc..85af63dbd9 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -220,7 +220,6 @@ jobs: run: > pnpm --filter @lynx-js/react-runtime - --filter @lynx-js/react-worklet-runtime --filter @lynx-js/react-transform run test --reporter=github-actions diff --git a/eslint.config.js b/eslint.config.js index 4c8b0c9301..3d97fbdd79 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -87,6 +87,8 @@ export default tseslint.config( 'packages/react/runtime/jsx-runtime/**', 'packages/react/runtime/lazy/**', 'packages/react/runtime/lepus/**', + // Generated worklet bundles are published assets, not source files. + 'packages/react/runtime/worklet-runtime/**', 'packages/react/runtime/src/renderToOpcodes/**', 'packages/react/runtime/types/**', diff --git a/packages/react/package.json b/packages/react/package.json index 344a96911d..df04980722 100644 --- a/packages/react/package.json +++ b/packages/react/package.json @@ -77,11 +77,11 @@ }, "./worklet-runtime": { "types": "./runtime/lib/worklet-runtime/index.d.ts", - "default": "./worklet-runtime/dist/main.js" + "default": "./runtime/worklet-runtime/main.js" }, "./worklet-dev-runtime": { "types": "./runtime/lib/worklet-runtime/index.d.ts", - "default": "./worklet-runtime/dist/dev.js" + "default": "./runtime/worklet-runtime/dev.js" }, "./worklet-runtime/bindings": { "types": "./runtime/lib/worklet-runtime/bindings/index.d.ts", @@ -163,7 +163,6 @@ "transform", "types", "docs", - "worklet-runtime", "testing-library", "CHANGELOG.md", "internal.js", @@ -171,6 +170,7 @@ "README.zh.md" ], "scripts": { + "build": "rslib build", "api-extractor": "api-extractor run --verbose" }, "dependencies": { diff --git a/packages/react/worklet-runtime/rslib.config.ts b/packages/react/rslib.config.ts similarity index 69% rename from packages/react/worklet-runtime/rslib.config.ts rename to packages/react/rslib.config.ts index 4fe4496a4d..7d74c4d49f 100644 --- a/packages/react/worklet-runtime/rslib.config.ts +++ b/packages/react/rslib.config.ts @@ -1,4 +1,4 @@ -// Copyright 2025 The Lynx Authors. All rights reserved. +// Copyright 2026 The Lynx Authors. All rights reserved. // Licensed under the Apache License Version 2.0 that can be found in the // LICENSE file in the root directory of this source tree. @@ -15,13 +15,16 @@ export default defineConfig({ __DEV__: 'true', }, entry: { - dev: '../runtime/src/worklet-runtime/index.ts', + dev: './runtime/src/worklet-runtime/index.ts', }, }, output: { sourceMap: { js: 'inline-source-map', }, + distPath: { + root: './runtime/worklet-runtime', + }, }, }, { @@ -33,11 +36,14 @@ export default defineConfig({ __DEV__: 'false', }, entry: { - main: '../runtime/src/worklet-runtime/index.ts', + main: './runtime/src/worklet-runtime/index.ts', }, }, output: { minify: true, + distPath: { + root: './runtime/worklet-runtime', + }, }, }, ], diff --git a/packages/react/runtime/.gitignore b/packages/react/runtime/.gitignore index a31109f1e0..0411384c6f 100644 --- a/packages/react/runtime/.gitignore +++ b/packages/react/runtime/.gitignore @@ -1,3 +1,4 @@ coverage/ lib/ +/worklet-runtime/ !debug diff --git a/packages/react/runtime/.npmignore b/packages/react/runtime/.npmignore index df07175b65..491353243f 100644 --- a/packages/react/runtime/.npmignore +++ b/packages/react/runtime/.npmignore @@ -11,3 +11,5 @@ !lepus/* !lib/** !lib/* +!worklet-runtime/* +!worklet-runtime/** diff --git a/packages/react/runtime/package.json b/packages/react/runtime/package.json index bb475a7e03..8b638fb8aa 100644 --- a/packages/react/runtime/package.json +++ b/packages/react/runtime/package.json @@ -15,6 +15,7 @@ "src" ], "scripts": { + "build": "tsc --build", "test": "vitest run --coverage" }, "devDependencies": { diff --git a/packages/react/runtime/src/worklet-runtime/api/lepusQuerySelector.ts b/packages/react/runtime/src/worklet-runtime/api/lepusQuerySelector.ts index 34bce80f39..aea8805d70 100644 --- a/packages/react/runtime/src/worklet-runtime/api/lepusQuerySelector.ts +++ b/packages/react/runtime/src/worklet-runtime/api/lepusQuerySelector.ts @@ -13,12 +13,20 @@ class PageElement { } export function querySelector(cssSelector: string): Element | null { - const element = __QuerySelector(PageElement.get(), cssSelector, {}); + const pageElement = PageElement.get(); + if (!pageElement) { + return null; + } + const element = __QuerySelector(pageElement, cssSelector, {}); return element ? new Element(element) : null; } export function querySelectorAll(cssSelector: string): Element[] { - return __QuerySelectorAll(PageElement.get(), cssSelector, {}).map( + const pageElement = PageElement.get(); + if (!pageElement) { + return []; + } + return __QuerySelectorAll(pageElement, cssSelector, {}).map( (element) => { return new Element(element); }, diff --git a/packages/react/runtime/tsconfig.json b/packages/react/runtime/tsconfig.json index 3c8b747a49..0d3d082bd4 100644 --- a/packages/react/runtime/tsconfig.json +++ b/packages/react/runtime/tsconfig.json @@ -3,14 +3,19 @@ "compilerOptions": { "composite": true, "outDir": "./lib", + // Keep incremental metadata under lib so clearing generated outputs also + // invalidates the runtime build cache for worklet-runtime artifacts. + "tsBuildInfoFile": "./lib/tsconfig.tsbuildinfo", "baseUrl": "./", + "paths": { + // Resolve the public bindings specifier back to source while building + // runtime itself, so the emitted lib output never becomes its own input. + "@lynx-js/react/worklet-runtime/bindings": ["./src/worklet-runtime/bindings/index.ts"], + }, "rootDir": "./src", "jsx": "react-jsx", "jsxImportSource": "./", }, - "references": [{ - "path": "../worklet-runtime/tsconfig.json", - }], "include": [ "debug", "jsx-dev-runtime", diff --git a/packages/react/worklet-runtime/turbo.json b/packages/react/runtime/turbo.json similarity index 51% rename from packages/react/worklet-runtime/turbo.json rename to packages/react/runtime/turbo.json index 2c119d4795..2dbadf76f9 100644 --- a/packages/react/worklet-runtime/turbo.json +++ b/packages/react/runtime/turbo.json @@ -5,11 +5,16 @@ "build": { "dependsOn": [], "inputs": [ - "../runtime/src/worklet-runtime/**", - "rslib.config.ts" + "debug/**", + "jsx-dev-runtime/**", + "jsx-runtime/**", + "lepus/**", + "src/**", + "types/**", + "tsconfig.json" ], "outputs": [ - "dist" + "lib/**" ] } } diff --git a/packages/react/runtime/vitest.config.ts b/packages/react/runtime/vitest.config.ts index efdc4773af..38178d3d1d 100644 --- a/packages/react/runtime/vitest.config.ts +++ b/packages/react/runtime/vitest.config.ts @@ -84,6 +84,7 @@ export default defineConfig({ 'vitest.config.ts', '__test__/utils/**', 'lib/**', + 'worklet-runtime/**', 'src/index.ts', 'src/lynx.ts', 'src/root.ts', diff --git a/packages/react/tsconfig.json b/packages/react/tsconfig.json index 0e2718eb0e..1fc6975b69 100644 --- a/packages/react/tsconfig.json +++ b/packages/react/tsconfig.json @@ -11,9 +11,6 @@ { "path": "./components/tsconfig.json", }, - { - "path": "./worklet-runtime/tsconfig.json", - }, { "path": "./transform/rspack-napi/tsconfig.json", } diff --git a/packages/react/turbo.json b/packages/react/turbo.json index de23051e9d..87532b65c8 100644 --- a/packages/react/turbo.json +++ b/packages/react/turbo.json @@ -5,10 +5,17 @@ "build": { "dependsOn": [ "@lynx-js/react-refresh#build", + "@lynx-js/react-runtime#build", "@lynx-js/react-transform#build:wasm", - "@lynx-js/react-worklet-runtime#build", "@lynx-js/reactlynx-testing-library#build", "@lynx-js/testing-environment#build" + ], + "inputs": [ + "runtime/src/worklet-runtime/**", + "rslib.config.ts" + ], + "outputs": [ + "runtime/worklet-runtime/**" ] } } diff --git a/packages/react/worklet-runtime/.gitignore b/packages/react/worklet-runtime/.gitignore deleted file mode 100644 index 7fc136e6c5..0000000000 --- a/packages/react/worklet-runtime/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -coverage/ -dist/ -lib/ diff --git a/packages/react/worklet-runtime/.npmignore b/packages/react/worklet-runtime/.npmignore deleted file mode 100644 index 7b813de382..0000000000 --- a/packages/react/worklet-runtime/.npmignore +++ /dev/null @@ -1,4 +0,0 @@ -* -!dist/* -!lib/** -!lib/* diff --git a/packages/react/worklet-runtime/__test__/runtimeSourceLayout.test.js b/packages/react/worklet-runtime/__test__/runtimeSourceLayout.test.js deleted file mode 100644 index 0e07a73d29..0000000000 --- a/packages/react/worklet-runtime/__test__/runtimeSourceLayout.test.js +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright 2026 The Lynx Authors. All rights reserved. -// Licensed under the Apache License Version 2.0 that can be found in the -// LICENSE file in the root directory of this source tree. -import fs from 'node:fs'; -import path from 'node:path'; -import { fileURLToPath } from 'node:url'; - -import { describe, expect, test } from 'vitest'; - -const __dirname = path.dirname(fileURLToPath(import.meta.url)); -const reactPackagesDir = path.resolve(__dirname, '..', '..'); -const reactPackageJsonPath = path.join(reactPackagesDir, 'package.json'); -const workletRuntimePackageJsonPath = path.join( - reactPackagesDir, - 'worklet-runtime', - 'package.json', -); -const runtimeWorkletRuntimeDir = path.join( - reactPackagesDir, - 'runtime', - 'src', - 'worklet-runtime', -); - -describe('runtime-local worklet-runtime source layout', () => { - test('stores the real implementation under runtime/src/worklet-runtime', () => { - const expectedFiles = [ - 'index.ts', - path.join('bindings', 'index.ts'), - path.join('api', 'lynxApi.ts'), - 'workletRuntime.ts', - ]; - - for (const file of expectedFiles) { - expect(fs.existsSync(path.join(runtimeWorkletRuntimeDir, file))).toBe(true); - } - }); - - test('keeps the shell package focused on dist-only worklet bundle outputs', () => { - const workletRuntimePackageJson = JSON.parse( - fs.readFileSync(workletRuntimePackageJsonPath, 'utf8'), - ); - - expect(workletRuntimePackageJson.exports['.']).toEqual({ - default: './dist/main.js', - }); - expect(workletRuntimePackageJson.exports['./dev']).toEqual({ - default: './dist/dev.js', - }); - expect(workletRuntimePackageJson.main).toBe('dist/main.js'); - expect(workletRuntimePackageJson.module).toBe('dist/main.js'); - expect( - fs.existsSync(path.join(reactPackagesDir, 'worklet-runtime', 'src')), - ).toBe(false); - }); - - test('preserves the public worklet-runtime export targets on @lynx-js/react', () => { - const reactPackageJson = JSON.parse(fs.readFileSync(reactPackageJsonPath, 'utf8')); - - expect(reactPackageJson.exports['./worklet-runtime']).toEqual({ - types: './runtime/lib/worklet-runtime/index.d.ts', - default: './worklet-runtime/dist/main.js', - }); - expect(reactPackageJson.exports['./worklet-dev-runtime']).toEqual({ - types: './runtime/lib/worklet-runtime/index.d.ts', - default: './worklet-runtime/dist/dev.js', - }); - expect(reactPackageJson.exports['./worklet-runtime/bindings']).toEqual({ - types: './runtime/lib/worklet-runtime/bindings/index.d.ts', - default: './runtime/lib/worklet-runtime/bindings/index.js', - }); - }); -}); diff --git a/packages/react/worklet-runtime/package.json b/packages/react/worklet-runtime/package.json deleted file mode 100644 index 5c7285cb3c..0000000000 --- a/packages/react/worklet-runtime/package.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "name": "@lynx-js/react-worklet-runtime", - "version": "0.0.1", - "private": true, - "description": "Worklet Runtime for ReactLynx 3.0", - "type": "module", - "exports": { - ".": { - "default": "./dist/main.js" - }, - "./dev": { - "default": "./dist/dev.js" - } - }, - "main": "dist/main.js", - "module": "dist/main.js", - "files": [ - "CHANGELOG.md", - "dist" - ], - "scripts": { - "build": "rslib build", - "test": "vitest run --coverage" - }, - "devDependencies": { - "@lynx-js/types": "3.7.0" - } -} diff --git a/packages/react/worklet-runtime/tsconfig.json b/packages/react/worklet-runtime/tsconfig.json deleted file mode 100644 index 0e1fbb9381..0000000000 --- a/packages/react/worklet-runtime/tsconfig.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "extends": "../../../tsconfig.json", - "compilerOptions": { - "noEmit": false, - "outDir": "../runtime/lib/worklet-runtime", - "rootDir": "../runtime/src/worklet-runtime", - "stripInternal": true, - "target": "ESNext", - "lib": ["es2021"], - "module": "Node16", - "moduleResolution": "Node16", - "resolveJsonModule": true, - "composite": true, - }, - "include": ["../runtime/src/worklet-runtime/**/*"], -} diff --git a/packages/react/worklet-runtime/vitest.config.ts b/packages/react/worklet-runtime/vitest.config.ts deleted file mode 100644 index 75adf372f0..0000000000 --- a/packages/react/worklet-runtime/vitest.config.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { defineConfig } from 'vitest/config'; -import type { ViteUserConfig } from 'vitest/config'; - -const config: ViteUserConfig = defineConfig({ - define: { - __DEV__: false, - }, - test: { - name: 'react/worklet-runtime', - }, -}); - -export default config; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 2a60f4e726..c18f8736f4 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -660,12 +660,6 @@ importers: packages/react/transform/swc-plugin-reactlynx-compat: {} - packages/react/worklet-runtime: - devDependencies: - '@lynx-js/types': - specifier: 3.7.0 - version: 3.7.0 - packages/repl: dependencies: '@radix-ui/react-select': diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index 65f41ed9d6..b9ddd8b557 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -13,7 +13,6 @@ packages: - packages/react/transform/rspack-napi - packages/react/transform/swc-plugin-reactlynx - packages/react/transform/swc-plugin-reactlynx-compat - - packages/react/worklet-runtime - packages/react-umd - packages/rspeedy/* - packages/tailwind-preset