summaryrefslogtreecommitdiff
path: root/packages/cli/src/utils/package.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/cli/src/utils/package.ts')
-rw-r--r--packages/cli/src/utils/package.ts38
1 files changed, 38 insertions, 0 deletions
diff --git a/packages/cli/src/utils/package.ts b/packages/cli/src/utils/package.ts
new file mode 100644
index 00000000..d53a0234
--- /dev/null
+++ b/packages/cli/src/utils/package.ts
@@ -0,0 +1,38 @@
+/**
+ * @license
+ * Copyright 2025 Google LLC
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+import {
+ readPackageUp,
+ type PackageJson as BasePackageJson,
+} from 'read-package-up';
+import { fileURLToPath } from 'url';
+import path from 'path';
+
+export type PackageJson = BasePackageJson & {
+ config?: {
+ sandboxImageUri?: string;
+ };
+};
+
+const __filename = fileURLToPath(import.meta.url);
+const __dirname = path.dirname(__filename);
+
+let packageJson: PackageJson | undefined;
+
+export async function getPackageJson(): Promise<PackageJson | undefined> {
+ if (packageJson) {
+ return packageJson;
+ }
+
+ const result = await readPackageUp({ cwd: __dirname });
+ if (!result) {
+ // TODO: Maybe bubble this up as an error.
+ return;
+ }
+
+ packageJson = result.packageJson;
+ return packageJson;
+}