@ts-intl/dependency
Version:
I18n keys dependency analysis
43 lines (42 loc) • 2.71 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getDependencies = void 0;
const promises_1 = require("fs/promises");
const path_1 = require("path");
const actions_1 = require("./actions");
const extractIntlKeysFromCode_1 = require("./compiler/extractIntlKeysFromCode");
const utils_1 = require("./utils");
const getDependencies = (statuses, entries, opts, ctx, extractIntlKeysOpts) => __awaiter(void 0, void 0, void 0, function* () {
const { madgeConfig, extractIntlKeys } = opts, rest = __rest(opts, ["madgeConfig", "extractIntlKeys"]);
const mergedOpts = Object.assign(Object.assign({}, rest), { madgeConfig: (0, utils_1.mergeMadgeConfig)(madgeConfig), extractIntlKeys: extractIntlKeys !== null && extractIntlKeys !== void 0 ? extractIntlKeys : ((module) => __awaiter(void 0, void 0, void 0, function* () {
return (0, extractIntlKeysFromCode_1.extractIntlKeysFromCode)(yield (0, promises_1.readFile)((0, path_1.resolve)(opts.madgeConfig.baseDir, module), 'utf-8'), extractIntlKeysOpts !== null && extractIntlKeysOpts !== void 0 ? extractIntlKeysOpts : { funcNamePattern: '' });
})) });
const { graph, pathIntlKeysMap } = yield (0, actions_1.applyActions)(statuses, mergedOpts, ctx);
const modules = entries.map((m) => (0, path_1.relative)(madgeConfig.baseDir, m));
return {
graph,
pathIntlKeysMap: (0, utils_1.extractPathIntlKeysMap)(modules, graph, pathIntlKeysMap, true),
modules,
};
});
exports.getDependencies = getDependencies;