Skip to content
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

Set compile string to output language extension #35

Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import { Runner } from 'relay-compiler'
import RelayLanguagePluginJavaScript from 'relay-compiler/lib/RelayLanguagePluginJavaScript'
import type { PluginInterface } from 'relay-compiler/lib/RelayLanguagePluginInterface'
import RelaySourceModuleParser from 'relay-compiler/lib/RelaySourceModuleParser'
import { DotGraphQLParser } from 'graphql-compiler'

Expand Down Expand Up @@ -35,9 +36,9 @@ class RaiseErrorsReporter {
}

class RelayCompilerWebpackPlugin {
parserConfigs: {}

writerConfigs: {}
parserConfigs: {};
writerConfigs: {};
languagePlugin: PluginInterface;

constructor (options: {
schema: string | GraphQLSchema,
Expand All @@ -46,7 +47,7 @@ class RelayCompilerWebpackPlugin {
extensions: Array<string>,
include: Array<string>,
exclude: Array<string>,
languagePlugin?: Function
languagePlugin?: () => PluginInterface
}) {
if (!options) {
throw new Error('You must provide options to RelayCompilerWebpackPlugin.')
Expand Down Expand Up @@ -104,6 +105,8 @@ class RelayCompilerWebpackPlugin {
sourceParserName,
languagePlugin: language
})

this.languagePlugin = language
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It wasn't obvious to me how I should pass the language output extension down to compile but I figured I'd just do it like this for now.

}

createParserConfigs ({
Expand All @@ -119,7 +122,7 @@ class RelayCompilerWebpackPlugin {
baseDir: string,
getParser?: Function,
sourceParserName: string,
languagePlugin: any,
languagePlugin: PluginInterface,
schema: string | GraphQLSchema,
include: Array<string>,
exclude: Array<string>,
Expand Down Expand Up @@ -161,7 +164,7 @@ class RelayCompilerWebpackPlugin {
}: {
baseDir: string,
sourceParserName: string,
languagePlugin: any
languagePlugin: PluginInterface
}) {
return {
[languagePlugin.outputExtension]: {
Expand All @@ -186,7 +189,7 @@ class RelayCompilerWebpackPlugin {
onlyValidate: false,
skipPersist: true
})
return runner.compile('js')
return runner.compile(this.languagePlugin.outputExtension)
} catch (error) {
errors.push(error)
}
Expand Down