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EAAc,QAAO,GAAQ,EAAI,IAAI,EAAK,KAC3D,MACA,EAAiB,EAOjB,GAFA,SADA,QAAuB,QAAQ,IAAI,EAAe,IAAI,uBAGlD,oBAAoB,EAAoB,GAC1C,OAAO,EAGT,IAAI,QAAmB,OAAO,GAG9B,aAFM,eAAe,EAAa,EAAY,CAAC,SAAU,UAElD,CACT","file":"/npm/@oxygenxml/js-license-aggregator@1.0.11/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/@oxygenxml/js-license-aggregator@1.0.11/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","const {promisify} = require('util');\nconst builder = require('xmlbuilder');\nconst checker = require('license-checker');\nconst getLicenses = promisify(checker.init);\nconst fs = require('fs');\nconst readFileAsync = promisify(fs.readFile);\nconst writeFileAsync = promisify(fs.writeFile);\nconst existsAsync = promisify(fs.exists);\nconst parseString = promisify(require('xml2js').parseString);\nconst path = require('path');\n\n/**\n * @type {boolean} true for windows os.\n */\nconst isWindowsOs = (process.platform + \"\").indexOf(\"win\") === 0;\n/**\n * Generates the XML file for the given components.\n * @param components The array of components.\n */\nasync function genXml(components) {\n  let root = builder.create('third-party');\n  components.forEach(comp => genComponent(root, comp));\n  return root.end({ pretty: true });\n}\n\n\n/**\n * If multiple licenses choose one that is not GPL.\n * @param licenses a license or array of licenses.\n * @return a license\n */\nfunction chooseLicense(licenses) {\n  if (!Array.isArray(licenses)) {\n    licenses = [licenses];\n  }\n  // Dual licensing - avoid GPL\n  let license = licenses\n    .filter(lic => !lic.startsWith(\"GPL\"))[0]\n  if (!license) {\n    throw new Error(\"Unsuitable license: \" + license);\n  }\n  return license;\n}\n\n/**\n * Guess the license URL from a component details.\n *\n * @param component The component descriptor.\n * @return The license URL.\n */\nfunction guessLicenseUrl(component) {\n  var licenseUrl = component.licenseUrl;\n  if (!licenseUrl && component.path && component.licenseFile && component.repository) {\n    var licenseRelPath = \n        component.licenseFile.substring(component.path.length);\n    licenseUrl = component.repository + '/blob/master' + \n        licenseRelPath.replace('\\\\', '/');\n  }\n  return licenseUrl;\n}\n\n\n/**\n * Generates the XML fragment for a component.\n * @param root The root element.\n * @param component The component descriptor.\n */\nfunction genComponent(root, component) {\n  var license = chooseLicense(component.licenses);\n  var licenseUrl = guessLicenseUrl(component);\n\n  var attrs = {id: component.id, product: 'content-fusion'};\n  if (component.draft) {\n    attrs.draft = true;\n  }\n  root.ele('component', attrs)\n    .ele('name', component.name).up()\n    .ele('version', component.version).up()\n    .ele('project-info')\n      .ele('about', component.description).up()\n      .ele('licensor', component.publisher).up()\n      .ele('start-year', component.startYear).up()\n      .ele('project-url', component.repository).up()\n    .up()\n    .ele('license')\n      .ele('type', license).up()\n      .ele('content', component.licenseContent).up()\n      .ele('url', licenseUrl).up()\n    .up()\n}\n\n/**\n * Parse a JS file bundled with browserify (with full paths enabled)\n * and extracts all package.json file paths.\n * @param appPath Path to the JS file.\n * @returns {string[]} Sorted list of package.json file paths.\n */\nfunction getPackageJsonFilesList(appPath) {\n  let files = [];\n  let app = fs.readFileSync(appPath, {encoding: 'utf8'});\n  let regexp;\n  if (isWindowsOs) {\n    regexp = new RegExp('\"([^\"]+node_modules\\\\\\\\\\\\\\\\[^\\\\\\\\]*)[^\"]+\"', 'g');\n  } else {\n    regexp = new RegExp('\"([^\"]+node_modules/[^/]*)[^\"]+\"', 'g');\n  }\n\n  let match = regexp.exec(app);\n  while(match) {\n    let nodeModuleLocation = match[1];\n\n    var packageFolders = [];\n    if (nodeModuleLocation.match(/@[^/\\\\]+$/)) {\n      // Nodejs modules that start with @ are official packages that are namespaced.\n      // So we need to go down one directory.\n      fs.readdirSync(nodeModuleLocation).forEach(folder => {\n        if (isWindowsOs) {\n          packageFolders.push(match[1] + '\\\\\\\\' + folder);\n        } else {\n          packageFolders.push(match[1] + '/' + folder);\n        }\n      })\n    } else {\n      packageFolders = [nodeModuleLocation];\n    }\n\n    packageFolders.forEach(packageFolder => {\n      let packageJson;\n      if (isWindowsOs) {\n        packageJson = packageFolder + \"\\\\\\\\package.json\";\n      } else {\n        packageJson = packageFolder + \"/package.json\";\n      }\n\n      if (files.indexOf(packageJson) === -1) {\n        files.push(packageJson)\n      }\n    });\n\n    match = regexp.exec(app);\n  }\n  files = files.sort();\n  return files;\n}\n\n/**\n * Return the ID of a component based on the package.json file.\n *\n * @param {string} packageFile - Path to a package.json file to be parsed.\n *\n * @return {string} The component ID in a `name@version` format.\n */\nasync function getComponentId(packageFile){\n  let jsonFile = await readFileAsync(packageFile, {encoding: 'utf8'});\n  let json = JSON.parse(jsonFile);\n  return `${json.name}@${json.version}`;\n}\n\n\n/**\n * Returns the IDs of the dependencies bundled by browserify.\n\n * @param appJsPath Path to the browserify bundle.\n\n * @return the list of ids in a `name@version` format.\n */\nasync function getBundledDependeciesIds(appJsPath) {\n\tlet files = getPackageJsonFilesList(appJsPath);\n\treturn Promise.all(files.map(getComponentId));\n}\n\n/**\n * Flattens an array of arrays and converts to a Set.\n * @param array the array to flatten.\n * @return The flattened set of values.\n */\nfunction flattenToSet(array) {\n  let flat = array.reduce((acc, val) => acc.concat(val), []);\n  return new Set(flat);\n}\n\n\n/**\n * Sort an array of components by ID.\n * @param {Array<{id: string}>} components\n */\nfunction sortById(components) {\n  components.sort(({id: id1}, {id: id2}) => {\n    if (id1 < id2) {\n      return -1;\n    }\n    if (id2 < id1) {\n      return 1;\n    }\n    return 0;\n  })\n}\n\n/**\n * Remove falsy fields from an object.\n *\n * @param obj An object.\n *\n * @return The object without falsy fields.\n */\nfunction removeFalsy(obj) {\n  let newObj = {};\n  Object.keys(obj).forEach((prop) => {\n    if (obj[prop]) { \n      newObj[prop] = obj[prop]; \n    }\n  });\n  return newObj;\n}\n\n\n/**\n * Load the components from an existing XML file.\n *\n * @param {string} dbPath The path to the XML file.\n * @return the list of descriptors.\n */\nasync function loadComponents(dbPath) {\n  if (!await existsAsync(dbPath)) {\n    return [];\n  }\n\n  let content = await readFileAsync(dbPath, {encoding: 'utf-8'});\n  let json = await parseString(content);\n\n  if (json) {\n    let components = json['third-party'].component;\n    if (components) {\n      return components.map(comp => {\n        let projInfo = comp['project-info'][0];\n        let licenseInfo = comp['license'][0];\n\n        return removeFalsy({\n          id: comp.$.id,\n          draft: comp.$.draft,\n          name: comp.name[0],\n          version: comp.version[0],\n          description: projInfo.about[0],\n          publisher: projInfo.licensor[0],\n          startYear: projInfo['start-year'][0],\n          url: projInfo['project-url'][0],\n          repository: projInfo['project-url'][0],\n          licenses: licenseInfo.type[0],\n          licenseContent: licenseInfo.content[0],\n          licenseUrl: licenseInfo.url[0]\n        });\n      });\n    }\n  }\n  return [];\n}\n\n/**\n * @param existingComponents The list of existing components.\n * @param components The currnet components.\n *\n * @return {boolean} true if the licenses are up to date.\n */\nfunction areLicensesUpToDate(existingComponents, components) {\n  var draftTrueComp = existingComponents.find(comp => comp.draft);\n  if (draftTrueComp) {\n    console.warn(\"There are components with @draft=true \", draftTrueComp);\n    return false;\n  }\n\n  let oldIds = existingComponents.map(comp => `${comp.name}@${comp.version}`);\n  let newIds = components.map(comp => `${comp.name}@${comp.version}`);\n  let idsMatch = JSON.stringify(oldIds) === JSON.stringify(newIds);\n\n  if (!idsMatch) {\n    console.warn(\"There are new or extra components declared in third-party-components.xml.\");\n    console.warn(\"Component IDs currently used:                         \", newIds);\n    console.warn(\"Component IDs declared in third-party-components.xml: \", oldIds);\n  }\n\n  return idsMatch;\n}\n\n\n/**\n * Create a list of descriptors for new components, some of which being drafts.\n *\n * @param drafts The array of draft descriptors for new components. \n * @param existingComponents The array of exising components descriptors.\n *\n * @return A list of draft component descriptors.\n */\nfunction mergeDrafts(drafts, existingComponents) {\n  let existingComponentsById = new Map(existingComponents.map(d => [d.id, d]));\n  let existingComponentsByName = new Map(existingComponents.map(d => [d.name, d]));\n\n  return drafts.map(draft => {\n    // The component was already used - preserve its details.\n    let existingComponent = existingComponentsById.get(draft.id);\n    if (existingComponent) {\n      return existingComponent;\n    }\n\n    // The component was already used at a different version - use that as \n    // a starting point.\n    let compWithSameName = existingComponentsByName.get(draft.name);\n    if (compWithSameName) {\n      return Object.assign({draft: true}, compWithSameName, {id: draft.id, version: draft.version});\n    }\n\n    // The component is new - use the draft.\n    return draft;\n  });\n}\n\n\n/**\n * Guesses the license content of a component.\n *\n * @param component The descriptor of a component.\n */\nasync function guessLicenseContent(component) {\n  var content = component.licenseContent;\n  if (!content && component.licenseFile) {\n    content = await readFileAsync(component.licenseFile, {encoding: 'utf8'});\n    component.licenseContent = content;\n  }\n  return component;\n}\n\n\n/**\n * Create draft descriptors for dependencies using the `license-checker` library. \n *\n * @param {string} projectPath The path to the project folder.\n * @param {boolean} production true if we should check only production deps.\n *\n * @return an array of draft descriptors.\n */\nasync function createDrafts(projectPath, production) {\n  // Custom format for license-checker\n  const customFormat = {\n    id: \"\",\n    name: \"\",\n    version: \"\",\n    repository: \"\",\n    publisher: \"\",\n    url: \"\",\n    licenses: \"\",\n    licenseFile: \"\",\n    license: \"\",\n    description: \"\"\n  };\n\n  let draftsCustom = await getLicenses({\n    start: projectPath,\n    production: production,\n    customFormat\n  });\n\n  // Ask also for default params since if we specify the format, some\n  // details will not be included\n  let draftsDefault = await getLicenses({\n    start: projectPath,\n    production: production\n  });\n\n  return Object.keys(draftsCustom)\n    .filter(id => {\n      var info = draftsCustom[id];\n      return info.license !== \"OXYGEN EULA\"\n    })\n    .map(id => {\n    var info = draftsCustom[id];\n    return Object.assign({}, draftsDefault[id], {\n      version: info.version,\n      name: info.name,\n      description: info.description,\n      id: `${info.name}@${info.version}`,\n      draft: true\n    });\n  });\n}\n\n/**\n * Generates the third-party components file for a given project.\n * @param options.path The path of the project\n * @param options.browserifyBundles An array with the paths to the browserify bundles.\n */\nexports.genThirdPartyComponentsXml = async function genThirdPartyComponentsXml(options) {\n  options = options || {};\n  let projectPath = options.path || '.';\n  let xmlFilePath = path.resolve(projectPath, 'third-party-components.xml');\n  let browserifyBundles = options.browserifyBundles || [];\n\n\tlet isBrowserify = browserifyBundles.length !== 0;\n  // Browserify bundles also dev-dependencies.\n\tlet production = !isBrowserify;\n\n  let existingComponents = await loadComponents(xmlFilePath);\n  let drafts = await createDrafts(projectPath, production);\n\n  let newComponents = mergeDrafts(drafts, existingComponents);\n\n\tvar usedComponents;\n  if (isBrowserify) {\n\t\tlet idsPerBundle = await Promise.all(browserifyBundles.map(getBundledDependeciesIds));\n\t\tlet ids = flattenToSet(idsPerBundle);\n\t\tusedComponents = newComponents.filter(comp => ids.has(comp.id));\n  } else {\n\t\tusedComponents = newComponents;\n  }\n\n  // Try to read the license content if not already available\n  usedComponents = await Promise.all(usedComponents.map(guessLicenseContent))\n  sortById(usedComponents);\n\n  if (areLicensesUpToDate(existingComponents, usedComponents)) {\n    return true;\n  }\n\n  var xmlContent = await genXml(usedComponents);\n  await writeFileAsync(xmlFilePath, xmlContent, {encoding: 'utf8'});\n\n  return false;\n};\n\n"]}