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

Get the library running again without errors [Breaking change] #482

Open
wants to merge 14 commits into
base: master
Choose a base branch
from

Conversation

rouanw
Copy link
Contributor

@rouanw rouanw commented Nov 17, 2022

Background

Last week I used npm-check for the first time in a while. I pulled the code and the test script isn't passing at the moment. The reason for this is that the renovate bot has upgraded a number of packages and quite a few of them (notably some maintained by https://github.com/sindresorhus) have dropped support for CommonJS in favour of ESM.

You can see Sindre’s motivations here: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c.

Approach

I think we can safely convert npm-check to a pure ESM module too. Most users are likely using the library via the CLI, so it should make no difference to them. For those importing the library, they’ll be able to use an older version of npm-check or do an async import.

I think we can safely drop support for es5. Even if there were some older projects still using es5, CLI users could switch node versions as a workaround and library users could pin to an older version.

This PR:

  • Drops support for es5 consumers (breaking change)
  • Converts npm-check to a pure ESM module (breaking change)
  • Fixes the lint configuration so we lint all files in lib.
  • Fixes a number of linting issues. The rest I've downgraded to warnings for now.
  • Moves the xo config to its own file so it doesn't take up too much space in the package.json
  • Adds one very simple test that checks the library can be imported and called. I've used ava because ESM support in jest is experimental.
  • Adds a GitHub Action workflow to run the tests against node 14, 16 and 18.

The net result is that the library can now be run without errors.

cc @dylang

bin/cli.js Outdated Show resolved Hide resolved
return script.indexOf(moduleName) !== -1;
return script.includes(moduleName);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice! 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You can thank xo --fix 😆

package.json Outdated Show resolved Hide resolved
npm-check.test.js Outdated Show resolved Hide resolved
const currentState = await npmCheck({});
const packages = await currentState.get('packages');
t.truthy(packages.length > 0);
});
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we add a test that runs the cli tool as well? As that was the previous test

Copy link
Contributor Author

Choose a reason for hiding this comment

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

On this branch, I've changed the npm test script to:

"test": "npm run lint && ava && ./bin/cli.js || echo Exit Status: $?."

So I've added the ava test to the existing test of running cli.js, rather than replacing it.

Copy link
Collaborator

@LinusU LinusU left a comment

Choose a reason for hiding this comment

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

Awesome work! 👍

Just a few small nits

@LinusU
Copy link
Collaborator

LinusU commented Nov 18, 2022

I have no idea why the bot is bumping the engines field since that would be a breaking change 🤦‍♂️ #481

But could you change the engines field to the following in this PR? And I'll try and disable that in the bot.

"node": "^12.20.0 || ^14.13.1 || >=16.0.0"

Could you also change the CI to test on exactly those versions? (I think it's much more likely that we accidentally depend on something only available in newer versions of Node, than that Node.js breaks backwards compatibility in a minor version)

node-version: [12.20.0, 14.13.1, 16.0.0]

@LinusU
Copy link
Collaborator

LinusU commented Nov 18, 2022

Oh, and could you also remove .travis.yml and appveyor.yml 🙏

@rouanw
Copy link
Contributor Author

rouanw commented Nov 18, 2022

Thanks for the great feedback @LinusU. I think I've addressed everything – would you mind taking another look please?

It seems that removing the config file didn't quite placate AppVeyor - see https://ci.appveyor.com/project/dylang/npm-check/builds/45424492. It looks like it's reverted to some sort of default configuration. Perhaps we need to delete the project in the AppVeyor UI?

@LinusU
Copy link
Collaborator

LinusU commented Nov 22, 2022

Awesome!

Just realised that I'm not actually admin on this repo 😅

@dylang could you remove AppVeyor, and enable GitHub Actions please?

MiniDigger added a commit to MiniDigger/npm-check that referenced this pull request Jan 2, 2023
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