Skip to content

Commit 723bda0

Browse files
authored
fix(deps): Remove gulp-yaml-validate and replace with internal script (#4675)
1 parent b238ce3 commit 723bda0

File tree

4 files changed

+104
-28
lines changed

4 files changed

+104
-28
lines changed

package-lock.json

Lines changed: 17 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
"babel-loader": "8.1.0",
7575
"babel-polyfill": "6.26.0",
7676
"body-parser": "1.19.0",
77+
"bufferstreams": "^3.0.0",
7778
"chalk": "4.1.0",
7879
"classnames": "2.2.6",
7980
"conventional-changelog": "1.1.4",
@@ -131,7 +132,6 @@
131132
"gulp-stylelint": "13.0.0",
132133
"gulp-theo": "1.0.0-alpha.5",
133134
"gulp-util": "3.0.8",
134-
"gulp-yaml-validate": "1.0.2",
135135
"gulp-zip": "4.0.0",
136136
"husky": "4.2.5",
137137
"immutable": "3.8.2",

scripts/gulp/lint/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import lintspaces from 'gulp-lintspaces';
77
import eslint from 'gulp-eslint';
88
import stylelint from 'gulp-stylelint';
99
import htmlhint from 'gulp-htmlhint';
10-
import yamlValidate from 'gulp-yaml-validate';
10+
import yamlValidate from './validate-yaml.js';
1111

1212
import tokenlint from '../plugins/lint-tokens';
1313

scripts/gulp/lint/validate-yaml.js

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
// Copyright (c) 2015-present, salesforce.com, inc. All rights reserved
2+
// Licensed under BSD 3-Clause - see LICENSE.txt or git.io/sfdc-license
3+
4+
// Code in this file taken and modified from https://github.com/dtothefp/gulp-yaml-validate/blob/master/task/index.js
5+
6+
import through from 'through2';
7+
import path from 'path';
8+
import gutil, { PluginError } from 'gulp-util';
9+
import jsyaml from 'js-yaml';
10+
import extend from 'extend';
11+
import BufferStreams from 'bufferstreams';
12+
const PLUGIN_NAME = 'validate-yaml';
13+
14+
const yaml2json = (buffer, options) => {
15+
const htmlRe = /(<([^>]+)>)/gi;
16+
let contents = buffer.toString('utf8');
17+
if (options.html && htmlRe.test(contents)) {
18+
throw new Error('YML cannot contain HTML');
19+
} else {
20+
let ymlDocument = options.safe
21+
? jsyaml.safeLoad(contents)
22+
: jsyaml.load(contents);
23+
24+
return Buffer.from(
25+
JSON.stringify(ymlDocument, options.replacer, options.space)
26+
);
27+
}
28+
};
29+
30+
export default function(pluginOptions) {
31+
var options = extend(
32+
{
33+
safe: false,
34+
html: false,
35+
replacer: null,
36+
space: null
37+
},
38+
pluginOptions
39+
);
40+
41+
return through.obj(function(file, enc, cb) {
42+
const self = this;
43+
if (file.isBuffer()) {
44+
if (file.contents.length === 0) {
45+
let msg = `File ${path.dirname(file.path)} is empty`;
46+
this.emit('error', new PluginError(PLUGIN_NAME, msg));
47+
return cb();
48+
}
49+
try {
50+
file.contents = yaml2json(file.contents, options);
51+
file.path = gutil.replaceExtension(file.path, '.json');
52+
} catch (error) {
53+
let msg = `${error.message} => ${file.path}`;
54+
this.emit('error', new PluginError(PLUGIN_NAME, msg));
55+
return cb();
56+
}
57+
} else if (file.isStream()) {
58+
file.contents = file.contents.pipe(
59+
new BufferStreams((err, buf, cb) => {
60+
if (err) {
61+
self.emit('error', new PluginError(PLUGIN_NAME, err.message));
62+
} else {
63+
if (buf.length === 0) {
64+
let msg = `File ${path.dirname(file.path)} is empty`;
65+
let error = new PluginError(PLUGIN_NAME, msg);
66+
self.emit('error', error);
67+
cb(error);
68+
} else {
69+
try {
70+
file.path = gutil.replaceExtension(file.path, '.json');
71+
cb(null, yaml2json(buf, options));
72+
} catch (error) {
73+
let msg = `${error.message} => ${file.path}`;
74+
self.emit('error', new PluginError(PLUGIN_NAME, msg));
75+
cb(error);
76+
}
77+
}
78+
}
79+
})
80+
);
81+
}
82+
this.push(file);
83+
cb();
84+
});
85+
}

0 commit comments

Comments
 (0)