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

Require Node.js 12.20 and move to ESM #478

Merged
merged 13 commits into from Nov 17, 2021
Merged

Require Node.js 12.20 and move to ESM #478

merged 13 commits into from Nov 17, 2021

Conversation

NMinhNguyen
Copy link
Contributor

@NMinhNguyen NMinhNguyen commented Nov 15, 2021

Apologies for a huge PR but it's best to review ignoring whitespace: https://github.com/sindresorhus/execa/pull/478/files?w=1

I tried to follow the following resources:

Opening this as a draft PR since I'm not 100% sure of some of the changes:

  • What should the named exports be for command, commandSync and node? Should they be execaCommand, execaCommandSync and execaNode? Prefixed the named exports with execa.
  • Had to switch from nyc to c8 to work around Nyc on ESM Node.js 13 (no babel) istanbuljs/nyc#1287
  • Removed Node.js 12 from the test matrix as I've changed require to import() + top-level await (TLA) in main...NMinhNguyen:esm?expand=1&w=1#diff-8f4f0a53c9, and TLA isn't supported in Node.js 12. Changed the test in aefa85c (#478) to ensure tests can still be run in Node.js 12.
  • Moved the fixtures to ESM which required adding a .js extension. Alternatively, I could've added a package.json with "type": "commonjs".

TODOs

  • Ensure all fixtures are referenced using .js extension

@sindresorhus
Copy link
Owner

What should the named exports be for command, commandSync and node? Should they be execaCommand, execaCommandSync and execaNode?

Yes, that's what I would go with, but let's wait for @ehmicky's opinion.

test/node.js Show resolved Hide resolved
index.test-d.ts Show resolved Hide resolved
index.d.ts Show resolved Hide resolved
package.json Show resolved Hide resolved
package.json Show resolved Hide resolved
test/command.js Outdated Show resolved Hide resolved
test/error.js Outdated Show resolved Hide resolved
index.d.ts Show resolved Hide resolved
Copy link
Collaborator

@ehmicky ehmicky left a comment

Choose a reason for hiding this comment

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

Thank you so much for working on this @NMinhNguyen, this is super awesome! That's a huge amount of work.

I reviewed it thoroughly and this is looking pretty close to perfect to me, except a few points:

Thanks a lot for focusing this PR only on the conversion itself, without changing any logic, except for dependencies upgrade, that's very helpful. ❤️

@NMinhNguyen
Copy link
Contributor Author

Thanks for the thorough review @ehmicky! I'll see if I can split the changes into a more reviewable diff when I get home tonight.

@ehmicky
Copy link
Collaborator

ehmicky commented Nov 15, 2021

Note: I think only the exported function names would need to be split into a separate PR, and that renaming has not been done yet. In particular, we do not need to split a PR for the xo update, per our above discussion.

@NMinhNguyen
Copy link
Contributor Author

Note: I think only the exported function names would need to be split into a separate PR, and that renaming has not been done yet. In particular, we do not need to split a PR for the xo update, per our above discussion.

Ah I meant I'd try to split this single commit into smaller ones for a better diff, unless you've already thoroughly reviewed all the changes? I find that ?w=1 really helps in these situations.

@ehmicky
Copy link
Collaborator

ehmicky commented Nov 15, 2021

Breaking it down to smaller commits might help @sindresorhus, since he might want to do a second round of review before we merge this PR. But as far as I am concerned, I've reviewed all of this PR, so I would not benefit from breaking down the commits.

@NMinhNguyen NMinhNguyen changed the title Convert from CommonJS to ESM Require Node.js 12.20 and move to ESM Nov 16, 2021
@NMinhNguyen NMinhNguyen marked this pull request as ready for review November 16, 2021 05:50
readme.md Show resolved Hide resolved
@NMinhNguyen NMinhNguyen marked this pull request as draft November 16, 2021 07:23
@NMinhNguyen NMinhNguyen marked this pull request as ready for review November 16, 2021 08:13
@NMinhNguyen
Copy link
Contributor Author

NMinhNguyen commented Nov 16, 2021

@ehmicky I've pushed separate commits (so you can review them more easily) to

  • restore the original formatting in index.d.ts (view the overall diff for this PR, it should be easier to follow)
  • update the named exports

I believe that these changes aren't too bad to review now (remember to use ?w=1) but if you have any objections, it is trivial for me to drop them.

test/error.js Outdated Show resolved Hide resolved
@ehmicky
Copy link
Collaborator

ehmicky commented Nov 16, 2021

This works like this, thanks @NMinhNguyen!

The PR looks good to me now 👍
@sindresorhus What do you think?

@NMinhNguyen
Copy link
Contributor Author

Pushed a change that restores running tests against Node.js 12. @ehmicky let me know if there's anything further you'd like me to do.

@sindresorhus
Copy link
Owner

There are a couple of outdated references:

test/stdio.js
51:forkMacro.title = macroTitle('execa.fork()');

lib/command.js
26:// Handle execa.command()

@sindresorhus
Copy link
Owner

It would also be great if you could remove all the (async () => { wrappers in the docs.

@NMinhNguyen
Copy link
Contributor Author

There are a couple of outdated references:

test/stdio.js
51:forkMacro.title = macroTitle('execa.fork()');

What should this be updated to since there's no execaFork?

By the way, I found another way to rewrite the override-promise.js test such that it works in Node.js 12 but I'm not sure if it's preferable as it's a little bit hacky:

test('should work with third-party Promise', async t => {
	// Introduce an artificial delay to avoid breaking `ava`.
	await Promise.resolve();

	// Can't use `test.before`, because `ava` needs `Promise`.
	const nativePromise = Promise;
	global.Promise = class BrokenPromise {
		then() {
			throw new Error('error');
		}
	};
	const {execa} = await import('../index.js');
	global.Promise = nativePromise;

	const {stdout} = await execa('noop.js', ['foo']);
	t.is(stdout, 'foo');
});

@sindresorhus
Copy link
Owner

What should this be updated to since there's no execaFork?

execaNode

@sindresorhus
Copy link
Owner

By the way, I found another way to rewrite the override-promise.js test such that it works in Node.js 12 but I'm not sure if it's preferable as it's a little bit hacky:

We can just keep the existing workaround until we can target Node.js 14.

@sindresorhus sindresorhus merged commit 7707880 into sindresorhus:main Nov 17, 2021
@sindresorhus
Copy link
Owner

Thanks for working on this, @NMinhNguyen 👍

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.

None yet

3 participants