balm-core 5.0.2 → 5.2.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 (57) hide show
  1. package/README.md +1 -1
  2. package/index.d.ts +9 -0
  3. package/lib/config/globals.js +14 -1
  4. package/lib/plugins/htmlmin.js +4 -3
  5. package/lib/plugins/imagemin.js +15 -10
  6. package/lib/plugins/index.js +2 -0
  7. package/lib/plugins/postcss.js +2 -2
  8. package/lib/plugins/rename.js +1 -3
  9. package/lib/plugins/replace.js +3 -1
  10. package/lib/plugins/sass-legacy.js +131 -0
  11. package/lib/plugins/sass.js +66 -125
  12. package/lib/plugins/sftp.js +7 -5
  13. package/lib/tasks/foundation/balm.js +4 -4
  14. package/lib/tasks/foundation/balm_style.js +1 -2
  15. package/lib/tasks/private/cache.js +7 -4
  16. package/lib/tasks/private/image.js +2 -2
  17. package/lib/tasks/private/pwa-cache.js +10 -4
  18. package/lib/tasks/public/publish.js +9 -3
  19. package/lib/tasks/public/pwa.js +22 -7
  20. package/lib/tasks/public/sass.js +1 -2
  21. package/package.json +48 -49
  22. package/tslib/balm.js +5 -8
  23. package/tslib/config/globals.js +21 -1
  24. package/tslib/plugins/htmlmin.js +4 -3
  25. package/tslib/plugins/imagemin.js +15 -10
  26. package/tslib/plugins/index.js +2 -0
  27. package/tslib/plugins/rename.js +1 -1
  28. package/tslib/plugins/replace.js +2 -1
  29. package/tslib/plugins/sass-legacy.js +95 -0
  30. package/tslib/plugins/sass.js +62 -124
  31. package/tslib/plugins/sftp.js +7 -4
  32. package/tslib/tasks/foundation/balm.js +12 -10
  33. package/tslib/tasks/foundation/balm_style.js +3 -2
  34. package/tslib/tasks/private/build.js +7 -7
  35. package/tslib/tasks/private/cache.js +14 -11
  36. package/tslib/tasks/private/clean.js +28 -31
  37. package/tslib/tasks/private/end.js +8 -8
  38. package/tslib/tasks/private/extra.js +7 -7
  39. package/tslib/tasks/private/font.js +4 -4
  40. package/tslib/tasks/private/image.js +16 -16
  41. package/tslib/tasks/private/lint.js +9 -9
  42. package/tslib/tasks/private/media.js +4 -4
  43. package/tslib/tasks/private/modernizr.js +40 -43
  44. package/tslib/tasks/private/pwa-cache.js +21 -13
  45. package/tslib/tasks/private/sprite.js +36 -39
  46. package/tslib/tasks/private/start.js +7 -7
  47. package/tslib/tasks/private/workbox-sw.js +4 -4
  48. package/tslib/tasks/public/html.js +23 -26
  49. package/tslib/tasks/public/publish.js +19 -16
  50. package/tslib/tasks/public/pwa.js +23 -6
  51. package/tslib/tasks/public/remove.js +8 -11
  52. package/tslib/tasks/public/sass.js +1 -2
  53. package/tslib/tasks/public/server.js +34 -37
  54. package/tslib/tasks/public/url.js +16 -19
  55. package/tslib/utilities/compiling.js +4 -9
  56. package/tslib/utilities/loading.js +8 -14
  57. package/tslib/utilities/logger.js +13 -18
@@ -8,7 +8,12 @@ class CacheTask extends BalmJS.BalmTask {
8
8
  super('cache');
9
9
  _defineProperty(this, "fn", () => {
10
10
  this.init();
11
- return this.src.pipe(revAll.revision(BalmJS.config.assets.options)).pipe($.if(/\.html$/, BalmJS.file.setPublicPath())).pipe(gulp.dest(this.output)).pipe($.revDeleteOriginal()).pipe(revAll.manifestFile()).pipe(gulp.dest(this.output));
11
+ this.gulpSrcOptions = {
12
+ base: this.output
13
+ };
14
+ return this.src.pipe(revAll.revision(BalmJS.config.assets.options)).pipe($.if(/\.html$/, BalmJS.file.setPublicPath())).pipe(gulp.dest(this.output)).pipe($.revDeleteOriginal({
15
+ exclude: /\.html$/
16
+ })).pipe(revAll.manifestFile()).pipe(gulp.dest(this.output));
12
17
  });
13
18
  const defaultIncludes = BalmJS.config.scripts.useCache ? ASSETS_TYPES.filter(assetType => assetType !== 'js').map(assetType => BalmJS.file.matchAllFiles(BalmJS.config.dest[assetType])) : ASSETS_TYPES.map(assetType => BalmJS.file.matchAllFiles(BalmJS.config.dest[assetType]));
14
19
  const defaultExcludes = [node.path.join(`!${BalmJS.config.dest.js}`, CHUNK.dir, '*'), node.path.join(`!${BalmJS.config.dest.js}`, ASSET.dir, '*'), node.path.join(`!${BalmJS.config.dest.base}`, BalmJS.config.pwa.manifest)];
@@ -18,10 +23,8 @@ class CacheTask extends BalmJS.BalmTask {
18
23
  });
