From e4035b2730bd3603db58baf86135bab64681df40 Mon Sep 17 00:00:00 2001 From: Lluis Agusti Date: Fri, 9 Apr 2021 12:45:28 +0200 Subject: [PATCH 1/2] 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`. --- 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..83a124a55d --- /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", From 7405e4216adddecca211590c29bbde40c04309b7 Mon Sep 17 00:00:00 2001 From: Lluis Agusti Date: Fri, 9 Apr 2021 17:44:06 +0200 Subject: [PATCH 2/2] refactor(lint): fix build-types script --- config/build-types.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/config/build-types.js b/config/build-types.js index 83a124a55d..c746a5662f 100644 --- a/config/build-types.js +++ b/config/build-types.js @@ -1,19 +1,19 @@ -const fs = require("fs") -const path = require("path") +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", + '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.resolve('types', target), path.join(process.cwd(), target), (err) => { if (err) throw err