Skip to content
9 changes: 9 additions & 0 deletions .changeset/align-lynx-terminology.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"@lynx-js/web-constants": patch
"@lynx-js/web-core": patch
"@lynx-js/react-webpack-plugin": patch
"@lynx-js/template-webpack-plugin": patch
"@lynx-js/react-rsbuild-plugin": patch
---

Align codebase terminology with the official Lynx specification. Add new preferred type aliases (`LynxBundle`, `BundleLoader`, `DecodedBundle`, `BundleSectionLabel`, `BundleHooks`, `LynxBundlePlugin`, `LynxBundlePluginOptions`) and deprecate legacy names.
13 changes: 8 additions & 5 deletions packages/rspeedy/plugin-react/etc/react-rsbuild-plugin.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@

```ts

import type { BundleHooks } from '@lynx-js/template-webpack-plugin';
import { LAYERS } from '@lynx-js/react-webpack-plugin';
import type { LynxTemplatePlugin as LynxTemplatePlugin_2 } from '@lynx-js/template-webpack-plugin';
import type { RsbuildPlugin } from '@rsbuild/core';
import type { TemplateHooks } from '@lynx-js/template-webpack-plugin';

// @public
export interface AddComponentElementConfig {
compilerOnly: boolean
}

export { BundleHooks }
export { BundleHooks as TemplateHooks }

// @public
export interface CompatVisitorConfig {
addComponentElement: boolean | AddComponentElementConfig
Expand Down Expand Up @@ -48,13 +51,15 @@ export interface ExtractStrConfig {

export { LAYERS }

// Warning: (ae-missing-release-tag) "LynxTemplatePlugin" is part of the package's API, but it is missing a release tag (@alpha, @beta, @public, or @internal)
// Warning: (ae-missing-release-tag) "LynxBundlePlugin" is part of the package's API, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
Comment on lines +54 to 56
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Find LynxBundlePlugin definition and its JSDoc in source files
find packages/rspeedy/plugin-react/src -type f \( -name "*.ts" -o -name "*.tsx" \) -exec grep -l "LynxBundlePlugin" {} \;

Repository: lynx-family/lynx-stack

Length of output: 108


🏁 Script executed:

#!/bin/bash
# Read the source file to check JSDoc and LynxBundlePlugin definition
cat -n packages/rspeedy/plugin-react/src/index.ts

Repository: lynx-family/lynx-stack

Length of output: 1637


🏁 Script executed:

#!/bin/bash
# Check if this is a private package and verify package details
cat packages/rspeedy/plugin-react/package.json | head -20

Repository: lynx-family/lynx-stack

Length of output: 532


🏁 Script executed:

#!/bin/bash
# Check if package is private
grep -A 2 '"private"' packages/rspeedy/plugin-react/package.json

Repository: lynx-family/lynx-stack

Length of output: 48


🏁 Script executed:

#!/bin/bash
# Check the api.md file to see the full context around lines 54-62
sed -n '50,65p' packages/rspeedy/plugin-react/etc/react-rsbuild-plugin.api.md

Repository: lynx-family/lynx-stack

Length of output: 592


🏁 Script executed:

#!/bin/bash
# Verify if there are other similar interfaces in the codebase with proper JSDoc examples
rg -B 3 "export type.*interface" packages/rspeedy/plugin-react/src/ -A 2

Repository: lynx-family/lynx-stack

Length of output: 48


🏁 Script executed:

#!/bin/bash
# Check if there are other exported types/interfaces with proper JSDoc in the same file
rg -B 5 "export.*PluginReactLynxOptions" packages/rspeedy/plugin-react/src/ -A 2

Repository: lynx-family/lynx-stack

Length of output: 1257


🏁 Script executed:

#!/bin/bash
# Double-check if api.md file is correctly generated by looking at regeneration scripts
find packages/rspeedy/plugin-react -name "tsconfig*.json" -o -name "api-extractor.json"

Repository: lynx-family/lynx-stack

Length of output: 257


🏁 Script executed:

#!/bin/bash
# Verify the API extractor configuration to understand how it processes exports
cat packages/rspeedy/plugin-react/api-extractor.json | head -30

Repository: lynx-family/lynx-stack

Length of output: 271


Add JSDoc with @public release tag to LynxBundlePlugin interface.

The LynxBundlePlugin interface exported from packages/rspeedy/plugin-react/src/index.ts is missing proper JSDoc documentation with a release tag. API Extractor correctly flagged this and defaulted to @public (undocumented). Other exported types in the same file like PluginReactLynxOptions include proper JSDoc with the @public tag—LynxBundlePlugin should follow the same pattern.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/rspeedy/plugin-react/etc/react-rsbuild-plugin.api.md` around lines
54 - 56, The exported interface LynxBundlePlugin is missing JSDoc with a release
tag; add a JSDoc block immediately above the LynxBundlePlugin declaration
(matching the style used for PluginReactLynxOptions) that includes a short
one-line description and the `@public` release tag so API Extractor no longer
marks it as undocumented.

