Skip to content
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/lazy-eels-know.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@callstack/repack": minor
---

Strip empty import statements that are a leftover from stripping flow type imports
2 changes: 1 addition & 1 deletion apps/tester-federation-v2/configs/rspack.host-app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export default (env) => {
'react-native': {
singleton: true,
eager: true,
requiredVersion: '0.78.0',
requiredVersion: '0.79.1',
},
'@react-navigation/native': {
singleton: true,
Expand Down
2 changes: 1 addition & 1 deletion packages/repack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
"estree-util-is-identifier-name": "^1.1.0",
"events": "^3.3.0",
"execa": "^5.0.0",
"flow-remove-types": "^2.250.0",
"flow-remove-types": "^2.268.0",
"gradient-string": "^2.0.2",
"image-size": "^1.1.1",
"jsonwebtoken": "^9.0.2",
Expand Down
4 changes: 3 additions & 1 deletion packages/repack/src/loaders/flowLoader/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { validate } from 'schema-utils';
export interface FlowLoaderOptions {
all?: boolean;
ignoreUninitializedFields?: boolean;
pretty?: true;
pretty?: boolean;
removeEmptyImports?: boolean;
}

type Schema = Parameters<typeof validate>[0];
Expand All @@ -16,6 +17,7 @@ export const optionsSchema: Schema = {
all: { type: 'boolean' },
ignoreUninitializedFields: { type: 'boolean' },
pretty: { type: 'boolean' },
removeEmptyImports: { type: 'boolean' },
},
};

Expand Down
3 changes: 2 additions & 1 deletion packages/repack/src/types/flow-remove-types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ declare module 'flow-remove-types' {
code: string,
options: {
all?: boolean;
pretty?: boolean;
ignoreUninitializedFields?: boolean;
pretty?: boolean;
removeEmptyImports?: boolean;
}
) => {
toString(): string;
Expand Down
10 changes: 9 additions & 1 deletion packages/repack/src/utils/getFlowTransformRules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ interface GetFlowTransformRulesOptions {
* rather than only removing the type.
*/
ignoreUninitializedFields?: boolean;

/**
* Whether to remove empty import statements which were
* only used for importing flow types.
*/
removeEmptyImports?: boolean;
}

/**
Expand All @@ -61,6 +67,7 @@ interface GetFlowTransformRulesOptions {
* @param options.exclude Array of module names to exclude from Flow transformation (defaults to empty array)
* @param options.all If true, bypasses looking for @flow pragma comment before parsing (defaults to true)
* @param options.ignoreUninitializedFields If true, removes uninitialized class fields completely rather than only removing the type (defaults to false)
* @param options.removeEmptyImports If true, removes empty import statements which were only used for importing flow types (defaults to true)
*
* @returns Array of rules for transforming Flow typed modules
*/
Expand All @@ -69,6 +76,7 @@ export function getFlowTransformRules({
exclude = [],
all = true,
ignoreUninitializedFields = false,
removeEmptyImports = true,
}: GetFlowTransformRulesOptions = {}) {
return [
{
Expand All @@ -78,7 +86,7 @@ export function getFlowTransformRules({
exclude: getModulePaths(exclude),
use: {
loader: '@callstack/repack/flow-loader',
options: { all, ignoreUninitializedFields },
options: { all, ignoreUninitializedFields, removeEmptyImports },
},
},
];
Expand Down
2 changes: 2 additions & 0 deletions packages/repack/src/utils/getJsTransformRules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ interface GetJsTransformRulesOptions {
all?: boolean;
/** If true, removes uninitialized class fields completely rather than only removing the type */
ignoreUninitializedFields?: boolean;
/** If true, removes empty import statements which were only used for importing flow types */
removeEmptyImports?: boolean;
};
/** Configuration for enabling/disabling codegen transformations */
codegen?: {
Expand Down
36 changes: 18 additions & 18 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions website/src/latest/api/loaders/flow-loader.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type FlowLoaderOptions = {
all?: boolean;
ignoreUninitializedFields?: boolean;
pretty?: boolean;
removeEmptyImports?: boolean;
};
```

Expand All @@ -37,6 +38,13 @@ If true, removes uninitialized class fields (`foo;`, `foo: string;`) completely

If true, removes types completely rather than replacing with spaces. This may require using source maps.

### removeEmptyImports

- Type: `boolean`
- Default: `true`

If true, removes empty import statements (`import {} from 'flow-typed-module';`) which were only used for importing flow types.

## Example

:::info
Expand Down
9 changes: 9 additions & 0 deletions website/src/latest/api/utils/get-flow-transform-rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ interface GetFlowTransformRulesOptions {
exclude?: string[];
all?: boolean;
ignoreUninitializedFields?: boolean;
removeEmptyImports?: boolean;
}
```

Expand Down Expand Up @@ -85,6 +86,13 @@ Whether to bypass looking for `@flow` pragma comment before parsing

Whether to remove uninitialized class fields completely rather than only removing the type (defaults to false)

### options.removeEmptyImports

- Type: `boolean`
- Default: `true`

Whether to remove empty import statements which were only used for importing flow types (defaults to true)

## Example

```js title=rspack.config.cjs
Expand All @@ -97,6 +105,7 @@ module.exports = {
include: ["react-native", "@react-native"],
all: true,
ignoreUninitializedFields: false,
removeEmptyImports: true,
}),
],
},
Expand Down
2 changes: 2 additions & 0 deletions website/src/latest/api/utils/get-js-transform-rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ interface GetJsTransformRulesOptions {
exclude?: string[];
all?: boolean;
ignoreUninitializedFields?: boolean;
removeEmptyImports?: boolean;
};
codegen?: {
enabled?: boolean;
Expand Down Expand Up @@ -81,6 +82,7 @@ Configuration for enabling/disabling Flow transformations. When enabled, the tra
exclude: [],
all: true,
ignoreUninitializedFields: false,
removeEmptyImports: true,
}
}
```
Expand Down