Skip to content

Commit 0670714

Browse files
committed
Ensure the correct directory path is used when writing out files after the esbuild step
I would sometimes see the compiled scripts getting written to the root.
1 parent a9b0d8c commit 0670714

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

gulpfile.mjs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,19 @@ function logError(message) {
6666
}
6767
}
6868

69+
/**
70+
* Strip .src .js from a JavaScript file's basename
71+
*
72+
* @param {string} val The JS basename to be cleaned
73+
*
74+
* @return {string} The modified basename
75+
*/
76+
function cleanJSBasename(val) {
77+
var val = val.replace('.src', '');
78+
val = val.replace('.js', '');
79+
return val;
80+
}
81+
6982
/**
7083
* Delete previously compiled files
7184
*/
@@ -153,6 +166,7 @@ gulp.task(
153166
*/
154167
gulp.task('scripts', function () {
155168
let hadError = false;
169+
let pathMapping = {};
156170
return gulp
157171
.src(config.scriptSRC)
158172
.pipe(
@@ -164,6 +178,13 @@ gulp.task('scripts', function () {
164178
},
165179
})
166180
)
181+
.pipe(
182+
rename(function (path) {
183+
let key = cleanJSBasename(path.basename);
184+
pathMapping[key] = path.dirname;
185+
return path;
186+
})
187+
)
167188
.pipe(
168189
esbuild({
169190
bundle: true,
@@ -175,7 +196,12 @@ gulp.task('scripts', function () {
175196
)
176197
.pipe(lineec()) // Consistent Line Endings for non UNIX systems
177198
.pipe(
199+
// Maybe fix paths that the esbuild step clobbers?
178200
rename(function (path) {
201+
let key = cleanJSBasename(path.basename);
202+
if (pathMapping[key]) {
203+
path.dirname = pathMapping[key];
204+
}
179205
if (path.extname === '.js') {
180206
path.basename = path.basename.replace('.src', '');
181207
}

0 commit comments

Comments
 (0)