-
Notifications
You must be signed in to change notification settings - Fork 82
Improve watcher #475
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
Merged
Merged
Improve watcher #475
Changes from all commits
Commits
Show all changes
67 commits
Select commit
Hold shift + click to select a range
28c4f95
First pass at better watcher
lydell 2355d3d
Fix chdir
lydell 11f99c4
Get rid of arbitrary split
lydell 762e3f7
Remove unnecessary path.resolve
lydell 5764ced
Replace dead code
lydell 24cd9cf
Update .flowconfig
lydell 125fd8c
Initial pass at ElmJson.js
lydell a9ada09
Fix error message
lydell a17f07a
Get rid of the last `any` annotations
lydell 1c4d753
ElmJson.getPath
lydell a2e61c3
Simplify
lydell 9c55e25
Remove resolved TODO comment
lydell b64079d
Refactor into a Project type
lydell 101b96c
Make globs watcher globs independent of cwd
lydell ae0e6bf
Inline make
lydell a278b6e
Concentrate console.log into elm-test.js and Supervisor.js
lydell ed3e1e3
Don’t clear console for json and junit
lydell 3699ef7
Move some functions to top level
lydell 06b5c68
Move pipe filename to its own function
lydell 9044e5f
Fix typo
lydell ce7ca74
Fix tests
lydell f96da98
Fix globbing
lydell fbd0d5b
Fix `elm-test tests src`
lydell 22392ac
Optimize watching
lydell aa22a6b
Queue runs
lydell 4467759
Batch events that happen roughly at the same time
lydell e79bea8
Always watch tests/
lydell 7a2b5f6
Make init and install commands code less noisy
lydell f78c221
Remove last `var` in Solve.js
lydell 656112d
Use object shorthand
lydell 3df45e9
Rename Runner.js to FindTests.js
lydell 0212108
Move more code related to finding tests to FindTests.js
lydell a0fe808
Move code for running the tests to RunTests.js
lydell 2a6c832
Remove .js prefix from require
lydell 25cab7f
Use cross-spawn when installing packages
lydell 4220502
Concentrate process.exit into elm-test.js
lydell fe97919
Add ElmJson tests
lydell 72b8f0e
Test that elm.json is watched
lydell 7e5901b
Test adding and removing files
lydell 53310e0
Test finding elm.json up the directory tree
lydell 1611825
Document how crazy big files are handled
lydell 9945d4a
Add tests for watch + init
lydell dcdb863
Improve error message when source-directories contains "."
lydell 9d87dcc
Validate source directories
lydell 9778eb7
Fix tests after added .gitignore
lydell 76f0dec
Fix paths in test snapshots
lydell f4f6a68
Try a different approach for resolving globs
lydell 45d993f
Don’t trigger test runs on non-elm file changes in tests/
lydell a5604c2
Update outdated comments
lydell 081dc67
Improve globbing
lydell 8e45355
Deduplicate test files
lydell 46299d9
Normalize paths on Windows
lydell 0f1e697
Reduce delay
lydell 9e11a05
Use async/await in tests/Parser.js
lydell 62007fb
Fix tests on Windows
lydell d2c09cf
Fix another test on Windows
lydell e9280de
Code review
lydell a426c29
Trigger build
lydell 46d7f77
Make sure elm-stuff doesn’t grow indefinitely
lydell 9ca9939
Remove outdated comment
lydell e1a1a45
Simplify after.js now that we always know the module name
lydell be5aa85
Remove unnecessary mutation when creating elm.json
lydell e1469b3
Better variable name: installationScratchDir
lydell b5f5b73
Add missing newline at the end of a file
lydell 596eb62
Improve comment in elm-test.js
lydell 261b1a9
Replace `findClosest` with `findClosestElmJson`
lydell 43b76cc
Enable Flow’s unclear-type lint rule
lydell 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 hidden or 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 |
|---|---|---|
| @@ -1,11 +1,7 @@ | ||
| [ignore] | ||
|
|
||
| .*elm.json | ||
|
|
||
| [include] | ||
|
|
||
| [libs] | ||
|
|
||
| [options] | ||
| include_warnings=true | ||
| exact_by_default=true | ||
|
|
||
| module.ignore_non_literal_requires=true | ||
| [lints] | ||
| all=error | ||
| untyped-import=off |
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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,193 @@ | ||
| // @flow | ||
|
|
||
| const fs = require('fs'); | ||
| const path = require('path'); | ||
|
|
||
| // Poor man’s type alias. We can’t use /*:: type Dependencies = ... */ because of: | ||
| // https://github.com/prettier/prettier/issues/2597 | ||
| const Dependencies /*: { [string]: string } */ = {}; | ||
|
|
||
| const DirectAndIndirectDependencies /*: { | ||
| direct: typeof Dependencies, | ||
| indirect: typeof Dependencies, | ||
| } */ = { direct: {}, indirect: {} }; | ||
|
|
||
| const ElmJson /*: | ||
| | { | ||
| type: 'application', | ||
| 'source-directories': Array<string>, | ||
| dependencies: typeof DirectAndIndirectDependencies, | ||
| 'test-dependencies': typeof DirectAndIndirectDependencies, | ||
| [string]: mixed, | ||
| } | ||
| | { | ||
| type: 'package', | ||
| dependencies: typeof Dependencies, | ||
| 'test-dependencies': typeof Dependencies, | ||
| [string]: mixed, | ||
| } */ = { | ||
| type: 'package', | ||
| dependencies: Dependencies, | ||
| 'test-dependencies': Dependencies, | ||
| }; | ||
|
|
||
| function getPath(dir /*: string */) /*: string */ { | ||
| return path.join(dir, 'elm.json'); | ||
| } | ||
|
|
||
| function write(dir /*: string */, elmJson /*: typeof ElmJson */) /*: void */ { | ||
| const elmJsonPath = getPath(dir); | ||
|
|
||
| try { | ||
| fs.writeFileSync(elmJsonPath, JSON.stringify(elmJson, null, 4) + '\n'); | ||
| } catch (error) { | ||
| throw new Error( | ||
| `${elmJsonPath}\nFailed to write elm.json:\n${error.message}` | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| function read(dir /*: string */) /*: typeof ElmJson */ { | ||
| const elmJsonPath = getPath(dir); | ||
|
|
||
| try { | ||
| return readHelper(elmJsonPath); | ||
| } catch (error) { | ||
| throw new Error( | ||
| `${elmJsonPath}\nFailed to read elm.json:\n${error.message}` | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| function readHelper(elmJsonPath /*: string */) /*: typeof ElmJson */ { | ||
| const json = parseObject( | ||
| JSON.parse(fs.readFileSync(elmJsonPath, 'utf8')), | ||
harrysarson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 'the file' | ||
| ); | ||
|
|
||
| switch (json.type) { | ||
| case 'application': | ||
| return { | ||
| ...json, | ||
| type: 'application', | ||
| 'source-directories': parseSourceDirectories( | ||
| json['source-directories'] | ||
| ), | ||
| dependencies: parseDirectAndIndirectDependencies( | ||
| json.dependencies, | ||
| 'dependencies' | ||
| ), | ||
| 'test-dependencies': parseDirectAndIndirectDependencies( | ||
| json['test-dependencies'], | ||
| 'test-dependencies' | ||
| ), | ||
| }; | ||
|
|
||
| case 'package': | ||
| return { | ||
| ...json, | ||
| type: 'package', | ||
| dependencies: parseDependencies(json.dependencies, 'dependencies'), | ||
| 'test-dependencies': parseDependencies( | ||
| json['test-dependencies'], | ||
| 'test-dependencies' | ||
| ), | ||
| }; | ||
|
|
||
| default: | ||
| throw new Error( | ||
| `Expected "type" to be "application" or "package", but got: ${stringify( | ||
| json.type | ||
| )}` | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| function parseSourceDirectories(json /*: mixed */) /*: Array<string> */ { | ||
| if (!Array.isArray(json)) { | ||
| throw new Error( | ||
| `Expected "source-directories" to be an array, but got: ${stringify( | ||
| json | ||
| )}` | ||
| ); | ||
| } | ||
|
|
||
| const result = []; | ||
|
|
||
| for (const [index, item] of json.entries()) { | ||
| if (typeof item !== 'string') { | ||
| throw new Error( | ||
| `Expected "source-directories"->${index} to be a string, but got: ${stringify( | ||
| item | ||
| )}` | ||
| ); | ||
| } | ||
| result.push(item); | ||
| } | ||
|
|
||
| if (result.length === 0) { | ||
| throw new Error( | ||
| 'Expected "source-directories" to contain at least one item, but it is empty.' | ||
| ); | ||
| } | ||
|
|
||
| return result; | ||
| } | ||
|
|
||
| function parseDirectAndIndirectDependencies( | ||
| json /*: mixed */, | ||
| what /*: string */ | ||
| ) /*: typeof DirectAndIndirectDependencies */ { | ||
| const jsonObject = parseObject(json, what); | ||
| return { | ||
| direct: parseDependencies(jsonObject.direct, `${what}->"direct"`), | ||
| indirect: parseDependencies(jsonObject.indirect, `${what}->"indirect"`), | ||
| }; | ||
| } | ||
|
|
||
| function parseDependencies( | ||
| json /*: mixed */, | ||
| what /*: string */ | ||
| ) /*: typeof Dependencies */ { | ||
| const jsonObject = parseObject(json, what); | ||
| const result = {}; | ||
|
|
||
| for (const [key, value] of Object.entries(jsonObject)) { | ||
| if (typeof value !== 'string') { | ||
| throw new Error( | ||
| `Expected ${what}->${stringify( | ||
| key | ||
| )} to be a string, but got: ${stringify(value)}` | ||
| ); | ||
| } | ||
| result[key] = value; | ||
| } | ||
|
|
||
| return result; | ||
| } | ||
|
|
||
| function parseObject( | ||
| json /*: mixed */, | ||
| what /*: string */ | ||
| ) /*: { +[string]: mixed } */ { | ||
| if (json == null || typeof json !== 'object' || Array.isArray(json)) { | ||
| throw new Error( | ||
| `Expected ${what} to be an object, but got: ${stringify(json)}` | ||
| ); | ||
| } | ||
| return json; | ||
| } | ||
|
|
||
| function stringify(json /*: mixed */) /*: string */ { | ||
| const maybeString = JSON.stringify(json); | ||
harrysarson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return maybeString === undefined ? 'undefined' : maybeString; | ||
| } | ||
|
|
||
| module.exports = { | ||
| DirectAndIndirectDependencies, | ||
| ElmJson, | ||
| getPath, | ||
| parseDirectAndIndirectDependencies, | ||
| read, | ||
| write, | ||
| }; | ||
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.
Uh oh!
There was an error while loading. Please reload this page.