css-typed-vars 0.4.2 → 0.4.3

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,65 @@
1
+ import {
2
+ __dirname,
3
+ generateDeclaration,
4
+ generateJs,
5
+ scanVarNames
6
+ } from "./chunk-Y6U2ERL3.js";
7
+
8
+ // src/unplugin.ts
9
+ import { createUnplugin } from "unplugin";
10
+ import { writeFile } from "fs/promises";
11
+ import { join, resolve } from "path";
12
+ var VIRTUAL_ID = "css-typed-vars/vars";
13
+ var RESOLVED_ID = "\0css-typed-vars/vars";
14
+ function getDtsPath(options) {
15
+ if (options.dts === false) return null;
16
+ return options.dts ? resolve(process.cwd(), options.dts) : join(__dirname, "generated.d.ts");
17
+ }
18
+ var unplugin_default = createUnplugin((options) => {
19
+ let cachedNames = null;
20
+ return {
21
+ name: "css-typed-vars",
22
+ vite: {
23
+ enforce: "pre",
24
+ configureServer(server) {
25
+ const handle = async (file) => {
26
+ if (!/\.(css|scss|less)$/i.test(file)) return;
27
+ cachedNames = null;
28
+ const names = await scanVarNames(options.input, options.exclude, options.selectors);
29
+ const dtsPath = getDtsPath(options);
30
+ if (dtsPath) {
31
+ await writeFile(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
32
+ }
33
+ const mod = server.moduleGraph.getModuleById(RESOLVED_ID);
34
+ if (mod) {
35
+ server.moduleGraph.invalidateModule(mod);
36
+ server.ws.send({ type: "full-reload" });
37
+ }
38
+ };
39
+ server.watcher.on("change", handle);
40
+ server.watcher.on("add", handle);
41
+ server.watcher.on("unlink", handle);
42
+ }
43
+ },
44
+ async buildStart() {
45
+ cachedNames = scanVarNames(options.input, options.exclude, options.selectors);
46
+ const dtsPath = getDtsPath(options);
47
+ if (!dtsPath) return;
48
+ const names = await cachedNames;
49
+ await writeFile(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
50
+ },
51
+ resolveId(id) {
52
+ if (id === VIRTUAL_ID) return RESOLVED_ID;
53
+ },
54
+ async load(id) {
55
+ if (id === RESOLVED_ID) {
56
+ const names = await (cachedNames ?? scanVarNames(options.input, options.exclude, options.selectors));
57
+ return generateJs(names, options.prefix, options.naming);
58
+ }
59
+ }
60
+ };
61
+ });
62
+
63
+ export {
64
+ unplugin_default
65
+ };
package/dist/esbuild.cjs CHANGED
@@ -130,42 +130,50 @@ function getDtsPath(options) {
130
130
  if (options.dts === false) return null;
131
131
  return options.dts ? (0, import_node_path.resolve)(process.cwd(), options.dts) : (0, import_node_path.join)(__dirname, "generated.d.ts");
132
132
  }
133
- var unplugin_default = (0, import_unplugin.createUnplugin)((options) => ({
134
- name: "css-typed-vars",
135
- vite: {
136
- enforce: "pre",
137
- configureServer(server) {
138
- server.watcher.on("change", async (file) => {
139
- if (!/\.(css|scss|less)$/i.test(file)) return;
140
- const names = await scanVarNames(options.input, options.exclude, options.selectors);
141
- const dtsPath = getDtsPath(options);
142
- if (dtsPath) {
143
- await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
144
- }
145
- const mod = server.moduleGraph.getModuleById(RESOLVED_ID);
146
- if (mod) {
147
- server.moduleGraph.invalidateModule(mod);
148
- server.ws.send({ type: "full-reload" });
149
- }
150
- });
151
- }
152
- },
153
- async buildStart() {
154
- const dtsPath = getDtsPath(options);
155
- if (!dtsPath) return;
156
- const names = await scanVarNames(options.input, options.exclude, options.selectors);
157
- await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
158
- },
159
- resolveId(id) {
160
- if (id === VIRTUAL_ID) return RESOLVED_ID;
161
- },
162
- async load(id) {
163
- if (id === RESOLVED_ID) {
164
- const names = await scanVarNames(options.input, options.exclude, options.selectors);
165
- return generateJs(names, options.prefix, options.naming);
133
+ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => {
134
+ let cachedNames = null;
135
+ return {
136
+ name: "css-typed-vars",
137
+ vite: {
138
+ enforce: "pre",
139
+ configureServer(server) {
140
+ const handle = async (file) => {
141
+ if (!/\.(css|scss|less)$/i.test(file)) return;
142
+ cachedNames = null;
143
+ const names = await scanVarNames(options.input, options.exclude, options.selectors);
144
+ const dtsPath = getDtsPath(options);
145
+ if (dtsPath) {
146
+ await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
147
+ }
148
+ const mod = server.moduleGraph.getModuleById(RESOLVED_ID);
149
+ if (mod) {
150
+ server.moduleGraph.invalidateModule(mod);
151
+ server.ws.send({ type: "full-reload" });
152
+ }
153
+ };
154
+ server.watcher.on("change", handle);
155
+ server.watcher.on("add", handle);
156
+ server.watcher.on("unlink", handle);
157
+ }
158
+ },
159
+ async buildStart() {
160
+ cachedNames = scanVarNames(options.input, options.exclude, options.selectors);
161
+ const dtsPath = getDtsPath(options);
162
+ if (!dtsPath) return;
163
+ const names = await cachedNames;
164
+ await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
165
+ },
166
+ resolveId(id) {
167
+ if (id === VIRTUAL_ID) return RESOLVED_ID;
168
+ },
169
+ async load(id) {
170
+ if (id === RESOLVED_ID) {
171
+ const names = await (cachedNames ?? scanVarNames(options.input, options.exclude, options.selectors));
172
+ return generateJs(names, options.prefix, options.naming);
173
+ }
166
174
  }
167
- }
168
- }));
175
+ };
176
+ });
169
177
 
170
178
  // src/esbuild.ts
171
179
  var esbuild_default = unplugin_default.esbuild;
package/dist/esbuild.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  unplugin_default
3
- } from "./chunk-7PBWBCVY.js";
3
+ } from "./chunk-LYWWAGNR.js";
4
4
  import "./chunk-Y6U2ERL3.js";
5
5
 
6
6
  // src/esbuild.ts
package/dist/rollup.cjs CHANGED
@@ -130,42 +130,50 @@ function getDtsPath(options) {
130
130
  if (options.dts === false) return null;
131
131
  return options.dts ? (0, import_node_path.resolve)(process.cwd(), options.dts) : (0, import_node_path.join)(__dirname, "generated.d.ts");
132
132
  }
133
- var unplugin_default = (0, import_unplugin.createUnplugin)((options) => ({
134
- name: "css-typed-vars",
135
- vite: {
136
- enforce: "pre",
137
- configureServer(server) {
138
- server.watcher.on("change", async (file) => {
139
- if (!/\.(css|scss|less)$/i.test(file)) return;
140
- const names = await scanVarNames(options.input, options.exclude, options.selectors);
141
- const dtsPath = getDtsPath(options);
142
- if (dtsPath) {
143
- await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
144
- }
145
- const mod = server.moduleGraph.getModuleById(RESOLVED_ID);
146
- if (mod) {
147
- server.moduleGraph.invalidateModule(mod);
148
- server.ws.send({ type: "full-reload" });
149
- }
150
- });
151
- }
152
- },
153
- async buildStart() {
154
- const dtsPath = getDtsPath(options);
155
- if (!dtsPath) return;
156
- const names = await scanVarNames(options.input, options.exclude, options.selectors);
157
- await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
158
- },
159
- resolveId(id) {
160
- if (id === VIRTUAL_ID) return RESOLVED_ID;
161
- },
162
- async load(id) {
163
- if (id === RESOLVED_ID) {
164
- const names = await scanVarNames(options.input, options.exclude, options.selectors);
165
- return generateJs(names, options.prefix, options.naming);
133
+ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => {
134
+ let cachedNames = null;
135
+ return {
136
+ name: "css-typed-vars",
137
+ vite: {
138
+ enforce: "pre",
139
+ configureServer(server) {
140
+ const handle = async (file) => {
141
+ if (!/\.(css|scss|less)$/i.test(file)) return;
142
+ cachedNames = null;
143
+ const names = await scanVarNames(options.input, options.exclude, options.selectors);
144
+ const dtsPath = getDtsPath(options);
145
+ if (dtsPath) {
146
+ await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
147
+ }
148
+ const mod = server.moduleGraph.getModuleById(RESOLVED_ID);
149
+ if (mod) {
150
+ server.moduleGraph.invalidateModule(mod);
151
+ server.ws.send({ type: "full-reload" });
152
+ }
153
+ };
154
+ server.watcher.on("change", handle);
155
+ server.watcher.on("add", handle);
156
+ server.watcher.on("unlink", handle);
157
+ }
158
+ },
159
+ async buildStart() {
160
+ cachedNames = scanVarNames(options.input, options.exclude, options.selectors);
161
+ const dtsPath = getDtsPath(options);
162
+ if (!dtsPath) return;
163
+ const names = await cachedNames;
164
+ await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
165
+ },
166
+ resolveId(id) {
167
+ if (id === VIRTUAL_ID) return RESOLVED_ID;
168
+ },
169
+ async load(id) {
170
+ if (id === RESOLVED_ID) {
171
+ const names = await (cachedNames ?? scanVarNames(options.input, options.exclude, options.selectors));
172
+ return generateJs(names, options.prefix, options.naming);
173
+ }
166
174
  }
167
- }
168
- }));
175
+ };
176
+ });
169
177
 
170
178
  // src/rollup.ts
171
179
  var rollup_default = unplugin_default.rollup;
package/dist/rollup.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  unplugin_default
3
- } from "./chunk-7PBWBCVY.js";
3
+ } from "./chunk-LYWWAGNR.js";
4
4
  import "./chunk-Y6U2ERL3.js";
5
5
 
6
6
  // src/rollup.ts
package/dist/unplugin.cjs CHANGED
@@ -128,39 +128,47 @@ function getDtsPath(options) {
128
128
  if (options.dts === false) return null;
129
129
  return options.dts ? (0, import_node_path.resolve)(process.cwd(), options.dts) : (0, import_node_path.join)(__dirname, "generated.d.ts");
130
130
  }
131
- var unplugin_default = (0, import_unplugin.createUnplugin)((options) => ({
132
- name: "css-typed-vars",
133
- vite: {
134
- enforce: "pre",
135
- configureServer(server) {
136
- server.watcher.on("change", async (file) => {
137
- if (!/\.(css|scss|less)$/i.test(file)) return;
138
- const names = await scanVarNames(options.input, options.exclude, options.selectors);
139
- const dtsPath = getDtsPath(options);
140
- if (dtsPath) {
141
- await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
142
- }
143
- const mod = server.moduleGraph.getModuleById(RESOLVED_ID);
144
- if (mod) {
145
- server.moduleGraph.invalidateModule(mod);
146
- server.ws.send({ type: "full-reload" });
147
- }
148
- });
149
- }
150
- },
151
- async buildStart() {
152
- const dtsPath = getDtsPath(options);
153
- if (!dtsPath) return;
154
- const names = await scanVarNames(options.input, options.exclude, options.selectors);
155
- await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
156
- },
157
- resolveId(id) {
158
- if (id === VIRTUAL_ID) return RESOLVED_ID;
159
- },
160
- async load(id) {
161
- if (id === RESOLVED_ID) {
162
- const names = await scanVarNames(options.input, options.exclude, options.selectors);
163
- return generateJs(names, options.prefix, options.naming);
131
+ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => {
132
+ let cachedNames = null;
133
+ return {
134
+ name: "css-typed-vars",
135
+ vite: {
136
+ enforce: "pre",
137
+ configureServer(server) {
138
+ const handle = async (file) => {
139
+ if (!/\.(css|scss|less)$/i.test(file)) return;
140
+ cachedNames = null;
141
+ const names = await scanVarNames(options.input, options.exclude, options.selectors);
142
+ const dtsPath = getDtsPath(options);
143
+ if (dtsPath) {
144
+ await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
145
+ }
146
+ const mod = server.moduleGraph.getModuleById(RESOLVED_ID);
147
+ if (mod) {
148
+ server.moduleGraph.invalidateModule(mod);
149
+ server.ws.send({ type: "full-reload" });
150
+ }
151
+ };
152
+ server.watcher.on("change", handle);
153
+ server.watcher.on("add", handle);
154
+ server.watcher.on("unlink", handle);
155
+ }
156
+ },
157
+ async buildStart() {
158
+ cachedNames = scanVarNames(options.input, options.exclude, options.selectors);
159
+ const dtsPath = getDtsPath(options);
160
+ if (!dtsPath) return;
161
+ const names = await cachedNames;
162
+ await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
163
+ },
164
+ resolveId(id) {
165
+ if (id === VIRTUAL_ID) return RESOLVED_ID;
166
+ },
167
+ async load(id) {
168
+ if (id === RESOLVED_ID) {
169
+ const names = await (cachedNames ?? scanVarNames(options.input, options.exclude, options.selectors));
170
+ return generateJs(names, options.prefix, options.naming);
171
+ }
164
172
  }
165
- }
166
- }));
173
+ };
174
+ });
package/dist/unplugin.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  unplugin_default
3
- } from "./chunk-7PBWBCVY.js";
3
+ } from "./chunk-LYWWAGNR.js";
4
4
  import "./chunk-Y6U2ERL3.js";
5
5
  export {
6
6
  unplugin_default as default
package/dist/vite.cjs CHANGED
@@ -130,42 +130,50 @@ function getDtsPath(options) {
130
130
  if (options.dts === false) return null;
131
131
  return options.dts ? (0, import_node_path.resolve)(process.cwd(), options.dts) : (0, import_node_path.join)(__dirname, "generated.d.ts");
132
132
  }
133
- var unplugin_default = (0, import_unplugin.createUnplugin)((options) => ({
134
- name: "css-typed-vars",
135
- vite: {
136
- enforce: "pre",
137
- configureServer(server) {
138
- server.watcher.on("change", async (file) => {
139
- if (!/\.(css|scss|less)$/i.test(file)) return;
140
- const names = await scanVarNames(options.input, options.exclude, options.selectors);
141
- const dtsPath = getDtsPath(options);
142
- if (dtsPath) {
143
- await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
144
- }
145
- const mod = server.moduleGraph.getModuleById(RESOLVED_ID);
146
- if (mod) {
147
- server.moduleGraph.invalidateModule(mod);
148
- server.ws.send({ type: "full-reload" });
149
- }
150
- });
151
- }
152
- },
153
- async buildStart() {
154
- const dtsPath = getDtsPath(options);
155
- if (!dtsPath) return;
156
- const names = await scanVarNames(options.input, options.exclude, options.selectors);
157
- await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
158
- },
159
- resolveId(id) {
160
- if (id === VIRTUAL_ID) return RESOLVED_ID;
161
- },
162
- async load(id) {
163
- if (id === RESOLVED_ID) {
164
- const names = await scanVarNames(options.input, options.exclude, options.selectors);
165
- return generateJs(names, options.prefix, options.naming);
133
+ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => {
134
+ let cachedNames = null;
135
+ return {
136
+ name: "css-typed-vars",
137
+ vite: {
138
+ enforce: "pre",
139
+ configureServer(server) {
140
+ const handle = async (file) => {
141
+ if (!/\.(css|scss|less)$/i.test(file)) return;
142
+ cachedNames = null;
143
+ const names = await scanVarNames(options.input, options.exclude, options.selectors);
144
+ const dtsPath = getDtsPath(options);
145
+ if (dtsPath) {
146
+ await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
147
+ }
148
+ const mod = server.moduleGraph.getModuleById(RESOLVED_ID);
149
+ if (mod) {
150
+ server.moduleGraph.invalidateModule(mod);
151
+ server.ws.send({ type: "full-reload" });
152
+ }
153
+ };
154
+ server.watcher.on("change", handle);
155
+ server.watcher.on("add", handle);
156
+ server.watcher.on("unlink", handle);
157
+ }
158
+ },
159
+ async buildStart() {
160
+ cachedNames = scanVarNames(options.input, options.exclude, options.selectors);
161
+ const dtsPath = getDtsPath(options);
162
+ if (!dtsPath) return;
163
+ const names = await cachedNames;
164
+ await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
165
+ },
166
+ resolveId(id) {
167
+ if (id === VIRTUAL_ID) return RESOLVED_ID;
168
+ },
169
+ async load(id) {
170
+ if (id === RESOLVED_ID) {
171
+ const names = await (cachedNames ?? scanVarNames(options.input, options.exclude, options.selectors));
172
+ return generateJs(names, options.prefix, options.naming);
173
+ }
166
174
  }
167
- }
168
- }));
175
+ };
176
+ });
169
177
 
170
178
  // src/vite.ts
171
179
  var vite_default = unplugin_default.vite;
package/dist/vite.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  unplugin_default
3
- } from "./chunk-7PBWBCVY.js";
3
+ } from "./chunk-LYWWAGNR.js";
4
4
  import "./chunk-Y6U2ERL3.js";
5
5
 
6
6
  // src/vite.ts
package/dist/webpack.cjs CHANGED
@@ -130,42 +130,50 @@ function getDtsPath(options) {
130
130
  if (options.dts === false) return null;
131
131
  return options.dts ? (0, import_node_path.resolve)(process.cwd(), options.dts) : (0, import_node_path.join)(__dirname, "generated.d.ts");
132
132
  }
133
- var unplugin_default = (0, import_unplugin.createUnplugin)((options) => ({
134
- name: "css-typed-vars",
135
- vite: {
136
- enforce: "pre",
137
- configureServer(server) {
138
- server.watcher.on("change", async (file) => {
139
- if (!/\.(css|scss|less)$/i.test(file)) return;
140
- const names = await scanVarNames(options.input, options.exclude, options.selectors);
141
- const dtsPath = getDtsPath(options);
142
- if (dtsPath) {
143
- await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
144
- }
145
- const mod = server.moduleGraph.getModuleById(RESOLVED_ID);
146
- if (mod) {
147
- server.moduleGraph.invalidateModule(mod);
148
- server.ws.send({ type: "full-reload" });
149
- }
150
- });
151
- }
152
- },
153
- async buildStart() {
154
- const dtsPath = getDtsPath(options);
155
- if (!dtsPath) return;
156
- const names = await scanVarNames(options.input, options.exclude, options.selectors);
157
- await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
158
- },
159
- resolveId(id) {
160
- if (id === VIRTUAL_ID) return RESOLVED_ID;
161
- },
162
- async load(id) {
163
- if (id === RESOLVED_ID) {
164
- const names = await scanVarNames(options.input, options.exclude, options.selectors);
165
- return generateJs(names, options.prefix, options.naming);
133
+ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => {
134
+ let cachedNames = null;
135
+ return {
136
+ name: "css-typed-vars",
137
+ vite: {
138
+ enforce: "pre",
139
+ configureServer(server) {
140
+ const handle = async (file) => {
141
+ if (!/\.(css|scss|less)$/i.test(file)) return;
142
+ cachedNames = null;
143
+ const names = await scanVarNames(options.input, options.exclude, options.selectors);
144
+ const dtsPath = getDtsPath(options);
145
+ if (dtsPath) {
146
+ await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
147
+ }
148
+ const mod = server.moduleGraph.getModuleById(RESOLVED_ID);
149
+ if (mod) {
150
+ server.moduleGraph.invalidateModule(mod);
151
+ server.ws.send({ type: "full-reload" });
152
+ }
153
+ };
154
+ server.watcher.on("change", handle);
155
+ server.watcher.on("add", handle);
156
+ server.watcher.on("unlink", handle);
157
+ }
158
+ },
159
+ async buildStart() {
160
+ cachedNames = scanVarNames(options.input, options.exclude, options.selectors);
161
+ const dtsPath = getDtsPath(options);
162
+ if (!dtsPath) return;
163
+ const names = await cachedNames;
164
+ await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
165
+ },
166
+ resolveId(id) {
167
+ if (id === VIRTUAL_ID) return RESOLVED_ID;
168
+ },
169
+ async load(id) {
170
+ if (id === RESOLVED_ID) {
171
+ const names = await (cachedNames ?? scanVarNames(options.input, options.exclude, options.selectors));
172
+ return generateJs(names, options.prefix, options.naming);
173
+ }
166
174
  }
167
- }
168
- }));
175
+ };
176
+ });
169
177
 
