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

afterPublish is called before the package is effectively published #604

Open
francoischalifour opened this issue Jan 9, 2020 · 4 comments

Comments

@francoischalifour
Copy link
Member

Describe the bug

I'm trying to upgrade my package dependency after it was published with the afterPublish hook. However, Ship.js doesn't wait for the publication to run afterPublish. Therefore, the npm registry isn't updated when the function is called, resulting in an upgrade error.

To Reproduce

Steps to reproduce the behavior:

  1. Add an afterPublish hook that relies on the npm registry
  2. Trigger a release (on CircleCI for instance)
  3. afterPublish errors because it's called before the package is effectively published to the npm registry

Expected behavior

We should somehow await before calling runAfterPublish so that this kind of afterPublish scripts is made possible.

Side note

It'd be nice to have access to a version parameter in the afterPublish function so that we don't need to read it from package.json.

@Haroenv
Copy link
Contributor

Haroenv commented Jan 9, 2020

There's npm hooks that could be awaited for the next release, but I think more likely an exponential backoff which checks if it's actually published will be more reliable

@eunjae-lee
Copy link
Contributor

Hi @francoischalifour ,

https://npm.community/t/newly-published-packages-have-a-delay-before-they-are-consumable/952

Indeed, there can be a gap between publish and distribution. Ship.js is made for releasing packages to NPM, but now that it provides publishCommand to customize publishCommand.
So I'm not sure if it's good to add waiting behaviour before afterPublish by default (User might not release to NPM at all.)

What if waitForNpmDistribution function is provided at afterPublish? waitForNpmDistribution can be implemented by exponential backoff like @Haroenv said.

  afterPublish({ exec, dir, version, waitForNpmDistribution }) {
    await waitForNpmDistribution();

    // Update the Autocomplete.js version in the examples
    const examplePath = path.resolve(dir, 'examples/autocomplete.js');

    // eslint-disable-next-line no-console
    console.log('Updating Autocomplete.js dependency in examples...');

    exec(
      `cd ${examplePath} && yarn upgrade @francoischalifour/autocomplete.js@${version}`
    );
    exec('git add examples');
    exec('git commit -m "chore(examples): update autocomplete.js dependency"');
    exec('git push origin next');
  },

What do you think?

@francoischalifour
Copy link
Member Author

At second thought, it makes sense to not fully rely on npm distribution as you mentioned.

Having a way that is documented would be great. waitForNpmDistribution is good to me!

@Haroenv
Copy link
Contributor

Haroenv commented Jan 10, 2020

Maybe a general "waitForDistribution" could be provided by the function which actually publishes in the previous hook?

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

No branches or pull requests

3 participants