@bamboocss/node 1.38.0 → 1.39.1

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/index.cjs CHANGED
@@ -3405,6 +3405,94 @@ const ensure = (outPath) => {
3405
3405
  return outPath;
3406
3406
  };
3407
3407
  //#endregion
3408
+ //#region src/vite-integration.ts
3409
+ /**
3410
+ * Whether a Bamboo source compiler is running in this process.
3411
+ *
3412
+ * Two integrations can emit the stylesheet, and only one of them also compiles source.
3413
+ * `@bamboocss/postcss` emits CSS and nothing else, so under it every `css()` and `cva()` call
3414
+ * stays a runtime call and the generated style engine ships in the client bundle. That is a
3415
+ * legitimate integration for a bundler with no Vite plugin — and a silent downgrade for a
3416
+ * project that has Vite and simply did not add `@bamboocss/vite`, which is a setup Bamboo's
3417
+ * own React Router guide used to describe. Nothing failed: the stylesheet was correct, the app
3418
+ * rendered, and 20 kB of engine went out with it.
3419
+ *
3420
+ * On `globalThis` under a registered symbol rather than in a module variable, because the two
3421
+ * packages that have to agree do not share a module instance. `@bamboocss/postcss` is required
3422
+ * as CommonJS by a PostCSS config while `@bamboocss/vite` is imported as ESM by a Vite config,
3423
+ * so even one installed copy of a shared dependency is loaded twice, once per format, with a
3424
+ * variable each. The symbol is one value per realm regardless.
3425
+ *
3426
+ * A realm is as far as it goes: a worker thread, or PostCSS run from a separate process
3427
+ * alongside the Vite build, sees no flag. Both fail towards saying something rather than
3428
+ * staying quiet, and what they say names the option that silences it.
3429
+ */
3430
+ const FLAG = Symbol.for("bamboocss.static-compiler");
3431
+ /** Called by an integration that compiles source, as it is constructed. */
3432
+ const markStaticCompilerActive = () => {
3433
+ globalThis[FLAG] = true;
3434
+ };
3435
+ const isStaticCompilerActive = () => Boolean(globalThis[FLAG]);
3436
+ /**
3437
+ * Every extension Vite accepts for its config, so "is this a Vite project" is answered by the
3438
+ * same file Vite itself would load.
3439
+ *
3440
+ * A file rather than a resolvable `vite` package: Vite is a transitive dependency of plenty of
3441
+ * things — Vitest above all — and a project that has one for its tests and builds with webpack
3442
+ * is exactly the case this must not mistake for a Vite app.
3443
+ */
3444
+ const VITE_CONFIG_FILES = [
3445
+ "vite.config.ts",
3446
+ "vite.config.js",
3447
+ "vite.config.mjs",
3448
+ "vite.config.mts",
3449
+ "vite.config.cjs",
3450
+ "vite.config.cts"
3451
+ ];
3452
+ /** The project's Vite config, if it has one. Not resolved further than existence. */
3453
+ const findViteConfig = (cwd) => VITE_CONFIG_FILES.map((file) => (0, path.join)(cwd, file)).find((file) => (0, fs.existsSync)(file));
3454
+ /**
3455
+ * Frameworks that author styles in a file the Vite compiler does not transform.
3456
+ *
3457
+ * It compiles JavaScript and TypeScript. A `.svelte`, `.vue` or `.astro` file is a template
3458
+ * with a script in it, and the compiler leaves those alone — which for a Svelte or Vue project
3459
+ * makes the PostCSS integration the right one, not a downgrade. Worse than that: switching one
3460
+ * to `@bamboocss/vite` would prune every rule only its components reach, since reachability is
3461
+ * computed from modules the compiler saw, so the pages would render unstyled.
3462
+ *
3463
+ * So this is the exception to the advice, and it has to be checked before giving it.
3464
+ */
3465
+ const TEMPLATE_EXTENSIONS = /\b(?:svelte|vue|astro|html|hbs|mdx?)\b/;
3466
+ const TEMPLATE_PACKAGES = [
3467
+ "svelte",
3468
+ "@sveltejs/kit",
3469
+ "vue",
3470
+ "nuxt",
3471
+ "astro"
3472
+ ];
3473
+ /**
3474
+ * Does this project author styles somewhere the Vite compiler cannot reach?
3475
+ *
3476
+ * Two signals because the two callers know different things. A resolved config names the file
3477
+ * types directly, and is authoritative when it does; `bamboo init` runs before there is one,
3478
+ * so the dependency list stands in. Either one is enough — both directions of a wrong answer
3479
+ * here only decide whether advice is offered, and the advice is worth less than a Svelte
3480
+ * project being told to break itself.
3481
+ */
3482
+ const hasUncompilableSources = (options) => {
3483
+ if (options.include?.some((glob) => TEMPLATE_EXTENSIONS.test(glob))) return true;
3484
+ try {
3485
+ const manifest = JSON.parse((0, fs.readFileSync)((0, path.join)(options.cwd, "package.json"), "utf8"));
3486
+ const dependencies = {
3487
+ ...manifest.dependencies,
3488
+ ...manifest.devDependencies
3489
+ };
3490
+ return TEMPLATE_PACKAGES.some((name) => name in dependencies);
3491
+ } catch {
3492
+ return false;
3493
+ }
3494
+ };
3495
+ //#endregion
3408
3496
  //#region src/setup-config.ts
