diff --git a/package.json b/package.json index 5e81c3f..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", @@ -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..783bd94 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(/\/(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)} }]}`; + } + }); + 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"