Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 90 additions & 28 deletions boot/boot.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions boot/bootprefix.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion core-server/commands/makelibrary.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Command.prototype.execute = function() {
title: upgradeLibraryTitle,
type: "application/json",
"plugin-type": "library",
"text": JSON.stringify({tiddlers: tiddlers})
"text": $tw.utils.stringifyDataTiddler("application/json",{tiddlers: tiddlers})
};
wiki.addTiddler(new $tw.Tiddler(pluginFields));
return null;
Expand Down
2 changes: 1 addition & 1 deletion core-server/commands/savelibrarytiddlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ Command.prototype.execute = function() {
$tw.utils.createFileDirectories(pathname);
fs.writeFileSync(pathname,JSON.stringify(tiddler),"utf8");
// Collect the skinny list data
var pluginTiddlers = $tw.utils.parseJSONSafe(tiddler.text),
var pluginTiddlers = $tw.utils.parseDataTiddler(tiddler.type,tiddler.text),
readmeContent = (pluginTiddlers.tiddlers[title + "/readme"] || {}).text,
doesRequireReload = !!self.commander.wiki.doesPluginInfoRequireReload(pluginTiddlers),
iconTiddler = pluginTiddlers.tiddlers[title + "/icon"] || {},
Expand Down
43 changes: 20 additions & 23 deletions core-server/commands/savewikifolder.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,29 +101,25 @@ WikiFolderMaker.prototype.save = function() {
if(self.tiddlersToIgnore.indexOf(title) !== -1) {
// Ignore the core plugin and the ephemeral info plugin
self.log("Ignoring tiddler: " + title);
} else {
var type = tiddler.fields.type,
pluginType = tiddler.fields["plugin-type"];
if(type === "application/json" && pluginType) {
// Plugin tiddler
var libraryDetails = self.findPluginInLibrary(title);
if(libraryDetails) {
// A plugin from the core library
self.log("Adding built-in plugin: " + libraryDetails.name);
newWikiInfo[libraryDetails.type] = newWikiInfo[libraryDetails.type] || [];
$tw.utils.pushTop(newWikiInfo[libraryDetails.type],libraryDetails.name);
} else if(self.explodePlugins !== "no") {
// A custom plugin
self.log("Processing custom plugin: " + title);
self.saveCustomPlugin(tiddler);
} else if(self.explodePlugins === "no") {
self.log("Processing custom plugin to tiddlders folder: " + title);
self.saveTiddler("tiddlers", tiddler);
}
} else {
// Ordinary tiddler
self.saveTiddler("tiddlers",tiddler);
} else if(tiddler.isPlugin()) {
// Plugin tiddler
var libraryDetails = self.findPluginInLibrary(title);
if(libraryDetails) {
// A plugin from the core library
self.log("Adding built-in plugin: " + libraryDetails.name);
newWikiInfo[libraryDetails.type] = newWikiInfo[libraryDetails.type] || [];
$tw.utils.pushTop(newWikiInfo[libraryDetails.type],libraryDetails.name);
} else if(self.explodePlugins !== "no") {
// A custom plugin
self.log("Processing custom plugin: " + title);
self.saveCustomPlugin(tiddler);
} else if(self.explodePlugins === "no") {
self.log("Processing custom plugin to tiddlders folder: " + title);
self.saveTiddler("tiddlers", tiddler);
}
} else {
// Ordinary tiddler
self.saveTiddler("tiddlers",tiddler);
}
}
});
Expand Down Expand Up @@ -164,6 +160,7 @@ WikiFolderMaker.prototype.findPluginInLibrary = function(title) {
};

