balm-core 4.10.0 → 4.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (108) hide show
  1. package/lib/balm.js +0 -20
  2. package/lib/bootstrap/check_config.js +6 -9
  3. package/lib/bootstrap/index.js +16 -22
  4. package/lib/bundler/esbuild/build.js +0 -2
  5. package/lib/bundler/esbuild/index.js +0 -2
  6. package/lib/bundler/esbuild/transform.js +0 -4
  7. package/lib/bundler/rollup/build.js +2 -4
  8. package/lib/bundler/rollup/entry.js +2 -5
  9. package/lib/bundler/rollup/index.js +0 -3
  10. package/lib/bundler/rollup/output.js +0 -5
  11. package/lib/bundler/rollup/plugins.js +0 -10
  12. package/lib/bundler/webpack/config/common.js +4 -15
  13. package/lib/bundler/webpack/config/dev.js +2 -3
  14. package/lib/bundler/webpack/config/env.js +12 -14
  15. package/lib/bundler/webpack/config/index.js +0 -2
  16. package/lib/bundler/webpack/config/prod.js +4 -7
  17. package/lib/bundler/webpack/entry.js +8 -12
  18. package/lib/bundler/webpack/index.js +2 -5
  19. package/lib/bundler/webpack/loaders.js +0 -6
  20. package/lib/bundler/webpack/output.js +0 -5
  21. package/lib/bundler/webpack/rules/asset.js +2 -3
  22. package/lib/bundler/webpack/rules/babel.js +3 -4
  23. package/lib/bundler/webpack/rules/css.js +4 -10
  24. package/lib/bundler/webpack/rules/html.js +0 -2
  25. package/lib/config/assets.js +0 -5
  26. package/lib/config/env.js +0 -2
  27. package/lib/config/globals.js +2 -5
  28. package/lib/config/index.js +0 -5
  29. package/lib/config/logs.js +0 -1
  30. package/lib/config/paths.js +3 -3
  31. package/lib/config/pwa.js +0 -3
  32. package/lib/config/roots.js +0 -2
  33. package/lib/config/scripts.js +20 -28
  34. package/lib/config/server.js +4 -10
  35. package/lib/config/styles.js +2 -10
  36. package/lib/hello.js +0 -2
  37. package/lib/hooks/index.js +18 -35
  38. package/lib/hooks/maker.js +0 -14
  39. package/lib/middlewares/history.js +0 -2
  40. package/lib/middlewares/index.js +0 -4
  41. package/lib/middlewares/proxy.js +0 -6
  42. package/lib/middlewares/webpack.js +0 -5
  43. package/lib/plugins/htmlmin.js +1 -7
  44. package/lib/plugins/imagemin.js +1 -18
  45. package/lib/plugins/jsmin.js +0 -10
  46. package/lib/plugins/less.js +7 -14
  47. package/lib/plugins/plumber.js +4 -21
  48. package/lib/plugins/postcss-plugins.js +0 -2
  49. package/lib/plugins/postcss.js +8 -21
  50. package/lib/plugins/rename.js +2 -13
  51. package/lib/plugins/replace.js +4 -22
  52. package/lib/plugins/sass.js +30 -39
  53. package/lib/plugins/sftp.js +33 -62
  54. package/lib/tasks/default.js +10 -19
  55. package/lib/tasks/foundation/balm.js +0 -25
  56. package/lib/tasks/foundation/balm_style.js +2 -15
  57. package/lib/tasks/foundation/index.js +0 -2
  58. package/lib/tasks/index.js +8 -7
  59. package/lib/tasks/private/build.js +0 -5
  60. package/lib/tasks/private/cache.js +0 -6
  61. package/lib/tasks/private/clean.js +0 -20
  62. package/lib/tasks/private/end.js +0 -6
  63. package/lib/tasks/private/extra.js +4 -11
  64. package/lib/tasks/private/font.js +0 -5
  65. package/lib/tasks/private/image.js +0 -11
  66. package/lib/tasks/private/lint.js +0 -5
  67. package/lib/tasks/private/media.js +0 -5
  68. package/lib/tasks/private/modernizr.js +0 -19
  69. package/lib/tasks/private/pwa-cache.js +0 -7
  70. package/lib/tasks/private/script.js +0 -3
  71. package/lib/tasks/private/sprite.js +3 -25
  72. package/lib/tasks/private/start.js +0 -6
  73. package/lib/tasks/private/style.js +0 -3
  74. package/lib/tasks/private/workbox-sw.js +0 -5
  75. package/lib/tasks/public/copy.js +0 -5
  76. package/lib/tasks/public/esbuild.js +0 -6
  77. package/lib/tasks/public/ftp.js +0 -11
  78. package/lib/tasks/public/html.js +0 -20
  79. package/lib/tasks/public/jsmin.js +0 -6
  80. package/lib/tasks/public/less.js +0 -6
  81. package/lib/tasks/public/postcss.js +0 -5
  82. package/lib/tasks/public/publish.js +3 -15
  83. package/lib/tasks/public/pwa.js +0 -13
  84. package/lib/tasks/public/remove.js +2 -18
  85. package/lib/tasks/public/replace.js +0 -7
  86. package/lib/tasks/public/rollup.js +0 -6
  87. package/lib/tasks/public/sass.js +0 -6
  88. package/lib/tasks/public/server.js +4 -32
  89. package/lib/tasks/public/url.js +0 -13
  90. package/lib/tasks/public/version.js +0 -6
  91. package/lib/tasks/public/webpack.js +2 -12
  92. package/lib/tasks/public/zip.js +0 -5
  93. package/lib/utilities/address.js +5 -16
  94. package/lib/utilities/cache-core.js +5 -13
  95. package/lib/utilities/color.js +0 -5
  96. package/lib/utilities/compiling.js +0 -14
  97. package/lib/utilities/detect-port.js +6 -22
  98. package/lib/utilities/escape-string-regexp.js +3 -4
  99. package/lib/utilities/file.js +2 -18
  100. package/lib/utilities/loading.js +0 -23
  101. package/lib/utilities/logger.js +0 -19
  102. package/lib/utilities/merge-stream.js +0 -8
  103. package/lib/utilities/namespace.js +0 -4
  104. package/lib/utilities/public-url.js +10 -10
  105. package/lib/utilities/replacestream.js +5 -27
  106. package/lib/utilities/typeof.js +0 -2
  107. package/lib/utilities/utils.js +2 -9
  108. package/package.json +30 -30
