@crustjs/extensions 0.3.0 → 0.3.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/index.d.ts CHANGED
@@ -109,10 +109,11 @@ declare const colorFlags: readonly [{
109
109
  * and hyperlinks keep following TTY detection, per
110
110
  * [no-color.org](https://no-color.org/).
111
111
  *
112
- * Previous values are restored after the command finishes. When overlapping
113
- * programmatic runs in one process use opposite flags, the later run wins
114
- * mid-flight (the env is process-global); the ambient values are restored
115
- * once all runs finish.
112
+ * Previous values are restored after the command finishes. Overlapping
113
+ * programmatic runs in one process may share a direction (both `--color` or
114
+ * both `--no-color`); the ambient values are restored once all runs finish.
115
+ * An overlapping run with the opposing flag throws a `CrustError` in
116
+ * `preRun`, because the env is process-global and cannot hold both values.
116
117
  */
117
118
  export declare const noColor: ExtensionFactory<[], {}, [], typeof colorFlags>;
118
119
  //#endregion
package/dist/index.js CHANGED
@@ -1467,6 +1467,7 @@ const didYouMean = defineExtension(DID_YOU_MEAN, (options = {}) => {
1467
1467
  //#region src/no-color.ts
1468
1468
  const NO_COLOR = defineExtensionId("crust:no-color");
1469
1469
  let activeRuns = 0;
1470
+ let activeFlag;
1470
1471
  let baseForceColor;
1471
1472
  let baseNoColor;
1472
1473
  const colorRuns = /* @__PURE__ */ new WeakSet();
@@ -1489,10 +1490,11 @@ const colorFlags = [{
1489
1490
  * and hyperlinks keep following TTY detection, per
1490
1491
  * [no-color.org](https://no-color.org/).
1491
1492
  *
1492
- * Previous values are restored after the command finishes. When overlapping
1493
- * programmatic runs in one process use opposite flags, the later run wins
1494
- * mid-flight (the env is process-global); the ambient values are restored
1495
- * once all runs finish.
1493
+ * Previous values are restored after the command finishes. Overlapping
1494
+ * programmatic runs in one process may share a direction (both `--color` or
1495
+ * both `--no-color`); the ambient values are restored once all runs finish.
1496
+ * An overlapping run with the opposing flag throws a `CrustError` in
1497
+ * `preRun`, because the env is process-global and cannot hold both values.
1496
1498
  */
1497
1499
  const noColor = defineExtension(NO_COLOR, () => ({
1498
1500
  flags: colorFlags,
@@ -1500,6 +1502,12 @@ const noColor = defineExtension(NO_COLOR, () => ({
1500
1502
  preRun(context) {
1501
1503
  const flagValue = context.flags.color;
1502
1504
  if (flagValue !== true && flagValue !== false) return;
1505
+ if (activeRuns > 0 && activeFlag !== flagValue) throw new CrustError("DEFINITION", "noColor: cannot start a --color run while a --no-color run is in flight (or vice versa); opposing overlapping runs share process.env", {
1506
+ subject: "extension",
1507
+ name: NO_COLOR,
1508
+ reason: "opposing-overlap"
1509
+ });
1510
+ activeFlag = flagValue;
1503
1511
  if (activeRuns === 0) {
1504
1512
  baseForceColor = process.env.FORCE_COLOR;
1505
1513
  baseNoColor = process.env.NO_COLOR;
@@ -1519,6 +1527,7 @@ const noColor = defineExtension(NO_COLOR, () => ({
1519
1527
  colorRuns.delete(context);
1520
1528
  activeRuns--;
1521
1529
  if (activeRuns === 0) {
1530
+ activeFlag = void 0;
1522
1531
  if (baseForceColor === void 0) delete process.env.FORCE_COLOR;
1523
1532
  else process.env.FORCE_COLOR = baseForceColor;
1524
1533
  if (baseNoColor === void 0) delete process.env.NO_COLOR;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crustjs/extensions",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "Official Extensions for the Crust CLI framework",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -47,16 +47,16 @@
47
47
  },
48
48
  "dependencies": {
49
49
  "@crustjs/store": "^0.4.0",
50
- "@crustjs/style": "^0.3.2"
50
+ "@crustjs/style": "^0.3.3"
51
51
  },
52
52
  "devDependencies": {
53
53
  "@crustjs/config": "0.0.0",
54
- "@crustjs/core": "0.3.0",
54
+ "@crustjs/core": "0.3.1",
55
55
  "@crustjs/utils": "0.0.0",
56
56
  "tsdown": "^0.23.0"
57
57
  },
58
58
  "peerDependencies": {
59
- "@crustjs/core": "^0.3.0",
59
+ "@crustjs/core": "^0.3.1",
60
60
  "typescript": "^7.0.0"
61
61
  },
62
62
  "peerDependenciesMeta": {