From f9e436bf209e75a1ca48ff878a36ba643313b199 Mon Sep 17 00:00:00 2001 From: Justin Beckwith Date: Wed, 2 Jun 2021 14:43:03 -0700 Subject: [PATCH 1/3] chore(deps): update to @types/nodejs 14.x (#962) --- package.json | 2 +- src/agent/controller.ts | 2 +- system-test/test-e2e.ts | 9 ++++----- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 300c4bdf..e8dac865 100644 --- a/package.json +++ b/package.json @@ -67,7 +67,7 @@ "@types/mocha": "^8.0.0", "@types/mv": "^2.1.0", "@types/ncp": "^2.0.3", - "@types/node": "~10.17.0", + "@types/node": "^14.17.2", "@types/proxyquire": "^1.3.28", "@types/semver": "^7.0.0", "@types/tmp": "^0.2.0", diff --git a/src/agent/controller.ts b/src/agent/controller.ts index 1687beb0..e8a511d5 100644 --- a/src/agent/controller.ts +++ b/src/agent/controller.ts @@ -122,7 +122,7 @@ export class Controller extends ServiceObject { '/debuggees/' + encodeURIComponent(debuggee.id) + '/breakpoints?' + - qs.stringify(query); + qs.stringify(query as qs.ParsedUrlQueryInput); that.request( {uri, json: true}, (err, body: stackdriver.ListBreakpointsResponse, response) => { diff --git a/system-test/test-e2e.ts b/system-test/test-e2e.ts index 6f1495fc..90795052 100644 --- a/system-test/test-e2e.ts +++ b/system-test/test-e2e.ts @@ -59,7 +59,7 @@ describe('@google-cloud/debug end-to-end behavior', () => { beforeEach(function () { this.timeout(10 * 1000); - return new Promise((resolve, reject) => { + return new Promise((resolve, reject) => { let numChildrenReady = 0; // Process a status message sent from a child process. @@ -117,9 +117,8 @@ describe('@google-cloud/debug end-to-end behavior', () => { child.process.on('message', handler); children.push(child); - - child.process.stdout.on('data', stdoutHandler(i)); - child.process.stderr.on('data', stdoutHandler(i)); + child.process.stdout!.on('data', stdoutHandler(i)); + child.process.stderr!.on('data', stdoutHandler(i)); } }); }); @@ -132,7 +131,7 @@ describe('@google-cloud/debug end-to-end behavior', () => { assert(child.process); const childProcess = child.process as cp.ChildProcess; childProcess.kill(); - return new Promise((resolve, reject) => { + return new Promise((resolve, reject) => { const timeout = setTimeout(() => { reject(new Error('A child process failed to exit.')); }, 3000); From 828125cde6fcfa6c8bb9c318aca4bba4a13aaf6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Louis=20Ye=20=E5=8F=B6=E7=BB=BF=E5=AE=87?= Date: Fri, 4 Jun 2021 11:23:46 -0400 Subject: [PATCH 2/3] fix(deps): upgrade to source-map 0.7.3 (#964) --- package.json | 2 +- src/agent/io/sourcemapper.ts | 84 +++++++++++++++++++++--------------- 2 files changed, 50 insertions(+), 36 deletions(-) diff --git a/package.json b/package.json index e8dac865..a99b0fc2 100644 --- a/package.json +++ b/package.json @@ -55,7 +55,7 @@ "gcp-metadata": "^4.0.0", "p-limit": "^3.0.1", "semver": "^7.0.0", - "source-map": "^0.6.1", + "source-map": "^0.7.3", "split": "^1.0.0" }, "devDependencies": { diff --git a/src/agent/io/sourcemapper.ts b/src/agent/io/sourcemapper.ts index 84e8787e..3de4ffa8 100644 --- a/src/agent/io/sourcemapper.ts +++ b/src/agent/io/sourcemapper.ts @@ -29,7 +29,7 @@ const readFilep = promisify(fs.readFile); export interface MapInfoInput { outputFile: string; mapFile: string; - mapConsumer: sourceMap.RawSourceMap; + mapConsumer: sourceMap.SourceMapConsumer; // the sources are in ascending order from // shortest to longest sources: string[]; @@ -59,24 +59,23 @@ async function processSourcemap( } mapPath = path.normalize(mapPath); - let contents; + let rawSourceMapString; try { - contents = await readFilep(mapPath, 'utf8'); + rawSourceMapString = await readFilep(mapPath, 'utf8'); } catch (e) { throw new Error('Could not read sourcemap file ' + mapPath + ': ' + e); } - let consumer: sourceMap.RawSourceMap; + let rawSourceMap; try { - // TODO: Determine how to reconsile the type conflict where `consumer` - // is constructed as a SourceMapConsumer but is used as a - // RawSourceMap. - // TODO: Resolve the cast of `contents as any` (This is needed because the - // type is expected to be of `RawSourceMap` but the existing - // working code uses a string.) - consumer = new sourceMap.SourceMapConsumer( - contents as {} as sourceMap.RawSourceMap - ) as {} as sourceMap.RawSourceMap; + rawSourceMap = JSON.parse(rawSourceMapString); + } catch (e) { + throw new Error('Could not parse the raw sourcemap ' + mapPath + ': ' + e); + } + + let consumer: sourceMap.SourceMapConsumer; + try { + consumer = await new sourceMap.SourceMapConsumer(rawSourceMapString); } catch (e) { throw new Error( 'An error occurred while reading the ' + @@ -93,18 +92,35 @@ async function processSourcemap( * containing the map file. Otherwise, use the name of the output * file (with the .map extension removed) as the output file. */ - const outputBase = consumer.file - ? consumer.file + const outputBase = rawSourceMap.file + ? rawSourceMap.file : path.basename(mapPath, '.map'); const parentDir = path.dirname(mapPath); const outputPath = path.normalize(path.join(parentDir, outputBase)); - // the sources are in ascending order from shortest to longest - const nonemptySources = consumer.sources - .filter(val => !!val) - .sort((src1, src2) => src1.length - src2.length); + // The paths of the sources that are relative to the source map file. Sort + // them in ascending order from shortest to longest. + // For webpack file path, normalize the path after the webpack prefix so that + // the source map library can recognize it. + const sourcesRelToSrcmap = rawSourceMap.sources + .filter((val: string) => !!val) + .map((val: string) => { + if (val.toLowerCase().startsWith(WEBPACK_PREFIX)) { + return ( + WEBPACK_PREFIX + + path.normalize(val.substr(WEBPACK_PREFIX.length)).replace(/\\/g, '/') + ); + } + return val; + }) + .sort((src1: string, src2: string) => src1.length - src2.length); - const normalizedSources = nonemptySources + // The paths of the sources that are relative to the current process's working + // directory. These are the ones that are used for the fuzzy search (thus are + // platform specific, e.g. using '\\' on Windows and using '/' in Unix, etc.). + // For webpack file path, the prefix is filtered out for better fuzzy search + // result. + const normalizedSourcesRelToProc = sourcesRelToSrcmap .map((src: string) => { if (src.toLowerCase().startsWith(WEBPACK_PREFIX)) { return src.substring(WEBPACK_PREFIX.length); @@ -112,21 +128,21 @@ async function processSourcemap( return src; }) .map((relPath: string) => { - // resolve the paths relative to the map file so that - // they are relative to the process's current working - // directory + // resolve the paths relative to the map file so that they are relative to + // the process's current working directory return path.normalize(path.join(parentDir, relPath)); }); - if (normalizedSources.length === 0) { + if (normalizedSourcesRelToProc.length === 0) { throw new Error('No sources listed in the sourcemap file ' + mapPath); } - for (const src of normalizedSources) { + + for (const src of normalizedSourcesRelToProc) { infoMap.set(path.normalize(src), { outputFile: outputPath, mapFile: mapPath, mapConsumer: consumer, - sources: nonemptySources, + sources: sourcesRelToSrcmap, }); } } @@ -223,7 +239,6 @@ export class SourceMapper { const relPath = path .relative(path.dirname(entry.mapFile), inputPath) .replace(/\\/g, '/'); - /** * Note: Since `entry.sources` is in ascending order from shortest * to longest, the first source path that ends with the @@ -245,10 +260,7 @@ export class SourceMapper { column: colNumber, // to be zero-based }; - // TODO: Determine how to remove the explicit cast here. - const consumer: sourceMap.SourceMapConsumer = - entry.mapConsumer as {} as sourceMap.SourceMapConsumer; - const allPos = consumer.allGeneratedPositionsFor(sourcePos); + const allPos = entry.mapConsumer.allGeneratedPositionsFor(sourcePos); /* * Based on testing, it appears that the following code is needed to * properly get the correct mapping information. @@ -256,16 +268,18 @@ export class SourceMapper { * In particular, the generatedPositionFor() alone doesn't appear to * give the correct mapping information. */ - const mappedPos: sourceMap.Position = + const mappedPos: sourceMap.NullablePosition = allPos && allPos.length > 0 ? allPos.reduce((accumulator, value) => { - return value.line < accumulator.line ? value : accumulator; + return (value.line ?? 0) < (accumulator.line ?? 0) + ? value + : accumulator; }) - : consumer.generatedPositionFor(sourcePos); + : entry.mapConsumer.generatedPositionFor(sourcePos); return { file: entry.outputFile, - line: mappedPos.line - 1, // convert the one-based line numbers returned + line: (mappedPos.line ?? 0) - 1, // convert the one-based line numbers returned // by the SourceMapConsumer to the expected // zero-based output. // TODO: The `sourceMap.Position` type definition has a `column` From 90499ae50d5a62ae1ff8b23cba479ae85390f7a7 Mon Sep 17 00:00:00 2001 From: "release-please[bot]" <55107282+release-please[bot]@users.noreply.github.com> Date: Sun, 6 Jun 2021 11:59:01 -0700 Subject: [PATCH 3/3] chore: release 5.2.2 (#965) Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com> --- CHANGELOG.md | 7 +++++++ package.json | 2 +- samples/package.json | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b1d49fbc..91e74bae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Node.js Agent for Google Cloud Debug ChangeLog +### [5.2.2](https://www.github.com/googleapis/cloud-debug-nodejs/compare/v5.2.1...v5.2.2) (2021-06-04) + + +### Bug Fixes + +* **deps:** upgrade to source-map 0.7.3 ([#964](https://www.github.com/googleapis/cloud-debug-nodejs/issues/964)) ([828125c](https://www.github.com/googleapis/cloud-debug-nodejs/commit/828125cde6fcfa6c8bb9c318aca4bba4a13aaf6c)) + ### [5.2.1](https://www.github.com/googleapis/cloud-debug-nodejs/compare/v5.2.0...v5.2.1) (2021-05-31) diff --git a/package.json b/package.json index a99b0fc2..a52b65cf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@google-cloud/debug-agent", - "version": "5.2.1", + "version": "5.2.2", "author": "Google Inc.", "description": "Stackdriver Debug Agent for Node.js", "main": "./build/src/index", diff --git a/samples/package.json b/samples/package.json index c100321e..d7ca6680 100644 --- a/samples/package.json +++ b/samples/package.json @@ -17,7 +17,7 @@ "test": "mocha" }, "dependencies": { - "@google-cloud/debug-agent": "^5.2.1", + "@google-cloud/debug-agent": "^5.2.2", "express": "4.17.1" }, "devDependencies": {