Skip to content

Commit

Permalink
refactor(core): switch from sync to async
Browse files Browse the repository at this point in the history
Refs #164
  • Loading branch information
JamieMason committed Dec 29, 2023
1 parent 419a254 commit 58f8bcb
Show file tree
Hide file tree
Showing 33 changed files with 813 additions and 811 deletions.
2 changes: 1 addition & 1 deletion src/bin-fix-mismatches/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ program
.option(...option.indent)
.parse(process.argv);

Effect.runSync<never, unknown>(
Effect.runPromise<never, unknown>(
fixMismatches({
io,
cli: {
Expand Down
24 changes: 12 additions & 12 deletions src/bin-format/format.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { expect, it } from 'vitest';
import { createScenario } from '../../test/lib/create-scenario';
import { format } from './format';

it('uses github shorthand format for "repository"', () => {
it('uses github shorthand format for "repository"', async () => {
const scenario = createScenario({
'package.json': {
name: 'a',
Expand All @@ -13,7 +13,7 @@ it('uses github shorthand format for "repository"', () => {
},
},
})();
Effect.runSyncExit(format(scenario));
await Effect.runPromiseExit(format(scenario));

expect(scenario.readPackages()).toHaveProperty('a', {
name: 'a',
Expand All @@ -22,7 +22,7 @@ it('uses github shorthand format for "repository"', () => {
expect(scenario.io.process.exit).not.toHaveBeenCalled();
});

it('retains long form format for "repository" when directory property used', () => {
it('retains long form format for "repository" when directory property used', async () => {
const scenario = createScenario({
'package.json': {
name: 'a',
Expand All @@ -33,7 +33,7 @@ it('retains long form format for "repository" when directory property used', ()
},
},
})();
Effect.runSyncExit(format(scenario));
await Effect.runPromiseExit(format(scenario));
expect(scenario.readPackages()).toHaveProperty('a', {
name: 'a',
repository: {
Expand All @@ -45,7 +45,7 @@ it('retains long form format for "repository" when directory property used', ()
expect(scenario.io.process.exit).not.toHaveBeenCalled();
});

it('uses shorthand format for "bugs" and "repository"', () => {
it('uses shorthand format for "bugs" and "repository"', async () => {
const scenario = createScenario({
'package.json': {
name: 'a',
Expand All @@ -58,7 +58,7 @@ it('uses shorthand format for "bugs" and "repository"', () => {
},
},
})();
Effect.runSyncExit(format(scenario));
await Effect.runPromiseExit(format(scenario));
expect(scenario.readPackages()).toHaveProperty('a', {
name: 'a',
bugs: 'https://github.com/User/repo/issues',
Expand All @@ -67,7 +67,7 @@ it('uses shorthand format for "bugs" and "repository"', () => {
expect(scenario.io.process.exit).not.toHaveBeenCalled();
});

it('sorts object properties alphabetically by key', () => {
it('sorts object properties alphabetically by key', async () => {
const scenario = createScenario({
'.syncpackrc': {
sortAz: ['scripts'],
Expand All @@ -80,15 +80,15 @@ it('sorts object properties alphabetically by key', () => {
},
},
})();
Effect.runSyncExit(format(scenario));
await Effect.runPromiseExit(format(scenario));
expect(scenario.readPackages()).toHaveProperty('a.scripts', {
A: '',
B: '',
});
expect(scenario.io.process.exit).not.toHaveBeenCalled();
});

it('sorts array members alphabetically by value', () => {
it('sorts array members alphabetically by value', async () => {
const scenario = createScenario({
'.syncpackrc': {
sortAz: ['keywords'],
Expand All @@ -98,15 +98,15 @@ it('sorts array members alphabetically by value', () => {
keywords: ['B', 'A'],
},
})();
Effect.runSyncExit(format(scenario));
await Effect.runPromiseExit(format(scenario));
expect(scenario.readPackages()).toHaveProperty('a', {
name: 'a',
keywords: ['A', 'B'],
});
expect(scenario.io.process.exit).not.toHaveBeenCalled();
});

it('sorts named properties first, then the rest alphabetically', () => {
it('sorts named properties first, then the rest alphabetically', async () => {
const scenario = createScenario({
'.syncpackrc': {
sortFirst: ['name', 'F', 'E', 'D'],
Expand All @@ -120,7 +120,7 @@ it('sorts named properties first, then the rest alphabetically', () => {
E: '',
},
})();
Effect.runSyncExit(format(scenario));
await Effect.runPromiseExit(format(scenario));
expect(scenario.readPackages()).toHaveProperty('a', {
name: 'a',
F: '',
Expand Down
2 changes: 1 addition & 1 deletion src/bin-format/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ program
.option(...option.indent)
.parse(process.argv);

Effect.runSync<never, unknown>(
Effect.runPromise<never, unknown>(
format({
io,
cli: {
Expand Down
2 changes: 1 addition & 1 deletion src/bin-lint-semver-ranges/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ program
.option(...option.types)
.parse(process.argv);

Effect.runSync<never, unknown>(
Effect.runPromise<never, unknown>(
lintSemverRanges({
io,
cli: {
Expand Down
2 changes: 1 addition & 1 deletion src/bin-lint/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ showHelpOnError(program);

program.option(...option.config).parse(process.argv);

Effect.runSync<never, unknown>(
Effect.runPromise<never, unknown>(
lint({
io,
cli: {
Expand Down
2 changes: 1 addition & 1 deletion src/bin-list-mismatches/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ program
.option(...option.types)
.parse(process.argv);

Effect.runSync<never, unknown>(
Effect.runPromise<never, unknown>(
listMismatches({
io,
cli: {
Expand Down
2 changes: 1 addition & 1 deletion src/bin-list/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ program
.option(...option.types)
.parse(process.argv);

Effect.runSync<never, unknown>(
Effect.runPromise<never, unknown>(
list({
io,
cli: {
Expand Down
2 changes: 1 addition & 1 deletion src/bin-set-semver-ranges/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ program
.option(...option.indent)
.parse(process.argv);

Effect.runSync<never, unknown>(
Effect.runPromise<never, unknown>(
setSemverRanges({
io,
cli: {
Expand Down
4 changes: 2 additions & 2 deletions src/bin-set-semver-ranges/set-semver-ranges.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ describe('when a semver group contains mismatches', () => {
});

describe('set-semver-ranges', () => {
it('fixes all dependencies to use "*", except for .version properties', () => {
it('fixes all dependencies to use "*", except for .version properties', async () => {
const scenario = getScenario();
Effect.runSyncExit(setSemverRanges(scenario));
await Effect.runPromiseExit(setSemverRanges(scenario));
const filesByName = scenario.readPackages();
expect(filesByName).toHaveProperty('a.version', '0.0.1');
expect(filesByName).toHaveProperty('a.dependencies.foo', '*');
Expand Down
64 changes: 32 additions & 32 deletions src/config/get-enabled-types.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ const nameAndVersion = expect.objectContaining({
path: 'version',
});

it('defaults to all when nothing is provided', () => {
it('defaults to all when nothing is provided', async () => {
expect(
Effect.runSync(
await Effect.runPromise(
pipe(
getEnabledTypes({
cli: {},
Expand All @@ -53,9 +53,9 @@ it('defaults to all when nothing is provided', () => {
).toEqual([dev, local, overrides, peerDependencies, pnpmOverrides, prod, resolutions]);
});

it('uses every type except a negated type such as "!prod"', () => {
it('uses every type except a negated type such as "!prod"', async () => {
expect(
Effect.runSync(
await Effect.runPromise(
pipe(
getEnabledTypes({
cli: {
Expand All @@ -69,9 +69,9 @@ it('uses every type except a negated type such as "!prod"', () => {
).toEqual([dev, local, overrides, peerDependencies, pnpmOverrides, resolutions]);
});

it('handles multiple negated types', () => {
it('handles multiple negated types', async () => {
expect(
Effect.runSync(
await Effect.runPromise(
pipe(
getEnabledTypes({
cli: {
Expand All @@ -85,9 +85,9 @@ it('handles multiple negated types', () => {
).toEqual([local, overrides, peerDependencies, pnpmOverrides, resolutions]);
});

it('uses only provided type when defined', () => {
it('uses only provided type when defined', async () => {
expect(
Effect.runSync(
await Effect.runPromise(
pipe(
getEnabledTypes({
cli: {
Expand All @@ -101,9 +101,9 @@ it('uses only provided type when defined', () => {
).toEqual([dev]);
});

it('handles multiple types', () => {
it('handles multiple types', async () => {
expect(
Effect.runSync(
await Effect.runPromise(
pipe(
getEnabledTypes({
cli: {
Expand All @@ -117,9 +117,9 @@ it('handles multiple types', () => {
).toEqual([dev, peerDependencies]);
});

it('gives precedence to cli options', () => {
it('gives precedence to cli options', async () => {
expect(
Effect.runSync(
await Effect.runPromise(
pipe(
getEnabledTypes({
cli: {
Expand All @@ -135,9 +135,9 @@ it('gives precedence to cli options', () => {
).toEqual([dev]);
});

it('includes custom types when others are negated', () => {
it('includes custom types when others are negated', async () => {
expect(
Effect.runSync(
await Effect.runPromise(
pipe(
getEnabledTypes({
cli: {
Expand All @@ -158,9 +158,9 @@ it('includes custom types when others are negated', () => {
).toEqual([local, overrides, peerDependencies, pnpmOverrides, prod, resolutions, engines]);
});

it('includes custom types when named', () => {
it('includes custom types when named', async () => {
expect(
Effect.runSync(
await Effect.runPromise(
pipe(
getEnabledTypes({
cli: {},
Expand All @@ -180,9 +180,9 @@ it('includes custom types when named', () => {
).toEqual([dev, engines]);
});

it('includes every type when "**" is provided', () => {
it('includes every type when "**" is provided', async () => {
expect(
Effect.runSync(
await Effect.runPromise(
pipe(
getEnabledTypes({
cli: {
Expand All @@ -203,9 +203,9 @@ it('includes every type when "**" is provided', () => {
).toEqual([dev, local, overrides, peerDependencies, pnpmOverrides, prod, resolutions, engines]);
});

it('includes every kind of custom type when named', () => {
it('includes every kind of custom type when named', async () => {
expect(
Effect.runSync(
await Effect.runPromise(
pipe(
getEnabledTypes({
cli: {},
Expand Down Expand Up @@ -238,9 +238,9 @@ it('includes every kind of custom type when named', () => {
).toEqual([dev, engines, packageManager, specificEngine, nameAndVersion]);
});

it('returns error when deprecated boolean configs are used', () => {
it('returns error when deprecated boolean configs are used', async () => {
expect(
Effect.runSync(
await Effect.runPromise(
pipe(
getEnabledTypes({
cli: {},
Expand All @@ -258,9 +258,9 @@ it('returns error when deprecated boolean configs are used', () => {
);
});

it('returns error when deprecated "workspace" name is used', () => {
it('returns error when deprecated "workspace" name is used', async () => {
expect(
Effect.runSync(
await Effect.runPromise(
pipe(
getEnabledTypes({
cli: {},
Expand All @@ -274,9 +274,9 @@ it('returns error when deprecated "workspace" name is used', () => {
).toEqual(new RenamedWorkspaceTypeError({}));
});

it('returns error when custom type is not an object', () => {
it('returns error when custom type is not an object', async () => {
expect(
Effect.runSync(
await Effect.runPromise(
pipe(
getEnabledTypes({
cli: {},
Expand All @@ -297,9 +297,9 @@ it('returns error when custom type is not an object', () => {
);
});

it('returns error when custom type has invalid path', () => {
it('returns error when custom type has invalid path', async () => {
expect(
Effect.runSync(
await Effect.runPromise(
pipe(
getEnabledTypes({
cli: {},
Expand All @@ -320,9 +320,9 @@ it('returns error when custom type has invalid path', () => {
);
});

it('returns error when custom type has invalid strategy', () => {
it('returns error when custom type has invalid strategy', async () => {
expect(
Effect.runSync(
await Effect.runPromise(
pipe(
getEnabledTypes({
cli: {},
Expand All @@ -347,9 +347,9 @@ it('returns error when custom type has invalid strategy', () => {
);
});

it('returns error when custom name~version strategy has invalid path', () => {
it('returns error when custom name~version strategy has invalid path', async () => {
expect(
Effect.runSync(
await Effect.runPromise(
pipe(
getEnabledTypes({
cli: {},
Expand Down

0 comments on commit 58f8bcb

Please sign in to comment.