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

Enable service worker for legacy build #21177

Merged
merged 1 commit into from
Jul 19, 2024
Merged

Conversation

steverep
Copy link
Member

@steverep steverep commented Jun 26, 2024

Proposed change

Create separate service workers for the modern and legacy builds. The legacy SW targets browsers that also support them to avoid some large unnecessary transpiling and polyfills. Adjusts the user-facing __BUILD__ global to the more user-friendly "modern" and "legacy" terms.

Workbox is patched with GoogleChrome/workbox#3234 in order to use the injection method which properly adjusts the source maps.

404 errors will occur without home-assistant/core#120488.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New feature (thank you!)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Example configuration

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue or discussion:
  • Link to documentation pull request:

Checklist

  • The code change is tested and works locally.
  • There is no commented out code in this PR.
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

Summary by CodeRabbit

  • New Features

    • Added support for service workers in the legacy build profile.
    • Enhanced service worker registration with dynamic script paths based on build type.
  • Refactor

    • Updated build configurations to distinguish between "modern" and "legacy" builds.
    • Refined service worker generation logic to handle modern and legacy builds separately.
    • Improved file handling for service worker scripts.
  • Bug Fixes

    • Patched workbox-build to address specific issues.
  • Style

    • Updated displayed JavaScript type from "latest" to "modern" in the UI.
  • Chores

    • Removed unused source-map-url dependency.
    • Adjusted browser compatibility configurations.

@github-actions github-actions bot added the Build Related to building the code label Jun 26, 2024
@steverep steverep added the Backend Change Required Requires a Backend Core Code Change label Jun 26, 2024
@steverep steverep marked this pull request as ready for review June 27, 2024 04:17
Copy link
Contributor

coderabbitai bot commented Jun 27, 2024

Walkthrough

Walkthrough

The changes introduce a new legacy-sw configuration profile, enable modern and legacy builds for improved support and optimize service worker registration and generation processes. The modifications include updates to build scripts for defining build types, adjustments to Babel and webpack configurations, and enhanced handling of service worker files using workbox-build.

Changes

Files Change Summary
.browserslistrc Added [legacy-sw] profile for service workers.
build-scripts/bundle.cjs Updated build type definitions and entry points for service workers.
build-scripts/gulp/service-worker.js Refactored service worker generation using node:fs/promises and workbox-build.
build-scripts/webpack.cjs Modified webpack configuration to support experimental features.
package.json Removed "source-map-url" and added a patch for "workbox-build".
src/entrypoints/custom-panel.ts Updated conditional checks for __BUILD__ variable.
src/entrypoints/service-worker.ts Refined routing logic and precacheAndRoute call for service workers.
src/panels/config/info/ha-config-info.ts Displayed JavaScript type as "modern" instead of "latest".
src/types.ts Updated __BUILD__ options from `"latest"
src/util/custom-panel/load-custom-panel.ts Updated build conditional checks from "latest" to "modern".
src/util/register-service-worker.ts Registered dynamic service worker script based on build type.

Recent review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between d9f1b06 and f285c40.

Files ignored due to path filters (2)
  • .yarn/patches/workbox-build-npm-7.1.1-a854f3faae.patch is excluded by !**/.yarn/**
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
Files selected for processing (11)
  • .browserslistrc (1 hunks)
  • build-scripts/bundle.cjs (3 hunks)
  • build-scripts/gulp/service-worker.js (1 hunks)
  • build-scripts/webpack.cjs (2 hunks)
  • package.json (2 hunks)
  • src/entrypoints/custom-panel.ts (1 hunks)
  • src/entrypoints/service-worker.ts (2 hunks)
  • src/panels/config/info/ha-config-info.ts (1 hunks)
  • src/types.ts (1 hunks)
  • src/util/custom-panel/load-custom-panel.ts (1 hunks)
  • src/util/register-service-worker.ts (1 hunks)
Files not reviewed due to errors (1)
  • src/util/custom-panel/load-custom-panel.ts (no review received)
Additional context used
Path-based instructions (3)
src/types.ts (4)

Pattern */**(html|markdown|md): - For instructional content in documentation, use a direct and authoritative tone. Avoid expressions of politeness such as 'may' or 'please', and ensure the goal of the instruction is fronted.

  • Apply the Microsoft Style Guide to ensure documentation maintains clarity and conciseness.
  • In step-by-step instructions, front the location phrase in the instructional sentence.
  • In step-by-step instructions, front the 'goal' in the instructional sentence.
  • In step-by-step instructions, if in doubt what to front, front the 'goal' before the location phrase in the instructional sentence.
  • do not hyphenate terms like 'top-right' or 'bottom-left' with 'corner'

Pattern */**(html|markdown|md): - Use bold to mark UI strings.

  • If "" are used to mark UI strings, replace them by bold.

Pattern */**(html|markdown|md): - Be brief in your replies and don't add fluff like "thank you for..." and "Please let me know if"


Pattern */**(html|markdown|md): - Use sentence-style capitalization also in headings.

build-scripts/webpack.cjs (4)

Pattern */**(html|markdown|md): - For instructional content in documentation, use a direct and authoritative tone. Avoid expressions of politeness such as 'may' or 'please', and ensure the goal of the instruction is fronted.

  • Apply the Microsoft Style Guide to ensure documentation maintains clarity and conciseness.
  • In step-by-step instructions, front the location phrase in the instructional sentence.
  • In step-by-step instructions, front the 'goal' in the instructional sentence.
  • In step-by-step instructions, if in doubt what to front, front the 'goal' before the location phrase in the instructional sentence.
  • do not hyphenate terms like 'top-right' or 'bottom-left' with 'corner'

Pattern */**(html|markdown|md): - Use bold to mark UI strings.

  • If "" are used to mark UI strings, replace them by bold.

Pattern */**(html|markdown|md): - Be brief in your replies and don't add fluff like "thank you for..." and "Please let me know if"


Pattern */**(html|markdown|md): - Use sentence-style capitalization also in headings.

build-scripts/bundle.cjs (4)

Pattern */**(html|markdown|md): - For instructional content in documentation, use a direct and authoritative tone. Avoid expressions of politeness such as 'may' or 'please', and ensure the goal of the instruction is fronted.

  • Apply the Microsoft Style Guide to ensure documentation maintains clarity and conciseness.
  • In step-by-step instructions, front the location phrase in the instructional sentence.
  • In step-by-step instructions, front the 'goal' in the instructional sentence.
  • In step-by-step instructions, if in doubt what to front, front the 'goal' before the location phrase in the instructional sentence.
  • do not hyphenate terms like 'top-right' or 'bottom-left' with 'corner'

Pattern */**(html|markdown|md): - Use bold to mark UI strings.

  • If "" are used to mark UI strings, replace them by bold.

Pattern */**(html|markdown|md): - Be brief in your replies and don't add fluff like "thank you for..." and "Please let me know if"


Pattern */**(html|markdown|md): - Use sentence-style capitalization also in headings.

Biome
src/util/custom-panel/load-custom-panel.ts

[error] 41-41: Forbidden non-null assertion.

(lint/style/noNonNullAssertion)

build-scripts/gulp/service-worker.js

[error] 16-24: Template literals are preferred over string concatenation.

Unsafe fix: Use a template literal.

(lint/style/useTemplate)

src/entrypoints/custom-panel.ts

[error] 94-94: Forbidden non-null assertion.

Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator

(lint/style/noNonNullAssertion)


[error] 95-95: Unexpected any. Specify a different type.

any disables many type checking rules. Its use should be avoided.

(lint/suspicious/noExplicitAny)


[error] 104-104: Forbidden non-null assertion.

(lint/style/noNonNullAssertion)


[error] 109-109: This variable implicitly has the any type.

Variable declarations without type annotation and initialization implicitly have the any type. Declare a type or initialize the variable with some value.

(lint/suspicious/noImplicitAnyLet)


[error] 114-114: Unexpected any. Specify a different type.

any disables many type checking rules. Its use should be avoided.

(lint/suspicious/noExplicitAny)


[error] 117-117: Unexpected any. Specify a different type.

any disables many type checking rules. Its use should be avoided.

(lint/suspicious/noExplicitAny)


[error] 140-140: Forbidden non-null assertion.

Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator

(lint/style/noNonNullAssertion)

src/entrypoints/service-worker.ts

[error] 88-88: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 94-94: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 101-101: Template literals are preferred over string concatenation.

Unsafe fix: Use a template literal.

(lint/style/useTemplate)


[error] 120-120: This variable implicitly has the any type.

Variable declarations without type annotation and initialization implicitly have the any type. Declare a type or initialize the variable with some value.

(lint/suspicious/noImplicitAnyLet)


[error] 171-171: This variable implicitly has the any type.

Variable declarations without type annotation and initialization implicitly have the any type. Declare a type or initialize the variable with some value.

(lint/suspicious/noImplicitAnyLet)


[error] 172-172: This variable implicitly has the any type.

Variable declarations without type annotation and initialization implicitly have the any type. Declare a type or initialize the variable with some value.

(lint/suspicious/noImplicitAnyLet)

src/types.ts

[error] 71-71: Unexpected any. Specify a different type.

any disables many type checking rules. Its use should be avoided.

(lint/suspicious/noExplicitAny)


[error] 71-71: Unexpected any. Specify a different type.

any disables many type checking rules. Its use should be avoided.

(lint/suspicious/noExplicitAny)


[error] 117-117: Unexpected any. Specify a different type.

any disables many type checking rules. Its use should be avoided.

(lint/suspicious/noExplicitAny)


[error] 195-195: Unexpected any. Specify a different type.

any disables many type checking rules. Its use should be avoided.

(lint/suspicious/noExplicitAny)


[error] 201-201: Unexpected any. Specify a different type.

any disables many type checking rules. Its use should be avoided.

(lint/suspicious/noExplicitAny)


[error] 253-253: Unexpected any. Specify a different type.

any disables many type checking rules. Its use should be avoided.

(lint/suspicious/noExplicitAny)


[error] 256-256: Unexpected any. Specify a different type.

any disables many type checking rules. Its use should be avoided.

(lint/suspicious/noExplicitAny)


[error] 269-269: Unexpected any. Specify a different type.

any disables many type checking rules. Its use should be avoided.

(lint/suspicious/noExplicitAny)


[error] 292-292: Unexpected any. Specify a different type.

any disables many type checking rules. Its use should be avoided.

(lint/suspicious/noExplicitAny)


[error] 292-292: Unexpected any. Specify a different type.

any disables many type checking rules. Its use should be avoided.

(lint/suspicious/noExplicitAny)


[error] 293-293: Unexpected any. Specify a different type.

any disables many type checking rules. Its use should be avoided.

(lint/suspicious/noExplicitAny)


[error] 296-296: Unexpected any. Specify a different type.

any disables many type checking rules. Its use should be avoided.

(lint/suspicious/noExplicitAny)

src/panels/config/info/ha-config-info.ts

[error] 106-106: Unexpected any. Specify a different type.

any disables many type checking rules. Its use should be avoided.

(lint/suspicious/noExplicitAny)


[error] 215-215: Unexpected any. Specify a different type.

any disables many type checking rules. Its use should be avoided.

(lint/suspicious/noExplicitAny)


[error] 217-217: Unexpected any. Specify a different type.

any disables many type checking rules. Its use should be avoided.

(lint/suspicious/noExplicitAny)

build-scripts/webpack.cjs

[error] 1-1: A Node.js builtin module should be imported with the node: protocol.

Using the node: protocol is more explicit and signals that the imported module belongs to Node.js.
Unsafe fix: Add the node: protocol.

(lint/style/useNodejsImportProtocol)


[error] 2-2: A Node.js builtin module should be imported with the node: protocol.

Using the node: protocol is more explicit and signals that the imported module belongs to Node.js.
Unsafe fix: Add the node: protocol.

(lint/style/useNodejsImportProtocol)


[error] 43-43: Excessive complexity detected.

Please refactor this function to reduce its complexity score from 19 to the max allowed complexity 15.

(lint/complexity/noExcessiveCognitiveComplexity)

build-scripts/bundle.cjs

[error] 1-1: A Node.js builtin module should be imported with the node: protocol.

Using the node: protocol is more explicit and signals that the imported module belongs to Node.js.
Unsafe fix: Add the node: protocol.

(lint/style/useNodejsImportProtocol)


[error] 221-221: Template literals are preferred over string concatenation.

Unsafe fix: Use a template literal.

(lint/style/useTemplate)


[error] 248-248: Template literals are preferred over string concatenation.

Unsafe fix: Use a template literal.

(lint/style/useTemplate)


[error] 278-278: Template literals are preferred over string concatenation.

Unsafe fix: Use a template literal.

(lint/style/useTemplate)


[error] 292-292: Template literals are preferred over string concatenation.

Unsafe fix: Use a template literal.

(lint/style/useTemplate)


[error] 312-312: Template literals are preferred over string concatenation.

Unsafe fix: Use a template literal.

(lint/style/useTemplate)

Additional comments not posted (13)
src/util/register-service-worker.ts (1)

20-20: Approved dynamic service worker registration path.

The dynamic generation of the service worker path based on the __BUILD__ variable is correctly implemented, ensuring that the appropriate service worker is registered for each build type.

.browserslistrc (1)

41-45: Approved addition of [legacy-sw] configuration.

The addition of the [legacy-sw] configuration to support service workers in legacy builds aligns with the PR objectives and enhances compatibility.

src/entrypoints/custom-panel.ts (1)

76-76: Approved conditional loading for legacy build.

The conditional loading of the ES5 adapter for the legacy build is correctly implemented, aligning with the PR objectives to handle different builds effectively.

src/entrypoints/service-worker.ts (3)

16-16: Updated manifest declaration to use TypeScript type annotations.

This change improves type safety by explicitly declaring the type of __WB_MANIFEST__, which is used in the precacheAndRoute function.


22-25: Ensure correct handling of URL parameters in caching strategy.

The configuration to ignore all URL parameters during caching is a good practice for service workers, as it prevents cache bloating and ensures that resources are fetched efficiently.


57-58: Network-only strategy for manifest and onboarding pages.

Using a NetworkOnly strategy for critical resources like the manifest and onboarding pages ensures they are always served with the most up-to-date version, which is crucial for proper app functioning.

src/types.ts (1)

24-24: Updated global variable declarations to reflect new build configurations.

The updated global variable __BUILD__ to use "modern" and "legacy" improves clarity and aligns with the project's new terminology.

src/panels/config/info/ha-config-info.ts (1)

160-160: Updated JavaScript version display logic to include build type.

This change ensures that the UI correctly reflects whether the "modern" or "legacy" build is being used, which is important for transparency and troubleshooting.

build-scripts/webpack.cjs (1)

66-78: Refactored babel loader configuration to handle service workers.

This change allows for specific babel configurations based on whether the module is a service worker, enhancing flexibility and maintainability of the build process.

package.json (1)

246-246: Approval of the patched workbox-build dependency.

The addition of the patched version of workbox-build is crucial for addressing the issue with source maps, as highlighted in the PR summary. This ensures that service workers function correctly across different build environments.

build-scripts/bundle.cjs (3)

223-229: Approved: Conditional configuration for service worker entry.

This setup ensures that the correct service worker script is used based on the build environment and tooling. It's a crucial part of supporting separate service workers for modern and legacy builds.


95-95: Approved: Dynamic setting of browserslistEnv.

This dynamic approach allows for more targeted builds depending on the environment and presence of a service worker. Verify that the browserslistEnv settings are correctly utilized in all relevant build scripts and testing environments.

Verification successful

Approved: Dynamic setting of browserslistEnv.

The dynamic approach to setting browserslistEnv is correctly implemented and utilized in the list-plugins-and-polyfills.js file. This ensures targeted builds based on the environment and presence of a service worker.

  • build-scripts/list-plugins-and-polyfills.js: Correct usage of browserslistEnv confirmed.
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the correct utilization of `browserslistEnv`.

# Test: Check for the usage of `browserslistEnv` in build scripts. Expect: Correct settings for each scenario.
rg --type all "browserslistEnv"

Length of output: 383



Script:

#!/bin/bash
# Description: Extract surrounding lines to verify the usage of `browserslistEnv` in the relevant file.

# Extract 5 lines before and after each occurrence of `browserslistEnv` for context.
rg --context 5 "browserslistEnv" build-scripts/list-plugins-and-polyfills.js

Length of output: 1091


50-50: Approved: Update to global variable __BUILD__.

The update aligns with the PR's objective to differentiate between modern and legacy builds. Ensure that all references to __BUILD__ throughout the codebase are updated accordingly.

Verification successful

Approved: Update to global variable __BUILD__.

The update aligns with the PR's objective to differentiate between modern and legacy builds. The search results indicate that all instances of __BUILD__ in the codebase are consistent with the new logic.

  • src/types.ts: Definition of __BUILD__.
  • src/entrypoints/custom-panel.ts: Conditional check for __BUILD__.
  • src/state/logging-mixin.ts: Usage in a template literal.
  • src/util/register-service-worker.ts: Usage in a service worker registration.
  • src/panels/config/info/ha-config-info.ts: Assignment to a constant.
  • src/util/custom-panel/load-custom-panel.ts: Conditional check for __BUILD__.
  • build-scripts/bundle.cjs: The line under review.

All instances of __BUILD__ have been updated accordingly.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify all instances of `__BUILD__` are updated.

# Test: Search for old instances of `__BUILD__`. Expect: No occurrences of old values.
rg --type python "__BUILD__ === 'es5'"

Length of output: 77



Script:

#!/bin/bash
# Description: Verify all instances of `__BUILD__` are updated.

# Search for all instances of `__BUILD__` in JavaScript files
rg "__BUILD__" --type js

Length of output: 24



Script:

#!/bin/bash
# Description: Verify all instances of `__BUILD__` are updated.

# Search for all instances of `__BUILD__` across all file types
rg "__BUILD__"

Length of output: 562


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Outside diff range comments (9)
src/entrypoints/custom-panel.ts (2)

Line range hint 94-94: Replace non-null assertions with optional chaining.

Using non-null assertions can lead to runtime errors. Replace them with optional chaining to safely access properties.

- panelEl!.addEventListener("hass-toggle-menu", forwardEvent);
- window.parent.customPanel!.navigate(
- window.parent.customPanel!.registerIframe(initialize, setProperties),
+ panelEl?.addEventListener("hass-toggle-menu", forwardEvent);
+ window.parent.customPanel?.navigate(
+ window.parent.customPanel?.registerIframe(initialize, setProperties),

Also applies to: 104-104, 140-140


Line range hint 95-95: Specify explicit types instead of using any.

Using any type disables many type checking rules and should be avoided. Specify more explicit types for better type safety.

- const installingWorker = reg.installing;
- const errorScreen = document.createElement("supervisor-error-screen") as any;
- const errorScreen = document.createElement("hass-error-screen") as any;
+ const installingWorker: ServiceWorker | null = reg.installing;
+ const errorScreen: SupervisorErrorScreen = document.createElement("supervisor-error-screen") as SupervisorErrorScreen;
+ const errorScreen: HassErrorScreen = document.createElement("hass-error-screen") as HassErrorScreen;

Also applies to: 109-109, 114-114, 117-117

src/entrypoints/service-worker.ts (3)

Line range hint 88-88: Consider refactoring to avoid using the delete operator.

The delete operator can lead to performance issues due to deoptimizations in JavaScript engines.

- delete payload.data.jwt;
+ payload.data.jwt = undefined;

Line range hint 101-101: Use template literals for string concatenation.

Using template literals instead of string concatenation is a more modern and readable approach in JavaScript.

- "Using fallback for:" + url
+ `Using fallback for: ${url}`

Line range hint 120-120: Specify explicit types to avoid implicit 'any'.

Variables i and client are implicitly typed as 'any', which can lead to runtime errors if misused.

- let i;
- let client;
+ let i: number;
+ let client: WindowClient;

Also applies to: 171-171, 172-172

src/types.ts (1)

Line range hint 71-71: Specify types instead of using 'any'.

The use of 'any' type should be minimized to enhance type safety. Specifying explicit types helps in catching errors during compilation.

- export type Constructor<T = any> = new (...args: any[]) => T;
+ export type Constructor<T = unknown> = new (...args: unknown[]) => T;

Also applies to: 117-117, 195-195, 201-201, 253-253, 256-256, 269-269, 292-292, 293-293, 296-296

src/panels/config/info/ha-config-info.ts (1)

Line range hint 106-106: Avoid using 'any' type for better type safety.

Using 'any' type can lead to less predictable code behavior and more difficult maintenance. Specifying more precise types would improve the robustness of the code.

- const customUiList: Array<{ name: string; url: string; version: string }> = (window as any).CUSTOM_UI_LIST || [];
+ const customUiList: Array<{ name: string; url: string; version: string }> = (window as Window & { CUSTOM_UI_LIST?: Array<{ name: string; url: string; version: string }> }).CUSTOM_UI_LIST || [];

Also applies to: 215-215, 217-217

build-scripts/webpack.cjs (1)

Line range hint 43-43: Consider refactoring to reduce cognitive complexity.

The createWebpackConfig function is complex and may be hard to maintain. Consider breaking it down into smaller, more manageable functions.

build-scripts/bundle.cjs (1)

Line range hint 1-1: Use the node: protocol when importing Node.js built-in modules.

This is a best practice to clearly distinguish built-in modules from local ones.

- const path = require("path");
+ const path = require("node:path");

build-scripts/bundle.cjs Show resolved Hide resolved
build-scripts/gulp/service-worker.js Show resolved Hide resolved
@silamon
Copy link
Contributor

silamon commented Jun 27, 2024

If this is considered as a "breaking change", what is expected to be done by the user?

@steverep
Copy link
Member Author

It's not breaking... I checked the wrong box.

!env.useRollup() && !latestBuild
? {
import: "./src/entrypoints/service-worker.ts",
layer: "sw",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do these layers work, can't find anything about it in the webpack docs...

Copy link
Member Author

@steverep steverep Jun 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah the docs on it are quite sparse. It's more or less a tag/label for a module. You can assign it by entry like this, or via a condition in the module config. Then you can act on it in cache groups, by issuer layer in the module config (like I do here to change the loader options), and they also get grouped in the stats output.

In this PR, it boils down to:

  1. The service worker entry and everything it imports is assigned to the "sw" layer.
  2. For any module in the "sw" layer, Babel transpiles using the "legacy-sw" environment instead of "legacy".

@frenck
Copy link
Member

frenck commented Jul 7, 2024

Core PR has been approved.

@bramkragten bramkragten merged commit 82d84de into dev Jul 19, 2024
15 checks passed
@bramkragten bramkragten deleted the legacy-service-worker branch July 19, 2024 08:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Backend Change Required Requires a Backend Core Code Change Build Related to building the code cla-signed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants