@master/create-css 2.0.0-rc.81 → 2.0.0-rc.83

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/README.md CHANGED
@@ -26,6 +26,14 @@ Without `--yes`, TTY sessions ask about ESLint, MCP, AI guidance, and dependency
26
26
 
27
27
  Use `--minimal` for core framework setup only, or disable individual recommended integrations with `--no-eslint`, `--no-mcp`, or `--no-ai`.
28
28
 
29
+ Use `--mode <mode>` when the framework integration should be configured for a specific rendering mode during setup:
30
+
31
+ ```bash
32
+ npm create @master/css@rc -- --framework nextjs --mode static --yes
33
+ ```
34
+
35
+ Supported `--mode` values are `runtime`, `static`, `progressive`, and `pre-render`. Mode setup is supported for `vite`, `react`, `react-router`, `tanstack-start`, `vue`, `nextjs`, `nuxt`, `astro`, `webpack`, `rspack`, `rsbuild`, `laravel`, and `lit`; Laravel supports `static` only.
36
+
29
37
  If you do not have a project yet, create one first:
30
38
 
31
39
  ```bash
@@ -52,10 +60,18 @@ npx @master/create-css@rc add --no-mcp --no-ai
52
60
  npx @master/create-css@rc add --json --minimal --eslint
53
61
  ```
54
62
 
63
+ ```bash
64
+ npx @master/create-css@rc add --framework nextjs --mode runtime --yes
65
+ ```
66
+
67
+ ```bash
68
+ npx @master/create-css@rc add --framework webpack --mode static --yes
69
+ ```
70
+
55
71
  Supported `--framework` values:
56
72
 
57
73
  ```txt
58
- auto, vite, react, react-router, vue, nextjs, svelte, nuxt, astro, webpack, rspack, rsbuild, laravel, lit, angular, none
74
+ auto, vite, react, react-router, tanstack-start, vue, nextjs, svelte, nuxt, astro, webpack, rspack, rsbuild, laravel, lit, angular, none
59
75
  ```
60
76
 
61
77
  SvelteKit setup is delegated to the Svelte CLI add-on:
package/dist/core.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import { RenderingMode } from "./modes.js";
2
+
1
3
  //#region src/core.d.ts
2
4
  type CommandFramework = 'none' | 'vite' | 'react' | 'react-router' | 'tanstack-start' | 'vue' | 'nextjs' | 'svelte' | 'nuxt' | 'astro' | 'webpack' | 'rspack' | 'rsbuild' | 'laravel' | 'lit' | 'angular';
3
5
  type CommandFrameworkOption = CommandFramework | 'auto';
@@ -13,6 +15,7 @@ interface CommandOptions {
13
15
  dryRun?: boolean;
14
16
  json?: boolean;
15
17
  yes?: boolean;
18
+ mode?: RenderingMode;
16
19
  }
17
20
  type InstallResolution = CommandPackageManager | false | 'detected' | undefined;
18
21
  type PromptQuestion = (question: string) => Promise<string>;
package/dist/core.js CHANGED
@@ -1,9 +1,10 @@
1
+ import { formatRenderingModes, isRenderingMode } from "./modes.js";
1
2
  import { applySetupPlan, createSetupPlan } from "./index.js";
2
3
  import { existsSync, readFileSync } from "node:fs";
3
4
  import { dirname, join, resolve } from "node:path";
4
5
  import { createInterface } from "node:readline/promises";
5
6
  import { fileURLToPath } from "node:url";
6
- import { Command } from "commander";
7
+ import { Command, InvalidArgumentError } from "commander";
7
8
  //#region src/core.ts
8
9
  const __dirname = dirname(fileURLToPath(import.meta.url));
9
10
  const pkg = JSON.parse(readFileSync(resolve(__dirname, "../package.json"), "utf8"));
