Fix source URLs in source maps (#17585)

This commit is contained in:
Steve Repsher 2023-08-15 11:10:12 -04:00 committed by GitHub
parent f4d575f456
commit cba246fc7f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 14 deletions

View File

@ -8,7 +8,7 @@ module.exports.sourceMapURL = () => {
const ref = env.version().endsWith("dev") const ref = env.version().endsWith("dev")
? process.env.GITHUB_SHA || "dev" ? process.env.GITHUB_SHA || "dev"
: env.version(); : env.version();
return `https://raw.githubusercontent.com/home-assistant/frontend/${ref}`; return `https://raw.githubusercontent.com/home-assistant/frontend/${ref}/`;
}; };
// Files from NPM Packages that should not be imported // Files from NPM Packages that should not be imported

View File

@ -1,5 +1,6 @@
const webpack = require("webpack"); const { existsSync } = require("fs");
const path = require("path"); const path = require("path");
const webpack = require("webpack");
const TerserPlugin = require("terser-webpack-plugin"); const TerserPlugin = require("terser-webpack-plugin");
const { WebpackManifestPlugin } = require("webpack-manifest-plugin"); const { WebpackManifestPlugin } = require("webpack-manifest-plugin");
const log = require("fancy-log"); const log = require("fancy-log");
@ -191,19 +192,23 @@ const createWebpackConfig = ({
// Since production source maps don't include sources, we need to point to them elsewhere // Since production source maps don't include sources, we need to point to them elsewhere
// For dependencies, just provide the path (no source in browser) // For dependencies, just provide the path (no source in browser)
// Otherwise, point to the raw code on GitHub for browser to load // Otherwise, point to the raw code on GitHub for browser to load
devtoolModuleFilenameTemplate: ...Object.fromEntries(
!isTestBuild && isProdBuild ["", "Fallback"].map((v) => [
? (info) => { `devtool${v}ModuleFilenameTemplate`,
const sourcePath = info.resourcePath.replace(/^\.\//, ""); !isTestBuild && isProdBuild
if ( ? (info) => {
sourcePath.startsWith("node_modules") || if (
sourcePath.startsWith("webpack") !path.isAbsolute(info.absoluteResourcePath) ||
) { !existsSync(info.resourcePath) ||
return `no-source/${sourcePath}`; info.resourcePath.startsWith("./node_modules")
) {
return new URL(info.resourcePath, "webpack://frontend/").href;
}
return new URL(info.resourcePath, bundle.sourceMapURL()).href;
} }
return `${bundle.sourceMapURL()}/${sourcePath}`; : undefined,
} ])
: undefined, ),
}, },
experiments: { experiments: {
outputModule: true, outputModule: true,