javascript-solid-server 0.0.195 → 0.0.196

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "javascript-solid-server",
3
- "version": "0.0.195",
3
+ "version": "0.0.196",
4
4
  "description": "A minimal, fast Solid server",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -90,11 +90,20 @@ function findGitDir(repoPath) {
90
90
  }
91
91
 
92
92
  /**
93
- * Auto-initialize a bare git repo at repoAbs to accept a first push, but
94
- * only when it's safe to do so. The caller must invoke this *after* the
95
- * standard ACL Write check has passed (i.e. inside the existing
96
- * preHandler-gated path for `git-receive-pack`), so authorization is
97
- * already enforced.
93
+ * Auto-initialize a regular (non-bare) git repo at repoAbs to accept a
94
+ * first push, but only when it's safe to do so. The caller must invoke
95
+ * this *after* the standard ACL Write check has passed (i.e. inside the
96
+ * existing preHandler-gated path for `git-receive-pack`), so
97
+ * authorization is already enforced.
98
+ *
99
+ * Regular (not bare): the repo has a `.git/` subdirectory plus a
100
+ * working tree. Combined with the `receive.denyCurrentBranch
101
+ * updateInstead` config the main handler sets on every push, the
102
+ * working tree is auto-extracted on each push. This means pushed files
103
+ * appear as static resources at the corresponding pod URL — the "apps
104
+ * live in pods" install pattern works end-to-end. (Bare repos store
105
+ * content in pack files only, so a pushed `index.html` wouldn't be
106
+ * servable as HTTP.)
98
107
  *
99
108
  * Safe iff one of:
100
109
  * - the target path does not exist (we create it), or
@@ -123,7 +132,7 @@ function findGitDir(repoPath) {
123
132
  * @param {object} [log] - optional Fastify request logger for diagnostics
124
133
  * @returns {{gitDir: string, isRegular: boolean}|null}
125
134
  */
