silgi 0.23.1 → 0.23.3
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/index.mjs +1 -1
- package/dist/cli/prepare.mjs +13 -15
- package/dist/kit/index.d.mts +5 -1
- package/dist/kit/index.d.ts +5 -1
- package/dist/kit/index.mjs +50 -1
- package/package.json +1 -1
package/dist/_chunks/index.mjs
CHANGED
package/dist/cli/prepare.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { defineCommand, runCommand } from 'citty';
|
|
2
2
|
import { join, resolve, relative, dirname, basename, extname, isAbsolute } from 'pathe';
|
|
3
3
|
import { peerDependencies, version } from 'silgi/meta';
|
|
4
|
-
import { genObjectFromRawEntries, genObjectFromRaw, genObjectFromValues
|
|
5
|
-
import { writeFile, relativeWithDot, hash, resolveAlias, directoryToURL, addTemplate, hasError, parseServices, useSilgiRuntimeConfig, normalizeTemplate, useLogger, initRuntimeConfig, resolveSilgiPath, isDirectory } from 'silgi/kit';
|
|
4
|
+
import { genObjectFromRawEntries, genObjectFromRaw, genObjectFromValues } from 'knitwork';
|
|
5
|
+
import { writeFile, relativeWithDot, hash, resolveAlias, directoryToURL, addTemplate, hasError, parseServices, useSilgiRuntimeConfig, normalizeTemplate, useLogger, initRuntimeConfig, resolveSilgiPath, genEnsureSafeVar, isDirectory } from 'silgi/kit';
|
|
6
6
|
import { existsSync, promises, readFileSync, writeFileSync, mkdirSync } from 'node:fs';
|
|
7
7
|
import { readdir, readFile } from 'node:fs/promises';
|
|
8
8
|
import consola, { consola as consola$1 } from 'consola';
|
|
@@ -861,6 +861,13 @@ function resolveGroupSyntax(group) {
|
|
|
861
861
|
return groups;
|
|
862
862
|
}
|
|
863
863
|
|
|
864
|
+
const safeFiles = [
|
|
865
|
+
"silgi/configs",
|
|
866
|
+
"silgi/core",
|
|
867
|
+
"silgi/rules",
|
|
868
|
+
"silgi/scan",
|
|
869
|
+
"silgi/vfs"
|
|
870
|
+
];
|
|
864
871
|
class SchemaParser {
|
|
865
872
|
options = {
|
|
866
873
|
debug: false
|
|
@@ -887,6 +894,8 @@ class SchemaParser {
|
|
|
887
894
|
parseVariableDeclaration(ast, path) {
|
|
888
895
|
const silgi = useSilgiCLI();
|
|
889
896
|
if (ast.program.body.length === 0) {
|
|
897
|
+
if (safeFiles.find((i) => path.includes(i)))
|
|
898
|
+
return [];
|
|
890
899
|
silgi.errors.push({
|
|
891
900
|
type: "Parser",
|
|
892
901
|
path
|
|
@@ -899,6 +908,8 @@ class SchemaParser {
|
|
|
899
908
|
parseTSInterfaceDeclaration(ast, path = "") {
|
|
900
909
|
const silgi = useSilgiCLI();
|
|
901
910
|
if (ast.program.body.length === 0) {
|
|
911
|
+
if (safeFiles.find((i) => path.includes(i)))
|
|
912
|
+
return [];
|
|
902
913
|
silgi.errors.push({
|
|
903
914
|
type: "Parser",
|
|
904
915
|
path
|
|
@@ -1716,19 +1727,6 @@ async function createSilgiCLI(config = {}, opts = {}) {
|
|
|
1716
1727
|
return silgi;
|
|
1717
1728
|
}
|
|
1718
1729
|
|
|
1719
|
-
const reservedCode = /* @__PURE__ */ new Set([
|
|
1720
|
-
"process",
|
|
1721
|
-
"global",
|
|
1722
|
-
"Buffer",
|
|
1723
|
-
"runtime",
|
|
1724
|
-
"runtimeConfig"
|
|
1725
|
-
]);
|
|
1726
|
-
function genEnsureSafeVar(name) {
|
|
1727
|
-
if (reservedCode.has(name)) {
|
|
1728
|
-
return name;
|
|
1729
|
-
}
|
|
1730
|
-
return genString(name);
|
|
1731
|
-
}
|
|
1732
1730
|
async function prepareConfigs(silgi) {
|
|
1733
1731
|
const _data = {
|
|
1734
1732
|
runtimeConfig: {}
|
package/dist/kit/index.d.mts
CHANGED
|
@@ -18,6 +18,9 @@ declare function tryResolveModule(id: string, url?: string | string[]): Promise<
|
|
|
18
18
|
declare function writeFile(file: string, contents: Buffer | string, log?: boolean): Promise<void>;
|
|
19
19
|
declare function isDirectory(path: string): Promise<boolean>;
|
|
20
20
|
|
|
21
|
+
declare function genEnsureSafeVar(name: string | any): string;
|
|
22
|
+
declare function getAllEntries(obj: object): [string, any][];
|
|
23
|
+
|
|
21
24
|
declare function hash(data: any): string;
|
|
22
25
|
|
|
23
26
|
declare function isNuxt(): boolean;
|
|
@@ -152,5 +155,6 @@ declare const MODE_RE: RegExp;
|
|
|
152
155
|
*/
|
|
153
156
|
declare function hasSilgiModule(moduleKey: string, silgi?: SilgiCLI): boolean;
|
|
154
157
|
declare function hasInstalledModule(moduleKey: string, silgi?: SilgiCLI): boolean;
|
|
158
|
+
declare const baseHeaderBannerComment: string[];
|
|
155
159
|
|
|
156
|
-
export { MODE_RE, addTemplate, applyEnv, createResolver, defineSilgiModule, defineSilgiPreset, directoryToURL, filterInPlace, getIpAddress, hasError, hasInstalledModule, hasSilgiModule, hash, initRuntimeConfig, ipAddress, isDirectory, isH3, isNitro, isNuxt, normalizeTemplate, parseServices, prettyPath, relativeWithDot, resolveAlias, resolvePath, resolveSilgiModule, resolveSilgiPath, serviceParseModule, toArray, tryResolveModule, useLogger, useRequest, useResponse, useSilgiRuntimeConfig, writeFile };
|
|
160
|
+
export { MODE_RE, addTemplate, applyEnv, baseHeaderBannerComment, createResolver, defineSilgiModule, defineSilgiPreset, directoryToURL, filterInPlace, genEnsureSafeVar, getAllEntries, getIpAddress, hasError, hasInstalledModule, hasSilgiModule, hash, initRuntimeConfig, ipAddress, isDirectory, isH3, isNitro, isNuxt, normalizeTemplate, parseServices, prettyPath, relativeWithDot, resolveAlias, resolvePath, resolveSilgiModule, resolveSilgiPath, serviceParseModule, toArray, tryResolveModule, useLogger, useRequest, useResponse, useSilgiRuntimeConfig, writeFile };
|
package/dist/kit/index.d.ts
CHANGED
|
@@ -18,6 +18,9 @@ declare function tryResolveModule(id: string, url?: string | string[]): Promise<
|
|
|
18
18
|
declare function writeFile(file: string, contents: Buffer | string, log?: boolean): Promise<void>;
|
|
19
19
|
declare function isDirectory(path: string): Promise<boolean>;
|
|
20
20
|
|
|
21
|
+
declare function genEnsureSafeVar(name: string | any): string;
|
|
22
|
+
declare function getAllEntries(obj: object): [string, any][];
|
|
23
|
+
|
|
21
24
|
declare function hash(data: any): string;
|
|
22
25
|
|
|
23
26
|
declare function isNuxt(): boolean;
|
|
@@ -152,5 +155,6 @@ declare const MODE_RE: RegExp;
|
|
|
152
155
|
*/
|
|
153
156
|
declare function hasSilgiModule(moduleKey: string, silgi?: SilgiCLI): boolean;
|
|
154
157
|
declare function hasInstalledModule(moduleKey: string, silgi?: SilgiCLI): boolean;
|
|
158
|
+
declare const baseHeaderBannerComment: string[];
|
|
155
159
|
|
|
156
|
-
export { MODE_RE, addTemplate, applyEnv, createResolver, defineSilgiModule, defineSilgiPreset, directoryToURL, filterInPlace, getIpAddress, hasError, hasInstalledModule, hasSilgiModule, hash, initRuntimeConfig, ipAddress, isDirectory, isH3, isNitro, isNuxt, normalizeTemplate, parseServices, prettyPath, relativeWithDot, resolveAlias, resolvePath, resolveSilgiModule, resolveSilgiPath, serviceParseModule, toArray, tryResolveModule, useLogger, useRequest, useResponse, useSilgiRuntimeConfig, writeFile };
|
|
160
|
+
export { MODE_RE, addTemplate, applyEnv, baseHeaderBannerComment, createResolver, defineSilgiModule, defineSilgiPreset, directoryToURL, filterInPlace, genEnsureSafeVar, getAllEntries, getIpAddress, hasError, hasInstalledModule, hasSilgiModule, hash, initRuntimeConfig, ipAddress, isDirectory, isH3, isNitro, isNuxt, normalizeTemplate, parseServices, prettyPath, relativeWithDot, resolveAlias, resolvePath, resolveSilgiModule, resolveSilgiPath, serviceParseModule, toArray, tryResolveModule, useLogger, useRequest, useResponse, useSilgiRuntimeConfig, writeFile };
|
package/dist/kit/index.mjs
CHANGED
|
@@ -6,6 +6,7 @@ import consola, { consola as consola$1 } from 'consola';
|
|
|
6
6
|
import { relative, resolve, dirname, normalize, isAbsolute, join, parse, basename } from 'pathe';
|
|
7
7
|
import { colors } from 'consola/utils';
|
|
8
8
|
import { getProperty } from 'dot-prop';
|
|
9
|
+
import { genString, genObjectFromRaw, genObjectFromValues, genObjectFromRawEntries } from 'knitwork';
|
|
9
10
|
import { hash as hash$1 } from 'ohash';
|
|
10
11
|
import { camelCase, snakeCase } from 'scule';
|
|
11
12
|
import { defu } from 'defu';
|
|
@@ -88,6 +89,47 @@ async function isDirectory$1(path) {
|
|
|
88
89
|
}
|
|
89
90
|
}
|
|
90
91
|
|
|
92
|
+
const reservedCode = /* @__PURE__ */ new Set([
|
|
93
|
+
"process",
|
|
94
|
+
"global",
|
|
95
|
+
"runtime",
|
|
96
|
+
"runtimeConfig"
|
|
97
|
+
]);
|
|
98
|
+
function genEnsureSafeVar(name) {
|
|
99
|
+
if (typeof name !== "string") {
|
|
100
|
+
return genString(name);
|
|
101
|
+
}
|
|
102
|
+
for (const reserved of reservedCode) {
|
|
103
|
+
if (name === reserved || name.startsWith(`${reserved}.`)) {
|
|
104
|
+
return name;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return genString(name);
|
|
108
|
+
}
|
|
109
|
+
function getAllEntries(obj) {
|
|
110
|
+
return Object.entries(obj).map(([
|
|
111
|
+
key,
|
|
112
|
+
value
|
|
113
|
+
]) => {
|
|
114
|
+
if (typeof value === "function") {
|
|
115
|
+
return [key, genObjectFromRaw(value)];
|
|
116
|
+
}
|
|
117
|
+
if (typeof value === "string") {
|
|
118
|
+
return [key, genEnsureSafeVar(value)];
|
|
119
|
+
}
|
|
120
|
+
if (typeof value === "object" && value !== null) {
|
|
121
|
+
if (Array.isArray(value)) {
|
|
122
|
+
return [key, genObjectFromValues(value.map(
|
|
123
|
+
(item) => typeof item === "object" && item !== null ? genObjectFromRawEntries(getAllEntries(item)) : item
|
|
124
|
+
))];
|
|
125
|
+
} else {
|
|
126
|
+
return [key, genObjectFromRawEntries(getAllEntries(value))];
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return [key, value];
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
|
|
91
133
|
function hash(data) {
|
|
92
134
|
return camelCase(hash$1(data));
|
|
93
135
|
}
|
|
@@ -439,6 +481,13 @@ function hasInstalledModule(moduleKey, silgi = useSilgiCLI()) {
|
|
|
439
481
|
const find = silgi.scanModules.find(({ meta }) => meta.configKey === moduleKey);
|
|
440
482
|
return find?.installed ?? false;
|
|
441
483
|
}
|
|
484
|
+
const baseHeaderBannerComment = [
|
|
485
|
+
"// DO NOT EDIT THIS FILE",
|
|
486
|
+
"// This file is generated by Silgi",
|
|
487
|
+
"/* eslint-disable */",
|
|
488
|
+
"/* prettier-ignore */",
|
|
489
|
+
"/* tslint:disable */"
|
|
490
|
+
];
|
|
442
491
|
|
|
443
492
|
function addTemplate(_template) {
|
|
444
493
|
const silgi = useSilgiCLI();
|
|
@@ -570,4 +619,4 @@ function isValidIp(ip) {
|
|
|
570
619
|
return false;
|
|
571
620
|
}
|
|
572
621
|
|
|
573
|
-
export { MODE_RE, addTemplate, applyEnv, createResolver, defineSilgiModule, defineSilgiPreset, directoryToURL, filterInPlace, getIpAddress, hasError, hasInstalledModule, hasSilgiModule, hash, initRuntimeConfig, ipAddress, isDirectory$1 as isDirectory, isH3, isNitro, isNuxt, normalizeTemplate, parseServices, prettyPath, relativeWithDot, resolveAlias, resolvePath, resolveSilgiModule, resolveSilgiPath, serviceParseModule, toArray, tryResolveModule, useLogger, useRequest, useResponse, useSilgiRuntimeConfig, writeFile };
|
|
622
|
+
export { MODE_RE, addTemplate, applyEnv, baseHeaderBannerComment, createResolver, defineSilgiModule, defineSilgiPreset, directoryToURL, filterInPlace, genEnsureSafeVar, getAllEntries, getIpAddress, hasError, hasInstalledModule, hasSilgiModule, hash, initRuntimeConfig, ipAddress, isDirectory$1 as isDirectory, isH3, isNitro, isNuxt, normalizeTemplate, parseServices, prettyPath, relativeWithDot, resolveAlias, resolvePath, resolveSilgiModule, resolveSilgiPath, serviceParseModule, toArray, tryResolveModule, useLogger, useRequest, useResponse, useSilgiRuntimeConfig, writeFile };
|