diff --git a/packages/react-cookie/package.json b/packages/react-cookie/package.json index 214960a..4010843 100644 --- a/packages/react-cookie/package.json +++ b/packages/react-cookie/package.json @@ -3,16 +3,16 @@ "version": "7.1.1", "description": "Universal cookies for React", "main": "cjs/index.js", - "types": "cjs/index.d.ts", + "types": "cjs/index.d.mts", "module": "esm/index.mjs", "exports": { ".": { "import": { - "types": "./esm/index.d.ts", + "types": "./esm/index.d.mts", "default": "./esm/index.mjs" }, "require": { - "types": "./cjs/index.d.ts", + "types": "./cjs/index.d.mts", "default": "./cjs/index.js" }, "default": "./cjs/index.js" @@ -23,7 +23,7 @@ "esm", "cjs", "umd", - "index.d.ts", + "index.d.mts", "LICENSE" ], "repository": { @@ -42,7 +42,8 @@ "license": "MIT", "scripts": { "prebuild": "rimraf esm && rimraf cjs && rimraf umd", - "build": "rollup -c" + "build": "rollup -c", + "postbuild": "node ../../tools/fix-typescript-typedef.mjs ./esm" }, "dependencies": { "@types/hoist-non-react-statics": "^3.3.5", diff --git a/packages/react-cookie/rollup.esm.mjs b/packages/react-cookie/rollup.esm.mjs deleted file mode 100644 index 952596f..0000000 --- a/packages/react-cookie/rollup.esm.mjs +++ /dev/null @@ -1,25 +0,0 @@ -import glob from 'glob'; -import path from 'node:path'; -import { fileURLToPath } from 'node:url'; -import typescript from '@rollup/plugin-typescript'; - -export default { - input: Object.fromEntries( - glob - .sync('src/**/*.{ts,tsx}') - .map((file) => [ - path.relative( - 'src', - file.slice(0, file.length - path.extname(file).length), - ), - fileURLToPath(new URL(file, import.meta.url)), - ]), - ), - output: { - dir: './esm', - format: 'esm', - entryFileNames: '[name].mjs', - }, - plugins: [typescript()], - external: ['react', 'universal-cookie', 'hoist-non-react-statics'], -}; diff --git a/packages/universal-cookie-express/package.json b/packages/universal-cookie-express/package.json index a85bf8c..78e2578 100644 --- a/packages/universal-cookie-express/package.json +++ b/packages/universal-cookie-express/package.json @@ -3,16 +3,16 @@ "version": "7.1.1", "description": "Hook cookies get/set on Express for server-rendering", "main": "cjs/index.js", - "types": "cjs/index.d.ts", + "types": "cjs/index.d.mts", "module": "esm/index.mjs", "exports": { ".": { "import": { - "types": "./esm/index.d.ts", + "types": "./esm/index.d.mts", "default": "./esm/index.mjs" }, "require": { - "types": "./cjs/index.d.ts", + "types": "./cjs/index.d.mts", "default": "./cjs/index.js" }, "default": "./cjs/index.js" @@ -40,7 +40,8 @@ "license": "MIT", "scripts": { "prebuild": "rimraf esm && rimraf cjs", - "build": "rollup -c" + "build": "rollup -c", + "postbuild": "node ../../tools/fix-typescript-typedef.mjs ./esm" }, "dependencies": { "universal-cookie": "^7.0.0" diff --git a/packages/universal-cookie-koa/package.json b/packages/universal-cookie-koa/package.json index 7d196fe..2a6b2aa 100644 --- a/packages/universal-cookie-koa/package.json +++ b/packages/universal-cookie-koa/package.json @@ -3,16 +3,16 @@ "version": "7.1.1", "description": "Hook cookies get/set on Koa for server-rendering", "main": "cjs/index.js", - "types": "cjs/index.d.ts", + "types": "cjs/index.d.mts", "module": "esm/index.mjs", "exports": { ".": { "import": { - "types": "./esm/index.d.ts", + "types": "./esm/index.d.mts", "default": "./esm/index.mjs" }, "require": { - "types": "./cjs/index.d.ts", + "types": "./cjs/index.d.mts", "default": "./cjs/index.js" }, "default": "./cjs/index.js" @@ -40,7 +40,8 @@ "license": "MIT", "scripts": { "prebuild": "rimraf esm && rimraf cjs", - "build": "rollup -c" + "build": "rollup -c", + "postbuild": "node ../../tools/fix-typescript-typedef.mjs ./esm" }, "dependencies": { "universal-cookie": "^7.0.0" diff --git a/packages/universal-cookie/index.d.ts b/packages/universal-cookie/index.d.ts deleted file mode 100644 index e660210..0000000 --- a/packages/universal-cookie/index.d.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './esm'; diff --git a/packages/universal-cookie/package.json b/packages/universal-cookie/package.json index 1d9e020..0518f5e 100644 --- a/packages/universal-cookie/package.json +++ b/packages/universal-cookie/package.json @@ -2,16 +2,16 @@ "name": "universal-cookie", "version": "7.1.1", "description": "Universal cookies for JavaScript", - "types": "cjs/index.d.ts", + "types": "cjs/index.d.mts", "module": "esm/index.mjs", "exports": { ".": { "import": { - "types": "./esm/index.d.ts", + "types": "./esm/index.d.mts", "default": "./esm/index.mjs" }, "require": { - "types": "./cjs/index.d.ts", + "types": "./cjs/index.d.mts", "default": "./cjs/index.js" }, "default": "./cjs/index.js" @@ -22,7 +22,7 @@ "esm", "cjs", "umd", - "index.d.ts", + "index.d.mts", "LICENSE" ], "repository": { @@ -40,7 +40,8 @@ "license": "MIT", "scripts": { "prebuild": "rimraf esm && rimraf cjs && rimraf umd", - "build": "rollup -c" + "build": "rollup -c", + "postbuild": "node ../../tools/fix-typescript-typedef.mjs ./esm" }, "dependencies": { "@types/cookie": "^0.6.0", diff --git a/tools/fix-typescript-typedef.mjs b/tools/fix-typescript-typedef.mjs new file mode 100644 index 0000000..fd26ae3 --- /dev/null +++ b/tools/fix-typescript-typedef.mjs @@ -0,0 +1,31 @@ +// When using ESM, the default export won't work unless we use .d.mts instead of .d.ts extension +import fs from 'fs/promises'; +import path from 'path'; + +if (process.argv.length < 3) { + throw new Error('Missing folder'); +} + +const folder = process.argv[2]; +console.log(folder); +const extLength = '.m.ts'.length; + +const files = await fs.readdir(folder); +const promises = files + .filter((file) => /\.d\.ts$/.test(file)) + .map(async (file) => { + const fullFile = path.join(folder, file); + const newFullFile = `${fullFile.substring(0, fullFile.length - extLength)}.d.mts`; + + await fs.rename(fullFile, newFullFile); + + const content = (await fs.readFile(newFullFile)).toString(); + const newContent = content.replaceAll( + / from \'([^']+)\'/g, + ` from '$1.d.mts'`, + ); + + await fs.writeFile(newFullFile, newContent); + }); + +await Promise.all(promises);