@lynovratech/baileys 1.0.3 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +5 -3
- package/scripts/fix-cjs.cjs +19 -0
- package/scripts/fix-cjs.js +19 -0
- package/scripts/patch-rust-bridge.cjs +20 -0
- package/scripts/update-version.ts +149 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lynovratech/baileys",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.4",
|
|
5
5
|
"description": "A WebSockets library for interacting with WhatsApp Web - lynovra fork with JID-first and dual ESM/CJS support",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"whatsapp",
|
|
@@ -33,7 +33,8 @@
|
|
|
33
33
|
"lib/**/*",
|
|
34
34
|
"WAProto/**/*",
|
|
35
35
|
"engine-requirements.js",
|
|
36
|
-
"lib/WAProto/**/*"
|
|
36
|
+
"lib/WAProto/**/*",
|
|
37
|
+
"scripts/**/*"
|
|
37
38
|
],
|
|
38
39
|
"scripts": {
|
|
39
40
|
"build:all": "npm run build && npm run build:docs",
|
|
@@ -55,7 +56,8 @@
|
|
|
55
56
|
"release": "release-it",
|
|
56
57
|
"test": "node --experimental-vm-modules ./node_modules/.bin/jest --testMatch '**/*.test.ts'",
|
|
57
58
|
"test:e2e": "node --experimental-vm-modules ./node_modules/.bin/jest --testMatch '**/*.test-e2e.ts'",
|
|
58
|
-
"update:version": "tsx ./scripts/update-version.ts"
|
|
59
|
+
"update:version": "tsx ./scripts/update-version.ts",
|
|
60
|
+
"postinstall": "node scripts/patch-rust-bridge.cjs"
|
|
59
61
|
},
|
|
60
62
|
"dependencies": {
|
|
61
63
|
"@cacheable/node-cache": "^1.4.0",
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Adds package.json to lib/cjs so Node knows it's CJS
|
|
3
|
+
const fs = require('fs')
|
|
4
|
+
const path = require('path')
|
|
5
|
+
|
|
6
|
+
const cjsDir = path.join(__dirname, '..', 'lib', 'cjs')
|
|
7
|
+
fs.writeFileSync(
|
|
8
|
+
path.join(cjsDir, 'package.json'),
|
|
9
|
+
JSON.stringify({ type: 'commonjs' }, null, 2)
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
// Add package.json to lib/esm so Node knows it's ESM
|
|
13
|
+
const esmDir = path.join(__dirname, '..', 'lib', 'esm')
|
|
14
|
+
fs.writeFileSync(
|
|
15
|
+
path.join(esmDir, 'package.json'),
|
|
16
|
+
JSON.stringify({ type: 'module' }, null, 2)
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
console.log('✅ CJS/ESM package.json markers written')
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Adds package.json to lib/cjs so Node knows it's CJS
|
|
3
|
+
const fs = require('fs')
|
|
4
|
+
const path = require('path')
|
|
5
|
+
|
|
6
|
+
const cjsDir = path.join(__dirname, '..', 'lib', 'cjs')
|
|
7
|
+
fs.writeFileSync(
|
|
8
|
+
path.join(cjsDir, 'package.json'),
|
|
9
|
+
JSON.stringify({ type: 'commonjs' }, null, 2)
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
// Add package.json to lib/esm so Node knows it's ESM
|
|
13
|
+
const esmDir = path.join(__dirname, '..', 'lib', 'esm')
|
|
14
|
+
fs.writeFileSync(
|
|
15
|
+
path.join(esmDir, 'package.json'),
|
|
16
|
+
JSON.stringify({ type: 'module' }, null, 2)
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
console.log('✅ CJS/ESM package.json markers written')
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
|
|
4
|
+
const pkgPath = path.resolve(__dirname, '../node_modules/whatsapp-rust-bridge/package.json');
|
|
5
|
+
|
|
6
|
+
if(!fs.existsSync(pkgPath)) {
|
|
7
|
+
console.log('whatsapp-rust-bridge not found, skipping patch');
|
|
8
|
+
process.exit(0);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
|
|
12
|
+
|
|
13
|
+
if(!pkg.exports['.'].require) {
|
|
14
|
+
pkg.exports['.'].require = './dist/index.js';
|
|
15
|
+
pkg.main = './dist/index.js';
|
|
16
|
+
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2));
|
|
17
|
+
console.log('patched whatsapp-rust-bridge for CJS support');
|
|
18
|
+
} else {
|
|
19
|
+
console.log('whatsapp-rust-bridge already patched');
|
|
20
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Script to update WhatsApp Web version across the codebase.
|
|
4
|
+
* Fetches the latest version from web.whatsapp.com and updates:
|
|
5
|
+
* - src/Defaults/baileys-version.json
|
|
6
|
+
* - src/Defaults/index.ts
|
|
7
|
+
* - src/Utils/generics.ts
|
|
8
|
+
*
|
|
9
|
+
* Usage: yarn update:version
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { readFileSync, writeFileSync } from 'fs'
|
|
13
|
+
import { dirname, join } from 'path'
|
|
14
|
+
import { fileURLToPath } from 'url'
|
|
15
|
+
import { fetchLatestWaWebVersion } from '../src/Utils/generics.ts'
|
|
16
|
+
|
|
17
|
+
const __filename = fileURLToPath(import.meta.url)
|
|
18
|
+
const __dirname = dirname(__filename)
|
|
19
|
+
const ROOT_DIR = join(__dirname, '..')
|
|
20
|
+
|
|
21
|
+
function updateBaileysVersionJson(version: [number, number, number]): boolean {
|
|
22
|
+
const filePath = join(ROOT_DIR, 'src/Defaults/baileys-version.json')
|
|
23
|
+
const content = {
|
|
24
|
+
version
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
try {
|
|
28
|
+
const currentContent = readFileSync(filePath, 'utf-8')
|
|
29
|
+
const currentVersion = JSON.parse(currentContent).version as number[]
|
|
30
|
+
|
|
31
|
+
if (currentVersion[0] === version[0] && currentVersion[1] === version[1] && currentVersion[2] === version[2]) {
|
|
32
|
+
console.log(`✓ baileys-version.json already up to date`)
|
|
33
|
+
return false
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
writeFileSync(filePath, JSON.stringify(content) + '\n')
|
|
37
|
+
console.log(`✓ Updated baileys-version.json: [${currentVersion.join(', ')}] → [${version.join(', ')}]`)
|
|
38
|
+
return true
|
|
39
|
+
} catch (error) {
|
|
40
|
+
console.error(`✗ Failed to update baileys-version.json:`, error)
|
|
41
|
+
throw error
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function updateGenerics(version: [number, number, number]): boolean {
|
|
46
|
+
const filePath = join(ROOT_DIR, 'src/Utils/generics.ts')
|
|
47
|
+
|
|
48
|
+
try {
|
|
49
|
+
const content = readFileSync(filePath, 'utf-8')
|
|
50
|
+
const versionRegex = /const baileysVersion = \[(\d+),\s*(\d+),\s*(\d+)\]/
|
|
51
|
+
const match = content.match(versionRegex)
|
|
52
|
+
|
|
53
|
+
if (!match) {
|
|
54
|
+
throw new Error('Could not find baileysVersion declaration in generics.ts')
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const currentVersion = [+match[1]!, +match[2]!, +match[3]!]
|
|
58
|
+
|
|
59
|
+
if (currentVersion[0] === version[0] && currentVersion[1] === version[1] && currentVersion[2] === version[2]) {
|
|
60
|
+
console.log(`✓ src/Utils/generics.ts already up to date`)
|
|
61
|
+
return false
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const newContent = content.replace(
|
|
65
|
+
versionRegex,
|
|
66
|
+
`const baileysVersion = [${version[0]}, ${version[1]}, ${version[2]}]`
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
writeFileSync(filePath, newContent)
|
|
70
|
+
console.log(`✓ Updated src/Utils/generics.ts: [${currentVersion.join(', ')}] → [${version.join(', ')}]`)
|
|
71
|
+
return true
|
|
72
|
+
} catch (error) {
|
|
73
|
+
console.error(`✗ Failed to update src/Utils/generics.ts:`, error)
|
|
74
|
+
throw error
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function updateIndex(version: [number, number, number]): boolean {
|
|
79
|
+
const filePath = join(ROOT_DIR, 'src/Defaults/index.ts')
|
|
80
|
+
|
|
81
|
+
try {
|
|
82
|
+
const content = readFileSync(filePath, 'utf-8')
|
|
83
|
+
const versionRegex = /const version = \[(\d+),\s*(\d+),\s*(\d+)\]/
|
|
84
|
+
const match = content.match(versionRegex)
|
|
85
|
+
|
|
86
|
+
if (!match) {
|
|
87
|
+
throw new Error('Could not find version declaration in index.ts')
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const currentVersion = [+match[1]!, +match[2]!, +match[3]!]
|
|
91
|
+
|
|
92
|
+
if (currentVersion[0] === version[0] && currentVersion[1] === version[1] && currentVersion[2] === version[2]) {
|
|
93
|
+
console.log(`✓ src/Defaults/index.ts already up to date`)
|
|
94
|
+
return false
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const newContent = content.replace(versionRegex, `const version = [${version[0]}, ${version[1]}, ${version[2]}]`)
|
|
98
|
+
|
|
99
|
+
writeFileSync(filePath, newContent)
|
|
100
|
+
console.log(`✓ Updated src/Defaults/index.ts: [${currentVersion.join(', ')}] → [${version.join(', ')}]`)
|
|
101
|
+
return true
|
|
102
|
+
} catch (error) {
|
|
103
|
+
console.error(`✗ Failed to update src/Defaults/index.ts:`, error)
|
|
104
|
+
throw error
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
async function main() {
|
|
109
|
+
console.log('Fetching latest WhatsApp Web version...\n')
|
|
110
|
+
|
|
111
|
+
const result = await fetchLatestWaWebVersion()
|
|
112
|
+
|
|
113
|
+
if (!result.isLatest) {
|
|
114
|
+
console.error('Failed to fetch latest version:', result.error)
|
|
115
|
+
process.exit(1)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
console.log(`Latest version: [${result.version.join(', ')}]\n`)
|
|
119
|
+
|
|
120
|
+
const updates = [
|
|
121
|
+
updateBaileysVersionJson(result.version),
|
|
122
|
+
updateGenerics(result.version),
|
|
123
|
+
updateIndex(result.version)
|
|
124
|
+
]
|
|
125
|
+
|
|
126
|
+
const hasUpdates = updates.some(Boolean)
|
|
127
|
+
|
|
128
|
+
console.log('')
|
|
129
|
+
if (hasUpdates) {
|
|
130
|
+
console.log('Version update complete!')
|
|
131
|
+
// Set GitHub Actions output if running in CI
|
|
132
|
+
if (process.env.GITHUB_OUTPUT) {
|
|
133
|
+
const { appendFileSync } = await import('fs')
|
|
134
|
+
appendFileSync(process.env.GITHUB_OUTPUT, `updated=true\n`)
|
|
135
|
+
appendFileSync(process.env.GITHUB_OUTPUT, `version=${result.version.join('.')}\n`)
|
|
136
|
+
}
|
|
137
|
+
} else {
|
|
138
|
+
console.log('All files are already up to date.')
|
|
139
|
+
if (process.env.GITHUB_OUTPUT) {
|
|
140
|
+
const { appendFileSync } = await import('fs')
|
|
141
|
+
appendFileSync(process.env.GITHUB_OUTPUT, `updated=false\n`)
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
main().catch(error => {
|
|
147
|
+
console.error('Fatal error:', error)
|
|
148
|
+
process.exit(1)
|
|
149
|
+
})
|