Skip to content

Commit

Permalink
Enhance TS options (#496)
Browse files Browse the repository at this point in the history
  • Loading branch information
paescuj authored Dec 15, 2024
1 parent 401a53c commit e7919b7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
8 changes: 8 additions & 0 deletions bin/build/lib/ts.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import ts from 'typescript';

/**
*
* @param {string} path
* @param {string} content
* @param {import('types-tsconfig').TSConfigJSON['compilerOptions']} options
*/
export function getDts(path, content, options) {
options = ts.convertCompilerOptionsFromJson(options, '').options;

let output;

const host = ts.createCompilerHost(options);
Expand Down
9 changes: 6 additions & 3 deletions bin/build/targets/react/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@ const jsTargets = [
/** @type {import('esbuild').TransformOptions} */
const defaultEsbuildOptions = { target: 'es6', minify: true };

/** @type {import('typescript').CompilerOptions} */
/** @type {import('types-tsconfig').TSConfigJSON['compilerOptions']} */
const defaultTsOptions = {
jsx: 'react',
declaration: true,
emitDeclarationOnly: true,
target: 'es6',
Expand Down Expand Up @@ -90,6 +89,7 @@ export default async (ctx, target) => {
iconoirContextDtsPath,
iconoirContext,
jsTarget.module,
target.native,
);

for (const variant of Object.keys(ctx.icons)) {
Expand Down Expand Up @@ -152,6 +152,7 @@ export default async (ctx, target) => {
dtsPath,
reactComponent,
jsTarget.module,
target.native,
);

promises.push(iconDts);
Expand Down Expand Up @@ -180,10 +181,12 @@ async function getReactComponent(iconPath, native, template) {
return svgr.transform(iconContent, options);
}

async function generateDts(inputPath, outputPath, input, module) {
async function generateDts(inputPath, outputPath, input, module, native) {
const dts = getDts(inputPath, await input, {
...defaultTsOptions,
jsx: native ? 'react-native' : 'react',
module,
...(module === 'esnext' && { moduleResolution: 'bundler' }),
});

return fs.writeFile(outputPath, dts);
Expand Down

0 comments on commit e7919b7

Please sign in to comment.