Skip to content

Commit

Permalink
Update the sort logic in the assets grouping (#15815)
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeAlhayek authored May 9, 2024
1 parent 548eaa1 commit 1ba8423
Show file tree
Hide file tree
Showing 5 changed files with 3,288 additions and 3,405 deletions.
35 changes: 23 additions & 12 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ var fs = require("graceful-fs"),
merge = require("merge-stream"),
gulp = require("gulp"),
gulpif = require("gulp-if"),
print = require("gulp-print"),
debug = require("gulp-debug"),
newer = require("gulp-newer"),
plumber = require("gulp-plumber"),
sourcemaps = require("gulp-sourcemaps"),
Expand Down Expand Up @@ -53,7 +51,6 @@ gulp.task("rebuild-assets", function () {

// Continuous watch (each asset group is built whenever one of its inputs changes).
gulp.task("watch", function () {
var pathWin32 = require("path");
getAssetGroups().forEach(function (assetGroup) {
var watchPaths = assetGroup.inputPaths.concat(assetGroup.watchPaths);
var inputWatcher;
Expand All @@ -66,7 +63,7 @@ gulp.task("watch", function () {
else
console.log("Asset file '" + watchedPath + "' was changed, rebuilding asset group.");
var doRebuild = true;
var task = createAssetGroupTask(assetGroup, doRebuild);
createAssetGroupTask(assetGroup, doRebuild);
});
}

Expand Down Expand Up @@ -114,14 +111,29 @@ function getAssetGroups() {
function resolveAssetGroupPaths(assetGroup, assetManifestPath) {
assetGroup.manifestPath = assetManifestPath.replace(/\\/g, '/');
assetGroup.basePath = path.dirname(assetGroup.manifestPath);
var inputPaths = assetGroup.inputs.map(function (inputPath) {
return path.resolve(path.join(assetGroup.basePath, inputPath)).replace(/\\/g, '/');
});

// For wildcard input paths also sortthem to ensure file concatenation is consistent.
if (inputPaths.some(path => path.includes('*'))) {
inputPaths = glob.sync(inputPaths, {}).sort();
}
var inputPaths = [];

// The inputPaths can contain either a physical path to a file or a path with a wildcard.
// It's crucial to maintain the order of each file based on its position in the assets.json file.
// When a path contains a wildcard, we need to convert the wildcard to physical paths
// and sort them independently of the previous paths to ensure consistent concatenation.
assetGroup.inputs.forEach(inputPath => {

var resolvedPath = path.resolve(path.join(assetGroup.basePath, inputPath)).replace(/\\/g, '/');

if (resolvedPath.includes('*')) {
var sortedPaths = glob.sync(resolvedPath, {});

sortedPaths.sort();

sortedPaths.forEach(sortedPath => {
inputPaths.push(sortedPath.replace(/\\/g, '/'));
});
} else {
inputPaths.push(resolvedPath);
}
});

assetGroup.inputPaths = inputPaths;

Expand Down Expand Up @@ -263,7 +275,6 @@ function buildJsPipeline(assetGroup, doConcat, doRebuild) {
target: "es5",
};

console.log(assetGroup.inputPaths);
return gulp.src(assetGroup.inputPaths)
.pipe(gulpif(!doRebuild,
gulpif(doConcat,
Expand Down
126 changes: 0 additions & 126 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
"gulp-cli": "^2.3.0",
"gulp-concat": "2.6.1",
"gulp-dart-sass": "1.1.0",
"gulp-debug": "4.0.0",
"gulp-eol": "0.2.0",
"gulp-header": "2.0.9",
"gulp-if": "3.0.0",
Expand All @@ -34,7 +33,6 @@
"gulp-newer": "1.4.0",
"gulp-plumber": "1.2.1",
"gulp-postcss": "^9.0.1",
"gulp-print": "5.0.2",
"gulp-rename": "2.0.0",
"gulp-sourcemaps": "^3.0.0",
"gulp-terser": "2.1.0",
Expand All @@ -46,7 +44,7 @@
"postcss": "8.4.28",
"postcss-rtl": "^2.0.0",
"rtlcss": "4.1.0",
"typescript": "^5.2.2",
"source-map": "^0.7.4"
"source-map": "^0.7.4",
"typescript": "^5.2.2"
}
}
Loading

0 comments on commit 1ba8423

Please sign in to comment.