diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 1d2c0cda..b60caf43 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -23,3 +23,5 @@ jobs: - run: npm run build # Verify built artefacts - run: npm run test + # Check that the exported types resolves correctly + - run: npm run check-exports diff --git a/bin/build.js b/bin/build.js index 959eea4a..6cc343ac 100644 --- a/bin/build.js +++ b/bin/build.js @@ -45,10 +45,12 @@ function clean (groupNames) { fse.removeSync(path.join(npmPath, `${bundleName}.js`)) fse.removeSync(path.join(npmPath, `${bundleName}.mjs`)) fse.removeSync(path.join(npmPath, `${bundleName}.d.ts`)) + fse.removeSync(path.join(npmPath, `${bundleName}.d.mts`)) // Remove old npm jsx content fse.removeSync(path.join(npmJsxFolder, npmPath, `${bundleName}.js`)) fse.removeSync(path.join(npmJsxFolder, npmPath, `${bundleName}.mjs`)) fse.removeSync(path.join(npmJsxFolder, npmPath, `${bundleName}.d.ts`)) + fse.removeSync(path.join(npmJsxFolder, npmPath, `${bundleName}.d.mts`)) // Ensure npm folders exist (for icons it's '' which is falsy) if (npmPath) fse.mkdirsSync(npmPath) @@ -140,11 +142,13 @@ function buildIcons (groupName) { fse.writeFileSync(path.join(npmPath, `${bundleName}.js`), icons.cjs) fse.writeFileSync(path.join(npmPath, `${bundleName}.mjs`), icons.esm) fse.writeFileSync(path.join(npmPath, `${bundleName}.d.ts`), icons.dtsLiteral) + fse.writeFileSync(path.join(npmPath, `${bundleName}.d.mts`), icons.dtsLiteral) // Generate jsx and mjsx with types for icons and logos fse.writeFileSync(path.join(npmJsxFolder, npmPath, `${bundleName}.js`), icons.cjsx) fse.writeFileSync(path.join(npmJsxFolder, npmPath, `${bundleName}.mjs`), icons.esmx) fse.writeFileSync(path.join(npmJsxFolder, npmPath, `${bundleName}.d.ts`), icons.dtsx) + fse.writeFileSync(path.join(npmJsxFolder, npmPath, `${bundleName}.d.mts`), icons.dtsx) // Generate js/jsx artefacts for logo/large -files if (groupName === 'logo') { @@ -162,20 +166,24 @@ function buildIcons (groupName) { fse.removeSync(path.join(npmLargePath, `${largeBundleName}.js`)) fse.removeSync(path.join(npmLargePath, `${largeBundleName}.mjs`)) fse.removeSync(path.join(npmLargePath, `${largeBundleName}.d.ts`)) + fse.removeSync(path.join(npmLargePath, `${largeBundleName}.d.mts`)) // Remove old npm jsx content fse.removeSync(path.join(npmJsxFolder, npmLargePath, `${largeBundleName}.js`)) fse.removeSync(path.join(npmJsxFolder, npmLargePath, `${largeBundleName}.mjs`)) fse.removeSync(path.join(npmJsxFolder, npmLargePath, `${largeBundleName}.d.ts`)) + fse.removeSync(path.join(npmJsxFolder, npmLargePath, `${largeBundleName}.d.mts`)) // Generate js and mjs with types for icons and logos fse.writeFileSync(path.join(npmLargePath, `${largeBundleName}.js`), largeIcons.cjs) fse.writeFileSync(path.join(npmLargePath, `${largeBundleName}.mjs`), largeIcons.esm) fse.writeFileSync(path.join(npmLargePath, `${largeBundleName}.d.ts`), largeIcons.dtsLiteral) + fse.writeFileSync(path.join(npmLargePath, `${largeBundleName}.d.mts`), largeIcons.dtsLiteral) // Generate jsx and mjsx with types for icons and logos fse.writeFileSync(path.join(npmJsxFolder, npmLargePath, `${largeBundleName}.js`), largeIcons.cjsx) fse.writeFileSync(path.join(npmJsxFolder, npmLargePath, `${largeBundleName}.mjs`), largeIcons.esmx) fse.writeFileSync(path.join(npmJsxFolder, npmLargePath, `${largeBundleName}.d.ts`), largeIcons.dtsx) + fse.writeFileSync(path.join(npmJsxFolder, npmLargePath, `${largeBundleName}.d.mts`), largeIcons.dtsx) } } catch (error) { console.error(`Failed to generate large js files for ${groupName} with error `, error) diff --git a/package-lock.json b/package-lock.json index db10448b..cf0645b4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,7 +12,7 @@ "svg2vectordrawable": "2.9.1" }, "devDependencies": { - "@arethetypeswrong/cli": "0.15.4", + "@arethetypeswrong/cli": "^0.15.4", "@nrk/svg-to-js": "3.1.0", "@types/fs-extra": "11.0.4", "archiver": "6.0.1", @@ -39,6 +39,7 @@ "resolved": "https://registry.npmjs.org/@arethetypeswrong/cli/-/cli-0.15.4.tgz", "integrity": "sha512-YDbImAi1MGkouT7f2yAECpUMFhhA1J0EaXzIqoC5GGtK0xDgauLtcsZezm8tNq7d3wOFXH7OnY+IORYcG212rw==", "dev": true, + "license": "MIT", "dependencies": { "@arethetypeswrong/core": "0.15.1", "chalk": "^4.1.2", diff --git a/package.json b/package.json index f2878569..e406334b 100644 --- a/package.json +++ b/package.json @@ -16,59 +16,110 @@ "./core-icons-iife.js", "./core-icons.js", "./core-icons.mjs", - "./core-icons.d.ts" + "./core-icons.d.ts", + "./core-icons.d.mts" ], "exports": { ".": { - "types": "./core-icons.d.ts", - "require": "./core-icons.js", - "import": "./core-icons.mjs", + "require": { + "default": "./core-icons.js", + "types": "./core-icons.d.ts" + }, + "import": { + "default": "./core-icons.mjs", + "types": "./core-icons.d.mts" + }, "browser": "./core-icons-iife.js" }, "./logo": { - "types": "./logo/core-icons-logo.d.ts", - "require": "./logo/core-icons-logo.js", - "import": "./logo/core-icons-logo.mjs" + "require": { + "default": "./logo/core-icons-logo.js", + "types": "./logo/core-icons-logo.d.ts" + }, + "import": { + "default": "./logo/core-icons-logo.mjs", + "types": "./logo/core-icons-logo.d.mts" + } }, "./logo/large": { - "types": "./logo/large/core-icons-logo-large.d.ts", - "require": "./logo/large/core-icons-logo-large.js", - "import": "./logo/large/core-icons-logo-large.mjs" + "require": { + "default": "./logo/large/core-icons-logo-large.js", + "types": "./logo/large/core-icons-logo-large.d.ts" + }, + "import": { + "default": "./logo/large/core-icons-logo-large.mjs", + "types": "./logo/large/core-icons-logo-large.d.mts" + } }, "./expressive": { - "types": "./expressive/core-icons-expressive.d.ts", - "require": "./expressive/core-icons-expressive.js", - "import": "./expressive/core-icons-expressive.mjs" + "require": { + "default": "./expressive/core-icons-expressive.js", + "types": "./expressive/core-icons-expressive.d.ts" + }, + "import": { + "default": "./expressive/core-icons-expressive.mjs", + "types": "./expressive/core-icons-expressive.d.mts" + } }, "./preview": { - "types": "./preview/core-icons-preview.d.ts", - "require": "./preview/core-icons-preview.js", - "import": "./preview/core-icons-preview.mjs" + "require": { + "default": "./preview/core-icons-preview.js", + "types": "./preview/core-icons-preview.d.ts" + }, + "import": { + "default": "./preview/core-icons-preview.mjs", + "types": "./preview/core-icons-preview.d.mts" + } }, "./jsx": { - "types": "./jsx/core-icons.d.ts", - "require": "./jsx/core-icons.js", - "import": "./jsx/core-icons.mjs" + "require": { + "default": "./jsx/core-icons.js", + "types": "./jsx/core-icons.d.ts" + }, + "import": { + "default": "./jsx/core-icons.mjs", + "types": "./jsx/core-icons.d.mts" + } }, "./jsx/logo": { - "types": "./jsx/logo/core-icons-logo.d.ts", - "require": "./jsx/logo/core-icons-logo.js", - "import": "./jsx/logo/core-icons-logo.mjs" + "require": { + "default": "./jsx/logo/core-icons-logo.js", + "types": "./jsx/logo/core-icons-logo.d.ts" + }, + "import": { + "default": "./jsx/logo/core-icons-logo.mjs", + "types": "./jsx/logo/core-icons-logo.d.mts" + } }, "./jsx/logo/large": { - "types": "./jsx/logo/large/core-icons-logo-large.d.ts", - "require": "./jsx/logo/large/core-icons-logo-large.js", - "import": "./jsx/logo/large/core-icons-logo-large.mjs" + "require": { + "default": "./jsx/logo/large/core-icons-logo-large.js", + "types": "./jsx/logo/large/core-icons-logo-large.d.ts" + }, + "import": { + "default": "./jsx/logo/large/core-icons-logo-large.mjs", + "types": "./jsx/logo/large/core-icons-logo-large.d.mts" + } }, "./jsx/expressive": { - "types": "./jsx/expressive/core-icons-expressive.d.ts", - "require": "./jsx/expressive/core-icons-expressive.js", - "import": "./jsx/expressive/core-icons-expressive.mjs" + "require": { + "default": "./jsx/expressive/core-icons-expressive.js", + "types": "./jsx/expressive/core-icons-expressive.d.ts" + }, + "import": { + "default": "./jsx/expressive/core-icons-expressive.mjs", + "types": "./jsx/expressive/core-icons-expressive.d.mts" + } }, "./jsx/preview": { - "types": "./jsx/preview/core-icons-preview.d.ts", - "require": "./jsx/preview/core-icons-preview.js", - "import": "./jsx/preview/core-icons-preview.mjs" + "require": { + "default": "./jsx/preview/core-icons-preview.js", + "types": "./jsx/preview/core-icons-preview.d.ts" + }, + "import": { + "default": "./jsx/preview/core-icons-preview.mjs", + "types": "./jsx/preview/core-icons-preview.d.mts" + } } }, "scripts": { @@ -83,10 +134,11 @@ "preversion": "npm run test", "postversion": "npm run build && git push && git push --tags && npm publish", "start": "npm run build:watch & http-server ./static -o -p 10001 -c-1", - "static-publish": "npm run build && static-publish --directory=static --account=nrk-core --latest --major" + "static-publish": "npm run build && static-publish --directory=static --account=nrk-core --latest --major", + "check-exports": "attw --pack ." }, "devDependencies": { - "@arethetypeswrong/cli": "0.15.4", + "@arethetypeswrong/cli": "^0.15.4", "@nrk/svg-to-js": "3.1.0", "@types/fs-extra": "11.0.4", "archiver": "6.0.1",