Skip to content
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
1129bc9
build: add railway build config
bytemain Jan 25, 2024
4bf5ffd
fix: add missing pkg
bytemain Jan 25, 2024
df9032b
fix: avoid rebuild when deploy
bytemain Jan 25, 2024
9663a18
chore: update build
bytemain Jan 25, 2024
36bb31f
chore: add nix libs
bytemain Jan 25, 2024
72d976f
build: fix nixpacks
bytemain Jan 25, 2024
ffe118c
chore: update dockerfile
bytemain Jan 26, 2024
ce7e10c
fix: add node webpack config
bytemain Jan 26, 2024
e9a7fa5
fix: ext host log
bytemain Jan 26, 2024
1c9d7bb
feat: remove request
bytemain Jan 26, 2024
aa354cb
build: remove circular dependency
bytemain Jan 26, 2024
3dfb981
feat: add server prod
bytemain Jan 26, 2024
7a8d41f
feat: update nixpack
bytemain Jan 26, 2024
9dc23ad
refactor: update code
bytemain Jan 26, 2024
0eddf32
chore: rename Dockerfile
bytemain Jan 26, 2024
d55933c
build: optimize bundle performance
bytemain Jan 26, 2024
4a0d0d1
build: bundle prod
bytemain Jan 27, 2024
383212a
build: fix webpack config
bytemain Jan 27, 2024
fb9a7ff
build: fix webview prod build
bytemain Jan 27, 2024
5aefdd6
fix: fix wrong ext worker host and ws path
bytemain Jan 27, 2024
1fbc4a7
chore: revert code changes
bytemain Jan 27, 2024
cf89b32
chore: update lock
bytemain Jan 27, 2024
d07ee85
chore: revert code changes
bytemain Jan 27, 2024
ecc46d1
chore: revert code changes
bytemain Jan 27, 2024
feeb254
chore: update eslint ignore
bytemain Jan 27, 2024
9324d9b
chore: use esbuild minify
bytemain Jan 27, 2024
7c06e67
chore: update railway.toml
bytemain Jan 27, 2024
8582c44
chore: remove superagent
bytemain Jan 27, 2024
2da325d
chore: remove got
bytemain Jan 27, 2024
351f6c0
chore: update lock
bytemain Jan 27, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ jobs:
run: |
yarn run init
yarn run bundle:lite
yarn run bundle:standard

- name: Lint
run: |
Expand Down Expand Up @@ -81,6 +82,7 @@ jobs:
yarn install --immutable
yarn run init
yarn run bundle:lite
yarn run bundle:standard

- name: Lint
run: |
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ jspm_packages/
.yarn-integrity

dist
dist-node
lib

