Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong handler recompiled when running in sandbox #16

Open
epfremmer opened this issue Dec 30, 2023 · 2 comments
Open

Wrong handler recompiled when running in sandbox #16

epfremmer opened this issue Dec 30, 2023 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@epfremmer
Copy link

When I have 2 http handlers with a common base path the first (shorter) handler is recompiled when there are changes made to the second.

Example:

Say I have the following http handlers:

  • src/http/get-api-v1-users/index.ts
  • src/http/get-api-v1-users-000id/index.ts

When I make a change to get-api-v1-users-000id, get-api-v1-users is recompiled instead. It looks like this line is matching the first handler because they share a common filename prefix.

Hopefully, this is helpful...

@ryanblock
Copy link
Member

Ah, wild! Fascinating find, thank you.

@ryanblock ryanblock self-assigned this Dec 30, 2023
@ryanblock ryanblock added the bug Something isn't working label Dec 30, 2023
@epfremmer
Copy link
Author

No problem! I ended up patching it locally by using dirname:

diff --git a/node_modules/@architect/plugin-typescript/src/index.js b/node_modules/@architect/plugin-typescript/src/index.js
index 6520fda..ba6cc66 100644
--- a/node_modules/@architect/plugin-typescript/src/index.js
+++ b/node_modules/@architect/plugin-typescript/src/index.js
@@ -1,3 +1,4 @@
+let path = require('path');
 let {
   compileProject,
   compileHandler,
@@ -48,16 +49,16 @@ module.exports = {
       let { filename, /* event, */ inventory } = params
       if (filename.endsWith('.ts') || filename.endsWith('.tsx')) {
         let { lambdasBySrcDir, shared, views } = inventory.inv
+        let dirname = path.dirname(filename);
 
         // Second pass filter by shared dirs
-        if (filename.startsWith(shared?.src) ||
-            filename.startsWith(views?.src)) {
+        if (dirname === shared?.src || dirname === views?.src) {
           await compileProject(params)
           return
         }
 
         // Second pass filter by Lambda dir
-        let lambda = Object.values(lambdasBySrcDir).find(({ src }) => filename.startsWith(src))
+        let lambda = Object.values(lambdasBySrcDir).find(({ src }) => dirname === src)
 
         if (!lambda) { return }

but I'm still fairly new to using architect so I'm not totally confident that solution works well for all projects.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

No branches or pull requests

2 participants