-
Notifications
You must be signed in to change notification settings - Fork 216
Mapping
unscriptable edited this page Sep 3, 2011
·
2 revisions
work in progress (actually, this is just notes at this point!)
- Allow devs to place packages and resources wherever they wish
- Allow several use cases or module and package mapping (see below)
- Only download a given module or resource once, regardless of aliases, mappings
- Make it simple to do the easy stuff and possible to do the edge cases
- use case
- "my package is located at this url"
- configuration
- location of lib folder
- location of main js file (if any)
- algorithm
- ./moduleId and ../moduleId are first normalized to parent moduleId:
- parentId/moduleId or grandparentId/moduleId (grandparent may be undefined)
- normalized module ids are mapped to urls via lib location
- urls are canonicalized
- ./moduleId and ../moduleId are first normalized to parent moduleId:
- use case
- "I want all text! plugins to use the module named x/text" (module id)
- configuration
- alias mapping (text --> curl/text)
- algorithm
- matching plugin module ids are translated to alias module ids
- alias module ids are mapped to urls via package location mappings
- urls are canonicalized
- use case
- "I want calls to 'x/a' from one package to reference 'x1.5/x/a' but calls to 'x/a' from another package to reference 'x1.6/x/a'"
- configuration
- ? (check out commonjs proposals?)
- algorithm
- ?
- use case
- "I want to alias calls to a generic 'array' module to the module named 'y/array'" (or vice versa. see chat with JD Dalton)
- configuration
- alias/name of fake package (array)
- actual name of module in package (y/array)
- algorithm
- if a request is made for a false package, the actual parent module id is provided in context
- algorithm proceeds as normal Package Location use case
- use case
- "I want to alias calls to 'my/array' to 'y/array'"
- configuration
- alias/name of fake package (array)
- actual name of module in package (y/array)
- algorithm
- if a request is made for an alias package, the actual parent module id is provided in context
- algorithm proceeds as normal Package Location use case
- use case
- "I want to use root paths like in node.js ("/x/b" should be the same as "x/b" unless we implement a way to have each package specify its relative dependency paths)
- configuration
- same as regular packages (except see comment above)
- algorithm
- same as regular packages (except see comment above)
Monkey Patch
- use case
- "I want to fix this module by replacing it on-the-fly with mine"
- configuration
- mapping of original name to patched module name
- algorithm
- if a request is made for he original module, a patched module id is provided in context
- algorithm proceeds as normal Package Location use case
- use case
- "I want to load this resource named x/y from url a/b/c"
- configuration
- mapping of name to url
- algorithm
- ?
mappings: {
// simple package with no main module
// or main module is peer to lib folder of same name
'packageA': 'path/to/packageA',
// package with a main module
'packageB': {
lib: 'path/to/packageB/lib',
main: 'path/to/packageB/main'
},
// package with a versioned dependency
'packageC': {
lib: 'path/to/packageC/lib',
main: 'path/to/packageC/main',
mappings: {
'packageA': 'path/to/packageA-0.7'
}
},
// false package
'array': 'packageA/array',
// aliased package
'my/query': 'packageB/query',
// plugin mapping
'text': 'curl/text',
// monkey patched module
'packageB/model': 'my/model',
//non-module resource
'my/templates': 'some/other/place/templates'
}