rollup-plugin-sass-bundle 1.1.2 → 1.2.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.
Files changed (3) hide show
  1. package/index.d.ts +53 -0
  2. package/index.js +26 -16
  3. package/package.json +12 -4
package/index.d.ts ADDED
@@ -0,0 +1,53 @@
1
+ /**
2
+ * @typedef {Object} SassPluginOptions
3
+ * @property {Parameters<CreateFilter>[0]} [include]
4
+ * @property {Parameters<CreateFilter>[1]} [exclude]
5
+ * @property {string[]} [loadPaths]
6
+ * @property {SassCompiler} [runtime]
7
+ * @property {boolean} [sourceMap]
8
+ * @property {SassOptions} [sassOptions]
9
+ * @property {BundleOptions} [bundleOptions]
10
+ */
11
+ /**
12
+ * @typedef {Object} BundleOptions
13
+ * @property {boolean} [enabled]
14
+ * @property {Parameters<CreateFilter>[0]} [include]
15
+ * @property {Parameters<CreateFilter>[1]} [exclude]
16
+ * @property {string} [name]
17
+ * @property {string} [fileName]
18
+ */
19
+ /** @typedef {({ bundle: { [id: string]: string } })} SassPluginState */
20
+ /** @typedef {typeof createFilter} CreateFilter */
21
+ /** @typedef {Pick<import('sass').Compiler, 'compileString'>} SassCompiler */
22
+ /** @typedef {import('sass').StringOptions<'sync'>} SassOptions */
23
+ /**
24
+ * @param {SassPluginOptions} options
25
+ * @returns {Promise<import('rollup').Plugin>}
26
+ */
27
+ export default function _default(options?: SassPluginOptions): Promise<import("rollup").Plugin>;
28
+ export type SassPluginOptions = {
29
+ include?: Parameters<CreateFilter>[0];
30
+ exclude?: Parameters<CreateFilter>[1];
31
+ loadPaths?: string[] | undefined;
32
+ runtime?: Pick<import("sass").Compiler, "compileString"> | undefined;
33
+ sourceMap?: boolean | undefined;
34
+ sassOptions?: import("sass").StringOptions<"sync"> | undefined;
35
+ bundleOptions?: BundleOptions | undefined;
36
+ };
37
+ export type BundleOptions = {
38
+ enabled?: boolean | undefined;
39
+ include?: Parameters<CreateFilter>[0];
40
+ exclude?: Parameters<CreateFilter>[1];
41
+ name?: string | undefined;
42
+ fileName?: string | undefined;
43
+ };
44
+ export type SassPluginState = ({
45
+ bundle: {
46
+ [id: string]: string;
47
+ };
48
+ });
49
+ export type CreateFilter = typeof createFilter;
50
+ export type SassCompiler = Pick<import("sass").Compiler, "compileString">;
51
+ export type SassOptions = import("sass").StringOptions<"sync">;
52
+ import { createFilter } from '@rollup/pluginutils';
53
+ //# sourceMappingURL=index.d.ts.map
package/index.js CHANGED
@@ -30,12 +30,12 @@ import { dirname } from 'node:path';
30
30
 
31
31
  /**
32
32
  * @param {SassPluginOptions} options
33
- * @returns {import('rollup').Plugin}
33
+ * @returns {Promise<import('rollup').Plugin>}
34
34
  */
