From 70248a133046205ca86590c103d2be2b9c3d5dcc Mon Sep 17 00:00:00 2001 From: harryadel Date: Fri, 16 Dec 2022 14:39:39 +0200 Subject: [PATCH 01/28] [test-in-browser] Update Blaze package --- packages/test-in-browser/package.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/test-in-browser/package.js b/packages/test-in-browser/package.js index 57e3474024..3840a847c1 100644 --- a/packages/test-in-browser/package.js +++ b/packages/test-in-browser/package.js @@ -19,7 +19,7 @@ Package.onUse(function (api) { api.use([ 'webapp', - 'blaze@2.3.4', + 'blaze@2.6.1', 'templating@1.3.2', 'spacebars@1.0.15', 'jquery@3.0.0', From fb35643ca60a73c7f3188a5a0c97e12ab926c118 Mon Sep 17 00:00:00 2001 From: harryadel Date: Fri, 16 Dec 2022 15:26:10 +0200 Subject: [PATCH 02/28] [test-in-browser] Update diff match patch library --- .../diff_match_patch_uncompressed.js | 215 ++++++++++-------- 1 file changed, 120 insertions(+), 95 deletions(-) diff --git a/packages/test-in-browser/diff_match_patch_uncompressed.js b/packages/test-in-browser/diff_match_patch_uncompressed.js index 112130e097..4d5542c1d3 100644 --- a/packages/test-in-browser/diff_match_patch_uncompressed.js +++ b/packages/test-in-browser/diff_match_patch_uncompressed.js @@ -1,8 +1,7 @@ /** * Diff Match and Patch - * - * Copyright 2006 Google Inc. - * http://code.google.com/p/google-diff-match-patch/ + * Copyright 2018 The diff-match-patch Authors. + * https://github.com/google/diff-match-patch * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,7 +26,7 @@ * Class containing the diff, match and patch methods. * @constructor */ -function diff_match_patch() { +var diff_match_patch = function() { // Defaults. // Redefine these in your program to override the defaults. @@ -52,7 +51,7 @@ function diff_match_patch() { // The number of bits in an int. this.Match_MaxBits = 32; -} +}; // DIFF FUNCTIONS @@ -67,9 +66,18 @@ var DIFF_DELETE = -1; var DIFF_INSERT = 1; var DIFF_EQUAL = 0; -/** @typedef {{0: number, 1: string}} */ -diff_match_patch.Diff; - +/** + * Class representing one diff tuple. + * ~Attempts to look like a two-element array (which is what this used to be).~ + * Constructor returns an actual two-element array, to allow destructing @JackuB + * See https://github.com/JackuB/diff-match-patch/issues/14 for details + * @param {number} op Operation, one of: DIFF_DELETE, DIFF_INSERT, DIFF_EQUAL. + * @param {string} text Text to be deleted, inserted, or retained. + * @constructor + */ +diff_match_patch.Diff = function(op, text) { + return [op, text]; +}; /** * Find the differences between two texts. Simplifies the problem by stripping @@ -79,7 +87,7 @@ diff_match_patch.Diff; * @param {boolean=} opt_checklines Optional speedup flag. If present and false, * then don't run a line-level diff first to identify the changed areas. * Defaults to true, which does a faster, slightly less optimal diff. - * @param {number} opt_deadline Optional time when the diff should be complete + * @param {number=} opt_deadline Optional time when the diff should be complete * by. Used internally for recursive calls. Users should set DiffTimeout * instead. * @return {!Array.} Array of diff tuples. @@ -104,7 +112,7 @@ diff_match_patch.prototype.diff_main = function(text1, text2, opt_checklines, // Check for equality (speedup). if (text1 == text2) { if (text1) { - return [[DIFF_EQUAL, text1]]; + return [new diff_match_patch.Diff(DIFF_EQUAL, text1)]; } return []; } @@ -131,10 +139,10 @@ diff_match_patch.prototype.diff_main = function(text1, text2, opt_checklines, // Restore the prefix and suffix. if (commonprefix) { - diffs.unshift([DIFF_EQUAL, commonprefix]); + diffs.unshift(new diff_match_patch.Diff(DIFF_EQUAL, commonprefix)); } if (commonsuffix) { - diffs.push([DIFF_EQUAL, commonsuffix]); + diffs.push(new diff_match_patch.Diff(DIFF_EQUAL, commonsuffix)); } this.diff_cleanupMerge(diffs); return diffs; @@ -159,12 +167,12 @@ diff_match_patch.prototype.diff_compute_ = function(text1, text2, checklines, if (!text1) { // Just add some text (speedup). - return [[DIFF_INSERT, text2]]; + return [new diff_match_patch.Diff(DIFF_INSERT, text2)]; } if (!text2) { // Just delete some text (speedup). - return [[DIFF_DELETE, text1]]; + return [new diff_match_patch.Diff(DIFF_DELETE, text1)]; } var longtext = text1.length > text2.length ? text1 : text2; @@ -172,9 +180,10 @@ diff_match_patch.prototype.diff_compute_ = function(text1, text2, checklines, var i = longtext.indexOf(shorttext); if (i != -1) { // Shorter text is inside the longer text (speedup). - diffs = [[DIFF_INSERT, longtext.substring(0, i)], - [DIFF_EQUAL, shorttext], - [DIFF_INSERT, longtext.substring(i + shorttext.length)]]; + diffs = [new diff_match_patch.Diff(DIFF_INSERT, longtext.substring(0, i)), + new diff_match_patch.Diff(DIFF_EQUAL, shorttext), + new diff_match_patch.Diff(DIFF_INSERT, + longtext.substring(i + shorttext.length))]; // Swap insertions for deletions if diff is reversed. if (text1.length > text2.length) { diffs[0][0] = diffs[2][0] = DIFF_DELETE; @@ -185,7 +194,8 @@ diff_match_patch.prototype.diff_compute_ = function(text1, text2, checklines, if (shorttext.length == 1) { // Single character string. // After the previous speedup, the character can't be an equality. - return [[DIFF_DELETE, text1], [DIFF_INSERT, text2]]; + return [new diff_match_patch.Diff(DIFF_DELETE, text1), + new diff_match_patch.Diff(DIFF_INSERT, text2)]; } // Check to see if the problem can be split in two. @@ -201,7 +211,8 @@ diff_match_patch.prototype.diff_compute_ = function(text1, text2, checklines, var diffs_a = this.diff_main(text1_a, text2_a, checklines, deadline); var diffs_b = this.diff_main(text1_b, text2_b, checklines, deadline); // Merge the results. - return diffs_a.concat([[DIFF_EQUAL, mid_common]], diffs_b); + return diffs_a.concat([new diff_match_patch.Diff(DIFF_EQUAL, mid_common)], + diffs_b); } if (checklines && text1.length > 100 && text2.length > 100) { @@ -238,7 +249,7 @@ diff_match_patch.prototype.diff_lineMode_ = function(text1, text2, deadline) { // Rediff any replacement blocks, this time character-by-character. // Add a dummy entry at the end. - diffs.push([DIFF_EQUAL, '']); + diffs.push(new diff_match_patch.Diff(DIFF_EQUAL, '')); var pointer = 0; var count_delete = 0; var count_insert = 0; @@ -261,11 +272,12 @@ diff_match_patch.prototype.diff_lineMode_ = function(text1, text2, deadline) { diffs.splice(pointer - count_delete - count_insert, count_delete + count_insert); pointer = pointer - count_delete - count_insert; - var a = this.diff_main(text_delete, text_insert, false, deadline); - for (var j = a.length - 1; j >= 0; j--) { - diffs.splice(pointer, 0, a[j]); + var subDiff = + this.diff_main(text_delete, text_insert, false, deadline); + for (var j = subDiff.length - 1; j >= 0; j--) { + diffs.splice(pointer, 0, subDiff[j]); } - pointer = pointer + a.length; + pointer = pointer + subDiff.length; } count_insert = 0; count_delete = 0; @@ -399,7 +411,8 @@ diff_match_patch.prototype.diff_bisect_ = function(text1, text2, deadline) { } // Diff took too long and hit the deadline or // number of diffs equals number of characters, no commonality at all. - return [[DIFF_DELETE, text1], [DIFF_INSERT, text2]]; + return [new diff_match_patch.Diff(DIFF_DELETE, text1), + new diff_match_patch.Diff(DIFF_INSERT, text2)]; }; @@ -471,21 +484,29 @@ diff_match_patch.prototype.diff_linesToChars_ = function(text1, text2) { lineEnd = text.length - 1; } var line = text.substring(lineStart, lineEnd + 1); - lineStart = lineEnd + 1; if (lineHash.hasOwnProperty ? lineHash.hasOwnProperty(line) : (lineHash[line] !== undefined)) { chars += String.fromCharCode(lineHash[line]); } else { + if (lineArrayLength == maxLines) { + // Bail out at 65535 because + // String.fromCharCode(65536) == String.fromCharCode(0) + line = text.substring(lineStart); + lineEnd = text.length; + } chars += String.fromCharCode(lineArrayLength); lineHash[line] = lineArrayLength; lineArray[lineArrayLength++] = line; } + lineStart = lineEnd + 1; } return chars; } - + // Allocate 2/3rds of the space for text1, the rest for text2. + var maxLines = 40000; var chars1 = diff_linesToCharsMunge_(text1); + maxLines = 65535; var chars2 = diff_linesToCharsMunge_(text2); return {chars1: chars1, chars2: chars2, lineArray: lineArray}; }; @@ -499,13 +520,13 @@ diff_match_patch.prototype.diff_linesToChars_ = function(text1, text2) { * @private */ diff_match_patch.prototype.diff_charsToLines_ = function(diffs, lineArray) { - for (var x = 0; x < diffs.length; x++) { - var chars = diffs[x][1]; + for (var i = 0; i < diffs.length; i++) { + var chars = diffs[i][1]; var text = []; - for (var y = 0; y < chars.length; y++) { - text[y] = lineArray[chars.charCodeAt(y)]; + for (var j = 0; j < chars.length; j++) { + text[j] = lineArray[chars.charCodeAt(j)]; } - diffs[x][1] = text.join(''); + diffs[i][1] = text.join(''); } }; @@ -523,7 +544,7 @@ diff_match_patch.prototype.diff_commonPrefix = function(text1, text2) { return 0; } // Binary search. - // Performance analysis: http://neil.fraser.name/news/2007/10/09/ + // Performance analysis: https://neil.fraser.name/news/2007/10/09/ var pointermin = 0; var pointermax = Math.min(text1.length, text2.length); var pointermid = pointermax; @@ -555,7 +576,7 @@ diff_match_patch.prototype.diff_commonSuffix = function(text1, text2) { return 0; } // Binary search. - // Performance analysis: http://neil.fraser.name/news/2007/10/09/ + // Performance analysis: https://neil.fraser.name/news/2007/10/09/ var pointermin = 0; var pointermax = Math.min(text1.length, text2.length); var pointermid = pointermax; @@ -604,7 +625,7 @@ diff_match_patch.prototype.diff_commonOverlap_ = function(text1, text2) { // Start by looking for a single character match // and increase length until no match is found. - // Performance analysis: http://neil.fraser.name/news/2010/11/04/ + // Performance analysis: https://neil.fraser.name/news/2010/11/04/ var best = 0; var length = 1; while (true) { @@ -731,7 +752,7 @@ diff_match_patch.prototype.diff_cleanupSemantic = function(diffs) { var equalities = []; // Stack of indices where equalities are found. var equalitiesLength = 0; // Keeping our own length var is faster in JS. /** @type {?string} */ - var lastequality = null; + var lastEquality = null; // Always equal to diffs[equalities[equalitiesLength - 1]][1] var pointer = 0; // Index of current position. // Number of characters that changed prior to the equality. @@ -747,7 +768,7 @@ diff_match_patch.prototype.diff_cleanupSemantic = function(diffs) { length_deletions1 = length_deletions2; length_insertions2 = 0; length_deletions2 = 0; - lastequality = diffs[pointer][1]; + lastEquality = diffs[pointer][1]; } else { // An insertion or deletion. if (diffs[pointer][0] == DIFF_INSERT) { length_insertions2 += diffs[pointer][1].length; @@ -756,13 +777,13 @@ diff_match_patch.prototype.diff_cleanupSemantic = function(diffs) { } // Eliminate an equality that is smaller or equal to the edits on both // sides of it. - if (lastequality && (lastequality.length <= + if (lastEquality && (lastEquality.length <= Math.max(length_insertions1, length_deletions1)) && - (lastequality.length <= Math.max(length_insertions2, + (lastEquality.length <= Math.max(length_insertions2, length_deletions2))) { // Duplicate record. diffs.splice(equalities[equalitiesLength - 1], 0, - [DIFF_DELETE, lastequality]); + new diff_match_patch.Diff(DIFF_DELETE, lastEquality)); // Change second copy to insert. diffs[equalities[equalitiesLength - 1] + 1][0] = DIFF_INSERT; // Throw away the equality we just deleted. @@ -774,7 +795,7 @@ diff_match_patch.prototype.diff_cleanupSemantic = function(diffs) { length_deletions1 = 0; length_insertions2 = 0; length_deletions2 = 0; - lastequality = null; + lastEquality = null; changes = true; } } @@ -805,8 +826,8 @@ diff_match_patch.prototype.diff_cleanupSemantic = function(diffs) { if (overlap_length1 >= deletion.length / 2 || overlap_length1 >= insertion.length / 2) { // Overlap found. Insert an equality and trim the surrounding edits. - diffs.splice(pointer, 0, - [DIFF_EQUAL, insertion.substring(0, overlap_length1)]); + diffs.splice(pointer, 0, new diff_match_patch.Diff(DIFF_EQUAL, + insertion.substring(0, overlap_length1))); diffs[pointer - 1][1] = deletion.substring(0, deletion.length - overlap_length1); diffs[pointer + 1][1] = insertion.substring(overlap_length1); @@ -817,8 +838,8 @@ diff_match_patch.prototype.diff_cleanupSemantic = function(diffs) { overlap_length2 >= insertion.length / 2) { // Reverse overlap found. // Insert an equality and swap and trim the surrounding edits. - diffs.splice(pointer, 0, - [DIFF_EQUAL, deletion.substring(0, overlap_length2)]); + diffs.splice(pointer, 0, new diff_match_patch.Diff(DIFF_EQUAL, + deletion.substring(0, overlap_length2))); diffs[pointer - 1][0] = DIFF_INSERT; diffs[pointer - 1][1] = insertion.substring(0, insertion.length - overlap_length2); @@ -976,7 +997,7 @@ diff_match_patch.prototype.diff_cleanupEfficiency = function(diffs) { var equalities = []; // Stack of indices where equalities are found. var equalitiesLength = 0; // Keeping our own length var is faster in JS. /** @type {?string} */ - var lastequality = null; + var lastEquality = null; // Always equal to diffs[equalities[equalitiesLength - 1]][1] var pointer = 0; // Index of current position. // Is there an insertion operation before the last equality. @@ -995,11 +1016,11 @@ diff_match_patch.prototype.diff_cleanupEfficiency = function(diffs) { equalities[equalitiesLength++] = pointer; pre_ins = post_ins; pre_del = post_del; - lastequality = diffs[pointer][1]; + lastEquality = diffs[pointer][1]; } else { // Not a candidate, and can never become one. equalitiesLength = 0; - lastequality = null; + lastEquality = null; } post_ins = post_del = false; } else { // An insertion or deletion. @@ -1016,16 +1037,16 @@ diff_match_patch.prototype.diff_cleanupEfficiency = function(diffs) { * AXCD * ABXC */ - if (lastequality && ((pre_ins && pre_del && post_ins && post_del) || - ((lastequality.length < this.Diff_EditCost / 2) && + if (lastEquality && ((pre_ins && pre_del && post_ins && post_del) || + ((lastEquality.length < this.Diff_EditCost / 2) && (pre_ins + pre_del + post_ins + post_del) == 3))) { // Duplicate record. diffs.splice(equalities[equalitiesLength - 1], 0, - [DIFF_DELETE, lastequality]); + new diff_match_patch.Diff(DIFF_DELETE, lastEquality)); // Change second copy to insert. diffs[equalities[equalitiesLength - 1] + 1][0] = DIFF_INSERT; equalitiesLength--; // Throw away the equality we just deleted; - lastequality = null; + lastEquality = null; if (pre_ins && pre_del) { // No changes made which could affect previous entry, keep going. post_ins = post_del = true; @@ -1054,7 +1075,8 @@ diff_match_patch.prototype.diff_cleanupEfficiency = function(diffs) { * @param {!Array.} diffs Array of diff tuples. */ diff_match_patch.prototype.diff_cleanupMerge = function(diffs) { - diffs.push([DIFF_EQUAL, '']); // Add a dummy entry at the end. + // Add a dummy entry at the end. + diffs.push(new diff_match_patch.Diff(DIFF_EQUAL, '')); var pointer = 0; var count_delete = 0; var count_insert = 0; @@ -1086,8 +1108,8 @@ diff_match_patch.prototype.diff_cleanupMerge = function(diffs) { diffs[pointer - count_delete - count_insert - 1][1] += text_insert.substring(0, commonlength); } else { - diffs.splice(0, 0, [DIFF_EQUAL, - text_insert.substring(0, commonlength)]); + diffs.splice(0, 0, new diff_match_patch.Diff(DIFF_EQUAL, + text_insert.substring(0, commonlength))); pointer++; } text_insert = text_insert.substring(commonlength); @@ -1105,19 +1127,19 @@ diff_match_patch.prototype.diff_cleanupMerge = function(diffs) { } } // Delete the offending records and add the merged ones. - if (count_delete === 0) { - diffs.splice(pointer - count_insert, - count_delete + count_insert, [DIFF_INSERT, text_insert]); - } else if (count_insert === 0) { - diffs.splice(pointer - count_delete, - count_delete + count_insert, [DIFF_DELETE, text_delete]); - } else { - diffs.splice(pointer - count_delete - count_insert, - count_delete + count_insert, [DIFF_DELETE, text_delete], - [DIFF_INSERT, text_insert]); + pointer -= count_delete + count_insert; + diffs.splice(pointer, count_delete + count_insert); + if (text_delete.length) { + diffs.splice(pointer, 0, + new diff_match_patch.Diff(DIFF_DELETE, text_delete)); + pointer++; } - pointer = pointer - count_delete - count_insert + - (count_delete ? 1 : 0) + (count_insert ? 1 : 0) + 1; + if (text_insert.length) { + diffs.splice(pointer, 0, + new diff_match_patch.Diff(DIFF_INSERT, text_insert)); + pointer++; + } + pointer++; } else if (pointer !== 0 && diffs[pointer - 1][0] == DIFF_EQUAL) { // Merge this equality with the previous one. diffs[pointer - 1][1] += diffs[pointer][1]; @@ -1355,7 +1377,8 @@ diff_match_patch.prototype.diff_fromDelta = function(text1, delta) { switch (tokens[x].charAt(0)) { case '+': try { - diffs[diffsLength++] = [DIFF_INSERT, decodeURI(param)]; + diffs[diffsLength++] = + new diff_match_patch.Diff(DIFF_INSERT, decodeURI(param)); } catch (ex) { // Malformed URI sequence. throw new Error('Illegal escape in diff_fromDelta: ' + param); @@ -1370,9 +1393,9 @@ diff_match_patch.prototype.diff_fromDelta = function(text1, delta) { } var text = text1.substring(pointer, pointer += n); if (tokens[x].charAt(0) == '=') { - diffs[diffsLength++] = [DIFF_EQUAL, text]; + diffs[diffsLength++] = new diff_match_patch.Diff(DIFF_EQUAL, text); } else { - diffs[diffsLength++] = [DIFF_DELETE, text]; + diffs[diffsLength++] = new diff_match_patch.Diff(DIFF_DELETE, text); } break; default: @@ -1575,6 +1598,9 @@ diff_match_patch.prototype.patch_addContext_ = function(patch, text) { if (text.length == 0) { return; } + if (patch.start2 === null) { + throw Error('patch not initialized'); + } var pattern = text.substring(patch.start2, patch.start2 + patch.length1); var padding = 0; @@ -1593,13 +1619,13 @@ diff_match_patch.prototype.patch_addContext_ = function(patch, text) { // Add the prefix. var prefix = text.substring(patch.start2 - padding, patch.start2); if (prefix) { - patch.diffs.unshift([DIFF_EQUAL, prefix]); + patch.diffs.unshift(new diff_match_patch.Diff(DIFF_EQUAL, prefix)); } // Add the suffix. var suffix = text.substring(patch.start2 + patch.length1, patch.start2 + patch.length1 + padding); if (suffix) { - patch.diffs.push([DIFF_EQUAL, suffix]); + patch.diffs.push(new diff_match_patch.Diff(DIFF_EQUAL, suffix)); } // Roll back the start points. @@ -1627,9 +1653,9 @@ diff_match_patch.prototype.patch_addContext_ = function(patch, text) { * * @param {string|!Array.} a text1 (methods 1,3,4) or * Array of diff tuples for text1 to text2 (method 2). - * @param {string|!Array.} opt_b text2 (methods 1,4) or + * @param {string|!Array.=} opt_b text2 (methods 1,4) or * Array of diff tuples for text1 to text2 (method 3) or undefined (method 2). - * @param {string|!Array.} opt_c Array of diff tuples + * @param {string|!Array.=} opt_c Array of diff tuples * for text1 to text2 (method 4) or undefined (methods 1,2,3). * @return {!Array.} Array of Patch objects. */ @@ -1718,7 +1744,7 @@ diff_match_patch.prototype.patch_make = function(a, opt_b, opt_c) { patch = new diff_match_patch.patch_obj(); patchDiffLength = 0; // Unlike Unidiff, our patch lists have a rolling context. - // http://code.google.com/p/google-diff-match-patch/wiki/Unidiff + // https://github.com/google/diff-match-patch/wiki/Unidiff // Update prepatch text & pos to reflect the application of the // just completed patch. prepatch_text = postpatch_text; @@ -1759,7 +1785,8 @@ diff_match_patch.prototype.patch_deepCopy = function(patches) { var patchCopy = new diff_match_patch.patch_obj(); patchCopy.diffs = []; for (var y = 0; y < patch.diffs.length; y++) { - patchCopy.diffs[y] = patch.diffs[y].slice(); + patchCopy.diffs[y] = + new diff_match_patch.Diff(patch.diffs[y][0], patch.diffs[y][1]); } patchCopy.start1 = patch.start1; patchCopy.start2 = patch.start2; @@ -1903,7 +1930,7 @@ diff_match_patch.prototype.patch_addPadding = function(patches) { var diffs = patch.diffs; if (diffs.length == 0 || diffs[0][0] != DIFF_EQUAL) { // Add nullPadding equality. - diffs.unshift([DIFF_EQUAL, nullPadding]); + diffs.unshift(new diff_match_patch.Diff(DIFF_EQUAL, nullPadding)); patch.start1 -= paddingLength; // Should be 0. patch.start2 -= paddingLength; // Should be 0. patch.length1 += paddingLength; @@ -1923,7 +1950,7 @@ diff_match_patch.prototype.patch_addPadding = function(patches) { diffs = patch.diffs; if (diffs.length == 0 || diffs[diffs.length - 1][0] != DIFF_EQUAL) { // Add nullPadding equality. - diffs.push([DIFF_EQUAL, nullPadding]); + diffs.push(new diff_match_patch.Diff(DIFF_EQUAL, nullPadding)); patch.length1 += paddingLength; patch.length2 += paddingLength; } else if (paddingLength > diffs[diffs.length - 1][1].length) { @@ -1964,7 +1991,7 @@ diff_match_patch.prototype.patch_splitMax = function(patches) { patch.start2 = start2 - precontext.length; if (precontext !== '') { patch.length1 = patch.length2 = precontext.length; - patch.diffs.push([DIFF_EQUAL, precontext]); + patch.diffs.push(new diff_match_patch.Diff(DIFF_EQUAL, precontext)); } while (bigpatch.diffs.length !== 0 && patch.length1 < patch_size - this.Patch_Margin) { @@ -1983,7 +2010,7 @@ diff_match_patch.prototype.patch_splitMax = function(patches) { patch.length1 += diff_text.length; start1 += diff_text.length; empty = false; - patch.diffs.push([diff_type, diff_text]); + patch.diffs.push(new diff_match_patch.Diff(diff_type, diff_text)); bigpatch.diffs.shift(); } else { // Deletion or equality. Only take as much as we can stomach. @@ -1997,7 +2024,7 @@ diff_match_patch.prototype.patch_splitMax = function(patches) { } else { empty = false; } - patch.diffs.push([diff_type, diff_text]); + patch.diffs.push(new diff_match_patch.Diff(diff_type, diff_text)); if (diff_text == bigpatch.diffs[0][1]) { bigpatch.diffs.shift(); } else { @@ -2020,7 +2047,7 @@ diff_match_patch.prototype.patch_splitMax = function(patches) { patch.diffs[patch.diffs.length - 1][0] === DIFF_EQUAL) { patch.diffs[patch.diffs.length - 1][1] += postcontext; } else { - patch.diffs.push([DIFF_EQUAL, postcontext]); + patch.diffs.push(new diff_match_patch.Diff(DIFF_EQUAL, postcontext)); } } if (!empty) { @@ -2099,13 +2126,13 @@ diff_match_patch.prototype.patch_fromText = function(textline) { } if (sign == '-') { // Deletion. - patch.diffs.push([DIFF_DELETE, line]); + patch.diffs.push(new diff_match_patch.Diff(DIFF_DELETE, line)); } else if (sign == '+') { // Insertion. - patch.diffs.push([DIFF_INSERT, line]); + patch.diffs.push(new diff_match_patch.Diff(DIFF_INSERT, line)); } else if (sign == ' ') { // Minor equality. - patch.diffs.push([DIFF_EQUAL, line]); + patch.diffs.push(new diff_match_patch.Diff(DIFF_EQUAL, line)); } else if (sign == '@') { // Start of next patch. break; @@ -2141,9 +2168,9 @@ diff_match_patch.patch_obj = function() { /** - * Emmulate GNU diff's format. + * Emulate GNU diff's format. * Header: @@ -382,8 +481,9 @@ - * Indicies are printed as 1-based, not 0-based. + * Indices are printed as 1-based, not 0-based. * @return {string} The GNU diff string. */ diff_match_patch.patch_obj.prototype.toString = function() { @@ -2183,11 +2210,9 @@ diff_match_patch.patch_obj.prototype.toString = function() { }; -// Export these global variables so that they survive Google's JS compiler. -// In a browser, 'this' will be 'window'. -// Users of node.js should 'require' the uncompressed version since Google's -// JS compiler may break the following exports for non-browser environments. -this['diff_match_patch'] = diff_match_patch; -this['DIFF_DELETE'] = DIFF_DELETE; -this['DIFF_INSERT'] = DIFF_INSERT; -this['DIFF_EQUAL'] = DIFF_EQUAL; +// The following export code was added by @ForbesLindesay +module.exports = diff_match_patch; +module.exports['diff_match_patch'] = diff_match_patch; +module.exports['DIFF_DELETE'] = DIFF_DELETE; +module.exports['DIFF_INSERT'] = DIFF_INSERT; +module.exports['DIFF_EQUAL'] = DIFF_EQUAL; \ No newline at end of file From d4042b2cc81316b3681a14ec60fe1d2c42bc9fcc Mon Sep 17 00:00:00 2001 From: Evan Broder Date: Wed, 28 Dec 2022 13:12:37 -0800 Subject: [PATCH 03/28] Fix errors in Mongo types Both the synchronous and asynchronous iterators for Mongo.Cursor are defined to have a "next" argument type of never. However, TypeScript will reject using such an iterator in a for-of loop with: > Cannot iterate value because the 'next' method of its iterator expects > type 'never', but for-of will always send 'undefined'.ts(2763) This changes back to the default (undefined), which is acceptable, since the iterators ignore any arguments passed into next() anyway. It also correctly declares the return type of dropIndexAsync, which should return a Promise, not void. --- packages/mongo/mongo.d.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/mongo/mongo.d.ts b/packages/mongo/mongo.d.ts index 43e8e9c3e7..67dc5e0ccb 100644 --- a/packages/mongo/mongo.d.ts +++ b/packages/mongo/mongo.d.ts @@ -269,7 +269,7 @@ export namespace Mongo { transform?: Fn | undefined; }): boolean; dropCollectionAsync(): Promise; - dropIndexAsync(indexName: string): void; + dropIndexAsync(indexName: string): Promise; /** * Find the documents in a collection that match the selector. * @param selector A query describing the documents to find @@ -541,8 +541,8 @@ export namespace Mongo { callbacks: ObserveChangesCallbacks, options?: { nonMutatingCallbacks?: boolean | undefined } ): Meteor.LiveQueryHandle; - [Symbol.iterator](): Iterator; - [Symbol.asyncIterator](): AsyncIterator; + [Symbol.iterator](): Iterator; + [Symbol.asyncIterator](): AsyncIterator; } var ObjectID: ObjectIDStatic; From fe1602c95711e42c9ff266dbe6d7ba0759d0e708 Mon Sep 17 00:00:00 2001 From: Jan Dvorak Date: Tue, 3 Jan 2023 11:11:47 +0900 Subject: [PATCH 04/28] Update skeletons to use React 18 --- tools/static-assets/skel-apollo/client/main.jsx | 6 ++++-- tools/static-assets/skel-apollo/package.json | 8 ++++---- tools/static-assets/skel-react/client/main.jsx | 6 ++++-- tools/static-assets/skel-react/package.json | 8 ++++---- tools/static-assets/skel-typescript/client/main.tsx | 8 +++++--- tools/static-assets/skel-typescript/package.json | 12 ++++++------ 6 files changed, 27 insertions(+), 21 deletions(-) diff --git a/tools/static-assets/skel-apollo/client/main.jsx b/tools/static-assets/skel-apollo/client/main.jsx index a42cee8ff3..d2e380f93c 100644 --- a/tools/static-assets/skel-apollo/client/main.jsx +++ b/tools/static-assets/skel-apollo/client/main.jsx @@ -1,8 +1,10 @@ import React from 'react'; +import { createRoot } from 'react-dom/client'; import { Meteor } from 'meteor/meteor'; -import { render } from 'react-dom'; import { App } from '/imports/ui/App'; Meteor.startup(() => { - render(, document.getElementById('react-target')); + const container = document.getElementById('react-target'); + const root = createRoot(container); + root.render(); }); diff --git a/tools/static-assets/skel-apollo/package.json b/tools/static-assets/skel-apollo/package.json index 169453642c..5b0908c844 100644 --- a/tools/static-assets/skel-apollo/package.json +++ b/tools/static-assets/skel-apollo/package.json @@ -8,12 +8,12 @@ "visualize": "meteor --production --extra-packages bundle-visualizer" }, "dependencies": { - "@apollo/client": "^3.6.9", - "@babel/runtime": "^7.18.6", + "@apollo/client": "^3.7.3", + "@babel/runtime": "^7.20.7", "apollo-server-express": "^3.10.0", "express": "^4.18.1", - "graphql": "^15.8.0", - "meteor-node-stubs": "^1.2.3", + "graphql": "^16.6.0", + "meteor-node-stubs": "^1.2.5", "react": "^18.2.0", "react-dom": "^18.2.0" }, diff --git a/tools/static-assets/skel-react/client/main.jsx b/tools/static-assets/skel-react/client/main.jsx index a42cee8ff3..d2e380f93c 100644 --- a/tools/static-assets/skel-react/client/main.jsx +++ b/tools/static-assets/skel-react/client/main.jsx @@ -1,8 +1,10 @@ import React from 'react'; +import { createRoot } from 'react-dom/client'; import { Meteor } from 'meteor/meteor'; -import { render } from 'react-dom'; import { App } from '/imports/ui/App'; Meteor.startup(() => { - render(, document.getElementById('react-target')); + const container = document.getElementById('react-target'); + const root = createRoot(container); + root.render(); }); diff --git a/tools/static-assets/skel-react/package.json b/tools/static-assets/skel-react/package.json index 2b26e9c8cd..1b0c4457f4 100644 --- a/tools/static-assets/skel-react/package.json +++ b/tools/static-assets/skel-react/package.json @@ -8,10 +8,10 @@ "visualize": "meteor --production --extra-packages bundle-visualizer" }, "dependencies": { - "@babel/runtime": "^7.17.9", - "meteor-node-stubs": "^1.2.1", - "react": "^17.0.2", - "react-dom": "^17.0.2" + "@babel/runtime": "^7.20.7", + "meteor-node-stubs": "^1.2.5", + "react": "^18.2.0", + "react-dom": "^18.2.0" }, "meteor": { "mainModule": { diff --git a/tools/static-assets/skel-typescript/client/main.tsx b/tools/static-assets/skel-typescript/client/main.tsx index 5e9849b062..523141b528 100644 --- a/tools/static-assets/skel-typescript/client/main.tsx +++ b/tools/static-assets/skel-typescript/client/main.tsx @@ -1,8 +1,10 @@ import React from 'react'; +import { createRoot } from 'react-dom/client'; import { Meteor } from 'meteor/meteor'; -import { render } from 'react-dom'; -import { App } from '/imports/ui/App' +import { App } from '/imports/ui/App'; Meteor.startup(() => { - render(, document.getElementById('react-target')); + const container = document.getElementById('react-target'); + const root = createRoot(container!); + root.render(); }); diff --git a/tools/static-assets/skel-typescript/package.json b/tools/static-assets/skel-typescript/package.json index 76457880f7..f9ac32d489 100644 --- a/tools/static-assets/skel-typescript/package.json +++ b/tools/static-assets/skel-typescript/package.json @@ -8,16 +8,16 @@ "visualize": "meteor --production --extra-packages bundle-visualizer" }, "dependencies": { - "@babel/runtime": "^7.17.9", - "meteor-node-stubs": "^1.2.1", - "react": "^17.0.2", - "react-dom": "^17.0.2" + "@babel/runtime": "^7.20.7", + "meteor-node-stubs": "^1.2.5", + "react": "^18.2.0", + "react-dom": "^18.2.0" }, "devDependencies": { "@types/meteor": "^1.4.87", "@types/mocha": "^8.2.3", - "@types/react": "^17.0.43", - "@types/react-dom": "^17.0.14", + "@types/react": "^18.0.26", + "@types/react-dom": "^18.0.10", "typescript": "^4.6.4" }, "meteor": { From 59e7fedccfc721def2991a4ef63b931fd7b940e8 Mon Sep 17 00:00:00 2001 From: harryadel Date: Tue, 3 Jan 2023 11:25:36 +0200 Subject: [PATCH 05/28] [test-in-browser] Import diff_match_patch instead of global import --- packages/test-in-browser/driver.js | 2 +- packages/test-in-browser/package.js | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/test-in-browser/driver.js b/packages/test-in-browser/driver.js index b8fb0a9ecf..d14a6fecde 100644 --- a/packages/test-in-browser/driver.js +++ b/packages/test-in-browser/driver.js @@ -1,7 +1,7 @@ //// //// Setup //// - +import { diff_match_patch } from './diff_match_patch_uncompressed' import 'bootstrap/dist/css/bootstrap.min.css'; // dependency for the count of tests running/passed/failed, etc. drives diff --git a/packages/test-in-browser/package.js b/packages/test-in-browser/package.js index 3840a847c1..4fceca27d6 100644 --- a/packages/test-in-browser/package.js +++ b/packages/test-in-browser/package.js @@ -27,8 +27,6 @@ Package.onUse(function (api) { 'tracker', ], 'client'); - api.addFiles('diff_match_patch_uncompressed.js', 'client'); - api.addFiles([ 'driver.html', 'driver.js', From 46f001ebe9d5d8b56879aea8ade285f43f8f5aea Mon Sep 17 00:00:00 2001 From: harryadel Date: Tue, 3 Jan 2023 11:48:09 +0200 Subject: [PATCH 06/28] [test-in-browser] Update blaze submodule --- packages/non-core/blaze | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/non-core/blaze b/packages/non-core/blaze index c856c6604b..646383bc37 160000 --- a/packages/non-core/blaze +++ b/packages/non-core/blaze @@ -1 +1 @@ -Subproject commit c856c6604b6e54b9a8fe87cd941a8bd660fd7e4f +Subproject commit 646383bc3730648c98ce8be8930d697f6eca83f3 From a61bcc395105bd4a0ddfe9f2ee5c9d63f158ff99 Mon Sep 17 00:00:00 2001 From: harryadel Date: Tue, 3 Jan 2023 12:29:54 +0200 Subject: [PATCH 07/28] Fix blaze-html-templates version constraint --- tools/tests/apps/shell/.meteor/packages | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/tests/apps/shell/.meteor/packages b/tools/tests/apps/shell/.meteor/packages index c45a0da55a..62532884c8 100644 --- a/tools/tests/apps/shell/.meteor/packages +++ b/tools/tests/apps/shell/.meteor/packages @@ -7,7 +7,7 @@ meteor-base # Packages every Meteor app needs to have mobile-experience # Packages for a great mobile UX mongo # The database Meteor supports right now -blaze-html-templates # Compile .html files into Meteor Blaze views +blaze-html-templates@2.0.0! # Compile .html files into Meteor Blaze views reactive-var # Reactive variable for tracker jquery # Helpful client-side library tracker # Meteor's client-side reactive programming library From 76c85ee0e457dfe467f0dc5adfbda7090cfae11b Mon Sep 17 00:00:00 2001 From: harryadel Date: Tue, 3 Jan 2023 13:24:50 +0200 Subject: [PATCH 08/28] [test-in-browser] Update blaze-html-templates version in dynamic-import --- tools/tests/apps/dynamic-import/.meteor/packages | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/tests/apps/dynamic-import/.meteor/packages b/tools/tests/apps/dynamic-import/.meteor/packages index 1570f6c394..04a1d2b87d 100644 --- a/tools/tests/apps/dynamic-import/.meteor/packages +++ b/tools/tests/apps/dynamic-import/.meteor/packages @@ -7,7 +7,7 @@ meteor-base@1.4.0 # Packages every Meteor app needs to have mobile-experience@1.1.0 # Packages for a great mobile UX mongo@1.9.0 # The database Meteor supports right now -blaze-html-templates@1.0.4 # Compile .html files into Meteor Blaze views +blaze-html-templates@2.0.0! # Compile .html files into Meteor Blaze views reactive-var@1.0.12 # Reactive variable for tracker tracker@1.2.1 # Meteor's client-side reactive programming library From 2fca78bf43a915811bfaf1019b56fe8280c159d0 Mon Sep 17 00:00:00 2001 From: Per Bergland Date: Fri, 30 Dec 2022 15:30:06 +0100 Subject: [PATCH 09/28] Use native driver types instead of homebuilt --- packages/mongo/mongo.d.ts | 111 +++----------------------------------- 1 file changed, 8 insertions(+), 103 deletions(-) diff --git a/packages/mongo/mongo.d.ts b/packages/mongo/mongo.d.ts index 43e8e9c3e7..38682bde81 100644 --- a/packages/mongo/mongo.d.ts +++ b/packages/mongo/mongo.d.ts @@ -15,78 +15,11 @@ export type UnionOmit = T extends T : never; export namespace Mongo { - // prettier-ignore - type BsonType = 1 | "double" | - 2 | "string" | - 3 | "object" | - 4 | "array" | - 5 | "binData" | - 6 | "undefined" | - 7 | "objectId" | - 8 | "bool" | - 9 | "date" | - 10 | "null" | - 11 | "regex" | - 12 | "dbPointer" | - 13 | "javascript" | - 14 | "symbol" | - 15 | "javascriptWithScope" | - 16 | "int" | - 17 | "timestamp" | - 18 | "long" | - 19 | "decimal" | - -1 | "minKey" | - 127 | "maxKey" | "number"; - type FieldExpression = { - $eq?: T | undefined; - $gt?: T | undefined; - $gte?: T | undefined; - $lt?: T | undefined; - $lte?: T | undefined; - $in?: T[] | undefined; - $nin?: T[] | undefined; - $ne?: T | undefined; - $exists?: boolean | undefined; - $type?: BsonType[] | BsonType | undefined; - $not?: FieldExpression | undefined; - $expr?: FieldExpression | undefined; - $jsonSchema?: any; - $mod?: number[] | undefined; - $regex?: RegExp | string | undefined; - $options?: string | undefined; - $text?: - | { - $search: string; - $language?: string | undefined; - $caseSensitive?: boolean | undefined; - $diacriticSensitive?: boolean | undefined; - } - | undefined; - $where?: string | Function | undefined; - $geoIntersects?: any; - $geoWithin?: any; - $near?: any; - $nearSphere?: any; - $all?: T[] | undefined; - $elemMatch?: T extends {} ? Query : FieldExpression | undefined; - $size?: number | undefined; - $bitsAllClear?: any; - $bitsAllSet?: any; - $bitsAnyClear?: any; - $bitsAnySet?: any; - $comment?: string | undefined; - }; - - type Flatten = T extends any[] ? T[0] : T; - - type Query = { - [P in keyof T]?: Flatten | RegExp | FieldExpression>; - } & { - $or?: Query[] | undefined; - $and?: Query[] | undefined; - $nor?: Query[] | undefined; - } & Dictionary; + /** + * Alias for {@link MongoNpmModule.Filter} + */ + type Query = MongoNpmModule.Filter; type QueryWithModifiers = { $query: Query; @@ -122,41 +55,13 @@ export namespace Mongo { $sort?: 1 | -1 | Dictionary | undefined; }; }; - type ArraysOrEach = { - [P in keyof T]?: OnlyElementsOfArrays | { $each: T[P] }; - }; - type CurrentDateModifier = { $type: 'timestamp' | 'date' } | true; - type Modifier = - | T - | { - $currentDate?: - | (Partial> & - Dictionary) - | undefined; - $inc?: (PartialMapTo & Dictionary) | undefined; - $min?: - | (PartialMapTo & Dictionary) - | undefined; - $max?: - | (PartialMapTo & Dictionary) - | undefined; - $mul?: (PartialMapTo & Dictionary) | undefined; - $rename?: (PartialMapTo & Dictionary) | undefined; - $set?: (Partial & Dictionary) | undefined; - $setOnInsert?: (Partial & Dictionary) | undefined; - $unset?: - | (PartialMapTo & Dictionary) - | undefined; - $addToSet?: (ArraysOrEach & Dictionary) | undefined; - $push?: (PushModifier & Dictionary) | undefined; - $pull?: (ElementsOf & Dictionary) | undefined; - $pullAll?: (Partial & Dictionary) | undefined; - $pop?: (PartialMapTo & Dictionary<1 | -1>) | undefined; - }; + + type Modifier = MongoNpmModule.UpdateFilter; type OptionalId = UnionOmit & { _id?: any }; - interface SortSpecifier {} + type SortSpecifier = MongoNpmModule.Sort; + interface FieldSpecifier { [id: string]: Number; } From 12be986301ed4c746ee187286ab844214f3ebdd2 Mon Sep 17 00:00:00 2001 From: Per Bergland Date: Fri, 30 Dec 2022 19:29:31 +0100 Subject: [PATCH 10/28] copy over fix from definitelytyped --- packages/mongo/mongo.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/mongo/mongo.d.ts b/packages/mongo/mongo.d.ts index 38682bde81..59b74e2da6 100644 --- a/packages/mongo/mongo.d.ts +++ b/packages/mongo/mongo.d.ts @@ -446,8 +446,8 @@ export namespace Mongo { callbacks: ObserveChangesCallbacks, options?: { nonMutatingCallbacks?: boolean | undefined } ): Meteor.LiveQueryHandle; - [Symbol.iterator](): Iterator; - [Symbol.asyncIterator](): AsyncIterator; + [Symbol.iterator](): Iterator; + [Symbol.asyncIterator](): AsyncIterator; } var ObjectID: ObjectIDStatic; From fa23757abd083653d6b70750fb25342cd97fab50 Mon Sep 17 00:00:00 2001 From: Per Bergland Date: Wed, 4 Jan 2023 09:02:56 +0100 Subject: [PATCH 11/28] remove unused types, export more types --- packages/mongo/mongo.d.ts | 31 +++++-------------------------- 1 file changed, 5 insertions(+), 26 deletions(-) diff --git a/packages/mongo/mongo.d.ts b/packages/mongo/mongo.d.ts index 59b74e2da6..4689b4e95d 100644 --- a/packages/mongo/mongo.d.ts +++ b/packages/mongo/mongo.d.ts @@ -16,12 +16,9 @@ export type UnionOmit = T extends T export namespace Mongo { - /** - * Alias for {@link MongoNpmModule.Filter} - */ type Query = MongoNpmModule.Filter; - type QueryWithModifiers = { + export type QueryWithModifiers = { $query: Query; $comment?: string | undefined; $explain?: any; @@ -36,39 +33,21 @@ export namespace Mongo { $natural?: any; }; - type Selector = Query | QueryWithModifiers; + export type Selector = Query | QueryWithModifiers; - type Dictionary = { [key: string]: T }; - type PartialMapTo = Partial>; - type OnlyArrays = T extends any[] ? T : never; - type OnlyElementsOfArrays = T extends any[] ? Partial : never; - type ElementsOf = { - [P in keyof T]?: OnlyElementsOfArrays; - }; - type PushModifier = { - [P in keyof T]?: - | OnlyElementsOfArrays - | { - $each?: T[P] | undefined; - $position?: number | undefined; - $slice?: number | undefined; - $sort?: 1 | -1 | Dictionary | undefined; - }; - }; - type Modifier = MongoNpmModule.UpdateFilter; - type OptionalId = UnionOmit & { _id?: any }; + export type OptionalId = UnionOmit & { _id?: any }; type SortSpecifier = MongoNpmModule.Sort; - interface FieldSpecifier { + export interface FieldSpecifier { [id: string]: Number; } type Transform = ((doc: T) => any) | null | undefined; - type Options = { + export type Options = { /** Sort order (default: natural order) */ sort?: SortSpecifier | undefined; /** Number of results to skip at the beginning */ From b1507e0325cf96036610a6e41dbc3b4e6b54d230 Mon Sep 17 00:00:00 2001 From: Per Bergland Date: Wed, 4 Jan 2023 09:10:35 +0100 Subject: [PATCH 12/28] export one more --- packages/mongo/mongo.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/mongo/mongo.d.ts b/packages/mongo/mongo.d.ts index 4689b4e95d..aff69ba8e4 100644 --- a/packages/mongo/mongo.d.ts +++ b/packages/mongo/mongo.d.ts @@ -45,7 +45,7 @@ export namespace Mongo { [id: string]: Number; } - type Transform = ((doc: T) => any) | null | undefined; + export type Transform = ((doc: T) => any) | null | undefined; export type Options = { /** Sort order (default: natural order) */ From 6a331ffe2022b69d12a59e2b103fc586f35993d2 Mon Sep 17 00:00:00 2001 From: Gabriel Grubba Date: Wed, 4 Jan 2023 16:45:30 -0300 Subject: [PATCH 13/28] docs: added initial docs to 2.10 --- docs/history.md | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/docs/history.md b/docs/history.md index 6a845af21d..fe4bf5491e 100644 --- a/docs/history.md +++ b/docs/history.md @@ -1,3 +1,50 @@ +## v2.10.0, 2023-01-XX + +### Highlights + +* Update skeletons to use React 18 [PR](https://github.com/meteor/meteor/pull/12419) by [StorytellerCZ](https://github.com/StorytellerCZ). +* Use MongoDB types instead of the homebuilt [PR](https://github.com/meteor/meteor/pull/12415) by [perbergland](https://github.com/perbergland). +* Fixing wrong type definitions in MongoDB package [PR](https://github.com/meteor/meteor/pull/12409) by [ebroder](https://github.com/ebroder). +* Typescript to version v4.7.4 [PR](https://github.com/meteor/meteor/pull/12393) by [StorytellerCZ](https://github.com/StorytellerCZ). +* Update test-in-browser dependencies [PR](https://github.com/meteor/meteor/pull/12384) by [harryadel](https://github.com/harryadel). + +#### Breaking Changes + +N/A + +#### Internal API changes + +N/A + +#### Migration Steps + +N/A + +#### Meteor Version Release + +* `mongo@1.16.4`: + - Fixed wrong type definitions. + - switch to using MongoDB types instead of the homebuilt. + +* `test-in-browser@1.3.3`: + - Updated dependencies and removed unused libs. + +* `typescript@4.7.4` + - Updated typescript to version 4.7.4. + +* `Command line`: + - Updated React skeletons to use react 18 + +#### Special thanks to + - [@StorytellerCZ](https://github.com/StorytellerCZ). + - [@perbergland](https://github.com/perbergland). + - [@ebroder](https://github.com/ebroder). + - [@harryadel](https://github.com/harryadel). + +For making this great framework even better! + + + ## v2.9.1, 2022-12-27 ### Highlights From c11dd67656102041014607e85659e2b9e5dba3ac Mon Sep 17 00:00:00 2001 From: Gabriel Grubba Date: Wed, 4 Jan 2023 16:49:02 -0300 Subject: [PATCH 14/28] docs: fixed React typo --- docs/history.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/history.md b/docs/history.md index fe4bf5491e..2f1515bb11 100644 --- a/docs/history.md +++ b/docs/history.md @@ -33,7 +33,7 @@ N/A - Updated typescript to version 4.7.4. * `Command line`: - - Updated React skeletons to use react 18 + - Updated React skeletons to use React 18 #### Special thanks to - [@StorytellerCZ](https://github.com/StorytellerCZ). From 7eed486800e2fdf9ee0329667047b18b8d6ef663 Mon Sep 17 00:00:00 2001 From: Evan Broder Date: Wed, 4 Jan 2023 14:11:30 -0800 Subject: [PATCH 15/28] Allow multiple runtime config and updated runtime hooks The forEach method on Hook will stop iterating unless the iterator function returns a truthy value. Previously, this meant that only the first registered runtime config hook would be called. --- packages/webapp/webapp_server.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/webapp/webapp_server.js b/packages/webapp/webapp_server.js index 03d6de971b..1c659da0ad 100644 --- a/packages/webapp/webapp_server.js +++ b/packages/webapp/webapp_server.js @@ -429,10 +429,11 @@ function getBoilerplateAsync(request, arch) { encodedCurrentConfig: boilerplate.baseData.meteorRuntimeConfig, updated: runtimeConfig.isUpdatedByArch[arch], }); - if (!meteorRuntimeConfig) return; + if (!meteorRuntimeConfig) return true; boilerplate.baseData = Object.assign({}, boilerplate.baseData, { meteorRuntimeConfig, }); + return true; }); runtimeConfig.isUpdatedByArch[arch] = false; const data = Object.assign( @@ -509,6 +510,7 @@ WebAppInternals.generateBoilerplateInstance = function( }; runtimeConfig.updateHooks.forEach(cb => { cb({ arch, manifest, runtimeConfig: rtimeConfig }); + return true; }); const meteorRuntimeConfig = JSON.stringify( From 9a87c3562b68b6ea7b5dc7346fff3fb1355680cb Mon Sep 17 00:00:00 2001 From: Jan Dvorak Date: Thu, 5 Jan 2023 15:54:33 +0900 Subject: [PATCH 16/28] Update react-fast-refresh dependencies --- packages/react-fast-refresh/package.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/react-fast-refresh/package.js b/packages/react-fast-refresh/package.js index f37a6b5ee1..036810d29e 100644 --- a/packages/react-fast-refresh/package.js +++ b/packages/react-fast-refresh/package.js @@ -1,14 +1,14 @@ Package.describe({ name: 'react-fast-refresh', - version: '0.2.3', + version: '0.2.4', summary: 'Automatically update React components with HMR', documentation: 'README.md', devOnly: true, }); Npm.depends({ - 'react-refresh': '0.11.0', - semver: '7.3.4', + 'react-refresh': '0.14.0', + semver: '7.3.8', }); Package.onUse(function(api) { From 9a4993b6432a685357b5ee8948e1923e77fa65b4 Mon Sep 17 00:00:00 2001 From: Gabriel Grubba Date: Thu, 5 Jan 2023 09:57:23 -0300 Subject: [PATCH 17/28] docs: updated docs from 2.10 --- docs/history.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/docs/history.md b/docs/history.md index 2f1515bb11..5d754415c3 100644 --- a/docs/history.md +++ b/docs/history.md @@ -7,6 +7,7 @@ * Fixing wrong type definitions in MongoDB package [PR](https://github.com/meteor/meteor/pull/12409) by [ebroder](https://github.com/ebroder). * Typescript to version v4.7.4 [PR](https://github.com/meteor/meteor/pull/12393) by [StorytellerCZ](https://github.com/StorytellerCZ). * Update test-in-browser dependencies [PR](https://github.com/meteor/meteor/pull/12384) by [harryadel](https://github.com/harryadel). +* Allow multiple runtime config and updated runtime hooks [PR](https://github.com/meteor/meteor/pull/12426) by [ebroder](https://github.com/ebroder). #### Breaking Changes @@ -30,7 +31,11 @@ N/A - Updated dependencies and removed unused libs. * `typescript@4.7.4` - - Updated typescript to version 4.7.4. + - Updated typescript to version 4.7.4. + +* `webapp@1.13.3` + - The forEach method on Hook will stop iterating unless the iterator function returns a truthy value. + Previously, this meant that only the first registered runtime config hook would be called. * `Command line`: - Updated React skeletons to use React 18 From f3950ff881235502d7fac4c9f2efd359c0d97d27 Mon Sep 17 00:00:00 2001 From: Gabriel Grubba Date: Thu, 5 Jan 2023 09:58:50 -0300 Subject: [PATCH 18/28] cherry picked from e6efc44c2e6dcc7ee80217ef9b0d85e75931aba3 --- packages/callback-hook/hook.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/packages/callback-hook/hook.js b/packages/callback-hook/hook.js index 8a8aa29ecd..f40151a288 100644 --- a/packages/callback-hook/hook.js +++ b/packages/callback-hook/hook.js @@ -84,6 +84,11 @@ export class Hook { }; } + clear() { + this.nextCallbackId = 0; + this.callbacks = []; + } + /** * For each registered callback, call the passed iterator function with the callback. * @@ -114,6 +119,20 @@ export class Hook { } } + async forEachAsync(iterator) { + const ids = Object.keys(this.callbacks); + for (let i = 0; i < ids.length; ++i) { + const id = ids[i]; + // check to see if the callback was removed during iteration + if (hasOwn.call(this.callbacks, id)) { + const callback = this.callbacks[id]; + if (!await iterator(callback)) { + break; + } + } + } + } + /** * @deprecated use forEach * @param iterator From 458267507877173323993a542de2c8eab845acfb Mon Sep 17 00:00:00 2001 From: Gabriel Grubba Date: Thu, 5 Jan 2023 10:06:48 -0300 Subject: [PATCH 19/28] docs: added docs to forEachAsync in hook.js --- packages/callback-hook/hook.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/callback-hook/hook.js b/packages/callback-hook/hook.js index f40151a288..58d33cc17e 100644 --- a/packages/callback-hook/hook.js +++ b/packages/callback-hook/hook.js @@ -119,6 +119,14 @@ export class Hook { } } + /** + * For each registered callback, call the passed iterator function with the callback. + * + * it is a counterpart of forEach, but it is async and returns a promise + * @param iterator + * @return {Promise} + * @see forEach + */ async forEachAsync(iterator) { const ids = Object.keys(this.callbacks); for (let i = 0; i < ids.length; ++i) { From c3bae92204527946d3023189dd1eb2aab435f4c4 Mon Sep 17 00:00:00 2001 From: Gabriel Grubba Date: Thu, 5 Jan 2023 10:07:05 -0300 Subject: [PATCH 20/28] docs: updated changelog for callback-hook --- docs/history.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/history.md b/docs/history.md index 5d754415c3..57f544dddc 100644 --- a/docs/history.md +++ b/docs/history.md @@ -36,6 +36,9 @@ N/A * `webapp@1.13.3` - The forEach method on Hook will stop iterating unless the iterator function returns a truthy value. Previously, this meant that only the first registered runtime config hook would be called. + +* `callback-hook@1.5.0` + - Added forEachAsync . * `Command line`: - Updated React skeletons to use React 18 From 629303484b3115c5a9d53e0b14ce1119f97be274 Mon Sep 17 00:00:00 2001 From: Gabriel Grubba Date: Thu, 5 Jan 2023 10:24:15 -0300 Subject: [PATCH 21/28] chore: turned hooks into async --- packages/accounts-base/accounts_client.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/accounts-base/accounts_client.js b/packages/accounts-base/accounts_client.js index 842e927ad9..98bcaf6e92 100644 --- a/packages/accounts-base/accounts_client.js +++ b/packages/accounts-base/accounts_client.js @@ -228,15 +228,15 @@ export class AccountsClient extends AccountsCommon { called = true; this._loginCallbacksCalled = true; if (!error) { - this._onLoginHook.forEach(callback => { - callback(loginDetails); + this._onLoginHook.forEachAsync(async callback => { + await callback(loginDetails); return true; - }); + }).then(); } else { - this._onLoginFailureHook.forEach(callback => { - callback({ error }); + this._onLoginFailureHook.forEachAsync(async callback => { + await callback({ error }); return true; - }); + }).then(); } options.userCallback(error, loginDetails); } @@ -377,10 +377,10 @@ export class AccountsClient extends AccountsCommon { makeClientLoggedOut() { // Ensure client was successfully logged in before running logout hooks. if (this.connection._userId) { - this._onLogoutHook.each(callback => { - callback(); + this._onLogoutHook.forEachAsync(async callback => { + await callback(); return true; - }); + }).then(); } this._unstoreLoginToken(); this.connection.setUserId(null); From 88b61119b01043d3d5d80aeb4fc618a95f64160e Mon Sep 17 00:00:00 2001 From: Gabriel Grubba Date: Thu, 5 Jan 2023 10:53:02 -0300 Subject: [PATCH 22/28] tests: added tests for on login --- packages/accounts-base/accounts_client_tests.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/packages/accounts-base/accounts_client_tests.js b/packages/accounts-base/accounts_client_tests.js index 880a71e4fe..d92d1ef818 100644 --- a/packages/accounts-base/accounts_client_tests.js +++ b/packages/accounts-base/accounts_client_tests.js @@ -146,6 +146,21 @@ Tinytest.addAsync( } ); +Tinytest.addAsync( + 'accounts async - make async call onLogin', + (test, done) => { + const onLogin = Accounts.onLogin( async () => { + const sleep = + (ms) => new Promise(resolve => setTimeout(() => resolve(true), ms)); + const async = await sleep(10) + test.isTrue(async); + onLogin.stop() + removeTestUser(done); + }); + logoutAndCreateUser(test, done, () => {}); + } +); + Tinytest.addAsync( 'accounts - onLogin callback receives { type: "resume" } param on ' + 'reconnect, if already logged in', From 05b39ad7e9e02c1ad349a0af3276967581113f45 Mon Sep 17 00:00:00 2001 From: Gabriel Grubba Date: Thu, 5 Jan 2023 11:02:43 -0300 Subject: [PATCH 23/28] tests: created test for onLoginFailture --- .../accounts-base/accounts_client_tests.js | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/packages/accounts-base/accounts_client_tests.js b/packages/accounts-base/accounts_client_tests.js index d92d1ef818..f7652f8ed6 100644 --- a/packages/accounts-base/accounts_client_tests.js +++ b/packages/accounts-base/accounts_client_tests.js @@ -161,6 +161,27 @@ Tinytest.addAsync( } ); +Tinytest.addAsync( + 'accounts async - make async call onLoginFailure', + (test, done) => { + logoutAndCreateUser(test, done, () => { + const onLoginFailure = Accounts.onLoginFailure( async () => { + const sleep = + (ms) => new Promise(resolve => setTimeout(() => resolve(true), ms)); + const async = await sleep(10) + test.isTrue(async); + onLoginFailure.stop() + removeTestUser(done); + }); + + Meteor.loginWithPassword(username, "somewrongstring", () => { + test.isFalse(Meteor.loggingIn()); + removeTestUser(done); + }); + + }); + } +); Tinytest.addAsync( 'accounts - onLogin callback receives { type: "resume" } param on ' + 'reconnect, if already logged in', From 8c6f5bbb8eceee357ed2e180324b61655fc62400 Mon Sep 17 00:00:00 2001 From: Gabriel Grubba Date: Thu, 5 Jan 2023 14:10:18 -0300 Subject: [PATCH 24/28] tests: reverted changes --- .../accounts-base/accounts_client_tests.js | 36 ------------------- 1 file changed, 36 deletions(-) diff --git a/packages/accounts-base/accounts_client_tests.js b/packages/accounts-base/accounts_client_tests.js index f7652f8ed6..880a71e4fe 100644 --- a/packages/accounts-base/accounts_client_tests.js +++ b/packages/accounts-base/accounts_client_tests.js @@ -146,42 +146,6 @@ Tinytest.addAsync( } ); -Tinytest.addAsync( - 'accounts async - make async call onLogin', - (test, done) => { - const onLogin = Accounts.onLogin( async () => { - const sleep = - (ms) => new Promise(resolve => setTimeout(() => resolve(true), ms)); - const async = await sleep(10) - test.isTrue(async); - onLogin.stop() - removeTestUser(done); - }); - logoutAndCreateUser(test, done, () => {}); - } -); - -Tinytest.addAsync( - 'accounts async - make async call onLoginFailure', - (test, done) => { - logoutAndCreateUser(test, done, () => { - const onLoginFailure = Accounts.onLoginFailure( async () => { - const sleep = - (ms) => new Promise(resolve => setTimeout(() => resolve(true), ms)); - const async = await sleep(10) - test.isTrue(async); - onLoginFailure.stop() - removeTestUser(done); - }); - - Meteor.loginWithPassword(username, "somewrongstring", () => { - test.isFalse(Meteor.loggingIn()); - removeTestUser(done); - }); - - }); - } -); Tinytest.addAsync( 'accounts - onLogin callback receives { type: "resume" } param on ' + 'reconnect, if already logged in', From 95ac8a9a3016e35fa55b46886e685af82eb9ae5d Mon Sep 17 00:00:00 2001 From: Gabriel Grubba Date: Thu, 5 Jan 2023 14:10:31 -0300 Subject: [PATCH 25/28] Revert "chore: turned hooks into async" This reverts commit 629303484b3115c5a9d53e0b14ce1119f97be274. --- packages/accounts-base/accounts_client.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/accounts-base/accounts_client.js b/packages/accounts-base/accounts_client.js index 98bcaf6e92..842e927ad9 100644 --- a/packages/accounts-base/accounts_client.js +++ b/packages/accounts-base/accounts_client.js @@ -228,15 +228,15 @@ export class AccountsClient extends AccountsCommon { called = true; this._loginCallbacksCalled = true; if (!error) { - this._onLoginHook.forEachAsync(async callback => { - await callback(loginDetails); + this._onLoginHook.forEach(callback => { + callback(loginDetails); return true; - }).then(); + }); } else { - this._onLoginFailureHook.forEachAsync(async callback => { - await callback({ error }); + this._onLoginFailureHook.forEach(callback => { + callback({ error }); return true; - }).then(); + }); } options.userCallback(error, loginDetails); } @@ -377,10 +377,10 @@ export class AccountsClient extends AccountsCommon { makeClientLoggedOut() { // Ensure client was successfully logged in before running logout hooks. if (this.connection._userId) { - this._onLogoutHook.forEachAsync(async callback => { - await callback(); + this._onLogoutHook.each(callback => { + callback(); return true; - }).then(); + }); } this._unstoreLoginToken(); this.connection.setUserId(null); From 3d7ced61d048b5669370689323a77c45dbe113ac Mon Sep 17 00:00:00 2001 From: Gabriel Grubba Date: Thu, 5 Jan 2023 14:10:40 -0300 Subject: [PATCH 26/28] Revert "tests: reverted changes" This reverts commit 8c6f5bbb8eceee357ed2e180324b61655fc62400. --- .../accounts-base/accounts_client_tests.js | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/packages/accounts-base/accounts_client_tests.js b/packages/accounts-base/accounts_client_tests.js index 880a71e4fe..f7652f8ed6 100644 --- a/packages/accounts-base/accounts_client_tests.js +++ b/packages/accounts-base/accounts_client_tests.js @@ -146,6 +146,42 @@ Tinytest.addAsync( } ); +Tinytest.addAsync( + 'accounts async - make async call onLogin', + (test, done) => { + const onLogin = Accounts.onLogin( async () => { + const sleep = + (ms) => new Promise(resolve => setTimeout(() => resolve(true), ms)); + const async = await sleep(10) + test.isTrue(async); + onLogin.stop() + removeTestUser(done); + }); + logoutAndCreateUser(test, done, () => {}); + } +); + +Tinytest.addAsync( + 'accounts async - make async call onLoginFailure', + (test, done) => { + logoutAndCreateUser(test, done, () => { + const onLoginFailure = Accounts.onLoginFailure( async () => { + const sleep = + (ms) => new Promise(resolve => setTimeout(() => resolve(true), ms)); + const async = await sleep(10) + test.isTrue(async); + onLoginFailure.stop() + removeTestUser(done); + }); + + Meteor.loginWithPassword(username, "somewrongstring", () => { + test.isFalse(Meteor.loggingIn()); + removeTestUser(done); + }); + + }); + } +); Tinytest.addAsync( 'accounts - onLogin callback receives { type: "resume" } param on ' + 'reconnect, if already logged in', From df982206dc79788d61489aa85ca565c1abbaee09 Mon Sep 17 00:00:00 2001 From: Gabriel Grubba Date: Thu, 5 Jan 2023 14:10:45 -0300 Subject: [PATCH 27/28] Revert "tests: created test for onLoginFailture" This reverts commit 05b39ad7e9e02c1ad349a0af3276967581113f45. --- .../accounts-base/accounts_client_tests.js | 21 ------------------- 1 file changed, 21 deletions(-) diff --git a/packages/accounts-base/accounts_client_tests.js b/packages/accounts-base/accounts_client_tests.js index f7652f8ed6..d92d1ef818 100644 --- a/packages/accounts-base/accounts_client_tests.js +++ b/packages/accounts-base/accounts_client_tests.js @@ -161,27 +161,6 @@ Tinytest.addAsync( } ); -Tinytest.addAsync( - 'accounts async - make async call onLoginFailure', - (test, done) => { - logoutAndCreateUser(test, done, () => { - const onLoginFailure = Accounts.onLoginFailure( async () => { - const sleep = - (ms) => new Promise(resolve => setTimeout(() => resolve(true), ms)); - const async = await sleep(10) - test.isTrue(async); - onLoginFailure.stop() - removeTestUser(done); - }); - - Meteor.loginWithPassword(username, "somewrongstring", () => { - test.isFalse(Meteor.loggingIn()); - removeTestUser(done); - }); - - }); - } -); Tinytest.addAsync( 'accounts - onLogin callback receives { type: "resume" } param on ' + 'reconnect, if already logged in', From 82baf4a39050813157a730c226054f08fe5d3bcc Mon Sep 17 00:00:00 2001 From: Gabriel Grubba Date: Thu, 5 Jan 2023 14:10:48 -0300 Subject: [PATCH 28/28] Revert "tests: added tests for on login" This reverts commit 88b61119b01043d3d5d80aeb4fc618a95f64160e. --- packages/accounts-base/accounts_client_tests.js | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/packages/accounts-base/accounts_client_tests.js b/packages/accounts-base/accounts_client_tests.js index d92d1ef818..880a71e4fe 100644 --- a/packages/accounts-base/accounts_client_tests.js +++ b/packages/accounts-base/accounts_client_tests.js @@ -146,21 +146,6 @@ Tinytest.addAsync( } ); -Tinytest.addAsync( - 'accounts async - make async call onLogin', - (test, done) => { - const onLogin = Accounts.onLogin( async () => { - const sleep = - (ms) => new Promise(resolve => setTimeout(() => resolve(true), ms)); - const async = await sleep(10) - test.isTrue(async); - onLogin.stop() - removeTestUser(done); - }); - logoutAndCreateUser(test, done, () => {}); - } -); - Tinytest.addAsync( 'accounts - onLogin callback receives { type: "resume" } param on ' + 'reconnect, if already logged in',