silgi 0.7.0 → 0.7.1

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.
Files changed (77) hide show
  1. package/dist/cli/build/framework/h3.mjs +46 -0
  2. package/dist/cli/build/framework/index.mjs +7 -0
  3. package/dist/cli/build/framework/nitro.mjs +28 -0
  4. package/dist/cli/build/framework/nuxt.mjs +9 -0
  5. package/dist/cli/build/prepare.mjs +7 -0
  6. package/dist/cli/build/scanURIs.mjs +27 -0
  7. package/dist/cli/build/template/framework.mjs +91 -0
  8. package/dist/cli/build/template/schema.mjs +115 -0
  9. package/dist/cli/build/template/silgi.mjs +149 -0
  10. package/dist/cli/build/types.mjs +130 -0
  11. package/dist/cli/commands/prepare.mjs +49 -0
  12. package/dist/cli/common.mjs +13 -0
  13. package/dist/cli/core/app.mjs +89 -0
  14. package/dist/cli/core/scan.mjs +40 -0
  15. package/dist/cli/core/silgi.mjs +77 -0
  16. package/dist/cli/core/storage.mjs +11 -0
  17. package/dist/cli/core/templates.mjs +29 -0
  18. package/dist/cli/index.mjs +3 -3
  19. package/dist/cli/module/exportScan.mjs +69 -0
  20. package/dist/cli/module/install.mjs +52 -0
  21. package/dist/cli/module/scan.mjs +141 -0
  22. package/dist/cli/{compatibility.mjs → utils/compatibility.mjs} +1 -1
  23. package/dist/cli/utils/generateRouterDTS.mjs +84 -0
  24. package/dist/cli/utils/ignore.mjs +46 -0
  25. package/dist/cli/utils/readCoreFile.mjs +47 -0
  26. package/dist/cli/utils/scan.mjs +147 -0
  27. package/dist/cli/utils/storage.mjs +21 -0
  28. package/dist/cli/utils/uri.mjs +71 -0
  29. package/dist/core/config/defaults.mjs +96 -0
  30. package/dist/core/config/loader.mjs +98 -0
  31. package/dist/core/config/resolvers/compatibility.mjs +90 -0
  32. package/dist/core/config/resolvers/imports.mjs +96 -0
  33. package/dist/core/config/resolvers/paths.mjs +194 -0
  34. package/dist/core/config/resolvers/storage.mjs +25 -0
  35. package/dist/core/config/resolvers/url.mjs +7 -0
  36. package/dist/core/config/types.mjs +160 -0
  37. package/dist/core/createSilgi.mjs +84 -0
  38. package/dist/core/error.mjs +227 -0
  39. package/dist/core/fetch/ofetch.mjs +35 -0
  40. package/dist/core/index.mjs +16 -1678
  41. package/dist/core/parser.mjs +136 -0
  42. package/dist/core/silgi.mjs +114 -0
  43. package/dist/core/silgiApp.mjs +15 -0
  44. package/dist/core/unctx.mjs +27 -0
  45. package/dist/core/uris/uri.mjs +33 -0
  46. package/dist/core/uris/utils.mjs +127 -0
  47. package/dist/core/utils/event.mjs +5 -0
  48. package/dist/core/utils/global.mjs +12 -0
  49. package/dist/core/utils/merge.mjs +25 -0
  50. package/dist/core/utils/schema.mjs +5 -0
  51. package/dist/core/utils/service.mjs +5 -0
  52. package/dist/core/utils/shared.mjs +5 -0
  53. package/dist/core/utils/storage.mjs +70 -0
  54. package/dist/ecosystem/nitro/index.mjs +1 -62
  55. package/dist/ecosystem/nitro/module.mjs +62 -0
  56. package/dist/kit/esm.mjs +10 -0
  57. package/dist/kit/fs.mjs +25 -0
  58. package/dist/kit/index.mjs +10 -299
  59. package/dist/kit/isFramework.mjs +25 -0
  60. package/dist/kit/logger.mjs +8 -0
  61. package/dist/kit/module.mjs +73 -0
  62. package/dist/kit/path.mjs +34 -0
  63. package/dist/kit/preset.mjs +6 -0
  64. package/dist/kit/resolve.mjs +78 -0
  65. package/dist/kit/template.mjs +47 -0
  66. package/dist/kit/utils.mjs +20 -0
  67. package/dist/meta/index.d.mts +1 -1
  68. package/dist/meta/index.d.ts +1 -1
  69. package/dist/meta/index.mjs +1 -1
  70. package/dist/package.json.mjs +5 -0
  71. package/dist/schema/common.mjs +43 -0
  72. package/dist/schema/index.mjs +9 -0
  73. package/dist/schema/internal.mjs +22 -0
  74. package/package.json +1 -1
  75. package/dist/_chunks/index.mjs +0 -5
  76. package/dist/cli/prepare.mjs +0 -1481
  77. /package/dist/cli/{init.mjs → commands/init.mjs} +0 -0
