Tdarr_Plugins icon indicating copy to clipboard operation
Tdarr_Plugins copied to clipboard

QUESTION Using module.exports.dependencies in a flow

Open tws101 opened this issue 10 months ago • 1 comments

QUESTION What is the command to install a dependency when processing it from a flow plugin?

I am new to writing flows and I have noticed that the command

module.exports.dependencies = ['@cospired/i18n-iso-languages'];

does not install @cospired/i18n-iso-languages which I get an error when initializing with var languages = require("@cospired/i18n-iso-languages");

A classic plugin will install this with this command module.exports.dependencies = ['@cospired/i18n-iso-languages'];

but a flow is not doing so

This was hard to detect as on tdarr reboots a flow using this would fail BUT once a classic plugin that called this it installs and the flow starts working....

can the above bolded question be answered so I can fix the code in my flow

Below are two use case examples that will fail after a reboot with only flows running

Example code block

const languages = require('@cospired/i18n-iso-languages');
const result2 = (languages.getAlpha2Code(nativeLang, 'en'));
const result3 = (languages.alpha2ToAlpha3B(result2));

Second example code block

const languages = require('/app/Tdarr_Node/assets/app/plugins/node_modules/@cospired/i18n-iso-languages');
const result2 = (languages.getAlpha2Code(nativeLang, 'en'));
const result3 = (languages.alpha2ToAlpha3B(result2));

tws101 avatar Mar 30 '24 15:03 tws101

I have managed this work around

image

If anyone knows the proper method to do this please let me know

tws101 avatar Apr 10 '24 20:04 tws101

Yes that's one way to do it although you shouldn't need to specify the full path when requiring the dependency. This should work const languages = require('@cospired/i18n-iso-languages'); as NodeJS automatically traverses up the directory tree until it finds a node_modules folder with @cospired/i18n-iso-languages in.

In terms of installing dependencies in flow plugins, I didn't implement the previous way as from what I can remember the npm module (https://www.npmjs.com/package/npm) dropped support for installing other dependencies from within js files so args.installClassicPluginDeps uses an older version which should be fine for now.

HaveAGitGat avatar Jun 01 '24 06:06 HaveAGitGat