-
Notifications
You must be signed in to change notification settings - Fork 31
/
gulp-sass+5.1.0.patch
351 lines (340 loc) · 10.5 KB
/
gulp-sass+5.1.0.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
diff --git a/node_modules/gulp-sass/index.js b/node_modules/gulp-sass/index.js
index 3a027bc..10182c3 100644
--- a/node_modules/gulp-sass/index.js
+++ b/node_modules/gulp-sass/index.js
@@ -24,13 +24,19 @@ const transfob = (transform) => new Transform({ transform, objectMode: true });
/**
* Handles returning the file to the stream
*/
-const filePush = (file, sassObject, callback) => {
+const filePush = (file, compileResult, callback) => {
+ file.contents = Buffer.from(compileResult.css);
+ file.path = replaceExtension(file.path, '.css');
+
// Build Source Maps!
- if (sassObject.map) {
- // Transform map into JSON
- const sassMap = JSON.parse(sassObject.map.toString());
- // Grab the stdout and transform it into stdin
- const sassMapFile = sassMap.file.replace(/^stdout$/, 'stdin');
+ if (compileResult.sourceMap) {
+ const sassMap = compileResult.sourceMap;
+
+ const sassMapFile = file.path;
+ if (!sassMap.file) {
+ sassMap.file = sassMapFile;
+ }
+
// Grab the base filename that's being worked on
const sassFileSrc = file.relative;
// Grab the path portion of the file that's being worked on
@@ -39,11 +45,9 @@ const filePush = (file, sassObject, callback) => {
if (sassFileSrcPath) {
const sourceFileIndex = sassMap.sources.indexOf(sassMapFile);
// Prepend the path to all files in the sources array except the file that's being worked on
- sassMap.sources = sassMap.sources.map((source, index) => (
- index === sourceFileIndex
- ? source
- : path.join(sassFileSrcPath, source)
- ));
+ sassMap.sources = sassMap.sources.map((source, index) =>
+ index === sourceFileIndex ? source : path.join(sassFileSrcPath, source)
+ );
}
// Remove 'stdin' from souces and replace with filenames!
@@ -55,9 +59,6 @@ const filePush = (file, sassObject, callback) => {
applySourceMap(file, sassMap);
}
- file.contents = sassObject.css;
- file.path = replaceExtension(file.path, '.css');
-
if (file.stat) {
file.stat.atime = file.stat.mtime = file.stat.ctime = new Date();
}
@@ -110,52 +111,47 @@ const gulpSass = (options, sync) => {
}
const opts = clonedeep(options || {});
- opts.data = file.contents.toString();
- // We set the file path here so that libsass can correctly resolve import paths
- opts.file = file.path;
-
- // Ensure `indentedSyntax` is true if a `.sass` file
+ // Ensure `indented` if a `.sass` file
if (path.extname(file.path) === '.sass') {
- opts.indentedSyntax = true;
+ opts.syntax = 'indented';
}
// Ensure file's parent directory in the include path
- if (opts.includePaths) {
- if (typeof opts.includePaths === 'string') {
- opts.includePaths = [opts.includePaths];
+ if (opts.loadPaths) {
+ if (typeof opts.loadPaths === 'string') {
+ opts.loadPaths = [opts.loadPaths];
}
} else {
- opts.includePaths = [];
+ opts.loadPaths = [];
}
- opts.includePaths.unshift(path.dirname(file.path));
+ opts.loadPaths.unshift(path.dirname(file.path));
// Generate Source Maps if the source-map plugin is present
if (file.sourceMap) {
- opts.sourceMap = file.path;
- opts.omitSourceMapUrl = true;
- opts.sourceMapContents = true;
+ opts.sourceMap = true;
+ opts.sourceMapIncludeSources = true;
}
if (sync !== true) {
/**
- * Async Sass render
+ * Async Sass compile
*/
- gulpSass.compiler.render(opts, (error, obj) => {
- if (error) {
+ gulpSass.compiler
+ .compileAsync(file.path, opts)
+ .then((compileResult) => {
+ filePush(file, compileResult, callback);
+ })
+ .catch((error) => {
handleError(error, file, callback);
- return;
- }
-
- filePush(file, obj, callback);
- });
+ });
} else {
/**
- * Sync Sass render
+ * Sync Sass compile
*/
try {
- filePush(file, gulpSass.compiler.renderSync(opts), callback);
+ filePush(file, gulpSass.compiler.compile(opts), callback);
} catch (error) {
handleError(error, file, callback);
}
@@ -164,7 +160,7 @@ const gulpSass = (options, sync) => {
};
/**
- * Sync Sass render
+ * Sync Sass compile
*/
gulpSass.sync = (options) => gulpSass(options, true);
@@ -172,13 +168,13 @@ gulpSass.sync = (options) => gulpSass(options, true);
* Log errors nicely
*/
gulpSass.logError = function logError(error) {
- const message = new PluginError('sass', error.messageFormatted).toString();
+ const message = new PluginError('sass', error).toString();
process.stderr.write(`${message}\n`);
this.emit('end');
};
module.exports = (compiler) => {
- if (!compiler || !compiler.render) {
+ if (!compiler || !compiler.compile) {
const message = new PluginError(
PLUGIN_NAME,
MISSING_COMPILER_MESSAGE,
diff --git a/node_modules/gulp-sass/legacy.js b/node_modules/gulp-sass/legacy.js
new file mode 100644
index 0000000..3a027bc
--- /dev/null
+++ b/node_modules/gulp-sass/legacy.js
@@ -0,0 +1,193 @@
+'use strict';
+
+const path = require('path');
+const { Transform } = require('stream');
+const picocolors = require('picocolors');
+const PluginError = require('plugin-error');
+const replaceExtension = require('replace-ext');
+const stripAnsi = require('strip-ansi');
+const clonedeep = require('lodash.clonedeep');
+const applySourceMap = require('vinyl-sourcemaps-apply');
+
+const PLUGIN_NAME = 'gulp-sass';
+
+const MISSING_COMPILER_MESSAGE = `
+gulp-sass no longer has a default Sass compiler; please set one yourself.
+Both the "sass" and "node-sass" packages are permitted.
+For example, in your gulpfile:
+
+ const sass = require('gulp-sass')(require('sass'));
+`;
+
+const transfob = (transform) => new Transform({ transform, objectMode: true });
+
+/**
+ * Handles returning the file to the stream
+ */
+const filePush = (file, sassObject, callback) => {
+ // Build Source Maps!
+ if (sassObject.map) {
+ // Transform map into JSON
+ const sassMap = JSON.parse(sassObject.map.toString());
+ // Grab the stdout and transform it into stdin
+ const sassMapFile = sassMap.file.replace(/^stdout$/, 'stdin');
+ // Grab the base filename that's being worked on
+ const sassFileSrc = file.relative;
+ // Grab the path portion of the file that's being worked on
+ const sassFileSrcPath = path.dirname(sassFileSrc);
+
+ if (sassFileSrcPath) {
+ const sourceFileIndex = sassMap.sources.indexOf(sassMapFile);
+ // Prepend the path to all files in the sources array except the file that's being worked on
+ sassMap.sources = sassMap.sources.map((source, index) => (
+ index === sourceFileIndex
+ ? source
+ : path.join(sassFileSrcPath, source)
+ ));
+ }
+
+ // Remove 'stdin' from souces and replace with filenames!
+ sassMap.sources = sassMap.sources.filter((src) => src !== 'stdin' && src);
+
+ // Replace the map file with the original filename (but new extension)
+ sassMap.file = replaceExtension(sassFileSrc, '.css');
+ // Apply the map
+ applySourceMap(file, sassMap);
+ }
+
+ file.contents = sassObject.css;
+ file.path = replaceExtension(file.path, '.css');
+
+ if (file.stat) {
+ file.stat.atime = file.stat.mtime = file.stat.ctime = new Date();
+ }
+
+ callback(null, file);
+};
+
+/**
+ * Handles error message
+ */
+const handleError = (error, file, callback) => {
+ const filePath = (error.file === 'stdin' ? file.path : error.file) || file.path;
+ const relativePath = path.relative(process.cwd(), filePath);
+ const message = `${picocolors.underline(relativePath)}\n${error.formatted}`;
+
+ error.messageFormatted = message;
+ error.messageOriginal = error.message;
+ error.message = stripAnsi(message);
+ error.relativePath = relativePath;
+
+ return callback(new PluginError(PLUGIN_NAME, error));
+};
+
+/**
+ * Main Gulp Sass function
+ */
+
+// eslint-disable-next-line arrow-body-style
+const gulpSass = (options, sync) => {
+ return transfob((file, encoding, callback) => {
+ if (file.isNull()) {
+ callback(null, file);
+ return;
+ }
+
+ if (file.isStream()) {
+ callback(new PluginError(PLUGIN_NAME, 'Streaming not supported'));
+ return;
+ }
+
+ if (path.basename(file.path).startsWith('_')) {
+ callback();
+ return;
+ }
+
+ if (!file.contents.length) {
+ file.path = replaceExtension(file.path, '.css');
+ callback(null, file);
+ return;
+ }
+
+ const opts = clonedeep(options || {});
+ opts.data = file.contents.toString();
+
+ // We set the file path here so that libsass can correctly resolve import paths
+ opts.file = file.path;
+
+ // Ensure `indentedSyntax` is true if a `.sass` file
+ if (path.extname(file.path) === '.sass') {
+ opts.indentedSyntax = true;
+ }
+
+ // Ensure file's parent directory in the include path
+ if (opts.includePaths) {
+ if (typeof opts.includePaths === 'string') {
+ opts.includePaths = [opts.includePaths];
+ }
+ } else {
+ opts.includePaths = [];
+ }
+
+ opts.includePaths.unshift(path.dirname(file.path));
+
+ // Generate Source Maps if the source-map plugin is present
+ if (file.sourceMap) {
+ opts.sourceMap = file.path;
+ opts.omitSourceMapUrl = true;
+ opts.sourceMapContents = true;
+ }
+
+ if (sync !== true) {
+ /**
+ * Async Sass render
+ */
+ gulpSass.compiler.render(opts, (error, obj) => {
+ if (error) {
+ handleError(error, file, callback);
+ return;
+ }
+
+ filePush(file, obj, callback);
+ });
+ } else {
+ /**
+ * Sync Sass render
+ */
+ try {
+ filePush(file, gulpSass.compiler.renderSync(opts), callback);
+ } catch (error) {
+ handleError(error, file, callback);
+ }
+ }
+ });
+};
+
+/**
+ * Sync Sass render
+ */
+gulpSass.sync = (options) => gulpSass(options, true);
+
+/**
+ * Log errors nicely
+ */
+gulpSass.logError = function logError(error) {
+ const message = new PluginError('sass', error.messageFormatted).toString();
+ process.stderr.write(`${message}\n`);
+ this.emit('end');
+};
+
+module.exports = (compiler) => {
+ if (!compiler || !compiler.render) {
+ const message = new PluginError(
+ PLUGIN_NAME,
+ MISSING_COMPILER_MESSAGE,
+ { showProperties: false },
+ ).toString();
+ process.stderr.write(`${message}\n`);
+ process.exit(1);
+ }
+
+ gulpSass.compiler = compiler;
+ return gulpSass;
+};