From 0d863d38bc5ef1b56c848cc29861591fc498c266 Mon Sep 17 00:00:00 2001 From: Lluis Agusti Date: Fri, 9 Apr 2021 20:28:11 +0200 Subject: [PATCH] fix(ts): correctly export sub-module types (#1677) * chore(types): build types script Adds a script that moves the declaration files we have in `./types` to `./dist` relative to the files they intend to type. This is the first step, we still need to change what we declare in `package.json`, add the script to the CI pipeline if we're happy with it and figure out how to type `next-auth/jwt`. * refactor(lint): fix build-types script --- config/build-types.js | 23 +++++++++++++++++++++++ package.json | 3 ++- 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 config/build-types.js diff --git a/config/build-types.js b/config/build-types.js new file mode 100644 index 0000000000..c746a5662f --- /dev/null +++ b/config/build-types.js @@ -0,0 +1,23 @@ +const fs = require('fs') +const path = require('path') + +const BUILD_TARGETS = [ + 'index.d.ts', + 'client.d.ts', + 'adapters.d.ts', + 'providers.d.ts', + 'jwt.d.ts', + '_next.d.ts', + '_utils.d.ts' +] + +BUILD_TARGETS.forEach((target) => { + fs.copyFile( + path.resolve('types', target), + path.join(process.cwd(), target), + (err) => { + if (err) throw err + console.log(`[build-types] copying "${target}" to root folder`) + } + ) +}) diff --git a/package.json b/package.json index a409d3509e..fd1992a11f 100644 --- a/package.json +++ b/package.json @@ -7,9 +7,10 @@ "author": "Iain Collins ", "main": "index.js", "scripts": { - "build": "npm run build:js && npm run build:css", + "build": "npm run build:js && npm run build:css && npm run build:types", "build:js": "babel --config-file ./config/babel.config.json src --out-dir dist", "build:css": "postcss --config config/postcss.config.js src/**/*.css --base src --dir dist && node config/wrap-css.js", + "build:types": "node ./config/build-types.js", "dev": "next | npm run watch:css", "watch": "npm run watch:js | npm run watch:css", "watch:js": "babel --config-file ./config/babel.config.json --watch src --out-dir dist",