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

Use a Promise wrapper for fs actions and minimist for argv parsing #25

Merged
merged 4 commits into from Mar 9, 2018

Conversation

kadamwhite
Copy link
Collaborator

This PR (which is PR'd against #15, not against master) proposes some final changes to #15 based on my review comments there.

  • Wrap callback-based fs actions in a ¶romise to ensure that action completes before we report success
  • Add chalk to project dependencies
  • Revert the change to auto-generating the script loader namespace from the project directory, in favor of using the --php-namespace command-line argument

To test, run

npx create-react-app --scripts-version git+https://git@github.com/humanmade/react-wp-scripts.git#12-init-proposed-changes --php-namespace DemoNamespace demo-wpscripts-plugin

Errors while reading and writing the namespace were not passed on to the
Promise chain, so the script would report that it was complete prior to
actually finishing file system interactions (where a further error may
then occur after we gave the all-clear). This commit wraps the callback-
based filesystem interaction in a Promise and passes errors to reject().

Chalk is also added to the project dependencies so that we don't rely on
the react-scripts dependency list.
While defaulting to ReactWPScripts does run the risk of namespace
collisions if multiple themes or plugins use the default value, deriving
the name of the script-loader namespace from the project's directory
name feels overly-general.
@kadamwhite kadamwhite mentioned this pull request Mar 8, 2018
scripts/init.js Outdated
namespace = upperCamelCase( projectPackageJSON.name );
}
catch ( err ) {}
let namespace = argv['php-namespace'] || 'ReactWPScripts';
Copy link
Contributor

Choose a reason for hiding this comment

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

Can be const now.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point!

@rmccue
Copy link
Member

rmccue commented Mar 9, 2018

@kadamwhite Can you split your php-namespace change out? The rest seems uncontroversial, so we can merge that straight away :)

@rmccue rmccue merged commit 2abe292 into 12-scripts-version-compatibility Mar 9, 2018
@rmccue rmccue deleted the 12-init-proposed-changes branch March 9, 2018 01:45
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