balm-core 3.23.2 → 3.23.3
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/lib/plugins/sass.js +88 -78
- package/package.json +2 -2
- package/tslib/plugins/sass.js +50 -53
package/lib/plugins/sass.js
CHANGED
|
@@ -7,36 +7,111 @@ 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
|
+
|
|
10
14
|
var _replaceExt = _interopRequireDefault(require("replace-ext"));
|
|
11
15
|
|
|
12
16
|
var _vinylSourcemapsApply = _interopRequireDefault(require("vinyl-sourcemaps-apply"));
|
|
13
17
|
|
|
18
|
+
// Reference `gulp-sass@5.1.0`
|
|
14
19
|
var PLUGIN_NAME = 'sass';
|
|
15
20
|
|
|
16
|
-
|
|
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
|
+
}; //////////////////////////////
|
|
17
86
|
// Main Gulp Sass function
|
|
18
87
|
//////////////////////////////
|
|
88
|
+
|
|
89
|
+
|
|
19
90
|
var gulpSass = function gulpSass(options) {
|
|
20
|
-
return
|
|
91
|
+
return transformObj(function (file, encoding, callback) {
|
|
21
92
|
if (file.isNull()) {
|
|
22
|
-
|
|
93
|
+
callback(null, file);
|
|
94
|
+
return;
|
|
23
95
|
}
|
|
24
96
|
|
|
25
97
|
if (file.isStream()) {
|
|
26
|
-
|
|
98
|
+
callback(new PluginError(PLUGIN_NAME, 'Streaming not supported'));
|
|
99
|
+
return;
|
|
27
100
|
}
|
|
28
101
|
|
|
29
|
-
if (path.basename(file.path).
|
|
30
|
-
|
|
102
|
+
if (path.basename(file.path).startsWith('_')) {
|
|
103
|
+
callback();
|
|
104
|
+
return;
|
|
31
105
|
}
|
|
32
106
|
|
|
33
107
|
if (!file.contents.length) {
|
|
34
108
|
file.path = (0, _replaceExt["default"])(file.path, '.css');
|
|
35
|
-
|
|
109
|
+
callback(null, file);
|
|
110
|
+
return;
|
|
36
111
|
}
|
|
37
112
|
|
|
38
113
|
var opts = options || {};
|
|
39
|
-
opts.data = file.contents.toString(); //
|
|
114
|
+
opts.data = file.contents.toString(); // We set the file path here so that libsass can correctly resolve import paths
|
|
40
115
|
|
|
41
116
|
opts.file = file.path; // Ensure `indentedSyntax` is true if a `.sass` file
|
|
42
117
|
|
|
@@ -53,90 +128,25 @@ var gulpSass = function gulpSass(options) {
|
|
|
53
128
|
opts.includePaths = [];
|
|
54
129
|
}
|
|
55
130
|
|
|
56
|
-
opts.includePaths.unshift(path.dirname(file.path)); // Generate Source Maps if
|
|
131
|
+
opts.includePaths.unshift(path.dirname(file.path)); // Generate Source Maps if the source-map plugin is present
|
|
57
132
|
|
|
58
133
|
if (file.sourceMap) {
|
|
59
134
|
opts.sourceMap = file.path;
|
|
60
135
|
opts.omitSourceMapUrl = true;
|
|
61
136
|
opts.sourceMapContents = true;
|
|
62
137
|
} //////////////////////////////
|
|
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
|
-
}; //////////////////////////////
|
|
125
138
|
// Sync Sass render
|
|
126
139
|
//////////////////////////////
|
|
127
140
|
|
|
128
141
|
|
|
129
142
|
try {
|
|
130
|
-
gulpSass.compiler && filePush(gulpSass.compiler.renderSync(opts));
|
|
143
|
+
gulpSass.compiler && filePush(file, gulpSass.compiler.renderSync(opts), callback);
|
|
131
144
|
} catch (error) {
|
|
132
|
-
|
|
145
|
+
handleError(error, file, callback);
|
|
133
146
|
}
|
|
134
147
|
});
|
|
135
148
|
};
|
|
136
149
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
return gulpSass(options);
|
|
140
|
-
};
|
|
141
|
-
|
|
150
|
+
gulpSass.compiler = _sass["default"];
|
|
151
|
+
var _default = gulpSass;
|
|
142
152
|
exports["default"] = _default;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "balm-core",
|
|
3
|
-
"version": "3.23.
|
|
3
|
+
"version": "3.23.3",
|
|
4
4
|
"description": "BalmJS compiler core",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"balm",
|
|
@@ -117,5 +117,5 @@
|
|
|
117
117
|
"engines": {
|
|
118
118
|
"node": ">=10.13.0"
|
|
119
119
|
},
|
|
120
|
-
"gitHead": "
|
|
120
|
+
"gitHead": "d2b8507e8b5ca3458ef44c01761c0d66908486d5"
|
|
121
121
|
}
|
package/tslib/plugins/sass.js
CHANGED
|
@@ -1,22 +1,61 @@
|
|
|
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"));
|
|
4
6
|
const replace_ext_1 = tslib_1.__importDefault(require("replace-ext"));
|
|
5
7
|
const vinyl_sourcemaps_apply_1 = tslib_1.__importDefault(require("vinyl-sourcemaps-apply"));
|
|
6
8
|
const PLUGIN_NAME = 'sass';
|
|
7
|
-
const
|
|
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) => {
|
|
8
43
|
if (file.isNull()) {
|
|
9
|
-
|
|
44
|
+
callback(null, file);
|
|
45
|
+
return;
|
|
10
46
|
}
|
|
11
47
|
if (file.isStream()) {
|
|
12
|
-
|
|
48
|
+
callback(new PluginError(PLUGIN_NAME, 'Streaming not supported'));
|
|
49
|
+
return;
|
|
13
50
|
}
|
|
14
|
-
if (path.basename(file.path).
|
|
15
|
-
|
|
51
|
+
if (path.basename(file.path).startsWith('_')) {
|
|
52
|
+
callback();
|
|
53
|
+
return;
|
|
16
54
|
}
|
|
17
55
|
if (!file.contents.length) {
|
|
18
56
|
file.path = (0, replace_ext_1.default)(file.path, '.css');
|
|
19
|
-
|
|
57
|
+
callback(null, file);
|
|
58
|
+
return;
|
|
20
59
|
}
|
|
21
60
|
const opts = (options || {});
|
|
22
61
|
opts.data = file.contents.toString();
|
|
@@ -38,55 +77,13 @@ const gulpSass = (options) => through2.obj((file, encoding, cb) => {
|
|
|
38
77
|
opts.omitSourceMapUrl = true;
|
|
39
78
|
opts.sourceMapContents = true;
|
|
40
79
|
}
|
|
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
|
-
};
|
|
82
80
|
try {
|
|
83
|
-
gulpSass.compiler &&
|
|
81
|
+
gulpSass.compiler &&
|
|
82
|
+
filePush(file, gulpSass.compiler.renderSync(opts), callback);
|
|
84
83
|
}
|
|
85
84
|
catch (error) {
|
|
86
|
-
|
|
85
|
+
handleError(error, file, callback);
|
|
87
86
|
}
|
|
88
87
|
});
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
return gulpSass(options);
|
|
92
|
-
};
|
|
88
|
+
gulpSass.compiler = sass_1.default;
|
|
89
|
+
exports.default = gulpSass;
|