MCPcopy
hub / github.com/transloadit/uppy / use

Method use

packages/@uppy/core/src/Uppy.ts:1891–1943  ·  view source on GitHub ↗

* Registers a plugin with Core.

(
    Plugin: T,
    // We want to let the plugin decide whether `opts` is optional or not
    // so we spread the argument rather than defining `opts:` ourselves.
    ...args: OmitFirstArg<ConstructorParameters<T>>
  )

Source from the content-addressed store, hash-verified

1889 * Registers a plugin with Core.
1890 */
1891 use<T extends typeof BasePlugin<any, M, B>>(
1892 Plugin: T,
1893 // We want to let the plugin decide whether `opts` is optional or not
1894 // so we spread the argument rather than defining `opts:` ourselves.
1895 ...args: OmitFirstArg<ConstructorParameters<T>>
1896 ): this {
1897 if (typeof Plugin !== 'function') {
1898 const msg =
1899 `Expected a plugin class, but got ${
1900 Plugin === null ? 'null' : typeof Plugin
1901 }.` +
1902 ' Please verify that the plugin was imported and spelled correctly.'
1903 throw new TypeError(msg)
1904 }
1905
1906 // Instantiate
1907 const plugin = new Plugin(this, ...args)
1908 const pluginId = plugin.id
1909
1910 if (!pluginId) {
1911 throw new Error('Your plugin must have an id')
1912 }
1913
1914 if (!plugin.type) {
1915 throw new Error('Your plugin must have a type')
1916 }
1917
1918 const existsPluginAlready = this.getPlugin(pluginId)
1919 if (existsPluginAlready) {
1920 const msg =
1921 `Already found a plugin named '${existsPluginAlready.id}'. ` +
1922 `Tried to use: '${pluginId}'.\n` +
1923 'Uppy plugins must have unique `id` options.'
1924 throw new Error(msg)
1925 }
1926
1927 // @ts-expect-error does exist
1928 if (Plugin.VERSION) {
1929 // @ts-expect-error does exist
1930 this.log(`Using ${pluginId} v${Plugin.VERSION}`)
1931 }
1932
1933 if (plugin.type in this.#plugins) {
1934 this.#plugins[plugin.type].push(plugin)
1935 } else {
1936 this.#plugins[plugin.type] = [plugin]
1937 }
1938 plugin.install()
1939
1940 this.emit('plugin-added', plugin)
1941
1942 return this
1943 }
1944
1945 /**
1946 * Find one Plugin by name.

Callers 15

UppyDashboardFunction · 0.95
createTransloaditUppyFunction · 0.95
index.test.tsFile · 0.80
index.test.tsFile · 0.80
createUppyFunction · 0.80
installPluginMethod · 0.80
installPluginMethod · 0.80
installPluginMethod · 0.80
getServerFunction · 0.80
appFunction · 0.80
serverFunction · 0.80

Calls 4

getPluginMethod · 0.95
logMethod · 0.95
emitMethod · 0.95
installMethod · 0.45

Tested by 3

createUppyFunction · 0.64
initializeUppyFunction · 0.64
createUppyFunction · 0.64