@lwrjs/fs-asset-provider 0.24.2 → 0.24.4

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