Skip to content

Commit

Permalink
chore: export events and types for re-use in vscode
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcMcIntosh committed Jan 24, 2024
1 parent 6c0096f commit e8ce11f
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 55 deletions.
1 change: 1 addition & 0 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
[ ] check what happens when the lsp isn't on in vscode
[ ] in vscode attach shouldn't show if there's no files (like when opening the ide)
[ ] canceling chat doesn't seems to work (the spinner keeps spinning) :/
[x] build the events (+ types) as a dedicated file

### EVENTS TODO FOR IDEs

Expand Down
21 changes: 16 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,22 @@
"type": "module",
"files": [
"dist",
"dist/style.css"
"dist/chat/style.css"
],
"main": "dist/refact-chat.umd.cjs",
"module": "dist/refact-chat.js",
"types": "dist/refact-chat.d.ts",
"main": "dist/chat/index.umd.cjs",
"module": "dist/chat/index.js",
"exports": {
".": {
"import": "./dist/chat/index.js",
"require": "./dist/chat/index.umd.cjs",
"types": "./dist/chat/index.d.ts"
},
"./dist/events": {
"import": "./dist/events/index.js",
"require": "./dist/events/index.umd.cjs",
"types": "./dist/events/index.d.ts"
}
},
"repository": {
"type": "git",
"url": "https://github.com/smallcloudai/refact-chat-js"
Expand All @@ -19,7 +30,7 @@
},
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"build": "tsc && vite build && vite build -c vite.node.config.ts",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview",
"test": "vitest",
Expand Down
2 changes: 2 additions & 0 deletions src/events/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {
ChatContextFile,
} from "../services/refact";

export type * from "../services/refact";

export enum EVENT_NAMES_FROM_CHAT {
SAVE_CHAT = "save_chat_to_history",
ASK_QUESTION = "chat_question",
Expand Down
2 changes: 1 addition & 1 deletion src/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from "./types";
export * from "../events";
export { render } from "./render";
2 changes: 0 additions & 2 deletions src/lib/types.ts

This file was deleted.

2 changes: 1 addition & 1 deletion tsconfig.node.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
"allowSyntheticDefaultImports": true,
"strict": true
},
"include": ["vite.config.ts", "vite.library.config.ts"]
"include": ["vite.config.ts", "vite.node.config.ts"]
}
112 changes: 66 additions & 46 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,56 +6,76 @@ import eslint from "vite-plugin-eslint";
import { coverageConfigDefaults } from "vitest/config";
import dts from "vite-plugin-dts";

// TODO: remove extra compile step when vscode can run esmodules

// https://vitejs.dev/config/
/** @type {import('vite').UserConfig} */
export default defineConfig(({ command, mode }) => {
const CONFIG: UserConfig = {
// Build the webpage
define: {
"process.env.NODE_ENV": JSON.stringify(mode),
},
mode,
build: {
emptyOutDir: true,
outDir: "dist",
},
plugins: [react()],
server: {
proxy: {
"/v1": process.env.REFACT_LSP_URL ?? "http://127.0.0.1:8001",
function makeConfig(library: "browser" | "node") {
return defineConfig(({ command, mode }) => {
const OUT_DIR = library === "browser" ? "dist/chat" : "dist/events";
const CONFIG: UserConfig = {
// Build the webpage
define: {
"process.env.NODE_ENV": JSON.stringify(mode),
},
mode,
build: {
emptyOutDir: true,
outDir: OUT_DIR,
copyPublicDir: false,
},
},
test: {
environment: "jsdom",
coverage: {
exclude: coverageConfigDefaults.exclude.concat(
"**/*.stories.@(js|jsx|mjs|ts|tsx)",
),
plugins: [react()],
server: {
proxy: {
"/v1": process.env.REFACT_LSP_URL ?? "http://127.0.0.1:8001",
},
},
},
css: {
modules: {},
},
};

if (command !== "serve") {
CONFIG.mode = "production";
CONFIG.define = { "process.env.NODE_ENV": "'production'" };
CONFIG.plugins?.push([
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
eslint() as PluginOption,
dts({ rollupTypes: true }),
]);
CONFIG.build = {
outDir: "dist",
lib: {
// TODO: make entry an object
entry: path.resolve(__dirname, "src/lib/index.ts"),
name: "RefactChat",
fileName: "chat",
test: {
environment: "jsdom",
coverage: {
exclude: coverageConfigDefaults.exclude.concat(
"**/*.stories.@(js|jsx|mjs|ts|tsx)",
),
},
},
css: {
modules: {},
},
};
}

return CONFIG;
});
if (command !== "serve") {
CONFIG.mode = "production";
CONFIG.define = { "process.env.NODE_ENV": "'production'" };
CONFIG.plugins?.push([
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
eslint() as PluginOption,
]);

CONFIG.plugins?.push([
dts({
outDir: OUT_DIR,
rollupTypes: true,
insertTypesEntry: true,
}),
]);

CONFIG.build = {
...CONFIG.build,
lib: {
entry:
library === "browser"
? path.resolve(__dirname, "src/lib/index.ts")
: path.resolve(__dirname, "src/events/index.ts"),
name: "RefactChat",
fileName: "index",
},
};
}

return CONFIG;
});
}

export default makeConfig("browser");

export const nodeConfig = makeConfig("node");
1 change: 1 addition & 0 deletions vite.node.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { nodeConfig as default } from "./vite.config";

0 comments on commit e8ce11f

Please sign in to comment.