@rosepetal/node-red-contrib-image-tools 1.5.2 → 1.5.3

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.
@@ -298,6 +298,14 @@ jobs:
298
298
  cp -r artifacts/$platform/* npm/$platform/
299
299
  done
300
300
 
301
+ - name: Sync version across all packages (from tag)
302
+ # Stamps the tag version (refs/tags/vX.Y.Z) into the root package.json
303
+ # (version + optionalDependencies pins) and every npm/<arch>/package.json,
304
+ # so releases never need a manual bump. Runs AFTER artifact copy so it is
305
+ # not overwritten. On manual workflow_dispatch (no tag) it re-stamps the
306
+ # version already in the root package.json.
307
+ run: node scripts/sync-version.js
308
+
301
309
  - name: Verify all addons exist
302
310
  run: |
303
311
  for platform in linux-x64 linux-arm64 linuxmusl-x64 darwin-arm64; do
@@ -315,7 +323,13 @@ jobs:
315
323
  for platform in linux-x64 linux-arm64 linuxmusl-x64 darwin-arm64; do
316
324
  echo "Publishing @rosepetal/node-red-contrib-image-tools-$platform..."
317
325
  cd npm/$platform
318
- npm publish --access public || echo "Package may already exist"
326
+ name=$(node -p "require('./package.json').name")
327
+ version=$(node -p "require('./package.json').version")
328
+ if npm view "$name@$version" version >/dev/null 2>&1; then
329
+ echo "$name@$version already published, skipping"
330
+ else
331
+ npm publish --access public
332
+ fi
319
333
  cd ../..
320
334
  done
321
335
 
@@ -326,4 +340,10 @@ jobs:
326
340
  env:
327
341
  NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
328
342
  run: |
329
- npm publish --access public || echo "Package may already exist"
343
+ name=$(node -p "require('./package.json').name")
344
+ version=$(node -p "require('./package.json').version")
345
+ if npm view "$name@$version" version >/dev/null 2>&1; then
346
+ echo "$name@$version already published, skipping"
347
+ else
348
+ npm publish --access public
349
+ fi
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rosepetal/node-red-contrib-image-tools-darwin-arm64",
3
- "version": "1.5.2",
3
+ "version": "1.5.3",
4
4
  "description": "Prebuilt native binary for macOS ARM64 (Apple Silicon)",
5
5
  "os": ["darwin"],
6
6
  "cpu": ["arm64"],
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rosepetal/node-red-contrib-image-tools-darwin-x64",
3
- "version": "1.5.2",
3
+ "version": "1.5.3",
4
4
  "description": "Prebuilt native binary for macOS x64 (Intel)",
5
5
  "os": ["darwin"],
6
6
  "cpu": ["x64"],
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rosepetal/node-red-contrib-image-tools-linux-arm64",
3
- "version": "1.5.2",
3
+ "version": "1.5.3",
4
4
  "description": "Prebuilt native binary for Linux ARM64 (glibc)",
5
5
  "os": ["linux"],
6
6
  "cpu": ["arm64"],
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rosepetal/node-red-contrib-image-tools-linux-x64",
3
- "version": "1.5.2",
3
+ "version": "1.5.3",
4
4
  "description": "Prebuilt native binary for Linux x64 (glibc)",
5
5
  "os": ["linux"],
6
6
  "cpu": ["x64"],
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rosepetal/node-red-contrib-image-tools-linuxmusl-x64",
3
- "version": "1.5.2",
3
+ "version": "1.5.3",
4
4
  "description": "Prebuilt native binary for Linux x64 (musl/Alpine)",
5
5
  "os": ["linux"],
6
6
  "cpu": ["x64"],
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rosepetal/rosepetal-engine-win32-x64",
3
- "version": "1.5.2",
3
+ "version": "1.5.3",
4
4
  "description": "Prebuilt rosepetal-image-engine binary for Windows x64",
5
5
  "os": ["win32"],
6
6
  "cpu": ["x64"],
package/package.json CHANGED
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "name": "@rosepetal/node-red-contrib-image-tools",
3
- "version": "1.5.2",
3
+ "version": "1.5.3",
4
4
  "description": "Node-RED Image Processing Toolkit",
5
5
  "main": "install.sh",
6
6
  "directories": {
7
7
  "doc": "docs"
8
8
  },
9
9
  "scripts": {
10
- "test": "echo \"Error: no test specified\" && exit 1"
10
+ "test": "echo \"Error: no test specified\" && exit 1",
11
+ "sync-version": "node scripts/sync-version.js"
11
12
  },
12
13
  "repository": {
13
14
  "type": "git",
@@ -35,11 +36,11 @@
35
36
  "sharp": "^0.34.2"
36
37
  },
37
38
  "optionalDependencies": {
38
- "@rosepetal/node-red-contrib-image-tools-linux-x64": "1.5.2",
39
- "@rosepetal/node-red-contrib-image-tools-linux-arm64": "1.5.2",
40
- "@rosepetal/node-red-contrib-image-tools-linuxmusl-x64": "1.5.2",
41
- "@rosepetal/node-red-contrib-image-tools-darwin-x64": "1.5.2",
42
- "@rosepetal/node-red-contrib-image-tools-darwin-arm64": "1.5.2"
39
+ "@rosepetal/node-red-contrib-image-tools-linux-x64": "1.5.3",
40
+ "@rosepetal/node-red-contrib-image-tools-linux-arm64": "1.5.3",
41
+ "@rosepetal/node-red-contrib-image-tools-linuxmusl-x64": "1.5.3",
42
+ "@rosepetal/node-red-contrib-image-tools-darwin-x64": "1.5.3",
43
+ "@rosepetal/node-red-contrib-image-tools-darwin-arm64": "1.5.3"
43
44
  },
44
45
  "node-red": {
45
46
  "version": ">=1.0.0",
@@ -107,7 +107,11 @@ inline cv::Mat ConvertToMat(const Napi::Value& input) {
107
107
  if (img.empty()) {
108
108
  throw Napi::Error::New(env, "Failed to decode image buffer.");
109
109
  }
110
- return img; // BGR/BGRA/GRAY according to file format
110
+
111
+ // imdecode returns BGR/BGRA regardless of file format, assume input is RGB/RGBA
112
+ if (img.channels() == 3) cv::cvtColor(img, img, cv::COLOR_BGR2RGB);
113
+ else if (img.channels() == 4) cv::cvtColor(img, img, cv::COLOR_BGRA2RGBA);
114
+ return img; // RGB/RGBA/GRAY, matching the colorSpace labels nodes assign
111
115
  }
112
116
 
113
117
  throw Napi::Error::New(env,
@@ -0,0 +1,109 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Version sync (CI + local use)
4
+ *
5
+ * Stamps a single version across every PUBLISHED package.json so a release
6
+ * only needs ONE source of truth — the git tag. No more hand-editing.
7
+ *
8
+ * Updates:
9
+ * - package.json (root) → "version"
10
+ * - package.json (root) → every "@rosepetal/node-red-contrib-image-tools-*"
11
+ * pin under optionalDependencies (must match exactly,
12
+ * or npm resolves the wrong / missing prebuilt binary)
13
+ * - npm/<arch>/package.json → "version" (all platform packages)
14
+ *
15
+ * Does NOT touch rosepetal-image-engine/package.json (private: true, internal build).
16
+ *
17
+ * Version source (priority order):
18
+ * 1. CLI arg: node scripts/sync-version.js 1.6.0
19
+ * 2. env GITHUB_REF tag: refs/tags/v1.6.0 → 1.6.0 (how CI passes it)
20
+ * 3. fallback: current root "version" (idempotent re-stamp)
21
+ *
22
+ * Edits are surgical (regex on the version string only) so unrelated formatting
23
+ * stays byte-for-byte identical — running it twice with the same version is a no-op.
24
+ *
25
+ * Usage: node scripts/sync-version.js [version] [--dry-run]
26
+ */
27
+
28
+ const fs = require('fs');
29
+ const path = require('path');
30
+
31
+ const ROOT = path.join(__dirname, '..');
32
+ const DRY_RUN = process.argv.includes('--dry-run');
33
+ const PLATFORM_PREFIX = '@rosepetal/node-red-contrib-image-tools-';
34
+ const SEMVER = /^\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)*$/;
35
+
36
+ function escapeRegex(str) {
37
+ return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
38
+ }
39
+
40
+ // Resolve the target version from CLI arg, the git tag, or the current root value.
41
+ function resolveVersion() {
42
+ const arg = process.argv.slice(2).find((a) => !a.startsWith('-'));
43
+ if (arg) return arg.replace(/^v/, '');
44
+
45
+ const tag = (process.env.GITHUB_REF || '').match(/^refs\/tags\/v?(.+)$/);
46
+ if (tag) return tag[1];
47
+
48
+ return require(path.join(ROOT, 'package.json')).version;
49
+ }
50
+
51
+ // Replace the FIRST top-level "version": "<digit...>". The leading-digit guard
52
+ // skips node-red's "version": ">=1.0.0" (and any other range-style field).
53
+ function setTopLevelVersion(content, version) {
54
+ return content.replace(/("version":\s*")\d[^"]*(")/, `$1${version}$2`);
55
+ }
56
+
57
+ // Replace the value of a specific dependency key (e.g. an optionalDependencies pin).
58
+ function setDepVersion(content, dep, version) {
59
+ const re = new RegExp(`("${escapeRegex(dep)}":\\s*")[^"]*(")`);
60
+ return content.replace(re, `$1${version}$2`);
61
+ }
62
+
63
+ // ─────────────────────────────────────────────────────────────
64
+ // Main
65
+ // ─────────────────────────────────────────────────────────────
66
+
67
+ const version = resolveVersion();
68
+ if (!SEMVER.test(version)) {
69
+ console.error(`✗ "${version}" is not a valid semver version`);
70
+ process.exit(1);
71
+ }
72
+
73
+ console.log(`=== Sync version → ${version} ===`);
74
+ if (DRY_RUN) console.log('(dry run — no files written)\n');
75
+ else console.log('');
76
+
77
+ let count = 0;
78
+
79
+ function applyEdit(absFile, label, transform) {
80
+ const before = fs.readFileSync(absFile, 'utf8');
81
+ const after = transform(before);
82
+ if (!DRY_RUN) fs.writeFileSync(absFile, after);
83
+ const changed = after !== before;
84
+ console.log(` ${changed ? '✓' : '·'} ${label}${changed ? '' : ' (already current)'}`);
85
+ count++;
86
+ }
87
+
88
+ // 1. root package.json: version + every platform pin in optionalDependencies
89
+ const rootFile = path.join(ROOT, 'package.json');
90
+ const rootPkg = JSON.parse(fs.readFileSync(rootFile, 'utf8'));
91
+ const pins = Object.keys(rootPkg.optionalDependencies || {}).filter((d) =>
92
+ d.startsWith(PLATFORM_PREFIX),
93
+ );
94
+ applyEdit(rootFile, `package.json (version + ${pins.length} optionalDependencies)`, (content) => {
95
+ content = setTopLevelVersion(content, version);
96
+ for (const dep of pins) content = setDepVersion(content, dep, version);
97
+ return content;
98
+ });
99
+
100
+ // 2. every npm/<arch>/package.json
101
+ const npmDir = path.join(ROOT, 'npm');
102
+ for (const arch of fs.readdirSync(npmDir).sort()) {
103
+ const file = path.join(npmDir, arch, 'package.json');
104
+ if (!fs.existsSync(file)) continue;
105
+ applyEdit(file, `npm/${arch}/package.json`, (content) => setTopLevelVersion(content, version));
106
+ }
107
+
108
+ console.log(`\nDone — ${count} package.json file(s) at ${version}.`);
109
+ if (DRY_RUN) console.log('(dry run — re-run without --dry-run to apply.)');