balm-core 5.0.2 → 5.1.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 (49) hide show
  1. package/README.md +1 -1
  2. package/index.d.ts +7 -0
  3. package/lib/config/globals.js +14 -1
  4. package/lib/plugins/imagemin.js +15 -10
  5. package/lib/plugins/index.js +2 -0
  6. package/lib/plugins/postcss.js +2 -2
  7. package/lib/plugins/rename.js +1 -3
  8. package/lib/plugins/replace.js +3 -1
  9. package/lib/plugins/sass-legacy.js +131 -0
  10. package/lib/plugins/sass.js +66 -125
  11. package/lib/tasks/foundation/balm.js +2 -2
  12. package/lib/tasks/foundation/balm_style.js +1 -2
  13. package/lib/tasks/private/cache.js +0 -5
  14. package/lib/tasks/private/image.js +2 -2
  15. package/lib/tasks/public/sass.js +1 -2
  16. package/package.json +46 -46
  17. package/tslib/balm.js +5 -8
  18. package/tslib/config/globals.js +21 -1
  19. package/tslib/plugins/imagemin.js +15 -10
  20. package/tslib/plugins/index.js +2 -0
  21. package/tslib/plugins/rename.js +1 -1
  22. package/tslib/plugins/replace.js +2 -1
  23. package/tslib/plugins/sass-legacy.js +95 -0
  24. package/tslib/plugins/sass.js +62 -124
  25. package/tslib/tasks/foundation/balm.js +10 -8
  26. package/tslib/tasks/foundation/balm_style.js +3 -2
  27. package/tslib/tasks/private/build.js +7 -7
  28. package/tslib/tasks/private/cache.js +10 -13
  29. package/tslib/tasks/private/clean.js +28 -31
  30. package/tslib/tasks/private/end.js +8 -8
  31. package/tslib/tasks/private/extra.js +7 -7
  32. package/tslib/tasks/private/font.js +4 -4
  33. package/tslib/tasks/private/image.js +16 -16
  34. package/tslib/tasks/private/lint.js +9 -9
  35. package/tslib/tasks/private/media.js +4 -4
  36. package/tslib/tasks/private/modernizr.js +40 -43
  37. package/tslib/tasks/private/pwa-cache.js +11 -11
  38. package/tslib/tasks/private/sprite.js +36 -39
  39. package/tslib/tasks/private/start.js +7 -7
  40. package/tslib/tasks/private/workbox-sw.js +4 -4
  41. package/tslib/tasks/public/html.js +23 -26
  42. package/tslib/tasks/public/publish.js +13 -16
  43. package/tslib/tasks/public/remove.js +8 -11
  44. package/tslib/tasks/public/sass.js +1 -2
  45. package/tslib/tasks/public/server.js +34 -37
  46. package/tslib/tasks/public/url.js +16 -19
  47. package/tslib/utilities/compiling.js +4 -9
  48. package/tslib/utilities/loading.js +8 -14
  49. package/tslib/utilities/logger.js +13 -18
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "balm-core",
3
- "version": "5.0.2",
3
+ "version": "5.1.0",
4
4
  "description": "BalmJS compiler core",
5
5
  "keywords": [
6
6
  "balm",
@@ -41,75 +41,75 @@
41
41
  "directory": "packages/balm-core"
42
42
  },
43
43
  "dependencies": {
44
- "@rollup/plugin-terser": "^0.4.4",
44
+ "@rollup/plugin-terser": "^1.0.0",
45
45
  "ansi-colors": "^4.1.3",
46
- "async": "^3.2.5",
47
- "autoprefixer": "^10.4.20",
48
- "babel-loader": "^9.1.3",
49
- "browser-sync": "^3.0.2",
46
+ "async": "^3.2.6",
47
+ "autoprefixer": "^10.5.0",
48
+ "babel-loader": "^10.1.1",
49
+ "browser-sync": "^3.0.4",
50
50
  "connect-history-api-fallback": "^2.0.0",
51
- "css-loader": "^7.1.2",
52
- "css-minimizer-webpack-plugin": "^7.0.0",
53
- "cssnano": "^7.0.5",
54
- "del": "^7.1.0",
55
- "dotenv": "^16.4.5",
56
- "dotenv-expand": "^11.0.6",
57
- "esbuild": "^0.23.0",
51
+ "css-loader": "^7.1.4",
52
+ "css-minimizer-webpack-plugin": "^8.0.0",
53
+ "cssnano": "7",
54
+ "del": "^8.0.1",
55
+ "dotenv": "^17.4.2",
56
+ "dotenv-expand": "^13.0.0",
57
+ "esbuild": "^0.28.0",
58
58
  "fancy-log": "^2.0.0",
59
59
  "gulp-eslint": "^6.0.0",
60
60
  "gulp-if": "^3.0.0",
61
61
  "gulp-load-plugins": "^2.0.8",
62
- "gulp-rev-all": "^4.0.0",
62
+ "gulp-rev-all": "^5.1.0",
63
63
  "gulp-rev-delete-original": "^0.2.3",
64
64
  "gulp-size": "^5.0.0",
65
65
  "gulp-useref": "^5.0.0",
66
- "gulp-zip": "^6.0.0",
66
+ "gulp-zip": "^6.1.0",
67
67
  "gulp.spritesmith": "^6.13.1",
68
68
  "html-loader": "^5.1.0",
69
69
  "html-minifier": "^4.0.0",
70
- "html-webpack-plugin": "^5.6.0",
71
- "http-proxy-middleware": "^3.0.0",
72
- "imagemin": "^9.0.0",
70
+ "html-webpack-plugin": "^5.6.7",
71
+ "http-proxy-middleware": "3",
72
+ "imagemin": "^9.0.1",
73
73
  "istextorbinary": "^9.5.0",
74
- "less": "^4.2.0",
75
- "mini-css-extract-plugin": "^2.9.0",
74
+ "less": "^4.6.4",
75
+ "mini-css-extract-plugin": "^2.10.2",
76
76
  "modernizr": "^3.13.1",
77
77
  "parents": "^1.0.1",
78
78
  "plugin-error": "^2.0.1",
79
- "postcss": "^8.4.41",
79
+ "postcss": "^8.5.14",
80
80
  "postcss-flexbugs-fixes": "^5.0.2",
81
- "postcss-import": "^16.1.0",
81
+ "postcss-import": "^16.1.1",
82
82
  "postcss-load-config": "^6.0.1",
83
- "postcss-loader": "^8.1.1",
84
- "postcss-preset-env": "^10.0.1",
85
- "pretty-bytes": "^6.1.1",
86
- "readable-stream": "^4.5.2",
83
+ "postcss-loader": "^8.2.1",
84
+ "postcss-preset-env": "^11.2.1",
85
+ "pretty-bytes": "^7.1.0",
86
+ "readable-stream": "^4.7.0",
87
87
  "replace-ext": "^2.0.0",
88
- "rollup": "^4.20.0",
89
- "sass": "^1.77.8",
90
- "sass-loader": "^16.0.0",
91
- "semver": "^7.6.3",
92
- "ssh2": "^1.15.0",
93
- "strip-ansi": "^7.1.0",
88
+ "rollup": "^4.60.3",
89
+ "sass": "^1.99.0",
90
+ "sass-loader": "^16.0.8",
91
+ "semver": "^7.8.0",
92
+ "ssh2": "^1.17.0",
93
+ "strip-ansi": "^7.2.0",
94
94
  "style-loader": "^4.0.0",
95
- "tailwindcss": "^3.4.10",
96
- "terser": "^5.31.6",
97
- "terser-webpack-plugin": "^5.3.10",
98
- "through2": "^4.0.2",
95
+ "tailwindcss": "^4.3.0",
96
+ "terser": "^5.47.1",
97
+ "terser-webpack-plugin": "^5.6.0",
98
+ "through2": "^5.0.0",
99
99
  "through2-concurrent": "^2.0.0",
100
- "tslib": "^2.6.3",
100
+ "tslib": "^2.8.1",
101
101
  "vinyl-sourcemaps-apply": "^0.2.1",
102
- "webpack": "^5.93.0",
103
- "webpack-bundle-analyzer": "^4.10.2",
104
- "webpack-dev-middleware": "^7.3.0",
102
+ "webpack": "^5.106.2",
103
+ "webpack-bundle-analyzer": "^5.3.0",
104
+ "webpack-dev-middleware": "^8.0.3",
105
105
  "webpack-hot-middleware": "^2.26.1",
106
106
  "webpack-merge": "^6.0.1",
107
- "workbox-build": "^7.1.1"
107
+ "workbox-build": "^7.4.1"
108
108
  },
