Skip to content

Commit

Permalink
feat: source code import to examples (#76)
Browse files Browse the repository at this point in the history
* feat: coze-js remove import .js

* feat: @coze/api 源码引入到coze-js-web、coze-js-node

* feat: realtime-api 源码引入到 examples

* feat: rebase 0109

feat: tsconfig

feat: cozePublishConfig

* feat: rebase 0113

* feat: taro dev source

---------

Co-authored-by: wfc <[email protected]>
  • Loading branch information
wfc-web and wfc authored Jan 14, 2025
1 parent 11e63ab commit 459b45e
Show file tree
Hide file tree
Showing 60 changed files with 317 additions and 160 deletions.
11 changes: 11 additions & 0 deletions common/changes/@coze/api/feat-dev-source_2025-01-07-08-18.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"packageName": "@coze/api",
"comment": "coze-js remove import .js",
"type": "minor"
}
],
"packageName": "@coze/api",
"email": "[email protected]"
}
11 changes: 11 additions & 0 deletions common/changes/@coze/api/feat-dev-source_2025-01-08-06-37.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"packageName": "@coze/api",
"comment": "@coze/api 源码引入到coze-js-web、coze-js-node",
"type": "minor"
}
],
"packageName": "@coze/api",
"email": "[email protected]"
}
11 changes: 11 additions & 0 deletions common/changes/@coze/api/feat-dev-source_2025-01-09-03-50.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"packageName": "@coze/api",
"comment": "rebase 0109",
"type": "minor"
}
],
"packageName": "@coze/api",
"email": "[email protected]"
}
11 changes: 11 additions & 0 deletions common/changes/@coze/api/feat-dev-source_2025-01-13-11-30.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"packageName": "@coze/api",
"comment": "cozePublishConfig",
"type": "minor"
}
],
"packageName": "@coze/api",
"email": "[email protected]"
}
11 changes: 11 additions & 0 deletions common/changes/@coze/api/feat-dev-source_2025-01-13-13-06.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"packageName": "@coze/api",
"comment": "rebase 0113",
"type": "minor"
}
],
"packageName": "@coze/api",
"email": "[email protected]"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"packageName": "@coze/realtime-api",
"comment": "realtime-api 源码引入到 examples",
"type": "minor"
}
],
"packageName": "@coze/realtime-api",
"email": "[email protected]"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"packageName": "@coze/realtime-api",
"comment": "rebase 0109",
"type": "minor"
}
],
"packageName": "@coze/realtime-api",
"email": "[email protected]"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"packageName": "@coze/realtime-api",
"comment": "cozePublishConfig",
"type": "minor"
}
],
"packageName": "@coze/realtime-api",
"email": "[email protected]"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"packageName": "@coze/realtime-api",
"comment": "taro dev source",
"type": "minor"
}
],
"packageName": "@coze/realtime-api",
"email": "[email protected]"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"packageName": "@coze/taro-api",
"comment": "taro dev source",
"type": "minor"
}
],
"packageName": "@coze/taro-api",
"email": "[email protected]"
}
12 changes: 12 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.

