smipper 41.0.0 → 43.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/LoadResult.js +2 -0
- package/dist/init.js +22 -3
- package/dist/load.js +30 -7
- package/dist/loadUri.js +12 -12
- package/dist/rewriteOCA.js +8 -0
- package/dist/run.js +6 -1
- package/package.json +1 -3
package/dist/init.js
CHANGED
|
@@ -7,6 +7,7 @@ exports.init = void 0;
|
|
|
7
7
|
const fs_1 = __importDefault(require("fs"));
|
|
8
8
|
const os_1 = __importDefault(require("os"));
|
|
9
9
|
const path_1 = __importDefault(require("path"));
|
|
10
|
+
const assert_1 = __importDefault(require("assert"));
|
|
10
11
|
const Cache_1 = require("./Cache");
|
|
11
12
|
function init() {
|
|
12
13
|
let smipper = {
|
|
@@ -15,8 +16,18 @@ function init() {
|
|
|
15
16
|
jsc: 0,
|
|
16
17
|
cacheDir: path_1.default.join(os_1.default.homedir(), ".cache", "smipper", "cache"),
|
|
17
18
|
cacheSize: 10,
|
|
18
|
-
sourceMaps:
|
|
19
|
-
noOriginalUrl: false
|
|
19
|
+
sourceMaps: new Map(),
|
|
20
|
+
noOriginalUrl: false,
|
|
21
|
+
mappedUrls: new Map()
|
|
22
|
+
};
|
|
23
|
+
const addMapUrl = (arg) => {
|
|
24
|
+
arg.split(" ").forEach((x, idx) => {
|
|
25
|
+
const split = x.split("=>");
|
|
26
|
+
if (split.length !== 2 || !split[0] || !split[1]) {
|
|
27
|
+
throw new Error(`Failed to parse map url: ${arg} ${idx}`);
|
|
28
|
+
}
|
|
29
|
+
smipper.mappedUrls.set(split[0], split[1]);
|
|
30
|
+
});
|
|
20
31
|
};
|
|
21
32
|
for (const key in process.env) {
|
|
22
33
|
switch (key) {
|
|
@@ -45,7 +56,7 @@ function init() {
|
|
|
45
56
|
}
|
|
46
57
|
}
|
|
47
58
|
}
|
|
48
|
-
const usage = "smipper [stack|-h|--help|-v|--verbose|--version|--jsc|--json|--file=@FILE@|-f=@FILE@|--cache-key=$CACHE_KEY$|--cache-dir=$CACHE_DIR$|--cache-size=$CACHE_SIZE$|--no-original-url|-n|-";
|
|
59
|
+
const usage = "smipper [stack|-h|--help|-v|--verbose|--version|--jsc|--json|--file=@FILE@|-f=@FILE@|--cache-key=$CACHE_KEY$|--cache-dir=$CACHE_DIR$|--cache-size=$CACHE_SIZE$|--no-original-url|-n|--map-url|-m|-";
|
|
49
60
|
for (let i = 2; i < process.argv.length; ++i) {
|
|
50
61
|
try {
|
|
51
62
|
const arg = process.argv[i] || "";
|
|
@@ -98,6 +109,12 @@ function init() {
|
|
|
98
109
|
else if (arg === "--no-original-url" || arg == "-n") {
|
|
99
110
|
smipper.noOriginalUrl = true;
|
|
100
111
|
}
|
|
112
|
+
else if (arg === "--map-url" || arg === "-m") {
|
|
113
|
+
addMapUrl(process.argv[++i]);
|
|
114
|
+
}
|
|
115
|
+
else if (arg.startsWith("--map-url=")) {
|
|
116
|
+
addMapUrl(arg.substring(10));
|
|
117
|
+
}
|
|
101
118
|
else if (arg === "-") {
|
|
102
119
|
// stdin
|
|
103
120
|
}
|
|
@@ -106,7 +123,9 @@ function init() {
|
|
|
106
123
|
}
|
|
107
124
|
}
|
|
108
125
|
catch (err) {
|
|
126
|
+
(0, assert_1.default)(err instanceof Error);
|
|
109
127
|
console.error("Error: " + err.toString());
|
|
128
|
+
smipper.verbose(err.stack);
|
|
110
129
|
process.exit(1);
|
|
111
130
|
}
|
|
112
131
|
}
|
package/dist/load.js
CHANGED
|
@@ -6,14 +6,28 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.load = void 0;
|
|
7
7
|
const rewriteLocalControl_1 = require("./rewriteLocalControl");
|
|
8
8
|
const fs_1 = __importDefault(require("fs"));
|
|
9
|
-
const got_1 = __importDefault(require("got"));
|
|
10
9
|
const path_1 = __importDefault(require("path"));
|
|
11
10
|
const process_1 = __importDefault(require("process"));
|
|
11
|
+
const assert_1 = __importDefault(require("assert"));
|
|
12
12
|
async function load(smipper, filePath) {
|
|
13
13
|
smipper.verbose("load", filePath);
|
|
14
14
|
if (filePath.startsWith("http://localcontrol.netflix.com/")) {
|
|
15
15
|
filePath = (0, rewriteLocalControl_1.rewriteLocalControl)(smipper, filePath);
|
|
16
16
|
}
|
|
17
|
+
smipper.verbose(smipper.mappedUrls);
|
|
18
|
+
const mapped = smipper.mappedUrls.get(filePath);
|
|
19
|
+
if (mapped) {
|
|
20
|
+
try {
|
|
21
|
+
const ret = fs_1.default.readFileSync(mapped, "utf8");
|
|
22
|
+
smipper.verbose("Loaded mapped url", filePath, mapped, "=>", ret.length);
|
|
23
|
+
return { contents: ret, resolvedUrl: mapped };
|
|
24
|
+
}
|
|
25
|
+
catch (err) {
|
|
26
|
+
(0, assert_1.default)(err instanceof Error);
|
|
27
|
+
smipper.verbose("Failed to load mapped url", filePath, mapped, err.message);
|
|
28
|
+
smipper.mappedUrls.delete(filePath);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
17
31
|
if (!filePath.includes("://")) {
|
|
18
32
|
if (filePath[0] === "/" && fs_1.default.existsSync(filePath)) {
|
|
19
33
|
filePath = `file://${filePath}`;
|
|
@@ -25,8 +39,14 @@ async function load(smipper, filePath) {
|
|
|
25
39
|
filePath = (0, rewriteLocalControl_1.rewriteLocalControl)(smipper, filePath);
|
|
26
40
|
}
|
|
27
41
|
}
|
|
42
|
+
else if (filePath.startsWith("file:///") && !fs_1.default.existsSync(filePath.substring(7))) {
|
|
43
|
+
filePath = (0, rewriteLocalControl_1.rewriteLocalControl)(smipper, filePath.substring(7));
|
|
44
|
+
}
|
|
28
45
|
if (filePath.startsWith("file:///")) {
|
|
29
|
-
return
|
|
46
|
+
return {
|
|
47
|
+
contents: fs_1.default.readFileSync(filePath.substring(7), "utf8"),
|
|
48
|
+
resolvedUrl: filePath
|
|
49
|
+
};
|
|
30
50
|
}
|
|
31
51
|
if (!filePath.startsWith("http://") && !filePath.startsWith("https://")) {
|
|
32
52
|
throw new Error("Not a url");
|
|
@@ -34,22 +54,25 @@ async function load(smipper, filePath) {
|
|
|
34
54
|
if (smipper.cache && smipper.cacheKey) {
|
|
35
55
|
const response = smipper.cache.get(smipper.cacheKey, filePath);
|
|
36
56
|
if (response) {
|
|
37
|
-
return response;
|
|
57
|
+
return { contents: response, resolvedUrl: filePath };
|
|
38
58
|
}
|
|
39
59
|
if (!smipper.cacheEntry) {
|
|
40
60
|
smipper.cacheEntry = smipper.cache.create(smipper.cacheKey);
|
|
41
61
|
}
|
|
42
62
|
}
|
|
43
|
-
// let retryIndex = 0;
|
|
44
63
|
async function get() {
|
|
45
|
-
const
|
|
64
|
+
const controller = new AbortController();
|
|
65
|
+
const timeoutId = setTimeout(() => {
|
|
66
|
+
controller.abort();
|
|
67
|
+
}, 10000);
|
|
68
|
+
const response = await fetch(filePath, { signal: controller.signal });
|
|
46
69
|
smipper.verbose(response.headers);
|
|
47
|
-
return response.
|
|
70
|
+
return response.text() || "";
|
|
48
71
|
}
|
|
49
72
|
const response = await get();
|
|
50
73
|
if (smipper.cacheEntry) {
|
|
51
74
|
smipper.cacheEntry.add(filePath, response);
|
|
52
75
|
}
|
|
53
|
-
return response;
|
|
76
|
+
return { contents: response, resolvedUrl: filePath };
|
|
54
77
|
}
|
|
55
78
|
exports.load = load;
|
package/dist/loadUri.js
CHANGED
|
@@ -13,17 +13,19 @@ function loadUri(smipper, path) {
|
|
|
13
13
|
}
|
|
14
14
|
return new Promise((resolve, reject) => {
|
|
15
15
|
smipper.verbose("loading", path);
|
|
16
|
-
if (!
|
|
17
|
-
smipper.sourceMaps
|
|
16
|
+
if (!smipper.sourceMaps.has(path)) {
|
|
17
|
+
smipper.sourceMaps.set(path, {
|
|
18
18
|
resolvers: [resolve],
|
|
19
19
|
rejecters: [reject]
|
|
20
|
-
};
|
|
20
|
+
});
|
|
21
21
|
(0, load_1.load)(smipper, path)
|
|
22
|
-
.then((
|
|
22
|
+
.then((jsResult) => {
|
|
23
|
+
const jsData = jsResult.contents;
|
|
24
|
+
const baseUrl = jsResult.resolvedUrl;
|
|
23
25
|
const idx = jsData.lastIndexOf("//# sourceMappingURL=");
|
|
24
26
|
smipper.verbose("Got the file", jsData.length, idx);
|
|
25
27
|
if (idx == -1) {
|
|
26
|
-
return
|
|
28
|
+
return baseUrl + ".map";
|
|
27
29
|
}
|
|
28
30
|
const end = jsData.indexOf("\n", idx + 21);
|
|
29
31
|
const mapUrl = jsData.substring(idx + 21, end === -1 ? jsData.length : end);
|
|
@@ -35,20 +37,18 @@ function loadUri(smipper, path) {
|
|
|
35
37
|
if (mapUrl.indexOf("://") != -1) {
|
|
36
38
|
return mapUrl;
|
|
37
39
|
}
|
|
38
|
-
|
|
39
|
-
return new URL(mapUrl, path).href;
|
|
40
|
+
return new URL(mapUrl, baseUrl).href;
|
|
40
41
|
})
|
|
41
42
|
.then((mapUrl) => {
|
|
42
|
-
// console.log(mapUrl.substring(0, 20));
|
|
43
43
|
if (mapUrl.startsWith("base64,")) {
|
|
44
44
|
return Buffer.from(mapUrl.substring(7), "base64").toString();
|
|
45
45
|
}
|
|
46
|
-
return (0, load_1.load)(smipper, mapUrl);
|
|
46
|
+
return (0, load_1.load)(smipper, mapUrl).then((r) => r.contents);
|
|
47
47
|
})
|
|
48
48
|
.then(async (sourceMapData) => {
|
|
49
49
|
const parsed = JSON.parse(sourceMapData);
|
|
50
50
|
const smap = await new source_map_1.default.SourceMapConsumer(parsed);
|
|
51
|
-
const pending = smipper.sourceMaps
|
|
51
|
+
const pending = smipper.sourceMaps.get(path);
|
|
52
52
|
// sourceMaps.delete(path);
|
|
53
53
|
if (pending) {
|
|
54
54
|
pending.resolvers.forEach((func) => {
|
|
@@ -57,7 +57,7 @@ function loadUri(smipper, path) {
|
|
|
57
57
|
}
|
|
58
58
|
})
|
|
59
59
|
.catch((err) => {
|
|
60
|
-
const pending = smipper.sourceMaps
|
|
60
|
+
const pending = smipper.sourceMaps.get(path);
|
|
61
61
|
if (!pending) {
|
|
62
62
|
throw new Error("Gotta have pending");
|
|
63
63
|
}
|
|
@@ -68,7 +68,7 @@ function loadUri(smipper, path) {
|
|
|
68
68
|
});
|
|
69
69
|
}
|
|
70
70
|
else {
|
|
71
|
-
const cur = smipper.sourceMaps
|
|
71
|
+
const cur = smipper.sourceMaps.get(path);
|
|
72
72
|
smipper.verbose("path is in source maps already", cur);
|
|
73
73
|
if (!cur) {
|
|
74
74
|
throw new Error("Gotta have cur");
|
package/dist/rewriteOCA.js
CHANGED
|
@@ -2,6 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.rewriteOCA = void 0;
|
|
4
4
|
const rewrites = [
|
|
5
|
+
{
|
|
6
|
+
pattern: /https:\/\/[^/]*nflxso.net\/genc\/nrdp\/milo\/1.0.([0-9]+)-[A-Za-z0-9]*\/milo\.shim\.prod\.js/,
|
|
7
|
+
replacement: [
|
|
8
|
+
"https://build.dta.netflix.com/nrdp/milo/(variantBuildNumber=",
|
|
9
|
+
1,
|
|
10
|
+
")/dist/milo.shim.prod.js"
|
|
11
|
+
]
|
|
12
|
+
},
|
|
5
13
|
{
|
|
6
14
|
pattern: /https:\/\/[^/]*nflxso.net\/genc\/nrdp\/milo\/1.0.([0-9]+)-[A-Za-z0-9]*\/milo.prod.js/,
|
|
7
15
|
replacement: [
|
package/dist/run.js
CHANGED
|
@@ -19,7 +19,12 @@ async function run(smipper) {
|
|
|
19
19
|
x = x.trim();
|
|
20
20
|
let match = / *at *([^ ]*).* \(?([^ ]+):([0-9]+):([0-9]+)/.exec(x);
|
|
21
21
|
if (!match) {
|
|
22
|
-
|
|
22
|
+
// Anchor the URL/path on a scheme (e.g. http://, file://) or a leading "/"
|
|
23
|
+
// so we don't accidentally swallow log prefixes like
|
|
24
|
+
// "00:00:00.133 [milo:0x16bb23000] SMIPPER(trace):"
|
|
25
|
+
// into the captured "url".
|
|
26
|
+
match =
|
|
27
|
+
/(?:([^\s@]+)@)?((?:[a-zA-Z][a-zA-Z0-9+.-]*:\/\/|\/)[^\s:]+):([0-9]+):([0-9]+)/.exec(x);
|
|
23
28
|
}
|
|
24
29
|
smipper.verbose(x, " => ", match);
|
|
25
30
|
if (!match) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "smipper",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "43.0.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"bin": {
|
|
@@ -16,11 +16,9 @@
|
|
|
16
16
|
"author": "",
|
|
17
17
|
"license": "ISC",
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"got": "^9.6.0",
|
|
20
19
|
"source-map": "^0.7.4"
|
|
21
20
|
},
|
|
22
21
|
"devDependencies": {
|
|
23
|
-
"@types/got": "^9.6.12",
|
|
24
22
|
"@types/node": "^18.7.18",
|
|
25
23
|
"prettier": "^2.7.1",
|
|
26
24
|
"typescript": "^4.8.3"
|