hedgedoc/commons/package.json

71 lines
1.7 KiB
JSON
Raw Normal View History

{
"name": "@hedgedoc/commons",
"private": true,
fix(commons): replace microbundle with bash based compile script The commons package ships wrong types because it is refering to the same files for the ESM and the CJS build. See https://arethetypeswrong.github.io/?p=%40mrdrogdrog%2Foptional%401.1.0 This happens because microbundle can handle the generation of `.mjs` and `.cjs` from files itself but delegates the generation of types entirely to typescript by running it once. Microbundle uses the "type" field from the package.json to know if a `.js` file is meant to be mjs or cjs and generates the other type by using the specific file extension `.cjs` and `.mjs` (so if your package is a `type: module`, then `.js` file are interpreted as ECMAModule and if you have a commonjs file you need to name it `.cjs`). But this causes a problem with typescript. If you use typescript with the newer module resolver then it expects the type declarations to be named exactly like the file you wanna import. So if you have a `.js` file it will try to look up types in a `.d.ts` file. If it is resolving a `.mjs` file it is looking for a `.d.mts` file. This clashes with the types generated by microbundle because you can't use a `.mjs` file with a `.d.ts` file. Running typescript multiple times can also be complicated. When generating type declaration files, typescript takes a look at the source file extension. So a `.mts` file will generate a `.mjs` and a `.d.mts` file. A `.ts` will generate a `.js` and `.d.ts` file. It doesn't matter if you run microbundle on `.ts`, `.mts` or `.cjs` files, it will only generate the type declarations once. How do you get the other type declaration? To solve this problem you either have to run typescript multiple times and manipulate the input or output data to have correct `.d.mts` / `.d.cts` files AND imports... or do what this PR changes. It runs typescript multiple times but places the complied files in different directories. It then places a package.json in both directories which declares if `.js` is commonjs or ESM. This way the resolver is happy because it can import `.js` files according to the package.json content and typescript is happy because it can find type declarations. And because package.json files are inheriting properties from other package.json files no necessary file is missing. Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
2023-07-30 08:02:14 -04:00
"version": "0.4.0",
"description": "Common code between frontend and backend",
"author": "The HedgeDoc Authors",
"license": "AGPL-3.0",
"scripts": {
fix(commons): replace microbundle with bash based compile script The commons package ships wrong types because it is refering to the same files for the ESM and the CJS build. See https://arethetypeswrong.github.io/?p=%40mrdrogdrog%2Foptional%401.1.0 This happens because microbundle can handle the generation of `.mjs` and `.cjs` from files itself but delegates the generation of types entirely to typescript by running it once. Microbundle uses the "type" field from the package.json to know if a `.js` file is meant to be mjs or cjs and generates the other type by using the specific file extension `.cjs` and `.mjs` (so if your package is a `type: module`, then `.js` file are interpreted as ECMAModule and if you have a commonjs file you need to name it `.cjs`). But this causes a problem with typescript. If you use typescript with the newer module resolver then it expects the type declarations to be named exactly like the file you wanna import. So if you have a `.js` file it will try to look up types in a `.d.ts` file. If it is resolving a `.mjs` file it is looking for a `.d.mts` file. This clashes with the types generated by microbundle because you can't use a `.mjs` file with a `.d.ts` file. Running typescript multiple times can also be complicated. When generating type declaration files, typescript takes a look at the source file extension. So a `.mts` file will generate a `.mjs` and a `.d.mts` file. A `.ts` will generate a `.js` and `.d.ts` file. It doesn't matter if you run microbundle on `.ts`, `.mts` or `.cjs` files, it will only generate the type declarations once. How do you get the other type declaration? To solve this problem you either have to run typescript multiple times and manipulate the input or output data to have correct `.d.mts` / `.d.cts` files AND imports... or do what this PR changes. It runs typescript multiple times but places the complied files in different directories. It then places a package.json in both directories which declares if `.js` is commonjs or ESM. This way the resolver is happy because it can import `.js` files according to the package.json content and typescript is happy because it can find type declarations. And because package.json files are inheriting properties from other package.json files no necessary file is missing. Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
2023-07-30 08:02:14 -04:00
"build": "./build.sh",
"test": "jest",
"test:ci": "jest --ci",
"prepublish": "rm -rf dist && yarn lint && yarn build && yarn test",
"lint": "eslint src --ext .ts",
"lint:fix": "eslint --fix --ext .ts src"
},
"type": "module",
"source": "src/index.ts",
fix(commons): replace microbundle with bash based compile script The commons package ships wrong types because it is refering to the same files for the ESM and the CJS build. See https://arethetypeswrong.github.io/?p=%40mrdrogdrog%2Foptional%401.1.0 This happens because microbundle can handle the generation of `.mjs` and `.cjs` from files itself but delegates the generation of types entirely to typescript by running it once. Microbundle uses the "type" field from the package.json to know if a `.js` file is meant to be mjs or cjs and generates the other type by using the specific file extension `.cjs` and `.mjs` (so if your package is a `type: module`, then `.js` file are interpreted as ECMAModule and if you have a commonjs file you need to name it `.cjs`). But this causes a problem with typescript. If you use typescript with the newer module resolver then it expects the type declarations to be named exactly like the file you wanna import. So if you have a `.js` file it will try to look up types in a `.d.ts` file. If it is resolving a `.mjs` file it is looking for a `.d.mts` file. This clashes with the types generated by microbundle because you can't use a `.mjs` file with a `.d.ts` file. Running typescript multiple times can also be complicated. When generating type declaration files, typescript takes a look at the source file extension. So a `.mts` file will generate a `.mjs` and a `.d.mts` file. A `.ts` will generate a `.js` and `.d.ts` file. It doesn't matter if you run microbundle on `.ts`, `.mts` or `.cjs` files, it will only generate the type declarations once. How do you get the other type declaration? To solve this problem you either have to run typescript multiple times and manipulate the input or output data to have correct `.d.mts` / `.d.cts` files AND imports... or do what this PR changes. It runs typescript multiple times but places the complied files in different directories. It then places a package.json in both directories which declares if `.js` is commonjs or ESM. This way the resolver is happy because it can import `.js` files according to the package.json content and typescript is happy because it can find type declarations. And because package.json files are inheriting properties from other package.json files no necessary file is missing. Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
2023-07-30 08:02:14 -04:00
"main": "dist/cjs/index.js",
"types": "dist/cjs/index.d.ts",
"module": "./dist/esm/index.js",
"exports": {
fix(commons): replace microbundle with bash based compile script The commons package ships wrong types because it is refering to the same files for the ESM and the CJS build. See https://arethetypeswrong.github.io/?p=%40mrdrogdrog%2Foptional%401.1.0 This happens because microbundle can handle the generation of `.mjs` and `.cjs` from files itself but delegates the generation of types entirely to typescript by running it once. Microbundle uses the "type" field from the package.json to know if a `.js` file is meant to be mjs or cjs and generates the other type by using the specific file extension `.cjs` and `.mjs` (so if your package is a `type: module`, then `.js` file are interpreted as ECMAModule and if you have a commonjs file you need to name it `.cjs`). But this causes a problem with typescript. If you use typescript with the newer module resolver then it expects the type declarations to be named exactly like the file you wanna import. So if you have a `.js` file it will try to look up types in a `.d.ts` file. If it is resolving a `.mjs` file it is looking for a `.d.mts` file. This clashes with the types generated by microbundle because you can't use a `.mjs` file with a `.d.ts` file. Running typescript multiple times can also be complicated. When generating type declaration files, typescript takes a look at the source file extension. So a `.mts` file will generate a `.mjs` and a `.d.mts` file. A `.ts` will generate a `.js` and `.d.ts` file. It doesn't matter if you run microbundle on `.ts`, `.mts` or `.cjs` files, it will only generate the type declarations once. How do you get the other type declaration? To solve this problem you either have to run typescript multiple times and manipulate the input or output data to have correct `.d.mts` / `.d.cts` files AND imports... or do what this PR changes. It runs typescript multiple times but places the complied files in different directories. It then places a package.json in both directories which declares if `.js` is commonjs or ESM. This way the resolver is happy because it can import `.js` files according to the package.json content and typescript is happy because it can find type declarations. And because package.json files are inheriting properties from other package.json files no necessary file is missing. Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
2023-07-30 08:02:14 -04:00
"import": {
"types": "./dist/esm/index.d.ts",
"default": "./dist/esm/index.js"
},
"require": {
"types": "./dist/cjs/index.d.ts",
"default": "./dist/cjs/index.js"
}
},
"files": [
"LICENSES/*",
"package.json",
"README.md",
"dist/**"
],
"browserslist": [
"node> 12"
],
"repository": {
"type": "git",
"url": "https://github.com/hedgedoc/hedgedoc.git"
},
"dependencies": {
"domhandler": "5.0.3",
"eventemitter2": "6.4.9",
"joi": "17.13.3",
"js-yaml": "4.1.0",
"reveal.js": "5.1.0",
"ws": "8.18.0",
"yjs": "13.6.20"
},
"devDependencies": {
"@jest/types": "29.6.3",
"@mrdrogdrog/optional": "1.2.1",
"@types/js-yaml": "4.0.9",
"@types/ws": "8.5.12",
"@typescript-eslint/eslint-plugin": "8.14.0",
"@typescript-eslint/parser": "8.14.0",
"eslint": "8.57.0",
"eslint-config-prettier": "9.1.0",
"eslint-plugin-jest": "28.8.3",
"eslint-plugin-prettier": "5.2.1",
"jest": "29.7.0",
"prettier": "3.3.3",
"ts-jest": "29.2.5",
"typescript": "5.6.3"
},
"packageManager": "yarn@4.5.1"
}