All files / packages/design-system/scripts/helpers css-options.js

0% Statements 0/10
0% Branches 0/6
0% Functions 0/2
0% Lines 0/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63                                                                                                                             
// Copyright (c) 2015-present, salesforce.com, inc. All rights reserved
// Licensed under BSD 3-Clause - see LICENSE.txt or git.io/sfdc-license
 
/*
 * Sass / PostCSS / Prettier settings shared by the gulp stream helpers
 * (./gulp.js) and the sanitized-component worker threads. Plain CommonJS so
 * worker threads can load it without @babel/register.
 */
 
const autoprefixer = require('autoprefixer');
const discardEmpty = require('postcss-discard-empty');
const paths = require('./paths');
 
// Dart Sass 1.80+ emits future-deprecation warnings for language features the
// SLDS SCSS still relies on (@import, the global if()/color builtins). Migrating
// off them (@use/@forward, sass:list, etc.) is a large, separate effort; until
// then, silence just these known categories so the build console stays readable.
// Scoped to specific IDs so genuinely new deprecations still surface.
const SILENCED_SASS_DEPRECATIONS = ['import', 'global-builtin', 'if-function'];
 
const sassOptions = ({ outputStyle, includePaths, ...options } = {}) => ({
  // gulp-sass v6 uses the modern Dart Sass API: `includePaths` → `loadPaths`,
  // `outputStyle` → `style`. (Legacy `precision` is gone — Dart Sass fixes it.)
  // The legacy API implicitly resolved bare imports (e.g. `dist/scss/init`)
  // against the CWD/package root; the modern API needs `paths.root` explicitly.
  loadPaths: includePaths || [paths.root, paths.ui, paths.node_modules],
  silenceDeprecations: SILENCED_SASS_DEPRECATIONS,
  ...(outputStyle ? { style: outputStyle } : {}),
  ...options,
});
 
const postCssPlugins = (bonusPlugins = []) => [
  autoprefixer({ remove: false }),
  ...bonusPlugins,
  // Dart Sass 1.7x+ emits empty rule blocks (e.g. `.slds-input {}`) for
  // selectors whose declarations are all nested/hoisted elsewhere; older Sass
  // omitted them. Strip them last (after any discardComments in bonusPlugins,
  // so comment-only rules are already emptied) to keep dist output clean and
  // stable across Sass versions.
  discardEmpty(),
];
 
const PRETTIER_CSS_OPTIONS = {
  arrowParens: 'avoid',
  bracketSpacing: true,
  htmlWhitespaceSensitivity: 'css',
  printWidth: 120,
  proseWrap: 'always',
  quoteProps: 'as-needed',
  semi: true,
  singleQuote: false,
  tabWidth: 2,
  trailingComma: 'none',
  useTabs: false,
};
 
module.exports = {
  SILENCED_SASS_DEPRECATIONS,
  sassOptions,
  postCssPlugins,
  PRETTIER_CSS_OPTIONS,
};