Skip to content
Open
Show file tree
Hide file tree
Changes from 5 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ common/autoinstallers/*/.npmrc
.vercel/output
rush-logs
dist
lib-ts

*.tsbuildinfo

Expand Down
322 changes: 207 additions & 115 deletions common/config/subspaces/default/pnpm-lock.yaml

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions config/rsbuild-config/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const { defineConfig } = require('@coze-infra/eslint-config');

module.exports = defineConfig({
preset: 'node',
packageRoot: __dirname,
ignores: ['lib-ts'],
});
24 changes: 24 additions & 0 deletions config/rsbuild-config/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "@coze-infra/rsbuild-config",
"version": "0.0.1",
"author": "[email protected]",
"maintainers": [],
"main": "src/index.ts",
"types": "src/index.ts",
"scripts": {
"build": "npx tsc -b tsconfig.build.json",
"lint": "eslint ./ --cache --quiet"
},
"dependencies": {
"@rsbuild/core": "1.1.10",
"@rsbuild/plugin-react": "1.1.0",
"process": "~0.11.10"
},
"devDependencies": {
"@coze-infra/eslint-config": "workspace:*",
"@coze-infra/ts-config": "workspace:*",
"@types/node": "^20",
"sucrase": "^3.32.0",
"typescript": "^5.5.3"
}
}
16 changes: 16 additions & 0 deletions config/rsbuild-config/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { defineConfig } from '@rsbuild/core';
import { pluginReact } from '@rsbuild/plugin-react';

const baseRsbuildConfig = defineConfig({
plugins: [pluginReact()],
tools: {
rspack: (_, { rspack, appendPlugins }) => {
appendPlugins([
new rspack.ProvidePlugin({
process: [require.resolve('process/browser')],
}),
]);
},
},
});
export default baseRsbuildConfig;
7 changes: 7 additions & 0 deletions config/rsbuild-config/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "lib-ts",
"noEmit": false
}
}
7 changes: 7 additions & 0 deletions config/rsbuild-config/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "../ts-config/tsconfig.node.json",
"compilerOptions": {
"noEmit": true
},
"include": ["src/**/*", "eslint.*.js"]
}
21 changes: 21 additions & 0 deletions config/rslib-config/bin/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env node
import nodeModule from 'node:module';

import { logger, prepareCli, runCli } from '@rslib/core';

// enable on-disk code caching of all modules loaded by Node.js
// requires Nodejs >= 22.8.0
const { enableCompileCache } = nodeModule;
if (enableCompileCache) {
try {
enableCompileCache();
} catch {
// ignore errors
}
}
prepareCli();
try {
runCli();
} catch (err) {
logger.error(err);
}
7 changes: 7 additions & 0 deletions config/rslib-config/eslint.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const { defineConfig } = require('@coze-infra/eslint-config');

module.exports = defineConfig({
preset: 'node',
packageRoot: __dirname,
ignores: ['lib-ts'],
});
27 changes: 27 additions & 0 deletions config/rslib-config/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "@coze-infra/rslib-config",
"version": "0.0.1",
"author": "[email protected]",
"maintainers": [],
"type": "module",
"main": "src/index.ts",
"types": "src/index.ts",
"bin": {
"rerslib": "./bin/index.js",
"rslib": "./bin/index.js"
},
"scripts": {
"build": "npx tsc -b tsconfig.build.json",
"lint": "eslint ./ --cache --quiet"
},
"dependencies": {
"@rslib/core": "0.0.18"
},
"devDependencies": {
"@coze-infra/eslint-config": "workspace:*",
"@coze-infra/ts-config": "workspace:*",
"@types/node": "^20",
"sucrase": "^3.32.0",
"typescript": "^5.5.3"
}
}
78 changes: 78 additions & 0 deletions config/rslib-config/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import {
defineConfig as _defineConfig,
type LibConfig,
type RsbuildConfigOutputTarget,
} from '@rslib/core';

type LibFormat = LibConfig['format'];
export type BundleType = boolean | 'excludeExternal';

const defineConfig: typeof _defineConfig = _defineConfig;

export { defineConfig };

interface Options {
format?: LibFormat[];
bundle?: BundleType;
tsconfigPath?: string;
umdName?: string;
target?: RsbuildConfigOutputTarget;
}
const defaultOptions = {
format: ['esm', 'cjs'] as LibFormat[],
bundle: true,
target: 'web' as RsbuildConfigOutputTarget,
tsconfigPath: './tsconfig.build.json',
};

export function getRslibConfig(options: Options) {
const { format, bundle, umdName, tsconfigPath, target } = {
...defaultOptions,
...options,
};

const libs = format.map(libFormat => {
const lib = getLibShared(libFormat, bundle);
if (libFormat === 'umd') {
if (!umdName) {
throw new Error(
'getRslibConfig: umdName is required when using UMD format',
);
}
lib.umdName = umdName;
lib.bundle = true;
}
return lib;
});

libs[0].dts = {
distPath: './dist/types',
};

return defineConfig({
source: {
tsconfigPath,
},
output: {
target,
},
lib: libs,
});
}

function getLibShared(format: LibFormat, bundleType: BundleType) {
const shared: LibConfig = {
output: {
distPath: {
root: `./dist/${format}`,
},
},
format,
syntax: 'es6',
bundle: !!bundleType,
autoExternal: bundleType === 'excludeExternal',
};
return shared;
}

