@paciolan/remote-module-loader 2.5.3 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.browserslistrc +4 -0
- package/README.md +30 -22
- package/dist/index.d.ts +2 -0
- package/dist/index.js +13 -20
- package/dist/index.js.map +1 -1
- package/dist/lib/createRequires.d.ts +8 -0
- package/dist/lib/createRequires.js +7 -14
- package/dist/lib/createRequires.js.map +1 -1
- package/dist/lib/loadRemoteModule.d.ts +12 -0
- package/dist/lib/loadRemoteModule.js +19 -37
- package/dist/lib/loadRemoteModule.js.map +1 -1
- package/dist/lib/memoize.d.ts +8 -0
- package/dist/lib/memoize.js +10 -18
- package/dist/lib/memoize.js.map +1 -1
- package/dist/lib/nodeFetcher.d.ts +6 -0
- package/dist/lib/nodeFetcher.js +43 -51
- package/dist/lib/nodeFetcher.js.map +1 -1
- package/dist/lib/status.d.ts +2 -0
- package/dist/lib/{xmlHttpRequestFetcher/status.js → status.js} +5 -10
- package/dist/lib/status.js.map +1 -0
- package/dist/lib/xmlHttpRequestFetcher/index.d.ts +3 -0
- package/dist/lib/xmlHttpRequestFetcher/index.js +17 -25
- package/dist/lib/xmlHttpRequestFetcher/index.js.map +1 -1
- package/dist/lib/xmlHttpRequestFetcher/readyState.d.ts +3 -0
- package/dist/lib/xmlHttpRequestFetcher/readyState.js +4 -13
- package/dist/lib/xmlHttpRequestFetcher/readyState.js.map +1 -1
- package/dist/models/index.d.ts +3 -0
- package/dist/models/index.js +3 -0
- package/dist/models/index.js.map +1 -0
- package/package.json +25 -19
- package/tsconfig.json +22 -0
- package/dist/lib/xmlHttpRequestFetcher/status.js.map +0 -1
package/.browserslistrc
ADDED
package/README.md
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
# Remote Module Loader 
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Loads a CommonJS module from a remote URL for the Browser or Node.js.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+

