From b51a47e6fcf12217563b96e322c120b369a1840a Mon Sep 17 00:00:00 2001 From: Martin Aeschlimann Date: Tue, 5 Jul 2022 10:41:32 +0200 Subject: [PATCH 1/3] Fix extension source maps --- package.json | 3 ++- src/server/app.ts | 13 ++++++++++++- yarn.lock | 5 +++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 5e81c3f..3c105a7 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,8 @@ "http-proxy-agent": "^5.0.0", "https-proxy-agent": "^5.0.1", "decompress": "^4.2.1", - "decompress-targz": "^4.1.1" + "decompress-targz": "^4.1.1", + "get-stream": "6.0.1" }, "devDependencies": { "@types/koa": "^2.13.4", diff --git a/src/server/app.ts b/src/server/app.ts index b7114d1..857c321 100644 --- a/src/server/app.ts +++ b/src/server/app.ts @@ -3,12 +3,14 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ +import { ReadStream } from 'fs'; import * as Koa from 'koa'; import * as morgan from 'koa-morgan'; import * as kstatic from 'koa-static'; import * as kmount from 'koa-mount'; import * as cors from '@koa/cors'; -import { join } from 'path'; +import * as getstream from 'get-stream'; +import { basename, join } from 'path'; import { IConfig } from './main'; import workbench from './workbench'; import { configureMounts } from './mounts'; @@ -42,6 +44,15 @@ export default async function createApp(config: IConfig): Promise { return next(); }); + // shift the line numbers of source maps in extensions by 2 as the content is wrapped by an anonymous function + app.use(async (ctx, next) => { + await next(); + if (ctx.status === 200 && ctx.path.match(/\/extensions\/.*\.js\.map$/) && ctx.body instanceof ReadStream) { + // we know it's a ReadSetram as that's what kstatic uses + ctx.response.body = `{"version":3,"file":"${basename(ctx.path)}","sections":[{"offset":{"line":2,"column":0},"map":${await getstream(ctx.body)} }]}`; + } + }); + const serveOptions: kstatic.Options = { hidden: true }; if (config.extensionDevelopmentPath) { diff --git a/yarn.lock b/yarn.lock index 92fc5d9..ff3ce99 100644 --- a/yarn.lock +++ b/yarn.lock @@ -943,6 +943,11 @@ functional-red-black-tree@^1.0.1: resolved "https://registry.yarnpkg.com/functional-red-black-tree/-/functional-red-black-tree-1.0.1.tgz#1b0ab3bd553b2a0d6399d29c0e3ea0b252078327" integrity sha1-GwqzvVU7Kg1jmdKcDj6gslIHgyc= +get-stream@6.0.1: + version "6.0.1" + resolved "https://registry.yarnpkg.com/get-stream/-/get-stream-6.0.1.tgz#a262d8eef67aced57c2852ad6167526a43cbf7b7" + integrity sha512-ts6Wi+2j3jQjqi70w5AlN8DFnkSwC+MqmxEzdEALB2qXZYV3X/b1CTfgPLGJNMeAWxdPfU8FO1ms3NUfaHCPYg== + get-stream@^2.2.0: version "2.3.1" resolved "https://registry.yarnpkg.com/get-stream/-/get-stream-2.3.1.tgz#5f38f93f346009666ee0150a054167f91bdd95de" From 875f4c2914665412b75399b979518a89a97c3511 Mon Sep 17 00:00:00 2001 From: Martin Aeschlimann Date: Tue, 5 Jul 2022 10:41:58 +0200 Subject: [PATCH 2/3] prepare 0.0.27 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3c105a7..4d74d8b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@vscode/test-web", - "version": "0.0.26", + "version": "0.0.27", "scripts": { "install-extensions": "yarn --cwd=fs-provider && yarn --cwd=sample", "compile": "tsc -p ./ && yarn compile-fs-provider", From f2a1c6f31447ca91df0ec770ed9a7e27a979a208 Mon Sep 17 00:00:00 2001 From: Martin Aeschlimann Date: Tue, 5 Jul 2022 11:21:00 +0200 Subject: [PATCH 3/3] fix for devextensions --- src/server/app.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/server/app.ts b/src/server/app.ts index 857c321..783bd94 100644 --- a/src/server/app.ts +++ b/src/server/app.ts @@ -47,8 +47,8 @@ export default async function createApp(config: IConfig): Promise { // shift the line numbers of source maps in extensions by 2 as the content is wrapped by an anonymous function app.use(async (ctx, next) => { await next(); - if (ctx.status === 200 && ctx.path.match(/\/extensions\/.*\.js\.map$/) && ctx.body instanceof ReadStream) { - // we know it's a ReadSetram as that's what kstatic uses + if (ctx.status === 200 && ctx.path.match(/\/(dev)?extensions\/.*\.js\.map$/) && ctx.body instanceof ReadStream) { + // we know it's a ReadStream as that's what kstatic uses ctx.response.body = `{"version":3,"file":"${basename(ctx.path)}","sections":[{"offset":{"line":2,"column":0},"map":${await getstream(ctx.body)} }]}`; } });