Skip to content

Commit

Permalink
Fix types
Browse files Browse the repository at this point in the history
  • Loading branch information
sandhose committed Jul 12, 2024
1 parent 658b175 commit 6b72ca0
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
32 changes: 32 additions & 0 deletions src/global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
Copyright 2024 New Vector Ltd.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

// Stub declarations, as svgr types depend on these, but we don't have them installed
declare module "prettier" {
export interface Options {}
}

declare module "svgo" {
export interface Config {}
}

// This module doens't have a type definition
declare module "@babel/plugin-transform-react-jsx" {
import type { PluginItem } from "@babel/core";

const babelTransformReactJsx: PluginItem;
export default babelTransformReactJsx;
}
10 changes: 7 additions & 3 deletions src/utils/generateIconTokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,17 @@ import path from "node:path";
import { fileURLToPath } from "node:url";

import type { TransformOptions as BabelOptions } from "@babel/core";
import generate from "@babel/generator";
import generate_ from "@babel/generator";
import babelTransformReactJsx from "@babel/plugin-transform-react-jsx";
import t from "@babel/types";
import { type ConfigPlugin, transform as svgrTransform } from "@svgr/core";
import svgrPluginJsx from "@svgr/plugin-jsx";
import { camelCase, startCase } from "lodash-es";

// Types for the default export of @babel/generator are wrong
const generate = (generate_ as unknown as { default: typeof generate_ })
.default;

/**
* Generates `icons/$icons.json` and React components off all the
* SVG icons discovered in the `icons/` folder
Expand Down Expand Up @@ -205,12 +209,12 @@ export default ${componentName};
]);

// Generate the index.cjs file
const cjsCode = generate.default(cjsProgram).code;
const cjsCode = generate(cjsProgram).code;
await fs.writeFile(path.join(webOutput, "index.cjs"), cjsCode, "utf-8");

// Generate the index.js file
const esmProgram = t.program(indexEsmStatements, [], "module");
const esmCode = generate.default(esmProgram).code;
const esmCode = generate(esmProgram).code;
await fs.writeFile(path.join(webOutput, "index.js"), esmCode, "utf-8");

// The index.d.ts is identical to the index.js as it only re-exports the icons
Expand Down

0 comments on commit 6b72ca0

Please sign in to comment.