-
-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(relay): Add
outputFileExtension
option (#222)
# Description ## Feature In this PR we add `outputFileExtension` parameter in the config that can be: - `ts` - `js` - `undefined` When it's undefined we do the same behaviour as now which is controlled by `language` parameter When it's configured we use the `outputFileExtension` parameter to specify which extension to use in the transpiled path import Example of usage: ```typescript [ '@swc/plugin-relay', { rootDir: __dirname, artifactDirectory: './src/relay/__generated__', eagerEsModules: true, outputFileExtension: 'js' }, ], ``` ## Initial issue We are migrating from `babel` to `swc` and currently our babel plugin The output in dist are javascript esm and instead of having this ```javascript import __stuffFragment1 from "../../../relay/__generated__/stuffFragment.graphql"; import { graphql } from "react-relay"; export const stuffFragment = __stuffFragment1; ``` we have this: ```javascript import __stuffFragment1 from "../../../relay/__generated__/stuffFragment.graphql.ts"; import { graphql } from "react-relay"; export const stuffFragment = __stuffFragment1; ``` Basically it add `.ts` at the end but our files are javascript transpiled files - I know it's due to default fallback to ts language: https://github.com/swc-project/plugins/blob/91fabf814285011eede6e80712da8ad7da1ae7ec/packages/relay/src/lib.rs#L42 - I know by default ts language add `.ts` at the end: https://github.com/swc-project/plugins/blob/91fabf814285011eede6e80712da8ad7da1ae7ec/packages/relay/transform/src/lib.rs#L165 Is it a configuration issue on our side or a plugin issue that by default transpilation import path should not have extensions ? If it's a configuration issue sorry in advance I thought the inputs were the same as the babel plugin If we consider it as a bug I'll obviously fix this PR and update test, otherwise I'll close it and change the config on my side Swc config: ```javascript const config = { jsc: { baseUrl: 'src', parser: { syntax: 'typescript', tsx: true, }, target: 'esnext', paths: { '@xxx/*': ['*'], }, experimental: { plugins: [ [ '@swc/plugin-relay', { rootDir: __dirname, artifactDirectory: './src/relay/__generated__', eagerEsModules: true, }, ], ], }, }, test: '(.ts|.tsx|.js|.jsx)', }; ``` previous babel config for relay: ```javascript plugins: [ [ 'relay', { artifactDirectory: './src/relay/__generated__', }, ], ``` Note: We cannot put `javascript` language type as our input files are `typescript`
- Loading branch information
1 parent
65cd6b5
commit dc992bb
Showing
30 changed files
with
176 additions
and
40 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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
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
10 changes: 10 additions & 0 deletions
10
packages/relay/transform/tests/fixture/outputFileExtension/javascript/input.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,10 @@ | ||
const myFragment = graphql` | ||
fragment FooFragment on Bar { | ||
id | ||
} | ||
` | ||
useQuery(graphql` | ||
query FooQuery { | ||
id | ||
} | ||
`) |
4 changes: 4 additions & 0 deletions
4
packages/relay/transform/tests/fixture/outputFileExtension/javascript/output.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,4 @@ | ||
import __FooFragment from "__generated__/FooFragment.graphql.js"; | ||
import __FooQuery from "__generated__/FooQuery.graphql.js"; | ||
const myFragment = __FooFragment; | ||
useQuery(__FooQuery); |
Oops, something went wrong.