Repository URL to install this package:
|
Version:
0.0.7 ▾
|
import { resolve } from 'path';
import { readJSON } from '@aretecode/flipfile';
import { getClientBundleEntryAssets, getConfigForEnv } from '../../aliased';
import { logger } from '../../log';
const clientEntryAssets = getClientBundleEntryAssets();
export const indexedCompatMap = new Map();
// used to remove the hash
export function fromPathToKey(relativePath) {
const pieces = relativePath.split('-');
pieces.pop();
const key = pieces.join('-');
return key;
}
export function tryToLoadCompatEntryAssets() {
try {
// => '/dist/bundled/client'
const assetDir = getConfigForEnv('assetsDir');
// => 'assets.json'
const assetFileName = getConfigForEnv('bundleAssetsFileName');
// => '/dist/bundled/client/assets.json'
const assetFilePathRelative = `${assetDir}/${assetFileName}`.replace('client', 'compat');
const assetFilePathAbsolute = resolve(assetFilePathRelative);
logger.info('[compat] assetFilePathAbsolute', assetFilePathAbsolute);
const compatEntryAssetsManifest = readJSON(assetFilePathAbsolute);
console.log({ compatEntryAssetsManifest });
const compatRelativePaths = Object.values(compatEntryAssetsManifest);
compatRelativePaths
.filter(x => !!x)
.map(relativePath => relativePath.js || relativePath || '')
.forEach((relativePath) => {
const key = fromPathToKey(relativePath);
const compatPath = relativePath.replace('client', 'compat');
indexedCompatMap.set(key, compatPath);
});
// @note - pino doesn't log maps properly
console.log({ indexedCompatMap });
// logger.info('[compat] indexedCompatMap', indexedCompatMap)
}
catch (failed) {
logger.error(failed);
}
}
tryToLoadCompatEntryAssets();
export const fromClientPathToCompatPath = (jsPath) => {
const key = fromPathToKey(jsPath);
const found = indexedCompatMap.get(key);
logger.info(`[compat] added compat url: ${jsPath}; key: ${key}; path: ${found} `);
if (indexedCompatMap.has(key)) {
return found;
}
else {
logger.error('[compat] missing compat url!!! ' + key);
logger.info(indexedCompatMap);
return jsPath;
}
};
//# sourceMappingURL=compat.js.map