silgi 0.24.18 → 0.24.19
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/dist/_chunks/path.mjs +62 -0
- package/dist/cli/dev.mjs +5 -42
- package/dist/cli/env.mjs +40 -0
- package/dist/cli/index.mjs +1 -1
- package/dist/cli/install.mjs +2 -34
- package/dist/cli/prepare.mjs +7 -9
- package/dist/index.d.mts +272 -7
- package/dist/index.mjs +4164 -41
- package/dist/kit/index.mjs +24 -51
- package/dist/runtime/internal/config.mjs +3 -3
- package/dist/runtime/internal/nitro.d.mts +1 -1
- package/dist/runtime/internal/nitro.mjs +5 -5
- package/package.json +1 -2
- package/dist/_chunks/routeRules.mjs +0 -311
- package/dist/cli/compatibility.mjs +0 -30
- package/dist/cli/config/index.d.mts +0 -11
- package/dist/cli/config/index.mjs +0 -16
- package/dist/cli/types.mjs +0 -772
- package/dist/cli/writeTypesAndFiles.mjs +0 -2376
- package/dist/core/index.d.mts +0 -271
- package/dist/core/index.mjs +0 -763
package/dist/kit/index.mjs
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import { consola } from 'consola';
|
|
2
|
+
import { tryUseSilgi, useSilgi, useSilgiApp } from 'silgi';
|
|
3
3
|
import fsp from 'node:fs/promises';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
4
|
+
import { dirname, resolve, normalize, isAbsolute, join, relative, parse, basename } from 'pathe';
|
|
5
|
+
import { p as prettyPath, c as checkSilgiCompatibility } from '../_chunks/path.mjs';
|
|
6
|
+
export { r as resolveSilgiPath } from '../_chunks/path.mjs';
|
|
7
7
|
import { hash as hash$1 } from 'ohash';
|
|
8
8
|
import { camelCase } from 'scule';
|
|
9
9
|
import { defu } from 'defu';
|
|
10
|
-
import { c as checkSilgiCompatibility } from '../cli/compatibility.mjs';
|
|
11
10
|
import { withLeadingSlash } from 'ufo';
|
|
12
11
|
import { existsSync, promises } from 'node:fs';
|
|
13
12
|
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
@@ -17,49 +16,23 @@ import { hash as hash$2 } from 'silgi/kit';
|
|
|
17
16
|
import { genString, genObjectFromRaw, genObjectFromValues, genObjectFromRawEntries } from 'knitwork';
|
|
18
17
|
import 'semver/functions/satisfies.js';
|
|
19
18
|
import 'silgi/meta';
|
|
19
|
+
import 'consola/utils';
|
|
20
|
+
import 'dot-prop';
|
|
20
21
|
|
|
21
22
|
function useLogger(tag, options = {}) {
|
|
22
23
|
return tag ? consola.create(options).withTag(tag) : consola;
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
function hasError(type, silgi) {
|
|
26
|
-
silgi = silgi ??
|
|
27
|
+
silgi = silgi ?? tryUseSilgi() ?? void 0;
|
|
27
28
|
if (silgi && silgi.errors.some((error) => error.type === type)) {
|
|
28
29
|
return true;
|
|
29
30
|
}
|
|
30
31
|
return false;
|
|
31
32
|
}
|
|
32
33
|
|
|
33
|
-
function prettyPath(p, highlight = true) {
|
|
34
|
-
p = relative(process.cwd(), p);
|
|
35
|
-
return highlight ? colors.cyan(p) : p;
|
|
36
|
-
}
|
|
37
|
-
function resolveSilgiPath(path, silgiCLIOptions, base) {
|
|
38
|
-
if (typeof path !== "string") {
|
|
39
|
-
throw new TypeError(`Invalid path: ${path}`);
|
|
40
|
-
}
|
|
41
|
-
path = _compilePathTemplate(path)(silgiCLIOptions);
|
|
42
|
-
for (const base2 in silgiCLIOptions.alias) {
|
|
43
|
-
if (path.startsWith(base2)) {
|
|
44
|
-
path = silgiCLIOptions.alias[base2] + path.slice(base2.length);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
return resolve(base || silgiCLIOptions.srcDir, path);
|
|
48
|
-
}
|
|
49
|
-
function _compilePathTemplate(contents) {
|
|
50
|
-
return (params) => contents.replace(/\{\{ ?([\w.]+) ?\}\}/g, (_, match) => {
|
|
51
|
-
const val = getProperty(params, match);
|
|
52
|
-
if (!val) {
|
|
53
|
-
consola$1.warn(
|
|
54
|
-
`cannot resolve template param '${match}' in ${contents.slice(0, 20)}`
|
|
55
|
-
);
|
|
56
|
-
}
|
|
57
|
-
return val || `${match}`;
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
|
|
61
34
|
async function writeFile(file, contents, log = false) {
|
|
62
|
-
const silgi =
|
|
35
|
+
const silgi = useSilgi();
|
|
63
36
|
if (silgi.errors.length) {
|
|
64
37
|
return;
|
|
65
38
|
}
|
|
@@ -99,14 +72,14 @@ function _defineSilgiModule(definition) {
|
|
|
99
72
|
}
|
|
100
73
|
const module = defu(definition, { meta: {} });
|
|
101
74
|
module.meta.configKey ||= module.meta.name;
|
|
102
|
-
async function getOptions(inlineOptions, silgi =
|
|
75
|
+
async function getOptions(inlineOptions, silgi = useSilgi()) {
|
|
103
76
|
const nuxtConfigOptionsKey = module.meta.configKey || module.meta.name;
|
|
104
77
|
const nuxtConfigOptions = nuxtConfigOptionsKey && nuxtConfigOptionsKey in silgi.options ? silgi.options[nuxtConfigOptionsKey] : {};
|
|
105
78
|
const optionsDefaults = typeof module.defaults === "function" ? await module.defaults(silgi) : module.defaults ?? {};
|
|
106
79
|
const options = defu(inlineOptions, nuxtConfigOptions, optionsDefaults);
|
|
107
80
|
return Promise.resolve(options);
|
|
108
81
|
}
|
|
109
|
-
async function silgiNormalizedModule(inlineOptions, silgi =
|
|
82
|
+
async function silgiNormalizedModule(inlineOptions, silgi = tryUseSilgi()) {
|
|
110
83
|
if (!silgi) {
|
|
111
84
|
throw new TypeError("Cannot use module outside of Silgi context");
|
|
112
85
|
}
|
|
@@ -253,7 +226,7 @@ async function isDirectory(path) {
|
|
|
253
226
|
return (await promises.lstat(path)).isDirectory();
|
|
254
227
|
}
|
|
255
228
|
function resolveAlias(path, alias) {
|
|
256
|
-
alias ||=
|
|
229
|
+
alias ||= tryUseSilgi()?.options.alias || {};
|
|
257
230
|
return resolveAlias$1(path, alias || {});
|
|
258
231
|
}
|
|
259
232
|
function createResolver(base) {
|
|
@@ -299,10 +272,10 @@ function filterInPlace(array, predicate) {
|
|
|
299
272
|
return array;
|
|
300
273
|
}
|
|
301
274
|
const MODE_RE = /\.(server|client)(\.\w+)*$/;
|
|
302
|
-
function hasSilgiModule(moduleKey, silgi =
|
|
275
|
+
function hasSilgiModule(moduleKey, silgi = useSilgi()) {
|
|
303
276
|
return silgi.scanModules.some(({ meta }) => meta.configKey === moduleKey) || Object.keys(silgi.scanModules).includes(moduleKey);
|
|
304
277
|
}
|
|
305
|
-
function hasInstalledModule(moduleKey, silgi =
|
|
278
|
+
function hasInstalledModule(moduleKey, silgi = useSilgi()) {
|
|
306
279
|
const find = silgi.scanModules.find(({ meta }) => meta.configKey === moduleKey);
|
|
307
280
|
return find?.installed ?? false;
|
|
308
281
|
}
|
|
@@ -314,7 +287,7 @@ const baseHeaderBannerComment = [
|
|
|
314
287
|
"/* tslint:disable */"
|
|
315
288
|
];
|
|
316
289
|
function processFilePath(src) {
|
|
317
|
-
const silgi =
|
|
290
|
+
const silgi = useSilgi();
|
|
318
291
|
if (silgi.options.typescript.removeFileExtension) {
|
|
319
292
|
src = src.replace(/\.ts$/, "");
|
|
320
293
|
return src;
|
|
@@ -323,7 +296,7 @@ function processFilePath(src) {
|
|
|
323
296
|
}
|
|
324
297
|
|
|
325
298
|
function addTemplate(_template) {
|
|
326
|
-
const silgi =
|
|
299
|
+
const silgi = useSilgi();
|
|
327
300
|
const template = normalizeTemplate(_template);
|
|
328
301
|
filterInPlace(silgi.options.build.templates, (p) => normalizeTemplate(p).dst !== template.dst);
|
|
329
302
|
silgi.options.build.templates.push(template);
|
|
@@ -357,7 +330,7 @@ function normalizeTemplate(template, buildDir) {
|
|
|
357
330
|
template.write = true;
|
|
358
331
|
}
|
|
359
332
|
if (!template.dst) {
|
|
360
|
-
const silgi =
|
|
333
|
+
const silgi = useSilgi();
|
|
361
334
|
const dir = template.where === ".silgi" ? silgi.options.build.dir : template.where === "server" ? silgi.options.silgi.serverDir : template.where === "client" ? silgi.options.silgi.clientDir : silgi.options.silgi.serverDir;
|
|
362
335
|
template.dst = resolve(buildDir ?? dir, template.filename);
|
|
363
336
|
}
|
|
@@ -365,21 +338,21 @@ function normalizeTemplate(template, buildDir) {
|
|
|
365
338
|
}
|
|
366
339
|
|
|
367
340
|
function useRequest(event) {
|
|
368
|
-
const silgi =
|
|
341
|
+
const silgi = useSilgiApp();
|
|
369
342
|
if (silgi.options.present === "nuxt" || silgi.options.present === "nitro" || silgi.options.present === "h3") {
|
|
370
343
|
return event.node.req;
|
|
371
344
|
}
|
|
372
345
|
return event;
|
|
373
346
|
}
|
|
374
347
|
function useResponse(event) {
|
|
375
|
-
const silgi =
|
|
348
|
+
const silgi = useSilgiApp();
|
|
376
349
|
if (silgi.options.present === "nuxt" || silgi.options.present === "nitro" || silgi.options.present === "h3") {
|
|
377
350
|
return event.node.res;
|
|
378
351
|
}
|
|
379
352
|
return event;
|
|
380
353
|
}
|
|
381
354
|
function getIpAddress(event) {
|
|
382
|
-
const silgi =
|
|
355
|
+
const silgi = useSilgiApp();
|
|
383
356
|
if (silgi.options.present === "nuxt" || silgi.options.present === "nitro" || silgi.options.present === "h3") {
|
|
384
357
|
const _ipAddress = ipAddress(event.node.req);
|
|
385
358
|
return _ipAddress;
|
|
@@ -504,25 +477,25 @@ function getAllEntries(obj) {
|
|
|
504
477
|
}
|
|
505
478
|
|
|
506
479
|
function isNuxt() {
|
|
507
|
-
const silgi =
|
|
480
|
+
const silgi = useSilgiApp();
|
|
508
481
|
if (silgi.options.present === "nitro" || silgi.options.present === "h3" || silgi.options.present === "nuxt") {
|
|
509
482
|
return true;
|
|
510
483
|
}
|
|
511
484
|
return false;
|
|
512
485
|
}
|
|
513
486
|
function isNitro() {
|
|
514
|
-
const silgi =
|
|
487
|
+
const silgi = useSilgiApp();
|
|
515
488
|
if (silgi.options.present === "nitro" || silgi.options.present === "h3") {
|
|
516
489
|
return true;
|
|
517
490
|
}
|
|
518
491
|
return false;
|
|
519
492
|
}
|
|
520
493
|
function isH3() {
|
|
521
|
-
const silgi =
|
|
494
|
+
const silgi = useSilgiApp();
|
|
522
495
|
if (silgi.options.present === "h3") {
|
|
523
496
|
return true;
|
|
524
497
|
}
|
|
525
498
|
return false;
|
|
526
499
|
}
|
|
527
500
|
|
|
528
|
-
export { MODE_RE, addTemplate, baseHeaderBannerComment, createResolver, defineSilgiModule, defineSilgiPreset, directoryToURL, filterInPlace, genEnsureSafeVar, getAllEntries, getIpAddress, hasError, hasInstalledModule, hasSilgiModule, hash, ipAddress, isDirectory$1 as isDirectory, isH3, isNitro, isNuxt, normalizeTemplate, parseServices, prettyPath, processFilePath, relativeWithDot, resolveAlias, resolvePath, resolveSilgiModule,
|
|
501
|
+
export { MODE_RE, addTemplate, baseHeaderBannerComment, createResolver, defineSilgiModule, defineSilgiPreset, directoryToURL, filterInPlace, genEnsureSafeVar, getAllEntries, getIpAddress, hasError, hasInstalledModule, hasSilgiModule, hash, ipAddress, isDirectory$1 as isDirectory, isH3, isNitro, isNuxt, normalizeTemplate, parseServices, prettyPath, processFilePath, relativeWithDot, resolveAlias, resolvePath, resolveSilgiModule, serviceParseModule, toArray, tryResolveModule, useLogger, useRequest, useResponse, writeFile };
|
|
@@ -2,7 +2,7 @@ import defu from "defu";
|
|
|
2
2
|
import destr from "destr";
|
|
3
3
|
import { klona } from "klona";
|
|
4
4
|
import { snakeCase } from "scule";
|
|
5
|
-
import {
|
|
5
|
+
import { tryUseSilgiApp, useSilgiApp } from "silgi";
|
|
6
6
|
let silgiRuntimeConfig = globalThis.__nitro__?.useRuntimeConfig?.() || process.env.RUNTIME_CONFIG;
|
|
7
7
|
let envOptions = {
|
|
8
8
|
prefix: "NITRO_",
|
|
@@ -26,7 +26,7 @@ export function useSilgiRuntimeConfig(event, inlineRuntimeConfig = {}) {
|
|
|
26
26
|
applyEnv(klona(silgiRuntimeConfig ?? {}), envOptions)
|
|
27
27
|
);
|
|
28
28
|
}
|
|
29
|
-
const silgi =
|
|
29
|
+
const silgi = tryUseSilgiApp();
|
|
30
30
|
if (!silgi) {
|
|
31
31
|
if (globalThis.$silgiSharedRuntimeConfig) {
|
|
32
32
|
inlineRuntimeConfig = globalThis.$silgiSharedRuntimeConfig;
|
|
@@ -67,7 +67,7 @@ export function initRuntimeConfig(envOptions2 = {}, inlineRuntimeConfig = {}) {
|
|
|
67
67
|
);
|
|
68
68
|
}
|
|
69
69
|
export function updateRuntimeConfig(runtimeConfig) {
|
|
70
|
-
const nuxt =
|
|
70
|
+
const nuxt = useSilgiApp();
|
|
71
71
|
Object.assign(nuxt.options.nitro.runtimeConfig, defu(runtimeConfig, nuxt.options.nitro.runtimeConfig));
|
|
72
72
|
try {
|
|
73
73
|
} catch {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createError, defineEventHandler, getQuery, H3Error, readBody } from "h3";
|
|
2
|
-
import { ErrorFactory, HttpStatus, parseURI, silgi, SilgiError,
|
|
3
|
-
export async function addNitroApp(
|
|
4
|
-
const nitro =
|
|
2
|
+
import { ErrorFactory, HttpStatus, parseURI, silgi, SilgiError, useSilgiApp } from "silgi";
|
|
3
|
+
export async function addNitroApp(silgiAppCtx = useSilgiApp()) {
|
|
4
|
+
const nitro = silgiAppCtx.framework;
|
|
5
5
|
nitro.router.use("/srn/**", defineEventHandler(async (event) => {
|
|
6
6
|
try {
|
|
7
7
|
const silgiConnect = silgi(event);
|
|
@@ -13,11 +13,11 @@ export async function addNitroApp(silgiCtx = useSilgi()) {
|
|
|
13
13
|
} else {
|
|
14
14
|
newPath = `${event.path}?method=${event.method}`;
|
|
15
15
|
}
|
|
16
|
-
const operation = parseURI(newPath,
|
|
16
|
+
const operation = parseURI(newPath, silgiAppCtx.uris);
|
|
17
17
|
if (!operation) {
|
|
18
18
|
throw ErrorFactory.create({ message: "Invalid URI", httpStatus: HttpStatus.BAD_REQUEST });
|
|
19
19
|
}
|
|
20
|
-
await
|
|
20
|
+
await silgiAppCtx.callHook("event:init", event, {
|
|
21
21
|
path: newPath,
|
|
22
22
|
queryParams: query,
|
|
23
23
|
operation
|
package/package.json
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "silgi",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.24.
|
|
4
|
+
"version": "0.24.19",
|
|
5
5
|
"private": false,
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"exports": {
|
|
8
8
|
"./package.json": "./package.json",
|
|
9
9
|
".": "./dist/index.mjs",
|
|
10
10
|
"./cli": "./dist/cli/index.mjs",
|
|
11
|
-
"./cli/config": "./dist/cli/config/index.mjs",
|
|
12
11
|
"./kit": "./dist/kit/index.mjs",
|
|
13
12
|
"./config": "./lib/config.mjs",
|
|
14
13
|
"./types": "./dist/types/index.d.mts",
|
|
@@ -1,311 +0,0 @@
|
|
|
1
|
-
import consola from 'consola';
|
|
2
|
-
import { createContext } from 'unctx';
|
|
3
|
-
import { withoutTrailingSlash, withLeadingSlash } from 'ufo';
|
|
4
|
-
|
|
5
|
-
const silgiCLICtx = createContext();
|
|
6
|
-
function useSilgiCLI() {
|
|
7
|
-
const instance = silgiCLICtx.tryUse();
|
|
8
|
-
if (!instance) {
|
|
9
|
-
throw new Error("Silgi instance is unavailable!");
|
|
10
|
-
}
|
|
11
|
-
return instance;
|
|
12
|
-
}
|
|
13
|
-
async function silgiCLIIClose() {
|
|
14
|
-
const silgi = silgiCLICtx.tryUse();
|
|
15
|
-
if (!silgi) {
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
await silgi.close();
|
|
19
|
-
await silgi.callHook("close", silgi);
|
|
20
|
-
consola.withTag("silgi").success("Process terminated");
|
|
21
|
-
}
|
|
22
|
-
function tryUseSilgiCLI() {
|
|
23
|
-
return silgiCLICtx.tryUse();
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function patternToRegex(pattern) {
|
|
27
|
-
let regexStr = pattern.replace(/[.+?^${}()|[\]\\]/g, "\\$&");
|
|
28
|
-
regexStr = regexStr.replace(/\*\*/g, ".+");
|
|
29
|
-
regexStr = regexStr.replace(/\*/g, "[^/]+");
|
|
30
|
-
regexStr = regexStr.replace(/:([^/]+)/g, "([^/]+)");
|
|
31
|
-
return new RegExp(`^${regexStr}$`);
|
|
32
|
-
}
|
|
33
|
-
function extractParams(url, pattern) {
|
|
34
|
-
url = withoutTrailingSlash(withLeadingSlash(url));
|
|
35
|
-
pattern = withoutTrailingSlash(withLeadingSlash(pattern));
|
|
36
|
-
if (!pattern.includes(":"))
|
|
37
|
-
return null;
|
|
38
|
-
const paramNames = [];
|
|
39
|
-
const patternRegex = pattern.replace(/:([^/]+)/g, (_, name) => {
|
|
40
|
-
paramNames.push(name);
|
|
41
|
-
return "([^/]+)";
|
|
42
|
-
});
|
|
43
|
-
const regex = new RegExp(`^${patternRegex}$`);
|
|
44
|
-
const matches = url.match(regex);
|
|
45
|
-
if (!matches)
|
|
46
|
-
return null;
|
|
47
|
-
const params = {};
|
|
48
|
-
paramNames.forEach((name, i) => {
|
|
49
|
-
params[name] = matches[i + 1];
|
|
50
|
-
});
|
|
51
|
-
return Object.keys(params).length > 0 ? params : null;
|
|
52
|
-
}
|
|
53
|
-
function matchesPattern(url, pattern) {
|
|
54
|
-
url = withoutTrailingSlash(withLeadingSlash(url));
|
|
55
|
-
pattern = withoutTrailingSlash(withLeadingSlash(pattern));
|
|
56
|
-
if (url === pattern)
|
|
57
|
-
return true;
|
|
58
|
-
if (pattern.endsWith("/**")) {
|
|
59
|
-
const basePath = pattern.slice(0, -3);
|
|
60
|
-
return url === basePath || url.startsWith(`${basePath}/`);
|
|
61
|
-
}
|
|
62
|
-
const urlParts = url.split("/");
|
|
63
|
-
const patternParts = pattern.split("/");
|
|
64
|
-
if (!pattern.includes("**") && urlParts.length !== patternParts.length) {
|
|
65
|
-
return false;
|
|
66
|
-
}
|
|
67
|
-
if (pattern.includes("/**/")) {
|
|
68
|
-
const [prefix, ...suffixParts] = pattern.split("/**/");
|
|
69
|
-
const suffix = suffixParts.join("/");
|
|
70
|
-
return url.startsWith(prefix) && (!suffix || url.endsWith(`/${suffix}`));
|
|
71
|
-
}
|
|
72
|
-
return patternToRegex(pattern).test(url);
|
|
73
|
-
}
|
|
74
|
-
function deepClone(obj) {
|
|
75
|
-
if (obj === null || typeof obj !== "object")
|
|
76
|
-
return obj;
|
|
77
|
-
if (typeof obj === "function")
|
|
78
|
-
return obj;
|
|
79
|
-
if (Array.isArray(obj))
|
|
80
|
-
return obj.map(deepClone);
|
|
81
|
-
const cloned = {};
|
|
82
|
-
for (const key in obj) {
|
|
83
|
-
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
84
|
-
cloned[key] = deepClone(obj[key]);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
return cloned;
|
|
88
|
-
}
|
|
89
|
-
function mergeConfigs(...configs) {
|
|
90
|
-
const result = {};
|
|
91
|
-
for (const config of configs) {
|
|
92
|
-
if (!config)
|
|
93
|
-
continue;
|
|
94
|
-
for (const key in config) {
|
|
95
|
-
const value = config[key];
|
|
96
|
-
if (value && typeof value === "object" && !Array.isArray(value) && result[key] && typeof result[key] === "object" && typeof result[key] !== "function") {
|
|
97
|
-
const resultValue = result[key];
|
|
98
|
-
const valueToMerge = value;
|
|
99
|
-
result[key] = mergeConfigs(resultValue, valueToMerge);
|
|
100
|
-
} else {
|
|
101
|
-
result[key] = value;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
return result;
|
|
106
|
-
}
|
|
107
|
-
function createRouteRules() {
|
|
108
|
-
let _rules = {};
|
|
109
|
-
let _mergedRules = {};
|
|
110
|
-
let _rulesModified = false;
|
|
111
|
-
function getRules() {
|
|
112
|
-
return deepClone(_rules);
|
|
113
|
-
}
|
|
114
|
-
function importRules(config) {
|
|
115
|
-
const normalizedConfig = {};
|
|
116
|
-
for (const pattern in config) {
|
|
117
|
-
normalizedConfig[withoutTrailingSlash(withLeadingSlash(pattern))] = deepClone(config[pattern]);
|
|
118
|
-
}
|
|
119
|
-
_rules = normalizedConfig;
|
|
120
|
-
_rulesModified = true;
|
|
121
|
-
updateMergeRules();
|
|
122
|
-
}
|
|
123
|
-
function exportRules() {
|
|
124
|
-
return deepClone(_rules);
|
|
125
|
-
}
|
|
126
|
-
function addRule(pattern, config) {
|
|
127
|
-
_rules[withoutTrailingSlash(withLeadingSlash(pattern))] = deepClone(config);
|
|
128
|
-
_rulesModified = true;
|
|
129
|
-
updateMergeRules();
|
|
130
|
-
}
|
|
131
|
-
function updateRule(pattern, config) {
|
|
132
|
-
const normalizedPattern = withoutTrailingSlash(withLeadingSlash(pattern));
|
|
133
|
-
if (_rules[normalizedPattern]) {
|
|
134
|
-
_rules[normalizedPattern] = { ..._rules[normalizedPattern], ...deepClone(config) };
|
|
135
|
-
} else {
|
|
136
|
-
_rules[normalizedPattern] = deepClone(config);
|
|
137
|
-
}
|
|
138
|
-
_rulesModified = true;
|
|
139
|
-
updateMergeRules();
|
|
140
|
-
}
|
|
141
|
-
function removeRule(pattern) {
|
|
142
|
-
delete _rules[withoutTrailingSlash(withLeadingSlash(pattern))];
|
|
143
|
-
_rulesModified = true;
|
|
144
|
-
updateMergeRules();
|
|
145
|
-
}
|
|
146
|
-
function matchesRule(url, pattern) {
|
|
147
|
-
return matchesPattern(withoutTrailingSlash(withLeadingSlash(url)), withoutTrailingSlash(withLeadingSlash(pattern)));
|
|
148
|
-
}
|
|
149
|
-
function getMatchingPatterns(url) {
|
|
150
|
-
const normalizedUrl = withoutTrailingSlash(withLeadingSlash(url));
|
|
151
|
-
return Object.keys(_rules).filter((pattern) => matchesPattern(normalizedUrl, pattern)).sort((a, b) => {
|
|
152
|
-
if (a === url)
|
|
153
|
-
return -1;
|
|
154
|
-
if (b === url)
|
|
155
|
-
return 1;
|
|
156
|
-
const aSegments = a.split("/").filter(Boolean).length;
|
|
157
|
-
const bSegments = b.split("/").filter(Boolean).length;
|
|
158
|
-
if (aSegments !== bSegments)
|
|
159
|
-
return bSegments - aSegments;
|
|
160
|
-
const aWildcards = (a.match(/\*/g) || []).length;
|
|
161
|
-
const bWildcards = (b.match(/\*/g) || []).length;
|
|
162
|
-
if (aWildcards !== bWildcards)
|
|
163
|
-
return aWildcards - bWildcards;
|
|
164
|
-
const aDoubleWildcards = (a.match(/\*\*/g) || []).length;
|
|
165
|
-
const bDoubleWildcards = (b.match(/\*\*/g) || []).length;
|
|
166
|
-
if (aDoubleWildcards !== bDoubleWildcards)
|
|
167
|
-
return aDoubleWildcards - bDoubleWildcards;
|
|
168
|
-
return b.length - a.length;
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
|
-
function getConfig(url) {
|
|
172
|
-
const normalizedUrl = withoutTrailingSlash(withLeadingSlash(url));
|
|
173
|
-
if (_rulesModified) {
|
|
174
|
-
updateMergeRules();
|
|
175
|
-
}
|
|
176
|
-
if (_mergedRules[normalizedUrl]) {
|
|
177
|
-
return deepClone(_mergedRules[normalizedUrl]);
|
|
178
|
-
}
|
|
179
|
-
const patterns = getMatchingPatterns(normalizedUrl);
|
|
180
|
-
if (!patterns.length)
|
|
181
|
-
return null;
|
|
182
|
-
const mergedConfig = {};
|
|
183
|
-
for (let i = patterns.length - 1; i >= 0; i--) {
|
|
184
|
-
const pattern = patterns[i];
|
|
185
|
-
const patternConfig = _mergedRules[pattern] || _rules[pattern];
|
|
186
|
-
Object.assign(mergedConfig, deepClone(patternConfig));
|
|
187
|
-
}
|
|
188
|
-
_mergedRules[normalizedUrl] = deepClone(mergedConfig);
|
|
189
|
-
return mergedConfig;
|
|
190
|
-
}
|
|
191
|
-
function computeMergedConfig(url, patterns) {
|
|
192
|
-
const normalizedUrl = withoutTrailingSlash(withLeadingSlash(url));
|
|
193
|
-
const matchingPatterns = patterns || getMatchingPatterns(normalizedUrl);
|
|
194
|
-
if (!matchingPatterns.length)
|
|
195
|
-
return {};
|
|
196
|
-
const allPatternsHaveCache = matchingPatterns.every((pattern) => !!_mergedRules[pattern]);
|
|
197
|
-
if (allPatternsHaveCache) {
|
|
198
|
-
return matchingPatterns.reduceRight((result, pattern) => mergeConfigs(result, deepClone(_mergedRules[pattern])), {});
|
|
199
|
-
}
|
|
200
|
-
return matchingPatterns.reduceRight((result, pattern) => mergeConfigs(result, deepClone(_rules[pattern])), {});
|
|
201
|
-
}
|
|
202
|
-
function getParams(url, pattern) {
|
|
203
|
-
return extractParams(withoutTrailingSlash(withLeadingSlash(url)), withoutTrailingSlash(withLeadingSlash(pattern)));
|
|
204
|
-
}
|
|
205
|
-
function match(url) {
|
|
206
|
-
const normalizedUrl = withoutTrailingSlash(withLeadingSlash(url));
|
|
207
|
-
const patterns = getMatchingPatterns(normalizedUrl);
|
|
208
|
-
if (!patterns.length)
|
|
209
|
-
return null;
|
|
210
|
-
const bestPattern = patterns[0];
|
|
211
|
-
return {
|
|
212
|
-
pattern: bestPattern,
|
|
213
|
-
config: deepClone(_rules[bestPattern]),
|
|
214
|
-
params: getParams(normalizedUrl, bestPattern)
|
|
215
|
-
};
|
|
216
|
-
}
|
|
217
|
-
function clear() {
|
|
218
|
-
_rules = {};
|
|
219
|
-
clearMergedRules();
|
|
220
|
-
_rulesModified = false;
|
|
221
|
-
}
|
|
222
|
-
function clearMergedRules() {
|
|
223
|
-
_mergedRules = {};
|
|
224
|
-
_rulesModified = true;
|
|
225
|
-
}
|
|
226
|
-
function precomputeMergedRules(urls) {
|
|
227
|
-
if (_rulesModified) {
|
|
228
|
-
updateMergeRules();
|
|
229
|
-
}
|
|
230
|
-
for (const url of urls) {
|
|
231
|
-
const normalizedUrl = withoutTrailingSlash(withLeadingSlash(url));
|
|
232
|
-
if (!_mergedRules[normalizedUrl]) {
|
|
233
|
-
const patterns = getMatchingPatterns(normalizedUrl);
|
|
234
|
-
if (patterns.length) {
|
|
235
|
-
_mergedRules[normalizedUrl] = computeMergedConfig(normalizedUrl, patterns);
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
function setMergedRule(url, config) {
|
|
241
|
-
const normalizedUrl = withoutTrailingSlash(withLeadingSlash(url));
|
|
242
|
-
_mergedRules[normalizedUrl] = deepClone(config);
|
|
243
|
-
if (url.includes("*") || url.includes(":")) {
|
|
244
|
-
_rulesModified = false;
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
function getMergedRules() {
|
|
248
|
-
return deepClone(_mergedRules);
|
|
249
|
-
}
|
|
250
|
-
function configure(config) {
|
|
251
|
-
importRules(config);
|
|
252
|
-
}
|
|
253
|
-
function updateMergeRules() {
|
|
254
|
-
if (!_rulesModified) {
|
|
255
|
-
return _mergedRules;
|
|
256
|
-
}
|
|
257
|
-
_mergedRules = {};
|
|
258
|
-
const rulePatterns = Object.keys(_rules);
|
|
259
|
-
for (const pattern of rulePatterns) {
|
|
260
|
-
const patterns = getMatchingPatterns(pattern);
|
|
261
|
-
_mergedRules[pattern] = computeMergedConfig(pattern, patterns);
|
|
262
|
-
}
|
|
263
|
-
for (const pattern of rulePatterns) {
|
|
264
|
-
if (pattern.includes("/:")) {
|
|
265
|
-
const segments = pattern.split("/");
|
|
266
|
-
let partialPath = "";
|
|
267
|
-
for (const segment of segments) {
|
|
268
|
-
if (segment) {
|
|
269
|
-
partialPath += `/${segment}`;
|
|
270
|
-
if (segment.startsWith(":") && partialPath !== pattern) {
|
|
271
|
-
const samplePath = partialPath.replace(/:\w+/g, "sample");
|
|
272
|
-
const patterns = getMatchingPatterns(samplePath);
|
|
273
|
-
_mergedRules[samplePath] = computeMergedConfig(samplePath, patterns);
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
_rulesModified = false;
|
|
280
|
-
return _mergedRules;
|
|
281
|
-
}
|
|
282
|
-
return {
|
|
283
|
-
// Public getters that return a cloned version to prevent direct modification
|
|
284
|
-
get rules() {
|
|
285
|
-
return getRules();
|
|
286
|
-
},
|
|
287
|
-
get mergedRules() {
|
|
288
|
-
return getMergedRules();
|
|
289
|
-
},
|
|
290
|
-
// API methods
|
|
291
|
-
importRules,
|
|
292
|
-
exportRules,
|
|
293
|
-
addRule,
|
|
294
|
-
updateRule,
|
|
295
|
-
removeRule,
|
|
296
|
-
matchesRule,
|
|
297
|
-
getMatchingPatterns,
|
|
298
|
-
getConfig,
|
|
299
|
-
getParams,
|
|
300
|
-
match,
|
|
301
|
-
clear,
|
|
302
|
-
clearMergedRules,
|
|
303
|
-
precomputeMergedRules,
|
|
304
|
-
setMergedRule,
|
|
305
|
-
getMergedRules,
|
|
306
|
-
configure,
|
|
307
|
-
updateMergeRules
|
|
308
|
-
};
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
export { silgiCLIIClose as a, createRouteRules as c, silgiCLICtx as s, tryUseSilgiCLI as t, useSilgiCLI as u };
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import satisfies from 'semver/functions/satisfies.js';
|
|
2
|
-
import { useSilgiCLI } from 'silgi';
|
|
3
|
-
import { version } from 'silgi/meta';
|
|
4
|
-
|
|
5
|
-
const SEMANTIC_VERSION_RE = /-\d+\.[0-9a-f]+/;
|
|
6
|
-
function normalizeSemanticVersion(version) {
|
|
7
|
-
return version.replace(SEMANTIC_VERSION_RE, "");
|
|
8
|
-
}
|
|
9
|
-
const SILGI_VERSION_RE = /^v/g;
|
|
10
|
-
async function checkSilgiCompatibility(constraints, silgi = useSilgiCLI()) {
|
|
11
|
-
const issues = [];
|
|
12
|
-
if (constraints.silgi) {
|
|
13
|
-
const _silgiVersion = version.replace(SILGI_VERSION_RE, "");
|
|
14
|
-
if (!satisfies(normalizeSemanticVersion(_silgiVersion), constraints.silgi, { includePrerelease: true })) {
|
|
15
|
-
issues.push({
|
|
16
|
-
name: "silgi",
|
|
17
|
-
message: `Silgi version \`${constraints.silgi}\` is required but currently using \`${version}\``
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
await silgi.callHook("kit:compatibility", constraints, issues);
|
|
22
|
-
issues.toString = () => issues.map((issue) => ` - [${issue.name}] ${issue.message}`).join("\n");
|
|
23
|
-
return issues;
|
|
24
|
-
}
|
|
25
|
-
function hasInstalledModule(moduleKey, silgi = useSilgiCLI()) {
|
|
26
|
-
const find = silgi.scanModules.find(({ meta }) => meta.configKey === moduleKey);
|
|
27
|
-
return find?.installed ?? false;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export { checkSilgiCompatibility as c, hasInstalledModule as h };
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { SilgiCLIConfig, LoadConfigOptions, SilgiCLIOptions, SilgiCLI } from 'silgi/types';
|
|
2
|
-
import { TSConfig } from 'pkg-types';
|
|
3
|
-
|
|
4
|
-
declare function loadOptions(configOverrides?: SilgiCLIConfig, opts?: LoadConfigOptions): Promise<SilgiCLIOptions>;
|
|
5
|
-
|
|
6
|
-
declare function silgiGenerateType(silgi: SilgiCLI): Promise<{
|
|
7
|
-
declarations: string[];
|
|
8
|
-
tsConfig: TSConfig;
|
|
9
|
-
}>;
|
|
10
|
-
|
|
11
|
-
export { loadOptions, silgiGenerateType };
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export { l as loadOptions, s as silgiGenerateType } from '../types.mjs';
|
|
2
|
-
import 'c12';
|
|
3
|
-
import 'compatx';
|
|
4
|
-
import 'klona/full';
|
|
5
|
-
import 'std-env';
|
|
6
|
-
import 'consola';
|
|
7
|
-
import 'consola/utils';
|
|
8
|
-
import 'pathe';
|
|
9
|
-
import 'escape-string-regexp';
|
|
10
|
-
import 'mlly';
|
|
11
|
-
import 'node:fs';
|
|
12
|
-
import 'pkg-types';
|
|
13
|
-
import 'silgi/kit';
|
|
14
|
-
import 'silgi/runtime/meta';
|
|
15
|
-
import 'ufo';
|
|
16
|
-
import 'defu';
|