From c1c66eda38e26324a5db04b749dda3cdb71d3502 Mon Sep 17 00:00:00 2001
From: ezsh <ezsh.junk@gmail.com>
Date: Fri, 5 Nov 2021 17:34:24 +0100
Subject: [PATCH] [gulp] Force case-sensitive compare for paths

The build relies on case-sensitive sort when concatenating sources, but
gulp-sort uses localized compare by default, which can be
case-insensitive.
---
 gulpfile.js | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/gulpfile.js b/gulpfile.js
index 41a987d0109..c3576981d91 100644
--- a/gulpfile.js
+++ b/gulpfile.js
@@ -99,12 +99,20 @@ function tweeCompileCommand() {
 	return `${tweeCompilerExecutable()} -f ${cfg.twineformat} --head=${cfg.sources.head} -o ${path.join(cfg.dirs.intermediate, htmlOut)} ${moduleArgs.join(' ')} ${sources.join(' ')}`;
 }
 
+/**
+ * gulp-sort uses String.localeCompare() by default, which may be case-insensitive,
+ * while we require case -sensitive sorting for sources
+ */
+function pathcmp(a, b) {
+	return (a.path < b.path ? -1 : (a.path > b.path ? 1 : 0));
+}
+
 /**
  * Creates a pipeline that sorts and combines files
  */
 function concatFiles(srcGlob, destDir, destFileName) {
 	return gulp.src(srcGlob)
-		.pipe(sort())
+		.pipe(sort(pathcmp))
 		.pipe(concat(destFileName))
 		.pipe(gulp.dest(destDir));
 }
@@ -120,7 +128,7 @@ function processScripts(srcGlob, destDir, destFileName) {
 	const addSourcemaps = !args.release;
 	const prefix = path.relative(destDir, srcGlob.substr(0, srcGlob.indexOf('*')));
 	return gulp.src(srcGlob)
-		.pipe(sort())
+		.pipe(sort(pathcmp))
 		.pipe(addSourcemaps ? sourcemaps.init() : noop())
 		.pipe(concat(destFileName))
 		.pipe(addSourcemaps ?
@@ -144,7 +152,7 @@ function processStylesheets(srcGlob, destDir, destFileName) {
 	const addSourcemaps = !args.release;
 	const prefix = path.relative(destDir, srcGlob.substr(0, srcGlob.indexOf('*')));
 	return gulp.src(srcGlob)
-		.pipe(sort())
+		.pipe(sort(pathcmp))
 		.pipe(addSourcemaps ? sourcemaps.init() : noop())
 		.pipe(concat(destFileName))
 		.pipe(cfg.options.css.autoprefix ?
@@ -332,7 +340,7 @@ gulp.task('twineCSS', function() {
 gulp.task('twineJS', function() {
 	return gulp.src([...cfg.sources.module.js, ...cfg.sources.story.js, '!src/art/assistantArt.js'])
 		.pipe(stripCssJSComments({trim: true}))
-		.pipe(sort())
+		.pipe(sort(pathcmp))
 		.pipe(concat('twine JS.txt'))
 		.pipe(gulp.dest('devNotes'));
 });
-- 
GitLab