@@ -15,7 +16,7 @@ const newProjectCommands = [
15
16
  async function runProgram(argv = process.argv) {
16
17
  const program = new Command();
17
18
  program.name("create-css").description(pkg.description).version(pkg.version || "0.0.0");
18
- const configure = (command) => command.option("-C, --cwd <path>", "Project root to update.").option("--framework <framework>", "Framework: auto, vite, react, react-router, tanstack-start, vue, nextjs, svelte, nuxt, astro, webpack, rspack, rsbuild, laravel, lit, angular, none.", "auto").option("--eslint", "Add the Master CSS recommended ESLint flat config.").option("--no-eslint", "Skip the Master CSS recommended ESLint flat config.").option("--mcp", "Add the Master CSS MCP package and print the stdio registration command.").option("--no-mcp", "Skip the Master CSS MCP package and registration command.").option("--ai", "Add Master CSS guidance to AGENTS.md.").option("--no-ai", "Skip Master CSS guidance for coding agents.").option("--minimal", "Only add core Master CSS framework setup.").option("--install <package-manager>", "Run dependency installation with npm, pnpm, yarn, or bun after edits.").option("--no-install", "Do not run dependency installation.").option("--dry-run", "Print the setup plan without writing files.").option("--json", "Print machine-readable JSON.").option("-y, --yes", "Accept recommended defaults and run package installation with the detected package manager.");
19
+ const configure = (command) => command.option("-C, --cwd <path>", "Project root to update.").option("--framework <framework>", "Framework: auto, vite, react, react-router, tanstack-start, vue, nextjs, svelte, nuxt, astro, webpack, rspack, rsbuild, laravel, lit, angular, none.", "auto").option("--eslint", "Add the Master CSS recommended ESLint flat config.").option("--no-eslint", "Skip the Master CSS recommended ESLint flat config.").option("--mcp", "Add the Master CSS MCP package and print the stdio registration command.").option("--no-mcp", "Skip the Master CSS MCP package and registration command.").option("--ai", "Add Master CSS guidance to AGENTS.md.").option("--no-ai", "Skip Master CSS guidance for coding agents.").option("--minimal", "Only add core Master CSS framework setup.").option("--mode <mode>", `Rendering mode: ${formatRenderingModes()}.`, parseRenderingModeOption).option("--install <package-manager>", "Run dependency installation with npm, pnpm, yarn, or bun after edits.").option("--no-install", "Do not run dependency installation.").option("--dry-run", "Print the setup plan without writing files.").option("--json", "Print machine-readable JSON.").option("-y, --yes", "Accept recommended defaults and run package installation with the detected package manager.");
19
20
  configure(program).argument("[project name]", "Deprecated. The installer now updates the current project; use --cwd for another root.").action(async (projectName, options) => {
20
21
  if (projectName && projectName !== "add") program.error(`Project scaffolding is not provided by @master/create-css. Create a Vite project first, then run the installer from the project root:\n\n${formatNewProjectCommands()}`);
21
22
  await runAdd(options);
@@ -37,14 +38,16 @@ async function runAdd(options) {
37
38
  prompt?.close();
38
39
  }
39
40
  const planInstall = resolvedOptions.install === "detected" ? void 0 : resolvedOptions.install;
40
- const plan = createSetupPlan({
41
+ const plan = createCommandSetupPlan({
41
42
  root,
42
43
  framework: options.framework,
43
44
  eslint: resolvedOptions.eslint,
44
45
  mcp: resolvedOptions.mcp,
45
46
  ai: resolvedOptions.ai,
46
- install: planInstall
47
+ install: planInstall,
48
+ mode: options.mode
47
49
  });
50
+ if (!plan) return;
48
51
  if (options.dryRun || options.json) {
49
52
  process.stdout.write(`${JSON.stringify(plan, null, 2)}\n`);
50
53
  return;
@@ -52,6 +55,18 @@ async function runAdd(options) {
52
55
  applySetupPlan(plan, { install: resolvedOptions.install === "detected" ? plan.packageManager : resolvedOptions.install });
53
56
  if (!options.json) printSummary(plan);
54
57
  }
58
+ function createCommandSetupPlan(options) {
59
+ try {
60
+ return createSetupPlan(options);
61
+ } catch (error) {
62
+ if (error instanceof Error) {
63
+ process.stderr.write(`${error.message}\n`);
64
+ process.exitCode = 1;
65
+ return;
66
+ }
67
+ throw error;
68
+ }
69
+ }
55
70
  async function resolveCommandOptions(options, prompt) {
56
71
  const question = options.yes ? void 0 : prompt;
57
72
  return {
@@ -83,6 +98,10 @@ async function confirm(question, prompt) {
83
98
  function shouldPrompt(options) {
84
99
  return !options.yes && !options.json && !options.dryRun && Boolean(process.stdin.isTTY) && Boolean(process.stdout.isTTY);
85
100
  }
101
+ function parseRenderingModeOption(value) {
102
+ if (isRenderingMode(value)) return value;
103
+ throw new InvalidArgumentError(`Invalid rendering mode "${value}". Supported modes: ${formatRenderingModes()}.`);
104
+ }
86
105
  function createTTYPrompt() {
87
106
  const input = process.stdin;
88
107
  const output = process.stdout;
package/dist/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import { RenderingMode } from "./modes.js";
2
+
1
3
  //#region src/index.d.ts
2
4
  type Framework = 'none' | 'vite' | 'react' | 'react-router' | 'tanstack-start' | 'vue' | 'nextjs' | 'svelte' | 'nuxt' | 'astro' | 'webpack' | 'rspack' | 'rsbuild' | 'laravel' | 'lit' | 'angular';
3
5
  type FrameworkOption = Framework | 'auto';
@@ -13,6 +15,7 @@ interface SetupOptions {
13
15
  install?: PackageManager | false;
14
16
  yes?: boolean;
15
17
  packageTag?: string;
18
+ mode?: RenderingMode;
16
19
  }
17
20
  interface PlannedDependency {
18
21
  name: string;
@@ -38,6 +41,7 @@ interface SetupPlan {
38
41
  files: PlannedFileChange[];
39
42
  commands: PlannedCommand[];
40
43
  warnings: string[];
44
+ mode?: RenderingMode;
41
45
  summary: {
42
46
  dependencies: number;
43
47
  filesToCreate: number;
@@ -50,4 +54,4 @@ declare function createSetupPlan(options?: SetupOptions): SetupPlan;
50
54
  declare function applySetupPlan(plan: SetupPlan, options?: SetupOptions): void;
51
55
  declare function applySetup(options?: SetupOptions): SetupPlan;
52
56
  //#endregion
53
- export { FileAction, Framework, FrameworkOption, PackageManager, PlannedCommand, PlannedDependency, PlannedFileChange, SetupOptions, SetupPlan, applySetup, applySetupPlan, createSetupPlan };
57
+ export { FileAction, Framework, FrameworkOption, PackageManager, PlannedCommand, PlannedDependency, PlannedFileChange, type RenderingMode, SetupOptions, SetupPlan, applySetup, applySetupPlan, createSetupPlan };
package/dist/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { AGENT_RULES_BLOCK, CANONICAL_ESLINT_CONFIG, MASTER_CSS_PACKAGES } from "./constants.js";
2
- import { addAngularRuntimeSetup, addLitShadowRuntime, addMasterCSSAstroIntegration, addMasterCSSEslintConfig, addMasterCSSImportToStylesheet, addMasterCSSNextConfig, addMasterCSSNuxtModule, addMasterCSSRsbuildPlugin, addMasterCSSRspackPlugin, addMasterCSSStaticVitePlugin, addMasterCSSTanStackStartVitePlugin, addMasterCSSVitePlugin, addReactRouterRootCSSImport, addTanStackStartRootCSSImport, addViteClientTypes, createAstroConfig, createMasterCSSStylesheet, createNextConfig, createNuxtConfig, createRsbuildConfig, createRspackConfig, createStaticViteConfig, createViteConfig } from "./transforms.js";
2
+ import { resolveRenderingMode } from "./modes.js";
3
+ import { addAngularRuntimeSetup, addLitShadowRuntime, addMasterCSSAstroIntegration, addMasterCSSEslintConfig, addMasterCSSImportToStylesheet, addMasterCSSNextConfig, addMasterCSSNuxtModule, addMasterCSSRsbuildPlugin, addMasterCSSRspackPlugin, addMasterCSSStaticVitePlugin, addMasterCSSTanStackStartVitePlugin, addMasterCSSVitePlugin, addMasterCSSWebpackPlugin, addReactRouterRootCSSImport, addTanStackStartRootCSSImport, addViteClientTypes, createAstroConfig, createMasterCSSStylesheet, createNextConfig, createNuxtConfig, createRsbuildConfig, createRspackConfig, createStaticViteConfig, createViteConfig, createWebpackConfig } from "./transforms.js";
3
4
  import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
4
5
  import { dirname, join, resolve } from "node:path";
5
6
  import { spawnSync } from "node:child_process";
@@ -15,6 +16,8 @@ function createSetupPlan(options = {}) {
15
16
  const packageJSON = readPackageJSON(root);
16
17
  const packageManager = resolvePackageManager(root, packageJSON, options.install || void 0);
17
18
  const framework = resolveFramework(root, packageJSON, options.framework || "auto");
19
+ const mode = resolveRenderingMode(options.mode);
20
+ assertFrameworkSupportsMode(framework, mode);
18
21
  const version = options.packageTag || "rc";
19
22
  const eslint = resolveRecommendedOption(options.eslint, options.minimal);
20
23
  const mcp = resolveRecommendedOption(options.mcp, options.minimal);
@@ -29,7 +32,7 @@ function createSetupPlan(options = {}) {
29
32
  });
30
33
  else {
31
34
  for (const dependency of dependenciesForFramework(framework, version)) pushDependency(dependencies, dependency.name, dependency.dev, dependency.version);
32
- files.push(...filesForFramework(root, framework, warnings));
35
+ files.push(...filesForFramework(root, framework, warnings, mode));
33
36
  }
34
37
  if (eslint) {
35
38
  pushDependency(dependencies, MASTER_CSS_PACKAGES.eslintConfig, true, version);
@@ -55,6 +58,7 @@ function createSetupPlan(options = {}) {
55
58
  files,
56
59
  commands,
57
60
  warnings,
61
+ ...mode ? { mode } : {},
58
62
  summary: {
59
63
  dependencies: dependencies.length,
60
64
  filesToCreate: files.filter((file) => file.action === "create").length,
@@ -87,13 +91,13 @@ function applySetup(options = {}) {
87
91
  applySetupPlan(plan, options);
88
92
  return plan;
89
93
  }
90
- function filesForFramework(root, framework, warnings) {
94
+ function filesForFramework(root, framework, warnings, mode) {
91
95
  switch (framework) {
92
96
  case "vite": return [planTextFile(root, firstExistingPath(root, [
93
97
  "vite.config.ts",
94
98
  "vite.config.js",
95
99
  "vite.config.mjs"
96
- ], "vite.config.js"), addMasterCSSVitePlugin, createViteConfig(), "Register the Master CSS Vite plugin."), planTextFile(root, firstExistingPath(root, [
100
+ ], "vite.config.js"), (content) => addMasterCSSVitePlugin(content, mode), createViteConfig(mode), "Register the Master CSS Vite plugin."), planTextFile(root, firstExistingPath(root, [
97
101
  "src/style.css",
98
102
  "src/index.css",
99
103
  "src/main.css"
@@ -102,13 +106,13 @@ function filesForFramework(root, framework, warnings) {
102
106
  "vite.config.ts",
103
107
  "vite.config.js",
104
108
  "vite.config.mjs"
105
- ], "vite.config.js"), addMasterCSSVitePlugin, createViteConfig(), "Register the Master CSS Vite plugin."), planTextFile(root, firstExistingPath(root, ["src/index.css", "src/style.css"], "src/index.css"), addMasterCSSImportToStylesheet, createMasterCSSStylesheet(), "Create or update the React project CSS entry.")];
109
+ ], "vite.config.js"), (content) => addMasterCSSVitePlugin(content, mode), createViteConfig(mode), "Register the Master CSS Vite plugin."), planTextFile(root, firstExistingPath(root, ["src/index.css", "src/style.css"], "src/index.css"), addMasterCSSImportToStylesheet, createMasterCSSStylesheet(), "Create or update the React project CSS entry.")];
106
110
  case "react-router": {
107
111
  const files = [planTextFile(root, firstExistingPath(root, [
108
112
  "vite.config.ts",
109
113
  "vite.config.js",
110
114
  "vite.config.mjs"
111
- ], "vite.config.ts"), addMasterCSSVitePlugin, createViteConfig(), "Register the Master CSS Vite plugin."), planTextFile(root, "app/app.css", addMasterCSSImportToStylesheet, createMasterCSSStylesheet(), "Create or update the React Router app stylesheet entry.")];
115
+ ], "vite.config.ts"), (content) => addMasterCSSVitePlugin(content, mode), createViteConfig(mode), "Register the Master CSS Vite plugin."), planTextFile(root, "app/app.css", addMasterCSSImportToStylesheet, createMasterCSSStylesheet(), "Create or update the React Router app stylesheet entry.")];
112
116
  const rootEntryPath = findExistingPath(root, [
113
117
  "app/root.tsx",
114
118
  "app/root.jsx",
@@ -120,11 +124,12 @@ function filesForFramework(root, framework, warnings) {
120
124
  return files;
121
125
  }
122
126
  case "tanstack-start": {
127
+ const pluginMode = mode ?? "runtime";
123
128
  const files = [planTextFile(root, firstExistingPath(root, [
124
129
  "vite.config.ts",
125
130
  "vite.config.js",
126
131
  "vite.config.mjs"
127
- ], "vite.config.ts"), addMasterCSSTanStackStartVitePlugin, createStaticViteConfig(), "Register the Master CSS Vite plugin in static mode."), planTextFile(root, "src/styles/app.css", addMasterCSSImportToStylesheet, createMasterCSSStylesheet(), "Create or update the TanStack Start stylesheet entry.")];
132
+ ], "vite.config.ts"), (content) => addMasterCSSTanStackStartVitePlugin(content, pluginMode), createViteConfig(pluginMode), `Register the Master CSS Vite plugin in ${pluginMode} mode.`), planTextFile(root, "src/styles/app.css", addMasterCSSImportToStylesheet, createMasterCSSStylesheet(), "Create or update the TanStack Start stylesheet entry.")];
128
133
  const rootEntryPath = findExistingPath(root, [
129
134
  "src/routes/__root.tsx",
130
135
  "src/routes/__root.jsx",
@@ -139,7 +144,7 @@ function filesForFramework(root, framework, warnings) {
139
144
  "vite.config.ts",
140
145
  "vite.config.js",
141
146
  "vite.config.mjs"
142
- ], "vite.config.ts"), addMasterCSSVitePlugin, createViteConfig(), "Register the Master CSS Vite plugin."), planTextFile(root, firstExistingPath(root, [
147
+ ], "vite.config.ts"), (content) => addMasterCSSVitePlugin(content, mode), createViteConfig(mode), "Register the Master CSS Vite plugin."), planTextFile(root, firstExistingPath(root, [
143
148
  "src/assets/main.css",
144
149
  "src/style.css",
145
150
  "src/main.css"
@@ -148,13 +153,13 @@ function filesForFramework(root, framework, warnings) {
148
153
  "next.config.ts",
149
154
  "next.config.mjs",
150
155
  "next.config.js"
151
- ], "next.config.js"), addMasterCSSNextConfig, createNextConfig(), "Register the Master CSS Next.js adapter."), planTextFile(root, "app/globals.css", addMasterCSSImportToStylesheet, createMasterCSSStylesheet(), "Create or update the Next.js global stylesheet entry.")];
152
- case "nuxt": return [planTextFile(root, firstExistingPath(root, ["nuxt.config.ts", "nuxt.config.js"], "nuxt.config.ts"), addMasterCSSNuxtModule, createNuxtConfig(), "Register the Master CSS Nuxt module."), planTextFile(root, "assets/css/master.css", addMasterCSSImportToStylesheet, createMasterCSSStylesheet(), "Create the Nuxt CSS entry referenced by nuxt.config.")];
156
+ ], "next.config.js"), (content) => addMasterCSSNextConfig(content, mode), createNextConfig(mode), "Register the Master CSS Next.js adapter."), planTextFile(root, "app/globals.css", addMasterCSSImportToStylesheet, createMasterCSSStylesheet(), "Create or update the Next.js global stylesheet entry.")];
157
+ case "nuxt": return [planTextFile(root, firstExistingPath(root, ["nuxt.config.ts", "nuxt.config.js"], "nuxt.config.ts"), (content) => addMasterCSSNuxtModule(content, mode), createNuxtConfig(mode), "Register the Master CSS Nuxt module."), planTextFile(root, "assets/css/master.css", addMasterCSSImportToStylesheet, createMasterCSSStylesheet(), "Create the Nuxt CSS entry referenced by nuxt.config.")];
153
158
  case "astro": return [planTextFile(root, firstExistingPath(root, [
154
159
  "astro.config.mjs",
155
160
  "astro.config.js",
156
161
  "astro.config.ts"
157
- ], "astro.config.mjs"), addMasterCSSAstroIntegration, createAstroConfig(), "Register the Master CSS Astro integration."), planTextFile(root, "src/styles/global.css", addMasterCSSImportToStylesheet, createMasterCSSStylesheet(), "Create the Astro project CSS entry.")];
162
+ ], "astro.config.mjs"), (content) => addMasterCSSAstroIntegration(content, mode), createAstroConfig(mode), "Register the Master CSS Astro integration."), planTextFile(root, "src/styles/global.css", addMasterCSSImportToStylesheet, createMasterCSSStylesheet(), "Create the Astro project CSS entry.")];
158
163
  case "laravel": {
159
164
  const viteConfigPath = findExistingPath(root, ["vite.config.ts", "vite.config.js"]);
160
165
  const files = [planTextFile(root, "resources/css/app.css", addMasterCSSImportToStylesheet, createMasterCSSStylesheet(), "Create or update the Laravel Vite CSS entry.")];
@@ -168,7 +173,7 @@ function filesForFramework(root, framework, warnings) {
168
173
  "vite.config.ts",
169
174
  "vite.config.js",
170
175
  "vite.config.mjs"
171
- ], "vite.config.ts"), addMasterCSSVitePlugin, createViteConfig(), "Register the Master CSS Vite plugin."),
176
+ ], "vite.config.ts"), (content) => addMasterCSSVitePlugin(content, mode), createViteConfig(mode), "Register the Master CSS Vite plugin."),
172
177
  planTextFile(root, "src/index.css", addMasterCSSImportToStylesheet, createMasterCSSStylesheet(), "Create or update the Lit project CSS entry."),
173
178
  planTextFile(root, "src/vite-env.d.ts", addViteClientTypes, `/// <reference types="vite/client" />
174
179
  /// <reference types="@master/css-integration/client" />
@@ -192,17 +197,31 @@ function filesForFramework(root, framework, warnings) {
192
197
  "rspack.config.mjs",
193
198
  "rspack.config.js",
194
199
  "rspack.config.cjs"
195
- ], "rspack.config.mjs"), addMasterCSSRspackPlugin, createRspackConfig(), "Register the Master CSS Webpack-compatible plugin in the Rspack config."), planTextFile(root, "src/index.css", addMasterCSSImportToStylesheet, createMasterCSSStylesheet(), "Create or update the project CSS entry for Rspack.")];
200
+ ], "rspack.config.mjs"), (content) => addMasterCSSRspackPlugin(content, mode), createRspackConfig(mode), "Register the Master CSS Webpack-compatible plugin in the Rspack config."), planTextFile(root, "src/index.css", addMasterCSSImportToStylesheet, createMasterCSSStylesheet(), "Create or update the project CSS entry for Rspack.")];
196
201
  case "rsbuild": return [planTextFile(root, firstExistingPath(root, [
197
202
  "rsbuild.config.ts",
198
203
  "rsbuild.config.mts",
199
204
  "rsbuild.config.mjs",
200
205
  "rsbuild.config.js"
201
- ], "rsbuild.config.ts"), addMasterCSSRsbuildPlugin, createRsbuildConfig(), "Register the Master CSS Webpack-compatible plugin through Rsbuild tools.rspack."), planTextFile(root, "src/index.css", addMasterCSSImportToStylesheet, createMasterCSSStylesheet(), "Create or update the project CSS entry for Rsbuild.")];
202
- case "webpack": return [planTextFile(root, "src/index.css", addMasterCSSImportToStylesheet, createMasterCSSStylesheet(), "Create or update the project CSS entry for Webpack.")];
206
+ ], "rsbuild.config.ts"), (content) => addMasterCSSRsbuildPlugin(content, mode), createRsbuildConfig(mode), "Register the Master CSS Webpack-compatible plugin through Rsbuild tools.rspack."), planTextFile(root, "src/index.css", addMasterCSSImportToStylesheet, createMasterCSSStylesheet(), "Create or update the project CSS entry for Rsbuild.")];
207
+ case "webpack": return [planTextFile(root, firstExistingPath(root, [
208
+ "webpack.config.ts",
209
+ "webpack.config.mts",
210
+ "webpack.config.mjs",
211
+ "webpack.config.js",
212
+ "webpack.config.cjs"
213
+ ], "webpack.config.mjs"), (content) => addMasterCSSWebpackPlugin(content, mode), createWebpackConfig(mode), "Register the Master CSS Webpack plugin."), planTextFile(root, "src/index.css", addMasterCSSImportToStylesheet, createMasterCSSStylesheet(), "Create or update the project CSS entry for Webpack.")];
203
214
  default: return [planTextFile(root, "src/master.css", addMasterCSSImportToStylesheet, createMasterCSSStylesheet(), "Create a standalone Master CSS stylesheet entry.")];
204
215
  }
205
216
  }
217
+ function assertFrameworkSupportsMode(framework, mode) {
218
+ if (!mode) return;
219
+ if (framework === "laravel") {
220
+ if (mode === "static") return;
221
+ throw new Error(`--mode ${mode} is not supported for laravel. The Laravel installer only supports --mode static.`);
222
+ }
223
+ if (framework === "angular" || framework === "svelte" || framework === "none") throw new Error(`--mode is not supported for ${framework}. Supported frameworks: vite, react, react-router, tanstack-start, vue, nextjs, nuxt, astro, webpack, rspack, rsbuild, laravel, lit.`);
224
+ }
206
225
  function dependenciesForFramework(framework, version) {
207
226
  const dependencies = [{
208
227
  name: MASTER_CSS_PACKAGES.css,
@@ -311,6 +330,7 @@ function resolveFramework(root, packageJSON, framework) {
311
330
  ...packageJSON?.dependencies,
312
331
  ...packageJSON?.devDependencies
313
332
  };
333
+ const hasWebpackConfig = existsSync(join(root, "webpack.config.ts")) || existsSync(join(root, "webpack.config.mts")) || existsSync(join(root, "webpack.config.mjs")) || existsSync(join(root, "webpack.config.js")) || existsSync(join(root, "webpack.config.cjs"));
314
334
  if (existsSync(join(root, "next.config.js")) || existsSync(join(root, "next.config.mjs")) || existsSync(join(root, "next.config.ts")) || dependencies.next) return "nextjs";
315
335
  if (existsSync(join(root, "svelte.config.js")) || existsSync(join(root, "svelte.config.mjs")) || dependencies["@sveltejs/kit"]) return "svelte";
316
336
  if (existsSync(join(root, "nuxt.config.ts")) || existsSync(join(root, "nuxt.config.js")) || dependencies.nuxt) return "nuxt";
@@ -319,12 +339,13 @@ function resolveFramework(root, packageJSON, framework) {
319
339
  if (dependencies["laravel-vite-plugin"] || existsSync(join(root, "artisan"))) return "laravel";
320
340
  if (existsSync(join(root, "rsbuild.config.ts")) || existsSync(join(root, "rsbuild.config.mts")) || existsSync(join(root, "rsbuild.config.mjs")) || existsSync(join(root, "rsbuild.config.js")) || dependencies["@rsbuild/core"]) return "rsbuild";
321
341
  if (existsSync(join(root, "rspack.config.ts")) || existsSync(join(root, "rspack.config.mts")) || existsSync(join(root, "rspack.config.mjs")) || existsSync(join(root, "rspack.config.js")) || existsSync(join(root, "rspack.config.cjs")) || dependencies["@rspack/core"] || dependencies["@rspack/cli"]) return "rspack";
342
+ if (hasWebpackConfig) return "webpack";
322
343
  if (existsSync(join(root, "react-router.config.ts")) || existsSync(join(root, "react-router.config.js")) || existsSync(join(root, "react-router.config.mjs")) || existsSync(join(root, "react-router.config.mts")) || dependencies["@react-router/dev"]) return "react-router";
323
344
  if (dependencies["@tanstack/react-start"]) return "tanstack-start";
324
345
  if (dependencies.vue || dependencies["@vitejs/plugin-vue"] || existsSync(join(root, "src/App.vue"))) return "vue";
325
346
  if (dependencies.lit) return "lit";
326
347
  if (dependencies.react || dependencies["react-dom"]) return "react";
327
- if (existsSync(join(root, "webpack.config.js")) || existsSync(join(root, "webpack.config.mjs")) || dependencies.webpack) return "webpack";
348
+ if (dependencies.webpack) return "webpack";
328
349
  if (existsSync(join(root, "vite.config.ts")) || existsSync(join(root, "vite.config.js")) || dependencies.vite) return "vite";
329
350
  return "none";
330
351
  }
@@ -0,0 +1,8 @@
1
+ //#region src/modes.d.ts
2
+ declare const renderingModes: readonly ["runtime", "static", "progressive", "pre-render"];
3
+ type RenderingMode = typeof renderingModes[number];
4
+ declare function isRenderingMode(value: unknown): value is RenderingMode;
5
+ declare function formatRenderingModes(): string;
6
+ declare function resolveRenderingMode(value: unknown): RenderingMode | undefined;
7
+ //#endregion
8
+ export { RenderingMode, formatRenderingModes, isRenderingMode, renderingModes, resolveRenderingMode };
package/dist/modes.js ADDED
@@ -0,0 +1,20 @@
1
+ //#region src/modes.ts
2
+ const renderingModes = [
3
+ "runtime",
4
+ "static",
5
+ "progressive",
6
+ "pre-render"
7
+ ];
8
+ function isRenderingMode(value) {
9
+ return renderingModes.includes(value);
10
+ }
11
+ function formatRenderingModes() {
12
+ return renderingModes.join(", ");
13
+ }
14
+ function resolveRenderingMode(value) {
15
+ if (value === void 0) return void 0;
16
+ if (isRenderingMode(value)) return value;
17
+ throw new Error(`Invalid rendering mode "${String(value)}". Supported modes: ${formatRenderingModes()}.`);
18
+ }
19
+ //#endregion
20
+ export { formatRenderingModes, isRenderingMode, renderingModes, resolveRenderingMode };
@@ -1,26 +1,30 @@
1
+ import { RenderingMode } from "./modes.js";
2
+
1
3
  //#region src/transforms.d.ts
2
4
  declare function addMasterCSSImportToStylesheet(content: string): string;
3
5
  declare function createMasterCSSStylesheet(): string;
4
- declare function addMasterCSSVitePlugin(content: string): string;
6
+ declare function addMasterCSSVitePlugin(content: string, mode?: RenderingMode): string;
5
7
  declare function addReactRouterRootCSSImport(content: string): string;
6
8
  declare function addTanStackStartRootCSSImport(content: string): string;
7
9
  declare function addMasterCSSStaticVitePlugin(content: string): string;
8
- declare function addMasterCSSTanStackStartVitePlugin(content: string): string;
9
- declare function addMasterCSSRspackPlugin(content: string): string;
10
- declare function addMasterCSSRsbuildPlugin(content: string): string;
11
- declare function createViteConfig(): string;
10
+ declare function addMasterCSSTanStackStartVitePlugin(content: string, mode?: RenderingMode): string;
11
+ declare function addMasterCSSRspackPlugin(content: string, mode?: RenderingMode): string;
12
+ declare function addMasterCSSWebpackPlugin(content: string, mode?: RenderingMode): string;
13
+ declare function addMasterCSSRsbuildPlugin(content: string, mode?: RenderingMode): string;
14
+ declare function createViteConfig(mode?: RenderingMode): string;
12
15
  declare function createStaticViteConfig(): string;
13
- declare function createRspackConfig(): string;
14
- declare function createRsbuildConfig(): string;
15
- declare function createNextConfig(): string;
16
- declare function addMasterCSSNextConfig(content: string): string;
17
- declare function addMasterCSSNuxtModule(content: string): string;
18
- declare function createNuxtConfig(): string;
19
- declare function addMasterCSSAstroIntegration(content: string): string;
20
- declare function createAstroConfig(): string;
16
+ declare function createRspackConfig(mode?: RenderingMode): string;
17
+ declare function createWebpackConfig(mode?: RenderingMode): string;
18
+ declare function createRsbuildConfig(mode?: RenderingMode): string;
19
+ declare function createNextConfig(mode?: RenderingMode): string;
20
+ declare function addMasterCSSNextConfig(content: string, mode?: RenderingMode): string;
21
+ declare function addMasterCSSNuxtModule(content: string, mode?: RenderingMode): string;
22
+ declare function createNuxtConfig(mode?: RenderingMode): string;
23
+ declare function addMasterCSSAstroIntegration(content: string, mode?: RenderingMode): string;
24
+ declare function createAstroConfig(mode?: RenderingMode): string;
21
25
  declare function addViteClientTypes(content: string): string;
22
26
  declare function addLitShadowRuntime(content: string): string;
23
27
  declare function addAngularRuntimeSetup(content: string): string;
24
28
  declare function addMasterCSSEslintConfig(content: string): string;
25
29
  //#endregion
26
- export { addAngularRuntimeSetup, addLitShadowRuntime, addMasterCSSAstroIntegration, addMasterCSSEslintConfig, addMasterCSSImportToStylesheet, addMasterCSSNextConfig, addMasterCSSNuxtModule, addMasterCSSRsbuildPlugin, addMasterCSSRspackPlugin, addMasterCSSStaticVitePlugin, addMasterCSSTanStackStartVitePlugin, addMasterCSSVitePlugin, addReactRouterRootCSSImport, addTanStackStartRootCSSImport, addViteClientTypes, createAstroConfig, createMasterCSSStylesheet, createNextConfig, createNuxtConfig, createRsbuildConfig, createRspackConfig, createStaticViteConfig, createViteConfig };
30
+ export { addAngularRuntimeSetup, addLitShadowRuntime, addMasterCSSAstroIntegration, addMasterCSSEslintConfig, addMasterCSSImportToStylesheet, addMasterCSSNextConfig, addMasterCSSNuxtModule, addMasterCSSRsbuildPlugin, addMasterCSSRspackPlugin, addMasterCSSStaticVitePlugin, addMasterCSSTanStackStartVitePlugin, addMasterCSSVitePlugin, addMasterCSSWebpackPlugin, addReactRouterRootCSSImport, addTanStackStartRootCSSImport, addViteClientTypes, createAstroConfig, createMasterCSSStylesheet, createNextConfig, createNuxtConfig, createRsbuildConfig, createRspackConfig, createStaticViteConfig, createViteConfig, createWebpackConfig };
@@ -1,5 +1,17 @@
1
1
  import { CANONICAL_ESLINT_CONFIG } from "./constants.js";
2
2
  //#region src/transforms.ts
3
+ function formatMasterCSSCall(mode) {
4
+ return mode ? `masterCSS({ mode: '${mode}' })` : "masterCSS()";
5
+ }
6
+ function formatWebpackPluginCall(mode) {
7
+ return mode ? `new MasterCSSPlugin({ mode: '${mode}' })` : "new MasterCSSPlugin()";
8
+ }
9
+ function formatNuxtModule(mode) {
10
+ return mode ? `['@master/css.nuxt', { mode: '${mode}' }]` : "'@master/css.nuxt'";
11
+ }
12
+ function formatNextCall(target, mode) {
13
+ return mode ? `${mode === "static" ? "await " : ""}withMasterCSS(${target}, { mode: '${mode}' })` : `withMasterCSS(${target})`;
14
+ }
3
15
  function addImport(content, statement) {
4
16
  if (content.includes(statement)) return content;
5
17
  const lines = content.split("\n");
@@ -21,8 +33,8 @@ function addMasterCSSImportToStylesheet(content) {
21
33
  function createMasterCSSStylesheet() {
22
34
  return "@import '@master/css';\n";
23
35
  }
24
- function addMasterCSSVitePlugin(content) {
25
- return addMasterCSSVitePluginCall(content, "masterCSS()");
36
+ function addMasterCSSVitePlugin(content, mode) {
37
+ return addMasterCSSVitePluginCall(content, formatMasterCSSCall(mode));
26
38
  }
27
39
  function addReactRouterRootCSSImport(content) {
28
40
  if (/^\s*import\s+['"]\.\/app\.css['"]\s*;?/m.test(content)) return content;
@@ -33,10 +45,10 @@ function addTanStackStartRootCSSImport(content) {
33
45
  return addImport(content, "import '../styles/app.css'");
34
46
  }
35
47
  function addMasterCSSStaticVitePlugin(content) {
36
- return addMasterCSSVitePluginCall(content, "masterCSS({ mode: 'static' })");
48
+ return addMasterCSSVitePlugin(content, "static");
37
49
  }
38
- function addMasterCSSTanStackStartVitePlugin(content) {
39
- const pluginCall = "masterCSS({ mode: 'static' })";
50
+ function addMasterCSSTanStackStartVitePlugin(content, mode = "static") {
51
+ const pluginCall = formatMasterCSSCall(mode);
40
52
  if (content.includes("@master/css.vite")) return content;
41
53
  let next = addImport(content, "import masterCSS from '@master/css.vite'");
42
54
  const tanStackStartPluginPattern = /^(\s*)tanstackStart\([^)]*\),?/m;
@@ -47,18 +59,27 @@ function addMasterCSSTanStackStartVitePlugin(content) {
47
59
  if (/defineConfig\(\s*\{/.test(next)) return replaceFirst(next, /defineConfig\(\s*\{/, `defineConfig({\n plugins: [${pluginCall}],`);
48
60
  return next;
49
61
  }
50
- function addMasterCSSRspackPlugin(content) {
62
+ function addMasterCSSRspackPlugin(content, mode) {
51
63
  if (content.includes("@master/css.webpack")) return content;
64
+ const pluginCall = formatWebpackPluginCall(mode);
52
65
  let next = addImport(content, "import MasterCSSPlugin from '@master/css.webpack'");
53
- if (/plugins\s*:\s*\[/.test(next)) return replaceFirst(next, /plugins\s*:\s*\[/, "plugins: [\n new MasterCSSPlugin(),");
54
- if (/export\s+default\s+\{/.test(next)) return replaceFirst(next, /export\s+default\s+\{/, "export default {\n plugins: [new MasterCSSPlugin()],");
66
+ if (/plugins\s*:\s*\[/.test(next)) return replaceFirst(next, /plugins\s*:\s*\[/, `plugins: [\n ${pluginCall},`);
67
+ if (/export\s+default\s+\{/.test(next)) return replaceFirst(next, /export\s+default\s+\{/, `export default {\n plugins: [${pluginCall}],`);
55
68
  return next;
56
69
  }
57
- function addMasterCSSRsbuildPlugin(content) {
70
+ function addMasterCSSWebpackPlugin(content, mode) {
71
+ if (content.includes("@master/css.webpack")) return content;
72
+ const pluginCall = formatWebpackPluginCall(mode);
73
+ let next = addImport(content, "import MasterCSSPlugin from '@master/css.webpack'");
74
+ if (/plugins\s*:\s*\[/.test(next)) return replaceFirst(next, /plugins\s*:\s*\[/, `plugins: [\n ${pluginCall},`);
75
+ if (/export\s+default\s+\{/.test(next)) return replaceFirst(next, /export\s+default\s+\{/, `export default {\n plugins: [${pluginCall}],`);
76
+ return next;
77
+ }
78
+ function addMasterCSSRsbuildPlugin(content, mode) {
58
79
  if (content.includes("@master/css.webpack")) return content;
59
80
  let next = addImport(content, "import MasterCSSPlugin from '@master/css.webpack'");
60
81
  const rspackSetupBody = ` config.plugins ||= []
61
- config.plugins.push(new MasterCSSPlugin())
82
+ config.plugins.push(${formatWebpackPluginCall(mode)})
62
83
  return config`;
63
84
  const rspackSetup = `rspack(config) {
64
85
  ${rspackSetupBody}
@@ -84,29 +105,21 @@ function addMasterCSSVitePluginCall(content, pluginCall) {
84
105
  if (/defineConfig\(\s*\{/.test(next)) return replaceFirst(next, /defineConfig\(\s*\{/, `defineConfig({\n plugins: [${pluginCall}],`);
85
106
  return next;
86
107
  }
87
- function createViteConfig() {
108
+ function createViteConfig(mode) {
88
109
  return `import { defineConfig } from 'vite'
89
110
  import masterCSS from '@master/css.vite'
90
111
 
91
112
  export default defineConfig({
92
113
  plugins: [
93
- masterCSS()
114
+ ${formatMasterCSSCall(mode)}
94
115
  ]
95
116
  })
96
117
  `;
97
118
  }
98
119
  function createStaticViteConfig() {
99
- return `import { defineConfig } from 'vite'
100
- import masterCSS from '@master/css.vite'
101
-
102
- export default defineConfig({
103
- plugins: [
104
- masterCSS({ mode: 'static' })
105
- ]
106
- })
107
- `;
120
+ return createViteConfig("static");
108
121
  }
109
- function createRspackConfig() {
122
+ function createRspackConfig(mode) {
110
123
  return `import MasterCSSPlugin from '@master/css.webpack'
111
124
 
112
125
  export default {
@@ -119,12 +132,22 @@ export default {
119
132
  ]
120
133
  },
121
134
  plugins: [
122
- new MasterCSSPlugin()
135
+ ${formatWebpackPluginCall(mode)}
136
+ ]
137
+ }
138
+ `;
139
+ }
140
+ function createWebpackConfig(mode) {
141
+ return `import MasterCSSPlugin from '@master/css.webpack'
142
+
143
+ export default {
144
+ plugins: [
145
+ ${formatWebpackPluginCall(mode)}
123
146
  ]
124
147
  }
125
148
  `;
126
149
  }
127
- function createRsbuildConfig() {
150
+ function createRsbuildConfig(mode) {
128
151
  return `import { defineConfig } from '@rsbuild/core'
129
152
  import MasterCSSPlugin from '@master/css.webpack'
130
153
 
@@ -132,57 +155,62 @@ export default defineConfig({
132
155
  tools: {
133
156
  rspack(config) {
134
157
  config.plugins ||= []
135
- config.plugins.push(new MasterCSSPlugin())
158
+ config.plugins.push(${formatWebpackPluginCall(mode)})
136
159
  return config
137
160
  }
138
161
  }
139
162
  })
140
163
  `;
141
164
  }
142
- function createNextConfig() {
165
+ function createNextConfig(mode) {
143
166
  return `import { withMasterCSS } from '@master/css.next'
144
167
 
145
- const nextConfig = withMasterCSS({})
168
+ const nextConfig = ${formatNextCall("{}", mode)}
146
169
 
147
170
  export default nextConfig
148
171
  `;
149
172
  }
150
- function addMasterCSSNextConfig(content) {
151
- if (content.includes("@master/css.next")) return content;
173
+ function addMasterCSSNextConfig(content, mode) {
174
+ if (content.includes("@master/css.next")) return mode ? addMasterCSSNextMode(content, mode) : content;
152
175
  const next = addImport(content, "import { withMasterCSS } from '@master/css.next'");
153
- if (/export\s+default\s+/.test(next)) return next.replace(/export\s+default\s+([^;\n]+)(;?)(\n|$)/, "export default withMasterCSS($1)$2$3");
176
+ if (/export\s+default\s+/.test(next)) return next.replace(/export\s+default\s+([^;\n]+)(;?)(\n|$)/, `export default ${formatNextCall("$1", mode)}$2$3`);
154
177
  return `${next.trimEnd()}
155
178
 
156
- export default withMasterCSS({})
179
+ export default ${formatNextCall("{}", mode)}
157
180
  `;
158
181
  }
159
- function addMasterCSSNuxtModule(content) {
182
+ function addMasterCSSNextMode(content, mode) {
183
+ return content.replace(/(?:await\s+)?withMasterCSS\(\s*(\{\s*\}|[A-Za-z_$][\w$]*)\s*(?:,\s*\{[^)]*\})?\s*\)/g, (_match, target) => formatNextCall(target, mode));
184
+ }
185
+ function addMasterCSSNuxtModule(content, mode) {
160
186
  if (content.includes("@master/css.nuxt")) return content;
161
- if (/modules\s*:\s*\[/.test(content)) return replaceFirst(content, /modules\s*:\s*\[/, "modules: [\n '@master/css.nuxt',");
162
- if (/defineNuxtConfig\(\s*\{/.test(content)) return replaceFirst(content, /defineNuxtConfig\(\s*\{/, "defineNuxtConfig({\n modules: ['@master/css.nuxt'],");
187
+ const moduleEntry = formatNuxtModule(mode);
188
+ if (/modules\s*:\s*\[/.test(content)) return replaceFirst(content, /modules\s*:\s*\[/, `modules: [\n ${moduleEntry},`);
189
+ if (/defineNuxtConfig\(\s*\{/.test(content)) return replaceFirst(content, /defineNuxtConfig\(\s*\{/, `defineNuxtConfig({\n modules: [${moduleEntry}],`);
163
190
  return content;
164
191
  }
165
- function createNuxtConfig() {
192
+ function createNuxtConfig(mode) {
166
193
  return `export default defineNuxtConfig({
167
- modules: ['@master/css.nuxt'],
194
+ modules: [${formatNuxtModule(mode)}],
168
195
  css: ['~/assets/css/master.css']
169
196
  })
170
197
  `;
171
198
  }
172
- function addMasterCSSAstroIntegration(content) {
199
+ function addMasterCSSAstroIntegration(content, mode) {
173
200
  if (content.includes("@master/css.astro")) return content;
201
+ const pluginCall = formatMasterCSSCall(mode);
174
202
  let next = addImport(content, "import masterCSS from '@master/css.astro'");
175
- if (/integrations\s*:\s*\[/.test(next)) return replaceFirst(next, /integrations\s*:\s*\[/, "integrations: [\n masterCSS(),");
176
- if (/defineConfig\(\s*\{/.test(next)) return replaceFirst(next, /defineConfig\(\s*\{/, "defineConfig({\n integrations: [masterCSS()],");
203
+ if (/integrations\s*:\s*\[/.test(next)) return replaceFirst(next, /integrations\s*:\s*\[/, `integrations: [\n ${pluginCall},`);
204
+ if (/defineConfig\(\s*\{/.test(next)) return replaceFirst(next, /defineConfig\(\s*\{/, `defineConfig({\n integrations: [${pluginCall}],`);
177
205
  return next;
178
206
  }
179
- function createAstroConfig() {
207
+ function createAstroConfig(mode) {
180
208
  return `import { defineConfig } from 'astro/config'
181
209
  import masterCSS from '@master/css.astro'
182
210
 
183
211
  export default defineConfig({
184
212
  integrations: [
185
- masterCSS()
213
+ ${formatMasterCSSCall(mode)}
186
214
  ]
187
215
  })
188
216
  `;
@@ -245,4 +273,4 @@ function addMasterCSSEslintConfig(content) {
245
273
  `;
246
274
  }
247
275
  //#endregion
248
- export { addAngularRuntimeSetup, addLitShadowRuntime, addMasterCSSAstroIntegration, addMasterCSSEslintConfig, addMasterCSSImportToStylesheet, addMasterCSSNextConfig, addMasterCSSNuxtModule, addMasterCSSRsbuildPlugin, addMasterCSSRspackPlugin, addMasterCSSStaticVitePlugin, addMasterCSSTanStackStartVitePlugin, addMasterCSSVitePlugin, addReactRouterRootCSSImport, addTanStackStartRootCSSImport, addViteClientTypes, createAstroConfig, createMasterCSSStylesheet, createNextConfig, createNuxtConfig, createRsbuildConfig, createRspackConfig, createStaticViteConfig, createViteConfig };
276
+ export { addAngularRuntimeSetup, addLitShadowRuntime, addMasterCSSAstroIntegration, addMasterCSSEslintConfig, addMasterCSSImportToStylesheet, addMasterCSSNextConfig, addMasterCSSNuxtModule, addMasterCSSRsbuildPlugin, addMasterCSSRspackPlugin, addMasterCSSStaticVitePlugin, addMasterCSSTanStackStartVitePlugin, addMasterCSSVitePlugin, addMasterCSSWebpackPlugin, addReactRouterRootCSSImport, addTanStackStartRootCSSImport, addViteClientTypes, createAstroConfig, createMasterCSSStylesheet, createNextConfig, createNuxtConfig, createRsbuildConfig, createRspackConfig, createStaticViteConfig, createViteConfig, createWebpackConfig };
package/package.json CHANGED
@@ -41,7 +41,7 @@
41
41
  "dependencies": {
42
42
  "commander": "^14.0.3"
43
43
  },
44
- "version": "2.0.0-rc.81",
44
+ "version": "2.0.0-rc.83",
45
45
  "scripts": {
46
46
  "build": "tsdown --config ../../shared/tsdown-package.config.ts",
47
47
  "dev": "tsdown --config ../../shared/tsdown-package.config.ts --watch",