@farm.js/create-app 0.1.16 → 0.1.18

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/index.js CHANGED
@@ -2187,8 +2187,8 @@ better-auth.sqlite-wal
2187
2187
  }
2188
2188
  ],
2189
2189
  ui: betterAuthUIFeature(),
2190
- template: () => `import { betterAuth } from "@farm.js/better-auth";
2191
- import { auth } from "../auth.ts";
2190
+ template: ({ importFrom }) => `import { betterAuth } from "@farm.js/better-auth";
2191
+ import { auth } from "${importFrom("src/lib/auth.ts")}";
2192
2192
 
2193
2193
  export const betterAuthIntegration = betterAuth({
2194
2194
  instance: auth,
@@ -2244,8 +2244,8 @@ export const auth = {
2244
2244
  }],
2245
2245
  notes: ["The generated Auth.js instance uses GitHub OAuth through @auth/core; add or replace providers in src/lib/auth.ts."],
2246
2246
  ui: authjsUIFeature(),
2247
- template: () => `import { authjs } from "@farm.js/authjs";
2248
- import { auth } from "../auth.ts";
2247
+ template: ({ importFrom }) => `import { authjs } from "@farm.js/authjs";
2248
+ import { auth } from "${importFrom("src/lib/auth.ts")}";
2249
2249
 
2250
2250
  export const authjsIntegration = authjs({
2251
2251
  instance: auth,
@@ -2363,6 +2363,7 @@ export const strapiIntegration = strapi({
2363
2363
  async function addFarmIntegration(options) {
2364
2364
  const root = node_path.default.resolve(options.root || process.cwd());
2365
2365
  const definition = resolveProvider(options.provider);
2366
+ if (!options.skipPackageJson) await assertReadablePackageJson(root);
2366
2367
  if (definition.provider === "ai") return addAIRouteIntegration({
2367
2368
  root,
2368
2369
  definition,
@@ -2389,6 +2390,7 @@ async function addFarmIntegration(options) {
2389
2390
  notes: [...definition.notes || []]
2390
2391
  };
2391
2392
  await writeIntegrationComponent({
2393
+ root,
2392
2394
  path: integrationFile,
2393
2395
  definition,
2394
2396
  force: options.force,
@@ -2450,6 +2452,7 @@ async function addAIRouteIntegration(input) {
2450
2452
  notes: [...input.definition.notes || []]
2451
2453
  };
2452
2454
  await writeIntegrationComponent({
2455
+ root: input.root,
2453
2456
  path: routeFile,
2454
2457
  definition: input.definition,
2455
2458
  force: input.force,
@@ -2493,7 +2496,8 @@ async function writeIntegrationComponent(input) {
2493
2496
  }
2494
2497
  if (!input.dryRun) {
2495
2498
  await (0, node_fs_promises.mkdir)(node_path.default.dirname(input.path), { recursive: true });
2496
- await (0, node_fs_promises.writeFile)(input.path, input.definition.template(), "utf8");
2499
+ const importFrom = (rootRelativePath) => toImportPath(node_path.default.relative(node_path.default.dirname(input.path), node_path.default.join(input.root, rootRelativePath)));
2500
+ await (0, node_fs_promises.writeFile)(input.path, input.definition.template({ importFrom }), "utf8");
2497
2501
  }
2498
2502
  if (exists) input.result.updated.push(input.path);
2499
2503
  else input.result.created.push(input.path);
@@ -2572,14 +2576,29 @@ async function writeIntegrationSetupFiles(input) {
2572
2576
  input.result[exists ? "updated" : "created"].push(absolutePath);
2573
2577
  }
2574
2578
  }
2579
+ async function readPackageManifest(packageJsonPath) {
2580
+ const source = await (0, node_fs_promises.readFile)(packageJsonPath, "utf8");
2581
+ try {
2582
+ return {
2583
+ source,
2584
+ manifest: JSON.parse(source)
2585
+ };
2586
+ } catch (error) {
2587
+ throw new Error(`Could not parse ${packageJsonPath}: ${error instanceof Error ? error.message : error}. Fix it, or pass --skip-package-json.`);
2588
+ }
2589
+ }
2590
+ /** Fails before any file is written, so a broken package.json leaves the app untouched. */
2591
+ async function assertReadablePackageJson(root) {
2592
+ const packageJsonPath = node_path.default.join(root, "package.json");
2593
+ if ((0, node_fs.existsSync)(packageJsonPath)) await readPackageManifest(packageJsonPath);
2594
+ }
2575
2595
  async function updatePackageJson$1(input) {
2576
2596
  const packageJsonPath = node_path.default.join(input.root, "package.json");
2577
2597
  if (!(0, node_fs.existsSync)(packageJsonPath)) {
2578
2598
  input.result.skipped.push(packageJsonPath);
2579
2599
  return;
2580
2600
  }
2581
- const source = await (0, node_fs_promises.readFile)(packageJsonPath, "utf8");
2582
- const manifest = JSON.parse(source);
2601
+ const { source, manifest } = await readPackageManifest(packageJsonPath);
2583
2602
  const dependencies = missingDependencies(manifest, input.definition.dependencies);
2584
2603
  const devDependencies = missingDependencies(manifest, input.definition.devDependencies);
2585
2604
  manifest.dependencies = {