feat: manually mirror opencoze's code from bytedance
Change-Id: I09a73aadda978ad9511264a756b2ce51f5761adf
This commit is contained in:
63
frontend/infra/plugins/import-watch-loader/README.md
Normal file
63
frontend/infra/plugins/import-watch-loader/README.md
Normal file
@@ -0,0 +1,63 @@
|
||||
# @coze-arch/import-watch-loader
|
||||
|
||||
A architecture package for the Coze Studio monorepo
|
||||
|
||||
## Overview
|
||||
|
||||
This package is part of the Coze Studio monorepo and provides architecture functionality. It serves as a core component in the Coze ecosystem.
|
||||
|
||||
## Getting Started
|
||||
|
||||
### Installation
|
||||
|
||||
Add this package to your `package.json`:
|
||||
|
||||
```json
|
||||
{
|
||||
"dependencies": {
|
||||
"@coze-arch/import-watch-loader": "workspace:*"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Then run:
|
||||
|
||||
```bash
|
||||
rush update
|
||||
```
|
||||
|
||||
### Usage
|
||||
|
||||
```typescript
|
||||
import { /* exported functions/components */ } from '@coze-arch/import-watch-loader';
|
||||
|
||||
// Example usage
|
||||
// TODO: Add specific usage examples
|
||||
```
|
||||
|
||||
## Features
|
||||
|
||||
- Core functionality for Coze Studio
|
||||
- TypeScript support
|
||||
- Modern ES modules
|
||||
|
||||
## API Reference
|
||||
|
||||
Please refer to the TypeScript definitions for detailed API documentation.
|
||||
|
||||
## Development
|
||||
|
||||
This package is built with:
|
||||
|
||||
- TypeScript
|
||||
- Modern JavaScript
|
||||
- Vitest for testing
|
||||
- ESLint for code quality
|
||||
|
||||
## Contributing
|
||||
|
||||
This package is part of the Coze Studio monorepo. Please follow the monorepo contribution guidelines.
|
||||
|
||||
## License
|
||||
|
||||
Apache-2.0
|
||||
@@ -0,0 +1,41 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import loader from '../index';
|
||||
describe('test import-watch-loader', () => {
|
||||
it('code include tailwind utils', () => {
|
||||
const rawCode = `
|
||||
@tailwind utilities;
|
||||
body {
|
||||
width: 100%;
|
||||
}
|
||||
`;
|
||||
expect(() =>
|
||||
loader.call(
|
||||
{
|
||||
resourcePath: 'test1 resourcePath',
|
||||
callback: () => 0,
|
||||
},
|
||||
rawCode,
|
||||
),
|
||||
).toThrowError(
|
||||
'Error: test1 resourcePath:引入了多余的 @tailwind utilities,请删除。如有疑问请找wangfocheng',
|
||||
);
|
||||
});
|
||||
it('code not include tailwind utils', () => {
|
||||
const rawCode = `
|
||||
body {
|
||||
width: 100%;
|
||||
}
|
||||
`;
|
||||
const expectCode = rawCode;
|
||||
loader.call(
|
||||
{
|
||||
resourcePath: 'test2 resourcePath',
|
||||
callback: (error, code) => {
|
||||
expect(code).toBe(expectCode);
|
||||
},
|
||||
},
|
||||
rawCode,
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"operationSettings": [
|
||||
{
|
||||
"operationName": "test:cov",
|
||||
"outputFolderNames": ["coverage"]
|
||||
},
|
||||
{
|
||||
"operationName": "ts-check",
|
||||
"outputFolderNames": ["dist"]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"$schema": "../../../../rushx-config.schema.json",
|
||||
"packageAudit": {
|
||||
"enable": true,
|
||||
"rules": [
|
||||
[
|
||||
"essential-config-file",
|
||||
"error",
|
||||
{ "essentialFiles": ["OWNERS", "eslint.config.js"] }
|
||||
]
|
||||
]
|
||||
},
|
||||
"codecov": {
|
||||
"coverage": 0,
|
||||
"incrementCoverage": 0
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
const { defineConfig } = require('@coze-arch/eslint-config');
|
||||
|
||||
module.exports = defineConfig({
|
||||
preset: 'node',
|
||||
packageRoot: __dirname,
|
||||
});
|
||||
36
frontend/infra/plugins/import-watch-loader/index.js
Normal file
36
frontend/infra/plugins/import-watch-loader/index.js
Normal file
@@ -0,0 +1,36 @@
|
||||
const defaultRuleOwner = 'wangfocheng';
|
||||
const rules = [
|
||||
{
|
||||
regexp: /@tailwind utilities/,
|
||||
message: '引入了多余的 @tailwind utilities,请删除',
|
||||
owner: defaultRuleOwner,
|
||||
},
|
||||
{
|
||||
regexp: /@ies\/starling_intl/,
|
||||
message: '请使用@coze-arch/i18n代替直接引入@ies/starling_intl',
|
||||
owner: defaultRuleOwner,
|
||||
},
|
||||
{
|
||||
regexp: /\@coze-arch\/bot-env(?:['"]|(?:\/(?!runtime).*)?$)/,
|
||||
message:
|
||||
'请勿在web中引入@coze-arch/bot-env。GLOBAL_ENV已注入到页面中,直接使用变量即可(例: GLOBAL_ENVS.IS_BOE❌ IS_BOE✅)',
|
||||
},
|
||||
];
|
||||
|
||||
module.exports = function (code, map) {
|
||||
try {
|
||||
rules.forEach(rule => {
|
||||
if (rule.regexp.test(code)) {
|
||||
throw Error(
|
||||
`${this.resourcePath}:${rule.message}。如有疑问请找${
|
||||
rule.owner || defaultRuleOwner
|
||||
}`,
|
||||
);
|
||||
}
|
||||
});
|
||||
this.callback(null, code, map);
|
||||
} catch (err) {
|
||||
this.callback(err, code, map);
|
||||
throw Error(err);
|
||||
}
|
||||
};
|
||||
21
frontend/infra/plugins/import-watch-loader/package.json
Normal file
21
frontend/infra/plugins/import-watch-loader/package.json
Normal file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "@coze-arch/import-watch-loader",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"license": "Apache-2.0",
|
||||
"author": "wangfocheng@bytedance.com",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"build": "exit 0",
|
||||
"lint": "eslint ./",
|
||||
"test": "vitest --run --passWithNoTests",
|
||||
"test:cov": "npm run test -- --coverage"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@coze-arch/eslint-config": "workspace:*",
|
||||
"@coze-arch/ts-config": "workspace:*",
|
||||
"@coze-arch/vitest-config": "workspace:*",
|
||||
"@vitest/coverage-v8": "~3.0.5",
|
||||
"vitest": "~3.0.5"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/tsconfig",
|
||||
"extends": "@coze-arch/ts-config/tsconfig.node.json",
|
||||
"include": ["index.js"],
|
||||
"exclude": [],
|
||||
"compilerOptions": {
|
||||
"allowJs": true,
|
||||
"rootDir": "./",
|
||||
"outDir": "dist",
|
||||
"tsBuildInfoFile": "dist/tsconfig.build.tsbuildinfo"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user