@neverquits/nq 0.1.2 → 0.1.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.
- package/lib/commands/pull.mjs +11 -4
- package/package.json +1 -1
package/lib/commands/pull.mjs
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { execSync } from 'node:child_process'
|
|
2
2
|
import { existsSync, writeFileSync } from 'node:fs'
|
|
3
|
-
import { join, resolve } from 'node:path'
|
|
3
|
+
import { join, resolve, dirname } from 'node:path'
|
|
4
|
+
import { fileURLToPath } from 'node:url'
|
|
4
5
|
import { apiFetch, getToken } from '../api.mjs'
|
|
5
6
|
import { getApiUrl } from '../config.mjs'
|
|
6
7
|
|
|
8
|
+
const NQ_BIN = resolve(dirname(fileURLToPath(import.meta.url)), '..', '..', 'bin', 'nq.mjs')
|
|
9
|
+
const NODE_BIN = process.execPath
|
|
10
|
+
|
|
7
11
|
export async function pull(agentKey, options) {
|
|
8
12
|
const orgId = options.org
|
|
9
13
|
if (!orgId) {
|
|
@@ -100,14 +104,17 @@ function setRemote(dest, url) {
|
|
|
100
104
|
}
|
|
101
105
|
|
|
102
106
|
function configureCredentialHelper(dest, orgId, agentKey) {
|
|
103
|
-
// The helper is invoked by git
|
|
104
|
-
//
|
|
107
|
+
// The helper is invoked by git during a github.com auth challenge.
|
|
108
|
+
// We point at the *absolute* path of this nq install (node binary +
|
|
109
|
+
// bin/nq.mjs) so the helper works regardless of whether `nq` is on
|
|
110
|
+
// the user's PATH — e.g. when they invoked us via `npx`.
|
|
111
|
+
const helperCmd = `${shArg(NODE_BIN)} ${shArg(NQ_BIN)} credential-helper`
|
|
105
112
|
const cmds = [
|
|
106
113
|
['nq.orgId', orgId],
|
|
107
114
|
['nq.agentKey', agentKey],
|
|
108
115
|
// Per-host helper, applied only inside this repo via --local config.
|
|
109
116
|
// The '!' prefix tells git to run it as a shell command.
|
|
110
|
-
['credential.https://github.com.helper',
|
|
117
|
+
['credential.https://github.com.helper', `!${helperCmd}`],
|
|
111
118
|
]
|
|
112
119
|
for (const [k, v] of cmds) {
|
|
113
120
|
execSync(`git config --local ${shArg(k)} ${shArg(v)}`, {
|