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: handle stripping flow types from popular packages #765

Merged
merged 7 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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