* fix(web): register @angular/compiler before other @angular packages
tabby-web-container's preload registered @angular/compiler after
@angular/cdk and @angular/cdk/clipboard. Because the module argument to
Tabby.registerModule is evaluated eagerly, requiring @angular/cdk/clipboard
pulls in @angular/common before the compiler has run.
@angular/common and @angular/cdk are shipped as partially compiled
(\u0275\u0275ngDeclare*) fesm bundles and this webpack config does not run the
Angular Linker over them, so they rely on the JIT fallback, which reads
ng.\u0275compilerFacade - published by @angular/compiler when it is evaluated:
Error: The injectable 'PlatformLocation' needs to be compiled using the
JIT compiler, but '@angular/compiler' is not available.
This aborts the whole bundle, leaving window.bootstrapTabby undefined, so
every plugin then fails with 'Attempted to require @angular/common' and the
web UI stays blank. Affects tabby-web-container 1.0.197-nightly.1 and
1.0.231-nightly.0; 1.0.189-nightly.2 (Angular 12) is unaffected.
Registering @angular/compiler first publishes the facade before anything
else is required.
* fix(web): expose window.pluginModules to the plugin-provided services
tabby-core's ConfigService.enabledServices() iterates over
window['pluginModules'] to collect providers contributed by plugins - this
is what ThemesService uses to apply the current theme. entry.ts only kept
pluginModules as a local variable, so the global was never set and
bootstrapping threw:
TypeError: window.pluginModules is not iterable
at ConfigService.enabledServices (tabby-core/dist/index.js)
at ThemesService.applyThemeVariables
Publish the array on window before building the root module.
* fix(web): tag plugin modules with their name
loadPlugins()/loadPlugin() returned the module from webRequire() as-is, but
bootstrap() reads `packageModule.pluginName` and tabby-core keys
ConfigService.servicesCache by that field:
this.servicesCache[module.pluginName] = module.\u0275inj.providers...
Since pluginName was never set, every plugin landed on the single key
"undefined" and each one overwrote the previous, leaving enabledServices()
with only the last loaded plugin's providers. Symptomatically the SSH
connection type disappeared from the "new connection" menu once tabby-telnet
started loading after tabby-ssh.
It stayed hidden because enabledServices() returns true for services it does
not recognise, so only plugins that consult the cache for a decision broke.
Tag the module in both entry points.
---------
Co-authored-by: gaoyifeng <work@gyf.name>
118 lines
3.4 KiB
TypeScript
118 lines
3.4 KiB
TypeScript
import 'source-sans-pro/source-sans-pro.css'
|
|
import 'source-code-pro/source-code-pro.css'
|
|
import '@fortawesome/fontawesome-free/css/solid.css'
|
|
import '@fortawesome/fontawesome-free/css/brands.css'
|
|
import '@fortawesome/fontawesome-free/css/regular.css'
|
|
import '@fortawesome/fontawesome-free/css/fontawesome.css'
|
|
import '../app/src/preload.scss'
|
|
|
|
// Required before other imports
|
|
import './polyfills.buffer'
|
|
|
|
const mocks = {}
|
|
const modules = {}
|
|
|
|
const customRequire = path => {
|
|
if (mocks[path]) {
|
|
console.log(':: mock', path)
|
|
return mocks[path]
|
|
}
|
|
if (modules[path]) {
|
|
return modules[path]
|
|
}
|
|
throw new Error(`Attempted to require ${path}`)
|
|
}
|
|
|
|
customRequire['resolve'] = (() => null) as any
|
|
customRequire['main'] = {
|
|
paths: [],
|
|
}
|
|
|
|
async function webRequire (url) {
|
|
console.log(`>> Loading ${url}`)
|
|
const e = document.createElement('script')
|
|
window['module'] = { exports: {} } as any
|
|
window['exports'] = window['module'].exports
|
|
await new Promise(resolve => {
|
|
e.onload = resolve
|
|
e.src = url
|
|
document.querySelector('head').appendChild(e)
|
|
})
|
|
return window['module'].exports
|
|
}
|
|
|
|
async function prefetchURL (url) {
|
|
console.log(`:: Prefetching ${url}`)
|
|
await (await fetch(url)).text()
|
|
}
|
|
|
|
const Tabby = {
|
|
registerMock: (name, mod) => {
|
|
mocks[name] = mod
|
|
},
|
|
registerModule: (name, mod) => {
|
|
modules[name] = mod
|
|
},
|
|
resolvePluginInfo: async (url): Promise<any> => {
|
|
const pkg = await (await fetch(url + '/package.json')).json()
|
|
url += '/' + pkg.main
|
|
return { ...pkg, url }
|
|
},
|
|
registerPluginModule: (packageName, module) => {
|
|
Tabby.registerModule(`resources/builtin-plugins/${packageName}`, module)
|
|
Tabby.registerModule(packageName, module)
|
|
},
|
|
loadPlugin: async (url) => {
|
|
const info = await Tabby.resolvePluginInfo(url)
|
|
const module = await webRequire(info.url)
|
|
Tabby.registerPluginModule(info.name, module)
|
|
module.pluginName = info.name
|
|
return module
|
|
},
|
|
loadPlugins: async (urls, progressCallback) => {
|
|
const infos: any[] = await Promise.all(urls.map(Tabby.resolvePluginInfo))
|
|
progressCallback?.(0, 1)
|
|
await Promise.all(infos.map(x => prefetchURL(x.url)))
|
|
const pluginModules = []
|
|
for (const info of infos) {
|
|
const module = await webRequire(info.url)
|
|
Tabby.registerPluginModule(info.name, module)
|
|
// bootstrap() copies pluginName onto the NgModule and tabby-core
|
|
// keys ConfigService.servicesCache by it.
|
|
module.pluginName = info.name
|
|
pluginModules.push(module)
|
|
progressCallback?.(infos.indexOf(info), infos.length)
|
|
}
|
|
progressCallback?.(1, 1)
|
|
return pluginModules
|
|
},
|
|
bootstrap: (...args) => window['bootstrapTabby'](...args),
|
|
webRequire,
|
|
}
|
|
|
|
Object.assign(window, {
|
|
require: customRequire,
|
|
module: {
|
|
paths: [],
|
|
},
|
|
Tabby,
|
|
__filename: '',
|
|
__dirname: '',
|
|
process: {
|
|
env: { },
|
|
argv: ['tabby'],
|
|
platform: 'darwin',
|
|
on: () => null,
|
|
stdout: {},
|
|
stderr: {},
|
|
resourcesPath: 'resources',
|
|
version: '14.0.0',
|
|
versions: {
|
|
modules: 0,
|
|
},
|
|
nextTick: (f, ...args) => setTimeout(() => f(...args)),
|
|
cwd: () => '/',
|
|
},
|
|
global: window,
|
|
})
|