aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/mozilla/add-ons/sdk/tools/package_json/index.html
diff options
context:
space:
mode:
Diffstat (limited to 'files/zh-cn/mozilla/add-ons/sdk/tools/package_json/index.html')
-rw-r--r--files/zh-cn/mozilla/add-ons/sdk/tools/package_json/index.html312
1 files changed, 312 insertions, 0 deletions
diff --git a/files/zh-cn/mozilla/add-ons/sdk/tools/package_json/index.html b/files/zh-cn/mozilla/add-ons/sdk/tools/package_json/index.html
new file mode 100644
index 0000000000..cd08ff2b64
--- /dev/null
+++ b/files/zh-cn/mozilla/add-ons/sdk/tools/package_json/index.html
@@ -0,0 +1,312 @@
+---
+title: package.json
+slug: Mozilla/Add-ons/SDK/Tools/package_json
+translation_of: Archive/Add-ons/Add-on_SDK/Tools/package_json
+---
+<p>{{AddonSidebar}}</p>
+
+<p><span class="seoSummary">The <code>package.json</code> file contains manifest data for your add-on, providing not only descriptive information about the add-on for presentation in the Add-ons Manager, but other metadata required of add-ons.</span></p>
+
+<p>一些条目, 比如<a href="/en-US/Add-ons/SDK/Tools/package_json#icon"><code>icon</code></a>, <a href="/en-US/Add-ons/SDK/Tools/package_json#name"><code>name</code></a>和<a href="/en-US/Add-ons/SDK/Tools/package_json#description"><code>description</code></a>, 有类似<a href="https://developer.mozilla.org/en-US/docs/Install_Manifests">install manifest</a>的格式, 并且<code>package.json会写入</code>install manifest, 当使用<a href="/en-US/Add-ons/SDK/Tools/jpm#jpm_xpi"><code>jpm xpi</code></a><code>的时候.</code></p>
+
+<p>Others, such as <a href="/en-US/Add-ons/SDK/Tools/package_json#lib"><code>lib</code></a>, <a href="/en-US/Add-ons/SDK/Tools/package_json#permissions"><code>permissions</code></a>, and <a href="/en-US/Add-ons/SDK/Tools/package_json#preferences"><code>preferences</code></a>, represent instructions to the <a href="/en-US/Add-ons/SDK/Tools/jpm">jpm</a> tool itself to generate and include particular code and data structures in your add-on.</p>
+
+<p>其他如<a href="/en-US/Add-ons/SDK/Tools/package_json#lib"><code>lib</code></a>, <a href="/en-US/Add-ons/SDK/Tools/package_json#permissions"><code>permissions</code></a>和<a href="/en-US/Add-ons/SDK/Tools/package_json#preferences"><code>preferences</code></a>表示使用<a href="/en-US/Add-ons/SDK/Tools/jpm">jpm</a>工具的步骤, 生成你扩展包含的特殊代码和数据结构.</p>
+
+<h2 id="创建manifest">创建manifest</h2>
+
+<p><code>package.json起初是通过运行</code><a href="/en-US/Add-ons/SDK/Tools/jpm#jpm_init"><code>jpm init</code></a>生成的<code>,通常在扩展的根目录.比如下面(假设扩展目录是</code>"my-addon"<code>)</code></p>
+
+<pre class="brush: json">{
+ "name": "my-addon",
+ "title": "my-addon",
+  "id": "jid1-1FERGV45e4f4f",
+ "description": "a basic add-on",
+ "author": "",
+ "license": "MPL-2.0",
+ "version": "0.1"
+}</pre>
+
+<p>如果你使用新的<a href="/en-US/Add-ons/SDK/Tools/jpm">jpm tool</a>话,可以方便的从package.json获取manifest数据, 通过require其他模块的方式:</p>
+
+<pre class="brush: js" id="comment_text_1">var title = require("./package.json").title;</pre>
+
+<h2 id="Key_reference">Key reference</h2>
+
+<p><code>package.json</code> may contain the following keys:</p>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <td id="author"><code>author</code></td>
+ <td>
+ <p>The name of the package's original author; this could be the name of a person or a company. Defaults to an empty string. It may include a optional URL in parentheses and an email address in angle brackets.</p>
+
+ <p>This value will be used as the add-on's <a href="https://developer.mozilla.org/en-US/docs/Install_Manifests#creator"><code>em:creator</code></a> element in the <code>install.rdf</code> file generated by <code>cfx</code>.</p>
+
+ <div class="note"><strong>Note:</strong> <a href="https://developer.mozilla.org/Add-ons/SDK/Tools/jpm">jpm</a> supports <a href="https://docs.npmjs.com/files/package.json#people-fields-author-contributors">NodeJS people fields</a>.</div>
+ </td>
+ </tr>
+ <tr>
+ <td id="contributors"><code>contributors</code></td>
+ <td>
+ <p>An array of additional <a href="/en-US/Add-ons/SDK/Tools/package_json#author"><code>author</code></a> strings, identifying other contributors to the add-on.</p>
+
+ <p>These values will be used as the add-on's <a href="https://developer.mozilla.org/en-US/docs/Install_Manifests#contributor"><code>em:contributor</code></a> elements in its <code>install.rdf</code>.</p>
+
+ <div class="note"><strong>Note:</strong> This is deprecated along with <code>cfx</code>; it's not available when using <a href="/en-US/Add-ons/SDK/Tools/jpm">jpm</a>.</div>
+ </td>
+ </tr>
+ <tr>
+ <td id="dependencies"><code>dependencies</code></td>
+ <td>
+ <p>A string or an array of strings specifying the names of packages that this add-on requires in order to function properly.</p>
+ </td>
+ </tr>
+ <tr>
+ <td id="description"><code>description</code></td>
+ <td>
+ <p>The add-on's description; this is a human-readable message describing what the add-on does. This defaults to the text "a basic add-on".</p>
+
+ <p>This value will be used as the add-on's <a href="https://developer.mozilla.org/en-US/docs/Install_Manifests#description"><code>em:description</code></a> element in its <code>install.rdf</code>.</p>
+ </td>
+ </tr>
+ <tr>
+ <td id="engines"><code>engines</code></td>
+ <td>
+ <p>Object with supported applications (key) and required version numbers (value).</p>
+
+ <ul>
+ <li><code>firefox</code>: Firefox Desktop</li>
+ <li><code>fennec</code>: Firefox for Android</li>
+ </ul>
+
+ <p>Example:</p>
+
+ <pre>
+<code> "engines": {
+ "firefox": "&gt;=38.0a1",
+ "fennec": "&gt;=38.0a1"
+ }</code></pre>
+ </td>
+ </tr>
+ <tr>
+ <td id="fullName"><code>fullName</code> {{deprecated_inline}}</td>
+ <td>
+ <div class="note"><strong>Note:</strong> This is deprecated along with <code>cfx</code>; it's not available when using <a href="/en-US/Add-ons/SDK/Tools/jpm">jpm</a>.</div>
+
+ <p>The full name of the package. It can contain spaces.</p>
+
+ <p>If this key is present its value will be used as the add-on's <a href="https://developer.mozilla.org/en-US/docs/Install_Manifests#name"><code>em:name</code></a> element in its <code>install.rdf</code>.</p>
+ </td>
+ </tr>
+ <tr>
+ <td id="harnessClassID"><code>harnessClassID</code> {{deprecated_inline}}</td>
+ <td>
+ <div class="note"><strong>Note:</strong> This is deprecated along with <code>cfx</code>; it's not available when using <a href="/en-US/Add-ons/SDK/Tools/jpm">jpm</a>.</div>
+
+ <p>String in the <a href="https://developer.mozilla.org/en-US/docs/Generating_GUIDs">GUID format</a>.</p>
+
+ <p>This is used as a <a href="https://developer.mozilla.org/en-US/docs/Creating_XPCOM_Components/An_Overview_of_XPCOM#CID"><code>classID</code></a> of the "harness service" XPCOM component. Defaults to a random GUID generated by <code>cfx</code>.</p>
+ </td>
+ </tr>
+ <tr>
+ <td id="homepage"><code>homepage</code></td>
+ <td>
+ <p>The URL of the add-on's website.</p>
+
+ <p>This value will be used as the add-on's <a href="https://developer.mozilla.org/en-US/docs/Install_Manifests#homepageURL"><code>em:homepageURL</code></a> element in its <code>install.rdf</code>.</p>
+ </td>
+ </tr>
+ <tr>
+ <td id="icon"><code>icon</code></td>
+ <td>
+ <p>The path to an image file containing the icon for the add-on. Defaults to <code>icon.png</code>. If no icon is specified, the standard add-on icon will be used by default.</p>
+
+ <div class="warning">
+ <p>When using <a href="/en-US/Add-ons/SDK/Tools/jpm">jpm</a>, relative path to the data directory (to make it re-usable for add-on HTML content) does not currently work. Instead you have to use following syntax:</p>
+
+ <p>resource://ID/data/icon-name.png</p>
+
+ <p>ID is the value from the <code>id </code>field. If it does <strong>not</strong> begin with the <code>@</code>-character, then <code>@</code> has to be escaped as <code>-at-</code> and <code>.</code> as <code>-dot-</code>. If the ID is a GUID, the curly braces used in the <code>id</code> field are <strong>not</strong> included.</p>
+ </div>
+
+ <p>This value will be used as the add-on's <a href="https://developer.mozilla.org/en-US/docs/Install_Manifests#iconURL"><code>em:iconURL</code></a> element in its <code>install.rdf</code>.</p>
+
+ <p>The icon may be up to 48x48 pixels in size (although a bigger icon is tolerated here too)</p>
+ </td>
+ </tr>
+ <tr>
+ <td id="icon64"><code>icon64</code> {{deprecated_inline}}</td>
+ <td>
+ <div class="note">
+ <p><strong>Note:</strong> This is deprecated along with <code>cfx</code>; it's not available when using <a href="/en-US/Add-ons/SDK/Tools/jpm">jpm</a>.</p>
+ </div>
+
+ <p><span style="background-color: rgba(212, 221, 228, 0.14902);">The path to an image</span> containing the large icon for the add-on. Defaults to <code>icon64.png</code>. If you don't provide an icon here, the same icon as specified by <code>icon</code> will be used.</p>
+
+ <p>This value will be used as the add-on's <a href="https://developer.mozilla.org/en-US/docs/Install_Manifests#icon64URL"><code>em:icon64URL</code></a> element in its <code>install.rdf</code>.</p>
+
+ <p>The icon may be up to 64x64 pixels in size.</p>
+ </td>
+ </tr>
+ <tr>
+ <td id="id"><code>id</code></td>
+ <td>
+ <p>A globally unique identifier for the add-on.</p>
+
+ <p>This value will be used as the add-on's <a href="https://developer.mozilla.org/en-US/docs/Install_Manifests#id"><code>em:id</code></a> element in its <code>install.rdf</code>.</p>
+
+ <p>See the <a href="/en-US/Add-ons/SDK/Guides/Program_ID">Program ID documentation</a>.</p>
+ </td>
+ </tr>
+ <tr>
+ <td><code>lib</code></td>
+ <td>
+ <p>String representing the top-level module directory provided in this add-on. Defaults to "lib".</p>
+
+ <div class="note">
+ <p><strong>Note:</strong> This is deprecated along with <code>cfx</code> and is not available when using <a href="/en-US/Add-ons/SDK/Tools/jpm">jpm</a>.</p>
+ </div>
+ </td>
+ </tr>
+ <tr>
+ <td id="license"><code>license</code></td>
+ <td>
+ <p>The name of the license under which the add-on is distributed, with an optional URL in parentheses. Defaults to <code>"MPL-2.0"</code>.</p>
+
+ <div class="note">
+ <p><strong>Note</strong>: It is recommend that you use an <a href="https://spdx.org/licenses/">SPDX license ID</a>.</p>
+ </div>
+ </td>
+ </tr>
+ <tr>
+ <td id="main"><code>main</code></td>
+ <td>
+ <p>A string representing the name of a program module that is located in one of the top-level module directories specified by <a href="/en-US/Add-ons/SDK/Tools/package_json#lib"><code>lib</code></a>. Defaults to <code>"main"</code>.</p>
+ </td>
+ </tr>
+ <tr>
+ <td id="name"><code>name</code></td>
+ <td>
+ <p>The add-on's name. This name cannot contain spaces or periods, and defaults to the name of the parent directory.</p>
+
+ <p>When the add-on is built as an XPI, if the <a href="/en-US/Add-ons/SDK/Tools/package_json#fullName"><code>fullName</code></a> and <a href="/en-US/Add-ons/SDK/Tools/package_json#title"><code>title</code></a> keys are not present, <code>name</code> is used as the add-on's <a href="https://developer.mozilla.org/en-US/docs/Install_Manifests#name"><code>em:name</code></a> element in its <code>install.rdf</code>.</p>
+ </td>
+ </tr>
+ <tr>
+ <td id="packages"><code>packages</code></td>
+ <td>
+ <div class="note">
+ <p><strong>Note:</strong> This is deprecated along with <code>cfx</code> and is not available when using <a href="/en-US/Add-ons/SDK/Tools/jpm">jpm</a>.</p>
+ </div>
+
+ <p>A string pointing to a directory containing additional packages. Defaults to <code>"packages"</code>.</p>
+ </td>
+ </tr>
+ <tr>
+ <td id="permissions"><code>permissions</code></td>
+ <td>
+ <p>A set of permissions that the add-on needs.</p>
+
+ <p><strong><code>private-browsing</code></strong>: a boolean indicating whether or not the add-on supports private browsing. If this value is not <code>true</code> or is omitted, then the add-on will not see any private windows or objects, such as tabs, that are associated with private windows. See the documentation for the <a href="/en-US/Add-ons/SDK/High-Level_APIs/private-browsing"><code>private-browsing</code> module</a>.</p>
+
+ <p><strong><code>cross-domain-content</code></strong>: a list of domains for which content scripts are given cross-domain privileges to access content in iframes or to make XMLHTTPRequests. See the documentation for <a href="/en-US/Add-ons/SDK/Guides/Content_Scripts/Cross_Domain_Content_Scripts">enabling cross-domain content scripts</a>.</p>
+
+ <p><strong><code>multiprocess</code></strong>: a Boolean value declaring whether this add-on is, or is not, compatible with <a href="/en-US/Add-ons/Working_with_multiprocess_Firefox">multiprocess Firefox</a>.</p>
+
+ <div class="note">
+ <p><strong>Note</strong> the <code>multiprocess</code> permission is not supported by <a href="/en-US/Add-ons/SDK/Tools/cfx">cfx</a>.</p>
+ </div>
+ </td>
+ </tr>
+ <tr>
+ <td id="preferences"><code>preferences</code></td>
+ <td>
+ <p>An array of <a href="/en-US/docs/Glossary/JSON">JSON</a> objects that use the following keys: <code>name</code>,<code>type</code>, <code>value</code>, <code>title</code>, and <code>description</code>. These JSON objects will be used to create a preferences interface for the add-on in the Add-ons Manager.</p>
+
+ <p>See the documentation for the <a href="/en-US/Add-ons/SDK/High-Level_APIs/simple-prefs"><code>simple-prefs</code> module</a>.</p>
+ </td>
+ </tr>
+ <tr>
+ <td id="preferences-branch"><code>preferences-branch</code></td>
+ <td>Use this to specify an alternative branch for your add-on's simple-prefs. See <a href="/en-US/Add-ons/SDK/High-Level_APIs/simple-prefs#Simple-prefs_in_the_preferences_system">"Simple-prefs in the preferences system"</a> for more details.</td>
+ </tr>
+ <tr>
+ <td id="title"><code>title</code></td>
+ <td>
+ <p>The human-readable title of the package; this can contain spaces.</p>
+
+ <p>If this key is present its value will be used as the add-on's <a href="https://developer.mozilla.org/en-US/docs/Install_Manifests#name"><code>em:name</code></a> element in its <code>install.rdf</code>.</p>
+ </td>
+ </tr>
+ <tr>
+ <td id="translators"><code>translators</code></td>
+ <td>
+ <p>An array of strings listing the people who contributed to the localization of this add-on.</p>
+
+ <p>These values will be used as the add-on's <a href="https://developer.mozilla.org/en-US/docs/Install_Manifests#translator"><code>em:translator</code></a> elements in its <code>install.rdf</code>.</p>
+
+ <div class="note"><strong>Note:</strong> <a href="https://developer.mozilla.org/Add-ons/SDK/Tools/jpm">jpm</a> supports <a href="https://docs.npmjs.com/files/package.json#people-fields-author-contributors">NodeJS people fields</a>.</div>
+ </td>
+ </tr>
+ <tr>
+ <td id="unpack"><code>unpack</code></td>
+ <td>
+ <p>Same as the <code><a href="/en-US/Add-ons/Install_Manifests#unpack">unpack</a></code> in an <code>install.rdf</code> file.</p>
+
+ <p>Useful when the extension contains binaries.</p>
+ </td>
+ </tr>
+ <tr>
+ <td id="updateKey"><code>updateKey</code></td>
+ <td>
+ <p>Same as the <code><a href="/en-US/Add-ons/Install_Manifests#updateKey">updateKey</a></code> in an <code>install.rdf</code> file.</p>
+
+ <p>See <a href="/en-US/Add-ons/SDK/Tools/jpm#Supporting_updates_for_self-hosted_add-ons">Supporting updates for self-hosted add-ons</a>.</p>
+
+ <div class="note">
+ <p><strong>Note:</strong> This key is only available with <a href="/en-US/Add-ons/SDK/Tools/jpm">jpm</a>.</p>
+ </div>
+ </td>
+ </tr>
+ <tr>
+ <td id="updateLink"><code>updateLink</code></td>
+ <td>
+ <p>Same as the <code><a href="/en-US/docs/Extension_Versioning%2C_Update_and_Compatibility#Securing_Updates">updateLink</a></code> for an <code>update.rdf</code> file. Previously was <code><a href="/en-US/Add-ons/SDK/Tools/cfx#updateURL_and_updateLink">--update-link in cfx</a></code>.</p>
+
+ <p>See <a href="/en-US/Add-ons/SDK/Tools/jpm#Supporting_updates_for_self-hosted_add-ons">Supporting updates for self-hosted add-ons</a>.</p>
+
+ <div class="note">
+ <p><strong>Note:</strong> This key is only available with <a href="/en-US/Add-ons/SDK/Tools/jpm">jpm</a>.</p>
+ </div>
+ </td>
+ </tr>
+ <tr>
+ <td id="updateURL"><code>updateURL</code></td>
+ <td>
+ <p>Same as the <code><a href="/en-US/Add-ons/Install_Manifests#updateURL">updateURL</a></code> for an <code>install.rdf</code> file.</p>
+
+ <p>See <a href="/en-US/Add-ons/SDK/Tools/jpm#Supporting_updates_for_self-hosted_add-ons">Supporting updates for self-hosted add-ons</a>.</p>
+
+ <div class="note">
+ <p><strong>Note:</strong> This key is only available with <a href="/en-US/Add-ons/SDK/Tools/jpm">jpm</a>.</p>
+ </div>
+ </td>
+ </tr>
+ <tr>
+ <td id="version"><code>version</code></td>
+ <td>
+ <p>String representing the version of the add-on. Defaults to "0.0.1".</p>
+
+ <p>This value is used as the add-on's <a href="https://developer.mozilla.org/en-US/docs/Install_Manifests#version"><code>em:version</code></a> element in its <code>install.rdf</code>.</p>
+
+ <div class="note">
+ <p><strong>Note:</strong> For <a href="/en-US/Add-ons/SDK/Tools/jpm">jpm</a> the version must be a valid <a href="http://semver.org/">semver</a>.</p>
+ </div>
+ </td>
+ </tr>
+ </tbody>
+</table>
+
+<p> </p>