Skip to content

Conversation

@rekmarks
Copy link
Member

@rekmarks rekmarks commented Nov 24, 2023

Explanation

In MetaMask/metamask-mobile#7734, code fence support was added to MetaMask Mobile by essentially copypasting the implementation from the extension. This PR extracts the shared logic from the extension and mobile implementations of code fencing into a new package, @metamask/build-utils, which can be imported into the respective clients. A draft integration in the extension can be found in MetaMask/metamask-extension#22033, which uses local copies of the built version of the new package.

@metamask/build-utils currently implements the shared logic for code fence parsing and removal,, as well as linting transformed files. The consumer is responsible for integrating the fence parser into the given build system, and configuring the ESLint instance used for linting.

Noteworthy changes / decisions made:

  • ONLY_INCLUDE_IN has been renamed to ONLY_INCLUDE_IF, which is more in line with its actual usage.
    • When code fencing was originally implemented, we imagined that it would be used to differentiate between specific builds, e.g. "main" and "beta". Since then, the parameters of the command are labels corresponding to different features. Thus, fenced code is not included in certain builds so much as if certain features are enabled.
  • The decision to only extract the removeFencedCode and lintTransformedFile functions was made for two reasons primarily:

References

Changelog

@metamask/build-utils

  • Added: Initial release

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've highlighted breaking changes using the "BREAKING" category above as appropriate

@socket-security
Copy link

New dependencies detected. Learn more about Socket for GitHub ↗︎

Packages Version New capabilities Transitives Size Publisher
@types/eslint 8.44.7 None +2 230 kB types

@rekmarks rekmarks force-pushed the add-build-utils-package branch from e128233 to 0a78bb7 Compare November 24, 2023 01:00
@rekmarks rekmarks marked this pull request as ready for review November 24, 2023 01:00
@rekmarks rekmarks requested a review from a team as a code owner November 24, 2023 01:00
- Fix title in readme
- Add default for shouldLintTransformFiles in
  package readme
- Simply ESLint mock in test
@rekmarks rekmarks force-pushed the add-build-utils-package branch from 0a78bb7 to 204d142 Compare November 25, 2023 02:09
- Emphasize that stylistic rules should probably
  be disabled for the ESLint instance.
- Address parameter order inconsistency with
  removeFencedCode.
Copy link
Contributor

@Jonathansoufer Jonathansoufer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job! LGTM!

@rekmarks rekmarks merged commit 0b75d37 into main Nov 29, 2023
@rekmarks rekmarks deleted the add-build-utils-package branch November 29, 2023 17:03
"@types/eslint": "^8.44.7",
"@types/jest": "^27.4.1",
"deepmerge": "^4.2.2",
"eslint": "^8.44.0",
Copy link
Contributor

@mcmire mcmire Nov 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that this is in devDependencies, but lintTransformedFile takes an argument that's of type ESLint. So, two questions:

  1. Where does this type come from — does it come from this package or @types/eslint? Do we need both or just one?
  2. ESLint will show up in the type definition file for src/transforms/utils.ts, so anyone who uses this library in a TypeScript will need that type in order to compile their code. We've encountered problems with this type of thing before and the solution has been to move the library in question to dependencies (e.g., Move eth-query back from devDeps to deps #3578). What are your thoughts on moving either eslint or @types/eslint to dependencies?

rekmarks added a commit that referenced this pull request Nov 30, 2023
…cy (#3588)

## Explanation

Following the recommendation of @mcmire, converts `@types/eslint` from a
dev to production dependency of `@metamask/build-utils`.

The reason:
> ESLint will show up in the type definition file for
`src/transforms/utils.ts`, so anyone who uses this library in a
TypeScript will need that type in order to compile their code.

## References

- #3577 (comment)

## Changelog

N/A (package unreleased)

## Checklist

- [x] I've updated the test suite for new or updated code as appropriate
- [x] I've updated documentation (JSDoc, Markdown, etc.) for new or
updated code as appropriate
- [x] I've highlighted breaking changes using the "BREAKING" category
above as appropriate
rekmarks added a commit to MetaMask/metamask-extension that referenced this pull request Dec 4, 2023
## **Description**

In MetaMask/metamask-mobile#7734, code fence
support was added to MetaMask Mobile by essentially copypasting the
implementation from the extension. This PR replaces the local code fence
implementation with a version that was extracted into its own package.

The external package implements code fence parsing and removal, as well
as linting transformed files. The consumer is responsible for
integrating the fence parser into the given build system, and
configuring the ESLint instance used for linting. Consequently, the
following remains in this repository after extracting the fence parsers:
- `RemoveFencedCodeTransform`, a transform stream compatible with
Browserify
- A utility for configuring and initializing a singleton ESLint instance

The PR is deceptively large; most changes are due to renaming existing
fences. For reviewers, the relevant files are:
- `development/build/transforms/*`
- `lavamoat/build-system/policy.json`

## **Related issues**

- MetaMask/core#3577
- MetaMask/metamask-mobile#7972

## **Manual testing steps**

1. Create different builds of the extension and verify that they are
working and include the correct features

---------

Co-authored-by: MetaMask Bot <metamaskbot@users.noreply.github.com>
rekmarks added a commit to MetaMask/metamask-mobile that referenced this pull request Dec 6, 2023
#7972)

## **Description**

In #7734, code fence
support was added to MetaMask Mobile by essentially copypasting the
implementation from the extension. This PR replaces the local code fence
implementation with a version that was extracted into its own package.

The external package implements code fence parsing and removal, as well
as linting transformed files. The consumer is responsible for
integrating the fence parser into the given build system, and
configuring the ESLint instance used for linting. Consequently, only the
Metro transform and the ESLint instance initialization remain in this
repository.

## **Related issues**

- MetaMask/core#3577
- MetaMask/metamask-extension#22033

## **Manual testing steps**

1. Check that different build types are built correctly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants