node-nim 10.9.71-beta.87 → 10.9.72

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-nim",
3
- "version": "10.9.71-beta.87",
3
+ "version": "10.9.72",
4
4
  "description": "NetEase IM nodejs wrapper based on NetEase IM C++ SDK",
5
5
  "main": "dist/node-nim.js",
6
6
  "bin": {
@@ -69,6 +69,72 @@ function formatBytes(bytes) {
69
69
  return parseFloat((bytes / Math.pow(k, i)).toFixed(1)) + ' ' + sizes[i]
70
70
  }
71
71
 
72
+ // Compatibility function for removing directories (supports older Node.js versions)
73
+ function removeDirectory(dirPath) {
74
+ if (!fs.existsSync(dirPath)) {
75
+ return
76
+ }
77
+
78
+ // Use rmSync if available (Node.js >= 14.14.0)
79
+ if (fs.rmSync) {
80
+ fs.rmSync(dirPath, { recursive: true, force: true })
81
+ return
82
+ }
83
+
84
+ // Fallback for older Node.js versions using rimraf-like logic
85
+ const rimraf = (path) => {
86
+ const stat = fs.lstatSync(path)
87
+
88
+ if (stat.isDirectory()) {
89
+ // Read directory contents
90
+ const files = fs.readdirSync(path)
91
+
92
+ // Recursively remove all contents
93
+ files.forEach(file => {
94
+ const fullPath = require('path').join(path, file)
95
+ rimraf(fullPath)
96
+ })
97
+
98
+ // Remove the empty directory
99
+ fs.rmdirSync(path)
100
+ } else {
101
+ // Remove file
102
+ // Handle readonly files on Windows
103
+ try {
104
+ fs.unlinkSync(path)
105
+ } catch (err) {
106
+ if (err.code === 'EBUSY' || err.code === 'ENOTEMPTY' || err.code === 'EPERM') {
107
+ // Try to change permissions and retry
108
+ try {
109
+ fs.chmodSync(path, 0o666)
110
+ fs.unlinkSync(path)
111
+ } catch (retryErr) {
112
+ // If still fails, just log and continue
113
+ console.warn(`Warning: Could not remove file ${path}: ${retryErr.message}`)
114
+ }
115
+ } else {
116
+ throw err
117
+ }
118
+ }
119
+ }
120
+ }
121
+
122
+ try {
123
+ rimraf(dirPath)
124
+ } catch (err) {
125
+ // If rmSync and rimraf both fail, try the legacy recursive option
126
+ if (fs.rmdirSync && typeof fs.rmdirSync === 'function') {
127
+ try {
128
+ fs.rmdirSync(dirPath, { recursive: true })
129
+ } catch (legacyErr) {
130
+ console.warn(`Warning: Could not remove directory ${dirPath}: ${legacyErr.message}`)
131
+ }
132
+ } else {
133
+ console.warn(`Warning: Could not remove directory ${dirPath}: ${err.message}`)
134
+ }
135
+ }
136
+ }
137
+
72
138
  // Download and extract function using axios + decompress
73
139
  async function downloadAndExtract(url, destination) {
74
140
  if (!fs.existsSync(destination)) {
@@ -112,11 +178,8 @@ async function downloadAndExtract(url, destination) {
112
178
  !filePath.includes('__MACOSX') &&
113
179
  !filePath.startsWith('._')
114
180
  },
115
- map: (file) => {
116
- // Remove any leading directory if needed
117
- file.path = file.path.replace(/^[^\/]+\//, '')
118
- return file
119
- }
181
+ // Remove the map function to preserve original directory structure
182
+ // This keeps the complete directory hierarchy from the archive
120
183
  })
121
184
  log(` ✅ Extraction complete`)
122
185
  // Clean up the temporary archive file
@@ -146,12 +209,8 @@ async function downloadSDK(customPackageUrl) {
146
209
  }
147
210
  // remove temporary download folder and target folder
148
211
  const target = path.join(__dirname, '..', 'build', 'Release')
149
- if (fs.existsSync(savePath)) {
150
- fs.rmSync(savePath, { recursive: true })
151
- }
152
- if (fs.existsSync(target)) {
153
- fs.rmSync(target, { recursive: true })
154
- }
212
+ removeDirectory(savePath)
213
+ removeDirectory(target)
155
214
  // download sdk
156
215
  try {
157
216
  await downloadAndExtract(downloadUrl, savePath)
@@ -159,15 +218,80 @@ async function downloadSDK(customPackageUrl) {
159
218
  if (!fs.existsSync(target)) {
160
219
  fs.mkdirSync(target, { recursive: true })
161
220
  }
162
- // move sdk/* files to build/Release
163
- const from = path.join(savePath, platform === 'win32' ? 'bin' : 'lib')
164
- const files = fs.readdirSync(from)
221
+ // Debug: List all extracted contents
222
+ log(` 🔍 Extracted contents in ${savePath}:`)
223
+ const extractedItems = fs.readdirSync(savePath)
224
+ extractedItems.forEach(item => {
225
+ const itemPath = path.join(savePath, item)
226
+ const isDir = fs.statSync(itemPath).isDirectory()
227
+ log(` ${isDir ? '📁' : '📄'} ${item}`)
228
+ })
229
+
230
+ // Find the package directory (should be the first directory that contains bin/lib)
231
+ const expectedSubDir = platform === 'win32' ? 'bin' : 'lib'
232
+ let packageDir = null
233
+ let libraryDir = null
234
+
235
+ // Look for the main package directory
236
+ for (const item of extractedItems) {
237
+ const itemPath = path.join(savePath, item)
238
+ if (fs.statSync(itemPath).isDirectory()) {
239
+ const subDirPath = path.join(itemPath, expectedSubDir)
240
+ if (fs.existsSync(subDirPath)) {
241
+ packageDir = itemPath
242
+ libraryDir = subDirPath
243
+ log(` ✅ Found package directory: ${item}`)
244
+ log(` ✅ Found library directory: ${item}/${expectedSubDir}`)
245
+ break
246
+ }
247
+ }
248
+ }
249
+
250
+ // Fallback: look for library files in any subdirectory
251
+ if (!libraryDir) {
252
+ log(` ⚠️ Standard package structure not found, searching for library files...`)
253
+
254
+ const searchForLibraryFiles = (searchPath, relativePath = '') => {
255
+ const items = fs.readdirSync(searchPath)
256
+ for (const item of items) {
257
+ const fullPath = path.join(searchPath, item)
258
+ const stat = fs.statSync(fullPath)
259
+
260
+ if (stat.isDirectory()) {
261
+ // Recursively search subdirectories
262
+ const found = searchForLibraryFiles(fullPath, path.join(relativePath, item))
263
+ if (found) return found
264
+ } else {
265
+ // Check if this directory contains library files
266
+ if (item.endsWith('.node')) {
267
+ return searchPath
268
+ }
269
+ }
270
+ }
271
+ return null
272
+ }
273
+
274
+ libraryDir = searchForLibraryFiles(savePath)
275
+ if (libraryDir) {
276
+ log(` ✅ Found library files in: ${path.relative(savePath, libraryDir)}`)
277
+ }
278
+ }
279
+
280
+ if (!libraryDir) {
281
+ throw new Error(`No library files found in extracted archive. Expected structure: packageDir/${expectedSubDir}/`)
282
+ }
283
+
284
+ // Install files from the found directory
285
+ const files = fs.readdirSync(libraryDir)
165
286
  files.forEach((file) => {
166
- log(` 📁 Installing ${file}`)
167
- fs.renameSync(path.join(from, file), path.join(target, file))
287
+ const filePath = path.join(libraryDir, file)
288
+ if (fs.statSync(filePath).isFile()) {
289
+ log(` 📁 Installing ${file}`)
290
+ fs.renameSync(filePath, path.join(target, file))
291
+ }
168
292
  })
169
293
  // remove temporary download folder
170
- fs.rmSync(savePath, { recursive: true })
294
+ removeDirectory(savePath)
171
295
  log(` ✅ Package installation complete!`)
172
296
  } catch (err) {
173
297
  log(` ❌ ERROR: ${err.message}`)
@@ -181,9 +305,14 @@ function findPackageUrl(publishData, targetVersion, platform, arch, product) {
181
305
  let targetDownloadUrl = ''
182
306
  // Check if package matches current platform/arch
183
307
  const isMatchingPackage = (member) => {
184
- return member.filename.includes(product) &&
185
- member.filename.includes(platform) &&
186
- member.filename.includes(arch)
308
+ const basicMatch = member.filename.includes(product) &&
309
+ member.filename.includes(platform) &&
310
+ member.filename.includes(arch)
311
+ // For win32 platform, also require 'multi-threaded' keyword
312
+ if (platform === 'win32') {
313
+ return basicMatch && member.filename.includes('multi-threaded')
314
+ }
315
+ return basicMatch
187
316
  }
188
317
  // Iterate through all versions
189
318
  Object.keys(publishData).forEach((versionKey) => {
@@ -282,19 +411,14 @@ async function findLatestBuildWithPackage(baseUrl, branch, nodePlatform, nodeArc
282
411
 
283
412
  // Map Node.js platform/arch to SDK directory format
284
413
  function getPlatformArchDir(nodePlatform, nodeArch) {
285
- // darwin-arm64, darwin-x64, win32-ia32, linux-arm64, linux-x64
286
- let platform = nodePlatform
287
- let arch = nodeArch
288
- // Map Node.js arch to package arch format
289
- if (nodePlatform === 'darwin') {
290
- arch = nodeArch === 'arm64' ? 'arm64' : 'x64'
291
- } else if (nodePlatform === 'win32') {
292
- platform = 'win32'
293
- arch = nodeArch === 'ia32' ? 'ia32' : nodeArch === 'x64' ? 'x64' : nodeArch
294
- } else if (nodePlatform === 'linux') {
295
- arch = nodeArch === 'arm64' ? 'arm64' : 'x64'
414
+ // Normalize arch - default to x64 if not arm64
415
+ const arch = nodeArch === 'arm64' ? 'arm64' : (nodeArch === 'ia32' ? 'ia32' : 'x64')
416
+ // For win32, include multi-threaded suffix
417
+ if (nodePlatform === 'win32') {
418
+ return `win32-${arch}-multi-threaded/`
296
419
  }
297
- return `${platform}-${arch}/`
420
+ // For other platforms (darwin, linux)
421
+ return `${nodePlatform}-${arch}/`
298
422
  }
299
423
 
300
424
  // Find package from directory listing