-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Conversation
bin/sdk/gutenberg.js
Outdated
|
||
const config = { | ||
return { | ||
...baseConfig, | ||
...{ | ||
context: __rootDir, |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved!
Nice job! The only regression I see is lack of Production:
Development:
That works for me, as long as development is the default. 👍 |
webpack.config.js
Outdated
/** | ||
* Converts @wordpress require into window reference | ||
* | ||
* Note this isn't the same as camelCase becuase of the |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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…
There was a problem hiding this comment.
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 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
space added!
webpack.config.js
Outdated
const wordpressRequire = request => { | ||
const [ , /* @wordpress */ name ] = request.split( '/' ); | ||
|
||
return `wp.${ name.replace( /-([a-z])/, ( match, letter ) => letter.toUpperCase() ) }`; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed!
webpack.config.js
Outdated
* @return {string} global variable reference for import | ||
*/ | ||
const wordpressRequire = request => { | ||
const [ , /* @wordpress */ name ] = request.split( '/' ); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 :(
There was a problem hiding this comment.
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 ), |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
webpack.config.js
Outdated
@@ -163,10 +187,6 @@ function getWebpackConfig( { extensionName = '' } = {}, argv ) { | |||
use: _.compact( [ | |||
MiniCssExtractPlugin.loader, | |||
'css-loader', | |||
extensionName && { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
53217a5
to
a4b01f3
Compare
There was a problem hiding this 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.
@@ -260,7 +292,7 @@ function getWebpackConfig() { | |||
}, | |||
} ), | |||
] ), | |||
externals: [ 'electron' ], | |||
externals: _.compact( [ externalizeWordPressPackages && wordpressExternals, 'electron' ] ), |
There was a problem hiding this comment.
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', |
There was a problem hiding this comment.
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.
When building with the SDK we have a generic runner -
sdk-cli.js
and target-specific options for that runner -
gutenberg.js
. Weinvoke 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/