syncpack 12.2.0 → 12.3.0

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/README.md CHANGED
@@ -1,10 +1,10 @@
1
1
  # syncpack
2
2
 
3
- <center>
4
- <img src="https://jamiemason.github.io/syncpack/logo.svg" width="200" height="179" alt="" />
5
- <div>Consistent dependency versions in large JavaScript Monorepos.</div>
6
- <div><a href="https://jamiemason.github.io/syncpack">https://jamiemason.github.io/syncpack</a></div>
7
- </center>
3
+ <p align="center">
4
+ <img src="https://jamiemason.github.io/syncpack/logo.svg" width="200" height="179" alt="">
5
+ <br>Consistent dependency versions in large JavaScript Monorepos.
6
+ <br><a href="https://jamiemason.github.io/syncpack">https://jamiemason.github.io/syncpack</a>
7
+ </p>
8
8
 
9
9
  ## Installation
10
10
 
@@ -1,6 +1,7 @@
1
1
  import { Effect } from 'effect';
2
2
  import { type CliConfig } from '../config/types';
3
3
  import type { ErrorHandlers } from '../error-handlers/default-error-handlers';
4
+ import type { Ctx } from '../get-context';
4
5
  import type { Io } from '../io';
5
6
  interface Input {
6
7
  io: Io;
@@ -8,4 +9,5 @@ interface Input {
8
9
  errorHandlers?: ErrorHandlers;
9
10
  }
10
11
  export declare function format({ io, cli, errorHandlers }: Input): Effect.Effect<never, never, unknown>;
12
+ export declare function pipeline(ctx: Ctx): Effect.Effect<never, never, Ctx>;
11
13
  export {};
@@ -1,11 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.format = void 0;
3
+ exports.pipeline = exports.format = void 0;
4
4
  const effect_1 = require("effect");
5
5
  const is_array_1 = require("tightrope/guard/is-array");
6
6
  const is_non_empty_string_1 = require("tightrope/guard/is-non-empty-string");
7
7
  const is_object_1 = require("tightrope/guard/is-object");
8
8
  const get_sort_az_1 = require("../config/get-sort-az");
9
+ const get_sort_exports_1 = require("../config/get-sort-exports");
9
10
  const get_sort_first_1 = require("../config/get-sort-first");
10
11
  const tag_1 = require("../config/tag");
11
12
  const default_error_handlers_1 = require("../error-handlers/default-error-handlers");
@@ -15,50 +16,79 @@ const exit_if_invalid_1 = require("../io/exit-if-invalid");
15
16
  const write_if_changed_1 = require("../io/write-if-changed");
16
17
  const with_logger_1 = require("../lib/with-logger");
17
18
  function format({ io, cli, errorHandlers = default_error_handlers_1.defaultErrorHandlers }) {
18
- return (0, effect_1.pipe)((0, get_context_1.getContext)({ io, cli, errorHandlers }), effect_1.Effect.map((ctx) => {
19
- const { packageJsonFiles } = ctx;
20
- const sortAz = (0, get_sort_az_1.getSortAz)(ctx.config);
21
- const sortFirst = (0, get_sort_first_1.getSortFirst)(ctx.config);
22
- packageJsonFiles.forEach((file) => {
23
- const { contents } = file.jsonFile;
24
- const sortedKeys = Object.keys(contents).sort();
25
- const keys = new Set(sortFirst.concat(sortedKeys));
26
- const optionalChaining = contents;
27
- const bugsUrl = optionalChaining?.bugs?.url;
28
- const repoUrl = optionalChaining?.repository?.url;
29
- const repoDir = optionalChaining?.repository?.directory;
19
+ return (0, effect_1.pipe)((0, get_context_1.getContext)({ io, cli, errorHandlers }), effect_1.Effect.flatMap(pipeline), effect_1.Effect.flatMap((ctx) => (0, effect_1.pipe)((0, write_if_changed_1.writeIfChanged)(ctx), effect_1.Effect.catchTags({
20
+ WriteFileError: (0, effect_1.flow)(errorHandlers.WriteFileError, effect_1.Effect.map(() => {
21
+ ctx.isInvalid = true;
22
+ return ctx;
23
+ })),
24
+ }))), effect_1.Effect.flatMap(exit_if_invalid_1.exitIfInvalid), effect_1.Effect.provide((0, effect_1.pipe)(effect_1.Context.empty(), effect_1.Context.add(tag_1.CliConfigTag, cli), effect_1.Context.add(io_1.IoTag, io))), with_logger_1.withLogger);
25
+ }
26
+ exports.format = format;
27
+ function pipeline(ctx) {
28
+ const { config, packageJsonFiles } = ctx;
29
+ const sortAz = (0, get_sort_az_1.getSortAz)(config);
30
+ const sortExports = (0, get_sort_exports_1.getSortExports)(config);
31
+ const sortFirst = (0, get_sort_first_1.getSortFirst)(config);
32
+ const sortPackages = config.rcFile.sortPackages !== false;
33
+ const formatBugs = config.rcFile.formatBugs !== false;
34
+ const formatRepository = config.rcFile.formatRepository !== false;
35
+ packageJsonFiles.forEach((file) => {
36
+ const { contents } = file.jsonFile;
37
+ const chain = contents;
38
+ if (formatBugs) {
39
+ const bugsUrl = chain?.bugs?.url;
30
40
  if (bugsUrl) {
31
41
  contents.bugs = bugsUrl;
32
42
  }
43
+ }
44
+ if (formatRepository) {
45
+ const repoUrl = chain?.repository?.url;
46
+ const repoDir = chain?.repository?.directory;
33
47
  if ((0, is_non_empty_string_1.isNonEmptyString)(repoUrl) && !(0, is_non_empty_string_1.isNonEmptyString)(repoDir)) {
34
48
  contents.repository = repoUrl.includes('github.com')
35
49
  ? repoUrl.replace(/^.+github\.com\//, '')
36
50
  : repoUrl;
37
51
  }
52
+ }
53
+ if (sortExports.length > 0) {
54
+ visitExports(sortExports, contents.exports);
55
+ }
56
+ if (sortAz.length > 0) {
38
57
  sortAz.forEach((key) => sortAlphabetically(contents[key]));
39
- sortObject(keys, contents);
40
- });
41
- return ctx;
42
- function sortObject(sortedKeys, obj) {
43
- sortedKeys.forEach((key) => {
44
- const value = obj[key];
45
- delete obj[key];
46
- obj[key] = value;
47
- });
48
58
  }
49
- function sortAlphabetically(value) {
50
- if ((0, is_array_1.isArray)(value)) {
51
- value.sort();
52
- }
53
- else if ((0, is_object_1.isObject)(value)) {
54
- sortObject(Object.keys(value).sort(), value);
55
- }
59
+ if (sortPackages) {
60
+ const sortedKeys = Object.keys(contents).sort();
61
+ sortObject(sortedKeys, contents);
56
62
  }
57
- }), effect_1.Effect.flatMap((ctx) => (0, effect_1.pipe)((0, write_if_changed_1.writeIfChanged)(ctx), effect_1.Effect.catchTags({
58
- WriteFileError: (0, effect_1.flow)(errorHandlers.WriteFileError, effect_1.Effect.map(() => {
59
- ctx.isInvalid = true;
60
- return ctx;
61
- })),
62
- }))), effect_1.Effect.flatMap(exit_if_invalid_1.exitIfInvalid), effect_1.Effect.provide((0, effect_1.pipe)(effect_1.Context.empty(), effect_1.Context.add(tag_1.CliConfigTag, cli), effect_1.Context.add(io_1.IoTag, io))), with_logger_1.withLogger);
63
+ if (sortFirst.length > 0) {
64
+ const otherKeys = Object.keys(contents);
65
+ const sortedKeys = new Set([...sortFirst, ...otherKeys]);
66
+ sortObject(sortedKeys, contents);
67
+ }
68
+ });
69
+ return effect_1.Effect.succeed(ctx);
70
+ }
71
+ exports.pipeline = pipeline;
72
+ function visitExports(sortExports, value) {
73
+ if ((0, is_object_1.isObject)(value)) {
74
+ const otherKeys = Object.keys(value);
75
+ const sortedKeys = new Set([...sortExports, ...otherKeys]);
76
+ sortObject(sortedKeys, value);
77
+ Object.values(value).forEach((nextValue) => visitExports(sortExports, nextValue));
78
+ }
79
+ }
80
+ function sortObject(sortedKeys, obj) {
81
+ sortedKeys.forEach((key) => {
82
+ const value = obj[key];
83
+ delete obj[key];
84
+ obj[key] = value;
85
+ });
86
+ }
87
+ function sortAlphabetically(value) {
88
+ if ((0, is_array_1.isArray)(value)) {
89
+ value.sort();
90
+ }
91
+ else if ((0, is_object_1.isObject)(value)) {
92
+ sortObject(Object.keys(value).sort(), value);
93
+ }
63
94
  }
64
- exports.format = format;
@@ -6,15 +6,54 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.lint = void 0;
7
7
  const chalk_1 = __importDefault(require("chalk"));
8
8
  const effect_1 = require("effect");
9
+ const format_1 = require("../bin-format/format");
9
10
  const lint_semver_ranges_1 = require("../bin-lint-semver-ranges/lint-semver-ranges");
10
11
  const list_mismatches_1 = require("../bin-list-mismatches/list-mismatches");
11
12
  const tag_1 = require("../config/tag");
13
+ const constants_1 = require("../constants");
12
14
  const default_error_handlers_1 = require("../error-handlers/default-error-handlers");
13
15
  const get_context_1 = require("../get-context");
14
16
  const io_1 = require("../io");
15
17
  const exit_if_invalid_1 = require("../io/exit-if-invalid");
18
+ const to_json_1 = require("../io/to-json");
16
19
  const with_logger_1 = require("../lib/with-logger");
17
20
  function lint({ io, cli, errorHandlers = default_error_handlers_1.defaultErrorHandlers }) {
18
- return (0, effect_1.pipe)((0, get_context_1.getContext)({ io, cli, errorHandlers }), effect_1.Effect.tap(() => effect_1.Effect.logInfo((0, chalk_1.default) `{yellow Versions}`)), effect_1.Effect.flatMap((ctx) => (0, list_mismatches_1.pipeline)(ctx, io, errorHandlers)), effect_1.Effect.tap(() => effect_1.Effect.logInfo((0, chalk_1.default) `{yellow Semver Ranges}`)), effect_1.Effect.flatMap((ctx) => (0, lint_semver_ranges_1.pipeline)(ctx, io, errorHandlers)), effect_1.Effect.flatMap(exit_if_invalid_1.exitIfInvalid), effect_1.Effect.provide((0, effect_1.pipe)(effect_1.Context.empty(), effect_1.Context.add(tag_1.CliConfigTag, cli), effect_1.Context.add(io_1.IoTag, io))), with_logger_1.withLogger);
21
+ return (0, effect_1.pipe)((0, get_context_1.getContext)({ io, cli, errorHandlers }),
22
+ // Versions
23
+ effect_1.Effect.flatMap((ctx) => effect_1.Effect.gen(function* ($) {
24
+ if (ctx.config.rcFile.lintVersions !== false) {
25
+ yield* $(effect_1.Effect.logInfo((0, chalk_1.default) `{yellow Versions}`));
26
+ yield* $((0, list_mismatches_1.pipeline)(ctx, io, errorHandlers));
27
+ }
28
+ return ctx;
29
+ })),
30
+ // Semver Ranges
31
+ effect_1.Effect.flatMap((ctx) => effect_1.Effect.gen(function* ($) {
32
+ if (ctx.config.rcFile.lintSemverRanges !== false) {
33
+ yield* $(effect_1.Effect.logInfo((0, chalk_1.default) `{yellow Semver Ranges}`));
34
+ yield* $((0, lint_semver_ranges_1.pipeline)(ctx, io, errorHandlers));
35
+ }
36
+ return ctx;
37
+ })),
38
+ // Formatting
39
+ effect_1.Effect.flatMap((ctx) => effect_1.Effect.gen(function* ($) {
40
+ if (ctx.config.rcFile.lintFormatting !== false) {
41
+ yield* $(effect_1.Effect.logInfo((0, chalk_1.default) `{yellow Formatting}`));
42
+ yield* $((0, format_1.pipeline)(ctx));
43
+ for (const file of ctx.packageJsonFiles) {
44
+ const nextJson = (0, to_json_1.toJson)(ctx, file);
45
+ const hasChanged = file.jsonFile.json !== nextJson;
46
+ const shortPath = file.jsonFile.shortPath;
47
+ if (hasChanged) {
48
+ ctx.isInvalid = true;
49
+ yield* $(effect_1.Effect.logInfo((0, chalk_1.default) `{red ${constants_1.ICON.cross}} ${shortPath}`));
50
+ }
51
+ else {
52
+ yield* $(effect_1.Effect.logInfo((0, chalk_1.default) `{green ${constants_1.ICON.tick}} ${shortPath}`));
53
+ }
54
+ }
55
+ }
56
+ return ctx;
57
+ })), effect_1.Effect.flatMap(exit_if_invalid_1.exitIfInvalid), effect_1.Effect.provide((0, effect_1.pipe)(effect_1.Context.empty(), effect_1.Context.add(tag_1.CliConfigTag, cli), effect_1.Context.add(io_1.IoTag, io))), with_logger_1.withLogger);
19
58
  }
20
59
  exports.lint = lint;
@@ -2,12 +2,13 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getFilter = void 0;
4
4
  const is_non_empty_string_1 = require("tightrope/guard/is-non-empty-string");
5
+ const constants_1 = require("../constants");
5
6
  function getFilter({ cli, rcFile }) {
6
7
  // @TODO Deprecate `filter` in .syncpackrc
7
8
  return (0, is_non_empty_string_1.isNonEmptyString)(cli.filter)
8
9
  ? cli.filter
9
10
  : (0, is_non_empty_string_1.isNonEmptyString)(rcFile.filter)
10
11
  ? rcFile.filter
11
- : '.';
12
+ : constants_1.DEFAULT_CONFIG.filter;
12
13
  }
13
14
  exports.getFilter = getFilter;
@@ -2,11 +2,12 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getIndent = void 0;
4
4
  const is_non_empty_string_1 = require("tightrope/guard/is-non-empty-string");
5
+ const constants_1 = require("../constants");
5
6
  function getIndent({ cli, rcFile }) {
6
7
  return (0, is_non_empty_string_1.isNonEmptyString)(cli.indent)
7
8
  ? cli.indent.replaceAll('\\t', '\t')
8
9
  : (0, is_non_empty_string_1.isNonEmptyString)(rcFile.indent)
9
10
  ? rcFile.indent
10
- : ' ';
11
+ : constants_1.DEFAULT_CONFIG.indent;
11
12
  }
12
13
  exports.getIndent = getIndent;
@@ -2,18 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getSortAz = void 0;
4
4
  const is_array_of_strings_1 = require("tightrope/guard/is-array-of-strings");
5
+ const is_empty_array_1 = require("tightrope/guard/is-empty-array");
6
+ const constants_1 = require("../constants");
5
7
  function getSortAz({ rcFile }) {
6
- return (0, is_array_of_strings_1.isArrayOfStrings)(rcFile.sortAz)
8
+ return (0, is_array_of_strings_1.isArrayOfStrings)(rcFile.sortAz) || (0, is_empty_array_1.isEmptyArray)(rcFile.sortAz)
7
9
  ? rcFile.sortAz
8
- : [
9
- 'bin',
10
- 'contributors',
11
- 'dependencies',
12
- 'devDependencies',
13
- 'keywords',
14
- 'peerDependencies',
15
- 'resolutions',
16
- 'scripts',
17
- ];
10
+ : constants_1.DEFAULT_CONFIG.sortAz;
18
11
  }
19
12
  exports.getSortAz = getSortAz;
@@ -0,0 +1,2 @@
1
+ import type { Ctx } from '../get-context';
2
+ export declare function getSortExports({ rcFile }: Ctx['config']): string[];
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getSortExports = void 0;
4
+ const is_array_of_strings_1 = require("tightrope/guard/is-array-of-strings");
5
+ const is_empty_array_1 = require("tightrope/guard/is-empty-array");
6
+ const constants_1 = require("../constants");
7
+ function getSortExports({ rcFile }) {
8
+ return (0, is_array_of_strings_1.isArrayOfStrings)(rcFile.sortExports) || (0, is_empty_array_1.isEmptyArray)(rcFile.sortExports)
9
+ ? rcFile.sortExports
10
+ : constants_1.DEFAULT_CONFIG.sortExports;
11
+ }
12
+ exports.getSortExports = getSortExports;
@@ -2,9 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getSortFirst = void 0;
4
4
  const is_array_of_strings_1 = require("tightrope/guard/is-array-of-strings");
5
+ const is_empty_array_1 = require("tightrope/guard/is-empty-array");
6
+ const constants_1 = require("../constants");
5
7
  function getSortFirst({ rcFile }) {
6
- return (0, is_array_of_strings_1.isArrayOfStrings)(rcFile.sortFirst)
8
+ return (0, is_array_of_strings_1.isArrayOfStrings)(rcFile.sortFirst) || (0, is_empty_array_1.isEmptyArray)(rcFile.sortFirst)
7
9
  ? rcFile.sortFirst
8
- : ['name', 'description', 'version', 'author'];
10
+ : constants_1.DEFAULT_CONFIG.sortFirst;
9
11
  }
10
12
  exports.getSortFirst = getSortFirst;
@@ -101,14 +101,28 @@ export interface RcConfig {
101
101
  dependencyTypes: DependencyType[];
102
102
  /** @see https://jamiemason.github.io/syncpack/config/filter */
103
103
  filter: string;
104
+ /** @see https://jamiemason.github.io/syncpack/config/format-bugs */
105
+ formatBugs: boolean;
106
+ /** @see https://jamiemason.github.io/syncpack/config/format-repository */
107
+ formatRepository: boolean;
104
108
  /** @see https://jamiemason.github.io/syncpack/config/indent */
105
109
  indent: string;
110
+ /** @see https://jamiemason.github.io/syncpack/config/lint-formatting */
111
+ lintFormatting: boolean;
112
+ /** @see https://jamiemason.github.io/syncpack/config/lint-semver-ranges */
113
+ lintSemverRanges: boolean;
114
+ /** @see https://jamiemason.github.io/syncpack/config/lint-versions */
115
+ lintVersions: boolean;
106
116
  /** @see https://jamiemason.github.io/syncpack/config/semver-groups */
107
117
  semverGroups: SemverGroupConfig.Any[];
108
118
  /** @see https://jamiemason.github.io/syncpack/config/sort-az */
109
119
  sortAz: string[];
120
+ /** @see https://jamiemason.github.io/syncpack/config/sort-exports */
121
+ sortExports: string[];
110
122
  /** @see https://jamiemason.github.io/syncpack/config/sort-first */
111
123
  sortFirst: string[];
124
+ /** @see https://jamiemason.github.io/syncpack/config/sort-packages */
125
+ sortPackages: boolean;
112
126
  /** @see https://jamiemason.github.io/syncpack/config/source */
113
127
  source: string[];
114
128
  /** @see https://jamiemason.github.io/syncpack/config/specifier-types */
@@ -89,10 +89,17 @@ export declare const DEFAULT_CONFIG: {
89
89
  };
90
90
  dependencyTypes: "**"[];
91
91
  filter: string;
92
+ formatBugs: true;
93
+ formatRepository: true;
92
94
  indent: string;
95
+ lintFormatting: true;
96
+ lintSemverRanges: true;
97
+ lintVersions: true;
93
98
  semverGroups: never[];
94
99
  sortAz: string[];
100
+ sortExports: string[];
95
101
  sortFirst: string[];
102
+ sortPackages: true;
96
103
  source: string[];
97
104
  specifierTypes: "**"[];
98
105
  versionGroups: never[];
package/dist/constants.js CHANGED
@@ -70,9 +70,15 @@ exports.DEFAULT_CONFIG = {
70
70
  customTypes: exports.CUSTOM_TYPES,
71
71
  dependencyTypes: ['**'],
72
72
  filter: '.',
73
+ formatBugs: true,
74
+ formatRepository: true,
73
75
  indent: ' ',
76
+ lintFormatting: true,
77
+ lintSemverRanges: true,
78
+ lintVersions: true,
74
79
  semverGroups: [],
75
80
  sortAz: [
81
+ 'bin',
76
82
  'contributors',
77
83
  'dependencies',
78
84
  'devDependencies',
@@ -81,7 +87,19 @@ exports.DEFAULT_CONFIG = {
81
87
  'resolutions',
82
88
  'scripts',
83
89
  ],
90
+ sortExports: [
91
+ 'types',
92
+ 'node-addons',
93
+ 'node',
94
+ 'browser',
95
+ 'import',
96
+ 'require',
97
+ 'development',
98
+ 'production',
99
+ 'default',
100
+ ],
84
101
  sortFirst: ['name', 'description', 'version', 'author'],
102
+ sortPackages: true,
85
103
  source: ['package.json', 'packages/*/package.json'],
86
104
  specifierTypes: ['**'],
87
105
  versionGroups: [],
@@ -0,0 +1,9 @@
1
+ import type { Ctx } from '../get-context';
2
+ import type { PackageJsonFile } from '../get-package-json-files/package-json-file';
3
+ type Ending = '\n' | '\r' | '\r\n' | string;
4
+ export declare const newlines: {
5
+ detect(source: string): Ending;
6
+ fix(source: string, lineEnding: Ending): string;
7
+ };
8
+ export declare function toJson(ctx: Ctx, file: PackageJsonFile): string;
9
+ export {};
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toJson = exports.newlines = void 0;
4
+ const os_1 = require("os");
5
+ const get_indent_1 = require("../config/get-indent");
6
+ const CR = '\r';
7
+ const CRLF = '\r\n';
8
+ const LF = '\n';
9
+ exports.newlines = {
10
+ detect(source) {
11
+ const cr = source.split(CR).length;
12
+ const lf = source.split(LF).length;
13
+ const crlf = source.split(CRLF).length;
14
+ if (cr + lf === 0)
15
+ return os_1.EOL;
16
+ if (crlf === cr && crlf === lf)
17
+ return CRLF;
18
+ if (cr > lf)
19
+ return CR;
20
+ return LF;
21
+ },
22
+ fix(source, lineEnding) {
23
+ return source.replace(/\r\n|\n|\r/g, lineEnding);
24
+ },
25
+ };
26
+ function toJson(ctx, file) {
27
+ const contents = file.jsonFile.contents;
28
+ const indent = (0, get_indent_1.getIndent)(ctx.config);
29
+ const EOL = exports.newlines.detect(file.jsonFile.json);
30
+ const source = `${JSON.stringify(contents, null, indent)}${EOL}`;
31
+ return exports.newlines.fix(source, EOL);
32
+ }
33
+ exports.toJson = toJson;
@@ -3,9 +3,3 @@ import type { Io } from '.';
3
3
  import type { Ctx } from '../get-context';
4
4
  import type { WriteFileError } from './write-file-sync';
5
5
  export declare function writeIfChanged(ctx: Ctx): Effect.Effect<Io, WriteFileError, Ctx>;
6
- type Ending = '\n' | '\r' | '\r\n' | string;
7
- export declare const newlines: {
8
- detect(source: string): Ending;
9
- fix(source: string, lineEnding: Ending): string;
10
- };
11
- export {};
@@ -3,43 +3,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.newlines = exports.writeIfChanged = void 0;
6
+ exports.writeIfChanged = void 0;
7
7
  const chalk_1 = __importDefault(require("chalk"));
8
8
  const effect_1 = require("effect");
9
- const os_1 = require("os");
10
- const get_indent_1 = require("../config/get-indent");
11
9
  const constants_1 = require("../constants");
10
+ const to_json_1 = require("./to-json");
12
11
  const write_file_sync_1 = require("./write-file-sync");
13
12
  function writeIfChanged(ctx) {
14
- return (0, effect_1.pipe)(effect_1.Effect.all(ctx.packageJsonFiles.map((file) => (0, effect_1.pipe)(effect_1.Effect.Do, effect_1.Effect.bind('nextJson', () => toJson(file)), effect_1.Effect.bind('hasChanged', ({ nextJson }) => effect_1.Effect.succeed(file.jsonFile.json !== nextJson)), effect_1.Effect.flatMap(({ hasChanged, nextJson }) => hasChanged
13
+ return (0, effect_1.pipe)(effect_1.Effect.all(ctx.packageJsonFiles.map((file) => (0, effect_1.pipe)(effect_1.Effect.Do, effect_1.Effect.bind('nextJson', () => effect_1.Effect.succeed((0, to_json_1.toJson)(ctx, file))), effect_1.Effect.bind('hasChanged', ({ nextJson }) => effect_1.Effect.succeed(file.jsonFile.json !== nextJson)), effect_1.Effect.flatMap(({ hasChanged, nextJson }) => hasChanged
15
14
  ? (0, effect_1.pipe)((0, write_file_sync_1.writeFileSync)(file.jsonFile.filePath, nextJson), effect_1.Effect.flatMap(() => effect_1.Effect.logInfo((0, chalk_1.default) `{green ${constants_1.ICON.tick}} ${file.jsonFile.shortPath}`)))
16
15
  : effect_1.Effect.logInfo((0, chalk_1.default) `{dim ${constants_1.ICON.skip} ${file.jsonFile.shortPath}}`))))), effect_1.Effect.map(() => ctx));
17
- function toJson(file) {
18
- const contents = file.jsonFile.contents;
19
- const indent = (0, get_indent_1.getIndent)(ctx.config);
20
- const EOL = exports.newlines.detect(file.jsonFile.json);
21
- const source = `${JSON.stringify(contents, null, indent)}${EOL}`;
22
- return effect_1.Effect.succeed(exports.newlines.fix(source, EOL));
23
- }
24
16
  }
25
17
  exports.writeIfChanged = writeIfChanged;
26
- const CR = '\r';
27
- const CRLF = '\r\n';
28
- const LF = '\n';
29
- exports.newlines = {
30
- detect(source) {
31
- const cr = source.split(CR).length;
32
- const lf = source.split(LF).length;
33
- const crlf = source.split(CRLF).length;
34
- if (cr + lf === 0)
35
- return os_1.EOL;
36
- if (crlf === cr && crlf === lf)
37
- return CRLF;
38
- if (cr > lf)
39
- return CR;
40
- return LF;
41
- },
42
- fix(source, lineEnding) {
43
- return source.replace(/\r\n|\n|\r/g, lineEnding);
44
- },
45
- };
package/dist/schema.json CHANGED
@@ -472,9 +472,24 @@
472
472
  "filter": {
473
473
  "type": "string"
474
474
  },
475
+ "formatBugs": {
476
+ "type": "boolean"
477
+ },
478
+ "formatRepository": {
479
+ "type": "boolean"
480
+ },
475
481
  "indent": {
476
482
  "type": "string"
477
483
  },
484
+ "lintFormatting": {
485
+ "type": "boolean"
486
+ },
487
+ "lintSemverRanges": {
488
+ "type": "boolean"
489
+ },
490
+ "lintVersions": {
491
+ "type": "boolean"
492
+ },
478
493
  "semverGroups": {
479
494
  "items": {
480
495
  "$ref": "#/definitions/SemverGroupConfig.Any"
@@ -487,12 +502,21 @@
487
502
  },
488
503
  "type": "array"
489
504
  },
505
+ "sortExports": {
506
+ "items": {
507
+ "type": "string"
508
+ },
509
+ "type": "array"
510
+ },
490
511
  "sortFirst": {
491
512
  "items": {
492
513
  "type": "string"
493
514
  },
494
515
  "type": "array"
495
516
  },
517
+ "sortPackages": {
518
+ "type": "boolean"
519
+ },
496
520
  "source": {
497
521
  "items": {
498
522
  "type": "string"
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "syncpack",
3
3
  "description": "Consistent dependency versions in large JavaScript Monorepos",
4
- "version": "12.2.0",
4
+ "version": "12.3.0",
5
5
  "author": "Jamie Mason <jamie@foldleft.io> (https://github.com/JamieMason)",
6
6
  "bin": {
7
7
  "syncpack": "dist/bin.js",