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

Build Tooling: Skip package for build if package.json unreadable #19439

Merged
merged 2 commits into from
Jan 6, 2020

Conversation

aduth
Copy link
Member

@aduth aduth commented Jan 6, 2020

This pull request seeks to resolve an issue where npm run dev can log errors for missing packages, typically when changing branches to an older branch:

⇒ npm run dev

> [email protected] dev:packages /Users/andrew/Documents/Code/gutenberg
> node ./bin/packages/watch.js

internal/modules/cjs/loader.js:797
    throw err;
    ^

Error: Cannot find module '/Users/andrew/Documents/Code/gutenberg/packages/foo/package.json'
...

The problem is that when switching to older branches where a package may not have yet been implemented, the package may be left lingering in the working directory, presumably because its built contents are considered in .gitignore.

In these cases, it should be safe to simply ignore the package. The implementation here generalizes this to ignore any directory in packages for which the package.json file cannot be read.

Testing Instructions:

Verify that an empty directory under packages does not cause a build failure on npm run dev:packages:

  1. mkdir packages/foo
  2. npm run dev:packages
  3. Note that "-> Watching for changes..." is logged, changes to valid packages still cause a rebuild

@aduth aduth added [Type] Bug An existing feature does not function as intended [Type] Build Tooling Issues or PRs related to build tooling labels Jan 6, 2020
These package directories aren't always empty (in fact, in most cases they exist due to the fact that the `build` directory within is ignored via `.gitignore`).
@aduth
Copy link
Member Author

aduth commented Jan 6, 2020

This should fix a (rather frustrating) issue where rebuilds don't happen at all if the initial error occurs where an extra (non-package) directory was found.

@aduth aduth merged commit afed83d into master Jan 6, 2020
@aduth aduth deleted the fix/tolerant-get-packages branch January 6, 2020 21:40
@ellatrix ellatrix added this to the Gutenberg 7.3 milestone Jan 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Bug An existing feature does not function as intended [Type] Build Tooling Issues or PRs related to build tooling
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants