rnwind 0.0.3 → 0.0.4

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,81 @@
1
+ 'use strict';
2
+
3
+ var node_module = require('node:module');
4
+ var node_fs = require('node:fs');
5
+
6
+ /**
7
+ * Inline `@import` resolution for the theme entry CSS.
8
+ *
9
+ * rnwind's scheme extractors (`extractThemeVars`, `extractSchemeAliases`,
10
+ * `extractCustomVariantSchemes`) are plain text passes over the entry
11
+ * CSS — they don't follow `@import`. Tailwind's own compiler DOES follow
12
+ * imports, so utilities still compile, but a user who keeps their theme
13
+ * in a separate file and points the entry at it:
14
+ *
15
+ * ```css
16
+ * @import "@acme/ui/theme.css"; // global.css — the cssEntryFile
17
+ * ```
18
+ *
19
+ * would hand the extractors a file with no `@theme` / `@variant` /
20
+ * `@custom-variant` in sight → every scheme collapses to base and theme
21
+ * switching dies. This module flattens those user imports first so the
22
+ * extractors (and the compiler) see the real declarations.
23
+ */
24
+ /** Matches a bare `@import "spec";` / `@import 'spec';` (no media/layer suffix). */
25
+ const CSS_IMPORT = /@import\s+(["'])([^"']+)\1\s*;/g;
26
+ /**
27
+ * Specs left untouched for the Tailwind compiler to resolve itself.
28
+ * `tailwindcss` resolves to JS (not inlinable) and `rnwind/css` is the
29
+ * framework preset — both are the compiler's job, not user theme files.
30
+ */
31
+ const FRAMEWORK_SPECS = new Set(['tailwindcss', 'rnwind/css', 'rnwind']);
32
+ /**
33
+ * Read `filePath` and replace each user `@import "<spec>";` whose spec
34
+ * resolves (Node resolution, honouring `exports` maps and workspace
35
+ * symlinks) to a readable `.css` file with that file's inlined +
36
+ * recursively-resolved contents. Unresolvable specs, non-CSS targets,
37
+ * and {@link FRAMEWORK_SPECS} are left as-is for the compiler.
38
+ * @param filePath Absolute path of the CSS file being inlined.
39
+ * @param seen Visited set guarding against import cycles.
40
+ * @returns CSS text with user imports flattened in place.
41
+ */
42
+ function inlineImports(filePath, seen) {
43
+ if (seen.has(filePath))
44
+ return '';
45
+ seen.add(filePath);
46
+ let css;
47
+ try {
48
+ css = node_fs.readFileSync(filePath, 'utf8');
49
+ }
50
+ catch {
51
+ return '';
52
+ }
53
+ const request = node_module.createRequire(filePath);
54
+ return css.replaceAll(CSS_IMPORT, (full, _quote, spec) => {
55
+ if (FRAMEWORK_SPECS.has(spec))
56
+ return full;
57
+ let resolved;
58
+ try {
59
+ resolved = request.resolve(spec);
60
+ }
61
+ catch {
62
+ return full;
63
+ }
64
+ if (!resolved.endsWith('.css') || !node_fs.existsSync(resolved))
65
+ return full;
66
+ return inlineImports(resolved, seen);
67
+ });
68
+ }
69
+ /**
70
+ * Flatten user `@import`s in a theme entry CSS file so rnwind's text-based
71
+ * scheme extractors see the real `@theme` / `@variant` / `@custom-variant`
72
+ * declarations even when the entry only re-exports them via `@import`.
73
+ * @param entryFilePath Absolute path to the theme entry CSS (the cssEntryFile).
74
+ * @returns Inlined CSS, or `''` when the entry can't be read.
75
+ */
76
+ function resolveThemeCss(entryFilePath) {
77
+ return inlineImports(entryFilePath, new Set());
78
+ }
79
+
80
+ exports.resolveThemeCss = resolveThemeCss;
81
+ //# sourceMappingURL=css-imports.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"css-imports.cjs","sources":["../../../../src/metro/css-imports.ts"],"sourcesContent":["import { createRequire } from 'node:module'\nimport { existsSync, readFileSync } from 'node:fs'\n\n/**\n * Inline `@import` resolution for the theme entry CSS.\n *\n * rnwind's scheme extractors (`extractThemeVars`, `extractSchemeAliases`,\n * `extractCustomVariantSchemes`) are plain text passes over the entry\n * CSS — they don't follow `@import`. Tailwind's own compiler DOES follow\n * imports, so utilities still compile, but a user who keeps their theme\n * in a separate file and points the entry at it:\n *\n * ```css\n * @import \"@acme/ui/theme.css\"; // global.css — the cssEntryFile\n * ```\n *\n * would hand the extractors a file with no `@theme` / `@variant` /\n * `@custom-variant` in sight → every scheme collapses to base and theme\n * switching dies. This module flattens those user imports first so the\n * extractors (and the compiler) see the real declarations.\n */\n\n/** Matches a bare `@import \"spec\";` / `@import 'spec';` (no media/layer suffix). */\nconst CSS_IMPORT = /@import\\s+([\"'])([^\"']+)\\1\\s*;/g\n\n/**\n * Specs left untouched for the Tailwind compiler to resolve itself.\n * `tailwindcss` resolves to JS (not inlinable) and `rnwind/css` is the\n * framework preset — both are the compiler's job, not user theme files.\n */\nconst FRAMEWORK_SPECS = new Set(['tailwindcss', 'rnwind/css', 'rnwind'])\n\n/**\n * Read `filePath` and replace each user `@import \"<spec>\";` whose spec\n * resolves (Node resolution, honouring `exports` maps and workspace\n * symlinks) to a readable `.css` file with that file's inlined +\n * recursively-resolved contents. Unresolvable specs, non-CSS targets,\n * and {@link FRAMEWORK_SPECS} are left as-is for the compiler.\n * @param filePath Absolute path of the CSS file being inlined.\n * @param seen Visited set guarding against import cycles.\n * @returns CSS text with user imports flattened in place.\n */\nfunction inlineImports(filePath: string, seen: Set<string>): string {\n if (seen.has(filePath)) return ''\n seen.add(filePath)\n let css: string\n try {\n css = readFileSync(filePath, 'utf8')\n } catch {\n return ''\n }\n const request = createRequire(filePath)\n return css.replaceAll(CSS_IMPORT, (full: string, _quote: string, spec: string): string => {\n if (FRAMEWORK_SPECS.has(spec)) return full\n let resolved: string\n try {\n resolved = request.resolve(spec)\n } catch {\n return full\n }\n if (!resolved.endsWith('.css') || !existsSync(resolved)) return full\n return inlineImports(resolved, seen)\n })\n}\n\n/**\n * Flatten user `@import`s in a theme entry CSS file so rnwind's text-based\n * scheme extractors see the real `@theme` / `@variant` / `@custom-variant`\n * declarations even when the entry only re-exports them via `@import`.\n * @param entryFilePath Absolute path to the theme entry CSS (the cssEntryFile).\n * @returns Inlined CSS, or `''` when the entry can't be read.\n */\nexport function resolveThemeCss(entryFilePath: string): string {\n return inlineImports(entryFilePath, new Set<string>())\n}\n"],"names":["readFileSync","createRequire","existsSync"],"mappings":";;;;;AAGA;;;;;;;;;;;;;;;;;AAiBG;AAEH;AACA,MAAM,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
2
+ * Flatten user `@import`s in a theme entry CSS file so rnwind's text-based
3
+ * scheme extractors see the real `@theme` / `@variant` / `@custom-variant`
4
+ * declarations even when the entry only re-exports them via `@import`.
5
+ * @param entryFilePath Absolute path to the theme entry CSS (the cssEntryFile).
6
+ * @returns Inlined CSS, or `''` when the entry can't be read.
7
+ */
8
+ export declare function resolveThemeCss(entryFilePath: string): string;
@@ -5,6 +5,7 @@ var path = require('node:path');
5
5
  var node_crypto = require('node:crypto');
6
6
  var unionBuilder = require('../core/style-builder/union-builder.cjs');
7
7
  var twParser = require('../core/parser/tw-parser.cjs');
8
+ var cssImports = require('./css-imports.cjs');
8
9
 
9
10
  /**
10
11
  * Default oxide Scanner globs — walk every JS/TS source under the
@@ -60,10 +61,11 @@ let libraryFingerprint;
60
61
  /** Live state shared across one Metro transform worker. */
61
62
  let cached = null;
62
63
  /**
63
- * Cheap content-hash readout. SHA-256 prefix of the CSS bytes plus the
64
- * file's mtime nanoseconds (so identical content with different mtime
65
- * atomic rewrites still picks up the change). Returns `'missing'`
66
- * when the file can't be read so the cache key is still deterministic.
64
+ * Cheap content-hash readout. SHA-256 prefix of the FULLY-RESOLVED theme
65
+ * CSS — `@import`s flattened so an edit to a theme file the entry only
66
+ * re-exports (`@import "@acme/ui/theme.css"`) still rotates the hash and
67
+ * invalidates Metro's cache. Returns `'missing'` when the entry can't be
68
+ * read so the cache key stays deterministic.
67
69
  * @param cssPath Absolute CSS path.
68
70
  * @returns 16-char hex content hash.
69
71
  */
@@ -71,9 +73,7 @@ function readThemeHashFor(cssPath) {
71
73
  if (!node_fs.existsSync(cssPath))
72
74
  return 'missing';
73
75
  try {
74
- const bytes = node_fs.readFileSync(cssPath);
75
- const mtime = node_fs.statSync(cssPath).mtimeMs.toString();
76
- return node_crypto.createHash('sha256').update(bytes).update(mtime).digest('hex').slice(0, 16);
76
+ return node_crypto.createHash('sha256').update(cssImports.resolveThemeCss(cssPath)).digest('hex').slice(0, 16);
77
77
  }
78
78
  catch {
79
79
  return 'missing';
@@ -228,7 +228,7 @@ function getRnwindState(projectRoot) {
228
228
  const currentHash = readThemeHashFor(cssEntry);
229
229
  if (cached?.themeHash === currentHash && cached.projectRoot === projectRoot)
230
230
  return cached;
231
- const themeCss = node_fs.readFileSync(cssEntry, 'utf8');
231
+ const themeCss = cssImports.resolveThemeCss(cssEntry);
232
232
  const parser = new twParser.TailwindParser({
233
233
  themeCss,
234
234
  sources: defaultSources(projectRoot, cacheDir, readWatchFolders()),
@@ -1 +1 @@
1
- {"version":3,"file":"state.cjs","sources":["../../../../src/metro/state.ts"],"sourcesContent":["import { existsSync, readFileSync, statSync } from 'node:fs'\nimport path from 'node:path'\nimport { createHash } from 'node:crypto'\nimport { UnionBuilder } from '../core/style-builder'\nimport { TailwindParser, type SourceEntry } from '../core/parser'\n\n/**\n * Default oxide Scanner globs — walk every JS/TS source under the\n * project root AND every monorepo watch folder, excluding\n * `node_modules` and rnwind's own cache dir so we don't rescan\n * generated scheme files.\n *\n * Monorepo layouts (Yarn workspaces, pnpm workspaces, Nx) surface\n * sibling package roots as `metroConfig.watchFolders`. Every folder\n * Metro watches must also be scanned so atoms declared in shared UI\n * packages make it into the union — without this, only the app's\n * own files would be scanned and every UI-package atom would resolve\n * to `undefined` at runtime.\n * @param projectRoot Absolute project root.\n * @param cacheDir Absolute rnwind cache dir (to exclude).\n * @param watchFolders Extra monorepo roots Metro is watching.\n * @returns Scanner sources suitable for `parser.parseProject()`.\n */\nfunction defaultSources(projectRoot: string, cacheDir: string, watchFolders: readonly string[]): readonly SourceEntry[] {\n const cacheBaseName = path.basename(cacheDir)\n const roots = new Set<string>([projectRoot, ...watchFolders])\n const sources: SourceEntry[] = []\n for (const root of roots) {\n sources.push({ base: root, pattern: '**/*.{ts,tsx,js,jsx}', negated: false }, { base: root, pattern: '**/node_modules/**', negated: true }, { base: root, pattern: `**/${cacheBaseName}/**`, negated: true })\n }\n return sources\n}\n\n/**\n * Read monorepo watch-folder paths out of the worker environment.\n * Empty array when the host isn't a monorepo.\n * @returns Absolute paths Metro also watches (sibling packages).\n */\nfunction readWatchFolders(): readonly string[] {\n const raw = process.env[WATCH_FOLDERS_ENV]\n if (!raw || raw.length === 0) return []\n return raw.split('\\0').filter((entry) => entry.length > 0)\n}\n\n/** Env var Metro workers read to locate the theme CSS on disk. */\nconst CSS_ENTRY_ENV = 'RNWIND_CSS_ENTRY_FILE'\n/** Env var Metro workers read to locate the cache directory (`.rnwind`). */\nconst CACHE_DIR_ENV = 'RNWIND_CACHE_DIR'\n/** Env var carrying `watchFolders` from Metro config (NUL-separated). */\nconst WATCH_FOLDERS_ENV = 'RNWIND_WATCH_FOLDERS'\n/** Env var carrying extra className prefixes the Metro config supplied. */\nconst CLASSNAME_PREFIXES_ENV = 'RNWIND_CLASSNAME_PREFIXES'\n/** Env var carrying extra import sources whose JSX exports get className→style rewrites. Comma-separated. */\nconst HOST_SOURCES_ENV = 'RNWIND_HOST_SOURCES'\n/** Env var carrying extra JSX tag names (verbatim, may contain `.`) treated as hosts. Comma-separated. */\nconst HOST_COMPONENTS_ENV = 'RNWIND_HOST_COMPONENTS'\n\n/** Memoised library fingerprint — read once per worker process. */\nlet libraryFingerprint: string | undefined\n\n/** Live state shared across one Metro transform worker. */\nlet cached: RnwindState | null = null\n\n/**\n * Cheap content-hash readout. SHA-256 prefix of the CSS bytes plus the\n * file's mtime nanoseconds (so identical content with different mtime\n * — atomic rewrites — still picks up the change). Returns `'missing'`\n * when the file can't be read so the cache key is still deterministic.\n * @param cssPath Absolute CSS path.\n * @returns 16-char hex content hash.\n */\nfunction readThemeHashFor(cssPath: string): string {\n if (!existsSync(cssPath)) return 'missing'\n try {\n const bytes = readFileSync(cssPath)\n const mtime = statSync(cssPath).mtimeMs.toString()\n return createHash('sha256').update(bytes).update(mtime).digest('hex').slice(0, 16)\n } catch {\n return 'missing'\n }\n}\n\n/**\n * Hash a small set of rnwind library files whose changes affect the\n * generated transform output. When the library is rebuilt (workspace\n * dev OR npm install of a new version) the file bytes change, the\n * fingerprint rotates, and Metro's transform cache invalidates.\n *\n * Includes the JSX rewriter (`transform-ast`) alongside the parser /\n * style-builder so a change to the transformer — e.g. renaming the\n * injected context hook — invalidates every stale per-file cache entry\n * on the next dev run. Without this, a user upgrading rnwind in-place\n * would keep loading the old transformed bytes; React-refresh would\n * then preserve fiber state across the version bump and the rendered\n * hook list could shift, surfacing as \"change in the order of Hooks\"\n * runtime errors.\n * Memoised — read once per worker process.\n * @returns 16-char hex fingerprint.\n */\nfunction getLibraryFingerprint(): string {\n if (libraryFingerprint !== undefined) return libraryFingerprint\n const here = path.dirname(__filename)\n const candidates = [\n path.resolve(here, '..', 'core', 'style-builder', 'build-style.mjs'),\n path.resolve(here, '..', 'core', 'style-builder', 'build-style.cjs'),\n path.resolve(here, '..', 'core', 'parser', 'tw-parser.mjs'),\n path.resolve(here, '..', 'core', 'parser', 'tw-parser.cjs'),\n path.resolve(here, 'transform-ast.mjs'),\n path.resolve(here, 'transform-ast.cjs'),\n path.resolve(here, 'transformer.mjs'),\n path.resolve(here, 'transformer.cjs'),\n // Source-tree fallback for tests + workspace dev (no built lib yet).\n path.resolve(here, '..', '..', 'src', 'core', 'style-builder', 'build-style.ts'),\n path.resolve(here, '..', '..', 'src', 'core', 'parser', 'tw-parser.ts'),\n path.resolve(here, '..', '..', 'src', 'metro', 'transform-ast.ts'),\n path.resolve(here, '..', '..', 'src', 'metro', 'transformer.ts'),\n ]\n const hash = createHash('sha256')\n let included = 0\n for (const file of candidates) {\n if (!existsSync(file)) continue\n try {\n hash.update(readFileSync(file))\n included += 1\n } catch {\n // Unreadable file — skip; fingerprint still derives from whatever WE could read.\n }\n }\n libraryFingerprint = included > 0 ? hash.digest('hex').slice(0, 16) : '0'.repeat(16)\n return libraryFingerprint\n}\n\n/**\n * Worker-local state. Lazy-initialised on first access so files that\n * bypass the transform don't pay for construction.\n */\nexport interface RnwindState {\n parser: TailwindParser\n builder: UnionBuilder\n themeCss: string\n themeHash: string\n projectRoot: string\n}\n\n/**\n * Publish the theme CSS path + cache dir to the environment so worker\n * subprocesses (spawned by Metro once `babelTransformerPath` is set)\n * can rebuild the same state without re-reading the Metro config.\n * @param cssEntryFile Absolute path to the user's theme CSS.\n * @param cacheDir Absolute path to the cache dir (`.rnwind`).\n * @param watchFolders\n * @param classNamePrefixes Extra JSX prop-name prefixes to rewrite.\n * @param hostSources\n * @param hostComponents\n */\nexport function configureRnwindState(\n cssEntryFile: string,\n cacheDir: string,\n watchFolders: readonly string[] = [],\n classNamePrefixes?: readonly string[],\n hostSources?: readonly string[],\n hostComponents?: readonly string[],\n): void {\n process.env[CSS_ENTRY_ENV] = cssEntryFile\n process.env[CACHE_DIR_ENV] = cacheDir\n if (watchFolders.length === 0) {\n delete process.env[WATCH_FOLDERS_ENV]\n } else {\n process.env[WATCH_FOLDERS_ENV] = watchFolders.join('\\0')\n }\n if (!classNamePrefixes || classNamePrefixes.length === 0) {\n delete process.env[CLASSNAME_PREFIXES_ENV]\n } else {\n process.env[CLASSNAME_PREFIXES_ENV] = classNamePrefixes.join(',')\n }\n if (!hostSources || hostSources.length === 0) {\n delete process.env[HOST_SOURCES_ENV]\n } else {\n process.env[HOST_SOURCES_ENV] = hostSources.join(',')\n }\n if (!hostComponents || hostComponents.length === 0) {\n delete process.env[HOST_COMPONENTS_ENV]\n } else {\n process.env[HOST_COMPONENTS_ENV] = hostComponents.join(',')\n }\n cached = null\n}\n\n/**\n * Read the caller-configured extra className prefixes out of the\n * worker environment. Returns an empty array when unset — the\n * transformer applies the built-in `contentContainer` default on top\n * either way.\n * @returns User-supplied extra prefixes.\n */\nexport function getClassNamePrefixes(): readonly string[] {\n const raw = process.env[CLASSNAME_PREFIXES_ENV]\n if (!raw || raw.length === 0) return []\n return raw.split(',').filter((entry) => entry.length > 0)\n}\n\n/**\n * Read the caller-configured extra host module sources out of the\n * worker environment. Empty array when unset — the transformer applies\n * its built-in default list on top either way.\n * @returns User-supplied extra host sources.\n */\nexport function getHostSources(): readonly string[] {\n const raw = process.env[HOST_SOURCES_ENV]\n if (!raw || raw.length === 0) return []\n return raw.split(',').filter((entry) => entry.length > 0)\n}\n\n/**\n * Read the caller-configured extra host JSX tag names out of the worker\n * environment. Verbatim names — may include `.` for member expressions\n * like `'Animated.View'`.\n * @returns User-supplied extra host component names.\n */\nexport function getHostComponents(): readonly string[] {\n const raw = process.env[HOST_COMPONENTS_ENV]\n if (!raw || raw.length === 0) return []\n return raw.split(',').filter((entry) => entry.length > 0)\n}\n\n/**\n * Fetch (or build) the worker-local rnwind state. Re-reads the theme\n * CSS hash on every call: if the user edited `global.css` while Metro\n * is running, the cached state is dropped and a fresh parser + ledger\n * is built. Combined with the `getCacheKey()` export on the\n * transformer (which folds the same hash into Metro's per-file cache\n * key) every CSS edit produces a full, correct re-bundle.\n * @param projectRoot\n * @returns The live rnwind state.\n */\nexport function getRnwindState(projectRoot: string): RnwindState {\n const cssEntry = process.env[CSS_ENTRY_ENV]\n const cacheDir = process.env[CACHE_DIR_ENV]\n if (!cssEntry) throw new Error('rnwind: RNWIND_CSS_ENTRY_FILE is not set — did `withRnwindConfig` run?')\n if (!cacheDir) throw new Error('rnwind: RNWIND_CACHE_DIR is not set — did `withRnwindConfig` run?')\n const currentHash = readThemeHashFor(cssEntry)\n if (cached?.themeHash === currentHash && cached.projectRoot === projectRoot) return cached\n const themeCss = readFileSync(cssEntry, 'utf8')\n const parser = new TailwindParser({\n themeCss,\n sources: defaultSources(projectRoot, cacheDir, readWatchFolders()),\n })\n const builder = new UnionBuilder(cacheDir, parser)\n cached = { parser, builder, themeCss, themeHash: currentHash, projectRoot }\n return cached\n}\n\n/**\n * Compute the rnwind cache-key suffix Metro mixes into every per-file\n * transform cache entry via the transformer's `getCacheKey()` export.\n * Includes the CSS path + its current content hash + the rnwind\n * library fingerprint, so any edit to `global.css` OR a library\n * upgrade flips the cache key and forces Metro to re-run the\n * transformer.\n * @returns Deterministic string suitable for appending to Metro's cache key.\n */\nexport function getRnwindCacheKey(): string {\n const cssEntry = process.env[CSS_ENTRY_ENV] ?? ''\n const prefixes = process.env[CLASSNAME_PREFIXES_ENV] ?? ''\n // Host source / component config changes which JSX tags get rewritten,\n // so it MUST flip the cache key — otherwise Metro replays stale\n // transforms (a newly-opted-in host keeps its raw className, a removed\n // one keeps the rewrite).\n const hostSources = process.env[HOST_SOURCES_ENV] ?? ''\n const hostComponents = process.env[HOST_COMPONENTS_ENV] ?? ''\n return `rnwind:${cssEntry}:${readThemeHashFor(cssEntry)}|lib:${getLibraryFingerprint()}|pfx:${prefixes}|hs:${hostSources}|hc:${hostComponents}`\n}\n\n/** Drop the cached state — call after editing the theme CSS. */\nexport function resetRnwindState(): void {\n cached = null\n}\n\n/**\n * Drop cached state, rebuild parser/builder with the fresh CSS, rescan\n * the project, and rewrite every scheme file on disk. This is what\n * `withRnwindConfig`'s CSS file-watcher invokes so `global.css` edits\n * propagate to the app via Metro's HMR — without this, the CSS-as-JS\n * module would re-emit `export {}` whose bytes never change, so Metro\n * would never invalidate downstream modules.\n * @param projectRoot Absolute project root (from `metroConfig.projectRoot`).\n */\nexport async function onThemeChange(projectRoot: string): Promise<void> {\n resetRnwindState()\n const state = getRnwindState(projectRoot)\n await state.builder.writeSchemes()\n}\n\n/**\n * Resolve the on-disk path of the scheme manifest module for the\n * resolver. The manifest eager-imports `common.style.js` and\n * lazy-requires each variant scheme; SchemeProvider calls its\n * `ensureSchemeLoaded` export to trigger per-scheme requires.\n * @returns Absolute path to `<cacheDir>/schemes.js`.\n */\nexport function manifestPathFor(): string {\n const cacheDir = process.env[CACHE_DIR_ENV]\n if (!cacheDir) throw new Error('rnwind: RNWIND_CACHE_DIR is not set')\n return path.join(cacheDir, 'schemes.js')\n}\n"],"names":["existsSync","readFileSync","statSync","createHash","TailwindParser","UnionBuilder"],"mappings":";;;;;;;;AAMA;;;;;;;;;;;;;;;;AAgBG;AACH,SAAS,cAAc,CAAC,WAAmB,EAAE,QAAgB,EAAE,YAA+B,EAAA;IAC5F,MAAM,a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c,CAAC,WAAW,CAAC;AACzC,IAAA,MAAM,KAAK,CAAC,OAAO,CAAC,YAAY,EAAE;AACpC;AAEA;;;;;;AAMG;SACa,eAAe,GAAA;IAC7B,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC;AAC3C,IAAA,IAAI,CAAC,QAAQ;AAAE,QAAA,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC;IACrE,OAAO,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,YAAY,CAAC;AAC1C;;;;;;;;;;;;"}
1
+ {"version":3,"file":"state.cjs","sources":["../../../../src/metro/state.ts"],"sourcesContent":["import { existsSync, readFileSync } from 'node:fs'\nimport path from 'node:path'\nimport { createHash } from 'node:crypto'\nimport { UnionBuilder } from '../core/style-builder'\nimport { TailwindParser, type SourceEntry } from '../core/parser'\nimport { resolveThemeCss } from './css-imports'\n\n/**\n * Default oxide Scanner globs — walk every JS/TS source under the\n * project root AND every monorepo watch folder, excluding\n * `node_modules` and rnwind's own cache dir so we don't rescan\n * generated scheme files.\n *\n * Monorepo layouts (Yarn workspaces, pnpm workspaces, Nx) surface\n * sibling package roots as `metroConfig.watchFolders`. Every folder\n * Metro watches must also be scanned so atoms declared in shared UI\n * packages make it into the union — without this, only the app's\n * own files would be scanned and every UI-package atom would resolve\n * to `undefined` at runtime.\n * @param projectRoot Absolute project root.\n * @param cacheDir Absolute rnwind cache dir (to exclude).\n * @param watchFolders Extra monorepo roots Metro is watching.\n * @returns Scanner sources suitable for `parser.parseProject()`.\n */\nfunction defaultSources(projectRoot: string, cacheDir: string, watchFolders: readonly string[]): readonly SourceEntry[] {\n const cacheBaseName = path.basename(cacheDir)\n const roots = new Set<string>([projectRoot, ...watchFolders])\n const sources: SourceEntry[] = []\n for (const root of roots) {\n sources.push({ base: root, pattern: '**/*.{ts,tsx,js,jsx}', negated: false }, { base: root, pattern: '**/node_modules/**', negated: true }, { base: root, pattern: `**/${cacheBaseName}/**`, negated: true })\n }\n return sources\n}\n\n/**\n * Read monorepo watch-folder paths out of the worker environment.\n * Empty array when the host isn't a monorepo.\n * @returns Absolute paths Metro also watches (sibling packages).\n */\nfunction readWatchFolders(): readonly string[] {\n const raw = process.env[WATCH_FOLDERS_ENV]\n if (!raw || raw.length === 0) return []\n return raw.split('\\0').filter((entry) => entry.length > 0)\n}\n\n/** Env var Metro workers read to locate the theme CSS on disk. */\nconst CSS_ENTRY_ENV = 'RNWIND_CSS_ENTRY_FILE'\n/** Env var Metro workers read to locate the cache directory (`.rnwind`). */\nconst CACHE_DIR_ENV = 'RNWIND_CACHE_DIR'\n/** Env var carrying `watchFolders` from Metro config (NUL-separated). */\nconst WATCH_FOLDERS_ENV = 'RNWIND_WATCH_FOLDERS'\n/** Env var carrying extra className prefixes the Metro config supplied. */\nconst CLASSNAME_PREFIXES_ENV = 'RNWIND_CLASSNAME_PREFIXES'\n/** Env var carrying extra import sources whose JSX exports get className→style rewrites. Comma-separated. */\nconst HOST_SOURCES_ENV = 'RNWIND_HOST_SOURCES'\n/** Env var carrying extra JSX tag names (verbatim, may contain `.`) treated as hosts. Comma-separated. */\nconst HOST_COMPONENTS_ENV = 'RNWIND_HOST_COMPONENTS'\n\n/** Memoised library fingerprint — read once per worker process. */\nlet libraryFingerprint: string | undefined\n\n/** Live state shared across one Metro transform worker. */\nlet cached: RnwindState | null = null\n\n/**\n * Cheap content-hash readout. SHA-256 prefix of the FULLY-RESOLVED theme\n * CSS — `@import`s flattened — so an edit to a theme file the entry only\n * re-exports (`@import \"@acme/ui/theme.css\"`) still rotates the hash and\n * invalidates Metro's cache. Returns `'missing'` when the entry can't be\n * read so the cache key stays deterministic.\n * @param cssPath Absolute CSS path.\n * @returns 16-char hex content hash.\n */\nfunction readThemeHashFor(cssPath: string): string {\n if (!existsSync(cssPath)) return 'missing'\n try {\n return createHash('sha256').update(resolveThemeCss(cssPath)).digest('hex').slice(0, 16)\n } catch {\n return 'missing'\n }\n}\n\n/**\n * Hash a small set of rnwind library files whose changes affect the\n * generated transform output. When the library is rebuilt (workspace\n * dev OR npm install of a new version) the file bytes change, the\n * fingerprint rotates, and Metro's transform cache invalidates.\n *\n * Includes the JSX rewriter (`transform-ast`) alongside the parser /\n * style-builder so a change to the transformer — e.g. renaming the\n * injected context hook — invalidates every stale per-file cache entry\n * on the next dev run. Without this, a user upgrading rnwind in-place\n * would keep loading the old transformed bytes; React-refresh would\n * then preserve fiber state across the version bump and the rendered\n * hook list could shift, surfacing as \"change in the order of Hooks\"\n * runtime errors.\n * Memoised — read once per worker process.\n * @returns 16-char hex fingerprint.\n */\nfunction getLibraryFingerprint(): string {\n if (libraryFingerprint !== undefined) return libraryFingerprint\n const here = path.dirname(__filename)\n const candidates = [\n path.resolve(here, '..', 'core', 'style-builder', 'build-style.mjs'),\n path.resolve(here, '..', 'core', 'style-builder', 'build-style.cjs'),\n path.resolve(here, '..', 'core', 'parser', 'tw-parser.mjs'),\n path.resolve(here, '..', 'core', 'parser', 'tw-parser.cjs'),\n path.resolve(here, 'transform-ast.mjs'),\n path.resolve(here, 'transform-ast.cjs'),\n path.resolve(here, 'transformer.mjs'),\n path.resolve(here, 'transformer.cjs'),\n // Source-tree fallback for tests + workspace dev (no built lib yet).\n path.resolve(here, '..', '..', 'src', 'core', 'style-builder', 'build-style.ts'),\n path.resolve(here, '..', '..', 'src', 'core', 'parser', 'tw-parser.ts'),\n path.resolve(here, '..', '..', 'src', 'metro', 'transform-ast.ts'),\n path.resolve(here, '..', '..', 'src', 'metro', 'transformer.ts'),\n ]\n const hash = createHash('sha256')\n let included = 0\n for (const file of candidates) {\n if (!existsSync(file)) continue\n try {\n hash.update(readFileSync(file))\n included += 1\n } catch {\n // Unreadable file — skip; fingerprint still derives from whatever WE could read.\n }\n }\n libraryFingerprint = included > 0 ? hash.digest('hex').slice(0, 16) : '0'.repeat(16)\n return libraryFingerprint\n}\n\n/**\n * Worker-local state. Lazy-initialised on first access so files that\n * bypass the transform don't pay for construction.\n */\nexport interface RnwindState {\n parser: TailwindParser\n builder: UnionBuilder\n themeCss: string\n themeHash: string\n projectRoot: string\n}\n\n/**\n * Publish the theme CSS path + cache dir to the environment so worker\n * subprocesses (spawned by Metro once `babelTransformerPath` is set)\n * can rebuild the same state without re-reading the Metro config.\n * @param cssEntryFile Absolute path to the user's theme CSS.\n * @param cacheDir Absolute path to the cache dir (`.rnwind`).\n * @param watchFolders\n * @param classNamePrefixes Extra JSX prop-name prefixes to rewrite.\n * @param hostSources\n * @param hostComponents\n */\nexport function configureRnwindState(\n cssEntryFile: string,\n cacheDir: string,\n watchFolders: readonly string[] = [],\n classNamePrefixes?: readonly string[],\n hostSources?: readonly string[],\n hostComponents?: readonly string[],\n): void {\n process.env[CSS_ENTRY_ENV] = cssEntryFile\n process.env[CACHE_DIR_ENV] = cacheDir\n if (watchFolders.length === 0) {\n delete process.env[WATCH_FOLDERS_ENV]\n } else {\n process.env[WATCH_FOLDERS_ENV] = watchFolders.join('\\0')\n }\n if (!classNamePrefixes || classNamePrefixes.length === 0) {\n delete process.env[CLASSNAME_PREFIXES_ENV]\n } else {\n process.env[CLASSNAME_PREFIXES_ENV] = classNamePrefixes.join(',')\n }\n if (!hostSources || hostSources.length === 0) {\n delete process.env[HOST_SOURCES_ENV]\n } else {\n process.env[HOST_SOURCES_ENV] = hostSources.join(',')\n }\n if (!hostComponents || hostComponents.length === 0) {\n delete process.env[HOST_COMPONENTS_ENV]\n } else {\n process.env[HOST_COMPONENTS_ENV] = hostComponents.join(',')\n }\n cached = null\n}\n\n/**\n * Read the caller-configured extra className prefixes out of the\n * worker environment. Returns an empty array when unset — the\n * transformer applies the built-in `contentContainer` default on top\n * either way.\n * @returns User-supplied extra prefixes.\n */\nexport function getClassNamePrefixes(): readonly string[] {\n const raw = process.env[CLASSNAME_PREFIXES_ENV]\n if (!raw || raw.length === 0) return []\n return raw.split(',').filter((entry) => entry.length > 0)\n}\n\n/**\n * Read the caller-configured extra host module sources out of the\n * worker environment. Empty array when unset — the transformer applies\n * its built-in default list on top either way.\n * @returns User-supplied extra host sources.\n */\nexport function getHostSources(): readonly string[] {\n const raw = process.env[HOST_SOURCES_ENV]\n if (!raw || raw.length === 0) return []\n return raw.split(',').filter((entry) => entry.length > 0)\n}\n\n/**\n * Read the caller-configured extra host JSX tag names out of the worker\n * environment. Verbatim names — may include `.` for member expressions\n * like `'Animated.View'`.\n * @returns User-supplied extra host component names.\n */\nexport function getHostComponents(): readonly string[] {\n const raw = process.env[HOST_COMPONENTS_ENV]\n if (!raw || raw.length === 0) return []\n return raw.split(',').filter((entry) => entry.length > 0)\n}\n\n/**\n * Fetch (or build) the worker-local rnwind state. Re-reads the theme\n * CSS hash on every call: if the user edited `global.css` while Metro\n * is running, the cached state is dropped and a fresh parser + ledger\n * is built. Combined with the `getCacheKey()` export on the\n * transformer (which folds the same hash into Metro's per-file cache\n * key) every CSS edit produces a full, correct re-bundle.\n * @param projectRoot\n * @returns The live rnwind state.\n */\nexport function getRnwindState(projectRoot: string): RnwindState {\n const cssEntry = process.env[CSS_ENTRY_ENV]\n const cacheDir = process.env[CACHE_DIR_ENV]\n if (!cssEntry) throw new Error('rnwind: RNWIND_CSS_ENTRY_FILE is not set — did `withRnwindConfig` run?')\n if (!cacheDir) throw new Error('rnwind: RNWIND_CACHE_DIR is not set — did `withRnwindConfig` run?')\n const currentHash = readThemeHashFor(cssEntry)\n if (cached?.themeHash === currentHash && cached.projectRoot === projectRoot) return cached\n const themeCss = resolveThemeCss(cssEntry)\n const parser = new TailwindParser({\n themeCss,\n sources: defaultSources(projectRoot, cacheDir, readWatchFolders()),\n })\n const builder = new UnionBuilder(cacheDir, parser)\n cached = { parser, builder, themeCss, themeHash: currentHash, projectRoot }\n return cached\n}\n\n/**\n * Compute the rnwind cache-key suffix Metro mixes into every per-file\n * transform cache entry via the transformer's `getCacheKey()` export.\n * Includes the CSS path + its current content hash + the rnwind\n * library fingerprint, so any edit to `global.css` OR a library\n * upgrade flips the cache key and forces Metro to re-run the\n * transformer.\n * @returns Deterministic string suitable for appending to Metro's cache key.\n */\nexport function getRnwindCacheKey(): string {\n const cssEntry = process.env[CSS_ENTRY_ENV] ?? ''\n const prefixes = process.env[CLASSNAME_PREFIXES_ENV] ?? ''\n // Host source / component config changes which JSX tags get rewritten,\n // so it MUST flip the cache key — otherwise Metro replays stale\n // transforms (a newly-opted-in host keeps its raw className, a removed\n // one keeps the rewrite).\n const hostSources = process.env[HOST_SOURCES_ENV] ?? ''\n const hostComponents = process.env[HOST_COMPONENTS_ENV] ?? ''\n return `rnwind:${cssEntry}:${readThemeHashFor(cssEntry)}|lib:${getLibraryFingerprint()}|pfx:${prefixes}|hs:${hostSources}|hc:${hostComponents}`\n}\n\n/** Drop the cached state — call after editing the theme CSS. */\nexport function resetRnwindState(): void {\n cached = null\n}\n\n/**\n * Drop cached state, rebuild parser/builder with the fresh CSS, rescan\n * the project, and rewrite every scheme file on disk. This is what\n * `withRnwindConfig`'s CSS file-watcher invokes so `global.css` edits\n * propagate to the app via Metro's HMR — without this, the CSS-as-JS\n * module would re-emit `export {}` whose bytes never change, so Metro\n * would never invalidate downstream modules.\n * @param projectRoot Absolute project root (from `metroConfig.projectRoot`).\n */\nexport async function onThemeChange(projectRoot: string): Promise<void> {\n resetRnwindState()\n const state = getRnwindState(projectRoot)\n await state.builder.writeSchemes()\n}\n\n/**\n * Resolve the on-disk path of the scheme manifest module for the\n * resolver. The manifest eager-imports `common.style.js` and\n * lazy-requires each variant scheme; SchemeProvider calls its\n * `ensureSchemeLoaded` export to trigger per-scheme requires.\n * @returns Absolute path to `<cacheDir>/schemes.js`.\n */\nexport function manifestPathFor(): string {\n const cacheDir = process.env[CACHE_DIR_ENV]\n if (!cacheDir) throw new Error('rnwind: RNWIND_CACHE_DIR is not set')\n return path.join(cacheDir, 'schemes.js')\n}\n"],"names":["existsSync","createHash","resolveThemeCss","readFileSync","TailwindParser","UnionBuilder"],"mappings":";;;;;;;;;AAOA;;;;;;;;;;;;;;;;AAgBG;AACH,SAAS,cAAc,C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G;SACa,eAAe,GAAA;IAC7B,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC;AAC3C,IAAA,IAAI,CAAC,QAAQ;AAAE,QAAA,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC;IACrE,OAAO,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,YAAY,CAAC;AAC1C;;;;;;;;;;;;"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Flatten user `@import`s in a theme entry CSS file so rnwind's text-based
3
+ * scheme extractors see the real `@theme` / `@variant` / `@custom-variant`
4
+ * declarations even when the entry only re-exports them via `@import`.
5
+ * @param entryFilePath Absolute path to the theme entry CSS (the cssEntryFile).
6
+ * @returns Inlined CSS, or `''` when the entry can't be read.
7
+ */
8
+ export declare function resolveThemeCss(entryFilePath: string): string;
@@ -0,0 +1,79 @@
1
+ import { createRequire } from 'node:module';
2
+ import { readFileSync, existsSync } from 'node:fs';
3
+
4
+ /**
5
+ * Inline `@import` resolution for the theme entry CSS.
6
+ *
7
+ * rnwind's scheme extractors (`extractThemeVars`, `extractSchemeAliases`,
8
+ * `extractCustomVariantSchemes`) are plain text passes over the entry
9
+ * CSS — they don't follow `@import`. Tailwind's own compiler DOES follow
10
+ * imports, so utilities still compile, but a user who keeps their theme
11
+ * in a separate file and points the entry at it:
12
+ *
13
+ * ```css
14
+ * @import "@acme/ui/theme.css"; // global.css — the cssEntryFile
15
+ * ```
16
+ *
17
+ * would hand the extractors a file with no `@theme` / `@variant` /
18
+ * `@custom-variant` in sight → every scheme collapses to base and theme
19
+ * switching dies. This module flattens those user imports first so the
20
+ * extractors (and the compiler) see the real declarations.
21
+ */
22
+ /** Matches a bare `@import "spec";` / `@import 'spec';` (no media/layer suffix). */
23
+ const CSS_IMPORT = /@import\s+(["'])([^"']+)\1\s*;/g;
24
+ /**
25
+ * Specs left untouched for the Tailwind compiler to resolve itself.
26
+ * `tailwindcss` resolves to JS (not inlinable) and `rnwind/css` is the
27
+ * framework preset — both are the compiler's job, not user theme files.
28
+ */
29
+ const FRAMEWORK_SPECS = new Set(['tailwindcss', 'rnwind/css', 'rnwind']);
30
+ /**
31
+ * Read `filePath` and replace each user `@import "<spec>";` whose spec
32
+ * resolves (Node resolution, honouring `exports` maps and workspace
33
+ * symlinks) to a readable `.css` file with that file's inlined +
34
+ * recursively-resolved contents. Unresolvable specs, non-CSS targets,
35
+ * and {@link FRAMEWORK_SPECS} are left as-is for the compiler.
36
+ * @param filePath Absolute path of the CSS file being inlined.
37
+ * @param seen Visited set guarding against import cycles.
38
+ * @returns CSS text with user imports flattened in place.
39
+ */
40
+ function inlineImports(filePath, seen) {
41
+ if (seen.has(filePath))
42
+ return '';
43
+ seen.add(filePath);
44
+ let css;
45
+ try {
46
+ css = readFileSync(filePath, 'utf8');
47
+ }
48
+ catch {
49
+ return '';
50
+ }
51
+ const request = createRequire(filePath);
52
+ return css.replaceAll(CSS_IMPORT, (full, _quote, spec) => {
53
+ if (FRAMEWORK_SPECS.has(spec))
54
+ return full;
55
+ let resolved;
56
+ try {
57
+ resolved = request.resolve(spec);
58
+ }
59
+ catch {
60
+ return full;
61
+ }
62
+ if (!resolved.endsWith('.css') || !existsSync(resolved))
63
+ return full;
64
+ return inlineImports(resolved, seen);
65
+ });
66
+ }
67
+ /**
68
+ * Flatten user `@import`s in a theme entry CSS file so rnwind's text-based
69
+ * scheme extractors see the real `@theme` / `@variant` / `@custom-variant`
70
+ * declarations even when the entry only re-exports them via `@import`.
71
+ * @param entryFilePath Absolute path to the theme entry CSS (the cssEntryFile).
72
+ * @returns Inlined CSS, or `''` when the entry can't be read.
73
+ */
74
+ function resolveThemeCss(entryFilePath) {
75
+ return inlineImports(entryFilePath, new Set());
76
+ }
77
+
78
+ export { resolveThemeCss };
79
+ //# sourceMappingURL=css-imports.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"css-imports.mjs","sources":["../../../../src/metro/css-imports.ts"],"sourcesContent":["import { createRequire } from 'node:module'\nimport { existsSync, readFileSync } from 'node:fs'\n\n/**\n * Inline `@import` resolution for the theme entry CSS.\n *\n * rnwind's scheme extractors (`extractThemeVars`, `extractSchemeAliases`,\n * `extractCustomVariantSchemes`) are plain text passes over the entry\n * CSS — they don't follow `@import`. Tailwind's own compiler DOES follow\n * imports, so utilities still compile, but a user who keeps their theme\n * in a separate file and points the entry at it:\n *\n * ```css\n * @import \"@acme/ui/theme.css\"; // global.css — the cssEntryFile\n * ```\n *\n * would hand the extractors a file with no `@theme` / `@variant` /\n * `@custom-variant` in sight → every scheme collapses to base and theme\n * switching dies. This module flattens those user imports first so the\n * extractors (and the compiler) see the real declarations.\n */\n\n/** Matches a bare `@import \"spec\";` / `@import 'spec';` (no media/layer suffix). */\nconst CSS_IMPORT = /@import\\s+([\"'])([^\"']+)\\1\\s*;/g\n\n/**\n * Specs left untouched for the Tailwind compiler to resolve itself.\n * `tailwindcss` resolves to JS (not inlinable) and `rnwind/css` is the\n * framework preset — both are the compiler's job, not user theme files.\n */\nconst FRAMEWORK_SPECS = new Set(['tailwindcss', 'rnwind/css', 'rnwind'])\n\n/**\n * Read `filePath` and replace each user `@import \"<spec>\";` whose spec\n * resolves (Node resolution, honouring `exports` maps and workspace\n * symlinks) to a readable `.css` file with that file's inlined +\n * recursively-resolved contents. Unresolvable specs, non-CSS targets,\n * and {@link FRAMEWORK_SPECS} are left as-is for the compiler.\n * @param filePath Absolute path of the CSS file being inlined.\n * @param seen Visited set guarding against import cycles.\n * @returns CSS text with user imports flattened in place.\n */\nfunction inlineImports(filePath: string, seen: Set<string>): string {\n if (seen.has(filePath)) return ''\n seen.add(filePath)\n let css: string\n try {\n css = readFileSync(filePath, 'utf8')\n } catch {\n return ''\n }\n const request = createRequire(filePath)\n return css.replaceAll(CSS_IMPORT, (full: string, _quote: string, spec: string): string => {\n if (FRAMEWORK_SPECS.has(spec)) return full\n let resolved: string\n try {\n resolved = request.resolve(spec)\n } catch {\n return full\n }\n if (!resolved.endsWith('.css') || !existsSync(resolved)) return full\n return inlineImports(resolved, seen)\n })\n}\n\n/**\n * Flatten user `@import`s in a theme entry CSS file so rnwind's text-based\n * scheme extractors see the real `@theme` / `@variant` / `@custom-variant`\n * declarations even when the entry only re-exports them via `@import`.\n * @param entryFilePath Absolute path to the theme entry CSS (the cssEntryFile).\n * @returns Inlined CSS, or `''` when the entry can't be read.\n */\nexport function resolveThemeCss(entryFilePath: string): string {\n return inlineImports(entryFilePath, new Set<string>())\n}\n"],"names":[],"mappings":";;;AAGA;;;;;;;;;;;;;;;;;AAiBG;AAEH;AACA,MAAM,UAAU,GAAG,iCAAiC;AAEpD;;;;AAIG;AACH,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC,CAAC,aAAa,EAAE,YAAY,EAAE,QAAQ,CAAC,CAAC;AAExE;;;;;;;;;AASG;AACH,SAAS,aAAa,CAAC,QAAgB,EAAE,IAAiB,EAAA;AACxD,IAAA,IAAI,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC;AAAE,QAAA,OAAO,EAAE;AACjC,IAAA,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC;AAClB,IAAA,IAAI,GAAW;AACf,IAAA,IAAI;AACF,QAAA,GAAG,GAAG,YAAY,CAAC,QAAQ,EAAE,MAAM,CAAC;IACtC;AAAE,IAAA,MAAM;AACN,QAAA,OAAO,EAAE;IACX;AACA,IAAA,MAAM,OAAO,GAAG,aAAa,CAAC,QAAQ,CAAC;AACvC,IAAA,OAAO,GAAG,CAAC,UAAU,CAAC,UAAU,EAAE,CAAC,IAAY,EAAE,MAAc,EAAE,IAAY,KAAY;AACvF,QAAA,IAAI,eAAe,CAAC,GAAG,CAAC,IAAI,CAAC;AAAE,YAAA,OAAO,IAAI;AAC1C,QAAA,IAAI,QAAgB;AACpB,QAAA,IAAI;AACF,YAAA,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC;QAClC;AAAE,QAAA,MAAM;AACN,YAAA,OAAO,IAAI;QACb;AACA,QAAA,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC;AAAE,YAAA,OAAO,IAAI;AACpE,QAAA,OAAO,aAAa,CAAC,QAAQ,EAAE,IAAI,CAAC;AACtC,IAAA,CAAC,CAAC;AACJ;AAEA;;;;;;AAMG;AACG,SAAU,eAAe,CAAC,aAAqB,EAAA;IACnD,OAAO,aAAa,CAAC,aAAa,EAAE,IAAI,GAAG,EAAU,CAAC;AACxD;;;;"}
@@ -1,8 +1,9 @@
1
- import { readFileSync, existsSync, statSync } from 'node:fs';
1
+ import { existsSync, readFileSync } from 'node:fs';
2
2
  import path from 'node:path';
3
3
  import { createHash } from 'node:crypto';
4
4
  import { UnionBuilder } from '../core/style-builder/union-builder.mjs';
5
5
  import { TailwindParser } from '../core/parser/tw-parser.mjs';
6
+ import { resolveThemeCss } from './css-imports.mjs';
6
7
 
7
8
  /**
8
9
  * Default oxide Scanner globs — walk every JS/TS source under the
@@ -58,10 +59,11 @@ let libraryFingerprint;
58
59
  /** Live state shared across one Metro transform worker. */
59
60
  let cached = null;
60
61
  /**
61
- * Cheap content-hash readout. SHA-256 prefix of the CSS bytes plus the
62
- * file's mtime nanoseconds (so identical content with different mtime
63
- * atomic rewrites still picks up the change). Returns `'missing'`
64
- * when the file can't be read so the cache key is still deterministic.
62
+ * Cheap content-hash readout. SHA-256 prefix of the FULLY-RESOLVED theme
63
+ * CSS — `@import`s flattened so an edit to a theme file the entry only
64
+ * re-exports (`@import "@acme/ui/theme.css"`) still rotates the hash and
65
+ * invalidates Metro's cache. Returns `'missing'` when the entry can't be
66
+ * read so the cache key stays deterministic.
65
67
  * @param cssPath Absolute CSS path.
66
68
  * @returns 16-char hex content hash.
67
69
  */
@@ -69,9 +71,7 @@ function readThemeHashFor(cssPath) {
69
71
  if (!existsSync(cssPath))
70
72
  return 'missing';
71
73
  try {
72
- const bytes = readFileSync(cssPath);
73
- const mtime = statSync(cssPath).mtimeMs.toString();
74
- return createHash('sha256').update(bytes).update(mtime).digest('hex').slice(0, 16);
74
+ return createHash('sha256').update(resolveThemeCss(cssPath)).digest('hex').slice(0, 16);
75
75
  }
76
76
  catch {
77
77
  return 'missing';
@@ -226,7 +226,7 @@ function getRnwindState(projectRoot) {
226
226
  const currentHash = readThemeHashFor(cssEntry);
227
227
  if (cached?.themeHash === currentHash && cached.projectRoot === projectRoot)
228
228
  return cached;
229
- const themeCss = readFileSync(cssEntry, 'utf8');
229
+ const themeCss = resolveThemeCss(cssEntry);
230
230
  const parser = new TailwindParser({
231
231
  themeCss,
232
232
  sources: defaultSources(projectRoot, cacheDir, readWatchFolders()),
@@ -1 +1 @@
1
- {"version":3,"file":"state.mjs","sources":["../../../../src/metro/state.ts"],"sourcesContent":["import { existsSync, readFileSync, statSync } from 'node:fs'\nimport path from 'node:path'\nimport { createHash } from 'node:crypto'\nimport { UnionBuilder } from '../core/style-builder'\nimport { TailwindParser, type SourceEntry } from '../core/parser'\n\n/**\n * Default oxide Scanner globs — walk every JS/TS source under the\n * project root AND every monorepo watch folder, excluding\n * `node_modules` and rnwind's own cache dir so we don't rescan\n * generated scheme files.\n *\n * Monorepo layouts (Yarn workspaces, pnpm workspaces, Nx) surface\n * sibling package roots as `metroConfig.watchFolders`. Every folder\n * Metro watches must also be scanned so atoms declared in shared UI\n * packages make it into the union — without this, only the app's\n * own files would be scanned and every UI-package atom would resolve\n * to `undefined` at runtime.\n * @param projectRoot Absolute project root.\n * @param cacheDir Absolute rnwind cache dir (to exclude).\n * @param watchFolders Extra monorepo roots Metro is watching.\n * @returns Scanner sources suitable for `parser.parseProject()`.\n */\nfunction defaultSources(projectRoot: string, cacheDir: string, watchFolders: readonly string[]): readonly SourceEntry[] {\n const cacheBaseName = path.basename(cacheDir)\n const roots = new Set<string>([projectRoot, ...watchFolders])\n const sources: SourceEntry[] = []\n for (const root of roots) {\n sources.push({ base: root, pattern: '**/*.{ts,tsx,js,jsx}', negated: false }, { base: root, pattern: '**/node_modules/**', negated: true }, { base: root, pattern: `**/${cacheBaseName}/**`, negated: true })\n }\n return sources\n}\n\n/**\n * Read monorepo watch-folder paths out of the worker environment.\n * Empty array when the host isn't a monorepo.\n * @returns Absolute paths Metro also watches (sibling packages).\n */\nfunction readWatchFolders(): readonly string[] {\n const raw = process.env[WATCH_FOLDERS_ENV]\n if (!raw || raw.length === 0) return []\n return raw.split('\\0').filter((entry) => entry.length > 0)\n}\n\n/** Env var Metro workers read to locate the theme CSS on disk. */\nconst CSS_ENTRY_ENV = 'RNWIND_CSS_ENTRY_FILE'\n/** Env var Metro workers read to locate the cache directory (`.rnwind`). */\nconst CACHE_DIR_ENV = 'RNWIND_CACHE_DIR'\n/** Env var carrying `watchFolders` from Metro config (NUL-separated). */\nconst WATCH_FOLDERS_ENV = 'RNWIND_WATCH_FOLDERS'\n/** Env var carrying extra className prefixes the Metro config supplied. */\nconst CLASSNAME_PREFIXES_ENV = 'RNWIND_CLASSNAME_PREFIXES'\n/** Env var carrying extra import sources whose JSX exports get className→style rewrites. Comma-separated. */\nconst HOST_SOURCES_ENV = 'RNWIND_HOST_SOURCES'\n/** Env var carrying extra JSX tag names (verbatim, may contain `.`) treated as hosts. Comma-separated. */\nconst HOST_COMPONENTS_ENV = 'RNWIND_HOST_COMPONENTS'\n\n/** Memoised library fingerprint — read once per worker process. */\nlet libraryFingerprint: string | undefined\n\n/** Live state shared across one Metro transform worker. */\nlet cached: RnwindState | null = null\n\n/**\n * Cheap content-hash readout. SHA-256 prefix of the CSS bytes plus the\n * file's mtime nanoseconds (so identical content with different mtime\n * — atomic rewrites — still picks up the change). Returns `'missing'`\n * when the file can't be read so the cache key is still deterministic.\n * @param cssPath Absolute CSS path.\n * @returns 16-char hex content hash.\n */\nfunction readThemeHashFor(cssPath: string): string {\n if (!existsSync(cssPath)) return 'missing'\n try {\n const bytes = readFileSync(cssPath)\n const mtime = statSync(cssPath).mtimeMs.toString()\n return createHash('sha256').update(bytes).update(mtime).digest('hex').slice(0, 16)\n } catch {\n return 'missing'\n }\n}\n\n/**\n * Hash a small set of rnwind library files whose changes affect the\n * generated transform output. When the library is rebuilt (workspace\n * dev OR npm install of a new version) the file bytes change, the\n * fingerprint rotates, and Metro's transform cache invalidates.\n *\n * Includes the JSX rewriter (`transform-ast`) alongside the parser /\n * style-builder so a change to the transformer — e.g. renaming the\n * injected context hook — invalidates every stale per-file cache entry\n * on the next dev run. Without this, a user upgrading rnwind in-place\n * would keep loading the old transformed bytes; React-refresh would\n * then preserve fiber state across the version bump and the rendered\n * hook list could shift, surfacing as \"change in the order of Hooks\"\n * runtime errors.\n * Memoised — read once per worker process.\n * @returns 16-char hex fingerprint.\n */\nfunction getLibraryFingerprint(): string {\n if (libraryFingerprint !== undefined) return libraryFingerprint\n const here = path.dirname(__filename)\n const candidates = [\n path.resolve(here, '..', 'core', 'style-builder', 'build-style.mjs'),\n path.resolve(here, '..', 'core', 'style-builder', 'build-style.cjs'),\n path.resolve(here, '..', 'core', 'parser', 'tw-parser.mjs'),\n path.resolve(here, '..', 'core', 'parser', 'tw-parser.cjs'),\n path.resolve(here, 'transform-ast.mjs'),\n path.resolve(here, 'transform-ast.cjs'),\n path.resolve(here, 'transformer.mjs'),\n path.resolve(here, 'transformer.cjs'),\n // Source-tree fallback for tests + workspace dev (no built lib yet).\n path.resolve(here, '..', '..', 'src', 'core', 'style-builder', 'build-style.ts'),\n path.resolve(here, '..', '..', 'src', 'core', 'parser', 'tw-parser.ts'),\n path.resolve(here, '..', '..', 'src', 'metro', 'transform-ast.ts'),\n path.resolve(here, '..', '..', 'src', 'metro', 'transformer.ts'),\n ]\n const hash = createHash('sha256')\n let included = 0\n for (const file of candidates) {\n if (!existsSync(file)) continue\n try {\n hash.update(readFileSync(file))\n included += 1\n } catch {\n // Unreadable file — skip; fingerprint still derives from whatever WE could read.\n }\n }\n libraryFingerprint = included > 0 ? hash.digest('hex').slice(0, 16) : '0'.repeat(16)\n return libraryFingerprint\n}\n\n/**\n * Worker-local state. Lazy-initialised on first access so files that\n * bypass the transform don't pay for construction.\n */\nexport interface RnwindState {\n parser: TailwindParser\n builder: UnionBuilder\n themeCss: string\n themeHash: string\n projectRoot: string\n}\n\n/**\n * Publish the theme CSS path + cache dir to the environment so worker\n * subprocesses (spawned by Metro once `babelTransformerPath` is set)\n * can rebuild the same state without re-reading the Metro config.\n * @param cssEntryFile Absolute path to the user's theme CSS.\n * @param cacheDir Absolute path to the cache dir (`.rnwind`).\n * @param watchFolders\n * @param classNamePrefixes Extra JSX prop-name prefixes to rewrite.\n * @param hostSources\n * @param hostComponents\n */\nexport function configureRnwindState(\n cssEntryFile: string,\n cacheDir: string,\n watchFolders: readonly string[] = [],\n classNamePrefixes?: readonly string[],\n hostSources?: readonly string[],\n hostComponents?: readonly string[],\n): void {\n process.env[CSS_ENTRY_ENV] = cssEntryFile\n process.env[CACHE_DIR_ENV] = cacheDir\n if (watchFolders.length === 0) {\n delete process.env[WATCH_FOLDERS_ENV]\n } else {\n process.env[WATCH_FOLDERS_ENV] = watchFolders.join('\\0')\n }\n if (!classNamePrefixes || classNamePrefixes.length === 0) {\n delete process.env[CLASSNAME_PREFIXES_ENV]\n } else {\n process.env[CLASSNAME_PREFIXES_ENV] = classNamePrefixes.join(',')\n }\n if (!hostSources || hostSources.length === 0) {\n delete process.env[HOST_SOURCES_ENV]\n } else {\n process.env[HOST_SOURCES_ENV] = hostSources.join(',')\n }\n if (!hostComponents || hostComponents.length === 0) {\n delete process.env[HOST_COMPONENTS_ENV]\n } else {\n process.env[HOST_COMPONENTS_ENV] = hostComponents.join(',')\n }\n cached = null\n}\n\n/**\n * Read the caller-configured extra className prefixes out of the\n * worker environment. Returns an empty array when unset — the\n * transformer applies the built-in `contentContainer` default on top\n * either way.\n * @returns User-supplied extra prefixes.\n */\nexport function getClassNamePrefixes(): readonly string[] {\n const raw = process.env[CLASSNAME_PREFIXES_ENV]\n if (!raw || raw.length === 0) return []\n return raw.split(',').filter((entry) => entry.length > 0)\n}\n\n/**\n * Read the caller-configured extra host module sources out of the\n * worker environment. Empty array when unset — the transformer applies\n * its built-in default list on top either way.\n * @returns User-supplied extra host sources.\n */\nexport function getHostSources(): readonly string[] {\n const raw = process.env[HOST_SOURCES_ENV]\n if (!raw || raw.length === 0) return []\n return raw.split(',').filter((entry) => entry.length > 0)\n}\n\n/**\n * Read the caller-configured extra host JSX tag names out of the worker\n * environment. Verbatim names — may include `.` for member expressions\n * like `'Animated.View'`.\n * @returns User-supplied extra host component names.\n */\nexport function getHostComponents(): readonly string[] {\n const raw = process.env[HOST_COMPONENTS_ENV]\n if (!raw || raw.length === 0) return []\n return raw.split(',').filter((entry) => entry.length > 0)\n}\n\n/**\n * Fetch (or build) the worker-local rnwind state. Re-reads the theme\n * CSS hash on every call: if the user edited `global.css` while Metro\n * is running, the cached state is dropped and a fresh parser + ledger\n * is built. Combined with the `getCacheKey()` export on the\n * transformer (which folds the same hash into Metro's per-file cache\n * key) every CSS edit produces a full, correct re-bundle.\n * @param projectRoot\n * @returns The live rnwind state.\n */\nexport function getRnwindState(projectRoot: string): RnwindState {\n const cssEntry = process.env[CSS_ENTRY_ENV]\n const cacheDir = process.env[CACHE_DIR_ENV]\n if (!cssEntry) throw new Error('rnwind: RNWIND_CSS_ENTRY_FILE is not set — did `withRnwindConfig` run?')\n if (!cacheDir) throw new Error('rnwind: RNWIND_CACHE_DIR is not set — did `withRnwindConfig` run?')\n const currentHash = readThemeHashFor(cssEntry)\n if (cached?.themeHash === currentHash && cached.projectRoot === projectRoot) return cached\n const themeCss = readFileSync(cssEntry, 'utf8')\n const parser = new TailwindParser({\n themeCss,\n sources: defaultSources(projectRoot, cacheDir, readWatchFolders()),\n })\n const builder = new UnionBuilder(cacheDir, parser)\n cached = { parser, builder, themeCss, themeHash: currentHash, projectRoot }\n return cached\n}\n\n/**\n * Compute the rnwind cache-key suffix Metro mixes into every per-file\n * transform cache entry via the transformer's `getCacheKey()` export.\n * Includes the CSS path + its current content hash + the rnwind\n * library fingerprint, so any edit to `global.css` OR a library\n * upgrade flips the cache key and forces Metro to re-run the\n * transformer.\n * @returns Deterministic string suitable for appending to Metro's cache key.\n */\nexport function getRnwindCacheKey(): string {\n const cssEntry = process.env[CSS_ENTRY_ENV] ?? ''\n const prefixes = process.env[CLASSNAME_PREFIXES_ENV] ?? ''\n // Host source / component config changes which JSX tags get rewritten,\n // so it MUST flip the cache key — otherwise Metro replays stale\n // transforms (a newly-opted-in host keeps its raw className, a removed\n // one keeps the rewrite).\n const hostSources = process.env[HOST_SOURCES_ENV] ?? ''\n const hostComponents = process.env[HOST_COMPONENTS_ENV] ?? ''\n return `rnwind:${cssEntry}:${readThemeHashFor(cssEntry)}|lib:${getLibraryFingerprint()}|pfx:${prefixes}|hs:${hostSources}|hc:${hostComponents}`\n}\n\n/** Drop the cached state — call after editing the theme CSS. */\nexport function resetRnwindState(): void {\n cached = null\n}\n\n/**\n * Drop cached state, rebuild parser/builder with the fresh CSS, rescan\n * the project, and rewrite every scheme file on disk. This is what\n * `withRnwindConfig`'s CSS file-watcher invokes so `global.css` edits\n * propagate to the app via Metro's HMR — without this, the CSS-as-JS\n * module would re-emit `export {}` whose bytes never change, so Metro\n * would never invalidate downstream modules.\n * @param projectRoot Absolute project root (from `metroConfig.projectRoot`).\n */\nexport async function onThemeChange(projectRoot: string): Promise<void> {\n resetRnwindState()\n const state = getRnwindState(projectRoot)\n await state.builder.writeSchemes()\n}\n\n/**\n * Resolve the on-disk path of the scheme manifest module for the\n * resolver. The manifest eager-imports `common.style.js` and\n * lazy-requires each variant scheme; SchemeProvider calls its\n * `ensureSchemeLoaded` export to trigger per-scheme requires.\n * @returns Absolute path to `<cacheDir>/schemes.js`.\n */\nexport function manifestPathFor(): string {\n const cacheDir = process.env[CACHE_DIR_ENV]\n if (!cacheDir) throw new Error('rnwind: RNWIND_CACHE_DIR is not set')\n return path.join(cacheDir, 'schemes.js')\n}\n"],"names":[],"mappings":";;;;;;AAMA;;;;;;;;;;;;;;;;AAgBG;AACH,SAA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gBAAgB,EAAE;AAClB,IAAA,MAAM,KAAK,GAAG,cAAc,CAAC,WAAW,CAAC;AACzC,IAAA,MAAM,KAAK,CAAC,OAAO,CAAC,YAAY,EAAE;AACpC;AAEA;;;;;;AAMG;SACa,eAAe,GAAA;IAC7B,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC;AAC3C,IAAA,IAAI,CAAC,QAAQ;AAAE,QAAA,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC;IACrE,OAAO,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,YAAY,CAAC;AAC1C;;;;"}
1
+ {"version":3,"file":"state.mjs","sources":["../../../../src/metro/state.ts"],"sourcesContent":["import { existsSync, readFileSync } from 'node:fs'\nimport path from 'node:path'\nimport { createHash } from 'node:crypto'\nimport { UnionBuilder } from '../core/style-builder'\nimport { TailwindParser, type SourceEntry } from '../core/parser'\nimport { resolveThemeCss } from './css-imports'\n\n/**\n * Default oxide Scanner globs — walk every JS/TS source under the\n * project root AND every monorepo watch folder, excluding\n * `node_modules` and rnwind's own cache dir so we don't rescan\n * generated scheme files.\n *\n * Monorepo layouts (Yarn workspaces, pnpm workspaces, Nx) surface\n * sibling package roots as `metroConfig.watchFolders`. Every folder\n * Metro watches must also be scanned so atoms declared in shared UI\n * packages make it into the union — without this, only the app's\n * own files would be scanned and every UI-package atom would resolve\n * to `undefined` at runtime.\n * @param projectRoot Absolute project root.\n * @param cacheDir Absolute rnwind cache dir (to exclude).\n * @param watchFolders Extra monorepo roots Metro is watching.\n * @returns Scanner sources suitable for `parser.parseProject()`.\n */\nfunction defaultSources(projectRoot: string, cacheDir: string, watchFolders: readonly string[]): readonly SourceEntry[] {\n const cacheBaseName = path.basename(cacheDir)\n const roots = new Set<string>([projectRoot, ...watchFolders])\n const sources: SourceEntry[] = []\n for (const root of roots) {\n sources.push({ base: root, pattern: '**/*.{ts,tsx,js,jsx}', negated: false }, { base: root, pattern: '**/node_modules/**', negated: true }, { base: root, pattern: `**/${cacheBaseName}/**`, negated: true })\n }\n return sources\n}\n\n/**\n * Read monorepo watch-folder paths out of the worker environment.\n * Empty array when the host isn't a monorepo.\n * @returns Absolute paths Metro also watches (sibling packages).\n */\nfunction readWatchFolders(): readonly string[] {\n const raw = process.env[WATCH_FOLDERS_ENV]\n if (!raw || raw.length === 0) return []\n return raw.split('\\0').filter((entry) => entry.length > 0)\n}\n\n/** Env var Metro workers read to locate the theme CSS on disk. */\nconst CSS_ENTRY_ENV = 'RNWIND_CSS_ENTRY_FILE'\n/** Env var Metro workers read to locate the cache directory (`.rnwind`). */\nconst CACHE_DIR_ENV = 'RNWIND_CACHE_DIR'\n/** Env var carrying `watchFolders` from Metro config (NUL-separated). */\nconst WATCH_FOLDERS_ENV = 'RNWIND_WATCH_FOLDERS'\n/** Env var carrying extra className prefixes the Metro config supplied. */\nconst CLASSNAME_PREFIXES_ENV = 'RNWIND_CLASSNAME_PREFIXES'\n/** Env var carrying extra import sources whose JSX exports get className→style rewrites. Comma-separated. */\nconst HOST_SOURCES_ENV = 'RNWIND_HOST_SOURCES'\n/** Env var carrying extra JSX tag names (verbatim, may contain `.`) treated as hosts. Comma-separated. */\nconst HOST_COMPONENTS_ENV = 'RNWIND_HOST_COMPONENTS'\n\n/** Memoised library fingerprint — read once per worker process. */\nlet libraryFingerprint: string | undefined\n\n/** Live state shared across one Metro transform worker. */\nlet cached: RnwindState | null = null\n\n/**\n * Cheap content-hash readout. SHA-256 prefix of the FULLY-RESOLVED theme\n * CSS — `@import`s flattened — so an edit to a theme file the entry only\n * re-exports (`@import \"@acme/ui/theme.css\"`) still rotates the hash and\n * invalidates Metro's cache. Returns `'missing'` when the entry can't be\n * read so the cache key stays deterministic.\n * @param cssPath Absolute CSS path.\n * @returns 16-char hex content hash.\n */\nfunction readThemeHashFor(cssPath: string): string {\n if (!existsSync(cssPath)) return 'missing'\n try {\n return createHash('sha256').update(resolveThemeCss(cssPath)).digest('hex').slice(0, 16)\n } catch {\n return 'missing'\n }\n}\n\n/**\n * Hash a small set of rnwind library files whose changes affect the\n * generated transform output. When the library is rebuilt (workspace\n * dev OR npm install of a new version) the file bytes change, the\n * fingerprint rotates, and Metro's transform cache invalidates.\n *\n * Includes the JSX rewriter (`transform-ast`) alongside the parser /\n * style-builder so a change to the transformer — e.g. renaming the\n * injected context hook — invalidates every stale per-file cache entry\n * on the next dev run. Without this, a user upgrading rnwind in-place\n * would keep loading the old transformed bytes; React-refresh would\n * then preserve fiber state across the version bump and the rendered\n * hook list could shift, surfacing as \"change in the order of Hooks\"\n * runtime errors.\n * Memoised — read once per worker process.\n * @returns 16-char hex fingerprint.\n */\nfunction getLibraryFingerprint(): string {\n if (libraryFingerprint !== undefined) return libraryFingerprint\n const here = path.dirname(__filename)\n const candidates = [\n path.resolve(here, '..', 'core', 'style-builder', 'build-style.mjs'),\n path.resolve(here, '..', 'core', 'style-builder', 'build-style.cjs'),\n path.resolve(here, '..', 'core', 'parser', 'tw-parser.mjs'),\n path.resolve(here, '..', 'core', 'parser', 'tw-parser.cjs'),\n path.resolve(here, 'transform-ast.mjs'),\n path.resolve(here, 'transform-ast.cjs'),\n path.resolve(here, 'transformer.mjs'),\n path.resolve(here, 'transformer.cjs'),\n // Source-tree fallback for tests + workspace dev (no built lib yet).\n path.resolve(here, '..', '..', 'src', 'core', 'style-builder', 'build-style.ts'),\n path.resolve(here, '..', '..', 'src', 'core', 'parser', 'tw-parser.ts'),\n path.resolve(here, '..', '..', 'src', 'metro', 'transform-ast.ts'),\n path.resolve(here, '..', '..', 'src', 'metro', 'transformer.ts'),\n ]\n const hash = createHash('sha256')\n let included = 0\n for (const file of candidates) {\n if (!existsSync(file)) continue\n try {\n hash.update(readFileSync(file))\n included += 1\n } catch {\n // Unreadable file — skip; fingerprint still derives from whatever WE could read.\n }\n }\n libraryFingerprint = included > 0 ? hash.digest('hex').slice(0, 16) : '0'.repeat(16)\n return libraryFingerprint\n}\n\n/**\n * Worker-local state. Lazy-initialised on first access so files that\n * bypass the transform don't pay for construction.\n */\nexport interface RnwindState {\n parser: TailwindParser\n builder: UnionBuilder\n themeCss: string\n themeHash: string\n projectRoot: string\n}\n\n/**\n * Publish the theme CSS path + cache dir to the environment so worker\n * subprocesses (spawned by Metro once `babelTransformerPath` is set)\n * can rebuild the same state without re-reading the Metro config.\n * @param cssEntryFile Absolute path to the user's theme CSS.\n * @param cacheDir Absolute path to the cache dir (`.rnwind`).\n * @param watchFolders\n * @param classNamePrefixes Extra JSX prop-name prefixes to rewrite.\n * @param hostSources\n * @param hostComponents\n */\nexport function configureRnwindState(\n cssEntryFile: string,\n cacheDir: string,\n watchFolders: readonly string[] = [],\n classNamePrefixes?: readonly string[],\n hostSources?: readonly string[],\n hostComponents?: readonly string[],\n): void {\n process.env[CSS_ENTRY_ENV] = cssEntryFile\n process.env[CACHE_DIR_ENV] = cacheDir\n if (watchFolders.length === 0) {\n delete process.env[WATCH_FOLDERS_ENV]\n } else {\n process.env[WATCH_FOLDERS_ENV] = watchFolders.join('\\0')\n }\n if (!classNamePrefixes || classNamePrefixes.length === 0) {\n delete process.env[CLASSNAME_PREFIXES_ENV]\n } else {\n process.env[CLASSNAME_PREFIXES_ENV] = classNamePrefixes.join(',')\n }\n if (!hostSources || hostSources.length === 0) {\n delete process.env[HOST_SOURCES_ENV]\n } else {\n process.env[HOST_SOURCES_ENV] = hostSources.join(',')\n }\n if (!hostComponents || hostComponents.length === 0) {\n delete process.env[HOST_COMPONENTS_ENV]\n } else {\n process.env[HOST_COMPONENTS_ENV] = hostComponents.join(',')\n }\n cached = null\n}\n\n/**\n * Read the caller-configured extra className prefixes out of the\n * worker environment. Returns an empty array when unset — the\n * transformer applies the built-in `contentContainer` default on top\n * either way.\n * @returns User-supplied extra prefixes.\n */\nexport function getClassNamePrefixes(): readonly string[] {\n const raw = process.env[CLASSNAME_PREFIXES_ENV]\n if (!raw || raw.length === 0) return []\n return raw.split(',').filter((entry) => entry.length > 0)\n}\n\n/**\n * Read the caller-configured extra host module sources out of the\n * worker environment. Empty array when unset — the transformer applies\n * its built-in default list on top either way.\n * @returns User-supplied extra host sources.\n */\nexport function getHostSources(): readonly string[] {\n const raw = process.env[HOST_SOURCES_ENV]\n if (!raw || raw.length === 0) return []\n return raw.split(',').filter((entry) => entry.length > 0)\n}\n\n/**\n * Read the caller-configured extra host JSX tag names out of the worker\n * environment. Verbatim names — may include `.` for member expressions\n * like `'Animated.View'`.\n * @returns User-supplied extra host component names.\n */\nexport function getHostComponents(): readonly string[] {\n const raw = process.env[HOST_COMPONENTS_ENV]\n if (!raw || raw.length === 0) return []\n return raw.split(',').filter((entry) => entry.length > 0)\n}\n\n/**\n * Fetch (or build) the worker-local rnwind state. Re-reads the theme\n * CSS hash on every call: if the user edited `global.css` while Metro\n * is running, the cached state is dropped and a fresh parser + ledger\n * is built. Combined with the `getCacheKey()` export on the\n * transformer (which folds the same hash into Metro's per-file cache\n * key) every CSS edit produces a full, correct re-bundle.\n * @param projectRoot\n * @returns The live rnwind state.\n */\nexport function getRnwindState(projectRoot: string): RnwindState {\n const cssEntry = process.env[CSS_ENTRY_ENV]\n const cacheDir = process.env[CACHE_DIR_ENV]\n if (!cssEntry) throw new Error('rnwind: RNWIND_CSS_ENTRY_FILE is not set — did `withRnwindConfig` run?')\n if (!cacheDir) throw new Error('rnwind: RNWIND_CACHE_DIR is not set — did `withRnwindConfig` run?')\n const currentHash = readThemeHashFor(cssEntry)\n if (cached?.themeHash === currentHash && cached.projectRoot === projectRoot) return cached\n const themeCss = resolveThemeCss(cssEntry)\n const parser = new TailwindParser({\n themeCss,\n sources: defaultSources(projectRoot, cacheDir, readWatchFolders()),\n })\n const builder = new UnionBuilder(cacheDir, parser)\n cached = { parser, builder, themeCss, themeHash: currentHash, projectRoot }\n return cached\n}\n\n/**\n * Compute the rnwind cache-key suffix Metro mixes into every per-file\n * transform cache entry via the transformer's `getCacheKey()` export.\n * Includes the CSS path + its current content hash + the rnwind\n * library fingerprint, so any edit to `global.css` OR a library\n * upgrade flips the cache key and forces Metro to re-run the\n * transformer.\n * @returns Deterministic string suitable for appending to Metro's cache key.\n */\nexport function getRnwindCacheKey(): string {\n const cssEntry = process.env[CSS_ENTRY_ENV] ?? ''\n const prefixes = process.env[CLASSNAME_PREFIXES_ENV] ?? ''\n // Host source / component config changes which JSX tags get rewritten,\n // so it MUST flip the cache key — otherwise Metro replays stale\n // transforms (a newly-opted-in host keeps its raw className, a removed\n // one keeps the rewrite).\n const hostSources = process.env[HOST_SOURCES_ENV] ?? ''\n const hostComponents = process.env[HOST_COMPONENTS_ENV] ?? ''\n return `rnwind:${cssEntry}:${readThemeHashFor(cssEntry)}|lib:${getLibraryFingerprint()}|pfx:${prefixes}|hs:${hostSources}|hc:${hostComponents}`\n}\n\n/** Drop the cached state — call after editing the theme CSS. */\nexport function resetRnwindState(): void {\n cached = null\n}\n\n/**\n * Drop cached state, rebuild parser/builder with the fresh CSS, rescan\n * the project, and rewrite every scheme file on disk. This is what\n * `withRnwindConfig`'s CSS file-watcher invokes so `global.css` edits\n * propagate to the app via Metro's HMR — without this, the CSS-as-JS\n * module would re-emit `export {}` whose bytes never change, so Metro\n * would never invalidate downstream modules.\n * @param projectRoot Absolute project root (from `metroConfig.projectRoot`).\n */\nexport async function onThemeChange(projectRoot: string): Promise<void> {\n resetRnwindState()\n const state = getRnwindState(projectRoot)\n await state.builder.writeSchemes()\n}\n\n/**\n * Resolve the on-disk path of the scheme manifest module for the\n * resolver. The manifest eager-imports `common.style.js` and\n * lazy-requires each variant scheme; SchemeProvider calls its\n * `ensureSchemeLoaded` export to trigger per-scheme requires.\n * @returns Absolute path to `<cacheDir>/schemes.js`.\n */\nexport function manifestPathFor(): string {\n const cacheDir = process.env[CACHE_DIR_ENV]\n if (!cacheDir) throw new Error('rnwind: RNWIND_CACHE_DIR is not set')\n return path.join(cacheDir, 'schemes.js')\n}\n"],"names":[],"mappings":";;;;;;;AAOA;;;;;;;;;;;;;;;;AAgBG;AACH,SAAS,cAAc,CAAC,WAAmB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AAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC;AAC3C,IAAA,IAAI,CAAC,QAAQ;AAAE,QAAA,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC;IACrE,OAAO,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,YAAY,CAAC;AAC1C;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rnwind",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "description": "Tailwind for React Native",
5
5
  "author": "https://github.com/sagltd",
6
6
  "license": "MIT",
@@ -0,0 +1,75 @@
1
+ import { createRequire } from 'node:module'
2
+ import { existsSync, readFileSync } from 'node:fs'
3
+
4
+ /**
5
+ * Inline `@import` resolution for the theme entry CSS.
6
+ *
7
+ * rnwind's scheme extractors (`extractThemeVars`, `extractSchemeAliases`,
8
+ * `extractCustomVariantSchemes`) are plain text passes over the entry
9
+ * CSS — they don't follow `@import`. Tailwind's own compiler DOES follow
10
+ * imports, so utilities still compile, but a user who keeps their theme
11
+ * in a separate file and points the entry at it:
12
+ *
13
+ * ```css
14
+ * @import "@acme/ui/theme.css"; // global.css — the cssEntryFile
15
+ * ```
16
+ *
17
+ * would hand the extractors a file with no `@theme` / `@variant` /
18
+ * `@custom-variant` in sight → every scheme collapses to base and theme
19
+ * switching dies. This module flattens those user imports first so the
20
+ * extractors (and the compiler) see the real declarations.
21
+ */
22
+
23
+ /** Matches a bare `@import "spec";` / `@import 'spec';` (no media/layer suffix). */
24
+ const CSS_IMPORT = /@import\s+(["'])([^"']+)\1\s*;/g
25
+
26
+ /**
27
+ * Specs left untouched for the Tailwind compiler to resolve itself.
28
+ * `tailwindcss` resolves to JS (not inlinable) and `rnwind/css` is the
29
+ * framework preset — both are the compiler's job, not user theme files.
30
+ */
31
+ const FRAMEWORK_SPECS = new Set(['tailwindcss', 'rnwind/css', 'rnwind'])
32
+
33
+ /**
34
+ * Read `filePath` and replace each user `@import "<spec>";` whose spec
35
+ * resolves (Node resolution, honouring `exports` maps and workspace
36
+ * symlinks) to a readable `.css` file with that file's inlined +
37
+ * recursively-resolved contents. Unresolvable specs, non-CSS targets,
38
+ * and {@link FRAMEWORK_SPECS} are left as-is for the compiler.
39
+ * @param filePath Absolute path of the CSS file being inlined.
40
+ * @param seen Visited set guarding against import cycles.
41
+ * @returns CSS text with user imports flattened in place.
42
+ */
43
+ function inlineImports(filePath: string, seen: Set<string>): string {
44
+ if (seen.has(filePath)) return ''
45
+ seen.add(filePath)
46
+ let css: string
47
+ try {
48
+ css = readFileSync(filePath, 'utf8')
49
+ } catch {
50
+ return ''
51
+ }
52
+ const request = createRequire(filePath)
53
+ return css.replaceAll(CSS_IMPORT, (full: string, _quote: string, spec: string): string => {
54
+ if (FRAMEWORK_SPECS.has(spec)) return full
55
+ let resolved: string
56
+ try {
57
+ resolved = request.resolve(spec)
58
+ } catch {
59
+ return full
60
+ }
61
+ if (!resolved.endsWith('.css') || !existsSync(resolved)) return full
62
+ return inlineImports(resolved, seen)
63
+ })
64
+ }
65
+
66
+ /**
67
+ * Flatten user `@import`s in a theme entry CSS file so rnwind's text-based
68
+ * scheme extractors see the real `@theme` / `@variant` / `@custom-variant`
69
+ * declarations even when the entry only re-exports them via `@import`.
70
+ * @param entryFilePath Absolute path to the theme entry CSS (the cssEntryFile).
71
+ * @returns Inlined CSS, or `''` when the entry can't be read.
72
+ */
73
+ export function resolveThemeCss(entryFilePath: string): string {
74
+ return inlineImports(entryFilePath, new Set<string>())
75
+ }
@@ -1,8 +1,9 @@
1
- import { existsSync, readFileSync, statSync } from 'node:fs'
1
+ import { existsSync, readFileSync } from 'node:fs'
2
2
  import path from 'node:path'
3
3
  import { createHash } from 'node:crypto'
4
4
  import { UnionBuilder } from '../core/style-builder'
5
5
  import { TailwindParser, type SourceEntry } from '../core/parser'
6
+ import { resolveThemeCss } from './css-imports'
6
7
 
7
8
  /**
8
9
  * Default oxide Scanner globs — walk every JS/TS source under the
@@ -62,19 +63,18 @@ let libraryFingerprint: string | undefined
62
63
  let cached: RnwindState | null = null
63
64
 
64
65
  /**
65
- * Cheap content-hash readout. SHA-256 prefix of the CSS bytes plus the
66
- * file's mtime nanoseconds (so identical content with different mtime
67
- * atomic rewrites still picks up the change). Returns `'missing'`
68
- * when the file can't be read so the cache key is still deterministic.
66
+ * Cheap content-hash readout. SHA-256 prefix of the FULLY-RESOLVED theme
67
+ * CSS — `@import`s flattened so an edit to a theme file the entry only
68
+ * re-exports (`@import "@acme/ui/theme.css"`) still rotates the hash and
69
+ * invalidates Metro's cache. Returns `'missing'` when the entry can't be
70
+ * read so the cache key stays deterministic.
69
71
  * @param cssPath Absolute CSS path.
70
72
  * @returns 16-char hex content hash.
71
73
  */
72
74
  function readThemeHashFor(cssPath: string): string {
73
75
  if (!existsSync(cssPath)) return 'missing'
74
76
  try {
75
- const bytes = readFileSync(cssPath)
76
- const mtime = statSync(cssPath).mtimeMs.toString()
77
- return createHash('sha256').update(bytes).update(mtime).digest('hex').slice(0, 16)
77
+ return createHash('sha256').update(resolveThemeCss(cssPath)).digest('hex').slice(0, 16)
78
78
  } catch {
79
79
  return 'missing'
80
80
  }
@@ -240,7 +240,7 @@ export function getRnwindState(projectRoot: string): RnwindState {
240
240
  if (!cacheDir) throw new Error('rnwind: RNWIND_CACHE_DIR is not set — did `withRnwindConfig` run?')
241
241
  const currentHash = readThemeHashFor(cssEntry)
242
242
  if (cached?.themeHash === currentHash && cached.projectRoot === projectRoot) return cached
243
- const themeCss = readFileSync(cssEntry, 'utf8')
243
+ const themeCss = resolveThemeCss(cssEntry)
244
244
  const parser = new TailwindParser({
245
245
  themeCss,
246
246
  sources: defaultSources(projectRoot, cacheDir, readWatchFolders()),