MCPcopy Create free account
hub / github.com/nuxt/icon / NuxtIconModuleContext

Class NuxtIconModuleContext

src/context.ts:18–200  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

16]
17
18export class NuxtIconModuleContext {
19 constructor(
20 public readonly nuxt: Nuxt,
21 public readonly options: ModuleOptions,
22 ) { }
23
24 public clientBundleVersion = 0
25 public scannedIcons = new Set<string>()
26 public scanner: IconUsageScanner | undefined
27
28 getRuntimeCollections(runtimeOptions: NuxtIconRuntimeOptions): string[] {
29 const resolved = runtimeOptions.fallbackToApi
30 ? collectionNames
31 : typeof this.options.serverBundle === 'string'
32 ? collectionNames
33 : this.options.serverBundle
34 ? this.options.serverBundle.collections
35 ?.map(c => typeof c === 'string' ? c : c.prefix) || []
36 : []
37
38 // Include custom collections prefixes
39 for (const collection of this.options.customCollections || []) {
40 if (collection.prefix && !resolved.includes(collection.prefix))
41 resolved.push(collection.prefix)
42 }
43
44 return resolved
45 }
46
47 private _customCollections: IconifyJSON[] | Promise<IconifyJSON[]> | undefined
48 private _serverBundle: ResolvedServerBundleOptions | Promise<ResolvedServerBundleOptions> | undefined
49 private _nitroPreset: string | undefined
50
51 setNitroPreset(preset: string | undefined): void {
52 this._nitroPreset = preset || this._nitroPreset
53 }
54
55 async resolveServerBundle(): Promise<ResolvedServerBundleOptions> {
56 if (!this._serverBundle) {
57 this._serverBundle = this._resolveServerBundle()
58 .then((bundle) => {
59 if (this._serverBundle)
60 this._serverBundle = bundle
61 return bundle
62 })
63 }
64 return this._serverBundle
65 }
66
67 private async _resolveServerBundle(): Promise<ResolvedServerBundleOptions> {
68 let serverBundle = this.options.serverBundle
69 if (serverBundle === 'auto') {
70 const preset = this._nitroPreset || (typeof this.nuxt.options.nitro.preset === 'string'
71 ? this.nuxt.options.nitro.preset || provider
72 : provider)
73
74 serverBundle = 'local'
75

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…