export interface LynxTemplatePlugin {
interface LynxBundlePlugin {
// (undocumented)
getLynxTemplatePluginHooks: typeof LynxTemplatePlugin_2.getLynxTemplatePluginHooks;
}
export { LynxBundlePlugin }
export { LynxBundlePlugin as LynxTemplatePlugin }

// @public
export function pluginReactLynx(userOptions?: PluginReactLynxOptions): RsbuildPlugin[];
Expand Down Expand Up @@ -93,6 +98,4 @@ export interface ShakeVisitorConfig {
retainProp: Array<string>
}

export { TemplateHooks }

```
11 changes: 8 additions & 3 deletions packages/rspeedy/plugin-react/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
*/

import type {
BundleHooks,
LynxTemplatePlugin as InnerLynxTemplatePlugin,
TemplateHooks,
} from '@lynx-js/template-webpack-plugin'

export { pluginReactLynx } from './pluginReactLynx.js'
Expand All @@ -24,14 +24,19 @@ export type {
ShakeVisitorConfig,
} from '@lynx-js/react-transform'

interface LynxTemplatePlugin {
interface LynxBundlePlugin {
getLynxTemplatePluginHooks:
typeof InnerLynxTemplatePlugin.getLynxTemplatePluginHooks
}

// We only export types here
// It is encouraged to use `api.useExposed(Symbol.for('LynxTemplatePlugin'))`
// to access the actual API
export type { LynxTemplatePlugin, TemplateHooks }
export type { LynxBundlePlugin }
export type { BundleHooks }
/** @deprecated Use {@link LynxBundlePlugin} instead. */
export type { LynxBundlePlugin as LynxTemplatePlugin }
/** @deprecated Use {@link BundleHooks} instead. */
export type { BundleHooks as TemplateHooks }

export { LAYERS } from '@lynx-js/react-webpack-plugin'
11 changes: 6 additions & 5 deletions packages/rspeedy/plugin-react/src/pluginReactLynx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,16 +197,17 @@ export interface PluginReactLynxOptions {
enableRemoveCSSScope?: boolean | undefined

/**
* This flag controls when MainThread (Lepus) transfers control to Background after the first screen
* This flag controls when Main Thread Script (MTS) transfers
* control to Background Thread Script (BTS) after the first screen.
*
* This flag has two options:
*
* `"immediately"`: Transfer immediately
*
* `"jsReady"`: Transfer when background (JS Runtime) is ready
*
* After handing over control, MainThread (Lepus) runtime can no longer respond to data updates,
* and data updates will be forwarded to background (JS Runtime) and processed __asynchronously__
* After handing over control, Main Thread Script (MTS) runtime can no longer respond to data updates,
* and data updates will be forwarded to Background Thread Script (BTS) and processed __asynchronously__
*
* @defaultValue "immediately"
*/
Expand Down Expand Up @@ -252,8 +253,8 @@ export interface PluginReactLynxOptions {
targetSdkVersion?: string

/**
* Merge same string literals in JS and Lepus to reduce output bundle size.
* Set to `false` to disable.
* Merge same string literals in JS and Main Thread Script (MTS)
* to reduce output bundle size. Set to `false` to disable.
*
* @defaultValue false
*/
Expand Down
2 changes: 2 additions & 0 deletions packages/rspeedy/plugin-react/test/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1925,6 +1925,7 @@ describe('Config', () => {
lynx: {},
},
plugins: [
pluginStubRspeedyAPI(),
pluginReactLynx({
defineDCE: { define: { __SOME_MACRO__: 'false' } },
}),
Expand Down Expand Up @@ -1957,6 +1958,7 @@ describe('Config', () => {
lynx: {},
},
plugins: [
pluginStubRspeedyAPI(),
pluginReactLynx({
defineDCE: {
define: {
Expand Down
7 changes: 7 additions & 0 deletions packages/web-platform/web-constants/src/endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@ export const flushElementTreeEndpoint = createRpcEndpoint<
void
>('flushElementTree', false, true);

/**
* Calls a method on the Main Thread Script (MTS) runtime.
*
* @remarks
* `callLepusMethod` is a legacy endpoint name. "Lepus" is the legacy term
* for Main Thread Script (MTS) in the Lynx specification.
*/
export const callLepusMethodEndpoint = createRpcEndpoint<
[name: string, data: unknown],
void
Expand Down
33 changes: 32 additions & 1 deletion packages/web-platform/web-constants/src/types/LynxModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,16 @@ export type ElementTemplateData = {
dataset?: Record<string, string>;
};

export interface LynxTemplate {
/**
* Represents a Lynx Bundle — the compiled artifact containing all necessary
* resources (stylesheet, scripts, serialized element tree) for a Lynx
* application to run.
*
* @remarks
* This interface corresponds to the "Bundle" concept in the official Lynx
* specification.
*/
export interface LynxBundle {
styleInfo: StyleInfo;
pageConfig: PageConfig;
customSections: {
Expand All @@ -28,10 +37,27 @@ export interface LynxTemplate {
};
};
cardType?: string;
/**
* Main Thread Script (MTS) — code that runs on the main thread (UI thread).
*
* @remarks
* In the official Lynx specification this is called "Main Thread Script"
* (MTS). The field name `lepusCode` is a legacy artifact that cannot be
* renamed as it is part of the wire format.
*/
lepusCode: {
root: string;
[key: string]: string;
};
/**
* Background Thread Script (BTS) — code that runs on the background thread.
*
* @remarks
* In the official Lynx specification this is called "Background Thread
* Script" (BTS). The field name `manifest` is a legacy artifact that cannot
* be renamed as it is part of the wire format. The key `'/app-service.js'`
* is a conventional entry point name for BTS.
*/
manifest: {
'/app-service.js': string;
[key: string]: string;
Expand All @@ -41,6 +67,11 @@ export interface LynxTemplate {
appType: 'card' | 'lazy';
}

/**
* @deprecated Use {@link LynxBundle} instead.
*/
export type LynxTemplate = LynxBundle;

export type BTSChunkEntry = (
postMessage: undefined,
module: { exports: unknown },
Expand Down
12 changes: 10 additions & 2 deletions packages/web-platform/web-constants/src/types/TemplateLoader.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
import type { LynxTemplate } from './LynxModule.js';
import type { LynxBundle } from './LynxModule.js';

export type TemplateLoader = (url: string) => Promise<LynxTemplate>;
/**
* Loads a Lynx Bundle from the given URL.
*/
export type BundleLoader = (url: string) => Promise<LynxBundle>;

/**
* @deprecated Use {@link BundleLoader} instead.
*/
export type TemplateLoader = BundleLoader;
41 changes: 41 additions & 0 deletions packages/web-platform/web-core-wasm/ts/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,60 @@
export const MagicHeader0 = /*#__PURE__*/ 0x41524453; // 'SDRA'
export const MagicHeader1 = /*#__PURE__*/ 0x464F5257; // 'WROF'

/**
* Section labels used in the binary Lynx Bundle encoding format.
*
* @remarks
* `BackgroundThreadScript` corresponds to "Manifest" in legacy code.
* `MainThreadScript` corresponds to "LepusCode" in legacy code.
* Wire values are unchanged.
*/
export const BundleSectionLabel = /*#__PURE__*/ {
/** Background Thread Script (BTS). Legacy name: "Manifest". */
BackgroundThreadScript: 1,
StyleInfo: 2,
/** Main Thread Script (MTS). Legacy name: "LepusCode". */
MainThreadScript: 3,
CustomSections: 4,
ElementTemplates: 5,
Configurations: 6,
} as const;

/**
* @deprecated Use {@link BundleSectionLabel} instead.
*/
export const TemplateSectionLabel = /*#__PURE__*/ {
/** @deprecated Use {@link BundleSectionLabel.BackgroundThreadScript} instead. */
Manifest: 1,
StyleInfo: 2,
/** @deprecated Use {@link BundleSectionLabel.MainThreadScript} instead. */
LepusCode: 3,
CustomSections: 4,
ElementTemplates: 5,
Configurations: 6,
/**
* Section labels used in the binary Lynx Bundle encoding format.
*
* @remarks
* `BackgroundThreadScript` corresponds to "Manifest" in legacy code.
* `MainThreadScript` corresponds to "LepusCode" in legacy code.
* Wire values are unchanged.
*/
export const BundleSectionLabel = /*#__PURE__*/ {

Check failure on line 93 in packages/web-platform/web-core-wasm/ts/constants.ts

View workflow job for this annotation

GitHub Actions / build / Build (Windows)

':' expected.
/** Background Thread Script (BTS). Legacy name: "Manifest". */
BackgroundThreadScript: 1,
StyleInfo: 2,
/** Main Thread Script (MTS). Legacy name: "LepusCode". */
MainThreadScript: 3,
CustomSections: 4,
ElementTemplates: 5,
Configurations: 6,
} as const;

Check failure on line 102 in packages/web-platform/web-core-wasm/ts/constants.ts

View workflow job for this annotation

GitHub Actions / build / Build (Windows)

',' expected.

/**
* const enum will be shakedown in Typescript Compiler
*/
export const enum ErrorCode {

Check failure on line 107 in packages/web-platform/web-core-wasm/ts/constants.ts

View workflow job for this annotation

GitHub Actions / build / Build (Windows)

',' expected.

Check failure on line 107 in packages/web-platform/web-core-wasm/ts/constants.ts

View workflow job for this annotation

GitHub Actions / build / Build (Windows)

':' expected.
SUCCESS = 0,
UNKNOWN = 1,
NODE_NOT_FOUND = 2,
Expand Down
8 changes: 8 additions & 0 deletions packages/web-platform/web-core-wasm/ts/encode/webEncoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,18 @@ function encodeStringMap(map: Record<string, string>): Uint8Array {

export type TasmJSONInfo = {
styleInfo: Record<string, CSS.LynxStyleNode[]>;
/**
* Background Thread Script (BTS) chunks.
* @remarks The field name `manifest` is a legacy artifact.
*/
manifest: Record<string, string>;
cardType: string;
appType: string;
pageConfig: Record<string, unknown>;
/**
* Main Thread Script (MTS) chunks.
* @remarks The field name `lepusCode` is a legacy artifact.
*/
lepusCode: Record<string, string>;
customSections: Record<string, {
type?: 'lazy';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,29 @@
import type { PageConfig } from './PageConfig.js';
import type { StyleSheetResource } from '../../binary/client/client.js';

export interface DecodedTemplate {
/**
* A decoded Lynx Bundle with its sections parsed into JS objects / blob URLs.
*
* @remarks
* This interface corresponds to the "Bundle" concept in the official Lynx
* specification.
*/
export interface DecodedBundle {
config?: PageConfig;
/**
* Main Thread Script (MTS) — code that runs on the main thread (UI thread).
*
* @remarks
* In the official Lynx specification this is called "Main Thread Script"
* (MTS). The field name `lepusCode` is a legacy artifact.
*/
lepusCode?: Record<string, string>;
customSections?: Record<string, any>;
backgroundCode?: Record<string, string>;
styleSheet?: StyleSheetResource;
}

/**
* @deprecated Use {@link DecodedBundle} instead.
*/
export type DecodedTemplate = DecodedBundle;
2 changes: 2 additions & 0 deletions packages/web-platform/web-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@
// LICENSE file in the root directory of this source tree.
export { createLynxView } from './apis/createLynxView.js';
export { LynxView } from './apis/LynxView.js';
/** @deprecated Use {@link LynxBundle} instead. `LynxTemplate` is a legacy name. */
export type { LynxTemplate } from '@lynx-js/web-constants';
export type { LynxBundle } from '@lynx-js/web-constants';
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ export interface MainThreadRuntimeConfig {
pageConfig: PageConfig;
globalProps: unknown;
callbacks: MainThreadRuntimeCallbacks;
/** The Lynx Bundle (legacy field name: `lynxTemplate`). */
lynxTemplate: LynxTemplate;
browserConfig: BrowserConfig;
tagMap: Record<string, string>;
Expand Down Expand Up @@ -676,6 +677,13 @@ export function createMainThreadGlobalThis(
);
};

/**
* Loads a Main Thread Script (MTS) chunk by path.
*
* @remarks
* `__LoadLepusChunk` is a legacy function name. "Lepus" is the legacy term
* for Main Thread Script (MTS) in the Lynx specification.
*/
const __LoadLepusChunk: (path: string) => boolean = (path) => {
try {
path = lepusCode?.[path] ?? path;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ import {
type Rpc,
} from '@lynx-js/web-constants';

/**
* Registers a handler for calling Main Thread Script (MTS) methods.
*
* @remarks
* "Lepus" in the function name is a legacy term for Main Thread Script (MTS).
*/
export function registerCallLepusMethodHandler(
rpc: Rpc,
runtime: MainThreadGlobalThis,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ interface ReactWebpackPluginOptions {
mainThreadChunks?: string[] | undefined;

/**
* Merge same string literals in JS and Lepus to reduce output bundle size.
* Set to `false` to disable.
* Merge same string literals in JS and Main Thread Script (MTS)
* to reduce output bundle size. Set to `false` to disable.
*
* @defaultValue false
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import type {

const PLUGIN_NAME = 'react:webpack';
const JSX_IMPORT_SOURCE = {
// `lepus` is a legacy path segment for Main Thread Script (MTS).
MAIN_THREAD: '@lynx-js/react/lepus',
BACKGROUND: '@lynx-js/react',
};
Expand Down
Loading
Loading