Innovenergy_trunk/frontend/node_modules/testcafe-hammerhead/lib/processing/resources/script.js

37 lines
1.6 KiB
JavaScript
Raw Normal View History

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const resource_processor_base_1 = __importDefault(require("./resource-processor-base"));
const lru_cache_1 = __importDefault(require("lru-cache"));
const script_1 = require("../script");
const url_1 = require("../../utils/url");
const builtin_header_names_1 = __importDefault(require("../../request-pipeline/builtin-header-names"));
class ScriptResourceProcessor extends resource_processor_base_1.default {
constructor() {
super();
this.jsCache = new lru_cache_1.default({
max: 50 * 1024 * 1024,
length: n => n.length, // NOTE: 1 char ~ 1 byte.
});
}
processResource(script, ctx, _charset, urlReplacer) {
if (!script)
return script;
let processedScript = this.jsCache.get(script);
if (!processedScript) {
processedScript = (0, script_1.processScript)(script, true, false, urlReplacer, ctx.destRes.headers[builtin_header_names_1.default.serviceWorkerAllowed], ctx.proxyless);
this.jsCache.set(script, processedScript);
}
else
processedScript = (0, url_1.updateScriptImportUrls)(processedScript, ctx.serverInfo, ctx.session.id, ctx.windowId);
return processedScript;
}
shouldProcessResource(ctx) {
return ctx.contentInfo.isScript;
}
}
exports.default = new ScriptResourceProcessor();module.exports = exports.default;