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oBAAsB,MAAO,EAAY,EAAO,CAAE,WAAY,CAAC,KAAM,MAAO,YAChF,IACE,MAAM,QAAc,kBAAkB,GAKtC,OAJoB,cACZ,QAAQ,IAAI,EAAM,KAAI,GAAY,8BAA8B,EAAU,OAG/D,QACjB,CAAC,GAAQ,gBAAe,oBAAoB,IACvC,EACH,CAAC,GAAgB,KAAK,EAAc,QAAQ,MAAO,UAErD,CAAC,EAEL,CAAE,MAAO,GACP,QAAQ,MAAM,EAChB,GAGF,OAAO,QAAU,CAAE","file":"/npm/rollup-entrypoint-generator@0.3.0/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/rollup-entrypoint-generator@0.3.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","const path = require('path')\nconst fs = require('fs')\nconst flatMap = require('lodash.flatmap')\nconst acorn = require('acorn-loose')\nconst find = require('find')\nconst flatten = require('lodash.flatten')\n\n/**\n * @typedef {Object} Options\n * @property {String[]} extensions Array of extensions to try to resolve automatically\n */\n\n/**\n * Find correct entry point based on access path\n *\n * - If path points to a folder, resolve to the `index.js` file contained in this folder\n * - If path exists and points to a file, return this path\n * - If path doesn't exist, try to add extensions `.js` or `.jsx`\n *\n * @param {String} relPath Relative path pointing to a JS *module*\n * @param {Options} opts Options\n * @return {String} Relative path pointing to the corresponding file\n */\nconst findCorrectPath = (relPath, opts) => {\n  if (fs.existsSync(relPath)) {\n    if (fs.lstatSync(relPath).isDirectory()) {\n      return `${relPath}/index.js`\n    }\n    return relPath\n  }\n\n  const fileByExtension = opts.extensions\n    .map(ext => `${relPath}.${ext}`)\n    .find(filePath => fs.existsSync(filePath))\n\n  if (fileByExtension) {\n    return fileByExtension\n  }\n\n  console.warn(`\n    Can't find any file at ${relPath} within the extensions ${opts.extensions}. \n    If this file exists and can be defined as an entrypoint, add its extension in the option extensions.\n  `)\n}\n\n/**\n * Find matching `export { default as` declarations for the given file content.\n *\n * @param {String} filePath Path of the file\n * @param {String} fileContent Content of the file (should be JS code)\n * @param {Options} opts Options\n * @return {Object}\n * @property {String} componentName Name of the exported component\n * @property {String} componentPath Relative path of the found entry point\n */\nconst findExportDeclarationsForContent = (filePath, fileContent, opts) => {\n  const parsed = acorn.parse(fileContent, {\n    sourceType: 'module',\n    ecmaVersion: opts.ecmaVersion || 2020,\n  })\n\n  return flatMap(\n    parsed.body.filter(expr => expr.type === 'ExportNamedDeclaration'),\n    exportDeclaration => {\n      const exportedNames = exportDeclaration.specifiers\n        .filter(specifier => specifier.type === 'ExportSpecifier')\n        .filter(specifier => specifier.local.name === 'default')\n        .map(specifier => specifier.exported.name)\n\n      const componentPath = exportDeclaration.source.value\n\n      const relativePath = findCorrectPath(path.join(filePath, '..', componentPath), opts)\n\n      if (!relativePath) {\n        return []\n      }\n      return exportedNames.map(componentName => ({ componentName, componentPath: relativePath }))\n    },\n  )\n}\n\n/**\n * Read the at the given path to parse it and find matching `export { default as` declarations\n *\n * @param {String} filePath Path of the file\n * @param {Options} opts Options\n * @return {Object}\n * @property {String} componentName Name of the exported component\n * @property {String} componentPath Relative path of the found entry point\n */\nconst findExportDeclarationsForFile = (filePath, opts) => {\n  return new Promise(resolve => {\n    fs.readFile(filePath, { encoding: 'utf-8' }, (err, data) => {\n      try {\n        resolve(findExportDeclarationsForContent(filePath, data, opts))\n      } catch (error) {\n        console.warn(`Could not parse ${filePath}. No entrypoint will be generated for this file.`)\n      }\n    })\n  })\n}\n\n/**\n * Find all files that can contain `export { default as` declarations.\n * Only file paths returned by this method should be parsed.\n *\n * @param {String} sourcePath Base folder of sources\n * @return {String[]} Array of file paths\n */\nconst findEligibleFiles = sourcePath => {\n  return new Promise(resolve => {\n    find.file(/index\\.js$/, sourcePath, files => resolve(files))\n  })\n}\n\nconst generateEntryPoints = async (sourcePath, opts = { extensions: ['js', 'jsx', 'json'] }) => {\n  try {\n    const files = await findEligibleFiles(sourcePath)\n    const entryPoints = flatten(\n      await Promise.all(files.map(filePath => findExportDeclarationsForFile(filePath, opts))),\n    )\n\n    return entryPoints.reduce(\n      (prev, { componentName, componentPath }) => ({\n        ...prev,\n        [componentName]: `./${componentPath.replace(/\\\\/g, '/')}`,\n      }),\n      {},\n    )\n  } catch (e) {\n    console.error(e)\n  }\n}\n\nmodule.exports = { generateEntryPoints }\n"]}