126
- function tryAutoInitBareRepo(repoAbs, log) {
135
+ function tryAutoInitRepo(repoAbs, log) {
127
136
  try {
128
137
  if (existsSync(repoAbs)) {
129
138
  if (!statSync(repoAbs).isDirectory()) return null;
@@ -131,18 +140,18 @@ function tryAutoInitBareRepo(repoAbs, log) {
131
140
  } else {
132
141
  mkdirSync(repoAbs, { recursive: true });
133
142
  }
134
- const result = spawnSync('git', ['init', '--bare', repoAbs], {
143
+ const result = spawnSync('git', ['init', repoAbs], {
135
144
  stdio: ['ignore', 'pipe', 'pipe']
136
145
  });
137
146
  if (result.status !== 0) {
138
147
  log?.warn?.(
139
148
  { repoAbs, status: result.status, stderr: result.stderr?.toString?.().slice(0, 500) },
140
- 'git auto-init: `git init --bare` exited non-zero'
149
+ 'git auto-init: `git init` exited non-zero'
141
150
  );
142
151
  return null;
143
152
  }
144
153
  const info = findGitDir(repoAbs);
145
- if (info) log?.info?.({ repoAbs }, 'git auto-init: bare repo created on first push');
154
+ if (info) log?.info?.({ repoAbs }, 'git auto-init: repo created on first push');
146
155
  return info;
147
156
  } catch (err) {
148
157
  log?.warn?.({ err, repoAbs }, 'git auto-init: refusing to init (filesystem error)');
@@ -213,14 +222,17 @@ export async function handleGit(request, reply) {
213
222
  }
214
223
 
215
224
  // Find git directory. On a push (`git-receive-pack`) to a path that
216
- // doesn't yet contain a repo, auto-init a bare one if the location is
217
- // safe to claim — the standard preHandler has already verified ACL
218
- // Write on this path, so authorization is enforced. See
219
- // tryAutoInitBareRepo for the safety conditions (empty / non-existent
220
- // path only; refuses to clobber existing files).
225
+ // doesn't yet contain a repo, auto-init one if the location is safe
226
+ // to claim — the standard preHandler has already verified ACL Write
227
+ // on this path, so authorization is enforced. See tryAutoInitRepo
228
+ // for the safety conditions (empty / non-existent path only; refuses
229
+ // to clobber existing files). Auto-init creates a regular (non-bare)
230
+ // repo so the `denyCurrentBranch updateInstead` config below
231
+ // auto-extracts the working tree on each push — pushed files become
232
+ // static resources at the corresponding pod URL.
221
233
  let gitInfo = findGitDir(repoAbs);
222
234
  if (!gitInfo && isGitWriteOperation(request.url)) {
223
- gitInfo = tryAutoInitBareRepo(repoAbs, request.log);
235
+ gitInfo = tryAutoInitRepo(repoAbs, request.log);
224
236
  }
225
237
  if (!gitInfo) {
226
238
  setGitCorsHeaders(reply);
@@ -56,7 +56,7 @@ describe('Git auto-init on first push', () => {
56
56
  await fs.remove(DATA_DIR);
57
57
  });
58
58
 
59
- it('auto-inits a bare repo on push-advertise to a non-existent path', async () => {
59
+ it('auto-inits a regular repo on push-advertise to a non-existent path', async () => {
60
60
  const repoPath = 'public/apps/penny';
61
61
  const url = `${baseUrl}/${repoPath}/info/refs?service=git-receive-pack`;
62
62
 
@@ -66,13 +66,18 @@ describe('Git auto-init on first push', () => {
66
66
  const repoAbs = path.resolve(DATA_DIR, repoPath);
67
67
  assert.ok(existsSync(repoAbs), 'directory must be created');
68
68
  assert.ok(statSync(repoAbs).isDirectory(), 'created path must be a directory');
69
- // Bare repo: HEAD + objects/ + refs/ live at the path itself.
70
- assert.ok(existsSync(path.join(repoAbs, 'HEAD')), 'bare repo HEAD must exist');
71
- assert.ok(existsSync(path.join(repoAbs, 'objects')), 'bare repo objects/ must exist');
72
- assert.ok(existsSync(path.join(repoAbs, 'refs')), 'bare repo refs/ must exist');
69
+ // Regular (non-bare) repo: .git/ subdirectory holds the internals.
70
+ // Working tree lives at the path itself so pushed files become
71
+ // static resources.
72
+ const dotGit = path.join(repoAbs, '.git');
73
+ assert.ok(existsSync(dotGit), '.git subdirectory must exist');
74
+ assert.ok(statSync(dotGit).isDirectory(), '.git must be a directory');
75
+ assert.ok(existsSync(path.join(dotGit, 'HEAD')), '.git/HEAD must exist');
76
+ assert.ok(existsSync(path.join(dotGit, 'objects')), '.git/objects must exist');
77
+ assert.ok(existsSync(path.join(dotGit, 'refs')), '.git/refs must exist');
73
78
  });
74
79
 
75
- it('auto-inits a bare repo when the target directory exists but is empty', async () => {
80
+ it('auto-inits a regular repo when the target directory exists but is empty', async () => {
76
81
  const repoPath = 'public/empty-dir';
77
82
  await fs.ensureDir(path.resolve(DATA_DIR, repoPath));
78
83
 
@@ -81,7 +86,7 @@ describe('Git auto-init on first push', () => {
81
86
  assert.strictEqual(res.status, 200);
82
87
 
83
88
  const repoAbs = path.resolve(DATA_DIR, repoPath);
84
- assert.ok(existsSync(path.join(repoAbs, 'HEAD')), 'bare repo HEAD must exist');
89
+ assert.ok(existsSync(path.join(repoAbs, '.git', 'HEAD')), '.git/HEAD must exist');
85
90
  });
86
91
 
87
92
  it('refuses to auto-init when the target directory contains user content', async () => {
@@ -96,8 +101,7 @@ describe('Git auto-init on first push', () => {
96
101
 
97
102
  // User's file must be intact and no .git should have been created.
98
103
  assert.ok(existsSync(path.join(repoAbs, 'index.html')), 'user file must survive');
99
- assert.ok(!existsSync(path.join(repoAbs, 'HEAD')), 'no bare-repo files should appear');
100
- assert.ok(!existsSync(path.join(repoAbs, 'objects')), 'no bare-repo objects/ should appear');
104
+ assert.ok(!existsSync(path.join(repoAbs, '.git')), 'no .git directory should appear');
101
105
  });
102
106
 
103
107
  it('does NOT auto-init on a fetch (`git-upload-pack`)', async () => {
@@ -151,8 +155,8 @@ describe('Git auto-init on first push', () => {
151
155
  const repoPath = 'public/apps/penny';
152
156
  const repoAbs = path.resolve(DATA_DIR, repoPath);
153
157
  // Repo was created by the first test in this suite; capture its
154
- // initial HEAD inode/mtime to verify we don't recreate the repo.
155
- const headPath = path.join(repoAbs, 'HEAD');
158
+ // initial HEAD inode to verify we don't recreate the repo.
159
+ const headPath = path.join(repoAbs, '.git', 'HEAD');
156
160
  assert.ok(existsSync(headPath), 'prereq: repo from earlier test still exists');
157
161
  const before = statSync(headPath);
158
162