@gadmin2n/cli 0.0.105 → 0.0.107
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/CHANGELOG.md +17 -0
- package/actions/new.action.js +140 -94
- package/actions/update.action.d.ts +1 -0
- package/actions/update.action.js +564 -630
- package/commands/command.input.d.ts +1 -6
- package/commands/command.input.js +1 -7
- package/commands/command.loader.js +0 -2
- package/commands/new.command.js +8 -3
- package/commands/update.command.js +27 -37
- package/lib/template-merge/base-store.d.ts +16 -0
- package/lib/template-merge/base-store.js +127 -0
- package/lib/template-merge/binary-detect.d.ts +7 -0
- package/lib/template-merge/binary-detect.js +36 -0
- package/lib/template-merge/classify.d.ts +10 -0
- package/lib/template-merge/classify.js +61 -0
- package/lib/template-merge/config-validate.d.ts +5 -0
- package/lib/template-merge/config-validate.js +33 -0
- package/lib/template-merge/excludes.d.ts +7 -0
- package/lib/template-merge/excludes.js +109 -0
- package/lib/template-merge/index.d.ts +9 -8
- package/lib/template-merge/index.js +10 -8
- package/lib/template-merge/materialize.d.ts +18 -0
- package/lib/template-merge/materialize.js +129 -0
- package/lib/template-merge/merge3way.d.ts +15 -0
- package/lib/template-merge/merge3way.js +54 -0
- package/lib/template-merge/residual-scan.d.ts +10 -0
- package/lib/template-merge/residual-scan.js +31 -0
- package/lib/template-merge/types.d.ts +27 -0
- package/lib/template-merge/types.js +5 -0
- package/lib/ui/messages.d.ts +0 -2
- package/lib/ui/messages.js +0 -2
- package/package.json +2 -2
- package/commands/build.command.d.ts +0 -5
- package/commands/build.command.js +0 -50
- package/lib/template-merge/config-loader.d.ts +0 -15
- package/lib/template-merge/config-loader.js +0 -38
- package/lib/template-merge/env-merger.d.ts +0 -5
- package/lib/template-merge/env-merger.js +0 -57
- package/lib/template-merge/glob.d.ts +0 -5
- package/lib/template-merge/glob.js +0 -78
- package/lib/template-merge/json-merger.d.ts +0 -5
- package/lib/template-merge/json-merger.js +0 -269
- package/lib/template-merge/merger.d.ts +0 -30
- package/lib/template-merge/merger.js +0 -2
- package/lib/template-merge/prisma-merger.d.ts +0 -5
- package/lib/template-merge/prisma-merger.js +0 -112
- package/lib/template-merge/registry.d.ts +0 -25
- package/lib/template-merge/registry.js +0 -42
- package/lib/template-merge/ts-module-merger.d.ts +0 -16
- package/lib/template-merge/ts-module-merger.js +0 -193
|
@@ -1,269 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.JsonMerger = void 0;
|
|
4
|
-
const PRESERVE_INSTANCE_KEYS = new Set([
|
|
5
|
-
'name',
|
|
6
|
-
'version',
|
|
7
|
-
'description',
|
|
8
|
-
'private',
|
|
9
|
-
'author',
|
|
10
|
-
'license',
|
|
11
|
-
'homepage',
|
|
12
|
-
'repository',
|
|
13
|
-
'bugs',
|
|
14
|
-
]);
|
|
15
|
-
const DEEP_MERGE_KEYS = new Set([
|
|
16
|
-
'dependencies',
|
|
17
|
-
'devDependencies',
|
|
18
|
-
'peerDependencies',
|
|
19
|
-
'optionalDependencies',
|
|
20
|
-
'scripts',
|
|
21
|
-
'engines',
|
|
22
|
-
'volta',
|
|
23
|
-
]);
|
|
24
|
-
const POLICY_OBJECT_KEYS = new Set([
|
|
25
|
-
'dependencies',
|
|
26
|
-
'devDependencies',
|
|
27
|
-
'peerDependencies',
|
|
28
|
-
'optionalDependencies',
|
|
29
|
-
'scripts',
|
|
30
|
-
]);
|
|
31
|
-
/**
|
|
32
|
-
* Default policy applied when the user has not configured an explicit policy
|
|
33
|
-
* via gadmin-cli.json `templateUpdate.policies`.
|
|
34
|
-
*
|
|
35
|
-
* Rationale: when running `gadmin2 update`, users almost always want template
|
|
36
|
-
* dependency versions to win — that's the whole point of the command. Keys
|
|
37
|
-
* intentionally absent from this map (e.g. `json.scripts`) fall through to the
|
|
38
|
-
* legacy preserve-instance behavior, since user scripts often diverge from
|
|
39
|
-
* template scripts on purpose.
|
|
40
|
-
*/
|
|
41
|
-
const DEFAULT_POLICIES = {
|
|
42
|
-
'json.dependencies': 'prefer-template',
|
|
43
|
-
'json.devDependencies': 'prefer-template',
|
|
44
|
-
'json.peerDependencies': 'prefer-template',
|
|
45
|
-
'json.optionalDependencies': 'prefer-template',
|
|
46
|
-
};
|
|
47
|
-
function isPlainObject(v) {
|
|
48
|
-
return v !== null && typeof v === 'object' && !Array.isArray(v);
|
|
49
|
-
}
|
|
50
|
-
function detectIndent(content) {
|
|
51
|
-
const lines = content.split('\n');
|
|
52
|
-
for (const line of lines) {
|
|
53
|
-
if (line.length === 0)
|
|
54
|
-
continue;
|
|
55
|
-
const m = line.match(/^([ \t]+)\S/);
|
|
56
|
-
if (!m)
|
|
57
|
-
continue;
|
|
58
|
-
const lead = m[1];
|
|
59
|
-
if (lead[0] === '\t')
|
|
60
|
-
return '\t';
|
|
61
|
-
if (lead.length >= 4)
|
|
62
|
-
return 4;
|
|
63
|
-
return 2;
|
|
64
|
-
}
|
|
65
|
-
return 2;
|
|
66
|
-
}
|
|
67
|
-
function unionArray(instArr, tmplArr) {
|
|
68
|
-
const seen = new Set();
|
|
69
|
-
const out = [];
|
|
70
|
-
for (const item of instArr) {
|
|
71
|
-
const key = JSON.stringify(item);
|
|
72
|
-
if (!seen.has(key)) {
|
|
73
|
-
seen.add(key);
|
|
74
|
-
out.push(item);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
for (const item of tmplArr) {
|
|
78
|
-
const key = JSON.stringify(item);
|
|
79
|
-
if (!seen.has(key)) {
|
|
80
|
-
seen.add(key);
|
|
81
|
-
out.push(item);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
return out;
|
|
85
|
-
}
|
|
86
|
-
function deepMergeKeepInstance(inst, tmpl) {
|
|
87
|
-
if (isPlainObject(inst) && isPlainObject(tmpl)) {
|
|
88
|
-
const out = {};
|
|
89
|
-
for (const k of Object.keys(inst)) {
|
|
90
|
-
if (k in tmpl) {
|
|
91
|
-
out[k] = deepMergeKeepInstance(inst[k], tmpl[k]);
|
|
92
|
-
}
|
|
93
|
-
else {
|
|
94
|
-
out[k] = inst[k];
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
for (const k of Object.keys(tmpl)) {
|
|
98
|
-
if (!(k in inst)) {
|
|
99
|
-
out[k] = tmpl[k];
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
return out;
|
|
103
|
-
}
|
|
104
|
-
if (Array.isArray(inst) && Array.isArray(tmpl)) {
|
|
105
|
-
return unionArray(inst, tmpl);
|
|
106
|
-
}
|
|
107
|
-
return inst;
|
|
108
|
-
}
|
|
109
|
-
function formatVal(v) {
|
|
110
|
-
if (typeof v === 'string')
|
|
111
|
-
return v;
|
|
112
|
-
return JSON.stringify(v);
|
|
113
|
-
}
|
|
114
|
-
class JsonMerger {
|
|
115
|
-
constructor() {
|
|
116
|
-
this.name = 'json';
|
|
117
|
-
}
|
|
118
|
-
merge(ctx) {
|
|
119
|
-
var _a;
|
|
120
|
-
let instData;
|
|
121
|
-
let tmplData;
|
|
122
|
-
try {
|
|
123
|
-
instData = JSON.parse(ctx.instanceContent);
|
|
124
|
-
}
|
|
125
|
-
catch (e) {
|
|
126
|
-
const msg = e instanceof Error ? e.message : String(e);
|
|
127
|
-
return { ok: false, reason: `parse failure: instance JSON: ${msg}` };
|
|
128
|
-
}
|
|
129
|
-
try {
|
|
130
|
-
tmplData = JSON.parse(ctx.templateContent);
|
|
131
|
-
}
|
|
132
|
-
catch (e) {
|
|
133
|
-
const msg = e instanceof Error ? e.message : String(e);
|
|
134
|
-
return { ok: false, reason: `parse failure: template JSON: ${msg}` };
|
|
135
|
-
}
|
|
136
|
-
const indent = detectIndent(ctx.instanceContent);
|
|
137
|
-
const hasTrailingNewline = ctx.instanceContent.endsWith('\n');
|
|
138
|
-
const policies = ctx.policies || {};
|
|
139
|
-
const notes = [];
|
|
140
|
-
if (!isPlainObject(instData) || !isPlainObject(tmplData)) {
|
|
141
|
-
const merged = JSON.stringify(instData, null, indent) +
|
|
142
|
-
(hasTrailingNewline ? '\n' : '');
|
|
143
|
-
return { ok: true, merged, notes: ['no changes'] };
|
|
144
|
-
}
|
|
145
|
-
const result = {};
|
|
146
|
-
const orderedKeys = [];
|
|
147
|
-
for (const k of Object.keys(instData))
|
|
148
|
-
orderedKeys.push(k);
|
|
149
|
-
for (const k of Object.keys(tmplData)) {
|
|
150
|
-
if (!(k in instData))
|
|
151
|
-
orderedKeys.push(k);
|
|
152
|
-
}
|
|
153
|
-
for (const k of orderedKeys) {
|
|
154
|
-
const inInst = k in instData;
|
|
155
|
-
const inTmpl = k in tmplData;
|
|
156
|
-
const instVal = instData[k];
|
|
157
|
-
const tmplVal = tmplData[k];
|
|
158
|
-
const policyKey = `json.${k}`;
|
|
159
|
-
const policy = (_a = policies[policyKey]) !== null && _a !== void 0 ? _a : DEFAULT_POLICIES[policyKey];
|
|
160
|
-
if (POLICY_OBJECT_KEYS.has(k) && policy) {
|
|
161
|
-
if (policy === 'overwrite') {
|
|
162
|
-
if (inTmpl) {
|
|
163
|
-
result[k] = tmplVal;
|
|
164
|
-
notes.push(`${k}: overwritten with template (policy)`);
|
|
165
|
-
}
|
|
166
|
-
else if (inInst) {
|
|
167
|
-
result[k] = instVal;
|
|
168
|
-
}
|
|
169
|
-
continue;
|
|
170
|
-
}
|
|
171
|
-
if (policy === 'prefer-template' &&
|
|
172
|
-
inInst &&
|
|
173
|
-
inTmpl &&
|
|
174
|
-
isPlainObject(instVal) &&
|
|
175
|
-
isPlainObject(tmplVal)) {
|
|
176
|
-
const obj = {};
|
|
177
|
-
const adds = [];
|
|
178
|
-
const changes = [];
|
|
179
|
-
for (const ik of Object.keys(instVal)) {
|
|
180
|
-
if (ik in tmplVal) {
|
|
181
|
-
obj[ik] = tmplVal[ik];
|
|
182
|
-
if (JSON.stringify(instVal[ik]) !== JSON.stringify(tmplVal[ik])) {
|
|
183
|
-
changes.push(`${ik} (instance ${formatVal(instVal[ik])} -> template ${formatVal(tmplVal[ik])})`);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
else {
|
|
187
|
-
obj[ik] = instVal[ik];
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
for (const tk of Object.keys(tmplVal)) {
|
|
191
|
-
if (!(tk in instVal)) {
|
|
192
|
-
obj[tk] = tmplVal[tk];
|
|
193
|
-
adds.push(tk);
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
result[k] = obj;
|
|
197
|
-
if (adds.length > 0) {
|
|
198
|
-
notes.push(`${k}: added ${adds.length} from template (${adds.join(', ')})`);
|
|
199
|
-
}
|
|
200
|
-
for (const c of changes) {
|
|
201
|
-
notes.push(`${k}: preferred template version of ${c}`);
|
|
202
|
-
}
|
|
203
|
-
continue;
|
|
204
|
-
}
|
|
205
|
-
// 'preserve-instance' or unmatched policy → fall through
|
|
206
|
-
}
|
|
207
|
-
if (inInst && !inTmpl) {
|
|
208
|
-
result[k] = instVal;
|
|
209
|
-
continue;
|
|
210
|
-
}
|
|
211
|
-
if (!inInst && inTmpl) {
|
|
212
|
-
result[k] = tmplVal;
|
|
213
|
-
continue;
|
|
214
|
-
}
|
|
215
|
-
if (PRESERVE_INSTANCE_KEYS.has(k)) {
|
|
216
|
-
result[k] = instVal;
|
|
217
|
-
continue;
|
|
218
|
-
}
|
|
219
|
-
if (DEEP_MERGE_KEYS.has(k) &&
|
|
220
|
-
isPlainObject(instVal) &&
|
|
221
|
-
isPlainObject(tmplVal)) {
|
|
222
|
-
const adds = [];
|
|
223
|
-
const kept = [];
|
|
224
|
-
const obj = {};
|
|
225
|
-
for (const ik of Object.keys(instVal)) {
|
|
226
|
-
if (ik in tmplVal) {
|
|
227
|
-
obj[ik] = instVal[ik];
|
|
228
|
-
if (JSON.stringify(instVal[ik]) !== JSON.stringify(tmplVal[ik])) {
|
|
229
|
-
kept.push(`${ik} (instance ${formatVal(instVal[ik])} vs template ${formatVal(tmplVal[ik])})`);
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
else {
|
|
233
|
-
obj[ik] = instVal[ik];
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
for (const tk of Object.keys(tmplVal)) {
|
|
237
|
-
if (!(tk in instVal)) {
|
|
238
|
-
obj[tk] = tmplVal[tk];
|
|
239
|
-
adds.push(tk);
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
result[k] = obj;
|
|
243
|
-
if (adds.length > 0) {
|
|
244
|
-
notes.push(`${k}: added ${adds.length} from template (${adds.join(', ')})`);
|
|
245
|
-
}
|
|
246
|
-
for (const keep of kept) {
|
|
247
|
-
notes.push(`${k}: kept instance version of ${keep}`);
|
|
248
|
-
}
|
|
249
|
-
continue;
|
|
250
|
-
}
|
|
251
|
-
if (isPlainObject(instVal) && isPlainObject(tmplVal)) {
|
|
252
|
-
result[k] = deepMergeKeepInstance(instVal, tmplVal);
|
|
253
|
-
continue;
|
|
254
|
-
}
|
|
255
|
-
if (Array.isArray(instVal) && Array.isArray(tmplVal)) {
|
|
256
|
-
result[k] = unionArray(instVal, tmplVal);
|
|
257
|
-
continue;
|
|
258
|
-
}
|
|
259
|
-
result[k] = instVal;
|
|
260
|
-
}
|
|
261
|
-
if (notes.length === 0)
|
|
262
|
-
notes.push('no changes');
|
|
263
|
-
let serialized = JSON.stringify(result, null, indent);
|
|
264
|
-
if (hasTrailingNewline)
|
|
265
|
-
serialized += '\n';
|
|
266
|
-
return { ok: true, merged: serialized, notes };
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
exports.JsonMerger = JsonMerger;
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
export interface MergeContext {
|
|
2
|
-
/** Relative path inside instance, e.g. 'web/package.json' */
|
|
3
|
-
filePath: string;
|
|
4
|
-
/** Absolute path to instance file */
|
|
5
|
-
instancePath: string;
|
|
6
|
-
/** Absolute path to template file */
|
|
7
|
-
templatePath: string;
|
|
8
|
-
instanceContent: string;
|
|
9
|
-
templateContent: string;
|
|
10
|
-
/** Optional per-merger policy values, dot-namespaced keys e.g. 'json.scripts': 'preserve-instance' */
|
|
11
|
-
policies?: Record<string, string>;
|
|
12
|
-
}
|
|
13
|
-
export declare type MergeOk = {
|
|
14
|
-
ok: true;
|
|
15
|
-
/** Final merged content to write to instance file */
|
|
16
|
-
merged: string;
|
|
17
|
-
/** Human-readable lines summarising what the merger did */
|
|
18
|
-
notes: string[];
|
|
19
|
-
};
|
|
20
|
-
export declare type MergeFail = {
|
|
21
|
-
ok: false;
|
|
22
|
-
/** Why this merger could not produce a result; caller should fall back */
|
|
23
|
-
reason: string;
|
|
24
|
-
};
|
|
25
|
-
export declare type MergeResult = MergeOk | MergeFail;
|
|
26
|
-
export interface Merger {
|
|
27
|
-
/** Unique id, e.g. 'json' | 'ts-module' | 'prisma' | 'env' | 'skip' */
|
|
28
|
-
readonly name: string;
|
|
29
|
-
merge(ctx: MergeContext): Promise<MergeResult> | MergeResult;
|
|
30
|
-
}
|
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PrismaMerger = void 0;
|
|
4
|
-
const BLOCK_HEADER_RE = /^(model|enum|generator|datasource|type|view)\s+(\w+)\s*\{/;
|
|
5
|
-
function parseBlocks(content) {
|
|
6
|
-
const lines = content.split('\n');
|
|
7
|
-
const blocks = [];
|
|
8
|
-
let prefixLines = [];
|
|
9
|
-
let i = 0;
|
|
10
|
-
while (i < lines.length) {
|
|
11
|
-
const line = lines[i];
|
|
12
|
-
const m = line.match(BLOCK_HEADER_RE);
|
|
13
|
-
if (m) {
|
|
14
|
-
const kind = m[1];
|
|
15
|
-
const name = m[2];
|
|
16
|
-
let depth = 0;
|
|
17
|
-
const blockLines = [];
|
|
18
|
-
let endIdx = -1;
|
|
19
|
-
for (let j = i; j < lines.length; j++) {
|
|
20
|
-
const l = lines[j];
|
|
21
|
-
for (const ch of l) {
|
|
22
|
-
if (ch === '{')
|
|
23
|
-
depth++;
|
|
24
|
-
else if (ch === '}') {
|
|
25
|
-
depth--;
|
|
26
|
-
if (depth < 0) {
|
|
27
|
-
return { ok: false, error: 'unbalanced braces' };
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
blockLines.push(l);
|
|
32
|
-
if (depth === 0) {
|
|
33
|
-
endIdx = j;
|
|
34
|
-
break;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
if (endIdx === -1) {
|
|
38
|
-
return { ok: false, error: 'unbalanced braces' };
|
|
39
|
-
}
|
|
40
|
-
blocks.push({
|
|
41
|
-
kind,
|
|
42
|
-
name,
|
|
43
|
-
prefix: prefixLines.join('\n'),
|
|
44
|
-
content: blockLines.join('\n'),
|
|
45
|
-
});
|
|
46
|
-
prefixLines = [];
|
|
47
|
-
i = endIdx + 1;
|
|
48
|
-
}
|
|
49
|
-
else {
|
|
50
|
-
prefixLines.push(line);
|
|
51
|
-
i++;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
return { ok: true, blocks, trailing: prefixLines.join('\n') };
|
|
55
|
-
}
|
|
56
|
-
class PrismaMerger {
|
|
57
|
-
constructor() {
|
|
58
|
-
this.name = 'prisma';
|
|
59
|
-
}
|
|
60
|
-
merge(ctx) {
|
|
61
|
-
const instParsed = parseBlocks(ctx.instanceContent);
|
|
62
|
-
if (!instParsed.ok) {
|
|
63
|
-
return { ok: false, reason: instParsed.error };
|
|
64
|
-
}
|
|
65
|
-
const tmplParsed = parseBlocks(ctx.templateContent);
|
|
66
|
-
if (!tmplParsed.ok) {
|
|
67
|
-
return { ok: false, reason: tmplParsed.error };
|
|
68
|
-
}
|
|
69
|
-
const instKeys = new Set();
|
|
70
|
-
const instKinds = new Set();
|
|
71
|
-
for (const b of instParsed.blocks) {
|
|
72
|
-
instKeys.add(`${b.kind}:${b.name}`);
|
|
73
|
-
instKinds.add(b.kind);
|
|
74
|
-
}
|
|
75
|
-
const notes = [];
|
|
76
|
-
const toAppend = [];
|
|
77
|
-
for (const tb of tmplParsed.blocks) {
|
|
78
|
-
if (tb.kind === 'generator' || tb.kind === 'datasource') {
|
|
79
|
-
if (instKinds.has(tb.kind)) {
|
|
80
|
-
notes.push(`kept instance ${tb.kind} ${tb.name}`);
|
|
81
|
-
continue;
|
|
82
|
-
}
|
|
83
|
-
toAppend.push(tb);
|
|
84
|
-
notes.push(`added ${tb.kind} ${tb.name} from template`);
|
|
85
|
-
continue;
|
|
86
|
-
}
|
|
87
|
-
const key = `${tb.kind}:${tb.name}`;
|
|
88
|
-
if (instKeys.has(key)) {
|
|
89
|
-
notes.push(`kept instance version of ${tb.kind} ${tb.name}`);
|
|
90
|
-
}
|
|
91
|
-
else {
|
|
92
|
-
toAppend.push(tb);
|
|
93
|
-
notes.push(`added ${tb.kind} ${tb.name} from template`);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
let merged = ctx.instanceContent;
|
|
97
|
-
if (toAppend.length > 0) {
|
|
98
|
-
if (!merged.endsWith('\n'))
|
|
99
|
-
merged += '\n';
|
|
100
|
-
const parts = [];
|
|
101
|
-
for (const b of toAppend) {
|
|
102
|
-
const piece = (b.prefix ? b.prefix + '\n' : '') + b.content;
|
|
103
|
-
parts.push(piece);
|
|
104
|
-
}
|
|
105
|
-
merged += parts.join('\n') + '\n';
|
|
106
|
-
}
|
|
107
|
-
if (notes.length === 0)
|
|
108
|
-
notes.push('no changes');
|
|
109
|
-
return { ok: true, merged, notes };
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
exports.PrismaMerger = PrismaMerger;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { Merger } from './merger';
|
|
2
|
-
export interface MergerRule {
|
|
3
|
-
/** Glob pattern, e.g. '**\/*.module.ts', 'package.json', 'config/prisma/*.prisma' */
|
|
4
|
-
pattern: string;
|
|
5
|
-
/** Refers to a Merger registered by this name in the registry */
|
|
6
|
-
mergerName: string;
|
|
7
|
-
}
|
|
8
|
-
export declare class MergerRegistry {
|
|
9
|
-
private mergers;
|
|
10
|
-
private rules;
|
|
11
|
-
/** Register a merger keyed by merger.name. Replaces any existing entry. */
|
|
12
|
-
register(merger: Merger): void;
|
|
13
|
-
/** Append a rule. Order matters: first match wins in resolve(). */
|
|
14
|
-
addRule(rule: MergerRule): void;
|
|
15
|
-
/** Clear all rules (mergers stay registered). Used when user config replaces defaults. */
|
|
16
|
-
resetRules(): void;
|
|
17
|
-
/**
|
|
18
|
-
* Resolve a Merger for the given file path by matching against rules in
|
|
19
|
-
* insertion order. Returns null if no rule matches OR if the matched rule
|
|
20
|
-
* names a merger that hasn't been registered.
|
|
21
|
-
*/
|
|
22
|
-
resolve(filePath: string): Merger | null;
|
|
23
|
-
/** Look up a merger by name. */
|
|
24
|
-
getMerger(name: string): Merger | null;
|
|
25
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MergerRegistry = void 0;
|
|
4
|
-
const glob_1 = require("./glob");
|
|
5
|
-
class MergerRegistry {
|
|
6
|
-
constructor() {
|
|
7
|
-
this.mergers = new Map();
|
|
8
|
-
this.rules = [];
|
|
9
|
-
}
|
|
10
|
-
/** Register a merger keyed by merger.name. Replaces any existing entry. */
|
|
11
|
-
register(merger) {
|
|
12
|
-
this.mergers.set(merger.name, merger);
|
|
13
|
-
}
|
|
14
|
-
/** Append a rule. Order matters: first match wins in resolve(). */
|
|
15
|
-
addRule(rule) {
|
|
16
|
-
this.rules.push(rule);
|
|
17
|
-
}
|
|
18
|
-
/** Clear all rules (mergers stay registered). Used when user config replaces defaults. */
|
|
19
|
-
resetRules() {
|
|
20
|
-
this.rules = [];
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Resolve a Merger for the given file path by matching against rules in
|
|
24
|
-
* insertion order. Returns null if no rule matches OR if the matched rule
|
|
25
|
-
* names a merger that hasn't been registered.
|
|
26
|
-
*/
|
|
27
|
-
resolve(filePath) {
|
|
28
|
-
var _a;
|
|
29
|
-
for (const rule of this.rules) {
|
|
30
|
-
if ((0, glob_1.globMatch)(filePath, rule.pattern)) {
|
|
31
|
-
return (_a = this.mergers.get(rule.mergerName)) !== null && _a !== void 0 ? _a : null;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
return null;
|
|
35
|
-
}
|
|
36
|
-
/** Look up a merger by name. */
|
|
37
|
-
getMerger(name) {
|
|
38
|
-
var _a;
|
|
39
|
-
return (_a = this.mergers.get(name)) !== null && _a !== void 0 ? _a : null;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
exports.MergerRegistry = MergerRegistry;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { MergeContext, MergeResult, Merger } from './merger';
|
|
2
|
-
/**
|
|
3
|
-
* Smart merger for NestJS-style `*.module.ts` files.
|
|
4
|
-
*
|
|
5
|
-
* Strategy: extract symbols from template's `@Module(...)` metadata arrays
|
|
6
|
-
* (imports/providers/controllers/exports) and missing top-level `import { ... } from '...'`
|
|
7
|
-
* lines, then insert each missing item into the instance file. Existing items are
|
|
8
|
-
* preserved. Method bodies and other class members are not touched.
|
|
9
|
-
*
|
|
10
|
-
* Falls back (returns `{ok: false}`) when the instance has no `@Module` decorator
|
|
11
|
-
* or when AST parsing/insertion throws.
|
|
12
|
-
*/
|
|
13
|
-
export declare class TsModuleMerger implements Merger {
|
|
14
|
-
readonly name = "ts-module";
|
|
15
|
-
merge(ctx: MergeContext): MergeResult;
|
|
16
|
-
}
|