Development Conventions
A Paperlib extension is essentially an npm package. Therefore, the development of a Paperlib extension is similar to the development of an npm package. However, there are some restrictions. This section will explain the restrictions and conventions:
- In the callback of the event listener, please avoid
floating promise. That is, if your callback function contains anyAsyncFunction, please be sure toawaitor.catchthe error exception. Because the error in thefloating promisecannot be caught in Paperlib, it will cause the extension to crash. - The extension must be able to be packaged as an
npmpackage that conforms to thecommonjsspecification. - The extension must be able to be packaged as a single
jsfile, and it is recommended tominifyto reduce the download size. (Except forNew Windowextensions) - Use the appropriate tools to remove the
importstatements ofPLAPI, PLMainAPI, PLExtAPI, and keep the usage statements ofPLAPI, PLMainAPI, PLExtAPIin the code after packaging. This ensures the normal operation of the extension in Paperlib. In our provided development environment, we use therollup-extension-modifyextension to achieve this. The reason for this constraint is that thePLAPI, PLMainAPI, PLExtAPIprovided by thepaperlib-api/apipackage are only used for code type autocompletion during development, do not contain any functionality, and should not appear in the final code of a extension. After a extension is loaded, thePLAPI, PLMainAPI, PLExtAPIobjects will be automatically globally injected into itsVMfor directly using. - The
manifest_versionfield must be included inpackage.jsonto indicate the API version used by the extension. Please keep it consistent with the version of thepaperlib-apipackage you actually installed. We recommend that you always use the latest API version. - The
mainfield must be included inpackage.json, pointing to the entry file of the extension. - The keywords in
package.jsonmust containpaperlibso that it can be searched in the extension marketplace. - The
namefield inpackage.jsonmust be consistent with theidfield in the main code of the extension. - The
versionfield inpackage.jsonmust comply with thesemverspecification. - The
descriptionfield inpackage.jsonmust contain a brief description of the extension. - The
authorfield inpackage.jsonmust contain the author information of the extension. - The
dependenciesfield inpackage.jsondoes not contain dependencies. That is, all dependencies aredevDependencies. Please package the related functions in the dependencies into the.jsfile of the extension through any bundling tool. - It is recommended to correctly set the
filesfield inpackage.jsonto only include the release files. - It is highly recommended to use the
homepagefield inpackage.jsonto provide the official website of the extension for users to learn more about the extension and feedback.