@jsenv/core 24.5.3 → 24.5.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,8 @@
1
1
  import { userAgentToVersion, firstMatch } from "./util.js"
2
2
 
3
- export const detectChrome = () => userAgentToBrowser(window.navigator.userAgent)
3
+ export const detectChrome = () => {
4
+ return userAgentToBrowser(window.navigator.userAgent)
5
+ }
4
6
 
5
7
  const userAgentToBrowser = (userAgent) => {
6
8
  if (/chromium/i.test(userAgent)) {
@@ -0,0 +1,26 @@
1
+ /*
2
+ * Prefer window.navigator.userAgentData before resorting to
3
+ * window.navigator.userAgent because of
4
+ * https://blog.chromium.org/2021/09/user-agent-reduction-origin-trial-and-dates.html
5
+ */
6
+
7
+ export const detectFromUserAgentData = () => {
8
+ const { userAgentData } = window.navigator
9
+ if (!userAgentData) {
10
+ return null
11
+ }
12
+
13
+ const { brands } = userAgentData
14
+ let i = 0
15
+ while (i < brands.legth) {
16
+ const { brand, version } = brands[i]
17
+ i++
18
+ if (brand === "chromium" || brand === "Google Chrome") {
19
+ return {
20
+ name: "chrome",
21
+ version,
22
+ }
23
+ }
24
+ }
25
+ return null
26
+ }
@@ -20,14 +20,31 @@ const fileNamePatternFromRessource = (ressource) => {
20
20
  }
21
21
 
22
22
  if (ressource.urlVersioningDisabled) {
23
- if (ressource.isEntryPoint || ressource.isJsModule) {
24
- return `[name][extname]`
23
+ if (canMoveToAssetsDirectory(ressource)) {
24
+ return assetFileNamePatternWithoutHash
25
25
  }
26
- return assetFileNamePatternWithoutHash
26
+ return `[name][extname]`
27
27
  }
28
28
 
29
- if (ressource.isEntryPoint || ressource.isJsModule) {
30
- return `[name]-[hash][extname]`
29
+ if (canMoveToAssetsDirectory(ressource)) {
30
+ return assetFileNamePattern
31
31
  }
32
- return assetFileNamePattern
32
+ return `[name]-[hash][extname]`
33
+ }
34
+
35
+ const canMoveToAssetsDirectory = (ressource) => {
36
+ if (ressource.isEntryPoint) {
37
+ return false
38
+ }
39
+ // in theory js module can be moved to assets directory
40
+ // but that needs to be tested
41
+ if (ressource.isJsModule) {
42
+ return false
43
+ }
44
+ // service worker MUST be at the root (same level than the HTML file)
45
+ // otherwise it might be registered for the scope "/assets/" instead of "/"
46
+ if (ressource.isServiceWorker) {
47
+ return false
48
+ }
49
+ return true
33
50
  }
@@ -27,6 +27,10 @@ export const jsenvServiceWorkerFinalizer = (
27
27
  buildUrl,
28
28
  serviceWorkerBuildUrl,
29
29
  )
30
+ if (urlRelativeToServiceWorker === "") {
31
+ // don't put the service worker itself
32
+ return
33
+ }
30
34
  const versioned = fileNameContainsHash(buildRelativeUrl)
31
35
  const rollupFile = rollupBuild[buildRelativeUrl]
32
36