@arcote.tech/arc-cli 0.3.1 → 0.4.1

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.
@@ -1,5 +1,5 @@
1
1
  import { spawn } from "child_process";
2
- import { existsSync, readFileSync } from "fs";
2
+ import { existsSync, mkdirSync, readFileSync, unlinkSync, writeFileSync } from "fs";
3
3
  import { dirname, join } from "path";
4
4
  import type { ArcConfig, ContextInfo } from "./config";
5
5
  import { generateClientTypes } from "./config";
@@ -134,13 +134,57 @@ export async function buildContextBundle(
134
134
  });
135
135
  }
136
136
 
137
- interface DeclarationResult {
137
+ export interface DeclarationResult {
138
138
  success: boolean;
139
139
  errors: string[];
140
140
  }
141
141
 
142
+ // ---------------------------------------------------------------------------
143
+ // Core declaration builder — reusable by both old arc.config flow and platform
144
+ // ---------------------------------------------------------------------------
145
+
146
+ /**
147
+ * Build type declarations using tsgo (with tsc fallback).
148
+ *
149
+ * @param files Entry .ts/.tsx files to generate declarations for
150
+ * @param outDir Output directory for .d.ts files
151
+ * @param rootDir Root directory for TypeScript (controls output structure)
152
+ * @param globalsContent Optional ambient declarations (ONLY_SERVER etc.) —
153
+ * written to a temp .d.ts and included in compilation.
154
+ */
155
+ export async function buildTypeDeclarations(
156
+ files: string[],
157
+ outDir: string,
158
+ rootDir: string,
159
+ globalsContent?: string,
160
+ ): Promise<DeclarationResult> {
161
+ const allFiles = [...files];
162
+
163
+ // Write temp globals .d.ts OUTSIDE source dir to avoid triggering file watchers
164
+ let globalsPath: string | null = null;
165
+ if (globalsContent) {
166
+ const tmpDir = join(outDir, "_build-types");
167
+ mkdirSync(tmpDir, { recursive: true });
168
+ globalsPath = join(tmpDir, "globals.d.ts");
169
+ writeFileSync(globalsPath, globalsContent);
170
+ allFiles.push(globalsPath);
171
+ }
172
+
173
+ let result = await runTsgo(allFiles, outDir, rootDir);
174
+ if (result === null) {
175
+ result = await runTsc(allFiles, outDir, rootDir);
176
+ }
177
+
178
+ // Clean up temp globals
179
+ if (globalsPath && existsSync(globalsPath)) {
180
+ unlinkSync(globalsPath);
181
+ }
182
+
183
+ return result;
184
+ }
185
+
142
186
  /**
143
- * Build declarations.
187
+ * Build declarations (old arc.config flow).
144
188
  * Output: dist/{client}/{context}/ (matches JS output and TypeScript's natural output)
145
189
  */
146
190
  export async function buildContextDeclarations(
@@ -152,7 +196,6 @@ export async function buildContextDeclarations(
152
196
  const configDir = dirname(configPath);
153
197
  generateClientTypes(config, configDir, client);
154
198
 
155
- // Output to dist/{client}/ - TypeScript will add {context}/ based on source structure
156
199
  const outDir = join(configDir, config.outDir, client.toLowerCase());
157
200
 
158
201
  // Include arc.d.ts for global constants
@@ -161,7 +204,6 @@ export async function buildContextDeclarations(
161
204
  ? [context.fullPath, arcTypesPath]
162
205
  : [context.fullPath];
163
206
 
164
- // Try tsgo, fallback to tsc - use configDir as rootDir
165
207
  let result = await runTsgo(files, outDir, configDir);
166
208
  if (result === null) {
167
209
  result = await runTsc(files, outDir, configDir);
@@ -169,13 +211,17 @@ export async function buildContextDeclarations(
169
211
  return result;
170
212
  }
171
213
 
214
+ // ---------------------------------------------------------------------------
215
+ // tsgo / tsc runners
216
+ // ---------------------------------------------------------------------------
217
+
172
218
  async function runTsgo(
173
219
  files: string[],
174
220
  outDir: string,
175
221
  cwd: string,
176
222
  ): Promise<DeclarationResult | null> {
177
223
  const fileArgs = files.map((f) => `"${f}"`).join(" ");
178
- const command = `npx tsgo ${fileArgs} --declaration --emitDeclarationOnly --outDir "${outDir}" --rootDir "${cwd}" --skipLibCheck --moduleResolution bundler --module esnext --target esnext --ignoreConfig`;
224
+ const command = `npx tsgo ${fileArgs} --declaration --emitDeclarationOnly --outDir "${outDir}" --rootDir "${cwd}" --skipLibCheck --moduleResolution bundler --module esnext --target esnext --jsx react-jsx --ignoreConfig`;
179
225
 
180
226
  return new Promise((resolve) => {
181
227
  const proc = spawn(command, { shell: true, cwd });
@@ -209,7 +255,7 @@ async function runTsc(
209
255
  cwd: string,
210
256
  ): Promise<DeclarationResult> {
211
257
  const fileArgs = files.map((f) => `"${f}"`).join(" ");
212
- const command = `npx tsc ${fileArgs} --declaration --emitDeclarationOnly --outDir "${outDir}" --rootDir "${cwd}" --skipLibCheck --moduleResolution bundler --module esnext --target esnext`;
258
+ const command = `npx tsc ${fileArgs} --declaration --emitDeclarationOnly --outDir "${outDir}" --rootDir "${cwd}" --skipLibCheck --moduleResolution bundler --module esnext --target esnext --jsx react-jsx`;
213
259
 
214
260
  return new Promise((resolve) => {
215
261
  const proc = spawn(command, { shell: true, cwd });