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AGhC,CACF,MAfE,EAAe,IAAI,EAAe,CAChC,UAAW,EACX,aAAc,GAcpB,CACF,CASA,IAAI,EAAW,IAAI,IAEnB,IAAK,IAAI,KAA0B,EAA2B,CAC5D,IAAI,EAAY,EAAuB,SACnC,EAAY,EAAuB,UAEvC,IAAK,IAAI,KAAM,EAAU,eAAgB,CACvC,IAAI,EAAW,EAAG,GACd,EAAW,EAAG,GAEd,EAAe,EAAU,EAEzB,EAA0B,EAAS,IAAI,GAC3C,GAA+B,MAA3B,EACF,EAA0B,GAC1B,EAAS,IAAI,EAAU,OAClB,CAEL,IAAI,EAAc,aAAoB,UAClC,EACF,EAAwB,GAAG,oBAAoB,UACjD,GAAI,IAAwB,EAAa,CACvC,IAAI,EAAQ,EAAsB,YAAc,OAC5C,EAAQ,EAAwB,GAAG,UAGvC,MAAM,IAAI,MAER,wCAAG,UAAqB,QAAY,WAJ1B,EAAc,YAAc,aAC5B,2CAOd,CAGA,IAAK,IAAgB,EAAW,CAC9B,IAAI,EAAe,EAAwB,GAAG,UAC9C,MAAM,IAAI,MACR,qBAAqB,eAClB,SAAoB,yFAI3B,CACF,CAEA,EAAwB,KAAK,CAC3B,SAAU,EACV,UAAW,GAEf,CACF,CAGA,IAAI,EAAS,IAAI,eACjB,IAAK,IAAI,KAAM,EAAU,CACvB,IAAI,EAAW,EAAG,GACd,EAA0B,EAAG,GAEjC,GAAI,EAAwB,GAAG,oBAAoB,UAAW,CAC5D,IAAI,EAAe,KAAK,qBACtB,EACA,GAAG,IAAU,MAEf,EAAO,IAAI,EAAU,EACvB,KAAO,CAGL,IAAI,EACF,EAAwB,EAAwB,OAAS,GAAG,SAC9D,EAAO,IAAI,EAAU,EACvB,CACF,CACA,OAAO,CACT,EAGF,OAAO,QAAU","file":"/npm/merge-trees@2.0.0/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.19.2.\n * Original file: /npm/merge-trees@2.0.0/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","\"use strict\";\n\nlet FSUpdater = require(\"fs-updater\");\nlet heimdall = require(\"heimdalljs\");\n\nlet Directory = FSUpdater.Directory;\nlet DirectoryIndex = FSUpdater.DirectoryIndex;\nlet makeFSObject = FSUpdater.makeFSObject;\n\nclass MergeTrees {\n  constructor(inputPaths, outputPath, options) {\n    options = options || {};\n    let name = \"merge-trees:\" + (options.annotation || \"\");\n    if (!Array.isArray(inputPaths)) {\n      throw new TypeError(name + \": Expected array, got: [\" + inputPaths + \"]\");\n    }\n\n    this.inputPaths = inputPaths;\n    this.outputPath = outputPath;\n    this.options = options;\n\n    this.updater = new FSUpdater(outputPath, options._fsUpdaterOptions);\n  }\n\n  merge() {\n    let instrumentation = heimdall.start(\"MergeTrees:readInput\");\n    let dir = this._getMergedDirectory();\n    instrumentation.stop();\n\n    instrumentation = heimdall.start(\"MergeTrees:update\");\n    this.updater.update(dir);\n    instrumentation.stop();\n  }\n\n  _getMergedDirectory() {\n    let directoriesWithInputPaths = this.inputPaths.map(inputPath => ({\n      fsObject: makeFSObject(inputPath), // Directory object\n      inputPath: inputPath // remember for error reporting\n    }));\n    return this._getMergedDirectory2(directoriesWithInputPaths, \"\");\n  }\n\n  // Say we are recursing into the \"foo\" directory, which only exists in\n  // this.inputPaths[1] and this.inputPaths[2]. Then baseDir will be \"foo/\",\n  // and directoriesWithInputPaths will be\n  //\n  // [\n  //   {\n  //     fsObject: new Directory(`${this.inputPaths[1]}/foo`),\n  //     inputPath: this.inputPaths[1]\n  //   },\n  //   {\n  //     fsObject: new Directory(`${this.inputPaths[2]}/foo`),\n  //     inputPath: this.inputPaths[2]\n  //   }\n  // ]\n  //\n  // The `fsObject` property is named so because later on we have a similar\n  // structure that may also contain File objects.\n  //\n  // `baseDir` and the `inputPath` property are only used for error reporting.\n  // Note that we must not use `fsObject.valueOf()` to report errors, because we\n  // may have followed symlinks and thus the fsObject may not point into any of\n  // the inputPaths.\n  _getMergedDirectory2(directoriesWithInputPaths, baseDir) {\n    // First, short-circuit on single input directory. This is particularly\n    // important for the recursive case: It means we only descend into\n    // subdirectories that exist in more than one input directory.\n    if (directoriesWithInputPaths.length === 1) {\n      return directoriesWithInputPaths[0].fsObject;\n    }\n\n    let overwrite = this.options.overwrite;\n\n    // Guard against conflicting capitalizations. We are strict about this to\n    // avoid divergent behavior between case-insensitive Mac/Windows and\n    // case-sensitive Linux.\n    let lowerCaseNames = new Map();\n    for (let directoryWithInputPath of directoriesWithInputPaths) {\n      let directory = directoryWithInputPath.fsObject;\n      let inputPath = directoryWithInputPath.inputPath;\n      for (let fileName of directory.getIndexSync().keys()) {\n        let lowerCaseName = fileName.toLowerCase();\n        // Note: We are using .toLowerCase to approximate the case\n        // insensitivity behavior of HFS+ and NTFS. While .toLowerCase is at\n        // least Unicode aware, there are probably better-suited functions.\n        if (!lowerCaseNames.has(lowerCaseName)) {\n          lowerCaseNames.set(lowerCaseName, {\n            inputPath: inputPath,\n            originalName: fileName\n          });\n        } else {\n          let originalName = lowerCaseNames.get(lowerCaseName).originalName;\n          if (originalName !== fileName) {\n            let originalPath = lowerCaseNames.get(lowerCaseName).inputPath;\n            throw new Error(\n              `Merge error: conflicting capitalizations:\\n` +\n              `${baseDir}${originalName} in ${originalPath}\\n` +\n              `${baseDir}${fileName} in ${inputPath}\\n` +\n              `Remove one of the files and re-add it with matching capitalization.`\n            );\n          }\n        }\n      }\n    }\n    // From here on out, no files and directories exist with conflicting\n    // capitalizations, which means we can use `===` without .toLowerCase\n    // normalization.\n\n    // fileInfo maps file names to fsObjectWithInputPaths lists. These lists\n    // contain, for each instance of the file in the input directories, the\n    // FSObject for that file and the inputPath (from this.inputPaths) that it\n    // came from.\n    let fileInfo = new Map();\n\n    for (let directoryWithInputPath of directoriesWithInputPaths) {\n      let directory = directoryWithInputPath.fsObject;\n      let inputPath = directoryWithInputPath.inputPath;\n\n      for (let kv of directory.getIndexSync()) {\n        let fileName = kv[0];\n        let fsObject = kv[1];\n\n        let relativePath = baseDir + fileName;\n\n        let fsObjectsWithInputPaths = fileInfo.get(fileName);\n        if (fsObjectsWithInputPaths == null) {\n          fsObjectsWithInputPaths = [];\n          fileInfo.set(fileName, fsObjectsWithInputPaths);\n        } else {\n          // Guard against conflicting file types\n          let isDirectory = fsObject instanceof Directory;\n          let originallyDirectory =\n            fsObjectsWithInputPaths[0].fsObject instanceof Directory;\n          if (originallyDirectory !== isDirectory) {\n            let type1 = originallyDirectory ? \"directory\" : \"file\";\n            let path1 = fsObjectsWithInputPaths[0].inputPath;\n            let type2 = isDirectory ? \"directory\" : \"file\";\n            let path2 = inputPath;\n            throw new Error(\n              `Merge error: conflicting file types: ` +\n              `${relativePath} is a ${type1} in ${path1}` +\n              ` but a ${type2} in ${path2}\\n` +\n              `Remove or rename either one of those.`\n            );\n          }\n\n          // Guard against overwriting when disabled\n          if (!isDirectory && !overwrite) {\n            let originalPath = fsObjectsWithInputPaths[0].inputPath;\n            throw new Error(\n              `Merge error: file ${relativePath} exists in ` +\n              `${originalPath} and ${inputPath}\\n` +\n              `Pass option { overwrite: true } to mergeTrees in order ` +\n              `to have the latter file win.`\n            );\n          }\n        }\n\n        fsObjectsWithInputPaths.push({\n          fsObject: fsObject,\n          inputPath: inputPath\n        });\n      }\n    }\n\n    // Done guarding against all error conditions. Actually merge now.\n    let output = new DirectoryIndex();\n    for (let kv of fileInfo) {\n      let fileName = kv[0];\n      let fsObjectsWithInputPaths = kv[1];\n\n      if (fsObjectsWithInputPaths[0].fsObject instanceof Directory) {\n        let subdirectory = this._getMergedDirectory2(\n          fsObjectsWithInputPaths,\n          `${baseDir}${fileName}/`\n        );\n        output.set(fileName, subdirectory);\n      } else {\n        // If there are multiple files, last one wins to get overwriting\n        // behavior.\n        let fsObject =\n          fsObjectsWithInputPaths[fsObjectsWithInputPaths.length - 1].fsObject;\n        output.set(fileName, fsObject);\n      }\n    }\n    return output;\n  }\n}\n\nmodule.exports = MergeTrees;\n"]}