diff --git a/README.md b/README.md index 85a1c2f..43ffb9c 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ pairing with smart people at Hashrocket. For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186). -_1231 TILs and counting..._ +_1232 TILs and counting..._ --- @@ -432,6 +432,7 @@ _1231 TILs and counting..._ - [Object Initialization With Shorthand Property Names](javascript/object-initialization-with-shorthand-property-names.md) - [Obtain Undefined Value With The Void Operator](javascript/obtain-undefined-value-with-the-void-operator.md) - [Parse A Date From A Timestamp](javascript/parse-a-date-from-a-timestamp.md) +- [Pre And Post Hooks For Yarn Scripts](javascript/pre-and-post-hooks-for-yarn-scripts.md) - [Purge Null And Undefined Values From Object](javascript/purge-null-and-undefined-values-from-object.md) - [Random Cannot Be Seeded](javascript/random-cannot-be-seeded.md) - [Reach Into An Object For Nested Data With Get](javascript/reach-into-an-object-for-nested-data-with-get.md) diff --git a/javascript/pre-and-post-hooks-for-yarn-scripts.md b/javascript/pre-and-post-hooks-for-yarn-scripts.md new file mode 100644 index 0000000..e2850af --- /dev/null +++ b/javascript/pre-and-post-hooks-for-yarn-scripts.md @@ -0,0 +1,28 @@ +# Pre And Post Hooks For Yarn Scripts + +In [yarn](https://classic.yarnpkg.com/) v1, there is a special syntax for +script names that allows you to define pre and post hooks. + +For instance, if you have a `build` script, you can define a `prebuild` and/or +a `postbuild` script as well. Then, anytime you invoke `yarn build`, the +`prebuild` script will be automatically run before `build` and the `postbuild` +script be automatically run after `build`. + +This `pre{script}` and `post{script}` syntax works for any script. + +```json +{ + "scripts": { + "predeploy": "node pre-deploy-steps" + "deploy": "my-framework deploy", + "postdeploy": "node post-deploy-steps" + } +} +``` + +This syntax may lead to unexpected script invocations. For instance, a +`preserve` script will run ahead of a `serve` script even though those were +probably intended to be unrelated scripts. This is, in part, why this syntax is +no longer support in yarn v2. + +[source](https://classic.yarnpkg.com/lang/en/docs/cli/run/#toc-yarn-run-script)