{"id":4787,"date":"2012-05-07T16:04:10","date_gmt":"2012-05-07T23:04:10","guid":{"rendered":"http:\/\/blog.mozilla.org\/addons\/?p=4787"},"modified":"2012-05-07T16:06:23","modified_gmt":"2012-05-07T23:06:23","slug":"spring-cleaning-changes-to-require-and-self-in-the-sdk","status":"publish","type":"post","link":"https:\/\/blog.mozilla.org\/addons\/2012\/05\/07\/spring-cleaning-changes-to-require-and-self-in-the-sdk\/","title":{"rendered":"Spring cleaning: changes to require and self in the SDK"},"content":{"rendered":"<p>Irakli recently posted a \u2018Spring Cleaning\u2019 todo list ( https:\/\/github.com\/mozilla\/addon-sdk\/wiki\/Spring-cleaning-2012 ) of changes we are proposing to make to the SDK in the next few months. While most of these changes deal with how the SDK is implemented and will not affect the behaviour of the top-level APIs, there are two specific changes that will change how the SDK behaves in specific circumstances.<\/p>\n<h3>Changes to require()<\/h3>\n<p>In the first case, the behaviour of the SDK\u2019s require statement will be greatly simplified to support 3 explicit use cases: loading local modules via relative paths, loading module names from the SDK\u2019s high level APIs, or loading via a dependency&#8217;s explicit path. Not only does this greatly simplify the implementation of the module loader, it will also allow us to make 3rd party module development and sharing much simpler. A nice side effect is that require will work exactly how it does in node.js.<\/p>\n<p>The proposal clarifies the three styles to be used when requiring a module:<\/p>\n<ol>\n<li>Relative path for modules included in the add-on&#8217;s lib directory\n<pre>require('.\/utils\/something')\r\n        require('..\/foo\/bar')<\/pre>\n<\/li>\n<li>Single term for high level SDK dependencies:\n<pre>require('panel')\r\n        require('tabs')<\/pre>\n<\/li>\n<li>Complete require form for external dependencies:\n<pre>require('api-utils\/functional')\r\n        require('io\/fs')\r\n        require('package-name\/module\/path')<\/pre>\n<\/li>\n<\/ol>\n<p>Once this change is made, require will raise warning for any deprecated require usage. Eventually support for older usage patterns for require will be removed.<\/p>\n<p>Why are we doing this? The main goal is to remove ambiguity in how the argument you supply to require is resolved. Currently these patterns are supported, but will be deprecated:<\/p>\n<pre>   require('functional')\r\n   require('fs')\r\n   require('module\/path')<\/pre>\n<p>In particular, the first example ( <code>require('functional')<\/code> ) currently means too many things:<\/p>\n<pre>   require('addon-kit\/functional')\r\n   require('api-utils\/functional')\r\n   require('.\/functional')\r\n   require('io\/functional')\r\n   require('package-name\/functional')<\/pre>\n<p>Changing to this more explicit require form makes us more compatible with other commonjs platforms like nodejs and also makes it distinction between high and low level APIs more obvious. While we will make our best efforts to keep high level APIs (ones that do not have `\/` in require: require(&#8216;panel&#8217;) ) backwards compatible at all times, we may change low level APIs when it makes sense.<\/p>\n<h3>Changes to self.data<\/h3>\n<p>In the second case, we will be changing how the SDK\u2019s self module resolves the location of the data directory, specifically in the case where a statement like self.data.load is called from inside a package that is loaded in as a dependency in an add-on.<\/p>\n<p>With the current implementation this code would try to load files from the package\u2019s own data directory. In the proposed change we would instead load files from the add-ons main data directory.<\/p>\n<p>Now, as far as we can tell this use of files in a package\u2019s data directory is not a wide-spread practice, in fact Irakli could not find a single module on Builder that uses this behaviour. This is a breaking change to the SDK\u2019s apis, however, but we think this particular use case is obscure.<\/p>\n<p>As always, we\u2019d love to hear your feedback on these changes and how they might affect you. We want to make sure we have your input before making changes such as these, and to ensure as much as possible that we do not break your add-ons as we improve the SDK.<br \/>\nI&#8217;ve also posted this info to the google user gorup for Jetpack, and we would appreciate we centralize discussion <a href=\"https:\/\/groups.google.com\/d\/msg\/mozilla-labs-jetpack\/YKYnYt9Yyfs\/N-kE-1_1UosJ\" target=\"_blank\">in that thread<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Irakli recently posted a \u2018Spring Cleaning\u2019 todo list ( https:\/\/github.com\/mozilla\/addon-sdk\/wiki\/Spring-cleaning-2012 ) of changes we are proposing to make to the SDK in the next few months. While most of these &hellip; <a class=\"go\" href=\"https:\/\/blog.mozilla.org\/addons\/2012\/05\/07\/spring-cleaning-changes-to-require-and-self-in-the-sdk\/\">Read more<\/a><\/p>\n","protected":false},"author":316,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7117,388,44,588,742],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Spring cleaning: changes to require and self in the SDK - Mozilla Add-ons Community Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/blog.mozilla.org\/addons\/2012\/05\/07\/spring-cleaning-changes-to-require-and-self-in-the-sdk\/\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Jeff Griffiths\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/blog.mozilla.org\/addons\/2012\/05\/07\/spring-cleaning-changes-to-require-and-self-in-the-sdk\/\",\"url\":\"https:\/\/blog.mozilla.org\/addons\/2012\/05\/07\/spring-cleaning-changes-to-require-and-self-in-the-sdk\/\",\"name\":\"Spring cleaning: changes to require and self in the SDK - Mozilla Add-ons Community Blog\",\"isPartOf\":{\"@id\":\"https:\/\/blog.mozilla.org\/addons\/#website\"},\"datePublished\":\"2012-05-07T23:04:10+00:00\",\"dateModified\":\"2012-05-07T23:06:23+00:00\",\"author\":{\"@id\":\"https:\/\/blog.mozilla.org\/addons\/#\/schema\/person\/e2f4c71eb45392ea29162432c3f1d433\"},\"breadcrumb\":{\"@id\":\"https:\/\/blog.mozilla.org\/addons\/2012\/05\/07\/spring-cleaning-changes-to-require-and-self-in-the-sdk\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/blog.mozilla.org\/addons\/2012\/05\/07\/spring-cleaning-changes-to-require-and-self-in-the-sdk\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/blog.mozilla.org\/addons\/2012\/05\/07\/spring-cleaning-changes-to-require-and-self-in-the-sdk\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/blog.mozilla.org\/addons\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Spring cleaning: changes to require and self in the SDK\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/blog.mozilla.org\/addons\/#website\",\"url\":\"https:\/\/blog.mozilla.org\/addons\/\",\"name\":\"Mozilla Add-ons Community Blog\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/blog.mozilla.org\/addons\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/blog.mozilla.org\/addons\/#\/schema\/person\/e2f4c71eb45392ea29162432c3f1d433\",\"name\":\"Jeff Griffiths\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/blog.mozilla.org\/addons\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/b07ae75dd1a5414bf30d7f773ccfc894?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/b07ae75dd1a5414bf30d7f773ccfc894?s=96&d=mm&r=g\",\"caption\":\"Jeff Griffiths\"},\"description\":\"Jeff is Product Manager for the Firefox Developer Tools and occasional Open Web hacker, based in Vancouver, BC.\",\"sameAs\":[\"http:\/\/canuckistani.ca\/\",\"https:\/\/x.com\/canuckistani\"],\"url\":\"https:\/\/blog.mozilla.org\/addons\/author\/jgriffithsmozilla-com\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Spring cleaning: changes to require and self in the SDK - Mozilla Add-ons Community Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/blog.mozilla.org\/addons\/2012\/05\/07\/spring-cleaning-changes-to-require-and-self-in-the-sdk\/","twitter_misc":{"Written by":"Jeff Griffiths","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/blog.mozilla.org\/addons\/2012\/05\/07\/spring-cleaning-changes-to-require-and-self-in-the-sdk\/","url":"https:\/\/blog.mozilla.org\/addons\/2012\/05\/07\/spring-cleaning-changes-to-require-and-self-in-the-sdk\/","name":"Spring cleaning: changes to require and self in the SDK - Mozilla Add-ons Community Blog","isPartOf":{"@id":"https:\/\/blog.mozilla.org\/addons\/#website"},"datePublished":"2012-05-07T23:04:10+00:00","dateModified":"2012-05-07T23:06:23+00:00","author":{"@id":"https:\/\/blog.mozilla.org\/addons\/#\/schema\/person\/e2f4c71eb45392ea29162432c3f1d433"},"breadcrumb":{"@id":"https:\/\/blog.mozilla.org\/addons\/2012\/05\/07\/spring-cleaning-changes-to-require-and-self-in-the-sdk\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/blog.mozilla.org\/addons\/2012\/05\/07\/spring-cleaning-changes-to-require-and-self-in-the-sdk\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/blog.mozilla.org\/addons\/2012\/05\/07\/spring-cleaning-changes-to-require-and-self-in-the-sdk\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/blog.mozilla.org\/addons\/"},{"@type":"ListItem","position":2,"name":"Spring cleaning: changes to require and self in the SDK"}]},{"@type":"WebSite","@id":"https:\/\/blog.mozilla.org\/addons\/#website","url":"https:\/\/blog.mozilla.org\/addons\/","name":"Mozilla Add-ons Community Blog","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/blog.mozilla.org\/addons\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/blog.mozilla.org\/addons\/#\/schema\/person\/e2f4c71eb45392ea29162432c3f1d433","name":"Jeff Griffiths","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/blog.mozilla.org\/addons\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/b07ae75dd1a5414bf30d7f773ccfc894?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/b07ae75dd1a5414bf30d7f773ccfc894?s=96&d=mm&r=g","caption":"Jeff Griffiths"},"description":"Jeff is Product Manager for the Firefox Developer Tools and occasional Open Web hacker, based in Vancouver, BC.","sameAs":["http:\/\/canuckistani.ca\/","https:\/\/x.com\/canuckistani"],"url":"https:\/\/blog.mozilla.org\/addons\/author\/jgriffithsmozilla-com\/"}]}},"_links":{"self":[{"href":"https:\/\/blog.mozilla.org\/addons\/wp-json\/wp\/v2\/posts\/4787"}],"collection":[{"href":"https:\/\/blog.mozilla.org\/addons\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.mozilla.org\/addons\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.mozilla.org\/addons\/wp-json\/wp\/v2\/users\/316"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.mozilla.org\/addons\/wp-json\/wp\/v2\/comments?post=4787"}],"version-history":[{"count":0,"href":"https:\/\/blog.mozilla.org\/addons\/wp-json\/wp\/v2\/posts\/4787\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.mozilla.org\/addons\/wp-json\/wp\/v2\/media?parent=4787"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.mozilla.org\/addons\/wp-json\/wp\/v2\/categories?post=4787"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.mozilla.org\/addons\/wp-json\/wp\/v2\/tags?post=4787"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}