@pipelex/create-method-app 0.5.3 → 0.5.4

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/README.md CHANGED
@@ -46,10 +46,13 @@ The initializer reads git before it writes anything:
46
46
  | A repository with no commit yet (a `git init` by hand, or a clone of an empty GitHub repository) | The pristine commit, as its first |
47
47
  | A repository with no commit whose index already holds a file, added and then deleted | Refused: the commit would record that file beside the template |
48
48
  | A repository with commits, holding only `.git` | Refused: every tracked file would show as deleted, and the commit would record that |
49
+ | Inside another repository's work tree, at a path it ignores | A new repository on `main`, then the pristine commit: that repository does not see the project |
49
50
  | Inside another repository's work tree | No repository and no commit: the project is new files in that repository. `--no-create` lets you commit the template there first |
50
51
  | Inside a checkout of `pipelex-method-apps` or of a starter | Refused, `--no-git` included whenever git is on the PATH |
51
52
 
52
- A commit needs a git identity, and a missing one is refused before anything is written. When git shows none outside a repository, the initializer asks again inside a throwaway repository at the destination, which it removes before going on, so an identity given only by an `includeIf "gitdir:…"` section is found.
53
+ A path the enclosing repository ignores, such as a `tmp/` its `.gitignore` lists or anywhere under a home directory kept as a repository that ignores `*`, is one it does not version, so a project there gets a repository of its own rather than no version control at all. Every source git reads counts: the enclosing repository's `.gitignore` files, its `.git/info/exclude`, and your `core.excludesFile`. What counts is the directory itself, which a missing destination is made for a moment to let git read: a directory the enclosing repository does not ignore gets no repository even when every file in it is ignored, as under `*` followed by `!*/`, since a repository there would still show in the enclosing one's `git status`, and the `git:` line then says the project is under no version control. A destination that is a symlink is read where it points: the repository whose work tree holds its target is the one whose ignores count.
54
+
55
+ A commit needs a git identity, and a missing one is refused before anything is written. When git shows none outside a repository, the initializer asks again inside a throwaway repository at the destination, which it removes before going on, so an identity given only by an `includeIf "gitdir:…"` section is found. At a path another repository ignores, it always asks inside that throwaway repository, since an identity set in the enclosing repository's own configuration does not reach the new one.
53
56
 
54
57
  The pristine commit reads `Start from Pipelex/pipelex-method-apps/webapp-js <version> (<sha>)`, so `make create`'s changes are a diff you can read before committing them. `make create` itself commits nothing.
55
58
 
package/lib/git.mjs CHANGED
@@ -5,6 +5,7 @@
5
5
  * the root of a repository with no commit → the pristine commit, its first
6
6
  * … whose index already holds an entry → refused: repository-has-staged-files
7
7
  * the root of a repository with history → refused: repository-has-history
8
+ * where another repository ignores it → a new repository on main, then the pristine commit
8
9
  * inside another repository's work tree → no repository and no commit
9
10
  * inside a checkout of a template → refused: inside-template-checkout
10
11
  *
@@ -16,7 +17,15 @@
16
17
  * inside another one's work tree makes the enclosing one fail `git add -A`
17
18
  * until the nested one has a commit, and then see an embedded repository, so
18
19
  * the project becomes new files in the enclosing repository instead, as
19
- * `create-next-app` does.
20
+ * `create-next-app` does. A path the enclosing repository ignores is the
21
+ * exception: a repository nested there is as invisible to it as plain files
22
+ * would be, and without one the project would be under no version control at
23
+ * all, so it gets a repository of its own, as outside every work tree. What
24
+ * counts is the directory: one the enclosing repository does not ignore gets
25
+ * no repository even when every file in it is ignored, as under a `*` that a
26
+ * later pattern lifts from every directory, since a repository there would
27
+ * still show in the enclosing one's status, and the report then says the
28
+ * project is under no version control.
20
29
  */
21
30
 
22
31
  import { spawnSync } from "node:child_process";
@@ -66,6 +75,7 @@ export function git(args, { cwd, env }) {
66
75
  * { kind: "outside" }
67
76
  * { kind: "template-checkout", origin }
68
77
  * { kind: "root", history: boolean, staged: string[] } `staged` is read only when there is no history
78
+ * { kind: "ignored", toplevel } the repository whose work tree it is in ignores it
69
79
  * { kind: "inside", toplevel }
70
80
  * { kind: "unreadable-git" } the destination holds a `.git` git does not read as its repository
71
81
  */
@@ -88,61 +98,87 @@ export function readGit({ dest, from, destExists, destHasGit, env }) {
88
98
  }
89
99
  if (destHasGit) return { kind: "unreadable-git" };
90
100
  }
