npm package diff

Package: @forge/manifest

Versions: 7.5.2-next.0-experimental-10722bc - 7.7.0-next.13

File: package/out/utils/manifest-parser.js

Index: package/out/utils/manifest-parser.js
===================================================================
--- package/out/utils/manifest-parser.js
+++ package/out/utils/manifest-parser.js
@@ -1,11 +1,9 @@
 "use strict";
 Object.defineProperty(exports, "__esModule", { value: true });
 exports.ManifestParser = exports.ManifestParserError = void 0;
-const tslib_1 = require("tslib");
 const yaml_1 = require("yaml");
-const errors_1 = require("../text/errors");
-const Sentry = tslib_1.__importStar(require("@sentry/node"));
+const manifest_interpolator_1 = require("../interpolator/manifest-interpolator");
 const yamlConfigOptions = { indent: 2, skipInvalid: true };
 class ManifestParserError extends Error {
     constructor(message) {
         super(message);
@@ -16,37 +14,23 @@
         };
     }
 }
 exports.ManifestParserError = ManifestParserError;
-const POSSIBLE_ENVIRONMENT_VARIABLE = /\$\{([a-zA-Z_][a-zA-Z0-9_]*)\}/g;
 class ManifestParser {
-    envVarsRecord;
-    envVarsToReplace;
-    constructor(envVarsRecord = {}) {
-        this.envVarsRecord = envVarsRecord;
-        this.envVarsToReplace = [];
+    manifestInterpolator;
+    constructor(manifestInterpolator) {
+        this.manifestInterpolator = manifestInterpolator;
     }
     parseManifest(manifest) {
-        const rawManifest = (0, yaml_1.parse)(manifest);
-        this.envVarsToReplace = rawManifest.environment?.variables ?? [];
-        return (0, yaml_1.parse)(manifest, this.environmentVariableReviver);
-    }
-    parseManifestAsString = (manifest) => (0, yaml_1.stringify)(this.parseManifest(manifest), yamlConfigOptions);
-    environmentVariableReviver = (_, value) => {
-        if (!(typeof value == 'string')) {
-            return value;
+        try {
+            return this.manifestInterpolator.interpolate(manifest);
         }
-        value = value.replace(POSSIBLE_ENVIRONMENT_VARIABLE, (original, envVarName) => {
-            if (!this.envVarsToReplace.includes(envVarName)) {
-                return original;
+        catch (error) {
+            if (error instanceof manifest_interpolator_1.ManifestInterpolatorError) {
+                throw new ManifestParserError(error.message);
             }
-            const envVar = this.envVarsRecord[envVarName];
-            if (envVar === undefined) {
-                throw new ManifestParserError(errors_1.errors.schema.missingEnvironmentVariable(envVarName));
-            }
-            Sentry.captureMessage('replaced environment variable');
-            return envVar;
-        });
-        return value;
-    };
+            throw error;
+        }
+    }
+    parseManifestAsString = (manifest) => (0, yaml_1.stringify)(this.parseManifest(manifest), yamlConfigOptions);
 }
 exports.ManifestParser = ManifestParser;