|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
## Use Cases
|
|
8
8
|
|
|
9
9
|
Lazy Load Modules to keep initial load times down and load modules just in time, similar to Webpack's code splitting.
|
|
10
10
|
|
|
11
11
|
Update Remote Modules independent of the web application. Update a module without redeploying the web application.
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
## Install
|
|
14
14
|
|
|
15
15
|
```bash
|
|
16
16
|
npm install @paciolan/remote-module-loader
|
|
17
17
|
```
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
## createLoadRemoteModule
|
|
20
20
|
|
|
21
21
|
The `createLoadRemoteModule` function is used to inject dependencies into a `loadRemoteModule` function.
|
|
22
22
|
|
|
23
23
|
It is recommended to create a separate file, in this example it is called `src/lib/loadRemoteModule.js`.
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
### Simple Example
|
|
26
26
|
|
|
27
27
|
If your module has no external dependencies, this is the easiest method to fetch the remote module.
|
|
28
28
|
|
|
@@ -36,7 +36,7 @@ import createLoadRemoteModule from "@paciolan/remote-module-loader";
|
|
|
36
36
|
export default createLoadRemoteModule();
|
|
37
37
|
```
|
|
38
38
|
|
|
39
|
-
|
|
39
|
+
### Require Example
|
|
40
40
|
|
|
41
41
|
You can pass dependencies to the module. All modules loaded with this version of `loadRemoteModule`, will have the dependencies available to `require`.
|
|
42
42
|
|
|
@@ -57,9 +57,11 @@ const requires = createRequires(dependencies);
|
|
|
57
57
|
export default createLoadRemoteModule({ requires });
|
|
58
58
|
```
|
|
59
59
|
|
|
60
|
-
|
|
60
|
+
### Using your own fetcher
|
|
61
|
+
|
|
62
|
+
The default loader can be overridden if you want to use an alternate method.
|
|
61
63
|
|
|
62
|
-
|
|
64
|
+
This example uses `axios` for the fetcher.
|
|
63
65
|
|
|
64
66
|
```javascript
|
|
65
67
|
/**
|
|
@@ -74,11 +76,11 @@ const fetcher = url => axios.get(url).then(request => request.data);
|
|
|
74
76
|
export default createLoadRemoteModule({ fetcher });
|
|
75
77
|
```
|
|
76
78
|
|
|
77
|
-
|
|
79
|
+
## Usage
|
|
78
80
|
|
|
79
81
|
Modules are loaded asynchronously, so use similar techniques to any other async function.
|
|
80
82
|
|
|
81
|
-
|
|
83
|
+
### Promise Style
|
|
82
84
|
|
|
83
85
|
```javascript
|
|
84
86
|
/**
|
|
@@ -115,20 +117,17 @@ const main = async () => {
|
|
|
115
117
|
main();
|
|
116
118
|
```
|
|
117
119
|
|
|
118
|
-
|
|
120
|
+
## Creating a Remote Module
|
|
119
121
|
|
|
120
122
|
Remote Modules must be in the CommonJS format, using `exports` to export functionality.
|
|
121
123
|
|
|
122
124
|
This is an example of a simple CommonJS module:
|
|
123
125
|
|
|
124
126
|
```javascript
|
|
125
|
-
var name = "myModule";
|
|
126
|
-
|
|
127
127
|
function helloWorld() {
|
|
128
128
|
console.log("Hello World!");
|
|
129
129
|
}
|
|
130
130
|
|
|
131
|
-
exports.name = name;
|
|
132
131
|
exports.default = helloWorld;
|
|
133
132
|
```
|
|
134
133
|
|
|
@@ -144,9 +143,9 @@ exports = {
|
|
|
144
143
|
exports.default = "SUCCESS!";
|
|
145
144
|
```
|
|
146
145
|
|
|
147
|
-
|
|
146
|
+
### Webpack
|
|
148
147
|
|
|
149
|
-
|
|
148
|
+
Webpack can be setup to export as CommonJS.
|
|
150
149
|
|
|
151
150
|
Inside `webpack.config.js`, set the `libraryTarget` to `"commonjs"`.
|
|
152
151
|
|
|
@@ -158,9 +157,9 @@ module.exports = {
|
|
|
158
157
|
};
|
|
159
158
|
```
|
|
160
159
|
|
|
161
|
-
Dependencies
|
|
160
|
+
Dependencies should be excluded from the bundle because they will be provided by the Web Application can be added to webpack's `externals` section.
|
|
162
161
|
|
|
163
|
-
This will prevent webpack from bundling
|
|
162
|
+
This will prevent webpack from bundling duplicate 3rd party libraries, decreasing the bundle size.
|
|
164
163
|
|
|
165
164
|
```javascript
|
|
166
165
|
module.exports = {
|
|
@@ -168,13 +167,22 @@ module.exports = {
|
|
|
168
167
|
libraryTarget: "commonjs"
|
|
169
168
|
},
|
|
170
169
|
externals: {
|
|
171
|
-
react: "react"
|
|
172
|
-
"prop-types": "prop-types"
|
|
170
|
+
react: "react"
|
|
173
171
|
}
|
|
174
172
|
};
|
|
175
173
|
```
|
|
176
174
|
|
|
177
|
-
|
|
175
|
+
## Content Security Policy (CSP)
|
|
176
|
+
|
|
177
|
+
Sites with a `content_security_policy` header set are likely to not work. CSP puts a restriction on using `new Function`, which `remote-module-loader` relies upon.
|
|
178
|
+
|
|
179
|
+
[Read more on CSP](https://developer.chrome.com/extensions/contentSecurityPolicy)
|
|
180
|
+
|
|
181
|
+
## Alternatives
|
|
182
|
+
|
|
183
|
+
- [Webpack Module Federation](https://webpack.js.org/concepts/module-federation)
|
|
184
|
+
|
|
185
|
+
## Contributors
|
|
178
186
|
|
|
179
187
|
Joel Thoms (https://twitter.com/joelnet)
|
|
180
188
|
|
package/dist/index.d.ts
ADDED
package/dist/index.js
CHANGED
|
@@ -1,22 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
})
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
return _createRequires.createRequires;
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
var _loadRemoteModule = require("./lib/loadRemoteModule");
|
|
20
|
-
|
|
21
|
-
var _createRequires = require("./lib/createRequires");
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
exports.__esModule = true;
|
|
10
|
+
exports.createRequires = exports["default"] = void 0;
|
|
11
|
+
var loadRemoteModule_1 = require("./lib/loadRemoteModule");
|
|
12
|
+
__createBinding(exports, loadRemoteModule_1, "createLoadRemoteModule", "default");
|
|
13
|
+
var createRequires_1 = require("./lib/createRequires");
|
|
14
|
+
__createBinding(exports, createRequires_1, "createRequires");
|
|
22
15
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2DAA2E;AAAlE,kFAAiC;AAC1C,uDAAsD;AAA7C,6DAAc"}
|
|
@@ -1,19 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
2
|
+
exports.__esModule = true;
|
|
6
3
|
exports.createRequires = void 0;
|
|
7
|
-
|
|
8
|
-
var
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
throw new Error("Could not require '".concat(name, "'. '").concat(name, "' does not exist in dependencies."));
|
|
4
|
+
var createRequires = function (dependencies) { return function (name) {
|
|
5
|
+
var _dependencies = dependencies || {};
|
|
6
|
+
if (!(name in _dependencies)) {
|
|
7
|
+
throw new Error("Could not require '" + name + "'. '" + name + "' does not exist in dependencies.");
|
|
12
8
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
};
|
|
16
|
-
};
|
|
17
|
-
|
|
9
|
+
return _dependencies[name];
|
|
10
|
+
}; };
|
|
18
11
|
exports.createRequires = createRequires;
|
|
19
12
|
//# sourceMappingURL=createRequires.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"createRequires.js","sourceRoot":"","sources":["../../src/lib/createRequires.ts"],"names":[],"mappings":";;;AAQO,IAAM,cAAc,GAAmB,UAAA,YAAY,IAAI,OAAA,UAAA,IAAI;IAChE,IAAM,aAAa,GAAG,YAAY,IAAI,EAAE,CAAC;IAEzC,IAAI,CAAC,CAAC,IAAI,IAAI,aAAa,CAAC,EAAE;QAC5B,MAAM,IAAI,KAAK,CACb,wBAAsB,IAAI,YAAO,IAAI,sCAAmC,CACzE,CAAC;KACH;IAED,OAAO,aAAa,CAAC,IAAI,CAAC,CAAC;AAC7B,CAAC,EAV6D,CAU7D,CAAC;AAVW,QAAA,cAAc,kBAUzB"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface CreateLoadRemoteModuleOptions {
|
|
2
|
+
requires?: any;
|
|
3
|
+
fetcher?: any;
|
|
4
|
+
}
|
|
5
|
+
interface LoadRemoteModule {
|
|
6
|
+
(url: string): Promise<any>;
|
|
7
|
+
}
|
|
8
|
+
interface CreateLoadRemoteModule {
|
|
9
|
+
(options?: CreateLoadRemoteModuleOptions): LoadRemoteModule;
|
|
10
|
+
}
|
|
11
|
+
export declare const createLoadRemoteModule: CreateLoadRemoteModule;
|
|
12
|
+
export {};
|
|
@@ -1,46 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
2
|
+
exports.__esModule = true;
|
|
6
3
|
exports.createLoadRemoteModule = void 0;
|
|
7
|
-
|
|
8
|
-
var
|
|
9
|
-
|
|
10
|
-
var _xmlHttpRequestFetcher = _interopRequireDefault(require("./xmlHttpRequestFetcher"));
|
|
11
|
-
|
|
12
|
-
var _nodeFetcher = _interopRequireDefault(require("./nodeFetcher"));
|
|
13
|
-
|
|
14
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
-
|
|
4
|
+
var memoize_1 = require("./memoize");
|
|
5
|
+
var index_1 = require("./xmlHttpRequestFetcher/index");
|
|
6
|
+
var nodeFetcher_1 = require("./nodeFetcher");
|
|
16
7
|
var isBrowser = typeof window !== "undefined" && typeof window.document !== "undefined";
|
|
17
8
|
/* istanbul ignore next - difficult to test */
|
|
18
|
-
|
|
19
|
-
var
|
|
20
|
-
|
|
21
|
-
var defaultRequires = function defaultRequires(name) {
|
|
22
|
-
throw new Error("Could not require '".concat(name, "'. The 'requires' function was not provided."));
|
|
9
|
+
var defaultFetcher = isBrowser ? index_1["default"] : nodeFetcher_1["default"];
|
|
10
|
+
var defaultRequires = function (name) {
|
|
11
|
+
throw new Error("Could not require '" + name + "'. The 'requires' function was not provided.");
|
|
23
12
|
};
|
|
24
|
-
|
|
25
|
-
var
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
exports: exports
|
|
37
|
-
};
|
|
38
|
-
var func = new Function("require", "module", "exports", data);
|
|
39
|
-
func(requires, module, exports);
|
|
40
|
-
return module.exports;
|
|
13
|
+
var createLoadRemoteModule = function (_a) {
|
|
14
|
+
var _b = _a === void 0 ? {} : _a, requires = _b.requires, fetcher = _b.fetcher;
|
|
15
|
+
var _requires = requires || defaultRequires;
|
|
16
|
+
var _fetcher = fetcher || defaultFetcher;
|
|
17
|
+
return memoize_1["default"](function (url) {
|
|
18
|
+
return _fetcher(url).then(function (data) {
|
|
19
|
+
var exports = {};
|
|
20
|
+
var module = { exports: exports };
|
|
21
|
+
var func = new Function("require", "module", "exports", data);
|
|
22
|
+
func(_requires, module, exports);
|
|
23
|
+
return module.exports;
|
|
24
|
+
});
|
|
41
25
|
});
|
|
42
|
-
});
|
|
43
26
|
};
|
|
44
|
-
|
|
45
27
|
exports.createLoadRemoteModule = createLoadRemoteModule;
|
|
46
28
|
//# sourceMappingURL=loadRemoteModule.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/lib/loadRemoteModule.
|
|
1
|
+
{"version":3,"file":"loadRemoteModule.js","sourceRoot":"","sources":["../../src/lib/loadRemoteModule.ts"],"names":[],"mappings":";;;AAAA,qCAAgC;AAChC,uDAAkE;AAClE,6CAAwC;AAExC,IAAM,SAAS,GACb,OAAO,MAAM,KAAK,WAAW,IAAI,OAAO,MAAM,CAAC,QAAQ,KAAK,WAAW,CAAC;AAE1E,8CAA8C;AAC9C,IAAM,cAAc,GAAG,SAAS,CAAC,CAAC,CAAC,kBAAqB,CAAC,CAAC,CAAC,wBAAW,CAAC;AAEvE,IAAM,eAAe,GAAG,UAAA,IAAI;IAC1B,MAAM,IAAI,KAAK,CACb,wBAAsB,IAAI,iDAA8C,CACzE,CAAC;AACJ,CAAC,CAAC;AAeK,IAAM,sBAAsB,GAA2B,UAAC,EAGzD;QAHyD,qBAG3D,EAAE,KAAA,EAFJ,QAAQ,cAAA,EACR,OAAO,aAAA;IAEP,IAAM,SAAS,GAAG,QAAQ,IAAI,eAAe,CAAC;IAC9C,IAAM,QAAQ,GAAG,OAAO,IAAI,cAAc,CAAC;IAE3C,OAAO,oBAAO,CAAC,UAAA,GAAG;QAChB,OAAA,QAAQ,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,UAAA,IAAI;YACrB,IAAM,OAAO,GAAG,EAAE,CAAC;YACnB,IAAM,MAAM,GAAG,EAAE,OAAO,SAAA,EAAE,CAAC;YAC3B,IAAM,IAAI,GAAG,IAAI,QAAQ,CAAC,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC;YAChE,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;YACjC,OAAO,MAAM,CAAC,OAAO,CAAC;QACxB,CAAC,CAAC;IANF,CAME,CACH,CAAC;AACJ,CAAC,CAAC;AAhBW,QAAA,sBAAsB,0BAgBjC"}
|
package/dist/lib/memoize.js
CHANGED
|
@@ -1,27 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
2
|
+
exports.__esModule = true;
|
|
8
3
|
/**
|
|
9
4
|
* Memoizes a 1-arity function
|
|
10
5
|
*
|
|
11
6
|
* @param {Function} func Function to memoize
|
|
12
7
|
* @returns {Function} Memoized version of func.
|
|
13
8
|
*/
|
|
14
|
-
var memoize = function
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
};
|
|
9
|
+
var memoize = function (func) {
|
|
10
|
+
var cache = {};
|
|
11
|
+
return function (key) {
|
|
12
|
+
if (key in cache == false) {
|
|
13
|
+
cache[key] = func(key);
|
|
14
|
+
}
|
|
15
|
+
return cache[key];
|
|
16
|
+
};
|
|
23
17
|
};
|
|
24
|
-
|
|
25
|
-
var _default = memoize;
|
|
26
|
-
exports.default = _default;
|
|
18
|
+
exports["default"] = memoize;
|
|
27
19
|
//# sourceMappingURL=memoize.js.map
|
package/dist/lib/memoize.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"memoize.js","sourceRoot":"","sources":["../../src/lib/memoize.ts"],"names":[],"mappings":";;AAAA;;;;;GAKG;AACH,IAAM,OAAO,GAAG,UAAA,IAAI;IAClB,IAAM,KAAK,GAAG,EAAE,CAAC;IACjB,OAAO,UAAA,GAAG;QACR,IAAI,GAAG,IAAI,KAAK,IAAI,KAAK,EAAE;YACzB,KAAK,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC;SACxB;QACD,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC;IACpB,CAAC,CAAC;AACJ,CAAC,CAAC;AAEF,qBAAe,OAAO,CAAC"}
|
package/dist/lib/nodeFetcher.js
CHANGED
|
@@ -1,63 +1,55 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
var __spreadArrays = (this && this.__spreadArrays) || function () {
|
|
3
|
+
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
|
|
4
|
+
for (var r = Array(s), k = 0, i = 0; i < il; i++)
|
|
5
|
+
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
|
|
6
|
+
r[k] = a[j];
|
|
7
|
+
return r;
|
|
8
|
+
};
|
|
9
|
+
exports.__esModule = true;
|
|
8
10
|
var http = require("http");
|
|
9
|
-
|
|
10
11
|
var https = require("https");
|
|
12
|
+
var status_1 = require("./status");
|
|
11
13
|
/**
|
|
12
14
|
* Get's a url. Compatible with http and https.
|
|
13
|
-
* @param {string} url
|
|
14
|
-
* @param {...any} args
|
|
15
15
|
*/
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
var
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return url.indexOf("https://") === 0 ? https.get.apply(https, [url].concat(args)) : http.get.apply(http, [url].concat(args));
|
|
16
|
+
var get = function (url) {
|
|
17
|
+
var args = [];
|
|
18
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
19
|
+
args[_i - 1] = arguments[_i];
|
|
20
|
+
}
|
|
21
|
+
if (typeof url !== "string") {
|
|
22
|
+
return {
|
|
23
|
+
on: function (eventName, callback) {
|
|
24
|
+
callback(new Error("URL must be a string."));
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
return url.indexOf("https://") === 0
|
|
29
|
+
? https.get.apply(https, __spreadArrays([url], args)) : http.get.apply(http, __spreadArrays([url], args));
|
|
32
30
|
};
|
|
33
31
|
/**
|
|
34
32
|
* Get's a URL and returns a Promise
|
|
35
|
-
* @param {string} url
|
|
36
|
-
* @returns {Promise<string>}
|
|
37
33
|
*/
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}).on("error", reject);
|
|
58
|
-
});
|
|
34
|
+
var nodeFetcher = function (url) {
|
|
35
|
+
return new Promise(function (resolve, reject) {
|
|
36
|
+
get(url, function (res) {
|
|
37
|
+
if (res.statusCode !== status_1.OK) {
|
|
38
|
+
return reject(new Error("HTTP Error Response: " + res.statusCode + " " + res.statusMessage + " (" + url + ")"));
|
|
39
|
+
}
|
|
40
|
+
var data = null;
|
|
41
|
+
// called when a data chunk is received.
|
|
42
|
+
res.on("data", function (chunk) {
|
|
43
|
+
if (data === null) {
|
|
44
|
+
data = chunk;
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
data += chunk;
|
|
48
|
+
});
|
|
49
|
+
// called when the complete response is received.
|
|
50
|
+
res.on("end", function () { return resolve(data); });
|
|
51
|
+
}).on("error", reject);
|
|
52
|
+
});
|
|
59
53
|
};
|
|
60
|
-
|
|
61
|
-
var _default = nodeFetcher;
|
|
62
|
-
exports.default = _default;
|
|
54
|
+
exports["default"] = nodeFetcher;
|
|
63
55
|
//# sourceMappingURL=nodeFetcher.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/lib/nodeFetcher.
|
|
1
|
+
{"version":3,"file":"nodeFetcher.js","sourceRoot":"","sources":["../../src/lib/nodeFetcher.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2BAA6B;AAC7B,6BAA+B;AAE/B,mCAA6B;AAM7B;;GAEG;AACH,IAAM,GAAG,GAAY,UAAC,GAAG;IAAE,cAAO;SAAP,UAAO,EAAP,qBAAO,EAAP,IAAO;QAAP,6BAAO;;IAChC,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE;QAC3B,OAAO;YACL,EAAE,YAAC,SAAS,EAAE,QAAQ;gBACpB,QAAQ,CAAC,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC,CAAC;YAC/C,CAAC;SACoB,CAAC;KACzB;IACD,OAAO,GAAG,CAAC,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC;QAClC,CAAC,CAAC,KAAK,CAAC,GAAG,OAAT,KAAK,kBAAK,GAAG,GAAK,IAAI,GACxB,CAAC,CAAC,IAAI,CAAC,GAAG,OAAR,IAAI,kBAAK,GAAG,GAAK,IAAI,EAAC,CAAC;AAC7B,CAAC,CAAC;AAEF;;GAEG;AACH,IAAM,WAAW,GAAY,UAAA,GAAG;IAC9B,OAAA,IAAI,OAAO,CAAC,UAAC,OAAO,EAAE,MAAM;QAC1B,GAAG,CAAC,GAAG,EAAE,UAAA,GAAG;YACV,IAAI,GAAG,CAAC,UAAU,KAAK,WAAE,EAAE;gBACzB,OAAO,MAAM,CAAC,IAAI,KAAK,CAAC,0BAAwB,GAAG,CAAC,UAAU,SAAI,GAAG,CAAC,aAAa,UAAK,GAAG,MAAG,CAAC,CAAC,CAAA;aACjG;YAED,IAAI,IAAI,GAAG,IAAI,CAAC;YAEhB,wCAAwC;YACxC,GAAG,CAAC,EAAE,CAAC,MAAM,EAAE,UAAA,KAAK;gBAClB,IAAI,IAAI,KAAK,IAAI,EAAE;oBACjB,IAAI,GAAG,KAAK,CAAC;oBACb,OAAO;iBACR;gBACD,IAAI,IAAI,KAAK,CAAC;YAChB,CAAC,CAAC,CAAC;YAEH,iDAAiD;YACjD,GAAG,CAAC,EAAE,CAAC,KAAK,EAAE,cAAM,OAAA,OAAO,CAAC,IAAI,CAAC,EAAb,CAAa,CAAC,CAAC;QACrC,CAAC,CAAC,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IACzB,CAAC,CAAC;AApBF,CAoBE,CAAC;AAEL,qBAAe,WAAW,CAAC"}
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
2
|
+
exports.__esModule = true;
|
|
6
3
|
exports.InternalServerError = exports.OK = void 0;
|
|
7
4
|
// export const Continue = 100;
|
|
8
5
|
// export const Switchingprotocols = 101;
|
|
9
|
-
|
|
6
|
+
exports.OK = 200;
|
|
7
|
+
// export const Created = 201;
|
|
10
8
|
// export const Accepted = 202;
|
|
11
9
|
// export const NonAuthoritativeInformation = 203;
|
|
12
10
|
// export const NoContent = 204;
|
|
@@ -37,13 +35,10 @@ var OK = 200; // export const Created = 201;
|
|
|
37
35
|
// export const UnsupportedMediaType = 415;
|
|
38
36
|
// export const RequestedRangeNotSuitable = 416;
|
|
39
37
|
// export const ExpectationFailed = 417;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
var InternalServerError = 500; // export const NotImplemented = 501;
|
|
38
|
+
exports.InternalServerError = 500;
|
|
39
|
+
// export const NotImplemented = 501;
|
|
43
40
|
// export const BadGateway = 502;
|
|
44
41
|
// export const ServiceUnavailable = 503;
|
|
45
42
|
// export const GatewayTimeout = 504;
|
|
46
43
|
// export const HTTPVersionNotSupported = 505;
|
|
47
|
-
|
|
48
|
-
exports.InternalServerError = InternalServerError;
|
|
49
44
|
//# sourceMappingURL=status.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"status.js","sourceRoot":"","sources":["../../src/lib/status.ts"],"names":[],"mappings":";;;AAAA,+BAA+B;AAC/B,yCAAyC;AAC5B,QAAA,EAAE,GAAG,GAAG,CAAC;AACtB,8BAA8B;AAC9B,+BAA+B;AAC/B,kDAAkD;AAClD,gCAAgC;AAChC,mCAAmC;AACnC,qCAAqC;AACrC,sCAAsC;AACtC,uCAAuC;AACvC,4BAA4B;AAC5B,+BAA+B;AAC/B,kCAAkC;AAClC,+BAA+B;AAC/B,wCAAwC;AACxC,iCAAiC;AACjC,mCAAmC;AACnC,sCAAsC;AACtC,gCAAgC;AAChC,+BAA+B;AAC/B,uCAAuC;AACvC,oCAAoC;AACpC,kDAAkD;AAClD,qCAAqC;AACrC,+BAA+B;AAC/B,2BAA2B;AAC3B,qCAAqC;AACrC,yCAAyC;AACzC,4CAA4C;AAC5C,wCAAwC;AACxC,2CAA2C;AAC3C,gDAAgD;AAChD,wCAAwC;AAC3B,QAAA,mBAAmB,GAAG,GAAG,CAAC;AACvC,qCAAqC;AACrC,iCAAiC;AACjC,yCAAyC;AACzC,qCAAqC;AACrC,8CAA8C"}
|
|
@@ -1,28 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
xhr.status === _status.OK ? resolve(xhr.responseText) : reject("".concat(xhr.status, " ").concat(xhr.statusText));
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
xhr.open("GET", url, true);
|
|
22
|
-
xhr.send();
|
|
23
|
-
});
|
|
2
|
+
exports.__esModule = true;
|
|
3
|
+
var status_1 = require("../status");
|
|
4
|
+
var readyState_1 = require("./readyState");
|
|
5
|
+
var xmlHttpRequestFetcher = function (url) {
|
|
6
|
+
return new Promise(function (resolve, reject) {
|
|
7
|
+
var xhr = new XMLHttpRequest();
|
|
8
|
+
xhr.onreadystatechange = function () {
|
|
9
|
+
if (xhr.readyState !== readyState_1.DONE)
|
|
10
|
+
return;
|
|
11
|
+
xhr.status === status_1.OK
|
|
12
|
+
? resolve(xhr.responseText)
|
|
13
|
+
: reject(new Error("HTTP Error Response: " + xhr.status + " " + xhr.statusText + " (" + url + ")"));
|
|
14
|
+
};
|
|
15
|
+
xhr.open("GET", url, true);
|
|
16
|
+
xhr.send();
|
|
17
|
+
});
|
|
24
18
|
};
|
|
25
|
-
|
|
26
|
-
var _default = xmlHttpRequestFetcher;
|
|
27
|
-
exports.default = _default;
|
|
19
|
+
exports["default"] = xmlHttpRequestFetcher;
|
|
28
20
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/xmlHttpRequestFetcher/index.
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/xmlHttpRequestFetcher/index.ts"],"names":[],"mappings":";;AACA,oCAA+B;AAC/B,2CAAoC;AAEpC,IAAM,qBAAqB,GAAY,UAAA,GAAG;IACxC,OAAA,IAAI,OAAO,CAAC,UAAC,OAAO,EAAE,MAAM;QAC1B,IAAM,GAAG,GAAG,IAAI,cAAc,EAAE,CAAC;QACjC,GAAG,CAAC,kBAAkB,GAAG;YACvB,IAAI,GAAG,CAAC,UAAU,KAAK,iBAAI;gBAAE,OAAO;YACpC,GAAG,CAAC,MAAM,KAAK,WAAE;gBACf,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC;gBAC3B,CAAC,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,0BAAwB,GAAG,CAAC,MAAM,SAAI,GAAG,CAAC,UAAU,UAAK,GAAG,MAAG,CAAC,CAAC,CAAA;QACxF,CAAC,CAAC;QACF,GAAG,CAAC,IAAI,CAAC,KAAK,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;QAC3B,GAAG,CAAC,IAAI,EAAE,CAAC;IACb,CAAC,CAAC;AAVF,CAUE,CAAC;AAEL,qBAAe,qBAAqB,CAAC"}
|
|
@@ -1,18 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
2
|
+
exports.__esModule = true;
|
|
6
3
|
exports.DONE = exports.OPENED = exports.UNSENT = void 0;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
exports.UNSENT = UNSENT;
|
|
10
|
-
var OPENED = 1; // open() has been called.
|
|
4
|
+
exports.UNSENT = 0; // Client has been created. open() not called yet.
|
|
5
|
+
exports.OPENED = 1; // open() has been called.
|
|
11
6
|
// export const HEADERS_RECEIVED = 2; // send() has been called, and headers and status are available.
|
|
12
7
|
// export const LOADING = 3; // Downloading; responseText holds partial data.
|
|
13
|
-
|
|
14
|
-
exports.OPENED = OPENED;
|
|
15
|
-
var DONE = 4; // The operation is complete.
|
|
16
|
-
|
|
17
|
-
exports.DONE = DONE;
|
|
8
|
+
exports.DONE = 4; // The operation is complete.
|
|
18
9
|
//# sourceMappingURL=readyState.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/xmlHttpRequestFetcher/readyState.
|
|
1
|
+
{"version":3,"file":"readyState.js","sourceRoot":"","sources":["../../../src/lib/xmlHttpRequestFetcher/readyState.ts"],"names":[],"mappings":";;;AAAa,QAAA,MAAM,GAAG,CAAC,CAAC,CAAC,kDAAkD;AAC9D,QAAA,MAAM,GAAG,CAAC,CAAC,CAAC,0BAA0B;AACnD,sGAAsG;AACtG,6EAA6E;AAChE,QAAA,IAAI,GAAG,CAAC,CAAC,CAAC,6BAA6B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/models/index.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@paciolan/remote-module-loader",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"author": "Paciolan",
|
|
@@ -24,7 +24,9 @@
|
|
|
24
24
|
]
|
|
25
25
|
},
|
|
26
26
|
"scripts": {
|
|
27
|
-
"
|
|
27
|
+
"prebuild": "npm run clean",
|
|
28
|
+
"build": "tsc --declaration",
|
|
29
|
+
"watch": "npm run build -- --watch",
|
|
28
30
|
"clean": "rimraf dist",
|
|
29
31
|
"cz": "git-cz",
|
|
30
32
|
"test": "cross-env NODE_ENV=test jest",
|
|
@@ -34,23 +36,27 @@
|
|
|
34
36
|
},
|
|
35
37
|
"dependencies": {},
|
|
36
38
|
"devDependencies": {
|
|
37
|
-
"@babel/cli": "^7.
|
|
38
|
-
"@babel/core": "^7.
|
|
39
|
-
"@babel/preset-env": "^7.
|
|
40
|
-
"@
|
|
41
|
-
"@commitlint/
|
|
42
|
-
"@
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"eslint
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"
|
|
39
|
+
"@babel/cli": "^7.12.8",
|
|
40
|
+
"@babel/core": "^7.12.9",
|
|
41
|
+
"@babel/preset-env": "^7.12.7",
|
|
42
|
+
"@babel/preset-typescript": "^7.12.7",
|
|
43
|
+
"@commitlint/cli": "^11.0.0",
|
|
44
|
+
"@commitlint/config-conventional": "^11.0.0",
|
|
45
|
+
"@types/jest": "^26.0.16",
|
|
46
|
+
"@types/node": "^14.14.10",
|
|
47
|
+
"babel-loader": "^8.2.2",
|
|
48
|
+
"cross-env": "^7.0.3",
|
|
49
|
+
"eslint": "^7.14.0",
|
|
50
|
+
"eslint-config-prettier": "^6.15.0",
|
|
51
|
+
"eslint-plugin-prettier": "^3.2.0",
|
|
52
|
+
"git-cz": "^4.7.5",
|
|
53
|
+
"husky": "^4.3.0",
|
|
54
|
+
"jest": "^26.6.3",
|
|
55
|
+
"prettier": "^2.2.1",
|
|
56
|
+
"regenerator-runtime": "^0.13.7",
|
|
57
|
+
"rimraf": "^3.0.2",
|
|
58
|
+
"ts-jest": "^26.4.4",
|
|
59
|
+
"typescript": "^4.1.2"
|
|
54
60
|
},
|
|
55
61
|
"husky": {
|
|
56
62
|
"hooks": {
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"lib": [
|
|
4
|
+
"ES2015",
|
|
5
|
+
"DOM"
|
|
6
|
+
],
|
|
7
|
+
"outDir": "dist",
|
|
8
|
+
"module": "commonjs",
|
|
9
|
+
"types": [
|
|
10
|
+
"node",
|
|
11
|
+
"jest"
|
|
12
|
+
],
|
|
13
|
+
"sourceMap": true,
|
|
14
|
+
},
|
|
15
|
+
"include": [
|
|
16
|
+
"./src/**/*.ts"
|
|
17
|
+
],
|
|
18
|
+
"exclude": [
|
|
19
|
+
"node_modules",
|
|
20
|
+
"./src/**/*.test.ts"
|
|
21
|
+
]
|
|
22
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/xmlHttpRequestFetcher/status.js"],"names":["OK","InternalServerError"],"mappings":";;;;;;AAAA;AACA;AACO,IAAMA,EAAE,GAAG,GAAX,C,CACP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,IAAMC,mBAAmB,GAAG,GAA5B,C,CACP;AACA;AACA;AACA;AACA","sourcesContent":["// export const Continue = 100;\n// export const Switchingprotocols = 101;\nexport const OK = 200;\n// export const Created = 201;\n// export const Accepted = 202;\n// export const NonAuthoritativeInformation = 203;\n// export const NoContent = 204;\n// export const ResetContent = 205;\n// export const PartialContent = 206;\n// export const MultipleChoices = 300;\n// export const MovedPermanently = 301;\n// export const Found = 302;\n// export const SeeOther = 303;\n// export const NotModified = 304;\n// export const UseProxy = 305;\n// export const TemporaryRedirect = 307;\n// export const BadRequest = 400;\n// export const Unauthorized = 401;\n// export const PaymentRequired = 402;\n// export const Forbidden = 403;\n// export const NotFound = 404;\n// export const MethodNotAllowed = 405;\n// export const NotAcceptable = 406;\n// export const ProxyAuthenticationRequired = 407;\n// export const RequestTimeout = 408;\n// export const Conflict = 409;\n// export const Gone = 410;\n// export const LengthRequired = 411;\n// export const PreconditionFailed = 412;\n// export const RequestEntityTooLarge = 413;\n// export const RequestURITooLong = 414;\n// export const UnsupportedMediaType = 415;\n// export const RequestedRangeNotSuitable = 416;\n// export const ExpectationFailed = 417;\nexport const InternalServerError = 500;\n// export const NotImplemented = 501;\n// export const BadGateway = 502;\n// export const ServiceUnavailable = 503;\n// export const GatewayTimeout = 504;\n// export const HTTPVersionNotSupported = 505;\n"],"file":"status.js"}
|