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 toawait
or.catch
the error exception. Because the error in thefloating promise
cannot be caught in Paperlib, it will cause the extension to crash. - The extension must be able to be packaged as an
npm
package that conforms to thecommonjs
specification. - The extension must be able to be packaged as a single
js
file, and it is recommended tominify
to reduce the download size. (Except forNew Window
extensions) - Use the appropriate tools to remove the
import
statements ofPLAPI, PLMainAPI, PLExtAPI
, and keep the usage statements ofPLAPI, PLMainAPI, PLExtAPI
in the code after packaging. This ensures the normal operation of the extension in Paperlib. In our provided development environment, we use therollup-extension-modify
extension to achieve this. The reason for this constraint is that thePLAPI, PLMainAPI, PLExtAPI
provided by thepaperlib-api/api
package 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, PLExtAPI
objects will be automatically globally injected into itsVM
for directly using. - The
manifest_version
field must be included inpackage.json
to indicate the API version used by the extension. Please keep it consistent with the version of thepaperlib-api
package you actually installed. We recommend that you always use the latest API version. - The
main
field must be included inpackage.json
, pointing to the entry file of the extension. - The keywords in
package.json
must containpaperlib
so that it can be searched in the extension marketplace. - The
name
field inpackage.json
must be consistent with theid
field in the main code of the extension. - The
version
field inpackage.json
must comply with thesemver
specification. - The
description
field inpackage.json
must contain a brief description of the extension. - The
author
field inpackage.json
must contain the author information of the extension. - The
dependencies
field inpackage.json
does not contain dependencies. That is, all dependencies aredevDependencies
. Please package the related functions in the dependencies into the.js
file of the extension through any bundling tool. - It is recommended to correctly set the
files
field inpackage.json
to only include the release files. - It is highly recommended to use the
homepage
field inpackage.json
to provide the official website of the extension for users to learn more about the extension and feedback.