Skip to content

Commit 2860ee5

Browse files
committed
fix: keep fn generator aligned with SMS function output
1 parent ab46bd2 commit 2860ee5

2 files changed

Lines changed: 34 additions & 9 deletions

File tree

packages/fn-generator/src/builders/package.ts

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import type { FunctionInfo, Manifest } from '../types';
88
* Build all manifests for a single function:
99
* - per-template files (placeholders applied, package.json/tsconfig.json processed)
1010
* - shared template files (same processing)
11-
* - symlinks for handler.{ts,py}, *.d.ts, and any other *.py
11+
* - symlinks for handler.{ts,py} and supporting TypeScript/Python sources
1212
*
1313
* `templateDir` is the resolved type-specific dir (`templates/node-graphql/` etc.).
1414
*/
@@ -56,17 +56,40 @@ export const buildPackageManifests = (
5656
out.push({ kind: 'symlink', path: path.join(args.genDir, 'handler.py'), target: handlerPy });
5757
}
5858

59-
// 4. Auxiliary symlinks: all *.d.ts and *.py (except handler.py already linked above)
60-
const files = fs.readdirSync(args.fnDir);
61-
for (const file of files) {
62-
if (file.endsWith('.d.ts') || (file.endsWith('.py') && file !== 'handler.py')) {
59+
// 4. Supporting source symlinks. Richer functions may split implementation
60+
// across nested TypeScript/Python files; mirror scripts/generate.ts exactly.
61+
const addSupportSymlinks = (base = ''): void => {
62+
const entries = fs.readdirSync(path.join(args.fnDir, base));
63+
for (const entry of entries) {
64+
if (entry === '__tests__') continue;
65+
66+
const relPath = path.join(base, entry);
67+
const sourcePath = path.join(args.fnDir, relPath);
68+
const stat = fs.statSync(sourcePath);
69+
70+
if (stat.isDirectory()) {
71+
addSupportSymlinks(relPath);
72+
continue;
73+
}
74+
75+
if (
76+
relPath === 'handler.ts' ||
77+
relPath === 'handler.py' ||
78+
!(/\.(ts|d\.ts|py)$/.test(entry)) ||
79+
entry.endsWith('.test.ts')
80+
) {
81+
continue;
82+
}
83+
6384
out.push({
6485
kind: 'symlink',
65-
path: path.join(args.genDir, file),
66-
target: path.join(args.fnDir, file),
86+
path: path.join(args.genDir, relPath),
87+
target: sourcePath,
6788
});
6889
}
69-
}
90+
};
91+
92+
addSupportSymlinks();
7093

7194
return out;
7295
};

packages/fn-generator/src/discovery.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ export const assignAndValidatePorts = (
5252
const usedPorts = new Set<number>(
5353
manifests.filter((m) => m.port).map((m) => m.port as number)
5454
);
55-
let nextPort = usedPorts.size > 0 ? Math.max(...usedPorts) + 1 : 8081;
55+
// Fill the lowest available local function port first. Explicit high ports
56+
// must not shift existing functions that rely on automatic assignment.
57+
let nextPort = 8081;
5658
for (const m of manifests) {
5759
if (!m.port) {
5860
while (usedPorts.has(nextPort)) nextPort++;

0 commit comments

Comments
 (0)