zephyr-xpack-internal
Version:
Xpack internals for Zephyr
91 lines (90 loc) • 3.82 kB
JavaScript
;
var __webpack_require__ = {};
(()=>{
__webpack_require__.d = (exports1, getters, values)=>{
var define = (defs, kind)=>{
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
enumerable: true,
[kind]: defs[key]
});
};
define(getters, "get");
define(values, "value");
};
})();
(()=>{
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
})();
(()=>{
__webpack_require__.r = (exports1)=>{
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
value: 'Module'
});
Object.defineProperty(exports1, '__esModule', {
value: true
});
};
})();
var __webpack_exports__ = {};
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
buildWebpackAssetMap: ()=>buildWebpackAssetMap
});
const external_zephyr_agent_namespaceObject = require("zephyr-agent");
function getAssetType(asset) {
return asset?.constructor?.name ?? typeof asset;
}
function extractBuffer(asset) {
try {
if ('function' == typeof asset?.buffer) {
const content = asset.buffer();
if (Buffer.isBuffer(content) || 'string' == typeof content) return content;
}
} catch {}
try {
if ('function' == typeof asset?.source) {
const content = asset.source();
if (Buffer.isBuffer(content) || 'string' == typeof content) return content;
}
} catch {}
}
function cacheExtractedBuffers() {
const contents = new Map();
return (source)=>{
if (contents.has(source)) return contents.get(source);
const content = extractBuffer(source);
contents.set(source, content);
return content;
};
}
function assertReadableTapSources(assets, getBuffer) {
for (const [path, source] of Object.entries(assets))if (void 0 === getBuffer(source)) throw new external_zephyr_agent_namespaceObject.ZephyrError(external_zephyr_agent_namespaceObject.ZeErrors.ERR_DEPLOY_LOCAL_BUILD, {
message: `Cannot publish TAP artifact ${JSON.stringify(path)} because its ${getAssetType(source)} source does not expose readable bytes.`
});
}
async function buildWebpackAssetMap(assets, props) {
const { wait_for_index_html, failOnUnsupportedSource = false } = props;
external_zephyr_agent_namespaceObject.ze_log.upload('Building assets map from webpack assets.');
const getBuffer = cacheExtractedBuffers();
if (failOnUnsupportedSource) assertReadableTapSources(assets, getBuffer);
const assetsMap = (0, external_zephyr_agent_namespaceObject.buildAssetsMap)(assets, getBuffer, getAssetType);
if (wait_for_index_html) {
external_zephyr_agent_namespaceObject.ze_log.upload('Assets map built. Checking for index.html waiter.');
const index_html_content = await (0, external_zephyr_agent_namespaceObject.onIndexHtmlResolved)();
const index_html_asset = (0, external_zephyr_agent_namespaceObject.zeBuildAssets)({
filepath: 'index.html',
content: index_html_content
});
assetsMap[index_html_asset.hash] = index_html_asset;
external_zephyr_agent_namespaceObject.ze_log.misc('Index.html added to assets map.');
}
return assetsMap;
}
exports.buildWebpackAssetMap = __webpack_exports__.buildWebpackAssetMap;
for(var __rspack_i in __webpack_exports__)if (-1 === [
"buildWebpackAssetMap"
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
Object.defineProperty(exports, '__esModule', {
value: true
});
//# sourceMappingURL=build-webpack-assets-map.js.map