Skip to content

Commit c5cdf03

Browse files
committed
fix(build): preserve CSS BOMs across copy steps
1 parent 8e68a18 commit c5cdf03

2 files changed

Lines changed: 29 additions & 16 deletions

File tree

‎gulpfile.js/index.js‎

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ const rename = require("gulp-rename");
3939
const execSync = require('child_process').execSync;
4040
const terser = require('terser');
4141

42+
const copyOptions = copyThirdPartyLibs.copyOptions;
43+
4244
function cleanDist() {
4345
return del(['dist', 'dist-test']);
4446
}
@@ -136,7 +138,7 @@ function _deletePhoenixProSourceFolder() {
136138
* @returns {*}
137139
*/
138140
function makeDistAll() {
139-
return src(['src/**/*', 'src/.*/*.*'])
141+
return src(['src/**/*', 'src/.*/*.*'], copyOptions)
140142
.pipe(dest('dist'));
141143
}
142144

@@ -170,7 +172,7 @@ function makeJSDist() {
170172

171173
// we had to do this as prettier is non minifiable
172174
function makeJSPrettierDist() {
173-
return src(["src/thirdparty/prettier/**/*"])
175+
return src(["src/thirdparty/prettier/**/*"], copyOptions)
174176
.pipe(dest('dist/thirdparty/prettier'));
175177
}
176178

@@ -182,12 +184,12 @@ function makeNonMinifyDist() {
182184
"src/LiveDevelopment/BrowserScripts/RemoteFunctions.js",
183185
"src/extensionsIntegrated/phoenix-pro/onboarding/**/*",
184186
"src/extensionsIntegrated/phoenix-pro/unit-tests/**/*",
185-
"src/mdViewer/**/*"], {base: 'src'})
187+
"src/mdViewer/**/*"], {...copyOptions, base: 'src'})
186188
.pipe(dest('dist'));
187189
}
188190

189191
function makeDistNonJS() {
190-
return src(['src/**/*', 'src/.*/*.*', '!src/**/*.js'])
192+
return src(['src/**/*', 'src/.*/*.*', '!src/**/*.js'], copyOptions)
191193
.pipe(dest('dist'));
192194
}
193195

@@ -230,40 +232,40 @@ function zipTestFiles() {
230232
'test/**',
231233
'test/**/.*',
232234
'!test/thirdparty/**',
233-
'!test/test_folders.zip'])
235+
'!test/test_folders.zip'], copyOptions)
234236
.pipe(zip('test_folders.zip'))
235237
.pipe(dest('test/'));
236238
}
237239

238240
function zipDefaultProjectFiles() {
239-
return src(['src/assets/default-project/en/**'])
241+
return src(['src/assets/default-project/en/**'], copyOptions)
240242
.pipe(zip('en.zip'))
241243
.pipe(dest('src/assets/default-project/'));
242244
}
243245

244246
// sample projects
245247
function zipSampleProjectBootstrapBlog() {
246-
return src(['src/assets/sample-projects/bootstrap-blog/**'])
248+
return src(['src/assets/sample-projects/bootstrap-blog/**'], copyOptions)
247249
.pipe(zip('bootstrap-blog.zip'))
248250
.pipe(dest('src/assets/sample-projects/'));
249251
}
250252
function zipSampleProjectExplore() {
251-
return src(['src/assets/sample-projects/explore/**'])
253+
return src(['src/assets/sample-projects/explore/**'], copyOptions)
252254
.pipe(zip('explore.zip'))
253255
.pipe(dest('src/assets/sample-projects/'));
254256
}
255257
function zipSampleProjectHTML5() {
256-
return src(['src/assets/sample-projects/HTML5/**'])
258+
return src(['src/assets/sample-projects/HTML5/**'], copyOptions)
257259
.pipe(zip('HTML5.zip'))
258260
.pipe(dest('src/assets/sample-projects/'));
259261
}
260262
function zipSampleProjectDashboard() {
261-
return src(['src/assets/sample-projects/dashboard/**'])
263+
return src(['src/assets/sample-projects/dashboard/**'], copyOptions)
262264
.pipe(zip('dashboard.zip'))
263265
.pipe(dest('src/assets/sample-projects/'));
264266
}
265267
function zipSampleProjectHomePages() {
266-
return src(['src/assets/sample-projects/home-pages/**'])
268+
return src(['src/assets/sample-projects/home-pages/**'], copyOptions)
267269
.pipe(zip('home-pages.zip'))
268270
.pipe(dest('src/assets/sample-projects/'));
269271
}
@@ -991,12 +993,12 @@ function createDistCacheManifestDev() {
991993
}
992994

993995
function copyDistToDistTestFolder() {
994-
return src('dist/**/*')
996+
return src('dist/**/*', copyOptions)
995997
.pipe(dest('dist-test/src'));
996998
}
997999

9981000
function copyTestToDistTestFolder() {
999-
return src('test/**/*')
1001+
return src('test/**/*', copyOptions)
10001002
.pipe(dest('dist-test/test'));
10011003
}
10021004

@@ -1094,7 +1096,7 @@ function _patchMinifiedCSSInDistIndex() {
10941096
return new Promise((resolve)=>{
10951097
let content = fs.readFileSync("dist/index.html", "utf8");
10961098
if(!content.includes(`<link rel="stylesheet/less" type="text/css" href="styles/brackets.less">`)){
1097-
throw new Error(`Could not locate string <link rel="stylesheet/less" type="text/css" href="styles/brackets.less"> in file dist/index.html`)
1099+
throw new Error(`Could not locate string <link rel="stylesheet/less" type="text/css" href="styles/brackets.less"> in file dist/index.html`);
10981100
}
10991101
content = content.replace(
11001102
`<link rel="stylesheet/less" type="text/css" href="styles/brackets.less">`,

‎gulpfile.js/thirdparty-lib-copy.js‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,16 @@ const path = require('path');
2727
// removed require('merge-stream') node module. it gives wired glob behavior and some files goes missing
2828
const rename = require("gulp-rename");
2929

30+
const copyOptions = {
31+
/**
32+
* Preserve CSS encoding markers; keep Gulp's BOM stripping for other file types.
33+
* @param {Object} file Vinyl file being read.
34+
* @returns {boolean} Whether to remove the file's BOM.
35+
*/
36+
removeBOM(file) {
37+
return file.extname.toLowerCase() !== ".css";
38+
}
39+
};
3040

3141
// individual third party copy
3242
function copyLicence(filePath, name) {
@@ -38,7 +48,7 @@ function copyLicence(filePath, name) {
3848

3949
function renameFile(filePath, newName, destPath) {
4050
console.log(`Renaming file ${filePath} to ${newName}`);
41-
return src(filePath)
51+
return src(filePath, copyOptions)
4252
.pipe(rename(newName))
4353
.pipe(dest(destPath));
4454
}
@@ -65,7 +75,7 @@ function downloadFile(url, outputPath) {
6575

6676
function copyFiles(srcPathList, dstPath) {
6777
console.log(`Copying files ${dstPath}`);
68-
return src(srcPathList)
78+
return src(srcPathList, copyOptions)
6979
.pipe(dest(dstPath));
7080
}
7181

@@ -304,5 +314,6 @@ function _patchTernLib() {
304314
});
305315
}
306316

317+
exports.copyOptions = copyOptions;
307318
exports.copyAll = series(copyThirdPartyLibs, _patchAcornLib, _patchTernLib);
308319
exports.copyAllDebug = series(copyThirdPartyLibs, copyThirdPartyDebugLibs, _patchAcornLib, _patchTernLib);

0 commit comments

Comments
 (0)