@lwrjs/router 0.9.0-alpha.12 → 0.9.0-alpha.13
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.
- package/build/cjs/services/module-provider/index.cjs +3 -2
- package/build/cjs/services/module-provider/utils.cjs +2 -2
- package/build/services/module-provider/index.js +5 -2
- package/build/services/module-provider/utils.d.ts +2 -1
- package/build/services/module-provider/utils.js +3 -3
- package/package.json +5 -5
|
@@ -38,7 +38,8 @@ var RouterModuleProvider = class {
|
|
|
38
38
|
const {
|
|
39
39
|
appEmitter,
|
|
40
40
|
config: {basePath, rootDir, contentDir, layoutsDir},
|
|
41
|
-
runtimeEnvironment: {lwrVersion, watchFiles}
|
|
41
|
+
runtimeEnvironment: {lwrVersion, watchFiles},
|
|
42
|
+
watcherFactory
|
|
42
43
|
} = context;
|
|
43
44
|
this.version = lwrVersion;
|
|
44
45
|
this.routesDir = (0, import_shared_utils.normalizeResourcePath)(routesDir, {
|
|
@@ -49,7 +50,7 @@ var RouterModuleProvider = class {
|
|
|
49
50
|
}).replace(/\/$/, "");
|
|
50
51
|
this.appBasePath = basePath ? basePath : void 0;
|
|
51
52
|
this.routerEmitter = appEmitter;
|
|
52
|
-
this.routerWatcher = watchFiles ? (0, import_utils.setUpWatcher)(this.onRouterModuleChange.bind(this)) : void 0;
|
|
53
|
+
this.routerWatcher = watchFiles && watcherFactory ? (0, import_utils.setUpWatcher)(watcherFactory, this.onRouterModuleChange.bind(this)) : void 0;
|
|
53
54
|
}
|
|
54
55
|
async onRouterModuleChange(configPath, deleted = false) {
|
|
55
56
|
const moduleId = this.watchedFileMap.get(configPath);
|
|
@@ -39,8 +39,8 @@ function getRouterConfigPath(dir, specifier) {
|
|
|
39
39
|
const routerId = parseSpecifier(specifier);
|
|
40
40
|
return `${dir}/${routerId}.json`;
|
|
41
41
|
}
|
|
42
|
-
function setUpWatcher(onModuleChange) {
|
|
43
|
-
const watcher =
|
|
42
|
+
function setUpWatcher(factory, onModuleChange) {
|
|
43
|
+
const watcher = factory.createFileWatcher();
|
|
44
44
|
watcher.on("change", (0, import_shared_utils.debounce)((file) => onModuleChange(file), 500));
|
|
45
45
|
watcher.on("unlink", (0, import_shared_utils.debounce)((file) => onModuleChange(file, true), 500));
|
|
46
46
|
watcher.on("add", (file) => import_shared_utils.logger.info(`Watching Router Config file at "${file}"`));
|
|
@@ -10,7 +10,7 @@ export default class RouterModuleProvider {
|
|
|
10
10
|
// 1. Cache the Router Config JSON objects read from the file system, by config path (routerConfigJsonCache in ../index)
|
|
11
11
|
// 2. Cache the modules generated from the config, by config path
|
|
12
12
|
this.routerModuleCache = new Map();
|
|
13
|
-
const { appEmitter, config: { basePath, rootDir, contentDir, layoutsDir }, runtimeEnvironment: { lwrVersion, watchFiles }, } = context;
|
|
13
|
+
const { appEmitter, config: { basePath, rootDir, contentDir, layoutsDir }, runtimeEnvironment: { lwrVersion, watchFiles }, watcherFactory, } = context;
|
|
14
14
|
this.version = lwrVersion;
|
|
15
15
|
// Replace aliases and remove trailing slash from the routes directory
|
|
16
16
|
this.routesDir = normalizeResourcePath(routesDir, {
|
|
@@ -24,7 +24,10 @@ export default class RouterModuleProvider {
|
|
|
24
24
|
this.appBasePath = basePath ? basePath : undefined;
|
|
25
25
|
// Set up watcher on Router Config files
|
|
26
26
|
this.routerEmitter = appEmitter;
|
|
27
|
-
this.routerWatcher =
|
|
27
|
+
this.routerWatcher =
|
|
28
|
+
watchFiles && watcherFactory
|
|
29
|
+
? setUpWatcher(watcherFactory, this.onRouterModuleChange.bind(this))
|
|
30
|
+
: undefined;
|
|
28
31
|
}
|
|
29
32
|
// When Router Metadata changes on the file system:
|
|
30
33
|
// 1. delete the config data from the routerConfigJsonCache (in ../index)
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Watcher } from '@lwrjs/types';
|
|
2
2
|
import type { LwrRouterConfig } from '../index.js';
|
|
3
|
+
import type { WatcherFactory } from '@lwrjs/types';
|
|
3
4
|
export declare const SPECIFIER_PREFIX = "@lwrjs/router/";
|
|
4
5
|
/**
|
|
5
6
|
* Parse a specifier into its Router Config ID
|
|
@@ -17,7 +18,7 @@ export declare function getRouterConfigPath(dir: string, specifier: string): str
|
|
|
17
18
|
* Set up a file system watcher; used to spy on Router Config file changes
|
|
18
19
|
* @param onModuleChange - File change callback function
|
|
19
20
|
*/
|
|
20
|
-
export declare function setUpWatcher(onModuleChange: (file: string, deleted?: boolean) => void): Watcher;
|
|
21
|
+
export declare function setUpWatcher(factory: WatcherFactory, onModuleChange: (file: string, deleted?: boolean) => void): Watcher;
|
|
21
22
|
/**
|
|
22
23
|
* Generate a module string which fulfills a router request
|
|
23
24
|
* @param routes - The array of route definitions
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { debounce, logger } from '@lwrjs/shared-utils';
|
|
2
2
|
export const SPECIFIER_PREFIX = '@lwrjs/router/';
|
|
3
3
|
/**
|
|
4
4
|
* Parse a specifier into its Router Config ID
|
|
@@ -21,8 +21,8 @@ export function getRouterConfigPath(dir, specifier) {
|
|
|
21
21
|
* Set up a file system watcher; used to spy on Router Config file changes
|
|
22
22
|
* @param onModuleChange - File change callback function
|
|
23
23
|
*/
|
|
24
|
-
export function setUpWatcher(onModuleChange) {
|
|
25
|
-
const watcher = createFileWatcher();
|
|
24
|
+
export function setUpWatcher(factory, onModuleChange) {
|
|
25
|
+
const watcher = factory.createFileWatcher();
|
|
26
26
|
watcher.on('change', debounce((file) => onModuleChange(file), 500));
|
|
27
27
|
watcher.on('unlink', debounce((file) => onModuleChange(file, true), 500));
|
|
28
28
|
watcher.on('add', (file) => logger.info(`Watching Router Config file at "${file}"`));
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
8
|
-
"version": "0.9.0-alpha.
|
|
8
|
+
"version": "0.9.0-alpha.13",
|
|
9
9
|
"homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
@@ -48,9 +48,9 @@
|
|
|
48
48
|
"utam:compile": "utam -c utam.config.cjs -t module"
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@lwrjs/client-modules": "0.9.0-alpha.
|
|
52
|
-
"@lwrjs/diagnostics": "0.9.0-alpha.
|
|
53
|
-
"@lwrjs/shared-utils": "0.9.0-alpha.
|
|
51
|
+
"@lwrjs/client-modules": "0.9.0-alpha.13",
|
|
52
|
+
"@lwrjs/diagnostics": "0.9.0-alpha.13",
|
|
53
|
+
"@lwrjs/shared-utils": "0.9.0-alpha.13",
|
|
54
54
|
"ajv": "6.12.6"
|
|
55
55
|
},
|
|
56
56
|
"lwc": {
|
|
@@ -76,5 +76,5 @@
|
|
|
76
76
|
"engines": {
|
|
77
77
|
"node": ">=14.15.4 <19"
|
|
78
78
|
},
|
|
79
|
-
"gitHead": "
|
|
79
|
+
"gitHead": "fa30915a685f6e8c5c2895d0c053d59145780123"
|
|
80
80
|
}
|