1 | "use strict";
|
2 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
3 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
4 | };
|
5 | Object.defineProperty(exports, "__esModule", { value: true });
|
6 | exports.StylesheetProcessor = exports.CssUrl = void 0;
|
7 | const browserslist_1 = __importDefault(require("browserslist"));
|
8 | const fs_1 = require("fs");
|
9 | const path_1 = require("path");
|
10 | const piscina_1 = __importDefault(require("piscina"));
|
11 | const color_1 = require("../utils/color");
|
12 | const postcss_configuration_1 = require("./postcss-configuration");
|
13 | const maxWorkersVariable = process.env['NG_BUILD_MAX_WORKERS'];
|
14 | const maxThreads = typeof maxWorkersVariable === 'string' && maxWorkersVariable !== '' ? +maxWorkersVariable : 4;
|
15 | var CssUrl;
|
16 | (function (CssUrl) {
|
17 | CssUrl["inline"] = "inline";
|
18 | CssUrl["none"] = "none";
|
19 | })(CssUrl || (exports.CssUrl = CssUrl = {}));
|
20 | class StylesheetProcessor {
|
21 | constructor(projectBasePath, basePath, cssUrl, includePaths, cacheDirectory) {
|
22 | this.projectBasePath = projectBasePath;
|
23 | this.basePath = basePath;
|
24 | this.cssUrl = cssUrl;
|
25 | this.includePaths = includePaths;
|
26 | this.cacheDirectory = cacheDirectory;
|
27 |
|
28 |
|
29 |
|
30 |
|
31 | browserslist_1.default.defaults = [
|
32 | 'last 2 Chrome versions',
|
33 | 'last 1 Firefox version',
|
34 | 'last 2 Edge major versions',
|
35 | 'last 2 Safari major versions',
|
36 | 'last 2 iOS major versions',
|
37 | 'Firefox ESR',
|
38 | ];
|
39 | }
|
40 | async process({ filePath, content }) {
|
41 | this.createRenderWorker();
|
42 | return this.renderWorker.run({ content, filePath });
|
43 | }
|
44 |
|
45 | destroy() {
|
46 | var _a;
|
47 | void ((_a = this.renderWorker) === null || _a === void 0 ? void 0 : _a.destroy());
|
48 | }
|
49 | createRenderWorker() {
|
50 |
|
51 | if (this.renderWorker) {
|
52 | return;
|
53 | }
|
54 | const styleIncludePaths = [...this.includePaths];
|
55 | let prevDir = null;
|
56 | let currentDir = this.basePath;
|
57 | while (currentDir !== prevDir) {
|
58 | const p = (0, path_1.join)(currentDir, 'node_modules');
|
59 | if ((0, fs_1.existsSync)(p)) {
|
60 | styleIncludePaths.push(p);
|
61 | }
|
62 | prevDir = currentDir;
|
63 | currentDir = (0, path_1.dirname)(prevDir);
|
64 | }
|
65 | const browserslistData = (0, browserslist_1.default)(undefined, { path: this.basePath });
|
66 | const searchDirs = (0, postcss_configuration_1.generateSearchDirectories)([this.projectBasePath]);
|
67 | this.renderWorker = new piscina_1.default({
|
68 | filename: require.resolve('./stylesheet-processor-worker'),
|
69 | maxThreads,
|
70 | recordTiming: false,
|
71 | env: {
|
72 | ...process.env,
|
73 | FORCE_COLOR: '' + color_1.colors.enabled,
|
74 | },
|
75 | workerData: {
|
76 | postcssConfiguration: (0, postcss_configuration_1.loadPostcssConfiguration)(searchDirs),
|
77 | tailwindConfigPath: (0, postcss_configuration_1.findTailwindConfiguration)(searchDirs),
|
78 | projectBasePath: this.projectBasePath,
|
79 | browserslistData,
|
80 | targets: transformSupportedBrowsersToTargets(browserslistData),
|
81 | cacheDirectory: this.cacheDirectory,
|
82 | cssUrl: this.cssUrl,
|
83 | styleIncludePaths,
|
84 | },
|
85 | });
|
86 | }
|
87 | }
|
88 | exports.StylesheetProcessor = StylesheetProcessor;
|
89 | function transformSupportedBrowsersToTargets(supportedBrowsers) {
|
90 | const transformed = [];
|
91 |
|
92 | const esBuildSupportedBrowsers = new Set(['safari', 'firefox', 'edge', 'chrome', 'ios']);
|
93 | for (const browser of supportedBrowsers) {
|
94 | let [browserName, version] = browser.split(' ');
|
95 |
|
96 | if (browserName === 'ios_saf') {
|
97 | browserName = 'ios';
|
98 | }
|
99 |
|
100 |
|
101 | [version] = version.split('-');
|
102 | if (esBuildSupportedBrowsers.has(browserName)) {
|
103 | if (browserName === 'safari' && version === 'tp') {
|
104 |
|
105 |
|
106 | version = '999';
|
107 | }
|
108 | transformed.push(browserName + version);
|
109 | }
|
110 | }
|
111 | return transformed.length ? transformed : undefined;
|
112 | }
|
113 |
|
\ | No newline at end of file |