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

Updates #2

Merged
merged 5 commits into from
Nov 22, 2024
Merged

Updates #2

merged 5 commits into from
Nov 22, 2024

Conversation

Ethan-Arrowood
Copy link
Contributor

  • removes Next.js version limitation
  • invokes next.js through its specified main path (package.json#main)
  • removes dependency on semver
  • Includes project's node_modules/.bin in the child_process path so that next build works correctly
  • adds command existance check via which

Copy link
Member

@kriszyp kriszyp left a comment

Choose a reason for hiding this comment

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

Great progress

extension.js Outdated
@@ -169,12 +171,21 @@ function assertNextJSApp(componentPath) {
*/
async function executeCommand(commandInput, componentPath) {
const [command, ...args] = shellQuote.parse(commandInput);
const cp = child_process.spawn(command, args, {
const env = { ...process.env, PATH: `${process.env.PATH}:${componentPath}/node_modules/.bin` };
Copy link
Member

Choose a reason for hiding this comment

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

I thought with an exec, that the pathing to the node_modules/.bin directory, but maybe I am misremembering. If this works, that's fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought so too, but I believe that is strictly when npm is being invoked. Since the default build command is just next build we need to set the bin here.

Im considering changing the default to npm run build but there's some UX to consider there. I'll review tomorrow

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay so the reason why I can't have the default be npm run build, is that the ideal UX is that the user changes their build script to: harperdb-nextjs build. Thus, { "scripts": { "build": "harperdb-nextjs build" } } in their package.json. This enables the user to locally run npm run build and 🪄 . If the extension would only ever run npm run build, then this would create a infinite loop.

extension.js Outdated
@@ -169,12 +171,21 @@ function assertNextJSApp(componentPath) {
*/
async function executeCommand(commandInput, componentPath) {
const [command, ...args] = shellQuote.parse(commandInput);
const cp = child_process.spawn(command, args, {
const env = { ...process.env, PATH: `${process.env.PATH}:${componentPath}/node_modules/.bin` };
let cp = child_process.spawn('which', [command], { cwd: componentPath, env, stdio: 'ignore' });
Copy link
Member

Choose a reason for hiding this comment

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

If the command can't be found, doesn't the ENOENT error code unambiguously indicate that? Is it necessary to do a which first or can we just listen for errors on the main spawn call and translate ENOENT to the appropriate error message.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point

extension.js Outdated

const [exitCode] = await events.once(cp, 'exit');
cp.on('error', (error) => {
throw error;
Copy link
Member

Choose a reason for hiding this comment

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

This is going to be an uncaught error, might be preferable to wrap this block in a Promise constructor so we could reject here.

@kriszyp kriszyp merged commit ad426f5 into main Nov 22, 2024
@Ethan-Arrowood Ethan-Arrowood deleted the updates branch November 22, 2024 19:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants