feat(lib/plugins): add sourceURL to external plugin scripts
This commit is contained in:
parent
1497e8ef8d
commit
ffce0e2cf2
1 changed files with 11 additions and 4 deletions
|
|
@ -160,7 +160,7 @@ export function registerExternalPlugin(external: ExternalPlugin) {
|
||||||
const id = internal
|
const id = internal
|
||||||
? registerInternalPlugin(
|
? registerInternalPlugin(
|
||||||
manifest,
|
manifest,
|
||||||
createOptionsFactory(script),
|
createOptionsFactory(manifest.id, script),
|
||||||
essential || enabledByDefault ? PluginFlags.Enabled : 0,
|
essential || enabledByDefault ? PluginFlags.Enabled : 0,
|
||||||
InternalPluginFlags.Internal |
|
InternalPluginFlags.Internal |
|
||||||
(essential ? InternalPluginFlags.Essential : 0) |
|
(essential ? InternalPluginFlags.Essential : 0) |
|
||||||
|
|
@ -168,7 +168,7 @@ export function registerExternalPlugin(external: ExternalPlugin) {
|
||||||
)
|
)
|
||||||
: registerPlugin(
|
: registerPlugin(
|
||||||
manifest,
|
manifest,
|
||||||
createOptionsFactory(script),
|
createOptionsFactory(manifest.id, script),
|
||||||
enabledByDefault ? PluginFlags.Enabled : 0,
|
enabledByDefault ? PluginFlags.Enabled : 0,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -235,11 +235,18 @@ function assertIsFunction(
|
||||||
throw new Error(`${name} must be a function, got ${typeof value}`)
|
throw new Error(`${name} must be a function, got ${typeof value}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
function createOptionsFactory(script?: string): PluginOptionsFactory {
|
function createOptionsFactory(
|
||||||
|
id: string,
|
||||||
|
script?: string,
|
||||||
|
): PluginOptionsFactory {
|
||||||
if (!script) return () => ({})
|
if (!script) return () => ({})
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
const opts = new Function('revenge', 'plugin', `return ${script}`)(
|
const opts = new Function(
|
||||||
|
'revenge',
|
||||||
|
'plugin',
|
||||||
|
`return ${script}\n//# sourceURL=Revenge:Plugin:${id}`,
|
||||||
|
)(
|
||||||
pUnscopedApi,
|
pUnscopedApi,
|
||||||
// See types.consumers.ts
|
// See types.consumers.ts
|
||||||
(opts: PluginOptions) => opts,
|
(opts: PluginOptions) => opts,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue