{"version":3,"file":"logging.mjs","sources":["../../src/util/logging.ts"],"sourcesContent":["import identity from 'lodash/identity.js';\n\ntype Check = boolean;\ntype LogLevel = 'warn' | 'error';\n\n/**\n * Prefix on every message that flags a bad usage pattern, so tools and people can filter for them.\n */\nexport const EDS_AUDIT_PREFIX = 'EDS-AUDIT: ';\n\n/**\n * Logging function used to check whether a usage of EDS is proper and advised. When using, it defaults\n * to warning, where it will print a message to the console for developers to see. LogLevel supported.\n *\n * @param list of truthy checks to assert whether the component usages are appropriate\n * @param message Message to print when ANY of the checks are true\n * @param [loglevel] Severity of the tracked issue\n */\nexport function assertEdsUsage(\n  checks: Check[],\n  message: string,\n  loglevel: LogLevel = 'warn',\n): void {\n  if (process.env.NODE_ENV !== 'production' && [...checks].some(identity)) {\n    console[loglevel](`${EDS_AUDIT_PREFIX}${message}`);\n  }\n}\n\n/**\n * Props that a major version removed, so an implementation can read one that arrives anyway\n * without putting it back into a public API.\n *\n * TODO(next-major): remove, with `assertNoRemovedProp` and every destructure that feeds it.\n */\nexport type WithRemovedProps<T, PropName extends string> = T &\n  Partial<Record<PropName, unknown>>;\n\n/**\n * Props that v19 removed in favor of `IconProvider`, so an implementation can read one\n * that arrives anyway without putting it back into a public API.\n *\n * TODO(next-major): remove, with `assertNoRemovedIconProp` and every destructure that\n * feeds it.\n */\nexport type WithRemovedIconProps<T, PropName extends string> = WithRemovedProps<\n  T,\n  PropName\n>;\n\n/**\n * Warns a consumer still passing a prop a major version removed outright, where nothing took\n * over its job and the component decides for itself instead.\n *\n * Worth a check of our own for the same reason `assertNoRemovedIconProp` is: neither route\n * reaches untyped code. A typed consumer gets TS2322 at the call site, but JavaScript never\n * sees that, and React's own reporting is uneven — it names an unknown camelCase prop but\n * forwards an unknown lowercase one to the DOM in silence. Neither says the prop was removed\n * or what happens now. Reading the prop here also keeps it off the DOM.\n *\n * TODO(next-major): remove, with every destructure that calls it.\n *\n * @param componentName the component as a consumer writes it, e.g. `Modal.Body`\n * @param propName the prop that was removed, e.g. `height`\n * @param behavior what the component does in its place, as a full sentence\n * @param value whatever arrived under that prop\n */\nexport function assertNoRemovedProp(\n  componentName: string,\n  propName: string,\n  behavior: string,\n  value: unknown,\n): void {\n  assertEdsUsage(\n    [typeof value !== 'undefined'],\n    `${componentName} no longer takes \\`${propName}\\`, and the one passed is ignored. ${behavior} Run \\`npx eds-migrate 18-to-19\\` to clean the prop up.`,\n  );\n}\n\n/**\n * Warns a consumer still passing one of the icon props that v19 removed in favor of\n * `IconProvider`.\n *\n * Worth a check of our own because neither route reaches untyped code. A typed consumer\n * gets TS2322 at the call site, but JavaScript never sees that, and what happens next\n * depends on the prop's name: React reports an unknown *camelCase* prop but forwards an\n * unknown *lowercase* one to the DOM in silence. So `icon` produced a stray attribute and\n * nothing else, while `indicatorContent` and friends produced a warning about React rather\n * than about EDS — nothing in either case saying the prop was removed, or what to do now.\n * Reading the prop here also keeps it off the DOM.\n *\n * The remediation stays general on purpose. This serves both kinds of removal: the migration\n * drops most of these props whatever their value, but leaves a non-default\n * `indicatorContent` or `trailingContent` in place for a person to decide on. Naming either\n * behaviour here would be wrong for the other half of the callers, so it points at the\n * action that is right for all of them — move the value to an `IconProvider` if it mattered.\n *\n * TODO(next-major): remove. By then `eds-migrate 18-to-19` is far enough back that code\n * still passing these is not worth carrying a runtime check for, and the destructures that\n * call this should go with it.\n *\n * @param componentName the component as a consumer writes it, e.g. `Breadcrumbs.Item`\n * @param propName the prop that was removed, e.g. `indicatorContent`\n * @param role the semantic icon role that supplies the icon now\n * @param value whatever arrived under that prop\n */\nexport function assertNoRemovedIconProp(\n  componentName: string,\n  propName: string,\n  role: string,\n  value: unknown,\n): void {\n  assertEdsUsage(\n    [typeof value !== 'undefined'],\n    `${componentName} no longer takes \\`${propName}\\`, and the one passed is ignored. It draws the \\`${role}\\` icon from \\`IconProvider\\` instead, so every component filling that role matches. Run \\`npx eds-migrate 18-to-19\\` to clean the prop up, and if its value mattered, set \\`${role}\\` on an \\`IconProvider\\` so the icon looks that way everywhere.`,\n  );\n}\n"],"names":[],"mappings":";;AAKA;;AAEG;AACI,MAAM,gBAAgB,GAAG;AAEhC;;;;;;;AAOG;AACG,SAAU,cAAc,CAC5B,MAAe,EACf,OAAe,EACf,WAAqB,MAAM,EAAA;AAE3B,IAAA,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,IAAI,CAAC,GAAG,MAAM,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE;QACvE,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAA,EAAG,gBAAgB,CAAA,EAAG,OAAO,CAAA,CAAE,CAAC;IACpD;AACF;AAuBA;;;;;;;;;;;;;;;;AAgBG;AACG,SAAU,mBAAmB,CACjC,aAAqB,EACrB,QAAgB,EAChB,QAAgB,EAChB,KAAc,EAAA;AAEd,IAAA,cAAc,CACZ,CAAC,OAAO,KAAK,KAAK,WAAW,CAAC,EAC9B,CAAA,EAAG,aAAa,sBAAsB,QAAQ,CAAA,mCAAA,EAAsC,QAAQ,CAAA,uDAAA,CAAyD,CACtJ;AACH;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;AA0BG;AACG,SAAU,uBAAuB,CACrC,aAAqB,EACrB,QAAgB,EAChB,IAAY,EACZ,KAAc,EAAA;AAEd,IAAA,cAAc,CACZ,CAAC,OAAO,KAAK,KAAK,WAAW,CAAC,EAC9B,CAAA,EAAG,aAAa,CAAA,mBAAA,EAAsB,QAAQ,CAAA,kDAAA,EAAqD,IAAI,gLAAgL,IAAI,CAAA,gEAAA,CAAkE,CAC9V;AACH;;"}