35
- export default async function(options = {}) {
35
+ export default async function (options = {}) {
36
36
  /** @type {SassPluginState} */
37
37
  const state = {
38
- bundle: {}
38
+ bundle: {},
39
39
  };
40
40
 
41
41
  /** @type {SassCompiler} */
@@ -46,15 +46,21 @@ export default async function(options = {}) {
46
46
  const defaultInclude = ['**/*.scss', '**/*.sass'];
47
47
  const defaultBundleInclude = ['**/*.css', ...defaultInclude];
48
48
 
49
- const filter = createFilter(options.include || defaultInclude, options.exclude);
49
+ const filter = createFilter(
50
+ options.include || defaultInclude,
51
+ options.exclude,
52
+ );
50
53
  const bundleFilter = bundleOptions?.enabled
51
- ? createFilter(bundleOptions?.include || defaultBundleInclude, bundleOptions?.exclude)
54
+ ? createFilter(
55
+ bundleOptions?.include || defaultBundleInclude,
56
+ bundleOptions?.exclude,
57
+ )
52
58
  : undefined;
53
59
 
54
60
  /**
55
61
  * @param {string} code
56
62
  * @param {string} id
57
- * @returns
63
+ * @returns {import('rollup').TransformResult}
58
64
  */
59
65
  function bundleFile(code, id) {
60
66
  if (!bundleOptions?.enabled || !bundleFilter?.(id)) {
@@ -67,6 +73,7 @@ export default async function(options = {}) {
67
73
 
68
74
  return {
69
75
  name: 'sass',
76
+ /** @type {import('rollup').TransformHook} */
70
77
  transform(code, id) {
71
78
  if (!filter(id)) {
72
79
  return bundleFile(code, id);
@@ -78,14 +85,14 @@ export default async function(options = {}) {
78
85
  loadPaths: [...paths, ...(options.loadPaths || [])],
79
86
  style: 'compressed',
80
87
  sourceMap: options.sourceMap,
81
- ...(options.sassOptions || {})
88
+ ...(options.sassOptions || {}),
82
89
  });
83
90
 
84
91
  bundleFile(result.css, id);
85
92
 
86
93
  if (process.env.ROLLUP_WATCH) {
87
94
  for (const loadedUrl of result.loadedUrls) {
88
- this.addWatchFile(loadedUrl.filePath);
95
+ this.addWatchFile(loadedUrl.pathname);
89
96
  }
90
97
  }
91
98
 
@@ -93,11 +100,19 @@ export default async function(options = {}) {
93
100
  return '';
94
101
  }
95
102
 
103
+ /** @type {import('rollup').SourceMapInput|undefined} */
104
+ const sourceMap = result.sourceMap
105
+ ? {
106
+ ...result.sourceMap,
107
+ version: parseInt(result.sourceMap.version) || 3,
108
+ }
109
+ : undefined;
96
110
  return {
97
111
  code: result.css,
98
- map: result.sourceMap
112
+ map: sourceMap,
99
113
  };
100
114
  },
115
+ /** @type {import('rollup').FunctionPluginHooks['generateBundle']} */
101
116
  generateBundle(rollupOptions, bundle, isWrite) {
102
117
  if (!isWrite || !bundleOptions?.enabled) {
103
118
  return;
@@ -108,13 +123,8 @@ export default async function(options = {}) {
108
123
  type: 'asset',
109
124
  source: source,
110
125
  name: bundleOptions.name,
111
- fileName: bundleOptions.fileName
126
+ fileName: bundleOptions.fileName,
112
127
  });
113
-
114
- return {
115
- type: 'asset',
116
- source: source
117
- };
118
- }
128
+ },
119
129
  };
120
130
  }
package/package.json CHANGED
@@ -1,13 +1,15 @@
1
1
  {
2
2
  "name": "rollup-plugin-sass-bundle",
3
- "version": "1.1.2",
3
+ "version": "1.2.0",
4
4
  "description": "A simple rollup plugin for transpile sass and bundle and output a single file",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "main": "index.js",
8
+ "types": "index.d.ts",
8
9
  "exports": {
9
10
  ".": {
10
- "default": "./index.js"
11
+ "default": "./index.js",
12
+ "types": "./index.d.ts"
11
13
  }
12
14
  },
13
15
  "author": {
@@ -15,13 +17,19 @@
15
17
  "email": "traykovski5@gmail.com"
16
18
  },
17
19
  "files": [
18
- "index.js"
20
+ "index.js",
21
+ "index.d.ts"
19
22
  ],
23
+ "scripts": {
24
+ "generate-types": "npx -p typescript tsc -p ./tsconfig.json"
25
+ },
20
26
  "dependencies": {
21
27
  "@rollup/pluginutils": "^5.1.2"
22
28
  },
23
29
  "devDependencies": {
24
- "sass": "^1.79.4"
30
+ "@types/node": "^25.2.2",
31
+ "rollup": "^4.57.1",
32
+ "sass": "^1.97.3"
25
33
  },
26
34
  "peerDependencies": {
27
35
  "sass": ">= 1.45.0"