Skip to content

Commit

Permalink
feat: use @coze-infra/rslib-config
Browse files Browse the repository at this point in the history
feat: use @coze-infra/rslib-config
  • Loading branch information
wfc committed Dec 3, 2024
1 parent b2aec1c commit 17de69d
Show file tree
Hide file tree
Showing 9 changed files with 151 additions and 68 deletions.
40 changes: 40 additions & 0 deletions common/config/subspaces/default/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions config/rslib-config/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = [];
59 changes: 59 additions & 0 deletions config/rslib-config/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { defineConfig, LibConfig } from '@rslib/core';

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

interface Options {
format?: LibFormat[];
bundle?: BundleType;
tsconfigPath?: string;
umdName?: string;
}
const defaultOptions = {
format: ['esm', 'cjs'] as LibFormat[],
bundle: true,
};

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

const libs = format.map(libFormat => {
const lib = getLibShared(libFormat, bundle!);
if (libFormat === 'umd') {
lib.umdName = umdName;
lib.bundle = true;
}
return lib;
});

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

return defineConfig({
source: {
tsconfigPath,
},
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 getRslibConfig;
28 changes: 28 additions & 0 deletions config/rslib-config/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "@coze-infra/rslib-config",
"version": "0.0.1",
"author": "[email protected]",
"maintainers": [],
"main": "src/index.ts",
"types": "src/index.ts",
"scripts": {
"build": "exit",
"lint": "exit",
"test": "exit",
"test:cov": "exit 0"
},
"dependencies": {
"@rslib/core": "0.0.18"
},
"devDependencies": {
"@coze-infra/eslint-config": "workspace:*",
"@coze-infra/ts-config": "workspace:*",
"@types/node": "^20",
"@vitejs/plugin-react": "~4.3.3",
"@vitest/coverage-v8": "~2.1.4",
"happy-dom": "~15.11.0",
"sucrase": "^3.32.0",
"typescript": "^5.5.3",
"vitest": "~2.1.4"
}
}
1 change: 1 addition & 0 deletions packages/coze-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
},
"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",
Expand Down
41 changes: 9 additions & 32 deletions packages/coze-js/rslib.config.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,10 @@
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: {
import { defineConfig } from '@rslib/core';
import getRslibConfig from '@coze-infra/rslib-config';
export default defineConfig(
getRslibConfig({
format: ['esm', 'cjs', 'umd'],
bundle: 'excludeExternal',
umdName: 'CozeJs',
tsconfigPath: './tsconfig.build.json',
},
lib: [
{
...getLibShared('esm'),
dts: {
distPath: './dist/types',
},
},
{
...getLibShared('umd'),
umdName: 'CozeJs',
},
getLibShared('cjs'),
],
});
}),
);
1 change: 1 addition & 0 deletions packages/realtime-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
},
"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",
Expand Down
44 changes: 8 additions & 36 deletions packages/realtime-api/rslib.config.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,9 @@
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: {
import { defineConfig } from '@rslib/core';
import getRslibConfig from '@coze-infra/rslib-config';
export default defineConfig(
getRslibConfig({
format: ['esm', 'cjs', 'umd'],
umdName: 'CozeRealtimeApi',
tsconfigPath: './tsconfig.build.json',
},
output: {
target: 'web',
},
lib: [
{
...getLibShared('esm'),
dts: {
distPath: './dist/types',
},
},
{
...getLibShared('umd'),
umdName: 'CozeRealtimeApi',
},
getLibShared('cjs'),
],
});
}),
);
4 changes: 4 additions & 0 deletions rush.json
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,10 @@
"packageName": "@coze-infra/vitest-config",
"projectFolder": "config/vitest-config"
},
{
"packageName": "@coze-infra/rslib-config",
"projectFolder": "config/rslib-config"
},
{
"packageName": "@coze/api",
"projectFolder": "packages/coze-js"
Expand Down

0 comments on commit 17de69d

Please sign in to comment.