@naseej/blox 1.5.2 → 1.6.1

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/dist/run.js CHANGED
@@ -185,7 +185,7 @@ var checkForCliUpdate = async (currentVersion) => {
185
185
  };
186
186
 
187
187
  // package.json
188
- var version = "1.5.2";
188
+ var version = "1.6.1";
189
189
 
190
190
  // src/commands/add/index.ts
191
191
  var import_fs_extra10 = __toESM(require("fs-extra"));
@@ -1159,6 +1159,9 @@ var import_fs_extra9 = __toESM(require("fs-extra"));
1159
1159
  var import_merge = __toESM(require("lodash/merge"));
1160
1160
  var registriesDataPath = import_node_path12.default.join(appPaths.data, "registries");
1161
1161
  var upeToDate = false;
1162
+ var cacheDirNameForRegistry = (registry) => {
1163
+ return encodeURIComponent(registry).replace(/%/g, "_");
1164
+ };
1162
1165
  var syncRegistries = async (branch) => {
1163
1166
  if (upeToDate) return;
1164
1167
  upeToDate = true;
@@ -1169,7 +1172,7 @@ var syncRegistries = async (branch) => {
1169
1172
  await Promise.all(
1170
1173
  config.registries.map(async (registry) => {
1171
1174
  debug(`update registry: ${registry}`);
1172
- const repoName = registry.split("/").pop() || "";
1175
+ const repoName = cacheDirNameForRegistry(registry);
1173
1176
  const repoDir = import_node_path12.default.join(registriesDataPath, repoName);
1174
1177
  if (!import_fs_extra9.default.existsSync(repoDir)) {
1175
1178
  await git.clone(registry, repoName, branch, {
@@ -1629,10 +1632,11 @@ var ContributionWorkflow = class {
1629
1632
  branch,
1630
1633
  onAttemptFailed: ({ attempt, error: error2 }) => this.logger.warn("push.failed", { attempt, error: error2 })
1631
1634
  });
1632
- this.logger.info("branch.pushed", {
1635
+ this.logger.debug("branch.pushed", {
1633
1636
  branch,
1634
1637
  remote: repoUrl
1635
1638
  });
1639
+ this.logger.info("Branch pushed successfully.");
1636
1640
  this.pullRequest.printPushSummary({
1637
1641
  repoUrl,
1638
1642
  sourceBranch: branch,
@@ -1762,10 +1766,17 @@ Expected remote ${remoteHead}, local checkpoint ${checkpoint.commit}.`
1762
1766
  if (!title) {
1763
1767
  throw new Error("New contribution requires a title.");
1764
1768
  }
1765
- await git.checkout(checkpointCommit, tmpCwd);
1766
- this.logger.debug("branch.create", { branch, from: checkpointCommit });
1767
- this.logger.info(`Create new branch ${branch} from ${checkpointCommit}`);
1768
- await git.createBranch(branch, checkpointCommit, tmpCwd);
1769
+ await runTask(
1770
+ {
1771
+ start: `Create new branch ${branch} from ${checkpointCommit}`,
1772
+ end: `Created new branch ${branch}`
1773
+ },
1774
+ async () => {
1775
+ await git.checkout(checkpointCommit, tmpCwd);
1776
+ this.logger.debug("branch.create", { branch, from: checkpointCommit });
1777
+ await git.createBranch(branch, checkpointCommit, tmpCwd);
1778
+ }
1779
+ );
1769
1780
  return;
1770
1781
  }
1771
1782
  await git.checkout(branch, tmpCwd);
@@ -1790,7 +1801,7 @@ var import_fs_extra12 = __toESM(require("fs-extra"));
1790
1801
 
1791
1802
  // src/services/contribute/config/index.ts
1792
1803
  var tempRepoName = "tmp";
1793
- var bloxConfigControlledKeys = ["checkpoints"];
1804
+ var bloxConfigControlledKeys = ["checkpoints", "project"];
1794
1805
 
1795
1806
  // src/services/contribute/utils/getExcludedPrefixesForTarget.ts
1796
1807
  var import_node_path14 = __toESM(require("path"));
@@ -1834,22 +1845,34 @@ var CommitApplierService = class {
1834
1845
  this.logger = logger;
1835
1846
  }
1836
1847
  async applyCommits(opts) {
1848
+ const prepareSpinner = spinner();
1849
+ prepareSpinner.start("Prepare for apply commits");
1837
1850
  const subtreePath = getPathPrefixToStrip(opts.target).replace(/\/$/, "");
1838
1851
  const exclusion = getExcludedPrefixesForTarget(opts.target, opts.appRepoCwd);
1852
+ const projectIgnore = getBloxFile(opts.appRepoCwd).project?.ignore || [];
1853
+ const projectIgnoreMatcher = createGitignoreMatcher(projectIgnore);
1839
1854
  this.logger.debug("Prepare for apply commits", {
1840
1855
  appRepo: opts.appRepoCwd,
1841
1856
  tmpRepo: opts.tmpRepoCwd,
1842
1857
  subtree: subtreePath || "(root)",
1843
- exclusion
1858
+ exclusion,
1859
+ projectIgnore
1844
1860
  });
1845
- this.logger.info("Prepare for apply commits");
1861
+ prepareSpinner.stop("Prepared apply commits");
1846
1862
  for (const commit2 of opts.commits) {
1847
- await this.applySingleCommit(opts, subtreePath, exclusion, commit2);
1863
+ await this.applySingleCommit(
1864
+ opts,
1865
+ subtreePath,
1866
+ exclusion,
1867
+ projectIgnoreMatcher,
1868
+ commit2
1869
+ );
1848
1870
  }
1849
1871
  }
1850
- async applySingleCommit(opts, subtreePath, exclusion, commit2) {
1872
+ async applySingleCommit(opts, subtreePath, exclusion, projectIgnoreMatcher, commit2) {
1851
1873
  this.logger.debug("apply.commit.start", { commit: commit2.slice(0, 7) });
1852
- this.logger.info(`Apply commit ${commit2.slice(0, 7)} start`);
1874
+ const commitSpinner = spinner();
1875
+ commitSpinner.start(`Apply commit ${commit2.slice(0, 7)} start`);
1853
1876
  try {
1854
1877
  await git.fetchCommit(opts.appRepoCwd, commit2, opts.tmpRepoCwd);
1855
1878
  try {
@@ -1860,7 +1883,13 @@ var CommitApplierService = class {
1860
1883
  message: e instanceof Error ? e.message : String(e)
1861
1884
  });
1862
1885
  }
1863
- await this.revertExcludedStagedFiles(opts.tmpRepoCwd, commit2, exclusion, opts.target);
1886
+ await this.revertExcludedStagedFiles(
1887
+ opts.tmpRepoCwd,
1888
+ commit2,
1889
+ exclusion,
1890
+ projectIgnoreMatcher,
1891
+ opts.target
1892
+ );
1864
1893
  const remainingConflicts = await git.getUnmergedFiles(opts.tmpRepoCwd);
1865
1894
  if (remainingConflicts.length) {
1866
1895
  this.logger.error("apply.commit.conflicts", {
@@ -1869,8 +1898,16 @@ var CommitApplierService = class {
1869
1898
  });
1870
1899
  await this.waitUntilUserResolvesConflicts(opts.tmpRepoCwd, commit2);
1871
1900
  }
1872
- await this.commitStagedIfAny(opts, commit2);
1901
+ const committed = await this.commitStagedIfAny(opts, commit2);
1902
+ if (committed) {
1903
+ commitSpinner.stop("Apply commit success");
1904
+ } else {
1905
+ commitSpinner.stop(
1906
+ `Apply commit (${commit2}) skipped: no changes left for this target after filtering.`
1907
+ );
1908
+ }
1873
1909
  } catch (e) {
1910
+ commitSpinner.stop(`Failed to apply commit ${commit2.slice(0, 7)}`, 1);
1874
1911
  const msg = `Failed to apply commit ${commit2.slice(0, 7)}.
1875
1912
  Resolve manually in the temp repo:
1876
1913
  cd ${opts.tmpRepoCwd}
@@ -1880,15 +1917,21 @@ Resolve manually in the temp repo:
1880
1917
  ${e instanceof Error ? e.message : String(e)}`);
1881
1918
  }
1882
1919
  }
1883
- async revertExcludedStagedFiles(tmpRepoCwd, commit2, exclusion, target) {
1920
+ async revertExcludedStagedFiles(tmpRepoCwd, commit2, exclusion, projectIgnoreMatcher, target) {
1884
1921
  const stagedFiles = await git.getStagedFiles(tmpRepoCwd);
1885
1922
  const unmergedFiles = await git.getUnmergedFiles(tmpRepoCwd);
1886
1923
  const allTouchedFiles = [.../* @__PURE__ */ new Set([...stagedFiles, ...unmergedFiles])];
1887
1924
  for (const file of allTouchedFiles) {
1888
1925
  const isBloxFile = isBloxConfigFile(file);
1889
1926
  const isExcludedByTarget = shouldExcludeFile(file, exclusion);
1927
+ const isExcludedByProjectIgnore = projectIgnoreMatcher.ignores(toIgnorePath(file));
1890
1928
  if (isExcludedByTarget) {
1891
- this.logger.warn("apply.commit.skip_file", { file });
1929
+ this.logger.debug("apply.commit.skip_file", { file });
1930
+ await git.revertPathToHead(file, tmpRepoCwd);
1931
+ continue;
1932
+ }
1933
+ if (isExcludedByProjectIgnore) {
1934
+ this.logger.debug("apply.commit.skip_file_project_ignore", { file });
1892
1935
  await git.revertPathToHead(file, tmpRepoCwd);
1893
1936
  continue;
1894
1937
  }
@@ -1985,16 +2028,13 @@ ${opts.description}`;
1985
2028
  }
1986
2029
  await git.commitAll(commitMsg, opts.tmpRepoCwd);
1987
2030
  this.logger.debug("apply.commit.success", { commit: commit2.slice(0, 7) });
1988
- this.logger.info("Apply commit success");
1989
- return;
2031
+ return true;
1990
2032
  }
1991
2033
  this.logger.debug("apply.commit.skip_empty", {
1992
2034
  commit: commit2.slice(0, 7),
1993
2035
  message: "No changes left for this target after filtering."
1994
2036
  });
1995
- this.logger.info(
1996
- "Apply commit skip empty : No changes left for this target after filtering."
1997
- );
2037
+ return false;
1998
2038
  }
1999
2039
  };
2000
2040
 
@@ -2021,7 +2061,7 @@ var CommitSelectorService = class {
2021
2061
  value: c.hash,
2022
2062
  label: `${c.hash.slice(0, 7)} ${c.subject}`
2023
2063
  })),
2024
- required: false
2064
+ required: true
2025
2065
  });
2026
2066
  for (const h of value) {
2027
2067
  if (!selected.includes(h)) {
@@ -2140,7 +2180,10 @@ var ContributionTargetSelector = class {
2140
2180
  if (!filtered.length) {
2141
2181
  this.logger.warn(`No matches for search: "${query}"`);
2142
2182
  const again = await confirm({ message: "Search again?" });
2143
- if (again) continue;
2183
+ if (again) {
2184
+ query = " ";
2185
+ continue;
2186
+ }
2144
2187
  throw new Error("Aborted: no target selected.");
2145
2188
  }
2146
2189
  const pageSize = UI_PAGE_SIZE;
@@ -2164,6 +2207,7 @@ var ContributionTargetSelector = class {
2164
2207
  continue;
2165
2208
  }
2166
2209
  if (value === TARGET_SELECT_PAGE.SEARCH_AGAIN) {
2210
+ query = " ";
2167
2211
  break;
2168
2212
  }
2169
2213
  const [typeRaw, name, templateNameRaw] = value.split(":");
@@ -2344,7 +2388,6 @@ ${fmt.cyan("\u25E2")}${line}${fmt.cyan("\u25E3")}
2344
2388
  this.logger.info("pr.skipped", { reason: "remote_not_azure_devops_git" });
2345
2389
  return { prUrl: void 0 };
2346
2390
  }
2347
- this.logger.info("pr.prompt.shown");
2348
2391
  const wantsPr = await confirm({
2349
2392
  message: "Do you want to open a Pull Request?",
2350
2393
  initialValue: true
@@ -2377,25 +2420,52 @@ var TmpRepoService = class {
2377
2420
  constructor(logger) {
2378
2421
  this.logger = logger;
2379
2422
  }
2423
+ async refreshExistingTmpRepo(dir, branch) {
2424
+ await git.fetchRepo(dir);
2425
+ try {
2426
+ await git.checkout(branch, dir);
2427
+ } catch {
2428
+ await git.createBranch(branch, `origin/${branch}`, dir);
2429
+ }
2430
+ await git.reset(void 0, true, dir);
2431
+ await git.update({ cwd: dir });
2432
+ }
2380
2433
  async getTmpDir(target) {
2381
2434
  const slug = `${target.type}-${target.name}`.replace(/[^a-zA-Z0-9._-]+/g, "-");
2382
2435
  return import_node_path17.default.join((0, import_node_os2.homedir)(), bloxFilePath, tempRepoName, slug);
2383
2436
  }
2384
2437
  async prepare(opts) {
2385
- const dir = await this.getTmpDir(opts.target);
2386
- this.logger.debug(`${tempRepoName}.prepare`, {
2387
- dir,
2388
- repoUrl: opts.repoUrl,
2389
- branch: opts.branch
2390
- });
2391
- this.logger.info("Prepare for tmp repo");
2392
- if (await import_fs_extra14.default.pathExists(dir)) {
2393
- this.logger.debug(`${tempRepoName}.remove`, { dir });
2394
- await import_fs_extra14.default.remove(dir);
2438
+ const taskSpinner = spinner();
2439
+ taskSpinner.start("Prepare for tmp repo");
2440
+ try {
2441
+ const dir = await this.getTmpDir(opts.target);
2442
+ this.logger.debug(`${tempRepoName}.prepare`, {
2443
+ dir,
2444
+ repoUrl: opts.repoUrl,
2445
+ branch: opts.branch
2446
+ });
2447
+ if (await import_fs_extra14.default.pathExists(dir)) {
2448
+ this.logger.debug(`${tempRepoName} reuse_tmp_local_repo`, { dir });
2449
+ try {
2450
+ await this.refreshExistingTmpRepo(dir, opts.branch);
2451
+ taskSpinner.stop("Prepared tmp repo");
2452
+ return dir;
2453
+ } catch (e) {
2454
+ this.logger.debug(`${tempRepoName} reuse_tmp_local_repo_failed_reclone`, {
2455
+ dir,
2456
+ message: e instanceof Error ? e.message : String(e)
2457
+ });
2458
+ await import_fs_extra14.default.remove(dir);
2459
+ }
2460
+ }
2461
+ await import_fs_extra14.default.ensureDir(import_node_path17.default.dirname(dir));
2462
+ await git.clone(opts.repoUrl, dir, opts.branch);
2463
+ taskSpinner.stop("Prepared tmp repo");
2464
+ return dir;
2465
+ } catch (e) {
2466
+ taskSpinner.stop("Failed: Prepare for tmp repo", 1);
2467
+ throw e;
2395
2468
  }
2396
- await import_fs_extra14.default.ensureDir(import_node_path17.default.dirname(dir));
2397
- await git.clone(opts.repoUrl, dir, opts.branch);
2398
- return dir;
2399
2469
  }
2400
2470
  };
2401
2471
 
@@ -2870,7 +2940,8 @@ async function updateFromRemote({
2870
2940
  }
2871
2941
  }
2872
2942
  const remoteIgnore = remoteBloxFile.definition?.ignore || [];
2873
- ignore3.push(...remoteIgnore, bloxFilePath, `**/${bloxFilePath}`);
2943
+ const projectIgnore = bloxFile.project?.ignore || [];
2944
+ ignore3.push(...remoteIgnore, ...projectIgnore, bloxFilePath, `**/${bloxFilePath}`);
2874
2945
  const gitIgnorePath = import_node_path21.default.join(dir, ".gitignore");
2875
2946
  if (await import_fs_extra19.default.pathExists(gitIgnorePath)) {
2876
2947
  const gitIgnoreContent = await import_fs_extra19.default.readFile(gitIgnorePath, "utf8");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naseej/blox",
3
- "version": "1.5.2",
3
+ "version": "1.6.1",
4
4
  "description": "blox cli",
5
5
  "bin": {
6
6
  "blox": "./bin/run"
package/readme.md CHANGED
@@ -56,6 +56,37 @@ Options:
56
56
  - [migrate](#migrate)
57
57
  - [skills](#installing-blox-cli-skills)
58
58
 
59
+ ## Ignore policy
60
+
61
+ Ignore rules tell BLOX which files or paths to skip.
62
+
63
+ Add project-level ignore rules in your root `.blox` file:
64
+
65
+ ```json
66
+ {
67
+ "project": {
68
+ "ignore": ["applet-core", "dist/**", "*.generated.ts"]
69
+ }
70
+ }
71
+ ```
72
+
73
+ How it works in a simple way:
74
+
75
+ Quick difference:
76
+
77
+ - `definition.ignore`: comes from the remote template/block (maintainer controls it).
78
+ - `project.ignore`: local to your app (you control it).
79
+
80
+ - `blox update` combines ignore patterns from multiple places:
81
+
82
+ - remote template ignore (`definition.ignore`)
83
+ - local project ignore (`project.ignore` in your local `.blox`)
84
+ - local `.gitignore`
85
+ - command option `--ignore` (when provided)
86
+
87
+ - `blox contribute` also respects local `project.ignore`, so matching files are not included in contributed commits.
88
+ - Local `project.ignore` is project-owned and is not replaced by remote template ignore during update.
89
+
59
90
  ## Lifecycle hooks
60
91
 
61
92
  Lifecycle hooks are **optional shell commands** defined in `.blox` files.
package/changelog.md DELETED
@@ -1,69 +0,0 @@
1
- ## Changelog
2
-
3
- ## 1.5.1
4
-
5
- Features:
6
-
7
- - Optional automatic open of the Azure DevOps / TFS pull request creation page after `blox contribute` / `blox cb` when the user confirms.
8
- - Support for `.blox` configuration files in the contribute flow for the template and blocks .
9
-
10
- Fixes:
11
-
12
- - Git commands that could fail with odd shell errors now run reliably.
13
-
14
- ## 1.5.0
15
-
16
- Features:
17
-
18
- - **`blox contribute`** (`blox cb`): push selected commits from the app repo to the template, base, or block remote, with an interactive target and branch flow.
19
-
20
- Changed:
21
-
22
- - Improve the `blox update` command by replacing the `git patch` approach with a `file-based merge strategy`.
23
-
24
- ## 1.3.0
25
-
26
- Features:
27
-
28
- - show blocks changelog even if updated with the remote template
29
- - faster operations by caching updateRemote and syncRegistries for the operation
30
-
31
- ## 1.2.2
32
-
33
- Features:
34
-
35
- - added detach command
36
-
37
- ## 1.2.1
38
-
39
- Fixes:
40
-
41
- - use app template ignore with bases
42
-
43
- ## 1.2.0
44
-
45
- Fixes:
46
-
47
- - solve app blocks conflicts in templates with base
48
- - wait for conflicts to be resolved on update
49
- - handles not blox dir
50
-
51
- ## 1.1.0
52
-
53
- Features:
54
-
55
- - added ignore support on init and add
56
-
57
- Fixes:
58
-
59
- - block update ignore prop
60
- - update with no not ignored files
61
-
62
- ## 1.0.0
63
-
64
- Features:
65
-
66
- - added versioning support
67
- - added check for uncommited files before update
68
- - added new .blox schema to avoid package.json conflicts
69
- - added new migrate command for blox schema