export default defineConfig(getRslibConfig({}));
7 changes: 7 additions & 0 deletions config/rslib-config/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "lib-ts",
"noEmit": false
}
}
7 changes: 7 additions & 0 deletions config/rslib-config/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "../ts-config/tsconfig.node.json",
"compilerOptions": {
"noEmit": true
},
"include": ["src/**/*", "eslint.*.js"]
}
6 changes: 4 additions & 2 deletions examples/coze-js-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"version": "0.1.0",
"private": true,
"scripts": {
"build": "node scripts/build.js",
"build": "rsbuild build",
"lint": "eslint --cache --quiet",
"start": "node scripts/start.js"
"start": "rsbuild dev"
},
"browserslist": {
"production": [
Expand Down Expand Up @@ -76,6 +76,8 @@
},
"devDependencies": {
"@coze-infra/eslint-config": "workspace:*",
"@coze-infra/rsbuild-config": "workspace:*",
"@rsbuild/core": "1.1.10",
"@types/jest": "^29.2.2",
"@types/node": "^20",
"@types/react": "^18.3.11",
Expand Down
3 changes: 3 additions & 0 deletions examples/coze-js-web/rsbuild.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { defineConfig } from '@rsbuild/core';
import baseRsbuildConfig from '@coze-infra/rsbuild-config/src';
export default defineConfig(baseRsbuildConfig);
2 changes: 1 addition & 1 deletion examples/coze-js-web/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import ChatX from './pages/chat-x';

function App() {
return (
<Router basename={`${process.env.PUBLIC_URL}`}>
<Router basename={`${process.env.PUBLIC_URL || ''}`}>
<div className="App">
<Routes>
<Route path="/chat" element={<Chat />} />
Expand Down
2 changes: 1 addition & 1 deletion examples/coze-js-web/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@
"noEmit": true,
"jsx": "react-jsx"
},
"include": ["src"]
"include": ["src", "rsbuild.config.ts"]
}
2 changes: 1 addition & 1 deletion packages/coze-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@
},
"devDependencies": {
"@coze-infra/eslint-config": "workspace:*",
"@coze-infra/rslib-config": "workspace:*",
"@coze-infra/ts-config": "workspace:*",
"@coze-infra/vitest-config": "workspace:*",
"@rslib/core": "0.0.18",
"@swc/core": "^1.3.14",
"@types/jsonwebtoken": "^9.0.0",
"@types/node": "^20",
Expand Down
41 changes: 8 additions & 33 deletions packages/coze-js/rslib.config.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,8 @@
import { defineConfig, type LibConfig } from '@rslib/core';

function getLibShared(format: LibConfig['format']) {
const shared: LibConfig = {
output: {
distPath: {
root: `./dist/${format}`,
},
},
format,
syntax: 'es6',
};
return shared;
}

export default defineConfig({
source: {
tsconfigPath: './tsconfig.build.json',
},
lib: [
{
...getLibShared('esm'),
dts: {
distPath: './dist/types',
},
},
{
...getLibShared('umd'),
umdName: 'CozeJs',
},
getLibShared('cjs'),
],
});
import { defineConfig, getRslibConfig } from '@coze-infra/rslib-config';
export default defineConfig(
getRslibConfig({
format: ['esm', 'cjs', 'umd'],
bundle: 'excludeExternal',
umdName: 'CozeJs',
}),
);
2 changes: 1 addition & 1 deletion packages/realtime-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@
},
"devDependencies": {
"@coze-infra/eslint-config": "workspace:*",
"@coze-infra/rslib-config": "workspace:*",
"@coze-infra/ts-config": "workspace:*",
"@coze-infra/vitest-config": "workspace:*",
"@rslib/core": "0.0.18",
"@swc/core": "^1.3.14",
"@types/node": "^20",
"@types/uuid": "^9.0.1",
Expand Down
44 changes: 7 additions & 37 deletions packages/realtime-api/rslib.config.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,7 @@
import { defineConfig, type LibConfig } from '@rslib/core';

function getLibShared(format: LibConfig['format']) {
const shared: LibConfig = {
output: {
distPath: {
root: `./dist/${format}`,
},
},
format,
syntax: 'es6',
autoExternal: false,
};
return shared;
}

export default defineConfig({
source: {
tsconfigPath: './tsconfig.build.json',
},
output: {
target: 'web',
},
lib: [
{
...getLibShared('esm'),
dts: {
distPath: './dist/types',
},
},
{
...getLibShared('umd'),
umdName: 'CozeRealtimeApi',
},
getLibShared('cjs'),
],
});
import { defineConfig, getRslibConfig } from '@coze-infra/rslib-config';
export default defineConfig(
getRslibConfig({
format: ['esm', 'cjs', 'umd'],
umdName: 'CozeRealtimeApi',
}),
);
8 changes: 8 additions & 0 deletions rush.json
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,14 @@
"packageName": "@coze-infra/package-audit",
"projectFolder": "infra/package-audit"
},
{
"packageName": "@coze-infra/rslib-config",
"projectFolder": "config/rslib-config"
},
{
"packageName": "@coze-infra/rsbuild-config",
"projectFolder": "config/rsbuild-config"
},
{
"packageName": "@coze/api",
"projectFolder": "packages/coze-js"
Expand Down