cdk-real-drift 0.4.16 → 0.4.17

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/cli.js CHANGED
@@ -836,14 +836,26 @@ function applyIgnores(findings, scope, config) {
836
836
 
837
837
  //#endregion
838
838
  //#region src/synth/resolve-app.ts
839
+ function decodeCdkJson(buf) {
840
+ const encoding = buf[0] === 255 && buf[1] === 254 ? "utf-16le" : buf[0] === 254 && buf[1] === 255 ? "utf-16be" : "utf-8";
841
+ return new TextDecoder(encoding).decode(buf);
842
+ }
839
843
  function resolveApp(explicit) {
840
844
  if (explicit) return explicit;
845
+ if (!existsSync("cdk.json")) return void 0;
846
+ let text;
841
847
  try {
842
- if (existsSync("cdk.json")) {
843
- const json = JSON.parse(readFileSync("cdk.json", "utf8"));
844
- if (typeof json.app === "string" && json.app.length > 0) return json.app;
845
- }
846
- } catch {}
848
+ text = decodeCdkJson(readFileSync("cdk.json"));
849
+ } catch (e) {
850
+ throw new Error(`cdk.json exists but could not be read: ${e.message}`);
851
+ }
852
+ let json;
853
+ try {
854
+ json = JSON.parse(text);
855
+ } catch (e) {
856
+ throw new Error(`cdk.json exists but is not valid JSON (an unsupported encoding or a syntax error?): ${e.message}`);
857
+ }
858
+ return typeof json.app === "string" && json.app.length > 0 ? json.app : void 0;
847
859
  }
848
860
 
849
861
  //#endregion