@silgi/module-builder 0.7.3 → 0.7.5

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.
@@ -7,7 +7,7 @@ import { consola } from 'consola';
7
7
  import defu from 'defu';
8
8
  import { createJiti } from 'jiti';
9
9
  import { createRegExp, anyOf } from 'magic-regexp';
10
- import { resolvePath } from 'mlly';
10
+ import { resolvePath, findExports, findTypeExports } from 'mlly';
11
11
  import { resolve, basename, normalize, dirname } from 'pathe';
12
12
  import { filename } from 'pathe/utils';
13
13
  import { readPackageJSON } from 'pkg-types';
@@ -15,7 +15,7 @@ import { pkgDir } from 'silgi/runtime/meta';
15
15
  import { parse } from 'tsconfck';
16
16
  import { convertCompilerOptionsFromJson } from 'typescript';
17
17
  import { scanExports } from 'unimport';
18
- import { v as version, n as name } from '../shared/silgi-module-builder.CeW3fdq4.mjs';
18
+ import { v as version, n as name } from '../shared/silgi-module-builder.C81SXUbd.mjs';
19
19
 
20
20
  const subpaths = [
21
21
  "runtime",
@@ -106,6 +106,7 @@ const build = defineCommand({
106
106
  entries.push({
107
107
  input: "src/types/index.ts",
108
108
  outDir: `${outDir}`,
109
+ name: "types",
109
110
  builder: "rollup"
110
111
  });
111
112
  }
@@ -229,6 +230,7 @@ const build = defineCommand({
229
230
  };
230
231
  const metaFile = resolve(ctx.options.outDir, "module.json");
231
232
  await promises.writeFile(metaFile, JSON.stringify(moduleMeta, null, 2), "utf8");
233
+ await writeTypes(ctx.options);
232
234
  },
233
235
  "build:done": async function(ctx) {
234
236
  const logs = [...ctx.warnings].filter((l) => l.startsWith("Potential missing package.json files:"));
@@ -261,6 +263,75 @@ const build = defineCommand({
261
263
  });
262
264
  }
263
265
  });
266
+ async function writeTypes(options, _moduleMeta) {
267
+ if (!options.stub) {
268
+ return;
269
+ }
270
+ const dtsFile = resolve(options.outDir, "types.d.mts");
271
+ const moduleReExports = [];
272
+ const moduleTypesFile = resolve(options.rootDir, "src/types/index.ts");
273
+ const moduleTypes = await promises.readFile(moduleTypesFile, "utf8").catch(() => "");
274
+ const normalisedModuleTypes = moduleTypes.replace(/export\s*\{.*?\}/gs, (match) => match.replace(/\b(type|interface)\b/g, ""));
275
+ for (const e of findExports(normalisedModuleTypes)) {
276
+ moduleReExports.push(e);
277
+ }
278
+ for (const i of findTypeExports(normalisedModuleTypes)) {
279
+ moduleReExports.push(i);
280
+ }
281
+ const moduleImports = [];
282
+ const hasTypeExport = (name2) => moduleReExports.find((exp) => exp.names?.includes(name2));
283
+ if (hasTypeExport("ModuleOptions")) {
284
+ moduleImports.push("ModuleOptions");
285
+ }
286
+ if (hasTypeExport("ModuleRuntimeOptions")) {
287
+ moduleImports.push("ModuleRuntimeOptions");
288
+ }
289
+ if (hasTypeExport("ModuleRuntimeShareds")) {
290
+ moduleImports.push("ModuleRuntimeShareds");
291
+ }
292
+ if (hasTypeExport("ModuleEvents")) {
293
+ moduleImports.push("ModuleEvents");
294
+ }
295
+ if (hasTypeExport("ModuleRuntimeContexts")) {
296
+ moduleImports.push("ModuleRuntimeContexts");
297
+ }
298
+ if (hasTypeExport("ModuleHooks")) {
299
+ moduleImports.push("ModuleHooks");
300
+ }
301
+ if (hasTypeExport("ModuleRuntimeHooks")) {
302
+ moduleImports.push("ModuleRuntimeHooks");
303
+ }
304
+ if (hasTypeExport("SetupModuleOption")) {
305
+ moduleImports.push("SetupModuleOption");
306
+ }
307
+ if (hasTypeExport("ModuleRuntimeMethods")) {
308
+ moduleImports.push("ModuleRuntimeMethods");
309
+ }
310
+ if (hasTypeExport("RouteRules")) {
311
+ moduleImports.push("RouteRules");
312
+ }
313
+ if (hasTypeExport("MetaData")) {
314
+ moduleImports.push("MetaData");
315
+ }
316
+ let fromPath;
317
+ if (existsSync(dtsFile)) {
318
+ const prevContent = await promises.readFile(dtsFile, "utf8").catch(() => "");
319
+ const match = prevContent.match(/export\s+\*\s+from\s+["'](.+)["']/);
320
+ if (match) {
321
+ fromPath = match[1];
322
+ }
323
+ }
324
+ let dtsContents;
325
+ const importFrom = fromPath || "./module.mjs";
326
+ dtsContents = `${`
327
+ ${moduleImports.length ? `import type { ${moduleImports.join(", ")} } from '${importFrom}'` : ""}
328
+
329
+ ${moduleImports.length ? `
330
+ export type { ${moduleImports.join(", ")} }` : ""}
331
+ `.trim().replace(/[\n\r]{3,}/g, "\n\n")}
332
+ `;
333
+ await promises.writeFile(dtsFile, dtsContents, "utf8");
334
+ }
264
335
  async function loadTSCompilerOptions(path) {
265
336
  const config = await parse(path);
266
337
  const resolvedCompilerOptions = config?.tsconfig.compilerOptions || {};
package/dist/cli.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import { defineCommand, runMain } from 'citty';
3
3
  import { consola } from 'consola';
4
- import { v as version, d as description, n as name } from './shared/silgi-module-builder.CeW3fdq4.mjs';
4
+ import { v as version, d as description, n as name } from './shared/silgi-module-builder.C81SXUbd.mjs';
5
5
 
6
6
  const _rDefault = (r) => r && typeof r === "object" && "default" in r ? r.default : r;
7
7
  const main = defineCommand({
package/dist/index.mjs CHANGED
@@ -16,4 +16,4 @@ import 'silgi/runtime/meta';
16
16
  import 'tsconfck';
17
17
  import 'typescript';
18
18
  import 'unimport';
19
- import './shared/silgi-module-builder.CeW3fdq4.mjs';
19
+ import './shared/silgi-module-builder.C81SXUbd.mjs';
@@ -1,5 +1,5 @@
1
1
  const name = "@silgi/module-builder";
2
- const version = "0.7.3";
2
+ const version = "0.7.5";
3
3
  const description = "Complete solution for building Silgi modules";
4
4
 
5
5
  export { description as d, name as n, version as v };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@silgi/module-builder",
3
3
  "type": "module",
4
- "version": "0.7.3",
4
+ "version": "0.7.5",
5
5
  "private": false,
6
6
  "description": "Complete solution for building Silgi modules",
7
7
  "exports": {