Skip to content

Commit 90bc15a

Browse files
committed
fix: re-loading of config file
1 parent aef7893 commit 90bc15a

File tree

4 files changed

+32
-9
lines changed

4 files changed

+32
-9
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,12 @@
9696
}
9797
},
9898
"dependencies": {
99+
"clear-module": "^4.1.1",
99100
"cssbeautify": "^0.3.1",
100101
"fast-json-stable-stringify": "^2.1.0",
101102
"match-sorter": "^6.3.0",
102103
"sucrase": "^3.17.1",
103-
"twind": "^0.16.9",
104+
"twind": "^0.16.10",
104105
"typescript": "^4.1.0",
105106
"typescript-template-language-service-decorator": "^2.2.0",
106107
"vscode-languageserver-types": "^3.13.0"

src/load.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import * as Path from 'path'
44
import Module from 'module'
55
import { fileURLToPath } from 'url'
66

7+
import clearModule from 'clear-module'
8+
79
import type { Configuration } from 'twind'
810

911
const TWIND_CONFIG_FILES = [
@@ -34,18 +36,23 @@ export const findConfig = (project: ts.server.Project, cwd = process.cwd()): str
3436
}
3537

3638
export const loadFile = <T>(file: string, cwd = process.cwd()): T => {
39+
const moduleId = Path.resolve(cwd, file)
40+
3741
try {
3842
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
3943
// @ts-ignore
4044
const from = fileURLToPath(import.meta.url)
4145

4246
const require = Module.createRequire?.(from) || Module.createRequireFromPath(from)
4347

48+
clearModule(moduleId)
49+
4450
require('sucrase/register')
4551

4652
// eslint-disable-next-line @typescript-eslint/no-var-requires
47-
return require(Path.resolve(cwd, file)) as T
48-
} catch {
53+
return require(moduleId) as T
54+
} catch (error) {
55+
console.error(`Failed to load ${moduleId}: ${error.stack}`)
4956
return {} as T
5057
}
5158
}

src/twind.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ export class Twind {
252252
)
253253

254254
if (configFile) {
255-
this.logger.log(`loaded twind config from ${configFile}`)
255+
this.logger.log(`loaded twind config from ${configFile}: ${JSON.stringify(config)}`)
256256

257257
// Reset all state on config file changes
258258
this._watchers.push(watch(configFile, () => this._reset(), { once: true }))

yarn.lock

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ braces@^3.0.1:
250250
dependencies:
251251
fill-range "^7.0.1"
252252

253-
callsites@^3.0.0:
253+
callsites@^3.0.0, callsites@^3.1.0:
254254
version "3.1.0"
255255
resolved "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz#b3630abd8943432f54b3f0519238e33cd7df2f73"
256256
integrity sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ==
@@ -272,6 +272,14 @@ chalk@^4.0.0:
272272
ansi-styles "^4.1.0"
273273
supports-color "^7.1.0"
274274

275+
clear-module@^4.1.1:
276+
version "4.1.1"
277+
resolved "https://registry.npmjs.org/clear-module/-/clear-module-4.1.1.tgz#bf8ba3b62eb70ee1e0adec90589741425cf32db8"
278+
integrity sha512-ng0E7LeODcT3QkazOckzZqbca+JByQy/Q2Z6qO24YsTp+pLxCfohGz2gJYJqZS0CWTX3LEUiHOqe5KlYeUbEMw==
279+
dependencies:
280+
parent-module "^2.0.0"
281+
resolve-from "^5.0.0"
282+
275283
color-convert@^1.9.0:
276284
version "1.9.3"
277285
resolved "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz#bb71850690e1f136567de629d2d5471deda4c1e8"
@@ -1017,6 +1025,13 @@ parent-module@^1.0.0:
10171025
dependencies:
10181026
callsites "^3.0.0"
10191027

1028+
parent-module@^2.0.0:
1029+
version "2.0.0"
1030+
resolved "https://registry.npmjs.org/parent-module/-/parent-module-2.0.0.tgz#fa71f88ff1a50c27e15d8ff74e0e3a9523bf8708"
1031+
integrity sha512-uo0Z9JJeWzv8BG+tRcapBKNJ0dro9cLyczGzulS6EfeyAdeC9sbojtW6XwvYxJkEne9En+J2XEl4zyglVeIwFg==
1032+
dependencies:
1033+
callsites "^3.1.0"
1034+
10201035
path-exists@^4.0.0:
10211036
version "4.0.0"
10221037
resolved "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz#513bdbe2d3b95d7762e8c1137efa195c6c61b5b3"
@@ -1325,10 +1340,10 @@ tsutils@^3.17.1:
13251340
dependencies:
13261341
tslib "^1.8.1"
13271342

1328-
twind@^0.16.9:
1329-
version "0.16.9"
1330-
resolved "https://registry.npmjs.org/twind/-/twind-0.16.9.tgz#62d04a12d4a96f5f1e72e477af4e8634f356eaac"
1331-
integrity sha512-cOpijhtEMEaIhHQ4H3+K/APn1kAYkMtV3fMB/zBfXP+rmKiwjnNZSot8w8YNGnKDqLbV+uCSuFiZtPL60Jscaw==
1343+
twind@^0.16.10:
1344+
version "0.16.10"
1345+
resolved "https://registry.npmjs.org/twind/-/twind-0.16.10.tgz#9e7ac848b48568fc4a49fc8ea2d218cbbadb9aab"
1346+
integrity sha512-GjTPjEbon/Z2FOVsEVkF6nCXqdpmNtlcfIC3p4zwWm+WUsLraryW2OK6pkWwjkXPVwWZEm0RTjzsWOuPs3gaHQ==
13321347
dependencies:
13331348
csstype "^3.0.5"
13341349
htmlparser2 "^6.0.0"

0 commit comments

Comments
 (0)