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

fix: stop sorting scripts #206

Merged
merged 6 commits into from
Feb 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
55 changes: 33 additions & 22 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,49 @@
/* eslint-disable @typescript-eslint/no-explicit-any */

declare namespace sortPackageJsonExports {
declare namespace sortPackageJson {
interface SortPackageJsonFn {
/**
* Sort packageJson object.
*
* @param packageJson - A packageJson
* @param options
* @returns Sorted packageJson object
*/
<T extends Record<any, any>>(packageJson: T, options?: Options): T,
* Sort packageJson object.
*
* @param packageJson - A packageJson
* @param options - An options object
* @returns Sorted packageJson object
*/
<T extends Record<any, any>>(packageJson: T, options?: Options): T

/**
* Sort packageJson string.
*
* @param packageJson - A packageJson string.
* @param options
* @returns Sorted packageJson string.
*/
(packageJson: string, options?: Options): string,
* Sort packageJson string.
*
* @param packageJson - A packageJson string.
* @param options - An options object
* @returns Sorted packageJson string.
*/
(packageJson: string, options?: Options): string
}

type ComparatorFunction = (left: string, right: string) => number;
type ComparatorFunction = (left: string, right: string) => number

function sortObjectBy<T extends Record<any, any>>(
jonathanmorley marked this conversation as resolved.
Show resolved Hide resolved
comparator?: string[],
deep?: boolean,
): (x: T) => T

interface Field {
readonly key: string
over?<T extends Record<any, any>>(x: T): T
}

interface Options {
readonly sortOrder?: readonly string[] | ComparatorFunction;
readonly sortOrder?: readonly string[] | ComparatorFunction
}
}

interface sortPackageJsonExports extends sortPackageJsonExports.SortPackageJsonFn {
readonly default: sortPackageJsonExports.SortPackageJsonFn;
readonly sortPackageJson: sortPackageJsonExports.SortPackageJsonFn;
interface sortPackageJsonExports extends sortPackageJson.SortPackageJsonFn {
readonly default: sortPackageJson.SortPackageJsonFn
readonly sortPackageJson: sortPackageJson.SortPackageJsonFn
readonly sortOrder: string[]
}

declare const sortPackageJsonExports: sortPackageJsonExports;
declare const sortPackageJsonExports: sortPackageJsonExports

export = sortPackageJsonExports;
export = sortPackageJsonExports
18 changes: 8 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,16 +135,14 @@ const sortScripts = onObject((scripts) => {
const names = Object.keys(scripts)
const prefixable = new Set()

const keys = names
.map((name) => {
const omitted = name.replace(/^(?:pre|post)/, '')
if (defaultNpmScripts.has(omitted) || names.includes(omitted)) {
prefixable.add(omitted)
return omitted
}
return name
})
.sort()
Copy link
Owner

Choose a reason for hiding this comment

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

Seems like this is the only LOC that should be in this diff now, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe this is prettier moving the .map up a line since it no longer has a .sort to align with

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@keithamus does this sufficiently explain the diff?

Copy link
Owner

Choose a reason for hiding this comment

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

Why has the index.d.ts changed so much? Is it just that the copy in the main branch is old?

const keys = names.map((name) => {
const omitted = name.replace(/^(?:pre|post)/, '')
if (defaultNpmScripts.has(omitted) || names.includes(omitted)) {
prefixable.add(omitted)
return omitted
}
return name
})

const order = keys.reduce(
(order, key) =>
Expand Down
Loading