zero-com 1.5.0 → 1.6.0

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.
Files changed (2) hide show
  1. package/lib/common.js +35 -0
  2. package/package.json +1 -1
package/lib/common.js CHANGED
@@ -217,6 +217,38 @@ if (!globalThis.${exports.ZERO_COM_SERVER_REGISTRY}) globalThis.${exports.ZERO_C
217
217
  ${registrations};`;
218
218
  };
219
219
  exports.appendRegistryCode = appendRegistryCode;
220
+ // Helper to ensure a specific named import exists
221
+ const ensureImport = (sourceFile, moduleSpecifier, namedImport) => {
222
+ const importDecls = sourceFile.getImportDeclarations().filter(d => d.getModuleSpecifierValue() === moduleSpecifier);
223
+ // 1. Look for an existing import declaration that already has named imports or is empty (not namespace/default only)
224
+ let targetDecl = importDecls.find(d => !d.getNamespaceImport() && !d.getDefaultImport());
225
+ if (!targetDecl) {
226
+ // Fallback: look for any declaration that has named imports (mixed with default is fine)
227
+ targetDecl = importDecls.find(d => d.getNamedImports().length > 0);
228
+ }
229
+ if (targetDecl) {
230
+ if (!targetDecl.getNamedImports().some(ni => ni.getName() === namedImport)) {
231
+ targetDecl.addNamedImport(namedImport);
232
+ }
233
+ }
234
+ else {
235
+ // 2. Check for default import where we can append named import
236
+ // Avoid namespace imports as we can't add named imports to `import * as ns`
237
+ const defaultImportDecl = importDecls.find(d => d.getDefaultImport() && !d.getNamespaceImport());
238
+ if (defaultImportDecl) {
239
+ if (!defaultImportDecl.getNamedImports().some(ni => ni.getName() === namedImport)) {
240
+ defaultImportDecl.addNamedImport(namedImport);
241
+ }
242
+ }
243
+ else {
244
+ // 3. Create new import declaration
245
+ sourceFile.addImportDeclaration({
246
+ moduleSpecifier,
247
+ namedImports: [namedImport]
248
+ });
249
+ }
250
+ }
251
+ };
220
252
  const transformSourceFile = (filePath, content, registry) => {
221
253
  const project = (0, exports.createProject)();
222
254
  const sourceFile = project.createSourceFile(filePath, content, { overwrite: true });
@@ -230,6 +262,9 @@ const transformSourceFile = (filePath, content, registry) => {
230
262
  const callsTransformed = (0, exports.transformCallSites)(sourceFile, importedFuncs);
231
263
  const handleTransformed = (0, exports.transformHandleCalls)(sourceFile);
232
264
  const sendTransformed = (0, exports.transformSendCalls)(sourceFile);
265
+ if (handleTransformed) {
266
+ ensureImport(sourceFile, exports.LIBRARY_NAME, exports.EXEC_FUNC_NAME);
267
+ }
233
268
  if (isServerFunctionFile) {
234
269
  return { content: (0, exports.appendRegistryCode)(sourceFile, fileRegistry), transformed: true };
235
270
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zero-com",
3
- "version": "1.5.0",
3
+ "version": "1.6.0",
4
4
  "main": "index.js",
5
5
  "repository": "https://github.com/yosbelms/zero-com",
6
6
  "keywords": [