170
178
  // src/webpack.ts
171
179
  var webpack_default = unplugin_default.webpack;
package/dist/webpack.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  unplugin_default
3
- } from "./chunk-7PBWBCVY.js";
3
+ } from "./chunk-LYWWAGNR.js";
4
4
  import "./chunk-Y6U2ERL3.js";
5
5
 
6
6
  // src/webpack.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "css-typed-vars",
3
- "version": "0.4.2",
3
+ "version": "0.4.3",
4
4
  "description": "Generate TypeScript typed constants from CSS custom properties",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -1,57 +0,0 @@
1
- import {
2
- __dirname,
3
- generateDeclaration,
4
- generateJs,
5
- scanVarNames
6
- } from "./chunk-Y6U2ERL3.js";
7
-
8
- // src/unplugin.ts
9
- import { createUnplugin } from "unplugin";
10
- import { writeFile } from "fs/promises";
11
- import { join, resolve } from "path";
12
- var VIRTUAL_ID = "css-typed-vars/vars";
13
- var RESOLVED_ID = "\0css-typed-vars/vars";
14
- function getDtsPath(options) {
15
- if (options.dts === false) return null;
16
- return options.dts ? resolve(process.cwd(), options.dts) : join(__dirname, "generated.d.ts");
17
- }
18
- var unplugin_default = createUnplugin((options) => ({
19
- name: "css-typed-vars",
20
- vite: {
21
- enforce: "pre",
22
- configureServer(server) {
23
- server.watcher.on("change", async (file) => {
24
- if (!/\.(css|scss|less)$/i.test(file)) return;
25
- const names = await scanVarNames(options.input, options.exclude, options.selectors);
26
- const dtsPath = getDtsPath(options);
27
- if (dtsPath) {
28
- await writeFile(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
29
- }
30
- const mod = server.moduleGraph.getModuleById(RESOLVED_ID);
31
- if (mod) {
32
- server.moduleGraph.invalidateModule(mod);
33
- server.ws.send({ type: "full-reload" });
34
- }
35
- });
36
- }
37
- },
38
- async buildStart() {
39
- const dtsPath = getDtsPath(options);
40
- if (!dtsPath) return;
41
- const names = await scanVarNames(options.input, options.exclude, options.selectors);
42
- await writeFile(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
43
- },
44
- resolveId(id) {
45
- if (id === VIRTUAL_ID) return RESOLVED_ID;
46
- },
47
- async load(id) {
48
- if (id === RESOLVED_ID) {
49
- const names = await scanVarNames(options.input, options.exclude, options.selectors);
50
- return generateJs(names, options.prefix, options.naming);
51
- }
52
- }
53
- }));
54
-
55
- export {
56
- unplugin_default
57
- };