From 00fc7505cc2e36ce86592ab60527b44c103387b9 Mon Sep 17 00:00:00 2001 From: Colin Rotherham Date: Mon, 2 Oct 2023 13:49:44 +0100 Subject: [PATCH] Publish type declarations --- packages/govuk-frontend-review/package.json | 2 +- packages/govuk-frontend/package.json | 4 +++- packages/govuk-frontend/tasks/build/package.unit.test.mjs | 3 ++- packages/govuk-frontend/tsconfig.build.json | 5 +++++ 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/govuk-frontend-review/package.json b/packages/govuk-frontend-review/package.json index 7120a0b71f..faf0651f8c 100644 --- a/packages/govuk-frontend-review/package.json +++ b/packages/govuk-frontend-review/package.json @@ -15,7 +15,7 @@ "build:sassdoc": "sassdoc --config sassdoc.config.yaml ../govuk-frontend/src/govuk", "build:types": "tsc --build tsconfig.build.json", "build:jsdoc": "typedoc", - "postbuild": "npm run build:jsdoc && npm run build:sassdoc", + "postbuild": "npm run build:jsdoc && npm run build:sassdoc && npm run build:types", "clean": "del-cli dist", "proxy": "browser-sync start --config browsersync.config.js", "serve": "nodemon", diff --git a/packages/govuk-frontend/package.json b/packages/govuk-frontend/package.json index 0fd94afdd5..d97890184c 100644 --- a/packages/govuk-frontend/package.json +++ b/packages/govuk-frontend/package.json @@ -4,6 +4,7 @@ "version": "5.0.0", "main": "dist/govuk/all.bundle.js", "module": "dist/govuk/all.mjs", + "types": "dist/govuk/all.d.mts", "sass": "dist/govuk/all.scss", "files": [ "dist", @@ -13,6 +14,7 @@ ], "exports": { ".": { + "types": "./dist/govuk/all.d.mts", "sass": "./dist/govuk/all.scss", "import": "./dist/govuk/all.mjs", "require": "./dist/govuk/all.bundle.js", @@ -57,7 +59,7 @@ "clean": "npm run clean:package", "clean:package": "del-cli *.tsbuildinfo dist govuk-prototype-kit.config.json", "clean:release": "del-cli ../../dist --force", - "postbuild:package": "npm run build:stats && govuk-prototype-kit validate-plugin .", + "postbuild:package": "npm run build:stats && npm run build:types && govuk-prototype-kit validate-plugin .", "version": "echo $npm_package_version" }, "devDependencies": { diff --git a/packages/govuk-frontend/tasks/build/package.unit.test.mjs b/packages/govuk-frontend/tasks/build/package.unit.test.mjs index 8530118a14..f081cc25a1 100644 --- a/packages/govuk-frontend/tasks/build/package.unit.test.mjs +++ b/packages/govuk-frontend/tasks/build/package.unit.test.mjs @@ -74,7 +74,8 @@ describe('packages/govuk-frontend/dist/', () => { .flatMap( mapPathTo(['**/*.mjs'], ({ dir: requirePath, name }) => [ join(requirePath, `${name}.mjs`), - join(requirePath, `${name}.mjs.map`) // with source map + join(requirePath, `${name}.mjs.map`), // with source map + join(requirePath, `${name}.d.mts`) // with type declaration ]) ) diff --git a/packages/govuk-frontend/tsconfig.build.json b/packages/govuk-frontend/tsconfig.build.json index 7d16b65566..e599c09192 100644 --- a/packages/govuk-frontend/tsconfig.build.json +++ b/packages/govuk-frontend/tsconfig.build.json @@ -3,7 +3,12 @@ "include": ["./src/govuk/**/*.mjs"], "exclude": ["**/*.test.*"], "compilerOptions": { + "declaration": true, + "emitDeclarationOnly": true, "lib": ["ESNext", "DOM"], + "noEmit": false, + "outDir": "./dist", + "rootDir": "./src", "strict": true, "target": "ES2015", "types": ["node", "typed-query-selector"]