Skip to content

Commit

Permalink
refactor(core): huge internal refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
JamieMason committed Feb 16, 2020
1 parent 5fdcc7b commit beee8ad
Show file tree
Hide file tree
Showing 72 changed files with 1,172 additions and 1,905 deletions.
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"arrowParens": "always",
"printWidth": 80,
"printWidth": 120,
"proseWrap": "always",
"singleQuote": true,
"trailingComma": "all"
Expand Down
24 changes: 17 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Ensure that multiple packages requiring the same dependency define the same vers
-p, --prod include dependencies
-d, --dev include devDependencies
-P, --peer include peerDependencies
-f, --filter [pattern] regex for dependency filter
-i, --indent [value] override indentation. defaults to " "
-h, --help output usage information

Expand All @@ -54,11 +55,11 @@ syncpack fix-mismatches
syncpack fix-mismatches --source "apps/*/package.json"
# multiple globs can be provided like this
syncpack fix-mismatches --source "apps/*/package.json" --source "core/*/package.json"
# uses packages that pass the regex defined by --filter when provided
syncpack fix-mismatches --filter "^package_name$"
# only fix "devDependencies"
# uses dependencies regular expression defined by --filter when provided
syncpack fix-mismatches --filter "typescript|tslint"
# only inspect "devDependencies"
syncpack fix-mismatches --dev
# only fix "devDependencies" and "peerDependencies"
# only inspect "devDependencies" and "peerDependencies"
syncpack fix-mismatches --dev --peer
# indent package.json with 4 spaces instead of 2
syncpack fix-mismatches --indent " "
Expand Down Expand Up @@ -106,6 +107,7 @@ List all dependencies required by your packages.
-p, --prod include dependencies
-d, --dev include devDependencies
-P, --peer include peerDependencies
-f, --filter [pattern] regex for dependency filter
-h, --help output usage information

</details>
Expand All @@ -120,6 +122,8 @@ syncpack list
syncpack list --source "apps/*/package.json"
# multiple globs can be provided like this
syncpack list --source "apps/*/package.json" --source "core/*/package.json"
# uses dependencies regular expression defined by --filter when provided
syncpack list --filter "typescript|tslint"
# only inspect "devDependencies"
syncpack list --dev
# only inspect "devDependencies" and "peerDependencies"
Expand All @@ -139,6 +143,7 @@ List dependencies which are required by multiple packages, where the version is
-p, --prod include dependencies
-d, --dev include devDependencies
-P, --peer include peerDependencies
-f, --filter [pattern] regex for dependency filter
-h, --help output usage information

</details>
Expand All @@ -153,9 +158,11 @@ syncpack list-mismatches
syncpack list-mismatches --source "apps/*/package.json"
# multiple globs can be provided like this
syncpack list-mismatches --source "apps/*/package.json" --source "core/*/package.json"
# only list "devDependencies"
# uses dependencies regular expression defined by --filter when provided
syncpack list-mismatches --filter "typescript|tslint"
# only inspect "devDependencies"
syncpack list-mismatches --dev
# only list "devDependencies" and "peerDependencies"
# only inspect "devDependencies" and "peerDependencies"
syncpack list-mismatches --dev --peer
```

Expand All @@ -168,12 +175,13 @@ Ensure dependency versions used within `"dependencies"`, `"devDependencies"`, an
<details>
<summary>Options</summary>

-r, --semver-range <range> <, <=, "", ~, ^, >=, >, or *. defaults to ""
-s, --source [pattern] glob pattern for package.json files to read from
-p, --prod include dependencies
-d, --dev include devDependencies
-P, --peer include peerDependencies
-f, --filter [pattern] regex for dependency filter
-i, --indent [value] override indentation. defaults to " "
-r, --semver-range <range> see supported ranges below. defaults to ""
-h, --help output usage information

</details>
Expand All @@ -188,6 +196,8 @@ syncpack set-semver-ranges
syncpack set-semver-ranges --source "apps/*/package.json"
# multiple globs can be provided like this
syncpack set-semver-ranges --source "apps/*/package.json" --source "core/*/package.json"
# uses dependencies regular expression defined by --filter when provided
syncpack set-semver-ranges --filter "typescript|tslint"
# use ~ range instead of default ""
syncpack set-semver-ranges --semver-range ~
# set ~ range in "devDependencies"
Expand Down
1 change: 0 additions & 1 deletion global.d.ts

This file was deleted.

17 changes: 8 additions & 9 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
module.exports = {
collectCoverage: true,
collectCoverageFrom: ['src/**/*.ts', '!src/**/typings.ts', '!src/**/bin*.ts'],
collectCoverageFrom: ['src/**/*.ts', '!src/**/bin*.ts'],
coverageReporters: ['html', 'lcov'],
coverageThreshold: {
global: {
branches: 95,
functions: 95,
lines: 95,
statements: 95
}
branches: 82,
functions: 72,
lines: 81,
statements: 77,
},
},
moduleFileExtensions: ['ts', 'tsx', 'js'],
setupFilesAfterEnv: ['<rootDir>/test/setup.ts'],
testMatch: ['<rootDir>/src/**/*.spec.(ts|tsx|js)'],
transform: {
'^.+\\.tsx?$': 'ts-jest'
}
'^.+\\.tsx?$': 'ts-jest',
},
};
91 changes: 45 additions & 46 deletions src/bin-fix-mismatches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,62 +2,61 @@

import chalk from 'chalk';
import program = require('commander');
import { run } from './fix-mismatches';
import { fixMismatchesToDisk } from './commands/fix-mismatches';
import { option } from './constants';

program.description(
`
Ensure that multiple packages requiring the same dependency define the same
version, so that every package requires eg. react@16.4.2, instead of a
combination of react@16.4.2, react@0.15.9, and react@16.0.0.`.replace(
/^\n/,
'',
),
combination of react@16.4.2, react@0.15.9, and react@16.0.0.`.replace(/^\n/, ''),
);

program.on('--help', () => {
console.log('');
console.log(`Examples:
${chalk.grey('# uses defaults for resolving packages')}
console.log(chalk`
Resolving Packages:
1. If {yellow --source} globs are provided, use those.
2. If using Yarn Workspaces, read {yellow workspaces} from {yellow package.json}.
3. If using Lerna, read {yellow packages} from {yellow lerna.json}.
4. Default to {yellow "package.json"} and {yellow "packages/*/package.json"}.
Examples:
{dim # uses defaults for resolving packages}
syncpack fix-mismatches
${chalk.grey('# uses packages defined by --source when provided')}
syncpack fix-mismatches --source ${chalk.yellow('"apps/*/package.json"')}
${chalk.grey(
'# uses dependencies regular expression defined by --filter when provided',
)}
syncpack fix-mismatches --filter ${chalk.yellow('"typescript|tslint"')}
${chalk.grey('# multiple globs can be provided like this')}
syncpack fix-mismatches --source ${chalk.yellow(
'"apps/*/package.json"',
)} --source ${chalk.yellow('"core/*/package.json"')}
${chalk.grey('# only fix "devDependencies"')}
{dim # uses packages defined by --source when provided}
syncpack fix-mismatches --source {yellow "apps/*/package.json"}
{dim # multiple globs can be provided like this}
syncpack fix-mismatches --source {yellow "apps/*/package.json"} --source {yellow "core/*/package.json"}
{dim # uses dependencies regular expression defined by --filter when provided}
syncpack fix-mismatches --filter {yellow "typescript|tslint"}
{dim # only inspect "devDependencies"}
syncpack fix-mismatches --dev
${chalk.grey('# only fix "devDependencies" and "peerDependencies"')}
{dim # only inspect "devDependencies" and "peerDependencies"}
syncpack fix-mismatches --dev --peer
${chalk.grey('# indent package.json with 4 spaces instead of 2')}
syncpack fix-mismatches --indent ${chalk.yellow('" "')}
`);
console.log(`Resolving Packages:
1. If ${chalk.yellow(`--source`)} globs are provided, use those.
2. If using Yarn Workspaces, read ${chalk.yellow(
`workspaces`,
)} from ${chalk.yellow(`package.json`)}.
3. If using Lerna, read ${chalk.yellow(`packages`)} from ${chalk.yellow(
`lerna.json`,
)}.
4. Default to ${chalk.yellow(`"package.json"`)} and ${chalk.yellow(
`"packages/*/package.json"`,
)}.
`);
console.log(`Reference:
globs ${chalk.blue.underline(
'https://github.com/isaacs/node-glob#glob-primer',
)}
lerna.json ${chalk.blue.underline(
'https://github.com/lerna/lerna#lernajson',
)}
Yarn Workspaces ${chalk.blue.underline(
'https://yarnpkg.com/lang/en/docs/workspaces',
)}`);
{dim # indent package.json with 4 spaces instead of 2}
syncpack fix-mismatches --indent {yellow " "}
Reference:
globs {blue.underline https://github.com/isaacs/node-glob#glob-primer}
lerna.json {blue.underline https://github.com/lerna/lerna#lernajson}
Yarn Workspaces {blue.underline https://yarnpkg.com/lang/en/docs/workspaces}
`);
});

run(program);
program
.option(...option.source)
.option(...option.prod)
.option(...option.dev)
.option(...option.peer)
.option(...option.filter)
.option(...option.indent)
.parse(process.argv);

fixMismatchesToDisk({
dev: Boolean(program.dev),
filter: new RegExp(program.filter ? program.filter : '.'),
indent: program.indent ? program.indent : ' ',
peer: Boolean(program.peer),
prod: Boolean(program.prod),
source: Array.isArray(program.source) ? program.source : [],
});
68 changes: 32 additions & 36 deletions src/bin-format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

import chalk from 'chalk';
import program = require('commander');
import { run } from './format';
import { formatToDisk } from './commands/format';
import { option } from './constants';

program.description(
`
Expand All @@ -13,41 +14,36 @@ program.description(
);

program.on('--help', () => {
console.log('');
console.log(`Examples:
${chalk.grey('# uses defaults for resolving packages')}
console.log(chalk`
Examples:
{dim # uses defaults for resolving packages}
syncpack format
${chalk.grey('# uses packages defined by --source when provided')}
syncpack format --source ${chalk.yellow('"apps/*/package.json"')}
${chalk.grey('# multiple globs can be provided like this')}
syncpack format --source ${chalk.yellow(
'"apps/*/package.json"',
)} --source ${chalk.yellow('"core/*/package.json"')}
${chalk.grey('# indent package.json with 4 spaces instead of 2')}
syncpack format --indent ${chalk.yellow('" "')}
`);
console.log(`Resolving Packages:
1. If ${chalk.yellow(`--source`)} globs are provided, use those.
2. If using Yarn Workspaces, read ${chalk.yellow(
`workspaces`,
)} from ${chalk.yellow(`package.json`)}.
3. If using Lerna, read ${chalk.yellow(`packages`)} from ${chalk.yellow(
`lerna.json`,
)}.
4. Default to ${chalk.yellow(`"package.json"`)} and ${chalk.yellow(
`"packages/*/package.json"`,
)}.
`);
console.log(`Reference:
globs ${chalk.blue.underline(
'https://github.com/isaacs/node-glob#glob-primer',
)}
lerna.json ${chalk.blue.underline(
'https://github.com/lerna/lerna#lernajson',
)}
Yarn Workspaces ${chalk.blue.underline(
'https://yarnpkg.com/lang/en/docs/workspaces',
)}`);
{dim # uses packages defined by --source when provided}
syncpack format --source {yellow "apps/*/package.json"}
{dim # multiple globs can be provided like this}
syncpack format --source {yellow "apps/*/package.json"} --source {yellow "core/*/package.json"}
{dim # indent package.json with 4 spaces instead of 2}
syncpack format --indent {yellow " "}
Resolving Packages:
1. If {yellow --source} globs are provided, use those.
2. If using Yarn Workspaces, read {yellow workspaces} from {yellow package.json}.
3. If using Lerna, read {yellow packages} from {yellow lerna.json}.
4. Default to {yellow "package.json"} and {yellow "packages/*/package.json"}.
Reference:
globs {blue.underline https://github.com/isaacs/node-glob#glob-primer}
lerna.json {blue.underline https://github.com/lerna/lerna#lernajson}
Yarn Workspaces {blue.underline https://yarnpkg.com/lang/en/docs/workspaces}
`);
});

run(program);
program
.option(...option.source)
.option(...option.indent)
.parse(process.argv);

formatToDisk({
indent: program.indent ? program.indent : ' ',
source: Array.isArray(program.source) ? program.source : [],
});

0 comments on commit beee8ad

Please sign in to comment.