Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a new "explain" logger #863

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@ Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Changed

- When running in watch mode, a persistent service will now restart on each run if it does not have a `files` field in its config. This makes persistent services better match the behavior of standard scripts and ephemeral services.

### Added

- Added a new logger for debugging your Wireit configs. Set `WIREIT_LOGGER=explain` to see detailed information about why each script is run, as well as the normal `simple` logs, without any stdout or stderr of scripts.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like a little more information is also added to the default logger in this PR (and I think simple logger, since it delegates to default sometimes?). Mention that too in a separate line?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


- Added more "why" information to the `simple` and `metrics` loggers as well, including why a service was restarted, and what file change triggered a new run in watch mode.
- Added more "why" explanations to the `simple` and `metrics` loggers as well, including why a service was restarted, and what file change triggered a new run in watch mode.

### Fixed

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ the given regular expression.

In watch mode, a service will be restarted whenever one of its input files or
dependencies change, except for dependencies with
[`cascade`](#execution-cascade) set to `false`. Unlike standard scripts, `wireit` assumes that a service doesn't depend on any files unless you tell it otherwise by defining a `files` array.
[`cascade`](#execution-cascade) set to `false`.

### Service output

Expand Down
6 changes: 3 additions & 3 deletions src/fingerprint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,16 +209,16 @@ export class Fingerprint {
if (script.command === undefined) {
return undefined;
}
if (script.files === undefined) {
return {name: 'no files field'};
}
// A service. Always fully tracked. No 'files' means that we
// assume that it writes no files. Can't produce output.
if (script.service !== undefined) {
return undefined;
}
// A standard script. Fully tracked if we know both its inputs and
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this comment be just above (above if (script.files === undefined) {) ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yes!

// outputs.
if (script.files === undefined) {
return {name: 'no files field'};
}
if (script.output === undefined) {
return {name: 'no output field'};
}
Expand Down
6 changes: 2 additions & 4 deletions src/logging/default-logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,15 +373,13 @@ export class DefaultLogger implements Logger {
);
}
case 'dependency not fully tracked': {
return `the service depends on [${labelForScript(
return `it depends on [${labelForScript(
this.rootPackageDir,
stringToScriptReference(notFullyTrackedReason.dependency),
)}] which must always be run`;
}
case 'no files field': {
throw new Error(
'Internal error: a service is tracked even without a files field',
);
return `it has no 'files' field`;
}
case 'no output field': {
throw new Error('Internal error: a service never has output');
Expand Down
3 changes: 3 additions & 0 deletions src/test/gc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ async function retryWithGcUntilCallbackDoesNotThrow(
cb: () => void,
): Promise<void> {
for (const wait of [0, 10, 100, 500, 1000]) {
collectGarbage();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 GC not enough?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Surprisingly, it often isn't. When doing memory leak tests in Lit we found that memory is often not freed unless you call gc twice in a row.

🤷

collectGarbage();
try {
cb();
Expand Down Expand Up @@ -251,10 +252,12 @@ test(
servicePersistent: {
command: servicePersistent.command,
service: true,
files: [],
},
serviceEphemeral: {
command: serviceEphemeral.command,
service: true,
files: [],
},
},
},
Expand Down
10 changes: 6 additions & 4 deletions src/test/service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,7 @@ for (const failureMode of ['continue', 'no-new']) {
},
service: {
command: service.command,
files: [],
service: true,
},
standard: {
Expand Down Expand Up @@ -833,10 +834,12 @@ test(
service1: {
command: service1.command,
dependencies: ['service2'],
files: [],
service: true,
},
service2: {
command: service2.command,
files: [],
service: true,
},
standard: {
Expand All @@ -849,9 +852,7 @@ test(

await rig.write('input', '0');
const wireit = rig.exec('npm run entrypoint --watch');
await wireit.waitForLog(
/67% \[2 \/ 3\] \[3 running\] \[2 services\] standard/,
);
await wireit.waitForLog(/67% \[2 \/ 3\] \[3 running\] \[2 services\]/);

// Iteration 1
{
Expand Down Expand Up @@ -1146,6 +1147,7 @@ test(
service: {
command: service.command,
service: true,
files: [],
dependencies: [
'hard',
{
Expand Down Expand Up @@ -1413,7 +1415,7 @@ test(
await wireit.waitForLog(/\[standard\] Executed successfully/);
await service.nextInvocation();
await wireit.waitForLog(
/\[service\] Service stopped because the service depends on \[standard\] which must always be run/,
/\[service\] Service stopped because it depends on \[standard\] which must always be run/,
);
await wireit.waitForLog(/\[service\] Service starting.../);
await wireit.waitForLog(/\[service\] Service ready/);
Expand Down
1 change: 1 addition & 0 deletions vscode-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"..:build"
],
"files": [
".tsbuildinfo",
"tsconfig.json",
"src/**/*.ts"
],
Expand Down