Skip to content

Commit

Permalink
Merge pull request #29 from microsoft/aeschli/fixextensionsourcemaps
Browse files Browse the repository at this point in the history
Fix extension source maps
  • Loading branch information
aeschli authored Jul 5, 2022
2 parents 7e44712 + f2a1c6f commit 0755f5e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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",
Expand Down
13 changes: 12 additions & 1 deletion src/server/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -42,6 +44,15 @@ export default async function createApp(config: IConfig): Promise<Koa> {
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) {
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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=

[email protected]:
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"
Expand Down

0 comments on commit 0755f5e

Please sign in to comment.