@abapify/adt-plugin-abapgit 0.4.29 → 0.4.32

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 +1 @@
1
- {"version":3,"file":"index.d.mts","names":["AdtPlugin","AbapObjectType"],"sources":["../src/lib/format-plugin.ts","../src/lib/folder-logic.ts","../src/lib/abapgit.ts","../src/lib/handlers/abapgit-schema.ts","../src/lib/handlers/base.ts","../src/lib/filename-parser.ts","../src/lib/handlers/xml-format.ts"],"mappings":";;;;cAgGa,qBAAqB;;;;;;;;;KCvFtB;;;;iBA6CI,qBAAqB;EACnC,aAAa;EACb;;;;;;;;;;;;;;;;iBAsBc,sBACd,iBACA,aAAa,aACb;;;;;;;;;;;;;iBA2Cc,0BACd,oBACA,gBACA,aAAa;;;;;;cCwBF,eAAeA;;;;;;;;UClIX,cACf,OACA,SACA,UAAU,aAAa,oBACf,YAAY,OAAO;;WAElB,SAAS;;;KA2CR,gBAAgB,KAC1B,UAAU,6BAA6B,KAAK;;;;;KC/ClC,aAAa,KACvB,UAAU,gBAAgB,UAAU,KAAK;;;;KAsB/BC;;;;UAKK;;EAEf;;EAEA;;EAEA,WAAW;;;;;;;;UASI,cACf,UAAU,YAAY,WACtB,gBAAgB,kCAAkC;;WAMzC,MAAMA;;WAEN;;WAEA,QAAQ;;WAER,oBAAoB;;WAEpB;;EAET,UACE,QAAQ,GACR,UAAU,yBACT,QAAQ;;;;;EAKX,aACE,QAAQ,gBAAgB,WACvB,QAAQ,aAAa;IAAQ;;;;;;;EAOhC,aAAa,MAAM,0BAA0B,QAAQ,aAAa;IAChE;;;;;;EAOF,YAAY,QAAQ,GAAG,SAAS;;;;;;;;;iBAyBlB,WAAW,MAAMA,mBAAiB;;;;;;iBASlC,YAAY,MAAMA;;;;iBAOlB,qBAAqBA;;;;;;;;;;;;;;;;;;;;;iBCjIrB,qBAAqB;EACnC;EACA;EACA;EACA;;;;;;;;;;;;;;;;;;;;;;;;iBC+Bc,oBAAoB;;;;;;;iBA8DpB,oBAAoB;;;;;;iBA8BpB,iBAAiB"}
1
+ {"version":3,"file":"index.d.mts","names":["AdtPlugin","AbapObjectType"],"sources":["../src/lib/format-plugin.ts","../src/lib/folder-logic.ts","../src/lib/abapgit.ts","../src/lib/handlers/abapgit-schema.ts","../src/lib/handlers/base.ts","../src/lib/filename-parser.ts","../src/lib/handlers/xml-format.ts"],"mappings":";;;;cAgGa,qBAAqB;;;;;;;;;KCvFtB;;;;iBA6CI,qBAAqB;EACnC,aAAa;EACb;;;;;;;;;;;;;;;;iBAsBc,sBACd,iBACA,aAAa,aACb;;;;;;;;;;;;;iBA2Cc,0BACd,oBACA,gBACA,aAAa;;;;;;cC2EF,eAAeA;;;;;;;;UCrLX,cACf,OACA,SACA,UAAU,aAAa,oBACf,YAAY,OAAO;;WAElB,SAAS;;;KA2CR,gBAAgB,KAC1B,UAAU,6BAA6B,KAAK;;;;;KC/ClC,aAAa,KACvB,UAAU,gBAAgB,UAAU,KAAK;;;;KAsB/BC;;;;UAKK;;EAEf;;EAEA;;EAEA,WAAW;;;;;;;;UASI,cACf,UAAU,YAAY,WACtB,gBAAgB,kCAAkC;;WAMzC,MAAMA;;WAEN;;WAEA,QAAQ;;WAER,oBAAoB;;WAEpB;;EAET,UACE,QAAQ,GACR,UAAU,yBACT,QAAQ;;;;;EAKX,aACE,QAAQ,gBAAgB,WACvB,QAAQ,aAAa;IAAQ;;;;;;;EAOhC,aAAa,MAAM,0BAA0B,QAAQ,aAAa;IAChE;;;;;;EAOF,YAAY,QAAQ,GAAG,SAAS;;;;;;;;;iBAyBlB,WAAW,MAAMA,mBAAiB;;;;;;iBASlC,YAAY,MAAMA;;;;iBAOlB,qBAAqBA;;;;;;;;;;;;;;;;;;;;;iBCjIrB,qBAAqB;EACnC;EACA;EACA;EACA;;;;;;;;;;;;;;;;;;;;;;;;iBC+Bc,oBAAoB;;;;;;;iBA8DpB,oBAAoB;;;;;;iBA8BpB,iBAAiB"}
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { FormatMaterializationError, createPlugin, registerFormatPlugin } from "@abapify/adt-plugin";
2
- import { basename, dirname, isAbsolute, join, posix, relative, sep } from "node:path";
2
+ import { basename, dirname, isAbsolute, join, posix, relative, resolve, sep } from "node:path";
3
3
  import { AdkClass, AdkDataElement, AdkDomain, AdkInclude, AdkInterface, AdkPackage, AdkStructure, AdkTable, AdkTableType, createAdk, getMainType, getTypeForKind } from "@abapify/adk";
