@mfeflow/core 0.2.0 → 0.3.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.
@@ -0,0 +1,8 @@
1
+ /**
2
+ * The Tailwind class prefix of an app. Tailwind 4 accepts lowercase letters only, so a name made of
3
+ * letters is its own prefix (`cart:flex`); any other name keeps its letters and gets four more from a hash
4
+ * of the whole name, so `cart_b` and `cartb` (and `cart1` and `cart2`) never share one.
5
+ */
6
+ export declare function tailwindPrefix(name: string): string;
7
+ /** Throws if two apps map to the same prefix, which would bring back the collision the prefix prevents. */
8
+ export declare function assertUniqueTailwindPrefixes(names: readonly string[], prefixOf?: (name: string) => string): void;
package/dist/index.js CHANGED
@@ -2022,6 +2022,31 @@ async function listLocalFeatures(featuresDir, ops = realFs) {
2022
2022
  const checked = await Promise.all(dirs.map(async (dir)=>await readIfExists(ops, node_path.join(featuresDir, dir, 'feature.json')) === void 0 ? void 0 : dir));
2023
2023
  return checked.filter((d)=>void 0 !== d).toSorted((a, b)=>a.localeCompare(b));
2024
2024
  }
2025
+ const LETTERS = 'abcdefghijklmnopqrstuvwxyz';
2026
+ function shortHash(text) {
2027
+ let hash = 0x811c9dc5;
2028
+ for (const char of text)hash = Math.imul(hash ^ char.codePointAt(0), 0x01000193) >>> 0;
2029
+ let out = '';
2030
+ for(let i = 0; i < 4; i++){
2031
+ out += LETTERS[hash % 26];
2032
+ hash = Math.floor(hash / 26);
2033
+ }
2034
+ return out;
2035
+ }
2036
+ function tailwindPrefix(name) {
2037
+ if (/^[a-z]+$/.test(name)) return name;
2038
+ const letters = name.replace(/[^a-z]/g, '') || 'app';
2039
+ return letters + shortHash(name);
2040
+ }
2041
+ function assertUniqueTailwindPrefixes(names, prefixOf = tailwindPrefix) {
2042
+ const seen = new Map();
2043
+ for (const name of names){
2044
+ const prefix = prefixOf(name);
2045
+ const other = seen.get(prefix);
2046
+ if (void 0 !== other) throw new MfeflowError('E208', `the apps "${other}" and "${name}" would both use the Tailwind prefix "${prefix}"; rename one of them`);
2047
+ seen.set(prefix, name);
2048
+ }
2049
+ }
2025
2050
  const TURBO_FILE = 'turbo.json';
2026
2051
  const EXACT_APP = 'app:';
2027
2052
  function placesFor(target, project) {
@@ -2102,6 +2127,7 @@ async function resolveFeature(input) {
2102
2127
  for (const other of manifest.conflicts ?? [])if (present.has(other)) throw new MfeflowError('E205', `${manifest.name} and ${other}`);
2103
2128
  for (const needed of manifest.requires ?? [])if (!present.has(needed)) throw new MfeflowError('E206', `${manifest.name} needs ${needed}`);
2104
2129
  const options = resolveOptions(manifest, input.options);
2130
+ if ('tailwind' === manifest.name) assertUniqueTailwindPrefixes(Object.keys(project.apps));
2105
2131
  const dataFor = (place)=>({
2106
2132
  scope: project.scope,
2107
2133
  topology: project.topology,
@@ -2115,7 +2141,8 @@ async function resolveFeature(input) {
2115
2141
  name: place.name,
2116
2142
  kind: place.kind,
2117
2143
  path: place.dir,
2118
- port: place.port
2144
+ port: place.port,
2145
+ tailwindPrefix: tailwindPrefix(place.name)
2119
2146
  }
2120
2147
  });
2121
2148
  const steps = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mfeflow/core",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "The engine behind the mfeflow CLI: project model, change plans with diffs, atomic apply with rollback, and feature resolution.",
5
5
  "keywords": [
6
6
  "micro-frontend",
@@ -45,7 +45,7 @@
45
45
  "dependencies": {
46
46
  "@babel/parser": "8.0.10",
47
47
  "@babel/types": "8.0.10",
48
- "@mfeflow/contracts": "0.2.0",
48
+ "@mfeflow/contracts": "0.3.0",
49
49
  "diff": "9.0.0",
50
50
  "eta": "4.6.0",
51
51
  "semver": "7.8.5",