@lwrjs/fs-asset-provider 0.5.11-alpha.2 → 0.6.0-alpha.11

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.
@@ -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 import_crypto = __toModule(require("crypto"));
32
+ var import_shared_utils2 = __toModule(require("@lwrjs/shared-utils"));
34
33
  function hash(filePath) {
35
- return new Promise((resolve, reject) => {
36
- const hash2 = import_crypto.default.createHash("sha1");
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, import_shared_utils.setupWatcher)(this.onModuleChange.bind(this));
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 = await hash(fullAssetPath);
67
+ const ownHash = hash(fullAssetPath);
74
68
  const assetDef = {
75
69
  entry: fullAssetPath,
76
70
  ext,
77
- mime: (0, import_mime_types.lookup)(fullAssetPath),
71
+ mime: (0, import_shared_utils.mimeLookup)(fullAssetPath),
78
72
  ownHash,
79
- stream: (encoding) => import_fs.default.createReadStream(fullAssetPath, {encoding}),
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 { lookup } from 'mime-types';
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
- return new Promise((resolve, reject) => {
8
- const hash = crypto.createHash('sha1');
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 = await hash(fullAssetPath);
39
+ const ownHash = hash(fullAssetPath);
46
40
  const assetDef = {
47
41
  entry: fullAssetPath,
48
42
  ext: ext,
49
- mime: lookup(fullAssetPath),
43
+ mime: mimeLookup(fullAssetPath),
50
44
  ownHash,
51
- stream: (encoding) => fs.createReadStream(fullAssetPath, { encoding }),
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.5.11-alpha.2",
8
- "homepage": "https://lwr.dev/",
7
+ "version": "0.6.0-alpha.11",
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.5.11-alpha.2",
34
- "mime-types": "^2.1.27"
33
+ "@lwrjs/shared-utils": "0.6.0-alpha.11"
35
34
  },
36
35
  "devDependencies": {
37
- "@lwrjs/types": "0.5.11-alpha.2",
38
- "@types/mime-types": "2.1.0"
36
+ "@lwrjs/types": "0.6.0-alpha.11"
39
37
  },
40
38
  "engines": {
41
39
  "node": ">=14.15.4 <17"
42
40
  },
43
- "gitHead": "83785c79e6adbfb1ead85e0c23e9164a22cb5755"
41
+ "gitHead": "18ab72188c2d52e32cca47333951a9c76f996039"
44
42
  }