Skip to content

Commit

Permalink
Use babel for transpilation
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandernanberg committed Dec 17, 2024
1 parent 58fdc32 commit 3e48ca3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
3 changes: 0 additions & 3 deletions packages/babel-plugin-fbtee/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,5 @@
"@types/babel__core": "^7.20.5",
"@types/babel__traverse": "^7.20.6",
"@types/glob": "^8.1.0"
},
"peerDependencies": {
"typescript": "^5.7.0"
}
}
18 changes: 12 additions & 6 deletions packages/babel-plugin-fbtee/src/bin/manifestUtils.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import fs from 'node:fs';
import { parse, relative, resolve } from 'node:path';
import { transformSync } from '@babel/core';
import presetReact from '@babel/preset-react';
import presetTypeScript from '@babel/preset-typescript';
import { globSync } from 'glob';
import invariant from 'invariant';
import ts from 'typescript';
import {
FBT_ENUM_MODULE_SUFFIX as ENUM_FILE,
ModuleNameRegExp,
Expand Down Expand Up @@ -34,18 +36,22 @@ export async function generateManifest(
);

for (const filepath of enumFiles) {
const name = parse(filepath).name;
const tsContent = fs.readFileSync(filepath, 'utf8');
const jsContent = ts.transpile(tsContent, {
module: ts.ModuleKind.ESNext,
target: ts.ScriptTarget.ESNext,
const result = transformSync(tsContent, {
ast: false,
filename: filepath,
presets: [presetTypeScript, presetReact],
sourceType: 'module',
});

const jsDataUrl = `data:text/javascript;base64,${Buffer.from(jsContent).toString('base64')}`;
invariant(result?.code, 'Unable to transform `%s`', filepath);

const jsDataUrl = `data:text/javascript;base64,${Buffer.from(result.code).toString('base64')}`;

const module = await import(jsDataUrl);
const enumValue: EnumModule = module.default;

const name = parse(filepath).name;
invariant(
enumValue != null,
'No valid enum found for `%s`, ensure you are exporting your enum ' +
Expand Down
3 changes: 0 additions & 3 deletions pnpm-lock.yaml

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

0 comments on commit 3e48ca3

Please sign in to comment.