@@ -1,111 +1,94 @@
1
1
  import Maker from './maker.js';
2
-
3
2
  class BaseHooks {
4
3
  get env() {
5
4
  return BalmJS.config.env;
6
- } // HTML
7
-
5
+ }
8
6
 
7
+ // HTML
9
8
  html(input, output) {
10
9
  Maker.generate('html', [input, output]);
11
- } // Stylesheets
12
-
10
+ }
13
11
 
12
+ // Stylesheets
14
13
  css(input, output) {
15
14
  Maker.generate('postcss', [input, output]);
16
15
  }
17
-
18
16
  sass(input, output, options) {
19
17
  Maker.generate('sass', [input, output, options]);
20
18
  }
21
-
22
19
  less(input, output, options) {
23
20
  Maker.generate('less', [input, output, options]);
24
21
  }
25
-
26
22
  url(input, output) {
27
23
  Maker.generate('url', [input, output]);
28
- } // JavaScript
29
-
24
+ }
30
25
 
26
+ // JavaScript
31
27
  js() {
32
28
  BalmJS.logger.warn('balm api', '`mix.js` is deprecated, please use `mix.webpack`/`mix.rollup`/`mix.esbuild` instead.');
33
29
  }
34
-
35
30
  webpack(input, output, options, fn) {
36
31
  Maker.generate('webpack', [input, output, options, fn]);
37
32
  }
38
-
39
33
  esbuild(input, output, options) {
40
34
  Maker.generate('esbuild', [input, output, options]);
41
35
  }
42
-
43
36
  rollup(input, output) {
44
37
  Maker.generate('rollup', [input, output]);
45
38
  }
46
-
47
39
  jsmin(input, output, options) {
48
40
  Maker.generate('jsmin', [input, output, options]);
49
- } // Files & Directories
50
-
41
+ }
51
42
 
