From 206decf92201e86b642c9eac8e25db39d18de593 Mon Sep 17 00:00:00 2001 From: Lukas Weiss Date: Thu, 3 Oct 2024 14:51:47 +0200 Subject: [PATCH] migrate to esm module --- generator.js | 18 +++++++++--------- package.json | 1 + tsconfig.json | 8 ++++---- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/generator.js b/generator.js index 5d8987218..e196d0cfa 100644 --- a/generator.js +++ b/generator.js @@ -1,6 +1,6 @@ -const fs = require('fs') -const path = require('path') -const axios = require('axios') +import fs from 'fs' +import path from 'path' +import axios from 'axios' const GOOGLE_FONTS_URL = 'https://fonts.google.com/metadata/icons?key=material_symbols&incomplete=true' @@ -42,17 +42,17 @@ function generatePropsFile() { } ` - fs.writeFileSync(path.join(__dirname, 'src', 'types.ts'), typesFile) + fs.writeFileSync(path.join('src', 'types.ts'), typesFile) } function generateIndexFile() { - return fs.writeFileSync(path.join(__dirname, 'src', 'index.ts'), '') + return fs.writeFileSync(path.join('src', 'index.ts'), '') } function appendToIndexFile(iconName) { return fs.appendFileSync( - path.join(__dirname, 'src', 'index.ts'), - `export * from './${iconName}'\n`, + path.join('src', 'index.ts'), + `export * from './${iconName}.js'\n`, ) } @@ -76,7 +76,7 @@ async function generateComponent(icon, family, filled = false) { console.log(`Downloading ${name}`) await fs.writeFileSync( - path.join(__dirname, 'src', `${name}.tsx`), + path.join('src', `${name}.tsx`), mapSVGToTemplate(name, svg), ) @@ -123,7 +123,7 @@ async function downloadSVG(icon, familyId, filled) { function mapSVGToTemplate(name, svg) { return ` import React from 'react' - import { IconProps } from './types' + import { IconProps } from './types.js' export const ${name}: React.FC = ({ ...props }) => ( ${svg} diff --git a/package.json b/package.json index 1c6e063e7..8369d1e19 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ "publishConfig": { "access": "public" }, + "type": "module", "main": "dist/index.js", "files": [ "readme.md", diff --git a/tsconfig.json b/tsconfig.json index 0ced7aced..60a842594 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,9 +1,9 @@ { "compilerOptions": { - "module": "CommonJS", - "target": "ES5", + "module": "NodeNext", + "moduleResolution": "NodeNext", + "target": "ES2022", "jsx": "react", - "moduleResolution": "Node", "esModuleInterop": true, "outDir": "./dist", "declaration": true, @@ -11,5 +11,5 @@ "sourceMap": false }, "include": ["src"], - "exclude": ["node_modules", "**/__test__/*", "**/__tests__/*"] + "exclude": ["node_modules"] }