balm-core 3.23.1 → 3.23.2

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.
@@ -7,111 +7,36 @@ Object.defineProperty(exports, "__esModule", {
7
7
  });
8
8
  exports["default"] = void 0;
9
9
 
10
- var _stream = require("stream");
11
-
12
- var _sass = _interopRequireDefault(require("sass"));
13
-
14
10
  var _replaceExt = _interopRequireDefault(require("replace-ext"));
15
11
 
16
12
  var _vinylSourcemapsApply = _interopRequireDefault(require("vinyl-sourcemaps-apply"));
17
13
 
18
- // Reference `gulp-sass@5.1.0`
19
14
  var PLUGIN_NAME = 'sass';
20
15
 
21
- var transformObj = function transformObj(transform) {
22
- return new _stream.Transform({
23
- transform: transform,
24
- objectMode: true
25
- });
26
- };
27
- /**
28
- * Handles returning the file to the stream
29
- */
30
-
31
-
32
- var filePush = function filePush(file, sassObject, callback) {
33
- // Build Source Maps!
34
- if (sassObject.map) {
35
- // Transform map into JSON
36
- var sassMap = JSON.parse(sassObject.map.toString()); // Grab the stdout and transform it into stdin
37
-
38
- var sassMapFile = sassMap.file.replace(/^stdout$/, 'stdin'); // Grab the base filename that's being worked on
39
-
40
- var sassFileSrc = file.relative; // Grab the path portion of the file that's being worked on
41
-
42
- var sassFileSrcPath = path.dirname(sassFileSrc);
43
-
44
- if (sassFileSrcPath) {
45
- var sourceFileIndex = sassMap.sources.indexOf(sassMapFile); // Prepend the path to all files in the sources array except the file that's being worked on
46
-
47
- sassMap.sources = sassMap.sources.map(function (source, index) {
48
- return index === sourceFileIndex ? source : path.join(sassFileSrcPath, source);
49
- });
50
- } // Remove 'stdin' from sources and replace with filenames!
51
-
52
-
53
- sassMap.sources = sassMap.sources.filter(function (src) {
54
- return src !== 'stdin' && src;
55
- }); // Replace the map file with the original filename (but new extension)
56
-
57
- sassMap.file = (0, _replaceExt["default"])(sassFileSrc, '.css'); // Apply the map
58
-
59
- (0, _vinylSourcemapsApply["default"])(file, sassMap);
60
- }
61
-
62
- file.contents = sassObject.css;
63
- file.path = (0, _replaceExt["default"])(file.path, '.css');
64
-
65
- if (file.stat) {
66
- file.stat.atime = file.stat.mtime = file.stat.ctime = new Date();
67
- }
68
-
69
- callback(null, file);
70
- };
71
- /**
72
- * Handles error message
73
- */
74
-
75
-
76
- var handleError = function handleError(error, file, callback) {
77
- var filePath = (error.file === 'stdin' ? file.path : error.file) || file.path;
78
- var relativePath = path.relative(process.cwd(), filePath);
79
- var message = "".concat(require('ansi-colors').underline(relativePath), "\n").concat(error.formatted);
80
- error.messageFormatted = message;
81
- error.messageOriginal = error.message;
82
- error.message = require('strip-ansi')(message);
83
- error.relativePath = relativePath;
84
- return callback(new PluginError(PLUGIN_NAME, error));
85
- }; //////////////////////////////
16
+ //////////////////////////////
86
17
  // Main Gulp Sass function
87
18
  //////////////////////////////
88
-
89
-
90
19
  var gulpSass = function gulpSass(options) {
91
- return transformObj(function (file, encoding, callback) {
20
+ return through2.obj(function (file, encoding, cb) {
92
21
  if (file.isNull()) {
93
- callback(null, file);
94
- return;
22
+ return cb(null, file);
95
23
  }
96
24
 
97
25
  if (file.isStream()) {
98
- callback(new PluginError(PLUGIN_NAME, 'Streaming not supported'));
99
- return;
26
+ return cb(new PluginError(PLUGIN_NAME, 'Streaming not supported'));
100
27
  }
101
28
 
102
- if (path.basename(file.path).startsWith('_')) {
103
- callback();
104
- return;
29
+ if (path.basename(file.path).indexOf('_') === 0) {
30
+ return cb();
105
31
  }
106
32
 
107
33
  if (!file.contents.length) {
108
34
  file.path = (0, _replaceExt["default"])(file.path, '.css');
109
- callback(null, file);
110
- return;
35
+ return cb(null, file);
111
36
  }
112
37
 
113
38
  var opts = options || {};
114
- opts.data = file.contents.toString(); // We set the file path here so that libsass can correctly resolve import paths
39
+ opts.data = file.contents.toString(); // we set the file path here so that libsass can correctly resolve import paths
115
40
 
116
41
  opts.file = file.path; // Ensure `indentedSyntax` is true if a `.sass` file
117
42
 
@@ -128,25 +53,90 @@ var gulpSass = function gulpSass(options) {
128
53
  opts.includePaths = [];
129
54
  }
130
55
 
131
- opts.includePaths.unshift(path.dirname(file.path)); // Generate Source Maps if the source-map plugin is present
56
+ opts.includePaths.unshift(path.dirname(file.path)); // Generate Source Maps if plugin source-map present
132
57
 
133
58
  if (file.sourceMap) {
134
59
  opts.sourceMap = file.path;
135
60
  opts.omitSourceMapUrl = true;
136
61
  opts.sourceMapContents = true;
137
62
  } //////////////////////////////
63
+ // Handles returning the file to the stream
64
+ //////////////////////////////
65
+
66
+
67
+ var filePush = function filePush(sassObj) {
68
+ var sassMap;
69
+ var sassMapFile;
70
+ var sassFileSrc;
71
+ var sassFileSrcPath;
72
+ var sourceFileIndex; // Build Source Maps!
73
+
74
+ if (sassObj.map) {
75
+ // Transform map into JSON
76
+ sassMap = JSON.parse(sassObj.map.toString()); // Grab the stdout and transform it into stdin
77
+
78
+ sassMapFile = sassMap.file.replace(/^stdout$/, 'stdin'); // Grab the base file name that's being worked on
79
+
80
+ sassFileSrc = file.relative; // Grab the path portion of the file that's being worked on
81
+
82
+ sassFileSrcPath = path.dirname(sassFileSrc);
83
+
84
+ if (sassFileSrcPath) {
85
+ // Prepend the path to all files in the sources array except the file that's being worked on
86
+ sourceFileIndex = sassMap.sources.indexOf(sassMapFile);
87
+ sassMap.sources = sassMap.sources.map(function (source, index) {
88
+ return index === sourceFileIndex ? source : path.join(sassFileSrcPath, source);
89
+ });
90
+ } // Remove 'stdin' from sources and replace with filenames!
91
+
92
+
93
+ sassMap.sources = sassMap.sources.filter(function (src) {
94
+ return src !== 'stdin' && src;
95
+ }); // Replace the map file with the original file name (but new extension)
96
+
97
+ sassMap.file = (0, _replaceExt["default"])(sassFileSrc, '.css'); // Apply the map
98
+
99
+ (0, _vinylSourcemapsApply["default"])(file, sassMap);
100
+ }
101
+
102
+ file.contents = sassObj.css;
103
+ file.path = (0, _replaceExt["default"])(file.path, '.css');
104
+
105
+ if (file.stat) {
106
+ file.stat.atime = file.stat.mtime = file.stat.ctime = new Date();
107
+ }
108
+
109
+ cb(null, file);
110
+ }; //////////////////////////////
111
+ // Handles error message
112
+ //////////////////////////////
113
+
114
+
115
+ var errorM = function errorM(error) {
116
+ var filePath = (error.file === 'stdin' ? file.path : error.file) || file.path;
117
+ var relativePath = path.relative(process.cwd(), filePath);
118
+ var message = [relativePath, error.formatted].join('\n');
119
+ error.messageFormatted = message;
120
+ error.messageOriginal = error.message;
121
+ error.message = require('strip-ansi')(message);
122
+ error.relativePath = relativePath;
123
+ return cb(new PluginError(PLUGIN_NAME, error));
124
+ }; //////////////////////////////
138
125
  // Sync Sass render
139
126
  //////////////////////////////
140
127
 
141
128
 
142
129
  try {
143
- gulpSass.compiler && filePush(file, gulpSass.compiler.renderSync(opts), callback);
130
+ gulpSass.compiler && filePush(gulpSass.compiler.renderSync(opts));
144
131
  } catch (error) {
145
- handleError(error, file, callback);
132
+ return errorM(error);
146
133
  }
147
134
  });
148
135
  };
149
136
 
150
- gulpSass.compiler = _sass["default"];
151
- var _default = gulpSass;
137
+ var _default = function _default(options) {
138
+ gulpSass.compiler = require('sass');
139
+ return gulpSass(options);
140
+ };
141
+
152
142
  exports["default"] = _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "balm-core",
3
- "version": "3.23.1",
3
+ "version": "3.23.2",
4
4
  "description": "BalmJS compiler core",
5
5
  "keywords": [
6
6
  "balm",
@@ -89,7 +89,7 @@
89
89
  "ssh2": "0.8.9",
90
90
  "strip-ansi": "6",
91
91
  "style-loader": "2",
92
- "terser": "^5.13.0",
92
+ "terser": "^5.13.1",
93
93
  "terser-webpack-plugin": "4",
94
94
  "through2": "^4.0.2",
95
95
  "through2-concurrent": "^2.0.0",
@@ -117,5 +117,5 @@
117
117
  "engines": {
118
118
  "node": ">=10.13.0"
119
119
  },
120
- "gitHead": "dc9280e2ecb912ff389d795634ad460a4ac2e962"
120
+ "gitHead": "b411c85a2dac2c93648c22c7c662a90280246cd0"
121
121
  }
@@ -1,61 +1,22 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
- const stream_1 = require("stream");
5
- const sass_1 = tslib_1.__importDefault(require("sass"));
6
4
  const replace_ext_1 = tslib_1.__importDefault(require("replace-ext"));
7
5
  const vinyl_sourcemaps_apply_1 = tslib_1.__importDefault(require("vinyl-sourcemaps-apply"));
8
6
  const PLUGIN_NAME = 'sass';
9
- const transformObj = (transform) => new stream_1.Transform({ transform, objectMode: true });
10
- const 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 = path.dirname(sassFileSrc);
16
- if (sassFileSrcPath) {
17
- const sourceFileIndex = sassMap.sources.indexOf(sassMapFile);
18
- sassMap.sources = sassMap.sources.map((source, index) => index === sourceFileIndex ? source : path.join(sassFileSrcPath, source));
19
- }
20
- sassMap.sources = sassMap.sources.filter((src) => src !== 'stdin' && src);
21
- sassMap.file = (0, replace_ext_1.default)(sassFileSrc, '.css');
22
- (0, vinyl_sourcemaps_apply_1.default)(file, sassMap);
23
- }
24
- file.contents = sassObject.css;
25
- file.path = (0, replace_ext_1.default)(file.path, '.css');
26
- if (file.stat) {
27
- file.stat.atime = file.stat.mtime = file.stat.ctime = new Date();
28
- }
29
- callback(null, file);
30
- };
31
- const handleError = (error, file, callback) => {
32
- const filePath = ((error.file === 'stdin' ? file.path : error.file) ||
33
- file.path);
34
- const relativePath = path.relative(process.cwd(), filePath);
35
- const message = `${require('ansi-colors').underline(relativePath)}\n${error.formatted}`;
36
- error.messageFormatted = message;
37
- error.messageOriginal = error.message;
38
- error.message = require('strip-ansi')(message);
39
- error.relativePath = relativePath;
40
- return callback(new PluginError(PLUGIN_NAME, error));
41
- };
42
- const gulpSass = (options) => transformObj((file, encoding, callback) => {
7
+ const gulpSass = (options) => through2.obj((file, encoding, cb) => {
43
8
  if (file.isNull()) {
44
- callback(null, file);
45
- return;
9
+ return cb(null, file);
46
10
  }
47
11
  if (file.isStream()) {
48
- callback(new PluginError(PLUGIN_NAME, 'Streaming not supported'));
49
- return;
12
+ return cb(new PluginError(PLUGIN_NAME, 'Streaming not supported'));
50
13
  }
51
- if (path.basename(file.path).startsWith('_')) {
52
- callback();
53
- return;
14
+ if (path.basename(file.path).indexOf('_') === 0) {
15
+ return cb();
54
16
  }
55
17
  if (!file.contents.length) {
56
18
  file.path = (0, replace_ext_1.default)(file.path, '.css');
57
- callback(null, file);
58
- return;
19
+ return cb(null, file);
59
20
  }
60
21
  const opts = (options || {});
61
22
  opts.data = file.contents.toString();
@@ -77,13 +38,55 @@ const gulpSass = (options) => transformObj((file, encoding, callback) => {
77
38
  opts.omitSourceMapUrl = true;
78
39
  opts.sourceMapContents = true;
79
40
  }
41
+ const filePush = (sassObj) => {
42
+ let sassMap;
43
+ let sassMapFile;
44
+ let sassFileSrc;
45
+ let sassFileSrcPath;
46
+ let sourceFileIndex;
47
+ if (sassObj.map) {
48
+ sassMap = JSON.parse(sassObj.map.toString());
49
+ sassMapFile = sassMap.file.replace(/^stdout$/, 'stdin');
50
+ sassFileSrc = file.relative;
51
+ sassFileSrcPath = path.dirname(sassFileSrc);
52
+ if (sassFileSrcPath) {
53
+ sourceFileIndex = sassMap.sources.indexOf(sassMapFile);
54
+ sassMap.sources = sassMap.sources.map((source, index) => {
55
+ return index === sourceFileIndex
56
+ ? source
57
+ : path.join(sassFileSrcPath, source);
58
+ });
59
+ }
60
+ sassMap.sources = sassMap.sources.filter((src) => src !== 'stdin' && src);
61
+ sassMap.file = (0, replace_ext_1.default)(sassFileSrc, '.css');
62
+ (0, vinyl_sourcemaps_apply_1.default)(file, sassMap);
63
+ }
64
+ file.contents = sassObj.css;
65
+ file.path = (0, replace_ext_1.default)(file.path, '.css');
66
+ if (file.stat) {
67
+ file.stat.atime = file.stat.mtime = file.stat.ctime = new Date();
68
+ }
69
+ cb(null, file);
70
+ };
71
+ const errorM = (error) => {
72
+ const filePath = ((error.file === 'stdin' ? file.path : error.file) ||
73
+ file.path);
74
+ const relativePath = path.relative(process.cwd(), filePath);
75
+ const message = [relativePath, error.formatted].join('\n');
76
+ error.messageFormatted = message;
77
+ error.messageOriginal = error.message;
78
+ error.message = require('strip-ansi')(message);
79
+ error.relativePath = relativePath;
80
+ return cb(new PluginError(PLUGIN_NAME, error));
81
+ };
80
82
  try {
81
- gulpSass.compiler &&
82
- filePush(file, gulpSass.compiler.renderSync(opts), callback);
83
+ gulpSass.compiler && filePush(gulpSass.compiler.renderSync(opts));
83
84
  }
84
85
  catch (error) {
85
- handleError(error, file, callback);
86
+ return errorM(error);
86
87
  }
87
88
  });
88
- gulpSass.compiler = sass_1.default;
89
- exports.default = gulpSass;
89
+ exports.default = (options) => {
90
+ gulpSass.compiler = require('sass');
91
+ return gulpSass(options);
92
+ };