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

feat(relay): Add outputFileExtension option #222

Merged
merged 27 commits into from
Oct 25, 2023

Conversation

JulienKode
Copy link
Contributor

@JulienKode JulienKode commented Oct 24, 2023

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:

 [
          '@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

import __stuffFragment1 from "../../../relay/__generated__/stuffFragment.graphql";
import { graphql } from "react-relay";
export const stuffFragment = __stuffFragment1;

we have this:

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

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:

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:

  plugins: [
    [
      'relay',
      {
        artifactDirectory: './src/relay/__generated__',
      },
    ],

Note: We cannot put javascript language type as our input files are typescript

found by @narajaon

@kdy1 kdy1 self-assigned this Oct 24, 2023
@JulienKode JulienKode changed the title fix: does not specify import path when transpiling relay imports feat: add outputFileExtension to specify which output extension to use Oct 24, 2023
@JulienKode JulienKode changed the title feat: add outputFileExtension to specify which output extension to use feat: add outputFileExtension to specify which output extension to use Oct 24, 2023
@JulienKode JulienKode changed the title feat: add outputFileExtension to specify which output extension to use feat(relay): add outputFileExtension to specify which output extension to use Oct 24, 2023
@kdy1 kdy1 self-requested a review October 25, 2023 00:52
@kdy1 kdy1 changed the title feat(relay): add outputFileExtension to specify which output extension to use feat(relay): Add outputFileExtension option Oct 25, 2023
@kdy1 kdy1 enabled auto-merge (squash) October 25, 2023 03:41
@kdy1 kdy1 merged commit dc992bb into swc-project:main Oct 25, 2023
4 checks passed
@kdy1 kdy1 assigned kdy1 and unassigned kdy1 Mar 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants