-
Notifications
You must be signed in to change notification settings - Fork 82
Add a command to use master version of elm-explorations/test #592
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
Changes from 5 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
202a2dc
Add a flag to use master version of elm-explorations/test
Janiczek f8429a3
Small fixes (we'll rip these out anyways)
Janiczek 14dd7fa
Use Node versions of commands
Janiczek ae25add
Revert await for Install.install
Janiczek 0d5d3c2
Revert Node 12->14 changes
Janiczek f8e8670
Apply CR suggestions
Janiczek b9bc09a
Minimize diff
Janiczek 6a2c471
lint
Janiczek 250a6b5
prettier + bugfix
Janiczek bec1562
Fix comments
Janiczek 59818ea
Fix comment again
Janiczek 7247fa5
Fix `??` not available in Node.js 12, the ambitious way
lydell 557634f
Handle errors like we do in other commands
lydell bbf9fa8
Replace rmFileSync with fs.unlinkSync
lydell 7ecf9ff
Merge pull request #1 from lydell/install-master
Janiczek bf7150e
Remove mention of rm -rf
Janiczek 94dedda
Try to fix Windows
lydell c11a29d
Merge pull request #2 from lydell/install-master
Janiczek 0b9a0f3
Remove unused value and add type annotations
lydell 54f7093
Validate that 1.2.2 is used
lydell 1714149
Merge pull request #3 from lydell/install-master
Janiczek e79119f
Install package elm-explorations/test after uninstalling master
lydell 1815420
Merge pull request #4 from lydell/install-master
Janiczek 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,8 +1,13 @@ | ||
| // @flow | ||
|
|
||
| const {exec} = require('child_process'); | ||
| const spawn = require('cross-spawn'); | ||
| const {unzip} = require('zlib'); | ||
| const fs = require('fs'); | ||
| const os = require('os'); | ||
| const https = require('https'); | ||
| const path = require('path'); | ||
| const chalk = require('chalk'); | ||
| const ElmJson = require('./ElmJson'); | ||
| const Project = require('./Project'); | ||
|
|
||
|
|
@@ -117,6 +122,122 @@ function install( | |
| return 'SuccessfullyInstalled'; | ||
| } | ||
|
|
||
| async function downloadFileNative(url, filePath) { | ||
| const usedCommand = `require("https").get(${JSON.stringify(url)})`; | ||
| const errorPrefix = `${usedCommand}\nThe above call errored: `; | ||
|
|
||
| return new Promise((resolve, reject) => { | ||
| const file = fs.createWriteStream(filePath); | ||
| let fileInfo = null; | ||
|
|
||
| const request = https.get(url, response => { | ||
| if (response.statusCode !== 200) { | ||
| fs.unlink(filePath, () => { | ||
| reject(new Error(`Failed to get '${url}' (${response.statusCode})`)); | ||
| }); | ||
| return; | ||
| } | ||
|
|
||
| fileInfo = { | ||
| mime: response.headers['content-type'], | ||
| size: parseInt(response.headers['content-length'], 10), | ||
| }; | ||
|
|
||
| response.pipe(file); | ||
| }); | ||
|
|
||
| // The destination stream is ended by the time it's called | ||
| file.on('finish', () => resolve(fileInfo)); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We seem to resolve the promise with some data we never use here. |
||
|
|
||
| request.on('error', err => { | ||
| fs.unlink(filePath, () => reject(err)); | ||
| }); | ||
|
|
||
| file.on('error', err => { | ||
| fs.unlink(filePath, () => reject(err)); | ||
| }); | ||
|
|
||
| request.end(); | ||
| }); | ||
| } | ||
|
|
||
| async function installUnstableTestMaster(projectRootDir) { | ||
| console.log(chalk.yellow('Using the master version of elm-explorations/test')); | ||
| console.log(chalk.yellow('Note you might need to rm -rf ~/.elm and/or ./elm-stuff afterwards.')); | ||
|
|
||
| const pkg = 'elm-explorations/test'; | ||
| const version = '1.2.2'; | ||
| const pkgWithDash = pkg.replace('/','-'); | ||
|
|
||
| const tempPath = path.join( | ||
| projectRootDir, | ||
| 'elm-stuff', | ||
| 'generated-code', | ||
| 'elm-community', | ||
| 'elm-test' | ||
| ); | ||
|
lydell marked this conversation as resolved.
Outdated
|
||
| const zipballUrl = `https://codeload.github.com/${pkg}/zip/refs/heads/master`; | ||
| const zipballFilename = `${pkgWithDash}.zip`; | ||
| const zipballPath = path.join(tempPath, zipballFilename); | ||
| const homeDir = os.homedir(); | ||
|
|
||
| // based on info in https://package.elm-lang.org/packages/elm/project-metadata-utils/latest/ | ||
| const elmHome = process.env.ELM_HOME ?? ( | ||
| process.platform === 'win32' | ||
| ? path.join(process.env.APPDATA, 'elm') | ||
| : path.join(homeDir, '.elm') | ||
| ); | ||
| const packagePath = path.join( | ||
| elmHome, | ||
| '0.19.1', | ||
| 'packages', | ||
| pkg, | ||
| version | ||
| ); | ||
|
|
||
| fs.rmSync(tempPath, { recursive: true, force: true }); | ||
| fs.rmSync(packagePath, { recursive: true, force: true }); | ||
| fs.mkdirSync(tempPath, { recursive: true }); | ||
| fs.mkdirSync(packagePath, { recursive: true }); | ||
| await downloadFileNative(zipballUrl, zipballPath); | ||
| const unzipResult = spawn.sync( | ||
| 'unzip', | ||
| [ | ||
| '-o', // overwrite | ||
| zipballFilename, // file to unzip | ||
| '-d', tempPath // directory where to extract files | ||
| ], | ||
| { | ||
| cwd: tempPath, | ||
| } | ||
| ); | ||
| if (unzipResult.status !== 0) { | ||
| const tarResult = spawn.sync( | ||
| 'tar', | ||
| [ | ||
| 'zxf', // eXtract Zipped File | ||
| zipballFilename, // file to unzip | ||
| '-C', tempPath // directory where to extract files | ||
| ], | ||
| { | ||
| cwd: tempPath, | ||
| } | ||
| ); | ||
| if (tarResult.status !== 0) { | ||
| throw new Error("Failed to unzip the elm-explorations/test repo zipfile"); | ||
| } | ||
| } | ||
| fs.renameSync( | ||
| path.join( | ||
| tempPath, | ||
| 'test-master' | ||
| ), | ||
| packagePath | ||
| ); | ||
| fs.rmSync(zipballPath, { recursive: true, force: true }); | ||
|
lydell marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| module.exports = { | ||
| install, | ||
| installUnstableTestMaster, | ||
| }; | ||
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
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.
Maybe we should add type annotations to all new functions in this file – for parameters and return types.
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.
Went ahead and did the last final touches: https://github.com/Janiczek/node-test-runner/pull/3