External js library for a widget plugin on node-->where should it go?

60 views
Skip to first unread message

stefano franchi

unread,
Feb 5, 2019, 11:56:27 PM2/5/19
to TiddlyWikiDev
Well, I thought I had finally sorted out how how to structure a demo site for developing  a new widget plugin on tiddlywiki/node, but I have one more problem:
Making tiddlywiki see the external library I need.

I have a local TW/Node site like this:

TW-Demo
    +------------plugins
                      +--------myPlugin
                                      +------------myPlugin.js
                                            +
                                             |
                                            +-----------files
                                                            +------myExtLibrary.js



How do I refer to myExtLIbrary.js within myPlugin.js? I tried the following:

var extLib = require("$:/plugins/myPlugin/files/myExtLibrary.js");

var extLib = require("$:/plugins/myPlugin/myExtLibrary.js");

var extLib = require("$:/myExtLibrary.js");

var extLib = require("$:files/myExtLibrary.js");

(I am clueless, obviously)

Everytime I get a "Cannot find module" error. I would immensely grateful to anyone kind enough to explain to me the semantics of the expression in the require statement. How is the path computed? Is it relative to the tiddliwiki module? That seems to implied by the standard use of a statement like:

var  Widget = require("$:/core/modules/widgets/widget.js").widget;

But that can't be true, otherwise no local installation would ever use a plugin...
There's gotta be some magic somewhere that escapes me.


Cheers,
Stefano



Matthew Lauber

unread,
Feb 6, 2019, 9:48:17 AM2/6/19
to TiddlyWikiDev
Have you given the external library a title?  

Not exactly sure what your use case is, but if you look at my tiddly-calc plugin, you can see that at the start of math.js I tell tiddlywiki what the title, type, and module-type of this file is.  This lets tiddlywiki add it to the tiddler store where it can then be referenced by require.  You can look at line 15 of calc.js to see how I do that.

Matt Lauber

stefano franchi

unread,
Feb 6, 2019, 2:54:38 PM2/6/19
to tiddly...@googlegroups.com
On Wed, Feb 6, 2019 at 8:48 AM Matthew Lauber <ma...@mklauber.com> wrote:
Have you given the external library a title?  

Not exactly sure what your use case is, but if you look at my tiddly-calc plugin, you can see that at the start of math.js I tell tiddlywiki what the title, type, and module-type of this file is.  This lets tiddlywiki add it to the tiddler store where it can then be referenced by require.  You can look at line 15 of calc.js to see how I do that.


Hi Matt,

thanks for the tip. I hadn't added a title and module-type to the library (in fact, I would rather not touch it, if possible), but doing so does not change the outcome. I still get a module not found error.


Cheers,

Stefano
--
__________________________________________________
Stefano Franchi

stefano...@gmail.com
http://stefano.cleinias.org

Brian Theado

unread,
Feb 7, 2019, 8:49:33 AM2/7/19
to tiddly...@googlegroups.com
Stefano,

On Wed, Feb 6, 2019 at 2:54 PM stefano franchi <stefano...@gmail.com> wrote:
 
thanks for the tip. I hadn't added a title and module-type to the library (in fact, I would rather not touch it, if possible), but doing so does not change the outcome. I still get a module not found error.

To avoid changing the .js file, you can have a tiddlywiki.files which adds title and module-type for you. See  https://github.com/Jermolene/TiddlyWiki5/tree/master/plugins/tiddlywiki/railroad/files

If your require is failing, it likely means the tiddler containing your javascript library is not being loaded. So as a first step, I recommend doing an advanced search for your library tiddler to verify it is in fact present in the wiki.

Brian

stefano franchi

unread,
Feb 7, 2019, 10:28:46 AM2/7/19
to tiddly...@googlegroups.com
On Thu, Feb 7, 2019 at 7:49 AM Brian Theado <brian....@gmail.com> wrote:
Stefano,

On Wed, Feb 6, 2019 at 2:54 PM stefano franchi <stefano...@gmail.com> wrote:
 
thanks for the tip. I hadn't added a title and module-type to the library (in fact, I would rather not touch it, if possible), but doing so does not change the outcome. I still get a module not found error.

To avoid changing the .js file, you can have a tiddlywiki.files which adds title and module-type for you. See  https://github.com/Jermolene/TiddlyWiki5/tree/master/plugins/tiddlywiki/railroad/files

Ah, that finally worked! Great, thank you.
I would be grateful if you could explain what the last section of the file tiddlywiki.files means:


{
"prefix": "(function(document) {\n",
"suffix": "\n})($tw.node ? $tw.fakeDocument : window.document)\n"
}

That's quite cryptic to me, but it it is obviously needed, as the file won't work if removed (I tried....).
 
If your require is failing, it likely means the tiddler containing your javascript library is not being loaded. So as a first step, I recommend doing an advanced search for your library tiddler to verify it is in fact present in the wiki.

Well, tiddlywiki wouldn't boot when it could not find the module, so my options were quite limited in that regard. But I'll keep it in mind for future ref.
 

Thanks again,

Stefano

Reply all
Reply to author
Forward
0 new messages