@lwrjs/fs-asset-provider 0.6.0-alpha.1 → 0.6.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/index.cjs +7 -14
- package/build/es/index.js +6 -13
- package/package.json +5 -7
package/build/cjs/index.cjs
CHANGED
|
@@ -28,17 +28,11 @@ __export(exports, {
|
|
|
28
28
|
});
|
|
29
29
|
var import_fs = __toModule(require("fs"));
|
|
30
30
|
var import_path = __toModule(require("path"));
|
|
31
|
-
var import_mime_types = __toModule(require("mime-types"));
|
|
32
31
|
var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
|
|
33
|
-
var
|
|
32
|
+
var import_shared_utils2 = __toModule(require("@lwrjs/shared-utils"));
|
|
34
33
|
function hash(filePath) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const rs = import_fs.default.createReadStream(filePath);
|
|
38
|
-
rs.on("error", reject);
|
|
39
|
-
rs.on("data", (chunk) => hash2.update(chunk));
|
|
40
|
-
rs.on("end", () => resolve(hash2.digest("hex").slice(0, 7)));
|
|
41
|
-
});
|
|
34
|
+
const result = import_fs.default.statSync(filePath);
|
|
35
|
+
return (result.mtimeMs * 1e4).toString();
|
|
42
36
|
}
|
|
43
37
|
var FsAssetProvider = class {
|
|
44
38
|
constructor(pluginConfig, providerConfig) {
|
|
@@ -50,7 +44,7 @@ var FsAssetProvider = class {
|
|
|
50
44
|
} = providerConfig;
|
|
51
45
|
this.emitter = appEmitter;
|
|
52
46
|
if (watchFiles) {
|
|
53
|
-
this.watcher = (0,
|
|
47
|
+
this.watcher = (0, import_shared_utils2.setupWatcher)(this.onModuleChange.bind(this));
|
|
54
48
|
}
|
|
55
49
|
}
|
|
56
50
|
async onModuleChange(fileChanged) {
|
|
@@ -70,14 +64,13 @@ var FsAssetProvider = class {
|
|
|
70
64
|
if (!this.cachedAssets.has(fullAssetPath)) {
|
|
71
65
|
const ext = (0, import_path.extname)(`x.${fullAssetPath}`).toLowerCase().substr(1);
|
|
72
66
|
if (ext && import_fs.default.existsSync(fullAssetPath)) {
|
|
73
|
-
const ownHash =
|
|
67
|
+
const ownHash = hash(fullAssetPath);
|
|
74
68
|
const assetDef = {
|
|
75
69
|
entry: fullAssetPath,
|
|
76
70
|
ext,
|
|
77
|
-
mime: (0,
|
|
71
|
+
mime: (0, import_shared_utils.mimeLookup)(fullAssetPath),
|
|
78
72
|
ownHash,
|
|
79
|
-
|
|
80
|
-
content: (encoding) => import_fs.default.readFileSync(fullAssetPath, encoding).toString()
|
|
73
|
+
content: (encoding) => import_fs.default.readFileSync(fullAssetPath, encoding)
|
|
81
74
|
};
|
|
82
75
|
this.cachedAssets.set(fullAssetPath, assetDef);
|
|
83
76
|
if (this.watcher) {
|
package/build/es/index.js
CHANGED
|
@@ -1,16 +1,10 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
2
|
import { extname } from 'path';
|
|
3
|
-
import {
|
|
3
|
+
import { mimeLookup } from '@lwrjs/shared-utils';
|
|
4
4
|
import { setupWatcher } from '@lwrjs/shared-utils';
|
|
5
|
-
import crypto from 'crypto';
|
|
6
5
|
function hash(filePath) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const rs = fs.createReadStream(filePath);
|
|
10
|
-
rs.on('error', reject);
|
|
11
|
-
rs.on('data', (chunk) => hash.update(chunk));
|
|
12
|
-
rs.on('end', () => resolve(hash.digest('hex').slice(0, 7)));
|
|
13
|
-
});
|
|
6
|
+
const result = fs.statSync(filePath);
|
|
7
|
+
return (result.mtimeMs * 10000).toString();
|
|
14
8
|
}
|
|
15
9
|
export default class FsAssetProvider {
|
|
16
10
|
constructor(pluginConfig, providerConfig) {
|
|
@@ -42,14 +36,13 @@ export default class FsAssetProvider {
|
|
|
42
36
|
// Clever normalization to avoid corner cases
|
|
43
37
|
const ext = extname(`x.${fullAssetPath}`).toLowerCase().substr(1);
|
|
44
38
|
if (ext && fs.existsSync(fullAssetPath)) {
|
|
45
|
-
const ownHash =
|
|
39
|
+
const ownHash = hash(fullAssetPath);
|
|
46
40
|
const assetDef = {
|
|
47
41
|
entry: fullAssetPath,
|
|
48
42
|
ext: ext,
|
|
49
|
-
mime:
|
|
43
|
+
mime: mimeLookup(fullAssetPath),
|
|
50
44
|
ownHash,
|
|
51
|
-
|
|
52
|
-
content: (encoding) => fs.readFileSync(fullAssetPath, encoding).toString(),
|
|
45
|
+
content: (encoding) => fs.readFileSync(fullAssetPath, encoding),
|
|
53
46
|
};
|
|
54
47
|
this.cachedAssets.set(fullAssetPath, assetDef);
|
|
55
48
|
if (this.watcher) {
|
package/package.json
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.6.0-alpha.
|
|
8
|
-
"homepage": "https://
|
|
7
|
+
"version": "0.6.0-alpha.13",
|
|
8
|
+
"homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
11
11
|
"url": "https://github.com/salesforce/lwr.git",
|
|
@@ -30,15 +30,13 @@
|
|
|
30
30
|
"build/**/*.d.ts"
|
|
31
31
|
],
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@lwrjs/shared-utils": "0.6.0-alpha.
|
|
34
|
-
"mime-types": "^2.1.27"
|
|
33
|
+
"@lwrjs/shared-utils": "0.6.0-alpha.13"
|
|
35
34
|
},
|
|
36
35
|
"devDependencies": {
|
|
37
|
-
"@lwrjs/types": "0.6.0-alpha.
|
|
38
|
-
"@types/mime-types": "2.1.0"
|
|
36
|
+
"@lwrjs/types": "0.6.0-alpha.13"
|
|
39
37
|
},
|
|
40
38
|
"engines": {
|
|
41
39
|
"node": ">=14.15.4 <17"
|
|
42
40
|
},
|
|
43
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "056d10307fe29540d1586f8fd75e357b82ce2acc"
|
|
44
42
|
}
|