Skip to content

Commit b4eeeca

Browse files
committed
fix: make sure windiService is available, rename service
1 parent b8c6667 commit b4eeeca

File tree

5 files changed

+26
-26
lines changed

5 files changed

+26
-26
lines changed

src/interfaces.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type webpack from 'webpack'
22
import type { WindiPluginUtils, UserOptions } from '@windicss/plugin-utils'
33

44
export type Compiler = webpack.Compiler & {
5-
$windyCSSService: WindiPluginUtils & {
5+
$windi: WindiPluginUtils & {
66
dirty: Set<string>
77
root: string
88
virtualModules: Map<string, string>

src/loaders/transform-css.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function TransformCss(
1010
return source
1111

1212
this.cacheable(true)
13-
const service = (this._compiler as Compiler).$windyCSSService
13+
const service = (this._compiler as Compiler).$windi
1414

1515
if (!service)
1616
return source

src/loaders/transform-template.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ function TransformTemplate(
1414
return source
1515

1616
this.cacheable(true)
17-
const service = (this._compiler as Compiler).$windyCSSService
17+
const service = (this._compiler as Compiler).$windi
1818

1919
if (!service)
2020
return source

src/loaders/virtual-module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ async function VirtualModule(
1717
return
1818
}
1919
this.cacheable(false)
20-
const service = (this._compiler as Compiler).$windyCSSService
20+
const service = (this._compiler as Compiler).$windi
2121
const match = this.resource.match(MODULE_ID_VIRTUAL_TEST)
2222
if (!service || !match) {
2323
const error = new Error(`Failed to match the resource "${this.resource}" to a WindiCSS virtual module.`)

src/plugin.ts

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,10 @@ class WindiCSSWebpackPlugin {
9393
*/
9494
compiler.options.module.rules.push({
9595
include(resource) {
96-
if (shouldExcludeResource(resource))
96+
if (!compiler.$windi || shouldExcludeResource(resource))
9797
return false
9898

99-
return Boolean(compiler.$windyCSSService.isDetectTarget(resource))
99+
return Boolean(compiler.$windi.isDetectTarget(resource))
100100
},
101101
enforce: 'post',
102102
use: [{
@@ -111,10 +111,10 @@ class WindiCSSWebpackPlugin {
111111
*/
112112
compiler.options.module.rules.push({
113113
include(resource) {
114-
if (shouldExcludeResource(resource))
114+
if (!compiler.$windi || shouldExcludeResource(resource))
115115
return false
116116

117-
return Boolean(compiler.$windyCSSService.isDetectTarget(resource))
117+
return Boolean(compiler.$windi.isDetectTarget(resource))
118118
},
119119
use: [{
120120
loader: transformTemplateLoader,
@@ -123,10 +123,10 @@ class WindiCSSWebpackPlugin {
123123

124124
compiler.options.module.rules.push({
125125
include(resource) {
126-
if (shouldExcludeResource(resource))
126+
if (!compiler.$windi || shouldExcludeResource(resource))
127127
return false
128128

129-
return Boolean(compiler.$windyCSSService.isCssTransformTarget(resource))
129+
return Boolean(compiler.$windi.isCssTransformTarget(resource))
130130
},
131131
use: [{
132132
loader: transformCSSLoader,
@@ -150,7 +150,7 @@ class WindiCSSWebpackPlugin {
150150
* Add the windycss config file as a dependency so that the watcher can handle updates to it.
151151
*/
152152
compiler.hooks.afterCompile.tap(NAME, (compilation) => {
153-
if (compiler.$windyCSSService) {
153+
if (compiler.$windi) {
154154
let hasConfig = false
155155
// add watcher for the config path
156156
for (const name of defaultConfigureFiles) {
@@ -191,27 +191,27 @@ class WindiCSSWebpackPlugin {
191191
resource = 'all-modules'
192192

193193
// make sure service is available and file is valid
194-
if (!compiler.$windyCSSService || shouldExcludeResource(resource))
194+
if (!compiler.$windi || shouldExcludeResource(resource))
195195
return
196196

197197
const skipInvalidation
198-
= compiler.$windyCSSService.dirty.has(resource)
199-
|| (resource !== 'all-modules' && !compiler.$windyCSSService.isDetectTarget(resource) && resource !== compiler.$windyCSSService.configFilePath)
198+
= compiler.$windi.dirty.has(resource)
199+
|| (resource !== 'all-modules' && !compiler.$windi.isDetectTarget(resource) && resource !== compiler.$windi.configFilePath)
200200

201201
debug.plugin('file update', resource, `skip:${skipInvalidation}`)
202202
if (skipInvalidation)
203203
return
204204
// Add dirty file so the loader can process it
205-
compiler.$windyCSSService.dirty.add(resource)
205+
compiler.$windi.dirty.add(resource)
206206
// Trigger a change to the virtual module
207207
const moduleUpdateId = hmrId++
208208
MODULE_ID_VIRTUAL_MODULES.forEach((virtualModulePath) => {
209209
let virtualModuleContent = ''
210210
const match = virtualModulePath.match(MODULE_ID_VIRTUAL_TEST)
211211
if (match) {
212212
const layer = (match[1] as LayerName | 'all') || 'all'
213-
if (compiler.$windyCSSService && compiler.$windyCSSService.virtualModules.has(layer))
214-
virtualModuleContent = def(compiler.$windyCSSService.virtualModules.get(layer), '')
213+
if (compiler.$windi && compiler.$windi.virtualModules.has(layer))
214+
virtualModuleContent = def(compiler.$windi.virtualModules.get(layer), '')
215215
}
216216
virtualModules.writeModule(
217217
join(this.options.virtualModulePath, virtualModulePath),
@@ -223,13 +223,13 @@ class WindiCSSWebpackPlugin {
223223

224224
// Make windy service available to the loader
225225
const initWindyCSSService = async() => {
226-
if (!compiler.$windyCSSService) {
226+
if (!compiler.$windi) {
227227
const utils = def(this.options.utils, createUtils(this.options, {
228228
root,
229229
name: NAME,
230230
}))
231231

232-
compiler.$windyCSSService = Object.assign(
232+
compiler.$windi = Object.assign(
233233
utils,
234234
{
235235
root,
@@ -240,25 +240,25 @@ class WindiCSSWebpackPlugin {
240240
// Scans all files and builds initial css
241241
// wrap in a try catch
242242
try {
243-
await compiler.$windyCSSService.init()
243+
await compiler.$windi.init()
244244
}
245245
catch (e: any) {
246-
compiler.$windyCSSService.initException = e
246+
compiler.$windi.initException = e
247247
}
248248
}
249249
}
250250

251251
compiler.hooks.thisCompilation.tap(NAME, (compilation) => {
252-
if (!compiler.$windyCSSService)
252+
if (!compiler.$windi)
253253
return
254254

255255
// give the init exception to the compilation so that the user can see there was an issue
256-
if (compiler.$windyCSSService.initException) {
257-
compilation.errors.push(compiler.$windyCSSService.initException)
258-
compiler.$windyCSSService.initException = undefined
256+
if (compiler.$windi.initException) {
257+
compilation.errors.push(compiler.$windi.initException)
258+
compiler.$windi.initException = undefined
259259
}
260260
compilation.hooks.childCompiler.tap(NAME, (childCompiler) => {
261-
childCompiler.$windyCSSService = compiler.$windyCSSService
261+
childCompiler.$windi = compiler.$windi
262262
})
263263
})
264264

0 commit comments

Comments
 (0)