mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
include the @gristlabs/grist-widget package, so Calendar is always available (#745)
The Calendar feature was implemented as a custom widget. To make it available offline, we prepare a package that includes it, and add that to Grist. The PluginManager is configured to find it. An optional `GRIST_SKIP_BUNDLED_WIDGETS` flag is added to disable widgets bundled this way from being used. This may be needed by the tests in grist-widget to avoid getting an echo :-)
This commit is contained in:
@@ -1998,8 +1998,13 @@ export class FlexServer implements GristServer {
|
||||
// Only used as {userRoot}/plugins as a place for plugins in addition to {appRoot}/plugins
|
||||
const userRoot = path.resolve(process.env.GRIST_USER_ROOT || getAppPathTo(this.appRoot, '.grist'));
|
||||
this.info.push(['userRoot', userRoot]);
|
||||
|
||||
const pluginManager = new PluginManager(this.appRoot, userRoot);
|
||||
// Some custom widgets may be included as an npm package called @gristlabs/grist-widget.
|
||||
const bundledRoot = isAffirmative(process.env.GRIST_SKIP_BUNDLED_WIDGETS) ? undefined : path.join(
|
||||
getAppPathTo(this.appRoot, 'node_modules'),
|
||||
'@gristlabs', 'grist-widget', 'dist'
|
||||
);
|
||||
this.info.push(['bundledRoot', bundledRoot]);
|
||||
const pluginManager = new PluginManager(this.appRoot, userRoot, bundledRoot);
|
||||
// `initialize()` is asynchronous and reads plugins manifests; if PluginManager is used before it
|
||||
// finishes, it will act as if there are no plugins.
|
||||
// ^ I think this comment was here to justify calling initialize without waiting for
|
||||
|
||||
@@ -46,7 +46,8 @@ function servePluginContent(req: express.Request, res: express.Response,
|
||||
req.get('X-From-Plugin-WebView') === "true" ||
|
||||
mimeTypes.lookup(path.extname(pluginPath)) === "application/javascript") {
|
||||
const dirs = pluginManager.dirs();
|
||||
const contentRoot = pluginKind === "installed" ? dirs.installed : dirs.builtIn;
|
||||
const contentRoot = pluginKind === "installed" ? dirs.installed :
|
||||
(pluginKind === "builtIn" ? dirs.builtIn : dirs.bundled);
|
||||
// Note that pluginPath may not be safe, but `sendFile` with the "root" option restricts
|
||||
// relative paths to be within the root folder (see the 3rd party library unit-test:
|
||||
// https://github.com/pillarjs/send/blob/3daa901cf731b86187e4449fa2c52f971e0b3dbc/test/send.js#L1363)
|
||||
|
||||
@@ -14,9 +14,14 @@ export interface PluginDirectories {
|
||||
*/
|
||||
readonly builtIn?: string;
|
||||
/**
|
||||
* Directory where user installed plugins are localted.
|
||||
* Directory where user installed plugins are located.
|
||||
*/
|
||||
readonly installed?: string;
|
||||
/**
|
||||
* Yet another option, for plugins that are included
|
||||
* during a build but not part of the codebase itself.
|
||||
*/
|
||||
readonly bundled?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -44,10 +49,12 @@ export class PluginManager {
|
||||
* @param {string} userRoot: path to user's grist directory; `null` is allowed, to only uses built in plugins.
|
||||
*
|
||||
*/
|
||||
public constructor(public appRoot?: string, userRoot?: string) {
|
||||
public constructor(public appRoot?: string, userRoot?: string,
|
||||
public bundledRoot?: string) {
|
||||
this._dirs = {
|
||||
installed: userRoot ? path.join(userRoot, 'plugins') : undefined,
|
||||
builtIn: appRoot ? getAppPathTo(appRoot, 'plugins') : undefined
|
||||
builtIn: appRoot ? getAppPathTo(appRoot, 'plugins') : undefined,
|
||||
bundled: bundledRoot ? getAppPathTo(bundledRoot, 'plugins') : undefined,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -91,6 +98,11 @@ export class PluginManager {
|
||||
this._entries.push(...await scanDirectory(this._dirs.builtIn, "builtIn"));
|
||||
}
|
||||
|
||||
// Load bundled plugins
|
||||
if (this._dirs.bundled) {
|
||||
this._entries.push(...await scanDirectory(this._dirs.bundled, "bundled"));
|
||||
}
|
||||
|
||||
if (!process.env.GRIST_EXPERIMENTAL_PLUGINS ||
|
||||
process.env.GRIST_EXPERIMENTAL_PLUGINS === '0') {
|
||||
// Remove experimental plugins
|
||||
@@ -130,7 +142,7 @@ export class PluginManager {
|
||||
}
|
||||
|
||||
|
||||
async function scanDirectory(dir: string, kind: "installed"|"builtIn"): Promise<DirectoryScanEntry[]> {
|
||||
async function scanDirectory(dir: string, kind: "installed"|"builtIn"|"bundled"): Promise<DirectoryScanEntry[]> {
|
||||
const plugins: DirectoryScanEntry[] = [];
|
||||
let listDir;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user