silgi 0.7.1 → 0.7.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 +5 -0
- package/dist/cli/{utils/compatibility.mjs → compatibility.mjs} +1 -1
- package/dist/cli/config/index.d.mts +11 -0
- package/dist/cli/config/index.d.ts +11 -0
- package/dist/{core/config/types.mjs → cli/config/index.mjs} +19 -2
- package/dist/cli/index.mjs +3 -3
- package/dist/cli/loader.mjs +581 -0
- package/dist/cli/prepare.mjs +1621 -0
- package/dist/core/index.d.mts +2 -37
- package/dist/core/index.d.ts +2 -37
- package/dist/core/index.mjs +809 -16
- package/dist/ecosystem/nitro/index.mjs +62 -1
- package/dist/ecosystem/nuxt/module.mjs +1 -1
- package/dist/kit/index.mjs +299 -10
- package/dist/meta/index.d.mts +1 -1
- package/dist/meta/index.d.ts +1 -1
- package/dist/meta/index.mjs +1 -1
- package/package.json +5 -1
- package/dist/cli/build/framework/h3.mjs +0 -46
- package/dist/cli/build/framework/index.mjs +0 -7
- package/dist/cli/build/framework/nitro.mjs +0 -28
- package/dist/cli/build/framework/nuxt.mjs +0 -9
- package/dist/cli/build/prepare.mjs +0 -7
- package/dist/cli/build/scanURIs.mjs +0 -27
- package/dist/cli/build/template/framework.mjs +0 -91
- package/dist/cli/build/template/schema.mjs +0 -115
- package/dist/cli/build/template/silgi.mjs +0 -149
- package/dist/cli/build/types.mjs +0 -130
- package/dist/cli/commands/prepare.mjs +0 -49
- package/dist/cli/common.mjs +0 -13
- package/dist/cli/core/app.mjs +0 -89
- package/dist/cli/core/scan.mjs +0 -40
- package/dist/cli/core/silgi.mjs +0 -77
- package/dist/cli/core/storage.mjs +0 -11
- package/dist/cli/core/templates.mjs +0 -29
- package/dist/cli/module/exportScan.mjs +0 -69
- package/dist/cli/module/install.mjs +0 -52
- package/dist/cli/module/scan.mjs +0 -141
- package/dist/cli/utils/generateRouterDTS.mjs +0 -84
- package/dist/cli/utils/ignore.mjs +0 -46
- package/dist/cli/utils/readCoreFile.mjs +0 -47
- package/dist/cli/utils/scan.mjs +0 -147
- package/dist/cli/utils/storage.mjs +0 -21
- package/dist/cli/utils/uri.mjs +0 -71
- package/dist/core/config/defaults.mjs +0 -96
- package/dist/core/config/loader.mjs +0 -98
- package/dist/core/config/resolvers/compatibility.mjs +0 -90
- package/dist/core/config/resolvers/imports.mjs +0 -96
- package/dist/core/config/resolvers/paths.mjs +0 -194
- package/dist/core/config/resolvers/storage.mjs +0 -25
- package/dist/core/config/resolvers/url.mjs +0 -7
- package/dist/core/createSilgi.mjs +0 -84
- package/dist/core/error.mjs +0 -227
- package/dist/core/fetch/ofetch.mjs +0 -35
- package/dist/core/parser.mjs +0 -136
- package/dist/core/silgi.mjs +0 -114
- package/dist/core/silgiApp.mjs +0 -15
- package/dist/core/unctx.mjs +0 -27
- package/dist/core/uris/uri.mjs +0 -33
- package/dist/core/uris/utils.mjs +0 -127
- package/dist/core/utils/event.mjs +0 -5
- package/dist/core/utils/global.mjs +0 -12
- package/dist/core/utils/merge.mjs +0 -25
- package/dist/core/utils/schema.mjs +0 -5
- package/dist/core/utils/service.mjs +0 -5
- package/dist/core/utils/shared.mjs +0 -5
- package/dist/core/utils/storage.mjs +0 -70
- package/dist/ecosystem/nitro/module.mjs +0 -62
- package/dist/kit/esm.mjs +0 -10
- package/dist/kit/fs.mjs +0 -25
- package/dist/kit/isFramework.mjs +0 -25
- package/dist/kit/logger.mjs +0 -8
- package/dist/kit/module.mjs +0 -73
- package/dist/kit/path.mjs +0 -34
- package/dist/kit/preset.mjs +0 -6
- package/dist/kit/resolve.mjs +0 -78
- package/dist/kit/template.mjs +0 -47
- package/dist/kit/utils.mjs +0 -20
- package/dist/package.json.mjs +0 -5
- package/dist/schema/common.mjs +0 -43
- package/dist/schema/index.mjs +0 -9
- package/dist/schema/internal.mjs +0 -22
- /package/dist/cli/{commands/init.mjs → init.mjs} +0 -0
|
@@ -0,0 +1,11 @@
|
|
|
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 };
|
|
@@ -0,0 +1,11 @@
|
|
|
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,11 +1,28 @@
|
|
|
1
|
-
|
|
1
|
+
export { l as loadOptions } from '../loader.mjs';
|
|
2
|
+
import { promises, lstatSync } from 'node:fs';
|
|
2
3
|
import { defu } from 'defu';
|
|
3
4
|
import { resolve, dirname, join, isAbsolute, relative } from 'pathe';
|
|
4
5
|
import { readPackageJSON } from 'pkg-types';
|
|
5
6
|
import { relativeWithDot, resolveSilgiModule } from 'silgi/kit';
|
|
6
7
|
import { withTrailingSlash } from 'ufo';
|
|
7
|
-
import
|
|
8
|
+
import 'c12';
|
|
9
|
+
import 'compatx';
|
|
10
|
+
import 'klona/full';
|
|
11
|
+
import 'std-env';
|
|
12
|
+
import 'consola';
|
|
13
|
+
import 'consola/utils';
|
|
14
|
+
import 'escape-string-regexp';
|
|
15
|
+
import 'mlly';
|
|
16
|
+
import 'node:url';
|
|
17
|
+
import 'silgi/runtime/meta';
|
|
8
18
|
|
|
19
|
+
function getDirectory(p) {
|
|
20
|
+
try {
|
|
21
|
+
return isAbsolute(p) && lstatSync(p).isFile() ? dirname(p) : p;
|
|
22
|
+
} catch {
|
|
23
|
+
}
|
|
24
|
+
return p;
|
|
25
|
+
}
|
|
9
26
|
function renderAttrs(obj) {
|
|
10
27
|
const attrs = [];
|
|
11
28
|
for (const key in obj) {
|
package/dist/cli/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { defineCommand, runMain } from 'citty';
|
|
2
2
|
import consola from 'consola';
|
|
3
|
-
import packageJson from '../
|
|
3
|
+
import { p as packageJson } from '../_chunks/index.mjs';
|
|
4
4
|
|
|
5
5
|
const main = defineCommand({
|
|
6
6
|
meta: {
|
|
@@ -15,8 +15,8 @@ const main = defineCommand({
|
|
|
15
15
|
}
|
|
16
16
|
},
|
|
17
17
|
subCommands: {
|
|
18
|
-
prepare: () => import('./
|
|
19
|
-
init: () => import('./
|
|
18
|
+
prepare: () => import('./prepare.mjs').then((m) => m.default),
|
|
19
|
+
init: () => import('./init.mjs').then((m) => m.default)
|
|
20
20
|
},
|
|
21
21
|
run({ args }) {
|
|
22
22
|
consola.info("Silgi CLI , --help for more info");
|
|
@@ -0,0 +1,581 @@
|
|
|
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, isAbsolute } from 'pathe';
|
|
8
|
+
import escapeRE from 'escape-string-regexp';
|
|
9
|
+
import { resolveModuleExportNames, resolvePath as resolvePath$1 } from 'mlly';
|
|
10
|
+
import { existsSync } from 'node:fs';
|
|
11
|
+
import { pathToFileURL } from 'node:url';
|
|
12
|
+
import { findWorkspaceDir, readPackageJSON } from 'pkg-types';
|
|
13
|
+
import { resolveSilgiPath, resolveAlias, resolvePath } from 'silgi/kit';
|
|
14
|
+
import { runtimeDir, pkgDir } from 'silgi/runtime/meta';
|
|
15
|
+
import { isRelative, withLeadingSlash, withTrailingSlash } from 'ufo';
|
|
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
|
+
// Dirs
|
|
26
|
+
scanDirs: [],
|
|
27
|
+
build: {
|
|
28
|
+
dir: ".silgi",
|
|
29
|
+
typesDir: "{{ build.dir }}/types",
|
|
30
|
+
templates: []
|
|
31
|
+
},
|
|
32
|
+
output: {
|
|
33
|
+
dir: "{{ rootDir }}/.output",
|
|
34
|
+
serverDir: "{{ output.dir }}/server",
|
|
35
|
+
publicDir: "{{ output.dir }}/public"
|
|
36
|
+
},
|
|
37
|
+
serverDir: "{{ rootDir }}/server",
|
|
38
|
+
clientDir: "{{ rootDir }}/client",
|
|
39
|
+
silgi: {
|
|
40
|
+
serverDir: "{{ serverDir }}/silgi",
|
|
41
|
+
clientDir: "{{ clientDir }}/silgi",
|
|
42
|
+
publicDir: "{{ silgi.serverDir }}/public",
|
|
43
|
+
utilsDir: "{{ silgi.serverDir }}/utils",
|
|
44
|
+
vfsDir: "{{ silgi.serverDir }}/vfs",
|
|
45
|
+
typesDir: "{{ silgi.serverDir }}/types"
|
|
46
|
+
},
|
|
47
|
+
// Modules
|
|
48
|
+
_modules: [],
|
|
49
|
+
modules: [],
|
|
50
|
+
// Features
|
|
51
|
+
// experimental: {},
|
|
52
|
+
future: {},
|
|
53
|
+
storage: {},
|
|
54
|
+
devStorage: {},
|
|
55
|
+
stub: false,
|
|
56
|
+
// bundledStorage: [],
|
|
57
|
+
// publicAssets: [],
|
|
58
|
+
// serverAssets: [],
|
|
59
|
+
plugins: [],
|
|
60
|
+
// tasks: {},
|
|
61
|
+
// scheduledTasks: {},
|
|
62
|
+
imports: {
|
|
63
|
+
exclude: [],
|
|
64
|
+
dirs: [],
|
|
65
|
+
presets: [],
|
|
66
|
+
virtualImports: ["#silgiImports"]
|
|
67
|
+
},
|
|
68
|
+
// virtual: {},
|
|
69
|
+
// compressPublicAssets: false,
|
|
70
|
+
ignore: [],
|
|
71
|
+
// Dev
|
|
72
|
+
dev: false,
|
|
73
|
+
// devServer: { watch: [] },
|
|
74
|
+
watchOptions: { ignoreInitial: true },
|
|
75
|
+
// devProxy: {},
|
|
76
|
+
// Logging
|
|
77
|
+
// logging: {
|
|
78
|
+
// compressedSizes: true,
|
|
79
|
+
// buildSuccess: true,
|
|
80
|
+
// },
|
|
81
|
+
// Routing
|
|
82
|
+
// baseURL: process.env.NITRO_APP_BASE_URL || '/',
|
|
83
|
+
// handlers: [],
|
|
84
|
+
// devHandlers: [],
|
|
85
|
+
// errorHandler: undefined,
|
|
86
|
+
// routeRules: {},
|
|
87
|
+
// Advanced
|
|
88
|
+
typescript: {
|
|
89
|
+
strict: false,
|
|
90
|
+
generateTsConfig: true,
|
|
91
|
+
// generateRuntimeConfigTypes: true,
|
|
92
|
+
tsconfigPath: "types/silgi.tsconfig.json",
|
|
93
|
+
internalPaths: false,
|
|
94
|
+
tsConfig: {},
|
|
95
|
+
customConditions: []
|
|
96
|
+
},
|
|
97
|
+
conditions: [],
|
|
98
|
+
nodeModulesDirs: [],
|
|
99
|
+
// hooks: {},
|
|
100
|
+
commands: {},
|
|
101
|
+
// Framework
|
|
102
|
+
framework: {
|
|
103
|
+
name: "h3",
|
|
104
|
+
version: ""
|
|
105
|
+
},
|
|
106
|
+
extensions: [".js", ".jsx", ".mjs", ".ts", ".tsx", ".vue"],
|
|
107
|
+
ignoreOptions: void 0
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
const fallbackCompatibilityDate = "2025-02-04";
|
|
111
|
+
async function resolveCompatibilityOptions(options) {
|
|
112
|
+
options.compatibilityDate = resolveCompatibilityDatesFromEnv(
|
|
113
|
+
options.compatibilityDate
|
|
114
|
+
);
|
|
115
|
+
if (!options.compatibilityDate.default) {
|
|
116
|
+
options.compatibilityDate.default = await _resolveDefault(options);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
let _fallbackInfoShown = false;
|
|
120
|
+
let _promptedUserToUpdate = false;
|
|
121
|
+
async function _resolveDefault(options) {
|
|
122
|
+
const _todayDate = formatDate(/* @__PURE__ */ new Date());
|
|
123
|
+
const consola$1 = consola.withTag("silgi");
|
|
124
|
+
consola$1.warn(`No valid compatibility date is specified.`);
|
|
125
|
+
const onFallback = () => {
|
|
126
|
+
if (!_fallbackInfoShown) {
|
|
127
|
+
consola$1.info(
|
|
128
|
+
[
|
|
129
|
+
`Using \`${fallbackCompatibilityDate}\` as fallback.`,
|
|
130
|
+
` Please specify compatibility date to avoid unwanted behavior changes:`,
|
|
131
|
+
` - Add \`compatibilityDate: '${_todayDate}'\` to the config file.`,
|
|
132
|
+
` - Or set \`COMPATIBILITY_DATE=${_todayDate}\` environment variable.`,
|
|
133
|
+
``
|
|
134
|
+
].join("\n")
|
|
135
|
+
);
|
|
136
|
+
_fallbackInfoShown = true;
|
|
137
|
+
}
|
|
138
|
+
return fallbackCompatibilityDate;
|
|
139
|
+
};
|
|
140
|
+
const shallUpdate = !_promptedUserToUpdate && await consola$1.prompt(
|
|
141
|
+
`Do you want to auto update config file to set ${colors.cyan(`compatibilityDate: '${_todayDate}'`)}?`,
|
|
142
|
+
{
|
|
143
|
+
type: "confirm",
|
|
144
|
+
default: true
|
|
145
|
+
}
|
|
146
|
+
);
|
|
147
|
+
_promptedUserToUpdate = true;
|
|
148
|
+
if (!shallUpdate) {
|
|
149
|
+
return onFallback();
|
|
150
|
+
}
|
|
151
|
+
const { updateConfig } = await import('c12/update');
|
|
152
|
+
const updateResult = await updateConfig({
|
|
153
|
+
configFile: "silgi.config",
|
|
154
|
+
cwd: options.rootDir,
|
|
155
|
+
async onCreate({ configFile }) {
|
|
156
|
+
const shallCreate = await consola$1.prompt(
|
|
157
|
+
`Do you want to initialize a new config in ${colors.cyan(relative(".", configFile))}?`,
|
|
158
|
+
{
|
|
159
|
+
type: "confirm",
|
|
160
|
+
default: true
|
|
161
|
+
}
|
|
162
|
+
);
|
|
163
|
+
if (shallCreate !== true) {
|
|
164
|
+
return false;
|
|
165
|
+
}
|
|
166
|
+
return _getDefaultNitroConfig();
|
|
167
|
+
},
|
|
168
|
+
async onUpdate(config) {
|
|
169
|
+
config.compatibilityDate = _todayDate;
|
|
170
|
+
}
|
|
171
|
+
}).catch((error) => {
|
|
172
|
+
consola$1.error(`Failed to update config: ${error.message}`);
|
|
173
|
+
return null;
|
|
174
|
+
});
|
|
175
|
+
if (updateResult?.configFile) {
|
|
176
|
+
consola$1.success(
|
|
177
|
+
`Compatibility date set to \`${_todayDate}\` in \`${relative(".", updateResult.configFile)}\``
|
|
178
|
+
);
|
|
179
|
+
return _todayDate;
|
|
180
|
+
}
|
|
181
|
+
return onFallback();
|
|
182
|
+
}
|
|
183
|
+
function _getDefaultNitroConfig() {
|
|
184
|
+
return (
|
|
185
|
+
/* js */
|
|
186
|
+
`
|
|
187
|
+
import { defineSilgiConfig } from 'silgi/config'
|
|
188
|
+
|
|
189
|
+
export default defineSilgiConfig({})
|
|
190
|
+
`
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
async function resolveImportsOptions(options) {
|
|
195
|
+
if (options.imports === false) {
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
options.imports.presets ??= [];
|
|
199
|
+
options.imports.presets.push(...getSilgiImportsPreset());
|
|
200
|
+
if (options.preset === "h3") {
|
|
201
|
+
const h3Exports = await resolveModuleExportNames("h3", {
|
|
202
|
+
url: import.meta.url
|
|
203
|
+
});
|
|
204
|
+
options.imports.presets ??= [];
|
|
205
|
+
options.imports.presets.push({
|
|
206
|
+
from: "h3",
|
|
207
|
+
imports: h3Exports.filter((n) => !/^[A-Z]/.test(n) && n !== "use")
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
options.imports.dirs ??= [];
|
|
211
|
+
options.imports.dirs.push(
|
|
212
|
+
...options.scanDirs.map((dir) => join(dir, "utils/**/*"))
|
|
213
|
+
);
|
|
214
|
+
if (Array.isArray(options.imports.exclude) && options.imports.exclude.length === 0) {
|
|
215
|
+
options.imports.exclude.push(/[/\\]\.git[/\\]/);
|
|
216
|
+
options.imports.exclude.push(options.build.dir);
|
|
217
|
+
const scanDirsInNodeModules = options.scanDirs.map((dir) => dir.match(/(?<=\/)node_modules\/(.+)$/)?.[1]).filter(Boolean);
|
|
218
|
+
options.imports.exclude.push(
|
|
219
|
+
scanDirsInNodeModules.length > 0 ? new RegExp(
|
|
220
|
+
`node_modules\\/(?!${scanDirsInNodeModules.map((dir) => escapeRE(dir)).join("|")})`
|
|
221
|
+
) : /[/\\]node_modules[/\\]/
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
function getSilgiImportsPreset() {
|
|
226
|
+
return [
|
|
227
|
+
// TODO: buraya bizim importlarimiz gelecek.
|
|
228
|
+
{
|
|
229
|
+
from: "silgi",
|
|
230
|
+
imports: [
|
|
231
|
+
"createShared",
|
|
232
|
+
"useSilgi",
|
|
233
|
+
"createService",
|
|
234
|
+
"createSchema"
|
|
235
|
+
]
|
|
236
|
+
},
|
|
237
|
+
// {
|
|
238
|
+
// from: 'nitropack/runtime',
|
|
239
|
+
// imports: ['useRuntimeConfig', 'useAppConfig'],
|
|
240
|
+
// },
|
|
241
|
+
// {
|
|
242
|
+
// from: 'nitropack/runtime',
|
|
243
|
+
// imports: ['defineNitroPlugin', 'nitroPlugin'],
|
|
244
|
+
// },
|
|
245
|
+
// {
|
|
246
|
+
// from: 'nitropack/runtime/internal/cache',
|
|
247
|
+
// imports: [
|
|
248
|
+
// 'defineCachedFunction',
|
|
249
|
+
// 'defineCachedEventHandler',
|
|
250
|
+
// 'cachedFunction',
|
|
251
|
+
// 'cachedEventHandler',
|
|
252
|
+
// ],
|
|
253
|
+
// },
|
|
254
|
+
{
|
|
255
|
+
from: "silgi/core",
|
|
256
|
+
imports: ["useSilgiStorage"]
|
|
257
|
+
}
|
|
258
|
+
// {
|
|
259
|
+
// from: 'nitropack/runtime/internal/renderer',
|
|
260
|
+
// imports: ['defineRenderHandler'],
|
|
261
|
+
// },
|
|
262
|
+
// {
|
|
263
|
+
// from: 'nitropack/runtime/internal/meta',
|
|
264
|
+
// imports: ['defineRouteMeta'],
|
|
265
|
+
// },
|
|
266
|
+
// {
|
|
267
|
+
// from: 'nitropack/runtime/internal/route-rules',
|
|
268
|
+
// imports: ['getRouteRules'],
|
|
269
|
+
// },
|
|
270
|
+
// {
|
|
271
|
+
// from: 'nitropack/runtime/internal/context',
|
|
272
|
+
// imports: ['useEvent'],
|
|
273
|
+
// },
|
|
274
|
+
// {
|
|
275
|
+
// from: 'nitropack/runtime/internal/task',
|
|
276
|
+
// imports: ['defineTask', 'runTask'],
|
|
277
|
+
// },
|
|
278
|
+
// {
|
|
279
|
+
// from: 'nitropack/runtime/internal/error/utils',
|
|
280
|
+
// imports: ['defineNitroErrorHandler'],
|
|
281
|
+
// },
|
|
282
|
+
];
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
async function resolvePathOptions(options) {
|
|
286
|
+
options.rootDir = resolve(options.rootDir || ".");
|
|
287
|
+
options.workspaceDir = await findWorkspaceDir(options.rootDir).catch(
|
|
288
|
+
() => options.rootDir
|
|
289
|
+
);
|
|
290
|
+
options.srcDir = resolve(options.srcDir || options.rootDir);
|
|
291
|
+
for (const key of ["srcDir"]) {
|
|
292
|
+
options[key] = resolve(options.rootDir, options[key]);
|
|
293
|
+
}
|
|
294
|
+
options.build.dir = resolve(options.rootDir, options.build.dir);
|
|
295
|
+
options.build.typesDir = resolveSilgiPath(
|
|
296
|
+
options.build.typesDir || SilgiCLIDefaults.build.typesDir,
|
|
297
|
+
options,
|
|
298
|
+
options.rootDir
|
|
299
|
+
);
|
|
300
|
+
if (options.preset === "npm-package") {
|
|
301
|
+
const packageJsonPath = resolve(options.rootDir, "package.json");
|
|
302
|
+
const packageJson = await readPackageJSON(packageJsonPath);
|
|
303
|
+
if (packageJson.name === void 0) {
|
|
304
|
+
throw new Error("Package name is undefined");
|
|
305
|
+
}
|
|
306
|
+
options.alias ||= {};
|
|
307
|
+
options.alias[packageJson.name] = join(options.rootDir, "src/module.ts");
|
|
308
|
+
options.alias[`${packageJson.name}/runtime/`] = join(options.rootDir, "src/runtime/");
|
|
309
|
+
}
|
|
310
|
+
if (options.typescript?.internalPaths || options.stub) {
|
|
311
|
+
options.alias = {
|
|
312
|
+
...options.alias,
|
|
313
|
+
"silgi/runtime": join(runtimeDir),
|
|
314
|
+
"#internal/silgi": join(runtimeDir),
|
|
315
|
+
"silgi/runtime/*": join(runtimeDir, "*"),
|
|
316
|
+
"#internal/silgi/*": join(runtimeDir, "*")
|
|
317
|
+
};
|
|
318
|
+
options.typescript.customConditions = [
|
|
319
|
+
...options.typescript.customConditions,
|
|
320
|
+
"silgiTypes"
|
|
321
|
+
];
|
|
322
|
+
options.conditions ||= [];
|
|
323
|
+
options.conditions.push("silgi");
|
|
324
|
+
}
|
|
325
|
+
options.alias = {
|
|
326
|
+
...options.alias,
|
|
327
|
+
"~/": join(options.srcDir, "/"),
|
|
328
|
+
"@/": join(options.srcDir, "/"),
|
|
329
|
+
"~~/": join(options.rootDir, "/"),
|
|
330
|
+
"@@/": join(options.rootDir, "/")
|
|
331
|
+
};
|
|
332
|
+
if (options.preset === "npm-package") {
|
|
333
|
+
options.alias = {
|
|
334
|
+
...options.alias,
|
|
335
|
+
"#silgi/app/": join(options.build.dir, "/")
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
if (options.alias && typeof options.alias === "object") {
|
|
339
|
+
((options.typescript.tsConfig ??= {}).compilerOptions ??= {}).paths ??= {};
|
|
340
|
+
const paths = options.typescript.tsConfig.compilerOptions.paths;
|
|
341
|
+
for (const [key, value] of Object.entries(options.alias)) {
|
|
342
|
+
if (typeof paths === "object") {
|
|
343
|
+
paths[key] = [value];
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
if (options.typescript.tsConfig.compilerOptions?.paths && typeof options.typescript.tsConfig.compilerOptions.paths === "object") {
|
|
348
|
+
((options.typescript.tsConfig ??= {}).compilerOptions ??= {}).paths ??= {};
|
|
349
|
+
const paths = options.typescript.tsConfig.compilerOptions.paths;
|
|
350
|
+
for (const [key, value] of Object.entries(options.alias)) {
|
|
351
|
+
if (typeof paths === "object") {
|
|
352
|
+
paths[key] = [value];
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
options.modulesDir = [resolve(options.rootDir, "node_modules")];
|
|
357
|
+
options.output.dir = resolveSilgiPath(
|
|
358
|
+
options.output.dir || SilgiCLIDefaults.output.dir,
|
|
359
|
+
options,
|
|
360
|
+
options.rootDir
|
|
361
|
+
);
|
|
362
|
+
options.output.publicDir = resolveSilgiPath(
|
|
363
|
+
options.output.publicDir || SilgiCLIDefaults.output.publicDir,
|
|
364
|
+
options,
|
|
365
|
+
options.rootDir
|
|
366
|
+
);
|
|
367
|
+
options.output.serverDir = resolveSilgiPath(
|
|
368
|
+
options.output.serverDir || SilgiCLIDefaults.output.serverDir,
|
|
369
|
+
options,
|
|
370
|
+
options.rootDir
|
|
371
|
+
);
|
|
372
|
+
options.serverDir = resolveSilgiPath(
|
|
373
|
+
options.serverDir || SilgiCLIDefaults.serverDir,
|
|
374
|
+
options,
|
|
375
|
+
options.rootDir
|
|
376
|
+
);
|
|
377
|
+
options.clientDir = resolveSilgiPath(
|
|
378
|
+
options.clientDir || SilgiCLIDefaults.clientDir,
|
|
379
|
+
options,
|
|
380
|
+
options.rootDir
|
|
381
|
+
);
|
|
382
|
+
options.silgi.serverDir = resolveSilgiPath(
|
|
383
|
+
options.silgi.serverDir || SilgiCLIDefaults.silgi.serverDir,
|
|
384
|
+
options,
|
|
385
|
+
options.rootDir
|
|
386
|
+
);
|
|
387
|
+
options.silgi.clientDir = resolveSilgiPath(
|
|
388
|
+
options.silgi.clientDir || SilgiCLIDefaults.silgi.clientDir,
|
|
389
|
+
options,
|
|
390
|
+
options.rootDir
|
|
391
|
+
);
|
|
392
|
+
options.silgi.publicDir = resolveSilgiPath(
|
|
393
|
+
options.silgi.publicDir || SilgiCLIDefaults.silgi.publicDir,
|
|
394
|
+
options,
|
|
395
|
+
options.rootDir
|
|
396
|
+
);
|
|
397
|
+
options.silgi.utilsDir = resolveSilgiPath(
|
|
398
|
+
options.silgi.utilsDir || SilgiCLIDefaults.silgi.utilsDir,
|
|
399
|
+
options,
|
|
400
|
+
options.rootDir
|
|
401
|
+
);
|
|
402
|
+
options.silgi.vfsDir = resolveSilgiPath(
|
|
403
|
+
options.silgi.vfsDir || SilgiCLIDefaults.silgi.vfsDir,
|
|
404
|
+
options,
|
|
405
|
+
options.rootDir
|
|
406
|
+
);
|
|
407
|
+
options.silgi.typesDir = resolveSilgiPath(
|
|
408
|
+
options.silgi.typesDir || SilgiCLIDefaults.silgi.typesDir,
|
|
409
|
+
options,
|
|
410
|
+
options.rootDir
|
|
411
|
+
);
|
|
412
|
+
options.nodeModulesDirs.push(resolve(options.workspaceDir, "node_modules"));
|
|
413
|
+
options.nodeModulesDirs.push(resolve(options.rootDir, "node_modules"));
|
|
414
|
+
options.nodeModulesDirs.push(resolve(pkgDir, "node_modules"));
|
|
415
|
+
options.nodeModulesDirs.push(resolve(pkgDir, ".."));
|
|
416
|
+
options.nodeModulesDirs = [
|
|
417
|
+
...new Set(
|
|
418
|
+
options.nodeModulesDirs.map((dir) => resolve(options.rootDir, dir))
|
|
419
|
+
)
|
|
420
|
+
];
|
|
421
|
+
options.scanDirs.unshift(options.srcDir);
|
|
422
|
+
options.scanDirs = options.scanDirs.map(
|
|
423
|
+
(dir) => resolve(options.srcDir, dir)
|
|
424
|
+
);
|
|
425
|
+
options.scanDirs = [...new Set(options.scanDirs)];
|
|
426
|
+
options.appConfigFiles ??= [];
|
|
427
|
+
options.appConfigFiles = options.appConfigFiles.map((file) => _tryResolve(resolveSilgiPath(file, options))).filter(Boolean);
|
|
428
|
+
for (const dir of options.scanDirs) {
|
|
429
|
+
const configFile = _tryResolve("app.config", dir);
|
|
430
|
+
if (configFile && !options.appConfigFiles.includes(configFile)) {
|
|
431
|
+
options.appConfigFiles.push(configFile);
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
const modulesRuntimePaths = {};
|
|
435
|
+
if (options.typescript?.internalPaths) {
|
|
436
|
+
for (let i of options.modules) {
|
|
437
|
+
if (typeof i === "string") {
|
|
438
|
+
i = resolveAlias(i, options.alias);
|
|
439
|
+
if (isRelative(i)) {
|
|
440
|
+
i = resolve(options.rootDir, i);
|
|
441
|
+
}
|
|
442
|
+
const src = isAbsolute(i) ? pathToFileURL(await resolvePath(i, { fallbackToOriginal: false, extensions: options.extensions })).href : await resolvePath$1(i, { url: options.modulesDir.map((m) => pathToFileURL(m.replace(/\/node_modules\/?$/, ""))), extensions: options.extensions });
|
|
443
|
+
const cleanPath = src.replace(/(\/(?:src|dist)(?:\/runtime)?(?:\/.*)?$)/, "");
|
|
444
|
+
modulesRuntimePaths[`${i}/runtime`] = `${cleanPath}/src/runtime`;
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
for (const [key, value] of Object.entries(modulesRuntimePaths)) {
|
|
448
|
+
options.alias = {
|
|
449
|
+
...options.alias,
|
|
450
|
+
[`${key}`]: value
|
|
451
|
+
};
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
function _tryResolve(path, base = ".", extensions = ["", ".js", ".ts", ".mjs", ".cjs", ".json"]) {
|
|
456
|
+
path = resolve(base, path);
|
|
457
|
+
if (existsSync(path)) {
|
|
458
|
+
return path;
|
|
459
|
+
}
|
|
460
|
+
for (const ext of extensions) {
|
|
461
|
+
const p = path + ext;
|
|
462
|
+
if (existsSync(p)) {
|
|
463
|
+
return p;
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
async function resolveStorageOptions(options) {
|
|
469
|
+
const fsMounts = {
|
|
470
|
+
root: resolve(options.rootDir),
|
|
471
|
+
src: resolve(options.srcDir),
|
|
472
|
+
build: resolve(options.build.dir),
|
|
473
|
+
cache: resolve(options.build.dir, "cache")
|
|
474
|
+
};
|
|
475
|
+
for (const p in fsMounts) {
|
|
476
|
+
options.devStorage[p] = options.devStorage[p] || {
|
|
477
|
+
driver: "fs",
|
|
478
|
+
readOnly: p === "root" || p === "src",
|
|
479
|
+
base: fsMounts[p]
|
|
480
|
+
};
|
|
481
|
+
}
|
|
482
|
+
if (options.dev && options.storage.data === void 0 && options.devStorage.data === void 0) {
|
|
483
|
+
options.devStorage.data = {
|
|
484
|
+
driver: "fs",
|
|
485
|
+
base: resolve(options.rootDir, ".data/kv")
|
|
486
|
+
};
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
async function resolveURLOptions(options) {
|
|
491
|
+
options.baseURL = withLeadingSlash(withTrailingSlash(options.baseURL));
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
const configResolvers = [
|
|
495
|
+
resolveCompatibilityOptions,
|
|
496
|
+
resolvePathOptions,
|
|
497
|
+
resolveImportsOptions,
|
|
498
|
+
// resolveRouteRulesOptions,
|
|
499
|
+
// resolveDatabaseOptions,
|
|
500
|
+
// resolveFetchOptions,
|
|
501
|
+
// resolveExportConditionsOptions,
|
|
502
|
+
// resolveRuntimeConfigOptions,
|
|
503
|
+
// resolveOpenAPIOptions,
|
|
504
|
+
resolveURLOptions,
|
|
505
|
+
// resolveAssetsOptions,
|
|
506
|
+
resolveStorageOptions
|
|
507
|
+
// resolveErrorOptions,
|
|
508
|
+
];
|
|
509
|
+
async function loadOptions(configOverrides = {}, opts = {}) {
|
|
510
|
+
const options = await _loadUserConfig(configOverrides, opts);
|
|
511
|
+
for (const resolver of configResolvers) {
|
|
512
|
+
await resolver(options);
|
|
513
|
+
}
|
|
514
|
+
return options;
|
|
515
|
+
}
|
|
516
|
+
async function _loadUserConfig(configOverrides = {}, opts = {}) {
|
|
517
|
+
const presetOverride = configOverrides.preset || process.env.SILGI_PRESET;
|
|
518
|
+
if (configOverrides.dev) ;
|
|
519
|
+
configOverrides = klona(configOverrides);
|
|
520
|
+
globalThis.defineSilgiConfig = globalThis.defineSilgiConfig || ((c) => c);
|
|
521
|
+
let compatibilityDate = configOverrides.compatibilityDate || opts.compatibilityDate || (process.env.SILGI_COMPATIBILITY_DATE || process.env.SERVER_COMPATIBILITY_DATE || process.env.COMPATIBILITY_DATE);
|
|
522
|
+
const { resolvePreset } = await import('silgi/presets');
|
|
523
|
+
const loadedConfig = await (opts.watch ? watchConfig : loadConfig)({
|
|
524
|
+
name: "silgi",
|
|
525
|
+
cwd: configOverrides.rootDir,
|
|
526
|
+
dotenv: configOverrides.dev,
|
|
527
|
+
extend: { extendKey: ["extends", "preset"] },
|
|
528
|
+
overrides: {
|
|
529
|
+
...configOverrides,
|
|
530
|
+
preset: presetOverride
|
|
531
|
+
},
|
|
532
|
+
async defaultConfig({ configs }) {
|
|
533
|
+
const getConf = (key) => configs.main?.[key] ?? configs.rc?.[key] ?? configs.packageJson?.[key];
|
|
534
|
+
if (!compatibilityDate) {
|
|
535
|
+
compatibilityDate = getConf("compatibilityDate");
|
|
536
|
+
}
|
|
537
|
+
return {
|
|
538
|
+
// typescript: {
|
|
539
|
+
// generateRuntimeConfigTypes:
|
|
540
|
+
// !framework?.name || framework.name === 'nitro',
|
|
541
|
+
// },
|
|
542
|
+
preset: presetOverride || (await resolvePreset("", {
|
|
543
|
+
static: getConf("static"),
|
|
544
|
+
compatibilityDate: compatibilityDate || fallbackCompatibilityDate
|
|
545
|
+
}))?._meta?.name
|
|
546
|
+
};
|
|
547
|
+
},
|
|
548
|
+
defaults: SilgiCLIDefaults,
|
|
549
|
+
jitiOptions: {
|
|
550
|
+
alias: {
|
|
551
|
+
"silgi": "silgi/config",
|
|
552
|
+
"silgi/config": "silgi/config"
|
|
553
|
+
}
|
|
554
|
+
},
|
|
555
|
+
async resolve(id) {
|
|
556
|
+
const preset = await resolvePreset(id, {
|
|
557
|
+
static: configOverrides.static,
|
|
558
|
+
compatibilityDate: compatibilityDate || fallbackCompatibilityDate
|
|
559
|
+
});
|
|
560
|
+
if (preset) {
|
|
561
|
+
return {
|
|
562
|
+
config: klona(preset)
|
|
563
|
+
};
|
|
564
|
+
}
|
|
565
|
+
},
|
|
566
|
+
...opts.c12
|
|
567
|
+
});
|
|
568
|
+
delete globalThis.defineSilgiConfig;
|
|
569
|
+
const options = klona(loadedConfig.config);
|
|
570
|
+
options._config = configOverrides;
|
|
571
|
+
options._c12 = loadedConfig;
|
|
572
|
+
const _presetName = (loadedConfig.layers || []).find((l) => l.config?._meta?.name)?.config?._meta?.name || presetOverride;
|
|
573
|
+
options.preset = _presetName;
|
|
574
|
+
options.compatibilityDate = resolveCompatibilityDates(
|
|
575
|
+
compatibilityDate,
|
|
576
|
+
options.compatibilityDate
|
|
577
|
+
);
|
|
578
|
+
return options;
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
export { loadOptions as l };
|