WikiFolderMaker.prototype.saveCustomPlugin = function(pluginTiddler) {
if(!pluginTiddler.isPlugin()) throw new Error("Tiddler is not a valid plugin");
var self = this,
pluginTitle = pluginTiddler.fields.title,
titleParts = pluginTitle.split("/"),
Expand All @@ -173,7 +170,7 @@ WikiFolderMaker.prototype.saveCustomPlugin = function(pluginTiddler) {
pluginInfo = pluginTiddler.getFieldStrings({exclude: ["text","type"]});
this.saveJSONFile(directory + path.sep + "plugin.info",pluginInfo);
self.log("Writing " + directory + path.sep + "plugin.info: " + JSON.stringify(pluginInfo,null,$tw.config.preferences.jsonSpaces));
var pluginTiddlers = $tw.utils.parseJSONSafe(pluginTiddler.fields.text).tiddlers; // A hashmap of tiddlers in the plugin
var pluginTiddlers = $tw.utils.parseDataTiddler(pluginTiddler.fields.type, pluginTiddler.fields.text).tiddlers;
$tw.utils.each(pluginTiddlers,function(tiddler,title) {
if(!tiddler.title) {
tiddler.title = title;
Expand Down
2 changes: 1 addition & 1 deletion core/modules/filters/json-ops.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ exports["jsonset"] = function(source,operator,options) {
value = null;
break;
case "json":
value = $tw.utils.parseJSONSafe(value,function() {return undefined;});
value = $tw.utils.parseJSONSafe(value, () => {});
break;
default:
// Use value unchanged
Expand Down
7 changes: 2 additions & 5 deletions core/modules/pluginswitcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,8 @@ PluginSwitcher.prototype.switchPlugins = function() {
var tiddler = self.wiki.getTiddler(title);
if(tiddler && tiddler.isPlugin() && plugins.indexOf(title) === -1) {
plugins.push(title);
var pluginInfo = $tw.utils.parseJSONSafe(self.wiki.getTiddlerText(title)),
dependents = $tw.utils.parseStringArray(tiddler.fields.dependents || "");
$tw.utils.each(dependents,function(title) {
accumulatePlugin(title);
});
var dependents = $tw.utils.parseStringArray(tiddler.fields.dependents || "");
$tw.utils.each(dependents,title => { accumulatePlugin(title); });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO each should be considered deprecated, it should use forEach instead.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was just tightening up the formatting. It's out of scope for this PR because each could be operating on an object or an array and I'd have to determine which it is before I make that change. So unfortunately I won't be able to do anything with that here. each may be deprecated, but that doesn't mean we're removing it, and it needs to be handled carefully.

}
};
accumulatePlugin(selectedPluginTitle);
Expand Down
1 change: 0 additions & 1 deletion core/modules/startup/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ exports.startup = function() {
if(requiresReload) {
requireReloadDueToPluginChange = true;
} else if(tiddler) {
var pluginType = tiddler.fields["plugin-type"];
if($tw.wiki.getTiddlerText(PREFIX_CONFIG_REGISTER_PLUGIN_TYPE + (tiddler.fields["plugin-type"] || ""),"no") === "yes") {
changesToProcess.push(title);
}
Expand Down
4 changes: 0 additions & 4 deletions core/modules/tiddler.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ exports.hasTag = function(tag) {
return this.fields.tags && this.fields.tags.indexOf(tag) !== -1;
};

exports.isPlugin = function() {
return this.fields.type === "application/json" && this.hasField("plugin-type");
};

exports.isDraft = function() {
return this.hasField("draft.of");
};
Expand Down
13 changes: 11 additions & 2 deletions core/modules/upgraders/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ var BLOCKED_PLUGINS = {
}
};

/**
* Upgrade the specified tiddlers to their latest versions
* @param {import("tiddlywiki").Wiki} wiki The wiki to which the tiddler is being imported
* @param {string[]} titles The titles of the tiddlers to be imported
* @param {Record<string, Record<string, string>>} tiddlers The tiddlers to be imported
* @returns {Object} An object containing messages about the upgrade process
*/
exports.upgrade = function(wiki,titles,tiddlers) {
var self = this,
messages = {},
Expand All @@ -36,9 +43,11 @@ exports.upgrade = function(wiki,titles,tiddlers) {
$tw.utils.each(titles,function(title) {
var incomingTiddler = tiddlers[title];
// Check if we're dealing with a plugin
if(incomingTiddler && incomingTiddler["plugin-type"]) {
if(incomingTiddler && incomingTiddler["plugin-type"] && $tw.utils.isValidDataTiddlerType(incomingTiddler.type)) {
// Check whether the plugin contains JS modules
var requiresReload = wiki.doesPluginInfoRequireReload($tw.utils.parseJSONSafe(incomingTiddler.text)) ? (wiki.getTiddlerText("$:/language/ControlPanel/Plugins/PluginWillRequireReload") + " ") : "";
var requiresReload = wiki.doesPluginInfoRequireReload($tw.utils.parseDataTiddler(incomingTiddler.type, incomingTiddler.text))
? (wiki.getTiddlerText("$:/language/ControlPanel/Plugins/PluginWillRequireReload") + " ")
: "";
messages[title] = requiresReload;
if(incomingTiddler.version) {
// Upgrade the incoming plugin if it is in the upgrade library
Expand Down
7 changes: 5 additions & 2 deletions core/modules/utils/pluginmaker.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ exports.repackPlugin = function(title,additionalTiddlers,excludeTiddlers) {
throw "No such tiddler as " + title;
}
// Extract the JSON
var jsonPluginTiddler = $tw.utils.parseJSONSafe(pluginTiddler.fields.text,null);
var jsonPluginTiddler = $tw.utils.parseDataTiddler(pluginTiddler.fields.type,pluginTiddler.fields.text);
if(!jsonPluginTiddler) {
throw "Cannot parse plugin tiddler " + title + "\n" + $tw.language.getString("Error/Caption") + ": " + e;
}
Expand Down Expand Up @@ -60,7 +60,10 @@ exports.repackPlugin = function(title,additionalTiddlers,excludeTiddlers) {
version += "+" + pluginVersion.build;
}
// Save the tiddler
$tw.wiki.addTiddler(new $tw.Tiddler(pluginTiddler,{text: JSON.stringify({tiddlers: plugins},null,4), version: version}));
$tw.wiki.addTiddler(new $tw.Tiddler(pluginTiddler,{
text: $tw.utils.stringifyDataTiddler(pluginTiddler.fields.type,{tiddlers: plugins}),
version: version
}));
// Delete any non-shadow constituent tiddlers
$tw.utils.each(tiddlers,function(title) {
if($tw.wiki.tiddlerExists(title)) {
Expand Down
Loading