Skip to content

Commit 85e81fc

Browse files
committed
fix(app): AE file resolution algorithm
1 parent 2ba8fcf commit 85e81fc

File tree

1 file changed

+21
-28
lines changed

1 file changed

+21
-28
lines changed

app/lib/app-extension/Extension.js

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

126126
isInstalled () {
127-
try {
128-
const pkgSrc = this.__getPkgSrc()
129-
require.resolve(`${this.packageName}/${pkgSrc}/index`, {
130-
paths: [ appPaths.appDir ]
131-
})
132-
}
133-
catch (e) {
134-
return false
135-
}
136-
137-
return true
127+
const indexScript = this.__getScriptFile('index')
128+
return !!indexScript
138129
}
139130

140131
async install (skipPkgInstall) {
@@ -302,31 +293,33 @@ module.exports = class Extension {
302293
)
303294
}
304295

305-
/**
306-
* Get the app extension's source folder from the package.json entrypoint "main"
307-
* TODO: Should be replaced or extended with "exports" for ESM support
308-
*/
309-
__getPkgSrc () {
310-
const pkg = require.resolve(this.packageName + `/package.json`, {
311-
paths: [ appPaths.appDir ]
312-
})
313-
return require(pkg).main.split('/')[0]
314-
}
315-
316-
__getScript (scriptName, fatalError) {
296+
__getScriptFile (scriptName) {
317297
let script
318-
const pkgSrc = this.__getPkgSrc()
298+
319299
try {
320-
script = require.resolve(`${this.packageName}/${pkgSrc}/${scriptName}`, {
300+
script = require.resolve(this.packageName + '/dist/' + scriptName, {
321301
paths: [ appPaths.appDir ]
322302
})
323303
}
324304
catch (e) {
325-
if (fatalError) {
326-
fatal(`App Extension "${this.extId}" has missing ${scriptName} script...`)
305+
try {
306+
script = require.resolve(this.packageName + '/src/' + scriptName, {
307+
paths: [ appPaths.appDir ]
308+
})
327309
}
310+
catch (e) {
311+
return
312+
}
313+
}
328314

329-
return
315+
return script
316+
}
317+
318+
__getScript (scriptName, fatalError) {
319+
const script = this.__getScriptFile(scriptName)
320+
321+
if (fatalError && !script) {
322+
fatal(`App Extension "${this.extId}" has missing ${scriptName} script...`)
330323
}
331324

332325
return require(script)

0 commit comments

Comments
 (0)