109
109
  "devDependencies": {
110
110
  "@types/async": "3",
111
111
  "@types/browser-sync": "2",
112
- "@types/express": "4",
112
+ "@types/express": "5",
113
113
  "@types/fancy-log": "2",
114
114
  "@types/html-minifier": "4",
115
115
  "@types/imagemin": "9",
@@ -124,12 +124,12 @@
124
124
  },
125
125
  "optionalDependencies": {
126
126
  "imagemin-gifsicle": "^7.0.0",
127
- "imagemin-mozjpeg": "^9.0.0",
127
+ "imagemin-mozjpeg": "^10.0.0",
128
128
  "imagemin-optipng": "^8.0.0",
129
- "imagemin-svgo": "^9.0.0"
129
+ "imagemin-svgo": "^12.0.0"
130
130
  },
131
131
  "engines": {
132
- "node": ">=18.12.0"
132
+ "node": "^20.19.0 || >=22.0.0"
133
133
  },
134
- "gitHead": "c0b70cc1a9042401efbdc47d4a2eee59f1f2df1b"
134
+ "gitHead": "561aaa5e4a9ad75b5b047ada2d8a66900e1d5431"
135
135
  }
package/tslib/balm.js CHANGED
@@ -1,5 +1,3 @@
1
- var _Balm_config;
2
- import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
3
1
  import './config/index.js';
4
2
  import './utilities/index.js';
5
3
  import './plugins/index.js';
@@ -7,18 +5,18 @@ import registerTasks from './tasks/index.js';
7
5
  import { setConfig, setTask } from './bootstrap/index.js';
8
6
  import loading from './utilities/loading.js';
