saaslayer 0.4.2 → 0.5.0

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.
Files changed (62) hide show
  1. package/bin/saaslayer.js +23 -11
  2. package/package.json +7 -7
  3. package/src/cdn-aws.js +67 -0
  4. package/src/cdn-publication.js +146 -0
  5. package/src/cdn-publisher.js +166 -0
  6. package/src/commands/cdn.js +66 -0
  7. package/src/commands/deploy.js +4 -3
  8. package/src/commands/lifecycle.js +20 -2
  9. package/src/commands/operations.js +8 -3
  10. package/src/commands/stacks.js +2 -0
  11. package/src/commands/users-management.js +2 -2
  12. package/src/deployments.js +5 -2
  13. package/src/module-catalog.js +15 -5
  14. package/src/sms/scope.js +4 -2
  15. package/src/source-branch.js +36 -0
  16. package/src/users-import/ids.js +1 -1
  17. package/templates/saaslayer-foundation.yml +215 -281
  18. package/vendor/config/login-domain.js +213 -0
  19. package/vendor/discovery/index.d.mts +109 -0
  20. package/vendor/discovery/index.mjs +409 -0
  21. package/vendor/ids/index.d.ts +21 -0
  22. package/vendor/ids/index.js +237 -0
  23. package/vendor/migrations/backups.js +118 -0
  24. package/vendor/migrations/child.js +78 -0
  25. package/vendor/migrations/credentials.js +103 -0
  26. package/vendor/migrations/errors.js +30 -0
  27. package/vendor/migrations/exec-child.js +78 -0
  28. package/vendor/migrations/gate.js +51 -0
  29. package/vendor/migrations/index.js +30 -0
  30. package/vendor/migrations/inventory.js +92 -0
  31. package/vendor/migrations/log.js +14 -0
  32. package/vendor/migrations/release.js +45 -0
  33. package/vendor/migrations/report.js +129 -0
  34. package/vendor/migrations/rules.js +104 -0
  35. package/vendor/migrations/run.js +311 -0
  36. package/vendor/migrations/session-policy.js +37 -0
  37. package/vendor/migrations/step-guard.js +82 -0
  38. package/vendor/operations/activity.d.ts +21 -0
  39. package/vendor/operations/activity.js +126 -0
  40. package/vendor/operations/index.d.ts +72 -0
  41. package/vendor/operations/index.js +510 -0
  42. package/vendor/permissions-engine-core/account-status.js +270 -0
  43. package/vendor/permissions-engine-core/delegation.js +174 -0
  44. package/vendor/permissions-engine-core/direct-mode-contract.js +237 -0
  45. package/vendor/permissions-engine-core/sso-claims.js +206 -0
  46. package/vendor/user-management/cognito/emails/token-registry.js +48 -0
  47. package/vendor/user-management/email/validate.js +207 -0
  48. package/vendor/user-management/extensibility/hook-contract.js +720 -0
  49. package/vendor/user-management/extensibility/safe-webhook.js +85 -0
  50. package/vendor/user-management/identity/admission.js +215 -0
  51. package/vendor/user-management/identity/attr.js +27 -0
  52. package/vendor/user-management/identity/attribute-registry.js +115 -0
  53. package/vendor/user-management/identity/email.js +25 -0
  54. package/vendor/user-management/identity/ensure-suid.js +74 -0
  55. package/vendor/user-management/identity/pointers.js +192 -0
  56. package/vendor/user-management/identity/stitch-provider.js +275 -0
  57. package/vendor/user-management/management/apply-request.js +227 -0
  58. package/vendor/user-management/management/core-profile.js +110 -0
  59. package/vendor/user-management/management/index.js +23 -0
  60. package/vendor/user-management/management/purposes.js +94 -0
  61. package/vendor/user-management/management/registry.js +569 -0
  62. package/vendor/user-management/store/table.js +332 -0
@@ -7,7 +7,7 @@ const { resolveScope, printScope } = require('../scope')
7
7
  const { apiCall } = require('../api-client')
8
8
  const { confirm } = require('../prompt')
9
9
  const { finishMutation } = require('./operations')
10
- const { fetchModuleCatalog, checkModuleIds, checkDependencies, checkParamModules } = require('../module-catalog')
10
+ const { fetchModuleCatalog, checkModuleIds, checkDependencies, checkParamModules, checkHosting } = require('../module-catalog')
11
11
  const { parseSetFlags, readSettingsFile, mergePatches, checkPatch } = require('../settings')
12
12
  const { fetchSchema } = require('./settings')
13
13
  const { USER_SERVICE, signInChange, signInRefusalHint } = require('../login-methods')
@@ -53,13 +53,13 @@ async function checkCreateSettings(parameters, choice, modules, flags) {
53
53
  }
54
54
  const commitSha = choice ? choice.commitSha : undefined
55
55
  /** @param {string} id */
56
- const revisionOf = (id) => commitSha || (modules.find((m) => m.id === id) || { attributes: {} }).attributes.revision
56
+ const revisionOf = (id) => commitSha || (modules.find((m) => m.id === id.split('@')[0]) || { attributes: {} }).attributes.revision
57
57
  const ids = Object.keys(parameters)
58
58
  if (ids.some((id) => !revisionOf(id))) {
59
59
  console.log(' the control plane reports no default release, so settings are checked by the control plane only (pass --commit-sha to check them here first)')
60
60
  return parameters
61
61
  }
62
- const schemas = Object.fromEntries(await Promise.all(ids.map(async (id) => [id, await fetchSchema(id, String(revisionOf(id)), flags)])))
62
+ const schemas = Object.fromEntries(await Promise.all(ids.map(async (id) => [id, await fetchSchema(id.split('@')[0], String(revisionOf(id)), flags)])))
63
63
  const { patch, createOnly } = checkPatch(parameters, schemas, { op: 'create' })
64
64
  if (createOnly.length) console.log(` create-only (fixed once deployed): ${createOnly.join(', ')}`)
65
65
  return patch
@@ -90,6 +90,7 @@ async function deploy(flags, io = {}) {
90
90
  if (services) {
91
91
  checkModuleIds(services, modules)
92
92
  checkDependencies(services, modules)
93
+ checkHosting(services, modules, hosting)
93
94
  }
94
95
  if (parameters) {
95
96
  checkParamModules(parameters, modules)
@@ -14,6 +14,9 @@ const { applySettings, fetchSchema } = require('./settings')
14
14
  const { signInRefusalHint } = require('../login-methods')
15
15
  const { releaseChoice, checkReleaseChoice, describeChoice } = require('../versions')
16
16
 
17
+ // A deployment whose last update failed or was blocked: `update --retry` re-runs it at its deployed release.
18
+ const FAILED_UPDATE_STATUSES = new Set(['UPDATE_FAILED', 'UPDATE_BLOCKED_DRIFT', 'UPDATE_BLOCKED_DRIFT_CHECK', 'UPDATE_BLOCKED_CHANGESET'])
19
+
17
20
  async function status(flags) {
18
21
  const scope = resolveScope(flags, { env: 'all' })
19
22
  printScope(scope, flags)
@@ -67,6 +70,12 @@ async function update(flags) {
67
70
  if (resolved && resolved.compat === 'breaking') console.log(` ${resolved.version} is a breaking release${resolved.notes ? `: ${resolved.notes}` : ''}`)
68
71
  // Protected envs (staging/prod) require --reason; --force passes the drift gate (audited with the reason).
69
72
  const attributes = { ...choice }
73
+ // The branch an explicit commit was pushed to, when the local checkout proves it: a pure code update may then wait
74
+ // behind an active run on a dev deployment instead of being refused (the deployer re-proves it from the repository)
75
+ if (choice.commitSha) {
76
+ const sourceBranch = require('../source-branch').pushedBranchOf(String(choice.commitSha))
77
+ if (sourceBranch) attributes.sourceBranch = sourceBranch
78
+ }
70
79
  if (flags.reason) attributes.reason = flags.reason
71
80
  if (flags.force === true || flags.force === 'true') attributes.force = true
72
81
  const res = await apiCall('POST', `/api/deployments/${encodeURIComponent(d.deploymentId)}/update`, { data: { type: 'deployments', attributes } }, flags, { headers: requestKeyHeaders() })
@@ -85,13 +94,16 @@ async function update(flags) {
85
94
  async function retry(flags, changes) {
86
95
  if (changes) throw new Error('--retry redeploys the deployed release: leave out --version, --channel, --commit-sha and --param')
87
96
  const d = await resolveDeployment(flags)
97
+ // A failed create released its stage: the control plane refuses to update it in place.
98
+ if (d.status === 'CREATE_FAILED') throw new Error(`${d.deploymentId} is CREATE_FAILED: a failed create cannot be retried in place; destroy it (saaslayer destroy --env ${d.env} --data-custody delete|retain), then run saaslayer deploy again`)
88
99
  if (!d.commitSha) throw new Error(`${d.deploymentId} has no deployed release to retry (status ${d.status || '—'}); deploy it first`)
89
100
  if (!flags.reason && PROTECTED_ENVS.has(d.env)) throw new Error(`\`update --retry\` on ${d.env} (protected) requires --reason <text>`)
90
- // Sign-in methods not ready, none of which the deployer says a retry resumes (retryable): none is sent.
101
+ // Sign-in methods not ready, none of which the deployer says a retry resumes (retryable): none is sent, unless the
102
+ // last update failed (the retry re-runs it).
91
103
  const doc = await apiCall('GET', `/api/deployments/${encodeURIComponent(d.deploymentId)}/settings`, undefined, flags)
92
104
  const report = (doc && doc.data && doc.data.attributes && doc.data.attributes.loginMethods) || []
93
105
  const notReady = report.flatMap((state) => state.methods.filter((m) => m.stage !== 'ready'))
94
- if (notReady.length && !notReady.some((m) => m.retryable)) {
106
+ if (notReady.length && !notReady.some((m) => m.retryable) && !FAILED_UPDATE_STATUSES.has(d.status)) {
95
107
  console.log('nothing to retry: a retry cannot fix what is pending')
96
108
  for (const m of notReady) console.log(` ${m.loginMethod} ${m.role} (${m.reason || m.stage}): ${m.guidance}`)
97
109
  return null
@@ -165,6 +177,7 @@ function printPurgeResult(purgeResult) {
165
177
  * @param {Record<string, any>} flags
166
178
  */
167
179
  async function destroy(flags) {
180
+ if (flags['acknowledge-cdn-outage'] !== undefined && flags['acknowledge-cdn-outage'] !== true) throw new Error('--acknowledge-cdn-outage is a presence flag')
168
181
  const purge = flags['purge-retained'] === true || flags['purge-retained'] === 'true'
169
182
  const dataCustody = flags['data-custody']
170
183
  if (purge && dataCustody !== undefined) throw new Error('--purge-retained purges what a retain destroy kept: it takes no --data-custody')
@@ -181,10 +194,12 @@ async function destroy(flags) {
181
194
  console.log(`⚠ This will DESTROY ${target}, data-custody=${dataCustody}.`)
182
195
  console.log(dataCustody === 'retain' ? ` ${RETAINED_COST_NOTICE}` : " Delete custody permanently deletes the deployment's data; this cannot be undone.")
183
196
  }
197
+ if (flags['acknowledge-cdn-outage']) console.log(' CDN delivery will stop. Its immutable assets, policies and logs remain in your AWS account and may incur charges.')
184
198
  const typed = flags.yes ? d.project : await ask(`Type the project name "${d.project}" to confirm: `)
185
199
  if (typed !== d.project) { console.log('Aborted (name did not match).'); return null }
186
200
  const query = new URLSearchParams(purge ? { purgeRetained: 'true' } : { dataCustody })
187
201
  if (reason) query.set('reason', reason)
202
+ if (flags['acknowledge-cdn-outage'] === true) query.set('acknowledgeCdnOutage', 'true')
188
203
  let res
189
204
  try {
190
205
  res = await jsonApiCall('DELETE', `/api/deployments/${encodeURIComponent(d.deploymentId)}?${query}`, undefined, flags)
@@ -230,6 +245,7 @@ async function serviceAdd(service, flags) {
230
245
  }
231
246
 
232
247
  async function serviceRemove(service, flags) {
248
+ if (flags['acknowledge-cdn-outage'] !== undefined && flags['acknowledge-cdn-outage'] !== true) throw new Error('--acknowledge-cdn-outage is a presence flag')
233
249
  if (!service) throw new Error('`service remove` requires a service name')
234
250
  const dataCustody = flags['data-custody']
235
251
  if (dataCustody !== 'delete' && dataCustody !== 'retain') throw new Error('`service remove` requires --data-custody delete|retain')
@@ -239,6 +255,8 @@ async function serviceRemove(service, flags) {
239
255
  if (isProtected && !flags.reason) throw new Error(`\`service remove\` on ${d.env} (protected) requires --reason <text>`)
240
256
  const query = new URLSearchParams({ dataCustody })
241
257
  if (flags.reason) query.set('reason', flags.reason)
258
+ if (flags['acknowledge-cdn-outage'] === true) query.set('acknowledgeCdnOutage', 'true')
259
+ if (flags['acknowledge-cdn-outage']) console.log('⚠ CDN delivery will stop. Its immutable assets, policies and logs remain in your AWS account and may incur charges.')
242
260
  if (isProtected) {
243
261
  console.log(`⚠ This will REMOVE ${service} from ${d.project}/${d.env}/${d.region} (${d.deploymentId}), data-custody=${dataCustody}.`)
244
262
  const typed = flags.yes ? service : await ask(`Type the service name "${service}" to confirm: `)
@@ -8,7 +8,7 @@ const { apiCall } = require('../api-client')
8
8
  const { resolveDeployment } = require('../deployments')
9
9
 
10
10
  // The monorepo source, for running the CLI from a checkout before vendor/ is synced (the published package carries
11
- // vendor/operations, synced on prepack).
11
+ // vendor/operations, synced by pack:release).
12
12
  const MONOREPO_OPERATIONS = path.join(__dirname, '../../../operations/src')
13
13
 
14
14
  /** A module of the operations package (index by default; activity for the activity feed). @param {string} [file] */
@@ -60,8 +60,9 @@ async function fetchOperation(deploymentId, operationId, flags) {
60
60
  }
61
61
 
62
62
  /**
63
- * Wait for an operation to finish. Succeeded: prints its components and returns it. Failed or partial: throws an
64
- * error whose message lists each component's outcome and the next supported command.
63
+ * Wait for an operation to finish. Succeeded: prints its components and returns it. Superseded (a newer request
64
+ * replaced it before it started): prints that and returns it. Failed or partial: throws an error whose message lists
65
+ * each component's outcome and the next supported command.
65
66
  * @param {{ deploymentId: string, operationId: string, flags: object }} input
66
67
  */
67
68
  async function followOperation({ deploymentId, operationId, flags }) {
@@ -78,6 +79,10 @@ async function followOperation({ deploymentId, operationId, flags }) {
78
79
  console.log(lines.join('\n'))
79
80
  return final
80
81
  }
82
+ if (final.status === 'superseded') {
83
+ console.log([...lines, ' replaced by a newer request before it started; nothing was deployed by this one'].join('\n'))
84
+ return final
85
+ }
81
86
  throw Object.assign(new Error(lines.join('\n')), { operation: final })
82
87
  }
83
88
 
@@ -10,6 +10,8 @@ async function stacks(flags) {
10
10
  const a = r.attributes || {}
11
11
  console.log(` ${r.id}${a.displayName ? ` ${a.displayName}` : ''}${a.description ? ' — ' + a.description : ''}`)
12
12
  console.log(` regions: ${a.supportedRegions ? a.supportedRegions.join(', ') : 'any'}`)
13
+ if (a.hostingModes) console.log(` hosting: ${a.hostingModes.map(mode => mode === 'byoa' ? 'your connected AWS account (BYOA)' : 'SaaSLayer-hosted').join(', ')}`)
14
+ if (a.minimumFoundationVersion) console.log(` foundation: >= ${a.minimumFoundationVersion}; upgrade with saaslayer foundation upgrade`)
13
15
  const deps = a.dependencies || []
14
16
  if (deps.length) console.log(` requires: ${deps.map((d) => `${d.module} (${d.phase})`).join(', ')}`)
15
17
  const stable = (a.outputs || []).filter((o) => o.stability === 'stable').map((o) => o.name)
@@ -10,13 +10,13 @@ const { ssmApi } = require('../ssm-api')
10
10
  const { awsCredentials } = require('../iam-session')
11
11
 
12
12
  // The monorepo source, for running the CLI from a checkout before vendor/ is synced (the published package carries
13
- // vendor/user-management, synced on prepack).
13
+ // vendor/user-management, synced by pack:release).
14
14
  const MONOREPO_MANAGEMENT = path.join(__dirname, '../../../../services/user-service/src/management')
15
15
 
16
16
  /** The user-service management package: registry, purposes and the request flow its seed also runs. */
17
17
  function loadManagement() {
18
18
  try {
19
- return require('../../vendor/user-management')
19
+ return require('../../vendor/user-management/management')
20
20
  } catch (err) {
21
21
  if (err && err.code !== 'MODULE_NOT_FOUND') throw err
22
22
  return require(MONOREPO_MANAGEMENT)
@@ -11,13 +11,16 @@ async function resolveDeployment(flags) {
11
11
  const scope = resolveScope(flags, { env: 'prod' })
12
12
  printScope(scope, flags)
13
13
  const project = scope.project.value
14
- const env = scope.env.value
15
14
  const region = flags.region
16
15
  const view = await apiCall('GET', `/api/projects/${encodeURIComponent(project)}/deployments`, undefined, flags)
16
+ const selected = typeof flags.deployment === 'string' && flags.deployment.startsWith('dep_') ? flags.deployment : null
17
+ // --deployment <id> without --env names the deployment in whichever environment holds it (not the default prod).
18
+ const holder = selected && typeof flags.env !== 'string' ? (view.environments || []).find((g) => (g.instances || []).some((i) => i.deploymentId === selected)) : null
19
+ if (selected && typeof flags.env !== 'string' && !holder) throw new Error(`no deployment ${selected} for project ${project} (${scope.project.kind})`)
20
+ const env = holder ? holder.environment : scope.env.value
17
21
  const group = (view.environments || []).find((g) => g.environment === env)
18
22
  let instances = group ? group.instances : []
19
23
  if (region) instances = instances.filter((i) => i.region === region)
20
- const selected = typeof flags.deployment === 'string' && flags.deployment.startsWith('dep_') ? flags.deployment : null
21
24
  if (selected) instances = instances.filter((i) => i.deploymentId === selected)
22
25
  // A failed or destroyed deployment never shadows a live one in the same env; alone, it still resolves (status, destroy).
23
26
  const live = instances.filter((i) => !DEAD_STATUSES.has(i.status))
@@ -2,6 +2,8 @@
2
2
  // module ids, required dependencies, and the module keys of --param flags.
3
3
  'use strict'
4
4
  const { apiCall } = require('./api-client')
5
+ const moduleType = id => id.split('@')[0]
6
+ const validRef = id => /^[a-z][a-z0-9-]*(?:@[a-z][a-z0-9]{0,11})?$/.test(id)
5
7
 
6
8
  /**
7
9
  * @typedef {{ id: string, attributes: { dependencies?: Array<{ module: string, phase: string }> } & Record<string, unknown> }} CatalogModule
@@ -35,7 +37,7 @@ function unknownModuleMessage(name, modules) {
35
37
  */
36
38
  function checkModuleIds(ids, modules) {
37
39
  for (const id of ids) {
38
- if (!modules.some((m) => m.id === id)) throw new Error(unknownModuleMessage(id, modules))
40
+ if (!validRef(id) || !modules.some((m) => m.id === moduleType(id))) throw new Error(unknownModuleMessage(id, modules))
39
41
  }
40
42
  }
41
43
 
@@ -47,9 +49,9 @@ function checkModuleIds(ids, modules) {
47
49
  */
48
50
  function checkDependencies(ids, modules) {
49
51
  for (const id of ids) {
50
- const m = modules.find((x) => x.id === id)
52
+ const m = modules.find((x) => x.id === moduleType(id))
51
53
  for (const dep of ((m && m.attributes.dependencies) || []).filter((d) => d.phase !== 'seed')) {
52
- if (!ids.includes(dep.module)) throw new Error(`${id} needs ${dep.module} in the same deployment (${dep.phase}) — add it to --services`)
54
+ if (!ids.some(selected => moduleType(selected) === dep.module)) throw new Error(`${id} needs ${dep.module} in the same deployment (${dep.phase}) — add it to --services`)
53
55
  }
54
56
  }
55
57
  }
@@ -60,8 +62,16 @@ function checkDependencies(ids, modules) {
60
62
  */
61
63
  function checkParamModules(parameters, modules) {
62
64
  for (const [id, values] of Object.entries(parameters)) {
63
- if (!modules.some((m) => m.id === id)) throw new Error(`--param ${id}.${Object.keys(values)[0]}: ${unknownModuleMessage(id, modules)}`)
65
+ if (!validRef(id) || !modules.some((m) => m.id === moduleType(id))) throw new Error(`--param ${id}.${Object.keys(values)[0]}: ${unknownModuleMessage(id, modules)}`)
64
66
  }
65
67
  }
66
68
 
67
- module.exports = { fetchModuleCatalog, checkModuleIds, checkDependencies, checkParamModules }
69
+ /** Refuse an explicitly incompatible hosting choice before sending a deployment mutation. Automatic placement stays server-authoritative. */
70
+ function checkHosting(ids, modules, hosting) {
71
+ if (!hosting) return
72
+ for (const id of ids) {
73
+ const modes = modules.find(m => m.id === moduleType(id))?.attributes.hostingModes
74
+ if (Array.isArray(modes) && !modes.includes(hosting)) throw new Error(`${id} supports ${modes.join(', ')} hosting; use --hosting byoa with your connected AWS account. Hosted CDN publishing is not available in v1.`)
75
+ }
76
+ }
77
+ module.exports = { fetchModuleCatalog, checkModuleIds, checkDependencies, checkParamModules, checkHosting }
package/src/sms/scope.js CHANGED
@@ -16,7 +16,8 @@ const DEFAULT_SMS_SENDER = 'default'
16
16
  */
17
17
 
18
18
  /**
19
- * Resolve the target account and region of `--env` (and `--region` when the env spans several). Prints the scope line and
19
+ * Resolve the target account and region of `--env` (and `--region` when the env spans several, `--target` when the
20
+ * project has several connected accounts). Prints the scope line and
20
21
  * the target line on stderr (--json suppresses both).
21
22
  * @param {Record<string, any>} flags
22
23
  * @param {ScopeDeps} [deps]
@@ -27,7 +28,8 @@ async function resolveSmsTarget(flags, { api = jsonApiCall, log = console.error,
27
28
  const scope = resolveScope(flags, { env: flags.env })
28
29
  if (!flags.json) log(formatScopeLine(scope))
29
30
  const project = String(scope.project.value)
30
- const query = new URLSearchParams({ environment: flags.env, ...(typeof flags.region === 'string' ? { region: flags.region } : {}) })
31
+ // --target names the connected account when the project has several (the same flag as `saaslayer deploy --target`).
32
+ const query = new URLSearchParams({ environment: flags.env, ...(typeof flags.region === 'string' ? { region: flags.region } : {}), ...(typeof flags.target === 'string' ? { targetAccountId: flags.target } : {}) })
31
33
  const doc = await api('GET', `/api/projects/${encodeURIComponent(project)}/sms-target?${query}`, undefined, flags)
32
34
  const a = doc.data.attributes
33
35
  /** @type {SmsTarget} */
@@ -0,0 +1,36 @@
1
+ // The branch a commit was pushed to, from the local checkout, only when that is certain: HEAD is the commit, the
2
+ // current branch tracks a remote branch, and that remote branch is at the same commit. Anything else is unknown.
3
+ 'use strict'
4
+ const { execFileSync } = require('child_process')
5
+
6
+ /**
7
+ * @param {string} cwd
8
+ * @param {string[]} args
9
+ * @returns {string|null}
10
+ */
11
+ function git(cwd, args) {
12
+ try {
13
+ return execFileSync('git', args, { cwd, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }).trim()
14
+ } catch {
15
+ return null
16
+ }
17
+ }
18
+
19
+ /**
20
+ * @param {string} commitSha full 40-character SHA
21
+ * @param {{ cwd?: string }} [opts]
22
+ * @returns {string|null} refs/heads/<name>, or null when not reliably known
23
+ */
24
+ function pushedBranchOf(commitSha, { cwd = process.cwd() } = {}) {
25
+ if (git(cwd, ['rev-parse', 'HEAD']) !== commitSha) return null
26
+ const branch = git(cwd, ['symbolic-ref', '--quiet', '--short', 'HEAD'])
27
+ if (!branch) return null
28
+ const upstream = git(cwd, ['rev-parse', '--abbrev-ref', '--symbolic-full-name', '@{upstream}'])
29
+ if (!upstream) return null
30
+ if (git(cwd, ['rev-parse', '@{upstream}']) !== commitSha) return null
31
+ // The upstream's branch name on its remote (origin/feat/x -> feat/x)
32
+ const remoteBranch = upstream.slice(upstream.indexOf('/') + 1)
33
+ return remoteBranch ? `refs/heads/${remoteBranch}` : null
34
+ }
35
+
36
+ module.exports = { pushedBranchOf }
@@ -4,7 +4,7 @@
4
4
  const path = require('path')
5
5
 
6
6
  // The monorepo source, for running the CLI from a checkout before vendor/ is synced. Resolved at runtime because it
7
- // is never shipped: the published package carries vendor/ids (synced on prepack).
7
+ // is never shipped: the published package carries vendor/ids (synced by pack:release).
8
8
  const MONOREPO_IDS = path.join(__dirname, '../../../ids/src')
9
9
 
10
10
  function loadIds() {