Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(build): leave the typings hunk out of the id backport

Yudhi Armyndharis3343b24ae7ac
diff --git a/scripts/patch-wwebjs-201832.js b/scripts/patch-wwebjs-201832.js
index c7499768d..639b661da 100644
--- a/scripts/patch-wwebjs-201832.js
+++ b/scripts/patch-wwebjs-201832.js
@@ -25,6 +25,11 @@
* dropped. Any OTHER reject means the installed shape drifted from the backport's
* expected base; we abort the build loudly rather than ship a silently partial
* patch.
+ *
+ * The PR's one typings hunk (index.d.ts, a method signature joined onto one line) is left out of
+ * wwebjs-201832.patch. It changes no behavior; as the first file `patch` wrote it would be the only
+ * marker of an interrupted run that tests formatting instead of the fix; and a release that merely
+ * reformatted its typings would reject it and fail the install.
*/
'use strict';
@@ -47,10 +52,8 @@ const EXPECTED_REJECTS = new Set(['src/structures/Contact.js.rej']);
// applies the diff in file order and Utils.js is applied LAST, one file after Message.js — which is
// what the skip branch keys on. Omitting a file here means a run that died in that window leaves a
// tree where every assertion passes, so every later run stands down and the missing site latches in
-// permanently. The same holds at the other end: index.d.ts is the FIRST file written, and a run that
-// died right after it reads as a pristine tree, so the diff is applied again and rejects its hunk.
-// One entry per file: `siteLanded` resolves a file's marker with `.find`, so a second entry for the
-// same path would never be read.
+// permanently. One entry per file: `siteLanded` resolves a file's marker with `.find`, so a second
+// entry for the same path would never be read.
const REQUIRED_SITES = [
['src/structures/Base.js', /static _normalizeId\(id\)/],
['src/structures/Message.js', /this\.id = Base\._normalizeId\(data\.id\)/],
@@ -65,8 +68,6 @@ const REQUIRED_SITES = [
['src/util/Injected/Utils.js', /_serialized: msg\.id\.\$1/],
['src/Client.js', /res\.gid\._serialized \|\| res\.gid\.\$1/],
['src/structures/GroupChat.js', /pWid\._serialized \|\| pWid\.\$1/],
- // The typings hunk, the one file the patch writes before any of the above.
- ['index.d.ts', /sendReaction\(messageId: string, reaction: string\): Promise<void>;/],
];
/** Artifacts `patch` can leave behind. `.~N~` are GNU's backup-if-mismatch copies of pre-patch source. */
@@ -86,7 +87,7 @@ function siteLanded(wwjsDir, rel) {
/**
* The REQUIRED_SITES a backport this patcher began did not reach, by relative path. The tree is judged
* ours when at least one site carries the text its marker looks for: with none the backport never
- * started, or upstream fixed the tree its own way. A run killed part-way leaves any prefix of the twelve
+ * started, or upstream fixed the tree its own way. A run killed part-way leaves any prefix of the eleven
* files, so no single file can stand for the rest. A file that cannot be read is not counted, since an
* install that cannot be inspected is not evidence of a broken one.
*/
@@ -148,8 +149,8 @@ function findArtifacts(root, dir = root) {
* has CRLF.
*
* Neither applier accepts CRLF: a unified diff line must start with ' ', '+', '-' or '@', and a bare
- * \r is none of those, so both stop at line 7 of this patch — its first empty context line (`git
- * apply`: "corrupt patch at line 7"; `patch`: "malformed patch at line 7"). Windows checks the file out
+ * \r is none of those, so both stop at line 12 of this patch — its first empty context line (`git
+ * apply`: "corrupt patch at line 12"; `patch`: "malformed patch at line 12"). Windows checks the file out
* that way whenever `core.autocrlf` is on, which is its default, so the git fallback added for Windows
* could never actually run there and took `npm install` down with it (#889).
*
@@ -259,7 +260,7 @@ function applyBackport(wwjsDir = DEFAULT_WWJS, patchFile = DEFAULT_PATCH) {
return { skipped: true, reason: 'installed whatsapp-web.js already normalizes message ids' };
}
- // A run that died before Message.js (the 11th of 12 files) left the earlier files patched and this one
+ // A run that died before Message.js (the 10th of 11 files) left the earlier files patched and this one
// not. Applying the diff again would reject every hunk that already landed, litter the tree with .rej
// files and report version skew for what is an interrupted install.
const landedBefore = missingSites(wwjsDir);
diff --git a/scripts/wwebjs-201832.patch b/scripts/wwebjs-201832.patch
index 1f842c4cf..f02559a53 100644
--- a/scripts/wwebjs-201832.patch
+++ b/scripts/wwebjs-201832.patch
@@ -1,19 +1,3 @@
-diff --git a/index.d.ts b/index.d.ts
-index 8127770492b..b155be8391d 100644
---- a/index.d.ts
-+++ b/index.d.ts
-@@ -212,10 +212,7 @@ declare namespace WAWebJS {
- ): Promise<Message>;
-
- /** Send a reaction to a specific messageId */
-- sendReaction(
-- messageId: string,
-- reaction: string,
-- ): Promise<void>;
-+ sendReaction(messageId: string, reaction: string): Promise<void>;
-
- /** Sends a channel admin invitation to a user, allowing them to become an admin of the channel */
- sendChannelAdminInvite(
diff --git a/src/Client.js b/src/Client.js
index a122a8f336b..62de5395407 100644
--- a/src/Client.js
diff --git a/src/engine/adapters/wwebjs-backport-201832.spec.ts b/src/engine/adapters/wwebjs-backport-201832.spec.ts
index d9c1ae069..d8357e246 100644
--- a/src/engine/adapters/wwebjs-backport-201832.spec.ts
+++ b/src/engine/adapters/wwebjs-backport-201832.spec.ts
@@ -44,7 +44,7 @@ describe('patch-wwebjs-201832 (build-time backport of upstream #201832)', () =>
describe('gitApplyLeftTreeUntouched', () => {
it.each([
['git never executed', { code: 'ENOENT' as const, status: undefined }],
- ['a diff git could not parse', { status: 128, stderr: 'error: corrupt patch at line 7' }],
+ ['a diff git could not parse', { status: 128, stderr: 'error: corrupt patch at line 12' }],
['input git did not recognise', { status: 128, stderr: 'error: unrecognized input' }],
['a non-diff file', { status: 128, stderr: 'error: No valid patches in input (allow with "--allow-empty")' }],
['a bad invocation', { status: 128, stderr: 'usage: git apply [<options>] [<patch>...]' }],
@@ -125,7 +125,7 @@ describe('patch-wwebjs-201832 (build-time backport of upstream #201832)', () =>
const injected = path.join(dir, 'src', 'util', 'Injected', 'Utils.js');
const pristine = fs.readFileSync(injected, 'utf8');
applyBackport(dir);
- // `patch` writes in diff order and Injected/Utils.js is the LAST of the twelve files, one after
+ // `patch` writes in diff order and Injected/Utils.js is the LAST of the eleven files, one after
// Message.js — which is what the stand-down check keys on. A run that died in that window leaves
// exactly this tree: every structure constructor normalizes, so the tree reads as healthy, while the
// browser-side normalizer every inbound message crosses never landed. Asserting only the structure
@@ -135,8 +135,8 @@ describe('patch-wwebjs-201832 (build-time backport of upstream #201832)', () =>
expect(() => applyBackport(dir)).toThrow(/PARTIALLY patched[\s\S]*Injected\/Utils\.js/);
});
- // `patch` writes in diff order and Message.js is the 11th of 12 files, so a run that was killed usually
- // stopped before it. Applying the diff again would reject the ten hunks that landed, leave their .rej
+ // `patch` writes in diff order and Message.js is the 10th of 11 files, so a run that was killed usually
+ // stopped before it. Applying the diff again would reject the nine hunks that landed, leave their .rej
// files in the tree and call an interrupted install version skew.
it('refuses a tree whose run stopped before Message.js, without touching it', () => {
const dir = copyWwjs();
@@ -162,24 +162,24 @@ describe('patch-wwebjs-201832 (build-time backport of upstream #201832)', () =>
expect(litter).toEqual([]);
});
- // index.d.ts is the FIRST file `patch` writes. No structure marker covers it, so a run that died right
- // after it read as a pristine tree: the diff was applied again, its typings hunk rejected and the
- // interrupted install reported as version skew with a .rej left behind.
+ // src/Client.js is the FIRST file `patch` writes, so a run that died right after it leaves every other
+ // file pristine. Its marker is a real one: the tree is refused, instead of the diff being applied again
+ // over the hunks of Client.js, which would reject them and call an interrupted install version skew.
it('refuses a tree whose run stopped right after the first file, without touching it', () => {
const done = copyWwjs();
applyBackport(done);
const dir = copyWwjs();
- const typings = path.join(dir, 'index.d.ts');
- fs.copyFileSync(path.join(done, 'index.d.ts'), typings);
- const before = fs.readFileSync(typings, 'utf8');
+ const clientJs = path.join(dir, 'src', 'Client.js');
+ fs.copyFileSync(path.join(done, 'src', 'Client.js'), clientJs);
+ const before = fs.readFileSync(clientJs, 'utf8');
const baseJs = path.join(dir, 'src', 'structures', 'Base.js');
const base = fs.readFileSync(baseJs, 'utf8');
expect(() => applyBackport(dir)).toThrow(/PARTIALLY patched[\s\S]*Message\.js[\s\S]*reinstall/i);
- expect(fs.readFileSync(typings, 'utf8')).toBe(before);
+ expect(fs.readFileSync(clientJs, 'utf8')).toBe(before);
expect(fs.readFileSync(baseJs, 'utf8')).toBe(base);
- expect(fs.existsSync(`${typings}.rej`)).toBe(false);
+ expect(fs.existsSync(`${clientJs}.rej`)).toBe(false);
});
it('refuses to stand down on a half-patched tree', () => {
@@ -378,7 +378,7 @@ describe('patch-wwebjs-201832 (build-time backport of upstream #201832)', () =>
}
// #889: both appliers reject a patch whose lines end CRLF — a bare \r is not one of the
- // ' '/'+'/'-'/'@' markers a unified diff allows, and line 7 of this patch is an empty context line,
+ // ' '/'+'/'-'/'@' markers a unified diff allows, and line 12 of this patch is an empty context line,
// so both fail exactly there. On Windows core.autocrlf=true checks the file out that way, so the
// git fallback added FOR Windows could never run there and `npm install` died on the attempt.
it('applies even when the patch file was checked out with CRLF line endings', () => {
diff --git a/src/engine/adapters/wwebjs-backport-check.spec.ts b/src/engine/adapters/wwebjs-backport-check.spec.ts
index 38e214a57..8f58591fc 100644
--- a/src/engine/adapters/wwebjs-backport-check.spec.ts
+++ b/src/engine/adapters/wwebjs-backport-check.spec.ts
@@ -96,8 +96,8 @@ describe('isBackportMissing', () => {
expect(backportProblem(dir)).toBe(BACKPORT_MISSING_MESSAGE);
});
- // Message.js is the 11th of 12 files the patcher writes, so a run that was killed usually stopped
- // before it: ten sites landed, Message.js did not, and the tree is not a pristine one.
+ // Message.js is the 10th of 11 files the patcher writes, so a run that was killed usually stopped
+ // before it: nine sites landed, Message.js did not, and the tree is not a pristine one.
it('names a tree whose run stopped before Message.js, not the missing-backport message', () => {
const dir = wholeInstall();
fs.writeFileSync(path.join(dir, 'src', 'structures', 'Message.js'), 'this.id = data.id;');
@@ -108,17 +108,17 @@ describe('isBackportMissing', () => {
expect(backportProblem(dir)).toContain('src/structures/Message.js, src/util/Injected/Utils.js');
});
- // index.d.ts is the first file written, so a run killed right after it leaves every structure file
+ // src/Client.js is the first file written, so a run killed right after it leaves every structure file
// unpatched: the tree is not a pristine one, and the answer is the list, not "run the patcher".
it('names a tree where only the first file the patcher writes landed', () => {
const dir = wholeInstall();
for (const [rel] of REQUIRED_SITES) {
- if (rel !== 'index.d.ts') fs.writeFileSync(path.join(dir, rel), 'this.id = data.id;');
+ if (rel !== 'src/Client.js') fs.writeFileSync(path.join(dir, rel), 'this.id = data.id;');
}
expect(isBackportMissing(dir)).toBe(true);
expect(partialBackportSites(dir)).toHaveLength(REQUIRED_SITES.length - 1);
- expect(partialBackportSites(dir)).not.toContain('index.d.ts');
+ expect(partialBackportSites(dir)).not.toContain('src/Client.js');
expect(backportProblem(dir)).toContain('src/structures/Message.js');
expect(backportProblem(dir)).not.toBe(BACKPORT_MISSING_MESSAGE);
});