@shivaedev/create-app 0.36.0 → 0.38.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.
Files changed (69) hide show
  1. package/CHANGELOG.md +57 -0
  2. package/README.md +23 -0
  3. package/dist/addResource.d.ts +4 -0
  4. package/dist/addResource.d.ts.map +1 -0
  5. package/dist/addResource.js +45 -0
  6. package/dist/addResource.js.map +1 -0
  7. package/dist/cli.js +316 -78
  8. package/dist/packTemplate.js +2 -2
  9. package/dist/packTemplate.js.map +1 -1
  10. package/dist/resource/contract.d.ts +3 -0
  11. package/dist/resource/contract.d.ts.map +1 -0
  12. package/dist/resource/contract.js +37 -0
  13. package/dist/resource/contract.js.map +1 -0
  14. package/dist/resource/files.d.ts +5 -0
  15. package/dist/resource/files.d.ts.map +1 -0
  16. package/dist/resource/files.js +18 -0
  17. package/dist/resource/files.js.map +1 -0
  18. package/dist/resource/kit.d.ts +4 -0
  19. package/dist/resource/kit.d.ts.map +1 -0
  20. package/dist/resource/kit.js +107 -0
  21. package/dist/resource/kit.js.map +1 -0
  22. package/dist/resource/names.d.ts +10 -0
  23. package/dist/resource/names.d.ts.map +1 -0
  24. package/dist/resource/names.js +11 -0
  25. package/dist/resource/names.js.map +1 -0
  26. package/dist/resource/persistence.d.ts +5 -0
  27. package/dist/resource/persistence.d.ts.map +1 -0
  28. package/dist/resource/persistence.js +64 -0
  29. package/dist/resource/persistence.js.map +1 -0
  30. package/dist/resource/registration.d.ts +4 -0
  31. package/dist/resource/registration.d.ts.map +1 -0
  32. package/dist/resource/registration.js +46 -0
  33. package/dist/resource/registration.js.map +1 -0
  34. package/dist/runProcess.d.ts +3 -3
  35. package/dist/runProcess.d.ts.map +1 -1
  36. package/dist/runProcess.js +6 -5
  37. package/dist/runProcess.js.map +1 -1
  38. package/dist/starterPatch.d.ts +4 -0
  39. package/dist/starterPatch.d.ts.map +1 -1
  40. package/dist/starterPatch.js +17 -5
  41. package/dist/starterPatch.js.map +1 -1
  42. package/dist/template.d.ts +2 -0
  43. package/dist/template.d.ts.map +1 -1
  44. package/dist/template.js +14 -3
  45. package/dist/template.js.map +1 -1
  46. package/dist/updateApp.d.ts +1 -1
  47. package/dist/updateApp.d.ts.map +1 -1
  48. package/dist/updateApp.js +23 -15
  49. package/dist/updateApp.js.map +1 -1
  50. package/dist/updateChecks.d.ts +1 -1
  51. package/dist/updateChecks.d.ts.map +1 -1
  52. package/dist/updateChecks.js +6 -3
  53. package/dist/updateChecks.js.map +1 -1
  54. package/package.json +4 -4
  55. package/src/addResource.ts +45 -0
  56. package/src/cli.ts +9 -2
  57. package/src/packTemplate.ts +2 -2
  58. package/src/resource/contract.ts +38 -0
  59. package/src/resource/files.ts +19 -0
  60. package/src/resource/kit.ts +109 -0
  61. package/src/resource/names.ts +13 -0
  62. package/src/resource/persistence.ts +67 -0
  63. package/src/resource/registration.ts +48 -0
  64. package/src/runProcess.ts +11 -5
  65. package/src/starterPatch.ts +18 -6
  66. package/src/template.ts +18 -3
  67. package/src/updateApp.ts +29 -15
  68. package/src/updateChecks.ts +6 -3
  69. package/template.json +1 -1
@@ -1,8 +1,8 @@
1
1
  import { join } from "node:path";
2
2
  import { Effect, FileSystem } from "effect";
3
- import { renderTemplate } from "./generation.ts";
4
- import { checkedProcess } from "./runProcess.ts";
5
- import type { Template } from "./template.ts";
3
+ import { renderTemplate } from "#generation.ts";
4
+ import { checkedProcess } from "#runProcess.ts";
5
+ import type { Template } from "#template.ts";
6
6
 
