diff --git a/appveyor.yml b/appveyor.yml index e797d535..0963e275 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,4 +1,4 @@ -image: Visual Studio 2017 +image: Visual Studio 2019 platform: - x64 @@ -23,8 +23,13 @@ skip_commits: - '**/*.md' test_script: - - node --version - - npm --version - - npm install - - npm link - - npm run test + - ps: node --version + - ps: npm --version + - ps: npm config set loglevel silent + # NPM prefix should be writable by current user. + - ps: npm config set prefix "$home\\.npm-prefix" + - ps: $env:Path += ";$home\\.npm-prefix\\" + - ps: npm install -g elm@latest-0.19.1 elm-test@latest-0.19.1 + - ps: npm install + - ps: npm link + - ps: npm run test diff --git a/bin/create-elm-app-cli.js b/bin/create-elm-app-cli.js index c698190f..6d714537 100755 --- a/bin/create-elm-app-cli.js +++ b/bin/create-elm-app-cli.js @@ -6,7 +6,9 @@ const path = require('path'); const spawn = require('cross-spawn'); const argv = require('minimist')(process.argv.slice(2)); const version = require('../package.json').version; -const elmVersion = require('elm/package.json').version; +const which = require('which'); +const elmExecutable = which.sync('elm', {nothrow: true}) || require.resolve('elm/bin/elm'); +const elmVersion = spawn.sync(elmExecutable, ['--version']).stdout.toString().trim(); const commands = argv._; if (commands.length === 0) { diff --git a/bin/elm-app-cli.js b/bin/elm-app-cli.js index 0f960b78..68f914ea 100755 --- a/bin/elm-app-cli.js +++ b/bin/elm-app-cli.js @@ -5,9 +5,11 @@ const path = require('path'); const spawn = require('cross-spawn'); const argv = require('minimist')(process.argv.slice(2)); -const elmExecutable = require.resolve('elm/bin/elm'); +const which = require('which'); +const elmExecutable = which.sync('elm', {nothrow: true}) || require.resolve('elm/bin/elm'); +const elmTestExecutable = which.sync('elm-test', {nothrow: true}) || require.resolve('elm-test/bin/elm-test'); const version = require('../package.json').version; -const elmVersion = require('elm/package.json').version; +const elmVersion = spawn.sync(elmExecutable, ['--version']).stdout.toString().trim(); const commands = argv._; @@ -66,8 +68,8 @@ switch (script) { } }); - args = args.concat(['--compiler', require.resolve('elm/bin/elm')]); - const cp = spawn.sync(require.resolve('elm-test/bin/elm-test'), args, { + args = args.concat(['--compiler', elmExecutable]); + const cp = spawn.sync(elmTestExecutable, args, { stdio: 'inherit' }); diff --git a/config/paths.js b/config/paths.js index d1a0508f..95df2534 100644 --- a/config/paths.js +++ b/config/paths.js @@ -4,6 +4,7 @@ const path = require('path'); const fs = require('fs'); const url = require('url'); const cosmiconfig = require('cosmiconfig'); +const which = require('which'); // Make sure any symlinks in the project folder are resolved: // https://github.com/facebookincubator/create-react-app/issues/637 @@ -76,7 +77,7 @@ module.exports = { entry: resolveApp('./src/index.js'), appBuild: resolveApp('./build'), elmJson: resolveApp('./elm.json'), - elm: require.resolve('elm/bin/elm'), + elm: which.sync('elm', {nothrow: true}) || require.resolve('elm/bin/elm'), publicUrl: getPublicUrl(config), servedPath: getServedPath(config), proxy: config.proxy, diff --git a/package.json b/package.json index 6f0346e4..68db2409 100644 --- a/package.json +++ b/package.json @@ -35,10 +35,8 @@ "cross-spawn": "7.0.3", "css-loader": "4.3.0", "dotenv": "8.2.0", - "elm": "latest-0.19.1", "elm-asset-webpack-loader": "1.1.2", "elm-hot-webpack-loader": "1.1.7", - "elm-test": "latest-0.19.1", "elm-webpack-loader": "6.0.1", "file-loader": "6.2.0", "fs-extra": "6.0.1", @@ -65,6 +63,7 @@ "webpack-dev-server": "3.11.0", "webpack-manifest-plugin": "2.2.0", "whatwg-fetch": "3.5.0", + "which": "^2.0.2", "workbox-webpack-plugin": "4.3.1" }, "devDependencies": { @@ -87,6 +86,10 @@ "shelljs": "0.8.3", "unexpected": "12.0.0" }, + "peerDependencies": { + "elm": "latest-0.19.1", + "elm-test": "latest-0.19.1" + }, "engines": { "node": ">=8.0.0" }, diff --git a/scripts/create.js b/scripts/create.js index 6e6f6712..8bfb8334 100644 --- a/scripts/create.js +++ b/scripts/create.js @@ -7,6 +7,8 @@ const chalk = require('chalk'); const spawn = require('cross-spawn'); const argv = require('minimist')(process.argv.slice(2)); const commands = argv._; +const which = require('which'); +const elmExecutable = which.sync('elm', {nothrow: true}) || require.resolve('elm/bin/elm'); const isWindows = process.platform === 'win32'; @@ -44,7 +46,7 @@ function createElmApp(name) { // Run initial `elm make` const spawnElmPkgResult = spawn.sync( - path.resolve(__dirname, '../node_modules/.bin/elm'), + elmExecutable, // Run elm-make to install the dependencies. ['make', 'src/Main.elm', '--output=/dev/null'], { stdio: 'inherit', cwd: appRoot }