Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add multi module compilation for elm (#8076)
- Loading branch information
1 parent
128e072
commit fca5c8c
Showing
11 changed files
with
204 additions
and
73 deletions.
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
24 changes: 24 additions & 0 deletions
24
packages/core/integration-tests/test/integration/elm-multiple-apps/elm.json
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,24 @@ | ||
{ | ||
"type": "application", | ||
"source-directories": [ | ||
"src" | ||
], | ||
"elm-version": "0.19.1", | ||
"dependencies": { | ||
"direct": { | ||
"elm/browser": "1.0.2", | ||
"elm/core": "1.0.5", | ||
"elm/html": "1.0.0" | ||
}, | ||
"indirect": { | ||
"elm/json": "1.1.3", | ||
"elm/time": "1.0.0", | ||
"elm/url": "1.0.0", | ||
"elm/virtual-dom": "1.0.2" | ||
} | ||
}, | ||
"test-dependencies": { | ||
"direct": {}, | ||
"indirect": {} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
packages/core/integration-tests/test/integration/elm-multiple-apps/package.json
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,10 @@ | ||
{ | ||
"@parcel/transformer-elm": { | ||
"extraSources": { | ||
"./src/Main.elm": [ | ||
"./src/MainB.elm", | ||
"./src/MainC.elm" | ||
] | ||
} | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
packages/core/integration-tests/test/integration/elm-multiple-apps/src/Main.elm
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,7 @@ | ||
module Main exposing (main) | ||
|
||
import Html | ||
|
||
|
||
main = | ||
Html.text "Hello, world!" |
7 changes: 7 additions & 0 deletions
7
packages/core/integration-tests/test/integration/elm-multiple-apps/src/MainB.elm
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,7 @@ | ||
module MainB exposing (main) | ||
|
||
import Html | ||
|
||
|
||
main = | ||
Html.text "Hello, world!" |
7 changes: 7 additions & 0 deletions
7
packages/core/integration-tests/test/integration/elm-multiple-apps/src/MainC.elm
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,7 @@ | ||
module MainC exposing (main) | ||
|
||
import Html | ||
|
||
|
||
main = | ||
Html.text "Hello, world!" |
5 changes: 5 additions & 0 deletions
5
packages/core/integration-tests/test/integration/elm-multiple-apps/src/index.js
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,5 @@ | ||
import { Elm } from './Main.elm?with=MainB.elm&with=MainC.elm'; | ||
|
||
export default function() { | ||
return Elm; | ||
} |
Empty file.
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,62 @@ | ||
// @flow strict-local | ||
|
||
import type {Config} from '@parcel/types'; | ||
import path from 'path'; | ||
import ThrowableDiagnostic from '@parcel/diagnostic'; | ||
import commandExists from 'command-exists'; | ||
import nullthrows from 'nullthrows'; | ||
|
||
async function load({config}: {|config: Config|}): Promise<null> { | ||
const elmConfig = await config.getConfig(['elm.json']); | ||
if (!elmConfig) { | ||
elmBinaryPath(); // Check if elm is even installed | ||
throw new ThrowableDiagnostic({ | ||
diagnostic: { | ||
origin: '@parcel/elm-transformer', | ||
message: "The 'elm.json' file is missing.", | ||
hints: [ | ||
"Initialize your elm project by running 'elm init'", | ||
"If you installed elm as project dependency then run 'yarn elm init' or 'npx elm init'", | ||
], | ||
}, | ||
}); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
function elmBinaryPath(): ?string { | ||
let elmBinary = resolveLocalElmBinary(); | ||
|
||
if (elmBinary == null && !commandExists.sync('elm')) { | ||
throw new ThrowableDiagnostic({ | ||
diagnostic: { | ||
message: "Can't find 'elm' binary.", | ||
hints: [ | ||
"You can add it as an dependency for your project by running 'yarn add -D elm' or 'npm add -D elm'", | ||
'If you want to install it globally then follow instructions on https://elm-lang.org/', | ||
], | ||
origin: '@parcel/elm-transformer', | ||
}, | ||
}); | ||
} | ||
|
||
return elmBinary; | ||
} | ||
|
||
function resolveLocalElmBinary() { | ||
try { | ||
let result = require.resolve('elm/package.json'); | ||
// $FlowFixMe | ||
let pkg = require('elm/package.json'); | ||
let bin = nullthrows(pkg.bin); | ||
return path.join( | ||
path.dirname(result), | ||
typeof bin === 'string' ? bin : bin.elm, | ||
); | ||
} catch (_) { | ||
return null; | ||
} | ||
} | ||
|
||
export {load, elmBinaryPath}; |