diff --git a/package.json b/package.json index d34e731..0a6d831 100644 --- a/package.json +++ b/package.json @@ -1,10 +1,18 @@ { "name": "@atom-learning/icons", - "main": "dist/index.cjs.js", + "type": "module", + "main": "dist/index.cjs", "module": "dist/index.js", "types": "dist/index.d.ts", - "version": "1.22.0", + "version": "1.23.0", "description": "", + "exports": { + ".": { + "types": "./dist/index.d.ts", + "import": "./dist/index.js", + "require": "./dist/index.cjs" + } + }, "files": [ "dist" ], @@ -12,7 +20,8 @@ "scripts": { "build": "tsm ./scripts/build-export.ts", "clean": "del ./dist/", - "test": "yarn clean && yarn build", + "test": "yarn clean && yarn build && yarn test:ssr", + "test:ssr": "node --test scripts/ssr.test.mjs scripts/ssr.test.cjs", "prepublishOnly": "yarn test", "start:sandbox": "yarn build && vite serve sandbox" }, diff --git a/scripts/build-export.ts b/scripts/build-export.ts index 6b43af2..0a1c3d4 100644 --- a/scripts/build-export.ts +++ b/scripts/build-export.ts @@ -77,7 +77,7 @@ const outputTypeDeclarations = async (icons: Record) => { const outputCJSBundle = async () => { await buildSync({ entryPoints: [path.resolve(DIRECTORY_OUTPUT, 'index.js')], - outfile: path.resolve(DIRECTORY_OUTPUT, 'index.cjs.js'), + outfile: path.resolve(DIRECTORY_OUTPUT, 'index.cjs'), format: 'cjs', bundle: true, external: ['react'], @@ -90,7 +90,7 @@ const createESExportString = async (icons: Record) => { // const filePaths = await glob.sync(`${source}/*.svg`) // apply export template to each and combine into single string return Object.entries(icons) - .map(([name]) => `export * from './${name}'\n`) + .map(([name]) => `export * from './${name}.js'\n`) .join('') } diff --git a/scripts/ssr.test.cjs b/scripts/ssr.test.cjs new file mode 100644 index 0000000..bb88f7d --- /dev/null +++ b/scripts/ssr.test.cjs @@ -0,0 +1,14 @@ +const { test } = require('node:test') +const assert = require('node:assert/strict') +const icons = require('@atom-learning/icons') + +test('CJS: package resolves via exports map in a Node SSR context', () => { + assert.ok(Object.keys(icons).length > 0, 'expected named exports') +}) + +test('CJS: known icons are exported as React components', () => { + for (const name of ['Accessibility', 'Activity', 'Add']) { + assert.equal(typeof icons[name], 'object', `${name} should be a forwardRef component`) + assert.equal(icons[name].displayName, name) + } +}) diff --git a/scripts/ssr.test.mjs b/scripts/ssr.test.mjs new file mode 100644 index 0000000..66597a1 --- /dev/null +++ b/scripts/ssr.test.mjs @@ -0,0 +1,14 @@ +import { test } from 'node:test' +import assert from 'node:assert/strict' +import * as icons from '@atom-learning/icons' + +test('ESM: package resolves via exports map in a Node SSR context', () => { + assert.ok(Object.keys(icons).length > 0, 'expected named exports') +}) + +test('ESM: known icons are exported as React components', () => { + for (const name of ['Accessibility', 'Activity', 'Add']) { + assert.equal(typeof icons[name], 'object', `${name} should be a forwardRef component`) + assert.equal(icons[name].displayName, name) + } +})