@xylabs/ts-scripts-yarn3 4.0.0-rc.9 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/actions/build.mjs.map +1 -1
- package/dist/actions/clean-docs.mjs +14 -4
- package/dist/actions/clean-docs.mjs.map +1 -1
- package/dist/actions/clean-eslint.mjs +16 -4
- package/dist/actions/clean-eslint.mjs.map +1 -1
- package/dist/actions/clean-jest.mjs.map +1 -1
- package/dist/actions/clean.mjs.map +1 -1
- package/dist/actions/compile.mjs +3 -2
- package/dist/actions/compile.mjs.map +1 -1
- package/dist/actions/copy-assets.mjs.map +1 -1
- package/dist/actions/cycle.mjs +25 -110
- package/dist/actions/cycle.mjs.map +1 -1
- package/dist/actions/dead.mjs.map +1 -1
- package/dist/actions/deploy-major.mjs.map +1 -1
- package/dist/actions/deploy-minor.mjs.map +1 -1
- package/dist/actions/deploy-next.mjs.map +1 -1
- package/dist/actions/deploy.mjs.map +1 -1
- package/dist/actions/deps.mjs.map +1 -1
- package/dist/actions/dupdeps.mjs +3 -2
- package/dist/actions/dupdeps.mjs.map +1 -1
- package/dist/actions/fix.mjs.map +1 -1
- package/dist/actions/gen-docs.mjs.map +1 -1
- package/dist/actions/gitignore-gen.mjs.map +1 -1
- package/dist/actions/index.mjs +213 -55
- package/dist/actions/index.mjs.map +1 -1
- package/dist/actions/license.mjs.map +1 -1
- package/dist/actions/lint-clean.mjs.map +1 -1
- package/dist/actions/lint-profile.mjs.map +1 -1
- package/dist/actions/lint.mjs.map +1 -1
- package/dist/actions/npmignore-gen.mjs.map +1 -1
- package/dist/actions/package/clean-outputs.mjs +16 -2
- package/dist/actions/package/clean-outputs.mjs.map +1 -1
- package/dist/actions/package/clean-typescript.mjs +16 -2
- package/dist/actions/package/clean-typescript.mjs.map +1 -1
- package/dist/actions/package/clean.mjs +17 -4
- package/dist/actions/package/clean.mjs.map +1 -1
- package/dist/actions/package/compile/buildEntries.mjs.map +1 -1
- package/dist/actions/package/compile/compile.mjs +151 -11
- package/dist/actions/package/compile/compile.mjs.map +1 -1
- package/dist/actions/package/compile/copyTypeFiles.mjs.map +1 -1
- package/dist/actions/package/compile/getCompilerOptions.mjs +145 -8
- package/dist/actions/package/compile/getCompilerOptions.mjs.map +1 -1
- package/dist/actions/package/compile/index.mjs +151 -11
- package/dist/actions/package/compile/index.mjs.map +1 -1
- package/dist/actions/package/compile/packageCompileTsc.mjs +148 -8
- package/dist/actions/package/compile/packageCompileTsc.mjs.map +1 -1
- package/dist/actions/package/compile/packageCompileTscTypes.mjs +145 -8
- package/dist/actions/package/compile/packageCompileTscTypes.mjs.map +1 -1
- package/dist/actions/package/compile/packageCompileTsup.mjs +3 -0
- package/dist/actions/package/compile/packageCompileTsup.mjs.map +1 -1
- package/dist/actions/package/copy-assets.mjs.map +1 -1
- package/dist/actions/package/deps.mjs.map +1 -1
- package/dist/actions/package/gen-docs.mjs.map +1 -1
- package/dist/actions/package/index.mjs +205 -52
- package/dist/actions/package/index.mjs.map +1 -1
- package/dist/actions/package/publint.mjs +3 -0
- package/dist/actions/package/publint.mjs.map +1 -1
- package/dist/actions/package/recompile.mjs +192 -39
- package/dist/actions/package/recompile.mjs.map +1 -1
- package/dist/actions/publint.mjs.map +1 -1
- package/dist/actions/rebuild.mjs.map +1 -1
- package/dist/actions/recompile.mjs.map +1 -1
- package/dist/actions/reinstall.mjs.map +1 -1
- package/dist/actions/relint.mjs.map +1 -1
- package/dist/actions/retest.mjs.map +1 -1
- package/dist/actions/sonar.mjs.map +1 -1
- package/dist/actions/statics.mjs +3 -2
- package/dist/actions/statics.mjs.map +1 -1
- package/dist/actions/test.mjs.map +1 -1
- package/dist/actions/up.mjs.map +1 -1
- package/dist/actions/updo.mjs.map +1 -1
- package/dist/actions/upplug.mjs.map +1 -1
- package/dist/actions/upyarn.mjs.map +1 -1
- package/dist/actions/yarn3only.mjs.map +1 -1
- package/dist/bin/package/clean-outputs.mjs +14 -2
- package/dist/bin/package/clean-outputs.mjs.map +1 -1
- package/dist/bin/package/clean-typescript.mjs +14 -2
- package/dist/bin/package/clean-typescript.mjs.map +1 -1
- package/dist/bin/package/clean.mjs +15 -4
- package/dist/bin/package/clean.mjs.map +1 -1
- package/dist/bin/package/compile-only.mjs +151 -11
- package/dist/bin/package/compile-only.mjs.map +1 -1
- package/dist/bin/package/compile-tsup.mjs +3 -0
- package/dist/bin/package/compile-tsup.mjs.map +1 -1
- package/dist/bin/package/compile.mjs +151 -11
- package/dist/bin/package/compile.mjs.map +1 -1
- package/dist/bin/package/copy-assets-cjs.mjs.map +1 -1
- package/dist/bin/package/copy-assets-esm.mjs.map +1 -1
- package/dist/bin/package/deps.mjs.map +1 -1
- package/dist/bin/package/gen-docs.mjs.map +1 -1
- package/dist/bin/package/publint.mjs +3 -0
- package/dist/bin/package/publint.mjs.map +1 -1
- package/dist/bin/package/recompile.mjs +170 -19
- package/dist/bin/package/recompile.mjs.map +1 -1
- package/dist/bin/xy-ts.mjs +52 -32
- package/dist/bin/xy-ts.mjs.map +1 -1
- package/dist/bin/xy.mjs +52 -32
- package/dist/bin/xy.mjs.map +1 -1
- package/dist/index.d.ts +11 -9
- package/dist/index.mjs +216 -57
- package/dist/index.mjs.map +1 -1
- package/dist/lib/createBuildConfig.mjs.map +1 -1
- package/dist/lib/defaultBuildConfig.mjs.map +1 -1
- package/dist/lib/deleteGlob.mjs +19 -0
- package/dist/lib/deleteGlob.mjs.map +1 -0
- package/dist/lib/dependencies/DuplicateDetector.mjs +3 -2
- package/dist/lib/dependencies/DuplicateDetector.mjs.map +1 -1
- package/dist/lib/dependencies/detectDuplicateDependencies.mjs +3 -2
- package/dist/lib/dependencies/detectDuplicateDependencies.mjs.map +1 -1
- package/dist/lib/dependencies/index.mjs +3 -2
- package/dist/lib/dependencies/index.mjs.map +1 -1
- package/dist/lib/file/ReadFileSyncOptions.mjs.map +1 -1
- package/dist/lib/file/fileLines.mjs.map +1 -1
- package/dist/lib/file/index.mjs.map +1 -1
- package/dist/lib/file/tryReadFileSync.mjs.map +1 -1
- package/dist/lib/generateIgnoreFiles.mjs.map +1 -1
- package/dist/lib/index.mjs +160 -5
- package/dist/lib/index.mjs.map +1 -1
- package/dist/lib/loadConfig.mjs +143 -3
- package/dist/lib/loadConfig.mjs.map +1 -1
- package/dist/lib/processEx.mjs.map +1 -1
- package/dist/lib/runSteps.mjs.map +1 -1
- package/dist/lib/runStepsAsync.mjs.map +1 -1
- package/dist/lib/runXy.mjs.map +1 -1
- package/dist/lib/safeExit.mjs.map +1 -1
- package/dist/lib/withErrnoException.mjs.map +1 -1
- package/dist/lib/yarn/index.mjs.map +1 -1
- package/dist/lib/yarn/workspace/index.mjs.map +1 -1
- package/dist/lib/yarn/workspace/yarnWorkspace.mjs.map +1 -1
- package/dist/lib/yarn/workspace/yarnWorkspaces.mjs.map +1 -1
- package/dist/loadPackageConfig.mjs.map +1 -1
- package/dist/xy/index.mjs +52 -32
- package/dist/xy/index.mjs.map +1 -1
- package/dist/xy/param.mjs.map +1 -1
- package/dist/xy/xy.mjs +52 -32
- package/dist/xy/xy.mjs.map +1 -1
- package/dist/xy/xyBuildCommands.mjs +3 -2
- package/dist/xy/xyBuildCommands.mjs.map +1 -1
- package/dist/xy/xyCommonCommands.mjs +14 -4
- package/dist/xy/xyCommonCommands.mjs.map +1 -1
- package/dist/xy/xyDeployCommands.mjs.map +1 -1
- package/dist/xy/xyInstallCommands.mjs +3 -2
- package/dist/xy/xyInstallCommands.mjs.map +1 -1
- package/dist/xy/xyLintCommands.mjs +30 -22
- package/dist/xy/xyLintCommands.mjs.map +1 -1
- package/dist/xy/xyParseOptions.mjs.map +1 -1
- package/package.json +53 -55
- package/src/actions/build.ts +3 -1
- package/src/actions/clean-docs.ts +2 -3
- package/src/actions/clean-eslint.ts +3 -2
- package/src/actions/clean.ts +3 -1
- package/src/actions/compile.ts +13 -3
- package/src/actions/cycle.ts +15 -4
- package/src/actions/deps.ts +6 -5
- package/src/actions/gen-docs.ts +3 -4
- package/src/actions/package/clean-outputs.ts +3 -2
- package/src/actions/package/clean-typescript.ts +3 -2
- package/src/actions/package/compile/XyConfig.ts +5 -13
- package/src/actions/package/compile/buildEntries.ts +1 -1
- package/src/actions/package/compile/compile.ts +3 -1
- package/src/actions/package/compile/copyTypeFiles.ts +1 -1
- package/src/actions/package/compile/getCompilerOptions.ts +10 -8
- package/src/actions/package/compile/packageCompileTsc.ts +11 -6
- package/src/actions/package/compile/packageCompileTscTypes.ts +5 -3
- package/src/actions/package/compile/packageCompileTsup.ts +6 -3
- package/src/actions/package/copy-assets.ts +1 -3
- package/src/actions/package/deps.ts +6 -2
- package/src/actions/package/gen-docs.ts +3 -1
- package/src/actions/package/publint.ts +8 -5
- package/src/actions/publint.ts +3 -1
- package/src/actions/recompile.ts +47 -9
- package/src/actions/reinstall.ts +3 -1
- package/src/lib/defaultBuildConfig.ts +11 -1
- package/src/lib/deleteGlob.ts +13 -0
- package/src/lib/dependencies/DuplicateDetector.ts +4 -4
- package/src/lib/file/ReadFileSyncOptions.ts +4 -1
- package/src/lib/file/fileLines.ts +9 -3
- package/src/lib/file/tryReadFileSync.ts +4 -2
- package/src/lib/generateIgnoreFiles.ts +3 -1
- package/src/lib/index.ts +1 -0
- package/src/lib/loadConfig.ts +3 -4
- package/src/lib/runSteps.ts +2 -1
- package/src/lib/runStepsAsync.ts +1 -1
- package/src/lib/runXy.ts +4 -1
- package/src/lib/withErrnoException.ts +3 -1
- package/src/lib/yarn/workspace/yarnWorkspace.ts +1 -1
- package/src/lib/yarn/workspace/yarnWorkspaces.ts +1 -1
- package/src/loadPackageConfig.ts +1 -1
- package/src/types.d.ts +23 -0
- package/src/xy/param.ts +2 -4
- package/src/xy/xyBuildCommands.ts +10 -20
- package/src/xy/xyCommonCommands.ts +4 -2
- package/src/xy/xyDeployCommands.ts +4 -2
- package/src/xy/xyInstallCommands.ts +5 -5
- package/src/xy/xyLintCommands.ts +6 -4
- package/src/xy/xyParseOptions.ts +3 -2
- package/tsup.config.ts +2 -6
- package/xy.config.ts +1 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/lib/createBuildConfig.ts","../../src/lib/defaultBuildConfig.ts"],"sourcesContent":["import { readFileSync } from 'node:fs'\n\nimport { defaultBuildConfig } from './defaultBuildConfig.ts'\n\nconst getGeneralTypescriptConfig = (location: string) => {\n let generalConfig: string | undefined\n try {\n generalConfig = readFileSync(`${location}/tsconfig.json`, { encoding: 'utf8' })\n } catch {\n return false\n }\n return JSON.parse(generalConfig)\n}\n\nexport const createBuildConfig = (\n location: string,\n module: 'ESNext' | 'CommonJS',\n target: 'ESNext' | 'ES6',\n outDirSuffix: string,\n): Record<string, unknown> | undefined => {\n const generalConfigObject = getGeneralTypescriptConfig(location)\n if (generalConfigObject === false) {\n return undefined\n }\n return {\n ...generalConfigObject,\n compilerOptions: {\n ...defaultBuildConfig.compilerOptions,\n ...generalConfigObject.compilerOptions,\n module,\n outDir: `./${generalConfigObject.compilerOptions?.outDir ?? 'dist'}/${outDirSuffix}`,\n target,\n },\n exclude: [...(generalConfigObject.exclude ?? []), ...defaultBuildConfig.exclude],\n include: [...(generalConfigObject.include ?? []), ...defaultBuildConfig.include],\n }\n}\n","export const defaultBuildConfig = {\n compilerOptions: {\n rootDir: 'src',\n rootDirs: ['package.json'],\n },\n exclude: ['**/build'
|
|
1
|
+
{"version":3,"sources":["../../src/lib/createBuildConfig.ts","../../src/lib/defaultBuildConfig.ts"],"sourcesContent":["import { readFileSync } from 'node:fs'\n\nimport { defaultBuildConfig } from './defaultBuildConfig.ts'\n\nconst getGeneralTypescriptConfig = (location: string) => {\n let generalConfig: string | undefined\n try {\n generalConfig = readFileSync(`${location}/tsconfig.json`, { encoding: 'utf8' })\n } catch {\n return false\n }\n return JSON.parse(generalConfig)\n}\n\nexport const createBuildConfig = (\n location: string,\n module: 'ESNext' | 'CommonJS',\n target: 'ESNext' | 'ES6',\n outDirSuffix: string,\n): Record<string, unknown> | undefined => {\n const generalConfigObject = getGeneralTypescriptConfig(location)\n if (generalConfigObject === false) {\n return undefined\n }\n return {\n ...generalConfigObject,\n compilerOptions: {\n ...defaultBuildConfig.compilerOptions,\n ...generalConfigObject.compilerOptions,\n module,\n outDir: `./${generalConfigObject.compilerOptions?.outDir ?? 'dist'}/${outDirSuffix}`,\n target,\n },\n exclude: [...(generalConfigObject.exclude ?? []), ...defaultBuildConfig.exclude],\n include: [...(generalConfigObject.include ?? []), ...defaultBuildConfig.include],\n }\n}\n","export const defaultBuildConfig = {\n compilerOptions: {\n rootDir: 'src',\n rootDirs: ['package.json'],\n },\n exclude: [\n '**/build',\n '**/dist',\n '**/node_modules',\n '**/*.spec.*',\n '**/*.spec',\n '**/*.stories.*',\n '**/*.example.*',\n '**/spec/*',\n '**/stories/*',\n ],\n include: ['src'],\n}\n"],"mappings":";;;;AAAA,SAASA,oBAAoB;;;ACAtB,IAAMC,qBAAqB;EAChCC,iBAAiB;IACfC,SAAS;IACTC,UAAU;MAAC;;EACb;EACAC,SAAS;IACP;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;;EAEFC,SAAS;IAAC;;AACZ;;;ADbA,IAAMC,6BAA6B,wBAACC,aAAAA;AAClC,MAAIC;AACJ,MAAI;AACFA,oBAAgBC,aAAa,GAAGF,QAAAA,kBAA0B;MAAEG,UAAU;IAAO,CAAA;EAC/E,QAAQ;AACN,WAAO;EACT;AACA,SAAOC,KAAKC,MAAMJ,aAAAA;AACpB,GARmC;AAU5B,IAAMK,oBAAoB,wBAC/BN,UACAO,QACAC,QACAC,iBAAAA;AAEA,QAAMC,sBAAsBX,2BAA2BC,QAAAA;AACvD,MAAIU,wBAAwB,OAAO;AACjC,WAAOC;EACT;AACA,SAAO;IACL,GAAGD;IACHE,iBAAiB;MACf,GAAGC,mBAAmBD;MACtB,GAAGF,oBAAoBE;MACvBL;MACAO,QAAQ,KAAKJ,oBAAoBE,iBAAiBE,UAAU,MAAA,IAAUL,YAAAA;MACtED;IACF;IACAO,SAAS;SAAKL,oBAAoBK,WAAW,CAAA;SAAQF,mBAAmBE;;IACxEC,SAAS;SAAKN,oBAAoBM,WAAW,CAAA;SAAQH,mBAAmBG;;EAC1E;AACF,GAtBiC;","names":["readFileSync","defaultBuildConfig","compilerOptions","rootDir","rootDirs","exclude","include","getGeneralTypescriptConfig","location","generalConfig","readFileSync","encoding","JSON","parse","createBuildConfig","module","target","outDirSuffix","generalConfigObject","undefined","compilerOptions","defaultBuildConfig","outDir","exclude","include"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/lib/defaultBuildConfig.ts"],"sourcesContent":["export const defaultBuildConfig = {\n compilerOptions: {\n rootDir: 'src',\n rootDirs: ['package.json'],\n },\n exclude: ['**/build'
|
|
1
|
+
{"version":3,"sources":["../../src/lib/defaultBuildConfig.ts"],"sourcesContent":["export const defaultBuildConfig = {\n compilerOptions: {\n rootDir: 'src',\n rootDirs: ['package.json'],\n },\n exclude: [\n '**/build',\n '**/dist',\n '**/node_modules',\n '**/*.spec.*',\n '**/*.spec',\n '**/*.stories.*',\n '**/*.example.*',\n '**/spec/*',\n '**/stories/*',\n ],\n include: ['src'],\n}\n"],"mappings":";AAAO,IAAMA,qBAAqB;EAChCC,iBAAiB;IACfC,SAAS;IACTC,UAAU;MAAC;;EACb;EACAC,SAAS;IACP;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;;EAEFC,SAAS;IAAC;;AACZ;","names":["defaultBuildConfig","compilerOptions","rootDir","rootDirs","exclude","include"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
|
|
4
|
+
// src/lib/deleteGlob.ts
|
|
5
|
+
import fs from "node:fs";
|
|
6
|
+
import { glob } from "glob";
|
|
7
|
+
var deleteGlob = /* @__PURE__ */ __name((globPath) => {
|
|
8
|
+
const files = glob.sync(globPath);
|
|
9
|
+
for (const file of files) {
|
|
10
|
+
fs.rmSync(file, {
|
|
11
|
+
recursive: true,
|
|
12
|
+
force: true
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
}, "deleteGlob");
|
|
16
|
+
export {
|
|
17
|
+
deleteGlob
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=deleteGlob.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/lib/deleteGlob.ts"],"sourcesContent":["import fs from 'node:fs'\n\nimport { glob } from 'glob'\n\nexport const deleteGlob = (globPath: string) => {\n // Find all files matching the glob pattern\n const files = glob.sync(globPath)\n\n // Remove each file or directory\n for (const file of files) {\n fs.rmSync(file, { recursive: true, force: true })\n }\n}\n"],"mappings":";;;;AAAA,OAAOA,QAAQ;AAEf,SAASC,YAAY;AAEd,IAAMC,aAAa,wBAACC,aAAAA;AAEzB,QAAMC,QAAQC,KAAKC,KAAKH,QAAAA;AAGxB,aAAWI,QAAQH,OAAO;AACxBI,OAAGC,OAAOF,MAAM;MAAEG,WAAW;MAAMC,OAAO;IAAK,CAAA;EACjD;AACF,GAR0B;","names":["fs","glob","deleteGlob","globPath","files","glob","sync","file","fs","rmSync","recursive","force"]}
|
|
@@ -4,7 +4,6 @@ var __name = (target, value) => __defProp(target, "name", { value, configurable:
|
|
|
4
4
|
// src/lib/dependencies/DuplicateDetector.ts
|
|
5
5
|
import { EOL } from "node:os";
|
|
6
6
|
import chalk from "chalk";
|
|
7
|
-
import uniq from "lodash/uniq.js";
|
|
8
7
|
|
|
9
8
|
// src/lib/jsonFormatters.ts
|
|
10
9
|
var multiLineToJSONArray = /* @__PURE__ */ __name((output) => {
|
|
@@ -75,7 +74,9 @@ var DuplicateDetector = class {
|
|
|
75
74
|
acc.duplicateVersions.push(acc.currentVersion);
|
|
76
75
|
}
|
|
77
76
|
acc.duplicateVersions.push(version);
|
|
78
|
-
acc.duplicateVersions =
|
|
77
|
+
acc.duplicateVersions = [
|
|
78
|
+
...new Set(acc.duplicateVersions)
|
|
79
|
+
];
|
|
79
80
|
}
|
|
80
81
|
return acc;
|
|
81
82
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/dependencies/DuplicateDetector.ts","../../../src/lib/jsonFormatters.ts"],"sourcesContent":["import { EOL } from 'node:os'\n\nimport chalk from 'chalk'\n
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/dependencies/DuplicateDetector.ts","../../../src/lib/jsonFormatters.ts"],"sourcesContent":["import { EOL } from 'node:os'\n\nimport chalk from 'chalk'\n\nimport { multiLineToJSONArray } from '../jsonFormatters.ts'\n\ninterface ChildFields {\n descriptor: string\n locator: string\n}\n\nconst trimVirtualMeta = (value: string): string => {\n const virtualParts = value.split('virtual:')\n if (virtualParts.length > 1) {\n const hashParts = virtualParts[1].split('#')\n return virtualParts[0] + hashParts[1]\n } else {\n return value\n }\n}\n\nconst trimObjectDependencyVirtualMeta = (obj: Record<string, ChildFields>): Record<string, ChildFields> => {\n const resultObj: Record<string, ChildFields> = {}\n for (const [key, value] of Object.entries(obj)) {\n resultObj[trimVirtualMeta(key)] = {\n descriptor: trimVirtualMeta(value.descriptor),\n locator: trimVirtualMeta(value.locator),\n }\n }\n return resultObj\n}\n\nconst trimDependencyVirtualMeta = (dependencies: DependencyEntries): DependencyEntries => {\n return dependencies.map((dependency) => {\n return { children: trimObjectDependencyVirtualMeta(dependency.children), value: trimVirtualMeta(dependency.value) }\n })\n}\n\ninterface DependencyEntry {\n children: Record<string, ChildFields>\n value: string\n}\n\ntype DependencyEntries = DependencyEntry[]\n\ninterface Results {\n currentVersion: string | undefined\n dependency: string\n duplicateVersions: string[]\n}\n\nexport class DuplicateDetector {\n private dependency: string\n private dependencyEntries: DependencyEntries\n\n constructor(output: string, dependency: string) {\n this.dependency = dependency\n this.dependencyEntries = trimDependencyVirtualMeta(multiLineToJSONArray(output))\n }\n\n detect() {\n // eslint-disable-next-line unicorn/no-array-reduce\n const result = this.dependencyEntries.reduce(this.detectReducer, this.resultsFactory(this.dependency))\n if (result.duplicateVersions.length > 0) {\n console.log(chalk.yellow(`${EOL}Duplicates found for: ${this.dependency}`))\n const duplicateVersions = result.duplicateVersions.toString().replaceAll(',', `${EOL} `)\n console.log(chalk.grey(` ${duplicateVersions}`, EOL))\n return 1\n } else {\n console.log(`${this.dependency} - OK`)\n return 0\n }\n }\n\n private detectReducer(acc: Results, entry: DependencyEntry) {\n const version = Object.entries(entry.children).map(([k]) => k)[0]\n\n if (!acc.currentVersion) {\n acc.currentVersion = version\n return acc\n }\n\n if (acc.currentVersion && acc.currentVersion !== version && !version.includes('@virtual:')) {\n // if first duplicate, push the current version as the first duplicate\n if (acc.duplicateVersions.length === 0) {\n acc.duplicateVersions.push(acc.currentVersion)\n }\n acc.duplicateVersions.push(version)\n acc.duplicateVersions = [...new Set(acc.duplicateVersions)]\n }\n return acc\n }\n\n private resultsFactory = (dependency: string): Results => ({\n currentVersion: undefined, dependency, duplicateVersions: [],\n })\n}\n","export const multiLineToJSONArray = (output: string) => {\n const withCommas = output.replaceAll('\\r\\n', '').replaceAll('\\n', ',')\n const cleanCollection = withCommas.slice(0, Math.max(0, withCommas.length - 1))\n const collection = `[${cleanCollection}]`\n return JSON.parse(collection)\n}\n"],"mappings":";;;;AAAA,SAASA,WAAW;AAEpB,OAAOC,WAAW;;;ACFX,IAAMC,uBAAuB,wBAACC,WAAAA;AACnC,QAAMC,aAAaD,OAAOE,WAAW,QAAQ,EAAA,EAAIA,WAAW,MAAM,GAAA;AAClE,QAAMC,kBAAkBF,WAAWG,MAAM,GAAGC,KAAKC,IAAI,GAAGL,WAAWM,SAAS,CAAA,CAAA;AAC5E,QAAMC,aAAa,IAAIL,eAAAA;AACvB,SAAOM,KAAKC,MAAMF,UAAAA;AACpB,GALoC;;;ADWpC,IAAMG,kBAAkB,wBAACC,UAAAA;AACvB,QAAMC,eAAeD,MAAME,MAAM,UAAA;AACjC,MAAID,aAAaE,SAA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J,cAAQC,IAAI,GAAG,KAAKd,UAAU,OAAO;AACrC,aAAO;IACT;EACF;EAEQU,cAAcW,KAAcC,OAAwB;AAC1D,UAAMC,UAAU9B,OAAOC,QAAQ4B,MAAMrB,QAAQ,EAAEF,IAAI,CAAC,CAACyB,CAAAA,MAAOA,CAAAA,EAAG,CAAA;AAE/D,QAAI,CAACH,IAAII,gBAAgB;AACvBJ,UAAII,iBAAiBF;AACrB,aAAOF;IACT;AAEA,QAAIA,IAAII,kBAAkBJ,IAAII,mBAAmBF,WAAW,CAACA,QAAQG,SAAS,WAAA,GAAc;AAE1F,UAAIL,IAAIT,kBAAkBzB,WAAW,GAAG;AACtCkC,YAAIT,kBAAkBe,KAAKN,IAAII,cAAc;MAC/C;AACAJ,UAAIT,kBAAkBe,KAAKJ,OAAAA;AAC3BF,UAAIT,oBAAoB;WAAI,IAAIgB,IAAIP,IAAIT,iBAAiB;;IAC3D;AACA,WAAOS;EACT;EAEQV,iBAAiB,wBAACX,gBAAiC;IACzDyB,gBAAgBI;IAAW7B;IAAYY,mBAAmB,CAAA;EAC5D,IAFyB;AAG3B;","names":["EOL","chalk","multiLineToJSONArray","output","withCommas","replaceAll","cleanCollection","slice","Math","max","length","collection","JSON","parse","trimVirtualMeta","value","virtualParts","split","length","hashParts","trimObjectDependencyVirtualMeta","obj","resultObj","key","Object","entries","descriptor","locator","trimDependencyVirtualMeta","dependencies","map","dependency","children","DuplicateDetector","dependencyEntries","constructor","output","multiLineToJSONArray","detect","result","reduce","detectReducer","resultsFactory","duplicateVersions","console","log","chalk","yellow","EOL","toString","replaceAll","grey","acc","entry","version","k","currentVersion","includes","push","Set","undefined"]}
|
|
@@ -53,7 +53,6 @@ var safeExit = /* @__PURE__ */ __name((func, exitOnFail = true) => {
|
|
|
53
53
|
// src/lib/dependencies/DuplicateDetector.ts
|
|
54
54
|
import { EOL } from "node:os";
|
|
55
55
|
import chalk2 from "chalk";
|
|
56
|
-
import uniq from "lodash/uniq.js";
|
|
57
56
|
|
|
58
57
|
// src/lib/jsonFormatters.ts
|
|
59
58
|
var multiLineToJSONArray = /* @__PURE__ */ __name((output) => {
|
|
@@ -124,7 +123,9 @@ var DuplicateDetector = class {
|
|
|
124
123
|
acc.duplicateVersions.push(acc.currentVersion);
|
|
125
124
|
}
|
|
126
125
|
acc.duplicateVersions.push(version);
|
|
127
|
-
acc.duplicateVersions =
|
|
126
|
+
acc.duplicateVersions = [
|
|
127
|
+
...new Set(acc.duplicateVersions)
|
|
128
|
+
];
|
|
128
129
|
}
|
|
129
130
|
return acc;
|
|
130
131
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/dependencies/detectDuplicateDependencies.ts","../../../src/lib/processEx.ts","../../../src/lib/withError.ts","../../../src/lib/withErrnoException.ts","../../../src/lib/safeExit.ts","../../../src/lib/dependencies/DuplicateDetector.ts","../../../src/lib/jsonFormatters.ts"],"sourcesContent":["import { execSync } from 'node:child_process'\n\nimport { safeExit } from '../safeExit.ts'\nimport { DuplicateDetector } from './DuplicateDetector.ts'\n\nexport const detectDuplicateDependencies = (depsFromPackageJSON?: string[], DefaultDependencies?: string[]) => {\n let exitCode = 0\n\n const dependencies = depsFromPackageJSON?.length ? depsFromPackageJSON : DefaultDependencies\n\n return safeExit(() => {\n if (dependencies) {\n for (const dependency of dependencies) {\n let output: string\n\n try {\n const cmd = `yarn why ${dependency} --json`\n output = execSync(cmd).toString()\n } catch (e) {\n console.error(`Error running yarn why: ${e}`)\n exitCode = 1\n continue\n }\n\n if (output) {\n exitCode = new DuplicateDetector(output, dependency).detect()\n } else {\n console.log(`${dependency} - N/A`)\n if (depsFromPackageJSON) {\n exitCode = 1\n console.log(`🚨 Library ${dependency} was requested in package.json but not found`)\n }\n }\n }\n return exitCode\n } else {\n console.log('🚨 No dependencies where passed')\n return exitCode\n }\n })\n}\n","import chalk from 'chalk'\n\nimport { withErrnoException } from './withErrnoException.ts'\nimport { withError } from './withError.ts'\n\nexport const processEx = (ex: unknown) => {\n const error = typeof ex === 'string' ? new Error(ex) : ex\n const exitCode\n = withErrnoException(error, (error) => {\n if (error.code === 'ENOENT') {\n console.error(chalk.red(`'${error.path}' not found.`))\n } else {\n console.error(chalk.red(`Errno: ${error.code}`))\n }\n return error.errno ?? -1\n })\n ?? withError(error, (error) => {\n console.error(chalk.red(`${error.name}: ${error.message}`))\n return -1\n })\n ?? (() => {\n console.error(chalk.red(`Unexpected Error: ${JSON.stringify(ex, null, 2)}`))\n return -1\n })()\n // This allows us to use a previously set exit code\n process.exit(process.exitCode ?? exitCode)\n}\n","export const withError = <T extends Error = Error>(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ex: any,\n closure: (error: T) => number,\n predicate = (ex: T) => ex.name !== undefined && ex.message !== undefined,\n) => {\n return predicate(ex as T) ? closure(ex as T) : undefined\n}\n","import { withError } from './withError.ts'\n\nexport const withErrnoException = <T extends NodeJS.ErrnoException = NodeJS.ErrnoException>(ex: unknown, closure: (error: T) => number) => {\n return withError<T>(ex, closure, (ex: unknown) => (ex as NodeJS.ErrnoException).errno !== undefined)\n}\n","/** Catch child process a crash and returns the code */\n\nimport { processEx } from './processEx.ts'\n\nconst safeExit = (func: () => number, exitOnFail = true): number => {\n try {\n const result = func()\n if (result && exitOnFail) {\n process.exit(result)\n }\n return result\n } catch (ex) {\n return processEx(ex)\n }\n}\n\nconst safeExitAsync = async (func: () => Promise<number>, exitOnFail = true): Promise<number> => {\n try {\n const result = await func()\n if (result && exitOnFail) {\n process.exit(result)\n }\n return result\n } catch (ex) {\n return processEx(ex)\n }\n}\n\nexport { safeExit, safeExitAsync }\n","import { EOL } from 'node:os'\n\nimport chalk from 'chalk'\n// eslint-disable-next-line import/no-internal-modules\nimport uniq from 'lodash/uniq.js'\n\nimport { multiLineToJSONArray } from '../jsonFormatters.ts'\n\ninterface ChildFields {\n descriptor: string\n locator: string\n}\n\nconst trimVirtualMeta = (value: string): string => {\n const virtualParts = value.split('virtual:')\n if (virtualParts.length > 1) {\n const hashParts = virtualParts[1].split('#')\n return virtualParts[0] + hashParts[1]\n } else {\n return value\n }\n}\n\nconst trimObjectDependencyVirtualMeta = (obj: Record<string, ChildFields>): Record<string, ChildFields> => {\n const resultObj: Record<string, ChildFields> = {}\n for (const [key, value] of Object.entries(obj)) {\n resultObj[trimVirtualMeta(key)] = {\n descriptor: trimVirtualMeta(value.descriptor),\n locator: trimVirtualMeta(value.locator),\n }\n }\n return resultObj\n}\n\nconst trimDependencyVirtualMeta = (dependencies: DependencyEntries): DependencyEntries => {\n return dependencies.map((dependency) => {\n return { children: trimObjectDependencyVirtualMeta(dependency.children), value: trimVirtualMeta(dependency.value) }\n })\n}\n\ninterface DependencyEntry {\n children: Record<string, ChildFields>\n value: string\n}\n\ntype DependencyEntries = DependencyEntry[]\n\ninterface Results {\n currentVersion: string | undefined\n dependency: string\n duplicateVersions: string[]\n}\n\nexport class DuplicateDetector {\n private dependency: string\n private dependencyEntries: DependencyEntries\n\n constructor(output: string, dependency: string) {\n this.dependency = dependency\n this.dependencyEntries = trimDependencyVirtualMeta(multiLineToJSONArray(output))\n }\n\n detect() {\n // eslint-disable-next-line unicorn/no-array-reduce\n const result = this.dependencyEntries.reduce(this.detectReducer, this.resultsFactory(this.dependency))\n if (result.duplicateVersions.length > 0) {\n console.log(chalk.yellow(`${EOL}Duplicates found for: ${this.dependency}`))\n const duplicateVersions = result.duplicateVersions.toString().replaceAll(',', `${EOL} `)\n console.log(chalk.grey(` ${duplicateVersions}`, EOL))\n return 1\n } else {\n console.log(`${this.dependency} - OK`)\n return 0\n }\n }\n\n private detectReducer(acc: Results, entry: DependencyEntry) {\n const version = Object.entries(entry.children).map(([k]) => k)[0]\n\n if (!acc.currentVersion) {\n acc.currentVersion = version\n return acc\n }\n\n if (acc.currentVersion && acc.currentVersion !== version && !version.includes('@virtual:')) {\n // if first duplicate, push the current version as the first duplicate\n if (acc.duplicateVersions.length === 0) {\n acc.duplicateVersions.push(acc.currentVersion)\n }\n acc.duplicateVersions.push(version)\n acc.duplicateVersions = uniq(acc.duplicateVersions)\n }\n return acc\n }\n\n private resultsFactory = (dependency: string): Results => ({ currentVersion: undefined, dependency, duplicateVersions: [] })\n}\n","export const multiLineToJSONArray = (output: string) => {\n const withCommas = output.replaceAll('\\r\\n', '').replaceAll('\\n', ',')\n const cleanCollection = withCommas.slice(0, Math.max(0, withCommas.length - 1))\n const collection = `[${cleanCollection}]`\n return JSON.parse(collection)\n}\n"],"mappings":";;;;AAAA,SAASA,gBAAgB;;;ACAzB,OAAOC,WAAW;;;ACAX,IAAMC,YAAY,wBAEvBC,IACAC,SACAC,YAAY,CAACF,QAAUA,IAAGG,SAASC,UAAaJ,IAAGK,YAAYD,WAAS;AAExE,SAAOF,UAAUF,EAAAA,IAAWC,QAAQD,EAAAA,IAAWI;AACjD,GAPyB;;;ACElB,IAAME,qBAAqB,wBAA0DC,IAAaC,YAAAA;AACvG,SAAOC,UAAaF,IAAIC,SAAS,CAACD,QAAiBA,IAA6BG,UAAUC,MAAAA;AAC5F,GAFkC;;;AFG3B,IAAMC,YAAY,wBAACC,OAAAA;AACxB,QAAMC,QAAQ,OAAOD,OAAO,WAAW,IAAIE,MAAMF,EAAAA,IAAMA;AACvD,QAAMG,WACFC,mBAAmBH,OAAO,CAACA,WAAAA;AAC3B,QAAIA,OAAMI,SAAS,UAAU;AAC3BC,cAAQL,MAAMM,MAAMC,IAAI,IAAIP,OAAMQ,IAAI,cAAc,CAAA;IACtD,OAAO;AACLH,cAAQL,MAAMM,MAAMC,IAAI,UAAUP,OAAMI,IAAI,EAAE,CAAA;IAChD;AACA,WAAOJ,OAAMS,SAAS;EACxB,CAAA,KACGC,UAAUV,OAAO,CAACA,WAAAA;AACnBK,YAAQL,MAAMM,MAAMC,IAAI,GAAGP,OAAMW,IAAI,KAAKX,OAAMY,OAAO,EAAE,CAAA;AACzD,WAAO;EACT,CAAA,MACI,MAAA;AACFP,YAAQL,MAAMM,MAAMC,IAAI,qBAAqBM,KAA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IAAII,cAAc;MAC/C;AACAJ,UAAIT,kBAAkBe,KAAKJ,OAAAA;AAC3BF,UAAIT,oBAAoBgB,KAAKP,IAAIT,iBAAiB;IACpD;AACA,WAAOS;EACT;EAEQV,iBAAiB,wBAACX,gBAAiC;IAAEyB,gBAAgBI;IAAW7B;IAAYY,mBAAmB,CAAA;EAAG,IAAjG;AAC3B;;;AL3FO,IAAMkB,8BAA8B,wBAACC,qBAAgCC,wBAAAA;AAC1E,MAAIC,WAAW;AAEf,QAAMC,eAAeH,qBAAqBI,SAASJ,sBAAsBC;AAEzE,SAAOI,SAAS,MAAA;AACd,QAAIF,cAAc;AAChB,iBAAWG,cAAcH,cAAc;AACrC,YAAII;AAEJ,YAAI;AACF,gBAAMC,MAAM,YAAYF,UAAAA;AACxBC,mBAASE,SAASD,GAAAA,EAAKE,SAAQ;QACjC,SAASC,GAAG;AACVC,kBAAQC,MAAM,2BAA2BF,CAAAA,EAAG;AAC5CT,qBAAW;AACX;QACF;AAEA,YAAIK,QAAQ;AACVL,qBAAW,IAAIY,kBAAkBP,QAAQD,UAAAA,EAAYS,OAAM;QAC7D,OAAO;AACLH,kBAAQI,IAAI,GAAGV,UAAAA,QAAkB;AACjC,cAAIN,qBAAqB;AACvBE,uBAAW;AACXU,oBAAQI,IAAI,qBAAcV,UAAAA,8CAAwD;UACpF;QACF;MACF;AACA,aAAOJ;IACT,OAAO;AACLU,cAAQI,IAAI,wCAAA;AACZ,aAAOd;IACT;EACF,CAAA;AACF,GAnC2C;","names":["execSync","chalk","withError","ex","closure","predicate","name","undefined","message","withErrnoException","ex","closure","withError","errno","undefined","processEx","ex","error","Error","exitCode","withErrnoException","code","console","chalk","red","path","errno","withError","name","message","JSON","stringify","process","exit","safeExit","func","exitOnFail","result","process","exit","ex","processEx","EOL","chalk","uniq","multiLineToJSONArray","output","withCommas","replaceAll","cleanCollection","slice","Math","max","length","collection","JSON","parse","trimVirtualMeta","value","virtualParts","split","length","hashParts","trimObjectDependencyVirtualMeta","obj","resultObj","key","Object","entries","descriptor","locator","trimDependencyVirtualMeta","dependencies","map","dependency","children","DuplicateDetector","dependencyEntries","constructor","output","multiLineToJSONArray","detect","result","reduce","detectReducer","resultsFactory","duplicateVersions","console","log","chalk","yellow","EOL","toString","replaceAll","grey","acc","entry","version","k","currentVersion","includes","push","uniq","undefined","detectDuplicateDependencies","depsFromPackageJSON","DefaultDependencies","exitCode","dependencies","length","safeExit","dependency","output","cmd","execSync","toString","e","console","error","DuplicateDetector","detect","log"]}
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/dependencies/detectDuplicateDependencies.ts","../../../src/lib/processEx.ts","../../../src/lib/withError.ts","../../../src/lib/withErrnoException.ts","../../../src/lib/safeExit.ts","../../../src/lib/dependencies/DuplicateDetector.ts","../../../src/lib/jsonFormatters.ts"],"sourcesContent":["import { execSync } from 'node:child_process'\n\nimport { safeExit } from '../safeExit.ts'\nimport { DuplicateDetector } from './DuplicateDetector.ts'\n\nexport const detectDuplicateDependencies = (depsFromPackageJSON?: string[], DefaultDependencies?: string[]) => {\n let exitCode = 0\n\n const dependencies = depsFromPackageJSON?.length ? depsFromPackageJSON : DefaultDependencies\n\n return safeExit(() => {\n if (dependencies) {\n for (const dependency of dependencies) {\n let output: string\n\n try {\n const cmd = `yarn why ${dependency} --json`\n output = execSync(cmd).toString()\n } catch (e) {\n console.error(`Error running yarn why: ${e}`)\n exitCode = 1\n continue\n }\n\n if (output) {\n exitCode = new DuplicateDetector(output, dependency).detect()\n } else {\n console.log(`${dependency} - N/A`)\n if (depsFromPackageJSON) {\n exitCode = 1\n console.log(`🚨 Library ${dependency} was requested in package.json but not found`)\n }\n }\n }\n return exitCode\n } else {\n console.log('🚨 No dependencies where passed')\n return exitCode\n }\n })\n}\n","import chalk from 'chalk'\n\nimport { withErrnoException } from './withErrnoException.ts'\nimport { withError } from './withError.ts'\n\nexport const processEx = (ex: unknown) => {\n const error = typeof ex === 'string' ? new Error(ex) : ex\n const exitCode\n = withErrnoException(error, (error) => {\n if (error.code === 'ENOENT') {\n console.error(chalk.red(`'${error.path}' not found.`))\n } else {\n console.error(chalk.red(`Errno: ${error.code}`))\n }\n return error.errno ?? -1\n })\n ?? withError(error, (error) => {\n console.error(chalk.red(`${error.name}: ${error.message}`))\n return -1\n })\n ?? (() => {\n console.error(chalk.red(`Unexpected Error: ${JSON.stringify(ex, null, 2)}`))\n return -1\n })()\n // This allows us to use a previously set exit code\n process.exit(process.exitCode ?? exitCode)\n}\n","export const withError = <T extends Error = Error>(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ex: any,\n closure: (error: T) => number,\n predicate = (ex: T) => ex.name !== undefined && ex.message !== undefined,\n) => {\n return predicate(ex as T) ? closure(ex as T) : undefined\n}\n","import { withError } from './withError.ts'\n\nexport const withErrnoException = <T extends NodeJS.ErrnoException = NodeJS.ErrnoException>(\n ex: unknown, closure: (error: T) => number,\n) => {\n return withError<T>(ex, closure, (ex: unknown) => (ex as NodeJS.ErrnoException).errno !== undefined)\n}\n","/** Catch child process a crash and returns the code */\n\nimport { processEx } from './processEx.ts'\n\nconst safeExit = (func: () => number, exitOnFail = true): number => {\n try {\n const result = func()\n if (result && exitOnFail) {\n process.exit(result)\n }\n return result\n } catch (ex) {\n return processEx(ex)\n }\n}\n\nconst safeExitAsync = async (func: () => Promise<number>, exitOnFail = true): Promise<number> => {\n try {\n const result = await func()\n if (result && exitOnFail) {\n process.exit(result)\n }\n return result\n } catch (ex) {\n return processEx(ex)\n }\n}\n\nexport { safeExit, safeExitAsync }\n","import { EOL } from 'node:os'\n\nimport chalk from 'chalk'\n\nimport { multiLineToJSONArray } from '../jsonFormatters.ts'\n\ninterface ChildFields {\n descriptor: string\n locator: string\n}\n\nconst trimVirtualMeta = (value: string): string => {\n const virtualParts = value.split('virtual:')\n if (virtualParts.length > 1) {\n const hashParts = virtualParts[1].split('#')\n return virtualParts[0] + hashParts[1]\n } else {\n return value\n }\n}\n\nconst trimObjectDependencyVirtualMeta = (obj: Record<string, ChildFields>): Record<string, ChildFields> => {\n const resultObj: Record<string, ChildFields> = {}\n for (const [key, value] of Object.entries(obj)) {\n resultObj[trimVirtualMeta(key)] = {\n descriptor: trimVirtualMeta(value.descriptor),\n locator: trimVirtualMeta(value.locator),\n }\n }\n return resultObj\n}\n\nconst trimDependencyVirtualMeta = (dependencies: DependencyEntries): DependencyEntries => {\n return dependencies.map((dependency) => {\n return { children: trimObjectDependencyVirtualMeta(dependency.children), value: trimVirtualMeta(dependency.value) }\n })\n}\n\ninterface DependencyEntry {\n children: Record<string, ChildFields>\n value: string\n}\n\ntype DependencyEntries = DependencyEntry[]\n\ninterface Results {\n currentVersion: string | undefined\n dependency: string\n duplicateVersions: string[]\n}\n\nexport class DuplicateDetector {\n private dependency: string\n private dependencyEntries: DependencyEntries\n\n constructor(output: string, dependency: string) {\n this.dependency = dependency\n this.dependencyEntries = trimDependencyVirtualMeta(multiLineToJSONArray(output))\n }\n\n detect() {\n // eslint-disable-next-line unicorn/no-array-reduce\n const result = this.dependencyEntries.reduce(this.detectReducer, this.resultsFactory(this.dependency))\n if (result.duplicateVersions.length > 0) {\n console.log(chalk.yellow(`${EOL}Duplicates found for: ${this.dependency}`))\n const duplicateVersions = result.duplicateVersions.toString().replaceAll(',', `${EOL} `)\n console.log(chalk.grey(` ${duplicateVersions}`, EOL))\n return 1\n } else {\n console.log(`${this.dependency} - OK`)\n return 0\n }\n }\n\n private detectReducer(acc: Results, entry: DependencyEntry) {\n const version = Object.entries(entry.children).map(([k]) => k)[0]\n\n if (!acc.currentVersion) {\n acc.currentVersion = version\n return acc\n }\n\n if (acc.currentVersion && acc.currentVersion !== version && !version.includes('@virtual:')) {\n // if first duplicate, push the current version as the first duplicate\n if (acc.duplicateVersions.length === 0) {\n acc.duplicateVersions.push(acc.currentVersion)\n }\n acc.duplicateVersions.push(version)\n acc.duplicateVersions = [...new Set(acc.duplicateVersions)]\n }\n return acc\n }\n\n private resultsFactory = (dependency: string): Results => ({\n currentVersion: undefined, dependency, duplicateVersions: [],\n })\n}\n","export const multiLineToJSONArray = (output: string) => {\n const withCommas = output.replaceAll('\\r\\n', '').replaceAll('\\n', ',')\n const cleanCollection = withCommas.slice(0, Math.max(0, withCommas.length - 1))\n const collection = `[${cleanCollection}]`\n return JSON.parse(collection)\n}\n"],"mappings":";;;;AAAA,SAASA,gBAAgB;;;ACAzB,OAAOC,WAAW;;;ACAX,IAAMC,YAAY,wBAEvBC,IACAC,SACAC,YAAY,CAACF,QAAUA,IAAGG,SAASC,UAAaJ,IAAGK,YAAYD,WAAS;AAExE,SAAOF,UAAUF,EAAAA,IAAWC,QAAQD,EAAAA,IAAWI;AACjD,GAPyB;;;ACElB,IAAME,qBAAqB,wBAChCC,IAAaC,YAAAA;AAEb,SAAOC,UAAaF,IAAIC,SAAS,CAACD,QAAiBA,IAA6BG,UAAUC,MAAAA;AAC5F,GAJkC;;;AFG3B,IAAMC,YAAY,wBAACC,OAAAA;AACxB,QAAMC,QAAQ,OAAOD,OAAO,WAAW,IAAIE,MAAMF,EAAAA,IAAMA;AACvD,QAAMG,WACFC,mBAAmBH,OAAO,CAACA,WAAAA;AAC3B,QAAIA,OAAMI,SAAS,UAAU;AAC3BC,cAAQL,MAAMM,MAAMC,IAAI,IAAIP,OAAMQ,IAAI,cAAc,CAAA;IACtD,OAAO;AACLH,cAAQL,MAAMM,MAAMC,IAAI,UAAUP,OAAMI,IAAI,EAAE,CAAA;IAChD;AACA,WAAOJ,OAAMS,SAAS;EACxB,CAAA,KACGC,UAAUV,OAAO,CAACA,WAAAA;AACnBK,YAAQL,MAAMM,MAAMC,IAAI,GAAGP,OAAMW,IAAI,KAAKX,OAAMY,OAAO,EAAE,CAAA;AACzD,WAAO;EACT,CAAA,MACI,MAAA;AACFP,YAAQL,MAAMM,MAAMC,IAAI,qBAAqBM,KAAKC,UAAUf,IAAI,MAAM,CAAA,CAAA,EAAI,CAAA;AAC1E,WAAO;EACT,GAAA;AAEFgB,UAAQC,KAAKD,QAAQb,YAAY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AC3D;AACA,WAAOS;EACT;EAEQV,iBAAiB,wBAACX,gBAAiC;IACzDyB,gBAAgBI;IAAW7B;IAAYY,mBAAmB,CAAA;EAC5D,IAFyB;AAG3B;;;AL3FO,IAAMkB,8BAA8B,wBAACC,qBAAgCC,wBAAAA;AAC1E,MAAIC,WAAW;AAEf,QAAMC,eAAeH,qBAAqBI,SAASJ,sBAAsBC;AAEzE,SAAOI,SAAS,MAAA;AACd,QAAIF,cAAc;AAChB,iBAAWG,cAAcH,cAAc;AACrC,YAAII;AAEJ,YAAI;AACF,gBAAMC,MAAM,YAAYF,UAAAA;AACxBC,mBAASE,SAASD,GAAAA,EAAKE,SAAQ;QACjC,SAASC,GAAG;AACVC,kBAAQC,MAAM,2BAA2BF,CAAAA,EAAG;AAC5CT,qBAAW;AACX;QACF;AAEA,YAAIK,QAAQ;AACVL,qBAAW,IAAIY,kBAAkBP,QAAQD,UAAAA,EAAYS,OAAM;QAC7D,OAAO;AACLH,kBAAQI,IAAI,GAAGV,UAAAA,QAAkB;AACjC,cAAIN,qBAAqB;AACvBE,uBAAW;AACXU,oBAAQI,IAAI,qBAAcV,UAAAA,8CAAwD;UACpF;QACF;MACF;AACA,aAAOJ;IACT,OAAO;AACLU,cAAQI,IAAI,wCAAA;AACZ,aAAOd;IACT;EACF,CAAA;AACF,GAnC2C;","names":["execSync","chalk","withError","ex","closure","predicate","name","undefined","message","withErrnoException","ex","closure","withError","errno","undefined","processEx","ex","error","Error","exitCode","withErrnoException","code","console","chalk","red","path","errno","withError","name","message","JSON","stringify","process","exit","safeExit","func","exitOnFail","result","process","exit","ex","processEx","EOL","chalk","multiLineToJSONArray","output","withCommas","replaceAll","cleanCollection","slice","Math","max","length","collection","JSON","parse","trimVirtualMeta","value","virtualParts","split","length","hashParts","trimObjectDependencyVirtualMeta","obj","resultObj","key","Object","entries","descriptor","locator","trimDependencyVirtualMeta","dependencies","map","dependency","children","DuplicateDetector","dependencyEntries","constructor","output","multiLineToJSONArray","detect","result","reduce","detectReducer","resultsFactory","duplicateVersions","console","log","chalk","yellow","EOL","toString","replaceAll","grey","acc","entry","version","k","currentVersion","includes","push","Set","undefined","detectDuplicateDependencies","depsFromPackageJSON","DefaultDependencies","exitCode","dependencies","length","safeExit","dependency","output","cmd","execSync","toString","e","console","error","DuplicateDetector","detect","log"]}
|
|
@@ -53,7 +53,6 @@ var safeExit = /* @__PURE__ */ __name((func, exitOnFail = true) => {
|
|
|
53
53
|
// src/lib/dependencies/DuplicateDetector.ts
|
|
54
54
|
import { EOL } from "node:os";
|
|
55
55
|
import chalk2 from "chalk";
|
|
56
|
-
import uniq from "lodash/uniq.js";
|
|
57
56
|
|
|
58
57
|
// src/lib/jsonFormatters.ts
|
|
59
58
|
var multiLineToJSONArray = /* @__PURE__ */ __name((output) => {
|
|
@@ -124,7 +123,9 @@ var DuplicateDetector = class {
|
|
|
124
123
|
acc.duplicateVersions.push(acc.currentVersion);
|
|
125
124
|
}
|
|
126
125
|
acc.duplicateVersions.push(version);
|
|
127
|
-
acc.duplicateVersions =
|
|
126
|
+
acc.duplicateVersions = [
|
|
127
|
+
...new Set(acc.duplicateVersions)
|
|
128
|
+
];
|
|
128
129
|
}
|
|
129
130
|
return acc;
|
|
130
131
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/dependencies/detectDuplicateDependencies.ts","../../../src/lib/processEx.ts","../../../src/lib/withError.ts","../../../src/lib/withErrnoException.ts","../../../src/lib/safeExit.ts","../../../src/lib/dependencies/DuplicateDetector.ts","../../../src/lib/jsonFormatters.ts"],"sourcesContent":["import { execSync } from 'node:child_process'\n\nimport { safeExit } from '../safeExit.ts'\nimport { DuplicateDetector } from './DuplicateDetector.ts'\n\nexport const detectDuplicateDependencies = (depsFromPackageJSON?: string[], DefaultDependencies?: string[]) => {\n let exitCode = 0\n\n const dependencies = depsFromPackageJSON?.length ? depsFromPackageJSON : DefaultDependencies\n\n return safeExit(() => {\n if (dependencies) {\n for (const dependency of dependencies) {\n let output: string\n\n try {\n const cmd = `yarn why ${dependency} --json`\n output = execSync(cmd).toString()\n } catch (e) {\n console.error(`Error running yarn why: ${e}`)\n exitCode = 1\n continue\n }\n\n if (output) {\n exitCode = new DuplicateDetector(output, dependency).detect()\n } else {\n console.log(`${dependency} - N/A`)\n if (depsFromPackageJSON) {\n exitCode = 1\n console.log(`🚨 Library ${dependency} was requested in package.json but not found`)\n }\n }\n }\n return exitCode\n } else {\n console.log('🚨 No dependencies where passed')\n return exitCode\n }\n })\n}\n","import chalk from 'chalk'\n\nimport { withErrnoException } from './withErrnoException.ts'\nimport { withError } from './withError.ts'\n\nexport const processEx = (ex: unknown) => {\n const error = typeof ex === 'string' ? new Error(ex) : ex\n const exitCode\n = withErrnoException(error, (error) => {\n if (error.code === 'ENOENT') {\n console.error(chalk.red(`'${error.path}' not found.`))\n } else {\n console.error(chalk.red(`Errno: ${error.code}`))\n }\n return error.errno ?? -1\n })\n ?? withError(error, (error) => {\n console.error(chalk.red(`${error.name}: ${error.message}`))\n return -1\n })\n ?? (() => {\n console.error(chalk.red(`Unexpected Error: ${JSON.stringify(ex, null, 2)}`))\n return -1\n })()\n // This allows us to use a previously set exit code\n process.exit(process.exitCode ?? exitCode)\n}\n","export const withError = <T extends Error = Error>(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ex: any,\n closure: (error: T) => number,\n predicate = (ex: T) => ex.name !== undefined && ex.message !== undefined,\n) => {\n return predicate(ex as T) ? closure(ex as T) : undefined\n}\n","import { withError } from './withError.ts'\n\nexport const withErrnoException = <T extends NodeJS.ErrnoException = NodeJS.ErrnoException>(ex: unknown, closure: (error: T) => number) => {\n return withError<T>(ex, closure, (ex: unknown) => (ex as NodeJS.ErrnoException).errno !== undefined)\n}\n","/** Catch child process a crash and returns the code */\n\nimport { processEx } from './processEx.ts'\n\nconst safeExit = (func: () => number, exitOnFail = true): number => {\n try {\n const result = func()\n if (result && exitOnFail) {\n process.exit(result)\n }\n return result\n } catch (ex) {\n return processEx(ex)\n }\n}\n\nconst safeExitAsync = async (func: () => Promise<number>, exitOnFail = true): Promise<number> => {\n try {\n const result = await func()\n if (result && exitOnFail) {\n process.exit(result)\n }\n return result\n } catch (ex) {\n return processEx(ex)\n }\n}\n\nexport { safeExit, safeExitAsync }\n","import { EOL } from 'node:os'\n\nimport chalk from 'chalk'\n// eslint-disable-next-line import/no-internal-modules\nimport uniq from 'lodash/uniq.js'\n\nimport { multiLineToJSONArray } from '../jsonFormatters.ts'\n\ninterface ChildFields {\n descriptor: string\n locator: string\n}\n\nconst trimVirtualMeta = (value: string): string => {\n const virtualParts = value.split('virtual:')\n if (virtualParts.length > 1) {\n const hashParts = virtualParts[1].split('#')\n return virtualParts[0] + hashParts[1]\n } else {\n return value\n }\n}\n\nconst trimObjectDependencyVirtualMeta = (obj: Record<string, ChildFields>): Record<string, ChildFields> => {\n const resultObj: Record<string, ChildFields> = {}\n for (const [key, value] of Object.entries(obj)) {\n resultObj[trimVirtualMeta(key)] = {\n descriptor: trimVirtualMeta(value.descriptor),\n locator: trimVirtualMeta(value.locator),\n }\n }\n return resultObj\n}\n\nconst trimDependencyVirtualMeta = (dependencies: DependencyEntries): DependencyEntries => {\n return dependencies.map((dependency) => {\n return { children: trimObjectDependencyVirtualMeta(dependency.children), value: trimVirtualMeta(dependency.value) }\n })\n}\n\ninterface DependencyEntry {\n children: Record<string, ChildFields>\n value: string\n}\n\ntype DependencyEntries = DependencyEntry[]\n\ninterface Results {\n currentVersion: string | undefined\n dependency: string\n duplicateVersions: string[]\n}\n\nexport class DuplicateDetector {\n private dependency: string\n private dependencyEntries: DependencyEntries\n\n constructor(output: string, dependency: string) {\n this.dependency = dependency\n this.dependencyEntries = trimDependencyVirtualMeta(multiLineToJSONArray(output))\n }\n\n detect() {\n // eslint-disable-next-line unicorn/no-array-reduce\n const result = this.dependencyEntries.reduce(this.detectReducer, this.resultsFactory(this.dependency))\n if (result.duplicateVersions.length > 0) {\n console.log(chalk.yellow(`${EOL}Duplicates found for: ${this.dependency}`))\n const duplicateVersions = result.duplicateVersions.toString().replaceAll(',', `${EOL} `)\n console.log(chalk.grey(` ${duplicateVersions}`, EOL))\n return 1\n } else {\n console.log(`${this.dependency} - OK`)\n return 0\n }\n }\n\n private detectReducer(acc: Results, entry: DependencyEntry) {\n const version = Object.entries(entry.children).map(([k]) => k)[0]\n\n if (!acc.currentVersion) {\n acc.currentVersion = version\n return acc\n }\n\n if (acc.currentVersion && acc.currentVersion !== version && !version.includes('@virtual:')) {\n // if first duplicate, push the current version as the first duplicate\n if (acc.duplicateVersions.length === 0) {\n acc.duplicateVersions.push(acc.currentVersion)\n }\n acc.duplicateVersions.push(version)\n acc.duplicateVersions = uniq(acc.duplicateVersions)\n }\n return acc\n }\n\n private resultsFactory = (dependency: string): Results => ({ currentVersion: undefined, dependency, duplicateVersions: [] })\n}\n","export const multiLineToJSONArray = (output: string) => {\n const withCommas = output.replaceAll('\\r\\n', '').replaceAll('\\n', ',')\n const cleanCollection = withCommas.slice(0, Math.max(0, withCommas.length - 1))\n const collection = `[${cleanCollection}]`\n return JSON.parse(collection)\n}\n"],"mappings":";;;;AAAA,SAASA,gBAAgB;;;ACAzB,OAAOC,WAAW;;;ACAX,IAAMC,YAAY,wBAEvBC,IACAC,SACAC,YAAY,CAACF,QAAUA,IAAGG,SAASC,UAAaJ,IAAGK,YAAYD,WAAS;AAExE,SAAOF,UAAUF,EAAAA,IAAWC,QAAQD,EAAAA,IAAWI;AACjD,GAPyB;;;ACElB,IAAME,qBAAqB,wBAA0DC,IAAaC,YAAAA;AACvG,SAAOC,UAAaF,IAAIC,SAAS,CAACD,QAAiBA,IAA6BG,UAAUC,MAAAA;AAC5F,GAFkC;;;AFG3B,IAAMC,YAAY,wBAACC,OAAAA;AACxB,QAAMC,QAAQ,OAAOD,OAAO,WAAW,IAAIE,MAAMF,EAAAA,IAAMA;AACvD,QAAMG,WACFC,mBAAmBH,OAAO,CAACA,WAAAA;AAC3B,QAAIA,OAAMI,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pF;QACF;MACF;AACA,aAAOJ;IACT,OAAO;AACLU,cAAQI,IAAI,wCAAA;AACZ,aAAOd;IACT;EACF,CAAA;AACF,GAnC2C;","names":["execSync","chalk","withError","ex","closure","predicate","name","undefined","message","withErrnoException","ex","closure","withError","errno","undefined","processEx","ex","error","Error","exitCode","withErrnoException","code","console","chalk","red","path","errno","withError","name","message","JSON","stringify","process","exit","safeExit","func","exitOnFail","result","process","exit","ex","processEx","EOL","chalk","uniq","multiLineToJSONArray","output","withCommas","replaceAll","cleanCollection","slice","Math","max","length","collection","JSON","parse","trimVirtualMeta","value","virtualParts","split","length","hashParts","trimObjectDependencyVirtualMeta","obj","resultObj","key","Object","entries","descriptor","locator","trimDependencyVirtualMeta","dependencies","map","dependency","children","DuplicateDetector","dependencyEntries","constructor","output","multiLineToJSONArray","detect","result","reduce","detectReducer","resultsFactory","duplicateVersions","console","log","chalk","yellow","EOL","toString","replaceAll","grey","acc","entry","version","k","currentVersion","includes","push","uniq","undefined","detectDuplicateDependencies","depsFromPackageJSON","DefaultDependencies","exitCode","dependencies","length","safeExit","dependency","output","cmd","execSync","toString","e","console","error","DuplicateDetector","detect","log"]}
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/dependencies/detectDuplicateDependencies.ts","../../../src/lib/processEx.ts","../../../src/lib/withError.ts","../../../src/lib/withErrnoException.ts","../../../src/lib/safeExit.ts","../../../src/lib/dependencies/DuplicateDetector.ts","../../../src/lib/jsonFormatters.ts"],"sourcesContent":["import { execSync } from 'node:child_process'\n\nimport { safeExit } from '../safeExit.ts'\nimport { DuplicateDetector } from './DuplicateDetector.ts'\n\nexport const detectDuplicateDependencies = (depsFromPackageJSON?: string[], DefaultDependencies?: string[]) => {\n let exitCode = 0\n\n const dependencies = depsFromPackageJSON?.length ? depsFromPackageJSON : DefaultDependencies\n\n return safeExit(() => {\n if (dependencies) {\n for (const dependency of dependencies) {\n let output: string\n\n try {\n const cmd = `yarn why ${dependency} --json`\n output = execSync(cmd).toString()\n } catch (e) {\n console.error(`Error running yarn why: ${e}`)\n exitCode = 1\n continue\n }\n\n if (output) {\n exitCode = new DuplicateDetector(output, dependency).detect()\n } else {\n console.log(`${dependency} - N/A`)\n if (depsFromPackageJSON) {\n exitCode = 1\n console.log(`🚨 Library ${dependency} was requested in package.json but not found`)\n }\n }\n }\n return exitCode\n } else {\n console.log('🚨 No dependencies where passed')\n return exitCode\n }\n })\n}\n","import chalk from 'chalk'\n\nimport { withErrnoException } from './withErrnoException.ts'\nimport { withError } from './withError.ts'\n\nexport const processEx = (ex: unknown) => {\n const error = typeof ex === 'string' ? new Error(ex) : ex\n const exitCode\n = withErrnoException(error, (error) => {\n if (error.code === 'ENOENT') {\n console.error(chalk.red(`'${error.path}' not found.`))\n } else {\n console.error(chalk.red(`Errno: ${error.code}`))\n }\n return error.errno ?? -1\n })\n ?? withError(error, (error) => {\n console.error(chalk.red(`${error.name}: ${error.message}`))\n return -1\n })\n ?? (() => {\n console.error(chalk.red(`Unexpected Error: ${JSON.stringify(ex, null, 2)}`))\n return -1\n })()\n // This allows us to use a previously set exit code\n process.exit(process.exitCode ?? exitCode)\n}\n","export const withError = <T extends Error = Error>(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ex: any,\n closure: (error: T) => number,\n predicate = (ex: T) => ex.name !== undefined && ex.message !== undefined,\n) => {\n return predicate(ex as T) ? closure(ex as T) : undefined\n}\n","import { withError } from './withError.ts'\n\nexport const withErrnoException = <T extends NodeJS.ErrnoException = NodeJS.ErrnoException>(\n ex: unknown, closure: (error: T) => number,\n) => {\n return withError<T>(ex, closure, (ex: unknown) => (ex as NodeJS.ErrnoException).errno !== undefined)\n}\n","/** Catch child process a crash and returns the code */\n\nimport { processEx } from './processEx.ts'\n\nconst safeExit = (func: () => number, exitOnFail = true): number => {\n try {\n const result = func()\n if (result && exitOnFail) {\n process.exit(result)\n }\n return result\n } catch (ex) {\n return processEx(ex)\n }\n}\n\nconst safeExitAsync = async (func: () => Promise<number>, exitOnFail = true): Promise<number> => {\n try {\n const result = await func()\n if (result && exitOnFail) {\n process.exit(result)\n }\n return result\n } catch (ex) {\n return processEx(ex)\n }\n}\n\nexport { safeExit, safeExitAsync }\n","import { EOL } from 'node:os'\n\nimport chalk from 'chalk'\n\nimport { multiLineToJSONArray } from '../jsonFormatters.ts'\n\ninterface ChildFields {\n descriptor: string\n locator: string\n}\n\nconst trimVirtualMeta = (value: string): string => {\n const virtualParts = value.split('virtual:')\n if (virtualParts.length > 1) {\n const hashParts = virtualParts[1].split('#')\n return virtualParts[0] + hashParts[1]\n } else {\n return value\n }\n}\n\nconst trimObjectDependencyVirtualMeta = (obj: Record<string, ChildFields>): Record<string, ChildFields> => {\n const resultObj: Record<string, ChildFields> = {}\n for (const [key, value] of Object.entries(obj)) {\n resultObj[trimVirtualMeta(key)] = {\n descriptor: trimVirtualMeta(value.descriptor),\n locator: trimVirtualMeta(value.locator),\n }\n }\n return resultObj\n}\n\nconst trimDependencyVirtualMeta = (dependencies: DependencyEntries): DependencyEntries => {\n return dependencies.map((dependency) => {\n return { children: trimObjectDependencyVirtualMeta(dependency.children), value: trimVirtualMeta(dependency.value) }\n })\n}\n\ninterface DependencyEntry {\n children: Record<string, ChildFields>\n value: string\n}\n\ntype DependencyEntries = DependencyEntry[]\n\ninterface Results {\n currentVersion: string | undefined\n dependency: string\n duplicateVersions: string[]\n}\n\nexport class DuplicateDetector {\n private dependency: string\n private dependencyEntries: DependencyEntries\n\n constructor(output: string, dependency: string) {\n this.dependency = dependency\n this.dependencyEntries = trimDependencyVirtualMeta(multiLineToJSONArray(output))\n }\n\n detect() {\n // eslint-disable-next-line unicorn/no-array-reduce\n const result = this.dependencyEntries.reduce(this.detectReducer, this.resultsFactory(this.dependency))\n if (result.duplicateVersions.length > 0) {\n console.log(chalk.yellow(`${EOL}Duplicates found for: ${this.dependency}`))\n const duplicateVersions = result.duplicateVersions.toString().replaceAll(',', `${EOL} `)\n console.log(chalk.grey(` ${duplicateVersions}`, EOL))\n return 1\n } else {\n console.log(`${this.dependency} - OK`)\n return 0\n }\n }\n\n private detectReducer(acc: Results, entry: DependencyEntry) {\n const version = Object.entries(entry.children).map(([k]) => k)[0]\n\n if (!acc.currentVersion) {\n acc.currentVersion = version\n return acc\n }\n\n if (acc.currentVersion && acc.currentVersion !== version && !version.includes('@virtual:')) {\n // if first duplicate, push the current version as the first duplicate\n if (acc.duplicateVersions.length === 0) {\n acc.duplicateVersions.push(acc.currentVersion)\n }\n acc.duplicateVersions.push(version)\n acc.duplicateVersions = [...new Set(acc.duplicateVersions)]\n }\n return acc\n }\n\n private resultsFactory = (dependency: string): Results => ({\n currentVersion: undefined, dependency, duplicateVersions: [],\n })\n}\n","export const multiLineToJSONArray = (output: string) => {\n const withCommas = output.replaceAll('\\r\\n', '').replaceAll('\\n', ',')\n const cleanCollection = withCommas.slice(0, Math.max(0, withCommas.length - 1))\n const collection = `[${cleanCollection}]`\n return JSON.parse(collection)\n}\n"],"mappings":";;;;AAAA,SAASA,gBAAgB;;;ACAzB,OAAOC,WAAW;;;ACAX,IAAMC,YAAY,wBAEvBC,IACAC,SACAC,YAAY,CAACF,QAAUA,IAAGG,SAASC,UAAaJ,IAAGK,YAAYD,WAAS;AAExE,SAAOF,UAAUF,EAAAA,IAAWC,QAAQD,EAAAA,IAAWI;AACjD,GAPyB;;;ACElB,IAAME,qBAAqB,wBAChCC,IAAaC,YAAAA;AAEb,SAAOC,UAAaF,IAAIC,SAAS,CAACD,QAAiBA,IAA6BG,UAAUC,MAAAA;AAC5F,GAJkC;;;AFG3B,IAAMC,YAAY,wBAACC,OAAAA;AACxB,QAAMC,QAAQ,OAAOD,OAAO,WAAW,IAAIE,MAAMF,EAAAA,IAAMA;AACvD,QAAMG,WACFC,mBAAmBH,OAAO,CAACA,WAAAA;AAC3B,QAAIA,OAAMI,SAAS,UAAU;AAC3BC,cAAQL,MAAMM,MAAMC,IAAI,IAAIP,OAAMQ,IAAI,cAAc,CAAA;IACtD,OAAO;AACLH,cAAQL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names":["execSync","chalk","withError","ex","closure","predicate","name","undefined","message","withErrnoException","ex","closure","withError","errno","undefined","processEx","ex","error","Error","exitCode","withErrnoException","code","console","chalk","red","path","errno","withError","name","message","JSON","stringify","process","exit","safeExit","func","exitOnFail","result","process","exit","ex","processEx","EOL","chalk","multiLineToJSONArray","output","withCommas","replaceAll","cleanCollection","slice","Math","max","length","collection","JSON","parse","trimVirtualMeta","value","virtualParts","split","length","hashParts","trimObjectDependencyVirtualMeta","obj","resultObj","key","Object","entries","descriptor","locator","trimDependencyVirtualMeta","dependencies","map","dependency","children","DuplicateDetector","dependencyEntries","constructor","output","multiLineToJSONArray","detect","result","reduce","detectReducer","resultsFactory","duplicateVersions","console","log","chalk","yellow","EOL","toString","replaceAll","grey","acc","entry","version","k","currentVersion","includes","push","Set","undefined","detectDuplicateDependencies","depsFromPackageJSON","DefaultDependencies","exitCode","dependencies","length","safeExit","dependency","output","cmd","execSync","toString","e","console","error","DuplicateDetector","detect","log"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/file/ReadFileSyncOptions.ts"],"sourcesContent":["export type ReadFileSyncOptions = BufferEncoding | {
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/file/ReadFileSyncOptions.ts"],"sourcesContent":["export type ReadFileSyncOptions = BufferEncoding | {\n encoding: BufferEncoding\n flags?: string\n}\n\nexport const defaultReadFileSyncOptions: ReadFileSyncOptions = { encoding: 'utf8' }\n"],"mappings":";AAKO,IAAMA,6BAAkD;EAAEC,UAAU;AAAO;","names":["defaultReadFileSyncOptions","encoding"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/file/fileLines.ts","../../../src/lib/string/empty.ts","../../../src/lib/file/constants.ts","../../../src/lib/file/ReadFileSyncOptions.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/file/fileLines.ts","../../../src/lib/string/empty.ts","../../../src/lib/file/constants.ts","../../../src/lib/file/ReadFileSyncOptions.ts"],"sourcesContent":["import type { PathLike, WriteFileOptions } from 'node:fs'\nimport {\n existsSync, readFileSync, writeFileSync,\n} from 'node:fs'\n\nimport { notEmpty } from '../string/index.ts'\nimport { CROSS_PLATFORM_NEWLINE, WINDOWS_NEWLINE_REGEX } from './constants.ts'\nimport type { ReadFileSyncOptions } from './ReadFileSyncOptions.ts'\nimport { defaultReadFileSyncOptions } from './ReadFileSyncOptions.ts'\n\nexport const readLines = (uri: PathLike, options: ReadFileSyncOptions = defaultReadFileSyncOptions): string[] =>\n existsSync(uri)\n ? readFileSync(uri, options).replace(WINDOWS_NEWLINE_REGEX, CROSS_PLATFORM_NEWLINE).split(CROSS_PLATFORM_NEWLINE)\n : []\n\nexport const readNonEmptyLines = (uri: PathLike, options: ReadFileSyncOptions = defaultReadFileSyncOptions): string[] =>\n readLines(uri, options).filter(notEmpty)\n\nexport const writeLines = (uri: PathLike, lines: string[], options: WriteFileOptions = defaultReadFileSyncOptions) => {\n const existing = existsSync(uri) ? readFileSync(uri, options) : undefined\n const desired = lines.join(CROSS_PLATFORM_NEWLINE)\n // Check if the file is different before writing\n if (existing !== desired) writeFileSync(uri, desired, options)\n}\n","export const empty = (value?: string | undefined): boolean => value?.trim().length === 0\nexport const notEmpty = (value?: string | undefined): boolean => !empty(value)\n","export const WINDOWS_NEWLINE_REGEX = /\\r\\n/g\nexport const CROSS_PLATFORM_NEWLINE = '\\n'\n","export type ReadFileSyncOptions = BufferEncoding | {\n encoding: BufferEncoding\n flags?: string\n}\n\nexport const defaultReadFileSyncOptions: ReadFileSyncOptions = { encoding: 'utf8' }\n"],"mappings":";;;;AACA,SACEA,YAAYC,cAAcC,qBACrB;;;ACHA,IAAMC,QAAQ,wBAACC,UAAwCA,OAAOC,KAAAA,EAAOC,WAAW,GAAlE;AACd,IAAMC,WAAW,wBAACH,UAAwC,CAACD,MAAMC,KAAAA,GAAhD;;;ACDjB,IAAMI,wBAAwB;AAC9B,IAAMC,yBAAyB;;;ACI/B,IAAMC,6BAAkD;EAAEC,UAAU;AAAO;;;AHK3E,IAAMC,YAAY,wBAACC,KAAeC,UAA+BC,+BACtEC,WAAWH,GAAAA,IACPI,aAAaJ,KAAKC,OAAAA,EAASI,QAAQC,uBAAuBC,sBAAAA,EAAwBC,MAAMD,sBAAAA,IACxF,CAAA,GAHmB;AAKlB,IAAME,oBAAoB,wBAACT,KAAeC,UAA+BC,+BAC9EH,UAAUC,KAAKC,OAAAA,EAASS,OAAOC,QAAAA,GADA;AAG1B,IAAMC,aAAa,wBAACZ,KAAea,OAAiBZ,UAA4BC,+BAA0B;AAC/G,QAAMY,WAAWX,WAAWH,GAAAA,IAAOI,aAAaJ,KAAKC,OAAAA,IAAWc;AAChE,QAAMC,UAAUH,MAAMI,KAAKV,sBAAAA;AAE3B,MAAIO,aAAaE,QAASE,eAAclB,KAAKgB,SAASf,OAAAA;AACxD,GAL0B;","names":["existsSync","readFileSync","writeFileSync","empty","value","trim","length","notEmpty","WINDOWS_NEWLINE_REGEX","CROSS_PLATFORM_NEWLINE","defaultReadFileSyncOptions","encoding","readLines","uri","options","defaultReadFileSyncOptions","existsSync","readFileSync","replace","WINDOWS_NEWLINE_REGEX","CROSS_PLATFORM_NEWLINE","split","readNonEmptyLines","filter","notEmpty","writeLines","lines","existing","undefined","desired","join","writeFileSync"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/file/constants.ts","../../../src/lib/file/fileLines.ts","../../../src/lib/string/empty.ts","../../../src/lib/file/ReadFileSyncOptions.ts","../../../src/lib/file/tryReadFileSync.ts"],"sourcesContent":["export const WINDOWS_NEWLINE_REGEX = /\\r\\n/g\nexport const CROSS_PLATFORM_NEWLINE = '\\n'\n","import {
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/file/constants.ts","../../../src/lib/file/fileLines.ts","../../../src/lib/string/empty.ts","../../../src/lib/file/ReadFileSyncOptions.ts","../../../src/lib/file/tryReadFileSync.ts"],"sourcesContent":["export const WINDOWS_NEWLINE_REGEX = /\\r\\n/g\nexport const CROSS_PLATFORM_NEWLINE = '\\n'\n","import type { PathLike, WriteFileOptions } from 'node:fs'\nimport {\n existsSync, readFileSync, writeFileSync,\n} from 'node:fs'\n\nimport { notEmpty } from '../string/index.ts'\nimport { CROSS_PLATFORM_NEWLINE, WINDOWS_NEWLINE_REGEX } from './constants.ts'\nimport type { ReadFileSyncOptions } from './ReadFileSyncOptions.ts'\nimport { defaultReadFileSyncOptions } from './ReadFileSyncOptions.ts'\n\nexport const readLines = (uri: PathLike, options: ReadFileSyncOptions = defaultReadFileSyncOptions): string[] =>\n existsSync(uri)\n ? readFileSync(uri, options).replace(WINDOWS_NEWLINE_REGEX, CROSS_PLATFORM_NEWLINE).split(CROSS_PLATFORM_NEWLINE)\n : []\n\nexport const readNonEmptyLines = (uri: PathLike, options: ReadFileSyncOptions = defaultReadFileSyncOptions): string[] =>\n readLines(uri, options).filter(notEmpty)\n\nexport const writeLines = (uri: PathLike, lines: string[], options: WriteFileOptions = defaultReadFileSyncOptions) => {\n const existing = existsSync(uri) ? readFileSync(uri, options) : undefined\n const desired = lines.join(CROSS_PLATFORM_NEWLINE)\n // Check if the file is different before writing\n if (existing !== desired) writeFileSync(uri, desired, options)\n}\n","export const empty = (value?: string | undefined): boolean => value?.trim().length === 0\nexport const notEmpty = (value?: string | undefined): boolean => !empty(value)\n","export type ReadFileSyncOptions = BufferEncoding | {\n encoding: BufferEncoding\n flags?: string\n}\n\nexport const defaultReadFileSyncOptions: ReadFileSyncOptions = { encoding: 'utf8' }\n","import type { PathLike } from 'node:fs'\nimport { existsSync, readFileSync } from 'node:fs'\n\nimport type { ReadFileSyncOptions } from './ReadFileSyncOptions.ts'\nimport { defaultReadFileSyncOptions } from './ReadFileSyncOptions.ts'\n\nexport const tryReadFileSync = (uri: PathLike, options: ReadFileSyncOptions = defaultReadFileSyncOptions): string | undefined => {\n return existsSync(uri) ? readFileSync(uri, options) : undefined\n}\n"],"mappings":";;;;AAAO,IAAMA,wBAAwB;AAC9B,IAAMC,yBAAyB;;;ACAtC,SACEC,YAAYC,cAAcC,qBACrB;;;ACHA,IAAMC,QAAQ,wBAACC,UAAwCA,OAAOC,KAAAA,EAAOC,WAAW,GAAlE;AACd,IAAMC,WAAW,wBAACH,UAAwC,CAACD,MAAMC,KAAAA,GAAhD;;;ACIjB,IAAMI,6BAAkD;EAAEC,UAAU;AAAO;;;AFK3E,IAAMC,YAAY,wBAACC,KAAeC,UAA+BC,+BACtEC,WAAWH,GAAAA,IACPI,aAAaJ,KAAKC,OAAAA,EAASI,QAAQC,uBAAuBC,sBAAAA,EAAwBC,MAAMD,sBAAAA,IACxF,CAAA,GAHmB;AAKlB,IAAME,oBAAoB,wBAACT,KAAeC,UAA+BC,+BAC9EH,UAAUC,KAAKC,OAAAA,EAASS,OAAOC,QAAAA,GADA;AAG1B,IAAMC,aAAa,wBAACZ,KAAea,OAAiBZ,UAA4BC,+BAA0B;AAC/G,QAAMY,WAAWX,WAAWH,GAAAA,IAAOI,aAAaJ,KAAKC,OAAAA,IAAWc;AAChE,QAAMC,UAAUH,MAAMI,KAAKV,sBAAAA;AAE3B,MAAIO,aAAaE,QAASE,eAAclB,KAAKgB,SAASf,OAAAA;AACxD,GAL0B;;;AGjB1B,SAASkB,cAAAA,aAAYC,gBAAAA,qBAAoB;AAKlC,IAAMC,kBAAkB,wBAACC,KAAeC,UAA+BC,+BAA0B;AACtG,SAAOC,YAAWH,GAAAA,IAAOI,cAAaJ,KAAKC,OAAAA,IAAWI;AACxD,GAF+B;","names":["WINDOWS_NEWLINE_REGEX","CROSS_PLATFORM_NEWLINE","existsSync","readFileSync","writeFileSync","empty","value","trim","length","notEmpty","defaultReadFileSyncOptions","encoding","readLines","uri","options","defaultReadFileSyncOptions","existsSync","readFileSync","replace","WINDOWS_NEWLINE_REGEX","CROSS_PLATFORM_NEWLINE","split","readNonEmptyLines","filter","notEmpty","writeLines","lines","existing","undefined","desired","join","writeFileSync","existsSync","readFileSync","tryReadFileSync","uri","options","defaultReadFileSyncOptions","existsSync","readFileSync","undefined"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/file/tryReadFileSync.ts","../../../src/lib/file/ReadFileSyncOptions.ts"],"sourcesContent":["import { existsSync,
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/file/tryReadFileSync.ts","../../../src/lib/file/ReadFileSyncOptions.ts"],"sourcesContent":["import type { PathLike } from 'node:fs'\nimport { existsSync, readFileSync } from 'node:fs'\n\nimport type { ReadFileSyncOptions } from './ReadFileSyncOptions.ts'\nimport { defaultReadFileSyncOptions } from './ReadFileSyncOptions.ts'\n\nexport const tryReadFileSync = (uri: PathLike, options: ReadFileSyncOptions = defaultReadFileSyncOptions): string | undefined => {\n return existsSync(uri) ? readFileSync(uri, options) : undefined\n}\n","export type ReadFileSyncOptions = BufferEncoding | {\n encoding: BufferEncoding\n flags?: string\n}\n\nexport const defaultReadFileSyncOptions: ReadFileSyncOptions = { encoding: 'utf8' }\n"],"mappings":";;;;AACA,SAASA,YAAYC,oBAAoB;;;ACIlC,IAAMC,6BAAkD;EAAEC,UAAU;AAAO;;;ADC3E,IAAMC,kBAAkB,wBAACC,KAAeC,UAA+BC,+BAA0B;AACtG,SAAOC,WAAWH,GAAAA,IAAOI,aAAaJ,KAAKC,OAAAA,IAAWI;AACxD,GAF+B;","names":["existsSync","readFileSync","defaultReadFileSyncOptions","encoding","tryReadFileSync","uri","options","defaultReadFileSyncOptions","existsSync","readFileSync","undefined"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/lib/generateIgnoreFiles.ts","../../src/lib/file/constants.ts","../../src/lib/file/fileLines.ts","../../src/lib/string/empty.ts","../../src/lib/string/union.ts","../../src/lib/file/ReadFileSyncOptions.ts","../../src/lib/yarn/workspace/yarnWorkspaces.ts","../../src/lib/yarn/workspace/yarnWorkspace.ts","../../src/lib/yarn/yarnInitCwd.ts"],"sourcesContent":["import chalk from 'chalk'\n\nimport { readNonEmptyLines, writeLines } from './file/index.ts'\nimport { union } from './string/index.ts'\nimport {
|
|
1
|
+
{"version":3,"sources":["../../src/lib/generateIgnoreFiles.ts","../../src/lib/file/constants.ts","../../src/lib/file/fileLines.ts","../../src/lib/string/empty.ts","../../src/lib/string/union.ts","../../src/lib/file/ReadFileSyncOptions.ts","../../src/lib/yarn/workspace/yarnWorkspaces.ts","../../src/lib/yarn/workspace/yarnWorkspace.ts","../../src/lib/yarn/yarnInitCwd.ts"],"sourcesContent":["import chalk from 'chalk'\n\nimport { readNonEmptyLines, writeLines } from './file/index.ts'\nimport { union } from './string/index.ts'\nimport {\n INIT_CWD, yarnWorkspace, yarnWorkspaces,\n} from './yarn/index.ts'\n\nconst mergeEntries = (a: string[], b: string[]): string[] => [...union(a, b)].sort()\n\nexport const generateIgnoreFiles = (filename: string, pkg?: string) => {\n console.log(chalk.green(`Generate ${filename} Files`))\n const cwd = INIT_CWD() ?? '.'\n const workspaces = pkg ? [yarnWorkspace(pkg)] : yarnWorkspaces()\n const readEntries = (location: string): string[] => readNonEmptyLines(`${location}/${filename}`)\n const writeEntries = (location: string, entries: string[]) => writeLines(`${location}/${filename}`, entries)\n const results = workspaces.map(({ location, name }) => {\n try {\n writeEntries(location, mergeEntries(readEntries(cwd), readEntries(location)))\n return 0\n } catch (ex) {\n const error = ex as Error\n console.error(`Generate ${filename} Files [${name}] [${error.message}]`)\n return 1\n }\n })\n const succeeded = results.every(result => result === 0)\n return succeeded ? 0 : 1\n}\n","export const WINDOWS_NEWLINE_REGEX = /\\r\\n/g\nexport const CROSS_PLATFORM_NEWLINE = '\\n'\n","import type { PathLike, WriteFileOptions } from 'node:fs'\nimport {\n existsSync, readFileSync, writeFileSync,\n} from 'node:fs'\n\nimport { notEmpty } from '../string/index.ts'\nimport { CROSS_PLATFORM_NEWLINE, WINDOWS_NEWLINE_REGEX } from './constants.ts'\nimport type { ReadFileSyncOptions } from './ReadFileSyncOptions.ts'\nimport { defaultReadFileSyncOptions } from './ReadFileSyncOptions.ts'\n\nexport const readLines = (uri: PathLike, options: ReadFileSyncOptions = defaultReadFileSyncOptions): string[] =>\n existsSync(uri)\n ? readFileSync(uri, options).replace(WINDOWS_NEWLINE_REGEX, CROSS_PLATFORM_NEWLINE).split(CROSS_PLATFORM_NEWLINE)\n : []\n\nexport const readNonEmptyLines = (uri: PathLike, options: ReadFileSyncOptions = defaultReadFileSyncOptions): string[] =>\n readLines(uri, options).filter(notEmpty)\n\nexport const writeLines = (uri: PathLike, lines: string[], options: WriteFileOptions = defaultReadFileSyncOptions) => {\n const existing = existsSync(uri) ? readFileSync(uri, options) : undefined\n const desired = lines.join(CROSS_PLATFORM_NEWLINE)\n // Check if the file is different before writing\n if (existing !== desired) writeFileSync(uri, desired, options)\n}\n","export const empty = (value?: string | undefined): boolean => value?.trim().length === 0\nexport const notEmpty = (value?: string | undefined): boolean => !empty(value)\n","export const union = (a: string[], b: string[]): Set<string> => new Set([...new Set(a), ...new Set(b)])\n","export type ReadFileSyncOptions = BufferEncoding | {\n encoding: BufferEncoding\n flags?: string\n}\n\nexport const defaultReadFileSyncOptions: ReadFileSyncOptions = { encoding: 'utf8' }\n","import { spawnSync } from 'node:child_process'\n\nimport type { Workspace } from './Workspace.ts'\n\nexport const yarnWorkspaces = (): Workspace[] => {\n const result = spawnSync('yarn', ['workspaces', 'list', '--json', '--recursive'], { encoding: 'utf8', shell: true })\n if (result.error) {\n throw result.error\n }\n return (\n result.stdout\n .toString()\n // NOTE: This probably doesn't work on Windows\n // TODO: Replace /r/n with /n first\n .split('\\n')\n .slice(0, -1)\n .map((item) => {\n return JSON.parse(item)\n })\n )\n}\n","import type { Workspace } from './Workspace.ts'\nimport { yarnWorkspaces } from './yarnWorkspaces.ts'\n\nexport const yarnWorkspace = (pkg: string): Workspace => {\n const workspace = yarnWorkspaces().find(({ name }) => name === pkg)\n if (!workspace) throw new Error(`Workspace ${pkg} not found`)\n return workspace\n}\n","export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QAAAA,WAAmBmB,IAAAA,MAAUE,MAAMC,OAAO,GAAG;AACvE,aAAO;IACT;EACF,CAAA;AACA,QAAMC,YAAYN,QAAQO,MAAMC,CAAAA,WAAUA,WAAW,CAAA;AACrD,SAAOF,YAAY,IAAI;AACzB,GAlBmC;","names":["chalk","WINDOWS_NEWLINE_REGEX","CROSS_PLATFORM_NEWLINE","existsSync","readFileSync","writeFileSync","empty","value","trim","length","notEmpty","union","a","b","Set","defaultReadFileSyncOptions","encoding","readLines","uri","options","defaultReadFileSyncOptions","existsSync","readFileSync","replace","WINDOWS_NEWLINE_REGEX","CROSS_PLATFORM_NEWLINE","split","readNonEmptyLines","filter","notEmpty","writeLines","lines","existing","undefined","desired","join","writeFileSync","spawnSync","yarnWorkspaces","result","spawnSync","encoding","shell","error","stdout","toString","split","slice","map","item","JSON","parse","yarnWorkspace","pkg","workspace","yarnWorkspaces","find","name","Error","INIT_CWD","process","env","console","error","mergeEntries","a","b","union","sort","generateIgnoreFiles","filename","pkg","console","log","chalk","green","cwd","INIT_CWD","workspaces","yarnWorkspace","yarnWorkspaces","readEntries","location","readNonEmptyLines","writeEntries","entries","writeLines","results","map","name","ex","error","message","succeeded","every","result"]}
|
package/dist/lib/index.mjs
CHANGED
|
@@ -1,5 +1,145 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
1
2
|
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
2
7
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
8
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
9
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
|
|
28
|
+
// ../../node_modules/deepmerge/dist/cjs.js
|
|
29
|
+
var require_cjs = __commonJS({
|
|
30
|
+
"../../node_modules/deepmerge/dist/cjs.js"(exports, module) {
|
|
31
|
+
"use strict";
|
|
32
|
+
var isMergeableObject = /* @__PURE__ */ __name(function isMergeableObject2(value) {
|
|
33
|
+
return isNonNullObject(value) && !isSpecial(value);
|
|
34
|
+
}, "isMergeableObject");
|
|
35
|
+
function isNonNullObject(value) {
|
|
36
|
+
return !!value && typeof value === "object";
|
|
37
|
+
}
|
|
38
|
+
__name(isNonNullObject, "isNonNullObject");
|
|
39
|
+
function isSpecial(value) {
|
|
40
|
+
var stringValue = Object.prototype.toString.call(value);
|
|
41
|
+
return stringValue === "[object RegExp]" || stringValue === "[object Date]" || isReactElement(value);
|
|
42
|
+
}
|
|
43
|
+
__name(isSpecial, "isSpecial");
|
|
44
|
+
var canUseSymbol = typeof Symbol === "function" && Symbol.for;
|
|
45
|
+
var REACT_ELEMENT_TYPE = canUseSymbol ? Symbol.for("react.element") : 60103;
|
|
46
|
+
function isReactElement(value) {
|
|
47
|
+
return value.$$typeof === REACT_ELEMENT_TYPE;
|
|
48
|
+
}
|
|
49
|
+
__name(isReactElement, "isReactElement");
|
|
50
|
+
function emptyTarget(val) {
|
|
51
|
+
return Array.isArray(val) ? [] : {};
|
|
52
|
+
}
|
|
53
|
+
__name(emptyTarget, "emptyTarget");
|
|
54
|
+
function cloneUnlessOtherwiseSpecified(value, options) {
|
|
55
|
+
return options.clone !== false && options.isMergeableObject(value) ? deepmerge2(emptyTarget(value), value, options) : value;
|
|
56
|
+
}
|
|
57
|
+
__name(cloneUnlessOtherwiseSpecified, "cloneUnlessOtherwiseSpecified");
|
|
58
|
+
function defaultArrayMerge(target, source, options) {
|
|
59
|
+
return target.concat(source).map(function(element) {
|
|
60
|
+
return cloneUnlessOtherwiseSpecified(element, options);
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
__name(defaultArrayMerge, "defaultArrayMerge");
|
|
64
|
+
function getMergeFunction(key, options) {
|
|
65
|
+
if (!options.customMerge) {
|
|
66
|
+
return deepmerge2;
|
|
67
|
+
}
|
|
68
|
+
var customMerge = options.customMerge(key);
|
|
69
|
+
return typeof customMerge === "function" ? customMerge : deepmerge2;
|
|
70
|
+
}
|
|
71
|
+
__name(getMergeFunction, "getMergeFunction");
|
|
72
|
+
function getEnumerableOwnPropertySymbols(target) {
|
|
73
|
+
return Object.getOwnPropertySymbols ? Object.getOwnPropertySymbols(target).filter(function(symbol) {
|
|
74
|
+
return Object.propertyIsEnumerable.call(target, symbol);
|
|
75
|
+
}) : [];
|
|
76
|
+
}
|
|
77
|
+
__name(getEnumerableOwnPropertySymbols, "getEnumerableOwnPropertySymbols");
|
|
78
|
+
function getKeys(target) {
|
|
79
|
+
return Object.keys(target).concat(getEnumerableOwnPropertySymbols(target));
|
|
80
|
+
}
|
|
81
|
+
__name(getKeys, "getKeys");
|
|
82
|
+
function propertyIsOnObject(object, property) {
|
|
83
|
+
try {
|
|
84
|
+
return property in object;
|
|
85
|
+
} catch (_) {
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
__name(propertyIsOnObject, "propertyIsOnObject");
|
|
90
|
+
function propertyIsUnsafe(target, key) {
|
|
91
|
+
return propertyIsOnObject(target, key) && !(Object.hasOwnProperty.call(target, key) && Object.propertyIsEnumerable.call(target, key));
|
|
92
|
+
}
|
|
93
|
+
__name(propertyIsUnsafe, "propertyIsUnsafe");
|
|
94
|
+
function mergeObject(target, source, options) {
|
|
95
|
+
var destination = {};
|
|
96
|
+
if (options.isMergeableObject(target)) {
|
|
97
|
+
getKeys(target).forEach(function(key) {
|
|
98
|
+
destination[key] = cloneUnlessOtherwiseSpecified(target[key], options);
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
getKeys(source).forEach(function(key) {
|
|
102
|
+
if (propertyIsUnsafe(target, key)) {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
if (propertyIsOnObject(target, key) && options.isMergeableObject(source[key])) {
|
|
106
|
+
destination[key] = getMergeFunction(key, options)(target[key], source[key], options);
|
|
107
|
+
} else {
|
|
108
|
+
destination[key] = cloneUnlessOtherwiseSpecified(source[key], options);
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
return destination;
|
|
112
|
+
}
|
|
113
|
+
__name(mergeObject, "mergeObject");
|
|
114
|
+
function deepmerge2(target, source, options) {
|
|
115
|
+
options = options || {};
|
|
116
|
+
options.arrayMerge = options.arrayMerge || defaultArrayMerge;
|
|
117
|
+
options.isMergeableObject = options.isMergeableObject || isMergeableObject;
|
|
118
|
+
options.cloneUnlessOtherwiseSpecified = cloneUnlessOtherwiseSpecified;
|
|
119
|
+
var sourceIsArray = Array.isArray(source);
|
|
120
|
+
var targetIsArray = Array.isArray(target);
|
|
121
|
+
var sourceAndTargetTypesMatch = sourceIsArray === targetIsArray;
|
|
122
|
+
if (!sourceAndTargetTypesMatch) {
|
|
123
|
+
return cloneUnlessOtherwiseSpecified(source, options);
|
|
124
|
+
} else if (sourceIsArray) {
|
|
125
|
+
return options.arrayMerge(target, source, options);
|
|
126
|
+
} else {
|
|
127
|
+
return mergeObject(target, source, options);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
__name(deepmerge2, "deepmerge");
|
|
131
|
+
deepmerge2.all = /* @__PURE__ */ __name(function deepmergeAll(array, options) {
|
|
132
|
+
if (!Array.isArray(array)) {
|
|
133
|
+
throw new Error("first argument should be an array");
|
|
134
|
+
}
|
|
135
|
+
return array.reduce(function(prev, next) {
|
|
136
|
+
return deepmerge2(prev, next, options);
|
|
137
|
+
}, {});
|
|
138
|
+
}, "deepmergeAll");
|
|
139
|
+
var deepmerge_1 = deepmerge2;
|
|
140
|
+
module.exports = deepmerge_1;
|
|
141
|
+
}
|
|
142
|
+
});
|
|
3
143
|
|
|
4
144
|
// src/lib/checkResult.ts
|
|
5
145
|
import chalk from "chalk";
|
|
@@ -78,6 +218,19 @@ var createBuildConfig = /* @__PURE__ */ __name((location, module, target, outDir
|
|
|
78
218
|
};
|
|
79
219
|
}, "createBuildConfig");
|
|
80
220
|
|
|
221
|
+
// src/lib/deleteGlob.ts
|
|
222
|
+
import fs from "node:fs";
|
|
223
|
+
import { glob } from "glob";
|
|
224
|
+
var deleteGlob = /* @__PURE__ */ __name((globPath) => {
|
|
225
|
+
const files = glob.sync(globPath);
|
|
226
|
+
for (const file of files) {
|
|
227
|
+
fs.rmSync(file, {
|
|
228
|
+
recursive: true,
|
|
229
|
+
force: true
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
}, "deleteGlob");
|
|
233
|
+
|
|
81
234
|
// src/lib/dependencies/detectDuplicateDependencies.ts
|
|
82
235
|
import { execSync } from "node:child_process";
|
|
83
236
|
|
|
@@ -141,7 +294,6 @@ var safeExitAsync = /* @__PURE__ */ __name(async (func, exitOnFail = true) => {
|
|
|
141
294
|
// src/lib/dependencies/DuplicateDetector.ts
|
|
142
295
|
import { EOL } from "node:os";
|
|
143
296
|
import chalk3 from "chalk";
|
|
144
|
-
import uniq from "lodash/uniq.js";
|
|
145
297
|
|
|
146
298
|
// src/lib/jsonFormatters.ts
|
|
147
299
|
var multiLineToJSONArray = /* @__PURE__ */ __name((output) => {
|
|
@@ -212,7 +364,9 @@ var DuplicateDetector = class {
|
|
|
212
364
|
acc.duplicateVersions.push(acc.currentVersion);
|
|
213
365
|
}
|
|
214
366
|
acc.duplicateVersions.push(version);
|
|
215
|
-
acc.duplicateVersions =
|
|
367
|
+
acc.duplicateVersions = [
|
|
368
|
+
...new Set(acc.duplicateVersions)
|
|
369
|
+
];
|
|
216
370
|
}
|
|
217
371
|
return acc;
|
|
218
372
|
}
|
|
@@ -380,13 +534,13 @@ var generateIgnoreFiles = /* @__PURE__ */ __name((filename, pkg) => {
|
|
|
380
534
|
}, "generateIgnoreFiles");
|
|
381
535
|
|
|
382
536
|
// src/lib/loadConfig.ts
|
|
537
|
+
var import_deepmerge = __toESM(require_cjs(), 1);
|
|
383
538
|
import chalk5 from "chalk";
|
|
384
539
|
import { cosmiconfig } from "cosmiconfig";
|
|
385
|
-
import merge from "lodash/merge.js";
|
|
386
540
|
var config;
|
|
387
541
|
var loadConfig = /* @__PURE__ */ __name(async (params) => {
|
|
388
542
|
if (config) {
|
|
389
|
-
return
|
|
543
|
+
return (0, import_deepmerge.default)(config, params ?? {});
|
|
390
544
|
}
|
|
391
545
|
const cosmicConfigResult = await cosmiconfig("xy", {
|
|
392
546
|
cache: true
|
|
@@ -396,7 +550,7 @@ var loadConfig = /* @__PURE__ */ __name(async (params) => {
|
|
|
396
550
|
if (configFilePath) {
|
|
397
551
|
console.log(chalk5.gray(`Loading config from ${configFilePath}`));
|
|
398
552
|
}
|
|
399
|
-
return
|
|
553
|
+
return (0, import_deepmerge.default)(config, params ?? {});
|
|
400
554
|
}, "loadConfig");
|
|
401
555
|
|
|
402
556
|
// src/lib/parsedPackageJSON.ts
|
|
@@ -518,6 +672,7 @@ export {
|
|
|
518
672
|
createBuildConfig,
|
|
519
673
|
defaultBuildConfig,
|
|
520
674
|
defaultReadFileSyncOptions,
|
|
675
|
+
deleteGlob,
|
|
521
676
|
detectDuplicateDependencies,
|
|
522
677
|
empty,
|
|
523
678
|
generateIgnoreFiles,
|