Skip to content

Commit 6edb031

Browse files
author
sbellone
authored
Merge pull request #17 from VirtuOz/upgrade_to_node_8.x
Upgrade to node 8.x
2 parents c888d8d + b1ef19f commit 6edb031

File tree

8 files changed

+823
-700
lines changed

8 files changed

+823
-700
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ before_script:
22
- export NPM_PATH=`which npm`
33
language: node_js
44
node_js:
5-
- "0.10"
5+
- "lts/carbon"

README.md

Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,16 @@ The Javascript files in the package may live anywhere, in any directory. You ne
2222
The rule is that you should follow the same rules for a dynamic module as you would for a Node.js library module.
2323

2424
The package.json file must contain the following:
25-
25+
```javascript
2626
{
27-
"main":"<path to main module"
27+
"main":"<path to main module>"
2828
}
29+
```
2930

3031
If you use other Node.js libraries, you must include the standard NPM dependencies blocks. The actual libraries shown
3132
below are for illustrative purposes only; you can put whatever you want in the dependencies section, as long as they
3233
can be accessed by the runtime server when NPM installs the package:
33-
34+
```javascript
3435
{
3536
"main":"./index.js",
3637

@@ -47,6 +48,7 @@ can be accessed by the runtime server when NPM installs the package:
4748
.
4849
}
4950
}
51+
```
5052
5153
5254
The Web Server
@@ -116,7 +118,7 @@ Let's say we have a package that consists of just two files: the _package.json_
116118
it interesting, the package uses Futures. Here are the files in the package:
117119
118120
*package.json*
119-
121+
```javascript
120122
{
121123
"name":"test-dynamic-module",
122124
"version":"0.0.1",
@@ -125,9 +127,10 @@ it interesting, the package uses Futures. Here are the files in the package:
125127
"futures":"2.1.0"
126128
}
127129
}
130+
```
128131
129132
*index.js*
130-
133+
```javascript
131134
var Future = require('futures').future;
132135

133136
module.exports.helloWorld = function()
@@ -140,9 +143,10 @@ it interesting, the package uses Futures. Here are the files in the package:
140143

141144
return future;
142145
};
146+
```
143147
144148
We can call the _helloWorld_ function like this:
145-
149+
```javascript
146150
var moduleResult = dynamicModuleLoader.load('test-dynamic-module');
147151
moduleResult.when(function(err, module)
148152
{
@@ -156,23 +160,25 @@ We can call the _helloWorld_ function like this:
156160
// Do something with the module.
157161
console.log(module.helloWorld());
158162
});
163+
```
159164
160165
Changing Defaults
161166
-----------------
162167
163168
By default the _DynamicModuleLoader_ assumes you will be downloading packages in _tar.gz_ form. You can change the
164169
default like this:
165-
170+
```javascript
166171
var dynamicModuleLoader = new DynamicModuleLoader({ defaultRemoteServerPackageFileExtension: '.zip' });
167172

168173
// Will assume a .zip extension when requesting the package from the web server.
169174
var moduleResult = dynamicModuleLoader.load('test-dynamic-module');
170175
.
171176
.
172177
.
178+
```
173179
174180
You can always override the default by specifying the extension when calling _load_:
175-
181+
```javascript
176182
// By default assume .tar.gz.
177183
var dynamicModuleLoader = new DynamicModuleLoader();
178184

@@ -187,6 +193,13 @@ You can always override the default by specifying the extension when calling _lo
187193
.
188194
.
189195
.
196+
```
197+
198+
And you can regroup the installed modules in subdirectories of `moduleInstallationDir`:
199+
```javascript
200+
// The module will be installed at moduleInstallationDir/demo_modules/
201+
var moduleResult = dynamicModuleLoader.load('test-dynamic-module', undefined, undefined, 'demo_modules');
202+
```
190203
191204
192205
External Dependencies
@@ -207,10 +220,11 @@ Customizing NPM Options
207220
-----------------------
208221
209222
You can customize the NPM options. For example, you can set NPM to perform a verbose install:
210-
223+
```javascript
211224
var dynamicModuleLoader = new DynamicModuleLoader({
212225
npmOptions: ['--production', '--verbose']
213226
});
227+
```
214228
215229
216230
Skipping Installation
@@ -247,31 +261,11 @@ the pre-installed `node_modules/` directory will be copied.
247261
```
248262
249263
250-
Sharing node_modules between modules
251-
------------------------------------
252-
253-
If you plan to load a lot of modules containing often the same dependencies (e.g. deploying regularly new versions
254-
of a module), you can have the dynamic module loader sharing the node_modules instead of reinstalling them each time,
255-
in order to speed up the installation. To do that, load your module with the following arguments:
256-
```javascript
257-
var dynamicModuleLoader = new DynamicModuleLoader();
258-
var moduleResult = dynamicModuleLoader.load('test-dynamic-module', undefined, undefined, nodeModulesInstallDirName);
259-
```
260-
Instead of installing your module in `moduleInstallationDir/moduleName`, this will create an extra directory and your module
261-
will be installed in `moduleInstallationDir/nodeModulesInstallDirName/moduleName`. Then, it will copy the package.json of your
262-
module in `moduleInstallationDir/nodeModulesInstallDirName`, do the `npm install` there, and copy back the `node_modules/` in
263-
the `moduleName` directory.
264-
265-
Next time you install a module in the same `nodeModulesInstallDirName`, if the `package.json` file is the same, it will skip
266-
the `npm install` and directly copy the `node_modules/` in your newly installed module directory.
267-
If the dependencies have changed, it runs again `npm install` before copying the `node_modules/`.
268-
269-
270264
Events
271265
------
272266
273267
_DynamicModuleLoader_ is an event emitter. Here's how to listen for the events it fires:
274-
268+
```javascript
275269
var dynamicModuleLoader = new DynamicModuleLoader();
276270
dynamicModuleLoader.on(dynamicModuleLoader.events.moduleDownloaded, function(moduleName, downloadedFile, next)
277271
{
@@ -316,6 +310,7 @@ _DynamicModuleLoader_ is an event emitter. Here's how to listen for the events
316310

317311
// moduleName - The name of the module loaded.
318312
});
313+
```
319314
320315
Next Function
321316
-------------

0 commit comments

Comments
 (0)