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

feat(space-nuxt-base): run tunnel on start up #75

Merged
merged 5 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions space-plugins/nuxt-base/modules/tunnel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { defineNuxtModule } from '@nuxt/kit';
import { execaCommand } from 'execa';

export default defineNuxtModule({
setup(_options, nuxt) {
const tunnelCommand = process.env.TUNNEL_COMMAND;
if (process.env.NODE_ENV !== 'development' || !tunnelCommand) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @eunjae-lee this might not be ready yet, I am just leaving comments as I am OOO tomorrow, but not to block you.

nit: process.env.NODE_ENV !== 'development' is this check needed? From what I understood, the listen hook will only be triggered when dev server is loaded. But I might be missing something here.

question: What happens when the dev server is closed, will the tunnel still be running?

Copy link
Contributor Author

@eunjae-lee eunjae-lee Jul 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually added the explanation in the PR description, but if the dev server is closed, the tunnel will be closed as well, because the tunnel is the child process of the dev server process. When the parent dies, the child dies as well. (horrific dev story)

process.env.NODE_ENV !== 'development' -> I guess we won't really need it because listen is for the dev server as you said, however, if we have this, the production build will not include the code within the if clause at all, and it means we won't include execa dependency as well in the bundle output. I actually copied this https://github.com/nuxtus/localtunnel/blob/main/src/module.ts#L44, and I believe that's why they did so?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😂😂

Totally missed the description sorry. I read it now, thank you for the details. Everything looks perfect. Can't wait to try it 🫰🏻

return;
}
nuxt.hook('listen', async () => {
// using execa@8.0.1 because we're using a bit lower version of Node.js than what execa@9 requires.
// https://github.com/sindresorhus/execa/blob/v8.0.1/readme.md
execaCommand(tunnelCommand);
});
},
});
3 changes: 2 additions & 1 deletion space-plugins/nuxt-base/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
"jsonwebtoken": "^9.0.2"
},
"devDependencies": {
"@types/jsonwebtoken": "^9.0.6",
"@nuxt/devtools": "latest",
"@types/jsonwebtoken": "^9.0.6",
"execa": "^8.0.1",
"h3": "^1.8.2",
"nuxt": "3.11.1",
"typescript": "^5.1.3",
Expand Down
3 changes: 3 additions & 0 deletions space-plugins/nuxt-base/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.