@silgi/module-builder 0.8.0 → 0.8.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.
@@ -17,7 +17,7 @@ declare const _default: citty0.CommandDef<{
17
17
  sourcemap: {
18
18
  type: "boolean";
19
19
  };
20
- stub: {
20
+ watch: {
21
21
  type: "boolean";
22
22
  };
23
23
  check: {
@@ -1,11 +1,11 @@
1
1
  import { name, version } from "../package.mjs";
2
2
  import { defineCommand } from "citty";
3
3
  import { consola } from "consola";
4
- import { existsSync, promises } from "node:fs";
4
+ import { promises } from "node:fs";
5
5
  import { join } from "node:path";
6
6
  import { pathToFileURL } from "node:url";
7
7
  import { createJiti } from "jiti";
8
- import { findExports, findTypeExports } from "mlly";
8
+ import "mlly";
9
9
  import { resolve } from "pathe";
10
10
  import { readPackageJSON } from "pkg-types";
11
11
  import { pkgDir } from "silgi/runtime/meta";
@@ -31,7 +31,7 @@ var build_default = defineCommand({
31
31
  },
32
32
  outDir: { type: "string" },
33
33
  sourcemap: { type: "boolean" },
34
- stub: { type: "boolean" },
34
+ watch: { type: "boolean" },
35
35
  check: { type: "boolean" }
36
36
  },
37
37
  async run(context) {
@@ -53,8 +53,11 @@ var build_default = defineCommand({
53
53
  "src/module.ts",
54
54
  "src/runtime",
55
55
  "src/types",
56
- "src/data"
56
+ "src/data",
57
+ "!src/assets",
58
+ "!src/silgi"
57
59
  ],
60
+ watch: context.args.watch,
58
61
  format: "esm",
59
62
  treeshake: true,
60
63
  fixedExtension: true,
@@ -98,51 +101,10 @@ var build_default = defineCommand({
98
101
  };
99
102
  const metaFile = resolve(ctx.options.outDir, "module.json");
100
103
  await promises.writeFile(metaFile, JSON.stringify(moduleMeta, null, 2), "utf8");
101
- await writeTypes(ctx, moduleMeta);
102
104
  } }
103
105
  });
104
106
  }
105
107
  });
106
- async function writeTypes(ctx, _moduleMeta) {
107
- const dtsFile = resolve(ctx.options.cwd, "types/index.d.mts");
108
- const moduleReExports = [];
109
- const moduleTypesFile = resolve(ctx.options.cwd, "src/types/index.ts");
110
- const moduleTypes = await promises.readFile(moduleTypesFile, "utf8").catch(() => "");
111
- const normalisedModuleTypes = moduleTypes.replace(/export\s*\{.*?\}/gs, (match) => match.replace(/\b(type|interface)\b/g, ""));
112
- for (const e of findExports(normalisedModuleTypes)) moduleReExports.push(e);
113
- for (const i of findTypeExports(normalisedModuleTypes)) moduleReExports.push(i);
114
- const moduleImports = [];
115
- const hasTypeExport = (name$1) => moduleReExports.find((exp) => exp.names?.includes(name$1));
116
- if (hasTypeExport("ModuleOptions")) moduleImports.push("ModuleOptions");
117
- if (hasTypeExport("ModuleRuntimeOptions")) moduleImports.push("ModuleRuntimeOptions");
118
- if (hasTypeExport("ModuleRuntimeShareds")) moduleImports.push("ModuleRuntimeShareds");
119
- if (hasTypeExport("ModuleEvents")) moduleImports.push("ModuleEvents");
120
- if (hasTypeExport("ModuleRuntimeContexts")) moduleImports.push("ModuleRuntimeContexts");
121
- if (hasTypeExport("ModuleHooks")) moduleImports.push("ModuleHooks");
122
- if (hasTypeExport("ModuleRuntimeHooks")) moduleImports.push("ModuleRuntimeHooks");
123
- if (hasTypeExport("SetupModuleOption")) moduleImports.push("SetupModuleOption");
124
- if (hasTypeExport("ModuleRuntimeMethods")) moduleImports.push("ModuleRuntimeMethods");
125
- if (hasTypeExport("RouteRules")) moduleImports.push("RouteRules");
126
- if (hasTypeExport("MetaData")) moduleImports.push("MetaData");
127
- let fromPath;
128
- let prevContent;
129
- if (existsSync(dtsFile)) {
130
- prevContent = await promises.readFile(dtsFile, "utf8").catch(() => "");
131
- const match = prevContent.match(/export\s+\*\s+from\s+["'](.+)["']/);
132
- if (match) fromPath = match[1];
133
- }
134
- let dtsContents;
135
- const importFrom = fromPath || "./module.mjs";
136
- dtsContents = `${`${moduleImports.length ? `import type { ${moduleImports.join(", ")} } from '${importFrom}'\n\nexport type { ${moduleImports.join(", ")} }` : ""}`.trim()}\n`;
137
- let mergedContent = dtsContents;
138
- if (prevContent) {
139
- const prevLines = prevContent.split("\n").map((l) => l.trim());
140
- const newLines = dtsContents.split("\n").map((l) => l.trim());
141
- const uniqueLines = newLines.filter((line) => line && !prevLines.includes(line));
142
- mergedContent = `${uniqueLines.join("\n")}\n${prevContent}`;
143
- }
144
- await promises.writeFile(dtsFile, mergedContent, "utf8");
145
- }
146
108
 
147
109
  //#endregion
148
110
  export { build_default as default, subpaths };
package/dist/package.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  //#region package.json
2
2
  var name = "@silgi/module-builder";
3
- var version = "0.8.0";
3
+ var version = "0.8.2";
4
4
  var description = "Complete solution for building Silgi modules";
5
5
 
6
6
  //#endregion
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@silgi/module-builder",
3
3
  "type": "module",
4
- "version": "0.8.0",
4
+ "version": "0.8.2",
5
5
  "private": false,
6
6
  "description": "Complete solution for building Silgi modules",
7
7
  "exports": {