Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changeset/chubby-hounds-hug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---

---
22 changes: 22 additions & 0 deletions .changeset/little-candies-carry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
"@lynx-js/rspeedy": patch
---

Add `callerName` option to `createRspeedy`.

It can be accessed by Rsbuild plugins through [`api.context.callerName`](https://rsbuild.dev/api/javascript-api/instance#contextcallername), and execute different logic based on this identifier.

```js
export const myPlugin = {
name: 'my-plugin',
setup(api) {
const { callerName } = api.context;

if (callerName === 'rslib') {
// ...
} else if (callerName === 'rspeedy') {
// ...
}
},
};
```
3 changes: 3 additions & 0 deletions .github/workflows/relative-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ jobs:
- path: ./packages/web-platform/web-explorer
name: web-explorer
key: RELATIVE_CI_PROJECT_WEB_EXPLORER_KEY
- path: ./packages/rspeedy/core
name: rspeedy
key: RELATIVE_CI_PROJECT_RSPEEDY_CORE_KEY
runs-on: lynx-ubuntu-24.04-medium
name: Upload ${{ matrix.project.name }}
env:
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/workflow-bundle-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ jobs:
name: example-react
- path: ./packages/web-platform/web-explorer
name: web-explorer
- path: ./packages/rspeedy/core
name: rspeedy
name: Build ${{ matrix.project.name }}
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
Expand All @@ -42,6 +44,8 @@ jobs:
run: |
pnpm turbo build --summarize
- name: Build ${{ matrix.project.name }}
env:
RSPEEDY_BUNDLE_ANALYSIS: 1
run: |
pnpm --filter ${{ matrix.project.path }} run build
- uses: relative-ci/agent-upload-artifact-action@a2b5741b4f7e6a989c84ec1a3059696b23c152e5 #v2
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"eslint-plugin-headers": "^1.2.1",
"eslint-plugin-import": "^2.31.0",
"eslint-plugin-markdown": "^5.1.0",
"eslint-plugin-n": "^17.17.0",
"eslint-plugin-n": "^17.18.0",
"eslint-plugin-regexp": "^2.7.0",
"eslint-plugin-unicorn": "^59.0.1",
"globals": "^16.1.0",
Expand Down
3 changes: 2 additions & 1 deletion packages/rspeedy/core/etc/rspeedy.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,11 @@ export interface Config {
export type ConsoleType = 'log' | 'warn' | 'error' | 'info' | 'debug' | 'profile' | 'profileEnd' | (string & Record<never, never>);

// @public
export function createRspeedy({ cwd, rspeedyConfig, loadEnv, environment }: CreateRspeedyOptions): Promise<RspeedyInstance>;
export function createRspeedy({ cwd, rspeedyConfig, loadEnv, environment, callerName, }: CreateRspeedyOptions): Promise<RspeedyInstance>;

// @public
export interface CreateRspeedyOptions {
callerName?: string;
cwd?: string;
environment?: CreateRsbuildOptions['environment'];
loadEnv?: CreateRsbuildOptions['loadEnv'];
Expand Down
2 changes: 1 addition & 1 deletion packages/rspeedy/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"ipaddr.js": "^2.2.0",
"javascript-stringify": "^2.1.0",
"picocolors": "^1.1.1",
"rsbuild-plugin-publint": "0.3.1",
"rsbuild-plugin-publint": "0.3.2",
"tiny-invariant": "^1.3.3",
"ts-blank-space": "^0.6.1",
"type-fest": "^4.41.0",
Expand Down
3 changes: 3 additions & 0 deletions packages/rspeedy/core/rslib.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ export default defineConfig({
syntax: 'es2022',
dts: { bundle: true },
plugins: [pluginTypia()],
performance: {
profile: !!process.env.RSPEEDY_BUNDLE_ANALYSIS,
},
},
{
format: 'esm',
Expand Down
26 changes: 17 additions & 9 deletions packages/rspeedy/core/src/config/source/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,9 @@ export interface Source {
* ```js
* import { defineConfig } from '@lynx-js/rspeedy'
* export default defineConfig({
* entry: './src/pages/main/index.js',
* source: {
* entry: './src/pages/main/index.js',
* },
* })
* ```
*
Expand All @@ -256,7 +258,9 @@ export interface Source {
* ```js
* import { defineConfig } from '@lynx-js/rspeedy'
* export default defineConfig({
* entry: ['./src/prefetch.js', './src/pages/main/index.js'],
* source: {
* entry: ['./src/prefetch.js', './src/pages/main/index.js'],
* },
* })
* ```
*
Expand All @@ -267,9 +271,11 @@ export interface Source {
* ```js
* import { defineConfig } from '@lynx-js/rspeedy'
* export default defineConfig({
* entry: {
* foo: './src/pages/foo/index.js',
* bar: ['./src/pages/bar/index.js', './src/post.js'], // multiple entry modules is allowed
* source: {
* entry: {
* foo: './src/pages/foo/index.js',
* bar: ['./src/pages/bar/index.js', './src/post.js'], // multiple entry modules is allowed
* },
* },
* })
* ```
Expand All @@ -281,10 +287,12 @@ export interface Source {
* ```js
* import { defineConfig } from '@lynx-js/rspeedy'
* export default defineConfig({
* entry: {
* foo: './src/pages/foo/index.js',
* bar: {
* import: ['./src/prefetch.js', './src/pages/bar'],
* source: {
* entry: {
* foo: './src/pages/foo/index.js',
* bar: {
* import: ['./src/prefetch.js', './src/pages/bar'],
* },
* },
* },
* })
Expand Down
47 changes: 45 additions & 2 deletions packages/rspeedy/core/src/create-rspeedy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,43 @@ export interface CreateRspeedyOptions {
* @defaultValue []
*/
environment?: CreateRsbuildOptions['environment']

/**
* The name of the framework or tool that is currently invoking Rsbuild.
* This allows plugins to tailor their behavior based on the calling context.
*
* @example
*
* Rsbuild plugins can access this value via `api.context.callerName`.
*
* ```js
* export function myPlugin() {
* return {
* name: 'my-plugin',
* setup(api) {
* // Log the name of the tool invoking Rsbuild
* console.log(`Called by: ${api.context.callerName}`);
*
* // Conditionally apply plugin logic based on caller
* if (api.context.callerName === 'rspeedy') {
* api.modifyRsbuildConfig((config) => {
* // Apply rspeedy-specific config changes
* return config;
* });
* } else if (api.context.callerName === 'rslib') {
* api.modifyRsbuildConfig((config) => {
* // Apply rslib-specific config changes
* return config;
* });
* }
* }
* };
* }
* ```
*
* @defaultValue 'rspeedy'
*/
callerName?: string
}
/**
* The `createRspeedy` method can let you create a Rspeedy instance and you can customize the build or development process in Node.js Runtime.
Expand All @@ -76,8 +113,13 @@ export interface CreateRspeedyOptions {
* @public
*/
export async function createRspeedy(
{ cwd = process.cwd(), rspeedyConfig = {}, loadEnv = true, environment = [] }:
CreateRspeedyOptions,
{
cwd = process.cwd(),
rspeedyConfig = {},
loadEnv = true,
environment = [],
callerName = 'rspeedy',
}: CreateRspeedyOptions,
): Promise<RspeedyInstance> {
const config = applyDefaultRspeedyConfig(rspeedyConfig)

Expand All @@ -87,6 +129,7 @@ export async function createRspeedy(
loadEnv,
rsbuildConfig: toRsbuildConfig(config) as RsbuildConfig,
environment,
callerName,
}),
import('./plugins/index.js'),
])
Expand Down
48 changes: 48 additions & 0 deletions packages/rspeedy/core/test/createRspeedy.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright 2024 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 type { RsbuildPluginAPI } from '@rsbuild/core'
import { describe, expect, test } from 'vitest'

import { createRspeedy } from '../src/create-rspeedy.js'

describe('createRspeedy', () => {
test('default callerName', async () => {
const rspeedy = await createRspeedy({
rspeedyConfig: {
plugins: [
{
name: 'test',
setup(api: RsbuildPluginAPI) {
expect(api.context.callerName).toBe('rspeedy')
},
},
],
},
})

await rspeedy.initConfigs()

expect.assertions(1)
})

test('custom callerName', async () => {
const rspeedy = await createRspeedy({
callerName: 'my-custom-framework',
rspeedyConfig: {
plugins: [
{
name: 'test',
setup(api: RsbuildPluginAPI) {
expect(api.context.callerName).toBe('my-custom-framework')
},
},
],
},
})

await rspeedy.initConfigs()

expect.assertions(1)
})
})
3 changes: 3 additions & 0 deletions packages/rspeedy/core/turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
"dependsOn": [
"^build"
],
"env": [
"RSPEEDY_BUNDLE_ANALYSIS"
],
"inputs": [
"register",
"src",
Expand Down
2 changes: 1 addition & 1 deletion packages/rspeedy/create-rspeedy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"test": "vitest"
},
"dependencies": {
"create-rstack": "1.4.1"
"create-rstack": "1.4.2"
},
"devDependencies": {
"@lynx-js/qrcode-rsbuild-plugin": "workspace:^",
Expand Down
2 changes: 1 addition & 1 deletion packages/testing-library/testing-environment/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@
"devDependencies": {
"@testing-library/jest-dom": "^6.6.3",
"@types/jsdom": "^21.1.7",
"rsbuild-plugin-publint": "0.3.1"
"rsbuild-plugin-publint": "0.3.2"
}
}
Loading