7 changes: 4 additions & 3 deletions examples/coze-js-node/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"compilerOptions": {
"target": "ESNext",
"module": "NodeNext",
"moduleResolution": "nodenext",
"module": "es2022",
"moduleResolution": "node",
"esModuleInterop": true,
"allowJs": true,
"strict": true,
"outDir": "dist"
"outDir": "dist",
"resolveJsonModule": true
},
"include": ["src/**/*"],
"ts-node": {
Expand Down
16 changes: 16 additions & 0 deletions examples/coze-js-taro3/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import { defineConfig, type UserConfigExport } from '@tarojs/cli';
import TsconfigPathsPlugin from 'tsconfig-paths-webpack-plugin';
import devConfig from './dev';
import prodConfig from './prod';
import path from 'path';

const packagesDir = path.resolve(__dirname, '../../../../');
export default defineConfig(async merge => {
const baseConfig: UserConfigExport = {
projectName: 'coze-js-taro3',
Expand Down Expand Up @@ -60,6 +62,13 @@ export default defineConfig(async merge => {
return args;
});
chain.resolve.plugin('tsconfig-paths').use(TsconfigPathsPlugin);
chain.module
.rule('taroApiBabel')
.test(/\.ts$/)
.use('babel-loader')
.loader('babel-loader')
.end()
.include.add(packagesDir);
},
},
h5: {
Expand Down Expand Up @@ -97,6 +106,13 @@ export default defineConfig(async merge => {
return args;
});
chain.resolve.plugin('tsconfig-paths').use(TsconfigPathsPlugin);
chain.module
.rule('taroApiBabel')
.test(/\.ts$/)
.use('babel-loader')
.loader('babel-loader')
.end()
.include.add(packagesDir);
},
},
rn: {
Expand Down
1 change: 1 addition & 0 deletions examples/coze-js-taro3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"@types/webpack-env": "^1.13.6",
"@vue/babel-plugin-jsx": "^1.0.6",
"@vue/compiler-sfc": "^3.0.0",
"babel-loader": "^8.2.3",
"babel-preset-taro": "3.6.35",
"css-loader": "^6.5.1",
"postcss": "^8.4.4",
Expand Down
32 changes: 17 additions & 15 deletions examples/coze-js-web/config/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ const shouldUseSourceMap = process.env.GENERATE_SOURCEMAP !== 'false';

const reactRefreshRuntimeEntry = require.resolve('react-refresh/runtime');
const reactRefreshWebpackPluginRuntimeEntry = require.resolve(
'@pmmmwh/react-refresh-webpack-plugin'
'@pmmmwh/react-refresh-webpack-plugin',
);
const babelRuntimeEntry = require.resolve('babel-preset-react-app');
const babelRuntimeEntryHelpers = require.resolve(
'@babel/runtime/helpers/esm/assertThisInitialized',
{ paths: [babelRuntimeEntry] }
{ paths: [babelRuntimeEntry] },
);
const babelRuntimeRegenerator = require.resolve('@babel/runtime/regenerator', {
paths: [babelRuntimeEntry],
Expand All @@ -47,17 +47,16 @@ const babelRuntimeRegenerator = require.resolve('@babel/runtime/regenerator', {
// makes for a smoother build process.
const shouldInlineRuntimeChunk = process.env.INLINE_RUNTIME_CHUNK !== 'false';


const imageInlineSizeLimit = parseInt(
process.env.IMAGE_INLINE_SIZE_LIMIT || '10000'
process.env.IMAGE_INLINE_SIZE_LIMIT || '10000',
);

// Check if TypeScript is setup
const useTypeScript = fs.existsSync(paths.appTsConfig);

// Check if Tailwind config exists
const useTailwind = fs.existsSync(
path.join(paths.appPath, 'tailwind.config.js')
path.join(paths.appPath, 'tailwind.config.js'),
);

// Get the path to the uncompiled service worker (if it exists).
Expand Down Expand Up @@ -177,7 +176,7 @@ module.exports = function (webpackEnv) {
options: {
sourceMap: true,
},
}
},
);
}
return loaders;
Expand Down Expand Up @@ -235,7 +234,7 @@ module.exports = function (webpackEnv) {
defaultWebpack: ['webpack/lib/'],
config: [__filename],
tsconfig: [paths.appTsConfig, paths.appJsConfig].filter(f =>
fs.existsSync(f)
fs.existsSync(f),
),
},
},
Expand Down Expand Up @@ -295,7 +294,7 @@ module.exports = function (webpackEnv) {
// if there are any conflicts. This matches Node resolution mechanism.
// https://github.com/facebook/create-react-app/issues/253
modules: ['node_modules', paths.appNodeModules].concat(
modules.additionalModulePaths || []
modules.additionalModulePaths || [],
),
// These are the reasonable defaults supported by the Node ecosystem.
// We also include JSX as a common component filename extension to support
Expand Down Expand Up @@ -402,11 +401,14 @@ module.exports = function (webpackEnv) {
// The preset includes JSX, Flow, TypeScript, and some ESnext features.
{
test: /\.(js|mjs|jsx|ts|tsx)$/,
include: paths.appSrc,
include: [
paths.appSrc,
path.resolve(__dirname, '../../../packages'),
],
loader: require.resolve('babel-loader'),
options: {
customize: require.resolve(
'babel-preset-react-app/webpack-overrides'
'babel-preset-react-app/webpack-overrides',
),
presets: [
[
Expand Down Expand Up @@ -514,7 +516,7 @@ module.exports = function (webpackEnv) {
mode: 'icss',
},
},
'sass-loader'
'sass-loader',
),
// Don't consider CSS imports dead code even if the
// containing package claims to have no side effects.
Expand All @@ -537,7 +539,7 @@ module.exports = function (webpackEnv) {
getLocalIdent: getCSSModuleLocalIdent,
},
},
'sass-loader'
'sass-loader',
),
},
// "file" loader makes sure those assets get served by WebpackDevServer.
Expand Down Expand Up @@ -583,8 +585,8 @@ module.exports = function (webpackEnv) {
minifyURLs: true,
},
}
: undefined
)
: undefined,
),
),
// Inlines the webpack runtime script. This script is too small to warrant
// a network request.
Expand Down Expand Up @@ -640,7 +642,7 @@ module.exports = function (webpackEnv) {
return manifest;
}, seed);
const entrypointFiles = entrypoints.main.filter(
fileName => !fileName.endsWith('.map')
fileName => !fileName.endsWith('.map'),
);

return {
Expand Down
26 changes: 17 additions & 9 deletions packages/coze-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,16 @@
"author": "Leeight <[email protected]>",
"type": "module",
"exports": {
".": {
"require": "./dist/cjs/index.cjs",
"import": "./dist/esm/index.js",
"types": "./dist/types/index.d.ts"
}
".": "./src/index.ts"
},
"main": "dist/cjs/index.cjs",
"module": "dist/esm/index.js",
"main": "src/index.ts",
"module": "src/index.ts",
"browser": {
"crypto": false,
"os": false,
"jsonwebtoken": false
},
"types": "dist/types/index.d.ts",
"types": "src/index.ts",
"files": [
"dist",
"LICENSE",
Expand Down Expand Up @@ -71,5 +67,17 @@
},
"peerDependencies": {
"axios": "^1.7.1"
},
"cozePublishConfig": {
"exports": {
".": {
"require": "./dist/cjs/index.cjs",
"import": "./dist/esm/index.js",
"types": "./dist/types/index.d.ts"
}
},
"main": "dist/cjs/index.cjs",
"module": "dist/esm/index.js",
"types": "dist/types/index.d.ts"
}
}
}
8 changes: 4 additions & 4 deletions packages/coze-js/src/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import * as nodeCrypto from 'crypto';

import jwt from 'jsonwebtoken';

import { isBrowser, sleep } from './utils.js';
import { APIError } from './error.js';
import { APIClient, type RequestOptions } from './core.js';
import { isBrowser, sleep } from './utils';
import { APIError } from './error';
import { APIClient, type RequestOptions } from './core';
import {
COZE_COM_BASE_URL,
MAX_POLL_INTERVAL,
POLL_INTERVAL,
} from './constant.js';
} from './constant';

const getCrypto = () => {
if (isBrowser()) {
Expand Down
Loading

0 comments on commit 459b45e

Please sign in to comment.