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

SDK: Shuffle around configuration in SDK runner #26680

Merged
merged 4 commits into from
Aug 15, 2018

Conversation

dmsnell
Copy link
Member

@dmsnell dmsnell commented Aug 14, 2018

When building with the SDK we have a generic runner - sdk-cli.js
and target-specific options for that runner - gutenberg.js. We
invoke the runner script while specifying the target which it calls.

Some of our configuration and runtime code though has been split
across these two places and some of the configuration could maybe
be moved upwards into the main Calypso config.

In this patch I'm shuffling around the configuration and execution
code to try and separate those layers more clearly. This work serves
to prepare us as well for integrating other projects, such as the
notifications panel, into the Calpyso repository.

Testing

Everything needs to build without regression.

The results in iscalypsofastyet.com should show no change in
the output size of the app. The same is true of built plugins for
Gutenberg that were built with this script.

We need to verify that the plugins run inside of Gutenberg too.

npm run sdk:gutenberg -- --editor-script client/gutenberg/extensions/presets/o2/editor.js --view-script client/gutenberg/extensions/presets/o2/view.js --output-dir ~/wherever/

@dmsnell dmsnell added Framework [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. Build [Project] SDK labels Aug 14, 2018
@dmsnell dmsnell requested a review from simison August 14, 2018 08:14
@matticbot
Copy link
Contributor

@dmsnell dmsnell requested review from ockham, ehg, coderkevin, tyxla and a team August 14, 2018 08:14

const config = {
return {
...baseConfig,
...{
context: __rootDir,
Copy link
Member

Choose a reason for hiding this comment

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

Moving context: __rootDir, to sdk-cli.js would probably make sense since it needs to be there each time sdk-cli.js is run via bin scripts.

Thus we also don't need to pass __rootDir down to gutenberg.js

Copy link
Member Author

Choose a reason for hiding this comment

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

thanks. I wondered about that but didn't feel confident enough on my own to move it

Copy link
Member

Choose a reason for hiding this comment

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

We could even consider moving it to webpack.config.js if it's not too much noise there, although it's relevant only for the SDK CLI.

Copy link
Member Author

Choose a reason for hiding this comment

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

moved!

@simison
Copy link
Member

simison commented Aug 14, 2018

Nice job!

The only regression I see is lack of --mode=production|development in CLI but suppose we'll build like so in future —

Production:

NODE_ENV=production calypso-sdk gutenberg --editor-script=client/gutenberg/extensions/hello-dolly/hello-block.js

Development:

calypso-sdk gutenberg --editor-script=client/gutenberg/extensions/hello-dolly/hello-block.js

That works for me, as long as development is the default. 👍

/**
* Converts @wordpress require into window reference
*
* Note this isn't the same as camelCase becuase of the
Copy link
Member

Choose a reason for hiding this comment

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

Typo here: becuase should be because. Also, perhaps we want to change camelCase to _.camelCase to be more specific.

Copy link
Member Author

Choose a reason for hiding this comment

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

thanks for the typo. interestedly though I wasn't referring to _.camelCase. maybe I should write camel case instead? I wanted to refer to the algorithm, not the lodash or underscore implementation…

Copy link
Member

Choose a reason for hiding this comment

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

camel case should be even better as it's more broad indeed 👍

Copy link
Member Author

Choose a reason for hiding this comment

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

space added!

const wordpressRequire = request => {
const [ , /* @wordpress */ name ] = request.split( '/' );

return `wp.${ name.replace( /-([a-z])/, ( match, letter ) => letter.toUpperCase() ) }`;
Copy link
Member

Choose a reason for hiding this comment

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

I see that you've removed the global flag /g, but this will not work as expected for imports that contain more than one dash in the second part of the name. In other words @wordpress/block-serialization-spec-parser will become wp.blockSerialization-spec-parser. We should bring back the global flag.

Copy link
Member Author

Choose a reason for hiding this comment

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

oops!

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed!

* @return {string} global variable reference for import
*/
const wordpressRequire = request => {
const [ , /* @wordpress */ name ] = request.split( '/' );
Copy link
Member

Choose a reason for hiding this comment

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

Should /* @wordpress */ be listed before the comma?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes but prettier moves it back - a long-standing bug sadly :(

Copy link
Member Author

Choose a reason for hiding this comment

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

adjusted to it's clearer

description: 'Entry for editor-side JavaScript file',
type: 'string',
required: true,
coerce: value => path.resolve( __dirname, '../', value ),
Copy link
Member

Choose a reason for hiding this comment

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

Not related with the PR, but occurred to me now: the *-script args use the same coerce callback - should we define it separately and use it for both?

Copy link
Member Author

Choose a reason for hiding this comment

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

🤷‍♂️ is the point to not write it twice? I don't understand coerce so I don't have a real opinion on the matter.

Copy link
Member

Choose a reason for hiding this comment

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

It's not about coerce - it's just about not defining the same callback twice when we can define it just once and just reuse it.

Copy link
Member Author

Choose a reason for hiding this comment

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

meh. it's an inline callback used twice. depending on how I feel when you ask me I'd probably suggest leaving it for now. if we discover that it's an important part that will need to be shared across many different places and the behavior needs to be the same for all of them then yeah I could be for that. at this point I'm not sure we have enough warrant to make the abstraction

Copy link
Member

Choose a reason for hiding this comment

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

Agreed, sometimes writing one line twice makes the code more clear. :-)

coerse docs if you wanna check it out: https://github.com/yargs/yargs/blob/efc0970bc8f91359905882b6990ffc0786193068/docs/api.md#coercekey-fn @dmsnell

@@ -163,10 +187,6 @@ function getWebpackConfig( { extensionName = '' } = {}, argv ) {
use: _.compact( [
MiniCssExtractPlugin.loader,
'css-loader',
extensionName && {
Copy link
Member

Choose a reason for hiding this comment

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

Are we intentionally removing the namespacing?

Copy link
Member Author

Choose a reason for hiding this comment

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

after removing it no, but temporarily in this diff we were

When building with the SDK we have a generic runner - `sdk-cli.js`
and target-specific options for that runner - `gutenberg.js`. We
invoke the runner script while specifying the target which it calls.

Some of our configuration and runtime code though has been split
across these two places and some of the configuration could maybe
be moved upwards into the main Calypso config.

In this patch I'm shuffling around the configuration and execution
code to try and separate those layers more clearly. This work serves
to prepare us as well for integrating other projects, such as the
notifications panel, into the Calpyso repository.
@dmsnell dmsnell force-pushed the sdk/shuffle-runner-config branch from 53217a5 to a4b01f3 Compare August 15, 2018 10:49
Copy link
Member

@tyxla tyxla left a comment

Choose a reason for hiding this comment

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

Nice work 👍 Looking good and testing as expected.

@dmsnell dmsnell merged commit 5238751 into master Aug 15, 2018
@matticbot matticbot removed the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Aug 15, 2018
@dmsnell dmsnell deleted the sdk/shuffle-runner-config branch August 15, 2018 13:51
@@ -260,7 +292,7 @@ function getWebpackConfig() {
},
} ),
] ),
externals: [ 'electron' ],
externals: _.compact( [ externalizeWordPressPackages && wordpressExternals, 'electron' ] ),
Copy link
Contributor

Choose a reason for hiding this comment

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

...baseConfig.externals,
...getWordPressExternals(),
lodash: 'lodash',
wp: 'wp',
Copy link
Member

Choose a reason for hiding this comment

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

Seems like we forgot to account for externalizing wp - see #26725 for a fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants