diffx-js 0.5.2 → 0.5.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/README.md +12 -1
- package/bin/darwin-arm64/diffx +0 -0
- package/bin/darwin-x64/diffx +0 -0
- package/bin/linux-x64/diffx +0 -0
- package/bin/win32-x64/diffx.exe +0 -0
- package/index.js +25 -9
- package/package.json +13 -8
- package/test.js +32 -6
- package/scripts/download-binary.js +0 -123
package/README.md
CHANGED
|
@@ -8,7 +8,18 @@ A Node.js wrapper for the `diffx` CLI tool.
|
|
|
8
8
|
npm install diffx-js
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
This
|
|
11
|
+
This package includes pre-compiled `diffx` binaries for all supported platforms (Linux x64, macOS x64/ARM64, Windows x64), enabling **completely offline installation** with no external downloads required.
|
|
12
|
+
|
|
13
|
+
### Supported Platforms
|
|
14
|
+
|
|
15
|
+
- **Linux x64** - Intel/AMD 64-bit
|
|
16
|
+
- **macOS x64** - Intel-based Macs
|
|
17
|
+
- **macOS ARM64** - Apple Silicon Macs (M1/M2/M3)
|
|
18
|
+
- **Windows x64** - 64-bit Windows
|
|
19
|
+
|
|
20
|
+
The appropriate binary is automatically selected at runtime based on your system.
|
|
21
|
+
|
|
22
|
+
**Note:** Due to bundling all platform binaries, this package is larger (~20MB) than typical npm packages but provides complete offline functionality.
|
|
12
23
|
|
|
13
24
|
## Usage
|
|
14
25
|
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/index.js
CHANGED
|
@@ -4,21 +4,37 @@ const { spawn } = require('child_process');
|
|
|
4
4
|
const path = require('path');
|
|
5
5
|
const fs = require('fs');
|
|
6
6
|
|
|
7
|
-
// Determine the platform-specific binary name
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
// Determine the platform-specific binary name and directory
|
|
8
|
+
function getPlatformInfo() {
|
|
9
|
+
const platform = process.platform;
|
|
10
|
+
const arch = process.arch;
|
|
11
|
+
|
|
12
|
+
if (platform === 'win32') {
|
|
13
|
+
return { subdir: 'win32-x64', binaryName: 'diffx.exe' };
|
|
14
|
+
} else if (platform === 'darwin') {
|
|
15
|
+
if (arch === 'arm64') {
|
|
16
|
+
return { subdir: 'darwin-arm64', binaryName: 'diffx' };
|
|
17
|
+
} else {
|
|
18
|
+
return { subdir: 'darwin-x64', binaryName: 'diffx' };
|
|
19
|
+
}
|
|
20
|
+
} else if (platform === 'linux') {
|
|
21
|
+
return { subdir: 'linux-x64', binaryName: 'diffx' };
|
|
22
|
+
} else {
|
|
23
|
+
throw new Error(`Unsupported platform: ${platform}-${arch}`);
|
|
24
|
+
}
|
|
11
25
|
}
|
|
12
26
|
|
|
13
|
-
//
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const binaryPath = path.join(__dirname, 'bin', binaryName);
|
|
27
|
+
// Get platform-specific binary path
|
|
28
|
+
const platformInfo = getPlatformInfo();
|
|
29
|
+
const binaryPath = path.join(__dirname, 'bin', platformInfo.subdir, platformInfo.binaryName);
|
|
17
30
|
|
|
18
31
|
// Check if the binary exists
|
|
19
32
|
if (!fs.existsSync(binaryPath)) {
|
|
20
33
|
console.error(`Error: Binary not found at ${binaryPath}`);
|
|
21
|
-
console.error(
|
|
34
|
+
console.error(`Platform: ${process.platform}-${process.arch}`);
|
|
35
|
+
console.error('Expected platform-specific binary not found.');
|
|
36
|
+
console.error('This might indicate a packaging issue. Please report this at:');
|
|
37
|
+
console.error('https://github.com/kako-jun/diffx/issues');
|
|
22
38
|
process.exit(1);
|
|
23
39
|
}
|
|
24
40
|
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "diffx-js",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.4",
|
|
4
4
|
"description": "A Node.js wrapper for the diffx CLI tool - semantic diffing of JSON, YAML, TOML, XML, INI, and CSV files. Focuses on structural meaning rather than formatting.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"diff",
|
|
7
|
-
"json",
|
|
7
|
+
"json",
|
|
8
8
|
"yaml",
|
|
9
9
|
"toml",
|
|
10
10
|
"xml",
|
|
@@ -22,10 +22,9 @@
|
|
|
22
22
|
],
|
|
23
23
|
"main": "lib.js",
|
|
24
24
|
"bin": {
|
|
25
|
-
"diffx": "
|
|
25
|
+
"diffx": "index.js"
|
|
26
26
|
},
|
|
27
27
|
"scripts": {
|
|
28
|
-
"postinstall": "node scripts/download-binary.js",
|
|
29
28
|
"test": "node test.js",
|
|
30
29
|
"examples": "node examples.js",
|
|
31
30
|
"verify": "node index.js --help",
|
|
@@ -37,20 +36,26 @@
|
|
|
37
36
|
"files": [
|
|
38
37
|
"index.js",
|
|
39
38
|
"lib.js",
|
|
40
|
-
"scripts/download-binary.js",
|
|
41
39
|
"bin/",
|
|
42
40
|
"README.md",
|
|
43
41
|
"examples.js",
|
|
44
42
|
"test.js"
|
|
45
43
|
],
|
|
46
|
-
"os": [
|
|
47
|
-
|
|
44
|
+
"os": [
|
|
45
|
+
"linux",
|
|
46
|
+
"darwin",
|
|
47
|
+
"win32"
|
|
48
|
+
],
|
|
49
|
+
"cpu": [
|
|
50
|
+
"x64",
|
|
51
|
+
"arm64"
|
|
52
|
+
],
|
|
48
53
|
"author": "kako-jun",
|
|
49
54
|
"license": "MIT",
|
|
50
55
|
"homepage": "https://github.com/kako-jun/diffx",
|
|
51
56
|
"repository": {
|
|
52
57
|
"type": "git",
|
|
53
|
-
"url": "https://github.com/kako-jun/diffx.git",
|
|
58
|
+
"url": "git+https://github.com/kako-jun/diffx.git",
|
|
54
59
|
"directory": "diffx-npm"
|
|
55
60
|
},
|
|
56
61
|
"bugs": {
|
package/test.js
CHANGED
|
@@ -118,12 +118,12 @@ async function runTests() {
|
|
|
118
118
|
'test2.json'
|
|
119
119
|
]);
|
|
120
120
|
|
|
121
|
-
if (diffResult.code ===
|
|
121
|
+
if (diffResult.code === 1 &&
|
|
122
122
|
diffResult.stdout.includes('version') &&
|
|
123
123
|
diffResult.stdout.includes('debug')) {
|
|
124
124
|
success('Basic JSON diff works correctly');
|
|
125
125
|
} else {
|
|
126
|
-
error(`JSON diff failed: ${diffResult.stderr}`);
|
|
126
|
+
error(`JSON diff failed. Code: ${diffResult.code}, Stdout: ${diffResult.stdout}, Stderr: ${diffResult.stderr}`);
|
|
127
127
|
throw new Error('JSON diff failed');
|
|
128
128
|
}
|
|
129
129
|
|
|
@@ -137,7 +137,7 @@ async function runTests() {
|
|
|
137
137
|
'json'
|
|
138
138
|
]);
|
|
139
139
|
|
|
140
|
-
if (jsonOutputResult.code ===
|
|
140
|
+
if (jsonOutputResult.code === 1) {
|
|
141
141
|
try {
|
|
142
142
|
const output = JSON.parse(jsonOutputResult.stdout);
|
|
143
143
|
if (Array.isArray(output) && output.length > 0) {
|
|
@@ -166,7 +166,7 @@ async function runTests() {
|
|
|
166
166
|
'test2.yaml'
|
|
167
167
|
]);
|
|
168
168
|
|
|
169
|
-
if (yamlResult.code ===
|
|
169
|
+
if (yamlResult.code === 1 && yamlResult.stdout.includes('version')) {
|
|
170
170
|
success('YAML diff works correctly');
|
|
171
171
|
} else {
|
|
172
172
|
error(`YAML diff failed: ${yamlResult.stderr}`);
|
|
@@ -220,8 +220,34 @@ async function runTests() {
|
|
|
220
220
|
throw new Error('Error handling failed');
|
|
221
221
|
}
|
|
222
222
|
|
|
223
|
-
// Test 8:
|
|
224
|
-
info('Test 8: Testing
|
|
223
|
+
// Test 8: Platform-specific binary verification
|
|
224
|
+
info('Test 8: Testing platform-specific binary verification...');
|
|
225
|
+
|
|
226
|
+
const platform = process.platform;
|
|
227
|
+
const arch = process.arch;
|
|
228
|
+
let expectedBinaryPath;
|
|
229
|
+
|
|
230
|
+
if (platform === 'win32') {
|
|
231
|
+
expectedBinaryPath = path.join(__dirname, 'bin', 'win32-x64', 'diffx.exe');
|
|
232
|
+
} else if (platform === 'darwin') {
|
|
233
|
+
if (arch === 'arm64') {
|
|
234
|
+
expectedBinaryPath = path.join(__dirname, 'bin', 'darwin-arm64', 'diffx');
|
|
235
|
+
} else {
|
|
236
|
+
expectedBinaryPath = path.join(__dirname, 'bin', 'darwin-x64', 'diffx');
|
|
237
|
+
}
|
|
238
|
+
} else if (platform === 'linux') {
|
|
239
|
+
expectedBinaryPath = path.join(__dirname, 'bin', 'linux-x64', 'diffx');
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
if (fs.existsSync(expectedBinaryPath)) {
|
|
243
|
+
success(`Platform-specific binary found: ${expectedBinaryPath}`);
|
|
244
|
+
} else {
|
|
245
|
+
error(`Platform-specific binary not found: ${expectedBinaryPath}`);
|
|
246
|
+
throw new Error('Platform binary missing');
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
// Test 9: API functionality with new options
|
|
250
|
+
info('Test 9: Testing API functionality with new options...');
|
|
225
251
|
|
|
226
252
|
// Test ignore case option
|
|
227
253
|
try {
|
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
const fs = require('fs');
|
|
4
|
-
const path = require('path');
|
|
5
|
-
const https = require('https');
|
|
6
|
-
const { execSync } = require('child_process');
|
|
7
|
-
|
|
8
|
-
const DIFFX_VERSION = require('../package.json').version;
|
|
9
|
-
const BINARY_DIR = path.join(__dirname, '..', 'bin');
|
|
10
|
-
|
|
11
|
-
function getPlatform() {
|
|
12
|
-
const platform = process.platform;
|
|
13
|
-
const arch = process.arch;
|
|
14
|
-
|
|
15
|
-
if (platform === 'win32') {
|
|
16
|
-
return 'diffx-windows-x86_64.zip';
|
|
17
|
-
} else if (platform === 'darwin') {
|
|
18
|
-
if (arch === 'arm64') {
|
|
19
|
-
return 'diffx-macos-aarch64.tar.gz';
|
|
20
|
-
} else {
|
|
21
|
-
return 'diffx-macos-x86_64.tar.gz';
|
|
22
|
-
}
|
|
23
|
-
} else if (platform === 'linux') {
|
|
24
|
-
return 'diffx-linux-x86_64.tar.gz';
|
|
25
|
-
} else {
|
|
26
|
-
throw new Error(`Unsupported platform: ${platform}-${arch}`);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function downloadFile(url, dest) {
|
|
31
|
-
return new Promise((resolve, reject) => {
|
|
32
|
-
console.log(`Downloading diffx binary from ${url}...`);
|
|
33
|
-
const file = fs.createWriteStream(dest);
|
|
34
|
-
|
|
35
|
-
https.get(url, (response) => {
|
|
36
|
-
if (response.statusCode === 302 || response.statusCode === 301) {
|
|
37
|
-
// Follow redirect
|
|
38
|
-
downloadFile(response.headers.location, dest).then(resolve).catch(reject);
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
if (response.statusCode !== 200) {
|
|
43
|
-
reject(new Error(`HTTP ${response.statusCode}: ${response.statusMessage}`));
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
response.pipe(file);
|
|
48
|
-
|
|
49
|
-
file.on('finish', () => {
|
|
50
|
-
file.close();
|
|
51
|
-
resolve();
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
file.on('error', (err) => {
|
|
55
|
-
fs.unlink(dest, () => {}); // Delete the file async
|
|
56
|
-
reject(err);
|
|
57
|
-
});
|
|
58
|
-
}).on('error', (err) => {
|
|
59
|
-
reject(err);
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
async function extractArchive(archivePath, extractDir) {
|
|
65
|
-
if (archivePath.endsWith('.zip')) {
|
|
66
|
-
// Use unzip for Windows
|
|
67
|
-
if (process.platform === 'win32') {
|
|
68
|
-
execSync(`powershell -command "Expand-Archive -Path '${archivePath}' -DestinationPath '${extractDir}' -Force"`, { stdio: 'inherit' });
|
|
69
|
-
} else {
|
|
70
|
-
execSync(`unzip -o "${archivePath}" -d "${extractDir}"`, { stdio: 'inherit' });
|
|
71
|
-
}
|
|
72
|
-
} else if (archivePath.endsWith('.tar.gz')) {
|
|
73
|
-
execSync(`tar -xzf "${archivePath}" -C "${extractDir}"`, { stdio: 'inherit' });
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
async function main() {
|
|
78
|
-
try {
|
|
79
|
-
// Skip download if binary already exists
|
|
80
|
-
const binaryName = process.platform === 'win32' ? 'diffx.exe' : 'diffx';
|
|
81
|
-
const binaryPath = path.join(BINARY_DIR, binaryName);
|
|
82
|
-
|
|
83
|
-
if (fs.existsSync(binaryPath)) {
|
|
84
|
-
console.log('diffx binary already exists, skipping download.');
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
const platformFile = getPlatform();
|
|
89
|
-
const downloadUrl = `https://github.com/kako-jun/diffx/releases/download/v${DIFFX_VERSION}/${platformFile}`;
|
|
90
|
-
|
|
91
|
-
// Create bin directory
|
|
92
|
-
if (!fs.existsSync(BINARY_DIR)) {
|
|
93
|
-
fs.mkdirSync(BINARY_DIR, { recursive: true });
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// Download archive
|
|
97
|
-
const archivePath = path.join(BINARY_DIR, platformFile);
|
|
98
|
-
await downloadFile(downloadUrl, archivePath);
|
|
99
|
-
|
|
100
|
-
console.log('Extracting binary...');
|
|
101
|
-
await extractArchive(archivePath, BINARY_DIR);
|
|
102
|
-
|
|
103
|
-
// Clean up archive
|
|
104
|
-
fs.unlinkSync(archivePath);
|
|
105
|
-
|
|
106
|
-
// Make binary executable on Unix systems
|
|
107
|
-
if (process.platform !== 'win32') {
|
|
108
|
-
fs.chmodSync(binaryPath, '755');
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
console.log(`SUCCESS: diffx binary installed successfully at ${binaryPath}`);
|
|
112
|
-
|
|
113
|
-
} catch (error) {
|
|
114
|
-
console.error('ERROR: Failed to download diffx binary:', error.message);
|
|
115
|
-
console.error('You may need to install diffx manually from: https://github.com/kako-jun/diffx/releases');
|
|
116
|
-
// Don't fail the installation, just warn
|
|
117
|
-
process.exit(0);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
if (require.main === module) {
|
|
122
|
-
main();
|
|
123
|
-
}
|