@tamagui/cli 2.0.0-rc.3 → 2.0.0-rc.30

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
@@ -56,8 +56,21 @@ ${jsContent}`;
56
56
  }
57
57
  const build = async options => {
58
58
  const sourceDir = options.dir ?? ".",
59
+ outputDir = options.output,
60
+ outputAround = options.outputAround || !1,
59
61
  promises = [],
60
- buildOptions = (0, import_static.loadTamaguiBuildConfigSync)(options.tamaguiOptions),
62
+ isDryRun = options.dryRun || !1;
63
+ isDryRun && console.info(`[dry-run] no files will be written
64
+ `), outputDir && (await (0, import_fs_extra.mkdir)(outputDir, {
65
+ recursive: !0
66
+ }));
67
+ const loadedOptions = (0, import_static.loadTamaguiBuildConfigSync)(options.tamaguiOptions);
68
+ loadedOptions.disable && console.warn('[tamagui] Note: "disable" option in tamagui.build.ts is being ignored for CLI build command');
69
+ const buildOptions = {
70
+ ...loadedOptions,
71
+ disable: !1,
72
+ disableExtraction: !1
73
+ },
61
74
  targets = options.target === "both" || !options.target ? ["web", "native"] : [options.target],
62
75
  webTamaguiOptions = {
63
76
  ...buildOptions,
@@ -67,12 +80,15 @@ const build = async options => {
67
80
  const allFiles = [],
68
81
  watchPattern = sourceDir.match(/\.(tsx|jsx)$/) ? sourceDir : `${sourceDir}/**/*.{tsx,jsx}`;
69
82
  await new Promise(res => {
70
- import_chokidar.default.watch(watchPattern, {
83
+ const watcher = import_chokidar.default.watch(watchPattern, {
71
84
  ignoreInitial: !1
72
- }).on("add", relativePath => {
85
+ });
86
+ watcher.on("add", relativePath => {
73
87
  const sourcePath = (0, import_node_path.resolve)(process.cwd(), relativePath);
74
88
  options.exclude && import_micromatch.default.contains(relativePath, options.exclude) || options.include && !import_micromatch.default.contains(relativePath, options.include) || allFiles.push(sourcePath);
75
- }).on("ready", () => res());
89
+ }).on("ready", () => {
90
+ watcher.close().then(() => res());
91
+ });
76
92
  });
77
93
  const fileToTargets = /* @__PURE__ */new Map();
78
94
  for (const sourcePath of allFiles) {
@@ -122,7 +138,8 @@ const build = async options => {
122
138
  for (const [sourcePath, filePlatforms] of fileToTargets) promises.push((async () => {
123
139
  options.debug && (process.env.NODE_ENV ||= "development");
124
140
  const originalSource = await (0, import_fs_extra.readFile)(sourcePath, "utf-8");
125
- if (filePlatforms.includes("web")) {
141
+ if (isDryRun && console.info(`
142
+ ${sourcePath} [${filePlatforms.join(", ")}]`), filePlatforms.includes("web")) {
126
143
  process.env.TAMAGUI_TARGET = "web";
127
144
  const extractor = (0, import_static.createExtractor)({
128
145
  platform: "web"
@@ -138,19 +155,33 @@ const build = async options => {
138
155
  shouldPrintDebug: options.debug || !1
139
156
  });
140
157
  if (out) {
141
- stats.filesProcessed++, stats.optimized += out.stats.optimized, stats.flattened += out.stats.flattened, stats.styled += out.stats.styled, stats.found += out.stats.found;
142
- const cssName = "_" + (0, import_node_path.basename)(sourcePath, (0, import_node_path.extname)(sourcePath)),
143
- stylePath = (0, import_node_path.join)((0, import_node_path.dirname)(sourcePath), cssName + ".css"),
144
- cssImport = `import "./${cssName}.css"`,
145
- jsContent = typeof out.js == "string" ? out.js : out.js.toString("utf-8"),
146
- code = insertCssImport(jsContent, cssImport);
147
- await trackFile(sourcePath), await (0, import_fs_extra.writeFile)(sourcePath, code, "utf-8"), await recordMtime(sourcePath), await (0, import_fs_extra.writeFile)(stylePath, out.styles, "utf-8"), trackedFiles.push({
148
- path: stylePath,
149
- hardlinkPath: "",
150
- // Empty means delete on restore
151
- mtimeAfterWrite: (await (0, import_fs_extra.stat)(stylePath)).mtimeMs
152
- });
153
- }
158
+ if (stats.filesProcessed++, stats.optimized += out.stats.optimized, stats.flattened += out.stats.flattened, stats.styled += out.stats.styled, stats.found += out.stats.found, isDryRun) {
159
+ const jsContent = typeof out.js == "string" ? out.js : out.js.toString("utf-8");
160
+ out.styles && console.info(`
161
+ css:
162
+ ${out.styles}`), console.info(`
163
+ js:
164
+ ${jsContent}`);
165
+ } else {
166
+ const relPath = outputDir ? (0, import_node_path.relative)((0, import_node_path.resolve)(sourceDir), sourcePath) : (0, import_node_path.basename)(sourcePath),
167
+ cssName = "_" + (0, import_node_path.basename)(sourcePath, (0, import_node_path.extname)(sourcePath)),
168
+ outputBase = outputDir ? (0, import_node_path.join)(outputDir, (0, import_node_path.dirname)(relPath)) : (0, import_node_path.dirname)(sourcePath);
169
+ outputDir && (await (0, import_fs_extra.mkdir)(outputBase, {
170
+ recursive: !0
171
+ }));
172
+ const stylePath = (0, import_node_path.join)(outputBase, cssName + ".css"),
173
+ cssImport = `import "./${cssName}.css"`,
174
+ jsContent = typeof out.js == "string" ? out.js : out.js.toString("utf-8"),
175
+ code = insertCssImport(jsContent, cssImport),
176
+ webOutputPath = outputDir ? (0, import_node_path.join)(outputDir, relPath) : sourcePath;
177
+ outputDir || (await trackFile(sourcePath)), await (0, import_fs_extra.writeFile)(webOutputPath, code, "utf-8"), outputDir || (await recordMtime(sourcePath)), await (0, import_fs_extra.writeFile)(stylePath, out.styles, "utf-8"), outputDir || trackedFiles.push({
178
+ path: stylePath,
179
+ hardlinkPath: "",
180
+ // Empty means delete on restore
181
+ mtimeAfterWrite: (await (0, import_fs_extra.stat)(stylePath)).mtimeMs
182
+ });
183
+ }
184
+ } else isDryRun && console.info(" web: no output");
154
185
  }
155
186
  if (filePlatforms.includes("native")) {
156
187
  process.env.TAMAGUI_TARGET = "native";
@@ -159,16 +190,39 @@ const build = async options => {
159
190
  platform: "native"
160
191
  },
161
192
  nativeOut = (0, import_static.extractToNative)(sourcePath, originalSource, nativeTamaguiOptions);
162
- let nativeOutputPath = sourcePath;
163
- !/\.(web|native|ios|android)\.(tsx|jsx)$/.test(sourcePath) && filePlatforms.length > 1 && (nativeOutputPath = sourcePath.replace(/\.(tsx|jsx)$/, ".native.$1")), nativeOut.code && ((nativeOutputPath === sourcePath || filePlatforms.length === 1) && (await trackFile(nativeOutputPath)), await (0, import_fs_extra.writeFile)(nativeOutputPath, nativeOut.code, "utf-8"), await recordMtime(nativeOutputPath), nativeOutputPath !== sourcePath && filePlatforms.length > 1 && trackedFiles.push({
164
- path: nativeOutputPath,
165
- hardlinkPath: "",
166
- // Empty = delete on restore
167
- mtimeAfterWrite: (await (0, import_fs_extra.stat)(nativeOutputPath)).mtimeMs
168
- }));
193
+ if (isDryRun) nativeOut.code ? console.info(`
194
+ native:
195
+ ${nativeOut.code}`) : console.info(" native: no output");else {
196
+ let nativeOutputPath = sourcePath;
197
+ const needsNativeSuffix = !/\.(web|native|ios|android)\.(tsx|jsx)$/.test(sourcePath) && (filePlatforms.length > 1 || outputAround);
198
+ if (outputAround) {
199
+ if (nativeOutputPath = sourcePath.replace(/\.(tsx|jsx)$/, ".native.$1"), await (0, import_fs_extra.stat)(nativeOutputPath).catch(() => null)) throw new Error(`--output-around: ${nativeOutputPath} already exists. Remove it first or use --output instead.`);
200
+ } else if (outputDir) {
201
+ const relPath = (0, import_node_path.relative)((0, import_node_path.resolve)(sourceDir), sourcePath),
202
+ outputRelPath = needsNativeSuffix ? relPath.replace(/\.(tsx|jsx)$/, ".native.$1") : relPath;
203
+ nativeOutputPath = (0, import_node_path.join)(outputDir, outputRelPath), await (0, import_fs_extra.mkdir)((0, import_node_path.dirname)(nativeOutputPath), {
204
+ recursive: !0
205
+ });
206
+ } else needsNativeSuffix && (nativeOutputPath = sourcePath.replace(/\.(tsx|jsx)$/, ".native.$1"));
207
+ if (nativeOut.code) {
208
+ if (nativeOut.code.includes("__ReactNativeStyleSheet") || nativeOut.code.includes("_withStableStyle")) {
209
+ stats.filesProcessed++;
210
+ const wrapperMatches = nativeOut.code.match(/_withStableStyle/g);
211
+ wrapperMatches && (stats.flattened += wrapperMatches.length);
212
+ }
213
+ !outputDir && !outputAround && (nativeOutputPath === sourcePath || filePlatforms.length === 1) && (await trackFile(nativeOutputPath)), await (0, import_fs_extra.writeFile)(nativeOutputPath, nativeOut.code, "utf-8"), !outputDir && !outputAround && (await recordMtime(nativeOutputPath)), !outputDir && !outputAround && nativeOutputPath !== sourcePath && filePlatforms.length > 1 && trackedFiles.push({
214
+ path: nativeOutputPath,
215
+ hardlinkPath: "",
216
+ // Empty = delete on restore
217
+ mtimeAfterWrite: (await (0, import_fs_extra.stat)(nativeOutputPath)).mtimeMs
218
+ }), outputAround && console.info(` \u2192 ${nativeOutputPath}`);
219
+ }
220
+ }
169
221
  }
170
222
  })());
171
- if (await Promise.all(promises), options.expectOptimizations !== void 0) {
223
+ if (await Promise.all(promises), isDryRun && console.info(`
224
+ ${stats.filesProcessed} files | ${stats.found} found | ${stats.optimized} optimized | ${stats.flattened} flattened | ${stats.styled} styled
225
+ `), options.expectOptimizations !== void 0) {
172
226
  const totalOptimizations = stats.optimized + stats.flattened;
173
227
  totalOptimizations < options.expectOptimizations && (console.error(`
