smipper 31.0.0 → 33.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/dist/load.js +23 -9
- package/dist/rewriteLocalControl.js +2 -1
- package/package.json +1 -2
package/dist/load.js
CHANGED
|
@@ -7,18 +7,32 @@ exports.load = void 0;
|
|
|
7
7
|
const rewriteLocalControl_1 = require("./rewriteLocalControl");
|
|
8
8
|
const fs_1 = __importDefault(require("fs"));
|
|
9
9
|
const got_1 = __importDefault(require("got"));
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
const path_1 = __importDefault(require("path"));
|
|
11
|
+
const process_1 = __importDefault(require("process"));
|
|
12
|
+
async function load(smipper, filePath) {
|
|
13
|
+
smipper.verbose("load", filePath);
|
|
14
|
+
if (filePath.startsWith("http://localcontrol.netflix.com/")) {
|
|
15
|
+
filePath = (0, rewriteLocalControl_1.rewriteLocalControl)(smipper, filePath);
|
|
13
16
|
}
|
|
14
|
-
if (
|
|
15
|
-
|
|
17
|
+
if (!filePath.includes("://")) {
|
|
18
|
+
if (filePath[0] === "/" && fs_1.default.existsSync(filePath)) {
|
|
19
|
+
filePath = `file://${filePath}`;
|
|
20
|
+
}
|
|
21
|
+
else if (fs_1.default.existsSync(filePath)) {
|
|
22
|
+
filePath = `file://${path_1.default.join(process_1.default.cwd(), filePath)}`;
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
filePath = (0, rewriteLocalControl_1.rewriteLocalControl)(smipper, filePath);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
if (filePath.startsWith("file:///")) {
|
|
29
|
+
return fs_1.default.readFileSync(filePath.substring(7), "utf8");
|
|
16
30
|
}
|
|
17
|
-
if (!
|
|
31
|
+
if (!filePath.startsWith("http://") && !filePath.startsWith("https://")) {
|
|
18
32
|
throw new Error("Not a url");
|
|
19
33
|
}
|
|
20
34
|
if (smipper.cache && smipper.cacheKey) {
|
|
21
|
-
const response = smipper.cache.get(smipper.cacheKey,
|
|
35
|
+
const response = smipper.cache.get(smipper.cacheKey, filePath);
|
|
22
36
|
if (response) {
|
|
23
37
|
return response;
|
|
24
38
|
}
|
|
@@ -28,13 +42,13 @@ async function load(smipper, path) {
|
|
|
28
42
|
}
|
|
29
43
|
// let retryIndex = 0;
|
|
30
44
|
async function get() {
|
|
31
|
-
const response = await got_1.default.get(
|
|
45
|
+
const response = await got_1.default.get(filePath, { timeout: 10000 });
|
|
32
46
|
smipper.verbose(response.headers);
|
|
33
47
|
return response.body || "";
|
|
34
48
|
}
|
|
35
49
|
const response = await get();
|
|
36
50
|
if (smipper.cacheEntry) {
|
|
37
|
-
smipper.cacheEntry.add(
|
|
51
|
+
smipper.cacheEntry.add(filePath, response);
|
|
38
52
|
}
|
|
39
53
|
return response;
|
|
40
54
|
}
|
|
@@ -24,8 +24,9 @@ function findFile(dir, fn) {
|
|
|
24
24
|
}
|
|
25
25
|
return undefined;
|
|
26
26
|
}
|
|
27
|
-
function rewriteLocalControl(url) {
|
|
27
|
+
function rewriteLocalControl(smipper, url) {
|
|
28
28
|
const found = findFile(process.cwd(), path_1.default.basename(url.substring(6)));
|
|
29
|
+
smipper.verbose("Rewriting", url, "in", process.cwd(), "=>", found);
|
|
29
30
|
if (found) {
|
|
30
31
|
return found;
|
|
31
32
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "smipper",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "33.0.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"bin": {
|
|
@@ -22,7 +22,6 @@
|
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@types/got": "^9.6.12",
|
|
24
24
|
"@types/node": "^18.7.18",
|
|
25
|
-
"@types/source-map": "^0.5.7",
|
|
26
25
|
"prettier": "^2.7.1",
|
|
27
26
|
"typescript": "^4.8.3"
|
|
28
27
|
}
|