From d6688b5ba37ce7b7c68cafe6a72f3fabf385818e Mon Sep 17 00:00:00 2001 From: Tyler James Leonhardt Date: Mon, 11 Nov 2024 15:45:15 -0800 Subject: [PATCH] Only rewrite sourcemap urls when js (#233626) This prevents the build from touching any other kind of file. --- build/lib/extensions.js | 10 ++++++---- build/lib/extensions.ts | 10 ++++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/build/lib/extensions.js b/build/lib/extensions.js index c6d56319c30..4e704bdab6f 100644 --- a/build/lib/extensions.js +++ b/build/lib/extensions.js @@ -158,10 +158,12 @@ function fromLocalWebpack(extensionPath, webpackConfigFileName, disableMangle) { // source map handling: // * rewrite sourceMappingURL // * save to disk so that upload-task picks this up - const contents = data.contents.toString('utf8'); - data.contents = Buffer.from(contents.replace(/\n\/\/# sourceMappingURL=(.*)$/gm, function (_m, g1) { - return `\n//# sourceMappingURL=${sourceMappingURLBase}/extensions/${path.basename(extensionPath)}/${relativeOutputPath}/${g1}`; - }), 'utf8'); + if (path.extname(data.basename) === '.js') { + const contents = data.contents.toString('utf8'); + data.contents = Buffer.from(contents.replace(/\n\/\/# sourceMappingURL=(.*)$/gm, function (_m, g1) { + return `\n//# sourceMappingURL=${sourceMappingURLBase}/extensions/${path.basename(extensionPath)}/${relativeOutputPath}/${g1}`; + }), 'utf8'); + } this.emit('data', data); })); }); diff --git a/build/lib/extensions.ts b/build/lib/extensions.ts index 2a9a215c5e4..14f2de9fef5 100644 --- a/build/lib/extensions.ts +++ b/build/lib/extensions.ts @@ -170,10 +170,12 @@ function fromLocalWebpack(extensionPath: string, webpackConfigFileName: string, // source map handling: // * rewrite sourceMappingURL // * save to disk so that upload-task picks this up - const contents = (data.contents).toString('utf8'); - data.contents = Buffer.from(contents.replace(/\n\/\/# sourceMappingURL=(.*)$/gm, function (_m, g1) { - return `\n//# sourceMappingURL=${sourceMappingURLBase}/extensions/${path.basename(extensionPath)}/${relativeOutputPath}/${g1}`; - }), 'utf8'); + if (path.extname(data.basename) === '.js') { + const contents = (data.contents).toString('utf8'); + data.contents = Buffer.from(contents.replace(/\n\/\/# sourceMappingURL=(.*)$/gm, function (_m, g1) { + return `\n//# sourceMappingURL=${sourceMappingURLBase}/extensions/${path.basename(extensionPath)}/${relativeOutputPath}/${g1}`; + }), 'utf8'); + } this.emit('data', data); }));