Skip to content

Commit cd8e455

Browse files
committed
fix(krawler): preserve URL query string and unify hooks registry
1 parent 6c70ad6 commit cd8e455

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

packages/krawler/src/bin.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,30 @@
11
#!/usr/bin/env node
22

3+
import { spawnSync } from 'node:child_process'
4+
import { fileURLToPath } from 'node:url'
5+
36
// import cluster from 'cluster'
47
import { Healthcheck } from './healthcheck.js'
58
import { processOptions, cli } from './cli.js'
69
import logger from './logger.js'
710

11+
// Re-exec under --conditions=development if not already set.
12+
// Without this, bin.js loads hooks via src/ while the user jobfile loads them via dist/index.mjs
13+
// (per package.json `exports.import`), giving two distinct hooks registries and breaking
14+
// custom hook registration. The development condition unifies both resolutions on src/.
15+
const hasDevCondition = process.execArgv.some(arg =>
16+
arg === '--conditions=development' ||
17+
(arg.startsWith('--conditions=') && arg.slice('--conditions='.length).split(',').includes('development'))
18+
)
19+
if (!hasDevCondition) {
20+
const child = spawnSync(
21+
process.execPath,
22+
['--conditions=development', fileURLToPath(import.meta.url), ...process.argv.slice(2)],
23+
{ stdio: 'inherit' }
24+
)
25+
process.exit(child.status ?? 1)
26+
}
27+
828
/* WIP: cluster mode, the main issue is that stores are created by a job before hook
929
thus are not availalbe on workers not running the job but running only tasks
1030
if (cluster.isMaster) {

packages/krawler/src/tasks/tasks.http.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,15 @@ export function getRequestParameters (options) {
2727
method: options.method || 'GET',
2828
headers: options.headers,
2929
body: options.body,
30-
searchParams: buildSearchParams(queryParameters),
3130
cookieJar: options.jar,
3231
// Do not throw on non-2xx so the downstream consumer can read statusCode from the 'response' event
3332
throwHttpErrors: false
3433
}
34+
// Only set searchParams when we actually have params; otherwise got would override
35+
// any pre-existing query string already embedded in options.url.
36+
if (Object.keys(queryParameters).length > 0) {
37+
requestParameters.searchParams = buildSearchParams(queryParameters)
38+
}
3539
if (options.timeout) {
3640
requestParameters.timeout = { request: options.timeout }
3741
}

0 commit comments

Comments
 (0)