lalph 0.2.12 → 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 -1398
  2. package/package.json +1 -1
  3. package/src/Worktree.ts +24 -51
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "lalph",
3
3
  "type": "module",
4
- "version": "0.2.12",
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,14 +109,14 @@ 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)
119
+ yield* options.exec`git fetch ${parsed.remote}`
123
120
  const code = yield* options.exec`git checkout ${parsed.branchWithRemote}`
124
121
  if (code !== 0) {
125
122
  yield* options.exec`git checkout -b ${parsed.branch}`
@@ -127,23 +124,24 @@ const setupWorktree = Effect.fnUntraced(function* (options: {
127
124
  }
128
125
  }
129
126
 
130
- const setupPath = shouldUseWorktree
131
- ? options.pathService.join(
132
- options.directory,
133
- "scripts",
134
- "worktree-setup.sh",
135
- )
136
- : options.pathService.resolve("scripts", "worktree-setup.sh")
137
- yield* seedSetupScript(setupPath)
138
- if (yield* fs.exists(setupPath)) {
139
- const setupCwd = shouldUseWorktree
140
- ? options.directory
141
- : options.pathService.resolve(".")
142
- yield* ChildProcess.make({
143
- cwd: setupCwd,
144
- shell: process.env.SHELL ?? true,
145
- })`${setupPath}`.pipe(ChildProcess.exitCode)
146
- }
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)
147
145
  })
148
146
 
149
147
  const getTargetBranch = Effect.gen(function* () {
@@ -155,35 +153,10 @@ const getTargetBranch = Effect.gen(function* () {
155
153
  return project.value.targetBranch
156
154
  })
157
155
 
158
- const discoverBaseBranch = Effect.gen(function* () {
159
- const originHead =
160
- yield* ChildProcess.make`git symbolic-ref --short refs/remotes/origin/HEAD`.pipe(
161
- ChildProcess.string,
162
- Effect.catch((_) => Effect.succeed("")),
163
- Effect.map((output) => output.trim()),
164
- )
165
-
166
- if (originHead !== "") {
167
- return originHead.startsWith("origin/")
168
- ? originHead.slice("origin/".length)
169
- : originHead
170
- }
171
-
172
- const currentBranch =
173
- yield* ChildProcess.make`git branch --show-current`.pipe(
174
- ChildProcess.string,
175
- Effect.catch((_) => Effect.succeed("")),
176
- Effect.map((output) => output.trim()),
177
- )
178
-
179
- return currentBranch === "" ? "main" : currentBranch
180
- })
181
-
182
- const setupScriptTemplate = (baseBranch: string) => `#!/usr/bin/env bash
156
+ const setupScriptTemplate = `#!/usr/bin/env bash
183
157
  set -euo pipefail
184
158
 
185
- git fetch origin
186
- git checkout origin/${baseBranch}
159
+ pnpm install
187
160
 
188
161
  # Seeded by lalph. Customize this to prepare new worktrees.
189
162
  `