9
7
  class Balm {
8
+ #config;
10
9
  constructor() {
11
- _Balm_config.set(this, void 0);
12
10
  BalmJS.loading = false;
13
11
  loading.succeed();
14
- __classPrivateFieldSet(this, _Balm_config, setConfig({}), "f");
12
+ this.#config = setConfig({});
15
13
  }
16
14
  get config() {
17
- return __classPrivateFieldGet(this, _Balm_config, "f");
15
+ return this.#config;
18
16
  }
19
17
  set config(value) {
20
- __classPrivateFieldSet(this, _Balm_config, setConfig(value), "f");
21
- BalmJS.config = __classPrivateFieldGet(this, _Balm_config, "f");
18
+ this.#config = setConfig(value);
19
+ BalmJS.config = this.#config;
22
20
  }
23
21
  set beforeTask(name) {
24
22
  BalmJS.beforeTask = setTask(name);
@@ -43,5 +41,4 @@ class Balm {
43
41
  BalmJS.config.useDefaults = true;
44
42
  }
45
43
  }
46
- _Balm_config = new WeakMap();
47
44
  export default Balm;
@@ -4,8 +4,26 @@ import colors from 'ansi-colors';
4
4
  import { create } from 'browser-sync';
5
5
  import through2 from 'through2';
6
6
  import PluginError from 'plugin-error';
7
+ import semver from 'semver';
7
8
  process.env.BALM_CWD = process.env.INIT_CWD || process.cwd();
8
9
  const gulpModule = path.join(process.env.BALM_ROOT || process.env.BALM_CWD, 'node_modules', 'gulp', 'index.js');
10
+ const localSassModule = path.join(process.env.BALM_CWD, 'node_modules', 'sass');
11
+ let isLegacySass = false;
12
+ try {
13
+ const sassPkg = requireModule(path.join(localSassModule, 'package.json'));
14
+ isLegacySass = semver.lt(sassPkg.version, '1.40.0');
15
+ }
16
+ catch (_) { }
17
+ const nodeLocalSassModule = path.join(localSassModule, 'sass.node.js');
18
+ const defaultLocalSassModule = path.join(localSassModule, 'sass.default.js');
19
+ const dartLocalSassModule = path.join(localSassModule, 'sass.dart.js');
20
+ const getSassModule = (sass) => fs.existsSync(nodeLocalSassModule)
21
+ ? requireModule(nodeLocalSassModule)
22
+ : fs.existsSync(defaultLocalSassModule)
23
+ ? requireModule(defaultLocalSassModule)
24
+ : fs.existsSync(dartLocalSassModule)
25
+ ? requireModule(dartLocalSassModule)
26
+ : sass;
9
27
  if (fs.existsSync(gulpModule)) {
10
28
  if (process.cwd() !== process.env.BALM_CWD) {
11
29
  process.chdir(process.env.BALM_CWD);
@@ -19,7 +37,9 @@ else {
19
37
  }
20
38
  global.node = {
21
39
  path,
22
- fs
40
+ fs,
41
+ isLegacySass,
42
+ getSassModule
23
43
  };
24
44
  global.server = create();
25
45
  global.through2 = through2;
@@ -4,12 +4,17 @@ import through2Concurrent from 'through2-concurrent';
4
4
  const PLUGIN_NAME = 'imagemin';
5
5
  const defaultPlugins = ['gifsicle', 'mozjpeg', 'optipng', 'svgo'];
6
6
  const loadPlugin = (plugin, ...args) => {
7
- try {
8
- return requireModule(`imagemin-${plugin}`)(...args);
9
- }
10
- catch (_) {
11
- BalmJS.logger.error(PLUGIN_NAME, `Could not load default plugin \`${plugin}\``);
12
- }
7
+ return async (input) => {
8
+ try {
9
+ const m = await import(`imagemin-${plugin}`);
10
+ const pluginFn = m.default(...args);
11
+ return pluginFn(input);
12
+ }
13
+ catch (_) {
14
+ BalmJS.logger.error(PLUGIN_NAME, `Could not load default plugin \`${plugin}\``);
15
+ return input;
16
+ }
17
+ };
13
18
  };
14
19
  const exposePlugin = (plugin) => (...args) => loadPlugin(plugin, ...args);
15
20
  const getDefaultPlugins = () => defaultPlugins.flatMap((plugin) => loadPlugin(plugin));
@@ -38,9 +43,9 @@ function gulpImagemin(customPlugins) {
38
43
  const plugins = customPlugins ?? getDefaultPlugins();
39
44
  (async () => {
40
45
  try {
41
- const data = Buffer.from(await imagemin.buffer(file.contents, {
42
- plugins
43
- }));
46
+ const data = await imagemin.buffer(file.contents, {
47
+ plugins: plugins
48
+ });
44
49
  const originalSize = file.contents.length;
45
50
  const optimizedSize = data.length;
46
51
  const saved = originalSize - optimizedSize;
@@ -55,7 +60,7 @@ function gulpImagemin(customPlugins) {
55
60
  totalFiles++;
56
61
  }
57
62
  BalmJS.logger.debug(PLUGIN_NAME, `${file.relative} (${message})`);
58
- file.contents = data;
63
+ file.contents = Buffer.from(data);
59
64
  callback(null, file);
60
65
  }
61
66
  catch (error) {
@@ -8,6 +8,7 @@ import postcssPlugins from './postcss-plugins.js';
8
8
  import rename from './rename.js';
9
9
  import replace from './replace.js';
10
10
  import sass from './sass.js';
11
+ import legacySass from './sass-legacy.js';
11
12
  import sftp from './sftp.js';
12
13
  const plugins = {
13
14
  htmlmin,
@@ -20,6 +21,7 @@ const plugins = {
20
21
  rename,
21
22
  replace,
22
23
  sass,
24
+ legacySass,
23
25
  sftp
24
26
  };
25
27
  BalmJS.plugins = plugins;
@@ -12,7 +12,7 @@ function gulpRename(obj, options = {}) {
12
12
  };
13
13
  };
14
14
  stream._transform = (chunk, unused, callback) => {
15
- const file = chunk.clone({ contents: false });
15
+ const file = chunk.clone();
16
16
  let parsedPath = parsePath(file.relative);
17
17
  let _path;
18
18
  const type = typeof obj;
@@ -1,6 +1,7 @@
1
1
  import { Transform } from 'node:stream';
2
- import { isText } from 'istextorbinary';
2
+ import * as isTextModule from 'istextorbinary';
3
3
  import rs from '../utilities/replacestream.js';
4
+ const isText = isTextModule.isText || isTextModule;
4
5
  const defaultOptions = {
5
6
  skipBinary: true
6
7
  };
@@ -0,0 +1,95 @@
1
+ import { Transform } from 'node:stream';
2
+ import * as sass from 'sass';
3
+ import replaceExtension from 'replace-ext';
4
+ import stripAnsi from 'strip-ansi';
5
+ import applySourceMap from 'vinyl-sourcemaps-apply';
6
+ import ansiColors from 'ansi-colors';
7
+ const sassModule = node.getSassModule(sass);
8
+ const PLUGIN_NAME = 'sass-legacy';
9
+ const transformObj = (transform) => new Transform({ transform, objectMode: true });
10
+ function filePush(file, sassObject, callback) {
11
+ if (sassObject.map) {
12
+ const sassMap = JSON.parse(sassObject.map.toString());
13
+ const sassMapFile = sassMap.file.replace(/^stdout$/, 'stdin');
14
+ const sassFileSrc = file.relative;
15
+ const sassFileSrcPath = node.path.dirname(sassFileSrc);
16
+ if (sassFileSrcPath) {
17
+ const sourceFileIndex = sassMap.sources.indexOf(sassMapFile);
18
+ sassMap.sources = sassMap.sources.map((source, index) => index === sourceFileIndex
19
+ ? source
20
+ : node.path.join(sassFileSrcPath, source));
21
+ }
22
+ sassMap.sources = sassMap.sources.filter((src) => src !== 'stdin' && src);
23
+ sassMap.file = replaceExtension(sassFileSrc, '.css');
24
+ applySourceMap(file, sassMap);
25
+ }
26
+ file.contents = sassObject.css;
27
+ file.path = replaceExtension(file.path, '.css');
28
+ if (file.stat) {
29
+ file.stat.atime = file.stat.mtime = file.stat.ctime = new Date();
30
+ }
31
+ callback(null, file);
32
+ }
33
+ function handleError(error, file, callback) {
34
+ const filePath = (error.file === 'stdin' ? file.path : error.file) || file.path;
35
+ const relativePath = node.path.relative(process.cwd(), filePath);
36
+ const message = `${ansiColors.underline(relativePath)}\n${error.formatted}`;
37
+ error.messageFormatted = message;
38
+ error.messageOriginal = error.message;
39
+ error.message = stripAnsi(message);
40
+ error.relativePath = relativePath;
41
+ return callback(new PluginError(PLUGIN_NAME, error));
42
+ }
43
+ const gulpSass = (options, sync = false) => transformObj((file, encoding, callback) => {
44
+ if (file.isNull()) {
45
+ return callback(null, file);
46
+ }
47
+ if (file.isStream()) {
48
+ return callback(new PluginError(PLUGIN_NAME, 'Streaming not supported'));
49
+ }
50
+ if (node.path.basename(file.path).startsWith('_')) {
51
+ return callback();
52
+ }
53
+ if (!file.contents.length) {
54
+ file.path = replaceExtension(file.path, '.css');
55
+ return callback(null, file);
56
+ }
57
+ const opts = (options || {});
58
+ opts.data = file.contents.toString();
59
+ opts.file = file.path;
60
+ if (node.path.extname(file.path) === '.sass') {
61
+ opts.indentedSyntax = true;
62
+ }
63
+ if (opts.includePaths) {
64
+ if (typeof opts.includePaths === 'string') {
65
+ opts.includePaths = [opts.includePaths];
66
+ }
67
+ }
68
+ else {
69
+ opts.includePaths = [];
70
+ }
71
+ opts.includePaths.unshift(node.path.dirname(file.path));
72
+ if (file.sourceMap) {
73
+ opts.sourceMap = file.path;
74
+ opts.omitSourceMapUrl = true;
75
+ opts.sourceMapContents = true;
76
+ }
77
+ if (sync !== true) {
78
+ sassModule.render(opts, (error, obj) => {
79
+ if (error) {
80
+ handleError(error, file, callback);
81
+ return;
82
+ }
83
+ filePush(file, obj, callback);
84
+ });
85
+ }
86
+ else {
87
+ try {
88
+ filePush(file, sassModule.renderSync(opts), callback);
89
+ }
90
+ catch (error) {
91
+ handleError(error, file, callback);
92
+ }
93
+ }
94
+ });
95
+ export default gulpSass;
@@ -1,86 +1,61 @@
1
- import fs from 'node:fs';
2
- import { pathToFileURL } from 'node:url';
3
1
  import { Transform } from 'node:stream';
4
- import semver from 'semver';
5
2
  import * as sass from 'sass';
6
3
  import replaceExtension from 'replace-ext';
7
4
  import stripAnsi from 'strip-ansi';
8
5
  import applySourceMap from 'vinyl-sourcemaps-apply';
9
6
  import ansiColors from 'ansi-colors';
10
- process.env.BALM_CWD = process.env.INIT_CWD || process.cwd();
11
- const localSassModule = node.path.join(process.env.BALM_CWD, 'node_modules', 'sass');
12
- let isLegacy = false;
13
- try {
14
- const sassPkg = requireModule(node.path.join(localSassModule, 'package.json'));
15
- isLegacy = semver.lt(sassPkg.version, '1.40.0');
16
- }
17
- catch (_) { }
18
- const nodeLocalSassModule = node.path.join(localSassModule, 'sass.node.js');
19
- const defaultLocalSassModule = node.path.join(localSassModule, 'sass.default.js');
20
- const dartLocalSassModule = node.path.join(localSassModule, 'sass.dart.js');
21
- const sassModule = fs.existsSync(nodeLocalSassModule)
22
- ? requireModule(nodeLocalSassModule)
23
- : fs.existsSync(defaultLocalSassModule)
24
- ? requireModule(defaultLocalSassModule)
25
- : fs.existsSync(dartLocalSassModule)
26
- ? requireModule(dartLocalSassModule)
27
- : sass;
7
+ const sassModule = node.getSassModule(sass);
28
8
  const PLUGIN_NAME = 'sass';
29
9
  const transformObj = (transform) => new Transform({ transform, objectMode: true });
30
10
  function filePush(file, result, callback) {
31
- if (result.sourceMap) {
32
- const sassMap = result.sourceMap;
33
- sassMap.file = replaceExtension(file.relative, '.css');
34
- applySourceMap(file, sassMap);
35
- }
36
11
  file.contents = Buffer.from(result.css);
37
12
  file.path = replaceExtension(file.path, '.css');
38
- if (file.stat) {
39
- file.stat.atime = file.stat.mtime = file.stat.ctime = new Date();
40
- }
41
- callback(null, file);
42
- }
43
- function legacyFilePush(file, sassObject, callback) {
44
- if (sassObject.map) {
45
- const sassMap = JSON.parse(sassObject.map.toString());
46
- const sassMapFile = sassMap.file.replace(/^stdout$/, 'stdin');
47
- const sassFileSrc = file.relative;
48
- const sassFileSrcPath = node.path.dirname(sassFileSrc);
49
- if (sassFileSrcPath) {
50
- const sourceFileIndex = sassMap.sources.indexOf(sassMapFile);
51
- sassMap.sources = sassMap.sources.map((source, index) => index === sourceFileIndex
52
- ? source
53
- : node.path.join(sassFileSrcPath, source));
13
+ if (result.sourceMap) {
14
+ const proto = /^file:\/\/?/;
15
+ const leadingSlash = /^\//;
16
+ const sassMap = result.sourceMap;
17
+ const base = node.path.resolve(file.cwd, file.base);
18
+ if (!sassMap.file) {
19
+ sassMap.file = file.history[0]
20
+ .replace(base + node.path.sep, '')
21
+ .replace(proto, '');
54
22
  }
55
- sassMap.sources = sassMap.sources.filter((src) => src !== 'stdin' && src);
23
+ sassMap.sources = sassMap.sources.map((src) => {
24
+ const baseUri = base.replace(/\\/g, '/');
25
+ if (src.startsWith('data:')) {
26
+ return file.history[0]
27
+ .replace(/\\/g, '/')
28
+ .replace(`${baseUri}/`, '')
29
+ .replace(proto, '')
30
+ .replace(leadingSlash, '');
31
+ }
32
+ return src
33
+ .replace(proto, '')
34
+ .replace(`${baseUri}/`, '')
35
+ .replace(leadingSlash, '');
36
+ });
37
+ const sassFileSrc = file.relative;
56
38
  sassMap.file = replaceExtension(sassFileSrc, '.css');
39
+ if (file.sourceMap &&
40
+ file.sourceMap.sourcesContent &&
41
+ !sassMap.sourcesContent) {
42
+ sassMap.sourcesContent = file.sourceMap.sourcesContent;
43
+ }
57
44
  applySourceMap(file, sassMap);
58
45
  }
59
- file.contents = sassObject.css;
60
- file.path = replaceExtension(file.path, '.css');
61
46
  if (file.stat) {
62
47
  file.stat.atime = file.stat.mtime = file.stat.ctime = new Date();
63
48
  }
64
49
  callback(null, file);
65
50
  }
66
51
  function handleError(error, file, callback) {
67
- const relativePath = node.path.relative(process.cwd(), file.path);
68
- const message = `${ansiColors.underline(relativePath)}\n${error.message}`;
69
- error.message = stripAnsi(message);
70
- return callback(new PluginError(PLUGIN_NAME, error));
71
- }
72
- function legacyHandleError(error, file, callback) {
73
- const filePath = ((error.file === 'stdin' ? file.path : error.file) ||
74
- file.path);
52
+ const filePath = (error.file === 'stdin' ? file.path : error.file) || file.path;
75
53
  const relativePath = node.path.relative(process.cwd(), filePath);
76
- const message = `${ansiColors.underline(relativePath)}\n${error.formatted}`;
77
- error.messageFormatted = message;
78
- error.messageOriginal = error.message;
54
+ const message = `${ansiColors.underline(relativePath)}\n${error.message}`;
79
55
  error.message = stripAnsi(message);
80
- error.relativePath = relativePath;
81
56
  return callback(new PluginError(PLUGIN_NAME, error));
82
57
  }
83
- const gulpSass = (options) => transformObj((file, encoding, callback) => {
58
+ const gulpSass = (options, sync = false) => transformObj((file, encoding, callback) => {
84
59
  if (file.isNull()) {
85
60
  return callback(null, file);
86
61
  }
@@ -95,77 +70,40 @@ const gulpSass = (options) => transformObj((file, encoding, callback) => {
95
70
  return callback(null, file);
96
71
  }
97
72
  const opts = (options || {});
98
- if (isLegacy) {
99
- opts.data = file.contents.toString();
100
- opts.file = file.path;
101
- if (node.path.extname(file.path) === '.sass') {
102
- opts.indentedSyntax = true;
103
- }
104
- if (opts.includePaths) {
105
- if (typeof opts.includePaths === 'string') {
106
- opts.includePaths = [opts.includePaths];
107
- }
108
- }
109
- else {
110
- opts.includePaths = [];
111
- }
112
- opts.includePaths.unshift(node.path.dirname(file.path));
113
- if (file.sourceMap) {
114
- opts.sourceMap = file.path;
115
- opts.omitSourceMapUrl = true;
116
- opts.sourceMapContents = true;
117
- }
118
- if (!opts.importer) {
119
- const aliasKeys = Object.keys(BalmJS.config.scripts.alias).filter((key) => /^@[a-z0-9-]{1,213}/.test(key));
120
- if (aliasKeys.length) {
121
- const aliasKeyRegex = new RegExp(`^(${aliasKeys.join('|')})/`);
122
- opts.importer = [
123
- function (url) {
124
- let file = url;
125
- const result = url.match(aliasKeyRegex);
126
- const key = result ? result[1] : null;
127
- if (key) {
128
- file = url.replace(key, BalmJS.config.scripts.alias[key]);
129
- BalmJS.logger.debug(`${PLUGIN_NAME} alias`, `${key} -> ${url} => ${file}`);
130
- }
131
- return { file };
132
- }
133
- ];
134
- }
73
+ if (node.path.extname(file.path) === '.sass') {
74
+ opts.syntax = 'indented';
75
+ }
76
+ if (opts.loadPaths) {
77
+ if (typeof opts.loadPaths === 'string') {
78
+ opts.loadPaths = [opts.loadPaths];
135
79
  }
136
80
  }
137
81
  else {
138
- if (!options.importers) {
139
- const aliasKeys = Object.keys(BalmJS.config.scripts.alias).filter((key) => /^@[a-z0-9-]{1,213}/.test(key));
140
- if (aliasKeys.length) {
141
- const aliasKeyRegex = new RegExp(`^(${aliasKeys.join('|')})/`);
142
- options.importers = [
143
- {
144
- findFileUrl(url) {
145
- let file = url;
146
- const result = url.match(aliasKeyRegex);
147
- const key = result ? result[1] : null;
148
- if (key) {
149
- file = url.replace(key, BalmJS.config.scripts.alias[key]);
150
- BalmJS.logger.debug(`${PLUGIN_NAME} alias`, `${key} -> ${url} => ${file}`);
151
- }
152
- return pathToFileURL(file);
153
- }
154
- }
155
- ];
156
- }
157
- }
82
+ opts.loadPaths = [];
158
83
  }
159
- try {
160
- isLegacy
161
- ? legacyFilePush(file, sassModule.renderSync(opts), callback)
162
- : filePush(file, sassModule.compile(file.path, options), callback);
84
+ opts.loadPaths.unshift(node.path.dirname(file.path));
85
+ if (file.sourceMap) {
86
+ opts.sourceMap = true;
87
+ opts.sourceMapIncludeSources = true;
163
88
  }
164
- catch (error) {
165
- isLegacy
166
- ? legacyHandleError(error, file, callback)
167
- : handleError(error, file, callback);
89
+ const fileContents = file.contents.toString();
90
+ if (sync !== true) {
91
+ sassModule
92
+ .compileStringAsync(fileContents, opts)
93
+ .then((compileResult) => {
94
+ filePush(file, compileResult, callback);
95
+ })
96
+ .catch((error) => {
97
+ handleError(error, file, callback);
98
+ });
99
+ }
100
+ else {
101
+ try {
102
+ filePush(file, sassModule.compileString(fileContents, opts), callback);
103
+ }
104
+ catch (error) {
105
+ handleError(error, file, callback);
106
+ }
168
107
  }
169
108
  });
170
109
  export default gulpSass;
171
- export { isLegacy };
@@ -1,11 +1,13 @@
1
1
  class BalmTask {
2
+ name;
3
+ taskName;
4
+ defaultInput = '';
5
+ defaultOutput = '';
6
+ input = '';
7
+ output = '';
8
+ customOptions = {};
9
+ gulpSrcOptions = {};
2
10
  constructor(name) {
3
- this.defaultInput = '';
4
- this.defaultOutput = '';
5
- this.input = '';
6
- this.output = '';
7
- this.customOptions = {};
8
- this.gulpSrcOptions = {};
9
11
  this.name = name;
10
12
  this.taskName = BalmJS.toNamespace(name);
11
13
  }
@@ -27,8 +29,8 @@ class BalmTask {
27
29
  get src() {
28
30
  return gulp
29
31
  .src(this.input, Object.assign({
30
- encoding: false,
31
- allowEmpty: true
32
+ allowEmpty: true,
33
+ encoding: false
32
34
  }, this.gulpSrcOptions))
33
35
  .pipe(BalmJS.plugins.plumber((error) => {
34
36
  BalmJS.logger.error(`${this.name} task`, error.message);