rnx-kit/packages/babel-plugin-import-path-re...
React Native SDK Bot 756ddeba67
RELEASING: Releasing 44 package(s) (#3342)
Releases:
  @rnx-kit/third-party-notices@2.0.0
  @rnx-kit/cli@0.18.0
  @rnx-kit/metro-plugin-cyclic-dependencies-detector@2.0.0
  @rnx-kit/react-native-error-trace-decorator@2.0.0
  @rnx-kit/esbuild-plugin-import-path-remapper@3.0.0
  @rnx-kit/babel-plugin-import-path-remapper@2.0.0
  @rnx-kit/babel-preset-metro-react-native@2.0.0
  @rnx-kit/metro-plugin-duplicates-checker@3.0.0
  @rnx-kit/react-native-test-app-msal@4.0.0
  @rnx-kit/react-native-lazy-index@4.0.0
  @rnx-kit/tools-react-native@2.0.0
  @rnx-kit/typescript-service@2.0.0
  @rnx-kit/commitlint-lite@2.0.0
  @rnx-kit/metro-serializer@2.0.0
  @rnx-kit/tools-language@3.0.0
  @rnx-kit/metro-service@4.0.0
  @rnx-kit/metro-config@2.0.0
  @rnx-kit/bundle-diff@2.0.0
  @rnx-kit/align-deps@3.0.0
  @rnx-kit/tools-node@3.0.0
  @rnx-kit/tsconfig@2.0.0
  @rnx-kit/console@2.0.0
  @react-native-webapis/battery-status@0.2.0
  @react-native-webapis/web-storage@0.3.0
  @rnx-kit/esbuild-bundle-analyzer@0.3.0
  @rnx-kit/metro-serializer-esbuild@0.2.0
  @rnx-kit/rn-changelog-generator@0.5.0
  @rnx-kit/metro-plugin-typescript@0.5.0
  @rnx-kit/metro-resolver-symlinks@0.2.0
  @rnx-kit/react-native-auth@0.3.0
  @rnx-kit/react-native-host@0.5.0
  @rnx-kit/patcher-rnmacos@0.2.0
  @rnx-kit/tools-filesystem@0.1.0
  @rnx-kit/tools-workspaces@0.2.0
  @rnx-kit/eslint-plugin@0.8.0
  @rnx-kit/tools-android@0.2.0
  @rnx-kit/tools-windows@0.2.0
  @rnx-kit/jest-preset@0.2.0
  @rnx-kit/tools-apple@0.2.0
  @rnx-kit/tools-shell@0.2.0
  @rnx-kit/polyfills@0.2.0
  @rnx-kit/config@0.7.0
  @rnx-kit/build@0.7.1
  @rnx-kit/eslint-config@0.0.4

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2024-09-11 08:59:50 +02:00
..
src
test
CHANGELOG.md RELEASING: Releasing 44 package(s) (#3342) 2024-09-11 08:59:50 +02:00
README.md
eslint.config.js
package.json RELEASING: Releasing 44 package(s) (#3342) 2024-09-11 08:59:50 +02:00
tsconfig.json

README.md

@rnx-kit/babel-plugin-import-path-remapper

Build npm version

@rnx-kit/babel-plugin-import-path-remapper remaps **/lib/** imports to **/src/**. This is useful for packages that are not correctly exporting everything via their index.ts, but you still want to consume the TypeScript files rather than the transpiled JavaScript.

Usage

Add @rnx-kit/babel-plugin-import-path-remapper to your babel.config.js under plugins. For example, to remap all paths under the @rnx-kit scope:

// babel.config.js
module.exports = {
  presets: ["module:metro-react-native-babel-preset"],
  overrides: [
    {
      test: /\.tsx?$/,
      plugins: [
        // @babel/plugin-transform-typescript doesn't support `const enum`s.
        // See https://babeljs.io/docs/en/babel-plugin-transform-typescript#caveats
        // for more details.
        "const-enum",

        [
          "@rnx-kit/babel-plugin-import-path-remapper",
          { test: (source) => source.startsWith("@rnx-kit/") },
        ],
      ],
    },
  ],
};

Or, if you're using @rnx-kit/metro-config:

// babel.config.js
const { makeBabelConfig } = require("@rnx-kit/metro-config");
module.exports = makeBabelConfig([
  [
    "@rnx-kit/babel-plugin-import-path-remapper",
    { test: (source) => source.startsWith("@rnx-kit/") },
  ],
]);

Options

Option Type Description
test (source: string) => boolean [Required] A function returning whether the passed source should be redirected to another module.
remap (moduleName: string, path: string) => string [Optional] A function returning the module that should be used instead, e.g. contoso/index.js -> contoso/index.ts.