-
-
Notifications
You must be signed in to change notification settings - Fork 6
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 flow for monorepo w/ independent versions #6
Merged
Merged
Changes from 2 commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
3d5b014
Use Babel for Jest coverage provider
mcmire 6a42f71
Add flow for monorepo w/ independent versions
mcmire 10d62bc
Fix lint issues / roll back some changes
mcmire cc69588
Fix test failure on Node 16
mcmire 557b5c1
Re-enable this test
mcmire 9b2d02f
Clean up a couple of things
mcmire c622b3a
Remove TODOs
mcmire f7c1538
Fix name of test in `git-utils`
mcmire 3dfa8b0
Merge branch 'main' into add-first-flow
mcmire 137c0d9
Respond to feedback
mcmire 29545e5
Fix docs for resolveExecutable
mcmire 7a9af7e
Remove deepmerge
mcmire c7d33f5
Improve test for `getEnvironmentVariables`
mcmire 8f4864d
Clean up assertions in tests for ensureDirectoryPathExists
mcmire 7ad7e75
Remove knownKeysOf
mcmire a9b3d8c
Add a polyrepo test for readProject
mcmire 8ceda73
Add 'bin' entry
mcmire b8521a1
Update yarn.lock
mcmire 3ab9e27
Use "initial parameters" instead of "information we need to proceed"
mcmire 9fbf13c
Bump dev version of Node to v16
mcmire 0931959
Simplify how lines are indented in validateReleaseSpecification
mcmire 05f66e0
indentationLength -> indentedLineLength
mcmire 20bca54
Drop -utils suffix from most files
mcmire 006fe54
Skip command-line-arguments from tests
mcmire cbdf61a
Make args to readManifestDependencyFields consistent with readManifes…
mcmire 6a3887a
wip
mcmire ecbba2b
Simplify UnvalidatedManifest and add more docs to package manifest stuff
mcmire fec220a
Rename 'Manifest' types to 'PackageManifest'
mcmire ad02957
Use .strict() when parsing command-line args
mcmire eb391cf
Update withSandbox to throw if entry exists, not just directory
mcmire 58dcdf1
Extract directory check in withSandbox
mcmire 6c52cc7
Fix typo in package-manifest
mcmire 7565f34
Fix another typo
mcmire fd2c322
Remove generics from package-manifest
mcmire d8f9c78
Remove dependencies fields
mcmire fa6b380
Remove extra 'describe' within 'when a release spec file already exists'
mcmire 1e5a8d6
Promisify rimraf
mcmire fc30d38
Throw if the new version of a package is less than its current version
mcmire e367ac1
Stop ignoring errors
mcmire 761377f
Use error causes to wrap errors
mcmire 35f5085
Clarify the version comparison check
mcmire b4d820d
Rename coverError to wrapError
mcmire File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
import { when } from 'jest-when'; | ||
import { determineEditor } from './editor-utils'; | ||
import * as envUtils from './env-utils'; | ||
import * as miscUtils from './misc-utils'; | ||
|
||
jest.mock('./env-utils'); | ||
jest.mock('./misc-utils'); | ||
|
||
describe('editor-utils', () => { | ||
describe('determineEditor', () => { | ||
it('returns information about the editor from EDITOR if it resolves to an executable', async () => { | ||
jest | ||
.spyOn(envUtils, 'getEnvironmentVariables') | ||
.mockReturnValue({ EDITOR: 'editor', TODAY: undefined }); | ||
when(jest.spyOn(miscUtils, 'resolveExecutable')) | ||
.calledWith('editor') | ||
.mockResolvedValue('/path/to/resolved-editor'); | ||
|
||
expect(await determineEditor()).toStrictEqual({ | ||
path: '/path/to/resolved-editor', | ||
args: [], | ||
}); | ||
}); | ||
|
||
it('falls back to VSCode if it exists and if EDITOR does not point to an executable', async () => { | ||
jest | ||
.spyOn(envUtils, 'getEnvironmentVariables') | ||
.mockReturnValue({ EDITOR: 'editor', TODAY: undefined }); | ||
when(jest.spyOn(miscUtils, 'resolveExecutable')) | ||
.calledWith('editor') | ||
.mockResolvedValue(null) | ||
.calledWith('code') | ||
.mockResolvedValue('/path/to/code'); | ||
|
||
expect(await determineEditor()).toStrictEqual({ | ||
path: '/path/to/code', | ||
args: ['--wait'], | ||
}); | ||
}); | ||
|
||
it('returns null if resolving EDITOR returns null and resolving VSCode returns null', async () => { | ||
jest | ||
.spyOn(envUtils, 'getEnvironmentVariables') | ||
.mockReturnValue({ EDITOR: 'editor', TODAY: undefined }); | ||
when(jest.spyOn(miscUtils, 'resolveExecutable')) | ||
.calledWith('editor') | ||
.mockResolvedValue(null) | ||
.calledWith('code') | ||
.mockResolvedValue(null); | ||
|
||
expect(await determineEditor()).toBeNull(); | ||
}); | ||
|
||
it('returns null if resolving EDITOR returns null and resolving VSCode throws', async () => { | ||
jest | ||
.spyOn(envUtils, 'getEnvironmentVariables') | ||
.mockReturnValue({ EDITOR: 'editor', TODAY: undefined }); | ||
when(jest.spyOn(miscUtils, 'resolveExecutable')) | ||
.calledWith('editor') | ||
.mockResolvedValue(null) | ||
.calledWith('code') | ||
.mockRejectedValue(new Error('some error')); | ||
|
||
expect(await determineEditor()).toBeNull(); | ||
}); | ||
|
||
it('returns null if resolving EDITOR throws and resolving VSCode returns null', async () => { | ||
jest | ||
.spyOn(envUtils, 'getEnvironmentVariables') | ||
.mockReturnValue({ EDITOR: 'editor', TODAY: undefined }); | ||
when(jest.spyOn(miscUtils, 'resolveExecutable')) | ||
.calledWith('editor') | ||
.mockRejectedValue(new Error('some error')) | ||
.calledWith('code') | ||
.mockResolvedValue(null); | ||
|
||
expect(await determineEditor()).toBeNull(); | ||
}); | ||
|
||
it('returns null if resolving EDITOR throws and resolving VSCode throws', async () => { | ||
jest | ||
.spyOn(envUtils, 'getEnvironmentVariables') | ||
.mockReturnValue({ EDITOR: 'editor', TODAY: undefined }); | ||
when(jest.spyOn(miscUtils, 'resolveExecutable')) | ||
.calledWith('editor') | ||
.mockRejectedValue(new Error('some error')) | ||
.calledWith('code') | ||
.mockRejectedValue(new Error('some error')); | ||
|
||
expect(await determineEditor()).toBeNull(); | ||
}); | ||
|
||
it('returns null if EDITOR is unset and resolving VSCode returns null', async () => { | ||
jest | ||
.spyOn(envUtils, 'getEnvironmentVariables') | ||
.mockReturnValue({ EDITOR: undefined, TODAY: undefined }); | ||
when(jest.spyOn(miscUtils, 'resolveExecutable')) | ||
.calledWith('code') | ||
.mockResolvedValue(null); | ||
|
||
expect(await determineEditor()).toBeNull(); | ||
}); | ||
|
||
it('returns null if EDITOR is unset and resolving VSCode throws', async () => { | ||
jest | ||
.spyOn(envUtils, 'getEnvironmentVariables') | ||
.mockReturnValue({ EDITOR: undefined, TODAY: undefined }); | ||
when(jest.spyOn(miscUtils, 'resolveExecutable')) | ||
.calledWith('code') | ||
.mockRejectedValue(new Error('some error')); | ||
|
||
expect(await determineEditor()).toBeNull(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { getEnvironmentVariables } from './env-utils'; | ||
Gudahtt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
import { debug, resolveExecutable } from './misc-utils'; | ||
|
||
/** | ||
* Information about the editor present on the user's computer. | ||
* | ||
* @property path - The path to the executable representing the editor. | ||
* @property args - Command-line arguments to pass to the executable when | ||
* calling it. | ||
*/ | ||
export interface Editor { | ||
path: string; | ||
args: string[]; | ||
} | ||
|
||
/** | ||
* Looks for an executable that represents a code editor on your computer. Tries | ||
* the `EDITOR` environment variable first, falling back to the executable that | ||
* represents VSCode (`code`). | ||
* | ||
* @returns A promise that contains information about the found editor (path and | ||
* arguments), or null otherwise. | ||
*/ | ||
export async function determineEditor(): Promise<Editor | null> { | ||
let executablePath: string | null = null; | ||
const executableArgs: string[] = []; | ||
const { EDITOR } = getEnvironmentVariables(); | ||
|
||
if (EDITOR !== undefined) { | ||
try { | ||
executablePath = await resolveExecutable(EDITOR); | ||
} catch (error) { | ||
debug( | ||
`Could not resolve executable ${EDITOR} (${error}), falling back to VSCode`, | ||
); | ||
} | ||
} | ||
|
||
if (executablePath === null) { | ||
try { | ||
executablePath = await resolveExecutable('code'); | ||
// Waits until the file is closed before returning | ||
executableArgs.push('--wait'); | ||
} catch (error) { | ||
debug( | ||
`Could not resolve path to VSCode: ${error}, continuing regardless`, | ||
); | ||
} | ||
} | ||
|
||
if (executablePath !== null) { | ||
return { path: executablePath, args: executableArgs }; | ||
} | ||
|
||
return null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { getEnvironmentVariables } from './env-utils'; | ||
|
||
describe('env-utils', () => { | ||
describe('getEnvironmentVariables', () => { | ||
let existingProcessEnv: NodeJS.ProcessEnv; | ||
|
||
beforeEach(() => { | ||
existingProcessEnv = { ...process.env }; | ||
}); | ||
|
||
afterEach(() => { | ||
Object.keys(existingProcessEnv).forEach((key) => { | ||
process.env[key] = existingProcessEnv[key]; | ||
}); | ||
}); | ||
|
||
it('returns only the environment variables from process.env that we use in this tool', () => { | ||
process.env.EDITOR = 'editor'; | ||
process.env.TODAY = 'today'; | ||
mcmire marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
expect(getEnvironmentVariables()).toStrictEqual({ | ||
EDITOR: 'editor', | ||
TODAY: 'today', | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
interface Env { | ||
EDITOR: string | undefined; | ||
TODAY: string | undefined; | ||
} | ||
|
||
/** | ||
* Returns all of the environment variables that this tool uses. | ||
* | ||
* @returns An object with a selection of properties from `process.env` that | ||
* this tool needs to access, whether their values are defined or not. | ||
*/ | ||
export function getEnvironmentVariables(): Env { | ||
return ['EDITOR', 'TODAY'].reduce((object, key) => { | ||
return { ...object, [key]: process.env[key] }; | ||
}, {} as Env); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file uses
yargs
to parse command-line arguments. It's pretty hard to mockyargs
given its flexible API, and this is the only thing this file does, so I opted not to write tests for it. If there's a way to do this however then I'd love to know!