101
+ if (ignores({ dest, from, env })) return { kind: "ignored", toplevel: top.stdout };
91
102
  return { kind: "inside", toplevel: top.stdout };
92
103
  }
93
104
 
94
- /** The `origin` of the repository `from` stands in when it is a template's own, or null. */
95
- export function templateOrigin({ from, env }) {
96
- const origin = git(["remote", "get-url", "origin"], { cwd: from, env });
97
- return origin.status === 0 && TEMPLATE_ORIGINS.test(origin.stdout) ? origin.stdout : null;
105
+ /**
106
+ * Whether the repository `from` stands in ignores `dest` as a directory, by
107
+ * every source git reads: its `.gitignore` files, its `info/exclude` and the
108
+ * user's `core.excludesFile`. That is exactly when a repository nested there is
109
+ * invisible to it.
110
+ *
111
+ * Git reads a path as a directory only when one stands there, so a missing
112
+ * destination is made for the question and removed after it. A trailing slash
113
+ * is no substitute: it makes git test an empty last name as well, which `*` and
114
+ * `my-app/*` match, so a `*` that a later pattern lifts from every directory
115
+ * would read a directory it re-includes as ignored. For the same reason the
116
+ * directory is named from its parent, with no slash, since asked from inside
117
+ * it as `./` git tests it with one. The name starts with `./` because git
118
+ * reads a leading `:` as pathspec magic, and `--literal-pathspecs` is refused
119
+ * by `check-ignore`. The directory is named where it physically is: a
120
+ * destination that is a symlink sits in one repository's work tree and points
121
+ * into another's, the one every other reading of the destination sees, and
122
+ * that one is the repository whose ignores count. Any answer but a plain yes, a
123
+ * directory that cannot be made or resolved included, reads as not ignored,
124
+ * since mistaking a tracked destination for an ignored one would plant a
125
+ * repository in the user's tracked tree. A directory that holds a tracked path
126
+ * reads as not ignored whatever the patterns say, whether or not its files are
127
+ * still on disk.
128
+ */
129
+ function ignores({ dest, from, env }) {
130
+ return withDirectories({ dest, from }, false, () => {
131
+ const real = fs.realpathSync(dest);
132
+ const name = `./${path.basename(real)}`;
133
+ return git(["check-ignore", "-q", "--", name], { cwd: path.dirname(real), env }).status === 0;
134
+ });
98
135
  }
99
136
 
100
- /** Whether git can name an author and a committer, as a commit needs. */
101
- export function hasIdentity({ cwd, env }) {
102
- return (
103
- git(["var", "GIT_AUTHOR_IDENT"], { cwd, env }).status === 0 &&
104
- git(["var", "GIT_COMMITTER_IDENT"], { cwd, env }).status === 0
105
- );
137
+ /**
138
+ * Whether the repository whose work tree holds `dest` shows none of the files
139
+ * written there, every one of them being ignored, though the directory is not.
140
+ * An empty status does not say so alone: a project the enclosing repository
141
+ * tracks, deleted and then written again as it was, shows nothing either, so
142
+ * its index must hold nothing under `dest` as well.
143
+ */
144
+ export function ignoresEveryFile({ dest, env }) {
145
+ const status = git(["status", "--porcelain", "--untracked-files=all", "--", "."], {
146
+ cwd: dest,
147
+ env,
148
+ });
149
+ if (status.status !== 0 || status.stdout !== "") return false;
150
+ const tracked = git(["ls-files", "--", "."], { cwd: dest, env });
151
+ return tracked.status === 0 && tracked.stdout === "";
106
152
  }
107
153
 
108
154
  /**
109
- * Whether git can name an author and a committer for the commit in the
110
- * repository about to be made at `dest`, which `from`, the destination or its
111
- * nearest existing ancestor, stands outside of. Outside a repository git reads
112
- * no `includeIf "gitdir:…"` section, so an identity given only to the
113
- * repositories under a directory is invisible from `from`. When that reading
114
- * finds none, the question is asked again inside a throwaway repository made
115
- * at `dest`, and what the probe made is removed before the answer is returned.
155
+ * Answer with every missing directory from `from`, the destination's nearest
156
+ * existing ancestor, down to `dest` made for the call and removed after it.
157
+ * Returns what `answer` returns, or `fallback` when a directory cannot be made
158
+ * or `answer` throws.
116
159
  *
117
- * It removes only what it made, as the write does. Each missing directory and
118
- * the `.git` are made without `recursive`, so a path that stands there already,
119
- * a dangling symlink the reading took for missing, or one another process
120
- * creates meanwhile fails the probe instead of being taken over and removed.
121
- * The directories go deepest first and only while empty, so what another
122
- * process writes into one meanwhile stays. A probe that cannot be made
123
- * answers no.
160
+ * It removes only what it made, as the write does. Each missing directory is
161
+ * made without `recursive`, so a path that stands there already, a dangling
162
+ * symlink the reading took for missing, or one another process creates
163
+ * meanwhile fails the call instead of being taken over and removed. The
164
+ * directories go deepest first and only while empty, so what another process
165
+ * writes into one meanwhile stays.
124
166
  */
125
- export function hasIdentityForInit({ dest, from, env }) {
126
- if (hasIdentity({ cwd: from, env })) return true;
167
+ function withDirectories({ dest, from }, fallback, answer) {
127
168
  const missing = [];
128
169
  for (let at = dest; at !== from && path.dirname(at) !== at; at = path.dirname(at)) {
129
170
  missing.unshift(at);
130
171
  }
131
- const probe = path.join(dest, ".git");
132
172
  const made = [];
133
- let probeMade = false;
134
173
  try {
135
174
  for (const dir of missing) {
136
175
  fs.mkdirSync(dir);
137
176
  made.push(dir);
138
177
  }
139
- fs.mkdirSync(probe);
140
- probeMade = true;
141
- return git(["init", "-q"], { cwd: dest, env }).status === 0 && hasIdentity({ cwd: dest, env });
178
+ return answer();
142
179
  } catch {
143
- return false;
180
+ return fallback;
144
181
  } finally {
145
- if (probeMade) fs.rmSync(probe, { recursive: true, force: true });
146
182
  for (const dir of made.reverse()) {
147
183
  try {
148
184
  fs.rmdirSync(dir);
@@ -153,6 +189,55 @@ export function hasIdentityForInit({ dest, from, env }) {
153
189
  }
154
190
  }
155
191
 
192
+ /** The `origin` of the repository `from` stands in when it is a template's own, or null. */
193
+ export function templateOrigin({ from, env }) {
194
+ const origin = git(["remote", "get-url", "origin"], { cwd: from, env });
195
+ return origin.status === 0 && TEMPLATE_ORIGINS.test(origin.stdout) ? origin.stdout : null;
196
+ }
197
+
198
+ /** Whether git can name an author and a committer, as a commit needs. */
199
+ export function hasIdentity({ cwd, env }) {
200
+ return (
201
+ git(["var", "GIT_AUTHOR_IDENT"], { cwd, env }).status === 0 &&
202
+ git(["var", "GIT_COMMITTER_IDENT"], { cwd, env }).status === 0
203
+ );
204
+ }
205
+
206
+ /**
207
+ * Whether git can name an author and a committer for the commit in the
208
+ * repository about to be made at `dest`. `from` is the destination or its
209
+ * nearest existing ancestor, and `enclosed` says whether it lies in the work
210
+ * tree of a repository that ignores the destination.
211
+ *
212
+ * Outside every repository, an identity git shows from `from` is one the new
213
+ * repository will see too, but git reads no `includeIf "gitdir:…"` section
214
+ * there, so an identity given only to the repositories under a directory is
215
+ * invisible from `from`. When that reading finds none, and always when `from`
216
+ * is enclosed, since it would then read the enclosing repository's own
217
+ * configuration, which the new repository does not inherit, the question is
218
+ * asked inside a throwaway repository made at `dest`, and what the probe made
219
+ * is removed before the answer is returned.
220
+ *
221
+ * The missing directories are made and removed as `withDirectories` says, and
222
+ * the `.git` is made without `recursive` too, so one that stands there already
223
+ * fails the probe instead of being taken over and removed. A probe that cannot
224
+ * be made answers no.
225
+ */
226
+ export function hasIdentityForInit({ dest, from, enclosed, env }) {
227
+ if (!enclosed && hasIdentity({ cwd: from, env })) return true;
228
+ return withDirectories({ dest, from }, false, () => {
229
+ const probe = path.join(dest, ".git");
230
+ fs.mkdirSync(probe);
231
+ try {
232
+ return (
233
+ git(["init", "-q"], { cwd: dest, env }).status === 0 && hasIdentity({ cwd: dest, env })
234
+ );
235
+ } finally {
236
+ fs.rmSync(probe, { recursive: true, force: true });
237
+ }
238
+ });
239
+ }
240
+
156
241
  /** The pristine commit's message, in the scaffold skill's format. */
157
242
  export function pristineMessage({ template, version, source }) {
158
243
  return `Start from Pipelex/pipelex-method-apps/${template} ${version} (${source})`;
package/lib/main.mjs CHANGED
@@ -10,14 +10,17 @@
10
10
  * `git` unless `--no-git`; `--method` and `PIPELEX_API_KEY` unless
11
11
  * `--no-create`, the key tested for presence and never printed; the
12
12
  * destination rule; git's reading of the destination, and an identity when
13
- * a commit will be made. It writes nothing but the throwaway repository in
14
- * which a new repository's identity is read when none shows outside one,
15
- * and removes that before going on. Each failure is a `refused:` verdict
16
- * naming the fix.
13
+ * a commit will be made. It writes nothing but a missing destination inside
14
+ * another repository's work tree, made so that git reads it as the
15
+ * directory it will be, and the throwaway repository in which a new
16
+ * repository's identity is read when none shows outside one, or always
17
+ * under a path another repository ignores, and removes each before going
18
+ * on. Each failure is a `refused:` verdict naming the fix.
17
19
  * 2. **The write**, exclusive, removing what it created when it cannot finish.
18
- * 3. **Git**: a new repository on `main` outside any work tree, then the pristine
19
- * commit; the commit alone at the root of a repository with no commit yet;
20
- * nothing inside another repository's work tree, or with `--no-git`.
20
+ * 3. **Git**: a new repository on `main` outside any work tree or where the
21
+ * enclosing repository ignores the destination, then the pristine commit;
22
+ * the commit alone at the root of a repository with no commit yet; nothing
23
+ * inside another repository's work tree, or with `--no-git`.
21
24
  * 4. **`make create`**, unless `--no-create`, streamed or logged.
22
25
  * 5. **The report**: the gesture's warnings, the git outcome, and the verdict
23
26
  * line, last.
@@ -36,6 +39,7 @@ import {
36
39
  commitPristine,
37
40
  hasIdentity,
38
41
  hasIdentityForInit,
42
+ ignoresEveryFile,
39
43
  pristineByHand,
40
44
  pristineMessage,
41
45
  readGit,
@@ -215,13 +219,19 @@ function planGit(args, dest, found, env) {
215
219
  return {
216
220
  commit: false,
217
221
  init: false,
222
+ inside: reading.toplevel,
218
223
  line: `git: ${dest} is inside the work tree of ${reading.toplevel}, so no repository was made and nothing was committed; the project is new files in that repository.`,
219
224
  };
225
+ case "ignored":
226
+ // The enclosing repository does not version the destination, so the
227
+ // project gets a repository of its own, as outside every work tree.
228
+ plan = { commit: true, init: true, ignoredBy: reading.toplevel };
229
+ break;
220
230
  default:
221
231
  plan = { commit: true, init: true };
222
232
  }
223
233
  const identity = plan.init
224
- ? hasIdentityForInit({ dest, from, env })
234
+ ? hasIdentityForInit({ dest, from, enclosed: reading.kind === "ignored", env })
225
235
  : hasIdentity({ cwd: from, env });
226
236
  if (!identity) {
227
237
  throw Verdict.refused(
@@ -333,6 +343,9 @@ async function create(argv, d, say, state) {
333
343
  // ── Git ──
334
344
  state.phase = "commit";
335
345
  let gitLine = git.line;
346
+ if (git.inside !== undefined && ignoresEveryFile({ dest, env: d.env })) {
347
+ gitLine = `git: ${dest} is inside the work tree of ${git.inside}, which ignores every file of the project but not its directory, so no repository was made and the project is under no version control.`;
348
+ }
336
349
  if (git.commit) {
337
350
  const message = pristineMessage(pack);
338
351
  try {
@@ -343,9 +356,14 @@ async function create(argv, d, say, state) {
343
356
  message,
344
357
  env: d.env,
345
358
  });
346
- gitLine = git.init
347
- ? `git: made a repository on main and committed the template as ${sha.slice(0, 12)}, "${message}".`
348
- : `git: committed the template as the repository's first commit, ${sha.slice(0, 12)}, "${message}".`;
359
+ const committed = `${sha.slice(0, 12)}, "${message}"`;
360
+ if (git.ignoredBy !== undefined) {
361
+ gitLine = `git: ${git.ignoredBy} ignores ${dest}, so the project got a repository of its own: made on main, with the template committed as ${committed}.`;
362
+ } else if (git.init) {
363
+ gitLine = `git: made a repository on main and committed the template as ${committed}.`;
364
+ } else {
365
+ gitLine = `git: committed the template as the repository's first commit, ${committed}.`;
366
+ }
349
367
  } catch (error) {
350
368
  for (const line of error.message.split("\n")) say(line);
351
369
  throw Verdict.failed(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pipelex/create-method-app",
3
- "version": "0.5.3",
3
+ "version": "0.5.4",
4
4
  "description": "Start a Pipelex method app: npm create @pipelex/method-app@latest my-app -- --method <bundle | mt_… | address>",
5
5
  "keywords": [
6
6
  "pipelex",
Binary file