Skip to content
This repository has been archived by the owner on Mar 15, 2024. It is now read-only.

Commit

Permalink
refactor: allow object in default-process config field
Browse files Browse the repository at this point in the history
It is confusing to the user why he cannot use an object for `default-process`:

```yaml
process:
  path: *.js
  enabled: true
default-process:
  enabled: false
```

I changed to internal representation of processes as well from boolean to the object. It is more explicit and more flexible should we add more information to processes.
  • Loading branch information
lachrist committed Mar 3, 2023
1 parent e5caf45 commit c2c2acd
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 8 deletions.
3 changes: 2 additions & 1 deletion components/configuration-accessor/default/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ export const isConfigurationEnabled = ({
processes,
main,
"default-process": default_process,
}) => main === null || lookupSpecifier(processes, main, default_process);
}) =>
main === null || lookupSpecifier(processes, main, default_process).enabled;

export const getConfigurationPackage = (
{ packages, "default-package": default_package },
Expand Down
17 changes: 14 additions & 3 deletions components/configuration/default/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@ const extendCommandOptions = (options1, options2) => ({
// Normalize //
///////////////

const normalizeDefaultProcess = (default_process, _base) => {
if (typeof default_process === "boolean") {
return { enabled: default_process };
} else {
return {
enabled: false,
...default_process,
};
}
};

const normalizeExclusion = (exclusion, _base) => {
if (typeof exclusion === "string") {
exclusion = {
Expand Down Expand Up @@ -218,7 +229,7 @@ const normalizeProcessSpecifier = (specifier, base) => {
enabled: true,
...specifier,
};
return [createSpecifier(rest, base), enabled];
return [createSpecifier(rest, base), { enabled }];
};

const normalizeProcesses = (specifiers, base) => {
Expand Down Expand Up @@ -333,7 +344,7 @@ const fields = {
},
"default-process": {
extend: overwrite,
normalize: identity,
normalize: normalizeDefaultProcess,
},
processes: {
extend: prepend,
Expand Down Expand Up @@ -486,7 +497,7 @@ export const createConfiguration = (home) => ({
},
appmap_dir: toAbsoluteUrl("tmp/appmap/", home),
appmap_file: null,
"default-process": true,
"default-process": { enabled: true },
processes: [],
recorder: null,
"postmortem-function-exclusion": null,
Expand Down
24 changes: 23 additions & 1 deletion components/configuration/default/index.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -231,14 +231,36 @@ assertDeepEqual(
],
);

// default-process //

assertDeepEqual(
extend(
"default-process",
true,
"protocol://host/base/",
"protocol://host/home",
),
{ enabled: true },
);

assertDeepEqual(
extend(
"default-process",
{ enabled: true },
"protocol://host/base/",
"protocol://host/home",
),
{ enabled: true },
);

// processes //

assertDeepEqual(
extend("processes", "/foo", "protocol://host/base/", "protocol://host/home"),
[
[
{ base: "protocol://host/base/", source: "^(?:\\/foo)$", flags: "" },
true,
{ enabled: true },
],
],
);
Expand Down
4 changes: 3 additions & 1 deletion schema/definitions/configuration-external.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ properties:
ordering:
$ref: ordering
default-process:
type: boolean
anyOf:
- type: boolean
- $ref: process
processes:
anyOf:
- $ref: specifier-process
Expand Down
4 changes: 2 additions & 2 deletions schema/definitions/configuration-internal.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ properties:
ordering:
$ref: ordering
default-process:
type: boolean
$ref: process
processes:
type: array
items:
Expand All @@ -134,7 +134,7 @@ properties:
maxItems: 2
items:
- $ref: specifier-cooked
- type: boolean
- $ref: process
main:
anyOf:
- const: null
Expand Down
7 changes: 7 additions & 0 deletions schema/definitions/process.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
type: object
additionalProperties: false
required:
- enabled
properties:
enabled:
type: boolean

0 comments on commit c2c2acd

Please sign in to comment.