silgi 0.24.15 → 0.24.17
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/cli/build/prepare.mjs +43 -0
- package/dist/cli/{dev.mjs → commands/dev.mjs} +4 -43
- package/dist/cli/commands/env.mjs +40 -0
- package/dist/cli/{install.mjs → commands/install.mjs} +3 -37
- package/dist/cli/commands/prepare.mjs +66 -0
- package/dist/cli/{prepare.mjs → commands/run.mjs} +9 -82
- package/dist/cli/config/defaults.mjs +129 -0
- package/dist/cli/config/index.mjs +2 -16
- package/dist/cli/config/loader.mjs +97 -0
- package/dist/cli/config/resolvers/compatibility.mjs +90 -0
- package/dist/cli/config/resolvers/imports.mjs +96 -0
- package/dist/cli/config/resolvers/paths.mjs +167 -0
- package/dist/cli/config/resolvers/storage.mjs +25 -0
- package/dist/cli/config/resolvers/url.mjs +7 -0
- package/dist/cli/config/types.mjs +191 -0
- package/dist/cli/core/app.mjs +92 -0
- package/dist/cli/core/devServer.mjs +8 -0
- package/dist/cli/core/env.mjs +76 -0
- package/dist/cli/core/installPackage.mjs +31 -0
- package/dist/cli/core/prepare.mjs +7 -0
- package/dist/cli/core/runtimeConfig.mjs +14 -0
- package/dist/cli/core/scan.mjs +39 -0
- package/dist/cli/core/silgi.mjs +125 -0
- package/dist/cli/core/templates.mjs +31 -0
- package/dist/cli/framework/emptyFramework.mjs +9 -0
- package/dist/cli/framework/h3.mjs +89 -0
- package/dist/cli/framework/index.mjs +8 -0
- package/dist/cli/framework/nitro.mjs +106 -0
- package/dist/cli/framework/nuxt.mjs +9 -0
- package/dist/cli/index.mjs +6 -9
- package/dist/cli/module/exportScan.mjs +130 -0
- package/dist/cli/module/install.mjs +59 -0
- package/dist/cli/module/scan.mjs +227 -0
- package/dist/cli/scan/commands.mjs +47 -0
- package/dist/cli/scan/prepareConfigs.mjs +46 -0
- package/dist/cli/scan/prepareCoreFile.mjs +166 -0
- package/dist/cli/scan/prepareFramework.mjs +73 -0
- package/dist/cli/scan/prepareSchema.mjs +177 -0
- package/dist/cli/scan/prepareServerFiles.mjs +119 -0
- package/dist/cli/scan/scanExportFile.mjs +155 -0
- package/dist/cli/scan/writeCoreFile.mjs +34 -0
- package/dist/cli/scan/writeScanFiles.mjs +30 -0
- package/dist/cli/scan/writeTypesAndFiles.mjs +109 -0
- package/dist/cli/utils/build-uri-map.mjs +39 -0
- package/dist/cli/utils/common.mjs +13 -0
- package/dist/cli/{compatibility.mjs → utils/compatibility.mjs} +1 -1
- package/dist/cli/utils/generateRouterDTS.mjs +80 -0
- package/dist/cli/utils/ignore.mjs +46 -0
- package/dist/cli/utils/parser.mjs +168 -0
- package/dist/cli/utils/readScanFile.mjs +79 -0
- package/dist/cli/utils/storage.mjs +25 -0
- package/dist/core/createSilgi.mjs +76 -0
- package/dist/core/error.mjs +227 -0
- package/dist/core/index.mjs +8 -0
- package/dist/core/routeRules.mjs +288 -0
- package/dist/core/silgi.mjs +128 -0
- package/dist/core/silgiApp.mjs +25 -0
- package/dist/core/storage.mjs +15 -0
- package/dist/core/unctx.mjs +27 -0
- package/dist/core/uris/uri.mjs +33 -0
- package/dist/core/uris/utils.mjs +130 -0
- package/dist/core/utils/event.mjs +15 -0
- package/dist/core/utils/merge.mjs +29 -0
- package/dist/core/utils/runtime.mjs +22 -0
- package/dist/core/utils/schema.mjs +5 -0
- package/dist/core/utils/service.mjs +5 -0
- package/dist/core/utils/shared.mjs +5 -0
- package/dist/core/utils/storage.mjs +72 -0
- package/dist/index.mjs +20 -793
- package/dist/kit/errors.mjs +11 -0
- package/dist/kit/esm.mjs +14 -0
- package/dist/kit/fs.mjs +30 -0
- package/dist/kit/gen.mjs +44 -0
- package/dist/kit/hash.mjs +8 -0
- package/dist/kit/index.mjs +15 -528
- package/dist/kit/isFramework.mjs +25 -0
- package/dist/kit/logger.mjs +7 -0
- package/dist/kit/module.mjs +73 -0
- package/dist/kit/parseServices.mjs +57 -0
- package/dist/kit/path.mjs +34 -0
- package/dist/kit/preset.mjs +6 -0
- package/dist/kit/resolve.mjs +80 -0
- package/dist/kit/template.mjs +49 -0
- package/dist/kit/useRequest.mjs +91 -0
- package/dist/kit/utils.mjs +43 -0
- package/dist/package.json.mjs +5 -0
- package/dist/types/index.d.mts +1 -1
- package/package.json +1 -1
- package/dist/_chunks/silgiApp.mjs +0 -2682
- package/dist/cli/types.mjs +0 -772
- /package/dist/cli/{init.mjs → commands/init.mjs} +0 -0
package/dist/cli/types.mjs
DELETED
|
@@ -1,772 +0,0 @@
|
|
|
1
|
-
import { watchConfig, loadConfig } from 'c12';
|
|
2
|
-
import { resolveCompatibilityDatesFromEnv, formatDate, resolveCompatibilityDates } from 'compatx';
|
|
3
|
-
import { klona } from 'klona/full';
|
|
4
|
-
import { isDebug, isTest } from 'std-env';
|
|
5
|
-
import consola from 'consola';
|
|
6
|
-
import { colors } from 'consola/utils';
|
|
7
|
-
import { relative, join, resolve, dirname, isAbsolute } from 'pathe';
|
|
8
|
-
import escapeRE from 'escape-string-regexp';
|
|
9
|
-
import { resolveModuleExportNames } from 'mlly';
|
|
10
|
-
import { existsSync, promises, lstatSync } from 'node:fs';
|
|
11
|
-
import { findWorkspaceDir, readPackageJSON } from 'pkg-types';
|
|
12
|
-
import { resolveSilgiPath, relativeWithDot, resolveSilgiModule } from 'silgi/kit';
|
|
13
|
-
import { runtimeDir, pkgDir } from 'silgi/runtime/meta';
|
|
14
|
-
import { withLeadingSlash, withTrailingSlash } from 'ufo';
|
|
15
|
-
import { defu } from 'defu';
|
|
16
|
-
|
|
17
|
-
const SilgiCLIDefaults = {
|
|
18
|
-
// General
|
|
19
|
-
debug: isDebug,
|
|
20
|
-
// timing: isDebug,
|
|
21
|
-
logLevel: isTest ? 1 : 3,
|
|
22
|
-
// runtimeConfig: { app: {}, silgi: {} },
|
|
23
|
-
appConfig: {},
|
|
24
|
-
appConfigFiles: [],
|
|
25
|
-
commandType: "prepare",
|
|
26
|
-
runtimeConfig: {
|
|
27
|
-
silgi: {
|
|
28
|
-
version: "0.0.1"
|
|
29
|
-
}
|
|
30
|
-
},
|
|
31
|
-
serviceParseModules: [],
|
|
32
|
-
storages: [],
|
|
33
|
-
devServer: {
|
|
34
|
-
watch: []
|
|
35
|
-
},
|
|
36
|
-
// Dirs
|
|
37
|
-
scanDirs: [],
|
|
38
|
-
build: {
|
|
39
|
-
dir: ".silgi",
|
|
40
|
-
typesDir: "{{ build.dir }}/types",
|
|
41
|
-
templates: []
|
|
42
|
-
},
|
|
43
|
-
output: {
|
|
44
|
-
dir: "{{ rootDir }}/.output",
|
|
45
|
-
serverDir: "{{ output.dir }}/server",
|
|
46
|
-
publicDir: "{{ output.dir }}/public"
|
|
47
|
-
},
|
|
48
|
-
serverDir: "{{ rootDir }}/server",
|
|
49
|
-
clientDir: "{{ rootDir }}/client",
|
|
50
|
-
silgi: {
|
|
51
|
-
serverDir: "{{ serverDir }}/silgi",
|
|
52
|
-
clientDir: "{{ clientDir }}/silgi",
|
|
53
|
-
publicDir: "{{ silgi.serverDir }}/public",
|
|
54
|
-
utilsDir: "{{ silgi.serverDir }}/utils",
|
|
55
|
-
vfsDir: "{{ silgi.serverDir }}/vfs",
|
|
56
|
-
typesDir: "{{ silgi.serverDir }}/types"
|
|
57
|
-
},
|
|
58
|
-
// Modules
|
|
59
|
-
_modules: [],
|
|
60
|
-
modules: [],
|
|
61
|
-
routeRules: {},
|
|
62
|
-
// Features
|
|
63
|
-
// experimental: {},
|
|
64
|
-
future: {},
|
|
65
|
-
storage: {},
|
|
66
|
-
devStorage: {},
|
|
67
|
-
stub: false,
|
|
68
|
-
// bundledStorage: [],
|
|
69
|
-
// publicAssets: [],
|
|
70
|
-
// serverAssets: [],
|
|
71
|
-
plugins: [],
|
|
72
|
-
// tasks: {},
|
|
73
|
-
// scheduledTasks: {},
|
|
74
|
-
imports: {
|
|
75
|
-
exclude: [],
|
|
76
|
-
dirs: [],
|
|
77
|
-
presets: [],
|
|
78
|
-
virtualImports: ["#silgiImports"]
|
|
79
|
-
},
|
|
80
|
-
// virtual: {},
|
|
81
|
-
// compressPublicAssets: false,
|
|
82
|
-
ignore: [],
|
|
83
|
-
// Dev
|
|
84
|
-
dev: false,
|
|
85
|
-
// devServer: { watch: [] },
|
|
86
|
-
watchOptions: {
|
|
87
|
-
ignoreInitial: true,
|
|
88
|
-
ignored: [
|
|
89
|
-
"**/node_modules/**",
|
|
90
|
-
"**/.git/**",
|
|
91
|
-
"**/.silgi/**",
|
|
92
|
-
"**/.output/**",
|
|
93
|
-
"**/.vscode/**",
|
|
94
|
-
"**/.idea/**",
|
|
95
|
-
"**/.nuxt/**",
|
|
96
|
-
"**/.next/**",
|
|
97
|
-
"**/.gitignore",
|
|
98
|
-
"**/.gitattributes",
|
|
99
|
-
"**/assets/**",
|
|
100
|
-
"**/dist/**",
|
|
101
|
-
"**/build/**",
|
|
102
|
-
"**/coverage/**",
|
|
103
|
-
"**/test/**",
|
|
104
|
-
"**/tests/**",
|
|
105
|
-
"**/tmp/**"
|
|
106
|
-
]
|
|
107
|
-
},
|
|
108
|
-
// devProxy: {},
|
|
109
|
-
// Logging
|
|
110
|
-
// logging: {
|
|
111
|
-
// compressedSizes: true,
|
|
112
|
-
// buildSuccess: true,
|
|
113
|
-
// },
|
|
114
|
-
// Routing
|
|
115
|
-
// baseURL: process.env.NITRO_APP_BASE_URL || '/',
|
|
116
|
-
// handlers: [],
|
|
117
|
-
// devHandlers: [],
|
|
118
|
-
// errorHandler: undefined,
|
|
119
|
-
// Advanced
|
|
120
|
-
typescript: {
|
|
121
|
-
strict: false,
|
|
122
|
-
generateTsConfig: true,
|
|
123
|
-
// generateRuntimeConfigTypes: true,
|
|
124
|
-
tsconfigPath: ".silgi/types/silgi.tsconfig.json",
|
|
125
|
-
tsConfig: {},
|
|
126
|
-
customConditions: [],
|
|
127
|
-
generateRuntimeConfigTypes: true,
|
|
128
|
-
removeFileExtension: false
|
|
129
|
-
},
|
|
130
|
-
conditions: [],
|
|
131
|
-
nodeModulesDirs: [],
|
|
132
|
-
// hooks: {},
|
|
133
|
-
commands: {},
|
|
134
|
-
// Framework
|
|
135
|
-
framework: {
|
|
136
|
-
name: "h3",
|
|
137
|
-
version: ""
|
|
138
|
-
},
|
|
139
|
-
extensions: [".js", ".jsx", ".mjs", ".ts", ".tsx", ".vue"],
|
|
140
|
-
ignoreOptions: void 0
|
|
141
|
-
};
|
|
142
|
-
|
|
143
|
-
const fallbackCompatibilityDate = "2025-02-04";
|
|
144
|
-
async function resolveCompatibilityOptions(options) {
|
|
145
|
-
options.compatibilityDate = resolveCompatibilityDatesFromEnv(
|
|
146
|
-
options.compatibilityDate
|
|
147
|
-
);
|
|
148
|
-
if (!options.compatibilityDate.default) {
|
|
149
|
-
options.compatibilityDate.default = await _resolveDefault(options);
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
let _fallbackInfoShown = false;
|
|
153
|
-
let _promptedUserToUpdate = false;
|
|
154
|
-
async function _resolveDefault(options) {
|
|
155
|
-
const _todayDate = formatDate(/* @__PURE__ */ new Date());
|
|
156
|
-
const consola$1 = consola.withTag("silgi");
|
|
157
|
-
consola$1.warn(`No valid compatibility date is specified.`);
|
|
158
|
-
const onFallback = () => {
|
|
159
|
-
if (!_fallbackInfoShown) {
|
|
160
|
-
consola$1.info(
|
|
161
|
-
[
|
|
162
|
-
`Using \`${fallbackCompatibilityDate}\` as fallback.`,
|
|
163
|
-
` Please specify compatibility date to avoid unwanted behavior changes:`,
|
|
164
|
-
` - Add \`compatibilityDate: '${_todayDate}'\` to the config file.`,
|
|
165
|
-
` - Or set \`COMPATIBILITY_DATE=${_todayDate}\` environment variable.`,
|
|
166
|
-
``
|
|
167
|
-
].join("\n")
|
|
168
|
-
);
|
|
169
|
-
_fallbackInfoShown = true;
|
|
170
|
-
}
|
|
171
|
-
return fallbackCompatibilityDate;
|
|
172
|
-
};
|
|
173
|
-
const shallUpdate = !_promptedUserToUpdate && await consola$1.prompt(
|
|
174
|
-
`Do you want to auto update config file to set ${colors.cyan(`compatibilityDate: '${_todayDate}'`)}?`,
|
|
175
|
-
{
|
|
176
|
-
type: "confirm",
|
|
177
|
-
default: true
|
|
178
|
-
}
|
|
179
|
-
);
|
|
180
|
-
_promptedUserToUpdate = true;
|
|
181
|
-
if (!shallUpdate) {
|
|
182
|
-
return onFallback();
|
|
183
|
-
}
|
|
184
|
-
const { updateConfig } = await import('c12/update');
|
|
185
|
-
const updateResult = await updateConfig({
|
|
186
|
-
configFile: "silgi.config",
|
|
187
|
-
cwd: options.rootDir,
|
|
188
|
-
async onCreate({ configFile }) {
|
|
189
|
-
const shallCreate = await consola$1.prompt(
|
|
190
|
-
`Do you want to initialize a new config in ${colors.cyan(relative(".", configFile))}?`,
|
|
191
|
-
{
|
|
192
|
-
type: "confirm",
|
|
193
|
-
default: true
|
|
194
|
-
}
|
|
195
|
-
);
|
|
196
|
-
if (shallCreate !== true) {
|
|
197
|
-
return false;
|
|
198
|
-
}
|
|
199
|
-
return _getDefaultNitroConfig();
|
|
200
|
-
},
|
|
201
|
-
async onUpdate(config) {
|
|
202
|
-
config.compatibilityDate = _todayDate;
|
|
203
|
-
}
|
|
204
|
-
}).catch((error) => {
|
|
205
|
-
consola$1.error(`Failed to update config: ${error.message}`);
|
|
206
|
-
return null;
|
|
207
|
-
});
|
|
208
|
-
if (updateResult?.configFile) {
|
|
209
|
-
consola$1.success(
|
|
210
|
-
`Compatibility date set to \`${_todayDate}\` in \`${relative(".", updateResult.configFile)}\``
|
|
211
|
-
);
|
|
212
|
-
return _todayDate;
|
|
213
|
-
}
|
|
214
|
-
return onFallback();
|
|
215
|
-
}
|
|
216
|
-
function _getDefaultNitroConfig() {
|
|
217
|
-
return (
|
|
218
|
-
/* js */
|
|
219
|
-
`
|
|
220
|
-
import { defineSilgiConfig } from 'silgi/config'
|
|
221
|
-
|
|
222
|
-
export default defineSilgiConfig({})
|
|
223
|
-
`
|
|
224
|
-
);
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
async function resolveImportsOptions(options) {
|
|
228
|
-
if (options.imports === false) {
|
|
229
|
-
return;
|
|
230
|
-
}
|
|
231
|
-
options.imports.presets ??= [];
|
|
232
|
-
options.imports.presets.push(...getSilgiImportsPreset());
|
|
233
|
-
if (options.preset === "h3") {
|
|
234
|
-
const h3Exports = await resolveModuleExportNames("h3", {
|
|
235
|
-
url: import.meta.url
|
|
236
|
-
});
|
|
237
|
-
options.imports.presets ??= [];
|
|
238
|
-
options.imports.presets.push({
|
|
239
|
-
from: "h3",
|
|
240
|
-
imports: h3Exports.filter((n) => !/^[A-Z]/.test(n) && n !== "use")
|
|
241
|
-
});
|
|
242
|
-
}
|
|
243
|
-
options.imports.dirs ??= [];
|
|
244
|
-
options.imports.dirs.push(
|
|
245
|
-
...options.scanDirs.map((dir) => join(dir, "utils/**/*"))
|
|
246
|
-
);
|
|
247
|
-
if (Array.isArray(options.imports.exclude) && options.imports.exclude.length === 0) {
|
|
248
|
-
options.imports.exclude.push(/[/\\]\.git[/\\]/);
|
|
249
|
-
options.imports.exclude.push(options.build.dir);
|
|
250
|
-
const scanDirsInNodeModules = options.scanDirs.map((dir) => dir.match(/(?<=\/)node_modules\/(.+)$/)?.[1]).filter(Boolean);
|
|
251
|
-
options.imports.exclude.push(
|
|
252
|
-
scanDirsInNodeModules.length > 0 ? new RegExp(
|
|
253
|
-
`node_modules\\/(?!${scanDirsInNodeModules.map((dir) => escapeRE(dir)).join("|")})`
|
|
254
|
-
) : /[/\\]node_modules[/\\]/
|
|
255
|
-
);
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
function getSilgiImportsPreset() {
|
|
259
|
-
return [
|
|
260
|
-
// TODO: buraya bizim importlarimiz gelecek.
|
|
261
|
-
{
|
|
262
|
-
from: "silgi",
|
|
263
|
-
imports: [
|
|
264
|
-
"createShared",
|
|
265
|
-
"useSilgi",
|
|
266
|
-
"createService",
|
|
267
|
-
"createSchema"
|
|
268
|
-
]
|
|
269
|
-
},
|
|
270
|
-
// {
|
|
271
|
-
// from: 'nitropack/runtime',
|
|
272
|
-
// imports: ['useRuntimeConfig', 'useAppConfig'],
|
|
273
|
-
// },
|
|
274
|
-
// {
|
|
275
|
-
// from: 'nitropack/runtime',
|
|
276
|
-
// imports: ['defineNitroPlugin', 'nitroPlugin'],
|
|
277
|
-
// },
|
|
278
|
-
// {
|
|
279
|
-
// from: 'nitropack/runtime/internal/cache',
|
|
280
|
-
// imports: [
|
|
281
|
-
// 'defineCachedFunction',
|
|
282
|
-
// 'defineCachedEventHandler',
|
|
283
|
-
// 'cachedFunction',
|
|
284
|
-
// 'cachedEventHandler',
|
|
285
|
-
// ],
|
|
286
|
-
// },
|
|
287
|
-
{
|
|
288
|
-
from: "silgi",
|
|
289
|
-
imports: ["useSilgiStorage"]
|
|
290
|
-
}
|
|
291
|
-
// {
|
|
292
|
-
// from: 'nitropack/runtime/internal/renderer',
|
|
293
|
-
// imports: ['defineRenderHandler'],
|
|
294
|
-
// },
|
|
295
|
-
// {
|
|
296
|
-
// from: 'nitropack/runtime/internal/meta',
|
|
297
|
-
// imports: ['defineRouteMeta'],
|
|
298
|
-
// },
|
|
299
|
-
// {
|
|
300
|
-
// from: 'nitropack/runtime/internal/route-rules',
|
|
301
|
-
// imports: ['getRouteRules'],
|
|
302
|
-
// },
|
|
303
|
-
// {
|
|
304
|
-
// from: 'nitropack/runtime/internal/context',
|
|
305
|
-
// imports: ['useEvent'],
|
|
306
|
-
// },
|
|
307
|
-
// {
|
|
308
|
-
// from: 'nitropack/runtime/internal/task',
|
|
309
|
-
// imports: ['defineTask', 'runTask'],
|
|
310
|
-
// },
|
|
311
|
-
// {
|
|
312
|
-
// from: 'nitropack/runtime/internal/error/utils',
|
|
313
|
-
// imports: ['defineNitroErrorHandler'],
|
|
314
|
-
// },
|
|
315
|
-
];
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
async function resolvePathOptions(options) {
|
|
319
|
-
options.rootDir = resolve(options.rootDir || ".");
|
|
320
|
-
options.workspaceDir = await findWorkspaceDir(options.rootDir).catch(
|
|
321
|
-
() => options.rootDir
|
|
322
|
-
);
|
|
323
|
-
options.srcDir = resolve(options.srcDir || options.rootDir);
|
|
324
|
-
for (const key of ["srcDir"]) {
|
|
325
|
-
options[key] = resolve(options.rootDir, options[key]);
|
|
326
|
-
}
|
|
327
|
-
options.build.dir = resolve(options.rootDir, options.build.dir);
|
|
328
|
-
options.build.typesDir = resolveSilgiPath(
|
|
329
|
-
options.build.typesDir || SilgiCLIDefaults.build.typesDir,
|
|
330
|
-
options,
|
|
331
|
-
options.rootDir
|
|
332
|
-
);
|
|
333
|
-
if (options.preset === "npm-package") {
|
|
334
|
-
const packageJsonPath = resolve(options.rootDir, "package.json");
|
|
335
|
-
const packageJson = await readPackageJSON(packageJsonPath);
|
|
336
|
-
if (packageJson.name === void 0) {
|
|
337
|
-
throw new Error("Package name is undefined");
|
|
338
|
-
}
|
|
339
|
-
options.alias ||= {};
|
|
340
|
-
options.alias[packageJson.name] = join(options.rootDir, "src/module");
|
|
341
|
-
options.alias[`${packageJson.name}/runtime/`] = join(options.rootDir, "src/runtime");
|
|
342
|
-
options.alias[`${packageJson.name}/runtime/*`] = join(options.rootDir, "src/runtime/*");
|
|
343
|
-
options.alias[`${packageJson.name}/types`] = join(options.rootDir, "src/types");
|
|
344
|
-
}
|
|
345
|
-
if (options.stub) {
|
|
346
|
-
options.alias = {
|
|
347
|
-
...options.alias,
|
|
348
|
-
"silgi/runtime": join(runtimeDir),
|
|
349
|
-
"#internal/silgi": join(runtimeDir),
|
|
350
|
-
"silgi/runtime/*": join(runtimeDir, "*"),
|
|
351
|
-
"#internal/silgi/*": join(runtimeDir, "*")
|
|
352
|
-
};
|
|
353
|
-
}
|
|
354
|
-
options.alias = {
|
|
355
|
-
...options.alias,
|
|
356
|
-
"~/": join(options.srcDir, "/"),
|
|
357
|
-
"@/": join(options.srcDir, "/"),
|
|
358
|
-
"~~/": join(options.rootDir, "/"),
|
|
359
|
-
"@@/": join(options.rootDir, "/")
|
|
360
|
-
};
|
|
361
|
-
if (options.preset === "npm-package") {
|
|
362
|
-
options.alias = {
|
|
363
|
-
...options.alias
|
|
364
|
-
// '#silgi/app/': join(options.build.dir, '/'),
|
|
365
|
-
};
|
|
366
|
-
}
|
|
367
|
-
if (options.alias && typeof options.alias === "object") {
|
|
368
|
-
((options.typescript.tsConfig ??= {}).compilerOptions ??= {}).paths ??= {};
|
|
369
|
-
const paths = options.typescript.tsConfig.compilerOptions.paths;
|
|
370
|
-
for (const [key, value] of Object.entries(options.alias)) {
|
|
371
|
-
if (typeof paths === "object") {
|
|
372
|
-
paths[key] = [value];
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
if (options.typescript.tsConfig.compilerOptions?.paths && typeof options.typescript.tsConfig.compilerOptions.paths === "object") {
|
|
377
|
-
((options.typescript.tsConfig ??= {}).compilerOptions ??= {}).paths ??= {};
|
|
378
|
-
const paths = options.typescript.tsConfig.compilerOptions.paths;
|
|
379
|
-
for (const [key, value] of Object.entries(options.alias)) {
|
|
380
|
-
if (typeof paths === "object") {
|
|
381
|
-
paths[key] = [value];
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
options.modulesDir = [resolve(options.rootDir, "node_modules")];
|
|
386
|
-
options.output.dir = resolveSilgiPath(
|
|
387
|
-
options.output.dir || SilgiCLIDefaults.output.dir,
|
|
388
|
-
options,
|
|
389
|
-
options.rootDir
|
|
390
|
-
);
|
|
391
|
-
options.output.publicDir = resolveSilgiPath(
|
|
392
|
-
options.output.publicDir || SilgiCLIDefaults.output.publicDir,
|
|
393
|
-
options,
|
|
394
|
-
options.rootDir
|
|
395
|
-
);
|
|
396
|
-
options.output.serverDir = resolveSilgiPath(
|
|
397
|
-
options.output.serverDir || SilgiCLIDefaults.output.serverDir,
|
|
398
|
-
options,
|
|
399
|
-
options.rootDir
|
|
400
|
-
);
|
|
401
|
-
options.serverDir = resolveSilgiPath(
|
|
402
|
-
options.serverDir || SilgiCLIDefaults.serverDir,
|
|
403
|
-
options,
|
|
404
|
-
options.rootDir
|
|
405
|
-
);
|
|
406
|
-
options.clientDir = resolveSilgiPath(
|
|
407
|
-
options.clientDir || SilgiCLIDefaults.clientDir,
|
|
408
|
-
options,
|
|
409
|
-
options.rootDir
|
|
410
|
-
);
|
|
411
|
-
options.silgi.serverDir = resolveSilgiPath(
|
|
412
|
-
options.silgi.serverDir || SilgiCLIDefaults.silgi.serverDir,
|
|
413
|
-
options,
|
|
414
|
-
options.rootDir
|
|
415
|
-
);
|
|
416
|
-
options.silgi.clientDir = resolveSilgiPath(
|
|
417
|
-
options.silgi.clientDir || SilgiCLIDefaults.silgi.clientDir,
|
|
418
|
-
options,
|
|
419
|
-
options.rootDir
|
|
420
|
-
);
|
|
421
|
-
options.silgi.publicDir = resolveSilgiPath(
|
|
422
|
-
options.silgi.publicDir || SilgiCLIDefaults.silgi.publicDir,
|
|
423
|
-
options,
|
|
424
|
-
options.rootDir
|
|
425
|
-
);
|
|
426
|
-
options.silgi.utilsDir = resolveSilgiPath(
|
|
427
|
-
options.silgi.utilsDir || SilgiCLIDefaults.silgi.utilsDir,
|
|
428
|
-
options,
|
|
429
|
-
options.rootDir
|
|
430
|
-
);
|
|
431
|
-
options.silgi.vfsDir = resolveSilgiPath(
|
|
432
|
-
options.silgi.vfsDir || SilgiCLIDefaults.silgi.vfsDir,
|
|
433
|
-
options,
|
|
434
|
-
options.rootDir
|
|
435
|
-
);
|
|
436
|
-
options.silgi.typesDir = resolveSilgiPath(
|
|
437
|
-
options.silgi.typesDir || SilgiCLIDefaults.silgi.typesDir,
|
|
438
|
-
options,
|
|
439
|
-
options.rootDir
|
|
440
|
-
);
|
|
441
|
-
options.nodeModulesDirs.push(resolve(options.workspaceDir, "node_modules"));
|
|
442
|
-
options.nodeModulesDirs.push(resolve(options.rootDir, "node_modules"));
|
|
443
|
-
options.nodeModulesDirs.push(resolve(pkgDir, "node_modules"));
|
|
444
|
-
options.nodeModulesDirs.push(resolve(pkgDir, ".."));
|
|
445
|
-
options.nodeModulesDirs = [
|
|
446
|
-
...new Set(
|
|
447
|
-
options.nodeModulesDirs.map((dir) => resolve(options.rootDir, dir))
|
|
448
|
-
)
|
|
449
|
-
];
|
|
450
|
-
options.scanDirs.unshift(options.srcDir);
|
|
451
|
-
options.scanDirs = options.scanDirs.map(
|
|
452
|
-
(dir) => resolve(options.srcDir, dir)
|
|
453
|
-
);
|
|
454
|
-
options.scanDirs = [...new Set(options.scanDirs)];
|
|
455
|
-
options.appConfigFiles ??= [];
|
|
456
|
-
options.appConfigFiles = options.appConfigFiles.map((file) => _tryResolve(resolveSilgiPath(file, options))).filter(Boolean);
|
|
457
|
-
for (const dir of options.scanDirs) {
|
|
458
|
-
const configFile = _tryResolve("app.config", dir);
|
|
459
|
-
if (configFile && !options.appConfigFiles.includes(configFile)) {
|
|
460
|
-
options.appConfigFiles.push(configFile);
|
|
461
|
-
}
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
function _tryResolve(path, base = ".", extensions = ["", ".js", ".ts", ".mjs", ".cjs", ".json"]) {
|
|
465
|
-
path = resolve(base, path);
|
|
466
|
-
if (existsSync(path)) {
|
|
467
|
-
return path;
|
|
468
|
-
}
|
|
469
|
-
for (const ext of extensions) {
|
|
470
|
-
const p = path + ext;
|
|
471
|
-
if (existsSync(p)) {
|
|
472
|
-
return p;
|
|
473
|
-
}
|
|
474
|
-
}
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
async function resolveStorageOptions(options) {
|
|
478
|
-
const fsMounts = {
|
|
479
|
-
root: resolve(options.rootDir),
|
|
480
|
-
src: resolve(options.srcDir),
|
|
481
|
-
build: resolve(options.build.dir),
|
|
482
|
-
cache: resolve(options.build.dir, "cache")
|
|
483
|
-
};
|
|
484
|
-
for (const p in fsMounts) {
|
|
485
|
-
options.devStorage[p] = options.devStorage[p] || {
|
|
486
|
-
driver: "fs",
|
|
487
|
-
readOnly: p === "root" || p === "src",
|
|
488
|
-
base: fsMounts[p]
|
|
489
|
-
};
|
|
490
|
-
}
|
|
491
|
-
if (options.dev && options.storage.data === void 0 && options.devStorage.data === void 0) {
|
|
492
|
-
options.devStorage.data = {
|
|
493
|
-
driver: "fs",
|
|
494
|
-
base: resolve(options.rootDir, ".data/kv")
|
|
495
|
-
};
|
|
496
|
-
}
|
|
497
|
-
}
|
|
498
|
-
|
|
499
|
-
async function resolveURLOptions(options) {
|
|
500
|
-
options.baseURL = withLeadingSlash(withTrailingSlash(options.baseURL));
|
|
501
|
-
}
|
|
502
|
-
|
|
503
|
-
const configResolvers = [
|
|
504
|
-
resolveCompatibilityOptions,
|
|
505
|
-
resolvePathOptions,
|
|
506
|
-
resolveImportsOptions,
|
|
507
|
-
// resolveRouteRulesOptions,
|
|
508
|
-
// resolveDatabaseOptions,
|
|
509
|
-
// resolveFetchOptions,
|
|
510
|
-
// resolveExportConditionsOptions,
|
|
511
|
-
// resolveRuntimeConfigOptions,
|
|
512
|
-
// resolveOpenAPIOptions,
|
|
513
|
-
resolveURLOptions,
|
|
514
|
-
// resolveAssetsOptions,
|
|
515
|
-
resolveStorageOptions
|
|
516
|
-
// resolveErrorOptions,
|
|
517
|
-
];
|
|
518
|
-
async function loadOptions(configOverrides = {}, opts = {}) {
|
|
519
|
-
const options = await _loadUserConfig(configOverrides, opts);
|
|
520
|
-
for (const resolver of configResolvers) {
|
|
521
|
-
await resolver(options);
|
|
522
|
-
}
|
|
523
|
-
return options;
|
|
524
|
-
}
|
|
525
|
-
async function _loadUserConfig(configOverrides = {}, opts = {}) {
|
|
526
|
-
const presetOverride = configOverrides.preset || process.env.SILGI_PRESET;
|
|
527
|
-
if (configOverrides.dev) ;
|
|
528
|
-
configOverrides = klona(configOverrides);
|
|
529
|
-
globalThis.defineSilgiConfig = globalThis.defineSilgiConfig || ((c) => c);
|
|
530
|
-
let compatibilityDate = configOverrides.compatibilityDate || opts.compatibilityDate || (process.env.SILGI_COMPATIBILITY_DATE || process.env.SERVER_COMPATIBILITY_DATE || process.env.COMPATIBILITY_DATE);
|
|
531
|
-
const { resolvePreset } = await import('silgi/presets');
|
|
532
|
-
const loadedConfig = await (opts.watch ? watchConfig : loadConfig)({
|
|
533
|
-
name: "silgi",
|
|
534
|
-
cwd: configOverrides.rootDir,
|
|
535
|
-
dotenv: configOverrides.dev,
|
|
536
|
-
extend: { extendKey: ["extends", "preset"] },
|
|
537
|
-
overrides: {
|
|
538
|
-
...configOverrides,
|
|
539
|
-
preset: presetOverride
|
|
540
|
-
},
|
|
541
|
-
async defaultConfig({ configs }) {
|
|
542
|
-
const getConf = (key) => configs.main?.[key] ?? configs.rc?.[key] ?? configs.packageJson?.[key];
|
|
543
|
-
if (!compatibilityDate) {
|
|
544
|
-
compatibilityDate = getConf("compatibilityDate");
|
|
545
|
-
}
|
|
546
|
-
return {
|
|
547
|
-
// typescript: {
|
|
548
|
-
// generateRuntimeConfigTypes:
|
|
549
|
-
// !framework?.name || framework.name === 'nitro',
|
|
550
|
-
// },
|
|
551
|
-
preset: presetOverride || (await resolvePreset("", {
|
|
552
|
-
static: getConf("static"),
|
|
553
|
-
compatibilityDate: compatibilityDate || fallbackCompatibilityDate
|
|
554
|
-
}))?._meta?.name
|
|
555
|
-
};
|
|
556
|
-
},
|
|
557
|
-
defaults: SilgiCLIDefaults,
|
|
558
|
-
jitiOptions: {
|
|
559
|
-
alias: {
|
|
560
|
-
"silgi/config": "silgi/config"
|
|
561
|
-
}
|
|
562
|
-
},
|
|
563
|
-
async resolve(id) {
|
|
564
|
-
const preset = await resolvePreset(id, {
|
|
565
|
-
static: configOverrides.static,
|
|
566
|
-
compatibilityDate: compatibilityDate || fallbackCompatibilityDate
|
|
567
|
-
});
|
|
568
|
-
if (preset) {
|
|
569
|
-
return {
|
|
570
|
-
config: klona(preset)
|
|
571
|
-
};
|
|
572
|
-
}
|
|
573
|
-
},
|
|
574
|
-
...opts.c12
|
|
575
|
-
});
|
|
576
|
-
delete globalThis.defineSilgiConfig;
|
|
577
|
-
const options = klona(loadedConfig.config);
|
|
578
|
-
options._config = configOverrides;
|
|
579
|
-
options._c12 = loadedConfig;
|
|
580
|
-
const _presetName = (loadedConfig.layers || []).find((l) => l.config?._meta?.name)?.config?._meta?.name || presetOverride;
|
|
581
|
-
options.preset = _presetName;
|
|
582
|
-
options.compatibilityDate = resolveCompatibilityDates(
|
|
583
|
-
compatibilityDate,
|
|
584
|
-
options.compatibilityDate
|
|
585
|
-
);
|
|
586
|
-
return options;
|
|
587
|
-
}
|
|
588
|
-
|
|
589
|
-
function getDirectory(p) {
|
|
590
|
-
try {
|
|
591
|
-
return isAbsolute(p) && lstatSync(p).isFile() ? dirname(p) : p;
|
|
592
|
-
} catch {
|
|
593
|
-
}
|
|
594
|
-
return p;
|
|
595
|
-
}
|
|
596
|
-
function renderAttrs(obj) {
|
|
597
|
-
const attrs = [];
|
|
598
|
-
for (const key in obj) {
|
|
599
|
-
attrs.push(renderAttr(key, obj[key]));
|
|
600
|
-
}
|
|
601
|
-
return attrs.join(" ");
|
|
602
|
-
}
|
|
603
|
-
function renderAttr(key, value) {
|
|
604
|
-
return value ? `${key}="${value}"` : "";
|
|
605
|
-
}
|
|
606
|
-
async function silgiGenerateType(silgi) {
|
|
607
|
-
const rootDirWithSlash = withTrailingSlash(silgi.options.rootDir);
|
|
608
|
-
const tsConfigPath = resolve(
|
|
609
|
-
silgi.options.rootDir,
|
|
610
|
-
silgi.options.typescript.tsconfigPath
|
|
611
|
-
);
|
|
612
|
-
const tsconfigDir = dirname(tsConfigPath);
|
|
613
|
-
const include = /* @__PURE__ */ new Set([
|
|
614
|
-
relativeWithDot(tsconfigDir, join(silgi.options.build.typesDir, "silgi.d.ts")).replace(
|
|
615
|
-
/^(?=[^.])/,
|
|
616
|
-
"./"
|
|
617
|
-
),
|
|
618
|
-
join(relativeWithDot(tsconfigDir, silgi.options.rootDir), "**/*"),
|
|
619
|
-
...silgi.options.srcDir === silgi.options.rootDir ? [] : [join(relativeWithDot(tsconfigDir, silgi.options.srcDir), "**/*")]
|
|
620
|
-
]);
|
|
621
|
-
const exclude = /* @__PURE__ */ new Set([
|
|
622
|
-
// nitro generate output: https://github.com/nuxt/nuxt/blob/main/packages/nuxt/src/core/nitro.ts#L186
|
|
623
|
-
relativeWithDot(tsconfigDir, "node_modules"),
|
|
624
|
-
relativeWithDot(tsconfigDir, "dist")
|
|
625
|
-
]);
|
|
626
|
-
for (const dir of silgi.options.modulesDir) {
|
|
627
|
-
exclude.add(relativeWithDot(silgi.options.build.dir, dir));
|
|
628
|
-
}
|
|
629
|
-
const moduleEntryPaths = [];
|
|
630
|
-
for (const m of silgi.scanModules) {
|
|
631
|
-
if (m.entryPath) {
|
|
632
|
-
moduleEntryPaths.push(getDirectory(m.entryPath));
|
|
633
|
-
}
|
|
634
|
-
}
|
|
635
|
-
const modulePaths = await resolveSilgiModule(rootDirWithSlash, moduleEntryPaths);
|
|
636
|
-
for (const path of modulePaths) {
|
|
637
|
-
const relative2 = relativeWithDot(tsconfigDir, path);
|
|
638
|
-
include.add(join(relative2, "runtime"));
|
|
639
|
-
exclude.add(join(relative2, "runtime/server"));
|
|
640
|
-
include.add(join(relative2, "dist/runtime"));
|
|
641
|
-
exclude.add(join(relative2, "dist/runtime/server"));
|
|
642
|
-
}
|
|
643
|
-
const userTsConfig = {
|
|
644
|
-
compilerOptions: {
|
|
645
|
-
/* Base options: */
|
|
646
|
-
esModuleInterop: true,
|
|
647
|
-
allowSyntheticDefaultImports: true,
|
|
648
|
-
skipLibCheck: true,
|
|
649
|
-
allowImportingTsExtensions: true,
|
|
650
|
-
/* Target options: */
|
|
651
|
-
target: "ESNext",
|
|
652
|
-
allowJs: true,
|
|
653
|
-
resolveJsonModule: true,
|
|
654
|
-
moduleDetection: "force",
|
|
655
|
-
isolatedModules: true,
|
|
656
|
-
verbatimModuleSyntax: true,
|
|
657
|
-
/* Strictness */
|
|
658
|
-
strict: silgi.options.typescript.strict,
|
|
659
|
-
noUncheckedIndexedAccess: true,
|
|
660
|
-
noImplicitOverride: true,
|
|
661
|
-
forceConsistentCasingInFileNames: true,
|
|
662
|
-
/* If NOT transpiling with TypeScript: */
|
|
663
|
-
module: "Preserve",
|
|
664
|
-
customConditions: silgi.options.typescript.customConditions,
|
|
665
|
-
paths: {
|
|
666
|
-
// '#silgiImports': [
|
|
667
|
-
// relativeWithDot(tsconfigDir, join(silgi.options.build.typesDir, 'silgi-imports')),
|
|
668
|
-
// ],
|
|
669
|
-
...silgi.scanModules.reduce((acc, m) => {
|
|
670
|
-
if (m.entryPath) {
|
|
671
|
-
acc[m.meta.name] = [relativeWithDot(tsconfigDir, m.entryPath)];
|
|
672
|
-
}
|
|
673
|
-
return acc;
|
|
674
|
-
}, {}),
|
|
675
|
-
...silgi.scanModules.reduce((acc, m) => {
|
|
676
|
-
if (m.entryPath) {
|
|
677
|
-
const directory = getDirectory(m.entryPath);
|
|
678
|
-
acc[`${m.meta.name}/*`] = [`${relativeWithDot(tsconfigDir, directory)}/*`];
|
|
679
|
-
}
|
|
680
|
-
return acc;
|
|
681
|
-
}, {})
|
|
682
|
-
}
|
|
683
|
-
},
|
|
684
|
-
include: [...include],
|
|
685
|
-
exclude: [...exclude]
|
|
686
|
-
};
|
|
687
|
-
const npmPackageTsConfig = {
|
|
688
|
-
compilerOptions: {
|
|
689
|
-
target: "es2022",
|
|
690
|
-
lib: ["es2022", "webworker", "dom.iterable"],
|
|
691
|
-
moduleDetection: "force",
|
|
692
|
-
/* If NOT transpiling with TypeScript: */
|
|
693
|
-
module: "preserve",
|
|
694
|
-
paths: {},
|
|
695
|
-
resolveJsonModule: true,
|
|
696
|
-
allowJs: true,
|
|
697
|
-
/* Strictness */
|
|
698
|
-
strict: true,
|
|
699
|
-
noImplicitOverride: true,
|
|
700
|
-
noEmit: true,
|
|
701
|
-
allowSyntheticDefaultImports: true,
|
|
702
|
-
/* Base options: */
|
|
703
|
-
esModuleInterop: false,
|
|
704
|
-
forceConsistentCasingInFileNames: true,
|
|
705
|
-
isolatedModules: true,
|
|
706
|
-
verbatimModuleSyntax: true,
|
|
707
|
-
skipLibCheck: true
|
|
708
|
-
},
|
|
709
|
-
// include: ['src', 'test', './moduleTypes.d.ts'],
|
|
710
|
-
// exclude: ['dist', 'examples', 'playground', 'test/fixture'],
|
|
711
|
-
include: [...include],
|
|
712
|
-
exclude: [...exclude]
|
|
713
|
-
};
|
|
714
|
-
const tsConfig = defu(
|
|
715
|
-
silgi.options.typescript?.tsConfig,
|
|
716
|
-
silgi.options.preset === "npm-package" ? npmPackageTsConfig : userTsConfig
|
|
717
|
-
);
|
|
718
|
-
tsConfig.compilerOptions ||= {};
|
|
719
|
-
tsConfig.compilerOptions.paths ||= {};
|
|
720
|
-
tsConfig.include ||= [];
|
|
721
|
-
for (const alias in tsConfig.compilerOptions.paths) {
|
|
722
|
-
const paths = tsConfig.compilerOptions.paths[alias];
|
|
723
|
-
tsConfig.compilerOptions.paths[alias] = await Promise.all(
|
|
724
|
-
paths.map(async (path) => {
|
|
725
|
-
if (!isAbsolute(path)) {
|
|
726
|
-
return path;
|
|
727
|
-
}
|
|
728
|
-
const stats = await promises.stat(path).catch(
|
|
729
|
-
() => null
|
|
730
|
-
/* file does not exist */
|
|
731
|
-
);
|
|
732
|
-
return relativeWithDot(
|
|
733
|
-
tsconfigDir,
|
|
734
|
-
stats?.isFile() ? path.replace(/\b\.\w+$/g, "") : path
|
|
735
|
-
);
|
|
736
|
-
})
|
|
737
|
-
);
|
|
738
|
-
}
|
|
739
|
-
const references = [];
|
|
740
|
-
await Promise.all([...silgi.options.modules, ...silgi.options._modules].map(async (id) => {
|
|
741
|
-
if (typeof id !== "string") {
|
|
742
|
-
return;
|
|
743
|
-
}
|
|
744
|
-
if (id === "./src" && silgi.options.preset === "npm-package") {
|
|
745
|
-
id = resolve(silgi.options.rootDir);
|
|
746
|
-
}
|
|
747
|
-
const pkg = await readPackageJSON(id, { url: silgi.options.rootDir }).catch(() => null);
|
|
748
|
-
references.push({ types: pkg?.name || id });
|
|
749
|
-
}));
|
|
750
|
-
const declarations = [];
|
|
751
|
-
await silgi.callHook("prepare:types", { references, declarations, tsConfig });
|
|
752
|
-
tsConfig.include = [...new Set(tsConfig.include.map((p) => isAbsolute(p) ? relativeWithDot(tsconfigDir, p) : p))];
|
|
753
|
-
tsConfig.exclude = [...new Set(tsConfig.exclude.map((p) => isAbsolute(p) ? relativeWithDot(tsconfigDir, p) : p))];
|
|
754
|
-
const _declarations = [
|
|
755
|
-
...references.map((ref) => {
|
|
756
|
-
if ("path" in ref && isAbsolute(ref.path)) {
|
|
757
|
-
ref.path = relative(silgi.options.build.dir, ref.path);
|
|
758
|
-
}
|
|
759
|
-
return `/// <reference ${renderAttrs(ref)} />`;
|
|
760
|
-
}),
|
|
761
|
-
...declarations,
|
|
762
|
-
"",
|
|
763
|
-
"export {}",
|
|
764
|
-
""
|
|
765
|
-
];
|
|
766
|
-
return {
|
|
767
|
-
declarations: _declarations,
|
|
768
|
-
tsConfig
|
|
769
|
-
};
|
|
770
|
-
}
|
|
771
|
-
|
|
772
|
-
export { loadOptions as l, silgiGenerateType as s };
|