@fastkit/plugboy-vanilla-extract-plugin 4.2.0 → 4.2.2
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.
|
@@ -10,8 +10,10 @@ async function createVanillaExtractPlugin(options = {}) {
|
|
|
10
10
|
_options: options,
|
|
11
11
|
hooks: { async setupWorkspace(ctx) {
|
|
12
12
|
const entryIds = Object.keys(ctx.config.entries);
|
|
13
|
-
const
|
|
14
|
-
const
|
|
13
|
+
const cssEntryIds = Object.entries(ctx.config.entries).filter(([, entry]) => entry.css).map(([id]) => id);
|
|
14
|
+
const normalizeEntryId = (id) => id === "." ? ctx.dir.basename : id;
|
|
15
|
+
const cssFileName = `${cssEntryIds.length === 1 ? normalizeEntryId(cssEntryIds[0]) : entryIds.includes(".") ? ctx.dir.basename : entryIds[0] ?? ctx.dir.basename}.css`;
|
|
16
|
+
const cssEntryCount = cssEntryIds.length;
|
|
15
17
|
ctx.mergeExternals(/@vanilla-extract/);
|
|
16
18
|
ctx.meta.hasVanillaExtract = !!await findFile(ctx.dirs.src.value, /\.css\.ts$/);
|
|
17
19
|
ctx.css = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugboy-vanilla-extract-plugin.mjs","names":[],"sources":["../src/plugin.ts"],"sourcesContent":["import path from 'node:path';\nimport { definePlugin, findFile, type Plugin } from '@fastkit/plugboy';\nimport { vanillaExtractPlugin } from '@vanilla-extract/rollup-plugin';\nimport {\n virtualCssFileFilter,\n getSourceFromVirtualCssFile,\n} from '@vanilla-extract/integration';\nimport { VanillaExtractPlugin, PluginOptions, PLUGIN_NAME } from './types';\n\ndeclare module '@fastkit/plugboy' {\n export interface WorkspaceMeta {\n hasVanillaExtract: boolean;\n }\n}\n\nexport async function createVanillaExtractPlugin(options: PluginOptions = {}) {\n return definePlugin<VanillaExtractPlugin>({\n name: PLUGIN_NAME,\n _options: options,\n hooks: {\n async setupWorkspace(ctx) {\n // Derive the CSS file name from the workspace entry, mirroring the way\n // plugboy names the JS output: the main entry (`.`) maps to the package\n // directory name (e.g. `vue-app-layout`), other entries keep their id.\n //
|
|
1
|
+
{"version":3,"file":"plugboy-vanilla-extract-plugin.mjs","names":[],"sources":["../src/plugin.ts"],"sourcesContent":["import path from 'node:path';\nimport { definePlugin, findFile, type Plugin } from '@fastkit/plugboy';\nimport { vanillaExtractPlugin } from '@vanilla-extract/rollup-plugin';\nimport {\n virtualCssFileFilter,\n getSourceFromVirtualCssFile,\n} from '@vanilla-extract/integration';\nimport { VanillaExtractPlugin, PluginOptions, PLUGIN_NAME } from './types';\n\ndeclare module '@fastkit/plugboy' {\n export interface WorkspaceMeta {\n hasVanillaExtract: boolean;\n }\n}\n\nexport async function createVanillaExtractPlugin(options: PluginOptions = {}) {\n return definePlugin<VanillaExtractPlugin>({\n name: PLUGIN_NAME,\n _options: options,\n hooks: {\n async setupWorkspace(ctx) {\n // Derive the CSS file name from the workspace entry, mirroring the way\n // plugboy names the JS output: the main entry (`.`) maps to the package\n // directory name (e.g. `vue-app-layout`), other entries keep their id.\n //\n // `splitting: false` produces a single combined CSS for the package, so\n // that one file has to be named after the entry plugboy declared\n // `./<entry>.css` for — which is the entry carrying `css: true`, not\n // necessarily the main one. Naming it after the main entry regardless\n // left a package whose only `css: true` entry is a secondary one (say\n // `styles`, in a package with a `.` entry that has no CSS) emitting\n // `dist/<package>.css` while plugboy declared `./styles.css`, so the\n // published export resolved to a file the build never wrote.\n //\n // With no CSS entry the name is unused; with several, `splitting` takes\n // over and names each stylesheet after its chunk.\n const entryIds = Object.keys(ctx.config.entries);\n const cssEntryIds = Object.entries(ctx.config.entries)\n .filter(([, entry]) => entry.css)\n .map(([id]) => id);\n const normalizeEntryId = (id: string) =>\n id === '.' ? ctx.dir.basename : id;\n const cssBaseName =\n cssEntryIds.length === 1\n ? normalizeEntryId(cssEntryIds[0])\n : entryIds.includes('.')\n ? ctx.dir.basename\n : (entryIds[0] ?? ctx.dir.basename);\n const cssFileName = `${cssBaseName}.css`;\n\n // plugboy declares a `./<entry>.css` export for every entry with\n // `css: true`, so more than one of them needs one stylesheet per entry —\n // which is what tsdown's `css.splitting` produces (one file per output\n // chunk, named after it). `splitting: false` collects the whole package\n // into `fileName`, and with several entries in play it keeps only one\n // chunk's CSS, silently dropping the rest.\n const cssEntryCount = cssEntryIds.length;\n\n ctx.mergeExternals(/@vanilla-extract/);\n\n ctx.meta.hasVanillaExtract = !!(await findFile(\n ctx.dirs.src.value,\n /\\.css\\.ts$/,\n ));\n\n // Defaults, not overrides: `...ctx.css` comes last so anything the\n // workspace/project configuration declares wins. See the README for why\n // these two keys should be left to the plugin.\n ctx.css = {\n splitting: cssEntryCount > 1,\n fileName: cssFileName,\n ...ctx.css,\n };\n\n if (!ctx.meta.hasVanillaExtract) return;\n\n // Hand vanilla-extract's extracted CSS to tsdown's own CSS pipeline.\n //\n // `@vanilla-extract/rollup-plugin` resolves its virtual stylesheets\n // (`<file>.vanilla.css?source=<serialized>`) to `{ external: true }` and,\n // in `extract` mode, emits the collected CSS itself as a rolldown asset.\n // Either way tsdown never sees the CSS, so none of the `css` options\n // apply to it — `css.target` in particular, which is why extracted CSS\n // used to ship a bare `user-select` while `.scss` in the same repo got\n // its `-webkit-` prefix.\n //\n // Resolving the virtual id to a real module instead — the approach the\n // official `@vanilla-extract/vite-plugin` takes — puts the CSS in the\n // module graph as an ordinary `.css` module. tsdown then owns it: the\n // configured `transformer` (lightningcss *or* postcss), `target`,\n // `minify` and preprocessor options all apply, and its CSS pipeline\n // collects and emits it under `css.fileName`. plugboy's `optimizeCSS`\n // runs afterwards, on the written file.\n //\n // Two details are load-bearing:\n // - The `?source=` query MUST be stripped. `@tsdown/css` skips any CSS id\n // carrying a non-`?inline` query (`shouldSkipTransform`), in both its\n // compile and its collect plugin — an id with the query intact is\n // dropped from the CSS output entirely.\n // - This plugin must be registered *before* the vanilla-extract plugin so\n // its `resolveId` wins; otherwise the module is marked external again.\n const virtualCss = new Map<string, string>();\n\n ctx.plugins.push({\n name: `${PLUGIN_NAME}:virtual-css`,\n buildStart() {\n virtualCss.clear();\n },\n async resolveId(source) {\n if (!virtualCssFileFilter.test(source)) return null;\n const { fileName, source: css } =\n await getSourceFromVirtualCssFile(source);\n // `fileName` is `<package-relative path>.vanilla.css`; resolving it\n // against the package gives a stable, unique module id that still\n // ends in `.css`. No file exists there — `load` below supplies the\n // content — so the path only has to be unique.\n const id = path.resolve(ctx.dir.value, fileName);\n virtualCss.set(id, css);\n return id;\n },\n load(id) {\n return virtualCss.get(id) ?? null;\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` type\n // `this` as rollup's `PluginContext` vs rolldown's\n // `MinimalPluginContext`, which makes them unassignable (the `this` type\n // is contravariant). rolldown accepts rollup plugins at runtime, so this\n // is harmless — cast to work around the type mismatch.\n //\n // Only its `transform` hook is used here (compiling `.css.ts` to JS).\n // `extract` stays off: its asset emission is what this plugin replaces.\n ctx.plugins.push(vanillaExtractPlugin(options) as unknown as Plugin);\n },\n },\n });\n}\n"],"mappings":";;;;;;AAeA,eAAsB,2BAA2B,UAAyB,CAAC,GAAG;CAC5E,OAAO,aAAmC;EACxC,MAAM;EACN,UAAU;EACV,OAAO,EACL,MAAM,eAAe,KAAK;GAgBxB,MAAM,WAAW,OAAO,KAAK,IAAI,OAAO,OAAO;GAC/C,MAAM,cAAc,OAAO,QAAQ,IAAI,OAAO,OAAO,CAAC,CACnD,QAAQ,GAAG,WAAW,MAAM,GAAG,CAAC,CAChC,KAAK,CAAC,QAAQ,EAAE;GACnB,MAAM,oBAAoB,OACxB,OAAO,MAAM,IAAI,IAAI,WAAW;GAOlC,MAAM,cAAc,GALlB,YAAY,WAAW,IACnB,iBAAiB,YAAY,EAAE,IAC/B,SAAS,SAAS,GAAG,IACnB,IAAI,IAAI,WACP,SAAS,MAAM,IAAI,IAAI,SACG;GAQnC,MAAM,gBAAgB,YAAY;GAElC,IAAI,eAAe,kBAAkB;GAErC,IAAI,KAAK,oBAAoB,CAAC,CAAE,MAAM,SACpC,IAAI,KAAK,IAAI,OACb,YACF;GAKA,IAAI,MAAM;IACR,WAAW,gBAAgB;IAC3B,UAAU;IACV,GAAG,IAAI;GACT;GAEA,IAAI,CAAC,IAAI,KAAK,mBAAmB;GA2BjC,MAAM,6BAAa,IAAI,IAAoB;GAE3C,IAAI,QAAQ,KAAK;IACf,MAAM,GAAG,YAAY;IACrB,aAAa;KACX,WAAW,MAAM;IACnB;IACA,MAAM,UAAU,QAAQ;KACtB,IAAI,CAAC,qBAAqB,KAAK,MAAM,GAAG,OAAO;KAC/C,MAAM,EAAE,UAAU,QAAQ,QACxB,MAAM,4BAA4B,MAAM;KAK1C,MAAM,KAAK,KAAK,QAAQ,IAAI,IAAI,OAAO,QAAQ;KAC/C,WAAW,IAAI,IAAI,GAAG;KACtB,OAAO;IACT;IACA,KAAK,IAAI;KACP,OAAO,WAAW,IAAI,EAAE,KAAK;IAC/B;GACF,CAAC;GAYD,IAAI,QAAQ,KAAK,qBAAqB,OAAO,CAAsB;EACrE,EACF;CACF,CAAC;AACH"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fastkit/plugboy-vanilla-extract-plugin",
|
|
3
|
-
"version": "4.2.
|
|
3
|
+
"version": "4.2.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"repository": {
|
|
@@ -48,12 +48,12 @@
|
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"@vanilla-extract/vite-plugin": "^5.2.5",
|
|
50
50
|
"vite": "^8.1.5",
|
|
51
|
-
"@fastkit/plugboy": "^1.4.
|
|
51
|
+
"@fastkit/plugboy": "^1.4.2"
|
|
52
52
|
},
|
|
53
53
|
"peerDependencies": {
|
|
54
54
|
"@vanilla-extract/vite-plugin": "^5.0.0",
|
|
55
55
|
"vite": "^6.0.0 || ^7.0.0 || ^8.0.0",
|
|
56
|
-
"@fastkit/plugboy": "^1.4.
|
|
56
|
+
"@fastkit/plugboy": "^1.4.2"
|
|
57
57
|
},
|
|
58
58
|
"peerDependenciesMeta": {
|
|
59
59
|
"@vanilla-extract/vite-plugin": {
|
|
@@ -63,6 +63,9 @@
|
|
|
63
63
|
"optional": true
|
|
64
64
|
}
|
|
65
65
|
},
|
|
66
|
+
"engines": {
|
|
67
|
+
"node": ">=22.18.0"
|
|
68
|
+
},
|
|
66
69
|
"scripts": {
|
|
67
70
|
"build": "plugboy build",
|
|
68
71
|
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist",
|