Skip to content

Commit 0de59f3

Browse files
author
Murat
committed
fix(script): support default exported modules
1 parent b240eae commit 0de59f3

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

src/tasks/scriptTask.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { processScript } from '../utils/processScript';
33
import {
44
ModStep,
55
ScriptTaskType,
6-
TaskContext,
6+
ModuleContext,
77
TaskName,
88
} from '../types/mod.types';
99
import { checkCondition } from '../utils/checkCondition';
@@ -61,7 +61,7 @@ export async function scriptTask(args: {
6161
set: function (variable: string, value: any): void {
6262
variables.set(variable, value);
6363
},
64-
} as TaskContext
64+
} as ModuleContext
6565
);
6666
let resultValue: any;
6767
if ('script' in action) {
@@ -79,8 +79,10 @@ export async function scriptTask(args: {
7979
__dirname,
8080
path.join(path.dirname(args.configPath), action.module)
8181
)
82-
) as (ctx: any) => any;
83-
resultValue = await plugin(ctx);
82+
) as ((ctx: any) => any) | { default: (ctx: any) => any };
83+
if ('default' in plugin) {
84+
resultValue = await plugin.default(ctx);
85+
} else resultValue = await plugin(ctx);
8486
}
8587
if (action.name && resultValue != null)
8688
variables.set(action.name, resultValue);

src/types/mod.types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ export type PackageJsonType = {
565565
} & Record<string, any>;
566566

567567
export type TaskName = keyof typeof taskList;
568-
export type TaskContext = {
568+
export type ModuleContext = {
569569
[K in TaskName]: (
570570
action:
571571
| Extract<ModStep, { task: K }>['actions'][number]

website/docs/guides/task-types/other-tasks/script.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,15 @@ module.exports = async function integrate(ctx) {
8282

8383
### Typescript
8484

85-
You can add `react-native-integrate` as dev dependency and use `TaskContext` type for TS.
85+
You can add `react-native-integrate` as dev dependency and use `ModuleContext` type for TS.
8686
Note that you need to transpile your plugin to CommonJS before shipping.
8787

8888
_plugin/integrate.ts_
8989

9090
```js
91-
import { TaskContext } from "react-native-integrate";
91+
import { ModuleContext } from "react-native-integrate";
9292
93-
module.exports = async function integrate(ctx: TaskContext) {
93+
export default async function integrate(ctx: ModuleContext) {
9494
await ctx.app_delegate({
9595
prepend: 'some import'
9696
});

0 commit comments

Comments
 (0)