@mochi-css/tsuki 3.0.0 → 4.0.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.
Files changed (3) hide show
  1. package/README.md +1 -1
  2. package/dist/index.js +35 -63
  3. package/package.json +2 -2
package/README.md CHANGED
@@ -15,7 +15,7 @@ To get more info, run it with `-h` or `--help` option.
15
15
  ## What `tsuki` sets up
16
16
 
17
17
  During initialization, `tsuki` installs the required packages and creates a `mochi.config.ts` file in your project root.
18
- This file is the single place to configure all Mochi-CSS options (`roots`, `extractors`, `plugins`, etc.) - all integrations load it automatically.
18
+ This file is the single place to configure all Mochi-CSS options (`roots`, `plugins`, `splitCss`, etc.) - all integrations load it automatically.
19
19
 
20
20
  ## Presets
21
21
 
package/dist/index.js CHANGED
@@ -138,7 +138,7 @@ var ModuleRunner = class {
138
138
  //#endregion
139
139
  //#region src/version.ts
140
140
  function mochiPackage(name) {
141
- return `${name}@^${parseInt("3.0.0".split(".")[0] ?? "0", 10)}.0.0`;
141
+ return `${name}@^${parseInt("4.0.0".split(".")[0] ?? "0", 10)}.0.0`;
142
142
  }
143
143
 
144
144
  //#endregion
@@ -442,59 +442,16 @@ function findMochiConfig() {
442
442
  return mochiConfigNames.find((name) => fsExtra.existsSync(name));
443
443
  }
444
444
  const defaultMochiConfigBase = dedent`
445
- import { defineConfig } from "@mochi-css/config"
445
+ import { defineConfig } from "@mochi-css/vanilla/config"
446
446
 
447
447
  export default defineConfig({})
448
448
  `;
449
449
  function defaultMochiConfigWithOptions(tmpDir, styledId) {
450
+ const importPath = styledId ? "@mochi-css/vanilla-react/config" : "@mochi-css/vanilla/config";
450
451
  const lines = [];
451
452
  if (tmpDir !== void 0) lines.push(` tmpDir: ${JSON.stringify(tmpDir)},`);
452
- if (styledId) lines.push(` plugins: [styledIdPlugin()],`);
453
453
  if (!styledId && lines.length === 0) return defaultMochiConfigBase;
454
- return `${styledId ? dedent`
455
- import { defineConfig } from "@mochi-css/config"
456
- import { styledIdPlugin } from "@mochi-css/builder"
457
- ` : `import { defineConfig } from "@mochi-css/config"`}\n\nexport default defineConfig({\n${lines.join("\n")}\n})\n`;
458
- }
459
- function addStyledIdPluginToObj(obj, configPath) {
460
- getPluginsElements(obj, configPath).push({
461
- type: "CallExpression",
462
- callee: {
463
- type: "Identifier",
464
- name: "styledIdPlugin"
465
- },
466
- arguments: []
467
- });
468
- }
469
- function addStyledIdToAst(mod, configPath) {
470
- const exportDefault = mod.$ast.body.find((s) => s.type === "ExportDefaultDeclaration");
471
- if (!exportDefault) throw new Error(`No default export found in ${configPath}`);
472
- const decl = exportDefault.declaration;
473
- if (decl["type"] === "ObjectExpression") {
474
- addStyledIdPluginToObj(decl, configPath);
475
- return;
476
- }
477
- if (decl["type"] === "CallExpression") {
478
- const firstArg = decl["arguments"][0];
479
- if (firstArg?.["type"] === "ObjectExpression") {
480
- addStyledIdPluginToObj(firstArg, configPath);
481
- return;
482
- }
483
- }
484
- throw new Error(`Failed to add styledIdPlugin to ${configPath}`);
485
- }
486
- async function addStyledIdToExistingConfig(configPath) {
487
- const content = await fs.readFile(configPath, "utf-8");
488
- if (content.includes("styledIdPlugin")) return;
489
- const mod = parseModule(content);
490
- mod.imports.$prepend({
491
- from: "@mochi-css/builder",
492
- imported: "styledIdPlugin",
493
- local: "styledIdPlugin"
494
- });
495
- addStyledIdToAst(mod, configPath);
496
- const { code } = generateCode(mod);
497
- await fs.writeFile(configPath, code);
454
+ return `import { defineConfig } from "${importPath}"\n\nexport default defineConfig({\n${lines.join("\n")}\n})\n`;
498
455
  }
499
456
  function getConfigObject(mod) {
500
457
  const exportDefault = mod.$ast.body.find((s) => s.type === "ExportDefaultDeclaration");
@@ -527,6 +484,12 @@ async function addTmpDirToExistingConfig(configPath, tmpDir) {
527
484
  const { code } = generateCode(mod);
528
485
  await fs.writeFile(configPath, code);
529
486
  }
487
+ async function patchToVanillaReact(configPath) {
488
+ const content = await fs.readFile(configPath, "utf-8");
489
+ if (content.includes("@mochi-css/vanilla-react")) return;
490
+ const patched = content.replace(/"@mochi-css\/vanilla\/config"/g, "\"@mochi-css/vanilla-react/config\"");
491
+ await fs.writeFile(configPath, patched);
492
+ }
530
493
  function createMochiConfigModule(options = {}) {
531
494
  const { styledId = false, tmpDir } = options;
532
495
  return {
@@ -545,19 +508,26 @@ function createMochiConfigModule(options = {}) {
545
508
  p.log.warn(`Could not automatically add tmpDir to ${existing} — add it manually`);
546
509
  }
547
510
  if (styledId) try {
548
- await addStyledIdToExistingConfig(existing);
549
- p.log.success("Added styledIdPlugin to mochi.config.ts");
511
+ await patchToVanillaReact(existing);
512
+ p.log.success("Switched mochi.config to @mochi-css/vanilla-react/config");
550
513
  } catch {
551
- p.log.warn(`Could not automatically add styledIdPlugin to ${existing} — add it manually`);
514
+ p.log.warn(`Could not patch ${existing} — change the import to @mochi-css/vanilla-react/config manually`);
552
515
  }
553
516
  }
554
- ctx.requirePackage(mochiPackage("@mochi-css/config"));
517
+ ctx.requirePackage(mochiPackage("@mochi-css/vanilla"));
518
+ if (styledId) ctx.requirePackage(mochiPackage("@mochi-css/vanilla-react"));
555
519
  }
556
520
  };
557
521
  }
