@fastkit/plugboy-vanilla-extract-plugin 4.0.0 → 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -23,7 +23,7 @@ pnpm add -D @fastkit/plugboy-vanilla-extract-plugin
23
23
  ```
24
24
 
25
25
  > [!NOTE]
26
- > Requires `@fastkit/plugboy` (and `vite`, when using the Vite integration) as peer dependencies.
26
+ > Requires `@fastkit/plugboy` as a peer dependency. When using the Vite integration (`@fastkit/plugboy-vanilla-extract-plugin/vite`), `vite` and `@vanilla-extract/vite-plugin` are also required as peer dependencies — install them yourself. The main entry never loads them, so build-only usage needs neither.
27
27
 
28
28
  ## Usage
29
29
 
@@ -53,7 +53,7 @@ For environments that resolve Vanilla Extract without a Plugboy build (Vite dev
53
53
 
54
54
  ```typescript
55
55
  import { defineConfig } from 'vite';
56
- import { ViteVanillaExtractPlugin } from '@fastkit/plugboy-vanilla-extract-plugin';
56
+ import { ViteVanillaExtractPlugin } from '@fastkit/plugboy-vanilla-extract-plugin/vite';
57
57
 
58
58
  export default defineConfig({
59
59
  plugins: [
@@ -1,7 +1,5 @@
1
1
  import { Plugin } from "@fastkit/plugboy";
2
2
  import { vanillaExtractPlugin } from "@vanilla-extract/rollup-plugin";
3
- import { vanillaExtractPlugin as vanillaExtractPlugin$1 } from "@vanilla-extract/vite-plugin";
4
- import { Plugin as Plugin$1 } from "vite";
5
3
 
6
4
  //#region src/types.d.ts
7
5
  type VanillaExtractPluginOptions = Omit<NonNullable<Parameters<typeof vanillaExtractPlugin>[0]>, 'extract'>;
@@ -20,10 +18,4 @@ declare module '@fastkit/plugboy' {
20
18
  }
21
19
  declare function createVanillaExtractPlugin(options?: PluginOptions): Promise<VanillaExtractPlugin>;
22
20
  //#endregion
23
- //#region src/vite.d.ts
24
- type VanillaExtractVitePluginOptions = NonNullable<Parameters<typeof vanillaExtractPlugin$1>[0]>;
25
- interface ViteVanillaExtractPluginOptions extends VanillaExtractVitePluginOptions {}
26
- declare function ViteVanillaExtractPlugin(options?: ViteVanillaExtractPluginOptions): Promise<Plugin$1[]>;
27
- //#endregion
28
- export { PLUGIN_NAME, PluginOptions, VanillaExtractPlugin, ViteVanillaExtractPlugin, ViteVanillaExtractPluginOptions, createVanillaExtractPlugin };
29
- //# sourceMappingURL=plugboy-vanilla-extract-plugin.d.mts.map
21
+ export { PLUGIN_NAME, PluginOptions, VanillaExtractPlugin, createVanillaExtractPlugin };
@@ -1,11 +1,8 @@
1
+ import { t as PLUGIN_NAME } from "./types-Djg9yxv0.mjs";
1
2
  import fs from "node:fs/promises";
2
3
  import path from "node:path";
3
- import { definePlugin, findFile, findProjectPlugin } from "@fastkit/plugboy";
4
+ import { definePlugin, findFile } from "@fastkit/plugboy";
4
5
  import { vanillaExtractPlugin } from "@vanilla-extract/rollup-plugin";
5
- import { vanillaExtractPlugin as vanillaExtractPlugin$1 } from "@vanilla-extract/vite-plugin";
6
- //#region src/types.ts
7
- const PLUGIN_NAME = "plugboy-vanilla-extract";
8
- //#endregion
9
6
  //#region src/plugin.ts
10
7
  /**
11
8
  * Temporary file name for the CSS that tsdown's own CSS pipeline emits.
@@ -140,22 +137,6 @@ async function createVanillaExtractPlugin(options = {}) {
140
137
  });
141
138
  }
142
139
  //#endregion
143
- //#region src/vite.ts
144
- async function ViteVanillaExtractPlugin(options = {}) {
145
- const { identifiers: baseIdentifiers } = (await findProjectPlugin("plugboy-vanilla-extract"))?._options || {};
146
- return [...vanillaExtractPlugin$1({
147
- identifiers: baseIdentifiers,
148
- ...options
149
- }), {
150
- name: "vanilla-extract-fix-file-scope",
151
- config(viteConfig) {
152
- viteConfig.resolve ??= {};
153
- viteConfig.resolve.dedupe ??= [];
154
- viteConfig.resolve.dedupe.push("@vanilla-extract/css", "@vanilla-extract/css/fileScope");
155
- }
156
- }];
157
- }
158
- //#endregion
159
- export { PLUGIN_NAME, ViteVanillaExtractPlugin, createVanillaExtractPlugin };
140
+ export { PLUGIN_NAME, createVanillaExtractPlugin };
160
141
 
161
142
  //# sourceMappingURL=plugboy-vanilla-extract-plugin.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"plugboy-vanilla-extract-plugin.mjs","names":["vanillaExtractPlugin"],"sources":["../src/types.ts","../src/plugin.ts","../src/vite.ts"],"sourcesContent":["import { Plugin } from '@fastkit/plugboy';\nimport type { vanillaExtractPlugin as rollupPlugin } from '@vanilla-extract/rollup-plugin';\n\ntype VanillaExtractPluginOptions = Omit<\n NonNullable<Parameters<typeof rollupPlugin>[0]>,\n 'extract'\n>;\n\nexport type PluginOptions = Pick<\n VanillaExtractPluginOptions,\n 'identifiers' | 'esbuildOptions'\n>;\n\nexport const PLUGIN_NAME = 'plugboy-vanilla-extract';\n\nexport interface VanillaExtractPlugin extends Plugin {\n name: typeof PLUGIN_NAME;\n _options: PluginOptions;\n}\n","import fs from 'node:fs/promises';\nimport path from 'node:path';\nimport { definePlugin, findFile, type Plugin } from '@fastkit/plugboy';\nimport { vanillaExtractPlugin } from '@vanilla-extract/rollup-plugin';\nimport { VanillaExtractPlugin, PluginOptions, PLUGIN_NAME } from './types';\n\ndeclare module '@fastkit/plugboy' {\n export interface WorkspaceMeta {\n hasVanillaExtract: boolean;\n }\n}\n\n/**\n * Temporary file name for the CSS that tsdown's own CSS pipeline emits.\n *\n * A package can have two independent sources of CSS:\n * - tsdown's built-in CSS handling, for plain `.css` / `.scss` imports.\n * - `@vanilla-extract/rollup-plugin`, for `.css.ts` files (extracted into a\n * single bundle named after the package).\n *\n * If both are pointed at the same final file name they collide\n * (`FILE_NAME_CONFLICT` — one silently overwrites the other, dropping all of\n * the vanilla-extract component CSS). To avoid that we route tsdown's CSS to\n * this temporary name and merge it into the vanilla-extract bundle in\n * `writeBundle`.\n */\nconst TSDOWN_CSS_FILE_NAME = '__ve-tsdown__.css';\n\nexport async function createVanillaExtractPlugin(options: PluginOptions = {}) {\n return definePlugin<VanillaExtractPlugin>({\n name: PLUGIN_NAME,\n _options: options,\n hooks: {\n async setupWorkspace(ctx, getWorkspace) {\n // Derive the final CSS file name from the workspace entry, mirroring the\n // way plugboy names the JS output: the main entry (`.`) maps to the\n // package directory name (e.g. `vue-app-layout`), other entries keep\n // their id. Since `splitting: false` produces a single combined CSS for\n // the package, we base it on the main entry (falling back to the first).\n // Result: `dist/vue-app-layout.css` instead of `dist/__ve-tmp__.css`.\n const entryIds = Object.keys(ctx.config.entries);\n const cssBaseName = entryIds.includes('.')\n ? ctx.dir.basename\n : (entryIds[0] ?? ctx.dir.basename);\n const cssFileName = `${cssBaseName}.css`;\n\n // Routing for tsdown's plain-CSS blob (see `writeBundle`). plugboy's CSS\n // pipeline emits ALL plain (non-`.css.ts`) CSS — e.g. an `@font-face`\n // sheet `import`ed by an entry — into a single combined file\n // (`TSDOWN_CSS_FILE_NAME`); it cannot be split per entry (tsdown's own CSS\n // `splitting` drops the styles entirely when vanilla-extract is present).\n // The per-entry split in `generateBundle` fills these so the blob is\n // merged into the right entry CSS files instead of an orphan\n // `cssFileName`. Defaults (no split) keep the original single-file\n // behavior. `plainCssTargets`: entry CSS files (`a.css`) that import plain\n // CSS. `plainCssFallback`: where the blob goes when the split fired but no\n // entry with a CSS file owns the plain CSS (avoids re-creating an orphan).\n const plainCssTargets = new Set<string>();\n let plainCssFallback = cssFileName;\n\n ctx.mergeExternals(/@vanilla-extract/);\n\n ctx.meta.hasVanillaExtract = !!(await findFile(\n ctx.dirs.src.value,\n /\\.css\\.ts$/,\n ));\n\n // When vanilla-extract is in play, route tsdown's own CSS to a temporary\n // name so it doesn't collide with the vanilla-extract bundle that also\n // targets `cssFileName`; the two are merged into a single `cssFileName`\n // by the `writeBundle` hook below. Without vanilla-extract there is no\n // second producer, so tsdown emits `cssFileName` directly.\n ctx.css = {\n splitting: false,\n fileName: ctx.meta.hasVanillaExtract\n ? TSDOWN_CSS_FILE_NAME\n : cssFileName,\n };\n\n if (ctx.meta.hasVanillaExtract) {\n const originalPlugin = vanillaExtractPlugin({\n ...options,\n extract: {\n name: cssFileName,\n sourcemap: false,\n },\n });\n\n // `@vanilla-extract/rollup-plugin` returns a rollup `Plugin`, but\n // plugboy's `ctx.plugins` expects a tsdown (rolldown) `Plugin`. The two\n // are structurally almost identical, but hooks like `outputOptions`\n // type `this` as rollup's `PluginContext` vs rolldown's\n // `MinimalPluginContext`, which makes them unassignable (the `this`\n // type is contravariant). rolldown accepts rollup plugins at runtime,\n // so this is harmless — cast to work around the type mismatch.\n ctx.plugins.push(originalPlugin as unknown as Plugin);\n\n // `@vanilla-extract/rollup-plugin` emits the extracted CSS via\n // `emitFile({ type: 'asset', name: cssFileName })`. Because it uses\n // `name` (a hint) rather than `fileName`, rolldown runs it through the\n // default `assetFileNames` pattern (`assets/[name]-[hash][extname]`),\n // producing e.g. `dist/assets/vue-app-layout-dry0z-1l.css`.\n //\n // We can't *rename* an asset in `generateBundle` because rolldown\n // ignores mutations to a bundle entry's `fileName`. Instead, override\n // `assetFileNames` via the `outputOptions` hook so this single CSS\n // asset keeps its derived name verbatim (no hash, no `assets/` dir)\n // while every other asset keeps its original naming.\n ctx.plugins.push({\n name: `${PLUGIN_NAME}:rename-css`,\n outputOptions(opts) {\n const original = opts.assetFileNames;\n opts.assetFileNames = (assetInfo) => {\n if (assetInfo.names.includes(cssFileName)) {\n return cssFileName;\n }\n if (typeof original === 'function') return original(assetInfo);\n return original ?? 'assets/[name]-[hash][extname]';\n };\n return opts;\n },\n // Split vanilla-extract's single bundle into one CSS file per entry.\n //\n // `extract: { name }` mode collects the CSS of EVERY `.css.ts` in the\n // graph into one asset (`cssFileName`), which loses plugboy's per-entry\n // CSS contract: every entry with `css: true` declares a `./<entry>.css`\n // export, but only `cssFileName` is ever produced. We rebuild the\n // per-entry files from data vanilla-extract already exposes:\n // `moduleInfo.meta.css` (its public hand-off for extracted CSS, the\n // same field its own bundler reads).\n //\n // CSS is attributed to an entry by walking the INPUT module graph from\n // that entry's `facadeModuleId` via `getModuleInfo().importedIds`, NOT\n // by reading the output chunk's `imports`. `chunk.imports` lists output\n // chunk file names plus external ids, and whether vanilla-extract's\n // external virtual CSS ids appear there is rolldown-version-dependent\n // (some versions only list real output chunks, so the lookup finds\n // nothing and the split silently no-ops). The input graph is stable: it\n // always yields the `.css.ts` modules an entry reaches, regardless of\n // how rolldown chunks the output. A `.css.ts` shared by several entries\n // is included in each entry's file (self-contained per-entry CSS).\n //\n // We never parse vanilla-extract's asset names or re-add the import\n // statements it strips, so the only coupling is `meta.css`.\n //\n // Runs before `plugboy-optimize-css` (appended later in\n // `workspace.plugins`), so each emitted per-entry file still goes\n // through the postcss optimizations.\n //\n // Only splits when more than one entry actually has CSS. With a single\n // CSS entry (the common case) vanilla-extract's bundle is already the\n // correct, fully-ordered output, so it is left untouched and existing\n // single-entry packages are byte-for-byte unaffected.\n generateBundle(_options, bundle) {\n // Walk the input module graph from `root`, collecting (deduped, in\n // import order) the CSS of every `.css.ts` reached (`meta.css`), and\n // flagging whether any plain (non-`.css.ts`) CSS file is imported.\n const collectEntryCss = (\n root: string,\n ): { css: string[]; hasPlain: boolean } => {\n const visited = new Set<string>();\n const seenCss = new Set<string>();\n const out: string[] = [];\n let hasPlain = false;\n const walk = (id: string) => {\n if (visited.has(id)) return;\n visited.add(id);\n const info = this.getModuleInfo(id);\n if (!info) return;\n for (const dep of info.importedIds ?? []) {\n const css = this.getModuleInfo(dep)?.meta?.css;\n if (typeof css === 'string') {\n // vanilla-extract virtual CSS (`*.vanilla.css`).\n if (!seenCss.has(dep)) {\n seenCss.add(dep);\n out.push(css);\n }\n } else if (/\\.css(\\?|$)/i.test(dep)) {\n // Plain CSS import (no `meta.css`) — its content lives in\n // tsdown's combined blob, merged per entry in `writeBundle`.\n hasPlain = true;\n }\n walk(dep);\n }\n };\n walk(root);\n return { css: out, hasPlain };\n };\n\n const entryCss: {\n name: string;\n source: string;\n hasPlain: boolean;\n }[] = [];\n\n for (const chunk of Object.values(bundle)) {\n if (\n chunk.type !== 'chunk' ||\n !chunk.isEntry ||\n !chunk.fileName.endsWith('.mjs') ||\n !chunk.facadeModuleId\n ) {\n continue;\n }\n const { css, hasPlain } = collectEntryCss(chunk.facadeModuleId);\n if (css.length) {\n entryCss.push({\n name: chunk.name,\n source: css.join('\\n'),\n hasPlain,\n });\n }\n }\n\n // 0 or 1 CSS entry → vanilla-extract's bundle is already correct,\n // and the single-file `writeBundle` fallback applies unchanged.\n if (entryCss.length <= 1) return;\n\n // Replace vanilla-extract's combined bundle with per-entry files.\n // The entry whose file name matches `cssFileName` overwrites the\n // existing asset in place — re-`emitFile`ing the same name would\n // trip rolldown's FILE_NAME_CONFLICT, since deleting the bundle\n // entry does not release the reserved file name. Other entries are\n // emitted as new assets.\n const reused = new Set<string>();\n for (const { name, source } of entryCss) {\n const fileName = `${name}.css`;\n const existing = bundle[fileName];\n if (existing && existing.type === 'asset') {\n existing.source = source;\n reused.add(fileName);\n } else {\n this.emitFile({ type: 'asset', fileName, source });\n }\n }\n\n // Drop vanilla-extract's combined bundle if no entry reused it.\n const combined = bundle[cssFileName];\n if (\n combined &&\n combined.type === 'asset' &&\n !reused.has(cssFileName)\n ) {\n delete bundle[cssFileName];\n }\n\n // Tell `writeBundle` where to merge tsdown's plain-CSS blob: into\n // each entry CSS file whose entry imports plain CSS. Falling back to\n // the first entry's file keeps the blob attached to a real, exported\n // CSS file instead of resurrecting the now-deleted `cssFileName`.\n plainCssTargets.clear();\n plainCssFallback = `${entryCss[0].name}.css`;\n for (const { name, hasPlain } of entryCss) {\n if (hasPlain) plainCssTargets.add(`${name}.css`);\n }\n },\n // Merge tsdown's own plain-CSS blob (emitted to\n // `TSDOWN_CSS_FILE_NAME`) into the vanilla-extract CSS file(s).\n //\n // This has to happen in `writeBundle`, not `generateBundle`: tsdown\n // emits its CSS in a separate output pass, so `TSDOWN_CSS_FILE_NAME`\n // is absent from the bundle our `generateBundle` sees but present by\n // `writeBundle`. By then the vanilla-extract files are already on disk,\n // so we merge on disk rather than mutating bundle sources. tsdown's\n // CSS goes first so its `@layer` declarations / resets / `@font-face`\n // are established before the extracted component styles.\n //\n // Targets:\n // - Per-entry split fired → the entry CSS files whose entries import\n // plain CSS (`plainCssTargets`), falling back to the first entry's\n // file. Never `cssFileName`, which the split deleted (no orphan).\n // - No split (single CSS entry) → `cssFileName`, the one combined file.\n // The combined blob cannot be partitioned per entry, so when several\n // entries import distinct plain CSS each target receives the whole\n // blob; in practice plain CSS (fonts/resets) is imported by one entry.\n async writeBundle(outputOptions, bundle) {\n // Only the output pass that emitted tsdown's CSS performs the merge\n // (it is the one whose `bundle` contains `TSDOWN_CSS_FILE_NAME`).\n // This also prevents a second output from re-injecting the imports.\n const tmp = bundle[TSDOWN_CSS_FILE_NAME];\n if (!tmp) return;\n\n const tmpCss = tmp.type === 'asset' ? tmp.source.toString() : '';\n const dir = outputOptions.dir ?? '.';\n const tmpPath = path.join(dir, TSDOWN_CSS_FILE_NAME);\n\n if (tmpCss) {\n const targets = plainCssTargets.size\n ? [...plainCssTargets]\n : [plainCssFallback];\n\n await Promise.all(\n targets.map(async (target) => {\n const targetPath = path.join(dir, target);\n let targetCss = '';\n try {\n targetCss = await fs.readFile(targetPath, 'utf8');\n } catch {\n // No vanilla-extract file for this target (e.g. `.css.ts`\n // produced no rules) — tsdown's CSS becomes the whole file.\n }\n await fs.writeFile(\n targetPath,\n targetCss ? `${tmpCss}\\n${targetCss}` : tmpCss,\n );\n }),\n );\n }\n\n await fs.rm(tmpPath, { force: true });\n },\n });\n }\n },\n },\n });\n}\n","import { findProjectPlugin } from '@fastkit/plugboy';\nimport { Plugin as VitePlugin } from 'vite';\nimport { vanillaExtractPlugin } from '@vanilla-extract/vite-plugin';\nimport { PLUGIN_NAME, VanillaExtractPlugin } from './types';\n\ntype VanillaExtractVitePluginOptions = NonNullable<\n Parameters<typeof vanillaExtractPlugin>[0]\n>;\n\nexport interface ViteVanillaExtractPluginOptions extends VanillaExtractVitePluginOptions {}\n\nexport async function ViteVanillaExtractPlugin(\n options: ViteVanillaExtractPluginOptions = {},\n): Promise<VitePlugin[]> {\n const plugin = await findProjectPlugin<VanillaExtractPlugin>(PLUGIN_NAME);\n const { identifiers: baseIdentifiers } = plugin?._options || {};\n\n return [\n ...vanillaExtractPlugin({\n identifiers: baseIdentifiers,\n ...options,\n }),\n // @MEMO\n // Plugin to prevent file scope mismatches when utilities using vanilla-extract\n // functions are placed in external files\n {\n name: 'vanilla-extract-fix-file-scope',\n config(viteConfig) {\n viteConfig.resolve ??= {};\n viteConfig.resolve.dedupe ??= [];\n viteConfig.resolve.dedupe.push(\n '@vanilla-extract/css',\n '@vanilla-extract/css/fileScope',\n );\n },\n },\n ];\n}\n"],"mappings":";;;;;;AAaA,MAAa,cAAc;;;;;;;;;;;;;;;;;ACa3B,MAAM,uBAAuB;AAE7B,eAAsB,2BAA2B,UAAyB,CAAC,GAAG;CAC5E,OAAO,aAAmC;EACxC,MAAM;EACN,UAAU;EACV,OAAO,EACL,MAAM,eAAe,KAAK,cAAc;GAOtC,MAAM,WAAW,OAAO,KAAK,IAAI,OAAO,OAAO;GAI/C,MAAM,cAAc,GAHA,SAAS,SAAS,GAAG,IACrC,IAAI,IAAI,WACP,SAAS,MAAM,IAAI,IAAI,SACO;GAanC,MAAM,kCAAkB,IAAI,IAAY;GACxC,IAAI,mBAAmB;GAEvB,IAAI,eAAe,kBAAkB;GAErC,IAAI,KAAK,oBAAoB,CAAC,CAAE,MAAM,SACpC,IAAI,KAAK,IAAI,OACb,YACF;GAOA,IAAI,MAAM;IACR,WAAW;IACX,UAAU,IAAI,KAAK,oBACf,uBACA;GACN;GAEA,IAAI,IAAI,KAAK,mBAAmB;IAC9B,MAAM,iBAAiB,qBAAqB;KAC1C,GAAG;KACH,SAAS;MACP,MAAM;MACN,WAAW;KACb;IACF,CAAC;IASD,IAAI,QAAQ,KAAK,cAAmC;IAapD,IAAI,QAAQ,KAAK;KACf,MAAM,GAAG,YAAY;KACrB,cAAc,MAAM;MAClB,MAAM,WAAW,KAAK;MACtB,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,MADpB,kBAAA,yBAAmD,EAAA,EACvB,YAAY,CAAC;CAE9D,OAAO,CACL,GAAGA,uBAAqB;EACtB,aAAa;EACb,GAAG;CACL,CAAC,GAID;EACE,MAAM;EACN,OAAO,YAAY;GACjB,WAAW,YAAY,CAAC;GACxB,WAAW,QAAQ,WAAW,CAAC;GAC/B,WAAW,QAAQ,OAAO,KACxB,wBACA,gCACF;EACF;CACF,CACF;AACF"}
1
+ {"version":3,"file":"plugboy-vanilla-extract-plugin.mjs","names":[],"sources":["../src/plugin.ts"],"sourcesContent":["import fs from 'node:fs/promises';\nimport path from 'node:path';\nimport { definePlugin, findFile, type Plugin } from '@fastkit/plugboy';\nimport { vanillaExtractPlugin } from '@vanilla-extract/rollup-plugin';\nimport { VanillaExtractPlugin, PluginOptions, PLUGIN_NAME } from './types';\n\ndeclare module '@fastkit/plugboy' {\n export interface WorkspaceMeta {\n hasVanillaExtract: boolean;\n }\n}\n\n/**\n * Temporary file name for the CSS that tsdown's own CSS pipeline emits.\n *\n * A package can have two independent sources of CSS:\n * - tsdown's built-in CSS handling, for plain `.css` / `.scss` imports.\n * - `@vanilla-extract/rollup-plugin`, for `.css.ts` files (extracted into a\n * single bundle named after the package).\n *\n * If both are pointed at the same final file name they collide\n * (`FILE_NAME_CONFLICT` — one silently overwrites the other, dropping all of\n * the vanilla-extract component CSS). To avoid that we route tsdown's CSS to\n * this temporary name and merge it into the vanilla-extract bundle in\n * `writeBundle`.\n */\nconst TSDOWN_CSS_FILE_NAME = '__ve-tsdown__.css';\n\nexport async function createVanillaExtractPlugin(options: PluginOptions = {}) {\n return definePlugin<VanillaExtractPlugin>({\n name: PLUGIN_NAME,\n _options: options,\n hooks: {\n async setupWorkspace(ctx, getWorkspace) {\n // Derive the final CSS file name from the workspace entry, mirroring the\n // way plugboy names the JS output: the main entry (`.`) maps to the\n // package directory name (e.g. `vue-app-layout`), other entries keep\n // their id. Since `splitting: false` produces a single combined CSS for\n // the package, we base it on the main entry (falling back to the first).\n // Result: `dist/vue-app-layout.css` instead of `dist/__ve-tmp__.css`.\n const entryIds = Object.keys(ctx.config.entries);\n const cssBaseName = entryIds.includes('.')\n ? ctx.dir.basename\n : (entryIds[0] ?? ctx.dir.basename);\n const cssFileName = `${cssBaseName}.css`;\n\n // Routing for tsdown's plain-CSS blob (see `writeBundle`). plugboy's CSS\n // pipeline emits ALL plain (non-`.css.ts`) CSS — e.g. an `@font-face`\n // sheet `import`ed by an entry — into a single combined file\n // (`TSDOWN_CSS_FILE_NAME`); it cannot be split per entry (tsdown's own CSS\n // `splitting` drops the styles entirely when vanilla-extract is present).\n // The per-entry split in `generateBundle` fills these so the blob is\n // merged into the right entry CSS files instead of an orphan\n // `cssFileName`. Defaults (no split) keep the original single-file\n // behavior. `plainCssTargets`: entry CSS files (`a.css`) that import plain\n // CSS. `plainCssFallback`: where the blob goes when the split fired but no\n // entry with a CSS file owns the plain CSS (avoids re-creating an orphan).\n const plainCssTargets = new Set<string>();\n let plainCssFallback = cssFileName;\n\n ctx.mergeExternals(/@vanilla-extract/);\n\n ctx.meta.hasVanillaExtract = !!(await findFile(\n ctx.dirs.src.value,\n /\\.css\\.ts$/,\n ));\n\n // When vanilla-extract is in play, route tsdown's own CSS to a temporary\n // name so it doesn't collide with the vanilla-extract bundle that also\n // targets `cssFileName`; the two are merged into a single `cssFileName`\n // by the `writeBundle` hook below. Without vanilla-extract there is no\n // second producer, so tsdown emits `cssFileName` directly.\n ctx.css = {\n splitting: false,\n fileName: ctx.meta.hasVanillaExtract\n ? TSDOWN_CSS_FILE_NAME\n : cssFileName,\n };\n\n if (ctx.meta.hasVanillaExtract) {\n const originalPlugin = vanillaExtractPlugin({\n ...options,\n extract: {\n name: cssFileName,\n sourcemap: false,\n },\n });\n\n // `@vanilla-extract/rollup-plugin` returns a rollup `Plugin`, but\n // plugboy's `ctx.plugins` expects a tsdown (rolldown) `Plugin`. The two\n // are structurally almost identical, but hooks like `outputOptions`\n // type `this` as rollup's `PluginContext` vs rolldown's\n // `MinimalPluginContext`, which makes them unassignable (the `this`\n // type is contravariant). rolldown accepts rollup plugins at runtime,\n // so this is harmless — cast to work around the type mismatch.\n ctx.plugins.push(originalPlugin as unknown as Plugin);\n\n // `@vanilla-extract/rollup-plugin` emits the extracted CSS via\n // `emitFile({ type: 'asset', name: cssFileName })`. Because it uses\n // `name` (a hint) rather than `fileName`, rolldown runs it through the\n // default `assetFileNames` pattern (`assets/[name]-[hash][extname]`),\n // producing e.g. `dist/assets/vue-app-layout-dry0z-1l.css`.\n //\n // We can't *rename* an asset in `generateBundle` because rolldown\n // ignores mutations to a bundle entry's `fileName`. Instead, override\n // `assetFileNames` via the `outputOptions` hook so this single CSS\n // asset keeps its derived name verbatim (no hash, no `assets/` dir)\n // while every other asset keeps its original naming.\n ctx.plugins.push({\n name: `${PLUGIN_NAME}:rename-css`,\n outputOptions(opts) {\n const original = opts.assetFileNames;\n opts.assetFileNames = (assetInfo) => {\n if (assetInfo.names.includes(cssFileName)) {\n return cssFileName;\n }\n if (typeof original === 'function') return original(assetInfo);\n return original ?? 'assets/[name]-[hash][extname]';\n };\n return opts;\n },\n // Split vanilla-extract's single bundle into one CSS file per entry.\n //\n // `extract: { name }` mode collects the CSS of EVERY `.css.ts` in the\n // graph into one asset (`cssFileName`), which loses plugboy's per-entry\n // CSS contract: every entry with `css: true` declares a `./<entry>.css`\n // export, but only `cssFileName` is ever produced. We rebuild the\n // per-entry files from data vanilla-extract already exposes:\n // `moduleInfo.meta.css` (its public hand-off for extracted CSS, the\n // same field its own bundler reads).\n //\n // CSS is attributed to an entry by walking the INPUT module graph from\n // that entry's `facadeModuleId` via `getModuleInfo().importedIds`, NOT\n // by reading the output chunk's `imports`. `chunk.imports` lists output\n // chunk file names plus external ids, and whether vanilla-extract's\n // external virtual CSS ids appear there is rolldown-version-dependent\n // (some versions only list real output chunks, so the lookup finds\n // nothing and the split silently no-ops). The input graph is stable: it\n // always yields the `.css.ts` modules an entry reaches, regardless of\n // how rolldown chunks the output. A `.css.ts` shared by several entries\n // is included in each entry's file (self-contained per-entry CSS).\n //\n // We never parse vanilla-extract's asset names or re-add the import\n // statements it strips, so the only coupling is `meta.css`.\n //\n // Runs before `plugboy-optimize-css` (appended later in\n // `workspace.plugins`), so each emitted per-entry file still goes\n // through the postcss optimizations.\n //\n // Only splits when more than one entry actually has CSS. With a single\n // CSS entry (the common case) vanilla-extract's bundle is already the\n // correct, fully-ordered output, so it is left untouched and existing\n // single-entry packages are byte-for-byte unaffected.\n generateBundle(_options, bundle) {\n // Walk the input module graph from `root`, collecting (deduped, in\n // import order) the CSS of every `.css.ts` reached (`meta.css`), and\n // flagging whether any plain (non-`.css.ts`) CSS file is imported.\n const collectEntryCss = (\n root: string,\n ): { css: string[]; hasPlain: boolean } => {\n const visited = new Set<string>();\n const seenCss = new Set<string>();\n const out: string[] = [];\n let hasPlain = false;\n const walk = (id: string) => {\n if (visited.has(id)) return;\n visited.add(id);\n const info = this.getModuleInfo(id);\n if (!info) return;\n for (const dep of info.importedIds ?? []) {\n const css = this.getModuleInfo(dep)?.meta?.css;\n if (typeof css === 'string') {\n // vanilla-extract virtual CSS (`*.vanilla.css`).\n if (!seenCss.has(dep)) {\n seenCss.add(dep);\n out.push(css);\n }\n } else if (/\\.css(\\?|$)/i.test(dep)) {\n // Plain CSS import (no `meta.css`) — its content lives in\n // tsdown's combined blob, merged per entry in `writeBundle`.\n hasPlain = true;\n }\n walk(dep);\n }\n };\n walk(root);\n return { css: out, hasPlain };\n };\n\n const entryCss: {\n name: string;\n source: string;\n hasPlain: boolean;\n }[] = [];\n\n for (const chunk of Object.values(bundle)) {\n if (\n chunk.type !== 'chunk' ||\n !chunk.isEntry ||\n !chunk.fileName.endsWith('.mjs') ||\n !chunk.facadeModuleId\n ) {\n continue;\n }\n const { css, hasPlain } = collectEntryCss(chunk.facadeModuleId);\n if (css.length) {\n entryCss.push({\n name: chunk.name,\n source: css.join('\\n'),\n hasPlain,\n });\n }\n }\n\n // 0 or 1 CSS entry → vanilla-extract's bundle is already correct,\n // and the single-file `writeBundle` fallback applies unchanged.\n if (entryCss.length <= 1) return;\n\n // Replace vanilla-extract's combined bundle with per-entry files.\n // The entry whose file name matches `cssFileName` overwrites the\n // existing asset in place — re-`emitFile`ing the same name would\n // trip rolldown's FILE_NAME_CONFLICT, since deleting the bundle\n // entry does not release the reserved file name. Other entries are\n // emitted as new assets.\n const reused = new Set<string>();\n for (const { name, source } of entryCss) {\n const fileName = `${name}.css`;\n const existing = bundle[fileName];\n if (existing && existing.type === 'asset') {\n existing.source = source;\n reused.add(fileName);\n } else {\n this.emitFile({ type: 'asset', fileName, source });\n }\n }\n\n // Drop vanilla-extract's combined bundle if no entry reused it.\n const combined = bundle[cssFileName];\n if (\n combined &&\n combined.type === 'asset' &&\n !reused.has(cssFileName)\n ) {\n delete bundle[cssFileName];\n }\n\n // Tell `writeBundle` where to merge tsdown's plain-CSS blob: into\n // each entry CSS file whose entry imports plain CSS. Falling back to\n // the first entry's file keeps the blob attached to a real, exported\n // CSS file instead of resurrecting the now-deleted `cssFileName`.\n plainCssTargets.clear();\n plainCssFallback = `${entryCss[0].name}.css`;\n for (const { name, hasPlain } of entryCss) {\n if (hasPlain) plainCssTargets.add(`${name}.css`);\n }\n },\n // Merge tsdown's own plain-CSS blob (emitted to\n // `TSDOWN_CSS_FILE_NAME`) into the vanilla-extract CSS file(s).\n //\n // This has to happen in `writeBundle`, not `generateBundle`: tsdown\n // emits its CSS in a separate output pass, so `TSDOWN_CSS_FILE_NAME`\n // is absent from the bundle our `generateBundle` sees but present by\n // `writeBundle`. By then the vanilla-extract files are already on disk,\n // so we merge on disk rather than mutating bundle sources. tsdown's\n // CSS goes first so its `@layer` declarations / resets / `@font-face`\n // are established before the extracted component styles.\n //\n // Targets:\n // - Per-entry split fired → the entry CSS files whose entries import\n // plain CSS (`plainCssTargets`), falling back to the first entry's\n // file. Never `cssFileName`, which the split deleted (no orphan).\n // - No split (single CSS entry) → `cssFileName`, the one combined file.\n // The combined blob cannot be partitioned per entry, so when several\n // entries import distinct plain CSS each target receives the whole\n // blob; in practice plain CSS (fonts/resets) is imported by one entry.\n async writeBundle(outputOptions, bundle) {\n // Only the output pass that emitted tsdown's CSS performs the merge\n // (it is the one whose `bundle` contains `TSDOWN_CSS_FILE_NAME`).\n // This also prevents a second output from re-injecting the imports.\n const tmp = bundle[TSDOWN_CSS_FILE_NAME];\n if (!tmp) return;\n\n const tmpCss = tmp.type === 'asset' ? tmp.source.toString() : '';\n const dir = outputOptions.dir ?? '.';\n const tmpPath = path.join(dir, TSDOWN_CSS_FILE_NAME);\n\n if (tmpCss) {\n const targets = plainCssTargets.size\n ? [...plainCssTargets]\n : [plainCssFallback];\n\n await Promise.all(\n targets.map(async (target) => {\n const targetPath = path.join(dir, target);\n let targetCss = '';\n try {\n targetCss = await fs.readFile(targetPath, 'utf8');\n } catch {\n // No vanilla-extract file for this target (e.g. `.css.ts`\n // produced no rules) — tsdown's CSS becomes the whole file.\n }\n await fs.writeFile(\n targetPath,\n targetCss ? `${tmpCss}\\n${targetCss}` : tmpCss,\n );\n }),\n );\n }\n\n await fs.rm(tmpPath, { force: true });\n },\n });\n }\n },\n },\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AA0BA,MAAM,uBAAuB;AAE7B,eAAsB,2BAA2B,UAAyB,CAAC,GAAG;CAC5E,OAAO,aAAmC;EACxC,MAAM;EACN,UAAU;EACV,OAAO,EACL,MAAM,eAAe,KAAK,cAAc;GAOtC,MAAM,WAAW,OAAO,KAAK,IAAI,OAAO,OAAO;GAI/C,MAAM,cAAc,GAHA,SAAS,SAAS,GAAG,IACrC,IAAI,IAAI,WACP,SAAS,MAAM,IAAI,IAAI,SACO;GAanC,MAAM,kCAAkB,IAAI,IAAY;GACxC,IAAI,mBAAmB;GAEvB,IAAI,eAAe,kBAAkB;GAErC,IAAI,KAAK,oBAAoB,CAAC,CAAE,MAAM,SACpC,IAAI,KAAK,IAAI,OACb,YACF;GAOA,IAAI,MAAM;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AG,SAAS,YAAY,MAAM;QAClD,QAAQ,CAGR;QACA,MAAM,GAAG,UACP,YACA,YAAY,GAAG,OAAO,IAAI,cAAc,MAC1C;OACF,CAAC,CACH;MACF;MAEA,MAAM,GAAG,GAAG,SAAS,EAAE,OAAO,KAAK,CAAC;KACtC;IACF,CAAC;GACH;EACF,EACF;CACF,CAAC;AACH"}
@@ -0,0 +1,6 @@
1
+ //#region src/types.ts
2
+ const PLUGIN_NAME = "plugboy-vanilla-extract";
3
+ //#endregion
4
+ export { PLUGIN_NAME as t };
5
+
6
+ //# sourceMappingURL=types-Djg9yxv0.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types-Djg9yxv0.mjs","names":[],"sources":["../src/types.ts"],"sourcesContent":["import { Plugin } from '@fastkit/plugboy';\nimport type { vanillaExtractPlugin as rollupPlugin } from '@vanilla-extract/rollup-plugin';\n\ntype VanillaExtractPluginOptions = Omit<\n NonNullable<Parameters<typeof rollupPlugin>[0]>,\n 'extract'\n>;\n\nexport type PluginOptions = Pick<\n VanillaExtractPluginOptions,\n 'identifiers' | 'esbuildOptions'\n>;\n\nexport const PLUGIN_NAME = 'plugboy-vanilla-extract';\n\nexport interface VanillaExtractPlugin extends Plugin {\n name: typeof PLUGIN_NAME;\n _options: PluginOptions;\n}\n"],"mappings":";AAaA,MAAa,cAAc"}
@@ -0,0 +1,9 @@
1
+ import { vanillaExtractPlugin } from "@vanilla-extract/vite-plugin";
2
+ import { Plugin } from "vite";
3
+
4
+ //#region src/vite.d.ts
5
+ type VanillaExtractVitePluginOptions = NonNullable<Parameters<typeof vanillaExtractPlugin>[0]>;
6
+ interface ViteVanillaExtractPluginOptions extends VanillaExtractVitePluginOptions {}
7
+ declare function ViteVanillaExtractPlugin(options?: ViteVanillaExtractPluginOptions): Promise<Plugin[]>;
8
+ //#endregion
9
+ export { ViteVanillaExtractPlugin, ViteVanillaExtractPluginOptions };
package/dist/vite.mjs ADDED
@@ -0,0 +1,22 @@
1
+ import "./types-Djg9yxv0.mjs";
2
+ import { findProjectPlugin } from "@fastkit/plugboy";
3
+ import { vanillaExtractPlugin } from "@vanilla-extract/vite-plugin";
4
+ //#region src/vite.ts
5
+ async function ViteVanillaExtractPlugin(options = {}) {
6
+ const { identifiers: baseIdentifiers } = (await findProjectPlugin("plugboy-vanilla-extract"))?._options || {};
7
+ return [...vanillaExtractPlugin({
8
+ identifiers: baseIdentifiers,
9
+ ...options
10
+ }), {
11
+ name: "vanilla-extract-fix-file-scope",
12
+ config(viteConfig) {
13
+ viteConfig.resolve ??= {};
14
+ viteConfig.resolve.dedupe ??= [];
15
+ viteConfig.resolve.dedupe.push("@vanilla-extract/css", "@vanilla-extract/css/fileScope");
16
+ }
17
+ }];
18
+ }
19
+ //#endregion
20
+ export { ViteVanillaExtractPlugin };
21
+
22
+ //# sourceMappingURL=vite.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vite.mjs","names":[],"sources":["../src/vite.ts"],"sourcesContent":["import { findProjectPlugin } from '@fastkit/plugboy';\nimport { Plugin as VitePlugin } from 'vite';\nimport { vanillaExtractPlugin } from '@vanilla-extract/vite-plugin';\nimport { PLUGIN_NAME, VanillaExtractPlugin } from './types';\n\ntype VanillaExtractVitePluginOptions = NonNullable<\n Parameters<typeof vanillaExtractPlugin>[0]\n>;\n\nexport interface ViteVanillaExtractPluginOptions extends VanillaExtractVitePluginOptions {}\n\nexport async function ViteVanillaExtractPlugin(\n options: ViteVanillaExtractPluginOptions = {},\n): Promise<VitePlugin[]> {\n const plugin = await findProjectPlugin<VanillaExtractPlugin>(PLUGIN_NAME);\n const { identifiers: baseIdentifiers } = plugin?._options || {};\n\n return [\n ...vanillaExtractPlugin({\n identifiers: baseIdentifiers,\n ...options,\n }),\n // @MEMO\n // Plugin to prevent file scope mismatches when utilities using vanilla-extract\n // functions are placed in external files\n {\n name: 'vanilla-extract-fix-file-scope',\n config(viteConfig) {\n viteConfig.resolve ??= {};\n viteConfig.resolve.dedupe ??= [];\n viteConfig.resolve.dedupe.push(\n '@vanilla-extract/css',\n '@vanilla-extract/css/fileScope',\n );\n },\n },\n ];\n}\n"],"mappings":";;;;AAWA,eAAsB,yBACpB,UAA2C,CAAC,GACrB;CAEvB,MAAM,EAAE,aAAa,qBAAoB,MADpB,kBAAA,yBAAmD,EAAA,EACvB,YAAY,CAAC;CAE9D,OAAO,CACL,GAAG,qBAAqB;EACtB,aAAa;EACb,GAAG;CACL,CAAC,GAID;EACE,MAAM;EACN,OAAO,YAAY;GACjB,WAAW,YAAY,CAAC;GACxB,WAAW,QAAQ,WAAW,CAAC;GAC/B,WAAW,QAAQ,OAAO,KACxB,wBACA,gCACF;EACF;CACF,CACF;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fastkit/plugboy-vanilla-extract-plugin",
3
- "version": "4.0.0",
3
+ "version": "4.1.0",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "repository": {
@@ -18,6 +18,12 @@
18
18
  "default": "./dist/plugboy-vanilla-extract-plugin.mjs"
19
19
  }
20
20
  },
21
+ "./vite": {
22
+ "types": "./dist/vite.d.mts",
23
+ "import": {
24
+ "default": "./dist/vite.mjs"
25
+ }
26
+ },
21
27
  "./*": "./dist/*"
22
28
  },
23
29
  "main": "./dist/plugboy-vanilla-extract-plugin.mjs",
@@ -26,6 +32,9 @@
26
32
  "*": {
27
33
  ".": [
28
34
  "./dist/plugboy-vanilla-extract-plugin.d.mts"
35
+ ],
36
+ "vite": [
37
+ "./dist/vite.d.mts"
29
38
  ]
30
39
  }
31
40
  },
@@ -33,16 +42,17 @@
33
42
  "dist"
34
43
  ],
35
44
  "dependencies": {
36
- "@vanilla-extract/rollup-plugin": "^1.5.3",
37
- "@vanilla-extract/vite-plugin": "^5.2.2"
45
+ "@vanilla-extract/rollup-plugin": "^1.5.3"
38
46
  },
39
47
  "devDependencies": {
48
+ "@vanilla-extract/vite-plugin": "^5.2.2",
40
49
  "vite": "^8.0.16",
41
- "@fastkit/plugboy": "^1.0.0"
50
+ "@fastkit/plugboy": "^1.0.1"
42
51
  },
43
52
  "peerDependencies": {
44
- "vite": "^5.0.0 || ^6.0.0 || ^7.0.0",
45
- "@fastkit/plugboy": "^1.0.0"
53
+ "@vanilla-extract/vite-plugin": "^5.0.0",
54
+ "vite": "^6.0.0 || ^7.0.0 || ^8.0.0",
55
+ "@fastkit/plugboy": "^1.0.1"
46
56
  },
47
57
  "peerDependenciesMeta": {
48
58
  "@vanilla-extract/vite-plugin": {