@tamagui/cli 3.2.3 → 3.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.
package/dist/build.cjs CHANGED
@@ -27,7 +27,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
27
27
  var build_exports = {};
28
28
  __export(build_exports, {
29
29
  build: () => build,
30
- insertCssImport: () => insertCssImport
30
+ insertCssImport: () => insertCssImport,
31
+ mergeCssRules: () => mergeCssRules
31
32
  });
32
33
  module.exports = __toCommonJS(build_exports);
33
34
  var import_static = require("@tamagui/static");
@@ -41,6 +42,26 @@ var import_node_crypto = require("node:crypto");
41
42
  var import_node_module = require("node:module");
42
43
  const import_meta = {};
43
44
  const cliVersion = (0, import_node_module.createRequire)(typeof __filename === "string" ? __filename : import_meta.url)("@tamagui/cli/package.json").version;
45
+ function mergeCssRules(cssParts) {
46
+ const groups = /* @__PURE__ */ new Map();
47
+ for (const css of cssParts) {
48
+ let depth = 0;
49
+ let start = 0;
50
+ for (let i = 0; i < css.length; i++) {
51
+ const char = css[i];
52
+ if (char === "{") depth++;
53
+ else if (char === "}" && --depth === 0) {
54
+ const rule = css.slice(start, i + 1);
55
+ start = i + 1;
56
+ const id = rule.match(/\._[a-zA-Z]+-[\w-]+/)?.[0] ?? "";
57
+ let group = groups.get(id);
58
+ if (!group) groups.set(id, group = /* @__PURE__ */ new Set());
59
+ group.add(rule);
60
+ }
61
+ }
62
+ }
63
+ return [...groups.keys()].sort().map((id) => [...groups.get(id)].join("\n")).join("\n");
64
+ }
44
65
  function insertCssImport(jsContent, cssImport) {
45
66
  const directiveMatch = jsContent.match(/^(['"])use (client|server)\1;?(?:\r\n|[\r\n])?/);
46
67
  if (directiveMatch) {
@@ -56,6 +77,8 @@ const build = async (options) => {
56
77
  const sourceDir = options.dir ?? ".";
57
78
  const outputDir = options.output;
58
79
  const outputAround = options.outputAround || false;
80
+ const cssOut = options.cssOut ? (0, import_node_path.resolve)(options.cssOut) : void 0;
81
+ const cssByFile = /* @__PURE__ */ new Map();
59
82
  const promises = [];
60
83
  const isDryRun = options.dryRun || false;
61
84
  const trackedFiles = [];
@@ -263,13 +286,14 @@ ${out.output.code}`);
263
286
  if (outputDir) await (0, import_fs_extra.mkdir)(outputBase, { recursive: true });
264
287
  const stylePath = (0, import_node_path.join)(outputBase, cssName + ".css");
265
288
  const cssImport = `import "./${cssName}.css"`;
266
- const code = out.plan.css ? insertCssImport(out.output.code, cssImport) : out.output.code;
289
+ const code = out.plan.css && !cssOut ? insertCssImport(out.output.code, cssImport) : out.output.code;
267
290
  const webOutputPath = outputDir ? (0, import_node_path.join)(outputDir, relPath) : sourcePath;
268
291
  if (!outputDir) await trackFile(sourcePath);
269
292
  await (0, import_fs_extra.writeFile)(webOutputPath, code, "utf-8");
270
293
  if (!outputDir) await recordMtime(sourcePath);
271
- if (out.plan.css) await (0, import_fs_extra.writeFile)(stylePath, out.plan.css, "utf-8");
272
- if (!outputDir && out.plan.css) trackedFiles.push({
294
+ if (out.plan.css && cssOut) cssByFile.set(sourcePath, out.plan.css);
295
+ else if (out.plan.css) await (0, import_fs_extra.writeFile)(stylePath, out.plan.css, "utf-8");
296
+ if (!outputDir && out.plan.css && !cssOut) trackedFiles.push({
273
297
  path: stylePath,
274
298
  hardlinkPath: "",
275
299
  mtimeAfterWrite: (await (0, import_fs_extra.stat)(stylePath)).mtimeMs
@@ -321,6 +345,16 @@ ${nativeOut.output.code}`);
321
345
  promises.push(...targetPromises);
322
346
  await Promise.all(targetPromises);
323
347
  }
348
+ if (cssOut && !isDryRun && cssByFile.size) {
349
+ const sourcePaths = [...cssByFile.keys()].sort();
350
+ await (0, import_fs_extra.mkdir)((0, import_node_path.dirname)(cssOut), { recursive: true });
351
+ await (0, import_fs_extra.writeFile)(cssOut, mergeCssRules(sourcePaths.map((path) => cssByFile.get(path))), "utf-8");
352
+ if (!outputDir) trackedFiles.push({
353
+ path: cssOut,
354
+ hardlinkPath: "",
355
+ mtimeAfterWrite: (await (0, import_fs_extra.stat)(cssOut)).mtimeMs
356
+ });
357
+ }
324
358
  if (isDryRun) console.info(`
325
359
  ${stats.filesProcessed} files | ${stats.found} found | ${stats.optimized} optimized | ${stats.flattened} flattened | ${stats.styled} styled | ${stats.bailed} bailed
326
360
  `);
package/dist/cli.cjs CHANGED
@@ -213,6 +213,7 @@ $ tamagui icons add Search=magnifying-glass --from phosphor`,
213
213
  "--exclude": String,
214
214
  "--output": String,
215
215
  "--output-around": Boolean,
216
+ "--css-out": String,
216
217
  "--expect-optimizations": Number
217
218
  },
218
219
  async run() {
@@ -237,6 +238,7 @@ $ tamagui icons add Search=magnifying-glass --from phosphor`,
237
238
  exclude: flags2["--exclude"],
238
239
  output: flags2["--output"],
239
240
  outputAround: flags2["--output-around"],
241
+ cssOut: flags2["--css-out"],
240
242
  expectOptimizations: flags2["--expect-optimizations"],
241
243
  runCommand,
242
244
  dryRun
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamagui/cli",
3
- "version": "3.2.3",
3
+ "version": "3.3.0",
4
4
  "license": "MIT",
5
5
  "bin": {
6
6
  "tama": "dist/index.cjs",
@@ -52,12 +52,12 @@
52
52
  "test:web": "bun run test"
53
53
  },
54
54
  "dependencies": {
55
- "@tamagui/generate-themes": "3.2.3",
56
- "@tamagui/metro-plugin": "3.2.3",
57
- "@tamagui/static": "3.2.3",
58
- "@tamagui/to-tailwind": "3.2.3",
59
- "@tamagui/types": "3.2.3",
60
- "@tamagui/vite-plugin": "3.2.3",
55
+ "@tamagui/generate-themes": "3.3.0",
56
+ "@tamagui/metro-plugin": "3.3.0",
57
+ "@tamagui/static": "3.3.0",
58
+ "@tamagui/to-tailwind": "3.3.0",
59
+ "@tamagui/types": "3.3.0",
60
+ "@tamagui/vite-plugin": "3.3.0",
61
61
  "arg": "^5.0.2",
62
62
  "chalk": "^4.1.2",
63
63
  "change-case": "^4.1.2",
@@ -67,7 +67,7 @@
67
67
  "express": "^4.18.2",
68
68
  "fs-extra": "^11.2.0",
69
69
  "get-port": "^7.0.0",
70
- "glob": "^13.0.3",
70
+ "glob": "13.0.6",
71
71
  "marked": "^14.1.2",
72
72
  "marked-terminal": "^5.2.0",
73
73
  "micromatch": "^4.0.7",
@@ -76,10 +76,10 @@
76
76
  "ts-morph": "^28.0.0",
77
77
  "typescript": "7.0.2",
78
78
  "url": "^0.11.0",
79
- "@tamagui/language-service": "3.2.3"
79
+ "@tamagui/language-service": "3.3.0"
80
80
  },
81
81
  "devDependencies": {
82
- "@tamagui/build": "3.2.3",
82
+ "@tamagui/build": "3.3.0",
83
83
  "@types/chokidar": "^2.1.3",
84
84
  "@types/marked": "^5.0.0",
85
85
  "vitest": "4.1.11"
@@ -89,5 +89,5 @@
89
89
  "url": "git+https://github.com/tamagui/tamagui.git",
90
90
  "directory": "code/core/cli"
91
91
  },
92
- "releaseSourceCommit": "ded3a760bc7d070ec010773fd6229783d6980208"
92
+ "releaseSourceCommit": "73efe6dc42fd5ce56532b783f707f6b32ade82ac"
93
93
  }
package/src/build.ts CHANGED
@@ -42,6 +42,37 @@ export type BuildResult = {
42
42
  trackedFiles: TrackedFile[]
43
43
  }
44
44
 
45
+ /**
46
+ * Merges per-file extracted CSS into one deduplicated sheet. Rules are grouped
47
+ * by atomic identifier and groups are ordered by identifier, the same order
48
+ * Tamagui's runtime uses when it serializes rules (getAllRules). A group keeps
49
+ * its rules in compiled order, so a `:where(:hover)` rule stays after the base
50
+ * rule it overrides.
51
+ */
52
+ export function mergeCssRules(cssParts: string[]): string {
53
+ const groups = new Map<string, Set<string>>()
54
+ for (const css of cssParts) {
55
+ let depth = 0
56
+ let start = 0
57
+ for (let i = 0; i < css.length; i++) {
58
+ const char = css[i]
59
+ if (char === '{') depth++
60
+ else if (char === '}' && --depth === 0) {
61
+ const rule = css.slice(start, i + 1)
62
+ start = i + 1
63
+ const id = rule.match(/\._[a-zA-Z]+-[\w-]+/)?.[0] ?? ''
64
+ let group = groups.get(id)
65
+ if (!group) groups.set(id, (group = new Set()))
66
+ group.add(rule)
67
+ }
68
+ }
69
+ }
70
+ return [...groups.keys()]
71
+ .sort()
72
+ .map((id) => [...groups.get(id)!].join('\n'))
73
+ .join('\n')
74
+ }
75
+
45
76
  /**
46
77
  * Inserts a CSS import statement into JS code, placing it after any
47
78
  * 'use client' or 'use server' directives at the top of the file.
@@ -68,6 +99,7 @@ export const build = async (
68
99
  exclude?: string
69
100
  output?: string
70
101
  outputAround?: boolean
102
+ cssOut?: string
71
103
  expectOptimizations?: number
72
104
  runCommand?: string[]
73
105
  dryRun?: boolean
@@ -76,6 +108,8 @@ export const build = async (
76
108
  const sourceDir = options.dir ?? '.'
77
109
  const outputDir = options.output
78
110
  const outputAround = options.outputAround || false
111
+ const cssOut = options.cssOut ? resolve(options.cssOut) : undefined
112
+ const cssByFile = new Map<string, string>()
79
113
  const promises: Promise<void>[] = []
80
114
  const isDryRun = options.dryRun || false
81
115
  const trackedFiles: TrackedFile[] = []
@@ -416,9 +450,10 @@ export const build = async (
416
450
 
417
451
  const stylePath = join(outputBase, cssName + '.css')
418
452
  const cssImport = `import "./${cssName}.css"`
419
- const code = out.plan.css
420
- ? insertCssImport(out.output.code, cssImport)
421
- : out.output.code
453
+ const code =
454
+ out.plan.css && !cssOut
455
+ ? insertCssImport(out.output.code, cssImport)
456
+ : out.output.code
422
457
 
423
458
  // Determine output path for JS (preserve directory structure)
424
459
  const webOutputPath = outputDir ? join(outputDir, relPath) : sourcePath
@@ -435,10 +470,12 @@ export const build = async (
435
470
  }
436
471
 
437
472
  // CSS file is new, track for cleanup (skip if using output dir)
438
- if (out.plan.css) {
473
+ if (out.plan.css && cssOut) {
474
+ cssByFile.set(sourcePath, out.plan.css)
475
+ } else if (out.plan.css) {
439
476
  await writeFile(stylePath, out.plan.css, 'utf-8')
440
477
  }
441
- if (!outputDir && out.plan.css) {
478
+ if (!outputDir && out.plan.css && !cssOut) {
442
479
  // Note: CSS files are new (generated), we'll delete them on restore
443
480
  trackedFiles.push({
444
481
  path: stylePath,
@@ -573,6 +610,23 @@ export const build = async (
573
610
  await Promise.all(targetPromises)
574
611
  }
575
612
 
613
+ if (cssOut && !isDryRun && cssByFile.size) {
614
+ const sourcePaths = [...cssByFile.keys()].sort()
615
+ await mkdir(dirname(cssOut), { recursive: true })
616
+ await writeFile(
617
+ cssOut,
618
+ mergeCssRules(sourcePaths.map((path) => cssByFile.get(path)!)),
619
+ 'utf-8'
620
+ )
621
+ if (!outputDir) {
622
+ trackedFiles.push({
623
+ path: cssOut,
624
+ hardlinkPath: '',
625
+ mtimeAfterWrite: (await stat(cssOut)).mtimeMs,
626
+ })
627
+ }
628
+ }
629
+
576
630
  if (isDryRun) {
577
631
  console.info(
578
632
  `\n${stats.filesProcessed} files | ${stats.found} found | ${stats.optimized} optimized | ${stats.flattened} flattened | ${stats.styled} styled | ${stats.bailed} bailed\n`
package/src/cli.ts CHANGED
@@ -212,6 +212,7 @@ $ tamagui icons add Search=magnifying-glass --from phosphor`,
212
212
  '--exclude': String,
213
213
  '--output': String,
214
214
  '--output-around': Boolean,
215
+ '--css-out': String,
215
216
  '--expect-optimizations': Number,
216
217
  },
217
218
  async run() {
@@ -249,6 +250,7 @@ $ tamagui icons add Search=magnifying-glass --from phosphor`,
249
250
  exclude: flags['--exclude'],
250
251
  output: flags['--output'],
251
252
  outputAround: flags['--output-around'],
253
+ cssOut: flags['--css-out'],
252
254
  expectOptimizations: flags['--expect-optimizations'],
253
255
  runCommand,
254
256
  dryRun,
package/types/build.d.ts CHANGED
@@ -16,6 +16,14 @@ export type BuildResult = {
16
16
  stats: BuildStats;
17
17
  trackedFiles: TrackedFile[];
18
18
  };
19
+ /**
20
+ * Merges per-file extracted CSS into one deduplicated sheet. Rules are grouped
21
+ * by atomic identifier and groups are ordered by identifier, the same order
22
+ * Tamagui's runtime uses when it serializes rules (getAllRules). A group keeps
23
+ * its rules in compiled order, so a `:where(:hover)` rule stays after the base
24
+ * rule it overrides.
25
+ */
26
+ export declare function mergeCssRules(cssParts: string[]): string;
19
27
  /**
20
28
  * Inserts a CSS import statement into JS code, placing it after any
21
29
  * 'use client' or 'use server' directives at the top of the file.
@@ -28,6 +36,7 @@ export declare const build: (options: CLIResolvedOptions & {
28
36
  exclude?: string;
29
37
  output?: string;
30
38
  outputAround?: boolean;
39
+ cssOut?: string;
31
40
  expectOptimizations?: number;
32
41
  runCommand?: string[];
33
42
  dryRun?: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../src/build.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,kBAAkB,EAAkB,MAAM,gBAAgB,CAAA;AAgBxE,MAAM,MAAM,UAAU,GAAG;IACvB,cAAc,EAAE,MAAM,CAAA;IACtB,SAAS,EAAE,MAAM,CAAA;IACjB,SAAS,EAAE,MAAM,CAAA;IACjB,MAAM,EAAE,MAAM,CAAA;IACd,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;CACf,CAAA;AAED,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,EAAE,MAAM,CAAA;IACZ,YAAY,EAAE,MAAM,CAAA;IACpB,eAAe,EAAE,MAAM,CAAA;CACxB,CAAA;AAED,MAAM,MAAM,WAAW,GAAG;IACxB,KAAK,EAAE,UAAU,CAAA;IACjB,YAAY,EAAE,WAAW,EAAE,CAAA;CAC5B,CAAA;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAY5E;AAED,eAAO,MAAM,KAAK,YACP,kBAAkB,GAAG;IAC5B,MAAM,CAAC,EAAE,KAAK,GAAG,QAAQ,GAAG,MAAM,CAAA;IAClC,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,MAAM,CAAC,EAAE,MAAM,CAAA;I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