19
24
  this.defaultInput = [...defaultIncludes, ...defaultExcludes, ...(BalmJS.config.inFrontend ? [node.path.join(BalmJS.config.dest.base, '*.html')] : []), ...customIncludes, ...customExcludes];
20
25
  this.defaultOutput = BalmJS.config.inFrontend ? BalmJS.config.dest.base : BalmJS.config.dest.static;
21
-
22
- // fix for gulp@5
23
26
  this.gulpSrcOptions = {
24
- base: BalmJS.config.dest.base
27
+ base: this.defaultOutput
25
28
  };
26
29
  }
27
30
  }
@@ -9,8 +9,8 @@ class ImageTask extends BalmJS.BalmTask {
9
9
  this.init();
10
10
  const balmImage = () => {
11
11
  return gulp.src(BalmJS.file.absPaths(this.input), {
12
- encoding: false,
13
- since: gulp.lastRun(balmImage)
12
+ since: gulp.lastRun(balmImage),
13
+ encoding: false
14
14
  }).pipe(BalmJS.plugins.plumber(error => {
15
15
  BalmJS.logger.error(`${this.name} task`, error);
16
16
  })).pipe(BalmJS.plugins.imagemin(this.plugins)).pipe(gulp.dest(this.output));
@@ -7,6 +7,10 @@ class PwaCacheTask extends BalmJS.BalmTask {
7
7
  super('pwa-cache');
8
8
  _defineProperty(this, "fn", () => {
9
9
  this.init();
10
+ const swDest = typeof this.input === 'string' && this.input ? BalmJS.file.absPath(this.input) : '';
11
+ if (!swDest || !node.fs.existsSync(swDest)) {
12
+ return Promise.resolve();
13
+ }
10
14
  const newVersion = BalmJS.config.pwa.version || Date.now().toString();
11
15
  BalmJS.logger.info('pwa - version', newVersion);
12
16
  const stream = this.src.pipe(BalmJS.plugins.replace('{{ version }}', newVersion)).pipe($.if(BalmJS.config.env.isProd, BalmJS.plugins.jsmin(BalmJS.config.scripts.minifyOptions))).pipe(gulp.dest(this.output));
@@ -17,10 +21,12 @@ class PwaCacheTask extends BalmJS.BalmTask {
17
21
  this.defaultInput = node.path.join(this.defaultOutput, BalmJS.config.pwa.swDestFilename);
18
22
  }
19
23
  clear() {
20
- const swOrigin = BalmJS.file.absPath(node.path.join(BalmJS.config.dest.base, BalmJS.config.pwa.swSrcFilename));
21
- deleteAsync(swOrigin, {
22
- force: true
23
- });
24
+ if (BalmJS.config.pwa.swSrcFilename !== BalmJS.config.pwa.swDestFilename) {
25
+ const swOrigin = BalmJS.file.absPath(node.path.join(BalmJS.config.dest.base, BalmJS.config.pwa.swSrcFilename));
26
+ deleteAsync(swOrigin, {
27
+ force: true
28
+ });
29
+ }
24
30
  }
25
31
  }
26
32
  export default PwaCacheTask;
@@ -8,13 +8,19 @@ class PublishTask extends BalmJS.BalmTask {
8
8
  constructor() {
9
9
  super('publish');
10
10
  _classPrivateFieldInitSpec(this, _release, (input, output, renameOptions = {}) => {
11
+ let srcPath;
12
+ let destPath;
11
13
  if (input && output) {
12
- this.init(node.path.join(BalmJS.config.dest.base, input), node.path.join(BalmJS.config.assets.root, output) // Remote dir
13
- );
14
+ srcPath = BalmJS.file.absPaths(node.path.join(BalmJS.config.dest.base, input));
15
+ destPath = BalmJS.file.absPath(node.path.join(BalmJS.config.assets.root, output));
14
16
  } else {
15
17
  this.init();
18
+ srcPath = this.input;
19
+ destPath = this.output;
16
20
  }
17
- return this.src.pipe($.if(!BalmJS.utils.isArray(this.input), BalmJS.plugins.rename(renameOptions))).pipe(gulp.dest(this.output)); // Absolute path
21
+ return gulp.src(srcPath, {
22
+ allowEmpty: true
23
+ }).pipe($.if(!BalmJS.utils.isArray(srcPath), BalmJS.plugins.rename(renameOptions))).pipe(gulp.dest(destPath));
18
24
  });
19
25
  this.defaultInput = [BalmJS.file.matchAllFiles(BalmJS.config.dest.static),
20
26
  // Assets
@@ -45,15 +45,30 @@ class PwaTask extends BalmJS.BalmTask {
45
45
  pre: true
46
46
  });
47
47
  const workboxBuild = mode === 'generateSW' ? generateSW(options) : injectManifest(options);
48
- await workboxBuild.then(({
49
- count,
50
- size
51
- }) => {
48
+ try {
49
+ const {
50
+ count,
51
+ size
52
+ } = await workboxBuild;
52
53
  BalmJS.logger.info(`pwa - ${mode}`, `Generated '${swDest}', which will precache ${count} files, totaling ${size} bytes`);
53
- gulp.parallel(BalmJS.toNamespace('pwa-cache'))();
54
- }).catch(err => {
54
+ await new Promise(resolve => {
55
+ const pwaCacheTask = BalmJS.tasks.get('pwa-cache');
56
+ if (pwaCacheTask) {
57
+ const stream = pwaCacheTask.fn();
58
+ if (stream && typeof stream.on === 'function') {
59
+ stream.on('finish', resolve).on('error', () => resolve());
60
+ } else if (stream && typeof stream.then === 'function') {
61
+ stream.then(resolve, resolve);
62
+ } else {
63
+ resolve();
64
+ }
65
+ } else {
66
+ resolve();
67
+ }
68
+ });
69
+ } catch (err) {
55
70
  BalmJS.logger.warn(`pwa - ${mode}`, `Service worker generation failed: ${err}`);
56
- });
71
+ }
57
72
  callback();
58
73
  } else {
59
74
  BalmJS.logger.warn('pwa task', 'Invalid PWA mode');
@@ -1,10 +1,9 @@
1
- import { isLegacy } from '../../plugins/sass.js';
2
1
  class SassTask extends BalmJS.BalmStyleTask {
3
2
  constructor() {
4
3
  super('sass');
5
4
  }
6
5
  get options() {
7
- return Object.assign(isLegacy ? {
6
+ return Object.assign(node.isLegacySass ? {
8
7
  includePaths: BalmJS.file.stylePaths,
9
8
  outputStyle: 'expanded'
10
9
  } : {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "balm-core",
3
- "version": "5.0.2",
3
+ "version": "5.2.0",
4
4
  "description": "BalmJS compiler core",
5
5
  "keywords": [
6
6
  "balm",
@@ -41,77 +41,77 @@
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
- "html-minifier": "^4.0.0",
70
- "html-webpack-plugin": "^5.6.0",
71
- "http-proxy-middleware": "^3.0.0",
72
- "imagemin": "^9.0.0",
69
+ "html-minifier-terser": "^7.2.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": "^6.0.1",
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
- "@types/html-minifier": "4",
114
+ "@types/html-minifier-terser": "^7.0.2",
115
115
  "@types/imagemin": "9",
116
116
  "@types/parents": "1",
117
117
  "@types/postcss-flexbugs-fixes": "5",
@@ -124,12 +124,11 @@
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"
133
- },
134
- "gitHead": "c0b70cc1a9042401efbdc47d4a2eee59f1f2df1b"
132
+ "node": "^20.19.0 || >=22.0.0"
133
+ }
135
134
  }
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;
@@ -1,4 +1,4 @@
1
- import { minify } from 'html-minifier';
1
+ import { minify } from 'html-minifier-terser';
2
2
  const PLUGIN_NAME = 'htmlmin';
3
3
  function gulpHtmlmin(options) {
4
4
  options = BalmJS.utils.deepMerge({}, options);
@@ -7,9 +7,10 @@ function gulpHtmlmin(options) {
7
7
  callback(null, file);
8
8
  return;
9
9
  }
10
- function htmlMinify(buf, enc, cb) {
10
+ async function htmlMinify(buf, enc, cb) {
11
11
  try {
12
- const contents = Buffer.from(minify(buf.toString(), options));
12
+ const minified = await minify(buf.toString(), options);
13
+ const contents = Buffer.from(minified);
13
14
  if (cb === callback) {
14
15
  file.contents = contents;
15
16
  cb(null, file);
@@ -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;