1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
10 | if (k2 === undefined) k2 = k;
|
11 | var desc = Object.getOwnPropertyDescriptor(m, k);
|
12 | if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
13 | desc = { enumerable: true, get: function() { return m[k]; } };
|
14 | }
|
15 | Object.defineProperty(o, k2, desc);
|
16 | }) : (function(o, m, k, k2) {
|
17 | if (k2 === undefined) k2 = k;
|
18 | o[k2] = m[k];
|
19 | }));
|
20 | var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
21 | Object.defineProperty(o, "default", { enumerable: true, value: v });
|
22 | }) : function(o, v) {
|
23 | o["default"] = v;
|
24 | });
|
25 | var __importStar = (this && this.__importStar) || function (mod) {
|
26 | if (mod && mod.__esModule) return mod;
|
27 | var result = {};
|
28 | if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
29 | __setModuleDefault(result, mod);
|
30 | return result;
|
31 | };
|
32 | Object.defineProperty(exports, "__esModule", { value: true });
|
33 | const nodePath = __importStar(require("path"));
|
34 | const load_esm_1 = require("../../utils/load-esm");
|
35 | function localizeExtractLoader(content, map) {
|
36 |
|
37 |
|
38 |
|
39 | this.cacheable(false);
|
40 | const options = this.getOptions();
|
41 | const callback = this.async();
|
42 | extract(this, content, map, options).then(() => {
|
43 |
|
44 | callback(undefined, content, map);
|
45 | }, (error) => {
|
46 | callback(error);
|
47 | });
|
48 | }
|
49 | exports.default = localizeExtractLoader;
|
50 | async function extract(loaderContext, content, map, options) {
|
51 |
|
52 |
|
53 |
|
54 | let MessageExtractor;
|
55 | try {
|
56 |
|
57 |
|
58 |
|
59 | const localizeToolsModule = await (0, load_esm_1.loadEsmModule)('@angular/localize/tools');
|
60 | MessageExtractor = localizeToolsModule.MessageExtractor;
|
61 | }
|
62 | catch {
|
63 | throw new Error(`Unable to load message extractor. Please ensure '@angular/localize' is installed.`);
|
64 | }
|
65 |
|
66 | const logger = {
|
67 |
|
68 | level: 2,
|
69 | debug(...args) {
|
70 |
|
71 | console.debug(...args);
|
72 | },
|
73 | info(...args) {
|
74 | loaderContext.emitWarning(new Error(args.join('')));
|
75 | },
|
76 | warn(...args) {
|
77 | loaderContext.emitWarning(new Error(args.join('')));
|
78 | },
|
79 | error(...args) {
|
80 | loaderContext.emitError(new Error(args.join('')));
|
81 | },
|
82 | };
|
83 | let filename = loaderContext.resourcePath;
|
84 | const mapObject = typeof map === 'string' ? JSON.parse(map) : map;
|
85 | if (mapObject === null || mapObject === void 0 ? void 0 : mapObject.file) {
|
86 |
|
87 | filename = nodePath.join(loaderContext.context, mapObject.file);
|
88 | }
|
89 |
|
90 |
|
91 |
|
92 | const filesystem = {
|
93 | readFile(path) {
|
94 | if (path === filename) {
|
95 | return content;
|
96 | }
|
97 | else if (path === filename + '.map') {
|
98 | return typeof map === 'string' ? map : JSON.stringify(map);
|
99 | }
|
100 | else {
|
101 | throw new Error('Unknown file requested: ' + path);
|
102 | }
|
103 | },
|
104 | relative(from, to) {
|
105 | return nodePath.relative(from, to);
|
106 | },
|
107 | resolve(...paths) {
|
108 | return nodePath.resolve(...paths);
|
109 | },
|
110 | exists(path) {
|
111 | return path === filename || path === filename + '.map';
|
112 | },
|
113 | dirname(path) {
|
114 | return nodePath.dirname(path);
|
115 | },
|
116 | };
|
117 |
|
118 | const extractor = new MessageExtractor(filesystem, logger, {
|
119 |
|
120 | basePath: loaderContext.rootContext,
|
121 | useSourceMaps: !!map,
|
122 | });
|
123 | const messages = extractor.extractMessages(filename);
|
124 | if (messages.length > 0) {
|
125 | options === null || options === void 0 ? void 0 : options.messageHandler(messages);
|
126 | }
|
127 | }
|