.vscode/*
Expand Down
11 changes: 11 additions & 0 deletions Dockerfile.node
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM node:20

WORKDIR /app/

RUN apt-get update && apt-get install -y --no-install-recommends build-essential libsecret-1-dev
COPY . /app/.

RUN yarn install --check-cache
RUN yarn run build:all

ENTRYPOINT [ "yarn", "start:prod" ]
14 changes: 14 additions & 0 deletions nixpacks.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
providers = ["..."]

[variables]
NODE_ENV = 'production'

[phases.setup]
nixPkgs = ["...", "libsecret"]
aptPkgs = ["...", "build-essential", "libsecret-1-dev"]

[phases.build]
cmds = ['yarn build:all', 'yarn bundle:prod', 'yarn download-extension']

[start]
cmd = 'node packages/startup/dist-node/server/server.js'
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,18 @@
"clean": "rimraf \"./packages/*/lib\"",
"check:dep": "ts-node ./scripts/depcheck",
"init": "yarn run clean && yarn run build:all",
"start": "yarn run rebuild:node && cross-env HOST=127.0.0.1 WS_PATH=ws://127.0.0.1:8000 NODE_ENV=development ts-node ./scripts/start",
"start:remote": "yarn run rebuild:node && cross-env NODE_ENV=development ts-node ./scripts/start",
"start": "cross-env HOST=127.0.0.1 WS_PATH=ws://127.0.0.1:8000 NODE_ENV=development ts-node ./scripts/start",
"start:remote": "cross-env NODE_ENV=development ts-node ./scripts/start",
"start:electron": "cross-env NODE_ENV=development ts-node ./scripts/start-electron",
"build:components": "cd packages/components && yarn run build:dist",
"start:lite": "cross-env NODE_ENV=development ts-node ./scripts/start --script=start:lite",
"bundle:lite": "ts-node ./scripts/start --script=bundle:lite",
"bundle:prod": "ts-node ./scripts/start --script=bundle:prod",
"start:pty-service": "KTLOG_SHOW_DEBUG=1 npx ts-node packages/terminal-next/src/node/pty.proxy.remote.exec.ts",
"create": "ts-node ./scripts/create",
"add:node": "ts-node ./scripts/add-node",
"add:browser": "ts-node ./scripts/add-browser",
"build": "yarn run compile && echo 'use `compile` instead'",
"build": "yarn run compile && yarn run rebuild:node",
"build:all": "yarn run build && yarn run build:worker-host && yarn run build:ext-host && yarn run build:components",
"compile": "cross-env NODE_ENV=production ts-node ./scripts/build",
"build:worker-host": "cd packages/extension && yarn run compile:worker",
Expand Down
15 changes: 3 additions & 12 deletions packages/components/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ module.exports = {
optimization: {
minimizer: [new OptimizeCSSAssetsPlugin({})],
},
cache: {
Comment thread
bytemain marked this conversation as resolved.
type: 'filesystem',
},
plugins: [
new MiniCssExtractPlugin({
filename: 'index.css',
Expand Down Expand Up @@ -53,18 +56,6 @@ module.exports = {
{
test: /\.tsx?$/,
use: [
{
Comment thread
bytemain marked this conversation as resolved.
loader: 'cache-loader',
options: {
cacheDirectory: path.resolve(__dirname, '../../../.cache'),
},
},
{
loader: 'thread-loader',
options: {
workers: require('os').cpus().length - 1,
},
},
{
loader: 'ts-loader',
options: {
Expand Down
2 changes: 1 addition & 1 deletion packages/core-node/src/bootstrap/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import net from 'net';
import os from 'os';
import path from 'path';

import Koa from 'koa';
import type Koa from 'koa';

import { Injector } from '@opensumi/di';
import { WebSocketHandler } from '@opensumi/ide-connection/lib/node';
Expand Down
10 changes: 3 additions & 7 deletions packages/extension-manager/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@
"@opensumi/ide-core-common": "workspace:*",
"@opensumi/ide-core-node": "workspace:*",
"@opensumi/ide-extension": "workspace:*",
"compressing": "^1.6.2",
"compressing": "^1.10.0",
"fs-extra": "^10.1.0",
"node-fetch": "^2.6.7",
"request": "2.*.*",
Comment thread
bytemain marked this conversation as resolved.
"requestretry": "^7.0.0"
"node-fetch": "^2.6.7"
},
"devDependencies": {
"@opensumi/ide-components": "workspace:*",
Expand All @@ -29,8 +27,6 @@
"@opensumi/ide-markdown": "workspace:*",
"@opensumi/ide-overlay": "workspace:*",
"@opensumi/ide-theme": "workspace:*",
"@types/node-fetch": "^2.6.1",
"@types/requestretry": "^1.12.7",
"@types/uuid": "^8.3.4"
"@types/node-fetch": "^2.6.1"
}
}
88 changes: 64 additions & 24 deletions packages/extension-manager/src/node/vsx-extension.service.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import assert from 'assert';
import os from 'os';
import path from 'path';
import { pipeline } from 'stream';

import compressing from 'compressing';
import fs from 'fs-extra';
import requestretry from 'requestretry';
import nodeFetch, { RequestInit } from 'node-fetch';

import { Injectable, Autowired, INJECTOR_TOKEN, Injector } from '@opensumi/di';
import { uuid } from '@opensumi/ide-core-common';
Expand Down Expand Up @@ -138,33 +139,72 @@ export class VSXExtensionService implements IVSXExtensionBackService {
const vsixFileName = id + '.vsix';
const downloadPath = path.join(extensionDir, vsixFileName);

return new Promise((resolve, reject) => {
requestretry(
url,
{
method: 'GET',
maxAttempts: 5,
retryDelay: 2000,
headers: this.getMarketplace().downloadHeaders,
retryStrategy: requestretry.RetryStrategies.HTTPOrNetworkError,
},
(err, response) => {
if (err) {
reject(err);
} else if (response && response.statusCode === 404) {
reject();
} else if (response && response.statusCode !== 200) {
reject(new Error(response.statusMessage));
}
},
)
.pipe(fs.createWriteStream(downloadPath))
.on('error', reject)
.on('close', () => resolve({ downloadPath }));
const res = await nodeFetchRetry(
url,
{
method: 'GET',
headers: this.getMarketplace().downloadHeaders,
},
{
maxAttempts: 5,
retryDelay: 2000,
},
);

assert(res, `download extension ${id} from ${url} failed`);

if (res.status === 404) {
throw new Error(`extension ${id} not found`);
}

if (res.status !== 200) {
throw new Error(`download extension ${id} from ${url} failed, status: ${res?.status} ${res?.statusText}`);
}

return await new Promise((resolve, reject) => {
const fileStream = fs.createWriteStream(downloadPath);
res.body.pipe(fileStream);

res.body.on('error', (err) => {
reject(err);
});
fileStream.on('finish', function () {
resolve({ downloadPath });
});
});
}

async search(param?: VSXSearchParam): Promise<VSXSearchResult> {
return await this.getMarketplace().search(param);
}
}

function sleep(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}

const nodeFetchRetry = async (
url: string,
fetchOptions: RequestInit,
opts: {
maxAttempts: number;
retryDelay: number;
},
) => {
let retry = (opts && opts.maxAttempts) || 3;

while (retry > 0) {
try {
return nodeFetch(url, fetchOptions);
} catch (e) {
retry = retry - 1;
if (retry === 0) {
throw e;
}

if (opts && opts.retryDelay) {
await sleep(opts.retryDelay);
}
}
}
};
2 changes: 1 addition & 1 deletion packages/extension/src/node/extension.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ export class ExtensionNodeServiceImpl implements IExtensionNodeService {

if (notExistExtension) {
// 进程未调用启动直接连接
this.logger.error(`${clientId} clientId process connection set error`, extProcessId);
this.logger.error(`${clientId} clientId process connection not exists`);
/**
* 如果前端与后端连接后发现没有对应的插件进程实例,那么通知前端重启插件进程
* 一般这种情况出现在用户关闭电脑超过 ProcessCloseExitThreshold 设定的最大时间,插件进程被杀死后,前端再次建立连接时
Expand Down
47 changes: 6 additions & 41 deletions packages/startup/entry/web/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,48 +10,13 @@ setLocale(defaultLanguage);

import '@opensumi/ide-i18n';
import '@opensumi/ide-core-browser/lib/style/index.less';
import { SlotLocation } from '@opensumi/ide-core-browser';
import { ExpressFileServerModule } from '@opensumi/ide-express-file-server/lib/browser';
import { defaultConfig } from '@opensumi/ide-main-layout/lib/browser/default-config';
import { RemoteOpenerModule } from '@opensumi/ide-remote-opener/lib/browser';

import { CommonBrowserModules } from '../../src/browser/common-modules';
import { SampleModule } from '../sample-modules';

import { renderApp } from './render-app';
import { getDefaultClientAppOpts, renderApp } from './render-app';

import '../styles.less';

renderApp({
modules: [...CommonBrowserModules, ExpressFileServerModule, SampleModule, RemoteOpenerModule],
layoutConfig: {
...defaultConfig,
...{
[SlotLocation.top]: {
modules: ['menubar', 'toolbar'],
},
},
...{
[SlotLocation.action]: {
modules: ['@opensumi/ide-toolbar-action'],
},
},
},
useCdnIcon: true,
useExperimentalShadowDom: true,
defaultPreferences: {
'general.language': defaultLanguage,
'general.theme': 'opensumi-dark',
'general.icon': 'vscode-icons',
'application.confirmExit': 'never',
'editor.quickSuggestionsDelay': 100,
},
defaultPanels: {
bottom: '@opensumi/ide-terminal-next',
right: '',
},
// 当 `.sumi` 下不存在配置文件时,默认采用 `.vscode` 下的配置
useVSCodeWorkspaceConfiguration: true,
// 开启 core-browser 对 OpenSumi DevTools 的支持,默认为关闭
devtools: true,
});
renderApp(
getDefaultClientAppOpts({
defaultLanguage,
}),
);
30 changes: 30 additions & 0 deletions packages/startup/entry/web/prod/app.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// eslint-disable-next-line import/order
import { LOCALE_TYPES } from '@opensumi/ide-core-common/lib/const';

const defaultLanguage = LOCALE_TYPES.EN_US;
// eslint-disable-next-line import/order
import { setLocale } from '@opensumi/ide-monaco/lib/browser/monaco-localize';
// 请注意,集成方在这里需要自己传一个正确的 locale 进去
// 如果不传则默认会根据 PreferenceScope 的优先级从 LocalStorage 取值
setLocale(defaultLanguage);

import '@opensumi/ide-i18n';
import '@opensumi/ide-core-browser/lib/style/index.less';

import { getDefaultClientAppOpts, renderApp } from '../render-app';

import '../../styles.less';

const hostname = window.location.hostname;
const port = window.location.port;

renderApp(
getDefaultClientAppOpts({
defaultLanguage,
opts: {
webviewEndpoint: '/webview',
extWorkerHost: '/worker-host.js',
wsPath: window.location.protocol === 'https:' ? `wss://${hostname}:${port}` : `ws://${hostname}:${port}`,
},
}),
);
16 changes: 16 additions & 0 deletions packages/startup/entry/web/prod/server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/* eslint-disable no-console */
import path from 'path';

import { startServer } from '@opensumi/ide-dev-tool/src/server';
import { ExpressFileServerModule } from '@opensumi/ide-express-file-server/lib/node';

import { CommonNodeModules } from '../../../src/node/common-modules';

startServer(
{
modules: [...CommonNodeModules, ExpressFileServerModule],
},
{
mountStaticPath: path.join(__dirname, '../../dist'),
},
);
Loading