Use hashes for hassio entrypoints (#6260)

This commit is contained in:
Paulus Schoutsen 2020-06-29 00:31:07 -07:00 committed by GitHub
parent fb7f620316
commit d33f18ecb7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 43 additions and 27 deletions

View File

@ -178,7 +178,6 @@ module.exports.config = {
publicPath: publicPath(latestBuild, paths.hassio_publicPath), publicPath: publicPath(latestBuild, paths.hassio_publicPath),
isProdBuild, isProdBuild,
latestBuild, latestBuild,
dontHash: new Set(["entrypoint"]),
}; };
}, },

View File

@ -90,8 +90,6 @@ gulp.task("gen-pages-prod", (done) => {
}); });
gulp.task("gen-index-app-dev", (done) => { gulp.task("gen-index-app-dev", (done) => {
// In dev mode we don't mangle names, so we hardcode urls. That way we can
// run webpack as last in watch mode, which blocks output.
const content = renderTemplate("index", { const content = renderTemplate("index", {
latestAppJS: "/frontend_latest/app.js", latestAppJS: "/frontend_latest/app.js",
latestCoreJS: "/frontend_latest/core.js", latestCoreJS: "/frontend_latest/core.js",
@ -201,8 +199,6 @@ gulp.task("gen-index-cast-prod", (done) => {
}); });
gulp.task("gen-index-demo-dev", (done) => { gulp.task("gen-index-demo-dev", (done) => {
// In dev mode we don't mangle names, so we hardcode urls. That way we can
// run webpack as last in watch mode, which blocks output.
const content = renderDemoTemplate("index", { const content = renderDemoTemplate("index", {
latestDemoJS: "/frontend_latest/main.js", latestDemoJS: "/frontend_latest/main.js",
@ -240,8 +236,6 @@ gulp.task("gen-index-demo-prod", (done) => {
}); });
gulp.task("gen-index-gallery-dev", (done) => { gulp.task("gen-index-gallery-dev", (done) => {
// In dev mode we don't mangle names, so we hardcode urls. That way we can
// run webpack as last in watch mode, which blocks output.
const content = renderGalleryTemplate("index", { const content = renderGalleryTemplate("index", {
latestGalleryJS: "./frontend_latest/entrypoint.js", latestGalleryJS: "./frontend_latest/entrypoint.js",
}); });
@ -269,3 +263,39 @@ gulp.task("gen-index-gallery-prod", (done) => {
); );
done(); done();
}); });
gulp.task("gen-index-hassio-dev", async () => {
writeHassioEntrypoint("entrypoint.js", "entrypoints.js");
});
gulp.task("gen-index-hassio-prod", async () => {
const latestManifest = require(path.resolve(
paths.hassio_output_latest,
"manifest.json"
));
const es5Manifest = require(path.resolve(
paths.hassio_output_es5,
"manifest.json"
));
writeHassioEntrypoint(
latestManifest["entrypoint.js"],
es5Manifest["entrypoint.js"]
);
});
function writeHassioEntrypoint(latestEntrypoint, es5Entrypoint) {
fs.mkdirSync(paths.hassio_output_root, { recursive: true });
fs.writeFileSync(
path.resolve(paths.hassio_output_root, "entrypoint.js"),
`
try {
new Function("import('${paths.hassio_publicPath}/frontend_latest/${latestEntrypoint}')")();
} catch (err) {
var el = document.createElement('script');
el.src = '${paths.hassio_publicPath}/frontend_es5/${es5Entrypoint}';
document.body.appendChild(el);
}
`,
{ encoding: "utf-8" }
);
}

View File

@ -11,24 +11,6 @@ require("./webpack.js");
require("./compress.js"); require("./compress.js");
require("./rollup.js"); require("./rollup.js");
async function writeEntrypointJS() {
// We ship two builds and we need to do feature detection on what version to load.
fs.mkdirSync(paths.hassio_output_root, { recursive: true });
fs.writeFileSync(
path.resolve(paths.hassio_output_root, "entrypoint.js"),
`
try {
new Function("import('${paths.hassio_publicPath}/frontend_latest/entrypoint.js')")();
} catch (err) {
var el = document.createElement('script');
el.src = '${paths.hassio_publicPath}/frontend_es5/entrypoint.js';
document.body.appendChild(el);
}
`,
{ encoding: "utf-8" }
);
}
gulp.task( gulp.task(
"develop-hassio", "develop-hassio",
gulp.series( gulp.series(
@ -37,7 +19,7 @@ gulp.task(
}, },
"clean-hassio", "clean-hassio",
"gen-icons-json", "gen-icons-json",
writeEntrypointJS, "gen-index-hassio-dev",
env.useRollup() ? "rollup-watch-hassio" : "webpack-watch-hassio" env.useRollup() ? "rollup-watch-hassio" : "webpack-watch-hassio"
) )
); );
@ -51,7 +33,7 @@ gulp.task(
"clean-hassio", "clean-hassio",
"gen-icons-json", "gen-icons-json",
env.useRollup() ? "rollup-prod-hassio" : "webpack-prod-hassio", env.useRollup() ? "rollup-prod-hassio" : "webpack-prod-hassio",
writeEntrypointJS, "gen-index-hassio-prod",
...// Don't compress running tests ...// Don't compress running tests
(env.isTest() ? [] : ["compress-hassio"]) (env.isTest() ? [] : ["compress-hassio"])
) )

View File

@ -34,6 +34,11 @@ module.exports = {
hassio_dir: path.resolve(__dirname, "../hassio"), hassio_dir: path.resolve(__dirname, "../hassio"),
hassio_output_root: path.resolve(__dirname, "../hassio/build"), hassio_output_root: path.resolve(__dirname, "../hassio/build"),
hassio_output_latest: path.resolve(
__dirname,
"../hassio/build/frontend_latest"
),
hassio_output_es5: path.resolve(__dirname, "../hassio/build/frontend_es5"),
hassio_publicPath: "/api/hassio/app", hassio_publicPath: "/api/hassio/app",
translations_src: path.resolve(__dirname, "../src/translations"), translations_src: path.resolve(__dirname, "../src/translations"),