Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -114,5 +114,3 @@ generated-parser

#husky
.husky

scripts/utils/_upload.js
25 changes: 25 additions & 0 deletions packages/common/src/cdn.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
export type TComponentCDNType = 'unpkg' | 'jsdelivr' | 'alipay' | 'npmmirror';

type IComponentCDNTypeMap = Record<TComponentCDNType, string>;

const CDN_TYPE_MAP: IComponentCDNTypeMap = {
alipay: 'https://gw.alipayobjects.com/os/lib',
npmmirror: 'https://registry.npmmirror.com',
unpkg: 'https://unpkg.com/browse',
jsdelivr: 'https://cdn.jsdelivr.net/npm',
};

export function getResource(
packageName: string,
filePath: string,
version: string,
cdnType: TComponentCDNType = 'alipay',
) {
if (cdnType === 'alipay') {
return `${CDN_TYPE_MAP['alipay']}/${packageName.slice(1)}/${version}/${filePath}`;
} else if (cdnType === 'npmmirror') {
return `${CDN_TYPE_MAP['npmmirror']}/${packageName}/${version}/files/${filePath}`;
} else {
return `${CDN_TYPE_MAP[cdnType]}/${packageName}@${version}/${filePath}`;
}
}
1 change: 1 addition & 0 deletions packages/common/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './mutex';
export * from './request';
export * from './types';
export * from './cdn';
4 changes: 2 additions & 2 deletions packages/core/src/api/createApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import '../core/extension/extension.patch';
import { disposableCollection, disposeMode } from '../core/patch';

