Skip to content

Commit 93c4530

Browse files
committed
fix: build app bundler
1 parent d35c020 commit 93c4530

File tree

7 files changed

+178
-30
lines changed

7 files changed

+178
-30
lines changed

apps/omega/forge.config.ts

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,16 @@ const projectRoot = path.resolve(__dirname, '.');
2121
const keepModules = new Set([
2222
...Object.keys(pkg.dependencies),
2323
'@mixmark-io/domino',
24+
'@modelcontextprotocol/sdk',
2425
]);
25-
const needSubDependencies = [...Object.values(keepModules)];
26+
const needSubDependencies = ['@modelcontextprotocol/sdk'];
2627
const keepLanguages = new Set(['en', 'en_GB', 'en-US', 'en_US']);
2728
const ignorePattern = new RegExp(
2829
`^/node_modules/(?!${[...keepModules].join('|')})`,
2930
);
3031

3132
console.log('keepModules', keepModules);
33+
console.log('needSubDependencies', needSubDependencies);
3234
console.log('ignorePattern', ignorePattern);
3335

3436
const enableOsxSign =
@@ -111,23 +113,24 @@ async function cleanSources(
111113
needSubDependencies,
112114
projectRoot,
113115
);
116+
console.log('subDependencies', subDependencies);
114117
await Promise.all(
115-
Array.from(subDependencies.values()).map((subDependency) => {
116-
if (
117-
fs.existsSync(path.join(buildPath, 'node_modules', subDependency.name))
118-
) {
119-
return;
120-
}
121-
122-
if (fs.existsSync(subDependency.path)) {
123-
console.log('copy_current_node_modules', subDependency.path);
124-
return cp(
125-
subDependency.path,
126-
path.join(buildPath, 'node_modules', subDependency.name),
127-
{
128-
recursive: true,
129-
},
130-
);
118+
subDependencies.map((subDependency) => {
119+
console.log(
120+
'target_dir',
121+
path.join(buildPath, 'node_modules', subDependency.name),
122+
);
123+
const targetDir = path.join(
124+
buildPath,
125+
'node_modules',
126+
subDependency.name,
127+
);
128+
const sourceDir = subDependency.path;
129+
if (!fs.existsSync(targetDir) && fs.existsSync(sourceDir)) {
130+
console.log('copy_current_node_modules', sourceDir);
131+
return cp(sourceDir, targetDir, {
132+
recursive: true,
133+
});
131134
}
132135
return;
133136
}),

apps/omega/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "agent-tars-app",
3-
"version": "1.0.0",
3+
"version": "1.0.0-beta.1",
44
"description": "An Electron application with React and TypeScript",
55
"main": "./dist/main/index.js",
66
"author": "example.com",
@@ -14,7 +14,7 @@
1414
"start": "electron-vite preview",
1515
"dev": "electron-vite dev",
1616
"package": "electron-forge package",
17-
"build": "npm run typecheck && npm run build:reporter && electron-vite build && electron-forge make",
17+
"build": "rimraf dist out && npm run typecheck && npm run build:reporter && electron-vite build && electron-forge make",
1818
"test": "vitest run",
1919
"publish:mac": "electron-vite build && electron-forge publish --arch=universal --platform=darwin",
2020
"build:reporter": "vite build"
@@ -74,6 +74,7 @@
7474
"@types/node": "^22.13.4",
7575
"@types/fs-extra": "11.0.4",
7676
"@vitejs/plugin-react": "^4.3.4",
77+
"rimraf": "^6.0.1",
7778
"autoprefixer": "10.4.20",
7879
"electron": "34.1.1",
7980
"electron-packager-languages": "0.6.0",

apps/omega/src/main/llmProvider/providers/AzureOpenAIProvider.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ export class AzureOpenAIProvider extends BaseProvider {
1616
super(config);
1717

1818
// Use environment variables or defaults
19-
const apiKey = config.apiKey || process.env.AZURE_OPENAI_API_KEY;
20-
const endpoint = config.baseURL || process.env.AZURE_OPENAI_ENDPOINT;
19+
const apiKey =
20+
config.apiKey || process.env.AZURE_OPENAI_API_KEY || 'your-api-key';
21+
const endpoint =
22+
config.baseURL || process.env.AZURE_OPENAI_ENDPOINT || 'your-endpoint';
2123
const apiVersion =
2224
config.apiVersion ||
2325
process.env.AZURE_OPENAI_API_VERSION ||

packages/common/electron-build/rslib.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ export default defineConfig({
99
...rslibConfig,
1010
output: {
1111
...rslibConfig.output,
12-
target: 'web',
12+
target: 'node',
1313
},
1414
});
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/**
2+
* The following code is modified based on
3+
* https://github.com/sindresorhus/find-up-simple/blob/main/index.js
4+
*
5+
* MIT License
6+
* Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
7+
* https://github.com/sindresorhus/find-up-simple/blob/main/license
8+
*/
9+
10+
import process from 'node:process';
11+
import fsPromises from 'node:fs/promises';
12+
import { fileURLToPath } from 'node:url';
13+
import fs from 'node:fs';
14+
import path from 'node:path';
15+
16+
const toPath = (urlOrPath: string | URL) =>
17+
urlOrPath instanceof URL ? fileURLToPath(urlOrPath) : urlOrPath;
18+
19+
export async function findUp(
20+
name: string,
21+
{
22+
cwd = process.cwd(),
23+
type = 'file',
24+
stopAt,
25+
}: {
26+
cwd?: string | URL;
27+
type?: string;
28+
stopAt?: string | URL;
29+
} = {},
30+
) {
31+
let directory = path.resolve(toPath(cwd) ?? '');
32+
const { root } = path.parse(directory);
33+
stopAt = path.resolve(directory, toPath(stopAt ?? root));
34+
const isAbsoluteName = path.isAbsolute(name);
35+
36+
while (directory) {
37+
const filePath = isAbsoluteName ? name : path.join(directory, name);
38+
try {
39+
const stats = await fsPromises.stat(filePath); // eslint-disable-line no-await-in-loop
40+
if (
41+
(type === 'file' && stats.isFile()) ||
42+
(type === 'directory' && stats.isDirectory())
43+
) {
44+
return filePath;
45+
}
46+
} catch {}
47+
48+
if (directory === stopAt || directory === root) {
49+
break;
50+
}
51+
52+
directory = path.dirname(directory);
53+
}
54+
}
55+
56+
export function findUpSync(
57+
name: string,
58+
// @ts-ignore
59+
{ cwd = process.cwd(), type = 'file', stopAt } = {},
60+
) {
61+
let directory = path.resolve(toPath(cwd) ?? '');
62+
const { root } = path.parse(directory);
63+
stopAt = path.resolve(directory, toPath(stopAt) ?? root);
64+
const isAbsoluteName = path.isAbsolute(name);
65+
66+
while (directory) {
67+
const filePath = isAbsoluteName ? name : path.join(directory, name);
68+
69+
try {
70+
const stats = fs.statSync(filePath, { throwIfNoEntry: false });
71+
if (
72+
(type === 'file' && stats?.isFile()) ||
73+
(type === 'directory' && stats?.isDirectory())
74+
) {
75+
return filePath;
76+
}
77+
} catch {}
78+
79+
if (directory === stopAt || directory === root) {
80+
break;
81+
}
82+
83+
directory = path.dirname(directory);
84+
}
85+
}

packages/common/electron-build/src/getPackageDependencies.ts

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,49 @@
88
*/
99
import { Walker, DepType } from 'flora-colossus';
1010
import { dirname } from 'path';
11+
import { findUpSync } from './findUp';
1112

1213
export const getModuleRoot = (cwd: string, pkgName: string): string => {
13-
const moduleRoot = dirname(
14+
const moduleEntryPath = dirname(
1415
require.resolve(`${pkgName}/package.json`, {
1516
paths: [cwd || process.cwd()],
1617
}),
1718
);
19+
20+
let pkgPath = findUpSync('package.json', {
21+
cwd: moduleEntryPath,
22+
});
23+
24+
if (!pkgPath) {
25+
return '';
26+
}
27+
28+
let currentDir = dirname(pkgPath);
29+
let isMatched = false;
30+
31+
while (pkgPath && !isMatched) {
32+
try {
33+
const pkg = require(pkgPath);
34+
if (pkg.name === pkgName) {
35+
isMatched = true;
36+
break;
37+
}
38+
39+
currentDir = dirname(currentDir);
40+
pkgPath = findUpSync('package.json', {
41+
cwd: currentDir,
42+
});
43+
} catch (err) {
44+
console.warn('Failed to read package.json:', err);
45+
break;
46+
}
47+
}
48+
49+
if (!isMatched || !pkgPath) {
50+
return '';
51+
}
52+
53+
const moduleRoot = dirname(pkgPath);
1854
return moduleRoot;
1955
};
2056

@@ -27,14 +63,15 @@ export async function getExternalPkgsDependencies(
2763
path: string;
2864
}[]
2965
> {
30-
const dependencies = new Set<{
31-
name: string;
32-
path: string;
33-
}>(pkgNames.map((name) => ({ name, path: getModuleRoot(cwd, name) })));
66+
const dependenciesMap = new Map<string, { name: string; path: string }>();
67+
pkgNames.forEach((name) => {
68+
dependenciesMap.set(name, { name, path: getModuleRoot(cwd, name) });
69+
});
3470

3571
for (const pkgName of pkgNames) {
3672
try {
3773
const moduleRoot = getModuleRoot(cwd, pkgName);
74+
console.log('moduleRoot', moduleRoot);
3875

3976
const walker = new Walker(moduleRoot);
4077
// These are private so it's quite nasty!
@@ -46,18 +83,18 @@ export async function getExternalPkgsDependencies(
4683
walker.modules
4784
.filter((dep: any) => dep.nativeModuleType === DepType.PROD)
4885
.forEach((dep: any) =>
49-
dependencies.add({
86+
dependenciesMap.set(dep.name, {
5087
name: dep.name,
5188
path: dep.path,
5289
}),
5390
);
5491

5592
// @ts-ignore
56-
console.log('walker.modules', walker.modules);
93+
// console.log('walker.modules', walker.modules);
5794
} catch (error) {
5895
console.warn('error', error);
5996
}
6097
}
6198

62-
return Array.from(dependencies.values());
99+
return Array.from(dependenciesMap.values());
63100
}

pnpm-lock.yaml

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)