7
7
  export const starterPatch = Effect.fn("CreateApp.starterPatch")(function* (
8
8
  target: string,
@@ -26,18 +26,30 @@ export const starterPatch = Effect.fn("CreateApp.starterPatch")(function* (
26
26
  yield* renderTemplate(repository, base, name);
27
27
  yield* checkedProcess(repository, "git", ["add", "--all"]);
28
28
  const tree = (yield* checkedProcess(repository, "git", ["write-tree"])).trim();
29
+ const conflicts: { path: string; indexInfo: string }[] = [];
30
+ const retained: Template[number][] = [];
29
31
  for (const entry of base) {
30
- yield* checkedProcess(target, "git", ["hash-object", "-w", "--", join(repository, entry.path)]);
32
+ const hash = (yield* checkedProcess(target, "git", ["hash-object", "-w", "--", join(repository, entry.path)])).trim();
33
+ if (!incoming.some((file) => file.path === entry.path)) {
34
+ const ours = yield* checkedProcess(target, "git", ["--literal-pathspecs", "ls-files", "--stage", "--full-name", "-z", "--", entry.path]);
35
+ if (!ours.startsWith(`100644 ${hash} 0\t`)) {
36
+ const indexedPath = ours.slice(ours.indexOf("\t") + 1, -1);
37
+ const indexInfo = [`0 ${hash}\t${indexedPath}\0`, `100644 ${hash} 1\t${indexedPath}\0`, ours.replace(" 0\t", " 2\t")].join("");
38
+ conflicts.push({ indexInfo, path: entry.path });
39
+ // Git apply rejects these deletions before applying any of the delta.
40
+ retained.push(entry);
41
+ }
42
+ }
31
43
  }
32
44
  for (const path of yield* fs.readDirectory(repository)) {
33
45
  if (path !== ".git") {
34
46
  yield* fs.remove(join(repository, path), { recursive: true });
35
47
  }
36
48
  }
37
- yield* renderTemplate(repository, incoming, name);
49
+ yield* renderTemplate(repository, [...incoming, ...retained], name);
38
50
  yield* checkedProcess(repository, "git", ["add", "--all"]);
39
51
  const patch = yield* checkedProcess(repository, "git", ["diff", "--cached", "--binary", "--full-index", "--no-renames", tree]);
40
52
  const path = join(directory, "starter.patch");
41
53
  yield* fs.writeFileString(path, patch);
42
- return { empty: patch.length === 0, path };
54
+ return { conflicts, empty: patch.length === 0, path };
43
55
  });
package/src/template.ts CHANGED
@@ -14,12 +14,21 @@ export function appTemplate(template: Template, minimal = false): Template {
14
14
  return files;
15
15
  }
16
16
  return files
17
- .filter((entry) => !entry.path.startsWith("src/modules/notes/"))
17
+ .filter((entry) => !(entry.path.startsWith("src/modules/notes/") || entry.path.startsWith("tooling/notes/")))
18
18
  .map((entry) => {
19
19
  if (entry.path === "package.json" && minimalManifest !== undefined) {
20
20
  return { ...entry, content: minimalManifest.content };
21
21
  }
22
- if (!["src/admin/modules.ts", "src/server/modules.ts", "src/server/workerModules.ts", "src/client/modules.ts"].includes(entry.path)) {
22
+ // Updates must reconstruct historical minimal files exactly to recognize unmodified deletions.
23
+ if (
24
+ ![
25
+ "src/admin/foundation.ts",
26
+ "src/admin/modules.ts",
27
+ "src/server/modules.ts",
28
+ "src/server/workerModules.ts",
29
+ "src/client/modules.ts",
30
+ ].includes(entry.path)
31
+ ) {
23
32
  return entry;
24
33
  }
25
34
  const source = Buffer.from(entry.content, "base64")
@@ -39,6 +48,7 @@ const Manifest = Schema.Struct({
39
48
  packageManager: Schema.String,
40
49
  private: Schema.Boolean,
41
50
  scripts: Versions,
51
+ shivaedevSkills: Schema.optional(Schema.Array(Schema.String)),
42
52
  type: Schema.String,
43
53
  version: Schema.String,
44
54
  });
@@ -55,6 +65,7 @@ const manifestOrder = [
55
65
  "devDependencies",
56
66
  "packageManager",
57
67
  "engines",
68
+ "shivaedevSkills",
58
69
  ] as const satisfies ReadonlyArray<keyof typeof Manifest.Type>;
59
70
 
60
71
  export function manifestJson(manifest: typeof Manifest.Type) {
@@ -86,7 +97,11 @@ export function prepareManifest(source: string, versions: Readonly<Record<string
86
97
  versions,
87
98
  ),
88
99
  devDependencies: registryDependencies(manifest.devDependencies, versions),
89
- scripts: Object.fromEntries(Object.entries(scripts).map(([name, script]) => [name, script.replaceAll("--conditions=source ", "")])),
100
+ scripts: Object.fromEntries(
101
+ Object.entries(scripts)
102
+ .filter(([name]) => !minimal || name !== "browser-check:live-notes")
103
+ .map(([name, script]) => [name, script.replaceAll("--conditions=source ", "")]),
104
+ ),
90
105
  };
91
106
  return manifestJson(prepared);
92
107
  }
package/src/updateApp.ts CHANGED
@@ -1,22 +1,31 @@
1
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
10
 
11
- const applyPatch = Effect.fn("CreateApp.applyPatch")(function* (target: string, repository: string, path: string) {
11
+ const applyPatch = Effect.fn("CreateApp.applyPatch")(function* (
12
+ target: string,
13
+ repository: string,
14
+ patch: Effect.Success<ReturnType<typeof starterPatch>>,
15
+ ) {
12
16
  const prefix = relative(repository, target);
13
- const result = yield* runProcess(repository, "git", ["apply", "--3way", ...(prefix ? [`--directory=${prefix}`] : []), path]);
14
- if (result.code !== 0) {
15
- const conflicts = (yield* checkedProcess(target, "git", ["diff", "--name-only", "--diff-filter=U", "--", "."])).trim();
16
- if (!conflicts) {
17
- return yield* new CreateAppError({ message: result.stderr.trim() });
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
+ }
18
24
  }
19
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
+ }
20
29
  if ((yield* checkedProcess(target, "git", ["diff", "--cached", "--name-only", "--", "."])).trim() === "") {
21
30
  return yield* new CreateAppError({ message: "The starter delta applied no changes. The generation record is unchanged." });
22
31
  }
@@ -44,11 +53,16 @@ export const updateApp = Effect.fn("CreateApp.updateApp")(function* (folder: str
44
53
  appTemplate(previous, generation.minimal),
45
54
  appTemplate(current, generation.minimal),
46
55
  );
47
- if (!patch.empty) {
48
- yield* applyPatch(target, repository, patch.path);
56
+ if (!patch.empty || patch.conflicts.length > 0) {
57
+ yield* applyPatch(target, repository, patch);
49
58
  }
50
59
  yield* writeGeneration(target, { ...generation, version });
51
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
+ }
52
66
  if (failures.length > 0) {
53
67
  return yield* new CreateAppError({
54
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) {