silgi 0.7.0 → 0.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_chunks/index.mjs +1 -1
- package/dist/cli/config/index.d.mts +11 -0
- package/dist/cli/config/index.d.ts +11 -0
- package/dist/cli/config/index.mjs +177 -0
- package/dist/cli/loader.mjs +581 -0
- package/dist/cli/prepare.mjs +8 -1
- package/dist/core/index.d.mts +2 -10
- package/dist/core/index.d.ts +2 -10
- package/dist/core/index.mjs +8 -743
- package/dist/ecosystem/nitro/index.mjs +1 -1
- package/dist/ecosystem/nuxt/module.mjs +1 -1
- package/dist/meta/index.d.mts +1 -1
- package/dist/meta/index.d.ts +1 -1
- package/package.json +5 -1
package/dist/_chunks/index.mjs
CHANGED
|
@@ -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 };
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
export { l as loadOptions } from '../loader.mjs';
|
|
2
|
+
import { promises, lstatSync } from 'node:fs';
|
|
3
|
+
import { defu } from 'defu';
|
|
4
|
+
import { resolve, dirname, join, isAbsolute, relative } from 'pathe';
|
|
5
|
+
import { readPackageJSON } from 'pkg-types';
|
|
6
|
+
import { relativeWithDot, resolveSilgiModule } from 'silgi/kit';
|
|
7
|
+
import { withTrailingSlash } from 'ufo';
|
|
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';
|
|
18
|
+
|
|
19
|
+
function getDirectory(p) {
|
|
20
|
+
try {
|
|
21
|
+
return isAbsolute(p) && lstatSync(p).isFile() ? dirname(p) : p;
|
|
22
|
+
} catch {
|
|
23
|
+
}
|
|
24
|
+
return p;
|
|
25
|
+
}
|
|
26
|
+
function renderAttrs(obj) {
|
|
27
|
+
const attrs = [];
|
|
28
|
+
for (const key in obj) {
|
|
29
|
+
attrs.push(renderAttr(key, obj[key]));
|
|
30
|
+
}
|
|
31
|
+
return attrs.join(" ");
|
|
32
|
+
}
|
|
33
|
+
function renderAttr(key, value) {
|
|
34
|
+
return value ? `${key}="${value}"` : "";
|
|
35
|
+
}
|
|
36
|
+
async function silgiGenerateType(silgi) {
|
|
37
|
+
const rootDirWithSlash = withTrailingSlash(silgi.options.rootDir);
|
|
38
|
+
const tsConfigPath = resolve(
|
|
39
|
+
silgi.options.rootDir,
|
|
40
|
+
silgi.options.typescript.tsconfigPath
|
|
41
|
+
);
|
|
42
|
+
const tsconfigDir = dirname(tsConfigPath);
|
|
43
|
+
const include = /* @__PURE__ */ new Set([
|
|
44
|
+
relativeWithDot(tsconfigDir, join(silgi.options.build.typesDir, "silgi.d.ts")).replace(
|
|
45
|
+
/^(?=[^.])/,
|
|
46
|
+
"./"
|
|
47
|
+
),
|
|
48
|
+
join(relativeWithDot(tsconfigDir, silgi.options.rootDir), "**/*"),
|
|
49
|
+
...silgi.options.srcDir === silgi.options.rootDir ? [] : [join(relativeWithDot(tsconfigDir, silgi.options.srcDir), "**/*")]
|
|
50
|
+
]);
|
|
51
|
+
const exclude = /* @__PURE__ */ new Set([
|
|
52
|
+
// nitro generate output: https://github.com/nuxt/nuxt/blob/main/packages/nuxt/src/core/nitro.ts#L186
|
|
53
|
+
relativeWithDot(silgi.options.build.dir, resolve(silgi.options.rootDir, "dist"))
|
|
54
|
+
]);
|
|
55
|
+
for (const dir of silgi.options.modulesDir) {
|
|
56
|
+
exclude.add(relativeWithDot(silgi.options.build.dir, dir));
|
|
57
|
+
}
|
|
58
|
+
const moduleEntryPaths = [];
|
|
59
|
+
for (const m of silgi.scanModules) {
|
|
60
|
+
if (m.entryPath) {
|
|
61
|
+
moduleEntryPaths.push(getDirectory(m.entryPath));
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
const modulePaths = await resolveSilgiModule(rootDirWithSlash, moduleEntryPaths);
|
|
65
|
+
for (const path of modulePaths) {
|
|
66
|
+
const relative2 = relativeWithDot(silgi.options.build.dir, path);
|
|
67
|
+
include.add(join(relative2, "runtime"));
|
|
68
|
+
exclude.add(join(relative2, "runtime/server"));
|
|
69
|
+
include.add(join(relative2, "dist/runtime"));
|
|
70
|
+
exclude.add(join(relative2, "dist/runtime/server"));
|
|
71
|
+
}
|
|
72
|
+
const tsConfig = defu(silgi.options.typescript?.tsConfig, {
|
|
73
|
+
compilerOptions: {
|
|
74
|
+
forceConsistentCasingInFileNames: true,
|
|
75
|
+
strict: silgi.options.typescript.strict,
|
|
76
|
+
noEmit: true,
|
|
77
|
+
target: "ESNext",
|
|
78
|
+
module: "ESNext",
|
|
79
|
+
moduleResolution: "Bundler",
|
|
80
|
+
allowJs: true,
|
|
81
|
+
resolveJsonModule: true,
|
|
82
|
+
jsx: "preserve",
|
|
83
|
+
allowSyntheticDefaultImports: true,
|
|
84
|
+
jsxFactory: "h",
|
|
85
|
+
jsxFragmentFactory: "Fragment",
|
|
86
|
+
allowImportingTsExtensions: true,
|
|
87
|
+
...silgi.options.typescript.customConditions ? { customConditions: ["silgiTypes"] } : {},
|
|
88
|
+
paths: {
|
|
89
|
+
"#silgiImports": [
|
|
90
|
+
relativeWithDot(tsconfigDir, join(silgi.options.build.typesDir, "silgi-imports"))
|
|
91
|
+
],
|
|
92
|
+
...silgi.scanModules.reduce((acc, m) => {
|
|
93
|
+
if (m.entryPath) {
|
|
94
|
+
acc[m.meta.name] = [relativeWithDot(tsconfigDir, m.entryPath)];
|
|
95
|
+
}
|
|
96
|
+
return acc;
|
|
97
|
+
}, {}),
|
|
98
|
+
...silgi.scanModules.reduce((acc, m) => {
|
|
99
|
+
if (m.entryPath) {
|
|
100
|
+
const directory = getDirectory(m.entryPath);
|
|
101
|
+
acc[`${m.meta.name}/*`] = [`${relativeWithDot(tsconfigDir, directory)}/*`];
|
|
102
|
+
}
|
|
103
|
+
return acc;
|
|
104
|
+
}, {})
|
|
105
|
+
// ...(silgi.options.typescript?.internalPaths
|
|
106
|
+
// ? {
|
|
107
|
+
// 'silgi/runtime': [
|
|
108
|
+
// relativeWithDot(tsconfigDir, join(runtimeDir, 'index')),
|
|
109
|
+
// ],
|
|
110
|
+
// '#internal/silgi': [
|
|
111
|
+
// relativeWithDot(tsconfigDir, join(runtimeDir, 'index')),
|
|
112
|
+
// ],
|
|
113
|
+
// 'silgi/runtime/*': [
|
|
114
|
+
// relativeWithDot(tsconfigDir, join(runtimeDir, '*')),
|
|
115
|
+
// ],
|
|
116
|
+
// '#internal/silgi/*': [
|
|
117
|
+
// relativeWithDot(tsconfigDir, join(runtimeDir, '*')),
|
|
118
|
+
// ],
|
|
119
|
+
// }
|
|
120
|
+
// : {}),
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
include: [...include],
|
|
124
|
+
exclude: [...exclude]
|
|
125
|
+
});
|
|
126
|
+
tsConfig.compilerOptions ||= {};
|
|
127
|
+
tsConfig.compilerOptions.paths ||= {};
|
|
128
|
+
tsConfig.include ||= [];
|
|
129
|
+
for (const alias in tsConfig.compilerOptions.paths) {
|
|
130
|
+
const paths = tsConfig.compilerOptions.paths[alias];
|
|
131
|
+
tsConfig.compilerOptions.paths[alias] = await Promise.all(
|
|
132
|
+
paths.map(async (path) => {
|
|
133
|
+
if (!isAbsolute(path)) {
|
|
134
|
+
return path;
|
|
135
|
+
}
|
|
136
|
+
const stats = await promises.stat(path).catch(
|
|
137
|
+
() => null
|
|
138
|
+
/* file does not exist */
|
|
139
|
+
);
|
|
140
|
+
return relativeWithDot(
|
|
141
|
+
tsconfigDir,
|
|
142
|
+
stats?.isFile() ? path.replace(/\b\.\w+$/g, "") : path
|
|
143
|
+
);
|
|
144
|
+
})
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
const references = [];
|
|
148
|
+
await Promise.all([...silgi.options.modules, ...silgi.options._modules].map(async (id) => {
|
|
149
|
+
if (typeof id !== "string") {
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
const pkg = await readPackageJSON(id, { url: silgi.options.modulesDir }).catch(() => null);
|
|
153
|
+
references.push({ types: pkg?.name || id });
|
|
154
|
+
}));
|
|
155
|
+
const declarations = [];
|
|
156
|
+
await silgi.callHook("prepare:types", { references, declarations, tsConfig });
|
|
157
|
+
tsConfig.include = [...new Set(tsConfig.include.map((p) => isAbsolute(p) ? relativeWithDot(silgi.options.build.dir, p) : p))];
|
|
158
|
+
tsConfig.exclude = [...new Set(tsConfig.exclude.map((p) => isAbsolute(p) ? relativeWithDot(silgi.options.build.dir, p) : p))];
|
|
159
|
+
const _declarations = [
|
|
160
|
+
...references.map((ref) => {
|
|
161
|
+
if ("path" in ref && isAbsolute(ref.path)) {
|
|
162
|
+
ref.path = relative(silgi.options.build.dir, ref.path);
|
|
163
|
+
}
|
|
164
|
+
return `/// <reference ${renderAttrs(ref)} />`;
|
|
165
|
+
}),
|
|
166
|
+
...declarations,
|
|
167
|
+
"",
|
|
168
|
+
"export {}",
|
|
169
|
+
""
|
|
170
|
+
];
|
|
171
|
+
return {
|
|
172
|
+
declarations: _declarations,
|
|
173
|
+
tsConfig
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export { silgiGenerateType };
|