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

Fix extension source maps #29

Merged
merged 3 commits into from
Jul 5, 2022
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
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