diff --git a/package.json b/package.json index c5c7520..2e6af74 100644 --- a/package.json +++ b/package.json @@ -6,8 +6,15 @@ "homepage": "https://mafs.dev", "repository": "github:stevenpetryk/mafs", "source": "src/index.tsx", - "main": "build/index.js", - "module": "build/index.mjs", + "type": "module", + "exports": { + ".": { + "import": "./build/index.js", + "require": "./build/index.cjs" + }, + "./core.css": "./core.css", + "./font.css": "./font.css" + }, "types": "build/index.d.ts", "packageManager": "pnpm@9.5.0", "engines": { diff --git a/scripts/build.ts b/scripts/build.ts index b72804b..0e8e1cd 100644 --- a/scripts/build.ts +++ b/scripts/build.ts @@ -5,7 +5,8 @@ import typescript from "typescript" import invariant from "tiny-invariant" const packageJson = fs.readJsonSync("./package.json") -const { main: cjsOutFile, module: esmOutFile, peerDependencies, dependencies } = packageJson +const { exports, peerDependencies, dependencies } = packageJson +const { import: esmOutFile, require: cjsOutFile } = exports["."] async function main() { fs.emptyDirSync("build") diff --git a/scripts/testgen.ts b/scripts/testgen.ts index 34d35f0..cd5dd2b 100644 --- a/scripts/testgen.ts +++ b/scripts/testgen.ts @@ -12,7 +12,7 @@ const SKIP = [ /latex/i, ] -const mafsRoot = path.join(__dirname, "..") +const mafsRoot = path.join(import.meta.dirname, "..") const guideExamplesFolder = path.join(mafsRoot, "docs/components/guide-examples") @@ -23,7 +23,7 @@ const examples = glob .filter((filepath) => !SKIP.some((skip) => skip.test(filepath))) let testFileContent = ` -// THIS FILE IS GENERATED BY ./${path.relative(mafsRoot, __filename)} +// THIS FILE IS GENERATED BY ./${path.relative(mafsRoot, import.meta.filename)} /* eslint-disable @typescript-eslint/no-explicit-any */ import { expect, test } from "@playwright/experimental-ct-react" @@ -72,7 +72,7 @@ for (const example of examples) { ` } -prettier.resolveConfig(__filename).then(async (config) => { +prettier.resolveConfig(import.meta.filename).then(async (config) => { const formattedTestFileContent = await prettier.format(testFileContent, { parser: "typescript", ...config,