Skip to content

Commit 81a970b

Browse files
committed
chore: inlining json files as well for require
1 parent 4824d0c commit 81a970b

File tree

3 files changed

+27
-11
lines changed

3 files changed

+27
-11
lines changed

gulpfile.js/index.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,7 @@ function containsRegExpExcludingEmpty(str) {
543543

544544

545545
const textContentMap = {};
546+
const excludeSuffixPathsInlining = ["MessageIds.json"];
546547
function inlineTextRequire(file, content, srcDir) {
547548
if(content.includes(`'text!`) || content.includes("`text!")) {
548549
throw new Error(`in file ${file} require("text!...") should always use a double quote "text! instead of " or \``);
@@ -551,18 +552,18 @@ function inlineTextRequire(file, content, srcDir) {
551552
const requireFragments = extractRequireTextFragments(content);
552553
for (const {requirePath, requireStatement} of requireFragments) {
553554
let textContent = textContentMap[requirePath];
555+
let filePath = srcDir + requirePath;
556+
if(requirePath.startsWith("./")) {
557+
filePath = path.join(path.dirname(file), requirePath);
558+
}
554559
if(!textContent){
555-
let filePath = srcDir + requirePath;
556-
if(requirePath.startsWith("./")) {
557-
filePath = path.join(path.dirname(file), requirePath);
558-
}
559560
console.log("reading file at path: ", filePath);
560561
const fileContent = fs.readFileSync(filePath, "utf8");
561562
textContentMap[requirePath] = fileContent;
562563
textContent = fileContent;
563564
}
564-
if(requirePath.endsWith(".js") || requirePath.endsWith(".json")) {
565-
console.log("Not inlining JS/JSON file:", requirePath);
565+
if(requirePath.endsWith(".js") || excludeSuffixPathsInlining.some(ext => requirePath.endsWith(ext))) {
566+
console.warn("Not inlining JS/JSON file:", requirePath, filePath);
566567
} else {
567568
console.log("Inlining", requireStatement);
568569
if((requireStatement.includes(".html") || requireStatement.includes(".js"))

src/LiveDevelopment/BrowserScripts/LivePreviewTransportRemote.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,9 +313,10 @@
313313
}
314314
};
315315

316+
const ABS_REGEX = new RegExp("^(?:[a-z]+:)?\\/\\/", "i");
316317
function getAbsoluteUrl(url) {
317318
// Check if the URL is already absolute
318-
if (/^(?:[a-z]+:)?\/\//i.test(url)) {
319+
if (ABS_REGEX.test(url)) {
319320
return url; // The URL is already absolute
320321
}
321322

src/LiveDevelopment/BrowserScripts/RemoteFunctions.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3273,8 +3273,16 @@ function RemoteFunctions(config = {}) {
32733273
const searchTerm = this._currentSearchQuery || 'image';
32743274

32753275
// clean the search term and the photograper name to write in file name
3276-
const cleanSearchTerm = searchTerm.toLowerCase().replace(/[^a-z0-9]/g, '-').replace(/-+/g, '-').replace(/^-|-$/g, '');
3277-
const cleanPhotographerName = photographerName.toLowerCase().replace(/[^a-z0-9]/g, '-').replace(/-+/g, '-').replace(/^-|-$/g, '');
3276+
const cleanSearchTerm = searchTerm
3277+
.toLowerCase()
3278+
.replace(new RegExp("[^a-z0-9]", "g"), "-")
3279+
.replace(new RegExp("-+", "g"), "-")
3280+
.replace(new RegExp("^-|-$", "g"), "");
3281+
const cleanPhotographerName = photographerName
3282+
.toLowerCase()
3283+
.replace(new RegExp("[^a-z0-9]", "g"), "-")
3284+
.replace(new RegExp("-+", "g"), "-")
3285+
.replace(new RegExp("^-|-$", "g"), "");
32783286

32793287
return `${cleanSearchTerm}-by-${cleanPhotographerName}`;
32803288
},
@@ -3329,7 +3337,11 @@ function RemoteFunctions(config = {}) {
33293337
const extension = originalName.substring(originalName.lastIndexOf('.')) || '.jpg';
33303338

33313339
// we clean the file name because the file might have some chars which might not be compatible
3332-
const cleanName = nameWithoutExt.toLowerCase().replace(/[^a-z0-9]/g, '-').replace(/-+/g, '-').replace(/^-|-$/g, '');
3340+
const cleanName = nameWithoutExt
3341+
.toLowerCase()
3342+
.replace(new RegExp("[^a-z0-9]", "g"), "-")
3343+
.replace(new RegExp("-+", "g"), "-")
3344+
.replace(new RegExp("^-|-$", "g"), "");
33333345
const filename = cleanName || 'selected-image';
33343346

33353347
// Use the unified _useImage method with isLocalFile flag
@@ -4767,7 +4779,9 @@ function RemoteFunctions(config = {}) {
47674779
return;
47684780
}
47694781

4770-
targetID = edit.type.match(/textReplace|textDelete|textInsert|elementInsert|elementMove/) ? edit.parentID : edit.tagID;
4782+
targetID = new RegExp("textReplace|textDelete|textInsert|elementInsert|elementMove").test(edit.type)
4783+
? edit.parentID : edit.tagID;
4784+
47714785
targetElement = self._queryBracketsID(targetID);
47724786

47734787
if (!targetElement && !editIsSpecialTag) {

0 commit comments

Comments
 (0)