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GACV,QAAQ,eAAgB,EAAiB,UAK5C,GACF,QAAQ,MACN,EACA,GAAG,KAAK,UAAU,EAAkB,KAAM,QAalD,GANI,EAAQ,eAMU,IAAlB,EAAQ,MAKZ,OAAO,MAAM,kCAAkC,EAAiB,cAAe,CAC7E,SAAU,OACV,MAAO,IAER,MAAM,IAEL,OAAO,IAAI,MAAM,MAAM,UAAU,EAAiB,gBAAgB,EAAE,cAAc,EAAE,iBAAiB,EAAE,aAAa,IAErH,OAAO,IAEN,OAAO,MAAM,mBAAmB,EAAiB,QAAS,EAAE,MAAM,GAEtE","file":"/npm/prepare-package@1.2.5/dist/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/prepare-package@1.2.5/dist/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 jetpack = require('fs-jetpack');\nconst fetch = require('wonderful-fetch');\nconst path = require('path');\nconst chalk = require('chalk');\nconst logger = require('./logger');\n\n// const argv = require('yargs').argv;\n\n// Helper function to check for local dependencies\nfunction checkForLocalDependencies(packageJSON) {\n  const localDeps = [];\n  const depTypes = [\n    'dependencies',\n    'devDependencies',\n    'peerDependencies',\n    'optionalDependencies'\n  ];\n\n  depTypes.forEach(type => {\n    if (!packageJSON[type]) {\n      return;\n    }\n\n    Object.entries(packageJSON[type]).forEach(([name, version]) => {\n      // Check for file: protocol or relative/absolute paths\n      if (version.startsWith('file:')\n        || version.startsWith('../')\n        || version.startsWith('./')\n        || version.startsWith('/')\n        || version.startsWith('~')) {\n        localDeps.push({\n          type,\n          name,\n          value: version\n        });\n      }\n    });\n  });\n\n  return localDeps;\n}\n\nmodule.exports = async function (options) {\n  // Set the options\n  options = options || {};\n  options.purge = typeof options.purge === 'undefined' ? true : options.purge;\n  options.cwd = options.cwd || process.cwd();\n  options.isPostInstall = typeof options.isPostInstall === 'undefined' ? false : options.isPostInstall;\n  options.singleFile = options.singleFile || null; // For watch mode - single file to process\n\n  // Detect if running via npm publish\n  // When npm publish runs, it sets npm_command to 'publish' even though lifecycle_event is 'prepare'\n  const isPublishing = process.env.npm_command === 'publish'\n    || process.env.npm_lifecycle_event === 'prepublishOnly'\n    || process.env.npm_lifecycle_event === 'prepublish';\n  const isManualPrepare = process.env.npm_lifecycle_event === 'prepare' && !isPublishing;\n\n  // Set the paths\n  const theirPackageJSONPath = path.resolve(options.cwd, 'package.json');\n  const theirPackageJSONExists = jetpack.exists(theirPackageJSONPath);\n\n  // Get the package.json files\n  const thisPackageJSON = require('../package.json');\n  const theirPackageJSON = theirPackageJSONExists ? require(theirPackageJSONPath) : {};\n  const isLivePreparation = theirPackageJSON.name !== 'prepare-package';\n\n\n  // Check for local dependencies when publishing\n  if (isPublishing) {\n    const hasLocalDeps = checkForLocalDependencies(theirPackageJSON);\n    if (hasLocalDeps.length > 0) {\n      logger.error('Cannot publish with local dependencies!');\n      logger.error('The following dependencies use local file references:');\n      hasLocalDeps.forEach(dep => {\n        logger.error(`  - ${dep.type}: ${dep.name} -> ${dep.value}`);\n      });\n      throw new Error('Publishing blocked: Remove local file dependencies before publishing to npm');\n    }\n  }\n\n  // const options = {\n  //   purge: argv['--purge'] || argv['-p'],\n  // };\n\n  // Fix their package.json\n  theirPackageJSON.main = theirPackageJSON.main || './dist/index.js';\n  theirPackageJSON.preparePackage = theirPackageJSON.preparePackage || {};\n  theirPackageJSON.preparePackage.input = theirPackageJSON.preparePackage.input || './src';\n  theirPackageJSON.preparePackage.output = theirPackageJSON.preparePackage.output || './dist';\n  theirPackageJSON.preparePackage.replace = theirPackageJSON.preparePackage.replace || {};\n\n  // Add script\n  theirPackageJSON.scripts = theirPackageJSON.scripts || {};\n  // theirPackageJSON.scripts.prepare = theirPackageJSON.scripts.prepare\n  //   || 'node -e \\'require(`prepare-package`)()\\'';\n  // theirPackageJSON.scripts['prepare:watch'] = theirPackageJSON.scripts['prepare:watch']\n  //   || `nodemon -w ./src -e '*' --exec 'npm run prepare'`\n  theirPackageJSON.scripts.prepare = `node -e \\\"require('prepare-package')()\\\"`;\n  theirPackageJSON.scripts['prepare:watch'] = `node -e \\\"require('prepare-package/watch')()\\\"`\n\n  // Log the options\n  // console.log(chalk.blue(`[prepare-package]: Options purge=${options.purge}`));\n  // console.log(chalk.blue(`[prepare-package]: input=${theirPackageJSON.preparePackage.input}`));\n  // console.log(chalk.blue(`[prepare-package]: output=${theirPackageJSON.preparePackage.output}`));\n  // console.log(chalk.blue(`[prepare-package]: main=${theirPackageJSON.main}`));\n  if (!options.singleFile) {\n    logger.log(`Starting...${isPublishing ? ' (via npm publish)' : ''}`);\n    logger.log({\n      purge: options.purge,\n      input: theirPackageJSON.preparePackage.input,\n      output: theirPackageJSON.preparePackage.output,\n      main: theirPackageJSON.main,\n\n      // lifecycle: process.env.npm_lifecycle_event,\n      // command: process.env.npm_command,\n      isPublishing: isPublishing,\n    });\n  }\n\n  // Set the paths relative to the cwd\n  const mainPath = path.resolve(options.cwd, theirPackageJSON.main);\n  const outputPath = path.resolve(options.cwd, theirPackageJSON.preparePackage.output);\n  const inputPath = path.resolve(options.cwd, theirPackageJSON.preparePackage.input);\n\n  // Check if paths exist\n  const mainPathExists = jetpack.exists(mainPath);\n  const outputPathExists = jetpack.exists(outputPath);\n  const inputPathExists = jetpack.exists(inputPath);\n\n  // Handle single file mode (for watch)\n  if (options.singleFile) {\n    const relativePath = path.relative(inputPath, options.singleFile);\n    const destPath = path.join(outputPath, relativePath);\n\n    // Copy single file\n    if (jetpack.exists(options.singleFile)) {\n      jetpack.copy(options.singleFile, destPath, { overwrite: true });\n      logger.log(`Updated: ${relativePath}`);\n    }\n  } else {\n    // Normal mode - full copy\n    // Remove the output folder if it exists (input must exist too)\n    if (outputPathExists && inputPathExists) {\n      jetpack.remove(outputPath);\n    }\n\n    // Copy the input folder to the output folder if it exists\n    if (inputPathExists) {\n      jetpack.copy(inputPath, outputPath);\n    }\n  }\n\n  // Only do this part on the actual package that is using THIS package because we dont't want to replace THIS {version}\n  if (isLivePreparation) {\n    // In single file mode, only process if it's the main file\n    if (options.singleFile) {\n      const destPath = path.join(outputPath, path.relative(inputPath, options.singleFile));\n      if (destPath === mainPath && jetpack.exists(destPath)) {\n        jetpack.write(\n          destPath,\n          jetpack.read(destPath).replace(/{version}/igm, theirPackageJSON.version)\n        );\n      }\n    } else {\n      // Normal mode - process main file and package.json\n      // Replace the main file\n      if (mainPathExists) {\n        jetpack.write(\n          mainPath,\n          jetpack.read(mainPath)\n            .replace(/{version}/igm, theirPackageJSON.version),\n        );\n      }\n\n      // Replace the package.json\n      if (theirPackageJSONExists) {\n        jetpack.write(\n          theirPackageJSONPath,\n          `${JSON.stringify(theirPackageJSON, null, 2)}\\n`\n        );\n      }\n    }\n  }\n\n  // Handle post install\n  if (options.isPostInstall) {\n    // Send analytics\n    // ... moveed to another package\n  }\n\n  // If purge is disabled, then return\n  if (options.purge === false) {\n    return;\n  }\n\n  // Purge the CDN\n  return fetch(`https://purge.jsdelivr.net/npm/${theirPackageJSON.name}@latest`, {\n    response: 'json',\n    tries: 3,\n  })\n  .then((r) => {\n    // console.log(chalk.green(`[prepare-package]: Purged ${theirPackageJSON.name}`));\n    logger.log(chalk.green(`Purged ${theirPackageJSON.name}: status=${r.status}, id=${r.id}, timestamp=${r.timestamp}`));\n  })\n  .catch((e) => {\n    // console.log(chalk.red(`[prepare-package]: Failed to purge ${theirPackageJSON.name}`, e));\n    logger.error(`Failed to purge ${theirPackageJSON.name}!`, e.stack);\n  })\n}\n\n"]}