import { Injector } from '@opensumi/di';
import { EXT_WORKER_HOST, WEBVIEW_ENDPOINT } from '../core/env';
import { EXT_WORKER_HOST } from '../core/env';
import { IconSlim, IDETheme } from '../core/extension/metadata';
import { getDefaultLayoutConfig, LayoutComponent } from '../core/layout';
import { modules } from '../core/modules';
Expand All @@ -46,7 +46,6 @@ export const getDefaultAppConfig = (): IAppOpts => ({
useCdnIcon: true,
noExtHost: true,
extWorkerHost: EXT_WORKER_HOST,
webviewEndpoint: WEBVIEW_ENDPOINT,
defaultPreferences: {
'general.theme': 'opensumi-design-dark-theme',
'general.icon': 'vsicons-slim',
Expand Down Expand Up @@ -75,6 +74,7 @@ export const getDefaultAppConfig = (): IAppOpts => ({
extensionStorageDirName: STORAGE_DIR,
appName,
allowSetDocumentTitleFollowWorkspaceDir: false,
useBuiltinWebview: true,
app: {
logo: 'https://mdn.alipayobjects.com/huamei_hwfivk/afts/img/A*byvFQJURn0kAAAAAAAAAAAAADlyoAQ/original',
brandName: 'Codeblitz',
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/api/createEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { deletionLogPath } from '@codeblitzjs/ide-browserfs/lib/backend/OverlayF
import { IPluginConfig } from '@codeblitzjs/ide-plugin';

import { getModules } from '../core/editor/modules';
import { EXT_WORKER_HOST, WEBVIEW_ENDPOINT } from '../core/env';
import { EXT_WORKER_HOST } from '../core/env';
import { EditorLayoutComponent, getEditorLayoutConfig } from '../core/layout';
import { disposableCollection, disposeMode } from '../core/patch';
import { mergeConfig } from '../core/utils';
Expand All @@ -35,7 +35,6 @@ const getDefaultEditorAppConfig = (): IAppOpts => ({
useCdnIcon: true,
noExtHost: true,
extWorkerHost: EXT_WORKER_HOST,
webviewEndpoint: WEBVIEW_ENDPOINT,
defaultPreferences: {
'general.theme': 'opensumi-design-light-theme',
'application.confirmExit': 'never',
Expand All @@ -59,6 +58,7 @@ const getDefaultEditorAppConfig = (): IAppOpts => ({
extensionStorageDirName: STORAGE_DIR,
appName,
allowSetDocumentTitleFollowWorkspaceDir: false,
useBuiltinWebview: true,
});

export function createEditor({ appConfig, runtimeConfig }: IConfig): IAppInstance {
Expand Down
19 changes: 5 additions & 14 deletions packages/core/src/core/env.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
/**
* worker url
*/
export const EXT_WORKER_HOST = __WORKER_HOST__;

/**
* webview endpoint
*/
export const WEBVIEW_ENDPOINT = __WEBVIEW_ENDPOINT__;

/**
* webview 脚本 url
*/
export const WEBVIEW_SCRIPT = __WEBVIEW_SCRIPT__;
import { getResource } from "@codeblitzjs/ide-common";

/**
* codeblitz version
*/
export const VERSION = __VERSION__;
/**
* worker url
*/
export const EXT_WORKER_HOST = getResource("@codeblitzjs/ide-sumi-core", "resources/worker-host.js", VERSION);
3 changes: 2 additions & 1 deletion packages/sumi-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"main": "lib/index.js",
"typings": "lib/index.d.ts",
"files": [
"lib"
"lib",
"resources"
],
"keywords": [
"opensumi codeblitzjs"
Expand Down
4 changes: 1 addition & 3 deletions packages/sumi-core/resources/manifest.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
{
"webview": "webview.9ae5c833.js",
"webview/index.html": "webview.25aac54e/index.html",
"worker-host": "worker-host.d80be369.js"
"worker-host": "worker-host.js"
}
1 change: 0 additions & 1 deletion packages/sumi-core/resources/webview.25aac54e/index.html

This file was deleted.

1 change: 0 additions & 1 deletion packages/sumi-core/resources/webview.9ae5c833.js

This file was deleted.

2 changes: 0 additions & 2 deletions packages/sumi-core/resources/worker-host.d80be369.js

This file was deleted.

2 changes: 2 additions & 0 deletions packages/sumi-core/resources/worker-host.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/toolkit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"dev": "webpack serve --config webpack/config.dev.js",
"build": "webpack --config webpack/config.build.js",
"analyze": "ANALYZE=1 npm run build",
"build:host": "webpack --config webpack/config.worker.js --config webpack/config.webview.js",
"build:host": "webpack --config webpack/config.worker.js",
Comment thread
bytemain marked this conversation as resolved.
"build:languages": "webpack --config webpack/config.languages.js",
"playground": "webpack serve --config playground/webpack.config.js"
},
Expand Down
1 change: 0 additions & 1 deletion packages/toolkit/webpack/config.build.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const path = require('path');
const fs = require('fs');
const TerserPlugin = require('terser-webpack-plugin');
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
const createWebpackConfig = require('./config.integration');
Expand Down
4 changes: 0 additions & 4 deletions packages/toolkit/webpack/config.integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,6 @@ module.exports = (option) => {
__WORKER_HOST__: process.env.WORKER_PATH
? JSON.stringify(`/assets/~${process.env.WORKER_PATH}`)
: JSON.stringify(`${baseURL}/${config.workerEntry}.js`),
__WEBVIEW_ENDPOINT__: process.env.WEBVIEW_ENDPOINT
? JSON.stringify(`/assets/~${process.env.WEBVIEW_ENDPOINT}`)
: JSON.stringify(`${baseURL}/${config.webviewEntry}`),
__WEBVIEW_SCRIPT__: JSON.stringify(''),
__VERSION__: JSON.stringify(pkg.version),
...option.define,
}),
Expand Down
6 changes: 5 additions & 1 deletion packages/toolkit/webpack/config.worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ const webpack = require('webpack');
const { WebpackManifestPlugin } = require('webpack-manifest-plugin');
const { nodePolyfill, config, manifestSeed } = require('./util');

/**
* @returns {import('webpack').Configuration}
*/
module.exports = () => {
const isDev = process.env.NODE_ENV === 'development';

Expand All @@ -13,8 +16,9 @@ module.exports = () => {
),
},
output: {
filename: `[name].${isDev ? 'js' : '[contenthash:8].js'}`,
filename: `[name].js`,
Comment thread
bytemain marked this conversation as resolved.
path: path.resolve(__dirname, '../../sumi-core/resources'),
clean: true,
},
target: 'webworker',
devtool: isDev ? 'inline-source-map' : false,
Expand Down
60 changes: 1 addition & 59 deletions scripts/build-assets.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,6 @@
/**
* 构建 worker-host 和 webview 并发布到内网 cdn 上
*/

const path = require('path');
const fs = require('fs');
const signale = require('signale');
const { invoke, exec } = require('./utils/utils');
const pkg = require('../package.json');
const { upload } = require('./utils/upload');
const args = require('minimist')(process.argv.slice(2));

const assetsKeyMap = {
__WORKER_HOST__: 'worker-host',
__WEBVIEW_ENDPOINT__: 'webview/index.html',
__WEBVIEW_SCRIPT__: 'webview',
};

invoke(async () => {
signale.pending(`开始编译 worker-host 和 webview`);
Expand All @@ -25,51 +11,7 @@ invoke(async () => {

const distDir = path.resolve(__dirname, '../packages/sumi-core/resources');
const manifest = require(path.join(distDir, 'manifest.json'));
const fileJSON = Object.keys(manifest).reduce((obj, key) => {
obj[key] = {
filename: manifest[key],
filepath: path.join(distDir, manifest[key]),
};
return obj;
}, {});
if (args['disable-upload']) {
return;
}

signale.info('构建成功,开始上传 cdn');
const cdnResult = await upload(fileJSON);
signale.info('上传成功,生成 define.json');

const transformHttps = (str) => str.replace(/^http:/, 'https:');
const env = {
__WORKER_HOST__: {
key: assetsKeyMap.__WORKER_HOST__,
transform: transformHttps,
},
__WEBVIEW_ENDPOINT__: {
key: assetsKeyMap.__WEBVIEW_ENDPOINT__,
transform: (v) => transformHttps(v.slice(0, v.lastIndexOf('/'))),
},
__WEBVIEW_SCRIPT__: {
key: assetsKeyMap.__WEBVIEW_SCRIPT__,
transform: transformHttps,
}
};
const config = Object.keys(env).reduce(
(obj, name) => {
const { key, transform } = env[name];
if (cdnResult[key]) {
obj[name] = transform(cdnResult[key]);
}
return obj;
},
{ __OPENSUMI_VERSION__: pkg.engines.opensumi }
);

fs.writeFileSync(
path.resolve(__dirname, '../packages/toolkit/define.json'),
JSON.stringify(config, null, 2)
);
console.log('manifest', manifest);
Comment thread
bytemain marked this conversation as resolved.

signale.success('构建资源成功');
});
15 changes: 0 additions & 15 deletions scripts/utils/upload.js

This file was deleted.

4 changes: 1 addition & 3 deletions typings/global/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ declare module 'process' {
// build 时会被替换
declare var __DEV__: string;
declare var __WORKER_HOST__: string;
declare var __WEBVIEW_ENDPOINT__: string;
declare var __WEBVIEW_SCRIPT__: string;
declare var __VERSION__: string;

type Optional<T, K extends keyof T> = Omit<T, K> & Partial<T>;
Expand All @@ -24,4 +22,4 @@ declare module '@codeblitzjs/ide-core/extensions/*' {
import { IExtensionBasicMetadata } from '@codeblitzjs/ide-common';
const metadata: IExtensionBasicMetadata;
export = metadata;
}
}