claude-switch-profile 1.4.0 → 1.4.2

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.
@@ -1,6 +1,17 @@
1
- import { existsSync, mkdirSync, cpSync, rmSync, lstatSync, statSync, copyFileSync, readFileSync, writeFileSync, readdirSync } from 'node:fs';
1
+ import {
2
+ existsSync,
3
+ mkdirSync,
4
+ cpSync,
5
+ rmSync,
6
+ lstatSync,
7
+ statSync,
8
+ readFileSync,
9
+ writeFileSync,
10
+ readdirSync,
11
+ readlinkSync,
12
+ } from 'node:fs';
2
13
  import { join, dirname } from 'node:path';
3
- import { MANAGED_ITEMS, COPY_ITEMS, COPY_DIRS, CLAUDE_DIR, DEFAULT_PROFILE } from './constants.js';
14
+ import { MANAGED_ITEMS, COPY_ITEMS, COPY_DIRS, CLAUDE_DIR } from './constants.js';
4
15
  import {
5
16
  getActive,
6
17
  getProfileDir,
@@ -37,6 +48,12 @@ const shouldSyncDir = (src, dest) => {
37
48
  const srcPath = join(srcDir, srcEntry.name);
38
49
  const destPath = join(destDir, srcEntry.name);
39
50
 
51
+ if (srcEntry.isSymbolicLink()) {
52
+ if (!destEntry.isSymbolicLink()) return true;
53
+ if (readlinkSync(srcPath) !== readlinkSync(destPath)) return true;
54
+ continue;
55
+ }
56
+
40
57
  if (srcEntry.isDirectory()) {
41
58
  if (!destEntry.isDirectory()) return true;
42
59
  pending.push([srcPath, destPath]);
@@ -99,36 +116,24 @@ const getStaticItems = () => {
99
116
  };
100
117
 
101
118
  const resolveSourceDir = (profileName) => {
102
- if (profileName === DEFAULT_PROFILE) {
103
- return CLAUDE_DIR;
104
- }
105
-
106
119
  const active = getActive();
107
- if (active === profileName) {
108
- return CLAUDE_DIR;
109
- }
110
-
111
- return getProfileDir(profileName);
120
+ return active === profileName ? CLAUDE_DIR : getProfileDir(profileName);
112
121
  };
113
122
 
114
123
  const resolveItemSource = (profileName, item) => {
115
- const profileDir = profileName === DEFAULT_PROFILE ? null : getProfileDir(profileName);
124
+ const profileDir = getProfileDir(profileName);
116
125
  const active = getActive();
117
126
  const profileIsActive = active === profileName;
118
127
 
119
- // When profile is active or default, items live in CLAUDE_DIR
120
- if (profileIsActive || profileName === DEFAULT_PROFILE) {
128
+ if (profileIsActive) {
121
129
  const claudePath = join(CLAUDE_DIR, item);
122
130
  if (existsSync(claudePath)) return claudePath;
123
- // Fallback: items may still be in profileDir (not yet moved by `use`)
124
- if (profileDir) {
125
- const profilePath = join(profileDir, item);
126
- if (existsSync(profilePath)) return profilePath;
127
- }
131
+
132
+ const profilePath = join(profileDir, item);
133
+ if (existsSync(profilePath)) return profilePath;
128
134
  return null;
129
135
  }
130
136
 
131
- // Profile is NOT active — items should be in profileDir
132
137
  const profilePath = join(profileDir, item);
133
138
  if (existsSync(profilePath)) return profilePath;
134
139
 
@@ -146,23 +151,18 @@ export const syncStaticConfig = (profileName, runtimeDir) => {
146
151
  const dest = join(runtimeDir, item);
147
152
 
148
153
  if (!src) {
149
- // Source doesn't exist anywhere — skip (don't delete existing runtime items)
150
154
  continue;
151
155
  }
152
156
 
153
157
  const stat = lstatSync(src);
154
158
 
155
- if (stat.isDirectory()) {
159
+ if (stat.isDirectory() && !stat.isSymbolicLink()) {
156
160
  if (!shouldSyncDir(src, dest)) continue;
157
- removePath(dest);
158
- cpSync(src, dest, { recursive: true });
159
- continue;
160
161
  }
161
162
 
162
- if (stat.isFile()) {
163
- mkdirSync(dirname(dest), { recursive: true });
164
- copyFileSync(src, dest);
165
- }
163
+ removePath(dest);
164
+ mkdirSync(dirname(dest), { recursive: true });
165
+ cpSync(src, dest, { recursive: true, verbatimSymlinks: true });
166
166
  }
167
167
 
168
168
  rewriteSettingsForRuntime(runtimeDir, sourceDir);