UNPKG

ng-packagr

Version:

Compile and package Angular libraries in Angular Package Format (APF)

74 lines 3.73 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.StylesheetProcessor = exports.CssUrl = void 0; const browserslist_1 = __importDefault(require("browserslist")); const component_stylesheets_1 = require("./component-stylesheets"); const postcss_configuration_1 = require("./postcss-configuration"); var CssUrl; (function (CssUrl) { CssUrl["inline"] = "inline"; CssUrl["none"] = "none"; })(CssUrl || (exports.CssUrl = CssUrl = {})); class StylesheetProcessor extends component_stylesheets_1.ComponentStylesheetBundler { constructor(projectBasePath, basePath, cssUrl, includePaths, sass, cacheDirectory, watch) { // By default, browserslist defaults are too inclusive // https://github.com/browserslist/browserslist/blob/83764ea81ffaa39111c204b02c371afa44a4ff07/index.js#L516-L522 // We change the default query to browsers that Angular support. // https://angular.dev/reference/versions#browser-support browserslist_1.default.defaults = (0, browserslist_1.default)(undefined, { path: require.resolve('../../../.browserslistrc'), }); const browserslistData = (0, browserslist_1.default)(undefined, { path: basePath }); const searchDirs = (0, postcss_configuration_1.generateSearchDirectories)([projectBasePath]); const postcssConfiguration = (0, postcss_configuration_1.loadPostcssConfiguration)(searchDirs); super({ cacheDirectory: cacheDirectory, postcssConfiguration: postcssConfiguration, tailwindConfiguration: postcssConfiguration ? undefined : (0, postcss_configuration_1.getTailwindConfig)(searchDirs, projectBasePath), sass: sass, workspaceRoot: projectBasePath, cssUrl: cssUrl, target: transformSupportedBrowsersToTargets(browserslistData), includePaths: includePaths, }, 'css', watch); this.projectBasePath = projectBasePath; this.basePath = basePath; this.cssUrl = cssUrl; this.includePaths = includePaths; this.sass = sass; this.cacheDirectory = cacheDirectory; this.watch = watch; } destroy() { void super.dispose(); } } exports.StylesheetProcessor = StylesheetProcessor; function transformSupportedBrowsersToTargets(supportedBrowsers) { const transformed = []; // https://esbuild.github.io/api/#target const esBuildSupportedBrowsers = new Set(['safari', 'firefox', 'edge', 'chrome', 'ios']); for (const browser of supportedBrowsers) { let [browserName, version] = browser.split(' '); // browserslist uses the name `ios_saf` for iOS Safari whereas esbuild uses `ios` if (browserName === 'ios_saf') { browserName = 'ios'; } // browserslist uses ranges `15.2-15.3` versions but only the lowest is required // to perform minimum supported feature checks. esbuild also expects a single version. [version] = version.split('-'); if (esBuildSupportedBrowsers.has(browserName)) { if (browserName === 'safari' && version === 'tp') { // esbuild only supports numeric versions so `TP` is converted to a high number (999) since // a Technology Preview (TP) of Safari is assumed to support all currently known features. version = '999'; } transformed.push(browserName + version); } } return transformed.length ? transformed : undefined; } //# sourceMappingURL=stylesheet-processor.js.map