{"version":3,"file":"functions-BbQkbvEM.cjs","names":[],"sources":["../src/functions/nuke.function.options.ts","../src/functions/nuke.function.ts"],"sourcesContent":["import {\n\tnormalizeDryOption,\n\ttype Defined,\n\ttype DryOption,\n\ttype NormalizedDryOption,\n} from '@alexaegis/common';\nimport {\n\tnormalizeLoggerOption,\n\ttype LoggerOption,\n\ttype NormalizedLoggerOption,\n} from '@alexaegis/logging';\nimport {\n\tnormalizeCollectWorkspacePackagesOptions,\n\ttype CollectWorkspacePackagesOptions,\n\ttype NormalizedCollectWorkspacePackagesOptions,\n} from '@alexaegis/workspace-tools';\n\nexport const DEFAULT_NUKE_LIST: string[] = [\n\t'.cache',\n\t'node_modules',\n\t'dist',\n\t'.turbo',\n\t'coverage',\n\t'package-lock.json',\n\t'pnpm-lock.yaml',\n\t'typedoc',\n\t'.svelte-kit',\n];\n\nexport const DEFAULT_NUKE_GLOBS: string[] = [\n\t'./vite.config.ts.timestamp*',\n\t'./vitest.config.ts.timestamp*',\n];\n\nexport interface NukeOptionsOnly {\n\t/**\n\t * Don't remove `node_modules` directories but try to clean them up\n\t *\n\t * @defaultValue false\n\t */\n\tskipNodeModules?: boolean;\n\n\t/**\n\t * A list of relative paths this script will remove in every package\n\t * in the workspace. If you define this, the default are not applied.\n\t *\n\t * If you only wish to extend or remove parts of it use the `nukeMore`\n\t * and `dontNuke` fields and leave this one alone.\n\t *\n\t * @defaultValue DEFAULT_NUKE_LIST\n\t */\n\tnukeList?: string[] | undefined;\n\n\t/**\n\t * Globs to also remove.\n\t *\n\t * If you only wish to extend or remove parts of it use the `nukeMoreGlobs`\n\t * and `dontNuke` fields and leave this one alone.\n\t *\n\t * @defaultValue DEFAULT_NUKE_GLOBS\n\t */\n\tnukeGlobs?: string[] | undefined;\n\n\t/**\n\t * Additional globs to nuke if you don't want to overwrite the default ones\n\t *\n\t * @defaultValue undefined\n\t */\n\tnukeMoreGlobs?: string[] | undefined;\n\n\t/**\n\t * These will be nuked too. Same role as `nukeList` but defining this\n\t * won't get rid of the built in nukelist\n\t *\n\t * @defaultValue []\n\t */\n\tnukeMore?: string[] | undefined;\n\n\t/**\n\t * If it shouldn't nuke a specific package, add them here.\n\t *\n\t * @defaultValue []\n\t */\n\tdontNukeIn?: (string | RegExp)[] | undefined;\n}\n\nexport type NukeOptions = NukeOptionsOnly &\n\tDryOption &\n\tCollectWorkspacePackagesOptions &\n\tLoggerOption;\n\nexport type NormalizedNukeOptions = Defined<NukeOptionsOnly> &\n\tNormalizedDryOption &\n\tNormalizedCollectWorkspacePackagesOptions &\n\tNormalizedLoggerOption;\n\nexport const normalizeNukeOptions = (options?: NukeOptions): NormalizedNukeOptions => {\n\treturn {\n\t\t...normalizeCollectWorkspacePackagesOptions(options),\n\t\t...normalizeDryOption(options),\n\t\t...normalizeLoggerOption(options),\n\t\tskipNodeModules: options?.skipNodeModules ?? false,\n\t\tnukeList: options?.nukeList ?? DEFAULT_NUKE_LIST,\n\t\tnukeGlobs: options?.nukeGlobs ?? DEFAULT_NUKE_GLOBS,\n\t\tnukeMoreGlobs: options?.nukeMoreGlobs ?? [],\n\t\tnukeMore: options?.nukeMore ?? [],\n\t\tdontNukeIn: options?.dontNukeIn ?? [],\n\t};\n};\n","import { dry } from '@alexaegis/common';\nimport { collectWorkspacePackages } from '@alexaegis/workspace-tools';\nimport { globby } from 'globby';\nimport { existsSync } from 'node:fs';\nimport { rm } from 'node:fs/promises';\nimport { join, relative } from 'node:path';\nimport { normalizeNukeOptions, type NukeOptions } from './nuke.function.options.ts';\n\n/**\n * Removes a bunch of stuff from packages for cleaning.\n */\nexport const nuke = async (rawOptions?: NukeOptions): Promise<void> => {\n\tconst options = normalizeNukeOptions(rawOptions);\n\n\tconst allWorkspacePackages = await collectWorkspacePackages(options);\n\n\tif (allWorkspacePackages.length === 0) {\n\t\tthrow new Error('not in a workspace!');\n\t}\n\n\tconst nukeList = [...options.nukeList, ...options.nukeMore];\n\tconst nukeGlobs = [...options.nukeGlobs, ...options.nukeMoreGlobs];\n\n\tconst nonSkippedWorkspacePackages = allWorkspacePackages.filter(\n\t\t(workspacePackage) =>\n\t\t\t!options.dontNukeIn.some((skip) =>\n\t\t\t\ttypeof skip === 'string'\n\t\t\t\t\t? skip === workspacePackage.packagePath\n\t\t\t\t\t: skip.test(workspacePackage.packagePath),\n\t\t\t),\n\t);\n\n\tconst rootPackage = allWorkspacePackages.find(\n\t\t(workspacePackage) => workspacePackage.packageKind === 'root',\n\t);\n\n\tif (!rootPackage) {\n\t\toptions.logger.error('Not inside a workspace!');\n\t\treturn;\n\t}\n\n\tconst packageFlatNukeTargets = nonSkippedWorkspacePackages.flatMap((workspacePackage) =>\n\t\tnukeList.map((toNuke) => join(workspacePackage.packagePath, toNuke)),\n\t);\n\n\tconst packageGlobNukeTargets = await Promise.all(\n\t\tnonSkippedWorkspacePackages.map((packageDirectory) =>\n\t\t\tglobby(nukeGlobs, {\n\t\t\t\tcwd: packageDirectory.packagePath,\n\t\t\t\tdot: true,\n\t\t\t\tfollowSymbolicLinks: false,\n\t\t\t\texpandDirectories: false,\n\t\t\t}).then((paths) => paths.map((path) => join(packageDirectory.packagePath, path))),\n\t\t),\n\t);\n\n\tconst everyNukeTarget = [...packageFlatNukeTargets, ...packageGlobNukeTargets.flat()].sort();\n\tconst dryRm = dry(options.dry, rm);\n\n\tawait Promise.allSettled(\n\t\teveryNukeTarget\n\t\t\t.filter((nukeTarget) => existsSync(nukeTarget))\n\t\t\t.map((nukeTarget) => {\n\t\t\t\toptions.logger.warn(\n\t\t\t\t\t'obliterating: ' + relative(rootPackage.packagePath, nukeTarget),\n\t\t\t\t);\n\t\t\t\treturn dryRm(nukeTarget, { recursive: true }).catch(() => false);\n\t\t\t}),\n\t);\n};\n"],"mappings":";;;;;;;;AAiBA,IAAa,oBAA8B;CAC1C;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACD;AAEA,IAAa,qBAA+B,CAC3C,+BACA,+BACD;AAgEA,IAAa,wBAAwB,YAAiD;CACrF,OAA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