powerlines 0.42.37 → 0.42.38

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.
@@ -1,7 +1,7 @@
1
1
  import { n as createProgram } from "./ts-morph-B85ZbV1Q.mjs";
2
2
  import { t as utils_exports } from "./utils.mjs";
3
3
  import { t as plugin_utils_exports } from "./plugin-utils.mjs";
4
- import { d as writeMetaFile, f as callHook, p as mergeConfigs, t as PowerlinesAPIContext } from "./api-context-CEJ3s11k.mjs";
4
+ import { d as writeMetaFile, f as callHook, p as mergeConfigs, t as PowerlinesAPIContext } from "./api-context-DuZIIJsm.mjs";
5
5
  import { a as isIncludeMatchFound, i as getTsconfigFilePath, r as getParsedTypeScriptConfig } from "./tsconfig-DoV1dUYg.mjs";
6
6
  import { formatLogMessage } from "@storm-software/config-tools/logger/console";
7
7
  import { toArray } from "@stryke/convert/to-array";
@@ -41,7 +41,7 @@ import { StormJSON } from "@stryke/json/storm-json";
41
41
 
42
42
  //#region package.json
43
43
  var name = "powerlines";
44
- var version = "0.42.37";
44
+ var version = "0.42.38";
45
45
 
46
46
  //#endregion
47
47
  //#region src/_internal/helpers/generate-types.ts
@@ -54,96 +54,135 @@ var version = "0.42.37";
54
54
  function formatTypes(code = "") {
55
55
  return code.replaceAll("#private;", "").replace(/__Ω/g, "");
56
56
  }
