@mono-labs/cli 0.0.215 → 0.0.216

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.
@@ -4,19 +4,25 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.loadMergedEnv = exports.loadProjectConfig = void 0;
7
- exports.detectWorkspaceAndConfigPath = detectWorkspaceAndConfigPath;
8
7
  exports.loadAppConfig = loadAppConfig;
9
8
  const node_fs_1 = __importDefault(require("node:fs"));
10
9
  const node_path_1 = __importDefault(require("node:path"));
11
- /**
12
- * Finds the workspace root by walking up from `startDir`.
13
- * Works for Yarn/npm workspaces via package.json "workspaces".
14
- * Also recognizes common mono-repo markers as fallback.
15
- */
16
- function detectWorkspaceAndConfigPath(startDir = process.cwd(), configFileName = 'mono.app.json') {
10
+ const requiredSystemDefaults = {
11
+ ec2User: 'ec2-user',
12
+ regions: ['us-east-1'],
13
+ };
14
+ /* ──────────────────────────────────────────────────────────
15
+ * Environment helpers
16
+ * ────────────────────────────────────────────────────────── */
17
+ function isLambdaRuntime() {
18
+ return !!process.env.AWS_LAMBDA_FUNCTION_NAME;
19
+ }
20
+ /* ──────────────────────────────────────────────────────────
21
+ * Workspace detection (CLI / local dev only)
22
+ * ────────────────────────────────────────────────────────── */
23
+ function detectWorkspaceAndConfigPath(startDir, configFileName) {
17
24
  const cwd = node_path_1.default.resolve(startDir);
18
25
  const isWorkspaceRootDir = (dir) => {
19
- // 1) package.json workspaces
20
26
  const pkgPath = node_path_1.default.join(dir, 'package.json');
21
27
  if (node_fs_1.default.existsSync(pkgPath)) {
22
28
  try {
@@ -28,41 +34,71 @@ function detectWorkspaceAndConfigPath(startDir = process.cwd(), configFileName =
28
34
  // ignore
29
35
  }
30
36
  }
31
- // 2) other common monorepo root markers (fallback)
32
37
  const markers = [
33
38
  'pnpm-workspace.yaml',
34
39
  'lerna.json',
35
40
  'turbo.json',
36
41
  'nx.json',
37
- '.git', // good enough for many repos
42
+ '.git',
38
43
  ];
39
44
  return markers.some((m) => node_fs_1.default.existsSync(node_path_1.default.join(dir, m)));
40
45
  };
41
- const findUp = (from, predicate) => {
42
- let dir = node_path_1.default.resolve(from);
43
- while (true) {
44
- if (predicate(dir))
45
- return dir;
46
- const parent = node_path_1.default.dirname(dir);
47
- if (parent === dir)
48
- return null; // reached filesystem root
49
- dir = parent;
46
+ let dir = cwd;
47
+ while (true) {
48
+ if (isWorkspaceRootDir(dir)) {
49
+ return {
50
+ cwd,
51
+ workspaceRoot: dir,
52
+ isWorkspaceRoot: dir === cwd,
53
+ configDir: dir,
54
+ configPath: node_path_1.default.join(dir, configFileName),
55
+ };
50
56
  }
57
+ const parent = node_path_1.default.dirname(dir);
58
+ if (parent === dir)
59
+ break;
60
+ dir = parent;
61
+ }
62
+ return {
63
+ cwd,
64
+ workspaceRoot: null,
65
+ isWorkspaceRoot: false,
66
+ configDir: cwd,
67
+ configPath: node_path_1.default.join(cwd, configFileName),
51
68
  };
52
- const workspaceRoot = findUp(cwd, isWorkspaceRootDir);
53
- const isWorkspaceRoot = workspaceRoot !== null && workspaceRoot === cwd;
54
- // If we are inside a workspace package, config lives at root.
55
- // If we're already at root, config lives in cwd (same thing).
56
- const configDir = workspaceRoot ?? cwd;
57
- const configPath = node_path_1.default.join(configDir, configFileName);
58
- return { cwd, workspaceRoot, isWorkspaceRoot, configDir, configPath };
59
69
  }
60
- const requiredSystemDefaults = {
61
- ec2User: 'ec2-user',
62
- regions: ['us-east-1'],
63
- };
70
+ /* ──────────────────────────────────────────────────────────
71
+ * Bundled config loader (Lambda runtime)
72
+ * ────────────────────────────────────────────────────────── */
73
+ function loadConfigFromBundle(fileName) {
74
+ const bundledPath = node_path_1.default.join(__dirname, fileName);
75
+ if (node_fs_1.default.existsSync(bundledPath)) {
76
+ return JSON.parse(node_fs_1.default.readFileSync(bundledPath, 'utf8'));
77
+ }
78
+ return null;
79
+ }
80
+ /* ──────────────────────────────────────────────────────────
81
+ * Public API
82
+ * ────────────────────────────────────────────────────────── */
64
83
  function loadAppConfig(configType = 'app', startDir = process.cwd()) {
65
84
  const fileName = `mono.${configType}.json`;
85
+ // ✅ 1. Lambda runtime: load bundled config if present
86
+ if (isLambdaRuntime()) {
87
+ const bundled = loadConfigFromBundle(fileName);
88
+ if (bundled) {
89
+ return {
90
+ config: bundled,
91
+ meta: {
92
+ cwd: __dirname,
93
+ workspaceRoot: null,
94
+ isWorkspaceRoot: false,
95
+ configDir: __dirname,
96
+ configPath: node_path_1.default.join(__dirname, fileName),
97
+ },
98
+ };
99
+ }
100
+ }
101
+ // ✅ 2. CLI / local dev: workspace discovery
66
102
  const meta = detectWorkspaceAndConfigPath(startDir, fileName);
67
103
  if (!node_fs_1.default.existsSync(meta.configPath)) {
68
104
  const where = meta.workspaceRoot ?
@@ -72,7 +108,7 @@ function loadAppConfig(configType = 'app', startDir = process.cwd()) {
72
108
  }
73
109
  const raw = node_fs_1.default.readFileSync(meta.configPath, 'utf8');
74
110
  const config = JSON.parse(raw);
75
- // Apply requiredSystemDefaults for missing/null/undefined values
111
+ // Apply required system defaults
76
112
  if (typeof config === 'object' && config !== null) {
77
113
  for (const key of Object.keys(requiredSystemDefaults)) {
78
114
  // @ts-ignore: index signature
@@ -5,12 +5,6 @@ type WorkspaceDetectResult = {
5
5
  configDir: string;
6
6
  configPath: string;
7
7
  };
8
- /**
9
- * Finds the workspace root by walking up from `startDir`.
10
- * Works for Yarn/npm workspaces via package.json "workspaces".
11
- * Also recognizes common mono-repo markers as fallback.
12
- */
13
- export declare function detectWorkspaceAndConfigPath(startDir?: string, configFileName?: string): WorkspaceDetectResult;
14
8
  type DefaultAppConfig = {
15
9
  appleAppId?: string;
16
10
  androidAppId?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mono-labs/cli",
3
- "version": "0.0.215",
3
+ "version": "0.0.216",
4
4
  "description": "A CLI tool for building and deploying projects",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/types.d.ts",
@@ -1,6 +1,10 @@
1
1
  import fs from 'node:fs';
2
2
  import path from 'node:path';
3
3
 
4
+ /* ──────────────────────────────────────────────────────────
5
+ * Types
6
+ * ────────────────────────────────────────────────────────── */
7
+
4
8
  type WorkspaceDetectResult = {
5
9
  cwd: string;
6
10
  workspaceRoot: string | null;
@@ -9,64 +13,6 @@ type WorkspaceDetectResult = {
9
13
  configPath: string;
10
14
  };
11
15
 
12
- /**
13
- * Finds the workspace root by walking up from `startDir`.
14
- * Works for Yarn/npm workspaces via package.json "workspaces".
15
- * Also recognizes common mono-repo markers as fallback.
16
- */
17
- export function detectWorkspaceAndConfigPath(
18
- startDir: string = process.cwd(),
19
- configFileName: string = 'mono.app.json'
20
- ): WorkspaceDetectResult {
21
- const cwd = path.resolve(startDir);
22
-
23
- const isWorkspaceRootDir = (dir: string): boolean => {
24
- // 1) package.json workspaces
25
- const pkgPath = path.join(dir, 'package.json');
26
- if (fs.existsSync(pkgPath)) {
27
- try {
28
- const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8')) as any;
29
- if (pkg?.workspaces) return true;
30
- } catch {
31
- // ignore
32
- }
33
- }
34
-
35
- // 2) other common monorepo root markers (fallback)
36
- const markers = [
37
- 'pnpm-workspace.yaml',
38
- 'lerna.json',
39
- 'turbo.json',
40
- 'nx.json',
41
- '.git', // good enough for many repos
42
- ];
43
- return markers.some((m) => fs.existsSync(path.join(dir, m)));
44
- };
45
-
46
- const findUp = (
47
- from: string,
48
- predicate: (dir: string) => boolean
49
- ): string | null => {
50
- let dir = path.resolve(from);
51
- while (true) {
52
- if (predicate(dir)) return dir;
53
- const parent = path.dirname(dir);
54
- if (parent === dir) return null; // reached filesystem root
55
- dir = parent;
56
- }
57
- };
58
-
59
- const workspaceRoot = findUp(cwd, isWorkspaceRootDir);
60
- const isWorkspaceRoot = workspaceRoot !== null && workspaceRoot === cwd;
61
-
62
- // If we are inside a workspace package, config lives at root.
63
- // If we're already at root, config lives in cwd (same thing).
64
- const configDir = workspaceRoot ?? cwd;
65
- const configPath = path.join(configDir, configFileName);
66
-
67
- return { cwd, workspaceRoot, isWorkspaceRoot, configDir, configPath };
68
- }
69
-
70
16
  type DefaultAppConfig = {
71
17
  appleAppId?: string;
72
18
  androidAppId?: string;
@@ -103,11 +49,115 @@ type ConfigTypeMap = {
103
49
  type ResolveConfig<TType extends string, TCustom = unknown> =
104
50
  TType extends keyof ConfigTypeMap ? ConfigTypeMap[TType] : TCustom;
105
51
 
52
+ /* ──────────────────────────────────────────────────────────
53
+ * Environment helpers
54
+ * ────────────────────────────────────────────────────────── */
55
+
56
+ function isLambdaRuntime(): boolean {
57
+ return !!process.env.AWS_LAMBDA_FUNCTION_NAME;
58
+ }
59
+
60
+ /* ──────────────────────────────────────────────────────────
61
+ * Workspace detection (CLI / local dev only)
62
+ * ────────────────────────────────────────────────────────── */
63
+
64
+ function detectWorkspaceAndConfigPath(
65
+ startDir: string,
66
+ configFileName: string
67
+ ): WorkspaceDetectResult {
68
+ const cwd = path.resolve(startDir);
69
+
70
+ const isWorkspaceRootDir = (dir: string): boolean => {
71
+ const pkgPath = path.join(dir, 'package.json');
72
+ if (fs.existsSync(pkgPath)) {
73
+ try {
74
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
75
+ if (pkg?.workspaces) return true;
76
+ } catch {
77
+ // ignore
78
+ }
79
+ }
80
+
81
+ const markers = [
82
+ 'pnpm-workspace.yaml',
83
+ 'lerna.json',
84
+ 'turbo.json',
85
+ 'nx.json',
86
+ '.git',
87
+ ];
88
+
89
+ return markers.some((m) => fs.existsSync(path.join(dir, m)));
90
+ };
91
+
92
+ let dir = cwd;
93
+ while (true) {
94
+ if (isWorkspaceRootDir(dir)) {
95
+ return {
96
+ cwd,
97
+ workspaceRoot: dir,
98
+ isWorkspaceRoot: dir === cwd,
99
+ configDir: dir,
100
+ configPath: path.join(dir, configFileName),
101
+ };
102
+ }
103
+
104
+ const parent = path.dirname(dir);
105
+ if (parent === dir) break;
106
+ dir = parent;
107
+ }
108
+
109
+ return {
110
+ cwd,
111
+ workspaceRoot: null,
112
+ isWorkspaceRoot: false,
113
+ configDir: cwd,
114
+ configPath: path.join(cwd, configFileName),
115
+ };
116
+ }
117
+
118
+ /* ──────────────────────────────────────────────────────────
119
+ * Bundled config loader (Lambda runtime)
120
+ * ────────────────────────────────────────────────────────── */
121
+
122
+ function loadConfigFromBundle(fileName: string): unknown | null {
123
+ const bundledPath = path.join(__dirname, fileName);
124
+
125
+ if (fs.existsSync(bundledPath)) {
126
+ return JSON.parse(fs.readFileSync(bundledPath, 'utf8'));
127
+ }
128
+
129
+ return null;
130
+ }
131
+
132
+ /* ──────────────────────────────────────────────────────────
133
+ * Public API
134
+ * ────────────────────────────────────────────────────────── */
135
+
106
136
  export function loadAppConfig<TCustom = unknown, TType extends string = 'app'>(
107
137
  configType: TType = 'app' as TType,
108
138
  startDir: string = process.cwd()
109
139
  ): { config: ResolveConfig<TType, TCustom>; meta: WorkspaceDetectResult } {
110
140
  const fileName = `mono.${configType}.json`;
141
+
142
+ // ✅ 1. Lambda runtime: load bundled config if present
143
+ if (isLambdaRuntime()) {
144
+ const bundled = loadConfigFromBundle(fileName);
145
+
146
+ if (bundled) {
147
+ return {
148
+ config: bundled as ResolveConfig<TType, TCustom>,
149
+ meta: {
150
+ cwd: __dirname,
151
+ workspaceRoot: null,
152
+ isWorkspaceRoot: false,
153
+ configDir: __dirname,
154
+ configPath: path.join(__dirname, fileName),
155
+ },
156
+ };
157
+ }
158
+ }
159
+
160
+ // ✅ 2. CLI / local dev: workspace discovery
111
161
  const meta = detectWorkspaceAndConfigPath(startDir, fileName);
112
162
 
113
163
  if (!fs.existsSync(meta.configPath)) {
@@ -115,6 +165,7 @@ export function loadAppConfig<TCustom = unknown, TType extends string = 'app'>(
115
165
  meta.workspaceRoot ?
116
166
  `workspace root: ${meta.workspaceRoot}`
117
167
  : `cwd: ${meta.cwd}`;
168
+
118
169
  throw new Error(
119
170
  `Could not find ${fileName} at ${meta.configPath} (detected from ${where}).`
120
171
  );
@@ -123,7 +174,7 @@ export function loadAppConfig<TCustom = unknown, TType extends string = 'app'>(
123
174
  const raw = fs.readFileSync(meta.configPath, 'utf8');
124
175
  const config = JSON.parse(raw) as ResolveConfig<TType, TCustom>;
125
176
 
126
- // Apply requiredSystemDefaults for missing/null/undefined values
177
+ // Apply required system defaults
127
178
  if (typeof config === 'object' && config !== null) {
128
179
  for (const key of Object.keys(requiredSystemDefaults)) {
129
180
  // @ts-ignore: index signature