@lass-lang/bun-plugin-lass 0.0.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.
package/CHANGELOG.md ADDED
@@ -0,0 +1,14 @@
1
+ # @lass-lang/bun-plugin-lass
2
+
3
+ ## 0.0.1
4
+
5
+ Initial release.
6
+
7
+ ### Features
8
+
9
+ - Process `.lass` files in Bun's bundler
10
+ - CSS Modules support (`.module.lass`)
11
+ - Preamble expression interpolation
12
+ - JSON/JS imports in preamble
13
+ - Preload support for bunfig.toml
14
+ - Verbose logging option
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Long-lazuli
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,89 @@
1
+ # @lass-lang/bun-plugin-lass
2
+
3
+ Bun plugin for processing `.lass` files. Transforms Lass source to CSS via `@lass-lang/core`.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ bun add @lass-lang/bun-plugin-lass --dev
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ### With Bun.build()
14
+
15
+ ```typescript
16
+ import lass from "@lass-lang/bun-plugin-lass";
17
+
18
+ await Bun.build({
19
+ entrypoints: ["./src/index.ts"],
20
+ outdir: "./dist",
21
+ plugins: [lass()],
22
+ });
23
+ ```
24
+
25
+ ### With bunfig.toml (preload)
26
+
27
+ For automatic `.lass` support without explicit plugin configuration:
28
+
29
+ ```toml
30
+ # bunfig.toml
31
+ preload = ["@lass-lang/bun-plugin-lass/preload"]
32
+ ```
33
+
34
+ Then import `.lass` files directly:
35
+
36
+ ```typescript
37
+ import "./styles.lass";
38
+ ```
39
+
40
+ ## CSS Modules
41
+
42
+ CSS Modules work with `.module.lass` files:
43
+
44
+ ```typescript
45
+ import styles from "./component.module.lass";
46
+
47
+ element.className = styles.container;
48
+ ```
49
+
50
+ For TypeScript, add declarations:
51
+
52
+ ```typescript
53
+ // lass.d.ts
54
+ declare module "*.lass";
55
+
56
+ declare module "*.module.lass" {
57
+ const classes: { readonly [key: string]: string };
58
+ export default classes;
59
+ }
60
+ ```
61
+
62
+ ## Options
63
+
64
+ ```typescript
65
+ lass({
66
+ verbose: true, // Enable logging (default: false)
67
+ });
68
+ ```
69
+
70
+ ## Limitations
71
+
72
+ - **No HMR**: Bun's plugin API doesn't support Hot Module Replacement.
73
+ For development with HMR, use Vite with `@lass-lang/vite-plugin-lass`.
74
+
75
+ ## How It Works
76
+
77
+ 1. Plugin intercepts `.lass` file imports via `onResolve`/`onLoad`
78
+ 2. Transpiles Lass source to JS module via `@lass-lang/core`
79
+ 3. Executes JS to extract CSS string
80
+ 4. Returns CSS to Bun's bundler with `loader: "css"`
81
+ 5. For `.module.lass`: resolves to virtual `.lass.module.css` path so Bun applies CSS Modules scoping
82
+
83
+ ## Peer Dependencies
84
+
85
+ - `bun` >=1.0.0
86
+
87
+ ## License
88
+
89
+ MIT
@@ -0,0 +1,60 @@
1
+ /**
2
+ * @lass-lang/bun-plugin-lass
3
+ *
4
+ * Bun plugin for processing .lass files.
5
+ * Transforms Lass source to CSS via @lass-lang/core.
6
+ *
7
+ * Features:
8
+ * - Regular .lass files -> CSS
9
+ * - CSS Modules (.module.lass) -> Scoped CSS
10
+ * - Preamble expressions -> Interpolated values
11
+ * - JSON/JS imports in preamble
12
+ *
13
+ * Limitations:
14
+ * - No HMR (Bun's plugin API doesn't support it)
15
+ *
16
+ * @module @lass-lang/bun-plugin-lass
17
+ */
18
+ import type { BunPlugin } from 'bun';
19
+ import type { LassPluginOptions } from './lib/types.js';
20
+ export type { LassPluginOptions } from './lib/types.js';
21
+ /**
22
+ * Creates a Bun plugin for processing .lass files.
23
+ *
24
+ * @param options - Plugin configuration options
25
+ * @returns Bun plugin
26
+ *
27
+ * @example
28
+ * ```typescript
29
+ * import lass from "@lass-lang/bun-plugin-lass";
30
+ *
31
+ * await Bun.build({
32
+ * entrypoints: ["./src/index.ts"],
33
+ * outdir: "./dist",
34
+ * plugins: [lass()],
35
+ * });
36
+ * ```
37
+ */
38
+ export declare function lass(options?: LassPluginOptions): BunPlugin;
39
+ /**
40
+ * Register the plugin globally for runtime usage.
41
+ *
42
+ * Use this in bunfig.toml preload for automatic .lass support:
43
+ *
44
+ * @example
45
+ * ```toml
46
+ * # bunfig.toml
47
+ * preload = ["@lass-lang/bun-plugin-lass/preload"]
48
+ * ```
49
+ *
50
+ * Or call programmatically:
51
+ *
52
+ * @example
53
+ * ```typescript
54
+ * import { register } from "@lass-lang/bun-plugin-lass";
55
+ * register({ verbose: true });
56
+ * ```
57
+ */
58
+ export declare function register(options?: LassPluginOptions): void;
59
+ export default lass;
60
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,KAAK,CAAC;AAUrC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAExD,YAAY,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAuBxD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,IAAI,CAAC,OAAO,GAAE,iBAAsB,GAAG,SAAS,CAqF/D;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,QAAQ,CAAC,OAAO,GAAE,iBAAsB,GAAG,IAAI,CAE9D;AAED,eAAe,IAAI,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,154 @@
1
+ /**
2
+ * @lass-lang/bun-plugin-lass
3
+ *
4
+ * Bun plugin for processing .lass files.
5
+ * Transforms Lass source to CSS via @lass-lang/core.
6
+ *
7
+ * Features:
8
+ * - Regular .lass files -> CSS
9
+ * - CSS Modules (.module.lass) -> Scoped CSS
10
+ * - Preamble expressions -> Interpolated values
11
+ * - JSON/JS imports in preamble
12
+ *
13
+ * Limitations:
14
+ * - No HMR (Bun's plugin API doesn't support it)
15
+ *
16
+ * @module @lass-lang/bun-plugin-lass
17
+ */
18
+ import { plugin } from 'bun';
19
+ import { dirname, resolve, isAbsolute } from 'node:path';
20
+ import { transpile } from '@lass-lang/core';
21
+ import { rewriteImportsForExecution, injectStyle, toVirtualCssPath, fromVirtualCssPath, } from './lib/plugin-utils.js';
22
+ /** Regex to match .lass file extensions */
23
+ const LASS_FILE_RE = /\.lass$/;
24
+ /** Regex to match .module.lass file extensions */
25
+ const LASS_MODULE_RE = /\.module\.lass$/;
26
+ /** Namespace for CSS Modules virtual paths */
27
+ const LASS_MODULE_NS = 'lass-module';
28
+ /**
29
+ * Resolve a path relative to an importer without triggering Bun.resolveSync
30
+ * (which would cause infinite recursion in onResolve).
31
+ */
32
+ function resolvePath(specifier, importer) {
33
+ if (isAbsolute(specifier)) {
34
+ return specifier;
35
+ }
36
+ const base = importer ? dirname(importer) : process.cwd();
37
+ return resolve(base, specifier);
38
+ }
39
+ /**
40
+ * Creates a Bun plugin for processing .lass files.
41
+ *
42
+ * @param options - Plugin configuration options
43
+ * @returns Bun plugin
44
+ *
45
+ * @example
46
+ * ```typescript
47
+ * import lass from "@lass-lang/bun-plugin-lass";
48
+ *
49
+ * await Bun.build({
50
+ * entrypoints: ["./src/index.ts"],
51
+ * outdir: "./dist",
52
+ * plugins: [lass()],
53
+ * });
54
+ * ```
55
+ */
56
+ export function lass(options = {}) {
57
+ const { verbose = false } = options;
58
+ return {
59
+ name: 'bun-plugin-lass',
60
+ setup(build) {
61
+ // ========================================================================
62
+ // CSS Modules: Resolve .module.lass to virtual .lass.module.css path
63
+ // ========================================================================
64
+ build.onResolve({ filter: LASS_MODULE_RE }, ({ path, importer }) => {
65
+ // Resolve the actual file path using simple path resolution
66
+ // (avoid Bun.resolveSync which would trigger this hook again)
67
+ const resolved = resolvePath(path, importer);
68
+ // Convert to virtual CSS Modules path using shared convention
69
+ const virtualPath = toVirtualCssPath(resolved);
70
+ if (verbose) {
71
+ console.log(`[lass] resolve module: ${path} -> ${virtualPath}`);
72
+ }
73
+ return {
74
+ path: virtualPath,
75
+ namespace: LASS_MODULE_NS,
76
+ };
77
+ });
78
+ // ========================================================================
79
+ // CSS Modules: Load virtual .lass.module.css from actual .module.lass
80
+ // ========================================================================
81
+ build.onLoad({ filter: /.*/, namespace: LASS_MODULE_NS }, async ({ path }) => {
82
+ // Convert virtual path back to actual .lass file
83
+ const actualPath = fromVirtualCssPath(path);
84
+ if (verbose) {
85
+ console.log(`[lass] loading module: ${actualPath}`);
86
+ }
87
+ try {
88
+ const source = await Bun.file(actualPath).text();
89
+ const { code: transpiled } = transpile(source, { filename: actualPath });
90
+ const executableCode = rewriteImportsForExecution(transpiled, dirname(actualPath));
91
+ const css = await injectStyle(executableCode);
92
+ return {
93
+ contents: css,
94
+ loader: 'css',
95
+ };
96
+ }
97
+ catch (error) {
98
+ const message = error instanceof Error ? error.message : String(error);
99
+ throw new Error(`[bun-plugin-lass] Failed to load CSS module ${actualPath}: ${message}`);
100
+ }
101
+ });
102
+ // ========================================================================
103
+ // Regular .lass files: Direct load and transform
104
+ // ========================================================================
105
+ build.onLoad({ filter: LASS_FILE_RE }, async ({ path }) => {
106
+ // Skip .module.lass - handled by namespace above
107
+ if (LASS_MODULE_RE.test(path)) {
108
+ return undefined;
109
+ }
110
+ if (verbose) {
111
+ console.log(`[lass] loading: ${path}`);
112
+ }
113
+ try {
114
+ const source = await Bun.file(path).text();
115
+ const { code: transpiled } = transpile(source, { filename: path });
116
+ const executableCode = rewriteImportsForExecution(transpiled, dirname(path));
117
+ const css = await injectStyle(executableCode);
118
+ return {
119
+ contents: css,
120
+ loader: 'css',
121
+ };
122
+ }
123
+ catch (error) {
124
+ const message = error instanceof Error ? error.message : String(error);
125
+ throw new Error(`[bun-plugin-lass] Failed to load ${path}: ${message}`);
126
+ }
127
+ });
128
+ },
129
+ };
130
+ }
131
+ /**
132
+ * Register the plugin globally for runtime usage.
133
+ *
134
+ * Use this in bunfig.toml preload for automatic .lass support:
135
+ *
136
+ * @example
137
+ * ```toml
138
+ * # bunfig.toml
139
+ * preload = ["@lass-lang/bun-plugin-lass/preload"]
140
+ * ```
141
+ *
142
+ * Or call programmatically:
143
+ *
144
+ * @example
145
+ * ```typescript
146
+ * import { register } from "@lass-lang/bun-plugin-lass";
147
+ * register({ verbose: true });
148
+ * ```
149
+ */
150
+ export function register(options = {}) {
151
+ plugin(lass(options));
152
+ }
153
+ export default lass;
154
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAGH,OAAO,EAAE,MAAM,EAAE,MAAM,KAAK,CAAC;AAC7B,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAi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CAAC,OAAO,CAAC,CAAC,CAAC;AACxB,CAAC;AAED,eAAe,IAAI,CAAC"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Plugin utilities for bun-plugin-lass
3
+ *
4
+ * Re-exports shared utilities from @lass-lang/plugin-utils
5
+ * and provides Bun-specific CSS injection.
6
+ */
7
+ export { LASS_EXT, VIRTUAL_CSS_EXT, VIRTUAL_MODULE_CSS_EXT, IMPORT_STATEMENT_RE, toVirtualCssPath, fromVirtualCssPath, isVirtualCssPath, isVirtualModuleCssPath, normalizePath, rewriteImportsForExecution, } from '@lass-lang/plugin-utils';
8
+ /**
9
+ * Execute transpiled Lass JS module and extract the CSS string.
10
+ *
11
+ * Uses a temp file + dynamic import to avoid Bun's "NameTooLong" error
12
+ * with data: URLs. The temp file is cleaned up after execution.
13
+ *
14
+ * Uses indirect Function() to prevent Bun's bundler from statically
15
+ * analyzing the import() call.
16
+ *
17
+ * @param jsCode - Transpiled JS module code
18
+ * @returns The CSS string from the module's default export
19
+ */
20
+ export declare function injectStyle(jsCode: string): Promise<string>;
21
+ //# sourceMappingURL=plugin-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin-utils.d.ts","sourceRoot":"","sources":["../../src/lib/plugin-utils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAQH,OAAO,EACL,QAAQ,EACR,eAAe,EACf,sBAAsB,EACtB,mBAAmB,EACnB,gBAAgB,EAChB,kBAAkB,EAClB,gBAAgB,EAChB,sBAAsB,EACtB,aAAa,EACb,0BAA0B,GAC3B,MAAM,yBAAyB,CAAC;AAMjC;;;;;;;;;;;GAWG;AACH,wBAAsB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAwBjE"}
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Plugin utilities for bun-plugin-lass
3
+ *
4
+ * Re-exports shared utilities from @lass-lang/plugin-utils
5
+ * and provides Bun-specific CSS injection.
6
+ */
7
+ import { join } from 'node:path';
8
+ import { pathToFileURL } from 'node:url';
9
+ import { writeFile, unlink } from 'node:fs/promises';
10
+ import { tmpdir } from 'node:os';
11
+ // Re-export all shared utilities
12
+ export { LASS_EXT, VIRTUAL_CSS_EXT, VIRTUAL_MODULE_CSS_EXT, IMPORT_STATEMENT_RE, toVirtualCssPath, fromVirtualCssPath, isVirtualCssPath, isVirtualModuleCssPath, normalizePath, rewriteImportsForExecution, } from '@lass-lang/plugin-utils';
13
+ // ============================================================================
14
+ // CSS INJECTION (Bun-specific)
15
+ // ============================================================================
16
+ /**
17
+ * Execute transpiled Lass JS module and extract the CSS string.
18
+ *
19
+ * Uses a temp file + dynamic import to avoid Bun's "NameTooLong" error
20
+ * with data: URLs. The temp file is cleaned up after execution.
21
+ *
22
+ * Uses indirect Function() to prevent Bun's bundler from statically
23
+ * analyzing the import() call.
24
+ *
25
+ * @param jsCode - Transpiled JS module code
26
+ * @returns The CSS string from the module's default export
27
+ */
28
+ export async function injectStyle(jsCode) {
29
+ // Generate unique temp file path
30
+ const tempPath = join(tmpdir(), `lass-${Date.now()}-${Math.random().toString(36).slice(2)}.mjs`);
31
+ try {
32
+ await writeFile(tempPath, jsCode, 'utf-8');
33
+ const fileUrl = pathToFileURL(tempPath).href;
34
+ // Use indirect Function to prevent Bun's bundler from static analysis
35
+ // eslint-disable-next-line @typescript-eslint/no-implied-eval
36
+ const dynamicImport = new Function('url', 'return import(url)');
37
+ const module = await dynamicImport(fileUrl);
38
+ return module.default;
39
+ }
40
+ finally {
41
+ // Clean up temp file
42
+ try {
43
+ await unlink(tempPath);
44
+ }
45
+ catch {
46
+ // Ignore cleanup errors
47
+ }
48
+ }
49
+ }
50
+ //# sourceMappingURL=plugin-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin-utils.js","sourceRoot":"","sources":["../../src/lib/plugin-utils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;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@@
1
+ /**
2
+ * Type definitions for bun-plugin-lass
3
+ */
4
+ export interface LassPluginOptions {
5
+ /** Enable verbose logging */
6
+ verbose?: boolean;
7
+ }
8
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/lib/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,WAAW,iBAAiB;IAChC,6BAA6B;IAC7B,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Type definitions for bun-plugin-lass
3
+ */
4
+ export {};
5
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/lib/types.ts"],"names":[],"mappings":"AAAA;;GAEG"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Preload script for automatic .lass file support.
3
+ *
4
+ * Usage in bunfig.toml:
5
+ *
6
+ * @example
7
+ * ```toml
8
+ * preload = ["@lass-lang/bun-plugin-lass/preload"]
9
+ * ```
10
+ *
11
+ * This registers the Lass plugin globally, enabling .lass imports
12
+ * without explicit Bun.build() configuration.
13
+ */
14
+ export {};
15
+ //# sourceMappingURL=preload.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"preload.d.ts","sourceRoot":"","sources":["../src/preload.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Preload script for automatic .lass file support.
3
+ *
4
+ * Usage in bunfig.toml:
5
+ *
6
+ * @example
7
+ * ```toml
8
+ * preload = ["@lass-lang/bun-plugin-lass/preload"]
9
+ * ```
10
+ *
11
+ * This registers the Lass plugin globally, enabling .lass imports
12
+ * without explicit Bun.build() configuration.
13
+ */
14
+ import { register } from './index.js';
15
+ register();
16
+ //# sourceMappingURL=preload.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"preload.js","sourceRoot":"","sources":["../src/preload.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC,QAAQ,EAAE,CAAC"}
package/package.json ADDED
@@ -0,0 +1,65 @@
1
+ {
2
+ "name": "@lass-lang/bun-plugin-lass",
3
+ "version": "0.0.1",
4
+ "description": "Bun plugin for Lass language",
5
+ "author": "Long-lazuli",
6
+ "type": "module",
7
+ "main": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js"
13
+ },
14
+ "./preload": {
15
+ "types": "./dist/preload.d.ts",
16
+ "import": "./dist/preload.js"
17
+ }
18
+ },
19
+ "files": [
20
+ "dist",
21
+ "CHANGELOG.md"
22
+ ],
23
+ "scripts": {
24
+ "build": "tsc",
25
+ "clean": "rm -rf dist",
26
+ "test": "bun test",
27
+ "test:coverage": "bun test --coverage --coverage-reporter=lcov --coverage-dir=coverage",
28
+ "changeset": "changeset",
29
+ "version": "changeset version",
30
+ "release": "bun run build && changeset publish"
31
+ },
32
+ "dependencies": {
33
+ "@lass-lang/core": "^0.0.1",
34
+ "@lass-lang/plugin-utils": "^0.0.1"
35
+ },
36
+ "peerDependencies": {
37
+ "bun": ">=1.0.0"
38
+ },
39
+ "devDependencies": {
40
+ "@changesets/cli": "^2.29.8",
41
+ "@types/bun": "latest",
42
+ "typescript": "^5.7.0"
43
+ },
44
+ "keywords": [
45
+ "lass",
46
+ "bun",
47
+ "bun-plugin",
48
+ "css",
49
+ "preprocessor",
50
+ "styling",
51
+ "css-modules"
52
+ ],
53
+ "engines": {
54
+ "bun": ">=1.0.0"
55
+ },
56
+ "license": "MIT",
57
+ "repository": {
58
+ "type": "git",
59
+ "url": "https://github.com/lass-lang/bun-plugin-lass.git"
60
+ },
61
+ "bugs": {
62
+ "url": "https://github.com/lass-lang/bun-plugin-lass/issues"
63
+ },
64
+ "homepage": "https://github.com/lass-lang/bun-plugin-lass#readme"
65
+ }