3409
3497
  async function setupConfig(cwd, opts = {}) {
3410
3498
  const { force, outExtension, outdir = "styled-system" } = opts;
@@ -3458,6 +3546,8 @@ export default defineConfig({
3458
3546
  }
3459
3547
  }
3460
3548
  async function setupPostcss(cwd) {
3549
+ const viteConfig = findViteConfig(cwd);
3550
+ if (viteConfig && !hasUncompilableSources({ cwd })) _bamboocss_logger.logger.warn("init:postcss", `This project has ${(0, _bamboocss_logger.quote)((0, path.basename)(viteConfig))}, so ${(0, _bamboocss_logger.quote)("@bamboocss/vite")} is the integration to use. The PostCSS one emits CSS only: it does not compile source, so ${(0, _bamboocss_logger.quote)("css()")} and ${(0, _bamboocss_logger.quote)("cva()")} stay runtime calls and the generated style engine ships in your client bundle. Both render identically, which is what makes the difference easy to miss. See https://bamboocss.com/docs/installation/vite`);
3461
3551
  _bamboocss_logger.logger.info("init:postcss", `creating postcss config file: ${(0, _bamboocss_logger.quote)("postcss.config.cjs")}`);
3462
3552
  const content = outdent.outdent`
3463
3553
  module.exports = {
@@ -3498,6 +3588,7 @@ exports.buildInfo = buildInfo;
3498
3588
  exports.codegen = codegen;
3499
3589
  exports.cssgen = cssgen;
3500
3590
  exports.debug = debug;
3591
+ exports.findViteConfig = findViteConfig;
3501
3592
  exports.generate = generate;
3502
3593
  Object.defineProperty(exports, "generatePackageExports", {
3503
3594
  enumerable: true,
@@ -3505,7 +3596,10 @@ Object.defineProperty(exports, "generatePackageExports", {
3505
3596
  return _bamboocss_generator.generatePackageExports;
3506
3597
  }
3507
3598
  });
3599
+ exports.hasUncompilableSources = hasUncompilableSources;
3600
+ exports.isStaticCompilerActive = isStaticCompilerActive;
3508
3601
  exports.loadConfigAndCreateContext = loadConfigAndCreateContext;
3602
+ exports.markStaticCompilerActive = markStaticCompilerActive;
3509
3603
  exports.parseDependency = parseDependency;
3510
3604
  exports.setLogStream = setLogStream;
3511
3605
  exports.setupConfig = setupConfig;
package/dist/index.d.cts CHANGED
@@ -346,4 +346,24 @@ interface SpecOptions {
346
346
  }
347
347
  declare function spec(ctx: BambooContext, options: SpecOptions): Promise<SpecFile[]>;
348
348
  //#endregion
349
- export { BambooContext, Builder, type CssGenOptions, analyze, buildInfo, codegen, cssgen, debug, generate, generatePackageExports, loadConfigAndCreateContext, parseDependency, setLogStream, setupConfig, setupGitIgnore, setupPostcss, spec, startProfiling };
349
+ //#region src/vite-integration.d.ts
350
+ /** Called by an integration that compiles source, as it is constructed. */
351
+ declare const markStaticCompilerActive: () => void;
352
+ declare const isStaticCompilerActive: () => boolean;
353
+ /** The project's Vite config, if it has one. Not resolved further than existence. */
354
+ declare const findViteConfig: (cwd: string) => string | undefined;
355
+ /**
356
+ * Does this project author styles somewhere the Vite compiler cannot reach?
357
+ *
358
+ * Two signals because the two callers know different things. A resolved config names the file
359
+ * types directly, and is authoritative when it does; `bamboo init` runs before there is one,
360
+ * so the dependency list stands in. Either one is enough — both directions of a wrong answer
361
+ * here only decide whether advice is offered, and the advice is worth less than a Svelte
362
+ * project being told to break itself.
363
+ */
364
+ declare const hasUncompilableSources: (options: {
365
+ cwd: string;
366
+ include?: readonly string[];
367
+ }) => boolean;
368
+ //#endregion
369
+ export { BambooContext, Builder, type CssGenOptions, analyze, buildInfo, codegen, cssgen, debug, findViteConfig, generate, generatePackageExports, hasUncompilableSources, isStaticCompilerActive, loadConfigAndCreateContext, markStaticCompilerActive, parseDependency, setLogStream, setupConfig, setupGitIgnore, setupPostcss, spec, startProfiling };
package/dist/index.d.mts CHANGED
@@ -346,4 +346,24 @@ interface SpecOptions {
346
346
  }
347
347
  declare function spec(ctx: BambooContext, options: SpecOptions): Promise<SpecFile[]>;
348
348
  //#endregion
349
- export { BambooContext, Builder, type CssGenOptions, analyze, buildInfo, codegen, cssgen, debug, generate, generatePackageExports, loadConfigAndCreateContext, parseDependency, setLogStream, setupConfig, setupGitIgnore, setupPostcss, spec, startProfiling };
349
+ //#region src/vite-integration.d.ts
350
+ /** Called by an integration that compiles source, as it is constructed. */
351
+ declare const markStaticCompilerActive: () => void;
352
+ declare const isStaticCompilerActive: () => boolean;
353
+ /** The project's Vite config, if it has one. Not resolved further than existence. */
354
+ declare const findViteConfig: (cwd: string) => string | undefined;
355
+ /**
356
+ * Does this project author styles somewhere the Vite compiler cannot reach?
357
+ *
358
+ * Two signals because the two callers know different things. A resolved config names the file
359
+ * types directly, and is authoritative when it does; `bamboo init` runs before there is one,
360
+ * so the dependency list stands in. Either one is enough — both directions of a wrong answer
361
+ * here only decide whether advice is offered, and the advice is worth less than a Svelte
362
+ * project being told to break itself.
363
+ */
364
+ declare const hasUncompilableSources: (options: {
365
+ cwd: string;
366
+ include?: readonly string[];
367
+ }) => boolean;
368
+ //#endregion
369
+ export { BambooContext, Builder, type CssGenOptions, analyze, buildInfo, codegen, cssgen, debug, findViteConfig, generate, generatePackageExports, hasUncompilableSources, isStaticCompilerActive, loadConfigAndCreateContext, markStaticCompilerActive, parseDependency, setLogStream, setupConfig, setupGitIgnore, setupPostcss, spec, startProfiling };
package/dist/index.mjs CHANGED
@@ -4,7 +4,7 @@ import { convertTsPathsToRegexes, diffConfigs, findConfig, getConfigDependencies
4
4
  import { checkNamingAgreement, formatNamingDisagreement, messages, prunesPreflight } from "@bamboocss/core";
5
5
  import { BambooError, cssVarRefs, groupBy, truncateList, uniq } from "@bamboocss/shared";
6
6
  import { appendFileSync, existsSync, readFileSync, statSync, writeFileSync } from "fs";
7
- import { dirname, extname, isAbsolute, join, normalize, parse, relative, resolve, sep } from "path";
7
+ import { basename, dirname, extname, isAbsolute, join, normalize, parse, relative, resolve, sep } from "path";
8
8
  import { pluginSvelte } from "@bamboocss/plugin-svelte";
9
9
  import { pluginVue } from "@bamboocss/plugin-vue";
10
10
  import { Generator, generatePackageExports } from "@bamboocss/generator";
@@ -3391,6 +3391,94 @@ const ensure = (outPath) => {
3391
3391
  return outPath;
3392
3392
  };
3393
3393
  //#endregion
3394
+ //#region src/vite-integration.ts
3395
+ /**
3396
+ * Whether a Bamboo source compiler is running in this process.
3397
+ *
3398
+ * Two integrations can emit the stylesheet, and only one of them also compiles source.
3399
+ * `@bamboocss/postcss` emits CSS and nothing else, so under it every `css()` and `cva()` call
3400
+ * stays a runtime call and the generated style engine ships in the client bundle. That is a
3401
+ * legitimate integration for a bundler with no Vite plugin — and a silent downgrade for a
3402
+ * project that has Vite and simply did not add `@bamboocss/vite`, which is a setup Bamboo's
3403
+ * own React Router guide used to describe. Nothing failed: the stylesheet was correct, the app
3404
+ * rendered, and 20 kB of engine went out with it.
3405
+ *
3406
+ * On `globalThis` under a registered symbol rather than in a module variable, because the two
3407
+ * packages that have to agree do not share a module instance. `@bamboocss/postcss` is required
3408
+ * as CommonJS by a PostCSS config while `@bamboocss/vite` is imported as ESM by a Vite config,
3409
+ * so even one installed copy of a shared dependency is loaded twice, once per format, with a
3410
+ * variable each. The symbol is one value per realm regardless.
3411
+ *
3412
+ * A realm is as far as it goes: a worker thread, or PostCSS run from a separate process
3413
+ * alongside the Vite build, sees no flag. Both fail towards saying something rather than
3414
+ * staying quiet, and what they say names the option that silences it.
3415
+ */
3416
+ const FLAG = Symbol.for("bamboocss.static-compiler");
3417
+ /** Called by an integration that compiles source, as it is constructed. */
3418
+ const markStaticCompilerActive = () => {
3419
+ globalThis[FLAG] = true;
3420
+ };
3421
+ const isStaticCompilerActive = () => Boolean(globalThis[FLAG]);
3422
+ /**
3423
+ * Every extension Vite accepts for its config, so "is this a Vite project" is answered by the
3424
+ * same file Vite itself would load.
3425
+ *
3426
+ * A file rather than a resolvable `vite` package: Vite is a transitive dependency of plenty of
3427
+ * things — Vitest above all — and a project that has one for its tests and builds with webpack
3428
+ * is exactly the case this must not mistake for a Vite app.
3429
+ */
3430
+ const VITE_CONFIG_FILES = [
3431
+ "vite.config.ts",
3432
+ "vite.config.js",
3433
+ "vite.config.mjs",
3434
+ "vite.config.mts",
3435
+ "vite.config.cjs",
3436
+ "vite.config.cts"
3437
+ ];
3438
+ /** The project's Vite config, if it has one. Not resolved further than existence. */
3439
+ const findViteConfig = (cwd) => VITE_CONFIG_FILES.map((file) => join(cwd, file)).find((file) => existsSync(file));
3440
+ /**
3441
+ * Frameworks that author styles in a file the Vite compiler does not transform.
3442
+ *
3443
+ * It compiles JavaScript and TypeScript. A `.svelte`, `.vue` or `.astro` file is a template
3444
+ * with a script in it, and the compiler leaves those alone — which for a Svelte or Vue project
3445
+ * makes the PostCSS integration the right one, not a downgrade. Worse than that: switching one
3446
+ * to `@bamboocss/vite` would prune every rule only its components reach, since reachability is
3447
+ * computed from modules the compiler saw, so the pages would render unstyled.
3448
+ *
3449
+ * So this is the exception to the advice, and it has to be checked before giving it.
3450
+ */
3451
+ const TEMPLATE_EXTENSIONS = /\b(?:svelte|vue|astro|html|hbs|mdx?)\b/;
3452
+ const TEMPLATE_PACKAGES = [
3453
+ "svelte",
3454
+ "@sveltejs/kit",
3455
+ "vue",
3456
+ "nuxt",
3457
+ "astro"
3458
+ ];
3459
+ /**
3460
+ * Does this project author styles somewhere the Vite compiler cannot reach?
3461
+ *
3462
+ * Two signals because the two callers know different things. A resolved config names the file
3463
+ * types directly, and is authoritative when it does; `bamboo init` runs before there is one,
3464
+ * so the dependency list stands in. Either one is enough — both directions of a wrong answer
3465
+ * here only decide whether advice is offered, and the advice is worth less than a Svelte
3466
+ * project being told to break itself.
3467
+ */
3468
+ const hasUncompilableSources = (options) => {
3469
+ if (options.include?.some((glob) => TEMPLATE_EXTENSIONS.test(glob))) return true;
3470
+ try {
3471
+ const manifest = JSON.parse(readFileSync(join(options.cwd, "package.json"), "utf8"));
3472
+ const dependencies = {
3473
+ ...manifest.dependencies,
3474
+ ...manifest.devDependencies
3475
+ };
3476
+ return TEMPLATE_PACKAGES.some((name) => name in dependencies);
3477
+ } catch {
3478
+ return false;
3479
+ }
3480
+ };
3481
+ //#endregion
3394
3482
  //#region src/setup-config.ts
3395
3483
  async function setupConfig(cwd, opts = {}) {
3396
3484
  const { force, outExtension, outdir = "styled-system" } = opts;
@@ -3444,6 +3532,8 @@ export default defineConfig({
3444
3532
  }
3445
3533
  }
3446
3534
  async function setupPostcss(cwd) {
3535
+ const viteConfig = findViteConfig(cwd);
3536
+ if (viteConfig && !hasUncompilableSources({ cwd })) logger.warn("init:postcss", `This project has ${quote(basename(viteConfig))}, so ${quote("@bamboocss/vite")} is the integration to use. The PostCSS one emits CSS only: it does not compile source, so ${quote("css()")} and ${quote("cva()")} stay runtime calls and the generated style engine ships in your client bundle. Both render identically, which is what makes the difference easy to miss. See https://bamboocss.com/docs/installation/vite`);
3447
3537
  logger.info("init:postcss", `creating postcss config file: ${quote("postcss.config.cjs")}`);
3448
3538
  const content = outdent`
3449
3539
  module.exports = {
@@ -3477,4 +3567,4 @@ async function spec(ctx, options) {
3477
3567
  return specs;
3478
3568
  }
3479
3569
  //#endregion
3480
- export { BambooContext, Builder, analyze, buildInfo, codegen, cssgen, debug, generate, generatePackageExports, loadConfigAndCreateContext, parseDependency, setLogStream, setupConfig, setupGitIgnore, setupPostcss, spec, startProfiling };
3570
+ export { BambooContext, Builder, analyze, buildInfo, codegen, cssgen, debug, findViteConfig, generate, generatePackageExports, hasUncompilableSources, isStaticCompilerActive, loadConfigAndCreateContext, markStaticCompilerActive, parseDependency, setLogStream, setupConfig, setupGitIgnore, setupPostcss, spec, startProfiling };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bamboocss/node",
3
- "version": "1.38.0",
3
+ "version": "1.39.1",
4
4
  "description": "The core css bamboo library",
5
5
  "homepage": "https://bamboocss.com",
6
6
  "license": "MIT",
@@ -52,17 +52,17 @@
52
52
  "postcss": "8.5.26",
53
53
  "ts-morph": "28.0.0",
54
54
  "ts-pattern": "5.9.0",
55
- "@bamboocss/config": "1.38.0",
56
- "@bamboocss/core": "1.38.0",
57
- "@bamboocss/generator": "1.38.0",
58
- "@bamboocss/logger": "1.38.0",
59
- "@bamboocss/parser": "1.38.0",
60
- "@bamboocss/plugin-svelte": "1.38.0",
61
- "@bamboocss/plugin-vue": "1.38.0",
62
- "@bamboocss/reporter": "1.38.0",
63
- "@bamboocss/shared": "1.38.0",
64
- "@bamboocss/token-dictionary": "1.38.0",
65
- "@bamboocss/types": "1.38.0"
55
+ "@bamboocss/config": "1.39.1",
56
+ "@bamboocss/core": "1.39.1",
57
+ "@bamboocss/generator": "1.39.1",
58
+ "@bamboocss/logger": "1.39.1",
59
+ "@bamboocss/parser": "1.39.1",
60
+ "@bamboocss/plugin-svelte": "1.39.1",
61
+ "@bamboocss/plugin-vue": "1.39.1",
62
+ "@bamboocss/reporter": "1.39.1",
63
+ "@bamboocss/shared": "1.39.1",
64
+ "@bamboocss/token-dictionary": "1.39.1",
65
+ "@bamboocss/types": "1.39.1"
66
66
  },
67
67
  "devDependencies": {
68
68
  "@types/fs-extra": "11.0.4",