@shivaedev/create-app 0.35.0 → 0.37.0

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/src/updateApp.ts CHANGED
@@ -1,20 +1,43 @@
1
- import { join, resolve } from "node:path";
1
+ import { join, relative, resolve } from "node:path";
2
2
  import { Console, Effect, FileSystem, Schema } from "effect";
3
- import { CreateAppError } from "./CreateAppError.ts";
4
- import { GENERATION_FILE, Generation, readTemplate, writeGeneration } from "./generation.ts";
5
- import { historicalTemplate } from "./historicalTemplate.ts";
6
- import { checkedProcess, runProcess } from "./runProcess.ts";
7
- import { starterPatch } from "./starterPatch.ts";
8
- import { appTemplate } from "./template.ts";
9
- import { updateChecks } from "./updateChecks.ts";
3
+ import { CreateAppError } from "#CreateAppError.ts";
4
+ import { GENERATION_FILE, Generation, readTemplate, writeGeneration } from "#generation.ts";
5
+ import { historicalTemplate } from "#historicalTemplate.ts";
6
+ import { checkedProcess, runProcess } from "#runProcess.ts";
7
+ import { starterPatch } from "#starterPatch.ts";
8
+ import { appTemplate } from "#template.ts";
9
+ import { updateChecks } from "#updateChecks.ts";
10
+
11
+ const applyPatch = Effect.fn("CreateApp.applyPatch")(function* (
12
+ target: string,
13
+ repository: string,
14
+ patch: Effect.Success<ReturnType<typeof starterPatch>>,
15
+ ) {
16
+ const prefix = relative(repository, target);
17
+ if (!patch.empty) {
18
+ const result = yield* runProcess(repository, "git", ["apply", "--3way", ...(prefix ? [`--directory=${prefix}`] : []), patch.path]);
19
+ if (result.code !== 0) {
20
+ const conflicts = (yield* checkedProcess(target, "git", ["diff", "--name-only", "--diff-filter=U", "--", "."])).trim();
21
+ if (!conflicts) {
22
+ return yield* new CreateAppError({ message: result.stderr.trim() });
23
+ }
24
+ }
25
+ }
26
+ if (patch.conflicts.length > 0) {
27
+ yield* checkedProcess(repository, "git", ["update-index", "-z", "--index-info"], patch.conflicts.map((conflict) => conflict.indexInfo).join(""));
28
+ }
29
+ if ((yield* checkedProcess(target, "git", ["diff", "--cached", "--name-only", "--", "."])).trim() === "") {
30
+ return yield* new CreateAppError({ message: "The starter delta applied no changes. The generation record is unchanged." });
31
+ }
32
+ });
10
33
 
11
34
  export const updateApp = Effect.fn("CreateApp.updateApp")(function* (folder: string, templatePath: string, version: string) {
12
35
  return yield* Effect.scoped(
13
36
  Effect.gen(function* () {
14
37
  const fs = yield* FileSystem.FileSystem;
15
38
  const target = resolve(folder);
16
- yield* checkedProcess(target, "git", ["rev-parse", "--show-toplevel"]);
17
- if ((yield* checkedProcess(target, "git", ["status", "--porcelain"])).trim() !== "") {
39
+ const repository = (yield* checkedProcess(target, "git", ["rev-parse", "--show-toplevel"])).trim();
40
+ if ((yield* checkedProcess(target, "git", ["status", "--porcelain", "--", "."])).trim() !== "") {
18
41
  return yield* new CreateAppError({ message: "Refusing to update a dirty working tree. Commit or stash your changes first." });
19
42
  }
20
43
  const generation = yield* Schema.decodeUnknownEffect(Schema.fromJsonString(Generation))(
@@ -30,17 +53,16 @@ export const updateApp = Effect.fn("CreateApp.updateApp")(function* (folder: str
30
53
  appTemplate(previous, generation.minimal),
31
54
  appTemplate(current, generation.minimal),
32
55
  );
33
- if (!patch.empty) {
34
- const result = yield* runProcess(target, "git", ["apply", "--3way", patch.path]);
35
- if (result.code !== 0) {
36
- const conflicts = (yield* checkedProcess(target, "git", ["diff", "--name-only", "--diff-filter=U"])).trim();
37
- if (!conflicts) {
38
- return yield* new CreateAppError({ message: result.stderr.trim() });
39
- }
40
- }
56
+ if (!patch.empty || patch.conflicts.length > 0) {
57
+ yield* applyPatch(target, repository, patch);
41
58
  }
42
59
  yield* writeGeneration(target, { ...generation, version });
43
60
  const failures = yield* updateChecks(target);
61
+ if (patch.conflicts.length > 0) {
62
+ failures.push(
63
+ `Starter deletions conflict with app changes:\n${patch.conflicts.map((conflict) => conflict.path).join("\n")}\nKeep a file with git add -- <path>, or accept its deletion with git rm -- <path>.`,
64
+ );
65
+ }
44
66
  if (failures.length > 0) {
45
67
  return yield* new CreateAppError({
46
68
  message: `Recorded create-app ${version}. Finish the update before committing:\n${failures.join("\n\n")}`,
@@ -1,6 +1,6 @@
1
1
  import { Console, Effect } from "effect";
2
- import { CreateAppError } from "./CreateAppError.ts";
3
- import { checkedProcess, runProcess } from "./runProcess.ts";
2
+ import { CreateAppError } from "#CreateAppError.ts";
3
+ import { checkedProcess, runProcess } from "#runProcess.ts";
4
4
 
5
5
  const conflictMarkers = Effect.fn("CreateApp.conflictMarkers")(function* (target: string) {
6
6
  const result = yield* runProcess(target, "git", [
@@ -23,7 +23,10 @@ const conflictMarkers = Effect.fn("CreateApp.conflictMarkers")(function* (target
23
23
 
24
24
  export const updateChecks = Effect.fn("CreateApp.updateChecks")(function* (target: string) {
25
25
  const failures: string[] = [];
26
- for (const args of [["install"], ["run", "typecheck"]]) {
26
+ for (const args of [
27
+ ["install", "--no-frozen-lockfile"],
28
+ ["run", "typecheck"],
29
+ ]) {
27
30
  yield* Console.log(`Running pnpm ${args.join(" ")}...`);
28
31
  const result = yield* runProcess(target, "pnpm", args);
29
32
  if (result.code !== 0) {
@@ -39,7 +42,7 @@ export const updateChecks = Effect.fn("CreateApp.updateChecks")(function* (targe
39
42
  if (markers.length > 0) {
40
43
  failures.unshift(`Files with conflict markers:\n${markers.join("\n")}`);
41
44
  }
42
- const unresolved = (yield* checkedProcess(target, "git", ["diff", "--name-only", "--diff-filter=U"])).trim();
45
+ const unresolved = (yield* checkedProcess(target, "git", ["diff", "--name-only", "--diff-filter=U", "--", "."])).trim();
43
46
  if (unresolved !== "") {
44
47
  failures.push(`Unresolved Git conflicts:\n${unresolved}`);
45
48
  }