Skip to content

Commit 65bb724

Browse files
authored
fix(app/ae): search Quasar scripts into src first and fix behaviour when the script isn't found (#12091)
1 parent 66ec7a4 commit 65bb724

File tree

1 file changed

+28
-14
lines changed

1 file changed

+28
-14
lines changed

app/lib/app-extension/Extension.js

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,13 @@ module.exports = class Extension {
124124
}
125125

126126
isInstalled () {
127-
const indexScript = this.__getScriptFile('index')
128-
return !!indexScript
127+
try {
128+
this.__getScriptFile('index')
129+
}
130+
catch (e) {
131+
return false
132+
}
133+
return true
129134
}
130135

131136
async install (skipPkgInstall) {
@@ -293,33 +298,42 @@ module.exports = class Extension {
293298
)
294299
}
295300

301+
/**
302+
* Returns the file absolute path. If the file cannot be found into the default 'src' folder,
303+
* searches it into the `dist` folder.
304+
*
305+
* This allows to use preprocessors (eg. TypeScript) for all AE files (even index, install and other Quasar-specific scripts)
306+
* as long as the corresponding file isn't available into the `src` folder, making the feature opt-in
307+
*/
296308
__getScriptFile (scriptName) {
297309
let script
298310

299311
try {
300-
script = require.resolve(this.packageName + '/dist/' + scriptName, {
312+
script = require.resolve(`${this.packageName}/src/${scriptName}`, {
301313
paths: [ appPaths.appDir ]
302314
})
303315
}
304316
catch (e) {
305-
try {
306-
script = require.resolve(this.packageName + '/src/' + scriptName, {
307-
paths: [ appPaths.appDir ]
308-
})
309-
}
310-
catch (e) {
311-
return
312-
}
317+
script = require.resolve(`${this.packageName}/dist/${scriptName}`, {
318+
paths: [ appPaths.appDir ]
319+
})
313320
}
314321

315322
return script
316323
}
317324

318325
__getScript (scriptName, fatalError) {
319-
const script = this.__getScriptFile(scriptName)
326+
let script
327+
328+
try {
329+
script = this.__getScriptFile(scriptName)
330+
}
331+
catch (e) {
332+
if (fatalError) {
333+
fatal(`App Extension "${this.extId}" has missing ${scriptName} script...`)
334+
}
320335

321-
if (fatalError && !script) {
322-
fatal(`App Extension "${this.extId}" has missing ${scriptName} script...`)
336+
return
323337
}
324338

325339
return require(script)

0 commit comments

Comments
 (0)