@ampless/runtime 1.0.0-alpha.30 → 1.0.0-alpha.31
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/dist/index.js +22 -6
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -236,10 +236,25 @@ import {
|
|
|
236
236
|
} from "ampless";
|
|
237
237
|
|
|
238
238
|
// src/plugin-package-manifest.ts
|
|
239
|
-
import { readFileSync } from "fs";
|
|
240
|
-
import { fileURLToPath } from "url";
|
|
241
239
|
var TRUST_LEVELS = ["untrusted", "trusted", "privileged"];
|
|
242
|
-
|
|
240
|
+
function getNodeApi() {
|
|
241
|
+
if (typeof window !== "undefined") return null;
|
|
242
|
+
const proc = typeof process !== "undefined" ? process : void 0;
|
|
243
|
+
if (typeof proc?.getBuiltinModule !== "function") return null;
|
|
244
|
+
if (typeof import.meta.resolve !== "function") return null;
|
|
245
|
+
try {
|
|
246
|
+
const fs = proc.getBuiltinModule("node:fs");
|
|
247
|
+
const url = proc.getBuiltinModule("node:url");
|
|
248
|
+
if (!fs || !url) return null;
|
|
249
|
+
const resolve = import.meta.resolve.bind(import.meta);
|
|
250
|
+
return {
|
|
251
|
+
readFile: (u) => fs.readFileSync(url.fileURLToPath(u), "utf8"),
|
|
252
|
+
resolve
|
|
253
|
+
};
|
|
254
|
+
} catch {
|
|
255
|
+
return null;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
243
258
|
function isValidManifest(value) {
|
|
244
259
|
if (typeof value !== "object" || value === null) return false;
|
|
245
260
|
const v = value;
|
|
@@ -254,16 +269,17 @@ function isValidManifest(value) {
|
|
|
254
269
|
return true;
|
|
255
270
|
}
|
|
256
271
|
function loadPackageManifest(packageName) {
|
|
257
|
-
|
|
272
|
+
const node = getNodeApi();
|
|
273
|
+
if (!node) return null;
|
|
258
274
|
let resolvedUrl;
|
|
259
275
|
try {
|
|
260
|
-
resolvedUrl =
|
|
276
|
+
resolvedUrl = node.resolve(`${packageName}/package.json`);
|
|
261
277
|
} catch {
|
|
262
278
|
return null;
|
|
263
279
|
}
|
|
264
280
|
let raw;
|
|
265
281
|
try {
|
|
266
|
-
raw =
|
|
282
|
+
raw = node.readFile(resolvedUrl);
|
|
267
283
|
} catch {
|
|
268
284
|
return null;
|
|
269
285
|
}
|
package/package.json
CHANGED