4
4
  import { typedSchema } from "@abapify/ts-xsd";
5
5
  import { parse } from "@abapify/acds";
@@ -26011,7 +26011,7 @@ var AbapGitSerializer = class {
26011
26011
 
26012
26012
  // src/lib/abapgit.ts
26013
26013
  const serializer = new AbapGitSerializer();
26014
- let currentFolderLogic = "prefix";
26014
+ const folderLogicByTarget = /* @__PURE__ */ new Map();
26015
26015
  /**
26016
26016
  * Recursively collect all file paths under a directory.
26017
26017
  */
@@ -26024,14 +26024,22 @@ function walkDir(dir, results = []) {
26024
26024
  }
26025
26025
  return results;
26026
26026
  }
26027
+ function getObjectFilePrefix(filePath) {
26028
+ const fname = basename(filePath).toLowerCase();
26029
+ const first = fname.indexOf(".");
26030
+ if (first === -1) return void 0;
26031
+ const second = fname.indexOf(".", first + 1);
26032
+ if (second === -1) return void 0;
26033
+ return fname.substring(0, second + 1);
26034
+ }
26027
26035
  /**
26028
26036
  * Lazy per-srcDir file index.
26029
26037
  *
26030
26038
  * Maps srcDir → (prefix → [absolute file paths]), where prefix is
26031
- * `${name}.${type}.` in lower-case. Built at most once per srcDir per
26032
- * process, so the O(repo-size) directory walk is amortised across all
26033
- * `format.delete()` calls in a single import run instead of repeated for
26034
- * every deleted object.
26039
+ * `${name}.${type}.` in lower-case. Reused between plugin writes so a
26040
+ * deletion batch avoids repeating the O(repo-size) directory walk for
26041
+ * every deleted object. Successful writes update a built index; failures
26042
+ * invalidate it because serialization may have left partial files.
26035
26043
  */
26036
26044
  const srcDirIndexCache = /* @__PURE__ */ new Map();
