Skip to content

Commit

Permalink
feat: handle stripping flow types from popular packages (#765)
Browse files Browse the repository at this point in the history
* refactor: add getModulePaths to utils index

* feat: add rules for transpiling flow typed modules

* chore: add jsdocs for other rules as well

* chore: add flow rule to v5 templates

* fix: add flow rules to index

* chore: add flow rule to testers

* chore: add changeset
  • Loading branch information
jbroma authored Oct 11, 2024
1 parent e433584 commit efff0c2
Show file tree
Hide file tree
Showing 12 changed files with 56 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/fast-falcons-joke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@callstack/repack": minor
---

Add default rules for transpiling popular flow typed packages
1 change: 1 addition & 0 deletions apps/tester-app/rspack.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export default (env) => {
rules: [
Repack.REACT_NATIVE_LOADING_RULES,
Repack.NODE_MODULES_LOADING_RULES,
Repack.FLOW_TYPED_MODULES_LOADING_RULES,
{
test: /\.[jt]sx?$/,
exclude: [/node_modules/],
Expand Down
1 change: 1 addition & 0 deletions apps/tester-federation/rspack.config.host-app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export default (env) => {
rules: [
Repack.REACT_NATIVE_LOADING_RULES,
Repack.NODE_MODULES_LOADING_RULES,
Repack.FLOW_TYPED_MODULES_LOADING_RULES,
/* repack is symlinked to a local workspace */
{
test: /\.[jt]sx?$/,
Expand Down
1 change: 1 addition & 0 deletions apps/tester-federation/rspack.config.mini-app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export default (env) => {
rules: [
Repack.REACT_NATIVE_LOADING_RULES,
Repack.NODE_MODULES_LOADING_RULES,
Repack.FLOW_TYPED_MODULES_LOADING_RULES,
/* repack is symlinked to a local workspace */
{
test: /\.[jt]sx?$/,
Expand Down
27 changes: 27 additions & 0 deletions packages/repack/src/rules/flowTypedModulesLoadingRules.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import type { RuleSetRule } from '@rspack/core';
import { getModulePaths } from '../utils';

/**
* @constant FLOW_TYPED_MODULES_LOADING_RULES
* @type {RuleSetRule}
* @description Module rule configuration for loading flow-typed modules.
*/
export const FLOW_TYPED_MODULES_LOADING_RULES: RuleSetRule = {
type: 'javascript/auto',
test: /\.jsx?$/,
include: getModulePaths([
'react-native-blob-util',
'react-native-pdf',
'@react-native-picker/picker',
'react-native-config',
'react-native-fs',
'react-native-image-size',
'react-native-performance',
'react-native-vector-icons',
'@react-native-community/datetimepicker',
]),
use: {
loader: '@callstack/repack/flow-loader',
options: { all: true },
},
};
1 change: 1 addition & 0 deletions packages/repack/src/rules/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './reactNativeLoadingRules';
export * from './reactNativeCodegenRules';
export * from './nodeModulesLoadingRules';
export * from './flowTypedModulesLoadingRules';
7 changes: 6 additions & 1 deletion packages/repack/src/rules/nodeModulesLoadingRules.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import type { RuleSetRule } from '@rspack/core';
import { getModulePaths } from '../utils/getModulePaths';
import { getModulePaths } from '../utils';

/**
* @constant NODE_MODULES_LOADING_RULES
* @type {RuleSetRule}
* @description Module rule configuration for loading node_modules, excluding React Native Core & out-of-tree platform packages.
*/
export const NODE_MODULES_LOADING_RULES: RuleSetRule = {
type: 'javascript/auto',
test: /\.[cm]?[jt]sx?$/,
Expand Down
5 changes: 5 additions & 0 deletions packages/repack/src/rules/reactNativeCodegenRules.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import type { RuleSetRule } from '@rspack/core';

/**
* @constant REACT_NATIVE_CODEGEN_RULES
* @type {RuleSetRule}
* @description Module rule configuration for handling React Native codegen files.
*/
export const REACT_NATIVE_CODEGEN_RULES: RuleSetRule = {
test: /(?:^|[\\/])(?:Native\w+|(\w+)NativeComponent)\.[jt]sx?$/,
rules: [
Expand Down
7 changes: 6 additions & 1 deletion packages/repack/src/rules/reactNativeLoadingRules.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import type { RuleSetRule } from '@rspack/core';
import { getModulePaths } from '../utils/getModulePaths';
import { getModulePaths } from '../utils';
import { REACT_NATIVE_LAZY_IMPORTS } from './lazyImports';

/**
* @constant REACT_NATIVE_LOADING_RULES
* @type {RuleSetRule}
* @description Module rule configuration for loading React Native Core & out-of-tree platform packages.
*/
export const REACT_NATIVE_LOADING_RULES: RuleSetRule = {
type: 'javascript/dynamic',
test: /\.jsx?$/,
Expand Down
1 change: 1 addition & 0 deletions packages/repack/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export * from './federated';
export * from './getDirname';
export * from './getPublicPath';
export * from './getResolveOptions';
export * from './getModulePaths';
1 change: 1 addition & 0 deletions templates_v5/rspack.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ module.exports = (env) => {
rules: [
Repack.REACT_NATIVE_LOADING_RULES,
Repack.NODE_MODULES_LOADING_RULES,
Repack.FLOW_TYPED_MODULES_LOADING_RULES,
/** Here you can adjust loader that will process your files. */
{
test: /\.[jt]sx?$/,
Expand Down
1 change: 1 addition & 0 deletions templates_v5/rspack.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export default (env) => {
rules: [
Repack.REACT_NATIVE_LOADING_RULES,
Repack.NODE_MODULES_LOADING_RULES,
Repack.FLOW_TYPED_MODULES_LOADING_RULES,
/** Here you can adjust loader that will process your files. */
{
test: /\.[jt]sx?$/,
Expand Down

0 comments on commit efff0c2

Please sign in to comment.