silgi 0.23.0 → 0.23.2

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.
@@ -1,4 +1,4 @@
1
- const version = "0.23.0";
1
+ const version = "0.23.2";
2
2
  const peerDependencies = {
3
3
  "@fastify/deepmerge": "^3.0.0",
4
4
  "@nuxt/kit": "^3.15.3",
@@ -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, genString } from 'knitwork';
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
@@ -1504,6 +1515,9 @@ async function generateApp(app, options = {}) {
1504
1515
  }
1505
1516
  if (template.modified && template.write) {
1506
1517
  dirs.add(dirname(fullPath));
1518
+ if (template.skipIfExists && existsSync(fullPath)) {
1519
+ return;
1520
+ }
1507
1521
  writes.push(() => writeFileSync(fullPath, contents, "utf8"));
1508
1522
  }
1509
1523
  }
@@ -1713,19 +1727,6 @@ async function createSilgiCLI(config = {}, opts = {}) {
1713
1727
  return silgi;
1714
1728
  }
1715
1729
 
1716
- const reservedCode = /* @__PURE__ */ new Set([
1717
- "process",
1718
- "global",
1719
- "Buffer",
1720
- "runtime",
1721
- "runtimeConfig"
1722
- ]);
1723
- function genEnsureSafeVar(name) {
1724
- if (reservedCode.has(name)) {
1725
- return name;
1726
- }
1727
- return genString(name);
1728
- }
1729
1730
  async function prepareConfigs(silgi) {
1730
1731
  const _data = {
1731
1732
  runtimeConfig: {}
@@ -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;
@@ -153,4 +156,4 @@ declare const MODE_RE: RegExp;
153
156
  declare function hasSilgiModule(moduleKey: string, silgi?: SilgiCLI): boolean;
154
157
  declare function hasInstalledModule(moduleKey: string, silgi?: SilgiCLI): boolean;
155
158
 
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 };
159
+ export { MODE_RE, addTemplate, applyEnv, 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 };
@@ -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;
@@ -153,4 +156,4 @@ declare const MODE_RE: RegExp;
153
156
  declare function hasSilgiModule(moduleKey: string, silgi?: SilgiCLI): boolean;
154
157
  declare function hasInstalledModule(moduleKey: string, silgi?: SilgiCLI): boolean;
155
158
 
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 };
159
+ export { MODE_RE, addTemplate, applyEnv, 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 };
@@ -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
  }
@@ -570,4 +612,4 @@ function isValidIp(ip) {
570
612
  return false;
571
613
  }
572
614
 
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 };
615
+ export { MODE_RE, addTemplate, applyEnv, 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 };
@@ -143,6 +143,7 @@ interface SilgiTemplate<Options = TemplateDefaultOptions> {
143
143
  }) => string | Promise<string>;
144
144
  /** Write to filesystem */
145
145
  write?: boolean;
146
+ skipIfExists?: boolean;
146
147
  }
147
148
  interface ResolvedSilgiTemplate<Options = TemplateDefaultOptions> extends SilgiTemplate<Options> {
148
149
  filename: string;
@@ -143,6 +143,7 @@ interface SilgiTemplate<Options = TemplateDefaultOptions> {
143
143
  }) => string | Promise<string>;
144
144
  /** Write to filesystem */
145
145
  write?: boolean;
146
+ skipIfExists?: boolean;
146
147
  }
147
148
  interface ResolvedSilgiTemplate<Options = TemplateDefaultOptions> extends SilgiTemplate<Options> {
148
149
  filename: string;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "silgi",
3
3
  "type": "module",
4
- "version": "0.23.0",
4
+ "version": "0.23.2",
5
5
  "private": false,
6
6
  "sideEffects": false,
7
7
  "exports": {