26037
26045
  function getOrBuildSrcIndex(srcDir) {
@@ -26039,12 +26047,8 @@ function getOrBuildSrcIndex(srcDir) {
26039
26047
  if (cached) return cached;
26040
26048
  const index = /* @__PURE__ */ new Map();
26041
26049
  for (const filePath of walkDir(srcDir)) {
26042
- const fname = basename(filePath).toLowerCase();
26043
- const first = fname.indexOf(".");
26044
- if (first === -1) continue;
26045
- const second = fname.indexOf(".", first + 1);
26046
- if (second === -1) continue;
26047
- const key = fname.substring(0, second + 1);
26050
+ const key = getObjectFilePrefix(filePath);
26051
+ if (!key) continue;
26048
26052
  const bucket = index.get(key);
26049
26053
  if (bucket) bucket.push(filePath);
26050
26054
  else index.set(key, [filePath]);
@@ -26052,6 +26056,27 @@ function getOrBuildSrcIndex(srcDir) {
26052
26056
  srcDirIndexCache.set(srcDir, index);
26053
26057
  return index;
26054
26058
  }
26059
+ function isWithinDirectory(dir, absolutePath) {
26060
+ const relativePath = relative(dir, absolutePath);
26061
+ return relativePath.length > 0 && !isAbsolute(relativePath) && relativePath !== ".." && !relativePath.startsWith(`..${sep}`);
26062
+ }
26063
+ function addPathToSrcIndex(index, key, absolutePath) {
26064
+ const paths = index.get(key) ?? [];
26065
+ if (!paths.includes(absolutePath)) paths.push(absolutePath);
26066
+ index.set(key, paths);
26067
+ }
26068
+ function addFileToBuiltSrcIndex(srcDir, index, filePath) {
26069
+ const absolutePath = resolve(filePath);
26070
+ if (!isWithinDirectory(srcDir, absolutePath)) return false;
26071
+ const key = getObjectFilePrefix(absolutePath);
26072
+ if (key) addPathToSrcIndex(index, key, absolutePath);
26073
+ return true;
26074
+ }
26075
+ function addFilesToBuiltSrcIndex(srcDir, files) {
26076
+ const index = srcDirIndexCache.get(srcDir);
26077
+ if (!index) return;
26078
+ if (files.some((filePath) => !addFileToBuiltSrcIndex(srcDir, index, filePath))) srcDirIndexCache.delete(srcDir);
26079
+ }
26055
26080
  /**
26056
26081
  * Find all abapGit files for a given object name and type.
26057
26082
  *
@@ -26105,15 +26130,19 @@ const abapGitPlugin = createPlugin({
26105
26130
  },
26106
26131
  format: {
26107
26132
  async import(object, targetPath, context) {
26133
+ let serializationCompleted = false;
26108
26134
  try {
26109
26135
  const objPackage = object.type?.startsWith("DEVC") ? object.name : object.package || object.name || "ROOT";
26110
26136
  const packagePath = await context.resolvePackagePath(objPackage);
26111
26137
  const folderLogic = resolveFolderLogic(context, targetPath);
26112
- currentFolderLogic = folderLogic;
26138
+ folderLogicByTarget.set(resolve(targetPath), folderLogic);
26113
26139
  const packageDir = calculatePackageDir(packagePath, folderLogic);
26140
+ const files = await serializer.serializeObjectPublic(object, targetPath, packageDir);
26141
+ addFilesToBuiltSrcIndex(resolve(targetPath, "src"), files);
26142
+ serializationCompleted = true;
26114
26143
  return {
26115
26144
  success: true,
26116
- filesCreated: await serializer.serializeObjectPublic(object, targetPath, packageDir)
26145
+ filesCreated: files
26117
26146
  };
26118
26147
  } catch (error) {
26119
26148
  return {
@@ -26121,6 +26150,8 @@ const abapGitPlugin = createPlugin({
26121
26150
  filesCreated: [],
26122
26151
  errors: [error instanceof Error ? error.message : String(error)]
26123
26152
  };
26153
+ } finally {
26154
+ if (!serializationCompleted) srcDirIndexCache.delete(resolve(targetPath, "src"));
26124
26155
  }
26125
26156
  },
26126
26157
  /**
@@ -26146,7 +26177,8 @@ const abapGitPlugin = createPlugin({
26146
26177
  */
26147
26178
  async delete(objectRef, targetPath, _context) {
26148
26179
  try {
26149
- const matchedFiles = findObjectFiles(join(targetPath, "src"), objectRef.name, objectRef.type);
26180
+ const srcDir = resolve(targetPath, "src");
26181
+ const matchedFiles = findObjectFiles(srcDir, objectRef.name, objectRef.type);
26150
26182
  const filesRemoved = [];
26151
26183
  const errors = [];
26152
26184
  for (const filePath of matchedFiles) try {
@@ -26159,6 +26191,7 @@ const abapGitPlugin = createPlugin({
26159
26191
  }
26160
26192
  errors.push(error instanceof Error ? `Failed to delete ${relative(targetPath, filePath)}: ${error.message}` : `Failed to delete ${relative(targetPath, filePath)}: ${String(error)}`);
26161
26193
  }
26194
+ srcDirIndexCache.get(srcDir)?.set(`${objectRef.name.toLowerCase()}.${objectRef.type.toLowerCase()}.`, matchedFiles.filter((filePath) => existsSync(filePath)));
26162
26195
  return {
26163
26196
  success: errors.length === 0,
26164
26197
  filesRemoved,
@@ -26174,10 +26207,16 @@ const abapGitPlugin = createPlugin({
26174
26207
  }
26175
26208
  },
26176
26209
  hooks: { async afterImport(targetPath) {
26177
- mkdirSync(targetPath, { recursive: true });
26178
- const abapgitXmlPath = join(targetPath, ".abapgit.xml");
26179
- const abapgitXmlContent = generateAbapGitXml(currentFolderLogic);
26180
- writeFileSync(abapgitXmlPath, abapgitXmlContent, "utf-8");
26210
+ const target = resolve(targetPath);
26211
+ const folderLogic = folderLogicByTarget.get(target) ?? readFolderLogicFromExistingRepo(targetPath) ?? "prefix";
26212
+ try {
26213
+ mkdirSync(targetPath, { recursive: true });
26214
+ const abapgitXmlPath = join(targetPath, ".abapgit.xml");
26215
+ writeFileSync(abapgitXmlPath, generateAbapGitXml(folderLogic), "utf-8");
26216
+ } finally {
26217
+ folderLogicByTarget.delete(target);
26218
+ srcDirIndexCache.delete(resolve(targetPath, "src"));
26219
+ }
26181
26220
  } }
26182
26221
  });
26183
26222