@fastkit/plugboy-sass-plugin 2.1.0 → 3.0.0-next.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.
@@ -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,74 @@
1
- import { definePlugin } from '@fastkit/plugboy';
2
- import { sassPlugin } from 'esbuild-sass-plugin';
1
+ import { definePlugin } from "@fastkit/plugboy";
2
+ import sass from "rollup-plugin-sass";
3
+ import { parse, resolve } from "path";
4
+ import { existsSync } from "fs";
3
5
 
4
- // src/types.ts
5
- var PLUGIN_NAME = "plugboy-sass";
6
+ //#region src/types.ts
7
+ const PLUGIN_NAME = "plugboy-sass";
6
8
 
7
- // src/plugin.ts
8
- function createSassPlugin(options) {
9
- return definePlugin({
10
- name: PLUGIN_NAME,
11
- esbuildPlugins: [sassPlugin(options)]
12
- });
9
+ //#endregion
10
+ //#region src/utils.ts
11
+ function modulesPaths(absWorkingDir) {
12
+ let path = absWorkingDir || process.cwd();
13
+ const { root } = parse(path);
14
+ const found = [];
15
+ while (path !== root) {
16
+ const filename = resolve(path, "node_modules");
17
+ if (existsSync(filename)) found.push(filename);
18
+ path = resolve(path, "..");
19
+ }
20
+ return [...found];
13
21
  }
14
22
 
23
+ //#endregion
24
+ //#region src/plugin.ts
25
+ function createSassPlugin(options = {}) {
26
+ let _styles = "";
27
+ const { sass: sassOptions, ...restOptions } = options;
28
+ const { name: _name, generateBundle, ...sassPluginSettings } = sass({
29
+ api: "modern",
30
+ ...restOptions,
31
+ options: {
32
+ ...sassOptions,
33
+ loadPaths: Array.from(new Set([...sassOptions?.loadPaths || modulesPaths()]))
34
+ },
35
+ output(styles) {
36
+ _styles = styles;
37
+ }
38
+ });
39
+ let _getWorkspace;
40
+ return definePlugin({
41
+ name: PLUGIN_NAME,
42
+ _options: options,
43
+ ...sassPluginSettings,
44
+ hooks: { setupWorkspace(_, getWorkspace) {
45
+ _getWorkspace = getWorkspace;
46
+ } },
47
+ async generateBundle(outputOptions, bundle, isWrite) {
48
+ if (typeof generateBundle === "function") await generateBundle.call(this, outputOptions, bundle, isWrite);
49
+ if (!_styles) return;
50
+ let cssFile = outputOptions.file;
51
+ if (!cssFile) {
52
+ const cssExport = _getWorkspace()?.exports.find((e) => e.id.endsWith(".css"));
53
+ if (cssExport) {
54
+ const tmp = cssExport.id.split("/");
55
+ cssFile = tmp[tmp.length - 1];
56
+ } else {
57
+ const jsFile = Object.keys(bundle).find((f) => /\.m?js$/.test(f));
58
+ if (!jsFile) return;
59
+ cssFile = jsFile.replace(/\.m?js$/, ".css");
60
+ }
61
+ }
62
+ this.emitFile({
63
+ type: "asset",
64
+ name: cssFile,
65
+ fileName: cssFile,
66
+ source: _styles
67
+ });
68
+ }
69
+ });
70
+ }
71
+
72
+ //#endregion
15
73
  export { createSassPlugin };
16
- //# sourceMappingURL=plugboy-sass-plugin.mjs.map
17
74
  //# sourceMappingURL=plugboy-sass-plugin.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/types.ts","../src/plugin.ts"],"names":[],"mappings":";;;;;;AAKO,IAAM,WAAA,GAAc,cAAA;;;ACDpB,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\n// eslint-disable-next-line @typescript-eslint/no-empty-interface\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\n extends Pick<RollupPluginSassOptions, 'include' | 'exclude'> {\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":";;;;;;AAWA,MAAa,cAAc;;;;ACR3B,SAAgB,aAAa,eAAkC;CAC7D,IAAI,OAAO,iBAAiB,QAAQ,KAAK;CACzC,MAAM,EAAE,SAAS,MAAM,KAAK;CAC5B,MAAM,QAAkB,EAAE;AAE1B,QAAO,SAAS,MAAM;EACpB,MAAM,WAAW,QAAQ,MAAM,eAAe;AAC9C,MAAI,WAAW,SAAS,CACtB,OAAM,KA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0-next.0",
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,21 +36,20 @@
36
36
  "dist"
37
37
  ],
38
38
  "dependencies": {
39
- "esbuild-sass-plugin": "^3.3.1",
40
- "resolve": "^1.22.10",
41
- "sass": "^1.93.1"
39
+ "rollup-plugin-sass": "^1.15.3",
40
+ "sass": "^1.97.2"
42
41
  },
43
42
  "devDependencies": {
44
- "@fastkit/plugboy": "^0.3.0"
43
+ "@fastkit/plugboy": "^1.0.0-next.0"
45
44
  },
46
45
  "peerDependencies": {
47
- "@fastkit/plugboy": "^0.3.0"
46
+ "@fastkit/plugboy": "^1.0.0-next.0"
48
47
  },
49
48
  "scripts": {
50
49
  "build": "plugboy build",
51
50
  "clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist",
52
- "eslint": "eslint . --ext ts,tsx,js,vue,html,yaml",
53
- "eslint:fix": "eslint . --ext ts,tsx,js,vue,html,yaml --fix",
51
+ "eslint": "eslint .",
52
+ "eslint:fix": "eslint . --fix",
54
53
  "format": "pnpm run eslint:fix",
55
54
  "lint": "pnpm run eslint",
56
55
  "test": "vitest run",
@@ -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 };