@balena/compose-parser 0.0.10 → 0.0.11
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 -5
- package/scripts/fetch-binary.js +48 -35
package/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@balena/compose-parser",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.11",
|
|
4
4
|
"description": "Wraps compose-go to parse balena-compatible docker-compose.yml files",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"clean": "rimraf dist",
|
|
7
|
-
"lint": "balena-lint lib/ test/ && tsc --noEmit",
|
|
8
|
-
"lint-fix": "balena-lint --fix lib/ test/",
|
|
7
|
+
"lint": "balena-lint lib/ test/ scripts/*.js && tsc --noEmit",
|
|
8
|
+
"lint-fix": "balena-lint --fix lib/ test/ scripts/*.js",
|
|
9
9
|
"build": "npm run clean && tsc --project tsconfig.release.json",
|
|
10
10
|
"build:go": "echo 'Building Go binary from source...' && CGO_ENABLED=0 go build -C lib -ldflags='-s -w' -o \"../bin/balena-compose-parser$(go env GOEXE)\"",
|
|
11
11
|
"test": "npm run lint && npm run test:unit",
|
|
12
12
|
"test:unit": "ts-mocha 'test/**/*unit.spec.ts'",
|
|
13
13
|
"test:integration": "ts-mocha 'test/**/*.spec.ts'",
|
|
14
|
-
"test:compose": "(docker compose -f docker-compose.test.yml run --build --rm sut || docker compose logs); npm run compose:down",
|
|
14
|
+
"test:compose": "(docker compose -f docker-compose.test.yml run --build --rm sut || docker compose -f docker-compose.test.yml logs); npm run compose:down",
|
|
15
15
|
"compose:down": "docker compose -f docker-compose.test.yml down --volumes",
|
|
16
16
|
"prepack": "npm run build",
|
|
17
17
|
"postinstall": "node scripts/fetch-binary.js || npm run build:go"
|
|
@@ -65,6 +65,6 @@
|
|
|
65
65
|
"typed-error": "^3.2.2"
|
|
66
66
|
},
|
|
67
67
|
"versionist": {
|
|
68
|
-
"publishedAt": "2025-09-
|
|
68
|
+
"publishedAt": "2025-09-18T20:00:16.569Z"
|
|
69
69
|
}
|
|
70
70
|
}
|
package/scripts/fetch-binary.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-require-imports */
|
|
3
2
|
const https = require('https');
|
|
4
3
|
const { promises: fs } = require('fs');
|
|
5
4
|
const path = require('path');
|
|
@@ -8,14 +7,16 @@ const { promisify } = require('util');
|
|
|
8
7
|
const zlib = require('zlib');
|
|
9
8
|
const tar = require('tar');
|
|
10
9
|
const packageJson = require('../package.json');
|
|
10
|
+
/* eslint-enable @typescript-eslint/no-require-imports */
|
|
11
11
|
|
|
12
12
|
const streamPipeline = promisify(pipeline);
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
async function exists(p) {
|
|
15
|
+
return await fs
|
|
16
|
+
.access(p, fs.constants.F_OK)
|
|
17
|
+
.then(() => true)
|
|
18
|
+
.catch(() => false);
|
|
19
|
+
}
|
|
19
20
|
|
|
20
21
|
function getPlatform() {
|
|
21
22
|
const platform = process.platform;
|
|
@@ -57,29 +58,35 @@ function getBinaryUrl() {
|
|
|
57
58
|
.replace('{platform}', platform)
|
|
58
59
|
.replace('{arch}', arch);
|
|
59
60
|
|
|
60
|
-
const url = config.remotePath
|
|
61
|
-
.replace('{version}', version) + packageName;
|
|
61
|
+
const url = config.remotePath.replace('{version}', version) + packageName;
|
|
62
62
|
|
|
63
63
|
return url;
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
function downloadFile(url) {
|
|
66
|
+
function downloadFile(url, logHost = true) {
|
|
67
67
|
return new Promise((resolve, reject) => {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
// Follow redirect
|
|
73
|
-
return downloadFile(response.headers.location).then(resolve).catch(reject);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
if (response.statusCode !== 200) {
|
|
77
|
-
reject(new Error(`Failed to download: HTTP ${response.statusCode}`));
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
68
|
+
// Truncate url to host only
|
|
69
|
+
if (logHost) {
|
|
70
|
+
console.log(`Downloading binary from: ${url.split('?')[0]}`);
|
|
71
|
+
}
|
|
80
72
|
|
|
81
|
-
|
|
82
|
-
|
|
73
|
+
https
|
|
74
|
+
.get(url, (response) => {
|
|
75
|
+
if (response.statusCode === 302 || response.statusCode === 301) {
|
|
76
|
+
// Follow redirect
|
|
77
|
+
return downloadFile(response.headers.location, false)
|
|
78
|
+
.then(resolve)
|
|
79
|
+
.catch(reject);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (response.statusCode !== 200) {
|
|
83
|
+
reject(new Error(`Failed to download: HTTP ${response.statusCode}`));
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
resolve(response);
|
|
88
|
+
})
|
|
89
|
+
.on('error', reject);
|
|
83
90
|
});
|
|
84
91
|
}
|
|
85
92
|
|
|
@@ -89,8 +96,8 @@ async function extractTarGz(stream, targetDir) {
|
|
|
89
96
|
zlib.createGunzip(),
|
|
90
97
|
tar.extract({
|
|
91
98
|
cwd: targetDir,
|
|
92
|
-
strip: 0
|
|
93
|
-
})
|
|
99
|
+
strip: 0,
|
|
100
|
+
}),
|
|
94
101
|
);
|
|
95
102
|
}
|
|
96
103
|
|
|
@@ -101,14 +108,8 @@ async function fetchBinary() {
|
|
|
101
108
|
const binaryName = `${config.moduleName}${process.platform === 'win32' ? '.exe' : ''}`;
|
|
102
109
|
const binaryPath = path.join(binDir, binaryName);
|
|
103
110
|
|
|
104
|
-
// Check if binary already exists
|
|
105
|
-
if (await fs.exists(binaryPath)) {
|
|
106
|
-
console.log(`Binary already exists at ${binaryPath}`);
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
111
|
// Create bin directory if it doesn't exist
|
|
111
|
-
if (!(await
|
|
112
|
+
if (!(await exists(binDir))) {
|
|
112
113
|
await fs.mkdir(binDir, { recursive: true });
|
|
113
114
|
}
|
|
114
115
|
|
|
@@ -126,9 +127,21 @@ async function fetchBinary() {
|
|
|
126
127
|
}
|
|
127
128
|
|
|
128
129
|
console.log(`Binary successfully installed at ${binaryPath}`);
|
|
129
|
-
process.exit(0);
|
|
130
130
|
} catch (error) {
|
|
131
131
|
console.error(`Failed to fetch binary: ${error.message}`);
|
|
132
|
-
process.exit(1);
|
|
133
132
|
}
|
|
134
133
|
}
|
|
134
|
+
|
|
135
|
+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
136
|
+
(async () => {
|
|
137
|
+
if (process.env.BUILD_FROM_SOURCE === 'true') {
|
|
138
|
+
console.log('Building Go binary from source');
|
|
139
|
+
process.exit(1);
|
|
140
|
+
}
|
|
141
|
+
try {
|
|
142
|
+
await fetchBinary();
|
|
143
|
+
process.exit(0);
|
|
144
|
+
} catch {
|
|
145
|
+
process.exit(1);
|
|
146
|
+
}
|
|
147
|
+
})();
|