@layerzerolabs/evm-sdks-build 3.0.16 → 3.0.18-movement.0

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 CHANGED
@@ -1,5 +1,12 @@
1
1
  # @layerzerolabs/evm-sdks-build
2
2
 
3
+ ## 3.0.17
4
+
5
+ ### Patch Changes
6
+
7
+ - 40f2269: islander mainnet
8
+ - 40f2269: testnets
9
+
3
10
  ## 3.0.16
4
11
 
5
12
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -52,8 +52,7 @@ var Semaphore = class {
52
52
  * Releases a lock on the semaphore.
53
53
  */
54
54
  release() {
55
- if (this.counter == 0)
56
- return;
55
+ if (this.counter == 0) return;
57
56
  this.counter--;
58
57
  const resolve = this.queue.shift() ?? (() => void 0);
59
58
  resolve();
@@ -70,8 +69,7 @@ async function parallelProcess(filePath, semaphore, errors) {
70
69
  await semaphore.acquire();
71
70
  try {
72
71
  const { abi } = await readJSONFile(filePath);
73
- if (abi === void 0 || !Array.isArray(abi))
74
- return;
72
+ if (abi === void 0 || !Array.isArray(abi)) return;
75
73
  abi.filter(({ type }) => type === "error").forEach((obj) => {
76
74
  const frag = ErrorFragment.from(obj);
77
75
  errors.full.add(frag.format(FormatTypes.full));
@@ -104,8 +102,7 @@ async function populateErrors(callerRootFile, destPath = "src/errors", maxConcur
104
102
  await promises.writeFile(path2__default.default.join(errorDir, "errorSelectors.json"), JSON.stringify(sortedSelectors, null, 2));
105
103
  }
106
104
  var buildPaths = (node) => {
107
- if (typeof node === "string")
108
- return [node];
105
+ if (typeof node === "string") return [node];
109
106
  const paths = [];
110
107
  if (Array.isArray(node)) {
111
108
  for (const contract of node) {
@@ -143,5 +140,5 @@ exports.Semaphore = Semaphore;
143
140
  exports.copyPackageFiles = copyPackageFiles;
144
141
  exports.populate = populate;
145
142
  exports.populateErrors = populateErrors;
146
- //# sourceMappingURL=out.js.map
143
+ //# sourceMappingURL=index.cjs.map
147
144
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/populate.ts","../src/errors.ts","../src/semaphore.ts","../src/copyFiles.ts"],"names":["mkdir","path","copyFile","createRequire","glob"],"mappings":";AAAA,SAAS,UAAU,aAAa;AAChC,SAAS,qBAAqB;AAC9B,OAAO,UAAU;AAEjB,SAAS,YAAY;AAiBrB,eAAsB,SAAS,aAA0B,gBAAuC;AAC5F,QAAM,gBAAgB,KAAK,QAAQ,cAAc;AACjD,aAAW,CAAC,YAAY,QAAQ,KAAK,OAAO,QAAQ,WAAW,GAAG;AAC9D,UAAM,SAAS,KAAK,QAAQ,cAAc,cAAc,EAAE,QAAQ,GAAG,UAAU,eAAe,CAAC;AAC/F,eAAW,CAAC,UAAU,QAAQ,KAAK,OAAO,QAAQ,QAAQ,GAAG;AACzD,YAAM,QAAQ,MAAM,KAAK,SAAS,IAAI,CAAC,MAAM,KAAK,KAAK,QAAQ,UAAU,CAAC,CAAC,CAAC;AAC5E,UAAI,QAAQ;AACZ,iBAAW,QAAQ,OAAO;AACtB,cAAM,eAAe,KAAK,SAAS,QAAQ,IAAI;AAC/C,cAAM,WAAW,KAAK,KAAK,eAAe,YAAY;AACtD,cAAM,MAAM,KAAK,QAAQ,QAAQ,GAAG,EAAE,WAAW,KAAK,CAAC;AACvD,cAAM,SAAS,MAAM,QAAQ;AAC7B;AAAA,MACJ;AACA,cAAQ,IAAI,UAAU,KAAK,IAAI,QAAQ,SAAS,UAAU,EAAE;AAAA,IAChE;AAAA,EACJ;AACJ;;;ACtCA,SAAS,SAAAA,QAAO,UAAU,SAAS,iBAAiB;AACpD,OAAOC,WAAU;AAEjB,SAAS,aAAa;;;ACCf,IAAM,YAAN,MAAgB;AAAA,EAGnB,YAAoB,KAAa;AAAb;AAFpB,SAAQ,UAAU;AAClB,SAAQ,QAAwB,CAAC;AAAA,EACC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOlC,MAAa,UAAyB;AAClC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AAI,GAAG;AACrB,eAAW,YAAY,MAAM;AACzB,YAAM,KAAK,GAAG,WAAW,QAAQ,CAAC;AAAA,IACtC;AAAA,EACJ,OAAO;AAEH,eAAW,CAAC,QAAQ,KAAK,KAAK,OAAO,QAAQ,IAAI,GAAG;AAChD,YAAM,WAAW,WAAW,KAAK;AACjC,eAAS,QAAQ,CAACH,UAAS,MAAM,KAAK,GAAG,MAAM,IAAIA,KAAI,EAAE,CAAC;AAAA,IAC9D;AAAA,EACJ;AACA,SAAO;AACX;AAYA,eAAsB,iBAAiB,cAA4B,gBAAuC;AACtG,QAAM,gBAAgBA,MAAK,QAAQ,cAAc;AACjD,aAAW,CAAC,YAAY,QAAQ,KAAK,OAAO,QAAQ,YAAY,GAAG;AAC/D,UAAM,WAAW,WAAW,QAAQ;AACpC,UAAM,SAASA,MAAK,QAAQE,eAAc,cAAc,EAAE,QAAQ,GAAG,UAAU,eAAe,CAAC;AAC/F,QAAI,QAAQ;AACZ,eAAW,cAAc,UAAU;AAC/B,YAAM,QAAQ,MAAMC,MAAKH,MAAK,KAAK,QAAQ,UAAU,CAAC;AACtD,iBAAW,QAAQ,OAAO;AACtB,cAAM,eAAeA,MAAK,SAAS,QAAQ,IAAI;AAC/C,cAAM,WAAWA,MAAK,KAAK,eAAe,YAAY;AACtD,cAAMD,OAAMC,MAAK,QAAQ,QAAQ,GAAG,EAAE,WAAW,KAAK,CAAC;AACvD,cAAMC,UAAS,MAAM,QAAQ;AAC7B;AAAA,MACJ;AAAA,IACJ;AACA,YAAQ,IAAI,UAAU,KAAK,eAAe,UAAU,EAAE;AAAA,EAC1D;AACJ","sourcesContent":["import { copyFile, mkdir } from 'fs/promises'\nimport { createRequire } from 'module'\nimport path from 'path'\n\nimport { glob } from 'glob'\n\ntype AllowedFiles = 'artifacts' | 'deployments' | 'artifacts-tron' | 'artifacts-zk'\n\nexport type SrcFiles = { [key in AllowedFiles]?: readonly string[] }\nexport interface CopyTargets {\n [key: string]: SrcFiles\n}\n\n/**\n * Populates the target directory with files from the specified source packages.\n * This function copies files from the source packages to the target directory based on the provided patterns.\n *\n * @param {CopyTargets} copyTargets - An object mapping source packages to their respective file patterns.\n * @param {string} callerRootFile - The absolute path to the root file of the caller, used to determine the root directory into which the files will be copied.\n * @returns {Promise<void>} A promise that resolves when the operation is complete.\n */\nexport async function populate(copyTargets: CopyTargets, callerRootFile: string): Promise<void> {\n const callerRootDir = path.dirname(callerRootFile)\n for (const [srcPackage, srcFiles] of Object.entries(copyTargets)) {\n const srcDir = path.dirname(createRequire(callerRootFile).resolve(`${srcPackage}/package.json`))\n for (const [filePath, patterns] of Object.entries(srcFiles)) {\n const files = await glob(patterns.map((p) => path.join(srcDir, filePath, p)))\n let count = 0\n for (const file of files) {\n const relativePath = path.relative(srcDir, file)\n const destPath = path.join(callerRootDir, relativePath)\n await mkdir(path.dirname(destPath), { recursive: true })\n await copyFile(file, destPath)\n count++\n }\n console.log(`Copied ${count} ${filePath} from ${srcPackage}`)\n }\n }\n}\n","import { mkdir, readFile, readdir, writeFile } from 'fs/promises'\nimport path from 'path'\n\nimport { utils } from 'ethers'\n\nimport { Semaphore } from './semaphore'\n\nconst { ErrorFragment, FormatTypes, Interface } = utils\n\n/**\n * Asynchronously reads a JSON file from a given file path.\n * @param filePath - The path to the JSON file.\n * @returns {Promise<any>} A promise that resolves to the parsed JSON data.\n */\nasync function readJSONFile(filePath: string): Promise<any> {\n const data = await readFile(filePath, { encoding: 'utf8' })\n return JSON.parse(data)\n}\n\n/**\n * Processes ABI errors in parallel, controlled by a semaphore, and populates error collections.\n * @param {string} filePath - The file path to read.\n * @param {Semaphore} semaphore - Semaphore instance for concurrency control.\n * @param {Object} errors - Object to collect full errors and error selectors.\n * @param {Set<string>} errors.full - Set to collect full error definitions.\n * @param {Object.<string, string>} errors.selector - Object to collect error selectors.\n * @returns {Promise<void>} A promise that resolves when the operation is complete.\n */\nasync function parallelProcess(\n filePath: string,\n semaphore: Semaphore,\n errors: { full: Set<string>; selector: { [key: string]: string } }\n): Promise<void> {\n await semaphore.acquire()\n try {\n const { abi } = await readJSONFile(filePath)\n if (abi === undefined || !Array.isArray(abi)) return\n abi.filter(({ type }) => type === 'error').forEach((obj) => {\n const frag = ErrorFragment.from(obj)\n errors.full.add(frag.format(FormatTypes.full))\n errors.selector[Interface.getSighash(frag)] = frag.format(FormatTypes.sighash)\n })\n } finally {\n semaphore.release()\n }\n}\n\n/**\n * Populates error information from ABI files in parallel.\n * This function reads ABI files, processes them to extract error information,\n * and writes the combined and sorted errors to JSON files.\n *\n * @param {string} callerRootFile - The root file path to start the search for ABI files.\n * @param {string} [destPath='src/errors'] - The path relative to root to copy the files in.\n * @param {number} [maxConcurrent=50] - Maximum number of concurrent file processing operations.\n * @returns {Promise<void>} A promise that resolves when the operation is complete.\n */\nexport async function populateErrors(\n callerRootFile: string,\n destPath = 'src/errors',\n maxConcurrent = 50\n): Promise<void> {\n // Determining the directory paths from the caller's root file\n const callerRootDir = path.dirname(callerRootFile)\n const callerArtifactsPath = path.join(callerRootDir, 'artifacts')\n\n // Reading and filtering artifacts to process only JSON files\n const files = await readdir(callerArtifactsPath, { recursive: true })\n const jsonFiles = files.filter((file) => path.extname(file).toLowerCase() === '.json')\n\n const semaphore = new Semaphore(maxConcurrent)\n const errors = { full: new Set<string>(), selector: {} }\n\n // Parallel processing of files using the semaphore for concurrency control\n const filePromises = jsonFiles.map(async (file) =>\n parallelProcess(path.join(callerArtifactsPath, file), semaphore, errors)\n )\n await Promise.all(filePromises)\n\n // Sorting and organizing errors for output\n const { full, selector } = errors\n let sorter = new Intl.Collator('en', { caseFirst: 'upper', numeric: true })\n const sortedErrors = [...full].sort(sorter.compare)\n sorter = new Intl.Collator('en', { caseFirst: 'upper', numeric: false })\n const sortedSelectors = Object.fromEntries(Object.entries(selector).sort(([a], [b]) => sorter.compare(a, b)))\n const errorDir = path.join(callerRootDir, destPath)\n // Writing errors to files in the error directory\n await mkdir(errorDir, { recursive: true })\n await writeFile(path.join(errorDir, 'errors.json'), JSON.stringify(sortedErrors, null, 2))\n console.log(`Generated abi for ${sortedErrors.length} errors`)\n await writeFile(path.join(errorDir, 'errorSelectors.json'), JSON.stringify(sortedSelectors, null, 2))\n}\n","/**\n * Semaphore class for controlling access to a resource by multiple processes.\n * It maintains a counter and a queue for managing access.\n */\nexport class Semaphore {\n private counter = 0\n private queue: (() => void)[] = []\n constructor(private max: number) {}\n\n /**\n * Acquires a lock on the semaphore. If the semaphore is at its maximum,\n * the function will wait until it can acquire the lock.\n * @returns A promise that resolves when the lock has been acquired.\n */\n public async acquire(): Promise<void> {\n if (this.counter >= this.max) {\n await new Promise<void>((resolve) => this.queue.push(resolve))\n }\n this.counter++\n }\n\n /**\n * Releases a lock on the semaphore.\n */\n public release(): void {\n if (this.counter == 0) return\n this.counter--\n const resolve = this.queue.shift() ?? ((): undefined => undefined)\n resolve()\n }\n}\n","import { copyFile, mkdir } from 'fs/promises'\nimport { createRequire } from 'module'\nimport path from 'path'\n\nimport { glob } from 'glob'\n\ntype Package = string\ntype File = string\ntype Directory = (File | NestedDirectory)[]\ninterface NestedDirectory {\n [key: string]: Directory | NestedDirectory\n}\nexport interface PackageFiles {\n [key: Package]: NestedDirectory | Directory\n}\n\n/**\n * Recursively traverses a directory structure to build paths to leaf nodes.\n * @param node - A directory structure represented as a string (for files), an array (for directories), or an object (for nested directories).\n * @returns {string[]} An array of strings, each representing a path from the root to a leaf node.\n */\nexport const buildPaths = (node: NestedDirectory | Directory | File): string[] => {\n // base case, we're at a leaf node, return the filename\n if (typeof node === 'string') return [node]\n\n const paths: string[] = []\n // If the current node is an array, recursively process each file / nested dir\n if (Array.isArray(node)) {\n for (const contract of node) {\n paths.push(...buildPaths(contract))\n }\n } else {\n // Current node is a nested directory. Recursively process each entry.\n for (const [parent, child] of Object.entries(node)) {\n const children = buildPaths(child)\n children.forEach((path) => paths.push(`${parent}/${path}`))\n }\n }\n return paths\n}\n\n/**\n * Asynchronously copies files from source packages to a target root directory based on the provided directory structure.\n * This function iterates over each source package, resolves all file paths,\n * and copies each file to the corresponding location within the caller's root directory.\n *\n * @param {PackageFiles} packageFiles - An object mapping package names to their directory structures,\n * where each directory structure defines the files and nested directories to be copied.\n * @param {string} callerRootFile - The absolute path to the root file of the caller, used to determine the root directory into which the files will be copied.\n * @returns {Promise<void>} A promise that resolves when the operation is complete.\n */\nexport async function copyPackageFiles(packageFiles: PackageFiles, callerRootFile: string): Promise<void> {\n const callerRootDir = path.dirname(callerRootFile)\n for (const [srcPackage, srcFiles] of Object.entries(packageFiles)) {\n const allPaths = buildPaths(srcFiles)\n const srcDir = path.dirname(createRequire(callerRootFile).resolve(`${srcPackage}/package.json`))\n let count = 0\n for (const uniquePath of allPaths) {\n const files = await glob(path.join(srcDir, uniquePath))\n for (const file of files) {\n const relativePath = path.relative(srcDir, file)\n const destPath = path.join(callerRootDir, relativePath)\n await mkdir(path.dirname(destPath), { recursive: true })\n await copyFile(file, destPath)\n count++\n }\n }\n console.log(`Copied ${count} files from ${srcPackage}`)\n }\n}\n"]}
1
+ {"version":3,"sources":["../src/populate.ts","../src/semaphore.ts","../src/errors.ts","../src/copyFiles.ts"],"names":["path","createRequire","glob","mkdir","copyFile","utils","readFile","readdir","writeFile"],"mappings":";;;;;;;;;;;;;AAqBA,eAAsB,QAAA,CAAS,aAA0B,cAAuC,EAAA;AAC5F,EAAM,MAAA,aAAA,GAAgBA,sBAAK,CAAA,OAAA,CAAQ,cAAc,CAAA;AACjD,EAAA,KAAA,MAAW,CAAC,UAAY,EAAA,QAAQ,KAAK,MAAO,CAAA,OAAA,CAAQ,WAAW,CAAG,EAAA;AAC9D,IAAM,MAAA,MAAA,GAASA,sBAAK,CAAA,OAAA,CAAQC,sBAAc,CAAA,cAAc,EAAE,OAAQ,CAAA,CAAA,EAAG,UAAU,CAAA,aAAA,CAAe,CAAC,CAAA;AAC/F,IAAA,KAAA,MAAW,CAAC,QAAU,EAAA,QAAQ,KAAK,MAAO,CAAA,OAAA,CAAQ,QAAQ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AA;AACJ;AAEJ,IAAA,OAAA,CAAQ,GAAI,CAAA,CAAA,OAAA,EAAU,KAAK,CAAA,YAAA,EAAe,UAAU,CAAE,CAAA,CAAA;AAAA;AAE9D","file":"index.cjs","sourcesContent":["import { copyFile, mkdir } from 'fs/promises'\nimport { createRequire } from 'module'\nimport path from 'path'\n\nimport { glob } from 'glob'\n\ntype AllowedFiles = 'artifacts' | 'deployments' | 'artifacts-tron' | 'artifacts-zk'\n\nexport type SrcFiles = { [key in AllowedFiles]?: readonly string[] }\nexport interface CopyTargets {\n [key: string]: SrcFiles\n}\n\n/**\n * Populates the target directory with files from the specified source packages.\n * This function copies files from the source packages to the target directory based on the provided patterns.\n *\n * @param {CopyTargets} copyTargets - An object mapping source packages to their respective file patterns.\n * @param {string} callerRootFile - The absolute path to the root file of the caller, used to determine the root directory into which the files will be copied.\n * @returns {Promise<void>} A promise that resolves when the operation is complete.\n */\nexport async function populate(copyTargets: CopyTargets, callerRootFile: string): Promise<void> {\n const callerRootDir = path.dirname(callerRootFile)\n for (const [srcPackage, srcFiles] of Object.entries(copyTargets)) {\n const srcDir = path.dirname(createRequire(callerRootFile).resolve(`${srcPackage}/package.json`))\n for (const [filePath, patterns] of Object.entries(srcFiles)) {\n const files = await glob(patterns.map((p) => path.join(srcDir, filePath, p)))\n let count = 0\n for (const file of files) {\n const relativePath = path.relative(srcDir, file)\n const destPath = path.join(callerRootDir, relativePath)\n await mkdir(path.dirname(destPath), { recursive: true })\n await copyFile(file, destPath)\n count++\n }\n console.log(`Copied ${count} ${filePath} from ${srcPackage}`)\n }\n }\n}\n","/**\n * Semaphore class for controlling access to a resource by multiple processes.\n * It maintains a counter and a queue for managing access.\n */\nexport class Semaphore {\n private counter = 0\n private queue: (() => void)[] = []\n constructor(private max: number) {}\n\n /**\n * Acquires a lock on the semaphore. If the semaphore is at its maximum,\n * the function will wait until it can acquire the lock.\n * @returns A promise that resolves when the lock has been acquired.\n */\n public async acquire(): Promise<void> {\n if (this.counter >= this.max) {\n await new Promise<void>((resolve) => this.queue.push(resolve))\n }\n this.counter++\n }\n\n /**\n * Releases a lock on the semaphore.\n */\n public release(): void {\n if (this.counter == 0) return\n this.counter--\n const resolve = this.queue.shift() ?? ((): undefined => undefined)\n resolve()\n }\n}\n","import { mkdir, readFile, readdir, writeFile } from 'fs/promises'\nimport path from 'path'\n\nimport { utils } from 'ethers'\n\nimport { Semaphore } from './semaphore'\n\nconst { ErrorFragment, FormatTypes, Interface } = utils\n\n/**\n * Asynchronously reads a JSON file from a given file path.\n * @param filePath - The path to the JSON file.\n * @returns {Promise<any>} A promise that resolves to the parsed JSON data.\n */\nasync function readJSONFile(filePath: string): Promise<any> {\n const data = await readFile(filePath, { encoding: 'utf8' })\n return JSON.parse(data)\n}\n\n/**\n * Processes ABI errors in parallel, controlled by a semaphore, and populates error collections.\n * @param {string} filePath - The file path to read.\n * @param {Semaphore} semaphore - Semaphore instance for concurrency control.\n * @param {Object} errors - Object to collect full errors and error selectors.\n * @param {Set<string>} errors.full - Set to collect full error definitions.\n * @param {Object.<string, string>} errors.selector - Object to collect error selectors.\n * @returns {Promise<void>} A promise that resolves when the operation is complete.\n */\nasync function parallelProcess(\n filePath: string,\n semaphore: Semaphore,\n errors: { full: Set<string>; selector: { [key: string]: string } }\n): Promise<void> {\n await semaphore.acquire()\n try {\n const { abi } = await readJSONFile(filePath)\n if (abi === undefined || !Array.isArray(abi)) return\n abi.filter(({ type }) => type === 'error').forEach((obj) => {\n const frag = ErrorFragment.from(obj)\n errors.full.add(frag.format(FormatTypes.full))\n errors.selector[Interface.getSighash(frag)] = frag.format(FormatTypes.sighash)\n })\n } finally {\n semaphore.release()\n }\n}\n\n/**\n * Populates error information from ABI files in parallel.\n * This function reads ABI files, processes them to extract error information,\n * and writes the combined and sorted errors to JSON files.\n *\n * @param {string} callerRootFile - The root file path to start the search for ABI files.\n * @param {string} [destPath='src/errors'] - The path relative to root to copy the files in.\n * @param {number} [maxConcurrent=50] - Maximum number of concurrent file processing operations.\n * @returns {Promise<void>} A promise that resolves when the operation is complete.\n */\nexport async function populateErrors(\n callerRootFile: string,\n destPath = 'src/errors',\n maxConcurrent = 50\n): Promise<void> {\n // Determining the directory paths from the caller's root file\n const callerRootDir = path.dirname(callerRootFile)\n const callerArtifactsPath = path.join(callerRootDir, 'artifacts')\n\n // Reading and filtering artifacts to process only JSON files\n const files = await readdir(callerArtifactsPath, { recursive: true })\n const jsonFiles = files.filter((file) => path.extname(file).toLowerCase() === '.json')\n\n const semaphore = new Semaphore(maxConcurrent)\n const errors = { full: new Set<string>(), selector: {} }\n\n // Parallel processing of files using the semaphore for concurrency control\n const filePromises = jsonFiles.map(async (file) =>\n parallelProcess(path.join(callerArtifactsPath, file), semaphore, errors)\n )\n await Promise.all(filePromises)\n\n // Sorting and organizing errors for output\n const { full, selector } = errors\n let sorter = new Intl.Collator('en', { caseFirst: 'upper', numeric: true })\n const sortedErrors = [...full].sort(sorter.compare)\n sorter = new Intl.Collator('en', { caseFirst: 'upper', numeric: false })\n const sortedSelectors = Object.fromEntries(Object.entries(selector).sort(([a], [b]) => sorter.compare(a, b)))\n const errorDir = path.join(callerRootDir, destPath)\n // Writing errors to files in the error directory\n await mkdir(errorDir, { recursive: true })\n await writeFile(path.join(errorDir, 'errors.json'), JSON.stringify(sortedErrors, null, 2))\n console.log(`Generated abi for ${sortedErrors.length} errors`)\n await writeFile(path.join(errorDir, 'errorSelectors.json'), JSON.stringify(sortedSelectors, null, 2))\n}\n","import { copyFile, mkdir } from 'fs/promises'\nimport { createRequire } from 'module'\nimport path from 'path'\n\nimport { glob } from 'glob'\n\ntype Package = string\ntype File = string\ntype Directory = (File | NestedDirectory)[]\ninterface NestedDirectory {\n [key: string]: Directory | NestedDirectory\n}\nexport interface PackageFiles {\n [key: Package]: NestedDirectory | Directory\n}\n\n/**\n * Recursively traverses a directory structure to build paths to leaf nodes.\n * @param node - A directory structure represented as a string (for files), an array (for directories), or an object (for nested directories).\n * @returns {string[]} An array of strings, each representing a path from the root to a leaf node.\n */\nexport const buildPaths = (node: NestedDirectory | Directory | File): string[] => {\n // base case, we're at a leaf node, return the filename\n if (typeof node === 'string') return [node]\n\n const paths: string[] = []\n // If the current node is an array, recursively process each file / nested dir\n if (Array.isArray(node)) {\n for (const contract of node) {\n paths.push(...buildPaths(contract))\n }\n } else {\n // Current node is a nested directory. Recursively process each entry.\n for (const [parent, child] of Object.entries(node)) {\n const children = buildPaths(child)\n children.forEach((path) => paths.push(`${parent}/${path}`))\n }\n }\n return paths\n}\n\n/**\n * Asynchronously copies files from source packages to a target root directory based on the provided directory structure.\n * This function iterates over each source package, resolves all file paths,\n * and copies each file to the corresponding location within the caller's root directory.\n *\n * @param {PackageFiles} packageFiles - An object mapping package names to their directory structures,\n * where each directory structure defines the files and nested directories to be copied.\n * @param {string} callerRootFile - The absolute path to the root file of the caller, used to determine the root directory into which the files will be copied.\n * @returns {Promise<void>} A promise that resolves when the operation is complete.\n */\nexport async function copyPackageFiles(packageFiles: PackageFiles, callerRootFile: string): Promise<void> {\n const callerRootDir = path.dirname(callerRootFile)\n for (const [srcPackage, srcFiles] of Object.entries(packageFiles)) {\n const allPaths = buildPaths(srcFiles)\n const srcDir = path.dirname(createRequire(callerRootFile).resolve(`${srcPackage}/package.json`))\n let count = 0\n for (const uniquePath of allPaths) {\n const files = await glob(path.join(srcDir, uniquePath))\n for (const file of files) {\n const relativePath = path.relative(srcDir, file)\n const destPath = path.join(callerRootDir, relativePath)\n await mkdir(path.dirname(destPath), { recursive: true })\n await copyFile(file, destPath)\n count++\n }\n }\n console.log(`Copied ${count} files from ${srcPackage}`)\n }\n}\n"]}
package/dist/index.mjs CHANGED
@@ -46,8 +46,7 @@ var Semaphore = class {
46
46
  * Releases a lock on the semaphore.
47
47
  */
48
48
  release() {
49
- if (this.counter == 0)
50
- return;
49
+ if (this.counter == 0) return;
51
50
  this.counter--;
52
51
  const resolve = this.queue.shift() ?? (() => void 0);
53
52
  resolve();
@@ -64,8 +63,7 @@ async function parallelProcess(filePath, semaphore, errors) {
64
63
  await semaphore.acquire();
65
64
  try {
66
65
  const { abi } = await readJSONFile(filePath);
67
- if (abi === void 0 || !Array.isArray(abi))
68
- return;
66
+ if (abi === void 0 || !Array.isArray(abi)) return;
69
67
  abi.filter(({ type }) => type === "error").forEach((obj) => {
70
68
  const frag = ErrorFragment.from(obj);
71
69
  errors.full.add(frag.format(FormatTypes.full));
@@ -98,8 +96,7 @@ async function populateErrors(callerRootFile, destPath = "src/errors", maxConcur
98
96
  await writeFile(path2.join(errorDir, "errorSelectors.json"), JSON.stringify(sortedSelectors, null, 2));
99
97
  }
100
98
  var buildPaths = (node) => {
101
- if (typeof node === "string")
102
- return [node];
99
+ if (typeof node === "string") return [node];
103
100
  const paths = [];
104
101
  if (Array.isArray(node)) {
105
102
  for (const contract of node) {
@@ -134,5 +131,5 @@ async function copyPackageFiles(packageFiles, callerRootFile) {
134
131
  }
135
132
 
136
133
  export { Semaphore, copyPackageFiles, populate, populateErrors };
137
- //# sourceMappingURL=out.js.map
134
+ //# sourceMappingURL=index.mjs.map
138
135
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/populate.ts","../src/errors.ts","../src/semaphore.ts","../src/copyFiles.ts"],"names":["mkdir","path","copyFile","createRequire","glob"],"mappings":";AAAA,SAAS,UAAU,aAAa;AAChC,SAAS,qBAAqB;AAC9B,OAAO,UAAU;AAEjB,SAAS,YAAY;AAiBrB,eAAsB,SAAS,aAA0B,gBAAuC;AAC5F,QAAM,gBAAgB,KAAK,QAAQ,cAAc;AACjD,aAAW,CAAC,YAAY,QAAQ,KAAK,OAAO,QAAQ,WAAW,GAAG;AAC9D,UAAM,SAAS,KAAK,QAAQ,cAAc,cAAc,EAAE,QAAQ,GAAG,UAAU,eAAe,CAAC;AAC/F,eAAW,CAAC,UAAU,QAAQ,KAAK,OAAO,QAAQ,QAAQ,GAAG;AACzD,YAAM,QAAQ,MAAM,KAAK,SAAS,IAAI,CAAC,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AAC;AAC/F,QAAI,QAAQ;AACZ,eAAW,cAAc,UAAU;AAC/B,YAAM,QAAQ,MAAMC,MAAKH,MAAK,KAAK,QAAQ,UAAU,CAAC;AACtD,iBAAW,QAAQ,OAAO;AACtB,cAAM,eAAeA,MAAK,SAAS,QAAQ,IAAI;AAC/C,cAAM,WAAWA,MAAK,KAAK,eAAe,YAAY;AACtD,cAAMD,OAAMC,MAAK,QAAQ,QAAQ,GAAG,EAAE,WAAW,KAAK,CAAC;AACvD,cAAMC,UAAS,MAAM,QAAQ;AAC7B;AAAA,MACJ;AAAA,IACJ;AACA,YAAQ,IAAI,UAAU,KAAK,eAAe,UAAU,EAAE;AAAA,EAC1D;AACJ","sourcesContent":["import { copyFile, mkdir } from 'fs/promises'\nimport { createRequire } from 'module'\nimport path from 'path'\n\nimport { glob } from 'glob'\n\ntype AllowedFiles = 'artifacts' | 'deployments' | 'artifacts-tron' | 'artifacts-zk'\n\nexport type SrcFiles = { [key in AllowedFiles]?: readonly string[] }\nexport interface CopyTargets {\n [key: string]: SrcFiles\n}\n\n/**\n * Populates the target directory with files from the specified source packages.\n * This function copies files from the source packages to the target directory based on the provided patterns.\n *\n * @param {CopyTargets} copyTargets - An object mapping source packages to their respective file patterns.\n * @param {string} callerRootFile - The absolute path to the root file of the caller, used to determine the root directory into which the files will be copied.\n * @returns {Promise<void>} A promise that resolves when the operation is complete.\n */\nexport async function populate(copyTargets: CopyTargets, callerRootFile: string): Promise<void> {\n const callerRootDir = path.dirname(callerRootFile)\n for (const [srcPackage, srcFiles] of Object.entries(copyTargets)) {\n const srcDir = path.dirname(createRequire(callerRootFile).resolve(`${srcPackage}/package.json`))\n for (const [filePath, patterns] of Object.entries(srcFiles)) {\n const files = await glob(patterns.map((p) => path.join(srcDir, filePath, p)))\n let count = 0\n for (const file of files) {\n const relativePath = path.relative(srcDir, file)\n const destPath = path.join(callerRootDir, relativePath)\n await mkdir(path.dirname(destPath), { recursive: true })\n await copyFile(file, destPath)\n count++\n }\n console.log(`Copied ${count} ${filePath} from ${srcPackage}`)\n }\n }\n}\n","import { mkdir, readFile, readdir, writeFile } from 'fs/promises'\nimport path from 'path'\n\nimport { utils } from 'ethers'\n\nimport { Semaphore } from './semaphore'\n\nconst { ErrorFragment, FormatTypes, Interface } = utils\n\n/**\n * Asynchronously reads a JSON file from a given file path.\n * @param filePath - The path to the JSON file.\n * @returns {Promise<any>} A promise that resolves to the parsed JSON data.\n */\nasync function readJSONFile(filePath: string): Promise<any> {\n const data = await readFile(filePath, { encoding: 'utf8' })\n return JSON.parse(data)\n}\n\n/**\n * Processes ABI errors in parallel, controlled by a semaphore, and populates error collections.\n * @param {string} filePath - The file path to read.\n * @param {Semaphore} semaphore - Semaphore instance for concurrency control.\n * @param {Object} errors - Object to collect full errors and error selectors.\n * @param {Set<string>} errors.full - Set to collect full error definitions.\n * @param {Object.<string, string>} errors.selector - Object to collect error selectors.\n * @returns {Promise<void>} A promise that resolves when the operation is complete.\n */\nasync function parallelProcess(\n filePath: string,\n semaphore: Semaphore,\n errors: { full: Set<string>; selector: { [key: string]: string } }\n): Promise<void> {\n await semaphore.acquire()\n try {\n const { abi } = await readJSONFile(filePath)\n if (abi === undefined || !Array.isArray(abi)) return\n abi.filter(({ type }) => type === 'error').forEach((obj) => {\n const frag = ErrorFragment.from(obj)\n errors.full.add(frag.format(FormatTypes.full))\n errors.selector[Interface.getSighash(frag)] = frag.format(FormatTypes.sighash)\n })\n } finally {\n semaphore.release()\n }\n}\n\n/**\n * Populates error information from ABI files in parallel.\n * This function reads ABI files, processes them to extract error information,\n * and writes the combined and sorted errors to JSON files.\n *\n * @param {string} callerRootFile - The root file path to start the search for ABI files.\n * @param {string} [destPath='src/errors'] - The path relative to root to copy the files in.\n * @param {number} [maxConcurrent=50] - Maximum number of concurrent file processing operations.\n * @returns {Promise<void>} A promise that resolves when the operation is complete.\n */\nexport async function populateErrors(\n callerRootFile: string,\n destPath = 'src/errors',\n maxConcurrent = 50\n): Promise<void> {\n // Determining the directory paths from the caller's root file\n const callerRootDir = path.dirname(callerRootFile)\n const callerArtifactsPath = path.join(callerRootDir, 'artifacts')\n\n // Reading and filtering artifacts to process only JSON files\n const files = await readdir(callerArtifactsPath, { recursive: true })\n const jsonFiles = files.filter((file) => path.extname(file).toLowerCase() === '.json')\n\n const semaphore = new Semaphore(maxConcurrent)\n const errors = { full: new Set<string>(), selector: {} }\n\n // Parallel processing of files using the semaphore for concurrency control\n const filePromises = jsonFiles.map(async (file) =>\n parallelProcess(path.join(callerArtifactsPath, file), semaphore, errors)\n )\n await Promise.all(filePromises)\n\n // Sorting and organizing errors for output\n const { full, selector } = errors\n let sorter = new Intl.Collator('en', { caseFirst: 'upper', numeric: true })\n const sortedErrors = [...full].sort(sorter.compare)\n sorter = new Intl.Collator('en', { caseFirst: 'upper', numeric: false })\n const sortedSelectors = Object.fromEntries(Object.entries(selector).sort(([a], [b]) => sorter.compare(a, b)))\n const errorDir = path.join(callerRootDir, destPath)\n // Writing errors to files in the error directory\n await mkdir(errorDir, { recursive: true })\n await writeFile(path.join(errorDir, 'errors.json'), JSON.stringify(sortedErrors, null, 2))\n console.log(`Generated abi for ${sortedErrors.length} errors`)\n await writeFile(path.join(errorDir, 'errorSelectors.json'), JSON.stringify(sortedSelectors, null, 2))\n}\n","/**\n * Semaphore class for controlling access to a resource by multiple processes.\n * It maintains a counter and a queue for managing access.\n */\nexport class Semaphore {\n private counter = 0\n private queue: (() => void)[] = []\n constructor(private max: number) {}\n\n /**\n * Acquires a lock on the semaphore. If the semaphore is at its maximum,\n * the function will wait until it can acquire the lock.\n * @returns A promise that resolves when the lock has been acquired.\n */\n public async acquire(): Promise<void> {\n if (this.counter >= this.max) {\n await new Promise<void>((resolve) => this.queue.push(resolve))\n }\n this.counter++\n }\n\n /**\n * Releases a lock on the semaphore.\n */\n public release(): void {\n if (this.counter == 0) return\n this.counter--\n const resolve = this.queue.shift() ?? ((): undefined => undefined)\n resolve()\n }\n}\n","import { copyFile, mkdir } from 'fs/promises'\nimport { createRequire } from 'module'\nimport path from 'path'\n\nimport { glob } from 'glob'\n\ntype Package = string\ntype File = string\ntype Directory = (File | NestedDirectory)[]\ninterface NestedDirectory {\n [key: string]: Directory | NestedDirectory\n}\nexport interface PackageFiles {\n [key: Package]: NestedDirectory | Directory\n}\n\n/**\n * Recursively traverses a directory structure to build paths to leaf nodes.\n * @param node - A directory structure represented as a string (for files), an array (for directories), or an object (for nested directories).\n * @returns {string[]} An array of strings, each representing a path from the root to a leaf node.\n */\nexport const buildPaths = (node: NestedDirectory | Directory | File): string[] => {\n // base case, we're at a leaf node, return the filename\n if (typeof node === 'string') return [node]\n\n const paths: string[] = []\n // If the current node is an array, recursively process each file / nested dir\n if (Array.isArray(node)) {\n for (const contract of node) {\n paths.push(...buildPaths(contract))\n }\n } else {\n // Current node is a nested directory. Recursively process each entry.\n for (const [parent, child] of Object.entries(node)) {\n const children = buildPaths(child)\n children.forEach((path) => paths.push(`${parent}/${path}`))\n }\n }\n return paths\n}\n\n/**\n * Asynchronously copies files from source packages to a target root directory based on the provided directory structure.\n * This function iterates over each source package, resolves all file paths,\n * and copies each file to the corresponding location within the caller's root directory.\n *\n * @param {PackageFiles} packageFiles - An object mapping package names to their directory structures,\n * where each directory structure defines the files and nested directories to be copied.\n * @param {string} callerRootFile - The absolute path to the root file of the caller, used to determine the root directory into which the files will be copied.\n * @returns {Promise<void>} A promise that resolves when the operation is complete.\n */\nexport async function copyPackageFiles(packageFiles: PackageFiles, callerRootFile: string): Promise<void> {\n const callerRootDir = path.dirname(callerRootFile)\n for (const [srcPackage, srcFiles] of Object.entries(packageFiles)) {\n const allPaths = buildPaths(srcFiles)\n const srcDir = path.dirname(createRequire(callerRootFile).resolve(`${srcPackage}/package.json`))\n let count = 0\n for (const uniquePath of allPaths) {\n const files = await glob(path.join(srcDir, uniquePath))\n for (const file of files) {\n const relativePath = path.relative(srcDir, file)\n const destPath = path.join(callerRootDir, relativePath)\n await mkdir(path.dirname(destPath), { recursive: true })\n await copyFile(file, destPath)\n count++\n }\n }\n console.log(`Copied ${count} files from ${srcPackage}`)\n }\n}\n"]}
1
+ {"version":3,"sources":["../src/populate.ts","../src/semaphore.ts","../src/errors.ts","../src/copyFiles.ts"],"names":["path","mkdir","createRequire","glob","copyFile"],"mappings":";;;;;;;AAqBA,eAAsB,QAAA,CAAS,aAA0B,cAAuC,EAAA;AAC5F,EAAM,MAAA,aAAA,GAAgBA,KAAK,CAAA,OAAA,CAAQ,cAAc,CAAA;AACjD,EAAA,KAAA,MAAW,CAAC,UAAY,EAAA,QAAQ,KAAK,MAAO,CAAA,OAAA,CAAQ,WAAW,CAAG,EAAA;AAC9D,IAAM,MAAA,MAAA,GAASA,KAAK,CAAA,OAAA,CAAQ,aAAc,CAAA,cAAc,EAAE,OAAQ,CAAA,CAAA,EAAG,UAAU,CAAA,aAAA,CAAe,CAAC,CAAA;AAC/F,IAAA,KAAA,MAAW,CAAC,QAAU,EAAA,QAAQ,KAAK,MAAO,CAAA,OAAA,CAAQ,QAAQ,CAAG,EAAA;AACzD,MAAA,MAAM,KAAQ,GAAA,MAAM,IAAK,CAAA,QAAA,CAAS,GAAI,CAAA,CAAC,CAAM,KAAAA,KAAA,CAAK,IAAK,CAAA,MAAA,EAAQ,QAAU,EAAA,CAAC,CAAC,CAAC,CAAA;AAC5E,MAAA,IAAI,KAAQ,GAAA,CAAA;AACZ,MAAA,KAAA,MAAW,QAAQ,KAAO,EAAA;AACtB,QAAA,MAAM,YAAe,GAAAA,KAAA,CAAK,QAAS,CAAA,MAAA,EAAQ,IAAI,CAAA;AAC/C,QAAA,MAAM,QAAW,GAAAA,KAAA,CAAK,IAAK,CAAA,aAAA,EAAe,YAAY,CAAA;AACtD,QAAM,MAAA,KAAA,CAAMA,MAAK,OAAQ,CAAA,QAAQ,GAAG,EAAE,SAAA,EAAW,MAAM,CAAA;AACvD,QAAM,MAAA,QAAA,CAAS,MAAM,QAAQ,CAAA;AAC7B,QAAA,KAAA,EAAA;AAAA;AAEJ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,aAAA,CAAe,CAAC,CAAA;AAC/F,IAAA,IAAI,KAAQ,GAAA,CAAA;AACZ,IAAA,KAAA,MAAW,cAAc,QAAU,EAAA;AAC/B,MAAA,MAAM,QAAQ,MAAMC,IAAAA,CAAKH,MAAK,IAAK,CAAA,MAAA,EAAQ,UAAU,CAAC,CAAA;AACtD,MAAA,KAAA,MAAW,QAAQ,KAAO,EAAA;AACtB,QAAA,MAAM,YAAeA,GAAAA,KAAAA,CAAK,QAAS,CAAA,MAAA,EAAQ,IAAI,CAAA;AAC/C,QAAA,MAAM,QAAWA,GAAAA,KAAAA,CAAK,IAAK,CAAA,aAAA,EAAe,YAAY,CAAA;AACtD,QAAMC,MAAAA,KAAAA,CAAMD,MAAK,OAAQ,CAAA,QAAQ,GAAG,EAAE,SAAA,EAAW,MAAM,CAAA;AACvD,QAAMI,MAAAA,QAAAA,CAAS,MAAM,QAAQ,CAAA;AAC7B,QAAA,KAAA,EAAA;AAAA;AACJ;AAEJ,IAAA,OAAA,CAAQ,GAAI,CAAA,CAAA,OAAA,EAAU,KAAK,CAAA,YAAA,EAAe,UAAU,CAAE,CAAA,CAAA;AAAA;AAE9D","file":"index.mjs","sourcesContent":["import { copyFile, mkdir } from 'fs/promises'\nimport { createRequire } from 'module'\nimport path from 'path'\n\nimport { glob } from 'glob'\n\ntype AllowedFiles = 'artifacts' | 'deployments' | 'artifacts-tron' | 'artifacts-zk'\n\nexport type SrcFiles = { [key in AllowedFiles]?: readonly string[] }\nexport interface CopyTargets {\n [key: string]: SrcFiles\n}\n\n/**\n * Populates the target directory with files from the specified source packages.\n * This function copies files from the source packages to the target directory based on the provided patterns.\n *\n * @param {CopyTargets} copyTargets - An object mapping source packages to their respective file patterns.\n * @param {string} callerRootFile - The absolute path to the root file of the caller, used to determine the root directory into which the files will be copied.\n * @returns {Promise<void>} A promise that resolves when the operation is complete.\n */\nexport async function populate(copyTargets: CopyTargets, callerRootFile: string): Promise<void> {\n const callerRootDir = path.dirname(callerRootFile)\n for (const [srcPackage, srcFiles] of Object.entries(copyTargets)) {\n const srcDir = path.dirname(createRequire(callerRootFile).resolve(`${srcPackage}/package.json`))\n for (const [filePath, patterns] of Object.entries(srcFiles)) {\n const files = await glob(patterns.map((p) => path.join(srcDir, filePath, p)))\n let count = 0\n for (const file of files) {\n const relativePath = path.relative(srcDir, file)\n const destPath = path.join(callerRootDir, relativePath)\n await mkdir(path.dirname(destPath), { recursive: true })\n await copyFile(file, destPath)\n count++\n }\n console.log(`Copied ${count} ${filePath} from ${srcPackage}`)\n }\n }\n}\n","/**\n * Semaphore class for controlling access to a resource by multiple processes.\n * It maintains a counter and a queue for managing access.\n */\nexport class Semaphore {\n private counter = 0\n private queue: (() => void)[] = []\n constructor(private max: number) {}\n\n /**\n * Acquires a lock on the semaphore. If the semaphore is at its maximum,\n * the function will wait until it can acquire the lock.\n * @returns A promise that resolves when the lock has been acquired.\n */\n public async acquire(): Promise<void> {\n if (this.counter >= this.max) {\n await new Promise<void>((resolve) => this.queue.push(resolve))\n }\n this.counter++\n }\n\n /**\n * Releases a lock on the semaphore.\n */\n public release(): void {\n if (this.counter == 0) return\n this.counter--\n const resolve = this.queue.shift() ?? ((): undefined => undefined)\n resolve()\n }\n}\n","import { mkdir, readFile, readdir, writeFile } from 'fs/promises'\nimport path from 'path'\n\nimport { utils } from 'ethers'\n\nimport { Semaphore } from './semaphore'\n\nconst { ErrorFragment, FormatTypes, Interface } = utils\n\n/**\n * Asynchronously reads a JSON file from a given file path.\n * @param filePath - The path to the JSON file.\n * @returns {Promise<any>} A promise that resolves to the parsed JSON data.\n */\nasync function readJSONFile(filePath: string): Promise<any> {\n const data = await readFile(filePath, { encoding: 'utf8' })\n return JSON.parse(data)\n}\n\n/**\n * Processes ABI errors in parallel, controlled by a semaphore, and populates error collections.\n * @param {string} filePath - The file path to read.\n * @param {Semaphore} semaphore - Semaphore instance for concurrency control.\n * @param {Object} errors - Object to collect full errors and error selectors.\n * @param {Set<string>} errors.full - Set to collect full error definitions.\n * @param {Object.<string, string>} errors.selector - Object to collect error selectors.\n * @returns {Promise<void>} A promise that resolves when the operation is complete.\n */\nasync function parallelProcess(\n filePath: string,\n semaphore: Semaphore,\n errors: { full: Set<string>; selector: { [key: string]: string } }\n): Promise<void> {\n await semaphore.acquire()\n try {\n const { abi } = await readJSONFile(filePath)\n if (abi === undefined || !Array.isArray(abi)) return\n abi.filter(({ type }) => type === 'error').forEach((obj) => {\n const frag = ErrorFragment.from(obj)\n errors.full.add(frag.format(FormatTypes.full))\n errors.selector[Interface.getSighash(frag)] = frag.format(FormatTypes.sighash)\n })\n } finally {\n semaphore.release()\n }\n}\n\n/**\n * Populates error information from ABI files in parallel.\n * This function reads ABI files, processes them to extract error information,\n * and writes the combined and sorted errors to JSON files.\n *\n * @param {string} callerRootFile - The root file path to start the search for ABI files.\n * @param {string} [destPath='src/errors'] - The path relative to root to copy the files in.\n * @param {number} [maxConcurrent=50] - Maximum number of concurrent file processing operations.\n * @returns {Promise<void>} A promise that resolves when the operation is complete.\n */\nexport async function populateErrors(\n callerRootFile: string,\n destPath = 'src/errors',\n maxConcurrent = 50\n): Promise<void> {\n // Determining the directory paths from the caller's root file\n const callerRootDir = path.dirname(callerRootFile)\n const callerArtifactsPath = path.join(callerRootDir, 'artifacts')\n\n // Reading and filtering artifacts to process only JSON files\n const files = await readdir(callerArtifactsPath, { recursive: true })\n const jsonFiles = files.filter((file) => path.extname(file).toLowerCase() === '.json')\n\n const semaphore = new Semaphore(maxConcurrent)\n const errors = { full: new Set<string>(), selector: {} }\n\n // Parallel processing of files using the semaphore for concurrency control\n const filePromises = jsonFiles.map(async (file) =>\n parallelProcess(path.join(callerArtifactsPath, file), semaphore, errors)\n )\n await Promise.all(filePromises)\n\n // Sorting and organizing errors for output\n const { full, selector } = errors\n let sorter = new Intl.Collator('en', { caseFirst: 'upper', numeric: true })\n const sortedErrors = [...full].sort(sorter.compare)\n sorter = new Intl.Collator('en', { caseFirst: 'upper', numeric: false })\n const sortedSelectors = Object.fromEntries(Object.entries(selector).sort(([a], [b]) => sorter.compare(a, b)))\n const errorDir = path.join(callerRootDir, destPath)\n // Writing errors to files in the error directory\n await mkdir(errorDir, { recursive: true })\n await writeFile(path.join(errorDir, 'errors.json'), JSON.stringify(sortedErrors, null, 2))\n console.log(`Generated abi for ${sortedErrors.length} errors`)\n await writeFile(path.join(errorDir, 'errorSelectors.json'), JSON.stringify(sortedSelectors, null, 2))\n}\n","import { copyFile, mkdir } from 'fs/promises'\nimport { createRequire } from 'module'\nimport path from 'path'\n\nimport { glob } from 'glob'\n\ntype Package = string\ntype File = string\ntype Directory = (File | NestedDirectory)[]\ninterface NestedDirectory {\n [key: string]: Directory | NestedDirectory\n}\nexport interface PackageFiles {\n [key: Package]: NestedDirectory | Directory\n}\n\n/**\n * Recursively traverses a directory structure to build paths to leaf nodes.\n * @param node - A directory structure represented as a string (for files), an array (for directories), or an object (for nested directories).\n * @returns {string[]} An array of strings, each representing a path from the root to a leaf node.\n */\nexport const buildPaths = (node: NestedDirectory | Directory | File): string[] => {\n // base case, we're at a leaf node, return the filename\n if (typeof node === 'string') return [node]\n\n const paths: string[] = []\n // If the current node is an array, recursively process each file / nested dir\n if (Array.isArray(node)) {\n for (const contract of node) {\n paths.push(...buildPaths(contract))\n }\n } else {\n // Current node is a nested directory. Recursively process each entry.\n for (const [parent, child] of Object.entries(node)) {\n const children = buildPaths(child)\n children.forEach((path) => paths.push(`${parent}/${path}`))\n }\n }\n return paths\n}\n\n/**\n * Asynchronously copies files from source packages to a target root directory based on the provided directory structure.\n * This function iterates over each source package, resolves all file paths,\n * and copies each file to the corresponding location within the caller's root directory.\n *\n * @param {PackageFiles} packageFiles - An object mapping package names to their directory structures,\n * where each directory structure defines the files and nested directories to be copied.\n * @param {string} callerRootFile - The absolute path to the root file of the caller, used to determine the root directory into which the files will be copied.\n * @returns {Promise<void>} A promise that resolves when the operation is complete.\n */\nexport async function copyPackageFiles(packageFiles: PackageFiles, callerRootFile: string): Promise<void> {\n const callerRootDir = path.dirname(callerRootFile)\n for (const [srcPackage, srcFiles] of Object.entries(packageFiles)) {\n const allPaths = buildPaths(srcFiles)\n const srcDir = path.dirname(createRequire(callerRootFile).resolve(`${srcPackage}/package.json`))\n let count = 0\n for (const uniquePath of allPaths) {\n const files = await glob(path.join(srcDir, uniquePath))\n for (const file of files) {\n const relativePath = path.relative(srcDir, file)\n const destPath = path.join(callerRootDir, relativePath)\n await mkdir(path.dirname(destPath), { recursive: true })\n await copyFile(file, destPath)\n count++\n }\n }\n console.log(`Copied ${count} files from ${srcPackage}`)\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@layerzerolabs/evm-sdks-build",
3
- "version": "3.0.16",
3
+ "version": "3.0.18-movement.0",
4
4
  "license": "BUSL-1.1",
5
5
  "exports": {
6
6
  "types": "./dist/index.d.ts",
@@ -24,15 +24,15 @@
24
24
  "glob": "^10.3.10"
25
25
  },
26
26
  "devDependencies": {
27
- "@layerzerolabs/tsup-config-next": "^3.0.16",
28
- "@layerzerolabs/typescript-config-next": "^3.0.16",
27
+ "@layerzerolabs/tsup-config-next": "^3.0.18-movement.0",
28
+ "@layerzerolabs/typescript-config-next": "^3.0.18-movement.0",
29
29
  "@types/glob": "^8.1.0",
30
30
  "@types/jest": "^29.5.10",
31
31
  "@types/node": "^20.10.5",
32
32
  "jest": "^29.7.0",
33
33
  "rimraf": "^5.0.5",
34
34
  "ts-jest": "^29.1.1",
35
- "tsup": "^8.0.1",
35
+ "tsup": "^8.3.5",
36
36
  "typescript": "~5.2.2"
37
37
  },
38
38
  "engines": {