silgi 0.3.12 → 0.4.0
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/README.md +1 -31
- package/cli.d.ts +1 -0
- package/config.d.ts +1 -0
- package/core.d.ts +1 -0
- package/dist/_chunks/index.mjs +233 -0
- package/dist/cli/compatibility.mjs +42 -0
- package/dist/cli/index.mjs +3 -178
- package/dist/cli/prepare.mjs +1346 -0
- package/dist/config/index.d.mts +5 -0
- package/dist/config/index.d.ts +5 -0
- package/dist/core/index.d.mts +136 -0
- package/dist/core/index.d.ts +136 -0
- package/dist/core/index.mjs +1444 -0
- package/dist/ecosystem/nitro/index.mjs +21 -10
- package/dist/ecosystem/nuxt/module.mjs +4 -6
- package/dist/kit/index.d.mts +90 -0
- package/dist/kit/index.d.ts +90 -0
- package/dist/kit/index.mjs +316 -0
- package/dist/meta/index.d.mts +3 -0
- package/dist/meta/index.d.ts +3 -0
- package/dist/meta/index.mjs +1 -0
- package/dist/presets/_all.gen.d.ts +2 -0
- package/dist/presets/_all.gen.mjs +8 -0
- package/dist/presets/_resolve.d.ts +8 -0
- package/dist/presets/_resolve.mjs +58 -0
- package/dist/presets/_types.gen.d.ts +5 -0
- package/dist/presets/_types.gen.mjs +1 -0
- package/dist/presets/h3/preset.d.ts +2 -0
- package/dist/presets/h3/preset.mjs +22 -0
- package/dist/presets/index.d.mts +1 -0
- package/dist/presets/index.d.ts +2 -0
- package/dist/presets/index.mjs +1 -0
- package/dist/presets/nitro/preset.d.ts +2 -0
- package/dist/presets/nitro/preset.mjs +26 -0
- package/dist/presets/npmpackage/preset.d.ts +2 -0
- package/dist/presets/npmpackage/preset.mjs +23 -0
- package/dist/runtime/index.d.ts +1 -0
- package/dist/runtime/index.mjs +1 -0
- package/dist/runtime/internal/debug.d.ts +2 -0
- package/dist/runtime/internal/debug.mjs +5 -0
- package/dist/runtime/internal/nitro.d.ts +2 -0
- package/dist/runtime/internal/nitro.mjs +45 -0
- package/dist/runtime/internal/plugin.d.ts +3 -0
- package/dist/runtime/internal/plugin.mjs +4 -0
- package/dist/shared/silgi.40ZJYm8F.d.mts +11 -0
- package/dist/shared/silgi.40ZJYm8F.d.ts +11 -0
- package/dist/shared/{silgi.ClpvycKI.d.mts → silgi.D8h2AAVk.d.ts} +451 -437
- package/dist/shared/{silgi.ClpvycKI.d.ts → silgi.DSHNePNA.d.mts} +451 -437
- package/dist/types/index.d.mts +42 -0
- package/dist/types/index.d.ts +42 -0
- package/dist/types/index.mjs +1 -0
- package/kit.d.ts +1 -0
- package/meta.d.ts +1 -0
- package/package.json +89 -39
- package/presets.d.ts +1 -0
- package/runtime-meta.d.ts +4 -0
- package/runtime-meta.mjs +32 -0
- package/runtime.d.ts +1 -0
- package/types.d.ts +1 -0
- package/bin/silgi.mjs +0 -3
- package/dist/chunks/generate.mjs +0 -1258
- package/dist/cli/config.d.mts +0 -1633
- package/dist/cli/config.d.ts +0 -1633
- package/dist/index.d.mts +0 -196
- package/dist/index.d.ts +0 -196
- package/dist/index.mjs +0 -499
- package/dist/shared/silgi.b9yhSIGd.mjs +0 -459
- package/dist/shared/silgi.mBwNj1W0.mjs +0 -386
- /package/dist/{chunks → cli}/init.mjs +0 -0
- /package/dist/{cli/config.mjs → config/index.mjs} +0 -0
|
@@ -1,14 +1,13 @@
|
|
|
1
|
+
import { execSync } from 'node:child_process';
|
|
1
2
|
import { fileURLToPath } from 'node:url';
|
|
2
3
|
import { resolve, dirname, join } from 'pathe';
|
|
3
|
-
import {
|
|
4
|
-
import '
|
|
5
|
-
import 'untyped';
|
|
6
|
-
import 'std-env';
|
|
4
|
+
import { loadOptions } from 'silgi/core';
|
|
5
|
+
import { relativeWithDot } from 'silgi/kit';
|
|
7
6
|
|
|
8
7
|
const module = {
|
|
9
8
|
name: "silgi",
|
|
10
9
|
setup: async (nitro) => {
|
|
11
|
-
const silgiConfig = await
|
|
10
|
+
const silgiConfig = await loadOptions({});
|
|
12
11
|
nitro.options.plugins = nitro.options.plugins || [];
|
|
13
12
|
nitro.options.plugins.push(
|
|
14
13
|
fileURLToPath(new URL("runtime/plugin", import.meta.url))
|
|
@@ -20,15 +19,27 @@ const module = {
|
|
|
20
19
|
const tsconfigDir = dirname(tsConfigPath);
|
|
21
20
|
nitro.options.typescript.strict = true;
|
|
22
21
|
nitro.options.typescript.tsConfig ??= {};
|
|
23
|
-
nitro.options.typescript.tsConfig.
|
|
24
|
-
nitro.options.typescript.tsConfig.include
|
|
22
|
+
nitro.options.typescript.tsConfig.extends = "./silgi.tsconfig.json";
|
|
23
|
+
nitro.options.typescript.tsConfig.include ??= [];
|
|
24
|
+
nitro.options.typescript.tsConfig.exclude ??= [];
|
|
25
|
+
if (silgiConfig.typescript.internalPaths) {
|
|
26
|
+
nitro.options.alias ||= {};
|
|
27
|
+
nitro.options.alias = {
|
|
28
|
+
...nitro.options.alias,
|
|
29
|
+
...silgiConfig.alias
|
|
30
|
+
// 'silgi/runtime': fileURLToPath(`${new URL(pkgDir, import.meta.url)}dist/runtime/`),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
nitro.options.typescript.tsConfig.include.push(join(relativeWithDot(tsconfigDir, silgiConfig.build.dir), "**/*"));
|
|
25
34
|
nitro.options.typescript.tsConfig.compilerOptions ??= {};
|
|
26
|
-
nitro.options.typescript.tsConfig.compilerOptions.
|
|
27
|
-
nitro.
|
|
35
|
+
nitro.options.typescript.tsConfig.compilerOptions.paths ??= {};
|
|
36
|
+
nitro.hooks.hook("types:extend", async () => {
|
|
37
|
+
execSync("pnpm silgi prepare", { stdio: "inherit", cwd: nitro.options.rootDir, env: process.env });
|
|
38
|
+
});
|
|
28
39
|
if (nitro.options.imports) {
|
|
29
40
|
nitro.options.imports.dirs ??= [];
|
|
30
41
|
nitro.options.imports.dirs.push(
|
|
31
|
-
join(silgiConfig.
|
|
42
|
+
join(silgiConfig.silgi.serverDir, "**/*")
|
|
32
43
|
);
|
|
33
44
|
nitro.options.imports.presets ??= [];
|
|
34
45
|
nitro.options.imports.presets.push({
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { defineNuxtModule, createResolver, addImportsDir } from '@nuxt/kit';
|
|
2
2
|
import { resolvePath } from 'mlly';
|
|
3
3
|
import { join } from 'pathe';
|
|
4
|
-
import {
|
|
5
|
-
import '
|
|
6
|
-
import 'untyped';
|
|
7
|
-
import 'std-env';
|
|
4
|
+
import { loadOptions } from 'silgi/core';
|
|
5
|
+
import { relativeWithDot } from 'silgi/kit';
|
|
8
6
|
|
|
9
7
|
const module = defineNuxtModule({
|
|
10
8
|
meta: {
|
|
@@ -19,12 +17,12 @@ const module = defineNuxtModule({
|
|
|
19
17
|
const { resolve } = createResolver(import.meta.url);
|
|
20
18
|
const runtimeDir = resolve("./runtime");
|
|
21
19
|
const composablesDir = resolve(join(runtimeDir, "./composables"));
|
|
22
|
-
const silgi = await
|
|
20
|
+
const silgi = await loadOptions({});
|
|
23
21
|
nuxt.options.build.transpile.push("silgi");
|
|
24
22
|
nuxt.options.nitro.modules ||= [];
|
|
25
23
|
nuxt.options.nitro.modules.push(await resolvePath("silgi/ecosystem/nitro"));
|
|
26
24
|
nuxt.hook("prepare:types", ({ references }) => {
|
|
27
|
-
references.push({ path: relativeWithDot(nuxt.options.buildDir, join(silgi.
|
|
25
|
+
references.push({ path: relativeWithDot(nuxt.options.buildDir, join(silgi.build.dir, "silgi.d.ts")) });
|
|
28
26
|
});
|
|
29
27
|
addImportsDir(composablesDir);
|
|
30
28
|
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { Buffer } from 'node:buffer';
|
|
2
|
+
import { GraphQLSchema } from 'graphql';
|
|
3
|
+
import { SilgiCLI, GraphQLJSON, SilgiPreset, SilgiPresetMeta } from 'silgi/types';
|
|
4
|
+
import { w as ModuleOptions, y as ModuleDefinition, F as SilgiModule } from '../shared/silgi.DSHNePNA.mjs';
|
|
5
|
+
import 'defu';
|
|
6
|
+
import '@graphql-tools/utils';
|
|
7
|
+
import 'pkg-types';
|
|
8
|
+
import '@standard-schema/spec';
|
|
9
|
+
import 'consola';
|
|
10
|
+
import 'hookable';
|
|
11
|
+
import 'silgi/presets';
|
|
12
|
+
import 'unimport';
|
|
13
|
+
import 'unstorage';
|
|
14
|
+
import 'c12';
|
|
15
|
+
import 'chokidar';
|
|
16
|
+
import 'compatx';
|
|
17
|
+
import 'unimport/unplugin';
|
|
18
|
+
import 'std-env';
|
|
19
|
+
import '../shared/silgi.40ZJYm8F.mjs';
|
|
20
|
+
import 'ignore';
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Resolve a module from a given root path using an algorithm patterned on
|
|
24
|
+
* the upcoming `import.meta.resolve`. It returns a file URL
|
|
25
|
+
*
|
|
26
|
+
* @internal
|
|
27
|
+
*/
|
|
28
|
+
declare function tryResolveModule(id: string, url?: string | string[]): Promise<string | undefined>;
|
|
29
|
+
|
|
30
|
+
declare function writeFile(file: string, contents: Buffer | string, log?: boolean): Promise<void>;
|
|
31
|
+
declare function isDirectory(path: string): Promise<boolean>;
|
|
32
|
+
|
|
33
|
+
declare function exportGraphQLInterfaceType(silgi: SilgiCLI, schema: GraphQLSchema): void;
|
|
34
|
+
|
|
35
|
+
declare function extractGraphQLSchemaToJSON(schema: GraphQLSchema): GraphQLJSON;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Define a Silgi module, automatically merging defaults with user provided options, installing
|
|
39
|
+
* any hooks that are provided, and calling an optional setup function for full control.
|
|
40
|
+
*/
|
|
41
|
+
declare function defineSilgiModule<TOptions extends ModuleOptions>(definition: ModuleDefinition<TOptions, Partial<TOptions>, false> | SilgiModule<TOptions, Partial<TOptions>, false>): SilgiModule<TOptions, TOptions, false>;
|
|
42
|
+
declare function defineSilgiModule<TOptions extends ModuleOptions>(): {
|
|
43
|
+
with: <TOptionsDefaults extends Partial<TOptions>>(definition: ModuleDefinition<TOptions, TOptionsDefaults, true> | SilgiModule<TOptions, TOptionsDefaults, true>) => SilgiModule<TOptions, TOptionsDefaults, true>;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
declare function prettyPath(p: string, highlight?: boolean): string;
|
|
47
|
+
declare function resolveSilgiPath(path: string, silgiCLIOptions: SilgiCLI['options'], base?: string): string;
|
|
48
|
+
|
|
49
|
+
declare function defineSilgiPreset<P extends SilgiPreset, M extends SilgiPresetMeta>(preset: P, meta?: M): P & {
|
|
50
|
+
_meta: SilgiPresetMeta;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
interface ResolvePathOptions {
|
|
54
|
+
modulesDir?: string[];
|
|
55
|
+
/** Base for resolving paths from. Default is Nuxt rootDir. */
|
|
56
|
+
cwd?: string;
|
|
57
|
+
/** An object of aliases. Default is Nuxt configured aliases. */
|
|
58
|
+
alias?: Record<string, string>;
|
|
59
|
+
/** The file extensions to try. Default is Nuxt configured extensions. */
|
|
60
|
+
extensions?: string[];
|
|
61
|
+
/**
|
|
62
|
+
* Whether to fallback to the original path if the resolved path does not exist instead of returning the normalized input path.
|
|
63
|
+
*
|
|
64
|
+
* @default false
|
|
65
|
+
*/
|
|
66
|
+
fallbackToOriginal?: boolean;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Resolve full path to a file or directory respecting Nuxt alias and extensions options
|
|
70
|
+
*
|
|
71
|
+
* If path could not be resolved, normalized input path will be returned
|
|
72
|
+
*/
|
|
73
|
+
declare function resolvePath(path: string, opts?: ResolvePathOptions): Promise<string>;
|
|
74
|
+
/**
|
|
75
|
+
* Resolve path aliases respecting Nuxt alias options
|
|
76
|
+
*/
|
|
77
|
+
declare function resolveAlias(path: string, alias?: Record<string, string>): string;
|
|
78
|
+
interface Resolver {
|
|
79
|
+
resolve: (...path: string[]) => string;
|
|
80
|
+
resolvePath: (path: string, opts?: ResolvePathOptions) => Promise<string>;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Create a relative resolver
|
|
84
|
+
*/
|
|
85
|
+
declare function createResolver(base: string | URL): Resolver;
|
|
86
|
+
declare function resolveSilgiModule(base: string, paths: string[]): Promise<string[]>;
|
|
87
|
+
|
|
88
|
+
declare function relativeWithDot(from: string, to: string): string;
|
|
89
|
+
|
|
90
|
+
export { createResolver, defineSilgiModule, defineSilgiPreset, exportGraphQLInterfaceType, extractGraphQLSchemaToJSON, isDirectory, prettyPath, relativeWithDot, resolveAlias, resolvePath, resolveSilgiModule, resolveSilgiPath, tryResolveModule, writeFile };
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { Buffer } from 'node:buffer';
|
|
2
|
+
import { GraphQLSchema } from 'graphql';
|
|
3
|
+
import { SilgiCLI, GraphQLJSON, SilgiPreset, SilgiPresetMeta } from 'silgi/types';
|
|
4
|
+
import { w as ModuleOptions, y as ModuleDefinition, F as SilgiModule } from '../shared/silgi.D8h2AAVk.js';
|
|
5
|
+
import 'defu';
|
|
6
|
+
import '@graphql-tools/utils';
|
|
7
|
+
import 'pkg-types';
|
|
8
|
+
import '@standard-schema/spec';
|
|
9
|
+
import 'consola';
|
|
10
|
+
import 'hookable';
|
|
11
|
+
import 'silgi/presets';
|
|
12
|
+
import 'unimport';
|
|
13
|
+
import 'unstorage';
|
|
14
|
+
import 'c12';
|
|
15
|
+
import 'chokidar';
|
|
16
|
+
import 'compatx';
|
|
17
|
+
import 'unimport/unplugin';
|
|
18
|
+
import 'std-env';
|
|
19
|
+
import '../shared/silgi.40ZJYm8F.js';
|
|
20
|
+
import 'ignore';
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Resolve a module from a given root path using an algorithm patterned on
|
|
24
|
+
* the upcoming `import.meta.resolve`. It returns a file URL
|
|
25
|
+
*
|
|
26
|
+
* @internal
|
|
27
|
+
*/
|
|
28
|
+
declare function tryResolveModule(id: string, url?: string | string[]): Promise<string | undefined>;
|
|
29
|
+
|
|
30
|
+
declare function writeFile(file: string, contents: Buffer | string, log?: boolean): Promise<void>;
|
|
31
|
+
declare function isDirectory(path: string): Promise<boolean>;
|
|
32
|
+
|
|
33
|
+
declare function exportGraphQLInterfaceType(silgi: SilgiCLI, schema: GraphQLSchema): void;
|
|
34
|
+
|
|
35
|
+
declare function extractGraphQLSchemaToJSON(schema: GraphQLSchema): GraphQLJSON;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Define a Silgi module, automatically merging defaults with user provided options, installing
|
|
39
|
+
* any hooks that are provided, and calling an optional setup function for full control.
|
|
40
|
+
*/
|
|
41
|
+
declare function defineSilgiModule<TOptions extends ModuleOptions>(definition: ModuleDefinition<TOptions, Partial<TOptions>, false> | SilgiModule<TOptions, Partial<TOptions>, false>): SilgiModule<TOptions, TOptions, false>;
|
|
42
|
+
declare function defineSilgiModule<TOptions extends ModuleOptions>(): {
|
|
43
|
+
with: <TOptionsDefaults extends Partial<TOptions>>(definition: ModuleDefinition<TOptions, TOptionsDefaults, true> | SilgiModule<TOptions, TOptionsDefaults, true>) => SilgiModule<TOptions, TOptionsDefaults, true>;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
declare function prettyPath(p: string, highlight?: boolean): string;
|
|
47
|
+
declare function resolveSilgiPath(path: string, silgiCLIOptions: SilgiCLI['options'], base?: string): string;
|
|
48
|
+
|
|
49
|
+
declare function defineSilgiPreset<P extends SilgiPreset, M extends SilgiPresetMeta>(preset: P, meta?: M): P & {
|
|
50
|
+
_meta: SilgiPresetMeta;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
interface ResolvePathOptions {
|
|
54
|
+
modulesDir?: string[];
|
|
55
|
+
/** Base for resolving paths from. Default is Nuxt rootDir. */
|
|
56
|
+
cwd?: string;
|
|
57
|
+
/** An object of aliases. Default is Nuxt configured aliases. */
|
|
58
|
+
alias?: Record<string, string>;
|
|
59
|
+
/** The file extensions to try. Default is Nuxt configured extensions. */
|
|
60
|
+
extensions?: string[];
|
|
61
|
+
/**
|
|
62
|
+
* Whether to fallback to the original path if the resolved path does not exist instead of returning the normalized input path.
|
|
63
|
+
*
|
|
64
|
+
* @default false
|
|
65
|
+
*/
|
|
66
|
+
fallbackToOriginal?: boolean;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Resolve full path to a file or directory respecting Nuxt alias and extensions options
|
|
70
|
+
*
|
|
71
|
+
* If path could not be resolved, normalized input path will be returned
|
|
72
|
+
*/
|
|
73
|
+
declare function resolvePath(path: string, opts?: ResolvePathOptions): Promise<string>;
|
|
74
|
+
/**
|
|
75
|
+
* Resolve path aliases respecting Nuxt alias options
|
|
76
|
+
*/
|
|
77
|
+
declare function resolveAlias(path: string, alias?: Record<string, string>): string;
|
|
78
|
+
interface Resolver {
|
|
79
|
+
resolve: (...path: string[]) => string;
|
|
80
|
+
resolvePath: (path: string, opts?: ResolvePathOptions) => Promise<string>;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Create a relative resolver
|
|
84
|
+
*/
|
|
85
|
+
declare function createResolver(base: string | URL): Resolver;
|
|
86
|
+
declare function resolveSilgiModule(base: string, paths: string[]): Promise<string[]>;
|
|
87
|
+
|
|
88
|
+
declare function relativeWithDot(from: string, to: string): string;
|
|
89
|
+
|
|
90
|
+
export { createResolver, defineSilgiModule, defineSilgiPreset, exportGraphQLInterfaceType, extractGraphQLSchemaToJSON, isDirectory, prettyPath, relativeWithDot, resolveAlias, resolvePath, resolveSilgiModule, resolveSilgiPath, tryResolveModule, writeFile };
|
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
import { resolvePath as resolvePath$1 } from 'mlly';
|
|
2
|
+
import fsp from 'node:fs/promises';
|
|
3
|
+
import consola, { consola as consola$1 } from 'consola';
|
|
4
|
+
import { relative, resolve, dirname, normalize, isAbsolute, join } from 'pathe';
|
|
5
|
+
import { colors } from 'consola/utils';
|
|
6
|
+
import { getProperty } from 'dot-prop';
|
|
7
|
+
import { extractGraphQLSchemaToJSON as extractGraphQLSchemaToJSON$1 } from 'silgi/kit';
|
|
8
|
+
import { defu } from 'defu';
|
|
9
|
+
import { u as useSilgiCLI, c as checkSilgiCompatibility, t as tryUseSilgiCLI } from '../cli/compatibility.mjs';
|
|
10
|
+
import { existsSync, promises } from 'node:fs';
|
|
11
|
+
import { fileURLToPath } from 'node:url';
|
|
12
|
+
import { resolveAlias as resolveAlias$1 } from 'pathe/utils';
|
|
13
|
+
import 'semver/functions/satisfies.js';
|
|
14
|
+
import 'silgi/meta';
|
|
15
|
+
import 'unctx';
|
|
16
|
+
|
|
17
|
+
async function tryResolveModule(id, url = import.meta.url) {
|
|
18
|
+
try {
|
|
19
|
+
return await resolvePath$1(id, { url });
|
|
20
|
+
} catch {
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function prettyPath(p, highlight = true) {
|
|
25
|
+
p = relative(process.cwd(), p);
|
|
26
|
+
return highlight ? colors.cyan(p) : p;
|
|
27
|
+
}
|
|
28
|
+
function resolveSilgiPath(path, silgiCLIOptions, base) {
|
|
29
|
+
if (typeof path !== "string") {
|
|
30
|
+
throw new TypeError(`Invalid path: ${path}`);
|
|
31
|
+
}
|
|
32
|
+
path = _compilePathTemplate(path)(silgiCLIOptions);
|
|
33
|
+
for (const base2 in silgiCLIOptions.alias) {
|
|
34
|
+
if (path.startsWith(base2)) {
|
|
35
|
+
path = silgiCLIOptions.alias[base2] + path.slice(base2.length);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return resolve(base || silgiCLIOptions.srcDir, path);
|
|
39
|
+
}
|
|
40
|
+
function _compilePathTemplate(contents) {
|
|
41
|
+
return (params) => contents.replace(/\{\{ ?([\w.]+) ?\}\}/g, (_, match) => {
|
|
42
|
+
const val = getProperty(params, match);
|
|
43
|
+
if (!val) {
|
|
44
|
+
consola.warn(
|
|
45
|
+
`cannot resolve template param '${match}' in ${contents.slice(0, 20)}`
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
return val || `${match}`;
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async function writeFile(file, contents, log = false) {
|
|
53
|
+
await fsp.mkdir(dirname(file), { recursive: true });
|
|
54
|
+
await fsp.writeFile(
|
|
55
|
+
file,
|
|
56
|
+
contents,
|
|
57
|
+
typeof contents === "string" ? "utf8" : undefined
|
|
58
|
+
);
|
|
59
|
+
if (log) {
|
|
60
|
+
consola$1.info("Generated", prettyPath(file));
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
async function isDirectory$1(path) {
|
|
64
|
+
try {
|
|
65
|
+
return (await fsp.stat(path)).isDirectory();
|
|
66
|
+
} catch {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function exportGraphQLInterfaceType(silgi, schema) {
|
|
72
|
+
const schemasJSON = extractGraphQLSchemaToJSON$1(schema);
|
|
73
|
+
for (const [key, schemaValue] of Object.entries(schemasJSON)) {
|
|
74
|
+
if (key === "queries") {
|
|
75
|
+
for (const [queryKey, _queryValue] of Object.entries(schemaValue)) {
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
if (key === "mutations") {
|
|
79
|
+
for (const [mutationKey, _mutationValue] of Object.entries(schemaValue)) {
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
if (key === "types") {
|
|
83
|
+
for (const [typeName, typeValue] of Object.entries(schemaValue)) {
|
|
84
|
+
if (typeof typeValue === "string" && typeValue.startsWith("$ref:")) {
|
|
85
|
+
const refName = typeValue.replace("$ref:", "");
|
|
86
|
+
const refFields = schemasJSON.references?.[refName];
|
|
87
|
+
if (refFields) {
|
|
88
|
+
for (const fieldName of Object.keys(refFields)) {
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function extractGraphQLSchemaToJSON(schema) {
|
|
98
|
+
const result = {
|
|
99
|
+
queries: {},
|
|
100
|
+
mutations: {},
|
|
101
|
+
types: {},
|
|
102
|
+
inputs: {},
|
|
103
|
+
references: {}
|
|
104
|
+
// Schema içindeki tüm referansları tutacak
|
|
105
|
+
};
|
|
106
|
+
function getTypeReference(type) {
|
|
107
|
+
if (["GraphQLScalarType", "GraphQLEnumType"].includes(type.constructor.name)) {
|
|
108
|
+
return type.name;
|
|
109
|
+
}
|
|
110
|
+
const typeName = type.name.toLowerCase();
|
|
111
|
+
if (!result.references[typeName]) {
|
|
112
|
+
const fields = {};
|
|
113
|
+
const typeFields = type.constructor.name === "GraphQLInputObjectType" ? type.getFields() : type._fields;
|
|
114
|
+
Object.entries(typeFields || {}).forEach(([fieldName, field]) => {
|
|
115
|
+
if (field?.type) {
|
|
116
|
+
if (["GraphQLObjectType", "GraphQLInputObjectType"].includes(field.type.constructor.name)) {
|
|
117
|
+
fields[fieldName] = `$ref:${field.type.name.toLowerCase()}`;
|
|
118
|
+
} else {
|
|
119
|
+
fields[fieldName] = field.type.name;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
result.references[typeName] = fields;
|
|
124
|
+
}
|
|
125
|
+
return `$ref:${typeName}`;
|
|
126
|
+
}
|
|
127
|
+
Object.entries(schema.getQueryType()?.getFields() || {}).forEach(([name, field]) => {
|
|
128
|
+
result.queries[name] = {
|
|
129
|
+
input: {},
|
|
130
|
+
output: field.type.name === "String" ? "String" : `$ref:${field.type.name.toLowerCase()}`
|
|
131
|
+
};
|
|
132
|
+
if (field.args?.length) {
|
|
133
|
+
field.args.forEach((arg) => {
|
|
134
|
+
result.queries[name].input[arg.name] = getTypeReference(arg.type);
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
Object.entries(schema.getMutationType()?.getFields() || {}).forEach(([name, field]) => {
|
|
139
|
+
result.mutations[name] = {
|
|
140
|
+
input: {},
|
|
141
|
+
output: field.type.name === "String" ? "String" : `$ref:${field.type.name.toLowerCase()}`
|
|
142
|
+
};
|
|
143
|
+
if (field.args?.length) {
|
|
144
|
+
field.args.forEach((arg) => {
|
|
145
|
+
result.mutations[name].input[arg.name] = getTypeReference(arg.type);
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
Object.entries(schema.getTypeMap()).forEach(([typeName, type]) => {
|
|
150
|
+
if (typeName.startsWith("__") || ["Query", "Mutation"].includes(typeName)) {
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
if (["GraphQLScalarType", "GraphQLEnumType"].includes(type.constructor.name)) {
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
const typeKey = typeName.toLowerCase();
|
|
157
|
+
if (type.constructor.name === "GraphQLInputObjectType") {
|
|
158
|
+
result.inputs[typeKey] = `$ref:${typeKey}`;
|
|
159
|
+
} else {
|
|
160
|
+
result.types[typeKey] = `$ref:${typeKey}`;
|
|
161
|
+
}
|
|
162
|
+
getTypeReference(type);
|
|
163
|
+
});
|
|
164
|
+
return result;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function defineSilgiModule(definition) {
|
|
168
|
+
if (definition) {
|
|
169
|
+
return _defineSilgiModule(definition);
|
|
170
|
+
}
|
|
171
|
+
return {
|
|
172
|
+
with: (definition2) => _defineSilgiModule(definition2)
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
function _defineSilgiModule(definition) {
|
|
176
|
+
if (typeof definition === "function") {
|
|
177
|
+
return _defineSilgiModule({ setup: definition });
|
|
178
|
+
}
|
|
179
|
+
const module = defu(definition, { meta: {} });
|
|
180
|
+
module.meta.configKey ||= module.meta.name;
|
|
181
|
+
async function getOptions(inlineOptions, silgi = useSilgiCLI()) {
|
|
182
|
+
const nuxtConfigOptionsKey = module.meta.configKey || module.meta.name;
|
|
183
|
+
const nuxtConfigOptions = nuxtConfigOptionsKey && nuxtConfigOptionsKey in silgi.options ? silgi.options[nuxtConfigOptionsKey] : {};
|
|
184
|
+
const optionsDefaults = module.defaults instanceof Function ? await module.defaults(silgi) : module.defaults ?? {};
|
|
185
|
+
const options = defu(inlineOptions, nuxtConfigOptions, optionsDefaults);
|
|
186
|
+
return Promise.resolve(options);
|
|
187
|
+
}
|
|
188
|
+
async function normalizedModule(inlineOptions, silgi = tryUseSilgiCLI()) {
|
|
189
|
+
if (!silgi) {
|
|
190
|
+
throw new TypeError("Cannot use module outside of Silgi context");
|
|
191
|
+
}
|
|
192
|
+
const uniqueKey = module.meta.configKey || module.meta.name;
|
|
193
|
+
if (uniqueKey) {
|
|
194
|
+
silgi._requiredModules ||= {};
|
|
195
|
+
if (silgi._requiredModules[uniqueKey]) {
|
|
196
|
+
return false;
|
|
197
|
+
}
|
|
198
|
+
silgi._requiredModules[uniqueKey] = true;
|
|
199
|
+
}
|
|
200
|
+
if (module.meta.compatibility) {
|
|
201
|
+
const issues = await checkSilgiCompatibility(module.meta.compatibility, silgi);
|
|
202
|
+
if (issues.length) {
|
|
203
|
+
silgi.logger.warn(`Module \`${module.meta.name}\` is disabled due to incompatibility issues:
|
|
204
|
+
${issues.toString()}`);
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
const _options = await getOptions(inlineOptions, silgi);
|
|
209
|
+
if (module.hooks) {
|
|
210
|
+
silgi.hooks.addHooks(module.hooks);
|
|
211
|
+
}
|
|
212
|
+
const start = performance.now();
|
|
213
|
+
const res = await module.setup?.call(null, _options, silgi) ?? {};
|
|
214
|
+
const perf = performance.now() - start;
|
|
215
|
+
const setupTime = Math.round(perf * 100) / 100;
|
|
216
|
+
if (setupTime > 5e3 && uniqueKey !== "@silgi/telemetry") {
|
|
217
|
+
silgi.logger.warn(`Slow module \`${uniqueKey || "<no name>"}\` took \`${setupTime}ms\` to setup.`);
|
|
218
|
+
} else if (silgi.options.debug) {
|
|
219
|
+
silgi.logger.info(`Module \`${uniqueKey || "<no name>"}\` took \`${setupTime}ms\` to setup.`);
|
|
220
|
+
}
|
|
221
|
+
if (res === false) {
|
|
222
|
+
return false;
|
|
223
|
+
}
|
|
224
|
+
return defu(res, {
|
|
225
|
+
timings: {
|
|
226
|
+
setup: setupTime
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
normalizedModule.getMeta = () => Promise.resolve(module.meta);
|
|
231
|
+
normalizedModule.getOptions = getOptions;
|
|
232
|
+
return normalizedModule;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
function defineSilgiPreset(preset, meta) {
|
|
236
|
+
if (meta?.url && typeof preset !== "function") ;
|
|
237
|
+
return { ...preset, _meta: meta };
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
async function resolvePath(path, opts = {}) {
|
|
241
|
+
const _path = path;
|
|
242
|
+
path = normalize(path);
|
|
243
|
+
if (isAbsolute(path)) {
|
|
244
|
+
if (existsSync(path) && !await isDirectory(path)) {
|
|
245
|
+
return path;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
const cwd = opts.cwd || process.cwd();
|
|
249
|
+
const extensions = opts.extensions || [".ts", ".mjs", ".cjs", ".json"];
|
|
250
|
+
const modulesDir = opts.modulesDir || [];
|
|
251
|
+
path = resolveAlias(path);
|
|
252
|
+
if (!isAbsolute(path)) {
|
|
253
|
+
path = resolve(cwd, path);
|
|
254
|
+
}
|
|
255
|
+
let _isDir = false;
|
|
256
|
+
if (existsSync(path)) {
|
|
257
|
+
_isDir = await isDirectory(path);
|
|
258
|
+
if (!_isDir) {
|
|
259
|
+
return path;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
for (const ext of extensions) {
|
|
263
|
+
const pathWithExt = path + ext;
|
|
264
|
+
if (existsSync(pathWithExt)) {
|
|
265
|
+
return pathWithExt;
|
|
266
|
+
}
|
|
267
|
+
const pathWithIndex = join(path, `index${ext}`);
|
|
268
|
+
if (_isDir && existsSync(pathWithIndex)) {
|
|
269
|
+
return pathWithIndex;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
const resolveModulePath = await resolvePath$1(_path, { url: [cwd, ...modulesDir] }).catch(() => null);
|
|
273
|
+
if (resolveModulePath) {
|
|
274
|
+
return resolveModulePath;
|
|
275
|
+
}
|
|
276
|
+
return opts.fallbackToOriginal ? _path : path;
|
|
277
|
+
}
|
|
278
|
+
async function isDirectory(path) {
|
|
279
|
+
return (await promises.lstat(path)).isDirectory();
|
|
280
|
+
}
|
|
281
|
+
function resolveAlias(path, alias) {
|
|
282
|
+
return resolveAlias$1(path, alias || {});
|
|
283
|
+
}
|
|
284
|
+
function createResolver(base) {
|
|
285
|
+
if (!base) {
|
|
286
|
+
throw new Error("`base` argument is missing for createResolver(base)!");
|
|
287
|
+
}
|
|
288
|
+
base = base.toString();
|
|
289
|
+
if (base.startsWith("file://")) {
|
|
290
|
+
base = dirname(fileURLToPath(base));
|
|
291
|
+
}
|
|
292
|
+
return {
|
|
293
|
+
resolve: (...path) => resolve(base, ...path),
|
|
294
|
+
resolvePath: (path, opts) => resolvePath(path, { cwd: base, ...opts })
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
async function resolveSilgiModule(base, paths) {
|
|
298
|
+
const resolved = [];
|
|
299
|
+
const resolver = createResolver(base);
|
|
300
|
+
for (const path of paths) {
|
|
301
|
+
if (path.startsWith(base)) {
|
|
302
|
+
resolved.push(path.split("/index.ts")[0]);
|
|
303
|
+
} else {
|
|
304
|
+
const resolvedPath = await resolver.resolvePath(path);
|
|
305
|
+
resolved.push(resolvedPath.slice(0, resolvedPath.lastIndexOf(path) + path.length));
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
return resolved;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
const RELATIVE_RE = /^([^.])/;
|
|
312
|
+
function relativeWithDot(from, to) {
|
|
313
|
+
return relative(from, to).replace(RELATIVE_RE, "./$1") || ".";
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
export { createResolver, defineSilgiModule, defineSilgiPreset, exportGraphQLInterfaceType, extractGraphQLSchemaToJSON, isDirectory$1 as isDirectory, prettyPath, relativeWithDot, resolveAlias, resolvePath, resolveSilgiModule, resolveSilgiPath, tryResolveModule, writeFile };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { v as version } from '../_chunks/index.mjs';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { SilgiPreset, SilgiPresetMeta } from 'silgi/types';
|
|
2
|
+
import { type CompatibilityDateSpec } from 'compatx';
|
|
3
|
+
export declare function resolvePreset(name: string, opts: {
|
|
4
|
+
static?: boolean;
|
|
5
|
+
compatibilityDate?: false | CompatibilityDateSpec;
|
|
6
|
+
}): Promise<(SilgiPreset & {
|
|
7
|
+
_meta?: SilgiPresetMeta;
|
|
8
|
+
}) | undefined>;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import {
|
|
2
|
+
formatCompatibilityDate,
|
|
3
|
+
resolveCompatibilityDatesFromEnv
|
|
4
|
+
} from "compatx";
|
|
5
|
+
import { kebabCase } from "scule";
|
|
6
|
+
import { provider } from "std-env";
|
|
7
|
+
import allPresets from "./_all.gen.mjs";
|
|
8
|
+
const _stdProviderMap = {
|
|
9
|
+
aws_amplify: "aws",
|
|
10
|
+
azure_static: "azure",
|
|
11
|
+
cloudflare_pages: "cloudflare"
|
|
12
|
+
};
|
|
13
|
+
export async function resolvePreset(name, opts) {
|
|
14
|
+
const _name = kebabCase(name) || provider;
|
|
15
|
+
const _compatDates = opts.compatibilityDate ? resolveCompatibilityDatesFromEnv(opts.compatibilityDate) : false;
|
|
16
|
+
const matches = allPresets.filter((preset2) => {
|
|
17
|
+
const names = [preset2._meta.name, preset2._meta.stdName, ...preset2._meta.aliases || []].filter(Boolean);
|
|
18
|
+
if (!names.includes(_name)) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
if (_compatDates) {
|
|
22
|
+
const _date = _compatDates[_stdProviderMap[preset2._meta.stdName]] || _compatDates[preset2._meta.stdName] || _compatDates[preset2._meta.name] || _compatDates.default;
|
|
23
|
+
if (_date && preset2._meta.compatibilityDate && new Date(preset2._meta.compatibilityDate) > new Date(_date)) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return true;
|
|
28
|
+
}).sort((a, b) => {
|
|
29
|
+
const aDate = new Date(a._meta.compatibilityDate || 0);
|
|
30
|
+
const bDate = new Date(b._meta.compatibilityDate || 0);
|
|
31
|
+
return bDate > aDate ? 1 : -1;
|
|
32
|
+
});
|
|
33
|
+
const preset = matches.find(
|
|
34
|
+
(p) => (p._meta.static || false) === (opts?.static || false)
|
|
35
|
+
) || matches[0];
|
|
36
|
+
if (typeof preset === "function") {
|
|
37
|
+
return preset();
|
|
38
|
+
}
|
|
39
|
+
if (!name && !preset) {
|
|
40
|
+
return opts?.static ? resolvePreset("static", opts) : resolvePreset("node-server", opts);
|
|
41
|
+
}
|
|
42
|
+
if (name && !preset) {
|
|
43
|
+
const options = allPresets.filter((p) => p._meta.name === name || p._meta.stdName === name || p._meta.aliases?.includes(name)).sort((a, b) => (a._meta.compatibilityDate || 0) > (b._meta.compatibilityDate || 0) ? 1 : -1);
|
|
44
|
+
if (options.length > 0) {
|
|
45
|
+
let msg = `Preset "${name}" cannot be resolved with current compatibilityDate: ${formatCompatibilityDate(_compatDates || "")}.
|
|
46
|
+
|
|
47
|
+
`;
|
|
48
|
+
for (const option of options) {
|
|
49
|
+
msg += `
|
|
50
|
+
- ${option._meta.name} (requires compatibilityDate >= ${option._meta.compatibilityDate})`;
|
|
51
|
+
}
|
|
52
|
+
const err = new Error(msg);
|
|
53
|
+
Error.captureStackTrace?.(err, resolvePreset);
|
|
54
|
+
throw err;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return preset;
|
|
58
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const presetsWithConfig = [];
|