From acb1e6e140e920f749321fea1c8e684f8f96dc07 Mon Sep 17 00:00:00 2001 From: owjs3901 Date: Tue, 17 Nov 2026 13:08:25 +0900 Subject: [PATCH 1/3] fix(sheet): ship the license banner once and add a licenseBanner option A stylesheet without any rule is now emitted empty instead of as a bare license banner. The shared base devup-ui.css of a per-file build with no base rules held only the banner, and every per-file sheet @imports it, so the banner shipped twice in one stylesheet chain. The @import itself is kept: a per-file sheet can be produced before a later module adds base rules, and bundlers inline the import anyway. The banner version was read by splitting a package.json line on ':' and kept the JSON comma (v1.0.83,). It is now parsed from the manifest (@devup-ui/wasm's npm version; the Cargo crates stay at 0.1.0). The banner stays on by default. A new licenseBanner plugin option (vite, webpack, next for webpack and Turbopack, rsbuild, bun) turns it off through the new setLicenseBanner/isLicenseBanner engine functions, identical in the NAPI and WASM engines. The serialized-CSS cache keys on the setting. The Devup UI benchmark apps turn it off. Co-Authored-By: Claude Opus 5.5 --- .../changepack_log_css_license_banner.json | 14 ++ README.md | 6 +- README_ko.md | 6 +- .../src/app/(detail)/docs/api/button/page.mdx | 2 +- .../docs/core-concepts/optimize-css/page.mdx | 12 +- .../(detail)/docs/installation/page.ko.mdx | 23 ++++ .../app/(detail)/docs/installation/page.mdx | 22 ++++ .../migration/vanilla-extract/page.ko.mdx | 4 +- .../docs/migration/vanilla-extract/page.mdx | 4 +- .../next-devup-ui-collapse/next.config.ts | 2 +- .../next.config.ts | 2 +- .../next-devup-ui-large-turbo/next.config.ts | 2 +- .../next-devup-ui-large-wasm/next.config.ts | 2 +- benchmark/next-devup-ui-large/next.config.ts | 2 +- .../next.config.mjs | 2 +- benchmark/next-devup-ui-single/next.config.ts | 2 +- benchmark/next-devup-ui-turbo/next.config.ts | 2 +- benchmark/next-devup-ui/next.config.ts | 2 +- .../next.config.mjs | 2 +- .../next.config.mjs | 5 +- .../next.config.mjs | 5 +- benchmark/vinext-devup-ui/vite.config.ts | 2 +- bindings/argument-validation.cjs | 1 + bindings/devup-ui-binding/README.md | 2 +- bindings/devup-ui-binding/adapter.cjs | 2 + bindings/devup-ui-binding/index.d.cts | 4 + bindings/devup-ui-binding/index.mjs | 2 + bindings/devup-ui-binding/src/lib.rs | 10 ++ bindings/devup-ui-wasm/AGENTS.md | 1 + bindings/devup-ui-wasm/README.md | 27 ++-- bindings/devup-ui-wasm/script.js | 6 +- bindings/devup-ui-wasm/src/lib.rs | 28 +++- e2e/binding/host.mjs | 3 +- e2e/binding/validation-cases.mjs | 5 +- e2e/binding/validation-host.mjs | 2 + libs/binding/src/css_cache.rs | 23 +++- libs/binding/src/lib.rs | 1 + libs/css/src/lib.rs | 1 + libs/css/src/license_banner.rs | 34 +++++ libs/css/src/test_state.rs | 8 +- libs/extractor/README.md | 2 +- libs/sheet/src/lib.rs | 124 +++++++++++++++--- packages/bun-plugin/README.md | 11 ++ .../bun-plugin/src/__tests__/plugin.test.ts | 14 ++ packages/bun-plugin/src/plugin.ts | 6 + packages/next-plugin/README.md | 12 ++ .../next-plugin/src/__tests__/plugin.test.ts | 31 +++++ packages/next-plugin/src/plugin.ts | 4 + .../src/__tests__/compiler-types.test.ts | 2 +- .../src/__tests__/wasm-abi.test.ts | 24 ++++ packages/plugin-utils/src/shared.ts | 6 + packages/rsbuild-plugin/README.md | 11 ++ .../src/__tests__/plugin.test.ts | 15 +++ packages/rsbuild-plugin/src/plugin.ts | 4 +- packages/vite-plugin/README.md | 11 ++ .../vite-plugin/src/__tests__/plugin.test.ts | 15 +++ packages/vite-plugin/src/plugin.ts | 4 +- packages/webpack-plugin/README.md | 11 ++ .../src/__tests__/plugin.test.ts | 20 +++ packages/webpack-plugin/src/plugin.ts | 5 +- 60 files changed, 537 insertions(+), 80 deletions(-) create mode 100644 .changepacks/changepack_log_css_license_banner.json create mode 100644 libs/css/src/license_banner.rs diff --git a/.changepacks/changepack_log_css_license_banner.json b/.changepacks/changepack_log_css_license_banner.json new file mode 100644 index 000000000..16e5faae8 --- /dev/null +++ b/.changepacks/changepack_log_css_license_banner.json @@ -0,0 +1,14 @@ +{ + "changes": { + "bindings/devup-ui-binding/package.json": "Patch", + "bindings/devup-ui-wasm/package.json": "Patch", + "packages/plugin-utils/package.json": "Patch", + "packages/vite-plugin/package.json": "Patch", + "packages/webpack-plugin/package.json": "Patch", + "packages/next-plugin/package.json": "Patch", + "packages/rsbuild-plugin/package.json": "Patch", + "packages/bun-plugin/package.json": "Patch" + }, + "note": "Stylesheets without any rule are emitted empty instead of as a bare license banner, so the empty shared base sheet no longer repeats the banner in every per-file stylesheet that imports it. The banner names the version without a trailing comma (`v1.0.83`, not `v1.0.83,`). A new `licenseBanner` plugin option (default `true`) and the `setLicenseBanner`/`isLicenseBanner` engine functions turn the banner off; both engines emit identical output.", + "date": "2026-11-17T00:00:00.000Z" +} diff --git a/README.md b/README.md index eceb7305d..3d6cdf16c 100644 --- a/README.md +++ b/README.md @@ -135,7 +135,7 @@ const example =
; With CSS: ```css -/*! devup-ui v1.0.82, | Apache License 2.0 | https://devup-ui.com */.b{background:red}.c{padding:16px}.a:hover{background:blue} +/*! devup-ui v1.0.82 | Apache License 2.0 | https://devup-ui.com */.b{background:red}.c{padding:16px}.a:hover{background:blue} ``` **Dynamic values become CSS variables:** @@ -158,7 +158,7 @@ const example =
; With CSS: ```css -/*! devup-ui v1.0.82, | Apache License 2.0 | https://devup-ui.com */.a{background:var(--b)} +/*! devup-ui v1.0.82 | Apache License 2.0 | https://devup-ui.com */.a{background:var(--b)} ``` **Complex expressions and responsive arrays:** @@ -181,7 +181,7 @@ const example =
; CSS: ```css -/*! devup-ui v1.0.82, | Apache License 2.0 | https://devup-ui.com */.b{background:red}.c{padding:16px}.a:hover{background:blue} +/*! devup-ui v1.0.82 | Apache License 2.0 | https://devup-ui.com */.b{background:red}.c{padding:16px}.a:hover{background:blue} ``` **동적 값은 CSS 변수로 변환:** @@ -158,7 +158,7 @@ const example =
; CSS: ```css -/*! devup-ui v1.0.82, | Apache License 2.0 | https://devup-ui.com */.a{background:var(--b)} +/*! devup-ui v1.0.82 | Apache License 2.0 | https://devup-ui.com */.a{background:var(--b)} ``` **복잡한 표현식과 반응형 배열:** @@ -181,7 +181,7 @@ const example =
Generated CSS: ```text -/*! devup-ui v1.0.82, | Apache License 2.0 | https://devup-ui.com */@keyframes a{from{opacity:0}to{opacity:1}}.b{animation:a 1s linear} +/*! devup-ui v1.0.82 | Apache License 2.0 | https://devup-ui.com */@keyframes a{from{opacity:0}to{opacity:1}}.b{animation:a 1s linear} ``` ## Font Family Extraction @@ -141,7 +141,7 @@ const text = Generated CSS: ```text -/*! devup-ui v1.0.82, | Apache License 2.0 | https://devup-ui.com */.a{font-family:Inter} +/*! devup-ui v1.0.82 | Apache License 2.0 | https://devup-ui.com */.a{font-family:Inter} ``` ## Style Deduplication @@ -175,7 +175,7 @@ const repeated =
Generated CSS: ```text -/*! devup-ui v1.0.82, | Apache License 2.0 | https://devup-ui.com */.a{background:red}.b{color:white} +/*! devup-ui v1.0.82 | Apache License 2.0 | https://devup-ui.com */.a{background:red}.b{color:white} ``` These three elements share two rules. Reuse reduces repeated CSS without adding diff --git a/apps/landing/src/app/(detail)/docs/installation/page.ko.mdx b/apps/landing/src/app/(detail)/docs/installation/page.ko.mdx index bce5c53c1..eb98ea748 100644 --- a/apps/landing/src/app/(detail)/docs/installation/page.ko.mdx +++ b/apps/landing/src/app/(detail)/docs/installation/page.ko.mdx @@ -147,6 +147,29 @@ await Bun.build({ }) ``` +## 라이선스 배너 + +Devup UI가 내보내는 모든 스타일시트는 +`/*! devup-ui v… | Apache License 2.0 | https://devup-ui.com */` 주석으로 +시작하며, 압축기도 이 주석을 남깁니다. 기본값은 켜짐입니다. 모든 빌드 플러그인은 +`licenseBanner` 옵션을 받으며, `licenseBanner: false`로 설정하면 모든 +스타일시트에서 배너를 뺍니다. 규칙이 하나도 없는 스타일시트는 배너 없이 빈 +파일로 내보냅니다. + +```ts +// next.config.ts +export default DevupUI(nextConfig, { licenseBanner: false }) + +// vite.config.ts +DevupUI({ licenseBanner: false }) + +// rsbuild.config.ts +DevupUIRsbuildPlugin({ licenseBanner: false }) + +// webpack.config.js +new DevupUIWebpackPlugin({ licenseBanner: false }) +``` + ## 프로젝트 예제 - [Next.js 예제](https://github.com/dev-five-git/devup-ui/tree/main/apps/next) diff --git a/apps/landing/src/app/(detail)/docs/installation/page.mdx b/apps/landing/src/app/(detail)/docs/installation/page.mdx index 030cf3900..49415187a 100644 --- a/apps/landing/src/app/(detail)/docs/installation/page.mdx +++ b/apps/landing/src/app/(detail)/docs/installation/page.mdx @@ -148,6 +148,28 @@ await Bun.build({ }) ``` +## License Banner + +Every stylesheet Devup UI emits starts with a +`/*! devup-ui v… | Apache License 2.0 | https://devup-ui.com */` comment, which +minifiers keep. It is on by default. Every build plugin takes a +`licenseBanner` option; `licenseBanner: false` drops the banner from every +stylesheet. A stylesheet without any rule is emitted empty, banner included. + +```ts +// next.config.ts +export default DevupUI(nextConfig, { licenseBanner: false }) + +// vite.config.ts +DevupUI({ licenseBanner: false }) + +// rsbuild.config.ts +DevupUIRsbuildPlugin({ licenseBanner: false }) + +// webpack.config.js +new DevupUIWebpackPlugin({ licenseBanner: false }) +``` + ## Project Examples - [Next.js Example](https://github.com/dev-five-git/devup-ui/tree/main/apps/next) diff --git a/apps/landing/src/app/(detail)/docs/migration/vanilla-extract/page.ko.mdx b/apps/landing/src/app/(detail)/docs/migration/vanilla-extract/page.ko.mdx index 0778b8973..115398de9 100644 --- a/apps/landing/src/app/(detail)/docs/migration/vanilla-extract/page.ko.mdx +++ b/apps/landing/src/app/(detail)/docs/migration/vanilla-extract/page.ko.mdx @@ -74,7 +74,7 @@ export const a = "a"; 테마가 비어 있으면 같은 예제에서 다음 CSS가 생성됩니다: ```text -/*! devup-ui v1.0.82, | Apache License 2.0 | https://devup-ui.com */@layer b;@layer b{body{margin:0}}.a{color:red} +/*! devup-ui v1.0.82 | Apache License 2.0 | https://devup-ui.com */@layer b;@layer b{body{margin:0}}.a{color:red} ``` 생성되는 이름은 클래스 접두사와 추출 상태에 따라 달라집니다. vanilla-extract API import는 제거되지만, 생성된 CSS import는 남습니다. @@ -101,7 +101,7 @@ export const button = "b c"; 생성된 CSS: ```text -/*! devup-ui v1.0.82, | Apache License 2.0 | https://devup-ui.com */.c{color:blue}.a{color:red}.b{padding:8px} +/*! devup-ui v1.0.82 | Apache License 2.0 | https://devup-ui.com */.c{color:blue}.a{color:red}.b{padding:8px} ``` `button`에는 충돌하는 red 클래스가 포함되지 않습니다. 빌드 시점에 알 수 없는 외부 클래스는 여전히 CSS 캐스케이드를 따르며, 클래스 이름 문자열의 순서가 덮어쓰기 규칙이 되지는 않습니다. diff --git a/apps/landing/src/app/(detail)/docs/migration/vanilla-extract/page.mdx b/apps/landing/src/app/(detail)/docs/migration/vanilla-extract/page.mdx index 4f6d04fcb..f7eae6af9 100644 --- a/apps/landing/src/app/(detail)/docs/migration/vanilla-extract/page.mdx +++ b/apps/landing/src/app/(detail)/docs/migration/vanilla-extract/page.mdx @@ -76,7 +76,7 @@ export const a = "a"; With an empty theme, the same probe emits: ```text -/*! devup-ui v1.0.82, | Apache License 2.0 | https://devup-ui.com */@layer b;@layer b{body{margin:0}}.a{color:red} +/*! devup-ui v1.0.82 | Apache License 2.0 | https://devup-ui.com */@layer b;@layer b{body{margin:0}}.a{color:red} ``` Generated names depend on the class prefix and extraction state. The @@ -107,7 +107,7 @@ export const button = "b c"; Generated CSS: ```text -/*! devup-ui v1.0.82, | Apache License 2.0 | https://devup-ui.com */.c{color:blue}.a{color:red}.b{padding:8px} +/*! devup-ui v1.0.82 | Apache License 2.0 | https://devup-ui.com */.c{color:blue}.a{color:red}.b{padding:8px} ``` `button` does not include the conflicting red class. Unknown external classes diff --git a/benchmark/next-devup-ui-collapse/next.config.ts b/benchmark/next-devup-ui-collapse/next.config.ts index 5af9af04e..b9c7fdd9f 100644 --- a/benchmark/next-devup-ui-collapse/next.config.ts +++ b/benchmark/next-devup-ui-collapse/next.config.ts @@ -2,4 +2,4 @@ import { DevupUI } from '@devup-ui/next-plugin' const nextConfig = { experimental: { useTypeScriptCli: true } } -export default DevupUI(nextConfig, {}) +export default DevupUI(nextConfig, { licenseBanner: false }) diff --git a/benchmark/next-devup-ui-large-turbo-wasm/next.config.ts b/benchmark/next-devup-ui-large-turbo-wasm/next.config.ts index db41da922..edf01d83d 100644 --- a/benchmark/next-devup-ui-large-turbo-wasm/next.config.ts +++ b/benchmark/next-devup-ui-large-turbo-wasm/next.config.ts @@ -2,4 +2,4 @@ import { DevupUI } from '@devup-ui/next-plugin' const nextConfig = { experimental: { useTypeScriptCli: true } } -export default DevupUI(nextConfig, { engine: 'wasm' }) +export default DevupUI(nextConfig, { engine: 'wasm', licenseBanner: false }) diff --git a/benchmark/next-devup-ui-large-turbo/next.config.ts b/benchmark/next-devup-ui-large-turbo/next.config.ts index 5af9af04e..b9c7fdd9f 100644 --- a/benchmark/next-devup-ui-large-turbo/next.config.ts +++ b/benchmark/next-devup-ui-large-turbo/next.config.ts @@ -2,4 +2,4 @@ import { DevupUI } from '@devup-ui/next-plugin' const nextConfig = { experimental: { useTypeScriptCli: true } } -export default DevupUI(nextConfig, {}) +export default DevupUI(nextConfig, { licenseBanner: false }) diff --git a/benchmark/next-devup-ui-large-wasm/next.config.ts b/benchmark/next-devup-ui-large-wasm/next.config.ts index db41da922..edf01d83d 100644 --- a/benchmark/next-devup-ui-large-wasm/next.config.ts +++ b/benchmark/next-devup-ui-large-wasm/next.config.ts @@ -2,4 +2,4 @@ import { DevupUI } from '@devup-ui/next-plugin' const nextConfig = { experimental: { useTypeScriptCli: true } } -export default DevupUI(nextConfig, { engine: 'wasm' }) +export default DevupUI(nextConfig, { engine: 'wasm', licenseBanner: false }) diff --git a/benchmark/next-devup-ui-large/next.config.ts b/benchmark/next-devup-ui-large/next.config.ts index 5af9af04e..b9c7fdd9f 100644 --- a/benchmark/next-devup-ui-large/next.config.ts +++ b/benchmark/next-devup-ui-large/next.config.ts @@ -2,4 +2,4 @@ import { DevupUI } from '@devup-ui/next-plugin' const nextConfig = { experimental: { useTypeScriptCli: true } } -export default DevupUI(nextConfig, {}) +export default DevupUI(nextConfig, { licenseBanner: false }) diff --git a/benchmark/next-devup-ui-single-turbo/next.config.mjs b/benchmark/next-devup-ui-single-turbo/next.config.mjs index 8b2b3bf05..02282a967 100644 --- a/benchmark/next-devup-ui-single-turbo/next.config.mjs +++ b/benchmark/next-devup-ui-single-turbo/next.config.mjs @@ -5,4 +5,4 @@ import { DevupUI } from '@devup-ui/next-plugin' /** @satisfies {import('next').NextConfig} */ const nextConfig = { experimental: { useTypeScriptCli: true } } -export default DevupUI(nextConfig, { singleCss: true }) +export default DevupUI(nextConfig, { singleCss: true, licenseBanner: false }) diff --git a/benchmark/next-devup-ui-single/next.config.ts b/benchmark/next-devup-ui-single/next.config.ts index 978420890..9cc919ea8 100644 --- a/benchmark/next-devup-ui-single/next.config.ts +++ b/benchmark/next-devup-ui-single/next.config.ts @@ -2,4 +2,4 @@ import { DevupUI } from '@devup-ui/next-plugin' const nextConfig = { experimental: { useTypeScriptCli: true } } -export default DevupUI(nextConfig, { singleCss: true }) +export default DevupUI(nextConfig, { singleCss: true, licenseBanner: false }) diff --git a/benchmark/next-devup-ui-turbo/next.config.ts b/benchmark/next-devup-ui-turbo/next.config.ts index 5af9af04e..b9c7fdd9f 100644 --- a/benchmark/next-devup-ui-turbo/next.config.ts +++ b/benchmark/next-devup-ui-turbo/next.config.ts @@ -2,4 +2,4 @@ import { DevupUI } from '@devup-ui/next-plugin' const nextConfig = { experimental: { useTypeScriptCli: true } } -export default DevupUI(nextConfig, {}) +export default DevupUI(nextConfig, { licenseBanner: false }) diff --git a/benchmark/next-devup-ui/next.config.ts b/benchmark/next-devup-ui/next.config.ts index 5af9af04e..b9c7fdd9f 100644 --- a/benchmark/next-devup-ui/next.config.ts +++ b/benchmark/next-devup-ui/next.config.ts @@ -2,4 +2,4 @@ import { DevupUI } from '@devup-ui/next-plugin' const nextConfig = { experimental: { useTypeScriptCli: true } } -export default DevupUI(nextConfig, {}) +export default DevupUI(nextConfig, { licenseBanner: false }) diff --git a/benchmark/next-stylex-turbo-devup-ui/next.config.mjs b/benchmark/next-stylex-turbo-devup-ui/next.config.mjs index bbd839d60..bfd980ac8 100644 --- a/benchmark/next-stylex-turbo-devup-ui/next.config.mjs +++ b/benchmark/next-stylex-turbo-devup-ui/next.config.mjs @@ -2,5 +2,5 @@ import { DevupUI } from '@devup-ui/next-plugin' export default DevupUI( { experimental: { useTypeScriptCli: true } }, - { singleCss: true }, + { singleCss: true, licenseBanner: false }, ) diff --git a/benchmark/next-tailwind-turbo-devup-ui/next.config.mjs b/benchmark/next-tailwind-turbo-devup-ui/next.config.mjs index e0668cb13..4c863044d 100644 --- a/benchmark/next-tailwind-turbo-devup-ui/next.config.mjs +++ b/benchmark/next-tailwind-turbo-devup-ui/next.config.mjs @@ -1,3 +1,6 @@ import { DevupUI } from '@devup-ui/next-plugin' -export default DevupUI({ experimental: { useTypeScriptCli: true } }) +export default DevupUI( + { experimental: { useTypeScriptCli: true } }, + { licenseBanner: false }, +) diff --git a/benchmark/next-vanilla-extract-devup-ui/next.config.mjs b/benchmark/next-vanilla-extract-devup-ui/next.config.mjs index e0668cb13..4c863044d 100644 --- a/benchmark/next-vanilla-extract-devup-ui/next.config.mjs +++ b/benchmark/next-vanilla-extract-devup-ui/next.config.mjs @@ -1,3 +1,6 @@ import { DevupUI } from '@devup-ui/next-plugin' -export default DevupUI({ experimental: { useTypeScriptCli: true } }) +export default DevupUI( + { experimental: { useTypeScriptCli: true } }, + { licenseBanner: false }, +) diff --git a/benchmark/vinext-devup-ui/vite.config.ts b/benchmark/vinext-devup-ui/vite.config.ts index e46db26c8..ad07fd6d1 100644 --- a/benchmark/vinext-devup-ui/vite.config.ts +++ b/benchmark/vinext-devup-ui/vite.config.ts @@ -3,5 +3,5 @@ import vinext from 'vinext' import { defineConfig } from 'vite' export default defineConfig({ - plugins: [DevupUI(), vinext()], + plugins: [DevupUI({ licenseBanner: false }), vinext()], }) diff --git a/bindings/argument-validation.cjs b/bindings/argument-validation.cjs index a0e3edb41..7b9f5b658 100644 --- a/bindings/argument-validation.cjs +++ b/bindings/argument-validation.cjs @@ -22,6 +22,7 @@ module.exports = function createBoundary() { seedFileMap: 'files:a', setAtomHoist: 'threshold:n', setDebug: 'debug:b', + setLicenseBanner: 'enabled:b', setModuleResolver: 'resolver:f', setPrefix: 'prefix:p', } diff --git a/bindings/devup-ui-binding/README.md b/bindings/devup-ui-binding/README.md index 71afa1212..54ae52197 100644 --- a/bindings/devup-ui-binding/README.md +++ b/bindings/devup-ui-binding/README.md @@ -96,4 +96,4 @@ The decoder is private and target-bounded: unused Serde hints use trait forwardi Malformed-enum error paths follow shipped serde-wasm-bindgen 0.6.5: Object.entries result length is read and coerced once for the check, then read and coerced again for the invalid-length diagnostic when the first length is not one, before any index read. The second value supplies the diagnostic; errors thrown by its getter or coercion propagate unchanged. Valid enums retain one length read. -The shared native/WASM boundary validates ordinary calls at 46 argument positions in 19 functions: malformed inputs throw a genuine `TypeError` naming the function, parameter and required type before state mutation. Preflight defaults the entire alias map on schema failure (after diagnostics) or a caught iterator-import failure whose `new Error(String(error))` conversion succeeds. Raw access failures and conversion faults escape unchanged before resolver selection; conversion runs once with the pending failure cleared, so reentry is isolated and resolver changes take effect before the outer core starts. Extraction and reservation remain strict. For example, `setPrefix(false)` throws `setPrefix(): argument prefix must be a string, null or undefined`; string/nullish prefixes remain supported. Extraction wrappers retain the measured metadata, receiver, extra-argument and apply/construct policy; `seedFileMap` validates and copies the caller's array before engine entry without rereading its indices. Same-revision Node/Bun identity, 272-case invalid-input, 73-exception preservation and seed-safety gates cover these contracts, not optimized shipping-native performance or real Node-host Linux Rust/authored-JS 100% coverage, which remain public-delivery gates. +The shared native/WASM boundary validates ordinary calls at 47 argument positions in 20 functions: malformed inputs throw a genuine `TypeError` naming the function, parameter and required type before state mutation. Preflight defaults the entire alias map on schema failure (after diagnostics) or a caught iterator-import failure whose `new Error(String(error))` conversion succeeds. Raw access failures and conversion faults escape unchanged before resolver selection; conversion runs once with the pending failure cleared, so reentry is isolated and resolver changes take effect before the outer core starts. Extraction and reservation remain strict. For example, `setPrefix(false)` throws `setPrefix(): argument prefix must be a string, null or undefined`; string/nullish prefixes remain supported. Extraction wrappers retain the measured metadata, receiver, extra-argument and apply/construct policy; `seedFileMap` validates and copies the caller's array before engine entry without rereading its indices. Same-revision Node/Bun identity, 276-case invalid-input, 73-exception preservation and seed-safety gates cover these contracts, not optimized shipping-native performance or real Node-host Linux Rust/authored-JS 100% coverage, which remain public-delivery gates. diff --git a/bindings/devup-ui-binding/adapter.cjs b/bindings/devup-ui-binding/adapter.cjs index a34c93cac..db16d73fe 100644 --- a/bindings/devup-ui-binding/adapter.cjs +++ b/bindings/devup-ui-binding/adapter.cjs @@ -100,6 +100,7 @@ exports.createBinding = function createBinding(raw) { importFileRoutes: (value) => call(raw.importFileRoutes, value), importSheet: (value) => call(raw.importSheet, value), isDebug: raw.isDebug, + isLicenseBanner: raw.isLicenseBanner, registerShorthands: (value) => call(raw.registerShorthands, value), registerTheme: (value) => call(raw.registerTheme, value), removeFile: (filename) => raw.removeFile(filename), @@ -110,6 +111,7 @@ exports.createBinding = function createBinding(raw) { seedFileMap, setAtomHoist: (value) => raw.setAtomHoist(index(value)), setDebug: (value) => raw.setDebug(value), + setLicenseBanner: (value) => raw.setLicenseBanner(value), setModuleResolver, setPrefix: (value) => raw.setPrefix(value == null ? undefined : value), }) diff --git a/bindings/devup-ui-binding/index.d.cts b/bindings/devup-ui-binding/index.d.cts index eae4ba96a..842bb21d8 100644 --- a/bindings/devup-ui-binding/index.d.cts +++ b/bindings/devup-ui-binding/index.d.cts @@ -63,6 +63,8 @@ export function importFileMap(value: unknown): void export function importFileRoutes(value: unknown): void export function importSheet(value: unknown): void export function isDebug(): boolean +/** Whether emitted stylesheets start with the license banner (on by default). */ +export function isLicenseBanner(): boolean export function registerShorthands(value: unknown): void export function registerTheme(value: unknown): void /** Forget a deleted source file's own styles; whether the sheet changed. */ @@ -80,6 +82,8 @@ export function resetStateForTesting(): void export function seedFileMap(files: string[]): void export function setAtomHoist(threshold?: number | null): void export function setDebug(debug: boolean): void +/** Turn the license banner of emitted stylesheets on or off. */ +export function setLicenseBanner(enabled: boolean): void export function setModuleResolver( resolver?: | (( diff --git a/bindings/devup-ui-binding/index.mjs b/bindings/devup-ui-binding/index.mjs index 015b58724..1524fd3f0 100644 --- a/bindings/devup-ui-binding/index.mjs +++ b/bindings/devup-ui-binding/index.mjs @@ -20,6 +20,7 @@ export const { importFileRoutes, importSheet, isDebug, + isLicenseBanner, registerShorthands, registerTheme, removeFile, @@ -29,6 +30,7 @@ export const { seedFileMap, setAtomHoist, setDebug, + setLicenseBanner, setModuleResolver, setPrefix, } = binding diff --git a/bindings/devup-ui-binding/src/lib.rs b/bindings/devup-ui-binding/src/lib.rs index 7211b6d16..8fdd217e2 100644 --- a/bindings/devup-ui-binding/src/lib.rs +++ b/bindings/devup-ui-binding/src/lib.rs @@ -205,6 +205,16 @@ pub fn set_debug(value: bool) { pub fn is_debug() -> bool { core::is_debug() } +/// Turn the license banner of emitted stylesheets on or off. +#[napi] +pub fn set_license_banner(value: bool) { + core::set_license_banner(value); +} +/// Read whether emitted stylesheets carry the license banner. +#[napi] +pub fn is_license_banner() -> bool { + core::is_license_banner() +} /// Set hoisting after facade nullish/unsigned-i32 conversion. #[napi] pub fn set_atom_hoist(value: Option) { diff --git a/bindings/devup-ui-wasm/AGENTS.md b/bindings/devup-ui-wasm/AGENTS.md index 0a26113a8..1fcd3f3c9 100644 --- a/bindings/devup-ui-wasm/AGENTS.md +++ b/bindings/devup-ui-wasm/AGENTS.md @@ -22,6 +22,7 @@ Rust → WebAssembly → JavaScript bridge. Exposes extraction engine to build p ### Configuration - `setPrefix()/getPrefix()` - Class name prefix - `setDebug()/isDebug()` - Debug mode +- `setLicenseBanner()/isLicenseBanner()` - License banner of emitted stylesheets (on by default) ## OUTPUT STRUCTURE diff --git a/bindings/devup-ui-wasm/README.md b/bindings/devup-ui-wasm/README.md index 066708bcf..c794b4e03 100644 --- a/bindings/devup-ui-wasm/README.md +++ b/bindings/devup-ui-wasm/README.md @@ -23,21 +23,22 @@ repository root fails if one does. Everything is exported from `pkg/index.js` (types in `pkg/index.d.ts`). -| Function | Does | -| ----------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| Function | Does | +| ----------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `codeExtract(filename, code, package, cssDir, singleCss, importMainCssInCode, importMainCssInCss, importAliases)` | Compiles one source file and returns an `Output`: the rewritten `code`, its `css`, `cssFile`, source `map`, the `dependencies` it read and `updatedBaseStyle`. Throws on a build error. | -| `codeExtractWithoutSourceMap(...)` | The same without the source map. | -| `hasDevupUI(filename, code, package)` | Whether the file imports Devup UI, so a plugin can skip the rest. | -| `getCss(fileNum, importMainCss)` | The stylesheet collected so far: the whole sheet for `null`, one file's for its number. | +| `codeExtractWithoutSourceMap(...)` | The same without the source map. | +| `hasDevupUI(filename, code, package)` | Whether the file imports Devup UI, so a plugin can skip the rest. | +| `getCss(fileNum, importMainCss)` | The stylesheet collected so far: the whole sheet for `null`, one file's for its number. | | `removeFile(filename)` | Forgets a deleted source file: its global CSS, its own stylesheet and the class names handed out in it. Returns whether the sheet changed. | -| `registerTheme(theme)`, `registerShorthands(shorthands)` | Registers the `devup.json` theme and the custom shorthand props before extracting. | -| `getThemeInterface(package, color, typography, length, shadows, theme)` | The `.d.ts` text that types the registered theme. | -| `getDefaultTheme()` | The theme variant that applies without `data-theme`. | -| `setPrefix(prefix)`, `getPrefix()` | Class name prefix. | -| `setDebug(debug)`, `isDebug()` | Readable class names instead of base-37 ones, with repeated declarations kept (the tests run this way). | -| `setModuleResolver(resolver)` | `(specifier, importer) => ({ path, code })`: how imports are resolved, so imported stylesheets are evaluated and imported constants inlined. | -| `setAtomHoist(threshold)`, `importFileRoutes(routes)` | Moves atoms used by `threshold` routes or more into the shared sheet. Call before `codeExtract`. | -| `exportSheet`, `exportClassMap`, `exportFileMap`, `exportCanonicalMap` and the matching `import*` functions | Save the collected state and load it into another process, as a bundler does between its server and client builds. | +| `registerTheme(theme)`, `registerShorthands(shorthands)` | Registers the `devup.json` theme and the custom shorthand props before extracting. | +| `getThemeInterface(package, color, typography, length, shadows, theme)` | The `.d.ts` text that types the registered theme. | +| `getDefaultTheme()` | The theme variant that applies without `data-theme`. | +| `setPrefix(prefix)`, `getPrefix()` | Class name prefix. | +| `setDebug(debug)`, `isDebug()` | Readable class names instead of base-37 ones, with repeated declarations kept (the tests run this way). | +| `setLicenseBanner(enabled)`, `isLicenseBanner()` | Whether every stylesheet starts with the `/*! devup-ui v… */` license banner. On by default. A stylesheet without any rule is emitted empty either way. | +| `setModuleResolver(resolver)` | `(specifier, importer) => ({ path, code })`: how imports are resolved, so imported stylesheets are evaluated and imported constants inlined. | +| `setAtomHoist(threshold)`, `importFileRoutes(routes)` | Moves atoms used by `threshold` routes or more into the shared sheet. Call before `codeExtract`. | +| `exportSheet`, `exportClassMap`, `exportFileMap`, `exportCanonicalMap` and the matching `import*` functions | Save the collected state and load it into another process, as a bundler does between its server and client builds. | ## State diff --git a/bindings/devup-ui-wasm/script.js b/bindings/devup-ui-wasm/script.js index 7bc343dff..4cf3cbebc 100644 --- a/bindings/devup-ui-wasm/script.js +++ b/bindings/devup-ui-wasm/script.js @@ -50,9 +50,9 @@ types = types.replace(hookType, '') assert.equal(types.includes('install_panic_hook'), false) writeFileSync('pkg/index.d.ts', types, 'utf8') const names = [...source.matchAll(/^exports\.(\w+) = \1;/gm)] -assert.equal(names.length, 30) -assert.equal(new Set(names.map((match) => match[1])).size, 30) -assert.equal([...source.matchAll(/^exports\./gm)].length, 30) +assert.equal(names.length, 32) +assert.equal(new Set(names.map((match) => match[1])).size, 32) +assert.equal([...source.matchAll(/^exports\./gm)].length, 32) assert.equal(source.includes('module.exports'), false) for (const name of ['codeExtract', 'codeExtractWithoutSourceMap']) { const signatures = [ diff --git a/bindings/devup-ui-wasm/src/lib.rs b/bindings/devup-ui-wasm/src/lib.rs index 067b5abb6..8dec0bca3 100644 --- a/bindings/devup-ui-wasm/src/lib.rs +++ b/bindings/devup-ui-wasm/src/lib.rs @@ -154,6 +154,17 @@ pub fn is_debug() -> bool { binding_core::is_debug() } +#[wasm_bindgen(js_name = "setLicenseBanner")] +pub fn set_license_banner(enabled: bool) { + binding_core::set_license_banner(enabled); +} + +#[wasm_bindgen(js_name = "isLicenseBanner")] +#[must_use] +pub fn is_license_banner() -> bool { + binding_core::is_license_banner() +} + /// Set the CSS class name prefix /// /// # Example (Vite Config) @@ -930,10 +941,8 @@ mod tests { let mut sheet = GLOBAL_STYLE_SHEET.lock().unwrap(); *sheet = StyleSheet::default(); } - assert_eq!( - get_css(None, false).unwrap().split("*/").nth(1).unwrap(), - "" - ); + // An empty sheet is emitted empty, without even the banner + assert_eq!(get_css(None, false).unwrap(), ""); { let mut sheet = GLOBAL_STYLE_SHEET.lock().unwrap(); @@ -1260,6 +1269,17 @@ mod tests { assert!(!is_debug()); } + #[test] + #[serial] + fn test_license_banner() { + let _state = TestStateGuard::new(); + assert!(is_license_banner()); + set_license_banner(false); + assert!(!is_license_banner()); + set_license_banner(true); + assert!(is_license_banner()); + } + #[test] #[serial] fn test_prefix() { diff --git a/e2e/binding/host.mjs b/e2e/binding/host.mjs index a86141ce5..cd2b59587 100644 --- a/e2e/binding/host.mjs +++ b/e2e/binding/host.mjs @@ -68,7 +68,7 @@ save('provenance.json', { scenarios: corpus.map((c) => c.name), }) const names = - 'Output codeExtract codeExtractWithoutSourceMap exportCanonicalMap exportClassMap exportFileMap exportSheet getCss getDefaultTheme getPrefix getThemeInterface getUnreservedClassSlotCount hasDevupUI importCanonicalMap importClassMap importFileMap importFileRoutes importSheet isDebug registerShorthands registerTheme removeFile reserveClassSlots resetBuildState resetStateForTesting seedFileMap setAtomHoist setDebug setModuleResolver setPrefix'.split( + 'Output codeExtract codeExtractWithoutSourceMap exportCanonicalMap exportClassMap exportFileMap exportSheet getCss getDefaultTheme getPrefix getThemeInterface getUnreservedClassSlotCount hasDevupUI importCanonicalMap importClassMap importFileMap importFileRoutes importSheet isDebug isLicenseBanner registerShorthands registerTheme removeFile reserveClassSlots resetBuildState resetStateForTesting seedFileMap setAtomHoist setDebug setLicenseBanner setModuleResolver setPrefix'.split( ' ', ) const abi = { @@ -117,6 +117,7 @@ const snapshot = () => ({ [ 'getPrefix', 'isDebug', + 'isLicenseBanner', 'getDefaultTheme', 'getUnreservedClassSlotCount', ].map((name) => [name, capture(() => w[name]())]), diff --git a/e2e/binding/validation-cases.mjs b/e2e/binding/validation-cases.mjs index f69d04387..b443f1822 100644 --- a/e2e/binding/validation-cases.mjs +++ b/e2e/binding/validation-cases.mjs @@ -47,6 +47,7 @@ export const positions = [ ['seedFileMap', 'files:seed', () => [['src/new.tsx']]], ['setAtomHoist', 'threshold:n', () => [2]], ['setDebug', 'debug:b', () => [true]], + ['setLicenseBanner', 'enabled:b', () => [false]], ['setModuleResolver', 'resolver:resolver', () => [null]], ['setPrefix', 'prefix:prefix', () => ['valid-']], ].flatMap(([fn, slots, args]) => @@ -154,6 +155,6 @@ export const cases = positions.flatMap((position) => .map((good, index) => (index === position.index ? value : good)), })), ) -assert.equal(positions.length, 46) -assert.equal(new Set(positions.map((p) => p.fn)).size, 19) +assert.equal(positions.length, 47) +assert.equal(new Set(positions.map((p) => p.fn)).size, 20) assert.equal(new Set(cases.map((c) => c.id)).size, cases.length) diff --git a/e2e/binding/validation-host.mjs b/e2e/binding/validation-host.mjs index 94eade6b6..c071e186d 100644 --- a/e2e/binding/validation-host.mjs +++ b/e2e/binding/validation-host.mjs @@ -47,6 +47,7 @@ const extract = (filename, text) => { w.resetStateForTesting() w.setPrefix('kept-') w.setDebug(true) +w.setLicenseBanner(false) w.registerTheme(theme) w.registerShorthands({ insetX: ['left', 'right'] }) w.importCanonicalMap({ 'src/kept.tsx': 'src/root.tsx' }) @@ -71,6 +72,7 @@ const snapshot = () => ({ config: [ 'getPrefix', 'isDebug', + 'isLicenseBanner', 'getDefaultTheme', 'getUnreservedClassSlotCount', ].map((name) => capture(() => w[name]())), diff --git a/libs/binding/src/css_cache.rs b/libs/binding/src/css_cache.rs index 61e005049..b399ee749 100644 --- a/libs/binding/src/css_cache.rs +++ b/libs/binding/src/css_cache.rs @@ -11,8 +11,9 @@ use std::ops::{Deref, DerefMut}; use std::sync::{LazyLock, LockResult, Mutex, MutexGuard, PoisonError}; /// What a serialization reads besides the sheet: the bucket, whether a file -/// stylesheet imports the shared base, and whether atom hoisting is in effect. -type Key = (Option, bool, bool); +/// stylesheet imports the shared base, whether atom hoisting is in effect, and +/// whether the license banner is on. +type Key = (Option, bool, bool, bool); static CSS_CACHE: LazyLock>> = LazyLock::new(Mutex::default); @@ -26,6 +27,7 @@ fn key(bucket: Option<&str>, import_main_css: bool) -> Key { bucket.map(str::to_string), bucket.is_some() && import_main_css, css::atom_hoist::is_atom_hoist(), + css::license_banner::is_license_banner(), ) } @@ -99,6 +101,23 @@ mod tests { assert_ne!(key(Some("a.tsx"), true), key(Some("a.tsx"), false)); } + #[test] + #[serial_test::serial] + fn the_license_banner_setting_keys_a_serialization() { + let _state = css::test_state::TestStateGuard::new(); + invalidate_css(); + let mut sheet = StyleSheet::default(); + sheet.add_property("a", "color", 0, "red", None, Some(255), None); + let with_banner = cached_css(&sheet, None, false); + assert!(with_banner.starts_with("/*! devup-ui v")); + // A serialization cached with the banner is not served without it + css::license_banner::set_license_banner(false); + assert_eq!(cached_css(&sheet, None, false), ".a{color:red}"); + css::license_banner::set_license_banner(true); + assert_eq!(cached_css(&sheet, None, false), with_banner); + invalidate_css(); + } + #[test] fn a_poisoned_sheet_stays_usable() { let cell = SheetCell::default(); diff --git a/libs/binding/src/lib.rs b/libs/binding/src/lib.rs index a7d7a4c23..b0a143b31 100644 --- a/libs/binding/src/lib.rs +++ b/libs/binding/src/lib.rs @@ -6,6 +6,7 @@ mod reservation; mod resolver_state; pub use css::debug::{is_debug, set_debug}; +pub use css::license_banner::{is_license_banner, set_license_banner}; pub use css::slot_reservation::unreserved_slot_count as get_unreserved_class_slot_count; pub use css::{get_prefix, set_custom_shorthands as register_shorthands_internal, set_prefix}; pub use css_cache::{SheetCell, SheetGuard}; diff --git a/libs/css/src/lib.rs b/libs/css/src/lib.rs index 43e2509a6..2288f1547 100644 --- a/libs/css/src/lib.rs +++ b/libs/css/src/lib.rs @@ -9,6 +9,7 @@ pub mod debug; pub mod file_map; pub mod file_routes; pub mod is_special_property; +pub mod license_banner; mod num_to_nm_base; pub mod optimize_multi_css_value; pub mod optimize_value; diff --git a/libs/css/src/license_banner.rs b/libs/css/src/license_banner.rs new file mode 100644 index 000000000..e7784f20a --- /dev/null +++ b/libs/css/src/license_banner.rs @@ -0,0 +1,34 @@ +//! Whether emitted stylesheets start with the `/*! devup-ui ... */` license banner. + +use std::sync::atomic::{AtomicBool, Ordering}; + +static LICENSE_BANNER: AtomicBool = AtomicBool::new(true); + +/// Turn the license banner of emitted stylesheets on or off (on by default). +#[inline(always)] +pub fn set_license_banner(value: bool) { + LICENSE_BANNER.store(value, Ordering::Relaxed); +} + +/// Whether emitted stylesheets start with the license banner. +#[inline(always)] +pub fn is_license_banner() -> bool { + LICENSE_BANNER.load(Ordering::Relaxed) +} + +#[cfg(test)] +mod tests { + use super::*; + use serial_test::serial; + + #[test] + #[serial] + fn test_set_license_banner() { + let _state = crate::test_state::TestStateGuard::new(); + assert!(is_license_banner()); + set_license_banner(false); + assert!(!is_license_banner()); + set_license_banner(true); + assert!(is_license_banner()); + } +} diff --git a/libs/css/src/test_state.rs b/libs/css/src/test_state.rs index 4a0929e5c..f2f2c8e06 100644 --- a/libs/css/src/test_state.rs +++ b/libs/css/src/test_state.rs @@ -8,8 +8,8 @@ use std::rc::Rc; use std::sync::atomic::Ordering; use crate::{ - atom_hoist, class_map, debug, file_map, file_routes, slot_reservation, tailwind_definitions, - theme_tokens, + atom_hoist, class_map, debug, file_map, file_routes, license_banner, slot_reservation, + tailwind_definitions, theme_tokens, }; pub(crate) fn replace_shorthands( @@ -29,6 +29,7 @@ pub(crate) fn replace_shorthands( pub fn reset_state_for_testing() { crate::set_prefix(None); debug::set_debug(false); + license_banner::set_license_banner(true); atom_hoist::set_atom_hoist(None); atom_hoist::restore_atom_plan(None); slot_reservation::reset(); @@ -47,6 +48,7 @@ pub fn reset_state_for_testing() { pub struct TestStateGuard { prefix: Option, debug: bool, + license_banner: bool, hoist: Option, plan: Option>, reservation: slot_reservation::State, @@ -66,6 +68,7 @@ impl TestStateGuard { let guard = Self { prefix: crate::get_prefix(), debug: debug::is_debug(), + license_banner: license_banner::is_license_banner(), hoist: atom_hoist::atom_hoist_threshold(), plan: atom_hoist::atom_plan(), reservation: slot_reservation::replace_state(Default::default()), @@ -93,6 +96,7 @@ impl Drop for TestStateGuard { fn drop(&mut self) { crate::set_prefix(self.prefix.take()); debug::set_debug(self.debug); + license_banner::set_license_banner(self.license_banner); atom_hoist::set_atom_hoist(self.hoist); atom_hoist::restore_atom_plan(self.plan.take()); slot_reservation::replace_state(std::mem::take(&mut self.reservation)); diff --git a/libs/extractor/README.md b/libs/extractor/README.md index 706dcfd13..be757364a 100644 --- a/libs/extractor/README.md +++ b/libs/extractor/README.md @@ -34,7 +34,7 @@ function Example({ variable }: { Generated CSS: ```css -/*! devup-ui v1.0.82, | Apache License 2.0 | https://devup-ui.com */.a{background:red}.b{color:white}.c{margin:8px}.d{padding:8px}.e{text-align:var(--f)} +/*! devup-ui v1.0.82 | Apache License 2.0 | https://devup-ui.com */.a{background:red}.b{color:white}.c{margin:8px}.d{padding:8px}.e{text-align:var(--f)} ``` ```mermaid diff --git a/libs/sheet/src/lib.rs b/libs/sheet/src/lib.rs index 4a3478516..1bca058ac 100644 --- a/libs/sheet/src/lib.rs +++ b/libs/sheet/src/lib.rs @@ -178,20 +178,40 @@ static VAR_RE: LazyLock = LazyLock::new(|| compile_regex(r"\$\w[\w.-]*")) static INTERFACE_KEY_RE: LazyLock = LazyLock::new(|| compile_regex(r"^[a-zA-Z_$][a-zA-Z0-9_$]*$")); -/// Cached header string — computed once from compile-time included package.json +/// Cached header string — computed once from compile-time included package.json. +/// The version is the published npm version of `@devup-ui/wasm` (the Cargo +/// crates stay at `0.1.0`); both engines build this crate, so they share it. static HEADER: LazyLock = LazyLock::new(|| { format!( "/*! devup-ui v{version} | Apache License 2.0 | https://devup-ui.com */", - version = include_str!("../../../bindings/devup-ui-wasm/package.json") - .lines() - .find(|line| line.contains("\"version\"")) - .and_then(|line| line.split(':').nth(1)) - .unwrap_or("\"unknown\"") - .trim() - .replace('"', ""), + version = package_version(include_str!("../../../bindings/devup-ui-wasm/package.json")), ) }); +/// The `version` field of a `package.json` manifest, or `unknown` without one +fn package_version(manifest: &str) -> String { + serde_json::from_str::(manifest) + .ok() + .and_then(|manifest| manifest.get("version")?.as_str().map(str::to_owned)) + .unwrap_or_else(|| "unknown".to_string()) +} + +/// The license banner, or nothing when the build turned it off +fn license_header(enabled: bool) -> &'static str { + if enabled { &HEADER } else { "" } +} + +/// A sheet without any rule is emitted empty rather than as a bare banner. The +/// shared base sheet is `@import`ed by every per-file sheet, so a banner-only +/// base would put the banner twice into one stylesheet chain. +fn without_bare_header(css: String, header: &str) -> String { + if css.len() == header.len() { + String::new() + } else { + css + } +} + fn convert_interface_key(key: &str) -> Cow<'_, str> { if INTERFACE_KEY_RE.is_match(key) { Cow::Borrowed(key) @@ -1302,13 +1322,14 @@ impl StyleSheet { #[inline] fn create_header() -> &'static str { - &HEADER + license_header(css::license_banner::is_license_banner()) } #[must_use] pub fn create_css(&self, filename: Option<&str>, import_main_css: bool) -> String { let mut css = String::with_capacity(4096); - css.push_str(Self::create_header()); + let header = Self::create_header(); + css.push_str(header); // An import written again takes effect where it is written last let imports: Vec<&String> = self.imports.values().flatten().collect(); for (index, import) in imports.iter().enumerate() { @@ -1563,7 +1584,7 @@ impl StyleSheet { } } } - css + without_bare_header(css, header) } } @@ -1670,6 +1691,70 @@ mod tests { assert_eq!(convert_theme_variable_value(input), expected); } + #[rstest] + #[case(r#"{"name":"a","version":"1.0.83","b":1}"#, "1.0.83")] + #[case("{\n \"version\": \"2.3.4\",\n \"x\": 1\n}", "2.3.4")] + #[case(r#"{"name":"a"}"#, "unknown")] + #[case(r#"{"version":1}"#, "unknown")] + #[case("not json", "unknown")] + fn test_package_version(#[case] manifest: &str, #[case] expected: &str) { + assert_eq!(package_version(manifest), expected); + } + + #[test] + fn test_header_names_the_published_version() { + // `@devup-ui/wasm`'s package.json holds the npm version; the old line + // split left the JSON comma in it (`v1.0.83,`). + let version = package_version(include_str!("../../../bindings/devup-ui-wasm/package.json")); + assert!( + compile_regex(r"^\d+\.\d+\.\d+").is_match(&version), + "{version}" + ); + assert_eq!( + license_header(true), + format!("/*! devup-ui v{version} | Apache License 2.0 | https://devup-ui.com */") + ); + assert_eq!(license_header(false), ""); + } + + #[test] + fn test_without_bare_header() { + assert_eq!(without_bare_header(HEADER.clone(), &HEADER), ""); + assert_eq!(without_bare_header(String::new(), ""), ""); + assert_eq!( + without_bare_header(format!("{}a{{}}", *HEADER), &HEADER), + format!("{}a{{}}", *HEADER) + ); + } + + #[test] + #[serial] + fn test_license_banner_option() { + let _state = css::test_state::TestStateGuard::new(); + let mut sheet = StyleSheet::default(); + // A sheet without rules ships nothing, banner or not + assert_eq!(sheet.create_css(None, false), ""); + assert_eq!(sheet.create_css(Some("a.tsx"), false), ""); + sheet.add_property("a", "color", 0, "red", None, Some(255), None); + // On by default + let with_banner = sheet.create_css(None, false); + assert_eq!(with_banner, format!("{}.a{{color:red}}", *HEADER)); + // The per-file sheet keeps importing the shared base, banner or not + assert_eq!( + sheet.create_css(Some("other.tsx"), true), + format!("{}@import \"./devup-ui.css\";", *HEADER) + ); + css::license_banner::set_license_banner(false); + assert_eq!(sheet.create_css(None, false), ".a{color:red}"); + assert_eq!( + sheet.create_css(Some("other.tsx"), true), + "@import \"./devup-ui.css\";" + ); + assert_eq!(sheet.create_css(Some("other.tsx"), false), ""); + css::license_banner::set_license_banner(true); + assert_eq!(sheet.create_css(None, false), with_banner); + } + #[test] #[serial] fn test_create_css_sort_test() { @@ -3036,7 +3121,15 @@ mod tests { assert_debug_snapshot!(sheet.create_css(None, false).split("*/").nth(1).unwrap()); sheet.rm_global_css("test.tsx", true); - assert_debug_snapshot!(sheet.create_css(None, false).split("*/").nth(1).unwrap()); + // Nothing is left, so the sheet is emitted empty, banner included + assert_eq!(sheet.create_css(None, false), ""); + assert_debug_snapshot!( + sheet + .create_css(None, false) + .split("*/") + .nth(1) + .unwrap_or_default() + ); let mut sheet = StyleSheet::default(); sheet.add_property( @@ -3986,11 +4079,8 @@ mod tests { let filename = if single_css { None } else { Some("test.tsx") }; let css = sheet.create_css(filename, false); if !single_css { - assert_eq!(sheet.create_css(None, false), StyleSheet::create_header()); - assert_eq!( - sheet.create_css(Some("other.tsx"), false), - StyleSheet::create_header() - ); + assert_eq!(sheet.create_css(None, false), ""); + assert_eq!(sheet.create_css(Some("other.tsx"), false), ""); } // Class names come from a process-wide counter; number them by first // appearance so the expected CSS only pins down structure and order. diff --git a/packages/bun-plugin/README.md b/packages/bun-plugin/README.md index 3fb45ddf9..09d3f1262 100644 --- a/packages/bun-plugin/README.md +++ b/packages/bun-plugin/README.md @@ -88,6 +88,17 @@ errors retain their cause and identify the missing platform package; they never silently select WASM. Each factory retains its selected compiler for later loads and theme reloads. Independent concurrent builds in one process are unsupported. +## License Banner + +Every emitted stylesheet starts with a +`/*! devup-ui v… | Apache License 2.0 | https://devup-ui.com */` comment, which +minifiers keep. It is on by default; `licenseBanner: false` drops it from every +stylesheet. A stylesheet without any rule is emitted empty, banner included. + +```ts +await register({ licenseBanner: false }) +``` + ## Custom Shorthands To configure custom shorthands, preload a local module instead of the diff --git a/packages/bun-plugin/src/__tests__/plugin.test.ts b/packages/bun-plugin/src/__tests__/plugin.test.ts index 9d656825a..82474c27f 100644 --- a/packages/bun-plugin/src/__tests__/plugin.test.ts +++ b/packages/bun-plugin/src/__tests__/plugin.test.ts @@ -223,6 +223,20 @@ describe('registered Bun hooks', () => { expect(loads.length).toBe(2) }) + it('turns the license banner off only when asked to', async () => { + try { + await register({ engine: 'wasm', licenseBanner: false }) + expect(wasm.isLicenseBanner()).toBe(false) + await register({ engine: 'wasm', licenseBanner: true }) + expect(wasm.isLicenseBanner()).toBe(true) + wasm.setLicenseBanner(false) + await register({ engine: 'wasm' }) + expect(wasm.isLicenseBanner()).toBe(true) + } finally { + wasm.setLicenseBanner(true) + } + }) + it('warns when runtime file numbering fails, and stays quiet without src', async () => { const collect = spyOn(pluginUtils, 'collectNumberedFiles') const warn = spyOn(console, 'warn').mockImplementation(() => {}) diff --git a/packages/bun-plugin/src/plugin.ts b/packages/bun-plugin/src/plugin.ts index 0e2b55754..a4738a006 100644 --- a/packages/bun-plugin/src/plugin.ts +++ b/packages/bun-plugin/src/plugin.ts @@ -52,6 +52,11 @@ export interface DevupUIBunPluginOptions { * `false` in `Bun.build`. */ debug?: boolean + /** + * Start every emitted stylesheet with the devup-ui license banner comment. + * Defaults to `true`. + */ + licenseBanner?: boolean } type SourceLoader = 'tsx' | 'ts' | 'jsx' | 'js' @@ -198,6 +203,7 @@ function DevupUI(options: DevupUIBunPluginOptions = {}) { // this process left in the engine const endBuild = beginBuild(compiler) build.onEnd?.(endBuild) + compiler.setLicenseBanner(options.licenseBanner ?? true) await initialize(compiler, shorthands, watchTailwindCss) const debug = options.debug ?? !bundling compiler.setDebug(debug) diff --git a/packages/next-plugin/README.md b/packages/next-plugin/README.md index 631d06541..ce32033e0 100644 --- a/packages/next-plugin/README.md +++ b/packages/next-plugin/README.md @@ -219,6 +219,18 @@ original cause. There is no automatic fallback to WASM. Install optional native dependencies normally, or choose WASM explicitly for an unsupported platform. Both engines extract CSS during the build and add no client styling runtime. +## License banner + +Every emitted stylesheet starts with a +`/*! devup-ui v… | Apache License 2.0 | https://devup-ui.com */` comment, which +minifiers keep. It is on by default; `licenseBanner: false` drops it from every +stylesheet, under Webpack and Turbopack alike. A stylesheet without any rule is +emitted empty, banner included. + +```ts +export default DevupUI(nextConfig, { licenseBanner: false }) +``` + ## Turbopack build profiling Set `DEVUP_UI_PROFILE=1` for an opt-in, structured timing log during a diff --git a/packages/next-plugin/src/__tests__/plugin.test.ts b/packages/next-plugin/src/__tests__/plugin.test.ts index 096069c64..5fc85ef79 100644 --- a/packages/next-plugin/src/__tests__/plugin.test.ts +++ b/packages/next-plugin/src/__tests__/plugin.test.ts @@ -443,6 +443,16 @@ describe('DevupUINextPlugin', () => { }) }) + it('hands licenseBanner to the webpack plugin', () => { + DevupUI({}, { licenseBanner: false }).webpack!( + createWebpackConfig(), + createWebpackContext(), + ) + expect(devupUIWebpackPluginSpy).toHaveBeenCalledWith( + expect.objectContaining({ licenseBanner: false }), + ) + }) + it('reads routes from the project root when it holds app or pages', () => { // Given: a Next app with `app/` at the root and no `src/`. existsSyncSpy.mockImplementation( @@ -1145,6 +1155,27 @@ export const box = style({ color: 'red' })` DevupUI({}, { prefix: 'my-prefix' }) expect(setPrefixSpy).toHaveBeenCalledWith('my-prefix') }) + it.each([ + [undefined, true], + [true, true], + [false, false], + ] as const)( + 'sets the license banner from licenseBanner=%s under Turbopack', + (licenseBanner, expected) => { + process.env.TURBOPACK = '1' + using setLicenseBanner = spyOn( + wasm, + 'setLicenseBanner', + ).mockReturnValue(undefined) + existsSyncSpy + .mockReturnValueOnce(true) + .mockReturnValueOnce(true) + .mockReturnValueOnce(true) + .mockReturnValueOnce(false) + DevupUI({}, { licenseBanner }) + expect(setLicenseBanner).toHaveBeenCalledWith(expected) + }, + ) it('numbers the files the scan finds, and survives a failing scan', () => { process.env.TURBOPACK = '1' const collectSpy = spyOn(importGraphModule, 'collectNumberedFiles') diff --git a/packages/next-plugin/src/plugin.ts b/packages/next-plugin/src/plugin.ts index 21aa6042a..c08b99f6b 100644 --- a/packages/next-plugin/src/plugin.ts +++ b/packages/next-plugin/src/plugin.ts @@ -163,6 +163,7 @@ export function DevupUI( devupFile = 'devup.json', include = [], prefix, + licenseBanner = true, atomHoist, importAliases: userImportAliases, } = options @@ -201,6 +202,7 @@ export function DevupUI( importAliases, include, libPackage, + licenseBanner, prefix, shorthands: normalizedShorthands, singleCss, @@ -259,12 +261,14 @@ export function DevupUI( importSheet, registerShorthands, registerTheme, + setLicenseBanner, setPrefix, } = wasm registerShorthands(normalizedShorthands) setPrefix(prefix ?? null) + setLicenseBanner(licenseBanner) writeFileSync( join(distDir, 'compat.d.ts'), diff --git a/packages/plugin-utils/src/__tests__/compiler-types.test.ts b/packages/plugin-utils/src/__tests__/compiler-types.test.ts index c6b757714..8e15dfbea 100644 --- a/packages/plugin-utils/src/__tests__/compiler-types.test.ts +++ b/packages/plugin-utils/src/__tests__/compiler-types.test.ts @@ -78,7 +78,7 @@ describe('compiler structural types', () => { Object.keys(compiler).filter( (key) => key !== 'Output' && key !== 'default', ), - ).toHaveLength(29) + ).toHaveLength(31) } finally { compiler.resetStateForTesting() } diff --git a/packages/plugin-utils/src/__tests__/wasm-abi.test.ts b/packages/plugin-utils/src/__tests__/wasm-abi.test.ts index 45390ebfc..195f26440 100644 --- a/packages/plugin-utils/src/__tests__/wasm-abi.test.ts +++ b/packages/plugin-utils/src/__tests__/wasm-abi.test.ts @@ -16,6 +16,7 @@ function saveState() { canonicalMap: JSON.parse(wasm.exportCanonicalMap()), css: wasm.getCss(null, false), debug: wasm.isDebug(), + licenseBanner: wasm.isLicenseBanner(), prefix: wasm.getPrefix(), } } @@ -26,6 +27,7 @@ function restoreState(state: ReturnType) { wasm.importFileMap(state.fileMap) wasm.importCanonicalMap(state.canonicalMap) wasm.setDebug(state.debug) + wasm.setLicenseBanner(state.licenseBanner) wasm.setPrefix(state.prefix ?? null) } @@ -60,6 +62,7 @@ describe('@devup-ui/wasm exports', () => { 'importFileRoutes', 'importSheet', 'isDebug', + 'isLicenseBanner', 'registerShorthands', 'registerTheme', 'removeFile', @@ -69,6 +72,7 @@ describe('@devup-ui/wasm exports', () => { 'seedFileMap', 'setAtomHoist', 'setDebug', + 'setLicenseBanner', 'setModuleResolver', 'setPrefix', ]) @@ -143,6 +147,26 @@ describe('@devup-ui/wasm extraction', () => { wasm.setPrefix(null) expect(wasm.getPrefix()).toBeUndefined() }) + + it('starts stylesheets with the license banner unless it is turned off', () => { + extract( + `import { Box } from '${PACKAGE}'\nexport const a = `, + 'banner.tsx', + ) + // The banner is on by default and names the published version + expect(wasm.isLicenseBanner()).toBe(true) + const css = wasm.getCss(null, false) + expect(css).toMatch( + /^\/\*! devup-ui v\d+\.\d+\.\d+ \| Apache License 2\.0 \| https:\/\/devup-ui\.com \*\/\S/, + ) + + wasm.setLicenseBanner(false) + expect(wasm.isLicenseBanner()).toBe(false) + expect(wasm.getCss(null, false)).toBe(css.slice(css.indexOf('*/') + 2)) + + wasm.setLicenseBanner(true) + expect(wasm.getCss(null, false)).toBe(css) + }) }) describe('@devup-ui/wasm theme', () => { diff --git a/packages/plugin-utils/src/shared.ts b/packages/plugin-utils/src/shared.ts index 1714c3649..0a7b0ec30 100644 --- a/packages/plugin-utils/src/shared.ts +++ b/packages/plugin-utils/src/shared.ts @@ -117,6 +117,12 @@ export interface DevupUIBasePluginOptions { include: string[] singleCss: boolean prefix?: string + /** + * Start every emitted stylesheet with the `/*! devup-ui v… | Apache License + * 2.0 | https://devup-ui.com *\/` comment, which minifiers keep. Defaults to + * `true`; `false` drops it from every stylesheet. + */ + licenseBanner?: boolean importAliases?: ImportAliases /** Build-time aliases that expand one style prop into multiple CSS properties. */ shorthands?: CustomShorthands diff --git a/packages/rsbuild-plugin/README.md b/packages/rsbuild-plugin/README.md index c94984cf7..3a16fb5fa 100644 --- a/packages/rsbuild-plugin/README.md +++ b/packages/rsbuild-plugin/README.md @@ -197,6 +197,17 @@ The selected compiler serves configuration, reservation, transforms and delayed watch/build callbacks together. Neither engine supports concurrent independent builds in the same process. +## License banner + +Every emitted stylesheet starts with a +`/*! devup-ui v… | Apache License 2.0 | https://devup-ui.com */` comment, which +minifiers keep. It is on by default; `licenseBanner: false` drops it from every +stylesheet. A stylesheet without any rule is emitted empty, banner included. + +```ts +DevupUI({ licenseBanner: false }) +``` + ## Custom Shorthands ```ts diff --git a/packages/rsbuild-plugin/src/__tests__/plugin.test.ts b/packages/rsbuild-plugin/src/__tests__/plugin.test.ts index cdacbcfe2..51dad59ba 100644 --- a/packages/rsbuild-plugin/src/__tests__/plugin.test.ts +++ b/packages/rsbuild-plugin/src/__tests__/plugin.test.ts @@ -880,6 +880,21 @@ const App = () => `, expect(setPrefixSpy).toHaveBeenCalledWith('my-prefix') }) + it.each([ + [undefined, true], + [true, true], + [false, false], + ] as const)( + 'sets the license banner from licenseBanner=%s', + async (licenseBanner, expected) => { + using setLicenseBanner = spyOn(wasm, 'setLicenseBanner').mockReturnValue( + undefined, + ) + await DevupUI({ licenseBanner }).setup(createSetupContext()) + expect(setLicenseBanner).toHaveBeenCalledWith(expected) + }, + ) + describe('deterministic file numbering', () => { it('sets the prefix every time, even without one', async () => { setPrefixSpy.mockClear() diff --git a/packages/rsbuild-plugin/src/plugin.ts b/packages/rsbuild-plugin/src/plugin.ts index 3ee51ae9a..7f18b19b7 100644 --- a/packages/rsbuild-plugin/src/plugin.ts +++ b/packages/rsbuild-plugin/src/plugin.ts @@ -36,7 +36,7 @@ const PLUGIN_NAME = 'devup-ui-rsbuild-plugin' export interface DevupUIRsbuildPluginOptions extends Pick< DevupUIBasePluginOptions, - 'engine' + 'engine' | 'licenseBanner' > { package: string cssDir: string @@ -139,6 +139,7 @@ export const DevupUI = ({ debug = false, singleCss = false, prefix, + licenseBanner = true, shorthands, engine, atomHoist = 2, @@ -165,6 +166,7 @@ export const DevupUI = ({ api.onCloseBuild?.(endBuild) compiler.setDebug(debug) compiler.setPrefix(prefix ?? null) + compiler.setLicenseBanner(licenseBanner) if (!existsSync(distDir)) await mkdir(distDir, { recursive: true }) await writeFile(join(distDir, '.gitignore'), '*', 'utf-8') diff --git a/packages/vite-plugin/README.md b/packages/vite-plugin/README.md index 61bf1278b..c7ad9a550 100644 --- a/packages/vite-plugin/README.md +++ b/packages/vite-plugin/README.md @@ -195,6 +195,17 @@ engine selection. Configuration, reservation, transforms and delayed callbacks use the same selected compiler. Neither engine supports concurrent independent builds in one process; Vite environments within a build share its compiler state. +## License banner + +Every emitted stylesheet starts with a +`/*! devup-ui v… | Apache License 2.0 | https://devup-ui.com */` comment, which +minifiers keep. It is on by default; `licenseBanner: false` drops it from every +stylesheet. A stylesheet without any rule is emitted empty, banner included. + +```ts +DevupUI({ licenseBanner: false }) +``` + ## Custom Shorthands Custom shorthands are build-plugin options, not theme tokens. Every target diff --git a/packages/vite-plugin/src/__tests__/plugin.test.ts b/packages/vite-plugin/src/__tests__/plugin.test.ts index a19dee99f..4dc84fa29 100644 --- a/packages/vite-plugin/src/__tests__/plugin.test.ts +++ b/packages/vite-plugin/src/__tests__/plugin.test.ts @@ -2290,6 +2290,21 @@ export const a =
` await plugin.configResolved() expect(setPrefixSpy).toHaveBeenCalledWith('my-prefix') }) + + it.each([ + [undefined, true], + [true, true], + [false, false], + ] as const)( + 'sets the license banner from licenseBanner=%s', + async (licenseBanner, expected) => { + using setLicenseBanner = spyOn(wasm, 'setLicenseBanner').mockReturnValue( + undefined, + ) + await createPlugin({ licenseBanner }).configResolved() + expect(setLicenseBanner).toHaveBeenCalledWith(expected) + }, + ) }) describe('module resolver', () => { diff --git a/packages/vite-plugin/src/plugin.ts b/packages/vite-plugin/src/plugin.ts index 1bf6d5eae..578ad1337 100644 --- a/packages/vite-plugin/src/plugin.ts +++ b/packages/vite-plugin/src/plugin.ts @@ -260,7 +260,7 @@ function createCssChunkBuildOptions( export interface DevupUIPluginOptions extends Pick< DevupUIBasePluginOptions, - 'engine' + 'engine' | 'licenseBanner' > { package: string cssDir: string @@ -357,6 +357,7 @@ export function DevupUI({ include = [], singleCss = false, prefix, + licenseBanner = true, shorthands, engine, atomHoist = 2, @@ -403,6 +404,7 @@ export function DevupUI({ compiler.registerShorthands(normalizedShorthands) compiler.setDebug(debug) compiler.setPrefix(prefix ?? null) + compiler.setLicenseBanner(licenseBanner) } if (ownsEngine) configureEngine() const importAliases = mergeImportAliases( diff --git a/packages/webpack-plugin/README.md b/packages/webpack-plugin/README.md index 74927fa6e..d0b8f5b7d 100644 --- a/packages/webpack-plugin/README.md +++ b/packages/webpack-plugin/README.md @@ -200,6 +200,17 @@ Selection applies to the plugin, source loader, CSS loader and delayed build callbacks as one unit. Native state, like WASM state, does not support concurrent independent builds in the same process. +## License banner + +Every emitted stylesheet starts with a +`/*! devup-ui v… | Apache License 2.0 | https://devup-ui.com */` comment, which +minifiers keep. It is on by default; `licenseBanner: false` drops it from every +stylesheet. A stylesheet without any rule is emitted empty, banner included. + +```ts +new DevupUIWebpackPlugin({ licenseBanner: false }) +``` + ## Custom Shorthands ```ts diff --git a/packages/webpack-plugin/src/__tests__/plugin.test.ts b/packages/webpack-plugin/src/__tests__/plugin.test.ts index 7091ee2ff..8db10965c 100644 --- a/packages/webpack-plugin/src/__tests__/plugin.test.ts +++ b/packages/webpack-plugin/src/__tests__/plugin.test.ts @@ -438,6 +438,7 @@ describe('devupUIWebpackPlugin', () => { debug: false, singleCss: false, engine: 'native', + licenseBanner: true, atomHoist: 2, }) }, @@ -518,6 +519,7 @@ describe('devupUIWebpackPlugin', () => { ).toEqual({ ...options, engine: 'wasm', + licenseBanner: true, atomHoist: 2, }) }) @@ -953,6 +955,24 @@ describe('devupUIWebpackPlugin', () => { expect(setPrefixSpy).toHaveBeenCalledWith('my-prefix') }) + it.each([ + [undefined, true], + [true, true], + [false, false], + ] as const)( + 'sets the license banner from licenseBanner=%s', + (licenseBanner, expected) => { + using setLicenseBanner = spyOn(wasm, 'setLicenseBanner').mockReturnValue( + undefined, + ) + existsSyncSpy.mockReturnValue(false) + new DevupUIWebpackPlugin({ engine: 'wasm', licenseBanner }).apply( + asCompiler(createCompiler()), + ) + expect(setLicenseBanner).toHaveBeenCalledWith(expected) + }, + ) + describe('collapse + atomHoist pre-pass', () => { let buildCanonicalMapSpy: ReturnType let computeFileReachSpy: ReturnType diff --git a/packages/webpack-plugin/src/plugin.ts b/packages/webpack-plugin/src/plugin.ts index 361085e25..22804ebfd 100644 --- a/packages/webpack-plugin/src/plugin.ts +++ b/packages/webpack-plugin/src/plugin.ts @@ -40,7 +40,7 @@ import { reconcileWatchCss } from './watch-css' export interface DevupUIWebpackPluginOptions extends Pick< DevupUIBasePluginOptions, - 'engine' + 'engine' | 'licenseBanner' > { package: string cssDir: string @@ -94,6 +94,7 @@ export class DevupUIWebpackPlugin { singleCss = false, engine = 'native', prefix, + licenseBanner = true, shorthands, atomHoist = 2, productionPrewarmFiles, @@ -118,6 +119,7 @@ export class DevupUIWebpackPlugin { singleCss, engine, prefix, + licenseBanner, shorthands, atomHoist, productionPrewarmFiles: @@ -284,6 +286,7 @@ export class DevupUIWebpackPlugin { private initialize(compiler: Compiler) { this.compiler.setDebug(this.options.debug) this.compiler.setPrefix(this.options.prefix ?? null) + this.compiler.setLicenseBanner(this.options.licenseBanner !== false) this.compiler.registerShorthands(this.normalizedShorthands) const existsDevup = existsSync(this.options.devupFile) // read devup.json From 6cc59a07ba68d596353a827be6df8b9bfdb629a0 Mon Sep 17 00:00:00 2001 From: owjs3901 Date: Tue, 17 Nov 2026 15:55:54 +0900 Subject: [PATCH 2/3] test(binding): count the two licenseBanner exports in the native consumer setLicenseBanner and isLicenseBanner bring the native package to 32 exported functions; the consumer e2e still expected 30. Co-Authored-By: Claude Opus 5.5 --- e2e/binding/package/consumer.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/binding/package/consumer.mjs b/e2e/binding/package/consumer.mjs index 3940b9cca..1de06ad40 100644 --- a/e2e/binding/package/consumer.mjs +++ b/e2e/binding/package/consumer.mjs @@ -136,7 +136,7 @@ export async function consume(options) { ] .map((match) => match[1]) .sort() - assert.equal(names.length, 30) + assert.equal(names.length, 32) for (const manager of ['npm', 'bun']) { for (const omit of [false, true]) { const startRequest = server.requests.length From 38c7fae01aa580647eb5f8b8713830cae42e5e91 Mon Sep 17 00:00:00 2001 From: owjs3901 Date: Tue, 17 Nov 2026 17:03:07 +0900 Subject: [PATCH 3/3] test(binding): keep the license banner per session and reach it in the WASM ABI gate The banner flag is part of CssState since the merge with main, so each engine session keeps its own. A session test now turns it off in session 0, checks that another session starts with it on and emits the banner, that session 0 keeps its own setting when it is live again, and that turning it off in the other session stays there. The WASM ABI gate (#952) failed with "setLicenseBanner: never called": the boundary corpus now calls it with the boolean ABI values next to setDebug, and the reset scenario dirties it before both resets. Co-Authored-By: Claude Opus 5.5 --- e2e/binding/corpus/boundary.mjs | 3 +++ e2e/binding/corpus/state.mjs | 1 + libs/binding/src/session/tests.rs | 29 +++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/e2e/binding/corpus/boundary.mjs b/e2e/binding/corpus/boundary.mjs index c7dd0a5a6..c781819e7 100644 --- a/e2e/binding/corpus/boundary.mjs +++ b/e2e/binding/corpus/boundary.mjs @@ -24,11 +24,14 @@ add('numeric-wrapper-and-boolean-abi', (h) => { h.call('setAtomHoist', value) h.call('getCss', value, false) h.call('setDebug', value) + h.call('setLicenseBanner', value) h.extract(source, { flags: [value, value, value] }) } h.call('setAtomHoist') h.call('getCss') h.call('setDebug') + h.call('setLicenseBanner') + h.call('setLicenseBanner', true) }) add('decoder-width-overflow-and-enums', (h) => { for (const value of [ diff --git a/e2e/binding/corpus/state.mjs b/e2e/binding/corpus/state.mjs index 85f5e8b64..a9db54b3e 100644 --- a/e2e/binding/corpus/state.mjs +++ b/e2e/binding/corpus/state.mjs @@ -68,6 +68,7 @@ add('distinct-resets-and-resolver-teardown', (h) => { h.call('registerTheme', theme) h.call('registerShorthands', { insetX: ['left', 'right'] }) h.call('setDebug', true) + h.call('setLicenseBanner', false) h.call('setPrefix', 'dirty-') h.call('setAtomHoist', 2) h.call('setModuleResolver', (...args) => { diff --git a/libs/binding/src/session/tests.rs b/libs/binding/src/session/tests.rs index 173d20e88..698522062 100644 --- a/libs/binding/src/session/tests.rs +++ b/libs/binding/src/session/tests.rs @@ -99,6 +99,35 @@ fn sessions_keep_their_own_numbering_settings_and_sheet() { assert!(css.is_ok_and(|css| css.contains("color:blue") && css.contains("--brand"))); } +#[test] +#[serial] +fn the_license_banner_setting_belongs_to_one_session() { + let _clean = clean(); + // Given: session 0 turned the banner off and both sessions hold styles + crate::set_license_banner(false); + extract("zero.tsx", "red"); + let session = create_session(); + // When: the other session runs + let css = with_session(session, || { + // Then: it starts with the banner on and emits it + assert!(crate::is_license_banner()); + extract("other.tsx", "blue"); + get_css(None, false) + }); + assert!(css.is_ok_and(|css| css.starts_with("/*! devup-ui v"))); + // And: session 0 keeps its own setting once it is live again + assert!(!crate::is_license_banner()); + assert!(get_css(None, false).starts_with(".a{color:red}")); + // And: turning it off in the other session stays there + assert_eq!( + with_session(session, || crate::set_license_banner(false)), + Ok(()) + ); + crate::set_license_banner(true); + assert_eq!(with_session(session, crate::is_license_banner), Ok(false)); + assert!(crate::is_license_banner()); +} + #[test] #[serial] fn removing_a_file_forgets_it_only_in_the_live_session() {