balm-core 4.31.0 → 4.33.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.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  <div align="center">
2
2
  <a href="https://balm.js.org/">
3
- <img width="128" heigth="128" src="https://balm.js.org/logo.png" alt="BalmJS">
3
+ <img width="128" height="128" src="https://balm.js.org/logo.png" alt="BalmJS">
4
4
  </a>
5
5
  <br>
6
6
  <br>
@@ -4,10 +4,21 @@ 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
 
8
9
  // Set env var for ORIGINAL cwd before anything touches it
9
10
  process.env.BALM_CWD = process.env.INIT_CWD || process.cwd();
10
11
  const gulpModule = path.join(process.env.BALM_ROOT || process.env.BALM_CWD, 'node_modules', 'gulp', 'index.js');
12
+ const localSassModule = path.join(process.env.BALM_CWD, 'node_modules', 'sass');
13
+ let isLegacySass = false;
14
+ try {
15
+ const sassPkg = requireModule(path.join(localSassModule, 'package.json'));
16
+ isLegacySass = semver.lt(sassPkg.version, '1.40.0');
17
+ } catch (_) {}
18
+ const nodeLocalSassModule = path.join(localSassModule, 'sass.node.js');
19
+ const defaultLocalSassModule = path.join(localSassModule, 'sass.default.js'); // For `npm i -D sass <= 1.62.1`
20
+ const dartLocalSassModule = path.join(localSassModule, 'sass.dart.js'); // For `npm i -D sass <= 1.39.2`
21
+ const getSassModule = sass => fs.existsSync(nodeLocalSassModule) ? requireModule(nodeLocalSassModule) : fs.existsSync(defaultLocalSassModule) ? requireModule(defaultLocalSassModule) : fs.existsSync(dartLocalSassModule) ? requireModule(dartLocalSassModule) : sass;
11
22
  if (fs.existsSync(gulpModule)) {
12
23
  // Chdir before requiring balm config to make sure
13
24
  // we let them chdir as needed
@@ -22,7 +33,9 @@ if (fs.existsSync(gulpModule)) {
22
33
  }
23
34
  global.node = {
24
35
  path,
25
- fs
36
+ fs,
37
+ isLegacySass,
38
+ getSassModule
26
39
  };
27
40
  global.server = create();
28
41
  global.through2 = through2;
@@ -1,4 +1,4 @@
1
- // Reference `gulp-imagemin@9.0.0`
1
+ // Reference `gulp-imagemin@9.1.0`
2
2
 
3
3
  import imagemin from 'imagemin';
4
4
  import prettyBytes from 'pretty-bytes';
@@ -54,7 +54,7 @@ function gulpImagemin(customPlugins) {
54
54
  totalFiles++;
55
55
  }
56
56
  BalmJS.logger.debug(PLUGIN_NAME, `${file.relative} (${message})`);
57
- file.contents = data;
57
+ file.contents = Buffer.from(data);
58
58
  callback(null, file);
59
59
  } catch (error) {
60
60
  callback(new PluginError(PLUGIN_NAME, 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;
@@ -1,4 +1,4 @@
1
- // Reference `gulp-postcss@9.0.1`
1
+ // Reference `gulp-postcss@10.0.0`
2
2
  import { Transform } from 'node:stream';
3
3
  import postcss from 'postcss';
4
4
  import postcssLoadConfig from 'postcss-load-config';
@@ -28,7 +28,7 @@ function gulpPostcss(cb) {
28
28
  }
29
29
  const ctx = {
30
30
  file,
31
- options: contextOptions
31
+ options: contextOptions // @TODO: The options property is deprecated and should be removed
32
32
  };
33
33
  return postcssLoadConfig(ctx, configPath);
34
34
  });
@@ -0,0 +1,131 @@
1
+ // Reference `gulp-sass@5.1.0`
2
+ import { Transform } from 'node:stream';
3
+ import * as sass from 'sass';
4
+ import replaceExtension from 'replace-ext';
5
+ import stripAnsi from 'strip-ansi';
6
+ import applySourceMap from 'vinyl-sourcemaps-apply';
7
+ import ansiColors from 'ansi-colors';
8
+ const sassModule = node.getSassModule(sass);
9
+ const PLUGIN_NAME = 'sass-legacy';
10
+ const transformObj = transform => new Transform({
11
+ transform,
12
+ objectMode: true
13
+ });
14
+
15
+ /**
16
+ * Handles returning the file to the stream
17
+ */
18
+ function filePush(file, sassObject, callback) {
19
+ // Build Source Maps!
20
+ if (sassObject.map) {
21
+ // Transform map into JSON
22
+ const sassMap = JSON.parse(sassObject.map.toString());
23
+ // Grab the stdout and transform it into stdin
24
+ const sassMapFile = sassMap.file.replace(/^stdout$/, 'stdin');
25
+ // Grab the base filename that's being worked on
26
+ const sassFileSrc = file.relative;
27
+ // Grab the path portion of the file that's being worked on
28
+ const sassFileSrcPath = node.path.dirname(sassFileSrc);
29
+ if (sassFileSrcPath) {
30
+ const sourceFileIndex = sassMap.sources.indexOf(sassMapFile);
31
+ // Prepend the path to all files in the sources array except the file that's being worked on
32
+ sassMap.sources = sassMap.sources.map((source, index) => index === sourceFileIndex ? source : node.path.join(sassFileSrcPath, source));
33
+ }
34
+
35
+ // Remove 'stdin' from sources and replace with filenames!
36
+ sassMap.sources = sassMap.sources.filter(src => src !== 'stdin' && src);
37
+
38
+ // Replace the map file with the original filename (but new extension)
39
+ sassMap.file = replaceExtension(sassFileSrc, '.css');
40
+ // Apply the map
41
+ applySourceMap(file, sassMap);
42
+ }
43
+ file.contents = sassObject.css;
44
+ file.path = replaceExtension(file.path, '.css');
45
+ if (file.stat) {
46
+ file.stat.atime = file.stat.mtime = file.stat.ctime = new Date();
47
+ }
48
+ callback(null, file);
49
+ }
50
+
51
+ /**
52
+ * Handles error message
53
+ */
54
+ function handleError(error, file, callback) {
55
+ const filePath = (error.file === 'stdin' ? file.path : error.file) || file.path;
56
+ const relativePath = node.path.relative(process.cwd(), filePath);
57
+ const message = `${ansiColors.underline(relativePath)}\n${error.formatted}`;
58
+ error.messageFormatted = message;
59
+ error.messageOriginal = error.message;
60
+ error.message = stripAnsi(message);
61
+ error.relativePath = relativePath;
62
+ return callback(new PluginError(PLUGIN_NAME, error));
63
+ }
64
+
65
+ //////////////////////////////
66
+ // Main Gulp Sass function
67
+ //////////////////////////////
68
+ const gulpSass = (options, sync = false) => transformObj((file, encoding, callback) => {
69
+ if (file.isNull()) {
70
+ return callback(null, file);
71
+ }
72
+ if (file.isStream()) {
73
+ return callback(new PluginError(PLUGIN_NAME, 'Streaming not supported'));
74
+ }
75
+ if (node.path.basename(file.path).startsWith('_')) {
76
+ return callback();
77
+ }
78
+ if (!file.contents.length) {
79
+ file.path = replaceExtension(file.path, '.css');
80
+ return callback(null, file);
81
+ }
82
+ const opts = options || {};
83
+ opts.data = file.contents.toString();
84
+
85
+ // We set the file path here so that libsass can correctly resolve import paths
86
+ opts.file = file.path;
87
+
88
+ // Ensure `indentedSyntax` is true if a `.sass` file
89
+ if (node.path.extname(file.path) === '.sass') {
90
+ opts.indentedSyntax = true;
91
+ }
92
+
93
+ // Ensure file's parent directory in the include path
94
+ if (opts.includePaths) {
95
+ if (typeof opts.includePaths === 'string') {
96
+ opts.includePaths = [opts.includePaths];
97
+ }
98
+ } else {
99
+ opts.includePaths = [];
100
+ }
101
+ opts.includePaths.unshift(node.path.dirname(file.path));
102
+
103
+ // Generate Source Maps if the source-map plugin is present
104
+ if (file.sourceMap) {
105
+ opts.sourceMap = file.path;
106
+ opts.omitSourceMapUrl = true;
107
+ opts.sourceMapContents = true;
108
+ }
109
+ if (sync !== true) {
110
+ /**
111
+ * Async Sass render
112
+ */
113
+ sassModule.render(opts, (error, obj) => {
114
+ if (error) {
115
+ handleError(error, file, callback);
116
+ return;
117
+ }
118
+ filePush(file, obj, callback);
119
+ });
120
+ } else {
121
+ /**
122
+ * Sync Sass render
123
+ */
124
+ try {
125
+ filePush(file, sassModule.renderSync(opts), callback);
126
+ } catch (error) {
127
+ handleError(error, file, callback);
128
+ }
129
+ }
130
+ });
131
+ export default gulpSass;
@@ -1,24 +1,11 @@
1
- import fs from 'node:fs';
2
- import { pathToFileURL } from 'node:url';
3
- // Reference `gulp-sass@5.1.0`
1
+ // Reference `gulp-sass@6.0.1`
4
2
  import { Transform } from 'node:stream';
5
- import semver from 'semver';
6
3
  import * as sass from 'sass';
7
4
  import replaceExtension from 'replace-ext';
8
5
  import stripAnsi from 'strip-ansi';
9
6
  import applySourceMap from 'vinyl-sourcemaps-apply';
10
7
  import ansiColors from 'ansi-colors';
11
- process.env.BALM_CWD = process.env.INIT_CWD || process.cwd();
12
- const localSassModule = node.path.join(process.env.BALM_CWD, 'node_modules', 'sass');
13
- let isLegacy = false;
14
- try {
15
- const sassPkg = requireModule(node.path.join(localSassModule, 'package.json'));
16
- isLegacy = semver.lt(sassPkg.version, '1.40.0');
17
- } catch (_) {}
18
- const nodeLocalSassModule = node.path.join(localSassModule, 'sass.node.js');
19
- const defaultLocalSassModule = node.path.join(localSassModule, 'sass.default.js'); // For `npm i -D sass <= 1.62.1`
20
- const dartLocalSassModule = node.path.join(localSassModule, 'sass.dart.js'); // For `npm i -D sass <= 1.39.2`
21
- const sassModule = fs.existsSync(nodeLocalSassModule) ? requireModule(nodeLocalSassModule) : fs.existsSync(defaultLocalSassModule) ? requireModule(defaultLocalSassModule) : fs.existsSync(dartLocalSassModule) ? requireModule(dartLocalSassModule) : sass;
8
+ const sassModule = node.getSassModule(sass);
22
9
  const PLUGIN_NAME = 'sass';
23
10
  const transformObj = transform => new Transform({
24
11
  transform,
@@ -29,48 +16,44 @@ const transformObj = transform => new Transform({
29
16
  * Handles returning the file to the stream
30
17
  */
31
18
  function filePush(file, result, callback) {
32
- // Build Source Maps!
33
- if (result.sourceMap) {
34
- const sassMap = result.sourceMap;
35
- // Replace the map file with the original filename (but new extension)
36
- sassMap.file = replaceExtension(file.relative, '.css');
37
- // Apply the map
38
- applySourceMap(file, sassMap);
39
- }
40
19
  file.contents = Buffer.from(result.css);
41
20
  file.path = replaceExtension(file.path, '.css');
42
- if (file.stat) {
43
- file.stat.atime = file.stat.mtime = file.stat.ctime = new Date();
44
- }
45
- callback(null, file);
46
- }
47
- function legacyFilePush(file, sassObject, callback) {
21
+
48
22
  // Build Source Maps!
49
- if (sassObject.map) {
50
- // Transform map into JSON
51
- const sassMap = JSON.parse(sassObject.map.toString());
52
- // Grab the stdout and transform it into stdin
53
- const sassMapFile = sassMap.file.replace(/^stdout$/, 'stdin');
54
- // Grab the base filename that's being worked on
55
- const sassFileSrc = file.relative;
56
- // Grab the path portion of the file that's being worked on
57
- const sassFileSrcPath = node.path.dirname(sassFileSrc);
58
- if (sassFileSrcPath) {
59
- const sourceFileIndex = sassMap.sources.indexOf(sassMapFile);
60
- // Prepend the path to all files in the sources array except the file that's being worked on
61
- sassMap.sources = sassMap.sources.map((source, index) => index === sourceFileIndex ? source : node.path.join(sassFileSrcPath, source));
23
+ if (result.sourceMap) {
24
+ const proto = /^file:\/\/?/;
25
+ const leadingSlash = /^\//;
26
+ const sassMap = result.sourceMap;
27
+ const base = node.path.resolve(file.cwd, file.base);
28
+ if (!sassMap.file) {
29
+ // Convert from absolute path to relative as in gulp-sass 5.0.0
30
+ sassMap.file = file.history[0].replace(base + node.path.sep, '').replace(proto, '');
62
31
  }
63
32
 
64
- // Remove 'stdin' from sources and replace with filenames!
65
- sassMap.sources = sassMap.sources.filter(src => src !== 'stdin' && src);
33
+ // Transform to relative file paths as in gulp-sass 5.0.0
34
+ sassMap.sources = sassMap.sources.map(src => {
35
+ // file uses Windows-style path separators, source is a URL.
36
+ const baseUri = base.replace(/\\/g, '/');
37
+ // The current file and its content is included
38
+ // as data:<encoded file contents> in the new Sass JS API.
39
+ // Map it to the original file name (first history entry).
40
+ if (src.startsWith('data:')) {
41
+ return file.history[0].replace(/\\/g, '/').replace(`${baseUri}/`, '').replace(proto, '').replace(leadingSlash, '');
42
+ }
43
+ return src.replace(proto, '').replace(`${baseUri}/`, '').replace(leadingSlash, '');
44
+ });
66
45
 
46
+ // Grab the base filename that's being worked on
47
+ const sassFileSrc = file.relative;
67
48
  // Replace the map file with the original filename (but new extension)
68
49
  sassMap.file = replaceExtension(sassFileSrc, '.css');
50
+ if (file.sourceMap && file.sourceMap.sourcesContent && !sassMap.sourcesContent) {
51
+ sassMap.sourcesContent = file.sourceMap.sourcesContent;
52
+ }
53
+
69
54
  // Apply the map
70
55
  applySourceMap(file, sassMap);
71
56
  }
72
- file.contents = sassObject.css;
73
- file.path = replaceExtension(file.path, '.css');
74
57
  if (file.stat) {
75
58
  file.stat.atime = file.stat.mtime = file.stat.ctime = new Date();
76
59
  }
@@ -81,26 +64,17 @@ function legacyFilePush(file, sassObject, callback) {
81
64
  * Handles error message
82
65
  */
83
66
  function handleError(error, file, callback) {
84
- const relativePath = node.path.relative(process.cwd(), file.path);
85
- const message = `${ansiColors.underline(relativePath)}\n${error.message}`;
86
- error.message = stripAnsi(message);
87
- return callback(new PluginError(PLUGIN_NAME, error));
88
- }
89
- function legacyHandleError(error, file, callback) {
90
67
  const filePath = (error.file === 'stdin' ? file.path : error.file) || file.path;
91
68
  const relativePath = node.path.relative(process.cwd(), filePath);
92
- const message = `${ansiColors.underline(relativePath)}\n${error.formatted}`;
93
- error.messageFormatted = message;
94
- error.messageOriginal = error.message;
69
+ const message = `${ansiColors.underline(relativePath)}\n${error.message}`;
95
70
  error.message = stripAnsi(message);
96
- error.relativePath = relativePath;
97
71
  return callback(new PluginError(PLUGIN_NAME, error));
98
72
  }
99
73
 
100
74
  //////////////////////////////
101
75
  // Main Gulp Sass function
102
76
  //////////////////////////////
103
- const gulpSass = options => transformObj((file, encoding, callback) => {
77
+ const gulpSass = (options, sync = false) => transformObj((file, encoding, callback) => {
104
78
  if (file.isNull()) {
105
79
  return callback(null, file);
106
80
  }
@@ -115,79 +89,46 @@ const gulpSass = options => transformObj((file, encoding, callback) => {
115
89
  return callback(null, file);
116
90
  }
117
91
  const opts = options || {};
118
- if (isLegacy) {
119
- opts.data = file.contents.toString();
120
-
121
- // We set the file path here so that libsass can correctly resolve import paths
122
- opts.file = file.path;
123
-
124
- // Ensure `indentedSyntax` is true if a `.sass` file
125
- if (node.path.extname(file.path) === '.sass') {
126
- opts.indentedSyntax = true;
127
- }
128
92
 
129
- // Ensure file's parent directory in the include path
130
- if (opts.includePaths) {
131
- if (typeof opts.includePaths === 'string') {
132
- opts.includePaths = [opts.includePaths];
133
- }
134
- } else {
135
- opts.includePaths = [];
136
- }
137
- opts.includePaths.unshift(node.path.dirname(file.path));
93
+ // Ensure `indented` if a `.sass` file
94
+ if (node.path.extname(file.path) === '.sass') {
95
+ opts.syntax = 'indented';
96
+ }
138
97
 
139
- // Generate Source Maps if the source-map plugin is present
140
- if (file.sourceMap) {
141
- opts.sourceMap = file.path;
142
- opts.omitSourceMapUrl = true;
143
- opts.sourceMapContents = true;
98
+ // Ensure file's parent directory in the include path
99
+ if (opts.loadPaths) {
100
+ if (typeof opts.loadPaths === 'string') {
101
+ opts.loadPaths = [opts.loadPaths];
144
102
  }
103
+ } else {
104
+ opts.loadPaths = [];
105
+ }
106
+ opts.loadPaths.unshift(node.path.dirname(file.path));
145
107
 
146
- // Create alias
147
- if (!opts.importer) {
148
- const aliasKeys = Object.keys(BalmJS.config.scripts.alias).filter(key => /^@[a-z0-9-]{1,213}/.test(key));
149
- if (aliasKeys.length) {
150
- const aliasKeyRegex = new RegExp(`^(${aliasKeys.join('|')})/`);
151
- opts.importer = [function (url) {
152
- let file = url;
153
- const result = url.match(aliasKeyRegex);
154
- const key = result ? result[1] : null;
155
- if (key) {
156
- file = url.replace(key, BalmJS.config.scripts.alias[key]);
157
- BalmJS.logger.debug(`${PLUGIN_NAME} alias`, `${key} -> ${url} => ${file}`);
158
- }
159
- return {
160
- file
161
- };
162
- }];
163
- }
164
- }
108
+ // Generate Source Maps if the source-map plugin is present
109
+ if (file.sourceMap) {
110
+ opts.sourceMap = true;
111
+ opts.sourceMapIncludeSources = true;
112
+ }
113
+ const fileContents = file.contents.toString();
114
+ if (sync !== true) {
115
+ /**
116
+ * Async Sass compile
117
+ */
118
+ sassModule.compileStringAsync(fileContents, opts).then(compileResult => {
119
+ filePush(file, compileResult, callback);
120
+ }).catch(error => {
121
+ handleError(error, file, callback);
122
+ });
165
123
  } else {
166
- // Create alias
167
- if (!options.importers) {
168
- const aliasKeys = Object.keys(BalmJS.config.scripts.alias).filter(key => /^@[a-z0-9-]{1,213}/.test(key));
169
- if (aliasKeys.length) {
170
- const aliasKeyRegex = new RegExp(`^(${aliasKeys.join('|')})/`);
171
- options.importers = [{
172
- findFileUrl(url) {
173
- let file = url;
174
- const result = url.match(aliasKeyRegex);
175
- const key = result ? result[1] : null;
176
- if (key) {
177
- file = url.replace(key, BalmJS.config.scripts.alias[key]);
178
- BalmJS.logger.debug(`${PLUGIN_NAME} alias`, `${key} -> ${url} => ${file}`);
179
- }
180
- return pathToFileURL(file);
181
- }
182
- }];
183
- }
124
+ /**
125
+ * Sync Sass compile
126
+ */
127
+ try {
128
+ filePush(file, sassModule.compileString(fileContents, opts), callback);
129
+ } catch (error) {
130
+ handleError(error, file, callback);
184
131
  }
185
132
  }
186
- try {
187
- isLegacy ? legacyFilePush(file, sassModule.renderSync(opts), callback) : filePush(file, sassModule.compile(file.path, options), callback);
188
- } catch (error) {
189
- isLegacy ? legacyHandleError(error, file, callback) : handleError(error, file, callback);
190
- }
191
133
  });
192
- export default gulpSass;
193
- export { isLegacy };
134
+ export default gulpSass;
@@ -46,7 +46,7 @@ class BalmStyleTask extends BalmTask {
46
46
  }));
47
47
  switch (style) {
48
48
  case 'sass':
49
- stream = stream.pipe(BalmJS.plugins.sass(options));
49
+ stream = stream.pipe(node.isLegacySass ? BalmJS.plugins.legacySass(options) : BalmJS.plugins.sass(options));
50
50
  break;
51
51
  case 'less':
52
52
  stream = stream.pipe(BalmJS.plugins.less(options));
@@ -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": "4.31.0",
3
+ "version": "4.33.0",
4
4
  "description": "BalmJS compiler core",
5
5
  "keywords": [
6
6
  "balm",
@@ -44,17 +44,17 @@
44
44
  "@rollup/plugin-terser": "^0.4.4",
45
45
  "ansi-colors": "^4.1.3",
46
46
  "async": "^3.2.6",
47
- "autoprefixer": "^10.4.20",
48
- "babel-loader": "^9.2.1",
49
- "browser-sync": "^3.0.3",
47
+ "autoprefixer": "^10.4.21",
48
+ "babel-loader": "^10.0.0",
49
+ "browser-sync": "^3.0.4",
50
50
  "connect-history-api-fallback": "^2.0.0",
51
51
  "css-loader": "^7.1.2",
52
- "css-minimizer-webpack-plugin": "^7.0.0",
53
- "cssnano": "^7.0.6",
52
+ "css-minimizer-webpack-plugin": "^7.0.2",
53
+ "cssnano": "^7.1.1",
54
54
  "del": "^8.0.0",
55
- "dotenv": "^16.4.5",
56
- "dotenv-expand": "^11.0.6",
57
- "esbuild": "^0.24.0",
55
+ "dotenv": "^17.2.2",
56
+ "dotenv-expand": "^12.0.3",
57
+ "esbuild": "^0.25.10",
58
58
  "fancy-log": "^2.0.0",
59
59
  "gulp-eslint": "^6.0.0",
60
60
  "gulp-if": "^3.0.0",
@@ -63,45 +63,45 @@
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.3",
71
- "http-proxy-middleware": "^3.0.3",
72
- "imagemin": "^9.0.0",
70
+ "html-webpack-plugin": "^5.6.4",
71
+ "http-proxy-middleware": "^3.0.5",
72
+ "imagemin": "^9.0.1",
73
73
  "istextorbinary": "^9.5.0",
74
- "less": "^4.2.0",
75
- "mini-css-extract-plugin": "^2.9.2",
74
+ "less": "^4.4.1",
75
+ "mini-css-extract-plugin": "^2.9.4",
76
76
  "modernizr": "^3.13.1",
77
77
  "parents": "^1.0.1",
78
78
  "plugin-error": "^2.0.1",
79
- "postcss": "^8.4.48",
79
+ "postcss": "^8.5.6",
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.9",
85
- "pretty-bytes": "^6.1.1",
86
- "readable-stream": "^4.5.2",
83
+ "postcss-loader": "^8.2.0",
84
+ "postcss-preset-env": "^10.3.1",
85
+ "pretty-bytes": "^7.0.1",
86
+ "readable-stream": "^4.7.0",
87
87
  "replace-ext": "^2.0.0",
88
- "rollup": "^4.25.0",
89
- "sass": "^1.80.6",
90
- "sass-loader": "^16.0.3",
91
- "semver": "^7.6.3",
92
- "ssh2": "^1.16.0",
93
- "strip-ansi": "^7.1.0",
88
+ "rollup": "^4.50.2",
89
+ "sass": "^1.92.1",
90
+ "sass-loader": "^16.0.5",
91
+ "semver": "^7.7.2",
92
+ "ssh2": "^1.17.0",
93
+ "strip-ansi": "^7.1.2",
94
94
  "style-loader": "^4.0.0",
95
- "tailwindcss": "^3.4.14",
96
- "terser": "^5.36.0",
97
- "terser-webpack-plugin": "^5.3.10",
95
+ "tailwindcss": "^4.1.13",
96
+ "terser": "^5.44.0",
97
+ "terser-webpack-plugin": "^5.3.14",
98
98
  "through2": "^4.0.2",
99
99
  "through2-concurrent": "^2.0.0",
100
100
  "tslib": "^2.8.1",
101
101
  "vinyl-sourcemaps-apply": "^0.2.1",
102
- "webpack": "^5.96.1",
102
+ "webpack": "^5.101.3",
103
103
  "webpack-bundle-analyzer": "^4.10.2",
104
- "webpack-dev-middleware": "^7.4.2",
104
+ "webpack-dev-middleware": "^7.4.3",
105
105
  "webpack-hot-middleware": "^2.26.1",
106
106
  "webpack-merge": "^6.0.1",
107
107
  "workbox-build": "^7.3.0"
@@ -129,7 +129,7 @@
129
129
  "imagemin-svgo": "^9.0.0"
130
130
  },
131
131
  "engines": {
132
- "node": ">=18.12.0"
132
+ "node": "^20.10.0 || >=22.0.0"
133
133
  },
134
- "gitHead": "521b594f027ef38e58fbe73b8fcee670082e4b03"
134
+ "gitHead": "c947ae1b5d1e83cabaa4a6737a9532fcab42503a"
135
135
  }
@@ -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;
@@ -55,7 +55,7 @@ function gulpImagemin(customPlugins) {
55
55
  totalFiles++;
56
56
  }
57
57
  BalmJS.logger.debug(PLUGIN_NAME, `${file.relative} (${message})`);
58
- file.contents = data;
58
+ file.contents = Buffer.from(data);
59
59
  callback(null, file);
60
60
  }
61
61
  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;
@@ -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 };
@@ -47,7 +47,9 @@ class BalmStyleTask extends BalmTask {
47
47
  }));
48
48
  switch (style) {
49
49
  case 'sass':
50
- stream = stream.pipe(BalmJS.plugins.sass(options));
50
+ stream = stream.pipe(node.isLegacySass
51
+ ? BalmJS.plugins.legacySass(options)
52
+ : BalmJS.plugins.sass(options));
51
53
  break;
52
54
  case 'less':
53
55
  stream = stream.pipe(BalmJS.plugins.less(options));
@@ -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
  ? {
9
8
  includePaths: BalmJS.file.stylePaths,
10
9
  outputStyle: 'expanded'