Skip to content
This repository was archived by the owner on Jan 18, 2024. It is now read-only.

[config plugins] extend base mods#3852

Merged
EvanBacon merged 5 commits intomasterfrom
@evanbacon/config-plugins/extend-base-mods
Sep 20, 2021
Merged

[config plugins] extend base mods#3852
EvanBacon merged 5 commits intomasterfrom
@evanbacon/config-plugins/extend-base-mods

Conversation

@EvanBacon
Copy link
Copy Markdown
Contributor

@EvanBacon EvanBacon commented Sep 15, 2021

Why

Follow up: #3839 (comment)

How

  • Added static mod property isIntrospective which will prevent a base mod from being removed during introspection.
  • Combined introspection providers with regular providers for a more unified interface, and as a way to test the public interface for introspection providers.
  • Exposed BaseMods.provider helper and BaseMods.withGeneratedBaseMods so users could create their own base mods locally and add them to the compiler sequence.

Test Plan

  • Existing tests
  • Locally using:
import {
  ConfigPlugin,
  IOSConfig,
  Mod,
  withMod,
  BaseMods,
} from "../../cli/packages/config-plugins/build/index";
import fs from "fs";

export function withCustomBaseMods(config) {
  return BaseMods.withGeneratedBaseMods<"appDelegateHeader">(config, {
    platform: "ios",
    skipEmptyMod: false,
    providers: {
      // Append a custom rule to supply AppDelegate header data to mods on `mods.ios.appDelegateHeader`
      appDelegateHeader:
        BaseMods.provider<IOSConfig.Paths.AppDelegateProjectFile>({
          isIntrospective: true,
          getFilePath({ modRequest: { projectRoot } }) {
            return IOSConfig.Paths.getAppDelegateHeaderFilePath(projectRoot);
          },
          async read(filePath) {
            return IOSConfig.Paths.getFileInfo(filePath);
          },
          async write(filePath, { modResults: { contents } }) {
            await fs.promises.writeFile(filePath, contents);
          },
        }),
    },
  });
}

/**
 * Provides the AppDelegate header file for modification.
 *
 * @param config
 * @param action
 */
export const withAppDelegateHeader: ConfigPlugin<
  Mod<IOSConfig.Paths.AppDelegateProjectFile>
> = (config, action) => {
  return withMod(config, {
    platform: "ios",
    mod: "appDelegateHeader",
    action,
  });
};

export const withCustomHeaderInterface = (config) => {
  return withAppDelegateHeader(config, (config) => {
    console.log("modify header:", config.modResults);
    return config;
  });
};

app.config.js

// Required for external files using TS
require("ts-node/register");

import {
  withCustomBaseMods,
  withCustomHeaderInterface,
} from "./withAppDelegateHeaderBaseMod.plugin.ts";

export default ({ config }) => {
  if (!config.plugins) config.plugins = [];
  config.plugins.push(
    withCustomHeaderInterface,
    // Base mods MUST be last
    withCustomBaseMods
  );
  return config;
};

@EvanBacon EvanBacon merged commit 47fb473 into master Sep 20, 2021
@EvanBacon EvanBacon deleted the @evanbacon/config-plugins/extend-base-mods branch September 20, 2021 20:27
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants