@webpieces/pr-gate 0.4.982 → 0.4.984
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/package.json +7 -6
- package/src/scripts/commands/build-dev-command.d.ts +27 -0
- package/src/scripts/commands/build-dev-command.js +99 -0
- package/src/scripts/commands/build-dev-command.js.map +1 -0
- package/src/scripts/commands/push-dev-command.d.ts +49 -19
- package/src/scripts/commands/push-dev-command.js +95 -32
- package/src/scripts/commands/push-dev-command.js.map +1 -1
- package/src/scripts/pr-gate-app.d.ts +10 -2
- package/src/scripts/pr-gate-app.js +15 -2
- package/src/scripts/pr-gate-app.js.map +1 -1
- package/src/scripts/pr-gate-cli-app.d.ts +1 -0
- package/src/scripts/pr-gate-cli-app.js +9 -2
- package/src/scripts/pr-gate-cli-app.js.map +1 -1
- package/src/scripts/workflow/build-affected.d.ts +7 -0
- package/src/scripts/workflow/build-affected.js +12 -4
- package/src/scripts/workflow/build-affected.js.map +1 -1
- package/src/scripts/workflow/build-gate-log.d.ts +4 -2
- package/src/scripts/workflow/build-gate-log.js +11 -3
- package/src/scripts/workflow/build-gate-log.js.map +1 -1
- package/src/scripts/workflow/dev-build.d.ts +31 -0
- package/src/scripts/workflow/dev-build.js +63 -0
- package/src/scripts/workflow/dev-build.js.map +1 -0
- package/src/scripts/workflow/dev-copy-on-main.d.ts +49 -0
- package/src/scripts/workflow/dev-copy-on-main.js +99 -0
- package/src/scripts/workflow/dev-copy-on-main.js.map +1 -0
- package/src/scripts/workflow/dev-deploy-refs.d.ts +13 -2
- package/src/scripts/workflow/dev-deploy-refs.js +17 -5
- package/src/scripts/workflow/dev-deploy-refs.js.map +1 -1
- package/src/scripts/workflow/dev-resolve-runner.d.ts +55 -8
- package/src/scripts/workflow/dev-resolve-runner.js +150 -22
- package/src/scripts/workflow/dev-resolve-runner.js.map +1 -1
- package/src/scripts/workflow/push-dev-state.d.ts +27 -0
- package/src/scripts/workflow/push-dev-state.js +41 -3
- package/src/scripts/workflow/push-dev-state.js.map +1 -1
- package/src/scripts/wp-build-dev.d.ts +2 -0
- package/src/scripts/wp-build-dev.js +13 -0
- package/src/scripts/wp-build-dev.js.map +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webpieces/pr-gate",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.984",
|
|
4
4
|
"description": "Gated PR system: 3-point squash-merge, merge validation gate, and red/yellow/green PR dashboard. Standalone scripts, no Nx dependency required.",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -16,22 +16,23 @@
|
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"@inversifyjs/binding-decorators": "1.1.5",
|
|
19
|
-
"@webpieces/hook-runtime": "0.4.
|
|
20
|
-
"@webpieces/rules-config": "0.4.
|
|
19
|
+
"@webpieces/hook-runtime": "0.4.984",
|
|
20
|
+
"@webpieces/rules-config": "0.4.984",
|
|
21
21
|
"inversify": "7.10.4",
|
|
22
22
|
"reflect-metadata": "0.2.2",
|
|
23
|
-
"@webpieces/tooling-common": "0.4.
|
|
24
|
-
"@webpieces/repo-workflow-core": "0.4.
|
|
23
|
+
"@webpieces/tooling-common": "0.4.984",
|
|
24
|
+
"@webpieces/repo-workflow-core": "0.4.984"
|
|
25
25
|
},
|
|
26
26
|
"publishConfig": {
|
|
27
27
|
"access": "public"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@webpieces/tooling-testkit": "0.4.
|
|
30
|
+
"@webpieces/tooling-testkit": "0.4.984"
|
|
31
31
|
},
|
|
32
32
|
"types": "./src/index.d.ts",
|
|
33
33
|
"bin": {
|
|
34
34
|
"wp-build": "./src/scripts/wp-build.js",
|
|
35
|
+
"wp-build-dev": "./src/scripts/wp-build-dev.js",
|
|
35
36
|
"wp-finish-upsert-pr": "./src/scripts/git-finishUpsertPr.js",
|
|
36
37
|
"wp-human-post-pr": "./src/scripts/wp-human-post-pr.js",
|
|
37
38
|
"wp-upsert-hotfix-pr": "./src/scripts/wp-upsert-hotfix-pr.js",
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { RepoRootFinder } from '@webpieces/rules-config';
|
|
2
|
+
import { GitExec } from '../workflow/git-exec';
|
|
3
|
+
import { DevDeployRefs } from '../workflow/dev-deploy-refs';
|
|
4
|
+
import { DevBuild } from '../workflow/dev-build';
|
|
5
|
+
/**
|
|
6
|
+
* `wp-build-dev` — the check `wp-push-dev` runs before it publishes, WITHOUT the publish (#1397).
|
|
7
|
+
*
|
|
8
|
+
* It merges `origin/<devBranch>` into a throwaway branch and runs `commands.push-dev.buildCommand` on the
|
|
9
|
+
* merged tree, then puts the checkout back. That is the cheap, honest form of the question a developer
|
|
10
|
+
* wants answered before publishing: does this branch build once it meets what is already on dev? Built on
|
|
11
|
+
* the feature branch itself, a `--base=origin/dev` build would also rebuild every project the OTHER copies
|
|
12
|
+
* on dev touched, because they differ from the feature branch too.
|
|
13
|
+
*
|
|
14
|
+
* It RESOLVES NOTHING. A conflict aborts the throwaway merge and names the files; resolving them is
|
|
15
|
+
* `wp-push-dev`'s job, because a resolution is only worth anything once it is recorded on the published
|
|
16
|
+
* copy. The feature branch is never written to, by the same rule as every other dev-deploy command.
|
|
17
|
+
*/
|
|
18
|
+
export declare class BuildDevCommand {
|
|
19
|
+
private readonly repoRootFinder;
|
|
20
|
+
private readonly gitExec;
|
|
21
|
+
private readonly refs;
|
|
22
|
+
private readonly devBuild;
|
|
23
|
+
constructor(repoRootFinder: RepoRootFinder, gitExec: GitExec, refs: DevDeployRefs, devBuild: DevBuild);
|
|
24
|
+
run(): Promise<void>;
|
|
25
|
+
private refuseConflict;
|
|
26
|
+
private restore;
|
|
27
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BuildDevCommand = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const rules_config_1 = require("@webpieces/rules-config");
|
|
6
|
+
const to_error_1 = require("@webpieces/tooling-common/to-error");
|
|
7
|
+
const inversify_1 = require("inversify");
|
|
8
|
+
const git_exec_1 = require("../workflow/git-exec");
|
|
9
|
+
const dev_deploy_refs_1 = require("../workflow/dev-deploy-refs");
|
|
10
|
+
const dev_build_1 = require("../workflow/dev-build");
|
|
11
|
+
const SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n';
|
|
12
|
+
/**
|
|
13
|
+
* `wp-build-dev` — the check `wp-push-dev` runs before it publishes, WITHOUT the publish (#1397).
|
|
14
|
+
*
|
|
15
|
+
* It merges `origin/<devBranch>` into a throwaway branch and runs `commands.push-dev.buildCommand` on the
|
|
16
|
+
* merged tree, then puts the checkout back. That is the cheap, honest form of the question a developer
|
|
17
|
+
* wants answered before publishing: does this branch build once it meets what is already on dev? Built on
|
|
18
|
+
* the feature branch itself, a `--base=origin/dev` build would also rebuild every project the OTHER copies
|
|
19
|
+
* on dev touched, because they differ from the feature branch too.
|
|
20
|
+
*
|
|
21
|
+
* It RESOLVES NOTHING. A conflict aborts the throwaway merge and names the files; resolving them is
|
|
22
|
+
* `wp-push-dev`'s job, because a resolution is only worth anything once it is recorded on the published
|
|
23
|
+
* copy. The feature branch is never written to, by the same rule as every other dev-deploy command.
|
|
24
|
+
*/
|
|
25
|
+
let BuildDevCommand = class BuildDevCommand {
|
|
26
|
+
repoRootFinder;
|
|
27
|
+
gitExec;
|
|
28
|
+
refs;
|
|
29
|
+
devBuild;
|
|
30
|
+
constructor(repoRootFinder, gitExec, refs, devBuild) {
|
|
31
|
+
this.repoRootFinder = repoRootFinder;
|
|
32
|
+
this.gitExec = gitExec;
|
|
33
|
+
this.refs = refs;
|
|
34
|
+
this.devBuild = devBuild;
|
|
35
|
+
}
|
|
36
|
+
async run() {
|
|
37
|
+
const repoRoot = this.repoRootFinder.resolveRepoRoot(process.cwd());
|
|
38
|
+
(0, rules_config_1.writeTemplate)(repoRoot, 'webpieces.git-workflow.md');
|
|
39
|
+
const cfg = this.refs.config(repoRoot);
|
|
40
|
+
const branch = this.refs.currentBranch(repoRoot);
|
|
41
|
+
this.refs.assertPushable(cfg, branch);
|
|
42
|
+
// Before any git write: an unconfigured dev build refuses here.
|
|
43
|
+
this.devBuild.command(repoRoot);
|
|
44
|
+
// The merge below must be of committed work only, and must not sweep uncommitted edits along.
|
|
45
|
+
await this.gitExec.assertCleanTree(repoRoot);
|
|
46
|
+
if (await this.refs.remoteSha(repoRoot, cfg.devBranch) === '') {
|
|
47
|
+
throw new rules_config_1.CliExitError(2, '\n' + SEP + `⛔ \`origin/${cfg.devBranch}\` does not exist yet\n` + SEP + '\n'
|
|
48
|
+
+ `There is nothing to build against. ${rules_config_1.WP_PUSH_DEV} publishes your copy without this check while\n`
|
|
49
|
+
+ `\`${cfg.devBranch}\` does not exist, and your CI creates it on its first composition run.\n`);
|
|
50
|
+
}
|
|
51
|
+
await this.refs.fetchCopies(repoRoot, [cfg.devBranch]);
|
|
52
|
+
const tmp = `${branch}DevCheck`;
|
|
53
|
+
await this.gitExec.runGitChecked(['-C', repoRoot, 'checkout', '-B', tmp, 'HEAD'], `Failed to create the throwaway check branch ${tmp}`);
|
|
54
|
+
const merged = await this.gitExec.tryGit(['-C', repoRoot, 'merge', '--no-ff', '--no-edit', '-m',
|
|
55
|
+
`Dev-check: merge ${cfg.devBranch} into ${tmp}`, `refs/remotes/origin/${cfg.devBranch}`], repoRoot);
|
|
56
|
+
if (!merged.ok)
|
|
57
|
+
await this.refuseConflict(repoRoot, branch, tmp, cfg.devBranch);
|
|
58
|
+
// webpieces-disable no-unmanaged-exceptions -- chokepoint: the checkout must go back to the feature branch whether or not the build passed; the build's own CliExitError is re-thrown unchanged
|
|
59
|
+
// eslint-disable-next-line @webpieces/no-unmanaged-exceptions
|
|
60
|
+
try {
|
|
61
|
+
await this.devBuild.run(repoRoot, rules_config_1.WP_BUILD_DEV);
|
|
62
|
+
}
|
|
63
|
+
catch (err) {
|
|
64
|
+
const error = (0, to_error_1.toError)(err);
|
|
65
|
+
await this.restore(repoRoot, branch, tmp);
|
|
66
|
+
throw error;
|
|
67
|
+
}
|
|
68
|
+
await this.restore(repoRoot, branch, tmp);
|
|
69
|
+
process.stdout.write(`\n\`${branch}\` merges cleanly with origin/${cfg.devBranch} and the dev build is green.\n`
|
|
70
|
+
+ `Nothing was published — ${rules_config_1.WP_PUSH_DEV} runs this same check and then publishes.\n`);
|
|
71
|
+
}
|
|
72
|
+
// A conflict: list the files, undo the merge, go back — and say which command resolves it.
|
|
73
|
+
async refuseConflict(repoRoot, branch, tmp, devBranch) {
|
|
74
|
+
const out = await this.gitExec.gitQuery(['-C', repoRoot, 'diff', '--name-only', '--diff-filter=U'], repoRoot, 'Failed to list the conflicted files (git diff --name-only --diff-filter=U).');
|
|
75
|
+
const conflicted = out.split('\n').filter((l) => l.trim() !== '');
|
|
76
|
+
await this.gitExec.tryGit(['-C', repoRoot, 'merge', '--abort'], repoRoot);
|
|
77
|
+
await this.restore(repoRoot, branch, tmp);
|
|
78
|
+
throw new rules_config_1.CliExitError(2, '\n' + SEP + `⚠️ \`${branch}\` CONFLICTS with origin/${devBranch}\n` + SEP + '\n'
|
|
79
|
+
+ (conflicted.length === 0
|
|
80
|
+
? 'git could not merge it (no conflicted file was reported).\n'
|
|
81
|
+
: 'These files conflict:\n' + conflicted.map((f) => ` ${f}`).join('\n') + '\n')
|
|
82
|
+
+ '\nNo build ran and nothing was published; the throwaway merge is undone and you are back on\n'
|
|
83
|
+
+ `\`${branch}\`, which was never modified. ${rules_config_1.WP_PUSH_DEV} stops on these same files on a throwaway\n`
|
|
84
|
+
+ 'branch, lets you resolve them there, builds, and publishes the copy with the resolution recorded.\n');
|
|
85
|
+
}
|
|
86
|
+
async restore(repoRoot, branch, tmp) {
|
|
87
|
+
await this.gitExec.runGitChecked(['-C', repoRoot, 'checkout', branch], `Failed to return to ${branch}`);
|
|
88
|
+
await this.gitExec.tryGit(['-C', repoRoot, 'branch', '-D', tmp], repoRoot);
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
exports.BuildDevCommand = BuildDevCommand;
|
|
92
|
+
exports.BuildDevCommand = BuildDevCommand = tslib_1.__decorate([
|
|
93
|
+
(0, inversify_1.injectable)(inversify_1.bindingScopeValues.Singleton),
|
|
94
|
+
tslib_1.__metadata("design:paramtypes", [rules_config_1.RepoRootFinder,
|
|
95
|
+
git_exec_1.GitExec,
|
|
96
|
+
dev_deploy_refs_1.DevDeployRefs,
|
|
97
|
+
dev_build_1.DevBuild])
|
|
98
|
+
], BuildDevCommand);
|
|
99
|
+
//# sourceMappingURL=build-dev-command.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-dev-command.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/commands/build-dev-command.ts"],"names":[],"mappings":";;;;AAAA,0DAAiH;AACjH,iEAA6D;AAC7D,yCAA2D;AAE3D,mDAA+C;AAC/C,iEAA4D;AAC5D,qDAAiD;AAEjD,MAAM,GAAG,GAAG,0DAA0D,CAAC;AAEvE;;;;;;;;;;;;GAYG;AAEI,IAAM,eAAe,GAArB,MAAM,eAAe;IAEH;IACA;IACA;IACA;IAJrB,YACqB,cAA8B,EAC9B,OAAgB,EAChB,IAAmB,EACnB,QAAkB;QAHlB,mBAAc,GAAd,cAAc,CAAgB;QAC9B,YAAO,GAAP,OAAO,CAAS;QAChB,SAAI,GAAJ,IAAI,CAAe;QACnB,aAAQ,GAAR,QAAQ,CAAU;IACpC,CAAC;IAEJ,KAAK,CAAC,GAAG;QACL,MAAM,QAAQ,GAAG,IAAI,CAAC,cAAc,CAAC,eAAe,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;QACpE,IAAA,4BAAa,EAAC,QAAQ,EAAE,2BAA2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H_DEV, writeTemplate } from '@webpieces/rules-config';\nimport { toError } from '@webpieces/tooling-common/to-error';\nimport { injectable, bindingScopeValues } from 'inversify';\n\nimport { GitExec } from '../workflow/git-exec';\nimport { DevDeployRefs } from '../workflow/dev-deploy-refs';\nimport { DevBuild } from '../workflow/dev-build';\n\nconst SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\n\n/**\n * `wp-build-dev` — the check `wp-push-dev` runs before it publishes, WITHOUT the publish (#1397).\n *\n * It merges `origin/<devBranch>` into a throwaway branch and runs `commands.push-dev.buildCommand` on the\n * merged tree, then puts the checkout back. That is the cheap, honest form of the question a developer\n * wants answered before publishing: does this branch build once it meets what is already on dev? Built on\n * the feature branch itself, a `--base=origin/dev` build would also rebuild every project the OTHER copies\n * on dev touched, because they differ from the feature branch too.\n *\n * It RESOLVES NOTHING. A conflict aborts the throwaway merge and names the files; resolving them is\n * `wp-push-dev`'s job, because a resolution is only worth anything once it is recorded on the published\n * copy. The feature branch is never written to, by the same rule as every other dev-deploy command.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class BuildDevCommand {\n constructor(\n private readonly repoRootFinder: RepoRootFinder,\n private readonly gitExec: GitExec,\n private readonly refs: DevDeployRefs,\n private readonly devBuild: DevBuild,\n ) {}\n\n async run(): Promise<void> {\n const repoRoot = this.repoRootFinder.resolveRepoRoot(process.cwd());\n writeTemplate(repoRoot, 'webpieces.git-workflow.md');\n const cfg = this.refs.config(repoRoot);\n const branch = this.refs.currentBranch(repoRoot);\n this.refs.assertPushable(cfg, branch);\n // Before any git write: an unconfigured dev build refuses here.\n this.devBuild.command(repoRoot);\n // The merge below must be of committed work only, and must not sweep uncommitted edits along.\n await this.gitExec.assertCleanTree(repoRoot);\n if (await this.refs.remoteSha(repoRoot, cfg.devBranch) === '') {\n throw new CliExitError(2,\n '\\n' + SEP + `⛔ \\`origin/${cfg.devBranch}\\` does not exist yet\\n` + SEP + '\\n'\n + `There is nothing to build against. ${WP_PUSH_DEV} publishes your copy without this check while\\n`\n + `\\`${cfg.devBranch}\\` does not exist, and your CI creates it on its first composition run.\\n`);\n }\n await this.refs.fetchCopies(repoRoot, [cfg.devBranch]);\n const tmp = `${branch}DevCheck`;\n await this.gitExec.runGitChecked(['-C', repoRoot, 'checkout', '-B', tmp, 'HEAD'],\n `Failed to create the throwaway check branch ${tmp}`);\n const merged = await this.gitExec.tryGit(\n ['-C', repoRoot, 'merge', '--no-ff', '--no-edit', '-m',\n `Dev-check: merge ${cfg.devBranch} into ${tmp}`, `refs/remotes/origin/${cfg.devBranch}`],\n repoRoot);\n if (!merged.ok) await this.refuseConflict(repoRoot, branch, tmp, cfg.devBranch);\n // webpieces-disable no-unmanaged-exceptions -- chokepoint: the checkout must go back to the feature branch whether or not the build passed; the build's own CliExitError is re-thrown unchanged\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n await this.devBuild.run(repoRoot, WP_BUILD_DEV);\n } catch (err: unknown) {\n const error = toError(err);\n await this.restore(repoRoot, branch, tmp);\n throw error;\n }\n await this.restore(repoRoot, branch, tmp);\n process.stdout.write(\n `\\n\\`${branch}\\` merges cleanly with origin/${cfg.devBranch} and the dev build is green.\\n`\n + `Nothing was published — ${WP_PUSH_DEV} runs this same check and then publishes.\\n`);\n }\n\n // A conflict: list the files, undo the merge, go back — and say which command resolves it.\n private async refuseConflict(repoRoot: string, branch: string, tmp: string, devBranch: string): Promise<never> {\n const out = await this.gitExec.gitQuery(['-C', repoRoot, 'diff', '--name-only', '--diff-filter=U'], repoRoot,\n 'Failed to list the conflicted files (git diff --name-only --diff-filter=U).');\n const conflicted = out.split('\\n').filter((l: string): boolean => l.trim() !== '');\n await this.gitExec.tryGit(['-C', repoRoot, 'merge', '--abort'], repoRoot);\n await this.restore(repoRoot, branch, tmp);\n throw new CliExitError(2,\n '\\n' + SEP + `⚠️ \\`${branch}\\` CONFLICTS with origin/${devBranch}\\n` + SEP + '\\n'\n + (conflicted.length === 0\n ? 'git could not merge it (no conflicted file was reported).\\n'\n : 'These files conflict:\\n' + conflicted.map((f: string): string => ` ${f}`).join('\\n') + '\\n')\n + '\\nNo build ran and nothing was published; the throwaway merge is undone and you are back on\\n'\n + `\\`${branch}\\`, which was never modified. ${WP_PUSH_DEV} stops on these same files on a throwaway\\n`\n + 'branch, lets you resolve them there, builds, and publishes the copy with the resolution recorded.\\n');\n }\n\n private async restore(repoRoot: string, branch: string, tmp: string): Promise<void> {\n await this.gitExec.runGitChecked(['-C', repoRoot, 'checkout', branch], `Failed to return to ${branch}`);\n await this.gitExec.tryGit(['-C', repoRoot, 'branch', '-D', tmp], repoRoot);\n }\n}\n"]}
|
|
@@ -4,6 +4,8 @@ import { DevDeployRefs } from '../workflow/dev-deploy-refs';
|
|
|
4
4
|
import { PushDevStateStore } from '../workflow/push-dev-state';
|
|
5
5
|
import { DevResolveRunner } from '../workflow/dev-resolve-runner';
|
|
6
6
|
import { DevDeployWatchHints } from '../workflow/dev-deploy-watch-hints';
|
|
7
|
+
import { DevBuild } from '../workflow/dev-build';
|
|
8
|
+
import { DevCopyOnMain } from '../workflow/dev-copy-on-main';
|
|
7
9
|
/**
|
|
8
10
|
* Which of `wp-push-dev`'s modes was asked for. Data-only (per CLAUDE.md) with plain assigned fields
|
|
9
11
|
* rather than a seven-argument constructor — the bin sets what argv carried and nothing else.
|
|
@@ -32,10 +34,17 @@ export declare class PushDevOptions {
|
|
|
32
34
|
* a gated command there is simply no legal way for an AI to get a branch onto a dev server, so the
|
|
33
35
|
* feature was undoable rather than merely awkward.
|
|
34
36
|
*
|
|
35
|
-
* WHY
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
37
|
+
* WHY IT CHECKS AGAINST `dev` FIRST (#1397): 61 of 73 failed dev publishes on one consumer failed on a git
|
|
38
|
+
* conflict, which the developer only learned about after the server-side composition failed. So a plain
|
|
39
|
+
* publish now does locally what CI is about to do: merge `origin/<devBranch>` into a THROWAWAY branch,
|
|
40
|
+
* resolve any conflict there (the same halt / `wp-finish-push-dev` state machine `--resolve` uses), and run
|
|
41
|
+
* `commands.push-dev.buildCommand` on the merged tree. A build against `main` alone would prove the wrong
|
|
42
|
+
* thing; a build of only what differs from `dev` proves the right one, quickly.
|
|
43
|
+
*
|
|
44
|
+
* WHAT IS PUBLISHED IS NEVER THAT MERGE: the copy is the feature head plus, when something conflicted, one
|
|
45
|
+
* commit recording the resolved files (DevResolveRunner.recordResolution). A copy that contained `dev`
|
|
46
|
+
* would carry every other copy's history, and a later `--remove` of one of them would leave it on dev
|
|
47
|
+
* through this one.
|
|
39
48
|
*
|
|
40
49
|
* WHAT IT NEVER DOES: touch the feature branch. See DevDeployRefs for the invariant and why the copy
|
|
41
50
|
* exists to hold conflict resolutions that must not reach the PR.
|
|
@@ -47,7 +56,9 @@ export declare class PushDevCommand {
|
|
|
47
56
|
private readonly store;
|
|
48
57
|
private readonly runner;
|
|
49
58
|
private readonly watchHints;
|
|
50
|
-
|
|
59
|
+
private readonly devBuild;
|
|
60
|
+
private readonly copyOnMain;
|
|
61
|
+
constructor(repoRootFinder: RepoRootFinder, gitExec: GitExec, refs: DevDeployRefs, store: PushDevStateStore, runner: DevResolveRunner, watchHints: DevDeployWatchHints, devBuild: DevBuild, copyOnMain: DevCopyOnMain);
|
|
51
62
|
run(opts: PushDevOptions): Promise<void>;
|
|
52
63
|
/** `--list`: exactly the live copies, straight from the remote — never a cached local view. */
|
|
53
64
|
private list;
|
|
@@ -61,11 +72,25 @@ export declare class PushDevCommand {
|
|
|
61
72
|
* workflow still listens on `delete:` keeps working through the rollout window; the marker is purely
|
|
62
73
|
* additive at the transport level.
|
|
63
74
|
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
75
|
+
* ALREADY ON MAIN (#1401): before anything is deleted, the copy is compared with `origin/main`. When
|
|
76
|
+
* every file it changes already has the copy's content on main, removing it takes nothing off dev —
|
|
77
|
+
* main keeps the change there — and would only force a pointless full recompose, so it is REFUSED
|
|
78
|
+
* ({@link refuseLanded}). When only some files are, the rest is still a real rollback: it warns, naming
|
|
79
|
+
* the landed files, and removes.
|
|
80
|
+
*
|
|
81
|
+
* ORDER: `origin/main` and the copy are fetched BEFORE anything is deleted, so a network failure there
|
|
82
|
+
* leaves the pool exactly as it was. The marker push is the last step, and the only one that can fail with the
|
|
66
83
|
* copy already gone — that is the state {@link markerPushFailed} names.
|
|
67
84
|
*/
|
|
68
85
|
private remove;
|
|
86
|
+
/**
|
|
87
|
+
* `--remove` of a copy whose every change is already on `origin/main`. Nothing was deleted and no marker
|
|
88
|
+
* was pushed. There is deliberately no override: a remove cannot take back what main already holds, so
|
|
89
|
+
* refusing never blocks a real rollback — that is a revert PR.
|
|
90
|
+
*/
|
|
91
|
+
private refuseLanded;
|
|
92
|
+
/** Some of the copy's files are already on main: the remove proceeds, and says what it does NOT take off. */
|
|
93
|
+
private partlyLandedWarning;
|
|
69
94
|
/**
|
|
70
95
|
* The one half-done state `--remove` can leave: the copy is deleted, the rebuild signal is not sent.
|
|
71
96
|
* Said out loud because it is invisible otherwise — `--list` already looks right, while the deployed
|
|
@@ -73,15 +98,26 @@ export declare class PushDevCommand {
|
|
|
73
98
|
*/
|
|
74
99
|
private markerPushFailed;
|
|
75
100
|
/**
|
|
76
|
-
* The ordinary path: publish
|
|
101
|
+
* The ordinary path: check the copy against `origin/<devBranch>`, build it, then publish it as
|
|
102
|
+
* `<namespace>/<branch>` (#1397). The merge, the conflict halt and the build all happen on a throwaway
|
|
103
|
+
* branch through DevResolveRunner, in DevResolveMode.PREBUILD — so a conflict stops in exactly the
|
|
104
|
+
* same `wp-finish-push-dev` state machine `--resolve` uses, rather than inventing a second way to be
|
|
105
|
+
* stuck.
|
|
77
106
|
*
|
|
78
|
-
* THE CLOBBER GUARD
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
107
|
+
* THE CLOBBER GUARD runs first. If the remote copy holds commits the local branch does not, somebody
|
|
108
|
+
* (quite possibly this developer, days ago) put real work there, and a silent force-push destroys it,
|
|
109
|
+
* so the default is refusal with two named ways forward — never a "use --force" one-liner, which is how
|
|
110
|
+
* a warning becomes a reflex. The one exception is a commit this flow wrote itself
|
|
111
|
+
* ({@link RESOLUTION_SUBJECT}): the check below re-derives it against today's dev, so replacing it
|
|
112
|
+
* loses nothing.
|
|
83
113
|
*/
|
|
84
114
|
private publish;
|
|
115
|
+
/**
|
|
116
|
+
* `origin/<devBranch>` does not exist yet — the very first publish in a repo whose CI has never
|
|
117
|
+
* composed. There is nothing to conflict with and no base for a dev-scoped build, so the copy is
|
|
118
|
+
* published as it is; refusing here would make the first dev composition impossible to start.
|
|
119
|
+
*/
|
|
120
|
+
private publishWithoutDev;
|
|
85
121
|
/**
|
|
86
122
|
* `--rebase-resolution`: keep the published resolution, replay it on top of the new commits.
|
|
87
123
|
*
|
|
@@ -99,12 +135,6 @@ export declare class PushDevCommand {
|
|
|
99
135
|
*/
|
|
100
136
|
private startResolve;
|
|
101
137
|
private resolveQueue;
|
|
102
|
-
/**
|
|
103
|
-
* `--force-with-lease` pinned to the sha we just inspected, so the clobber guard's verdict cannot go
|
|
104
|
-
* stale between the check and the push. Plain `--force` only when the caller explicitly asked to
|
|
105
|
-
* discard, and no force at all for a brand-new copy.
|
|
106
|
-
*/
|
|
107
|
-
private pushSafety;
|
|
108
138
|
private refuseClobber;
|
|
109
139
|
private assertNoResolveInProgress;
|
|
110
140
|
}
|
|
@@ -9,6 +9,8 @@ const dev_deploy_refs_1 = require("../workflow/dev-deploy-refs");
|
|
|
9
9
|
const push_dev_state_1 = require("../workflow/push-dev-state");
|
|
10
10
|
const dev_resolve_runner_1 = require("../workflow/dev-resolve-runner");
|
|
11
11
|
const dev_deploy_watch_hints_1 = require("../workflow/dev-deploy-watch-hints");
|
|
12
|
+
const dev_build_1 = require("../workflow/dev-build");
|
|
13
|
+
const dev_copy_on_main_1 = require("../workflow/dev-copy-on-main");
|
|
12
14
|
const SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n';
|
|
13
15
|
/**
|
|
14
16
|
* Which of `wp-push-dev`'s modes was asked for. Data-only (per CLAUDE.md) with plain assigned fields
|
|
@@ -39,10 +41,17 @@ exports.PushDevOptions = PushDevOptions;
|
|
|
39
41
|
* a gated command there is simply no legal way for an AI to get a branch onto a dev server, so the
|
|
40
42
|
* feature was undoable rather than merely awkward.
|
|
41
43
|
*
|
|
42
|
-
* WHY
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
44
|
+
* WHY IT CHECKS AGAINST `dev` FIRST (#1397): 61 of 73 failed dev publishes on one consumer failed on a git
|
|
45
|
+
* conflict, which the developer only learned about after the server-side composition failed. So a plain
|
|
46
|
+
* publish now does locally what CI is about to do: merge `origin/<devBranch>` into a THROWAWAY branch,
|
|
47
|
+
* resolve any conflict there (the same halt / `wp-finish-push-dev` state machine `--resolve` uses), and run
|
|
48
|
+
* `commands.push-dev.buildCommand` on the merged tree. A build against `main` alone would prove the wrong
|
|
49
|
+
* thing; a build of only what differs from `dev` proves the right one, quickly.
|
|
50
|
+
*
|
|
51
|
+
* WHAT IS PUBLISHED IS NEVER THAT MERGE: the copy is the feature head plus, when something conflicted, one
|
|
52
|
+
* commit recording the resolved files (DevResolveRunner.recordResolution). A copy that contained `dev`
|
|
53
|
+
* would carry every other copy's history, and a later `--remove` of one of them would leave it on dev
|
|
54
|
+
* through this one.
|
|
46
55
|
*
|
|
47
56
|
* WHAT IT NEVER DOES: touch the feature branch. See DevDeployRefs for the invariant and why the copy
|
|
48
57
|
* exists to hold conflict resolutions that must not reach the PR.
|
|
@@ -54,13 +63,17 @@ let PushDevCommand = class PushDevCommand {
|
|
|
54
63
|
store;
|
|
55
64
|
runner;
|
|
56
65
|
watchHints;
|
|
57
|
-
|
|
66
|
+
devBuild;
|
|
67
|
+
copyOnMain;
|
|
68
|
+
constructor(repoRootFinder, gitExec, refs, store, runner, watchHints, devBuild, copyOnMain) {
|
|
58
69
|
this.repoRootFinder = repoRootFinder;
|
|
59
70
|
this.gitExec = gitExec;
|
|
60
71
|
this.refs = refs;
|
|
61
72
|
this.store = store;
|
|
62
73
|
this.runner = runner;
|
|
63
74
|
this.watchHints = watchHints;
|
|
75
|
+
this.devBuild = devBuild;
|
|
76
|
+
this.copyOnMain = copyOnMain;
|
|
64
77
|
}
|
|
65
78
|
async run(opts) {
|
|
66
79
|
const repoRoot = this.repoRootFinder.resolveRepoRoot(process.cwd());
|
|
@@ -116,8 +129,14 @@ let PushDevCommand = class PushDevCommand {
|
|
|
116
129
|
* workflow still listens on `delete:` keeps working through the rollout window; the marker is purely
|
|
117
130
|
* additive at the transport level.
|
|
118
131
|
*
|
|
119
|
-
*
|
|
120
|
-
*
|
|
132
|
+
* ALREADY ON MAIN (#1401): before anything is deleted, the copy is compared with `origin/main`. When
|
|
133
|
+
* every file it changes already has the copy's content on main, removing it takes nothing off dev —
|
|
134
|
+
* main keeps the change there — and would only force a pointless full recompose, so it is REFUSED
|
|
135
|
+
* ({@link refuseLanded}). When only some files are, the rest is still a real rollback: it warns, naming
|
|
136
|
+
* the landed files, and removes.
|
|
137
|
+
*
|
|
138
|
+
* ORDER: `origin/main` and the copy are fetched BEFORE anything is deleted, so a network failure there
|
|
139
|
+
* leaves the pool exactly as it was. The marker push is the last step, and the only one that can fail with the
|
|
121
140
|
* copy already gone — that is the state {@link markerPushFailed} names.
|
|
122
141
|
*/
|
|
123
142
|
async remove(repoRoot, cfg, branch, targetRef) {
|
|
@@ -128,6 +147,13 @@ let PushDevCommand = class PushDevCommand {
|
|
|
128
147
|
}
|
|
129
148
|
const markerRef = cfg.removeMarkerRefFor(branch);
|
|
130
149
|
const mainTip = await this.refs.freshMainTip(repoRoot);
|
|
150
|
+
await this.refs.fetchCopies(repoRoot, [targetRef]);
|
|
151
|
+
const landing = await this.copyOnMain.landing(repoRoot, targetRef);
|
|
152
|
+
if (landing.fullyOnMain()) {
|
|
153
|
+
this.refuseLanded(targetRef, await this.copyOnMain.mergedPr(repoRoot, branch));
|
|
154
|
+
}
|
|
155
|
+
if (landing.partlyOnMain())
|
|
156
|
+
process.stdout.write(this.partlyLandedWarning(targetRef, landing));
|
|
131
157
|
await this.gitExec.runGitChecked(['-C', repoRoot, 'push', 'origin', '--delete', `refs/heads/${targetRef}`], `Failed to delete the dev copy ${targetRef}`);
|
|
132
158
|
// --force: the marker carries no content, so whatever an earlier, never-deleted marker pointed at
|
|
133
159
|
// is worthless — and refusing a non-fast-forward here would strand the rollback half-done.
|
|
@@ -139,6 +165,27 @@ let PushDevCommand = class PushDevCommand {
|
|
|
139
165
|
+ `on it, deletes it, and rebuilds \`${cfg.devBranch}\` without \`${branch}\`. Your branch and any PR on it\n`
|
|
140
166
|
+ 'are untouched.\n');
|
|
141
167
|
}
|
|
168
|
+
/**
|
|
169
|
+
* `--remove` of a copy whose every change is already on `origin/main`. Nothing was deleted and no marker
|
|
170
|
+
* was pushed. There is deliberately no override: a remove cannot take back what main already holds, so
|
|
171
|
+
* refusing never blocks a real rollback — that is a revert PR.
|
|
172
|
+
*/
|
|
173
|
+
refuseLanded(targetRef, pr) {
|
|
174
|
+
const landedVia = pr === null ? '' : ` (PR #${pr.num} landed ${pr.mergedAt})`;
|
|
175
|
+
throw new rules_config_1.CliExitError(2, '\n' + SEP + `⛔ \`${targetRef}\` is already on origin/main — nothing was removed\n` + SEP + '\n'
|
|
176
|
+
+ `\`${targetRef}\` is already on origin/main${landedVia}, so removing the copy\n`
|
|
177
|
+
+ 'would not take anything off dev — main keeps it there. The nightly reset deletes the copy.\n'
|
|
178
|
+
+ 'Nothing was removed, and no rebuild marker was pushed.\n\n'
|
|
179
|
+
+ 'If that code is what broke dev, it is on main now: the fix is a revert PR against main, not a remove.\n');
|
|
180
|
+
}
|
|
181
|
+
/** Some of the copy's files are already on main: the remove proceeds, and says what it does NOT take off. */
|
|
182
|
+
partlyLandedWarning(targetRef, landing) {
|
|
183
|
+
return '\n' + SEP + `⚠️ Part of \`${targetRef}\` is already on origin/main\n` + SEP + '\n'
|
|
184
|
+
+ `${String(landing.landed.length)} of the ${String(landing.changed.length)} files this copy changes already have the copy's content on\n`
|
|
185
|
+
+ 'origin/main. Removing the copy does NOT take these off dev — main keeps them there:\n'
|
|
186
|
+
+ landing.landed.map((f) => ` ${f}`).join('\n') + '\n'
|
|
187
|
+
+ 'Only the rest of the copy is being removed. If one of the files above broke dev, the fix is a revert PR.\n';
|
|
188
|
+
}
|
|
142
189
|
/**
|
|
143
190
|
* The one half-done state `--remove` can leave: the copy is deleted, the rebuild signal is not sent.
|
|
144
191
|
* Said out loud because it is invisible otherwise — `--list` already looks right, while the deployed
|
|
@@ -156,19 +203,25 @@ let PushDevCommand = class PushDevCommand {
|
|
|
156
203
|
+ ` ${rules_config_1.WP_PUSH_DEV}\n ${rules_config_1.WP_PUSH_DEV} --remove\n`);
|
|
157
204
|
}
|
|
158
205
|
/**
|
|
159
|
-
* The ordinary path: publish
|
|
206
|
+
* The ordinary path: check the copy against `origin/<devBranch>`, build it, then publish it as
|
|
207
|
+
* `<namespace>/<branch>` (#1397). The merge, the conflict halt and the build all happen on a throwaway
|
|
208
|
+
* branch through DevResolveRunner, in DevResolveMode.PREBUILD — so a conflict stops in exactly the
|
|
209
|
+
* same `wp-finish-push-dev` state machine `--resolve` uses, rather than inventing a second way to be
|
|
210
|
+
* stuck.
|
|
160
211
|
*
|
|
161
|
-
* THE CLOBBER GUARD
|
|
162
|
-
*
|
|
163
|
-
*
|
|
164
|
-
*
|
|
165
|
-
*
|
|
212
|
+
* THE CLOBBER GUARD runs first. If the remote copy holds commits the local branch does not, somebody
|
|
213
|
+
* (quite possibly this developer, days ago) put real work there, and a silent force-push destroys it,
|
|
214
|
+
* so the default is refusal with two named ways forward — never a "use --force" one-liner, which is how
|
|
215
|
+
* a warning becomes a reflex. The one exception is a commit this flow wrote itself
|
|
216
|
+
* ({@link RESOLUTION_SUBJECT}): the check below re-derives it against today's dev, so replacing it
|
|
217
|
+
* loses nothing.
|
|
166
218
|
*/
|
|
167
219
|
async publish(repoRoot, cfg, branch, targetRef, opts) {
|
|
168
220
|
const remoteSha = await this.refs.remoteSha(repoRoot, targetRef);
|
|
169
221
|
if (remoteSha !== '') {
|
|
170
222
|
await this.refs.fetchCopies(repoRoot, [targetRef]);
|
|
171
|
-
const
|
|
223
|
+
const subjects = await this.refs.subjectsOnlyOnRemote(repoRoot, targetRef);
|
|
224
|
+
const ahead = subjects.filter((s) => !s.startsWith(dev_resolve_runner_1.RESOLUTION_SUBJECT)).length;
|
|
172
225
|
if (ahead > 0 && opts.rebaseResolution) {
|
|
173
226
|
await this.rebaseResolution(repoRoot, branch, targetRef);
|
|
174
227
|
return;
|
|
@@ -176,13 +229,31 @@ let PushDevCommand = class PushDevCommand {
|
|
|
176
229
|
if (ahead > 0 && !opts.force)
|
|
177
230
|
this.refuseClobber(cfg, branch, targetRef, ahead);
|
|
178
231
|
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
232
|
+
// Before any git write: an unconfigured dev build refuses here, with nothing merged or published.
|
|
233
|
+
this.devBuild.command(repoRoot);
|
|
234
|
+
if (await this.refs.remoteSha(repoRoot, cfg.devBranch) === '') {
|
|
235
|
+
await this.publishWithoutDev(repoRoot, cfg, branch, targetRef, remoteSha, opts.force);
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
const state = new push_dev_state_1.PushDevState(branch, this.runner.tmpBranchFor(branch), targetRef, [cfg.devBranch]);
|
|
239
|
+
state.mode = push_dev_state_1.DevResolveMode.PREBUILD;
|
|
240
|
+
state.leaseSha = remoteSha;
|
|
241
|
+
state.force = opts.force;
|
|
242
|
+
process.stdout.write(this.runner.announcePrebuild(cfg, state));
|
|
243
|
+
await this.runner.start(repoRoot, state, 'HEAD', [cfg.devBranch]);
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* `origin/<devBranch>` does not exist yet — the very first publish in a repo whose CI has never
|
|
247
|
+
* composed. There is nothing to conflict with and no base for a dev-scoped build, so the copy is
|
|
248
|
+
* published as it is; refusing here would make the first dev composition impossible to start.
|
|
249
|
+
*/
|
|
250
|
+
async publishWithoutDev(repoRoot, cfg, branch, targetRef, remoteSha, force) {
|
|
251
|
+
const lease = remoteSha === '' ? [] : force ? ['--force'] : [`--force-with-lease=refs/heads/${targetRef}:${remoteSha}`];
|
|
252
|
+
await this.gitExec.runGitChecked(['-C', repoRoot, 'push', ...lease, 'origin', `HEAD:refs/heads/${targetRef}`], `Failed to publish the dev copy ${targetRef}`);
|
|
182
253
|
const published = await this.refs.headSha(repoRoot);
|
|
183
254
|
process.stdout.write('\n' + SEP + `✅ Published ${targetRef}\n` + SEP + '\n'
|
|
184
|
-
+
|
|
185
|
-
+
|
|
255
|
+
+ `\`origin/${cfg.devBranch}\` does not exist yet, so there was nothing to check the copy against and no\n`
|
|
256
|
+
+ `dev build ran. \`${branch}\` is now in the pool your CI composes \`${cfg.devBranch}\` from.\n\n`
|
|
186
257
|
+ ` ${rules_config_1.WP_PUSH_DEV} --list ← what else is in the pool\n`
|
|
187
258
|
+ ` ${rules_config_1.WP_PUSH_DEV} --remove ← take this branch back out\n`
|
|
188
259
|
+ this.watchHints.render(cfg, targetRef, published));
|
|
@@ -196,6 +267,7 @@ let PushDevCommand = class PushDevCommand {
|
|
|
196
267
|
*/
|
|
197
268
|
async rebaseResolution(repoRoot, branch, targetRef) {
|
|
198
269
|
const state = new push_dev_state_1.PushDevState(branch, this.runner.tmpBranchFor(branch), targetRef, [targetRef]);
|
|
270
|
+
state.mode = push_dev_state_1.DevResolveMode.REPLAY;
|
|
199
271
|
process.stdout.write('\n' + SEP + `♻️ Replaying the published resolution onto \`${branch}\`\n` + SEP + '\n'
|
|
200
272
|
+ `Merging \`${targetRef}\` (which holds the resolution) into your new commits on a throwaway branch.\n`
|
|
201
273
|
+ `Your feature branch \`${branch}\` is not touched.\n\n`);
|
|
@@ -221,6 +293,7 @@ let PushDevCommand = class PushDevCommand {
|
|
|
221
293
|
return;
|
|
222
294
|
}
|
|
223
295
|
const state = new push_dev_state_1.PushDevState(branch, this.runner.tmpBranchFor(branch), targetRef, queue);
|
|
296
|
+
state.mode = push_dev_state_1.DevResolveMode.COMPOSE;
|
|
224
297
|
process.stdout.write(this.runner.announce(cfg, state));
|
|
225
298
|
await this.runner.start(repoRoot, state, `refs/remotes/origin/${targetRef}`, [targetRef, ...queue]);
|
|
226
299
|
}
|
|
@@ -242,18 +315,6 @@ let PushDevCommand = class PushDevCommand {
|
|
|
242
315
|
}
|
|
243
316
|
return [wanted];
|
|
244
317
|
}
|
|
245
|
-
/**
|
|
246
|
-
* `--force-with-lease` pinned to the sha we just inspected, so the clobber guard's verdict cannot go
|
|
247
|
-
* stale between the check and the push. Plain `--force` only when the caller explicitly asked to
|
|
248
|
-
* discard, and no force at all for a brand-new copy.
|
|
249
|
-
*/
|
|
250
|
-
pushSafety(targetRef, remoteSha, force) {
|
|
251
|
-
if (remoteSha === '')
|
|
252
|
-
return [];
|
|
253
|
-
if (force)
|
|
254
|
-
return ['--force'];
|
|
255
|
-
return [`--force-with-lease=refs/heads/${targetRef}:${remoteSha}`];
|
|
256
|
-
}
|
|
257
318
|
refuseClobber(cfg, branch, targetRef, ahead) {
|
|
258
319
|
throw new rules_config_1.CliExitError(2, '\n' + SEP + `⛔ \`${targetRef}\` holds ${String(ahead)} commit(s) your branch does not\n` + SEP + '\n'
|
|
259
320
|
+ 'That is what a CONFLICT RESOLUTION looks like: somebody composed this copy against another\n'
|
|
@@ -288,6 +349,8 @@ exports.PushDevCommand = PushDevCommand = tslib_1.__decorate([
|
|
|
288
349
|
dev_deploy_refs_1.DevDeployRefs,
|
|
289
350
|
push_dev_state_1.PushDevStateStore,
|
|
290
351
|
dev_resolve_runner_1.DevResolveRunner,
|
|
291
|
-
dev_deploy_watch_hints_1.DevDeployWatchHints
|
|
352
|
+
dev_deploy_watch_hints_1.DevDeployWatchHints,
|
|
353
|
+
dev_build_1.DevBuild,
|
|
354
|
+
dev_copy_on_main_1.DevCopyOnMain])
|
|
292
355
|
], PushDevCommand);
|
|
293
356
|
//# sourceMappingURL=push-dev-command.js.map
|