@@ -24,6 +24,7 @@ import { getConfig } from './load-twind-config'
24
24
import { getColor } from './colors'
25
25
26
26
import type { ConfigurationManager } from './configuration'
27
+ import { watch } from './watch'
27
28
28
29
const isCSSProperty = ( key : string , value : CSSRuleValue ) : boolean =>
29
30
! '@:&' . includes ( key [ 0 ] ) && ( 'rg' . includes ( ( typeof value ) [ 5 ] ) || Array . isArray ( value ) )
@@ -194,10 +195,8 @@ export interface Completions {
194
195
export class Twind {
195
196
private readonly typescript : typeof TS
196
197
private readonly info : ts . server . PluginCreateInfo
197
- private readonly configurationManager : ConfigurationManager
198
198
private readonly logger : Logger
199
199
private _completions : Completions | undefined
200
- private _configFile : string | undefined
201
200
private _state :
202
201
| {
203
202
program : TS . Program
@@ -217,8 +216,14 @@ export class Twind {
217
216
) {
218
217
this . typescript = typescript
219
218
this . info = info
220
- this . configurationManager = configurationManager
221
219
this . logger = logger
220
+
221
+ configurationManager . onUpdatedConfig ( ( ) => this . _reset ( ) )
222
+ // TODO watch changes to package.json, package-lock.json, yarn.lock, pnpm-lock.yaml
223
+ }
224
+
225
+ private _reset ( ) : void {
226
+ this . _state = this . _completions = undefined
222
227
}
223
228
224
229
private get state ( ) {
@@ -234,7 +239,14 @@ export class Twind {
234
239
235
240
const { configFile, ...config } = getConfig ( program . getCurrentDirectory ( ) )
236
241
237
- this . _configFile = configFile
242
+ if ( configFile ) {
243
+ this . logger . log ( `Loaded twind config from ${ configFile } ` )
244
+
245
+ // Resez all state on config file changes
246
+ watch ( configFile , ( ) => this . _reset ( ) )
247
+ } else {
248
+ this . logger . log ( `No twind config found` )
249
+ }
238
250
239
251
const sheet = virtualSheet ( )
240
252
const reports : ReportInfo [ ] = [ ]
@@ -251,13 +263,14 @@ export class Twind {
251
263
reports . push ( info )
252
264
} ,
253
265
} ,
254
- preflight : false ,
255
- prefix : false ,
256
266
plugins : {
257
267
...config . plugins ,
258
268
// Used to generate CSS for variants
259
269
TYPESCRIPT_PLUGIN_PLACEHOLDER : { '--typescript_plugin_placeholder' : 'none' } ,
260
270
} ,
271
+ preflight : false ,
272
+ hash : false ,
273
+ prefix : false ,
261
274
} )
262
275
263
276
let context : Context
0 commit comments