t1kit 0.1.0 → 0.1.1

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,118 +1,118 @@
1
- import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs';
2
- import { dirname, join, resolve } from 'node:path';
3
- import { readIfExists, writeIfChanged } from './files.mjs';
4
- import { patchAutoSizerMocks, patchPopupMock } from './transforms.mjs';
5
-
6
- const SKIP_DIRS = new Set([
7
- '.git',
8
- 'node_modules',
9
- 'dist',
10
- 'build',
11
- 'coverage',
12
- 'artifacts',
13
- 'semantic-ui',
14
- 'api',
15
- 'modules',
16
- ]);
17
-
18
- const walk = (dir, files = []) => {
19
- if (!existsSync(dir)) return files;
20
-
21
- for (const entry of readdirSync(dir)) {
22
- if (SKIP_DIRS.has(entry)) continue;
23
-
24
- const full = join(dir, entry);
25
- const stat = statSync(full);
26
-
27
- if (stat.isDirectory()) walk(full, files);
28
- else files.push(full);
29
- }
30
-
31
- return files;
32
- };
33
-
34
- const isTestFile = path => /\.(test|spec)\.[jt]sx?$/.test(path);
35
-
36
- const readRelativeImports = (testPath, source) => {
37
- const matches = [...source.matchAll(/from\s+['"](\.[^'"]+)['"]/g)].map(match => match[1]);
38
- const files = [];
39
-
40
- for (const specifier of matches) {
41
- const base = resolve(dirname(testPath), specifier);
42
- const candidates = [
43
- base,
44
- `${base}.js`,
45
- `${base}.jsx`,
46
- `${base}.ts`,
47
- `${base}.tsx`,
48
- join(base, 'index.js'),
49
- join(base, 'index.jsx'),
50
- join(base, 'index.ts'),
51
- join(base, 'index.tsx'),
52
- ];
53
-
54
- const found = candidates.find(candidate => existsSync(candidate) && statSync(candidate).isFile());
55
-
56
- if (found) files.push(found);
57
- }
58
-
59
- return files;
60
- };
61
-
62
- const SKIP_WALK = /[\\/](utils|actions|selectors|reducer|saga|constants|validation)([\\/.]|$)/;
63
-
64
- const mockedSpecifiers = source =>
65
- [...source.matchAll(/(?:vi|jest)\.mock\(\s*['"]([^'"]+)['"]/g)].map(match => match[1]);
66
-
67
- const fileUsesSemanticPopup = path => {
68
- const source = readIfExists(path);
69
-
70
- if (!source) return false;
71
-
72
- return /import\s*\{[^}]*\bPopup\b[^}]*\}\s*from\s*['"]semantic-ui-react['"]/.test(source);
73
- };
74
-
75
- export const componentTreeUsesPopup = (testPath, source) => {
76
- const mocked = mockedSpecifiers(source);
77
- const isSkipped = path =>
78
- SKIP_WALK.test(path) ||
79
- path.includes(`${join('src', 'semantic-ui')}`) ||
80
- mocked.some(spec => path.replace(/\\/g, '/').includes(spec.replace(/^\.\//, '').replace(/\\/g, '/')));
81
-
82
- const queue = readRelativeImports(testPath, source).filter(path => !isSkipped(path));
83
- const seen = new Set();
84
-
85
- while (queue.length) {
86
- const path = queue.shift();
87
-
88
- if (seen.has(path) || isSkipped(path)) continue;
89
- seen.add(path);
90
- if (fileUsesSemanticPopup(path)) return true;
91
-
92
- const child = readIfExists(path);
93
-
94
- if (child) queue.push(...readRelativeImports(path, child));
95
- }
96
-
97
- return false;
98
- };
99
-
100
- export const patchHostTests = ({ root, dryRun, changed }) => {
101
- const src = join(root, 'src');
102
- const notes = [];
103
-
104
- for (const file of walk(src).filter(isTestFile)) {
105
- const previous = readFileSync(file, 'utf8');
106
- const withAutoSizer = patchAutoSizerMocks(previous);
107
- const next = patchPopupMock(withAutoSizer, {
108
- componentUsesPopup: componentTreeUsesPopup(file, withAutoSizer),
109
- });
110
-
111
- if (next !== previous) {
112
- writeIfChanged({ dryRun, path: file, next, previous, changed });
113
- if (withAutoSizer !== previous) notes.push('snapshots');
114
- }
115
- }
116
-
117
- return notes;
118
- };
1
+ import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs';
2
+ import { dirname, join, resolve } from 'node:path';
3
+ import { readIfExists, writeIfChanged } from './files.mjs';
4
+ import { patchAutoSizerMocks, patchPopupMock } from './transforms.mjs';
5
+
6
+ const SKIP_DIRS = new Set([
7
+ '.git',
8
+ 'node_modules',
9
+ 'dist',
10
+ 'build',
11
+ 'coverage',
12
+ 'artifacts',
13
+ 'semantic-ui',
14
+ 'api',
15
+ 'modules',
16
+ ]);
17
+
18
+ const walk = (dir, files = []) => {
19
+ if (!existsSync(dir)) return files;
20
+
21
+ for (const entry of readdirSync(dir)) {
22
+ if (SKIP_DIRS.has(entry)) continue;
23
+
24
+ const full = join(dir, entry);
25
+ const stat = statSync(full);
26
+
27
+ if (stat.isDirectory()) walk(full, files);
28
+ else files.push(full);
29
+ }
30
+
31
+ return files;
32
+ };
33
+
34
+ const isTestFile = path => /\.(test|spec)\.[jt]sx?$/.test(path);
35
+
36
+ const readRelativeImports = (testPath, source) => {
37
+ const matches = [...source.matchAll(/from\s+['"](\.[^'"]+)['"]/g)].map(match => match[1]);
38
+ const files = [];
39
+
40
+ for (const specifier of matches) {
41
+ const base = resolve(dirname(testPath), specifier);
42
+ const candidates = [
43
+ base,
44
+ `${base}.js`,
45
+ `${base}.jsx`,
46
+ `${base}.ts`,
47
+ `${base}.tsx`,
48
+ join(base, 'index.js'),
49
+ join(base, 'index.jsx'),
50
+ join(base, 'index.ts'),
51
+ join(base, 'index.tsx'),
52
+ ];
53
+
54
+ const found = candidates.find(candidate => existsSync(candidate) && statSync(candidate).isFile());
55
+
56
+ if (found) files.push(found);
57
+ }
58
+
59
+ return files;
60
+ };
61
+
62
+ const SKIP_WALK = /[\\/](utils|actions|selectors|reducer|saga|constants|validation)([\\/.]|$)/;
63
+
64
+ const mockedSpecifiers = source =>
65
+ [...source.matchAll(/(?:vi|jest)\.mock\(\s*['"]([^'"]+)['"]/g)].map(match => match[1]);
66
+
67
+ const fileUsesSemanticPopup = path => {
68
+ const source = readIfExists(path);
69
+
70
+ if (!source) return false;
71
+
72
+ return /import\s*\{[^}]*\bPopup\b[^}]*\}\s*from\s*['"]semantic-ui-react['"]/.test(source);
73
+ };
74
+
75
+ export const componentTreeUsesPopup = (testPath, source) => {
76
+ const mocked = mockedSpecifiers(source);
77
+ const isSkipped = path =>
78
+ SKIP_WALK.test(path) ||
79
+ path.includes(`${join('src', 'semantic-ui')}`) ||
80
+ mocked.some(spec => path.replace(/\\/g, '/').includes(spec.replace(/^\.\//, '').replace(/\\/g, '/')));
81
+
82
+ const queue = readRelativeImports(testPath, source).filter(path => !isSkipped(path));
83
+ const seen = new Set();
84
+
85
+ while (queue.length) {
86
+ const path = queue.shift();
87
+
88
+ if (seen.has(path) || isSkipped(path)) continue;
89
+ seen.add(path);
90
+ if (fileUsesSemanticPopup(path)) return true;
91
+
92
+ const child = readIfExists(path);
93
+
94
+ if (child) queue.push(...readRelativeImports(path, child));
95
+ }
96
+
97
+ return false;
98
+ };
99
+
100
+ export const patchHostTests = ({ root, dryRun, changed }) => {
101
+ const src = join(root, 'src');
102
+ const notes = [];
103
+
104
+ for (const file of walk(src).filter(isTestFile)) {
105
+ const previous = readFileSync(file, 'utf8');
106
+ const withAutoSizer = patchAutoSizerMocks(previous);
107
+ const next = patchPopupMock(withAutoSizer, {
108
+ componentUsesPopup: componentTreeUsesPopup(file, withAutoSizer),
109
+ });
110
+
111
+ if (next !== previous) {
112
+ writeIfChanged({ dryRun, path: file, next, previous, changed });
113
+ if (withAutoSizer !== previous) notes.push('snapshots');
114
+ }
115
+ }
116
+
117
+ return notes;
118
+ };
@@ -1,181 +1,208 @@
1
- import { spawnSync } from 'node:child_process';
2
- import { existsSync, renameSync, rmSync, writeFileSync } from 'node:fs';
3
- import { join, relative, resolve } from 'node:path';
4
- import { readIfExists } from './files.mjs';
5
- import {
6
- SEMANTIC_SUBMODULE_PATH,
7
- SEMANTIC_THEME_BRANCH,
8
- SEMANTIC_THEME_TS,
9
- ensureSubmoduleBranch,
10
- parseSemanticSubmodule,
11
- semanticAddUrl,
12
- themeGitUnsafeReasons,
13
- } from './transforms.mjs';
14
-
15
- const runGit = (root, args, { allowFail = false, inherit = true } = {}) => {
16
- const result = spawnSync('git', args, {
17
- cwd: root,
18
- encoding: 'utf8',
19
- stdio: inherit ? 'inherit' : ['ignore', 'pipe', 'pipe'],
20
- });
21
-
22
- if (!allowFail && result.status !== 0) {
23
- throw new Error(`git ${args.join(' ')} failed (exit ${result.status ?? 'spawn'})`);
24
- }
25
-
26
- return result;
27
- };
28
-
29
- const gitText = (root, args) => (runGit(root, args, { inherit: false, allowFail: true }).stdout || '').trim();
30
-
31
- const moduleGitDirs = (root, names) => {
32
- const gitDir = gitText(root, ['rev-parse', '--git-dir']);
33
-
34
- if (!gitDir) return [];
35
-
36
- const absGitDir = resolve(root, gitDir);
37
- const dirs = new Set();
38
-
39
- for (const name of new Set(names.filter(Boolean).map(String))) {
40
- const dir = resolve(absGitDir, 'modules', ...name.split('/'));
41
- if (existsSync(dir)) dirs.add(dir);
42
- }
43
-
44
- return [...dirs];
45
- };
46
-
47
- const inspectThemeGit = (root, path, names) => {
48
- const worktree = join(root, path);
49
- const gitDirs = moduleGitDirs(root, names);
50
- const gitInWorktree = existsSync(worktree) && existsSync(join(worktree, '.git'));
51
-
52
- const status = gitInWorktree ? gitText(worktree, ['status', '--porcelain']) : '';
53
- const stashList = [
54
- gitInWorktree ? gitText(worktree, ['stash', 'list']) : '',
55
- ...gitDirs.map(dir => gitText(root, ['--git-dir', dir, 'stash', 'list'])),
56
- ].join('\n');
57
- const unpublished = [
58
- gitInWorktree ? gitText(worktree, ['log', 'HEAD', '--branches', '--not', '--remotes', '--oneline']) : '',
59
- ...gitDirs.map(dir =>
60
- gitText(root, ['--git-dir', dir, 'log', 'HEAD', '--branches', '--not', '--remotes', '--oneline']),
61
- ),
62
- ].join('\n');
63
-
64
- return { status, stashList, unpublished, gitDirs };
65
- };
66
-
67
- const assertThemeGitSafe = (root, path, names) => {
68
- const { status, stashList, unpublished } = inspectThemeGit(root, path, names);
69
- const reasons = themeGitUnsafeReasons({ status, stashList, unpublished });
70
-
71
- if (!reasons.length) return;
72
-
73
- throw new Error(
74
- `Не трогаю gitdir темы: ${reasons.join('; ')}.\n` +
75
- 'Закоммитьте и push в front-semantic-theme, затем запустите снова. Stash в src/semantic-ui недостаточно — после clone его не будет.',
76
- );
77
- };
78
-
79
- const backupGitModuleWorktree = (root, names) => {
80
- for (const dir of moduleGitDirs(root, names)) {
81
- let backup = `${dir}.pre-theme-ts`;
82
- let n = 1;
83
-
84
- while (existsSync(backup)) {
85
- n += 1;
86
- backup = `${dir}.pre-theme-ts-${n}`;
87
- }
88
-
89
- renameSync(dir, backup);
90
- log(`Старый gitdir темы сохранён: ${relative(root, backup)}`);
91
- }
92
- };
93
-
94
- const runInitSh = root => {
95
- const script = join(root, 'init.sh');
96
-
97
- if (!existsSync(script)) {
98
- log('init.sh не найден, git submodule init && sync && update --remote');
99
- runGit(root, ['submodule', 'init']);
100
- runGit(root, ['submodule', 'sync']);
101
- runGit(root, ['submodule', 'update', '--remote']);
102
- return;
103
- }
104
-
105
- const result = spawnSync('sh', [script], { cwd: root, encoding: 'utf8', stdio: 'inherit' });
106
-
107
- if (result.status !== 0) {
108
- throw new Error(`init.sh failed (exit ${result.status ?? 'spawn'})`);
109
- }
110
- };
111
-
112
- const alreadyOnThemeTs = (parsed, root) =>
113
- Boolean(
114
- parsed?.url?.includes(SEMANTIC_THEME_TS) &&
115
- parsed?.name === SEMANTIC_SUBMODULE_PATH &&
116
- existsSync(join(root, SEMANTIC_SUBMODULE_PATH, 'package.json')),
117
- );
118
-
119
- const semanticTarget = root => {
120
- const gitmodules = readIfExists(join(root, '.gitmodules')) || '';
121
- const parsed = parseSemanticSubmodule(gitmodules);
122
- const path = parsed?.path || SEMANTIC_SUBMODULE_PATH;
123
-
124
- return {
125
- gitmodules,
126
- parsed,
127
- path,
128
- url: semanticAddUrl(gitmodules),
129
- themeNames: [path, parsed?.name, 'front-semantic-theme'],
130
- };
131
- };
132
-
133
- export const assertSemanticReplaceSafe = root => {
134
- const { parsed, path, themeNames } = semanticTarget(root);
135
-
136
- if (!alreadyOnThemeTs(parsed, root)) assertThemeGitSafe(root, path, themeNames);
137
- };
138
-
139
- export const replaceSemanticSubmodule = root => {
140
- const { gitmodules, parsed, url, path, themeNames } = semanticTarget(root);
141
-
142
- log(`\nReplacing submodule ${path} → ${url} (branch ${SEMANTIC_THEME_BRANCH})`);
143
-
144
- if (alreadyOnThemeTs(parsed, root)) {
145
- log('Уже front-semantic-theme-ts по пути src/semantic-ui, add пропускаю.');
146
- const next = ensureSubmoduleBranch(gitmodules);
147
- if (next !== gitmodules) writeFileSync(join(root, '.gitmodules'), next);
148
- runInitSh(root);
149
- return;
150
- }
151
-
152
- runGit(root, ['submodule', 'deinit', '-f', '--', path], { allowFail: true });
153
- if (parsed?.name && parsed.name !== path) {
154
- runGit(root, ['submodule', 'deinit', '-f', '--', parsed.name], { allowFail: true });
155
- }
156
-
157
- const removed = runGit(root, ['rm', '-rf', '--', path], { allowFail: true });
158
-
159
- if (removed.status !== 0) {
160
- runGit(root, ['rm', '-rf', '--cached', '--', path], { allowFail: true });
161
- }
162
-
163
- const folder = join(root, path);
164
- if (existsSync(folder)) rmSync(folder, { recursive: true, force: true });
165
-
166
- backupGitModuleWorktree(root, themeNames);
167
-
168
- runGit(root, ['submodule', 'add', '-f', url, path]);
169
-
170
- const afterAdd = readIfExists(join(root, '.gitmodules')) || '';
171
- const withBranch = ensureSubmoduleBranch(afterAdd);
172
-
173
- if (withBranch !== afterAdd) {
174
- writeFileSync(join(root, '.gitmodules'), withBranch);
175
- runGit(root, ['add', '--', '.gitmodules']);
176
- }
177
-
178
- runInitSh(root);
179
- };
180
-
181
- const log = message => process.stdout.write(`${message}\n`);
1
+ import { spawnSync } from 'node:child_process';
2
+ import { existsSync, renameSync, rmSync, writeFileSync } from 'node:fs';
3
+ import { join, relative, resolve } from 'node:path';
4
+ import { readIfExists } from './files.mjs';
5
+ import {
6
+ SEMANTIC_SUBMODULE_PATH,
7
+ SEMANTIC_THEME_BRANCH,
8
+ SEMANTIC_THEME_TS,
9
+ ensureSubmoduleBranch,
10
+ isLegacyThemeRemoteUrl,
11
+ isThemeTsRemoteUrl,
12
+ parseSemanticSubmodule,
13
+ semanticAddUrl,
14
+ themeGitUnsafeReasons,
15
+ } from './transforms.mjs';
16
+
17
+ const runGit = (root, args, { allowFail = false, inherit = true } = {}) => {
18
+ const result = spawnSync('git', args, {
19
+ cwd: root,
20
+ encoding: 'utf8',
21
+ stdio: inherit ? 'inherit' : ['ignore', 'pipe', 'pipe'],
22
+ });
23
+
24
+ if (!allowFail && result.status !== 0) {
25
+ throw new Error(`git ${args.join(' ')} failed (exit ${result.status ?? 'spawn'})`);
26
+ }
27
+
28
+ return result;
29
+ };
30
+
31
+ const gitText = (root, args) => (runGit(root, args, { inherit: false, allowFail: true }).stdout || '').trim();
32
+
33
+ const moduleGitDirs = (root, names) => {
34
+ const gitDir = gitText(root, ['rev-parse', '--git-dir']);
35
+
36
+ if (!gitDir) return [];
37
+
38
+ const absGitDir = resolve(root, gitDir);
39
+ const dirs = new Set();
40
+
41
+ for (const name of new Set(names.filter(Boolean).map(String))) {
42
+ const dir = resolve(absGitDir, 'modules', ...name.split('/'));
43
+ if (existsSync(dir)) dirs.add(dir);
44
+ }
45
+
46
+ return [...dirs];
47
+ };
48
+
49
+ const inspectThemeGit = (root, path, names) => {
50
+ const worktree = join(root, path);
51
+ const gitDirs = moduleGitDirs(root, names);
52
+ const gitInWorktree = existsSync(worktree) && existsSync(join(worktree, '.git'));
53
+
54
+ const status = gitInWorktree ? gitText(worktree, ['status', '--porcelain']) : '';
55
+ const stashList = [
56
+ gitInWorktree ? gitText(worktree, ['stash', 'list']) : '',
57
+ ...gitDirs.map(dir => gitText(root, ['--git-dir', dir, 'stash', 'list'])),
58
+ ].join('\n');
59
+ const unpublished = [
60
+ gitInWorktree ? gitText(worktree, ['log', 'HEAD', '--branches', '--not', '--remotes', '--oneline']) : '',
61
+ ...gitDirs.map(dir =>
62
+ gitText(root, ['--git-dir', dir, 'log', 'HEAD', '--branches', '--not', '--remotes', '--oneline']),
63
+ ),
64
+ ].join('\n');
65
+
66
+ return { status, stashList, unpublished, gitDirs };
67
+ };
68
+
69
+ const assertThemeGitSafe = (root, path, names) => {
70
+ const { status, stashList, unpublished } = inspectThemeGit(root, path, names);
71
+ const reasons = themeGitUnsafeReasons({ status, stashList, unpublished });
72
+
73
+ if (!reasons.length) return;
74
+
75
+ throw new Error(
76
+ `Не трогаю gitdir темы: ${reasons.join('; ')}.\n` +
77
+ 'Закоммитьте и push в front-semantic-theme, затем запустите команду снова. Stash в src/semantic-ui недостаточно — после clone его не будет.',
78
+ );
79
+ };
80
+
81
+ const backupGitModuleWorktree = (root, names) => {
82
+ for (const dir of moduleGitDirs(root, names)) {
83
+ let backup = `${dir}.pre-theme-ts`;
84
+ let n = 1;
85
+
86
+ while (existsSync(backup)) {
87
+ n += 1;
88
+ backup = `${dir}.pre-theme-ts-${n}`;
89
+ }
90
+
91
+ renameSync(dir, backup);
92
+ log(`Старый gitdir темы сохранён: ${relative(root, backup)}`);
93
+ }
94
+ };
95
+
96
+ const runInitSh = root => {
97
+ const script = join(root, 'init.sh');
98
+
99
+ if (!existsSync(script)) {
100
+ log('init.sh не найден, git submodule init && sync && update --remote');
101
+ runGit(root, ['submodule', 'init']);
102
+ runGit(root, ['submodule', 'sync']);
103
+ runGit(root, ['submodule', 'update', '--remote']);
104
+ return;
105
+ }
106
+
107
+ const result = spawnSync('sh', [script], { cwd: root, encoding: 'utf8', stdio: 'inherit' });
108
+
109
+ if (result.status !== 0) {
110
+ throw new Error(`init.sh failed (exit ${result.status ?? 'spawn'})`);
111
+ }
112
+ };
113
+
114
+ const themeTsCheckoutLooksReady = root => {
115
+ const dir = join(root, SEMANTIC_SUBMODULE_PATH);
116
+
117
+ return existsSync(join(dir, 'package.json')) || existsSync(join(dir, 'craco.config.ts'));
118
+ };
119
+
120
+ const themeOrigins = (root, path, names) => {
121
+ const worktree = join(root, path);
122
+ const urls = [];
123
+
124
+ if (existsSync(worktree) && existsSync(join(worktree, '.git'))) {
125
+ urls.push(gitText(worktree, ['remote', 'get-url', 'origin']));
126
+ }
127
+
128
+ for (const dir of moduleGitDirs(root, names)) {
129
+ urls.push(gitText(root, ['--git-dir', dir, 'remote', 'get-url', 'origin']));
130
+ }
131
+
132
+ return urls.filter(Boolean);
133
+ };
134
+
135
+ const alreadyOnThemeTs = (parsed, root, names) => {
136
+ if (!isThemeTsRemoteUrl(parsed?.url) || !themeTsCheckoutLooksReady(root)) return false;
137
+
138
+ const origins = themeOrigins(root, parsed.path || SEMANTIC_SUBMODULE_PATH, names);
139
+
140
+ return !origins.some(isLegacyThemeRemoteUrl);
141
+ };
142
+
143
+ const semanticTarget = root => {
144
+ const gitmodules = readIfExists(join(root, '.gitmodules')) || '';
145
+ const headGitmodules = gitText(root, ['show', 'HEAD:.gitmodules']);
146
+ const parsed = parseSemanticSubmodule(gitmodules) || parseSemanticSubmodule(headGitmodules);
147
+ const path = parsed?.path || SEMANTIC_SUBMODULE_PATH;
148
+
149
+ return {
150
+ gitmodules,
151
+ parsed,
152
+ path,
153
+ url: semanticAddUrl(gitmodules, headGitmodules),
154
+ themeNames: [path, parsed?.name, 'front-semantic-theme'],
155
+ };
156
+ };
157
+
158
+ export const previewSemanticAddUrl = root => semanticTarget(root).url;
159
+
160
+ export const assertSemanticReplaceSafe = root => {
161
+ const { parsed, path, themeNames } = semanticTarget(root);
162
+
163
+ if (!alreadyOnThemeTs(parsed, root, themeNames)) assertThemeGitSafe(root, path, themeNames);
164
+ };
165
+
166
+ export const replaceSemanticSubmodule = root => {
167
+ const { gitmodules, parsed, url, path, themeNames } = semanticTarget(root);
168
+
169
+ log(`\nReplacing submodule ${path} → ${url} (branch ${SEMANTIC_THEME_BRANCH})`);
170
+
171
+ if (alreadyOnThemeTs(parsed, root, themeNames)) {
172
+ log('Уже front-semantic-theme-ts по пути src/semantic-ui, add пропускаю.');
173
+ const next = ensureSubmoduleBranch(gitmodules);
174
+ if (next !== gitmodules) writeFileSync(join(root, '.gitmodules'), next);
175
+ runInitSh(root);
176
+ return;
177
+ }
178
+
179
+ runGit(root, ['submodule', 'deinit', '-f', '--', path], { allowFail: true });
180
+ if (parsed?.name && parsed.name !== path) {
181
+ runGit(root, ['submodule', 'deinit', '-f', '--', parsed.name], { allowFail: true });
182
+ }
183
+
184
+ const removed = runGit(root, ['rm', '-rf', '--', path], { allowFail: true });
185
+
186
+ if (removed.status !== 0) {
187
+ runGit(root, ['rm', '-rf', '--cached', '--', path], { allowFail: true });
188
+ }
189
+
190
+ const folder = join(root, path);
191
+ if (existsSync(folder)) rmSync(folder, { recursive: true, force: true });
192
+
193
+ backupGitModuleWorktree(root, themeNames);
194
+
195
+ runGit(root, ['submodule', 'add', '-f', url, path]);
196
+
197
+ const afterAdd = readIfExists(join(root, '.gitmodules')) || '';
198
+ const withBranch = ensureSubmoduleBranch(afterAdd);
199
+
200
+ if (withBranch !== afterAdd) {
201
+ writeFileSync(join(root, '.gitmodules'), withBranch);
202
+ runGit(root, ['add', '--', '.gitmodules']);
203
+ }
204
+
205
+ runInitSh(root);
206
+ };
207
+
208
+ const log = message => process.stdout.write(`${message}\n`);