@tramvai/module-progressive-web-app 2.101.1 → 2.103.1

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.
@@ -2,7 +2,7 @@ import { declareModule, provide, Scope, commandLineListTokens } from '@tramvai/c
2
2
  import { ResourceType, ResourceSlot, RESOURCES_REGISTRY } from '@tramvai/tokens-render';
3
3
  import { PROXY_CONFIG_TOKEN } from '@tramvai/tokens-server';
4
4
  import { appConfig } from '@tramvai/cli/lib/external/config';
5
- import { PWA_MANIFEST_URL_TOKEN } from '../tokens.es.js';
5
+ import { PWA_MANIFEST_URL_TOKEN, PWA_SW_SCOPE_TOKEN } from '../tokens.es.js';
6
6
 
7
7
  const TramvaiPwaManifestModule = declareModule({
8
8
  name: 'TramvaiPwaManifestModule',
@@ -10,15 +10,19 @@ const TramvaiPwaManifestModule = declareModule({
10
10
  provide({
11
11
  provide: PROXY_CONFIG_TOKEN,
12
12
  scope: Scope.SINGLETON,
13
- useFactory: ({ manifestUrl }) => {
13
+ useFactory: ({ manifestUrl, swScope }) => {
14
14
  var _a, _b;
15
- return ({
15
+ return {
16
16
  context: [manifestUrl],
17
17
  target: (_b = (_a = appConfig.assetsPrefix) !== null && _a !== void 0 ? _a : process.env.ASSETS_PREFIX) !== null && _b !== void 0 ? _b : '',
18
- });
18
+ pathRewrite: (path) => {
19
+ return path.replace(swScope, '/');
20
+ },
21
+ };
19
22
  },
20
23
  deps: {
21
24
  manifestUrl: PWA_MANIFEST_URL_TOKEN,
25
+ swScope: PWA_SW_SCOPE_TOKEN,
22
26
  },
23
27
  }),
24
28
  provide({
@@ -42,12 +46,17 @@ const TramvaiPwaManifestModule = declareModule({
42
46
  }),
43
47
  provide({
44
48
  provide: PWA_MANIFEST_URL_TOKEN,
45
- useFactory: () => {
49
+ useFactory: ({ swScope }) => {
46
50
  const manifestDest = process.env.TRAMVAI_PWA_MANIFEST_DEST;
47
- const finalUrl = manifestDest.startsWith('/') ? manifestDest : `/${manifestDest}`;
48
- // @todo check that finalUrl is relative and ends with .json or .webmanifest
51
+ const normalizedUrl = manifestDest.startsWith('/') ? manifestDest : `/${manifestDest}`;
52
+ const normalizedScope = swScope.replace(/\/$/, '');
53
+ const finalUrl = `${normalizedScope}${normalizedUrl}`;
54
+ // @todo check that finalUrl is relative and ends with .json or .webmanifest and no slash duplicates
49
55
  return finalUrl;
50
56
  },
57
+ deps: {
58
+ swScope: PWA_SW_SCOPE_TOKEN,
59
+ },
51
60
  }),
52
61
  ],
53
62
  });
@@ -14,15 +14,19 @@ const TramvaiPwaManifestModule = core.declareModule({
14
14
  core.provide({
15
15
  provide: tokensServer.PROXY_CONFIG_TOKEN,
16
16
  scope: core.Scope.SINGLETON,
17
- useFactory: ({ manifestUrl }) => {
17
+ useFactory: ({ manifestUrl, swScope }) => {
18
18
  var _a, _b;
19
- return ({
19
+ return {
20
20
  context: [manifestUrl],
21
21
  target: (_b = (_a = config.appConfig.assetsPrefix) !== null && _a !== void 0 ? _a : process.env.ASSETS_PREFIX) !== null && _b !== void 0 ? _b : '',
22
- });
22
+ pathRewrite: (path) => {
23
+ return path.replace(swScope, '/');
24
+ },
25
+ };
23
26
  },
24
27
  deps: {
25
28
  manifestUrl: tokens.PWA_MANIFEST_URL_TOKEN,
29
+ swScope: tokens.PWA_SW_SCOPE_TOKEN,
26
30
  },
27
31
  }),
28
32
  core.provide({
@@ -46,12 +50,17 @@ const TramvaiPwaManifestModule = core.declareModule({
46
50
  }),
47
51
  core.provide({
48
52
  provide: tokens.PWA_MANIFEST_URL_TOKEN,
49
- useFactory: () => {
53
+ useFactory: ({ swScope }) => {
50
54
  const manifestDest = process.env.TRAMVAI_PWA_MANIFEST_DEST;
51
- const finalUrl = manifestDest.startsWith('/') ? manifestDest : `/${manifestDest}`;
52
- // @todo check that finalUrl is relative and ends with .json or .webmanifest
55
+ const normalizedUrl = manifestDest.startsWith('/') ? manifestDest : `/${manifestDest}`;
56
+ const normalizedScope = swScope.replace(/\/$/, '');
57
+ const finalUrl = `${normalizedScope}${normalizedUrl}`;
58
+ // @todo check that finalUrl is relative and ends with .json or .webmanifest and no slash duplicates
53
59
  return finalUrl;
54
60
  },
61
+ deps: {
62
+ swScope: tokens.PWA_SW_SCOPE_TOKEN,
63
+ },
55
64
  }),
56
65
  ],
57
66
  });
@@ -1,5 +1,6 @@
1
1
  import { declareModule, provide, Scope, optional, commandLineListTokens } from '@tramvai/core';
2
2
  import { MODERN_SATISFIES_TOKEN } from '@tramvai/tokens-render';
3
+ import { ENV_MANAGER_TOKEN } from '@tramvai/tokens-common';
3
4
  import { PWA_WORKBOX_TOKEN, PWA_SW_URL_TOKEN, PWA_SW_SCOPE_TOKEN, PWA_SW_PARAMS_TOKEN } from '../tokens.browser.js';
4
5
  import { providers } from './shared.browser.js';
5
6
 
@@ -10,7 +11,7 @@ const TramvaiPwaWorkboxModule = declareModule({
10
11
  provide({
11
12
  provide: PWA_WORKBOX_TOKEN,
12
13
  scope: Scope.SINGLETON,
13
- useFactory: ({ swUrl, swScope, modern, swParams }) => {
14
+ useFactory: ({ swUrl, swScope, modern, swParams, envManager }) => {
14
15
  let workbox = null;
15
16
  return async () => {
16
17
  if (!('serviceWorker' in navigator)) {
@@ -18,7 +19,10 @@ const TramvaiPwaWorkboxModule = declareModule({
18
19
  return workbox;
19
20
  }
20
21
  const { Workbox } = await import('workbox-window/Workbox');
21
- let finalSwUrl = modern ? swUrl.replace(/\.js$/, '.modern.js') : swUrl;
22
+ const hasModernBuild = !!process.env.TRAMVAI_MODERN_BUILD;
23
+ const isCsrMode = envManager.get('TRAMVAI_FORCE_CLIENT_SIDE_RENDERING') === 'true';
24
+ // tramvai modern build is not supported for CSR and not compatible with PWA module in CSR mode
25
+ let finalSwUrl = modern && hasModernBuild && !isCsrMode ? swUrl.replace(/\.js$/, '.modern.js') : swUrl;
22
26
  if (swParams && swParams.length) {
23
27
  const params = swParams
24
28
  .filter(Boolean)
@@ -44,6 +48,7 @@ const TramvaiPwaWorkboxModule = declareModule({
44
48
  swScope: PWA_SW_SCOPE_TOKEN,
45
49
  modern: MODERN_SATISFIES_TOKEN,
46
50
  swParams: optional(PWA_SW_PARAMS_TOKEN),
51
+ envManager: ENV_MANAGER_TOKEN,
47
52
  },
48
53
  }),
49
54
  provide({
@@ -53,12 +58,12 @@ const TramvaiPwaWorkboxModule = declareModule({
53
58
  if (!process.env.TRAMVAI_PWA_WORKBOX_ENABLED) {
54
59
  return;
55
60
  }
56
- const wb = await workbox();
57
- if (!wb) {
58
- // @todo: logs
59
- return;
60
- }
61
61
  try {
62
+ const wb = await workbox();
63
+ if (!wb) {
64
+ // @todo: logs
65
+ return;
66
+ }
62
67
  // @todo unregister when Workbox is disabled in config !!!
63
68
  // https://github.com/nuxt-community/pwa-module/blob/main/templates/workbox/workbox.unregister.js
64
69
  await wb.register();
@@ -1,7 +1,7 @@
1
1
  import { declareModule, provide, Scope } from '@tramvai/core';
2
2
  import { PROXY_CONFIG_TOKEN } from '@tramvai/tokens-server';
3
3
  import { appConfig } from '@tramvai/cli/lib/external/config';
4
- import { PWA_SW_URL_TOKEN } from '../tokens.es.js';
4
+ import { PWA_SW_URL_TOKEN, PWA_SW_SCOPE_TOKEN } from '../tokens.es.js';
5
5
  import { providers } from './shared.es.js';
6
6
 
7
7
  const TramvaiPwaWorkboxModule = declareModule({
@@ -11,15 +11,19 @@ const TramvaiPwaWorkboxModule = declareModule({
11
11
  provide({
12
12
  provide: PROXY_CONFIG_TOKEN,
13
13
  scope: Scope.SINGLETON,
14
- useFactory: ({ swUrl }) => {
14
+ useFactory: ({ swUrl, swScope }) => {
15
15
  var _a, _b;
16
- return ({
16
+ return {
17
17
  context: [swUrl, swUrl.replace(/\.js$/, '.modern.js')],
18
18
  target: (_b = (_a = appConfig.assetsPrefix) !== null && _a !== void 0 ? _a : process.env.ASSETS_PREFIX) !== null && _b !== void 0 ? _b : '',
19
- });
19
+ pathRewrite: (path) => {
20
+ return path.replace(swScope, '/');
21
+ },
22
+ };
20
23
  },
21
24
  deps: {
22
25
  swUrl: PWA_SW_URL_TOKEN,
26
+ swScope: PWA_SW_SCOPE_TOKEN,
23
27
  },
24
28
  }),
25
29
  ],
@@ -15,15 +15,19 @@ const TramvaiPwaWorkboxModule = core.declareModule({
15
15
  core.provide({
16
16
  provide: tokensServer.PROXY_CONFIG_TOKEN,
17
17
  scope: core.Scope.SINGLETON,
18
- useFactory: ({ swUrl }) => {
18
+ useFactory: ({ swUrl, swScope }) => {
19
19
  var _a, _b;
20
- return ({
20
+ return {
21
21
  context: [swUrl, swUrl.replace(/\.js$/, '.modern.js')],
22
22
  target: (_b = (_a = config.appConfig.assetsPrefix) !== null && _a !== void 0 ? _a : process.env.ASSETS_PREFIX) !== null && _b !== void 0 ? _b : '',
23
- });
23
+ pathRewrite: (path) => {
24
+ return path.replace(swScope, '/');
25
+ },
26
+ };
24
27
  },
25
28
  deps: {
26
29
  swUrl: tokens.PWA_SW_URL_TOKEN,
30
+ swScope: tokens.PWA_SW_SCOPE_TOKEN,
27
31
  },
28
32
  }),
29
33
  ],
@@ -1,16 +1,7 @@
1
1
  import { provide } from '@tramvai/core';
2
- import { PWA_SW_URL_TOKEN, PWA_SW_SCOPE_TOKEN } from '../tokens.browser.js';
2
+ import { PWA_SW_SCOPE_TOKEN, PWA_SW_URL_TOKEN } from '../tokens.browser.js';
3
3
 
4
4
  const providers = [
5
- provide({
6
- provide: PWA_SW_URL_TOKEN,
7
- useFactory: () => {
8
- const swDest = process.env.TRAMVAI_PWA_SW_DEST;
9
- const finalUrl = swDest.startsWith('/') ? swDest : `/${swDest}`;
10
- // @todo check that finalUrl is relative and ends with .js
11
- return finalUrl;
12
- },
13
- }),
14
5
  provide({
15
6
  provide: PWA_SW_SCOPE_TOKEN,
16
7
  useFactory: () => {
@@ -19,6 +10,20 @@ const providers = [
19
10
  return swScope;
20
11
  },
21
12
  }),
13
+ provide({
14
+ provide: PWA_SW_URL_TOKEN,
15
+ useFactory: ({ swScope }) => {
16
+ const swDest = process.env.TRAMVAI_PWA_SW_DEST;
17
+ const normalizedUrl = swDest.startsWith('/') ? swDest : `/${swDest}`;
18
+ const normalizedScope = swScope.replace(/\/$/, '');
19
+ const finalUrl = `${normalizedScope}${normalizedUrl}`;
20
+ // @todo check that finalUrl is relative and ends with .js and no slash duplicates
21
+ return finalUrl;
22
+ },
23
+ deps: {
24
+ swScope: PWA_SW_SCOPE_TOKEN,
25
+ },
26
+ }),
22
27
  ];
23
28
 
24
29
  export { providers };
@@ -1,3 +1,23 @@
1
- export declare const providers: import("@tramvai/core").Provider<unknown, string & {
1
+ export declare const providers: (import("@tinkoff/dippy/lib/Provider").ValueProvider<string & {
2
2
  __type?: "base token" | undefined;
3
- }>[];
3
+ }> | import("@tinkoff/dippy/lib/Provider").ClassProviderWithDeps<unknown, string & {
4
+ __type?: "base token" | undefined;
5
+ }> | import("@tinkoff/dippy/lib/Provider").ClassProviderWithoutDeps<string & {
6
+ __type?: "base token" | undefined;
7
+ }> | import("@tinkoff/dippy/lib/Provider").FactoryProviderWithDeps<unknown, string & {
8
+ __type?: "base token" | undefined;
9
+ }> | import("@tinkoff/dippy/lib/Provider").FactoryProviderWithoutDeps<string & {
10
+ __type?: "base token" | undefined;
11
+ }> | import("@tinkoff/dippy/lib/Provider").ClassProviderWithDeps<{
12
+ swScope: string & {
13
+ __type?: "base token" | undefined;
14
+ };
15
+ }, string & {
16
+ __type?: "base token" | undefined;
17
+ }> | import("@tinkoff/dippy/lib/Provider").FactoryProviderWithDeps<{
18
+ swScope: string & {
19
+ __type?: "base token" | undefined;
20
+ };
21
+ }, string & {
22
+ __type?: "base token" | undefined;
23
+ }>)[];
@@ -1,16 +1,7 @@
1
1
  import { provide } from '@tramvai/core';
2
- import { PWA_SW_URL_TOKEN, PWA_SW_SCOPE_TOKEN } from '../tokens.es.js';
2
+ import { PWA_SW_SCOPE_TOKEN, PWA_SW_URL_TOKEN } from '../tokens.es.js';
3
3
 
4
4
  const providers = [
5
- provide({
6
- provide: PWA_SW_URL_TOKEN,
7
- useFactory: () => {
8
- const swDest = process.env.TRAMVAI_PWA_SW_DEST;
9
- const finalUrl = swDest.startsWith('/') ? swDest : `/${swDest}`;
10
- // @todo check that finalUrl is relative and ends with .js
11
- return finalUrl;
12
- },
13
- }),
14
5
  provide({
15
6
  provide: PWA_SW_SCOPE_TOKEN,
16
7
  useFactory: () => {
@@ -19,6 +10,20 @@ const providers = [
19
10
  return swScope;
20
11
  },
21
12
  }),
13
+ provide({
14
+ provide: PWA_SW_URL_TOKEN,
15
+ useFactory: ({ swScope }) => {
16
+ const swDest = process.env.TRAMVAI_PWA_SW_DEST;
17
+ const normalizedUrl = swDest.startsWith('/') ? swDest : `/${swDest}`;
18
+ const normalizedScope = swScope.replace(/\/$/, '');
19
+ const finalUrl = `${normalizedScope}${normalizedUrl}`;
20
+ // @todo check that finalUrl is relative and ends with .js and no slash duplicates
21
+ return finalUrl;
22
+ },
23
+ deps: {
24
+ swScope: PWA_SW_SCOPE_TOKEN,
25
+ },
26
+ }),
22
27
  ];
23
28
 
24
29
  export { providers };
@@ -6,15 +6,6 @@ var core = require('@tramvai/core');
6
6
  var tokens = require('../tokens.js');
7
7
 
8
8
  const providers = [
9
- core.provide({
10
- provide: tokens.PWA_SW_URL_TOKEN,
11
- useFactory: () => {
12
- const swDest = process.env.TRAMVAI_PWA_SW_DEST;
13
- const finalUrl = swDest.startsWith('/') ? swDest : `/${swDest}`;
14
- // @todo check that finalUrl is relative and ends with .js
15
- return finalUrl;
16
- },
17
- }),
18
9
  core.provide({
19
10
  provide: tokens.PWA_SW_SCOPE_TOKEN,
20
11
  useFactory: () => {
@@ -23,6 +14,20 @@ const providers = [
23
14
  return swScope;
24
15
  },
25
16
  }),
17
+ core.provide({
18
+ provide: tokens.PWA_SW_URL_TOKEN,
19
+ useFactory: ({ swScope }) => {
20
+ const swDest = process.env.TRAMVAI_PWA_SW_DEST;
21
+ const normalizedUrl = swDest.startsWith('/') ? swDest : `/${swDest}`;
22
+ const normalizedScope = swScope.replace(/\/$/, '');
23
+ const finalUrl = `${normalizedScope}${normalizedUrl}`;
24
+ // @todo check that finalUrl is relative and ends with .js and no slash duplicates
25
+ return finalUrl;
26
+ },
27
+ deps: {
28
+ swScope: tokens.PWA_SW_SCOPE_TOKEN,
29
+ },
30
+ }),
26
31
  ];
27
32
 
28
33
  exports.providers = providers;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tramvai/module-progressive-web-app",
3
- "version": "2.101.1",
3
+ "version": "2.103.1",
4
4
  "description": "Pwa integration - SW, manifest, icons and meta",
5
5
  "browser": "lib/browser.js",
6
6
  "main": "lib/server.js",
@@ -23,14 +23,15 @@
23
23
  "registry": "https://registry.npmjs.org/"
24
24
  },
25
25
  "dependencies": {
26
- "@tramvai/tokens-render": "2.101.1",
27
- "@tramvai/tokens-server": "2.101.1",
26
+ "@tramvai/tokens-common": "2.103.1",
27
+ "@tramvai/tokens-render": "2.103.1",
28
+ "@tramvai/tokens-server": "2.103.1",
28
29
  "workbox-window": "^6.4.1"
29
30
  },
30
31
  "devDependencies": {},
31
32
  "peerDependencies": {
32
- "@tramvai/cli": "2.101.1",
33
- "@tramvai/core": "2.101.1",
33
+ "@tramvai/cli": "2.103.1",
34
+ "@tramvai/core": "2.103.1",
34
35
  "@tinkoff/dippy": "0.8.15",
35
36
  "tslib": "^2.4.0"
36
37
  }