@fastkit/plugboy-sass-plugin 2.2.0 → 3.0.0-next.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,20 @@
1
+ import { Plugin } from "@fastkit/plugboy";
2
+ import sass from "rollup-plugin-sass";
3
+ import { Options } from "sass";
4
+
5
+ //#region src/types.d.ts
6
+ type RollupPluginSassOptions = NonNullable<Parameters<typeof sass>[0]>;
7
+ interface PluginOptions extends Pick<RollupPluginSassOptions, 'include' | 'exclude'> {
8
+ sass?: Options<'async'>;
9
+ }
10
+ declare const PLUGIN_NAME = "plugboy-sass";
11
+ interface SassPlugin extends Plugin {
12
+ name: typeof PLUGIN_NAME;
13
+ _options: PluginOptions;
14
+ }
15
+ //#endregion
16
+ //#region src/plugin.d.ts
17
+ declare function createSassPlugin(options?: PluginOptions): SassPlugin;
18
+ //#endregion
19
+ export { createSassPlugin };
20
+ //# sourceMappingURL=plugboy-sass-plugin.d.mts.map
@@ -1,17 +1,71 @@
1
- import { definePlugin } from '@fastkit/plugboy';
2
- import { sassPlugin } from 'esbuild-sass-plugin';
3
-
4
- // src/types.ts
5
- var PLUGIN_NAME = "plugboy-sass";
6
-
7
- // src/plugin.ts
8
- function createSassPlugin(options) {
9
- return definePlugin({
10
- name: PLUGIN_NAME,
11
- esbuildPlugins: [sassPlugin(options)]
12
- });
1
+ import { definePlugin } from "@fastkit/plugboy";
2
+ import sass from "rollup-plugin-sass";
3
+ import { parse, resolve } from "path";
4
+ import { existsSync } from "fs";
5
+ //#region src/types.ts
6
+ const PLUGIN_NAME = "plugboy-sass";
7
+ //#endregion
8
+ //#region src/utils.ts
9
+ function modulesPaths(absWorkingDir) {
10
+ let path = absWorkingDir || process.cwd();
11
+ const { root } = parse(path);
12
+ const found = [];
13
+ while (path !== root) {
14
+ const filename = resolve(path, "node_modules");
15
+ if (existsSync(filename)) found.push(filename);
16
+ path = resolve(path, "..");
17
+ }
18
+ return [...found];
13
19
  }
14
-
20
+ //#endregion
21
+ //#region src/plugin.ts
22
+ function createSassPlugin(options = {}) {
23
+ let _styles = "";
24
+ const { sass: sassOptions, ...restOptions } = options;
25
+ const { name: _name, generateBundle, ...sassPluginSettings } = sass({
26
+ api: "modern",
27
+ ...restOptions,
28
+ options: {
29
+ ...sassOptions,
30
+ loadPaths: Array.from(new Set([...sassOptions?.loadPaths || modulesPaths()]))
31
+ },
32
+ output(styles) {
33
+ _styles = styles;
34
+ }
35
+ });
36
+ let _getWorkspace;
37
+ return definePlugin({
38
+ name: PLUGIN_NAME,
39
+ _options: options,
40
+ ...sassPluginSettings,
41
+ hooks: { setupWorkspace(_, getWorkspace) {
42
+ _getWorkspace = getWorkspace;
43
+ } },
44
+ async generateBundle(outputOptions, bundle, isWrite) {
45
+ if (typeof generateBundle === "function") await generateBundle.call(this, outputOptions, bundle, isWrite);
46
+ if (!_styles) return;
47
+ let cssFile = outputOptions.file;
48
+ if (!cssFile) {
49
+ const cssExport = _getWorkspace()?.exports.find((e) => e.id.endsWith(".css"));
50
+ if (cssExport) {
51
+ const tmp = cssExport.id.split("/");
52
+ cssFile = tmp[tmp.length - 1];
53
+ } else {
54
+ const jsFile = Object.keys(bundle).find((f) => /\.m?js$/.test(f));
55
+ if (!jsFile) return;
56
+ cssFile = jsFile.replace(/\.m?js$/, ".css");
57
+ }
58
+ }
59
+ this.emitFile({
60
+ type: "asset",
61
+ name: cssFile,
62
+ fileName: cssFile,
63
+ source: _styles
64
+ });
65
+ }
66
+ });
67
+ }
68
+ //#endregion
15
69
  export { createSassPlugin };
16
- //# sourceMappingURL=plugboy-sass-plugin.mjs.map
70
+
17
71
  //# sourceMappingURL=plugboy-sass-plugin.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/types.ts","../src/plugin.ts"],"names":[],"mappings":";;;;;;AAIO,IAAM,WAAA,GAAc,cAAA;;;ACApB,SAAS,iBAAiB,OAAA,EAAyB;AACxD,EAAA,OAAO,YAAA,CAAyB;AAAA,IAC9B,IAAA,EAAM,WAAA;AAAA,IACN,cAAA,EAAgB,CAAC,UAAA,CAAW,OAAO,CAA6B;AAAA,GACjE,CAAA;AACH","file":"plugboy-sass-plugin.mjs","sourcesContent":["import { Plugin } from '@fastkit/plugboy';\n\nexport interface PluginOptions {}\n\nexport const PLUGIN_NAME = 'plugboy-sass';\n\nexport interface SassPlugin extends Plugin {\n name: typeof PLUGIN_NAME;\n}\n","import { definePlugin, ESBuildPlugin } from '@fastkit/plugboy';\nimport { sassPlugin } from 'esbuild-sass-plugin';\nimport { PLUGIN_NAME, PluginOptions, SassPlugin } from './types';\n\nexport function createSassPlugin(options?: PluginOptions) {\n return definePlugin<SassPlugin>({\n name: PLUGIN_NAME,\n esbuildPlugins: [sassPlugin(options) as unknown as ESBuildPlugin],\n });\n}\n"]}
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\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 { definePlugin, type TryGetWorkspace } from '@fastkit/plugboy';\nimport sass from 'rollup-plugin-sass';\nimport { PLUGIN_NAME, PluginOptions, SassPlugin } from './types';\nimport { modulesPaths } from './utils';\n\nexport function createSassPlugin(options: PluginOptions = {}) {\n let _styles = '';\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 output(styles) {\n _styles = styles;\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 if (!_styles) return;\n\n let cssFile = outputOptions.file;\n\n if (!cssFile) {\n const workspace = _getWorkspace();\n\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":";;;;;AAaA,MAAa,cAAc;;;ACV3B,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,IAA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3.0.0-next.1",
4
4
  "description": "plugboy-sass-plugin",
5
5
  "keywords": [
6
6
  "plugboy",
@@ -16,7 +16,7 @@
16
16
  "exports": {
17
17
  "./package.json": "./package.json",
18
18
  ".": {
19
- "types": "./dist/plugboy-sass-plugin.d.ts",
19
+ "types": "./dist/plugboy-sass-plugin.d.mts",
20
20
  "import": {
21
21
  "default": "./dist/plugboy-sass-plugin.mjs"
22
22
  }
@@ -24,11 +24,11 @@
24
24
  "./*": "./dist/*"
25
25
  },
26
26
  "main": "./dist/plugboy-sass-plugin.mjs",
27
- "types": "./dist/plugboy-sass-plugin.d.ts",
27
+ "types": "./dist/plugboy-sass-plugin.d.mts",
28
28
  "typesVersions": {
29
29
  "*": {
30
30
  ".": [
31
- "./dist/plugboy-sass-plugin.d.ts"
31
+ "./dist/plugboy-sass-plugin.d.mts"
32
32
  ]
33
33
  }
34
34
  },
@@ -36,15 +36,14 @@
36
36
  "dist"
37
37
  ],
38
38
  "dependencies": {
39
- "esbuild-sass-plugin": "^3.3.1",
40
- "resolve": "^1.22.10",
41
- "sass": "^1.93.2"
39
+ "rollup-plugin-sass": "^1.15.3",
40
+ "sass": "^1.101.0"
42
41
  },
43
42
  "devDependencies": {
44
- "@fastkit/plugboy": "^0.3.0"
43
+ "@fastkit/plugboy": "^1.0.0-next.5"
45
44
  },
46
45
  "peerDependencies": {
47
- "@fastkit/plugboy": "^0.3.0"
46
+ "@fastkit/plugboy": "^1.0.0-next.5"
48
47
  },
49
48
  "scripts": {
50
49
  "build": "plugboy build",
@@ -1,12 +0,0 @@
1
- import { Plugin } from '@fastkit/plugboy';
2
-
3
- interface PluginOptions {
4
- }
5
- declare const PLUGIN_NAME = "plugboy-sass";
6
- interface SassPlugin extends Plugin {
7
- name: typeof PLUGIN_NAME;
8
- }
9
-
10
- declare function createSassPlugin(options?: PluginOptions): SassPlugin;
11
-
12
- export { createSassPlugin };