@@ -0,0 +1,47 @@
1
+ import { promises } from 'node:fs';
2
+ import { createJiti } from 'dev-jiti';
3
+ import { resolve } from 'pathe';
4
+
5
+ async function readCoreFile(silgi) {
6
+ const path = resolve(silgi.options.silgi.serverDir, "core.ts");
7
+ const context = await promises.readFile(path, { encoding: "utf-8" });
8
+ const injectedResult = await silgi.unimport.injectImports(context, path);
9
+ if (!injectedResult) {
10
+ throw new Error("Failed to inject imports");
11
+ }
12
+ const jiti = createJiti(silgi.options.rootDir, {
13
+ fsCache: false,
14
+ moduleCache: false,
15
+ debug: silgi.options.debug,
16
+ alias: silgi.options.alias
17
+ });
18
+ const coreFile = await jiti.evalModule(
19
+ injectedResult.code,
20
+ {
21
+ filename: path,
22
+ async: true,
23
+ conditions: silgi.options.conditions
24
+ },
25
+ async (data, name) => {
26
+ return (await silgi.unimport.injectImports(data, name)).code;
27
+ }
28
+ );
29
+ silgi.uris = coreFile.uris;
30
+ silgi.schemas = coreFile.schemas;
31
+ silgi.services = coreFile.services;
32
+ silgi.shareds = coreFile.shareds;
33
+ silgi.modulesURIs = coreFile.modulesURIs;
34
+ return {
35
+ context,
36
+ object: {
37
+ schemas: coreFile.schemas,
38
+ uris: coreFile.uris,
39
+ services: coreFile.services,
40
+ shareds: coreFile.shareds,
41
+ modulesURIs: coreFile.modulesURIs
42
+ },
43
+ path
44
+ };
45
+ }
46
+
47
+ export { readCoreFile };
@@ -0,0 +1,147 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import { readdir } from 'node:fs/promises';
3
+ import { consola } from 'consola';
4
+ import { globby } from 'globby';
5
+ import { dirname, basename, relative, join, resolve, extname } from 'pathe';
6
+ import { SchemaParser } from 'silgi/core';
7
+ import { relativeWithDot } from 'silgi/kit';
8
+ import { withTrailingSlash } from 'ufo';
9
+ import { isIgnored } from './ignore.mjs';
10
+
11
+ async function scanFiles(silgi) {
12
+ const filePaths = /* @__PURE__ */ new Set();
13
+ const scannedPaths = [];
14
+ const dir = silgi.options.serverDir;
15
+ const files = (await globby(dir, { cwd: silgi.options.rootDir, ignore: silgi.options.ignore })).sort();
16
+ if (files.length) {
17
+ const siblings = await readdir(dirname(dir)).catch(() => []);
18
+ const directory = basename(dir);
19
+ if (!siblings.includes(directory)) {
20
+ const directoryLowerCase = directory.toLowerCase();
21
+ const caseCorrected = siblings.find((sibling) => sibling.toLowerCase() === directoryLowerCase);
22
+ if (caseCorrected) {
23
+ const original = relative(silgi.options.serverDir, dir);
24
+ const corrected = relative(silgi.options.serverDir, join(dirname(dir), caseCorrected));
25
+ consola.warn(`Components not scanned from \`~/${corrected}\`. Did you mean to name the directory \`~/${original}\` instead?`);
26
+ }
27
+ }
28
+ }
29
+ for (const _file of files) {
30
+ const filePath = resolve(dir, _file);
31
+ if (scannedPaths.find((d) => filePath.startsWith(withTrailingSlash(d))) || isIgnored(filePath, silgi)) {
32
+ continue;
33
+ }
34
+ if (filePaths.has(filePath)) {
35
+ continue;
36
+ }
37
+ filePaths.add(filePath);
38
+ if (silgi.options.extensions.includes(extname(filePath))) {
39
+ const parser = new SchemaParser({
40
+ debug: false
41
+ });
42
+ const readfile = readFileSync(filePath, "utf-8");
43
+ const { exportVariables, parseInterfaceDeclarations } = parser.parseExports(readfile, filePath);
44
+ const createServices = exportVariables("createService", filePath);
45
+ if (createServices.length > 0) {
46
+ for (const createService of createServices) {
47
+ const { exportName, path } = createService;
48
+ silgi.hook("prepare:core.ts", (options) => {
49
+ options.services.push(exportName);
50
+ });
51
+ silgi.hook("prepare:core.ts", (options) => {
52
+ options.importItems[path] ??= {
53
+ import: [],
54
+ from: relativeWithDot(silgi.options.silgi.serverDir, path)
55
+ };
56
+ options.importItems[path].import.push({
57
+ name: exportName
58
+ });
59
+ });
60
+ }
61
+ }
62
+ const createSchemas = exportVariables("createSchema", filePath);
63
+ if (createSchemas.length > 0) {
64
+ for (const createSchema of createSchemas) {
65
+ const { exportName, path } = createSchema;
66
+ silgi.hook("prepare:core.ts", (options) => {
67
+ options.schemas.push(exportName);
68
+ });
69
+ silgi.hook("prepare:core.ts", (options) => {
70
+ options.importItems[path] ??= {
71
+ import: [],
72
+ from: relativeWithDot(silgi.options.silgi.serverDir, path)
73
+ };
74
+ options.importItems[path].import.push({
75
+ name: exportName
76
+ });
77
+ });
78
+ }
79
+ }
80
+ const createShareds = exportVariables("createShared", filePath);
81
+ if (createShareds.length > 0) {
82
+ for (const createShared of createShareds) {
83
+ const { exportName, path } = createShared;
84
+ silgi.hook("prepare:core.ts", (options) => {
85
+ options.shareds.push(exportName);
86
+ });
87
+ silgi.hook("prepare:core.ts", (options) => {
88
+ options.importItems[path] ??= {
89
+ import: [],
90
+ // Relative path kaldirmamiz gerekiyor bunlar hooklarin bittigi yerde karar verilmeli.
91
+ from: relativeWithDot(silgi.options.silgi.serverDir, path)
92
+ };
93
+ options.importItems[path].import.push({
94
+ name: exportName
95
+ });
96
+ });
97
+ }
98
+ }
99
+ const sharedsTypes = parseInterfaceDeclarations("ExtendShared", filePath);
100
+ if (sharedsTypes.length > 0) {
101
+ for (const sharedType of sharedsTypes) {
102
+ const { exportName, path } = sharedType;
103
+ silgi.hook("prepare:schema.ts", (options) => {
104
+ options.shareds.push({
105
+ key: exportName,
106
+ value: exportName
107
+ });
108
+ });
109
+ silgi.hook("prepare:schema.ts", (options) => {
110
+ options.importItems[path] ??= {
111
+ import: [],
112
+ from: path
113
+ };
114
+ options.importItems[path].import.push({
115
+ name: exportName,
116
+ type: true
117
+ });
118
+ });
119
+ }
120
+ }
121
+ const contextTypes = parseInterfaceDeclarations("ExtendContext", filePath);
122
+ if (contextTypes.length > 0) {
123
+ for (const contextType of contextTypes) {
124
+ const { exportName, path } = contextType;
125
+ silgi.hook("prepare:schema.ts", (options) => {
126
+ options.contexts.push({
127
+ key: exportName,
128
+ value: exportName
129
+ });
130
+ });
131
+ silgi.hook("prepare:schema.ts", (options) => {
132
+ options.importItems[path] ??= {
133
+ import: [],
134
+ from: path
135
+ };
136
+ options.importItems[path].import.push({
137
+ name: exportName,
138
+ type: true
139
+ });
140
+ });
141
+ }
142
+ }
143
+ }
144
+ }
145
+ }
146
+
147
+ export { scanFiles };
@@ -0,0 +1,21 @@
1
+ import { klona } from 'klona';
2
+ import { createStorage, builtinDrivers } from 'unstorage';
3
+
4
+ async function createStorageCLI(silgi) {
5
+ const storage = createStorage();
6
+ const mounts = klona({
7
+ ...silgi.options.storage,
8
+ ...silgi.options.devStorage
9
+ });
10
+ for (const [path, opts] of Object.entries(mounts)) {
11
+ if (opts.driver) {
12
+ const driver = await import(builtinDrivers[opts.driver] || opts.driver).then((r) => r.default || r);
13
+ storage.mount(path, driver(opts));
14
+ } else {
15
+ silgi.logger.warn(`No \`driver\` set for storage mount point "${path}".`);
16
+ }
17
+ }
18
+ return storage;
19
+ }
20
+
21
+ export { createStorageCLI };
@@ -0,0 +1,71 @@
1
+ function traverseObject(silgi, obj, currentPath = []) {
2
+ const uriMap = /* @__PURE__ */ new Map();
3
+ function traverse(node, path = []) {
4
+ if (!node || typeof node !== "object")
5
+ return;
6
+ if (path.length === 4) {
7
+ const basePath = path.join("/");
8
+ let paramString = "";
9
+ if (node.router) {
10
+ let params = null;
11
+ if (node.router?._def?.typeName !== void 0) {
12
+ try {
13
+ const shape = node.router?.shape?.params?.shape;
14
+ params = shape ? Object.keys(shape) : null;
15
+ } catch {
16
+ params = null;
17
+ }
18
+ }
19
+ if (params?.length) {
20
+ paramString = params.map((p) => `:${p}`).join("/");
21
+ }
22
+ }
23
+ uriMap.set(basePath, paramString);
24
+ return;
25
+ }
26
+ for (const key in node) {
27
+ if (!["_type", "fields"].includes(key)) {
28
+ traverse(node[key], [...path, key]);
29
+ }
30
+ }
31
+ }
32
+ traverse(obj, currentPath);
33
+ return uriMap;
34
+ }
35
+ function scanActionModulesUris(silgi, obj, currentPath = []) {
36
+ const uriMap = {};
37
+ function traverse(node, path = []) {
38
+ if (!node || typeof node !== "object")
39
+ return;
40
+ if (path.length === 4) {
41
+ const basePath = path.join("/");
42
+ let moduleName = "";
43
+ if (node.modules?.yoga) {
44
+ let rootFieldName = null;
45
+ if (node.modules?.yoga?.rootFieldName) {
46
+ moduleName = "yoga";
47
+ rootFieldName = node.modules?.yoga?.rootFieldName;
48
+ }
49
+ if (!rootFieldName) {
50
+ return;
51
+ }
52
+ uriMap[moduleName] ??= {};
53
+ if (uriMap[moduleName].rootFieldName) {
54
+ silgi.logger.withTag("scanActionModulesUris").error(`Hata ${moduleName} ${rootFieldName} ${basePath} bu zaten burada kullanilmis.`);
55
+ }
56
+ uriMap[moduleName].rootFieldName ??= {};
57
+ uriMap[moduleName].rootFieldName[rootFieldName] = basePath;
58
+ }
59
+ return;
60
+ }
61
+ for (const key in node) {
62
+ if (!["_type", "fields"].includes(key)) {
63
+ traverse(node[key], [...path, key]);
64
+ }
65
+ }
66
+ }
67
+ traverse(obj, currentPath);
68
+ return uriMap;
69
+ }
70
+
71
+ export { scanActionModulesUris, traverseObject };
@@ -0,0 +1,96 @@
1
+ import { isDebug, isTest } from 'std-env';
2
+
3
+ const SilgiCLIDefaults = {
4
+ // General
5
+ debug: isDebug,
6
+ // timing: isDebug,
7
+ logLevel: isTest ? 1 : 3,
8
+ // runtimeConfig: { app: {}, silgi: {} },
9
+ appConfig: {},
10
+ appConfigFiles: [],
11
+ // Dirs
12
+ scanDirs: [],
13
+ build: {
14
+ dir: ".silgi",
15
+ typesDir: "{{ build.dir }}/types",
16
+ templates: []
17
+ },
18
+ output: {
19
+ dir: "{{ rootDir }}/.output",
20
+ serverDir: "{{ output.dir }}/server",
21
+ publicDir: "{{ output.dir }}/public"
22
+ },
23
+ serverDir: "{{ rootDir }}/server",
24
+ clientDir: "{{ rootDir }}/client",
25
+ silgi: {
26
+ serverDir: "{{ serverDir }}/silgi",
27
+ clientDir: "{{ clientDir }}/silgi",
28
+ publicDir: "{{ silgi.serverDir }}/public",
29
+ utilsDir: "{{ silgi.serverDir }}/utils",
30
+ vfsDir: "{{ silgi.serverDir }}/vfs",
31
+ typesDir: "{{ silgi.serverDir }}/types"
32
+ },
33
+ // Modules
34
+ _modules: [],
35
+ modules: [],
36
+ // Features
37
+ // experimental: {},
38
+ future: {},
39
+ storage: {},
40
+ devStorage: {},
41
+ stub: false,
42
+ // bundledStorage: [],
43
+ // publicAssets: [],
44
+ // serverAssets: [],
45
+ plugins: [],
46
+ // tasks: {},
47
+ // scheduledTasks: {},
48
+ imports: {
49
+ exclude: [],
50
+ dirs: [],
51
+ presets: [],
52
+ virtualImports: ["#silgiImports"]
53
+ },
54
+ // virtual: {},
55
+ // compressPublicAssets: false,
56
+ ignore: [],
57
+ // Dev
58
+ dev: false,
59
+ // devServer: { watch: [] },
60
+ watchOptions: { ignoreInitial: true },
61
+ // devProxy: {},
62
+ // Logging
63
+ // logging: {
64
+ // compressedSizes: true,
65
+ // buildSuccess: true,
66
+ // },
67
+ // Routing
68
+ // baseURL: process.env.NITRO_APP_BASE_URL || '/',
69
+ // handlers: [],
70
+ // devHandlers: [],
71
+ // errorHandler: undefined,
72
+ // routeRules: {},
73
+ // Advanced
74
+ typescript: {
75
+ strict: false,
76
+ generateTsConfig: true,
77
+ // generateRuntimeConfigTypes: true,
78
+ tsconfigPath: "types/silgi.tsconfig.json",
79
+ internalPaths: false,
80
+ tsConfig: {},
81
+ customConditions: []
82
+ },
83
+ conditions: [],
84
+ nodeModulesDirs: [],
85
+ // hooks: {},
86
+ commands: {},
87
+ // Framework
88
+ framework: {
89
+ name: "h3",
90
+ version: ""
91
+ },
92
+ extensions: [".js", ".jsx", ".mjs", ".ts", ".tsx", ".vue"],
93
+ ignoreOptions: void 0
94
+ };
95
+
96
+ export { SilgiCLIDefaults };
@@ -0,0 +1,98 @@
1
+ import { watchConfig, loadConfig } from 'c12';
2
+ import { resolveCompatibilityDates } from 'compatx';
3
+ import { klona } from 'klona/full';
4
+ import { SilgiCLIDefaults } from './defaults.mjs';
5
+ import { resolveCompatibilityOptions, fallbackCompatibilityDate } from './resolvers/compatibility.mjs';
6
+ import { resolveImportsOptions } from './resolvers/imports.mjs';
7
+ import { resolvePathOptions } from './resolvers/paths.mjs';
8
+ import { resolveStorageOptions } from './resolvers/storage.mjs';
9
+ import { resolveURLOptions } from './resolvers/url.mjs';
10
+
11
+ const configResolvers = [
12
+ resolveCompatibilityOptions,
13
+ resolvePathOptions,
14
+ resolveImportsOptions,
15
+ // resolveRouteRulesOptions,
16
+ // resolveDatabaseOptions,
17
+ // resolveFetchOptions,
18
+ // resolveExportConditionsOptions,
19
+ // resolveRuntimeConfigOptions,
20
+ // resolveOpenAPIOptions,
21
+ resolveURLOptions,
22
+ // resolveAssetsOptions,
23
+ resolveStorageOptions
24
+ // resolveErrorOptions,
25
+ ];
26
+ async function loadOptions(configOverrides = {}, opts = {}) {
27
+ const options = await _loadUserConfig(configOverrides, opts);
28
+ for (const resolver of configResolvers) {
29
+ await resolver(options);
30
+ }
31
+ return options;
32
+ }
33
+ async function _loadUserConfig(configOverrides = {}, opts = {}) {
34
+ const presetOverride = configOverrides.preset || process.env.SILGI_PRESET;
35
+ if (configOverrides.dev) ;
36
+ configOverrides = klona(configOverrides);
37
+ globalThis.defineSilgiConfig = globalThis.defineSilgiConfig || ((c) => c);
38
+ let compatibilityDate = configOverrides.compatibilityDate || opts.compatibilityDate || (process.env.SILGI_COMPATIBILITY_DATE || process.env.SERVER_COMPATIBILITY_DATE || process.env.COMPATIBILITY_DATE);
39
+ const { resolvePreset } = await import('silgi/presets');
40
+ const loadedConfig = await (opts.watch ? watchConfig : loadConfig)({
41
+ name: "silgi",
42
+ cwd: configOverrides.rootDir,
43
+ dotenv: configOverrides.dev,
44
+ extend: { extendKey: ["extends", "preset"] },
45
+ overrides: {
46
+ ...configOverrides,
47
+ preset: presetOverride
48
+ },
49
+ async defaultConfig({ configs }) {
50
+ const getConf = (key) => configs.main?.[key] ?? configs.rc?.[key] ?? configs.packageJson?.[key];
51
+ if (!compatibilityDate) {
52
+ compatibilityDate = getConf("compatibilityDate");
53
+ }
54
+ return {
55
+ // typescript: {
56
+ // generateRuntimeConfigTypes:
57
+ // !framework?.name || framework.name === 'nitro',
58
+ // },
59
+ preset: presetOverride || (await resolvePreset("", {
60
+ static: getConf("static"),
61
+ compatibilityDate: compatibilityDate || fallbackCompatibilityDate
62
+ }))?._meta?.name
63
+ };
64
+ },
65
+ defaults: SilgiCLIDefaults,
66
+ jitiOptions: {
67
+ alias: {
68
+ "silgi": "silgi/config",
69
+ "silgi/config": "silgi/config"
70
+ }
71
+ },
72
+ async resolve(id) {
73
+ const preset = await resolvePreset(id, {
74
+ static: configOverrides.static,
75
+ compatibilityDate: compatibilityDate || fallbackCompatibilityDate
76
+ });
77
+ if (preset) {
78
+ return {
79
+ config: klona(preset)
80
+ };
81
+ }
82
+ },
83
+ ...opts.c12
84
+ });
85
+ delete globalThis.defineSilgiConfig;
86
+ const options = klona(loadedConfig.config);
87
+ options._config = configOverrides;
88
+ options._c12 = loadedConfig;
89
+ const _presetName = (loadedConfig.layers || []).find((l) => l.config?._meta?.name)?.config?._meta?.name || presetOverride;
90
+ options.preset = _presetName;
91
+ options.compatibilityDate = resolveCompatibilityDates(
92
+ compatibilityDate,
93
+ options.compatibilityDate
94
+ );
95
+ return options;
96
+ }
97
+
98
+ export { loadOptions };
@@ -0,0 +1,90 @@
1
+ import { resolveCompatibilityDatesFromEnv, formatDate } from 'compatx';
2
+ import consola from 'consola';
3
+ import { colors } from 'consola/utils';
4
+ import { relative } from 'pathe';
5
+
6
+ const fallbackCompatibilityDate = "2025-02-04";
7
+ async function resolveCompatibilityOptions(options) {
8
+ options.compatibilityDate = resolveCompatibilityDatesFromEnv(
9
+ options.compatibilityDate
10
+ );
11
+ if (!options.compatibilityDate.default) {
12
+ options.compatibilityDate.default = await _resolveDefault(options);
13
+ }
14
+ }
15
+ let _fallbackInfoShown = false;
16
+ let _promptedUserToUpdate = false;
17
+ async function _resolveDefault(options) {
18
+ const _todayDate = formatDate(/* @__PURE__ */ new Date());
19
+ const consola$1 = consola.withTag("silgi");
20
+ consola$1.warn(`No valid compatibility date is specified.`);
21
+ const onFallback = () => {
22
+ if (!_fallbackInfoShown) {
23
+ consola$1.info(
24
+ [
25
+ `Using \`${fallbackCompatibilityDate}\` as fallback.`,
26
+ ` Please specify compatibility date to avoid unwanted behavior changes:`,
27
+ ` - Add \`compatibilityDate: '${_todayDate}'\` to the config file.`,
28
+ ` - Or set \`COMPATIBILITY_DATE=${_todayDate}\` environment variable.`,
29
+ ``
30
+ ].join("\n")
31
+ );
32
+ _fallbackInfoShown = true;
33
+ }
34
+ return fallbackCompatibilityDate;
35
+ };
36
+ const shallUpdate = !_promptedUserToUpdate && await consola$1.prompt(
37
+ `Do you want to auto update config file to set ${colors.cyan(`compatibilityDate: '${_todayDate}'`)}?`,
38
+ {
39
+ type: "confirm",
40
+ default: true
41
+ }
42
+ );
43
+ _promptedUserToUpdate = true;
44
+ if (!shallUpdate) {
45
+ return onFallback();
46
+ }
47
+ const { updateConfig } = await import('c12/update');
48
+ const updateResult = await updateConfig({
49
+ configFile: "silgi.config",
50
+ cwd: options.rootDir,
51
+ async onCreate({ configFile }) {
52
+ const shallCreate = await consola$1.prompt(
53
+ `Do you want to initialize a new config in ${colors.cyan(relative(".", configFile))}?`,
54
+ {
55
+ type: "confirm",
56
+ default: true
57
+ }
58
+ );
59
+ if (shallCreate !== true) {
60
+ return false;
61
+ }
62
+ return _getDefaultNitroConfig();
63
+ },
64
+ async onUpdate(config) {
65
+ config.compatibilityDate = _todayDate;
66
+ }
67
+ }).catch((error) => {
68
+ consola$1.error(`Failed to update config: ${error.message}`);
69
+ return null;
70
+ });
71
+ if (updateResult?.configFile) {
72
+ consola$1.success(
73
+ `Compatibility date set to \`${_todayDate}\` in \`${relative(".", updateResult.configFile)}\``
74
+ );
75
+ return _todayDate;
76
+ }
77
+ return onFallback();
78
+ }
79
+ function _getDefaultNitroConfig() {
80
+ return (
81
+ /* js */
82
+ `
83
+ import { defineSilgiConfig } from 'silgi/config'
84
+
85
+ export default defineSilgiConfig({})
86
+ `
87
+ );
88
+ }
89
+
90
+ export { fallbackCompatibilityDate, resolveCompatibilityOptions };
@@ -0,0 +1,96 @@
1
+ import escapeRE from 'escape-string-regexp';
2
+ import { resolveModuleExportNames } from 'mlly';
3
+ import { join } from 'pathe';
4
+
5
+ async function resolveImportsOptions(options) {
6
+ if (options.imports === false) {
7
+ return;
8
+ }
9
+ options.imports.presets ??= [];
10
+ options.imports.presets.push(...getSilgiImportsPreset());
11
+ if (options.preset === "h3") {
12
+ const h3Exports = await resolveModuleExportNames("h3", {
13
+ url: import.meta.url
14
+ });
15
+ options.imports.presets ??= [];
16
+ options.imports.presets.push({
17
+ from: "h3",
18
+ imports: h3Exports.filter((n) => !/^[A-Z]/.test(n) && n !== "use")
19
+ });
20
+ }
21
+ options.imports.dirs ??= [];
22
+ options.imports.dirs.push(
23
+ ...options.scanDirs.map((dir) => join(dir, "utils/**/*"))
24
+ );
25
+ if (Array.isArray(options.imports.exclude) && options.imports.exclude.length === 0) {
26
+ options.imports.exclude.push(/[/\\]\.git[/\\]/);
27
+ options.imports.exclude.push(options.build.dir);
28
+ const scanDirsInNodeModules = options.scanDirs.map((dir) => dir.match(/(?<=\/)node_modules\/(.+)$/)?.[1]).filter(Boolean);
29
+ options.imports.exclude.push(
30
+ scanDirsInNodeModules.length > 0 ? new RegExp(
31
+ `node_modules\\/(?!${scanDirsInNodeModules.map((dir) => escapeRE(dir)).join("|")})`
32
+ ) : /[/\\]node_modules[/\\]/
33
+ );
34
+ }
35
+ }
36
+ function getSilgiImportsPreset() {
37
+ return [
38
+ // TODO: buraya bizim importlarimiz gelecek.
39
+ {
40
+ from: "silgi",
41
+ imports: [
42
+ "createShared",
43
+ "useSilgi",
44
+ "createService",
45
+ "createSchema"
46
+ ]
47
+ },
48
+ // {
49
+ // from: 'nitropack/runtime',
50
+ // imports: ['useRuntimeConfig', 'useAppConfig'],
51
+ // },
52
+ // {
53
+ // from: 'nitropack/runtime',
54
+ // imports: ['defineNitroPlugin', 'nitroPlugin'],
55
+ // },
56
+ // {
57
+ // from: 'nitropack/runtime/internal/cache',
58
+ // imports: [
59
+ // 'defineCachedFunction',
60
+ // 'defineCachedEventHandler',
61
+ // 'cachedFunction',
62
+ // 'cachedEventHandler',
63
+ // ],
64
+ // },
65
+ {
66
+ from: "silgi/core",
67
+ imports: ["useSilgiStorage"]
68
+ }
69
+ // {
70
+ // from: 'nitropack/runtime/internal/renderer',
71
+ // imports: ['defineRenderHandler'],
72
+ // },
73
+ // {
74
+ // from: 'nitropack/runtime/internal/meta',
75
+ // imports: ['defineRouteMeta'],
76
+ // },
77
+ // {
78
+ // from: 'nitropack/runtime/internal/route-rules',
79
+ // imports: ['getRouteRules'],
80
+ // },
81
+ // {
82
+ // from: 'nitropack/runtime/internal/context',
83
+ // imports: ['useEvent'],
84
+ // },
85
+ // {
86
+ // from: 'nitropack/runtime/internal/task',
87
+ // imports: ['defineTask', 'runTask'],
88
+ // },
89
+ // {
90
+ // from: 'nitropack/runtime/internal/error/utils',
91
+ // imports: ['defineNitroErrorHandler'],
92
+ // },
93
+ ];
94
+ }
95
+
96
+ export { resolveImportsOptions };