@fastkit/plugboy-sass-plugin 3.0.2 → 3.0.4
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.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { definePlugin } from "@fastkit/plugboy";
|
|
1
|
+
import { captureChunkGraph, definePlugin, orderPackageChunks } from "@fastkit/plugboy";
|
|
2
2
|
import sass from "rollup-plugin-sass";
|
|
3
3
|
import { parse, resolve } from "path";
|
|
4
4
|
import { existsSync } from "fs";
|
|
@@ -28,15 +28,18 @@ function modulesPaths(absWorkingDir) {
|
|
|
28
28
|
* to finish and the emitted CSS differs between builds of identical sources —
|
|
29
29
|
* which matters, because that order is the cascade order.
|
|
30
30
|
*
|
|
31
|
-
* The
|
|
32
|
-
*
|
|
33
|
-
*
|
|
31
|
+
* The key is the order the stylesheets load in: chunks in dependency order
|
|
32
|
+
* (`orderPackageChunks`, the order plugboy assembles every other stylesheet in),
|
|
33
|
+
* and modules in their order within each chunk. The bundle's own chunk order is
|
|
34
|
+
* stable but not usable, since it puts a shared chunk after the entries that
|
|
35
|
+
* depend on it. Entries the module graph does not account for keep the order
|
|
36
|
+
* they were collected in, after the ones that could be placed.
|
|
34
37
|
*/
|
|
35
|
-
function concatStylesInModuleOrder(entries, bundle) {
|
|
38
|
+
function concatStylesInModuleOrder(entries, bundle, entryIds) {
|
|
36
39
|
const position = /* @__PURE__ */ new Map();
|
|
37
|
-
for (const
|
|
38
|
-
const chunk =
|
|
39
|
-
if (chunk
|
|
40
|
+
for (const fileName of orderPackageChunks(captureChunkGraph(bundle), entryIds)) {
|
|
41
|
+
const chunk = bundle[fileName];
|
|
42
|
+
if (chunk?.type !== "chunk" || !chunk.modules) continue;
|
|
40
43
|
for (const id of Object.keys(chunk.modules)) if (!position.has(id)) position.set(id, position.size);
|
|
41
44
|
}
|
|
42
45
|
return entries.map((entry, collectedAt) => ({
|
|
@@ -75,11 +78,12 @@ function createSassPlugin(options = {}) {
|
|
|
75
78
|
} },
|
|
76
79
|
async generateBundle(outputOptions, bundle, isWrite) {
|
|
77
80
|
if (typeof generateBundle === "function") await generateBundle.call(this, outputOptions, bundle, isWrite);
|
|
78
|
-
const
|
|
81
|
+
const workspace = _getWorkspace();
|
|
82
|
+
const styles = concatStylesInModuleOrder(_styleEntries, bundle, workspace && Object.keys(workspace.entry));
|
|
79
83
|
if (!styles) return;
|
|
80
84
|
let cssFile = outputOptions.file;
|
|
81
85
|
if (!cssFile) {
|
|
82
|
-
const cssExport =
|
|
86
|
+
const cssExport = workspace?.exports.find((e) => e.id.endsWith(".css"));
|
|
83
87
|
if (cssExport) {
|
|
84
88
|
const tmp = cssExport.id.split("/");
|
|
85
89
|
cssFile = tmp[tmp.length - 1];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugboy-sass-plugin.mjs","names":[],"sources":["../src/types.ts","../src/utils.ts","../src/plugin.ts"],"sourcesContent":["import { Plugin } from '@fastkit/plugboy';\nimport sass from 'rollup-plugin-sass';\nimport { type Options as SassOptions } from 'sass';\n\ntype RollupPluginSassOptions = NonNullable<Parameters<typeof sass>[0]>;\n\nexport interface PluginOptions extends Pick<\n RollupPluginSassOptions,\n 'include' | 'exclude'\n> {\n sass?: SassOptions<'async'>;\n}\n\n/**\n * One stylesheet as collected by rollup-plugin-sass, handed to the `output`\n * callback alongside the concatenated result.\n */\nexport type SassStyleEntry = Parameters<\n Extract<NonNullable<RollupPluginSassOptions['output']>, (...args: any) => any>\n>[1][number];\n\nexport const PLUGIN_NAME = 'plugboy-sass';\n\nexport interface SassPlugin extends Plugin {\n name: typeof PLUGIN_NAME;\n _options: PluginOptions;\n}\n","import { parse, resolve } from 'path';\nimport { existsSync } from 'fs';\n\nexport function modulesPaths(absWorkingDir?: string): string[] {\n let path = absWorkingDir || process.cwd();\n const { root } = parse(path);\n const found: string[] = [];\n\n while (path !== root) {\n const filename = resolve(path, 'node_modules');\n if (existsSync(filename)) {\n found.push(filename);\n }\n path = resolve(path, '..');\n }\n return [...found];\n}\n","import {
|
|
1
|
+
{"version":3,"file":"plugboy-sass-plugin.mjs","names":[],"sources":["../src/types.ts","../src/utils.ts","../src/plugin.ts"],"sourcesContent":["import { Plugin } from '@fastkit/plugboy';\nimport sass from 'rollup-plugin-sass';\nimport { type Options as SassOptions } from 'sass';\n\ntype RollupPluginSassOptions = NonNullable<Parameters<typeof sass>[0]>;\n\nexport interface PluginOptions extends Pick<\n RollupPluginSassOptions,\n 'include' | 'exclude'\n> {\n sass?: SassOptions<'async'>;\n}\n\n/**\n * One stylesheet as collected by rollup-plugin-sass, handed to the `output`\n * callback alongside the concatenated result.\n */\nexport type SassStyleEntry = Parameters<\n Extract<NonNullable<RollupPluginSassOptions['output']>, (...args: any) => any>\n>[1][number];\n\nexport const PLUGIN_NAME = 'plugboy-sass';\n\nexport interface SassPlugin extends Plugin {\n name: typeof PLUGIN_NAME;\n _options: PluginOptions;\n}\n","import { parse, resolve } from 'path';\nimport { existsSync } from 'fs';\n\nexport function modulesPaths(absWorkingDir?: string): string[] {\n let path = absWorkingDir || process.cwd();\n const { root } = parse(path);\n const found: string[] = [];\n\n while (path !== root) {\n const filename = resolve(path, 'node_modules');\n if (existsSync(filename)) {\n found.push(filename);\n }\n path = resolve(path, '..');\n }\n return [...found];\n}\n","import {\n captureChunkGraph,\n definePlugin,\n orderPackageChunks,\n type TryGetWorkspace,\n} from '@fastkit/plugboy';\nimport sass from 'rollup-plugin-sass';\nimport {\n PLUGIN_NAME,\n PluginOptions,\n SassPlugin,\n SassStyleEntry,\n} from './types';\nimport { modulesPaths } from './utils';\n\n/** The parts of a bundle output the ordering reads. */\ninterface BundleOutput {\n type: string;\n fileName: string;\n name?: string;\n isEntry?: boolean;\n imports?: string[];\n dynamicImports?: string[];\n modules?: Record<string, unknown>;\n}\n\n/**\n * Concatenate the collected stylesheets in module execution order.\n *\n * rollup-plugin-sass appends each stylesheet to a flat array from its\n * `transform` hook, then joins that array as-is. rolldown runs `transform`\n * concurrently, so the array ends up in whatever order the transforms happened\n * to finish and the emitted CSS differs between builds of identical sources —\n * which matters, because that order is the cascade order.\n *\n * The key is the order the stylesheets load in: chunks in dependency order\n * (`orderPackageChunks`, the order plugboy assembles every other stylesheet in),\n * and modules in their order within each chunk. The bundle's own chunk order is\n * stable but not usable, since it puts a shared chunk after the entries that\n * depend on it. Entries the module graph does not account for keep the order\n * they were collected in, after the ones that could be placed.\n */\nfunction concatStylesInModuleOrder(\n entries: SassStyleEntry[],\n bundle: Record<string, BundleOutput>,\n entryIds: readonly string[] | undefined,\n): string {\n const position = new Map<string, number>();\n\n for (const fileName of orderPackageChunks(\n captureChunkGraph(bundle),\n entryIds,\n )) {\n const chunk = bundle[fileName];\n if (chunk?.type !== 'chunk' || !chunk.modules) continue;\n for (const id of Object.keys(chunk.modules)) {\n if (!position.has(id)) position.set(id, position.size);\n }\n }\n\n return entries\n .map((entry, collectedAt) => ({ entry, collectedAt }))\n .sort((a, b) => {\n const pa =\n a.entry.id === undefined ? undefined : position.get(a.entry.id);\n const pb =\n b.entry.id === undefined ? undefined : position.get(b.entry.id);\n if (pa === undefined && pb === undefined)\n return a.collectedAt - b.collectedAt;\n if (pa === undefined) return 1;\n if (pb === undefined) return -1;\n return pa - pb;\n })\n .map(({ entry }) => entry.content || '')\n .join('');\n}\n\nexport function createSassPlugin(options: PluginOptions = {}) {\n let _styleEntries: SassStyleEntry[] = [];\n\n const { sass: sassOptions, ...restOptions } = options;\n\n const {\n name: _name,\n generateBundle,\n ...sassPluginSettings\n } = sass({\n api: 'modern',\n ...restOptions,\n options: {\n ...sassOptions,\n loadPaths: Array.from(\n new Set([...(sassOptions?.loadPaths || modulesPaths())]),\n ),\n },\n // The joined string this also receives is built in transform-completion\n // order, so take the entries and join them ourselves.\n output(_styles, entries) {\n _styleEntries = entries;\n },\n });\n\n let _getWorkspace: TryGetWorkspace;\n\n return definePlugin<SassPlugin>({\n name: PLUGIN_NAME,\n _options: options,\n ...(sassPluginSettings as any),\n hooks: {\n setupWorkspace(_, getWorkspace) {\n _getWorkspace = getWorkspace;\n },\n },\n async generateBundle(outputOptions, bundle, isWrite) {\n if (typeof generateBundle === 'function') {\n await generateBundle.call(\n this as any,\n outputOptions as any,\n bundle as any,\n isWrite,\n );\n }\n\n const workspace = _getWorkspace();\n const styles = concatStylesInModuleOrder(\n _styleEntries,\n bundle as unknown as Record<string, BundleOutput>,\n workspace && Object.keys(workspace.entry),\n );\n if (!styles) return;\n\n let cssFile = outputOptions.file;\n\n if (!cssFile) {\n const cssExport = workspace?.exports.find((e) => e.id.endsWith('.css'));\n if (cssExport) {\n const tmp = cssExport.id.split('/');\n cssFile = tmp[tmp.length - 1];\n } else {\n const fileNames = Object.keys(bundle);\n const jsFile = fileNames.find((f) => /\\.m?js$/.test(f));\n\n if (!jsFile) {\n return;\n }\n cssFile = jsFile.replace(/\\.m?js$/, '.css');\n }\n }\n this.emitFile({\n type: 'asset',\n name: cssFile,\n fileName: cssFile,\n source: styles,\n });\n },\n });\n}\n"],"mappings":";;;;;AAqBA,MAAa,cAAc;;;AClB3B,SAAgB,aAAa,eAAkC;CAC7D,IAAI,OAAO,iBAAiB,QAAQ,IAAI;CACxC,MAAM,EAAE,SAAS,MAAM,IAAI;CAC3B,MAAM,QAAkB,CAAC;CAEzB,OAAO,SAAS,MAAM;EACpB,MAAM,WAAW,QAAQ,MAAM,cAAc;EAC7C,IAAI,WAAW,QAAQ,GACrB,MAAM,KAAK,QAAQ;EAErB,OAAO,QAAQ,MAAM,IAAI;CAC3B;CACA,OAAO,CAAC,GAAG,KAAK;AAClB;;;;;;;;;;;;;;;;;;;AC0BA,SAAS,0BACP,SACA,QACA,UACQ;CACR,MAAM,2BAAW,IAAI,IAAoB;CAEzC,KAAK,MAAM,YAAY,mBACrB,kBAAkB,MAAM,GACxB,QACF,GAAG;EACD,MAAM,QAAQ,OAAO;EACrB,IAAI,OAAO,SAAS,WAAW,CAAC,MAAM,SAAS;EAC/C,KAAK,MAA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F,MAAM,YAAY,cAAc;GAChC,MAAM,SAAS,0BACb,eACA,QACA,aAAa,OAAO,KAAK,UAAU,KAAK,CAC1C;GACA,IAAI,CAAC,QAAQ;GAEb,IAAI,UAAU,cAAc;GAE5B,IAAI,CAAC,SAAS;IACZ,MAAM,YAAY,WAAW,QAAQ,MAAM,MAAM,EAAE,GAAG,SAAS,MAAM,CAAC;IACtE,IAAI,WAAW;KACb,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG;KAClC,UAAU,IAAI,IAAI,SAAS;IAC7B,OAAO;KAEL,MAAM,SADY,OAAO,KAAK,MACP,CAAC,CAAC,MAAM,MAAM,UAAU,KAAK,CAAC,CAAC;KAEtD,IAAI,CAAC,QACH;KAEF,UAAU,OAAO,QAAQ,WAAW,MAAM;IAC5C;GACF;GACA,KAAK,SAAS;IACZ,MAAM;IACN,MAAM;IACN,UAAU;IACV,QAAQ;GACV,CAAC;EACH;CACF,CAAC;AACH"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fastkit/plugboy-sass-plugin",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.4",
|
|
4
4
|
"description": "plugboy-sass-plugin",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"plugboy",
|
|
@@ -40,10 +40,13 @@
|
|
|
40
40
|
"sass": "^1.102.0"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@fastkit/plugboy": "^1.
|
|
43
|
+
"@fastkit/plugboy": "^1.6.0"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
46
|
-
"@fastkit/plugboy": "^1.
|
|
46
|
+
"@fastkit/plugboy": "^1.6.0"
|
|
47
|
+
},
|
|
48
|
+
"engines": {
|
|
49
|
+
"node": ">=22.18.0"
|
|
47
50
|
},
|
|
48
51
|
"scripts": {
|
|
49
52
|
"build": "plugboy build",
|