43
+ // Files & Directories
52
44
  copy(input, output, options) {
53
45
  Maker.generate('copy', [input, output, options]);
54
46
  }
55
-
56
47
  remove(paths) {
57
48
  Maker.generate('remove', [paths]);
58
- } // Cache
59
-
49
+ }
60
50
 
51
+ // Cache
61
52
  version(input, output, assetsOptions) {
62
53
  Maker.generate('version', [input, output, assetsOptions]);
63
- } // Server
64
-
54
+ }
65
55
 
56
+ // Server
66
57
  serve(handler) {
67
58
  Maker.generate('serve', [handler]);
68
59
  }
69
-
70
60
  }
71
-
72
61
  class BalmHooks extends BaseHooks {
73
62
  // Stylesheets
74
63
  sprite(input, output, spriteOptions) {
75
64
  Maker.generate('sprite', [input, output, spriteOptions]);
76
- } // Assets
77
-
65
+ }
78
66
 
67
+ // Assets
79
68
  replace(input, output, options) {
80
69
  Maker.generate('replace', [input, output, options]);
81
70
  }
82
-
83
71
  publish(input, output, renameOptions) {
84
72
  Maker.generate('publish', [input, output, renameOptions]);
85
73
  }
86
-
87
74
  zip(input = '', output = '', filename = 'archive.zip') {
88
75
  Maker.generate('zip', [input, output, filename]);
89
76
  }
90
-
91
77
  ftp(localFiles, options) {
92
78
  Maker.generate('ftp', [localFiles, options]);
93
- } // PWA
94
-
79
+ }
95
80
 
81
+ // PWA
96
82
  generateSW(pwaOptions) {
97
83
  Maker.generate('pwa', ['generateSW', pwaOptions]);
98
84
  }
99
-
100
85
  injectManifest(pwaOptions) {
101
86
  Maker.generate('pwa', ['injectManifest', pwaOptions]);
102
- } // Others
103
-
87
+ }
104
88
 
89
+ // Others
105
90
  modernizr() {
106
91
  Maker.generate('modernizr');
107
92
  }
108
-
109
93
  }
110
-
111
94
  export default BalmHooks;
@@ -1,58 +1,46 @@
1
1
  const BLOCKLIST_IN_PROD = ['serve'];
2
2
  let compiling = false;
3
-
4
3
  function ban(name) {
5
4
  const BLOCKLIST_IN_DEV = ['publish', ...(BalmJS.config.useDefaults ? BLOCKLIST_IN_PROD : [])];
6
5
  const banInProd = BalmJS.config.env.isProd && BLOCKLIST_IN_PROD.includes(name);
7
6
  const banInDev = BalmJS.config.env.isDev && BLOCKLIST_IN_DEV.includes(name);
8
7
  const isBan = banInProd || banInDev;
9
8
  const api = name === 'postcss' ? 'css' : name;
10
-
11
9
  if (isBan) {
12
10
  const message = BalmJS.config.useDefaults && BalmJS.config.env.isDev && BLOCKLIST_IN_PROD.includes(name) ? `'mix.${api}()' can only be used for 'balm.config.useDefaults = false;'` : `There is no 'mix.${api}()' hook in ${banInProd ? 'production' : 'development'} mode`;
13
11
  BalmJS.logger.warn('balm hook', message);
14
12
  }
15
-
16
13
  return isBan;
17
14
  }
18
-
19
15
  class Maker {
20
16
  // Register custom task
21
17
  static generate(name, args = []) {
22
18
  if (ban(name)) {
23
19
  return;
24
20
  }
25
-
26
21
  const customTask = BalmJS.tasks.get(name);
27
22
  const taskName = ['sprite', ...BLOCKLIST_IN_PROD].includes(customTask.name) ? customTask.name : `${customTask.name}:${BalmJS.recipeIndex}`;
28
-
29
23
  let balmTask = callback => {
30
24
  callback();
31
25
  }; // NOTE: `balmTask` function name for `gulp.parallel`
32
26
 
33
-
34
27
  switch (customTask.name) {
35
28
  // private
36
29
  case 'sprite':
37
30
  customTask.recipe(...args);
38
-
39
31
  if (customTask.deps.length) {
40
32
  balmTask = gulp.series(...BalmJS.toNamespace(customTask.deps));
41
33
  } else {
42
34
  BalmJS.logger.warn('balm hook', '`mix.sprite()` is missing `input` parameters');
43
35
  }
44
-
45
36
  break;
46
-
47
37
  case 'modernizr':
48
38
  balmTask = customTask.fn;
49
39
  break;
50
40
  // public
51
-
52
41
  default:
53
42
  balmTask = customTask.recipe(...args);
54
43
  }
55
-
56
44
  if (BalmJS.watching) {
57
45
  if (!compiling) {
58
46
  compiling = true;
@@ -67,7 +55,5 @@ class Maker {
67
55
  BalmJS.recipeIndex++;
68
56
  }
69
57
  }
70
-
71
58
  }
72
-
73
59
  export default Maker;
@@ -1,8 +1,6 @@
1
1
  import history from 'connect-history-api-fallback';
2
-
3
2
  function historyMiddleware() {
4
3
  const historyOptions = BalmJS.config.server.historyOptions;
5
4
  return historyOptions ? [BalmJS.utils.isObject(historyOptions) ? history(historyOptions) : history()] : [];
6
5
  }
7
-
8
6
  export default historyMiddleware;
@@ -1,15 +1,11 @@
1
1
  import webpackMiddleware from './webpack.js';
2
2
  import httpProxyMiddleware from './proxy.js';
3
3
  import historyMiddleware from './history.js';
4
-
5
4
  function getMiddlewares() {
6
5
  const canOverride = BalmJS.config.server.middlewares.every(middleware => BalmJS.utils.isFunction(middleware) || BalmJS.utils.isObject(middleware));
7
-
8
6
  if (!canOverride) {
9
7
  BalmJS.logger.error('server middleware', 'Server middleware must be a function (`function (req, res, next) {}`) or object (`{ route: "/api", handle: function (req, res, next) {} }`)');
10
8
  }
11
-
12
9
  return [...(BalmJS.config.scripts.bundler === BalmJS.Bundler.webpack ? webpackMiddleware() : []), ...httpProxyMiddleware(), ...historyMiddleware(), ...(canOverride ? BalmJS.config.server.middlewares : [])];
13
10
  }
14
-
15
11
  export default getMiddlewares;
@@ -1,20 +1,16 @@
1
1
  import { createProxyMiddleware } from 'http-proxy-middleware';
2
-
3
2
  function handleProxyConfigError() {
4
3
  const configuration = '{ context: string | array, options: object }';
5
4
  BalmJS.logger.error('proxy middleware', `Proxy config must be an object (${configuration}) or array ([${configuration}])`);
6
5
  }
7
-
8
6
  function httpProxyMiddleware() {
9
7
  const middleware = [];
10
8
  const proxyConfig = BalmJS.config.server.proxyConfig;
11
-
12
9
  if (proxyConfig) {
13
10
  try {
14
11
  if (BalmJS.utils.isObject(proxyConfig)) {
15
12
  // Single proxy
16
13
  const config = proxyConfig;
17
-
18
14
  if (config.context && config.options) {
19
15
  middleware.push(createProxyMiddleware(config.context, config.options));
20
16
  } else {
@@ -39,8 +35,6 @@ function httpProxyMiddleware() {
39
35
  BalmJS.logger.error('proxy middleware', message);
40
36
  }
41
37
  }
42
-
43
38
  return middleware;
44
39
  }
45
-
46
40
  export default httpProxyMiddleware;
@@ -1,10 +1,8 @@
1
1
  import webpackDevMiddleware from 'webpack-dev-middleware';
2
2
  import webpackHotMiddleware from 'webpack-hot-middleware';
3
3
  import { HMR_PATH } from '../config/constants.js';
4
-
5
4
  function webpackMiddleware() {
6
5
  const middleware = [];
7
-
8
6
  if (BalmJS.webpackCompiler) {
9
7
  middleware.push(webpackDevMiddleware(BalmJS.webpackCompiler, Object.assign({}, BalmJS.config.server.devOptions, {
10
8
  headers: [{
@@ -14,7 +12,6 @@ function webpackMiddleware() {
14
12
  publicPath: BalmJS.file.publicUrlOrPath,
15
13
  stats: false
16
14
  })));
17
-
18
15
  if (BalmJS.config.server.useHMR) {
19
16
  middleware.push(webpackHotMiddleware(BalmJS.webpackCompiler, {
20
17
  log: false,
@@ -24,8 +21,6 @@ function webpackMiddleware() {
24
21
  } else {
25
22
  BalmJS.logger.warn('webpack middleware', 'Webpack compiler is not ready');
26
23
  }
27
-
28
24
  return middleware;
29
25
  }
30
-
31
26
  export default webpackMiddleware;
@@ -1,20 +1,17 @@
1
1
  // Reference `gulp-htmlmin@5.0.1`
2
+
2
3
  import { minify } from 'html-minifier';
3
4
  const PLUGIN_NAME = 'htmlmin';
4
-
5
5
  function gulpHtmlmin(options) {
6
6
  options = BalmJS.utils.deepMerge({}, options);
7
-
8
7
  function transform(file, encoding, callback) {
9
8
  if (file.isNull()) {
10
9
  callback(null, file);
11
10
  return;
12
11
  }
13
-
14
12
  function htmlMinify(buf, enc, cb) {
15
13
  try {
16
14
  const contents = Buffer.from(minify(buf.toString(), options));
17
-
18
15
  if (cb === callback) {
19
16
  file.contents = contents;
20
17
  cb(null, file);
@@ -30,15 +27,12 @@ function gulpHtmlmin(options) {
30
27
  cb === callback ? cb(error) : callback(error);
31
28
  }
32
29
  }
33
-
34
30
  if (file.isStream()) {
35
31
  file.contents = file.contents.pipe(through2(htmlMinify));
36
32
  } else {
37
33
  htmlMinify(file.contents, null, callback);
38
34
  }
39
35
  }
40
-
41
36
  return through2.obj(transform);
42
37
  }
43
-
44
38
  export default gulpHtmlmin;
@@ -1,10 +1,10 @@
1
1
  // Reference `gulp-imagemin@8.0.0`
2
+
2
3
  import imagemin from 'imagemin';
3
4
  import prettyBytes from 'pretty-bytes';
4
5
  import through2Concurrent from 'through2-concurrent';
5
6
  const PLUGIN_NAME = 'imagemin';
6
7
  const defaultPlugins = ['gifsicle', 'mozjpeg', 'optipng', 'svgo'];
7
-
8
8
  const loadPlugin = (plugin, ...args) => {
9
9
  try {
10
10
  return requireModule(`imagemin-${plugin}`)(...args);
@@ -12,36 +12,28 @@ const loadPlugin = (plugin, ...args) => {
12
12
  BalmJS.logger.error(PLUGIN_NAME, `Couldn't load default plugin "${plugin}"`);
13
13
  }
14
14
  };
15
-
16
15
  const exposePlugin = plugin => (...args) => loadPlugin(plugin, ...args);
17
-
18
16
  const getDefaultPlugins = () => defaultPlugins.flatMap(plugin => loadPlugin(plugin));
19
-
20
17
  const gulpImagemin = customPlugins => {
21
18
  const validExtensions = new Set(['.jpg', '.jpeg', '.png', '.gif', '.svg']);
22
19
  let totalBytes = 0;
23
20
  let totalSavedBytes = 0;
24
21
  let totalFiles = 0;
25
-
26
22
  function transform(file, encoding, callback) {
27
23
  if (file.isNull()) {
28
24
  callback(null, file);
29
25
  return;
30
26
  }
31
-
32
27
  if (file.isStream()) {
33
28
  callback(new PluginError(PLUGIN_NAME, 'Streaming not supported'));
34
29
  return;
35
30
  }
36
-
37
31
  if (!validExtensions.has(node.path.extname(file.path).toLowerCase())) {
38
32
  BalmJS.logger.info(PLUGIN_NAME, `Skipping unsupported image "${file.relative}"`);
39
33
  callback(null, file);
40
34
  return;
41
35
  }
42
-
43
36
  const plugins = customPlugins || getDefaultPlugins();
44
-
45
37
  (async () => {
46
38
  try {
47
39
  const data = await imagemin.buffer(file.contents, {
@@ -53,13 +45,11 @@ const gulpImagemin = customPlugins => {
53
45
  const percent = originalSize > 0 ? saved / originalSize * 100 : 0;
54
46
  const savedMessage = `saved ${prettyBytes(saved)} - ${percent.toFixed(1).replace(/\.0$/, '')}%`;
55
47
  const message = saved > 0 ? savedMessage : 'already optimized';
56
-
57
48
  if (saved > 0) {
58
49
  totalBytes += originalSize;
59
50
  totalSavedBytes += saved;
60
51
  totalFiles++;
61
52
  }
62
-
63
53
  BalmJS.logger.debug(PLUGIN_NAME, `${file.relative} (${message})`);
64
54
  file.contents = data;
65
55
  callback(null, file);
@@ -70,35 +60,28 @@ const gulpImagemin = customPlugins => {
70
60
  }
71
61
  })();
72
62
  }
73
-
74
63
  function flush(callback) {
75
64
  const percent = totalBytes > 0 ? totalSavedBytes / totalBytes * 100 : 0;
76
65
  let message = `Minified ${totalFiles} image${totalFiles > 1 ? 's' : ''}`;
77
-
78
66
  if (totalFiles > 0) {
79
67
  message += ` (saved ${prettyBytes(totalSavedBytes)} - ${percent.toFixed(1).replace(/\.0$/, '')}%)`;
80
68
  }
81
-
82
69
  BalmJS.logger.info(PLUGIN_NAME, message);
83
70
  callback();
84
71
  }
85
-
86
72
  return through2Concurrent.obj({
87
73
  maxConcurrency: 8
88
74
  }, transform, flush);
89
75
  };
90
-
91
76
  const gifsicle = exposePlugin('gifsicle');
92
77
  const mozjpeg = exposePlugin('mozjpeg');
93
78
  const optipng = exposePlugin('optipng');
94
79
  const svgo = exposePlugin('svgo');
95
-
96
80
  const getDefaultImagePlugins = () => ({
97
81
  gif: gifsicle(),
98
82
  jpeg: mozjpeg(),
99
83
  png: optipng(),
100
84
  svg: svgo()
101
85
  });
102
-
103
86
  export default gulpImagemin;
104
87
  export { getDefaultImagePlugins };
@@ -1,14 +1,11 @@
1
1
  import { minify } from 'terser';
2
2
  const PLUGIN_NAME = 'jsmin';
3
-
4
3
  async function jsMinify(file, opts, cb) {
5
4
  const extname = node.path.extname(file.path);
6
-
7
5
  if (extname === '.js') {
8
6
  const code = {};
9
7
  let content = file.contents.toString();
10
8
  code[node.path.basename(file.path)] = content;
11
-
12
9
  try {
13
10
  const result = await minify(code, opts);
14
11
  content = result.code;
@@ -21,27 +18,20 @@ async function jsMinify(file, opts, cb) {
21
18
  } else {
22
19
  BalmJS.logger.error(PLUGIN_NAME, 'Invalid JS file');
23
20
  }
24
-
25
21
  return file;
26
22
  }
27
-
28
23
  function gulpJsmin(options) {
29
24
  options = BalmJS.utils.deepMerge({}, options);
30
-
31
25
  function transform(chunk, encoding, callback) {
32
26
  if (chunk.isStream()) {
33
27
  return this.emit('error', new PluginError(PLUGIN_NAME, 'Streams not supported'));
34
28
  }
35
-
36
29
  if (chunk.isNull()) {
37
30
  callback(null, chunk);
38
31
  return;
39
32
  }
40
-
41
33
  jsMinify(chunk, options, callback);
42
34
  }
43
-
44
35
  return through2.obj(transform);
45
36
  }
46
-
47
37
  export default gulpJsmin;
@@ -1,14 +1,13 @@
1
1
  // Reference `gulp-less@5.0.0`
2
+
2
3
  import less from 'less';
3
4
  import replaceExtension from 'replace-ext';
4
5
  import applySourceMap from 'vinyl-sourcemaps-apply';
5
6
  const PLUGIN_NAME = 'less';
6
-
7
7
  function inlineSources(sourcemap) {
8
8
  if (sourcemap.sourcesContent) {
9
9
  return Promise.resolve(sourcemap);
10
10
  }
11
-
12
11
  return Promise.all(sourcemap.sources.map(source => {
13
12
  return new Promise((resolve, reject) => {
14
13
  node.fs.readFile(source, 'utf8', (err, data) => {
@@ -24,7 +23,6 @@ function inlineSources(sourcemap) {
24
23
  return sourcemap;
25
24
  }, () => sourcemap);
26
25
  }
27
-
28
26
  function renderLess(str, opts) {
29
27
  return new Promise((resolve, reject) => {
30
28
  less.render(str, opts, (err, res) => {
@@ -35,7 +33,6 @@ function renderLess(str, opts) {
35
33
  result: res.css,
36
34
  imports: res.imports
37
35
  };
38
-
39
36
  if (opts.sourceMap && res.map) {
40
37
  obj.sourcemap = JSON.parse(res.map);
41
38
  inlineSources(obj.sourcemap).then(map => {
@@ -49,7 +46,6 @@ function renderLess(str, opts) {
49
46
  });
50
47
  });
51
48
  }
52
-
53
49
  function gulpLess(options) {
54
50
  // Mixes in default options.
55
51
  const opts = Object.assign({}, {
@@ -60,41 +56,38 @@ function gulpLess(options) {
60
56
  if (file.isNull()) {
61
57
  return cb(null, file);
62
58
  }
63
-
64
59
  if (file.isStream()) {
65
60
  return cb(new PluginError(PLUGIN_NAME, 'Streaming not supported'));
66
61
  }
62
+ const str = file.contents.toString();
67
63
 
68
- const str = file.contents.toString(); // Injects the path of the current file
69
-
70
- opts.filename = file.path; // Bootstrap source maps
64
+ // Injects the path of the current file
65
+ opts.filename = file.path;
71
66
 
67
+ // Bootstrap source maps
72
68
  if (file.sourceMap || opts.sourcemap) {
73
69
  opts.sourceMap = true;
74
70
  }
75
-
76
71
  renderLess(str, opts).then(res => {
77
72
  file.contents = Buffer.from(res.result);
78
73
  file.path = replaceExtension(file.path, '.css');
79
-
80
74
  if (res.sourcemap) {
81
75
  res.sourcemap.file = file.relative;
82
76
  res.sourcemap.sources = res.sourcemap.sources.map(source => node.path.relative(file.base, source));
83
77
  applySourceMap(file, res.sourcemap);
84
78
  }
85
-
86
79
  return file;
87
80
  }).then(file => {
88
81
  cb(null, file);
89
82
  }).catch(err => {
90
83
  // Convert the keys so PluginError can read them
91
84
  err.lineNumber = err.line;
92
- err.fileName = err.filename; // Add a better error message
85
+ err.fileName = err.filename;
93
86
 
87
+ // Add a better error message
94
88
  err.message = `${err.message} in file ${err.fileName} line no.${err.lineNumber}`;
95
89
  return cb(new PluginError(PLUGIN_NAME, err));
96
90
  });
97
91
  });
98
92
  }
99
-
100
93
  export default gulpLess;
@@ -2,7 +2,6 @@
2
2
  import { EventEmitter } from 'node:events';
3
3
  const PLUGIN_NAME = 'plumber';
4
4
  const emitter = new EventEmitter();
5
-
6
5
  function removeDefaultHandler(stream, event) {
7
6
  let found = false;
8
7
  stream.listeners(event).forEach(function (item) {
@@ -13,10 +12,8 @@ function removeDefaultHandler(stream, event) {
13
12
  }, stream);
14
13
  return found;
15
14
  }
16
-
17
15
  function wrapPanicOnErrorHandler(stream) {
18
16
  const oldHandler = removeDefaultHandler(stream, 'error');
19
-
20
17
  if (oldHandler) {
21
18
  stream.on('error', function onerror2(error) {
22
19
  if (emitter.listenerCount('error') === 1) {
@@ -26,28 +23,23 @@ function wrapPanicOnErrorHandler(stream) {
26
23
  });
27
24
  }
28
25
  }
29
-
30
26
  function defaultErrorHandler(error) {
31
27
  // onerror2 and this handler
32
28
  if (emitter.listenerCount('error') < 3) {
33
29
  BalmJS.logger.error(`${PLUGIN_NAME} - found unhandled error`, error.toString());
34
30
  }
35
31
  }
36
-
37
32
  function gulpPlumber(opts = {}) {
38
33
  if (BalmJS.utils.isFunction(opts)) {
39
34
  opts = {
40
35
  errorHandler: opts
41
36
  };
42
37
  }
43
-
44
38
  const through = through2.obj();
45
39
  through._plumber = true;
46
-
47
40
  if (opts.errorHandler !== false) {
48
41
  through.errorHandler = BalmJS.utils.isFunction(opts.errorHandler) ? opts.errorHandler : defaultErrorHandler;
49
42
  }
50
-
51
43
  function patchPipe(stream) {
52
44
  if (stream.pipe2) {
53
45
  wrapPanicOnErrorHandler(stream);
@@ -56,49 +48,40 @@ function gulpPlumber(opts = {}) {
56
48
  stream._plumbed = true;
57
49
  }
58
50
  }
59
-
60
51
  through.pipe2 = function pipe2(dest) {
61
52
  if (!dest) {
62
53
  throw new PluginError(PLUGIN_NAME, "Can't pipe to undefined");
63
54
  }
64
-
65
55
  this._pipe(dest);
66
-
67
56
  if (dest._unplumbed) {
68
57
  return dest;
69
58
  }
70
-
71
59
  removeDefaultHandler(this, 'error');
72
-
73
60
  if (dest._plumber) {
74
61
  return dest;
75
62
  }
63
+ dest.pipe2 = pipe2;
76
64
 
77
- dest.pipe2 = pipe2; // Patching pipe method
78
-
65
+ // Patching pipe method
79
66
  if (opts.inherit !== false) {
80
67
  patchPipe(dest);
81
- } // Placing custom on error handler
82
-
68
+ }
83
69
 
70
+ // Placing custom on error handler
84
71
  if (this.errorHandler) {
85
72
  dest.errorHandler = this.errorHandler;
86
73
  dest.on('error', this.errorHandler.bind(dest));
87
74
  }
88
-
89
75
  dest._plumbed = true;
90
76
  return dest;
91
77
  };
92
-
93
78
  patchPipe(through);
94
79
  return through;
95
80
  }
96
-
97
81
  function stop() {
98
82
  const through = through2.obj();
99
83
  through._unplumbed = true;
100
84
  return through;
101
85
  }
102
-
103
86
  export default gulpPlumber;
104
87
  export { stop };
@@ -3,7 +3,6 @@ import postcssFlexbugsFixes from 'postcss-flexbugs-fixes';
3
3
  import postcssPresetEnv from 'postcss-preset-env';
4
4
  import autoprefixer from 'autoprefixer';
5
5
  import cssnano from 'cssnano';
6
-
7
6
  function getDefaultPostcssPlugins(isPostCSS = false) {
8
7
  const defaultPostcssPlugins = isPostCSS || BalmJS.config.styles.extname === 'css' ? [atImport({
9
8
  path: BalmJS.file.stylePaths
@@ -11,5 +10,4 @@ function getDefaultPostcssPlugins(isPostCSS = false) {
11
10
  const cssnanoPlugin = BalmJS.config.env.isProd || BalmJS.config.styles.minify ? [cssnano(BalmJS.config.styles.options)] : [];
12
11
  return defaultPostcssPlugins.concat([autoprefixer(), ...cssnanoPlugin, ...BalmJS.config.styles.postcssPlugins]);
13
12
  }
14
-
15
13
  export default getDefaultPostcssPlugins;