balm-core 5.0.1 → 5.1.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 +1 -1
- package/index.d.ts +7 -0
- package/lib/balm.js +2 -2
- package/lib/bundler/webpack/config/env.js +1 -1
- package/lib/config/globals.js +14 -1
- package/lib/plugins/imagemin.js +13 -8
- package/lib/plugins/index.js +2 -0
- package/lib/plugins/postcss.js +2 -2
- package/lib/plugins/rename.js +1 -3
- package/lib/plugins/replace.js +4 -2
- package/lib/plugins/sass-legacy.js +131 -0
- package/lib/plugins/sass.js +66 -125
- package/lib/tasks/foundation/balm.js +3 -2
- package/lib/tasks/foundation/balm_style.js +1 -1
- package/lib/tasks/private/build.js +1 -1
- package/lib/tasks/private/cache.js +1 -1
- package/lib/tasks/private/clean.js +3 -3
- package/lib/tasks/private/end.js +1 -1
- package/lib/tasks/private/extra.js +1 -1
- package/lib/tasks/private/font.js +1 -1
- package/lib/tasks/private/image.js +3 -2
- package/lib/tasks/private/lint.js +1 -1
- package/lib/tasks/private/media.js +1 -1
- package/lib/tasks/private/modernizr.js +3 -3
- package/lib/tasks/private/pwa-cache.js +1 -1
- package/lib/tasks/private/sprite.js +5 -3
- package/lib/tasks/private/start.js +1 -1
- package/lib/tasks/private/workbox-sw.js +1 -1
- package/lib/tasks/public/html.js +2 -2
- package/lib/tasks/public/publish.js +2 -2
- package/lib/tasks/public/remove.js +2 -2
- package/lib/tasks/public/sass.js +1 -2
- package/lib/tasks/public/server.js +2 -2
- package/lib/tasks/public/url.js +2 -2
- package/lib/utilities/compiling.js +2 -2
- package/lib/utilities/loading.js +2 -2
- package/lib/utilities/logger.js +2 -2
- package/package.json +53 -52
- package/tslib/balm.js +5 -8
- package/tslib/config/globals.js +21 -1
- package/tslib/plugins/imagemin.js +13 -8
- package/tslib/plugins/index.js +2 -0
- package/tslib/plugins/rename.js +1 -1
- package/tslib/plugins/replace.js +2 -1
- package/tslib/plugins/sass-legacy.js +95 -0
- package/tslib/plugins/sass.js +62 -124
- package/tslib/tasks/foundation/balm.js +10 -7
- package/tslib/tasks/foundation/balm_style.js +3 -1
- package/tslib/tasks/private/build.js +7 -7
- package/tslib/tasks/private/cache.js +10 -10
- package/tslib/tasks/private/clean.js +28 -31
- package/tslib/tasks/private/end.js +8 -8
- package/tslib/tasks/private/extra.js +7 -7
- package/tslib/tasks/private/font.js +4 -4
- package/tslib/tasks/private/image.js +16 -15
- package/tslib/tasks/private/lint.js +9 -9
- package/tslib/tasks/private/media.js +4 -4
- package/tslib/tasks/private/modernizr.js +40 -43
- package/tslib/tasks/private/pwa-cache.js +11 -11
- package/tslib/tasks/private/sprite.js +37 -40
- package/tslib/tasks/private/start.js +7 -7
- package/tslib/tasks/private/workbox-sw.js +4 -4
- package/tslib/tasks/public/html.js +23 -26
- package/tslib/tasks/public/publish.js +13 -16
- package/tslib/tasks/public/remove.js +8 -11
- package/tslib/tasks/public/sass.js +1 -2
- package/tslib/tasks/public/server.js +34 -37
- package/tslib/tasks/public/url.js +16 -19
- package/tslib/utilities/compiling.js +4 -9
- package/tslib/utilities/loading.js +8 -14
- package/tslib/utilities/logger.js +13 -18
package/README.md
CHANGED
package/index.d.ts
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
export * from './types/vendors';
|
|
2
|
+
export * from './types/globals';
|
|
3
|
+
export * from './types/webworker';
|
|
4
|
+
export * from './types/balm';
|
|
5
|
+
export * from './types/gulp';
|
|
6
|
+
export * from './types/node';
|
|
7
|
+
|
|
1
8
|
export interface LooseObject {
|
|
2
9
|
[key: string]: any;
|
|
3
10
|
}
|
package/lib/balm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
function _classPrivateFieldInitSpec(
|
|
2
|
-
function _checkPrivateRedeclaration(
|
|
1
|
+
function _classPrivateFieldInitSpec(e, t, a) { _checkPrivateRedeclaration(e, t), t.set(e, a); }
|
|
2
|
+
function _checkPrivateRedeclaration(e, t) { if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object"); }
|
|
3
3
|
function _classPrivateFieldGet(s, a) { return s.get(_assertClassBrand(s, a)); }
|
|
4
4
|
function _classPrivateFieldSet(s, a, r) { return s.set(_assertClassBrand(s, a), r), r; }
|
|
5
5
|
function _assertClassBrand(e, t, n) { if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n; throw new TypeError("Private element is not present on this object"); }
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
2
2
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
3
|
-
function _defineProperty(
|
|
3
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
4
4
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
5
5
|
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
6
6
|
import dotenv from 'dotenv';
|
package/lib/config/globals.js
CHANGED
|
@@ -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;
|
package/lib/plugins/imagemin.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Reference `gulp-imagemin@9.
|
|
1
|
+
// Reference `gulp-imagemin@9.1.0`
|
|
2
2
|
|
|
3
3
|
import imagemin from 'imagemin';
|
|
4
4
|
import prettyBytes from 'pretty-bytes';
|
|
@@ -6,11 +6,16 @@ import through2Concurrent from 'through2-concurrent';
|
|
|
6
6
|
const PLUGIN_NAME = 'imagemin';
|
|
7
7
|
const defaultPlugins = ['gifsicle', 'mozjpeg', 'optipng', 'svgo'];
|
|
8
8
|
const loadPlugin = (plugin, ...args) => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
return async input => {
|
|
10
|
+
try {
|
|
11
|
+
const m = await import(`imagemin-${plugin}`);
|
|
12
|
+
const pluginFn = m.default(...args);
|
|
13
|
+
return pluginFn(input);
|
|
14
|
+
} catch (_) {
|
|
15
|
+
BalmJS.logger.error(PLUGIN_NAME, `Could not load default plugin \`${plugin}\``);
|
|
16
|
+
return input;
|
|
17
|
+
}
|
|
18
|
+
};
|
|
14
19
|
};
|
|
15
20
|
const exposePlugin = plugin => (...args) => loadPlugin(plugin, ...args);
|
|
16
21
|
const getDefaultPlugins = () => defaultPlugins.flatMap(plugin => loadPlugin(plugin));
|
|
@@ -40,7 +45,7 @@ function gulpImagemin(customPlugins) {
|
|
|
40
45
|
(async () => {
|
|
41
46
|
try {
|
|
42
47
|
const data = await imagemin.buffer(file.contents, {
|
|
43
|
-
plugins
|
|
48
|
+
plugins: plugins
|
|
44
49
|
});
|
|
45
50
|
const originalSize = file.contents.length;
|
|
46
51
|
const optimizedSize = data.length;
|
|
@@ -54,7 +59,7 @@ function gulpImagemin(customPlugins) {
|
|
|
54
59
|
totalFiles++;
|
|
55
60
|
}
|
|
56
61
|
BalmJS.logger.debug(PLUGIN_NAME, `${file.relative} (${message})`);
|
|
57
|
-
file.contents = data;
|
|
62
|
+
file.contents = Buffer.from(data);
|
|
58
63
|
callback(null, file);
|
|
59
64
|
} catch (error) {
|
|
60
65
|
callback(new PluginError(PLUGIN_NAME, error, {
|
package/lib/plugins/index.js
CHANGED
|
@@ -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;
|
package/lib/plugins/postcss.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Reference `gulp-postcss@
|
|
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
|
});
|
package/lib/plugins/rename.js
CHANGED
|
@@ -13,9 +13,7 @@ function gulpRename(obj, options = {}) {
|
|
|
13
13
|
};
|
|
14
14
|
};
|
|
15
15
|
stream._transform = (chunk, unused, callback) => {
|
|
16
|
-
const file = chunk.clone(
|
|
17
|
-
contents: false
|
|
18
|
-
});
|
|
16
|
+
const file = chunk.clone();
|
|
19
17
|
let parsedPath = parsePath(file.relative);
|
|
20
18
|
let _path;
|
|
21
19
|
const type = typeof obj;
|
package/lib/plugins/replace.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
2
2
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
3
|
-
function _defineProperty(
|
|
3
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
4
4
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
5
5
|
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
6
6
|
// Reference `gulp-replace@1.1.4`
|
|
7
7
|
import { Transform } from 'node:stream';
|
|
8
|
-
|
|
8
|
+
// @ts-ignore
|
|
9
|
+
import * as isTextModule from 'istextorbinary';
|
|
9
10
|
import rs from '../utilities/replacestream.js';
|
|
11
|
+
const isText = isTextModule.isText || isTextModule;
|
|
10
12
|
const defaultOptions = {
|
|
11
13
|
skipBinary: true
|
|
12
14
|
};
|
|
@@ -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;
|
package/lib/plugins/sass.js
CHANGED
|
@@ -1,24 +1,11 @@
|
|
|
1
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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 (
|
|
50
|
-
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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
|
-
//
|
|
65
|
-
sassMap.sources = sassMap.sources.
|
|
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.
|
|
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
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
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
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
opts.
|
|
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
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
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
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
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;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
function _defineProperty(
|
|
1
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
2
2
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
3
3
|
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
4
4
|
class BalmTask {
|
|
@@ -31,7 +31,8 @@ class BalmTask {
|
|
|
31
31
|
}
|
|
32
32
|
get src() {
|
|
33
33
|
return gulp.src(this.input, Object.assign({
|
|
34
|
-
allowEmpty: true
|
|
34
|
+
allowEmpty: true,
|
|
35
|
+
encoding: false
|
|
35
36
|
}, this.gulpSrcOptions)).pipe(BalmJS.plugins.plumber(error => {
|
|
36
37
|
BalmJS.logger.error(`${this.name} task`, error.message);
|
|
37
38
|
}));
|
|
@@ -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,4 +1,4 @@
|
|
|
1
|
-
function _defineProperty(
|
|
1
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
2
2
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
3
3
|
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
4
4
|
import gulpSize from 'gulp-size';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
function _defineProperty(
|
|
1
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
2
2
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
3
3
|
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
4
4
|
import revAll from 'gulp-rev-all';
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
function _defineProperty(
|
|
1
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
2
2
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
3
3
|
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
4
|
-
function _classPrivateFieldInitSpec(
|
|
5
|
-
function _checkPrivateRedeclaration(
|
|
4
|
+
function _classPrivateFieldInitSpec(e, t, a) { _checkPrivateRedeclaration(e, t), t.set(e, a); }
|
|
5
|
+
function _checkPrivateRedeclaration(e, t) { if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object"); }
|
|
6
6
|
function _classPrivateFieldGet(s, a) { return s.get(_assertClassBrand(s, a)); }
|
|
7
7
|
function _assertClassBrand(e, t, n) { if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n; throw new TypeError("Private element is not present on this object"); }
|
|
8
8
|
import { deleteAsync } from 'del';
|
package/lib/tasks/private/end.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
function _defineProperty(
|
|
1
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
2
2
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
3
3
|
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
4
4
|
class EndTask extends BalmJS.BalmTask {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
function _defineProperty(
|
|
1
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
2
2
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
3
3
|
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
4
4
|
class ExtraTask extends BalmJS.BalmTask {
|