57
- async function writeModuleDeclarations(context, filePath, id, code, fileToModuleMap) {
58
- const mappings = /* @__PURE__ */ new Map();
59
- const ambient = [];
60
- const sourceFile = new Project({ useInMemoryFileSystem: true }).createSourceFile("module.d.ts", code);
61
- for (const ref of sourceFile.getTypeReferenceDirectives()) ambient.push({
62
- id: ref.getFileName(),
63
- external: true
57
+ async function extractModuleDeclarations(ctx, filePath, name, text) {
58
+ const imports = [];
59
+ const exports = [];
60
+ const comment = text.match(new RegExp(`\\/\\*\\*(?s:.)*?@module\\s+${ctx.context.config.framework}:${name}(?s:.)*?\\*\\/\\s+`))?.find((comment) => isSetString(comment?.trim()));
61
+ const sourceFile = new Project({ useInMemoryFileSystem: true }).createSourceFile("module.d.ts", text);
62
+ for (const ref of sourceFile.getTypeReferenceDirectives()) if (ref.getFileName() && !ctx.context.builtins.some((builtin) => ref.getFileName().endsWith(builtin))) imports.push({
63
+ name: ref.getFileName(),
64
+ ambient: true
64
65
  });
65
- const importLines = [];
66
- const reExportLines = [];
67
- const declarationLines = [];
68
- for (const statement of sourceFile.getStatements()) {
69
- if (Node.isImportDeclaration(statement)) {
70
- const moduleSpec = statement.getModuleSpecifierValue();
71
- const defaultImport = statement.getDefaultImport();
72
- const namedImports = statement.getNamedImports();
73
- const namespaceImport = statement.getNamespaceImport();
74
- if (!defaultImport && namedImports.length === 0 && !namespaceImport) {
75
- ambient.push({
76
- id: moduleSpec,
77
- external: !context.fs.isResolvableId(moduleSpec, filePath)
66
+ for (const statement of sourceFile.getStatements()) if (Node.isImportDeclaration(statement)) {
67
+ const moduleSpec = statement.getModuleSpecifierValue();
68
+ if (statement.getNamespaceImport()) imports.push({
69
+ name: moduleSpec,
70
+ specifiers: [{ name: statement.getNamespaceImport().getText() }],
71
+ all: true
72
+ });
73
+ else if (statement.getNamedImports().length > 0 || statement.getDefaultImport()) {
74
+ const specifiers = [];
75
+ if (statement.getDefaultImport()) specifiers.push({
76
+ name: statement.getDefaultImport().getText(),
77
+ default: true,
78
+ type: statement.isTypeOnly()
79
+ });
80
+ statement.getNamedImports().forEach((named) => {
81
+ specifiers.push({
82
+ name: named.getName(),
83
+ alias: named.getAliasNode()?.getText(),
84
+ type: statement.isTypeOnly()
78
85
  });
79
- continue;
80
- }
86
+ });
87
+ imports.push({
88
+ name: moduleSpec,
89
+ specifiers
90
+ });
91
+ }
92
+ } else if (Node.isExportDeclaration(statement)) {
93
+ const moduleSpec = statement.getModuleSpecifierValue();
94
+ if (moduleSpec) {
81
95
  let resolvedSpec = moduleSpec;
82
- if (context.fs.isResolvableId(moduleSpec, filePath)) {
83
- const resolved = await context.resolve(moduleSpec, filePath);
84
- if (resolved) {
85
- const mapped = fileToModuleMap.get(resolved.id);
86
- if (mapped) resolvedSpec = mapped;
87
- else context.trace(`Could not resolve relative import '${moduleSpec}' from '${filePath}' to a builtin module. Keeping as-is.`);
88
- }
89
- }
90
- if (namespaceImport) importLines.push(`\timport * as ${namespaceImport.getText()} from '${resolvedSpec}';`);
96
+ if (!ctx.context.builtins.includes(moduleSpec)) if (ctx.emitted.has(moduleSpec)) resolvedSpec = ctx.emitted.get(moduleSpec);
91
97
  else {
92
- const specifiers = [];
93
- if (defaultImport) specifiers.push(`default as ${defaultImport.getText()}`);
94
- for (const named of namedImports) {
95
- const alias = named.getAliasNode()?.getText();
96
- specifiers.push(alias ? `${named.getName()} as ${alias}` : named.getName());
97
- }
98
- if (specifiers.length > 0) {
99
- const typeOnly = statement.isTypeOnly() ? " type" : "";
100
- importLines.push(`\timport${typeOnly} { ${specifiers.join(", ")} } from '${resolvedSpec}';`);
101
- }
98
+ const resolvedModule = await ctx.context.resolve(moduleSpec, filePath);
99
+ if (isSetString(resolvedModule?.id)) resolvedSpec = resolvedModule.id;
102
100
  }
103
- continue;
104
- }
105
- if (Node.isExportDeclaration(statement)) {
106
- const moduleSpec = statement.getModuleSpecifierValue();
107
- if (moduleSpec) {
108
- let resolvedSpec = moduleSpec;
109
- if (context.fs.isResolvableId(moduleSpec, filePath)) {
110
- const resolved = await context.resolve(moduleSpec, filePath);
111
- if (resolved) {
112
- const mapped = fileToModuleMap.get(resolved.id);
113
- if (mapped) resolvedSpec = mapped;
114
- else context.trace(`Could not resolve relative import '${moduleSpec}' from '${filePath}' to a builtin module. Keeping as-is.`);
115
- }
116
- }
117
- const namedExports = statement.getNamedExports();
118
- if (namedExports.length > 0) {
119
- const specifiers = namedExports.map((named) => {
120
- const alias = named.getAliasNode()?.getText();
121
- return alias ? `${named.getName()} as ${alias}` : named.getName();
122
- });
123
- const typeOnly = statement.isTypeOnly() ? " type" : "";
124
- reExportLines.push(`\texport${typeOnly} { ${specifiers.join(", ")} } from '${resolvedSpec}';`);
125
- } else reExportLines.push(`\texport * from '${resolvedSpec}';`);
126
- } else declarationLines.push(`\t${statement.getText()}`);
127
- continue;
128
- }
129
- if (Node.isExportAssignment(statement)) {
130
- declarationLines.push(`\t${statement.getText()}`);
131
- continue;
101
+ const namedExports = statement.getNamedExports();
102
+ if (namedExports.length > 0) exports.push({
103
+ name: resolvedSpec,
104
+ text: statement.getText(),
105
+ fullText: statement.getFullText(),
106
+ specifiers: namedExports.map((named) => ({
107
+ name: named.getName(),
108
+ alias: named.getAliasNode()?.getText(),
109
+ type: statement.isTypeOnly()
110
+ })),
111
+ comment: statement.getLeadingCommentRanges().filter((c) => isSetString(c.getText().trim()) && !c.getText().includes("@module")).map((c) => c.getText().trim()).join("\n").trim()
112
+ });
113
+ else exports.push({
114
+ name: resolvedSpec,
115
+ text: statement.getText(),
116
+ fullText: statement.getFullText(),
117
+ all: true,
118
+ comment: statement.getLeadingCommentRanges().filter((c) => isSetString(c.getText().trim()) && !c.getText().includes("@module")).map((c) => c.getText().trim()).join("\n").trim()
119
+ });
120
+ } else {
121
+ const specifiers = statement.getNamedExports().map((named) => ({
122
+ name: named.getName(),
123
+ alias: named.getAliasNode()?.getText(),
124
+ type: statement.isTypeOnly()
125
+ }));
126
+ if (specifiers.length > 0) exports.push({
127
+ text: statement.getText(),
128
+ fullText: statement.getFullText(),
129
+ specifiers,
130
+ comment: statement.getLeadingCommentRanges().filter((c) => isSetString(c.getText().trim()) && !c.getText().includes("@module")).map((c) => c.getText().trim()).join("\n")
131
+ });
132
132
  }
133
- const text = statement.getText();
134
- if (text.includes("//# sourceMappingURL=")) continue;
135
- declarationLines.push(formatTypes(text.replace(/^(export\s+)?declare\s+/, "$1")).split("\n").map((line) => `\t${line}`).join("\n"));
136
- }
137
- const moduleComment = code.match(new RegExp(`\\/\\*\\*(?s:.)*?@module\\s+${context.config.framework}:${id}(?s:.)*?\\*\\/\\s+`))?.find((comment) => isSetString(comment?.trim()));
138
- let content = `${moduleComment ? `${moduleComment.trim()}\n` : ""}declare module "${context.config.framework}:${id}" {`;
139
- for (const line of importLines) content += `\n${line}`;
140
- for (const line of reExportLines) content += `\n${line}`;
141
- for (const line of declarationLines) content += `\n${line}`;
142
- content += "\n}";
133
+ } else if (Node.isExportAssignment(statement)) exports.push({
134
+ text: statement.getText(),
135
+ fullText: statement.getFullText(),
136
+ comment: statement.getLeadingCommentRanges().filter((c) => isSetString(c.getText().trim()) && !c.getText().includes("@module")).map((c) => c.getText().trim()).join("\n")
137
+ });
138
+ else if (Node.isFunctionDeclaration(statement) && statement.isExported() && statement.getNameNode()) exports.push({
139
+ text: statement.getText(),
140
+ fullText: statement.getFullText(),
141
+ specifiers: [{ name: statement.getNameNode().getText() }],
142
+ comment: statement.getLeadingCommentRanges().filter((c) => isSetString(c.getText().trim()) && !c.getText().includes("@module")).map((c) => c.getText().trim()).join("\n")
143
+ });
144
+ else if (Node.isVariableStatement(statement) && statement.isExported()) exports.push({
145
+ text: statement.getText(),
146
+ fullText: statement.getFullText(),
147
+ specifiers: statement.getDeclarationList().getDeclarations().filter((decl) => decl.getNameNode() && Node.isIdentifier(decl.getNameNode())).map((decl) => ({ name: decl.getNameNode().getText() })),
148
+ comment: statement.getLeadingCommentRanges().filter((c) => isSetString(c.getText().trim()) && !c.getText().includes("@module")).map((c) => c.getText().trim()).join("\n")
149
+ });
150
+ else if (Node.isClassDeclaration(statement) && statement.isExported()) {
151
+ const nameNode = statement.getNameNode();
152
+ exports.push({
153
+ text: statement.getText(),
154
+ fullText: statement.getFullText(),
155
+ specifiers: nameNode ? [{ name: nameNode.getText() }] : void 0,
156
+ comment: statement.getLeadingCommentRanges().filter((c) => isSetString(c.getText().trim()) && !c.getText().includes("@module")).map((c) => c.getText().trim()).join("\n")
157
+ });
158
+ } else if (Node.isInterfaceDeclaration(statement) && statement.isExported()) {
159
+ const nameNode = statement.getNameNode();
160
+ exports.push({
161
+ text: statement.getText(),
162
+ fullText: statement.getFullText(),
163
+ specifiers: nameNode ? [{ name: nameNode.getText() }] : void 0,
164
+ comment: statement.getLeadingCommentRanges().filter((c) => isSetString(c.getText().trim()) && !c.getText().includes("@module")).map((c) => c.getText().trim()).join("\n")
165
+ });
166
+ } else if (Node.isTypeAliasDeclaration(statement) && statement.isExported()) {
167
+ const nameNode = statement.getNameNode();
168
+ exports.push({
169
+ text: statement.getText(),
170
+ fullText: statement.getFullText(),
171
+ specifiers: nameNode ? [{ name: nameNode.getText() }] : void 0,
172
+ comment: statement.getLeadingCommentRanges().filter((c) => isSetString(c.getText().trim()) && !c.getText().includes("@module")).map((c) => c.getText().trim()).join("\n")
173
+ });
174
+ } else if (ctx.context.config.output.sourceMap || !statement.getFullText().includes("//# sourceMappingURL=")) exports.push({
175
+ text: statement.getText(),
176
+ fullText: statement.getFullText(),
177
+ comment: statement.getLeadingCommentRanges().filter((c) => isSetString(c.getText().trim()) && !c.getText().includes("@module")).map((c) => c.getText().trim()).join("\n")
178
+ });
143
179
  return {
144
- content,
145
- mappings,
146
- ambient
180
+ name,
181
+ text,
182
+ sourceFile,
183
+ comment,
184
+ imports,
185
+ exports
147
186
  };
148
187
  }
149
188
  /**
@@ -190,68 +229,77 @@ async function emitBuiltinTypes(context, files) {
190
229
  directives: []
191
230
  };
192
231
  }
193
- const fileToModuleMap = /* @__PURE__ */ new Map();
194
- const emittedBuiltinFiles = [];
195
- for (const emittedFile of emittedFiles) {
232
+ const ctx = {
233
+ context,
234
+ modules: [],
235
+ emitted: /* @__PURE__ */ new Map()
236
+ };
237
+ await Promise.all(emittedFiles.map(async (emittedFile) => {
196
238
  const filePath = appendPath(emittedFile.filePath, context.workspaceConfig.workspaceRoot);
197
239
  if (!filePath.endsWith(".map") && findFileName(filePath) !== "tsconfig.tsbuildinfo" && isParentPath(filePath, context.builtinsPath)) {
198
- const moduleId = replaceExtension(replacePath(replacePath(filePath, context.builtinsPath), replacePath(context.builtinsPath, context.workspaceConfig.workspaceRoot)), "", { fullExtension: true });
199
- if (context.builtins.includes(moduleId)) {
200
- fileToModuleMap.set(filePath, moduleId);
201
- emittedBuiltinFiles.push({
202
- filePath,
203
- text: emittedFile.text
204
- });
240
+ const moduleName = replaceExtension(replacePath(replacePath(filePath, context.builtinsPath), replacePath(context.builtinsPath, context.workspaceConfig.workspaceRoot)), "", { fullExtension: true });
241
+ if (context.builtins.includes(moduleName)) {
242
+ ctx.emitted.set(filePath, moduleName);
243
+ ctx.modules.push(await extractModuleDeclarations(ctx, filePath, moduleName, emittedFile.text));
205
244
  }
206
245
  }
207
- }
208
- const builtins = await context.getBuiltins();
209
- const emittedContentMap = /* @__PURE__ */ new Map();
210
- for (const emittedFile of emittedFiles) {
211
- const filePath = appendPath(emittedFile.filePath, context.workspaceConfig.workspaceRoot);
212
- if (!filePath.endsWith(".map") && findFileName(filePath) !== "tsconfig.tsbuildinfo") emittedContentMap.set(filePath, emittedFile.text);
213
- }
214
- let code = "";
215
- const directives = [];
216
- const ambientModules = /* @__PURE__ */ new Set();
217
- let isFirst = true;
218
- for (const entry of emittedBuiltinFiles) {
219
- context.trace(`Processing emitted type declaration file: ${entry.filePath}`);
220
- const moduleId = fileToModuleMap.get(entry.filePath);
221
- const moduleDecl = await writeModuleDeclarations(context, entry.filePath, moduleId, entry.text, fileToModuleMap);
222
- if (!isFirst) code += "\n\n";
223
- isFirst = false;
224
- code += moduleDecl.content;
225
- for (const dep of moduleDecl.ambient) if (dep.external) {
226
- const directive = dep.id;
227
- if (!directives.includes(directive)) directives.push(directive);
228
- } else if (builtins.some((builtin) => builtin.id === dep.id)) ambientModules.add(builtins.find((builtin) => builtin.id === dep.id).path);
229
- else if (builtins.some((builtin) => replaceExtension(builtin.path) === replaceExtension(dep.id))) ambientModules.add(dep.id);
230
- else {
231
- const resolved = await context.resolve(dep.id, entry.filePath);
232
- if (resolved) {
233
- for (const name of [
234
- resolved.id,
235
- `${resolved.id}.d.ts`,
236
- `${resolved.id}.d.mts`,
237
- `${resolved.id}.d.cts`,
238
- replaceExtension(resolved.id, ".d.ts"),
239
- replaceExtension(resolved.id, ".d.mts"),
240
- replaceExtension(resolved.id, ".d.cts"),
241
- `${resolved.id}/index.d.ts`
242
- ]) if (emittedContentMap.has(name)) {
243
- ambientModules.add(name);
246
+ }));
247
+ const commonDeclarations = [];
248
+ for (const mod of ctx.modules) for (const importRef of mod.imports.filter((importRef) => context.builtins.some((builtin) => importRef.name.endsWith(`:${builtin}`)))) {
249
+ const moduleRef = ctx.modules.find((moduleRef) => importRef.name.endsWith(`:${moduleRef.name}`));
250
+ if (moduleRef) {
251
+ let declaration;
252
+ for (const decl of moduleRef.exports.filter((decl) => isSetObject(decl))) {
253
+ const specifiers = decl.specifiers?.filter((specifier) => importRef.specifiers?.some((s) => (specifier.alias ? specifier.alias : specifier.name) === (s.alias ? s.alias : s.name)));
254
+ if (specifiers && specifiers.length > 0) {
255
+ importRef.specifiers = importRef.specifiers?.filter((s) => !specifiers.some((specifier) => (specifier.alias ? specifier.alias : specifier.name) === (s.alias ? s.alias : s.name)));
256
+ if (importRef.specifiers && importRef.specifiers.length === 0 && !importRef.all && !importRef.ambient) mod.imports = mod.imports.filter((imp) => imp.name !== importRef.name);
257
+ declaration = decl;
244
258
  break;
245
259
  }
246
260
  }
261
+ if (declaration) {
262
+ for (const decl of moduleRef.exports.filter((decl) => isSetObject(decl) && !decl.specifiers?.some((s) => declaration?.specifiers?.some((specifier) => (specifier.alias ? specifier.alias : specifier.name) === (s.alias ? s.alias : s.name))))) {
263
+ const exportModuleRef = decl;
264
+ if ((exportModuleRef.specifiers?.some((s) => s.alias || s.name) || exportModuleRef.name) && new RegExp(`(^|\\s|\\n|\\r\\n|\\(|\\)|<|>|{|}|\\[|\\]|\\!|\\?|\\.|,|\\*|&|:)(${exportModuleRef.specifiers?.map((s) => `${s.alias ? `${s.alias}|` : ""}${s.name}`).join("|") || exportModuleRef.name})($|\\s|\\n|\\r\\n|\\(|\\)|<|>|{|}|\\[|\\]|\\!|\\?|\\.|,|\\*|&|:|;)`).test(declaration.text)) commonDeclarations.push(exportModuleRef);
265
+ }
266
+ commonDeclarations.push(declaration);
267
+ }
247
268
  }
248
269
  }
249
- for (const ambientFile of ambientModules) {
250
- const dts = emittedContentMap.get(ambientFile);
251
- if (dts) {
252
- const cleaned = dts.replace(/\/\/# sourceMappingURL=.*$/m, "").trim();
253
- if (cleaned) code += `\n\n${formatTypes(cleaned)}`;
270
+ let code = "";
271
+ const directives = [];
272
+ for (const commonDeclaration of commonDeclarations) {
273
+ code += formatTypes(`${commonDeclaration.comment?.trim() ? commonDeclaration.comment.trim() : ""}${commonDeclaration.comment?.trim() ? "\n" : ""}${formatTypes(commonDeclaration.text.replace(/\s*export\s*/, "").replace(/\s*declare\s*interface\s*/, "interface ").replace(/\s*declare\s*type\s*/, "type "))}`);
274
+ code += "\n\n";
275
+ }
276
+ for (const mod of ctx.modules) {
277
+ code += mod.comment ? `${mod.comment.trim()}\n` : "";
278
+ code += `declare module "${context.config.framework}:${mod.name}" { \n`;
279
+ for (const importRef of mod.imports) if (importRef.ambient) code += directives.push(importRef.name);
280
+ else if (importRef.all) code += `\timport * as ${findFileName(importRef.name)} from "${importRef.name}";\n`;
281
+ else if (importRef.specifiers) {
282
+ const typeOnly = importRef.specifiers.every((s) => s.type) ? " type" : "";
283
+ const specifiers = importRef.specifiers.map((s) => s.alias ? `${s.name} as ${s.alias}` : s.name).join(", ");
284
+ code += `\timport${typeOnly} { ${specifiers} } from "${importRef.name}";\n`;
254
285
  }
286
+ if (mod.imports.length > 0) code += "\n";
287
+ for (const exportRef of mod.exports.filter((e) => isString(e) || !e.specifiers || !commonDeclarations.some((commonDecl) => commonDecl.specifiers && commonDecl.specifiers.some((specifier) => e.specifiers?.some((s) => (s.alias ? s.alias : s.name) === (specifier.alias ? specifier.alias : specifier.name)))))) if (isSetString(exportRef)) code += `${exportRef}\n`;
288
+ else if (exportRef.name) {
289
+ if (exportRef.all) code += `${exportRef.comment?.trim() ? exportRef.comment.trim() : ""}${exportRef.comment?.trim() ? "\n" : ""}export * from "${exportRef.name}";\n`;
290
+ else if (exportRef.specifiers) {
291
+ if (exportRef.comment?.trim()) code += `${exportRef.comment.trim()}\n`;
292
+ code += `\texport${exportRef.specifiers.every((s) => s.type) ? " type" : ""} { ${exportRef.specifiers.map((s) => s.alias ? `${s.name} as ${s.alias}` : s.name).join(", ")} } from "${exportRef.name}";\n`;
293
+ }
294
+ } else code += `${exportRef.comment?.trim() ? exportRef.comment.trim() : ""}${exportRef.comment?.trim() ? "\n" : ""}${formatTypes(exportRef.text.replace(/\s*export\s*declare\s*/, "export ").replace(/\s*declare\s*/, " "))}\n`;
295
+ mod.exports.filter((e) => !isString(e) && e.specifiers && commonDeclarations.some((commonDeclaration) => commonDeclaration.specifiers && commonDeclaration.specifiers.some((specifier) => e.specifiers?.some((s) => (s.alias ? s.alias : s.name) === (specifier.alias ? specifier.alias : specifier.name))))).forEach((e, i, arr) => {
296
+ if (i === 0) code += "\nexport { ";
297
+ else code += ", ";
298
+ code += `${e?.specifiers?.filter((s) => commonDeclarations.some((commonDeclaration) => commonDeclaration.specifiers && commonDeclaration.specifiers.some((specifier) => (s.alias ? s.alias : s.name) === (specifier.alias ? specifier.alias : specifier.name)))).map((s) => s.alias ? `${s.name} as ${s.alias}` : s.name).join(", ") || ""}`;
299
+ if (i === arr.length - 1) code += ` };\n`;
300
+ });
301
+ code += "}";
302
+ code += "\n\n";
255
303
  }
256
304
  code = await (0, utils_exports.format)(context, context.typesPath, code);
257
305
  context.debug(`A TypeScript declaration file (size: ${prettyBytes(new Blob(toArray(code)).size)}) emitted for the built-in modules types.`);
@@ -1027,4 +1075,4 @@ ${formatTypes(code)}
1027
1075
 
1028
1076
  //#endregion
1029
1077
  export { name as n, version as r, PowerlinesAPI as t };
1030
- //# sourceMappingURL=api-BVTRS4-e.mjs.map
1078
+ //# sourceMappingURL=api-BrPeHPR6.mjs.map