@silgi/module-builder 0.8.0 → 0.8.1
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/commands/build.mjs +5 -44
- package/dist/package.mjs +1 -1
- package/package.json +1 -1
package/dist/commands/build.mjs
CHANGED
@@ -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 {
|
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
|
8
|
+
import "mlly";
|
9
9
|
import { resolve } from "pathe";
|
10
10
|
import { readPackageJSON } from "pkg-types";
|
11
11
|
import { pkgDir } from "silgi/runtime/meta";
|
@@ -53,7 +53,9 @@ 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
|
],
|
58
60
|
format: "esm",
|
59
61
|
treeshake: true,
|
@@ -98,51 +100,10 @@ var build_default = defineCommand({
|
|
98
100
|
};
|
99
101
|
const metaFile = resolve(ctx.options.outDir, "module.json");
|
100
102
|
await promises.writeFile(metaFile, JSON.stringify(moduleMeta, null, 2), "utf8");
|
101
|
-
await writeTypes(ctx, moduleMeta);
|
102
103
|
} }
|
103
104
|
});
|
104
105
|
}
|
105
106
|
});
|
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
107
|
|
147
108
|
//#endregion
|
148
109
|
export { build_default as default, subpaths };
|
package/dist/package.mjs
CHANGED