Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use json #75

Merged
merged 2 commits into from
Apr 5, 2023
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: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@vscode/test-web",
"version": "0.0.39",
"version": "0.0.40",
"scripts": {
"install-extensions": "yarn --cwd=fs-provider && yarn --cwd=sample",
"compile": "tsc -p ./ && yarn compile-fs-provider",
Expand Down
12 changes: 6 additions & 6 deletions src/server/workbench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ function asJSON(value: unknown): string {
}

class Workbench {
constructor(readonly baseUrl: string, readonly dev: boolean, readonly esm: boolean, private readonly builtInExtensions: IScannedBuiltinExtension[] = [], private readonly productOverrides: string = '') { }
constructor(readonly baseUrl: string, readonly dev: boolean, readonly esm: boolean, private readonly builtInExtensions: IScannedBuiltinExtension[] = [], private readonly productOverrides?: Record<string, any>) { }

async render(workbenchWebConfiguration: IWorkbenchOptions): Promise<string> {
const values: { [key: string]: string } = {
WORKBENCH_WEB_CONFIGURATION: asJSON(workbenchWebConfiguration),
WORKBENCH_AUTH_SESSION: '',
WORKBENCH_WEB_BASE_URL: this.baseUrl,
WORKBENCH_BUILTIN_EXTENSIONS: asJSON(this.builtInExtensions),
WORKBENCH_PRODUCT_OVERRIDES: this.productOverrides,
WORKBENCH_PRODUCT_OVERRIDES: this.productOverrides ? asJSON(this.productOverrides) : '',
WORKBENCH_MAIN: this.getMain()
};

Expand Down Expand Up @@ -134,7 +134,7 @@ export default function (config: IConfig): Router.Middleware {
router.use(async (ctx, next) => {
if (config.build.type === 'sources') {
const builtInExtensions = await getScannedBuiltinExtensions(config.build.location);
const productOverrides = await getProductOverridesContent(config.build.location);
const productOverrides = await getProductOverrides(config.build.location);
ctx.state.workbench = new Workbench(`${ctx.protocol}://${ctx.host}/static/sources`, true, config.esm, builtInExtensions, productOverrides);
} else if (config.build.type === 'static') {
ctx.state.workbench = new Workbench(`${ctx.protocol}://${ctx.host}/static/build`, false, config.esm);
Expand All @@ -160,10 +160,10 @@ export default function (config: IConfig): Router.Middleware {
return router.routes();
}

async function getProductOverridesContent(vsCodeDevLocation: string): Promise<string> {
async function getProductOverrides(vsCodeDevLocation: string): Promise<Record<string, any> | undefined> {
try {
return (await fs.readFile(path.join(vsCodeDevLocation, 'product.overrides.json'))).toString();
return JSON.parse((await fs.readFile(path.join(vsCodeDevLocation, 'product.overrides.json'))).toString());
} catch (e) {
return '';
return undefined;
}
}