174
228
  Expected at least ${options.expectOptimizations} optimizations but only got ${totalOptimizations}`), console.error(`Stats: ${JSON.stringify(stats, null, 2)}`), process.exit(1)), console.info(`
package/dist/cli.cjs CHANGED
@@ -22,9 +22,7 @@ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
22
22
  }) : target, mod));
23
23
  var import_arg = __toESM(require("arg")),
24
24
  import_chalk = __toESM(require("chalk")),
25
- import_add = require("./add.cjs"),
26
- import_utils = require("./utils.cjs"),
27
- import_static = require("@tamagui/static");
25
+ import_utils = require("./utils.cjs");
28
26
  ["exit", "SIGINT"].forEach(_ => {
29
27
  process.on(_, () => {
30
28
  (0, import_utils.disposeAll)(), process.exit();
@@ -32,7 +30,7 @@ var import_arg = __toESM(require("arg")),
32
30
  });
33
31
  const COMMAND_MAP = {
34
32
  check: {
35
- description: "Checks your dependencies for inconsistent versions.",
33
+ description: "Checks for inconsistent versions, duplicate installs, lockfile issues, and missing config.",
36
34
  shorthands: [],
37
35
  flags: {
38
36
  "--help": Boolean,
@@ -45,10 +43,12 @@ const COMMAND_MAP = {
45
43
  ...flags2
46
44
  } = (0, import_arg.default)(this.flags),
47
45
  options = await (0, import_utils.getOptions)({
48
- debug: flags2["--debug"] ? flags2["--verbose"] ? "verbose" : !0 : !1,
49
- loadTamaguiOptions: !0
50
- });
51
- await (0, import_static.checkDeps)(options.paths.root);
46
+ debug: flags2["--debug"] ? flags2["--verbose"] ? "verbose" : !0 : !1
47
+ }),
48
+ {
49
+ checkDeps
50
+ } = require("@tamagui/static/checkDeps");
51
+ await checkDeps(options.paths.root);
52
52
  }
53
53
  },
54
54
  generate: {
@@ -67,8 +67,11 @@ const COMMAND_MAP = {
67
67
  options = await (0, import_utils.getOptions)({
68
68
  debug: flags2["--debug"] ? flags2["--verbose"] ? "verbose" : !0 : !1,
69
69
  loadTamaguiOptions: !0
70
- });
71
- process.env.TAMAGUI_KEEP_THEMES = "1", await (0, import_static.loadTamagui)({
70
+ }),
71
+ {
72
+ loadTamagui
73
+ } = require("@tamagui/static/loadTamagui");
74
+ process.env.TAMAGUI_KEEP_THEMES = "1", await loadTamagui({
72
75
  ...options.tamaguiOptions,
73
76
  platform: "web"
74
77
  });
@@ -102,8 +105,11 @@ const COMMAND_MAP = {
102
105
  debug: flags2["--debug"] ? flags2["--verbose"] ? "verbose" : !0 : !1,
103
106
  loadTamaguiOptions: !0
104
107
  }),
105
- outputPath = flags2["--output"] || options.tamaguiOptions.outputCSS || "./tamagui.generated.css";
106
- process.env.TAMAGUI_KEEP_THEMES = "1", await (0, import_static.loadTamagui)({
108
+ outputPath = flags2["--output"] || options.tamaguiOptions.outputCSS || "./tamagui.generated.css",
109
+ {
110
+ loadTamagui
111
+ } = require("@tamagui/static/loadTamagui");
112
+ process.env.TAMAGUI_KEEP_THEMES = "1", await loadTamagui({
107
113
  ...options.tamaguiOptions,
108
114
  outputCSS: outputPath,
109
115
  platform: "web"
@@ -143,7 +149,7 @@ const COMMAND_MAP = {
143
149
  },
144
150
  add: {
145
151
  shorthands: [],
146
- description: `Use to add fonts and icons to your monorepo. Supported types: ${import_add.generatedPackageTypes.join(", ")}`,
152
+ description: "Use to add fonts and icons to your monorepo.",
147
153
  flags: {
148
154
  "--help": Boolean,
149
155
  "--debug": Boolean,
@@ -168,9 +174,12 @@ const COMMAND_MAP = {
168
174
  "--help": Boolean,
169
175
  "--debug": Boolean,
170
176
  "--verbose": Boolean,
177
+ "--dry-run": Boolean,
171
178
  "--target": String,
172
179
  "--include": String,
173
180
  "--exclude": String,
181
+ "--output": String,
182
+ "--output-around": Boolean,
174
183
  "--expect-optimizations": Number
175
184
  },
176
185
  async run() {
@@ -186,11 +195,13 @@ const COMMAND_MAP = {
186
195
  ...flags2
187
196
  } = (0, import_arg.default)(this.flags),
188
197
  [_command, dir] = _,
198
+ dryRun = flags2["--dry-run"] || !1,
199
+ debug = flags2["--debug"] ? flags2["--verbose"] ? "verbose" : !0 : !1,
189
200
  {
190
201
  build
191
202
  } = require("./build.cjs"),
192
203
  options = await (0, import_utils.getOptions)({
193
- debug: flags2["--debug"] ? flags2["--verbose"] ? "verbose" : !0 : !1
204
+ debug
194
205
  });
195
206
  await build({
196
207
  ...options,
@@ -198,8 +209,11 @@ const COMMAND_MAP = {
198
209
  include: flags2["--include"],
199
210
  target: flags2["--target"] || "both",
200
211
  exclude: flags2["--exclude"],
212
+ output: flags2["--output"],
213
+ outputAround: flags2["--output-around"],
201
214
  expectOptimizations: flags2["--expect-optimizations"],
202
- runCommand
215
+ runCommand,
216
+ dryRun
203
217
  });
204
218
  }
205
219
  },
@@ -35,14 +35,16 @@ __export(generate_prompt_exports, {
35
35
  });
36
36
  module.exports = __toCommonJS(generate_prompt_exports);
37
37
  var import_node_path = require("node:path"),
38
- FS = __toESM(require("fs-extra")),
39
- import_static = require("@tamagui/static");
38
+ FS = __toESM(require("fs-extra"));
40
39
  async function generatePrompt(options) {
41
40
  const {
42
- paths,
43
- output
44
- } = options;
45
- process.env.TAMAGUI_KEEP_THEMES = "1", await (0, import_static.loadTamagui)({
41
+ paths,
42
+ output
43
+ } = options,
44
+ {
45
+ loadTamagui
46
+ } = require("@tamagui/static/loadTamagui");
47
+ process.env.TAMAGUI_KEEP_THEMES = "1", await loadTamagui({
46
48
  ...options.tamaguiOptions,
47
49
  platform: "web"
48
50
  });
package/dist/generate.cjs CHANGED
File without changes
package/dist/utils.cjs CHANGED
@@ -38,8 +38,7 @@ __export(utils_exports, {
38
38
  registerDispose: () => registerDispose
39
39
  });
40
40
  module.exports = __toCommonJS(utils_exports);
41
- var import_static = require("@tamagui/static"),
42
- import_chalk = __toESM(require("chalk")),
41
+ var import_chalk = __toESM(require("chalk")),
43
42
  import_fs_extra = require("fs-extra"),
44
43
  import_node_path = require("node:path");
45
44
  async function getOptions({
@@ -55,14 +54,22 @@ async function getOptions({
55
54
  config = "";
56
55
  try {
57
56
  config = await getDefaultTamaguiConfigPath(), pkgJson = await (0, import_fs_extra.readJSON)((0, import_node_path.join)(root, "package.json"));
58
- } catch {}
57
+ } catch {
58
+ loadTamaguiOptions && console.warn(import_chalk.default.yellow(`Warning: no tamagui.config.ts found in ${root}. Commands that need a config may fail.`));
59
+ }
59
60
  const filledOptions = {
60
- platform: "native",
61
- components: ["tamagui"],
62
- config,
63
- ...tamaguiOptions
64
- },
65
- finalOptions = loadTamaguiOptions ? (0, import_static.loadTamaguiBuildConfigSync)(filledOptions) : filledOptions;
61
+ platform: "native",
62
+ components: ["tamagui"],
63
+ config,
64
+ ...tamaguiOptions
65
+ };
66
+ let finalOptions = filledOptions;
67
+ if (loadTamaguiOptions) {
68
+ const {
69
+ loadTamaguiBuildConfigSync
70
+ } = require("@tamagui/static/loadTamagui");
71
+ finalOptions = loadTamaguiBuildConfigSync(filledOptions);
72
+ }
66
73
  return {
67
74
  mode: process.env.NODE_ENV === "production" ? "production" : "development",
68
75
  root,
@@ -91,11 +98,16 @@ async function getDefaultTamaguiConfigPath() {
91
98
  if (!found) throw new Error("No found tamagui.config.ts");
92
99
  return cachedPath = found, found;
93
100
  }
94
- const loadTamagui = async opts => await (0, import_static.loadTamagui)({
95
- components: ["tamagui"],
96
- ...opts,
97
- config: opts.config ?? (await getDefaultTamaguiConfigPath())
98
- }),
101
+ const loadTamagui = async opts => {
102
+ const {
103
+ loadTamagui: loadTamaguiStatic
104
+ } = require("@tamagui/static/loadTamagui");
105
+ return await loadTamaguiStatic({
106
+ components: ["tamagui"],
107
+ ...opts,
108
+ config: opts.config ?? (await getDefaultTamaguiConfigPath())
109
+ });
110
+ },
99
111
  disposers = /* @__PURE__ */new Set();
100
112
  function registerDispose(cb) {
101
113
  disposers.add(cb);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamagui/cli",
3
- "version": "2.0.0-rc.3",
3
+ "version": "2.0.0-rc.30",
4
4
  "bin": {
5
5
  "tama": "./dist/index.cjs",
6
6
  "tamagui": "./dist/index.cjs"
@@ -22,14 +22,15 @@
22
22
  "watch": "bun run build --skip-native --watch",
23
23
  "clean": "tamagui-build clean",
24
24
  "clean:build": "tamagui-build clean:build",
25
- "test": "vitest run"
25
+ "test": "vitest run",
26
+ "test:web": "bun run test"
26
27
  },
27
28
  "dependencies": {
28
- "@tamagui/create-theme": "2.0.0-rc.3",
29
- "@tamagui/generate-themes": "2.0.0-rc.3",
30
- "@tamagui/static": "2.0.0-rc.3",
31
- "@tamagui/types": "2.0.0-rc.3",
32
- "@tamagui/vite-plugin": "2.0.0-rc.3",
29
+ "@tamagui/create-theme": "2.0.0-rc.30",
30
+ "@tamagui/generate-themes": "2.0.0-rc.30",
31
+ "@tamagui/static": "2.0.0-rc.30",
32
+ "@tamagui/types": "2.0.0-rc.30",
33
+ "@tamagui/vite-plugin": "2.0.0-rc.30",
33
34
  "arg": "^5.0.2",
34
35
  "chalk": "^4.1.2",
35
36
  "change-case": "^4.1.2",
@@ -48,7 +49,7 @@
48
49
  "url": "^0.11.0"
49
50
  },
50
51
  "devDependencies": {
51
- "@tamagui/build": "2.0.0-rc.3",
52
+ "@tamagui/build": "2.0.0-rc.30",
52
53
  "@types/chokidar": "^2.1.3",
53
54
  "@types/marked": "^5.0.0",
54
55
  "vitest": "4.0.4"