lalph 0.2.13 → 0.2.14

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 (3) hide show
  1. package/dist/cli.mjs +807 -1399
  2. package/package.json +1 -1
  3. package/src/Worktree.ts +23 -51
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "lalph",
3
3
  "type": "module",
4
- "version": "0.2.13",
4
+ "version": "0.2.14",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
package/src/Worktree.ts CHANGED
@@ -60,7 +60,6 @@ export class Worktree extends ServiceMap.Service<Worktree>()("lalph/Worktree", {
60
60
  yield* setupWorktree({
61
61
  directory,
62
62
  exec: execHelpers.exec,
63
- pathService,
64
63
  })
65
64
 
66
65
  return {
@@ -97,12 +96,10 @@ const seedSetupScript = Effect.fnUntraced(function* (setupPath: string) {
97
96
  return
98
97
  }
99
98
 
100
- const baseBranch = yield* discoverBaseBranch
101
-
102
99
  yield* fs.makeDirectory(pathService.dirname(setupPath), {
103
100
  recursive: true,
104
101
  })
105
- yield* fs.writeFileString(setupPath, setupScriptTemplate(baseBranch))
102
+ yield* fs.writeFileString(setupPath, setupScriptTemplate)
106
103
  yield* fs.chmod(setupPath, 0o755)
107
104
  })
108
105
 
@@ -112,13 +109,12 @@ const setupWorktree = Effect.fnUntraced(function* (options: {
112
109
  template: TemplateStringsArray,
113
110
  ...args: Array<string | number | boolean>
114
111
  ) => Effect.Effect<ChildProcessSpawner.ExitCode, PlatformError.PlatformError>
115
- readonly pathService: Path.Path
116
112
  }) {
117
113
  const fs = yield* FileSystem.FileSystem
114
+ const pathService = yield* Path.Path
118
115
  const targetBranch = yield* getTargetBranch
119
- const shouldUseWorktree = Option.isSome(targetBranch)
120
116
 
121
- if (shouldUseWorktree) {
117
+ if (Option.isSome(targetBranch)) {
122
118
  const parsed = parseBranch(targetBranch.value)
123
119
  yield* options.exec`git fetch ${parsed.remote}`
124
120
  const code = yield* options.exec`git checkout ${parsed.branchWithRemote}`
@@ -128,23 +124,24 @@ const setupWorktree = Effect.fnUntraced(function* (options: {
128
124
  }
129
125
  }
130
126
 
131
- const setupPath = shouldUseWorktree
132
- ? options.pathService.join(
133
- options.directory,
134
- "scripts",
135
- "worktree-setup.sh",
136
- )
137
- : options.pathService.resolve("scripts", "worktree-setup.sh")
138
- yield* seedSetupScript(setupPath)
139
- if (yield* fs.exists(setupPath)) {
140
- const setupCwd = shouldUseWorktree
141
- ? options.directory
142
- : options.pathService.resolve(".")
143
- yield* ChildProcess.make({
144
- cwd: setupCwd,
145
- shell: process.env.SHELL ?? true,
146
- })`${setupPath}`.pipe(ChildProcess.exitCode)
147
- }
127
+ const cwdSetupPath = pathService.resolve(".lalph", "worktree-setup.sh")
128
+ const worktreeSetupPath = pathService.join(
129
+ options.directory,
130
+ ".lalph",
131
+ "worktree-setup.sh",
132
+ )
133
+
134
+ yield* seedSetupScript(cwdSetupPath)
135
+
136
+ // worktree setup script takes precedence
137
+ const setupPath = (yield* fs.exists(worktreeSetupPath))
138
+ ? worktreeSetupPath
139
+ : cwdSetupPath
140
+
141
+ yield* ChildProcess.make({
142
+ cwd: options.directory,
143
+ shell: process.env.SHELL ?? true,
144
+ })`${setupPath}`.pipe(ChildProcess.exitCode)
148
145
  })
149
146
 
150
147
  const getTargetBranch = Effect.gen(function* () {
@@ -156,35 +153,10 @@ const getTargetBranch = Effect.gen(function* () {
156
153
  return project.value.targetBranch
157
154
  })
158
155
 
159
- const discoverBaseBranch = Effect.gen(function* () {
160
- const originHead =
161
- yield* ChildProcess.make`git symbolic-ref --short refs/remotes/origin/HEAD`.pipe(
162
- ChildProcess.string,
163
- Effect.catch((_) => Effect.succeed("")),
164
- Effect.map((output) => output.trim()),
165
- )
166
-
167
- if (originHead !== "") {
168
- return originHead.startsWith("origin/")
169
- ? originHead.slice("origin/".length)
170
- : originHead
171
- }
172
-
173
- const currentBranch =
174
- yield* ChildProcess.make`git branch --show-current`.pipe(
175
- ChildProcess.string,
176
- Effect.catch((_) => Effect.succeed("")),
177
- Effect.map((output) => output.trim()),
178
- )
179
-
180
- return currentBranch === "" ? "main" : currentBranch
181
- })
182
-
183
- const setupScriptTemplate = (baseBranch: string) => `#!/usr/bin/env bash
156
+ const setupScriptTemplate = `#!/usr/bin/env bash
184
157
  set -euo pipefail
185
158
 
186
- git fetch origin
187
- git checkout origin/${baseBranch}
159
+ pnpm install
188
160
 
189
161
  # Seeded by lalph. Customize this to prepare new worktrees.
190
162
  `