From c2bb4e750a824662a794e01158101b028793a5cb Mon Sep 17 00:00:00 2001 From: Arkadiusz Bachorski <60391032+arkadiuszbachorski@users.noreply.github.com> Date: Tue, 4 Jun 2024 08:06:38 +0200 Subject: [PATCH] Fix modules resolution (#23) # Fix modules resolution ## :recycle: Current situation & Problem Currently modules aren't properly resolved. There is a mix between two approaches. We have build process and package.json link of local file, but result of this operation isn't used. Actually, TS alias is used, which in the end works exactly like if we just imported relatively from `packages` directory. ## :gear: Release Notes * Fix modules resolution ## :books: Documentation This PR changes from TS alias to import of the actual package. Now, this resembles using 3rd party package, but it's stored in monorepo. It makes it bulletproof to move a package to separate repo without a lot of modifications. ### Code of Conduct & Contributing Guidelines By submitting creating this pull request, you agree to follow our [Code of Conduct](https://github.com/StanfordBDHG/.github/blob/main/CODE_OF_CONDUCT.md) and [Contributing Guidelines](https://github.com/StanfordBDHG/.github/blob/main/CONTRIBUTING.md): - [x] I agree to follow the [Code of Conduct](https://github.com/StanfordBDHG/.github/blob/main/CODE_OF_CONDUCT.md) and [Contributing Guidelines](https://github.com/StanfordBDHG/.github/blob/main/CONTRIBUTING.md). --- package-lock.json | 17 +++++++++++------ package.json | 5 ++--- packages/example-package/.gitignore | 3 ++- packages/example-package/package.json | 6 ++++-- packages/example-package/tsconfig.json | 15 +++++++++++---- tsconfig.json | 3 --- 6 files changed, 30 insertions(+), 19 deletions(-) diff --git a/package-lock.json b/package-lock.json index ab426f9..f3f66a7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "0.1.0", "license": "MIT", "dependencies": { - "@stanfordbdhg/example-package": "file:../packages/example-package", + "@stanfordbdhg/example-package": "file:./packages/example-package", "next": "^14", "prettier-plugin-tailwindcss": "^0.5.14", "react": "^18", @@ -23,14 +23,14 @@ "@types/node": "^20", "@types/react": "^18", "@types/react-dom": "^18", - "@typescript-eslint/eslint-plugin": "^7.11.0", - "@typescript-eslint/parser": "^7.11.0", + "@typescript-eslint/eslint-plugin": "^7", + "@typescript-eslint/parser": "^7", "autoprefixer": "^10", "concurrently": "^8", "eslint": "^8", "eslint-config-next": "^14", "eslint-config-prettier": "^9", - "eslint-plugin-import": "^2.29.1", + "eslint-plugin-import": "^2", "eslint-plugin-prettier": "^5", "jest": "^29", "jest-environment-jsdom": "^29", @@ -42,7 +42,9 @@ "typescript": "^5" } }, - "../packages/example-package": {}, + "../packages/example-package": { + "extraneous": true + }, "node_modules/@adobe/css-tools": { "version": "4.3.3", "resolved": "https://registry.npmjs.org/@adobe/css-tools/-/css-tools-4.3.3.tgz", @@ -2179,7 +2181,7 @@ } }, "node_modules/@stanfordbdhg/example-package": { - "resolved": "../packages/example-package", + "resolved": "packages/example-package", "link": true }, "node_modules/@swc/counter": { @@ -11236,6 +11238,9 @@ "funding": { "url": "https://github.com/sponsors/sindresorhus" } + }, + "packages/example-package": { + "version": "0.1.0" } } } diff --git a/package.json b/package.json index 73feac3..0e11109 100644 --- a/package.json +++ b/package.json @@ -15,19 +15,18 @@ "scripts": { "dev": "concurrently \"next dev\" \"npm --prefix packages/example-package run watch\"", "prebuild": "npm --prefix packages/example-package run build", - "buildTypes": "npm --prefix packages/example-package run buildTypes", "build": "next build", "start": "next start", "lint": "eslint .", "lint:fix": "eslint . --fix & prettier --write .", - "lint:ci": "npm run buildTypes && eslint --output-file eslint_report.json --format json .", + "lint:ci": "npm run prebuild && eslint --output-file eslint_report.json --format json .", "pretest": "npm --prefix packages/example-package run build", "test": "jest", "docs": "typedoc", "docs:ci": "typedoc --out ./out/docs --githubPages true" }, "dependencies": { - "@stanfordbdhg/example-package": "file:../packages/example-package", + "@stanfordbdhg/example-package": "file:./packages/example-package", "next": "^14", "prettier-plugin-tailwindcss": "^0.5.14", "react": "^18", diff --git a/packages/example-package/.gitignore b/packages/example-package/.gitignore index b23dada..2f7ba05 100644 --- a/packages/example-package/.gitignore +++ b/packages/example-package/.gitignore @@ -6,4 +6,5 @@ # SPDX-License-Identifier: MIT # -dist \ No newline at end of file +dist +node_modules diff --git a/packages/example-package/package.json b/packages/example-package/package.json index 39b2f0c..b65a5a4 100644 --- a/packages/example-package/package.json +++ b/packages/example-package/package.json @@ -2,10 +2,12 @@ "name": "@stanfordbdhg/example-package", "version": "0.1.0", "private": true, - "main": "dist/index.js", "scripts": { "build": "tsc", - "buildTypes": "tsc --emitDeclarationOnly", "watch": "tsc -w" + }, + "types": "dist/index.d.ts", + "exports": { + ".": "./dist/index.js" } } diff --git a/packages/example-package/tsconfig.json b/packages/example-package/tsconfig.json index 7f1ed38..1d19b72 100644 --- a/packages/example-package/tsconfig.json +++ b/packages/example-package/tsconfig.json @@ -1,12 +1,19 @@ { + "include": ["src"], "compilerOptions": { - "composite": true, + "declaration": true, + "declarationMap": true, + "module": "commonjs", + "target": "es6", + "lib": ["esnext"], + "jsx": "preserve", "rootDir": "src", "outDir": "dist", - "declaration": true, - "declarationMap": true + "esModuleInterop": true, + "forceConsistentCasingInFileNames": true, + "strict": true, + "skipLibCheck": true }, - "include": ["src"], "typedocOptions": { "includeVersion": true, "entryPoints": ["src/index.ts"] diff --git a/tsconfig.json b/tsconfig.json index 120a09c..7f4d743 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -19,9 +19,6 @@ "name": "next" } ], - "paths": { - "@stanfordbdhg/example-package": ["./packages/example-package/dist"] - } }, "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"], "exclude": ["node_modules"],