text: (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[59650],{22122:function(e,n,t){"use strict";function r(){return(r=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])}return e}).apply(this,arguments)}t.d(n,{Z:function(){return r}})},17375:function(e,n,t){"use strict";function r(e,n){if(null==e)return{};var t,r,a=function(e,n){if(null==e)return{};var t,r,a={},i=Object.keys(e);for(r=0;r<i.length;r++)t=i[r],n.indexOf(t)>=0||(a[t]=e[t]);return a}(e,n);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(r=0;r<i.length;r++)t=i[r],n.indexOf(t)>=0||Object.prototype.propertyIsEnumerable.call(e,t)&&(a[t]=e[t])}return a}t.d(n,{Z:function(){return r}})},3905:function(e,n,t){"use strict";t.d(n,{Zo:function(){return c},kt:function(){return m}});var r=t(67294);function a(e,n,t){return n in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function i(e,n){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);n&&(r=r.filter((function(n){return Object.getOwnPropertyDescriptor(e,n).enumerable}))),t.push.apply(t,r)}return t}function o(e){for(var n=1;n<arguments.length;n++){var t=null!=arguments[n]?arguments[n]:{};n%2?i(Object(t),!0).forEach((function(n){a(e,n,t[n])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):i(Object(t)).forEach((function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))}))}return e}function l(e,n){if(null==e)return{};var t,r,a=function(e,n){if(null==e)return{};var t,r,a={},i=Object.keys(e);for(r=0;r<i.length;r++)t=i[r],n.indexOf(t)>=0||(a[t]=e[t]);return a}(e,n);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(r=0;r<i.length;r++)t=i[r],n.indexOf(t)>=0||Object.prototype.propertyIsEnumerable.call(e,t)&&(a[t]=e[t])}return a}var p=r.createContext({}),s=function(e){var n=r.useContext(p),t=n;return e&&(t="function"===typeof e?e(n):o(o({},n),e)),t},c=function(e){var n=s(e.components);return r.createElement(p.Provider,{value:n},e.children)},u={inlineCode:"code",wrapper:function(e){var n=e.children;return r.createElement(r.Fragment,{},n)}},d=r.forwardRef((function(e,n){var t=e.components,a=e.mdxType,i=e.originalType,p=e.parentName,c=l(e,["components","mdxType","originalType","parentName"]),d=s(t),m=a,k=d["".concat(p,".").concat(m)]||d[m]||u[m]||i;return t?r.createElement(k,o(o({ref:n},c),{},{components:t})):r.createElement(k,o({ref:n},c))}));function m(e,n){var t=arguments,a=n&&n.mdxType;if("string"===typeof e||a){var i=t.length,o=new Array(i);o[0]=d;var l={};for(var p in n)hasOwnProperty.call(n,p)&&(l[p]=n[p]);l.originalType=e,l.mdxType="string"===typeof e?e:a,o[1]=l;for(var s=2;s<i;s++)o[s]=t[s];return r.createElement.apply(null,o)}return r.createElement.apply(null,t)}d.displayName="MDXCreateElement"},96086:function(e){"use strict";var n=Object.assign.bind(Object);e.exports=n,e.exports.default=e.exports},31711:function(e,n,t){"use strict";t.r(n),t.d(n,{default:function(){return p}});var r=t(22122),a=t(17375),i=t(67294),o=t(3905),l=(i.createElement,{});function p(e){var n=e.components,t=(0,a.Z)(e,["components"]);return(0,o.kt)("wrapper",(0,r.Z)({},l,t,{components:n,mdxType:"MDXLayout"}),(0,o.kt)("h1",{id:"pinned-dependencies"},"Pinned Dependencies"),(0,o.kt)("p",null,(0,o.kt)("strong",{parentName:"p"},"Since 8.4")),(0,o.kt)("p",null,"Usually we'd recommend to use ReScript in a single-codebase style by using one ",(0,o.kt)("inlineCode",{parentName:"p"},"bsconfig.json")," file for your whole codebase."),(0,o.kt)("p",null,"There are scenarios where you still want to connect and build multiple independent ReScript packages for one main project though (",(0,o.kt)("inlineCode",{parentName:"p"},"yarn workspaces"),'-like "monorepos"). This is where ',(0,o.kt)("inlineCode",{parentName:"p"},"pinned-dependencies")," come into play."),(0,o.kt)("h2",{id:"package-types"},"Package Types"),(0,o.kt)("p",null,"Before we go into detail, let's first explain all the different package types recognized by the build system:"),(0,o.kt)("ul",null,(0,o.kt)("li",{parentName:"ul"},"Toplevel (this is usually the final app you are building, which has dependencies to other packages)"),(0,o.kt)("li",{parentName:"ul"},"Pinned dependencies (these are your local packages that should always rebuild when you build your toplevel, those should be listed in ",(0,o.kt)("inlineCode",{parentName:"li"},"bs-dependencies")," and ",(0,o.kt)("inlineCode",{parentName:"li"},"pinned-dependencies"),")"),(0,o.kt)("li",{parentName:"ul"},"Normal dependencies (these are packages that are consumed from npm and listed via ",(0,o.kt)("inlineCode",{parentName:"li"},"bs-dependencies"),")")),(0,o.kt)("p",null,"Whenever a package is being built (",(0,o.kt)("inlineCode",{parentName:"p"},"bsb -make-world"),"), the build system will build the toplevel package with its pinned-dependencies. So any changes made in a pinned dependency will automatically be reflected in the final app."),(0,o.kt)("h2",{id:"build-system-package-rules"},"Build System Package Rules"),(0,o.kt)("p",null,"The build system respects the following rules for each package type:"),(0,o.kt)("p",null,(0,o.kt)("strong",{parentName:"p"},"Toplevel")),(0,o.kt)("ul",null,(0,o.kt)("li",{parentName:"ul"},"Warnings reported"),(0,o.kt)("li",{parentName:"ul"},"Warn-error respected"),(0,o.kt)("li",{parentName:"ul"},"Builds dev dependencies"),(0,o.kt)("li",{parentName:"ul"},"Builds pinned dependencies"),(0,o.kt)("li",{parentName:"ul"},"Runs custom rules"),(0,o.kt)("li",{parentName:"ul"},"Package-specs like ES6/CommonJS overrides all its dependencies")),(0,o.kt)("p",null,(0,o.kt)("strong",{parentName:"p"},"Pinned dependencies")),(0,o.kt)("ul",null,(0,o.kt)("li",{parentName:"ul"},"Warnings reported"),(0,o.kt)("li",{parentName:"ul"},"Warn-error respected"),(0,o.kt)("li",{parentName:"ul"},"Ignores pinned dependencies"),(0,o.kt)("li",{parentName:"ul"},"Builds dev dependencies"),(0,o.kt)("li",{parentName:"ul"},"Runs custom rules")),(0,o.kt)("p",null,(0,o.kt)("strong",{parentName:"p"},"Normal dependencies")),(0,o.kt)("ul",null,(0,o.kt)("li",{parentName:"ul"},"Warnings, warn-error ignored"),(0,o.kt)("li",{parentName:"ul"},"Ignores dev directories"),(0,o.kt)("li",{parentName:"ul"},"Ignores pinned dependencies"),(0,o.kt)("li",{parentName:"ul"},"Ignores custom generator rules")),(0,o.kt)("p",null,"So with that knowledge in mind, let's dive into some more concrete examples to see our pinned dependencies in action."),(0,o.kt)("h2",{id:"examples"},"Examples"),(0,o.kt)("h3",{id:"yarn-workspaces"},"Yarn workspaces"),(0,o.kt)("p",null,"Let's assume we have a codebase like this:"),(0,o.kt)("pre",null,(0,o.kt)("code",(0,r.Z)({parentName:"pre"},{}),"myproject/\n  app/\n   - src/App.res\n   - bsconfig.json\n  common/\n   - src/Header.res\n   - bsconfig.json\n  myplugin/\n   - src/MyPlugin.res\n   - bsconfig.json\n  package.json\n")),(0,o.kt)("p",null,"Our ",(0,o.kt)("inlineCode",{parentName:"p"},"package.json")," file within our codebase root would look like this:"),(0,o.kt)("pre",null,(0,o.kt)("code",(0,r.Z)({parentName:"pre"},{className:"language-json"}),'{\n  "name": "myproject",\n  "private": true,\n  "workspaces": {\n    "packages": [\n      "app",\n      "common",\n      "myplugin"\n    ]\n  }\n}\n')),(0,o.kt)("p",null,"Our ",(0,o.kt)("inlineCode",{parentName:"p"},"app")," folder would be our toplevel package, consuming our ",(0,o.kt)("inlineCode",{parentName:"p"},"common")," and ",(0,o.kt)("inlineCode",{parentName:"p"},"myplugin")," packages as ",(0,o.kt)("inlineCode",{parentName:"p"},"pinned-dependencies"),". The configuration for ",(0,o.kt)("inlineCode",{parentName:"p"},"app/bsconfig.json")," looks like this:"),(0,o.kt)("pre",null,(0,o.kt)("code",(0,r.Z)({parentName:"pre"},{className:"language-json"}),'{\n  "name": "app",\n  "version": "1.0.0",\n  "sources": {\n    "dir" : "src",\n    "subdirs" : true\n  },\n  /* ... */\n  "bs-dependencies": [\n    "common",\n    "myplugin"\n  ],\n  "pinned-dependencies": ["common", "myplugin"],\n  /* ... */\n}\n')),(0,o.kt)("p",null,"Now, whenever we are running ",(0,o.kt)("inlineCode",{parentName:"p"},"npx bsb -make-world")," within our ",(0,o.kt)("inlineCode",{parentName:"p"},"app")," package, the compiler would always rebuild any changes within its pinned dependencies as well."),(0,o.kt)("p",null,(0,o.kt)("strong",{parentName:"p"},"Important:")," ReScript will not rebuild any ",(0,o.kt)("inlineCode",{parentName:"p"},"pinned-dependencies")," in watch mode! This is due to the complexity of file watching, so you'd need to set up your own file-watcher process that runs ",(0,o.kt)("inlineCode",{parentName:"p"},"bsb -make-world")," on specific file changes. E.g. you could use ",(0,o.kt)("a",(0,r.Z)({parentName:"p"},{href:"https://facebook.github.io/watchman/docs/watchman-make.html"}),(0,o.kt)("inlineCode",{parentName:"a"},"watchman-make"))," to automatically run the build task when a file in ",(0,o.kt)("inlineCode",{parentName:"p"},"common")," or ",(0,o.kt)("inlineCode",{parentName:"p"},"myplugin")," has been changed."))}p.isMDXComponent=!0,p.frontmatter={title:"Pinned Dependencies",metaTitle:"Pinned Dependencies",description:"Handling multiple packages within one ReScript project with pinned dependencies",canonical:"/docs/manual/latest/build-pinned-dependencies",__ghEditHref:"https://github.com/reason-association/rescript-lang.org/blob/master/pages/docs/manual/v9.0.0/build-pinned-dependencies.mdx"}},11653:function(e,n,t){(window.__NEXT_P=window.__NEXT_P||[]).push(["/docs/manual/v9.0.0/build-pinned-dependencies",function(){return t(31711)}])}},function(e){e.O(0,[49774],(function(){return n=11653,e(e.s=n);var n}));var n=e.O();_N_E=n}]);