Skip to content

Commit 988e85c

Browse files
committed
fix JIT initialisation when mode is set in a preset (fixes #333)
1 parent e292283 commit 988e85c

File tree

1 file changed

+43
-4
lines changed

1 file changed

+43
-4
lines changed

src/server.ts

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,9 @@ async function createProjectService(
577577
let userVariants: any
578578
let userMode: any
579579
let userPlugins: any
580+
let presetModes: any[] = []
581+
let presetVariants: any[] = []
582+
580583
let hook = new Hook(fs.realpathSync(state.configPath), (exports) => {
581584
userSeperator = dlv(exports, sepLocation)
582585
if (typeof userSeperator !== 'string') {
@@ -589,17 +592,38 @@ async function createProjectService(
589592
`__TWSEP__${typeof userSeperator === 'undefined' ? ':' : userSeperator}__TWSEP__`
590593
)
591594
exports.purge = []
592-
if (state.modules.jit && exports.mode === 'jit') {
595+
596+
let mode: any
597+
if (Array.isArray(exports.presets)) {
598+
for (let preset of exports.presets) {
599+
if (typeof preset.mode !== 'undefined') {
600+
mode = preset.mode
601+
}
602+
presetModes.push(preset.mode)
603+
delete preset.mode
604+
}
605+
}
606+
if (typeof exports.mode !== 'undefined') {
607+
mode = exports.mode
608+
}
609+
userMode = exports.mode
610+
delete exports.mode
611+
612+
if (state.modules.jit && mode === 'jit') {
593613
state.jit = true
594614
userVariants = exports.variants
595615
exports.variants = []
616+
617+
if (Array.isArray(exports.presets)) {
618+
for (let preset of exports.presets) {
619+
presetVariants.push(preset.variants)
620+
preset.variants = []
621+
}
622+
}
596623
} else {
597624
state.jit = false
598625
}
599626

600-
userMode = exports.mode
601-
delete exports.mode
602-
603627
// inject JIT `matchUtilities` function
604628
if (Array.isArray(exports.plugins)) {
605629
userPlugins = exports.plugins
@@ -702,6 +726,21 @@ async function createProjectService(
702726
config.plugins = userPlugins
703727
}
704728

729+
for (let index in presetModes) {
730+
if (typeof presetModes[index] === 'undefined') {
731+
delete config.presets[index].mode
732+
} else {
733+
config.presets[index].mode = presetModes[index]
734+
}
735+
}
736+
for (let index in presetVariants) {
737+
if (typeof presetVariants[index] === 'undefined') {
738+
delete config.presets[index].variants
739+
} else {
740+
config.presets[index].variants = presetVariants[index]
741+
}
742+
}
743+
705744
if (state.dependencies) {
706745
watcher.unwatch(state.dependencies)
707746
}

0 commit comments

Comments
 (0)