Unable to override scripts

Solved Plugin Development
  • Migrating to NodeBB v2 I came across an issue that I cannot resolve. In my theme/plugin I override two scripts because I want to write my own logic for two pages:

    • register
    • email

    I get this error:

    uncaughtException: EEXIST: file already exists, symlink '../../../../node_modules/[PLUGIN/THEME NAME]/lib/client/register.js'

    Any ideas on how to get around this?

  • @baris Instead of overriding the file, you can name the file whatever you want, and use filter:script.load on the client-side to remove the call to the built-in module, and insert your own.

    hooks.on('filter:script.load', (data) => {
      console.log(data.tpl_url, data.scripts);
    });
    
  • Do you want to completely replace the logic on register page? Can you post a sample from your plugin.json?

    I think the suggested way to do this is to use modules section.

  • @baris Instead of overriding the file, you can name the file whatever you want, and use filter:script.load on the client-side to remove the call to the built-in module, and insert your own.

    hooks.on('filter:script.load', (data) => {
      console.log(data.tpl_url, data.scripts);
    });
    
  • magnusvhendinM magnusvhendin has marked this topic as solved on
  • @julian This worked great. I did this in my main client file (like persona.js).

    require(['hooks'], (hooks) => {
    	hooks.on('filter:script.load', (data) => {
    		const replaceMap = {
    			register: {
    				target: 'forum/register',
    				with: 'replacement/register',
    			},
    		};
    
    		const replace = replaceMap[data.tpl_url];
    
    		if (replace) {
    			const index = data.scripts.indexOf(replace.target);
    			if (index > -1) data.scripts[index] = replace.with;
    			else data.scripts.push(replace.with);
    		}
    
    		return data;
    	});
    });
    

    Then I can just add my scripts that I want to replace to the replaceMap object.


Suggested Topics


  • 0 Votes
    18 Posts
    904 Views
  • Cached scripts

    Plugin Development
    1 Votes
    1 Posts
    153 Views
  • 0 Votes
    1 Posts
    153 Views
  • 0 Votes
    5 Posts
    2091 Views
  • 0 Votes
    5 Posts
    1623 Views