fix JIT initialisation when mode is set in a preset (fixes #333)

master
Brad Cornes 2021-05-20 17:07:46 +01:00
parent e2922837b1
commit 988e85cfb3
1 changed files with 43 additions and 4 deletions

View File

@ -577,6 +577,9 @@ async function createProjectService(
let userVariants: any let userVariants: any
let userMode: any let userMode: any
let userPlugins: any let userPlugins: any
let presetModes: any[] = []
let presetVariants: any[] = []
let hook = new Hook(fs.realpathSync(state.configPath), (exports) => { let hook = new Hook(fs.realpathSync(state.configPath), (exports) => {
userSeperator = dlv(exports, sepLocation) userSeperator = dlv(exports, sepLocation)
if (typeof userSeperator !== 'string') { if (typeof userSeperator !== 'string') {
@ -589,17 +592,38 @@ async function createProjectService(
`__TWSEP__${typeof userSeperator === 'undefined' ? ':' : userSeperator}__TWSEP__` `__TWSEP__${typeof userSeperator === 'undefined' ? ':' : userSeperator}__TWSEP__`
) )
exports.purge = [] exports.purge = []
if (state.modules.jit && exports.mode === 'jit') {
let mode: any
if (Array.isArray(exports.presets)) {
for (let preset of exports.presets) {
if (typeof preset.mode !== 'undefined') {
mode = preset.mode
}
presetModes.push(preset.mode)
delete preset.mode
}
}
if (typeof exports.mode !== 'undefined') {
mode = exports.mode
}
userMode = exports.mode
delete exports.mode
if (state.modules.jit && mode === 'jit') {
state.jit = true state.jit = true
userVariants = exports.variants userVariants = exports.variants
exports.variants = [] exports.variants = []
if (Array.isArray(exports.presets)) {
for (let preset of exports.presets) {
presetVariants.push(preset.variants)
preset.variants = []
}
}
} else { } else {
state.jit = false state.jit = false
} }
userMode = exports.mode
delete exports.mode
// inject JIT `matchUtilities` function // inject JIT `matchUtilities` function
if (Array.isArray(exports.plugins)) { if (Array.isArray(exports.plugins)) {
userPlugins = exports.plugins userPlugins = exports.plugins
@ -702,6 +726,21 @@ async function createProjectService(
config.plugins = userPlugins config.plugins = userPlugins
} }
for (let index in presetModes) {
if (typeof presetModes[index] === 'undefined') {
delete config.presets[index].mode
} else {
config.presets[index].mode = presetModes[index]
}
}
for (let index in presetVariants) {
if (typeof presetVariants[index] === 'undefined') {
delete config.presets[index].variants
} else {
config.presets[index].variants = presetVariants[index]
}
}
if (state.dependencies) { if (state.dependencies) {
watcher.unwatch(state.dependencies) watcher.unwatch(state.dependencies)
} }