@nikelyh/metamorph 2.0.11 → 2.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.
@@ -0,0 +1,61 @@
1
+ // ../application/src/migration/registry.ts
2
+ import * as path from "path";
3
+ var plugins = [];
4
+ function registerMigrationPlugin(plugin) {
5
+ if (plugins.some((existing) => existing.id === plugin.id)) return;
6
+ plugins.push(plugin);
7
+ }
8
+ function matchingMigrationPlugins(source, target, layer) {
9
+ const src = source.toLowerCase();
10
+ const tgt = target.toLowerCase();
11
+ return plugins.filter((plugin) => {
12
+ if (plugin.source && plugin.source.toLowerCase() !== src) return false;
13
+ if (plugin.target && plugin.target.toLowerCase() !== tgt) return false;
14
+ if (plugin.layer && layer && plugin.layer !== layer) return false;
15
+ return true;
16
+ });
17
+ }
18
+ function collectFileHints(filePath, ctx, layer) {
19
+ return matchingMigrationPlugins(ctx.source, ctx.target, layer).map((plugin) => plugin.fileHint?.(filePath, ctx) ?? "").filter(Boolean).join("\n");
20
+ }
21
+ function collectShadowIssues(shadowRoot, ctx, layer) {
22
+ return matchingMigrationPlugins(ctx.source, ctx.target, layer).flatMap(
23
+ (plugin) => plugin.verifyShadow?.(shadowRoot, ctx) ?? []
24
+ );
25
+ }
26
+ function resolveShadowPath(shadowRoot, filePath) {
27
+ return path.isAbsolute(filePath) ? filePath : path.join(shadowRoot, filePath);
28
+ }
29
+ function collectRepairTargets(shadowRoot, ctx, options = {}) {
30
+ const seen = /* @__PURE__ */ new Set();
31
+ const out = [];
32
+ const add = (filePath) => {
33
+ if (!filePath) return;
34
+ const abs = path.resolve(resolveShadowPath(shadowRoot, filePath));
35
+ const key = abs.replace(/\\/g, "/").toLowerCase();
36
+ if (seen.has(key)) return;
37
+ seen.add(key);
38
+ out.push(abs);
39
+ };
40
+ for (const file of options.implicated ?? []) add(file);
41
+ for (const issue of options.issues ?? []) add(issue.filePath);
42
+ const hasPinpoint = (options.implicated?.length ?? 0) > 0 || (options.issues?.length ?? 0) > 0;
43
+ if (!hasPinpoint) {
44
+ for (const plugin of matchingMigrationPlugins(ctx.source, ctx.target, options.layer)) {
45
+ for (const file of plugin.repairTargets?.(shadowRoot, ctx) ?? []) add(file);
46
+ }
47
+ if (options.catalog?.filesToScaffold) {
48
+ for (const rel of Object.keys(options.catalog.filesToScaffold)) add(path.join(shadowRoot, rel));
49
+ }
50
+ add(path.join(shadowRoot, "package.json"));
51
+ }
52
+ return out;
53
+ }
54
+
55
+ export {
56
+ registerMigrationPlugin,
57
+ matchingMigrationPlugins,
58
+ collectFileHints,
59
+ collectShadowIssues,
60
+ collectRepairTargets
61
+ };