558
522
 
559
523
  //#endregion
560
524
  //#region src/modules/uiFramework.ts
525
+ async function patchConfigForReact(configPath) {
526
+ const content = await fs.readFile(configPath, "utf-8");
527
+ if (content.includes("@mochi-css/vanilla-react")) return;
528
+ const patched = content.replace(/"@mochi-css\/vanilla\/config"/g, "\"@mochi-css/vanilla-react/config\"");
529
+ await fs.writeFile(configPath, patched);
530
+ }
561
531
  function createUiFrameworkModule(options = {}) {
562
532
  return {
563
533
  id: "ui-framework",
@@ -565,14 +535,19 @@ function createUiFrameworkModule(options = {}) {
565
535
  async run(ctx) {
566
536
  const { framework: cliOption } = ctx.moduleOptions;
567
537
  let useReact = options.auto === true || cliOption === "react";
568
- if (useReact) {
569
- ctx.requirePackage(mochiPackage("@mochi-css/react"), false);
570
- return;
538
+ if (!useReact) {
539
+ if (ctx.nonInteractive) return;
540
+ const confirmed = await p.confirm({ message: "Do you use React?" });
541
+ if (p.isCancel(confirmed) || !confirmed) return;
542
+ useReact = true;
543
+ }
544
+ ctx.requirePackage(mochiPackage("@mochi-css/vanilla-react"), false);
545
+ const configPath = findMochiConfig();
546
+ if (configPath) try {
547
+ await patchConfigForReact(configPath);
548
+ } catch {
549
+ p.log.warn(`Could not patch ${configPath} — change the import to @mochi-css/vanilla-react/config manually`);
571
550
  }
572
- if (ctx.nonInteractive) return;
573
- const confirmed = await p.confirm({ message: "Do you use React?" });
574
- if (p.isCancel(confirmed) || !confirmed) return;
575
- useReact = true;
576
551
  }
577
552
  };
578
553
  }
@@ -583,10 +558,7 @@ const vitePreset = {
583
558
  id: "vite",
584
559
  name: "Vite",
585
560
  setup(runner) {
586
- runner.register(createMochiConfigModule({
587
- styledId: true,
588
- tmpDir: ".mochi"
589
- }));
561
+ runner.register(createMochiConfigModule({ tmpDir: ".mochi" }));
590
562
  runner.register(createPostcssModule());
591
563
  runner.register(viteModule);
592
564
  runner.register(createUiFrameworkModule());
@@ -688,7 +660,7 @@ const presets = {
688
660
 
689
661
  //#endregion
690
662
  //#region src/index.ts
691
- program.name("tsuki").description("Add mochi-css to your project").version("3.0.0").addOption(new Option("-p, --preset <preset>", "Preset to use").choices([
663
+ program.name("tsuki").description("Add mochi-css to your project").version("4.0.0").addOption(new Option("-p, --preset <preset>", "Preset to use").choices([
692
664
  "vite",
693
665
  "nextjs",
694
666
  "lib"
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mochi-css/tsuki",
3
3
  "repository": "git@github.com:Niikelion/mochi-css.git",
4
- "version": "3.0.0",
4
+ "version": "4.0.0",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "bin": "./dist/index.js",
@@ -15,7 +15,7 @@
15
15
  "manual": "jiti scripts/manual.ts",
16
16
  "lint": "eslint src",
17
17
  "lint:fix": "eslint src --fix",
18
- "format": "prettier --write"
18
+ "format": "prettier --write ."
19
19
  },
20
20
  "devDependencies": {
21
21
  "@mochi-css/shared-config": "^2.0.0",