@tonycodes-ui/mortar 0.22.3 → 0.23.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/cli/audit.mjs CHANGED
@@ -21,6 +21,10 @@ import {
21
21
  RENAMED_VALUES,
22
22
  } from "./migrations.mjs";
23
23
 
24
+ // Built from parts so tracked source does not contain the retired scope literal
25
+ // (tests/npm-package-name.test.mjs forbids it outside the migration allowlist).
26
+ const LEGACY_PKG = ["@", "tony-ui", "/", "mortar"].join("");
27
+
24
28
  export const RULES = {
25
29
  "not-installed": "@tonycodes-ui/mortar is imported but not installed.",
26
30
  "not-declared": "@tonycodes-ui/mortar is imported but not in package.json.",
@@ -48,6 +52,7 @@ export const RULES = {
48
52
  "local-copy": "A local copy of Mortar source.",
49
53
  "raw-element":
50
54
  "A raw HTML element (such as <table> or <select>) that a Mortar component replaces, in an app that uses Mortar.",
55
+ "legacy-package": `A dependency or import of the retired ${LEGACY_PKG}; install and import @tonycodes-ui/mortar instead (see the CHANGELOG migration note).`,
51
56
  "limited-data": "The audit could not use the installed version's own data.",
52
57
  };
53
58
 
@@ -84,6 +89,20 @@ const CODE = new Set([
84
89
  const JSX = new Set([".js", ".jsx", ".tsx", ".mjs"]);
85
90
  const STYLE = new Set([".css", ".scss", ".sass", ".less", ".pcss", ".postcss"]);
86
91
  const PKG = "@tonycodes-ui/mortar";
92
+ const LEGACY_ESCAPE = LEGACY_PKG.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
93
+ const LEGACY_IMPORT = new RegExp(
94
+ String.raw`\b(import|export)\s+(type\s+)?((?:(?!\bfrom\b)[^;])*?)\s*\bfrom\s*(["'])(${LEGACY_ESCAPE}(?:\/[^"']*)?)\4`,
95
+ "g",
96
+ );
97
+ const LEGACY_SIDE_EFFECT = new RegExp(
98
+ String.raw`\bimport\s*(["'])(${LEGACY_ESCAPE}(?:\/[^"']*)?)\1`,
99
+ "g",
100
+ );
101
+ const LEGACY_CSS_IMPORT = new RegExp(
102
+ String.raw`@import\s*(["'])(${LEGACY_ESCAPE}(?:\/[^"']*)?)\1`,
103
+ "g",
104
+ );
105
+ const LEGACY_FIX = `Install and import "${PKG}" instead of "${LEGACY_PKG}". See the CHANGELOG migration note.`;
87
106
  const MAX_FILES = 20000;
88
107
  const MAX_BYTES = 1_000_000;
89
108
 
@@ -795,6 +814,15 @@ export async function auditApp(path = ".", { data: bundled } = {}) {
795
814
  '@import "tailwindcss"; first, then @import "@tonycodes-ui/mortar/styles.css";',
796
815
  );
797
816
  }
817
+ for (const m of css.matchAll(LEGACY_CSS_IMPORT))
818
+ add(
819
+ "legacy-package",
820
+ "error",
821
+ file,
822
+ line(m.index),
823
+ `Imports the retired "${m[2]}"; install and import "${PKG}" instead (see the CHANGELOG migration note).`,
824
+ LEGACY_FIX,
825
+ );
798
826
  // Selectors: the text before each `{` that is not an at-rule.
799
827
  for (const m of css.matchAll(/([^{};]+)\{/g)) {
800
828
  const selector = m[1].trim();
@@ -822,6 +850,24 @@ export async function auditApp(path = ".", { data: bundled } = {}) {
822
850
  }
823
851
 
824
852
  const src = blankComments(text);
853
+ for (const m of src.matchAll(LEGACY_IMPORT))
854
+ add(
855
+ "legacy-package",
856
+ "error",
857
+ file,
858
+ line(m.index),
859
+ `Imports the retired "${m[5]}"; install and import "${PKG}" instead (see the CHANGELOG migration note).`,
860
+ LEGACY_FIX,
861
+ );
862
+ for (const m of src.matchAll(LEGACY_SIDE_EFFECT))
863
+ add(
864
+ "legacy-package",
865
+ "error",
866
+ file,
867
+ line(m.index),
868
+ `Imports the retired "${m[2]}"; install and import "${PKG}" instead (see the CHANGELOG migration note).`,
869
+ LEGACY_FIX,
870
+ );
825
871
  // Email markup is tables by design, and has its own components.
826
872
  const emailFile = EMAIL_FILE.test(src);
827
873
  if (JSX.has(ext) && !emailFile) {
@@ -1168,6 +1214,19 @@ export async function auditApp(path = ".", { data: bundled } = {}) {
1168
1214
  pkgJson?.dependencies?.[PKG] ??
1169
1215
  pkgJson?.devDependencies?.[PKG] ??
1170
1216
  pkgJson?.peerDependencies?.[PKG];
1217
+ const legacyRange =
1218
+ pkgJson?.dependencies?.[LEGACY_PKG] ??
1219
+ pkgJson?.devDependencies?.[LEGACY_PKG] ??
1220
+ pkgJson?.peerDependencies?.[LEGACY_PKG];
1221
+ if (legacyRange)
1222
+ add(
1223
+ "legacy-package",
1224
+ "error",
1225
+ pkgFile,
1226
+ 1,
1227
+ `Depends on the retired "${LEGACY_PKG}"; install and import "${PKG}" instead (see the CHANGELOG migration note).`,
1228
+ LEGACY_FIX,
1229
+ );
1171
1230
  const reactEmail = "@react-email/components";
1172
1231
  if (
1173
1232
  usesEmail &&