Skip to content

-require local script file vs. npm package  #646

Description

@indus

I'm struggling with -require (again ;-)

I'm having a bunch of scripts that extend mapshaper functionality that I use from time to time. To make it easier to use them on other systems I wanted to put them in a registry so I would be able to load them with npm. I was surprised that this makes quite a difference.

Some of my findings:

  • with a global mapshaper install the my addon scripts also need to be installed globally (thats ok - but I was a bit surprised)
  • With local script files I was able to call the functions without curly braces - with a npm package this is no longer possible as the functions are no longer directly added to the global context but below the package name (or alias).
  • I tried to add them to the global context exporting a function but had no luck (besides it sounds deprecated)
  • the scripts no longer have access to the context via this when called with -run. This gave a lot of flexibility.

There are probably good reasons for those differences between those two types of "-require" but maybe you could give me a hint what the best-practice is to create a plugin-library that combines multiple commands - that is easy to distribute, load and call...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions