@lwrjs/fs-asset-provider 0.24.1 → 0.24.3

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.
Files changed (2) hide show
  1. package/build/cjs/index.cjs +58 -32
  2. package/package.json +5 -5
@@ -1,35 +1,42 @@
1
+ "use strict";
1
2
  var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
3
6
  var __getProtoOf = Object.getPrototypeOf;
4
7
  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
8
  var __export = (target, all) => {
9
9
  for (var name in all)
10
- __defProp(target, name, {get: all[name], enumerable: true});
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
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});
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
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);
18
+ return to;
22
19
  };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
23
29
 
24
30
  // packages/@lwrjs/fs-asset-provider/src/index.ts
25
- __markAsModule(exports);
26
- __export(exports, {
27
- default: () => src_default
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ default: () => FsAssetProvider
28
34
  });
29
- var import_fs_extra = __toModule(require("fs-extra"));
30
- var import_path = __toModule(require("path"));
31
- var import_diagnostics = __toModule(require("@lwrjs/diagnostics"));
32
- var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
35
+ module.exports = __toCommonJS(index_exports);
36
+ var import_fs_extra = __toESM(require("fs-extra"), 1);
37
+ var import_path = require("path");
38
+ var import_diagnostics = require("@lwrjs/diagnostics");
39
+ var import_shared_utils = require("@lwrjs/shared-utils");
33
40
  function hash(filePath) {
34
41
  const result = import_fs_extra.default.statSync(filePath);
35
42
  return (result.mtimeMs * 1e4).toString();
@@ -37,20 +44,23 @@ function hash(filePath) {
37
44
  var FsAssetProvider = class {
38
45
  constructor(_pluginConfig, providerConfig) {
39
46
  this.name = "fs-asset-provider";
40
- this.cachedAssets = new Map();
47
+ this.cachedAssets = /* @__PURE__ */ new Map();
41
48
  const {
42
49
  appEmitter,
43
- runtimeEnvironment: {watchFiles},
50
+ runtimeEnvironment: { watchFiles },
44
51
  watcherFactory
45
52
  } = providerConfig;
46
- const {assets, rootDir, layoutsDir, contentDir, basePath} = providerConfig.config;
53
+ const { assets, rootDir, layoutsDir, contentDir, basePath } = providerConfig.config;
47
54
  this.basePath = basePath;
48
- this.resourcePaths = {assets, rootDir, layoutsDir, contentDir};
49
- this.assetPathMap = assets.reduce((map, asset) => {
50
- const urlPath = `${basePath}${asset.urlPath}`;
51
- map.set(urlPath, asset.dir || asset.file);
52
- return map;
53
- }, new Map());
55
+ this.resourcePaths = { assets, rootDir, layoutsDir, contentDir };
56
+ this.assetPathMap = assets.reduce(
57
+ (map, asset) => {
58
+ const urlPath = `${basePath}${asset.urlPath}`;
59
+ map.set(urlPath, asset.dir || asset.file);
60
+ return map;
61
+ },
62
+ /* @__PURE__ */ new Map()
63
+ );
54
64
  this.emitter = appEmitter;
55
65
  if (watchFiles && watcherFactory) {
56
66
  this.watcher = watcherFactory.setupWatcher(this.onModuleChange.bind(this));
@@ -65,17 +75,34 @@ var FsAssetProvider = class {
65
75
  cachedAsset = await this.getAssetFromFSPath(fileChanged);
66
76
  this.emitter.notifyAssetSourceChanged(cachedAsset);
67
77
  }
78
+ // -- Public API --------------------------------------------------------------------
68
79
  async initialize() {
69
80
  return;
70
81
  }
82
+ /**
83
+ * Public API to get an AssetSource object from an asset identifier
84
+ */
71
85
  async getAsset(assetId) {
72
- const fullAssetPath = (0, import_shared_utils.normalizeAssetSpecifier)(assetId, this.assetPathMap, this.resourcePaths, this.basePath);
86
+ const fullAssetPath = (0, import_shared_utils.normalizeAssetSpecifier)(
87
+ assetId,
88
+ this.assetPathMap,
89
+ this.resourcePaths,
90
+ this.basePath
91
+ );
73
92
  return this.getAssetFromFSPath(fullAssetPath);
74
93
  }
94
+ /**
95
+ * True if the resolved path falls within one of the roots this provider is configured
96
+ * to serve from. Last line of defense against path traversal, independent of whatever
97
+ * validation (or lack thereof) happened upstream of this provider.
98
+ */
75
99
  isWithinConfiguredRoots(resolvedPath) {
76
100
  const roots = [...this.assetPathMap.values(), ...Object.values(this.resourcePaths)].filter((root) => typeof root === "string" && root.length > 0).map((root) => (0, import_path.resolve)(root));
77
101
  return roots.some((root) => resolvedPath === root || resolvedPath.startsWith(root + import_path.sep));
78
102
  }
103
+ /**
104
+ * Get and AssetSource object from a resolved filesystem file path.
105
+ */
79
106
  async getAssetFromFSPath(assetPath) {
80
107
  const decodedAssetPath = decodeURI(assetPath);
81
108
  const fullAssetPath = (0, import_shared_utils.toForwardSlash)((0, import_path.normalize)(decodedAssetPath));
@@ -92,7 +119,7 @@ var FsAssetProvider = class {
92
119
  ownHash,
93
120
  content: (passedEncoding) => {
94
121
  const encoding = passedEncoding || (mimeType && mimeType.startsWith("text/") ? "utf-8" : null);
95
- return import_fs_extra.default.readFileSync(assetPath2, {encoding});
122
+ return import_fs_extra.default.readFileSync(assetPath2, { encoding });
96
123
  }
97
124
  };
98
125
  this.cachedAssets.set(fullAssetPath, assetDef);
@@ -110,4 +137,3 @@ var FsAssetProvider = class {
110
137
  return this.cachedAssets.get(fullAssetPath);
111
138
  }
112
139
  };
113
- var src_default = FsAssetProvider;
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.24.1",
7
+ "version": "0.24.3",
8
8
  "homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
9
9
  "repository": {
10
10
  "type": "git",
@@ -33,16 +33,16 @@
33
33
  "build": "tsc -b"
34
34
  },
35
35
  "dependencies": {
36
- "@lwrjs/diagnostics": "0.24.1",
37
- "@lwrjs/shared-utils": "0.24.1",
36
+ "@lwrjs/diagnostics": "0.24.3",
37
+ "@lwrjs/shared-utils": "0.24.3",
38
38
  "fs-extra": "^11.2.0"
39
39
  },
40
40
  "devDependencies": {
41
- "@lwrjs/types": "0.24.1",
41
+ "@lwrjs/types": "0.24.3",
42
42
  "memfs": "^4.13.0"
43
43
  },
44
44
  "engines": {
45
45
  "node": ">=22.0.0"
46
46
  },
47
- "gitHead": "ebc0aaa310f5ebd008732d0203a15a1c51f77e5e"
47
+ "gitHead": "ed415a8f04d5558cac756fbc2a0e454a373e31c1"
48
48
  }