datagrok-tools 6.4.0 → 6.4.2
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/CHANGELOG.md +9 -0
- package/bin/commands/build.js +209 -0
- package/bin/commands/publish.js +49 -12
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# Datagrok-tools changelog
|
|
2
2
|
|
|
3
|
+
## 6.4.2 (2026-06-18)
|
|
4
|
+
|
|
5
|
+
* `grok publish` — registry-aware Docker fallback: when a package's image isn't built locally and the target server has no compatible record, `grok publish` now checks the configured registry and Docker Hub (`docker manifest inspect`) for the expected `datagrok/<name>:<version>` (and content-hashed) tag and uses it, instead of reporting "No fallback available" and failing. Fixes dependency publishes (e.g. Bio → @datagrok/chem) on CI runners where the image exists in the registry but not locally.
|
|
6
|
+
|
|
7
|
+
## 6.4.1 (2026-06-18)
|
|
8
|
+
|
|
9
|
+
* Fixed `grok` failing with `Cannot find module './commands/build'` — the `.npmignore` `build.js` rule was unanchored and excluded the compiled `bin/commands/build.js` from the published package; anchored it to `/build.js`.
|
|
10
|
+
* Pinned `ignore-walk` to ^6.0.5 so the package still supports Node 18 (9.x requires Node 22+).
|
|
11
|
+
|
|
3
12
|
## 6.4.0 (2026-06-18)
|
|
4
13
|
|
|
5
14
|
* Dependencies: sanitized and updated all dependencies; `npm install` is now warning-free and `npm audit` reports 0 vulnerabilities (was 24).
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.applyFilter = applyFilter;
|
|
8
|
+
exports.build = build;
|
|
9
|
+
exports.confirm = confirm;
|
|
10
|
+
exports.discoverPackages = discoverPackages;
|
|
11
|
+
exports.getNestedValue = getNestedValue;
|
|
12
|
+
var _fs = _interopRequireDefault(require("fs"));
|
|
13
|
+
var _path = _interopRequireDefault(require("path"));
|
|
14
|
+
var _util = require("util");
|
|
15
|
+
var _child_process = require("child_process");
|
|
16
|
+
var readline = _interopRequireWildcard(require("readline"));
|
|
17
|
+
var utils = _interopRequireWildcard(require("../utils/utils"));
|
|
18
|
+
var color = _interopRequireWildcard(require("../utils/color-utils"));
|
|
19
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
20
|
+
const execAsync = (0, _util.promisify)(_child_process.exec);
|
|
21
|
+
async function build(args) {
|
|
22
|
+
if (args.verbose) color.setVerbose(true);
|
|
23
|
+
const buildCmd = args['no-incremental'] ? 'npm run build' : 'npm run build -- --env incremental';
|
|
24
|
+
if (args.recursive) return await buildRecursive(process.cwd(), args, buildCmd);else return await buildSingle(process.cwd(), buildCmd);
|
|
25
|
+
}
|
|
26
|
+
async function buildSingle(dir, buildCmd) {
|
|
27
|
+
if (!utils.isPackageDir(dir)) {
|
|
28
|
+
color.error('Not a package directory (no package.json found)');
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
const packageJson = JSON.parse(_fs.default.readFileSync(_path.default.join(dir, 'package.json'), 'utf-8'));
|
|
32
|
+
const name = packageJson.friendlyName || packageJson.name;
|
|
33
|
+
console.log(`Building ${name}...`);
|
|
34
|
+
try {
|
|
35
|
+
await utils.runScript('npm install', dir, color.isVerbose());
|
|
36
|
+
await utils.runScript(buildCmd, dir, color.isVerbose());
|
|
37
|
+
color.success(`Successfully built ${name}`);
|
|
38
|
+
return true;
|
|
39
|
+
} catch (error) {
|
|
40
|
+
color.error(`Failed to build ${name}`);
|
|
41
|
+
if (error.message) color.error(error.message);
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
async function buildRecursive(baseDir, args, buildCmd) {
|
|
46
|
+
const packages = discoverPackages(baseDir);
|
|
47
|
+
if (packages.length === 0) {
|
|
48
|
+
color.warn('No packages found in the current directory');
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
const filtered = args.filter ? applyFilter(packages, args.filter) : packages;
|
|
52
|
+
if (filtered.length === 0) {
|
|
53
|
+
color.warn('No packages match the filter');
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
console.log(`Found ${filtered.length} package(s): ${filtered.map(p => p.friendlyName).join(', ')}`);
|
|
57
|
+
if (!args.silent && !args.s) {
|
|
58
|
+
const confirmed = await confirm(`\nBuild ${filtered.length} package(s)?`);
|
|
59
|
+
if (!confirmed) {
|
|
60
|
+
console.log('Aborted.');
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
const maxParallel = args.parallel || 4;
|
|
65
|
+
const results = await buildParallel(filtered, buildCmd, maxParallel);
|
|
66
|
+
return results.every(r => r.success);
|
|
67
|
+
}
|
|
68
|
+
function discoverPackages(baseDir) {
|
|
69
|
+
const entries = _fs.default.readdirSync(baseDir);
|
|
70
|
+
const packages = [];
|
|
71
|
+
for (const entry of entries) {
|
|
72
|
+
if (entry.startsWith('.') || entry === 'node_modules') continue;
|
|
73
|
+
const dir = _path.default.join(baseDir, entry);
|
|
74
|
+
try {
|
|
75
|
+
if (!_fs.default.statSync(dir).isDirectory()) continue;
|
|
76
|
+
} catch (_) {
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
const packageJsonPath = _path.default.join(dir, 'package.json');
|
|
80
|
+
if (!_fs.default.existsSync(packageJsonPath)) continue;
|
|
81
|
+
try {
|
|
82
|
+
const packageJson = JSON.parse(_fs.default.readFileSync(packageJsonPath, 'utf-8'));
|
|
83
|
+
packages.push({
|
|
84
|
+
dir,
|
|
85
|
+
name: packageJson.name || entry,
|
|
86
|
+
friendlyName: packageJson.friendlyName || packageJson.name || entry,
|
|
87
|
+
version: packageJson.version || '0.0.0',
|
|
88
|
+
packageJson
|
|
89
|
+
});
|
|
90
|
+
} catch (_) {
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return packages.sort((a, b) => a.friendlyName.localeCompare(b.friendlyName));
|
|
95
|
+
}
|
|
96
|
+
function applyFilter(packages, filterStr) {
|
|
97
|
+
const conditions = filterStr.split('&&').map(s => s.trim());
|
|
98
|
+
const parsedConditions = conditions.map(cond => {
|
|
99
|
+
const colonIdx = cond.indexOf(':');
|
|
100
|
+
if (colonIdx === -1) return {
|
|
101
|
+
field: cond,
|
|
102
|
+
pattern: new RegExp('.')
|
|
103
|
+
};
|
|
104
|
+
const field = cond.substring(0, colonIdx).trim();
|
|
105
|
+
const pattern = new RegExp(cond.substring(colonIdx + 1).trim());
|
|
106
|
+
return {
|
|
107
|
+
field,
|
|
108
|
+
pattern
|
|
109
|
+
};
|
|
110
|
+
});
|
|
111
|
+
return packages.filter(pkg => {
|
|
112
|
+
for (const cond of parsedConditions) {
|
|
113
|
+
const value = getNestedValue(pkg.packageJson, cond.field);
|
|
114
|
+
if (value === undefined || !cond.pattern.test(String(value))) return false;
|
|
115
|
+
}
|
|
116
|
+
return true;
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
function getNestedValue(obj, path) {
|
|
120
|
+
const parts = path.split('.');
|
|
121
|
+
let current = obj;
|
|
122
|
+
for (const part of parts) {
|
|
123
|
+
if (current == null || typeof current !== 'object') return undefined;
|
|
124
|
+
current = current[part];
|
|
125
|
+
}
|
|
126
|
+
return current;
|
|
127
|
+
}
|
|
128
|
+
async function buildParallel(packages, buildCmd, maxParallel) {
|
|
129
|
+
const results = [];
|
|
130
|
+
const headers = ['Plugin', 'Version', 'Build time', 'Bundle size'];
|
|
131
|
+
const widths = [Math.max(headers[0].length, ...packages.map(p => p.friendlyName.length)), Math.max(headers[1].length, ...packages.map(p => p.version.length)), Math.max(headers[2].length, 10), Math.max(headers[3].length, 40)];
|
|
132
|
+
const pad = (s, w) => s + ' '.repeat(Math.max(0, w - s.length));
|
|
133
|
+
console.log(`\nBuilding with ${maxParallel} parallel job(s)...`);
|
|
134
|
+
console.log(headers.map((h, i) => pad(h, widths[i])).join(' | '));
|
|
135
|
+
console.log(widths.map(w => '-'.repeat(w)).join('-+-'));
|
|
136
|
+
const buildOne = async pkg => {
|
|
137
|
+
const start = Date.now();
|
|
138
|
+
let success = true;
|
|
139
|
+
let buildTime = '';
|
|
140
|
+
let bundleSize = '';
|
|
141
|
+
try {
|
|
142
|
+
await execAsync('npm install', {
|
|
143
|
+
cwd: pkg.dir,
|
|
144
|
+
maxBuffer: 10 * 1024 * 1024
|
|
145
|
+
});
|
|
146
|
+
await execAsync(buildCmd, {
|
|
147
|
+
cwd: pkg.dir,
|
|
148
|
+
maxBuffer: 10 * 1024 * 1024
|
|
149
|
+
});
|
|
150
|
+
const elapsed = (Date.now() - start) / 1000;
|
|
151
|
+
buildTime = `${elapsed.toFixed(1)}s`;
|
|
152
|
+
bundleSize = getBundleSize(pkg.dir);
|
|
153
|
+
} catch (error) {
|
|
154
|
+
success = false;
|
|
155
|
+
buildTime = 'Error';
|
|
156
|
+
const raw = (error.stderr || error.stdout || error.message || 'Unknown error').trim();
|
|
157
|
+
bundleSize = raw.replace(/\r?\n/g, ' ').replace(/\s+/g, ' ').substring(0, 40);
|
|
158
|
+
}
|
|
159
|
+
const result = {
|
|
160
|
+
name: pkg.friendlyName,
|
|
161
|
+
version: pkg.version,
|
|
162
|
+
buildTime,
|
|
163
|
+
bundleSize,
|
|
164
|
+
success
|
|
165
|
+
};
|
|
166
|
+
results.push(result);
|
|
167
|
+
const cells = [result.name, result.version, result.buildTime, result.bundleSize];
|
|
168
|
+
const line = cells.map((cell, j) => pad(cell, widths[j])).join(' | ');
|
|
169
|
+
if (success) color.info(line);else color.error(line);
|
|
170
|
+
return result;
|
|
171
|
+
};
|
|
172
|
+
let idx = 0;
|
|
173
|
+
const next = async () => {
|
|
174
|
+
while (idx < packages.length) {
|
|
175
|
+
const pkg = packages[idx++];
|
|
176
|
+
await buildOne(pkg);
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
const workers = Array.from({
|
|
180
|
+
length: Math.min(maxParallel, packages.length)
|
|
181
|
+
}, () => next());
|
|
182
|
+
await Promise.all(workers);
|
|
183
|
+
const succeeded = results.filter(r => r.success).length;
|
|
184
|
+
const failed = results.length - succeeded;
|
|
185
|
+
console.log('');
|
|
186
|
+
if (failed === 0) color.success(`All ${results.length} package(s) built successfully`);else color.warn(`${succeeded} succeeded, ${failed} failed`);
|
|
187
|
+
return results;
|
|
188
|
+
}
|
|
189
|
+
function getBundleSize(dir) {
|
|
190
|
+
const bundlePath = _path.default.join(dir, 'dist', 'package.js');
|
|
191
|
+
try {
|
|
192
|
+
const stats = _fs.default.statSync(bundlePath);
|
|
193
|
+
return `${(stats.size / 1024).toFixed(1)} KB`;
|
|
194
|
+
} catch (_) {
|
|
195
|
+
return 'N/A';
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
function confirm(message) {
|
|
199
|
+
const rl = readline.createInterface({
|
|
200
|
+
input: process.stdin,
|
|
201
|
+
output: process.stdout
|
|
202
|
+
});
|
|
203
|
+
return new Promise(resolve => {
|
|
204
|
+
rl.question(`${message} [Y/n] `, answer => {
|
|
205
|
+
rl.close();
|
|
206
|
+
resolve(answer.trim().toLowerCase() !== 'n');
|
|
207
|
+
});
|
|
208
|
+
});
|
|
209
|
+
}
|
package/bin/commands/publish.js
CHANGED
|
@@ -95,6 +95,30 @@ function localImageExists(fullName, checkPlatform = true) {
|
|
|
95
95
|
return false;
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
|
+
function imageExistsInRegistry(ref) {
|
|
99
|
+
try {
|
|
100
|
+
execSync(`docker manifest inspect ${ref}`, {
|
|
101
|
+
stdio: ['pipe', 'pipe', 'pipe']
|
|
102
|
+
});
|
|
103
|
+
return true;
|
|
104
|
+
} catch {
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// Looks for an already-published image in the configured registry and on Docker Hub,
|
|
110
|
+
// without pulling it. Prefers the content-hashed release tag (exact dockerfile match),
|
|
111
|
+
// then the plain version tag. Returns the canonical `datagrok/<name>:<tag>` reference
|
|
112
|
+
// for image.json, or null when nothing usable is published.
|
|
113
|
+
function resolveRegistryImage(imageName, registryTag, versionTag, registry) {
|
|
114
|
+
const tags = registryTag === versionTag ? [versionTag] : [registryTag, versionTag];
|
|
115
|
+
for (const tag of tags) {
|
|
116
|
+
const canonical = `datagrok/${imageName}:${tag}`;
|
|
117
|
+
if (registry && imageExistsInRegistry(`${registry}/${canonical}`)) return canonical;
|
|
118
|
+
if (imageExistsInRegistry(canonical)) return canonical;
|
|
119
|
+
}
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
98
122
|
function dockerLogin(registry, devKey) {
|
|
99
123
|
try {
|
|
100
124
|
dockerCommand(`login ${registry} -u any -p ${devKey}`);
|
|
@@ -333,24 +357,37 @@ async function processDockerImages(packageName, version, registry, devKey, host,
|
|
|
333
357
|
requestedVersion: registryTag
|
|
334
358
|
};
|
|
335
359
|
if (!result || result.fallback) color.warn(`Build failed. Falling back to ${fallback.image} (hash mismatch)`);
|
|
336
|
-
} else if (skipDockerRebuild) {
|
|
337
|
-
color.warn(`No fallback available. Skipping docker build (--skip-docker-rebuild).`);
|
|
338
|
-
result = {
|
|
339
|
-
image: null,
|
|
340
|
-
fallback: true,
|
|
341
|
-
requestedVersion: registryTag
|
|
342
|
-
};
|
|
343
360
|
} else {
|
|
344
|
-
//
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
361
|
+
// The server has no compatible record, but the image may already be
|
|
362
|
+
// published in the configured registry / Docker Hub (e.g. pushed by an
|
|
363
|
+
// earlier CI run). Use it directly rather than failing or rebuilding.
|
|
364
|
+
const registryImage = resolveRegistryImage(img.imageName, registryTag, img.imageTag, registry);
|
|
365
|
+
if (registryImage) {
|
|
366
|
+
result = {
|
|
367
|
+
image: registryImage,
|
|
368
|
+
fallback: true,
|
|
369
|
+
requestedVersion: registryTag
|
|
370
|
+
};
|
|
371
|
+
color.success(`Falling back to registry image ${registryImage}`);
|
|
372
|
+
} else if (skipDockerRebuild) {
|
|
373
|
+
color.warn(`No fallback available. Skipping docker build (--skip-docker-rebuild).`);
|
|
348
374
|
result = {
|
|
349
375
|
image: null,
|
|
350
376
|
fallback: true,
|
|
351
377
|
requestedVersion: registryTag
|
|
352
378
|
};
|
|
353
|
-
|
|
379
|
+
} else {
|
|
380
|
+
// No fallback and no local image — must build
|
|
381
|
+
color.warn(`No fallback available. Building ${img.fullLocalName}...`);
|
|
382
|
+
const built = buildAndPush();
|
|
383
|
+
if (built) result = built;else {
|
|
384
|
+
result = {
|
|
385
|
+
image: null,
|
|
386
|
+
fallback: true,
|
|
387
|
+
requestedVersion: registryTag
|
|
388
|
+
};
|
|
389
|
+
color.error(`Failed to build ${img.fullLocalName}. No container will be available.`);
|
|
390
|
+
}
|
|
354
391
|
}
|
|
355
392
|
}
|
|
356
393
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "datagrok-tools",
|
|
3
|
-
"version": "6.4.
|
|
3
|
+
"version": "6.4.2",
|
|
4
4
|
"description": "Utility to upload and publish packages to Datagrok",
|
|
5
5
|
"homepage": "https://github.com/datagrok-ai/public/tree/master/tools#readme",
|
|
6
6
|
"dependencies": {
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"datagrok-api": "^1.27.6",
|
|
15
15
|
"estraverse": "^5.3.0",
|
|
16
16
|
"glob": "^13.0.6",
|
|
17
|
-
"ignore-walk": "^
|
|
17
|
+
"ignore-walk": "^6.0.5",
|
|
18
18
|
"inquirer": "^8.2.7",
|
|
19
19
|
"js-yaml": "^4.2.0",
|
|
20
20
|
"minimist": "^1.2.8",
|