@lorion-org/nuxt 1.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +578 -0
- package/dist/descriptor-schema.d.ts +4 -0
- package/dist/descriptor-schema.js +63 -0
- package/dist/extensions-vNob6d2x.d.ts +127 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +864 -0
- package/dist/runtime-config-node.d.ts +15 -0
- package/dist/runtime-config-node.js +106 -0
- package/dist/runtime-config.d.ts +22 -0
- package/dist/runtime-config.js +184 -0
- package/examples/read-runtime-config.server.ts +3 -0
- package/examples/runtime-config-source.nuxt.config.ts +13 -0
- package/examples/selected-extensions.nuxt.config.ts +30 -0
- package/package.json +89 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,864 @@
|
|
|
1
|
+
// src/module.ts
|
|
2
|
+
import { existsSync as existsSync2 } from "fs";
|
|
3
|
+
import { join as join2 } from "path";
|
|
4
|
+
import {
|
|
5
|
+
addImports,
|
|
6
|
+
addServerImports,
|
|
7
|
+
addServerTemplate,
|
|
8
|
+
addTemplate,
|
|
9
|
+
createResolver,
|
|
10
|
+
defineNuxtModule,
|
|
11
|
+
useLogger
|
|
12
|
+
} from "@nuxt/kit";
|
|
13
|
+
|
|
14
|
+
// src/extensions.ts
|
|
15
|
+
import { existsSync } from "fs";
|
|
16
|
+
import { join } from "path";
|
|
17
|
+
import {
|
|
18
|
+
createDescriptorCatalog
|
|
19
|
+
} from "@lorion-org/composition-graph";
|
|
20
|
+
import { discoverDescriptors } from "@lorion-org/descriptor-discovery";
|
|
21
|
+
import {
|
|
22
|
+
resolveItemProviderSelection
|
|
23
|
+
} from "@lorion-org/provider-selection";
|
|
24
|
+
|
|
25
|
+
// src/extension-descriptor.schema.json
|
|
26
|
+
var extension_descriptor_schema_default = {
|
|
27
|
+
$schema: "http://json-schema.org/draft-07/schema#",
|
|
28
|
+
$id: "https://lorion.dev/schemas/nuxt-extension-descriptor.schema.json",
|
|
29
|
+
$ref: "#/$defs/extension",
|
|
30
|
+
$defs: {
|
|
31
|
+
semver: {
|
|
32
|
+
type: "string",
|
|
33
|
+
pattern: "^(\\^|~)?\\d+\\.\\d+\\.\\d+$"
|
|
34
|
+
},
|
|
35
|
+
dependencyMap: {
|
|
36
|
+
type: "object",
|
|
37
|
+
additionalProperties: { $ref: "#/$defs/semver" }
|
|
38
|
+
},
|
|
39
|
+
extension: {
|
|
40
|
+
type: "object",
|
|
41
|
+
properties: {
|
|
42
|
+
id: {
|
|
43
|
+
type: "string",
|
|
44
|
+
minLength: 1
|
|
45
|
+
},
|
|
46
|
+
version: { $ref: "#/$defs/semver" },
|
|
47
|
+
providesFor: {
|
|
48
|
+
type: "string",
|
|
49
|
+
minLength: 1
|
|
50
|
+
},
|
|
51
|
+
capabilities: {
|
|
52
|
+
type: "array",
|
|
53
|
+
items: {
|
|
54
|
+
type: "string",
|
|
55
|
+
minLength: 1
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
dependencies: { $ref: "#/$defs/dependencyMap" },
|
|
59
|
+
disabled: { type: "boolean" },
|
|
60
|
+
location: { type: "string" },
|
|
61
|
+
providerPreferences: {
|
|
62
|
+
type: "object",
|
|
63
|
+
additionalProperties: {
|
|
64
|
+
type: "string",
|
|
65
|
+
minLength: 1
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
publicRuntimeConfig: {
|
|
69
|
+
type: "object",
|
|
70
|
+
additionalProperties: true
|
|
71
|
+
},
|
|
72
|
+
bundles: {
|
|
73
|
+
type: "array",
|
|
74
|
+
items: { $ref: "#/$defs/extension" }
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
required: ["id", "version"],
|
|
78
|
+
additionalProperties: true
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
// src/descriptor-schema.ts
|
|
84
|
+
var nuxtExtensionDescriptorSchema = extension_descriptor_schema_default;
|
|
85
|
+
|
|
86
|
+
// src/extensions.ts
|
|
87
|
+
var defaultExtensionOptions = {
|
|
88
|
+
defaultSelection: "default",
|
|
89
|
+
publicRuntimeConfigKey: "extensionSelection",
|
|
90
|
+
descriptorPaths: ["extensions/*/extension.json"]
|
|
91
|
+
};
|
|
92
|
+
function isRecord(value) {
|
|
93
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
94
|
+
}
|
|
95
|
+
function asArray(value) {
|
|
96
|
+
if (value === void 0) return [];
|
|
97
|
+
return Array.isArray(value) ? value : [value];
|
|
98
|
+
}
|
|
99
|
+
function splitSelectionValue(value) {
|
|
100
|
+
return value.split(/[,\s]+/).map((entry) => entry.trim()).filter(Boolean);
|
|
101
|
+
}
|
|
102
|
+
function normalizeSelection(value) {
|
|
103
|
+
return asArray(value).flatMap((entry) => {
|
|
104
|
+
if (typeof entry !== "string") return [];
|
|
105
|
+
return splitSelectionValue(entry);
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
function resolveExtensionOptions(options) {
|
|
109
|
+
return {
|
|
110
|
+
descriptorSchema: options.descriptorSchema ?? nuxtExtensionDescriptorSchema,
|
|
111
|
+
descriptorPaths: options.descriptorPaths ?? [...defaultExtensionOptions.descriptorPaths]
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
function resolveExtensionSelection(input = {}) {
|
|
115
|
+
const candidates = [
|
|
116
|
+
normalizeSelection(input.selected),
|
|
117
|
+
normalizeSelection(input.defaultSelection ?? defaultExtensionOptions.defaultSelection)
|
|
118
|
+
];
|
|
119
|
+
return candidates.find((candidate) => candidate.length > 0) ?? [];
|
|
120
|
+
}
|
|
121
|
+
function resolveBaseExtensionSelection(input) {
|
|
122
|
+
const baseExtensions = input.options.baseExtensions;
|
|
123
|
+
return typeof baseExtensions === "function" ? normalizeSelection(baseExtensions(input)) : normalizeSelection(baseExtensions);
|
|
124
|
+
}
|
|
125
|
+
function optionalDir(path) {
|
|
126
|
+
return existsSync(path) ? path : void 0;
|
|
127
|
+
}
|
|
128
|
+
function optionalFile(path) {
|
|
129
|
+
return existsSync(path) ? path : void 0;
|
|
130
|
+
}
|
|
131
|
+
function findNuxtConfigFile(cwd) {
|
|
132
|
+
return ["nuxt.config.ts", "nuxt.config.mts", "nuxt.config.js", "nuxt.config.mjs"].map((fileName) => optionalFile(join(cwd, fileName))).find(Boolean);
|
|
133
|
+
}
|
|
134
|
+
function createExtensionEntry(input) {
|
|
135
|
+
const appDir = optionalDir(join(input.cwd, "app"));
|
|
136
|
+
const modulesDir = optionalDir(join(input.cwd, "modules"));
|
|
137
|
+
const publicDir = optionalDir(join(input.cwd, "public"));
|
|
138
|
+
const serverDir = optionalDir(join(input.cwd, "server"));
|
|
139
|
+
const sharedDir = optionalDir(join(input.cwd, "shared"));
|
|
140
|
+
const configFile = findNuxtConfigFile(input.cwd);
|
|
141
|
+
const entry = {
|
|
142
|
+
cwd: input.cwd,
|
|
143
|
+
descriptor: input.descriptor
|
|
144
|
+
};
|
|
145
|
+
if (appDir) entry.appDir = appDir;
|
|
146
|
+
if (configFile) entry.configFile = configFile;
|
|
147
|
+
if (modulesDir) entry.modulesDir = modulesDir;
|
|
148
|
+
if (publicDir) entry.publicDir = publicDir;
|
|
149
|
+
if (serverDir) entry.serverDir = serverDir;
|
|
150
|
+
if (sharedDir) entry.sharedDir = sharedDir;
|
|
151
|
+
return entry;
|
|
152
|
+
}
|
|
153
|
+
function canRegisterExtensionLayer(entry) {
|
|
154
|
+
return Boolean(
|
|
155
|
+
entry.appDir || entry.configFile || entry.modulesDir || entry.publicDir || entry.serverDir || entry.sharedDir
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
function canExtendExtensionLayer(entry) {
|
|
159
|
+
return Boolean(entry.configFile);
|
|
160
|
+
}
|
|
161
|
+
function discoverExtensionEntries(input) {
|
|
162
|
+
const resolvedOptions = resolveExtensionOptions(input.options);
|
|
163
|
+
return discoverDescriptors({
|
|
164
|
+
cwd: input.projectRootDir,
|
|
165
|
+
descriptorPaths: resolvedOptions.descriptorPaths,
|
|
166
|
+
nestedField: "bundles",
|
|
167
|
+
...resolvedOptions.descriptorSchema === false ? {} : {
|
|
168
|
+
validation: {
|
|
169
|
+
schema: resolvedOptions.descriptorSchema
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}).map(
|
|
173
|
+
(entry) => createExtensionEntry({
|
|
174
|
+
cwd: entry.cwd,
|
|
175
|
+
descriptor: entry.descriptor
|
|
176
|
+
})
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
function pickEntriesById(ids, entryById) {
|
|
180
|
+
return ids.map((id) => entryById.get(id)).filter((entry) => Boolean(entry));
|
|
181
|
+
}
|
|
182
|
+
function mergeRuntimeConfigSection(target = {}, source = {}) {
|
|
183
|
+
const merged = { ...target };
|
|
184
|
+
for (const [key, value] of Object.entries(source)) {
|
|
185
|
+
const current = merged[key];
|
|
186
|
+
merged[key] = isRecord(current) && isRecord(value) ? mergeRuntimeConfigSection(current, value) : value;
|
|
187
|
+
}
|
|
188
|
+
return merged;
|
|
189
|
+
}
|
|
190
|
+
function createExtensionSelectionRuntimeConfig(input) {
|
|
191
|
+
const runtimeConfig = input.activeExtensions.reduce(
|
|
192
|
+
(current, extension) => ({
|
|
193
|
+
...current,
|
|
194
|
+
public: mergeRuntimeConfigSection(
|
|
195
|
+
current.public,
|
|
196
|
+
extension.descriptor.publicRuntimeConfig ?? {}
|
|
197
|
+
)
|
|
198
|
+
}),
|
|
199
|
+
{ public: {} }
|
|
200
|
+
);
|
|
201
|
+
if (input.publicRuntimeConfigKey === false) return runtimeConfig;
|
|
202
|
+
return {
|
|
203
|
+
...runtimeConfig,
|
|
204
|
+
public: {
|
|
205
|
+
...runtimeConfig.public,
|
|
206
|
+
[defaultExtensionOptions.publicRuntimeConfigKey]: {
|
|
207
|
+
discoveredExtensionIds: input.discoveredExtensions.map((extension) => extension.descriptor.id).sort((left, right) => left.localeCompare(right)),
|
|
208
|
+
resolvedExtensionIds: input.resolvedExtensionIds,
|
|
209
|
+
selectedExtensionIds: input.selectedExtensions
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
function createNuxtExtensionBootstrap(input) {
|
|
215
|
+
const options = input.options ?? {};
|
|
216
|
+
const selectedExtensions = resolveExtensionSelection({
|
|
217
|
+
...options.defaultSelection ? { defaultSelection: options.defaultSelection } : {},
|
|
218
|
+
...options.selected ? { selected: options.selected } : {}
|
|
219
|
+
});
|
|
220
|
+
const createCatalog = (entries2) => createDescriptorCatalog({
|
|
221
|
+
descriptors: entries2.map((entry) => entry.descriptor),
|
|
222
|
+
...options.relationDescriptors ? { relationDescriptors: options.relationDescriptors } : {}
|
|
223
|
+
});
|
|
224
|
+
if (options.enabled === false) {
|
|
225
|
+
return {
|
|
226
|
+
activeExtensions: [],
|
|
227
|
+
baseExtensionIds: [],
|
|
228
|
+
catalog: createCatalog([]),
|
|
229
|
+
discoveredExtensions: [],
|
|
230
|
+
publicRuntimeConfig: { public: {} },
|
|
231
|
+
resolvedExtensionIds: [],
|
|
232
|
+
resolvedExtensions: [],
|
|
233
|
+
selectedExtensions
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
const entries = discoverExtensionEntries({
|
|
237
|
+
projectRootDir: input.rootDir,
|
|
238
|
+
options
|
|
239
|
+
});
|
|
240
|
+
const baseExtensionIds = resolveBaseExtensionSelection({
|
|
241
|
+
descriptors: entries.map((entry) => entry.descriptor),
|
|
242
|
+
options,
|
|
243
|
+
selectedExtensions
|
|
244
|
+
});
|
|
245
|
+
const entryById = new Map(entries.map((entry) => [entry.descriptor.id, entry]));
|
|
246
|
+
if (!entries.length) {
|
|
247
|
+
return {
|
|
248
|
+
activeExtensions: [],
|
|
249
|
+
baseExtensionIds,
|
|
250
|
+
catalog: createCatalog(entries),
|
|
251
|
+
discoveredExtensions: entries,
|
|
252
|
+
publicRuntimeConfig: { public: {} },
|
|
253
|
+
resolvedExtensionIds: [],
|
|
254
|
+
resolvedExtensions: [],
|
|
255
|
+
selectedExtensions
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
const catalog = createCatalog(entries);
|
|
259
|
+
const selection = catalog.resolveSelection({
|
|
260
|
+
baseDescriptors: baseExtensionIds,
|
|
261
|
+
selected: selectedExtensions
|
|
262
|
+
});
|
|
263
|
+
const resolvedExtensionIds = selection.getResolved();
|
|
264
|
+
const resolvedExtensions = pickEntriesById(resolvedExtensionIds, entryById);
|
|
265
|
+
const activeExtensions = resolvedExtensions.filter(canRegisterExtensionLayer);
|
|
266
|
+
return {
|
|
267
|
+
activeExtensions,
|
|
268
|
+
baseExtensionIds: selection.getBaseDescriptors(),
|
|
269
|
+
catalog,
|
|
270
|
+
discoveredExtensions: entries,
|
|
271
|
+
publicRuntimeConfig: createExtensionSelectionRuntimeConfig({
|
|
272
|
+
activeExtensions,
|
|
273
|
+
baseExtensionIds: selection.getBaseDescriptors(),
|
|
274
|
+
discoveredExtensions: entries,
|
|
275
|
+
publicRuntimeConfigKey: defaultExtensionOptions.publicRuntimeConfigKey,
|
|
276
|
+
resolvedExtensionIds,
|
|
277
|
+
selectedExtensions
|
|
278
|
+
}),
|
|
279
|
+
resolvedExtensionIds,
|
|
280
|
+
resolvedExtensions,
|
|
281
|
+
selectedExtensions: selection.getSelected()
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
function createNuxtExtensionLayerPaths(bootstrap) {
|
|
285
|
+
return bootstrap.activeExtensions.filter(canExtendExtensionLayer).map((extension) => extension.cwd);
|
|
286
|
+
}
|
|
287
|
+
function collectProviderPreferences(extensions) {
|
|
288
|
+
return extensions.reduce((preferences, extension) => {
|
|
289
|
+
const value = extension.descriptor.providerPreferences;
|
|
290
|
+
if (!isRecord(value)) return preferences;
|
|
291
|
+
return {
|
|
292
|
+
...preferences,
|
|
293
|
+
...Object.fromEntries(
|
|
294
|
+
Object.entries(value).filter(
|
|
295
|
+
(entry) => typeof entry[1] === "string" && entry[1].length > 0
|
|
296
|
+
)
|
|
297
|
+
)
|
|
298
|
+
};
|
|
299
|
+
}, {});
|
|
300
|
+
}
|
|
301
|
+
function createNuxtProviderSelectionRuntimeConfig(extensions, options = {}) {
|
|
302
|
+
const publicRuntimeConfigKey = "providerSelection";
|
|
303
|
+
const descriptorPreferences = collectProviderPreferences(extensions);
|
|
304
|
+
const configuredProviders = {
|
|
305
|
+
...descriptorPreferences,
|
|
306
|
+
...options.configuredProviders ?? {}
|
|
307
|
+
};
|
|
308
|
+
const resolution = resolveItemProviderSelection({
|
|
309
|
+
items: extensions,
|
|
310
|
+
getCapabilityId: (extension) => extension.descriptor.providesFor,
|
|
311
|
+
getProviderId: (extension) => extension.descriptor.id,
|
|
312
|
+
configuredProviders
|
|
313
|
+
});
|
|
314
|
+
return {
|
|
315
|
+
public: {
|
|
316
|
+
[publicRuntimeConfigKey]: {
|
|
317
|
+
configuredProviders,
|
|
318
|
+
excludedProviderIds: resolution.excludedProviderIds,
|
|
319
|
+
mismatches: resolution.mismatches,
|
|
320
|
+
selections: Object.fromEntries(resolution.selections)
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
// src/runtime-config.ts
|
|
327
|
+
import {
|
|
328
|
+
getPrivateRuntimeConfigScope,
|
|
329
|
+
getPublicRuntimeConfigScope,
|
|
330
|
+
getRuntimeConfigFragment,
|
|
331
|
+
getRuntimeConfigScope,
|
|
332
|
+
projectSectionedRuntimeConfig,
|
|
333
|
+
resolveRuntimeConfigValueFromRuntimeConfig,
|
|
334
|
+
toRuntimeConfigFragment
|
|
335
|
+
} from "@lorion-org/runtime-config";
|
|
336
|
+
var isObject = (value) => {
|
|
337
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
338
|
+
};
|
|
339
|
+
var toStringArray = (value) => Array.isArray(value) ? value.filter((entry) => typeof entry === "string") : [];
|
|
340
|
+
function createContextInputOptions(contextInputKey) {
|
|
341
|
+
return contextInputKey === void 0 ? {} : { contextInputKey };
|
|
342
|
+
}
|
|
343
|
+
function createPrivateOutputOptions(privateOutput) {
|
|
344
|
+
return privateOutput === void 0 ? {} : { privateOutput };
|
|
345
|
+
}
|
|
346
|
+
function withoutPublicRuntimeConfig(config) {
|
|
347
|
+
const privateConfig = { ...config };
|
|
348
|
+
delete privateConfig.public;
|
|
349
|
+
return privateConfig;
|
|
350
|
+
}
|
|
351
|
+
function normalizeNuxtRuntimeConfigFragments(fragments = {}, options = {}) {
|
|
352
|
+
if (fragments instanceof Map) {
|
|
353
|
+
const normalizedFragments = /* @__PURE__ */ new Map();
|
|
354
|
+
for (const [scopeId, config] of fragments.entries()) {
|
|
355
|
+
normalizedFragments.set(scopeId, toRuntimeConfigFragment(config, options));
|
|
356
|
+
}
|
|
357
|
+
return normalizedFragments;
|
|
358
|
+
}
|
|
359
|
+
if (Array.isArray(fragments)) {
|
|
360
|
+
return fragments.map((fragment) => ({
|
|
361
|
+
scopeId: fragment.scopeId,
|
|
362
|
+
config: toRuntimeConfigFragment(fragment.config, options)
|
|
363
|
+
}));
|
|
364
|
+
}
|
|
365
|
+
return Object.entries(fragments).map(([scopeId, config]) => ({
|
|
366
|
+
scopeId,
|
|
367
|
+
config: toRuntimeConfigFragment(config, options)
|
|
368
|
+
}));
|
|
369
|
+
}
|
|
370
|
+
function toNuxtRuntimeConfig(runtimeConfig, options = {}) {
|
|
371
|
+
if (options.privateOutput === "section") {
|
|
372
|
+
return {
|
|
373
|
+
private: {
|
|
374
|
+
...runtimeConfig.private
|
|
375
|
+
},
|
|
376
|
+
public: {
|
|
377
|
+
...runtimeConfig.public
|
|
378
|
+
}
|
|
379
|
+
};
|
|
380
|
+
}
|
|
381
|
+
return {
|
|
382
|
+
...runtimeConfig.private,
|
|
383
|
+
public: {
|
|
384
|
+
...runtimeConfig.public
|
|
385
|
+
}
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
function createNuxtRuntimeConfig(options = {}) {
|
|
389
|
+
const { contextInputKey, fragments, runtimeConfig, ...projectOptions } = options;
|
|
390
|
+
const runtimeConfigFragments = fragments ?? {};
|
|
391
|
+
const sectionedRuntimeConfig = runtimeConfig ?? projectSectionedRuntimeConfig(
|
|
392
|
+
normalizeNuxtRuntimeConfigFragments(
|
|
393
|
+
runtimeConfigFragments,
|
|
394
|
+
createContextInputOptions(contextInputKey)
|
|
395
|
+
),
|
|
396
|
+
projectOptions
|
|
397
|
+
);
|
|
398
|
+
return toNuxtRuntimeConfig(
|
|
399
|
+
sectionedRuntimeConfig,
|
|
400
|
+
createPrivateOutputOptions(options.privateOutput)
|
|
401
|
+
);
|
|
402
|
+
}
|
|
403
|
+
function mergeNuxtRuntimeConfig(target = {}, source = {}) {
|
|
404
|
+
const targetPublic = isObject(target.public) ? target.public : {};
|
|
405
|
+
const sourcePublic = isObject(source.public) ? source.public : {};
|
|
406
|
+
return {
|
|
407
|
+
...withoutPublicRuntimeConfig(target),
|
|
408
|
+
...withoutPublicRuntimeConfig(source),
|
|
409
|
+
public: {
|
|
410
|
+
...targetPublic,
|
|
411
|
+
...sourcePublic
|
|
412
|
+
}
|
|
413
|
+
};
|
|
414
|
+
}
|
|
415
|
+
function getNuxtExtensionSelection(runtimeConfig) {
|
|
416
|
+
const selection = isObject(runtimeConfig.public?.extensionSelection) ? runtimeConfig.public.extensionSelection : void 0;
|
|
417
|
+
if (!selection) {
|
|
418
|
+
return {
|
|
419
|
+
discoveredExtensionIds: [],
|
|
420
|
+
notInjectedExtensionIds: [],
|
|
421
|
+
resolvedExtensionIds: [],
|
|
422
|
+
selectedExtensionIds: []
|
|
423
|
+
};
|
|
424
|
+
}
|
|
425
|
+
const discoveredExtensionIds = toStringArray(selection.discoveredExtensionIds);
|
|
426
|
+
const resolvedExtensionIds = toStringArray(selection.resolvedExtensionIds);
|
|
427
|
+
const resolvedExtensionIdSet = new Set(resolvedExtensionIds);
|
|
428
|
+
return {
|
|
429
|
+
discoveredExtensionIds,
|
|
430
|
+
notInjectedExtensionIds: discoveredExtensionIds.filter((id) => !resolvedExtensionIdSet.has(id)).sort((left, right) => left.localeCompare(right)),
|
|
431
|
+
resolvedExtensionIds,
|
|
432
|
+
selectedExtensionIds: toStringArray(selection.selectedExtensionIds)
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
function getNuxtProviderSelection(runtimeConfig) {
|
|
436
|
+
const providerSelection = runtimeConfig.public?.providerSelection;
|
|
437
|
+
return isObject(providerSelection) && isObject(providerSelection.selections) ? providerSelection : void 0;
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
// src/runtime-config-node.ts
|
|
441
|
+
import {
|
|
442
|
+
loadRuntimeConfigSourceTree,
|
|
443
|
+
resolveRuntimeConfigSourcePublicRootPath,
|
|
444
|
+
validateRuntimeConfigSourceScopes
|
|
445
|
+
} from "@lorion-org/runtime-config-node";
|
|
446
|
+
import { toRuntimeConfigFragment as toRuntimeConfigFragment2 } from "@lorion-org/runtime-config";
|
|
447
|
+
function resolveNuxtRuntimeConfigPublicRootPath(source) {
|
|
448
|
+
return resolveRuntimeConfigSourcePublicRootPath(source);
|
|
449
|
+
}
|
|
450
|
+
function loadNuxtRuntimeConfigFragments(source, options = {}) {
|
|
451
|
+
const fragments = loadRuntimeConfigSourceTree(source);
|
|
452
|
+
const normalizedFragments = /* @__PURE__ */ new Map();
|
|
453
|
+
for (const [scopeId, config] of fragments.entries()) {
|
|
454
|
+
normalizedFragments.set(scopeId, toRuntimeConfigFragment2(config, options));
|
|
455
|
+
}
|
|
456
|
+
return normalizedFragments;
|
|
457
|
+
}
|
|
458
|
+
function createNuxtRuntimeConfigFromSource(source, options = {}) {
|
|
459
|
+
return createNuxtRuntimeConfig({
|
|
460
|
+
...options,
|
|
461
|
+
fragments: loadNuxtRuntimeConfigFragments(source, {
|
|
462
|
+
...options.contextInputKey ? { contextInputKey: options.contextInputKey } : {}
|
|
463
|
+
})
|
|
464
|
+
});
|
|
465
|
+
}
|
|
466
|
+
function validateNuxtRuntimeConfigSourceScopes(source, targets, options = {}) {
|
|
467
|
+
return validateRuntimeConfigSourceScopes(source, targets, options);
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
// src/module.ts
|
|
471
|
+
var runtimeConfigImportNames = [
|
|
472
|
+
"useRuntimeConfigFragment",
|
|
473
|
+
"useRuntimeConfigScope",
|
|
474
|
+
"usePublicRuntimeConfigScope",
|
|
475
|
+
"usePrivateRuntimeConfigScope",
|
|
476
|
+
"useRuntimeConfigValue"
|
|
477
|
+
];
|
|
478
|
+
var runtimeConfigComposablesTemplate = "lorion/runtime-config-composables.ts";
|
|
479
|
+
var serverRuntimeConfigComposablesTemplate = "#internal/lorion-runtime-config-composables.mjs";
|
|
480
|
+
var defaultRuntimeConfigSource = {
|
|
481
|
+
contextInputKey: "contexts",
|
|
482
|
+
contextOutputKey: "__contexts",
|
|
483
|
+
paths: [".runtimeconfig/runtime-config/*/runtime.config.json"]
|
|
484
|
+
};
|
|
485
|
+
var joinLogIds = (ids) => ids.join(", ");
|
|
486
|
+
var hasLogIds = (ids) => ids.length > 0;
|
|
487
|
+
function pickRuntimeConfigOptions(options, bootstrap) {
|
|
488
|
+
const runtimeConfigOptions = {};
|
|
489
|
+
if (options.contextInputKey !== void 0)
|
|
490
|
+
runtimeConfigOptions.contextInputKey = options.contextInputKey;
|
|
491
|
+
if (options.contextOutputKey !== void 0)
|
|
492
|
+
runtimeConfigOptions.contextOutputKey = options.contextOutputKey;
|
|
493
|
+
if (options.fragments !== void 0) runtimeConfigOptions.fragments = options.fragments;
|
|
494
|
+
if (options.includeContexts !== void 0)
|
|
495
|
+
runtimeConfigOptions.includeContexts = options.includeContexts;
|
|
496
|
+
if (options.keyStrategy !== void 0) runtimeConfigOptions.keyStrategy = options.keyStrategy;
|
|
497
|
+
if (options.privateOutput !== void 0)
|
|
498
|
+
runtimeConfigOptions.privateOutput = options.privateOutput;
|
|
499
|
+
if (options.runtimeConfig !== void 0)
|
|
500
|
+
runtimeConfigOptions.runtimeConfig = options.runtimeConfig;
|
|
501
|
+
if (bootstrap?.resolvedExtensionIds.length) {
|
|
502
|
+
runtimeConfigOptions.scopeIds = bootstrap.resolvedExtensionIds;
|
|
503
|
+
}
|
|
504
|
+
return runtimeConfigOptions;
|
|
505
|
+
}
|
|
506
|
+
function createRuntimeConfigComposableDefaults(options) {
|
|
507
|
+
return {
|
|
508
|
+
...options.contextOutputKey ? { contextOutputKey: options.contextOutputKey } : {},
|
|
509
|
+
privateInput: options.privateOutput === "section" ? "section" : "root"
|
|
510
|
+
};
|
|
511
|
+
}
|
|
512
|
+
function normalizeImportPath(path) {
|
|
513
|
+
return path.replace(/\\/g, "/");
|
|
514
|
+
}
|
|
515
|
+
function createRuntimeConfigComposablesSource(input) {
|
|
516
|
+
const typeImports = input.typed ? `
|
|
517
|
+
import type {
|
|
518
|
+
GetRuntimeConfigFragmentOptions,
|
|
519
|
+
GetRuntimeConfigScopeOptions,
|
|
520
|
+
ResolveRuntimeConfigValueFromRuntimeConfigOptions,
|
|
521
|
+
RuntimeConfigContext,
|
|
522
|
+
RuntimeConfigSection,
|
|
523
|
+
} from '@lorion-org/runtime-config'
|
|
524
|
+
import type {
|
|
525
|
+
NuxtPrivateRuntimeConfigMode,
|
|
526
|
+
NuxtRuntimeConfigInput,
|
|
527
|
+
ReadNuxtRuntimeConfigOptions,
|
|
528
|
+
} from '${input.runtimeConfigFrom}'
|
|
529
|
+
|
|
530
|
+
export type RuntimeConfigComposableDefaults = {
|
|
531
|
+
contextOutputKey?: string
|
|
532
|
+
privateInput?: NuxtPrivateRuntimeConfigMode
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
export type UseRuntimeConfigScopeOptions = GetRuntimeConfigScopeOptions & ReadNuxtRuntimeConfigOptions
|
|
536
|
+
export type UsePublicRuntimeConfigScopeOptions =
|
|
537
|
+
Omit<GetRuntimeConfigScopeOptions, 'visibility'> &
|
|
538
|
+
ReadNuxtRuntimeConfigOptions
|
|
539
|
+
export type UseRuntimeConfigValueOptions<T = unknown> =
|
|
540
|
+
ResolveRuntimeConfigValueFromRuntimeConfigOptions<T> &
|
|
541
|
+
ReadNuxtRuntimeConfigOptions
|
|
542
|
+
export type UseRuntimeConfigFragmentOptions =
|
|
543
|
+
GetRuntimeConfigFragmentOptions &
|
|
544
|
+
ReadNuxtRuntimeConfigOptions
|
|
545
|
+
` : "";
|
|
546
|
+
const typeAnnotations = input.typed ? {
|
|
547
|
+
defaults: ": RuntimeConfigComposableDefaults",
|
|
548
|
+
fragmentReturn: ": RuntimeConfigContext",
|
|
549
|
+
fragmentOptions: ": UseRuntimeConfigFragmentOptions",
|
|
550
|
+
privateOptions: ": UsePublicRuntimeConfigScopeOptions",
|
|
551
|
+
publicOptions: ": UsePublicRuntimeConfigScopeOptions",
|
|
552
|
+
runtimeConfig: ": NuxtRuntimeConfigInput",
|
|
553
|
+
scopeOptions: ": UseRuntimeConfigScopeOptions",
|
|
554
|
+
scopeReturn: "<T extends RuntimeConfigSection = RuntimeConfigSection>",
|
|
555
|
+
valueOptions: "<T = unknown>",
|
|
556
|
+
valueOptionsType: ": UseRuntimeConfigValueOptions<T>",
|
|
557
|
+
valueReturn: ": T | undefined"
|
|
558
|
+
} : {
|
|
559
|
+
defaults: "",
|
|
560
|
+
fragmentReturn: "",
|
|
561
|
+
fragmentOptions: "",
|
|
562
|
+
privateOptions: "",
|
|
563
|
+
publicOptions: "",
|
|
564
|
+
runtimeConfig: "",
|
|
565
|
+
scopeOptions: "",
|
|
566
|
+
scopeReturn: "",
|
|
567
|
+
valueOptions: "",
|
|
568
|
+
valueOptionsType: "",
|
|
569
|
+
valueReturn: ""
|
|
570
|
+
};
|
|
571
|
+
return `import { useRuntimeConfig } from '${input.useRuntimeConfigFrom}'
|
|
572
|
+
import {
|
|
573
|
+
getNuxtRuntimeConfigFragment,
|
|
574
|
+
getNuxtRuntimeConfigScope,
|
|
575
|
+
getPrivateNuxtRuntimeConfigScope,
|
|
576
|
+
getPublicNuxtRuntimeConfigScope,
|
|
577
|
+
resolveNuxtRuntimeConfigValue,
|
|
578
|
+
} from '${input.runtimeConfigFrom}'
|
|
579
|
+
${typeImports}
|
|
580
|
+
const runtimeConfigDefaultsKey = '__lorionNuxt'
|
|
581
|
+
|
|
582
|
+
function getComposableDefaults(runtimeConfig${typeAnnotations.runtimeConfig})${typeAnnotations.defaults} {
|
|
583
|
+
const container = runtimeConfig.public?.[runtimeConfigDefaultsKey]
|
|
584
|
+
|
|
585
|
+
if (typeof container !== 'object' || container === null || Array.isArray(container)) {
|
|
586
|
+
return {}
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
const defaults = container.runtimeConfig
|
|
590
|
+
|
|
591
|
+
return typeof defaults === 'object' && defaults !== null && !Array.isArray(defaults)
|
|
592
|
+
? defaults
|
|
593
|
+
: {}
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
function withComposableDefaults(runtimeConfig${typeAnnotations.runtimeConfig}, options = {}) {
|
|
597
|
+
return {
|
|
598
|
+
...getComposableDefaults(runtimeConfig),
|
|
599
|
+
...options,
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
export function useRuntimeConfigFragment(scopeId, options${typeAnnotations.fragmentOptions} = {})${typeAnnotations.fragmentReturn} {
|
|
604
|
+
const runtimeConfig = useRuntimeConfig()
|
|
605
|
+
|
|
606
|
+
return getNuxtRuntimeConfigFragment(runtimeConfig, scopeId, withComposableDefaults(runtimeConfig, options))
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
export function useRuntimeConfigScope${typeAnnotations.scopeReturn}(scopeId, options${typeAnnotations.scopeOptions} = {}) {
|
|
610
|
+
const runtimeConfig = useRuntimeConfig()
|
|
611
|
+
|
|
612
|
+
return getNuxtRuntimeConfigScope(runtimeConfig, scopeId, withComposableDefaults(runtimeConfig, options))
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
export function usePublicRuntimeConfigScope${typeAnnotations.scopeReturn}(scopeId, options${typeAnnotations.publicOptions} = {}) {
|
|
616
|
+
const runtimeConfig = useRuntimeConfig()
|
|
617
|
+
|
|
618
|
+
return getPublicNuxtRuntimeConfigScope(runtimeConfig, scopeId, withComposableDefaults(runtimeConfig, options))
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
export function usePrivateRuntimeConfigScope${typeAnnotations.scopeReturn}(scopeId, options${typeAnnotations.privateOptions} = {}) {
|
|
622
|
+
const runtimeConfig = useRuntimeConfig()
|
|
623
|
+
|
|
624
|
+
return getPrivateNuxtRuntimeConfigScope(runtimeConfig, scopeId, withComposableDefaults(runtimeConfig, options))
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
export function useRuntimeConfigValue${typeAnnotations.valueOptions}(scopeId, key, options${typeAnnotations.valueOptionsType} = {})${typeAnnotations.valueReturn} {
|
|
628
|
+
const runtimeConfig = useRuntimeConfig()
|
|
629
|
+
|
|
630
|
+
return resolveNuxtRuntimeConfigValue(runtimeConfig, scopeId, key, withComposableDefaults(runtimeConfig, options))
|
|
631
|
+
}
|
|
632
|
+
`;
|
|
633
|
+
}
|
|
634
|
+
function createDefaultRuntimeConfigOptions(rootDir) {
|
|
635
|
+
const paths = defaultRuntimeConfigSource.paths.map((pattern) => join2(rootDir, pattern));
|
|
636
|
+
const runtimeConfigDir = join2(rootDir, ".runtimeconfig", "runtime-config");
|
|
637
|
+
if (!existsSync2(runtimeConfigDir)) return void 0;
|
|
638
|
+
return {
|
|
639
|
+
contextInputKey: defaultRuntimeConfigSource.contextInputKey,
|
|
640
|
+
contextOutputKey: defaultRuntimeConfigSource.contextOutputKey,
|
|
641
|
+
source: { paths }
|
|
642
|
+
};
|
|
643
|
+
}
|
|
644
|
+
function resolveRuntimeConfigModuleOptions(options, rootDir) {
|
|
645
|
+
if (options?.enabled === false) return void 0;
|
|
646
|
+
return options ?? createDefaultRuntimeConfigOptions(rootDir);
|
|
647
|
+
}
|
|
648
|
+
function registerRuntimeConfigPublicAssets(options, nuxt) {
|
|
649
|
+
if (options.publicAssets === false || !options.source) return;
|
|
650
|
+
const publicRoot = resolveNuxtRuntimeConfigPublicRootPath(options.source);
|
|
651
|
+
if (!publicRoot || !existsSync2(publicRoot)) return;
|
|
652
|
+
const maxAge = typeof options.publicAssets === "object" ? options.publicAssets.maxAge : void 0;
|
|
653
|
+
const hook = nuxt.hook;
|
|
654
|
+
hook("nitro:config", (nitroConfig) => {
|
|
655
|
+
nitroConfig.publicAssets = nitroConfig.publicAssets ?? [];
|
|
656
|
+
nitroConfig.publicAssets.push({
|
|
657
|
+
dir: publicRoot,
|
|
658
|
+
...maxAge === void 0 ? {} : { maxAge }
|
|
659
|
+
});
|
|
660
|
+
});
|
|
661
|
+
}
|
|
662
|
+
function resolveRuntimeConfigValidationTargets(bootstrap) {
|
|
663
|
+
return bootstrap?.resolvedExtensions.map((extension) => ({
|
|
664
|
+
scopeId: extension.descriptor.id,
|
|
665
|
+
cwd: extension.cwd
|
|
666
|
+
})) ?? [];
|
|
667
|
+
}
|
|
668
|
+
function validateRuntimeConfigSource(options, bootstrap) {
|
|
669
|
+
if (!options.source || options.validation === false || !options.validation) return;
|
|
670
|
+
const targets = resolveRuntimeConfigValidationTargets(bootstrap);
|
|
671
|
+
if (!targets.length) return;
|
|
672
|
+
validateNuxtRuntimeConfigSourceScopes(options.source, targets, {
|
|
673
|
+
...options.validation.formatError ? { formatError: options.validation.formatError } : {},
|
|
674
|
+
...options.validation.schemaFileName ? { schemaFileName: options.validation.schemaFileName } : {}
|
|
675
|
+
});
|
|
676
|
+
}
|
|
677
|
+
function addRuntimeConfigImports(options) {
|
|
678
|
+
if (options.imports === false) return;
|
|
679
|
+
const resolver = createResolver(import.meta.url);
|
|
680
|
+
const runtimeConfigFrom = normalizeImportPath(resolver.resolve("./runtime-config"));
|
|
681
|
+
const template = addTemplate({
|
|
682
|
+
filename: runtimeConfigComposablesTemplate,
|
|
683
|
+
getContents: () => createRuntimeConfigComposablesSource({
|
|
684
|
+
runtimeConfigFrom,
|
|
685
|
+
typed: true,
|
|
686
|
+
useRuntimeConfigFrom: "nuxt/app"
|
|
687
|
+
})
|
|
688
|
+
});
|
|
689
|
+
addServerTemplate({
|
|
690
|
+
filename: serverRuntimeConfigComposablesTemplate,
|
|
691
|
+
getContents: () => createRuntimeConfigComposablesSource({
|
|
692
|
+
runtimeConfigFrom,
|
|
693
|
+
typed: false,
|
|
694
|
+
useRuntimeConfigFrom: "nitropack/runtime"
|
|
695
|
+
})
|
|
696
|
+
});
|
|
697
|
+
const imports = runtimeConfigImportNames.map((name) => ({
|
|
698
|
+
as: name,
|
|
699
|
+
from: `#build/${template.filename}`,
|
|
700
|
+
name
|
|
701
|
+
}));
|
|
702
|
+
const serverImports = runtimeConfigImportNames.map((name) => ({
|
|
703
|
+
as: name,
|
|
704
|
+
from: serverRuntimeConfigComposablesTemplate,
|
|
705
|
+
name
|
|
706
|
+
}));
|
|
707
|
+
addImports(imports);
|
|
708
|
+
addServerImports(serverImports);
|
|
709
|
+
}
|
|
710
|
+
function createRuntimeConfigDefaultsConfig(options) {
|
|
711
|
+
return {
|
|
712
|
+
public: {
|
|
713
|
+
__lorionNuxt: {
|
|
714
|
+
runtimeConfig: createRuntimeConfigComposableDefaults(options)
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
};
|
|
718
|
+
}
|
|
719
|
+
function createConfiguredNuxtRuntimeConfig(options, bootstrap) {
|
|
720
|
+
if (!options.runtimeConfig || options.runtimeConfig.enabled === false) return void 0;
|
|
721
|
+
const runtimeConfigOptions = pickRuntimeConfigOptions(options.runtimeConfig, bootstrap);
|
|
722
|
+
return options.runtimeConfig.source ? createNuxtRuntimeConfigFromSource(options.runtimeConfig.source, runtimeConfigOptions) : createNuxtRuntimeConfig(runtimeConfigOptions);
|
|
723
|
+
}
|
|
724
|
+
function applyRuntimeConfigModule(input) {
|
|
725
|
+
const runtimeConfigOptions = resolveRuntimeConfigModuleOptions(
|
|
726
|
+
input.moduleOptions,
|
|
727
|
+
input.rootDir
|
|
728
|
+
);
|
|
729
|
+
const runtimeConfig = runtimeConfigOptions ? createConfiguredNuxtRuntimeConfig({ runtimeConfig: runtimeConfigOptions }, input.bootstrap) : void 0;
|
|
730
|
+
if (!runtimeConfigOptions) return input.currentRuntimeConfig;
|
|
731
|
+
addRuntimeConfigImports(runtimeConfigOptions);
|
|
732
|
+
registerRuntimeConfigPublicAssets(runtimeConfigOptions, input.nuxt);
|
|
733
|
+
validateRuntimeConfigSource(runtimeConfigOptions, input.bootstrap);
|
|
734
|
+
return mergeNuxtRuntimeConfig(
|
|
735
|
+
input.currentRuntimeConfig,
|
|
736
|
+
mergeNuxtRuntimeConfig(createRuntimeConfigDefaultsConfig(runtimeConfigOptions), runtimeConfig)
|
|
737
|
+
);
|
|
738
|
+
}
|
|
739
|
+
function createProviderSelectionRuntimeConfig(bootstrap, options) {
|
|
740
|
+
if (options?.enabled === false) return void 0;
|
|
741
|
+
return createNuxtProviderSelectionRuntimeConfig(bootstrap.resolvedExtensions, options);
|
|
742
|
+
}
|
|
743
|
+
function createNuxtExtensionBootstrapLogEvent(input) {
|
|
744
|
+
const providerSelection = input.providerSelectionRuntimeConfig ? getNuxtProviderSelection(input.providerSelectionRuntimeConfig) : void 0;
|
|
745
|
+
return {
|
|
746
|
+
bootstrap: input.bootstrap,
|
|
747
|
+
...providerSelection ? { providerSelection } : {}
|
|
748
|
+
};
|
|
749
|
+
}
|
|
750
|
+
function formatNuxtExtensionBootstrapLog(event) {
|
|
751
|
+
const lines = ["LORION Nuxt"];
|
|
752
|
+
const bootstrap = event.bootstrap;
|
|
753
|
+
const extensionSelection = getNuxtExtensionSelection(bootstrap.publicRuntimeConfig);
|
|
754
|
+
if (hasLogIds(bootstrap.selectedExtensions)) {
|
|
755
|
+
lines.push(`Selected: ${joinLogIds(bootstrap.selectedExtensions)}`);
|
|
756
|
+
}
|
|
757
|
+
if (hasLogIds(bootstrap.baseExtensionIds)) {
|
|
758
|
+
lines.push(`Base: ${joinLogIds(bootstrap.baseExtensionIds)}`);
|
|
759
|
+
}
|
|
760
|
+
lines.push(`Descriptors found: ${bootstrap.discoveredExtensions.length}`);
|
|
761
|
+
if (hasLogIds(bootstrap.resolvedExtensionIds)) {
|
|
762
|
+
lines.push(`Injected: ${joinLogIds(bootstrap.resolvedExtensionIds)}`);
|
|
763
|
+
}
|
|
764
|
+
if (hasLogIds(extensionSelection.notInjectedExtensionIds)) {
|
|
765
|
+
lines.push(`Not injected: ${joinLogIds(extensionSelection.notInjectedExtensionIds)}`);
|
|
766
|
+
}
|
|
767
|
+
const providerSelections = Object.values(event.providerSelection?.selections ?? {}).sort(
|
|
768
|
+
(left, right) => left.capabilityId.localeCompare(right.capabilityId)
|
|
769
|
+
);
|
|
770
|
+
for (const selection of providerSelections) {
|
|
771
|
+
lines.push(`Provider ${selection.capabilityId}: ${selection.selectedProviderId}`);
|
|
772
|
+
}
|
|
773
|
+
return lines.join("\n");
|
|
774
|
+
}
|
|
775
|
+
function reportNuxtExtensionBootstrap(input) {
|
|
776
|
+
if (!input.logging || input.logging === true || !input.logging.reporter) return;
|
|
777
|
+
input.logging.reporter(
|
|
778
|
+
createNuxtExtensionBootstrapLogEvent({
|
|
779
|
+
bootstrap: input.bootstrap,
|
|
780
|
+
...input.providerSelectionRuntimeConfig ? { providerSelectionRuntimeConfig: input.providerSelectionRuntimeConfig } : {}
|
|
781
|
+
})
|
|
782
|
+
);
|
|
783
|
+
}
|
|
784
|
+
function getLayerRoot(layer) {
|
|
785
|
+
return layer.config.rootDir ?? layer.cwd;
|
|
786
|
+
}
|
|
787
|
+
function createLayerConfig(extension) {
|
|
788
|
+
return {
|
|
789
|
+
cwd: extension.cwd,
|
|
790
|
+
configFile: "",
|
|
791
|
+
config: {
|
|
792
|
+
rootDir: extension.cwd,
|
|
793
|
+
serverDir: extension.serverDir ?? join2(extension.cwd, "server"),
|
|
794
|
+
srcDir: extension.appDir ?? extension.cwd
|
|
795
|
+
}
|
|
796
|
+
};
|
|
797
|
+
}
|
|
798
|
+
function registerFileOnlyExtensionLayers(bootstrap, nuxtOptions) {
|
|
799
|
+
const fileOnlyExtensions = bootstrap.activeExtensions.filter(
|
|
800
|
+
(extension) => !extension.configFile
|
|
801
|
+
);
|
|
802
|
+
if (!fileOnlyExtensions.length) return;
|
|
803
|
+
const options = nuxtOptions;
|
|
804
|
+
const layers = [...options._layers];
|
|
805
|
+
const existingRoots = new Set(layers.map((layer) => getLayerRoot(layer)));
|
|
806
|
+
const extensionLayers = fileOnlyExtensions.filter((extension) => {
|
|
807
|
+
if (existingRoots.has(extension.cwd)) return false;
|
|
808
|
+
existingRoots.add(extension.cwd);
|
|
809
|
+
return true;
|
|
810
|
+
}).map(createLayerConfig);
|
|
811
|
+
if (!extensionLayers.length) return;
|
|
812
|
+
const [projectLayer, ...baseLayers] = layers;
|
|
813
|
+
options._layers = projectLayer ? [projectLayer, ...extensionLayers, ...baseLayers] : [...extensionLayers];
|
|
814
|
+
}
|
|
815
|
+
var lorionNuxtModule = defineNuxtModule({
|
|
816
|
+
meta: {
|
|
817
|
+
name: "@lorion-org/nuxt",
|
|
818
|
+
configKey: "lorion"
|
|
819
|
+
},
|
|
820
|
+
setup(options, nuxt) {
|
|
821
|
+
const bootstrap = options.extensionBootstrap ?? (options.extensions?.enabled === false || !options.extensions ? void 0 : createNuxtExtensionBootstrap({
|
|
822
|
+
rootDir: nuxt.options.rootDir,
|
|
823
|
+
options: options.extensions
|
|
824
|
+
}));
|
|
825
|
+
if (bootstrap) {
|
|
826
|
+
const providerSelectionRuntimeConfig = createProviderSelectionRuntimeConfig(
|
|
827
|
+
bootstrap,
|
|
828
|
+
options.providers
|
|
829
|
+
);
|
|
830
|
+
const logger = useLogger("@lorion-org/nuxt");
|
|
831
|
+
const logging = options.logging === true ? {
|
|
832
|
+
reporter: (event) => logger.info(formatNuxtExtensionBootstrapLog(event))
|
|
833
|
+
} : options.logging;
|
|
834
|
+
reportNuxtExtensionBootstrap({
|
|
835
|
+
bootstrap,
|
|
836
|
+
logging,
|
|
837
|
+
...providerSelectionRuntimeConfig ? { providerSelectionRuntimeConfig } : {}
|
|
838
|
+
});
|
|
839
|
+
registerFileOnlyExtensionLayers(bootstrap, nuxt.options);
|
|
840
|
+
nuxt.options.runtimeConfig = mergeNuxtRuntimeConfig(
|
|
841
|
+
nuxt.options.runtimeConfig,
|
|
842
|
+
mergeNuxtRuntimeConfig(bootstrap.publicRuntimeConfig, providerSelectionRuntimeConfig)
|
|
843
|
+
);
|
|
844
|
+
}
|
|
845
|
+
nuxt.options.runtimeConfig = applyRuntimeConfigModule({
|
|
846
|
+
...bootstrap ? { bootstrap } : {},
|
|
847
|
+
currentRuntimeConfig: nuxt.options.runtimeConfig,
|
|
848
|
+
nuxt,
|
|
849
|
+
rootDir: nuxt.options.rootDir,
|
|
850
|
+
...options.runtimeConfig ? { moduleOptions: options.runtimeConfig } : {}
|
|
851
|
+
});
|
|
852
|
+
}
|
|
853
|
+
});
|
|
854
|
+
var module_default = lorionNuxtModule;
|
|
855
|
+
export {
|
|
856
|
+
createNuxtExtensionBootstrap,
|
|
857
|
+
createNuxtExtensionBootstrapLogEvent,
|
|
858
|
+
createNuxtExtensionLayerPaths,
|
|
859
|
+
createNuxtProviderSelectionRuntimeConfig,
|
|
860
|
+
module_default as default,
|
|
861
|
+
formatNuxtExtensionBootstrapLog,
|
|
862
|
+
reportNuxtExtensionBootstrap,
|
|
863
|
+
resolveExtensionSelection
|
|
864
|
+
};
|