-
Notifications
You must be signed in to change notification settings - Fork 7
How it works (documentation) #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
So if I understand correctly the (P3) requirement is not fulfilled by the algorithm yet? |
Awesome! Needs one or two modifications but thats the overall gist :) I need to sort something out now. But will reply a bit later. Great work though :D |
Sorry that I'm only getting to this now, been a long weekend. I'm just going to say explain the overall approach as if I were explaining it fresh. To start with, we need the following two things:
There are two primary data structures I operate on,
[
{
name: 'react',
version: '15.4.1',
deps: <array like one above (recursive)>
},
...
]
{
name: 'react',
version: '15.4.1',
key: 'react@15.4.1',
location: 'node_modules/react',
config: <package.json file for that package (with extra compatibility info)>
} In the case that there are two locations of a single version of a package, we pick one (I think the last one). This is fine since we control the mapping, and is actually helpful for caching. Almost all functions are transformations of To find packages we take the approach of traversing node_modules (more universal then using a yarn lock). This is performed by At this point, all packages can be located, however, there are some intricacies loading node modules in the browser. To make the packages At this point we have all locations and know how to load the packages, so we just need to format this in a way SystemJS understands, so we build a config object. All top level node_modules (first level in the {
...
paths: {
...
'nm:': 'node_modules/'
},
map: {
...
'react': 'nm:react'
}
} The Now we add package information so that packages can correctly be resolved (only one per version of a package) by making {
...
"packages": {
...
"nm:react": {
"meta": {
"*": {
"globals": {
"process": "process"
}
},
"*.json": {
"format": "json"
},
"dist/react-with-addons.js": {
"cjsRequireDetection": false
},
"dist/react.js": {
"cjsRequireDetection": false
}
},
"main": "react.js",
"format": "cjs"
},
}
} for nested modules it looks like this: {
...
"packages": {
...
"nm:collect-all/node_modules/stream-via": {
...
}
}
} We're almost done, at the moment we only have mappings for top level node_modules. So we traverse the tree, and add mapping entries to all packages that require their own nested node_modules. Using the "nm:collect-all": {
"map": {
"stream-via": "node_modules/collect-all/node_modules/stream-via"
},
...
} The map entry should be fixed (optimized) to map to Finally, we also include mappings for our core node libs (needs work), as follows: {
"map": {
...
"https": "nm:jspm-nodelibs-https",
"module": "nm:jspm-nodelibs-module",
...
"vm": "nm:jspm-nodelibs-vm",
}
Some other hacks are currently hardcoded in for the moment until a more general solution is found. But this is basically how everything works. @jonaskello Well done on your write up, you got 98% of everything. Just wanted to give a full description. |
Uh oh!
There was an error while loading. Please reload this page.
Good work on this package so far!
I have breifly looked through the code and are trying to understand the details of how it works. In doing so I thought I would write my findings down and maybe it could be added to a "How it works" section of the readme in the future. It may also help in discussion of improvements to the algoritm. So here it is, please let me know what I have misunderstood :-).
How it works
SystemJS needs three pieces of information to load a package:
P1. Extended package.json information (eg.
format: cjs
).P2. The URL to the package root.
P3. Map to dependent packages.
systemjs-config-builder
provides the above information for each package by this algoritm:A1. Walk
node_modules
recursively and look forpackage.json
. Build a registry (map) of packages with keyname@version
and value{location}
. The recursive part ensures that packages that has private dependencies in their ownnode_modules
folder are included in the registry.A2. Iterate the registry and call
jspm
to generate the extended package.json information needed (P1). The registry values now have{location, config}
.A3. Loop through the registry and write information to a
generated.config.js
file.A3.1 Output
path
section (P2). This section is hardcoded to this:A3.2 Output
map
section. For each package (1...N) setname
to registry key minus@version
part and output:A3.3 Output
packages
section. For each package (1...N) setname
to registry key minus@version
part, andconfig
from the registry value and output:The text was updated successfully, but these errors were encountered: