LibraryManager icon indicating copy to clipboard operation
LibraryManager copied to clipboard

Discussion: Library destination root

Open justcla opened this issue 7 years ago • 6 comments

We are considering introducing a property in the libman.json for "destinationRoot" (name to be decided). The path specified here would be prefixed to any relative destination defined for a library.

For example:

{
  "version": "1.0",
  "defaultProvider": "cdnjs",
  "destinationRoot": "/wwwroot/lib",
  "libraries": [
    {
      "library": "[email protected]",
      "destination": "jquery"
    }
  ]
}

In the case above, the jquery library would be downloaded to "/wwwroot/lib/jquery".

If not specified, the default/implied destinationRoot would be the project root ("/"). (This is the current behavior today.)

If a library specifies a path beginning with a forward slash ("/"), destinationRoot will be ignore for that library.

Please comment. Is this a design that would work for you? Would this be your preferred approach to defining library destinations? Or are you happy to specify the full destination path for each library you're pulling down?

Does the "defaultDestination" property suit your needs better? ie. Are you more likely to place all your library files in the same directory? Or is the defaultDestination useless to you as you'd always want to put each library in a separate directory? (ie. to avoid potential conflicts, or for cleaner management of 3rd party libraries)

Should we combine the defaultDestination with destinationRoot into a single property that becomes both

  • the destination prefix for libraries that define a destination without a slash ("/"), and
  • the default destination for libraries that don't define a specific destination ?

Alternatively (and separately), should we consider using the library's name combined with defaultDestination/destinationRoot as the destination folder if no "destination" is defined for a specific library.

So, in this example, the jquery library files would go into the "/wwwroot/lib/jquery" directory.

{
  "version": "1.0",
  "defaultProvider": "cdnjs",
  "defaultDestination": "/wwwroot/lib",
  "libraries": [
    {
      "library": "[email protected]",
    }
  ]
}

justcla avatar Apr 26 '18 22:04 justcla

I like defaultDestination, and the use of the library name if nothing else is provided. This is pretty much what we used to have with PackMan and worked great.

acinep avatar Apr 27 '18 00:04 acinep

Thanks for the input @acinep .

But should defaultDestination be used as a prefix to the destination of the library (whether provided explicitly or defaulted to the library name)?

{
  "version": "1.0",
  "defaultProvider": "cdnjs",
  "defaultDestination": "/wwwroot/lib",
  "libraries": [
    {
      "library": "[email protected]",
    },
    {
      "library": "[email protected]",
      "destination": "otherlibs",
    },
    {
      "library": "[email protected]",
      "destination": "/foobar",
    }
  ]
}

Question 1: In the example above, which folder would the "barlib" files go to? a - "/otherlibs" (current behavior) b - "/wwwroot/lib/otherlibs" (defaultDestination prefixed to explicitly set relative destination)

(separately) Question 2: Which folder would the "foolib" files go to? a - "/wwwroot/lib" (current behavior) b - "/foolib" (default to library name) c - "/wwwroot/lib/foolib" (defaultDestination prefixed to default library name)

Question 3: Which folder would the "foobar" files go to? (Note the destination start with "/") a - "/foobar" (current behavior) b - "/wwwroot/bin/foobar" (defaultDestination prefixed to explicitly set root path)

justcla avatar Apr 30 '18 19:04 justcla

Or should we introduce a new property for the destination prefix?

justcla avatar Apr 30 '18 19:04 justcla

If defaultDestination is prefixed in both cases, question 1 & 2 above, then you wouldn't be able to dump a file directly lib folder such as /wwwroot/lib/coollib.js. I suppose you could specify destination as /wwwroot/lib.

I guess developers either want their libraries in library subfolders or they don't. Maybe a property could be added such as "useLibraryFolders"? Then you could set it to the true or false and get the behavior you like best.

mattfraley1 avatar May 08 '18 13:05 mattfraley1

Thanks @mattfraley1. Yes, the design is that a forward slash ("/") at the beginning of the destination would indicate that the destination is relative to the root of the project. ie. "/scripts" would send files to the [root]/scripts, but "scripts" would send files to [defaultDestinationFolder]/scripts.'

Thanks for the suggestion about "useLibraryFolders". We will consider that!

justcla avatar May 09 '18 23:05 justcla

@justcla I expected it to work like this, but unfortunately, it's not implemented yet.

Question 1: B Question 2: A Question 3: A

The useLibraryFolders would be nice, you should be able to override this behavior by setting the destination in the library setting.

Example:

{
  "version": "1.0",
  "defaultProvider": "unpkg",
  "defaultDestination": "Assets/Libraries/",
  "useLibraryFolders": true,
  "libraries": [
    {
      "library": "[email protected]",
      "destination": "jquery-custom" // Assets/Libraries/jquery-custom/ (custom library folder)
    },
    {
      "library": "[email protected]"  // Assets/Libraries/bootstrap/
    },
    {
      "library": "[email protected]",
      "destination": "" // Assets/Libraries/coollib.js (overrides useLibraryFolders)
    },
    {
      "library": "[email protected]",
      "destination": "/foobar" // foobar (overrides root defaultDestination)
    }
  ]
}

This will give you full flexibility.

lgoudriaan avatar Aug 23 '19 12:08 lgoudriaan