@lwrjs/shared-utils 0.9.0-alpha.11 → 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/fs-watch.cjs +43 -0
- package/build/cjs/fs.cjs +1 -15
- package/build/es/fs-watch.d.ts +17 -0
- package/build/es/fs-watch.js +27 -0
- package/build/es/fs.d.ts +1 -10
- package/build/es/fs.js +0 -21
- package/package.json +11 -5
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
+
var __markAsModule = (target) => __defProp(target, "__esModule", {value: true});
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, {get: all[name], enumerable: true});
|
|
11
|
+
};
|
|
12
|
+
var __exportStar = (target, module2, desc) => {
|
|
13
|
+
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(module2))
|
|
15
|
+
if (!__hasOwnProp.call(target, key) && key !== "default")
|
|
16
|
+
__defProp(target, key, {get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable});
|
|
17
|
+
}
|
|
18
|
+
return target;
|
|
19
|
+
};
|
|
20
|
+
var __toModule = (module2) => {
|
|
21
|
+
return __exportStar(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? {get: () => module2.default, enumerable: true} : {value: module2, enumerable: true})), module2);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// packages/@lwrjs/shared-utils/src/fs-watch.ts
|
|
25
|
+
__markAsModule(exports);
|
|
26
|
+
__export(exports, {
|
|
27
|
+
WatcherFactoryImpl: () => WatcherFactoryImpl
|
|
28
|
+
});
|
|
29
|
+
var import_chokidar = __toModule(require("chokidar"));
|
|
30
|
+
var import_object = __toModule(require("./object.cjs"));
|
|
31
|
+
var import_logger = __toModule(require("./logger.cjs"));
|
|
32
|
+
var WatcherFactoryImpl = class {
|
|
33
|
+
createFileWatcher(options = {persistent: true, ignored: "**/node_modules/**"}) {
|
|
34
|
+
return import_chokidar.default.watch([], options);
|
|
35
|
+
}
|
|
36
|
+
setupWatcher(onModuleChange) {
|
|
37
|
+
const fileWatcher = this.createFileWatcher();
|
|
38
|
+
fileWatcher.on("change", (0, import_object.debounce)((file) => onModuleChange(file), 500));
|
|
39
|
+
fileWatcher.on("unlink", (0, import_object.debounce)((file) => onModuleChange(file), 500));
|
|
40
|
+
fileWatcher.on("add", (file) => import_logger.logger.info(`Watching: ${file}`));
|
|
41
|
+
return fileWatcher;
|
|
42
|
+
}
|
|
43
|
+
};
|
package/build/cjs/fs.cjs
CHANGED
|
@@ -25,22 +25,18 @@ var __toModule = (module2) => {
|
|
|
25
25
|
__markAsModule(exports);
|
|
26
26
|
__export(exports, {
|
|
27
27
|
canResolveView: () => canResolveView,
|
|
28
|
-
createFileWatcher: () => createFileWatcher,
|
|
29
28
|
getViewSourceFromFile: () => getViewSourceFromFile,
|
|
30
29
|
hashContent: () => hashContent,
|
|
31
30
|
mimeLookup: () => import_mime_types.lookup,
|
|
32
31
|
normalizeDirectory: () => normalizeDirectory,
|
|
33
32
|
normalizeResourcePath: () => normalizeResourcePath,
|
|
34
33
|
readFile: () => readFile,
|
|
35
|
-
resolveFileExtension: () => resolveFileExtension
|
|
36
|
-
setupWatcher: () => setupWatcher
|
|
34
|
+
resolveFileExtension: () => resolveFileExtension
|
|
37
35
|
});
|
|
38
36
|
var import_fs = __toModule(require("fs"));
|
|
39
37
|
var import_path = __toModule(require("path"));
|
|
40
38
|
var import_crypto = __toModule(require("crypto"));
|
|
41
39
|
var import_identity = __toModule(require("./identity.cjs"));
|
|
42
|
-
var import_object = __toModule(require("./object.cjs"));
|
|
43
|
-
var import_chokidar = __toModule(require("chokidar"));
|
|
44
40
|
var import_diagnostics = __toModule(require("@lwrjs/diagnostics"));
|
|
45
41
|
var import_mime_types = __toModule(require("mime-types"));
|
|
46
42
|
var import_logger = __toModule(require("./logger.cjs"));
|
|
@@ -74,16 +70,6 @@ function resolveFileExtension(filePath) {
|
|
|
74
70
|
throw new Error(`Unable to find file "${filePath}"`);
|
|
75
71
|
}
|
|
76
72
|
}
|
|
77
|
-
function createFileWatcher(options = {persistent: true, ignored: "**/node_modules/**"}) {
|
|
78
|
-
return import_chokidar.default.watch([], options);
|
|
79
|
-
}
|
|
80
|
-
function setupWatcher(onModuleChange) {
|
|
81
|
-
const fileWatcher = createFileWatcher();
|
|
82
|
-
fileWatcher.on("change", (0, import_object.debounce)((file) => onModuleChange(file), 500));
|
|
83
|
-
fileWatcher.on("unlink", (0, import_object.debounce)((file) => onModuleChange(file), 500));
|
|
84
|
-
fileWatcher.on("add", (file) => import_logger.logger.info(`Watching: ${file}`));
|
|
85
|
-
return fileWatcher;
|
|
86
|
-
}
|
|
87
73
|
function canResolveView(source, type) {
|
|
88
74
|
if (!source.endsWith(`.${type}`)) {
|
|
89
75
|
return false;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Watcher, WatcherFactory, WatchOptions } from '@lwrjs/types';
|
|
2
|
+
/**
|
|
3
|
+
* Factory comptable with the LWR Runtime to create a file watch library for LWR dev server.
|
|
4
|
+
* When importing this module make sure the optional library 'chokidar' is installed.
|
|
5
|
+
*/
|
|
6
|
+
export declare class WatcherFactoryImpl implements WatcherFactory {
|
|
7
|
+
/**
|
|
8
|
+
* Set up a watcher with the given options
|
|
9
|
+
* @param options
|
|
10
|
+
*/
|
|
11
|
+
createFileWatcher(options?: WatchOptions): Watcher;
|
|
12
|
+
/**
|
|
13
|
+
* Set up file watcher
|
|
14
|
+
*/
|
|
15
|
+
setupWatcher(onModuleChange: Function): Watcher;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=fs-watch.d.ts.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import chokidar from 'chokidar';
|
|
2
|
+
import { debounce } from './object.js';
|
|
3
|
+
import { logger } from './logger.js';
|
|
4
|
+
/**
|
|
5
|
+
* Factory comptable with the LWR Runtime to create a file watch library for LWR dev server.
|
|
6
|
+
* When importing this module make sure the optional library 'chokidar' is installed.
|
|
7
|
+
*/
|
|
8
|
+
export class WatcherFactoryImpl {
|
|
9
|
+
/**
|
|
10
|
+
* Set up a watcher with the given options
|
|
11
|
+
* @param options
|
|
12
|
+
*/
|
|
13
|
+
createFileWatcher(options = { persistent: true, ignored: '**/node_modules/**' }) {
|
|
14
|
+
return chokidar.watch([], options);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Set up file watcher
|
|
18
|
+
*/
|
|
19
|
+
setupWatcher(onModuleChange) {
|
|
20
|
+
const fileWatcher = this.createFileWatcher();
|
|
21
|
+
fileWatcher.on('change', debounce((file) => onModuleChange(file), 500));
|
|
22
|
+
fileWatcher.on('unlink', debounce((file) => onModuleChange(file), 500));
|
|
23
|
+
fileWatcher.on('add', (file) => logger.info(`Watching: ${file}`));
|
|
24
|
+
return fileWatcher;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=fs-watch.js.map
|
package/build/es/fs.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { ResourcePaths,
|
|
2
|
+
import type { ResourcePaths, ViewSource } from '@lwrjs/types';
|
|
3
3
|
import { lookup } from 'mime-types';
|
|
4
4
|
/**
|
|
5
5
|
* Create a hash string for a source
|
|
@@ -16,15 +16,6 @@ export declare function readFile(filePath: string): string;
|
|
|
16
16
|
* @param filePath
|
|
17
17
|
*/
|
|
18
18
|
export declare function resolveFileExtension(filePath: string): string;
|
|
19
|
-
/**
|
|
20
|
-
* Set up a watcher with the given options
|
|
21
|
-
* @param options
|
|
22
|
-
*/
|
|
23
|
-
export declare function createFileWatcher(options?: any): Watcher;
|
|
24
|
-
/**
|
|
25
|
-
* Set up file watcher
|
|
26
|
-
*/
|
|
27
|
-
export declare function setupWatcher(onModuleChange: Function): Watcher;
|
|
28
19
|
/**
|
|
29
20
|
* Returns if view of specific type can be resolved
|
|
30
21
|
*
|
package/build/es/fs.js
CHANGED
|
@@ -2,8 +2,6 @@ import fs from 'fs';
|
|
|
2
2
|
import pathLib from 'path';
|
|
3
3
|
import crypto from 'crypto';
|
|
4
4
|
import { slugify } from './identity.js';
|
|
5
|
-
import { debounce } from './object.js';
|
|
6
|
-
import chokidar from 'chokidar';
|
|
7
5
|
import { LwrUnresolvableError, createSingleDiagnosticError, descriptions } from '@lwrjs/diagnostics';
|
|
8
6
|
import { lookup } from 'mime-types';
|
|
9
7
|
import { DEBUG, logger, VERBOSE } from './logger.js';
|
|
@@ -55,25 +53,6 @@ export function resolveFileExtension(filePath) {
|
|
|
55
53
|
throw new Error(`Unable to find file "${filePath}"`);
|
|
56
54
|
}
|
|
57
55
|
}
|
|
58
|
-
/**
|
|
59
|
-
* Set up a watcher with the given options
|
|
60
|
-
* @param options
|
|
61
|
-
*/
|
|
62
|
-
export function createFileWatcher(
|
|
63
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
64
|
-
options = { persistent: true, ignored: '**/node_modules/**' }) {
|
|
65
|
-
return chokidar.watch([], options);
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Set up file watcher
|
|
69
|
-
*/
|
|
70
|
-
export function setupWatcher(onModuleChange) {
|
|
71
|
-
const fileWatcher = createFileWatcher();
|
|
72
|
-
fileWatcher.on('change', debounce((file) => onModuleChange(file), 500));
|
|
73
|
-
fileWatcher.on('unlink', debounce((file) => onModuleChange(file), 500));
|
|
74
|
-
fileWatcher.on('add', (file) => logger.info(`Watching: ${file}`));
|
|
75
|
-
return fileWatcher;
|
|
76
|
-
}
|
|
77
56
|
/**
|
|
78
57
|
* Returns if view of specific type can be resolved
|
|
79
58
|
*
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.9.0-alpha.
|
|
7
|
+
"version": "0.9.0-alpha.13",
|
|
8
8
|
"homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
@@ -25,6 +25,10 @@
|
|
|
25
25
|
".": {
|
|
26
26
|
"import": "./build/es/index.js",
|
|
27
27
|
"require": "./build/cjs/index.cjs"
|
|
28
|
+
},
|
|
29
|
+
"./fs-watch": {
|
|
30
|
+
"import": "./build/es/fs-watch.js",
|
|
31
|
+
"require": "./build/cjs/fs-watch.cjs"
|
|
28
32
|
}
|
|
29
33
|
},
|
|
30
34
|
"files": [
|
|
@@ -33,7 +37,6 @@
|
|
|
33
37
|
"build/**/*.d.ts"
|
|
34
38
|
],
|
|
35
39
|
"dependencies": {
|
|
36
|
-
"chokidar": "^3.4.0",
|
|
37
40
|
"es-module-lexer": "^0.3.18",
|
|
38
41
|
"esbuild": "^0.9.7",
|
|
39
42
|
"fast-json-stable-stringify": "^2.1.0",
|
|
@@ -44,14 +47,17 @@
|
|
|
44
47
|
"path-to-regexp": "^6.2.0",
|
|
45
48
|
"slugify": "^1.4.5"
|
|
46
49
|
},
|
|
50
|
+
"optionalDependencies": {
|
|
51
|
+
"chokidar": "^3.5.3"
|
|
52
|
+
},
|
|
47
53
|
"devDependencies": {
|
|
48
|
-
"@lwrjs/diagnostics": "0.9.0-alpha.
|
|
49
|
-
"@lwrjs/types": "0.9.0-alpha.
|
|
54
|
+
"@lwrjs/diagnostics": "0.9.0-alpha.13",
|
|
55
|
+
"@lwrjs/types": "0.9.0-alpha.13",
|
|
50
56
|
"@types/mime-types": "2.1.1",
|
|
51
57
|
"@types/path-to-regexp": "^1.7.0"
|
|
52
58
|
},
|
|
53
59
|
"engines": {
|
|
54
60
|
"node": ">=14.15.4 <19"
|
|
55
61
|
},
|
|
56
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "fa30915a685f6e8c5c2895d0c053d59145780123"
|
|
57
63
|
}
|