Mirror: The highly customizable and versatile GraphQL client with which you add on features like normalized caching as you grow.
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Fix tsc and Jest setup for paths mapping (#539)

* Update package naming conventions

* Readd individual tsconfig.json configs to packages

* Fix moduleNameMapper for new paths convention

* Fix scripts/rollup/build to glob instead tsc paths

authored by

Phil Plückthun and committed by
GitHub
6cb62907 077fb43e

+91 -28
+15 -6
CONTRIBUTING.md
··· 111 111 112 112 ## How do I add a new package? 113 113 114 + First of all we need to know where to put the package. 115 + 116 + - Exchanges should be added to `exchanges/` and the folder should be the plain 117 + name of the exchange. Since the `package.json:name` is following the convention 118 + of `@urql/exchange-*` the folder should just be without this conventional prefix. 119 + - All other packages should be added to `packages/`. Typically all packages should 120 + be named `@urql/*` and their folders should be named exactly this without the 121 + prefix or `*-urql`. Optionally if the package will be named `*-urql` then the folder 122 + can take on the same name. 123 + 114 124 When adding a new package, start by copying a `package.json` file from another project. 115 125 You may want to alter the following fields first: 116 126 ··· 130 140 131 141 If your entrypoint won't be at `src/index.ts` you may alter it. But the `types` field has to match 132 142 the same file relative to the `dist/types` folder, where `rollup` will output the TypeScript 133 - declaration files. When setting up your package make sure to create a `src/index.ts` file (or a file 134 - at what you've set `source` to) 143 + declaration files. 144 + 145 + When setting up your package make sure to create a `src/index.ts` file 146 + (or any other file which you've pointed `package.json:source` to). Also don't forget to 147 + copy over the `tsconfig.json` from another package (You won't need to change it). 135 148 136 149 The `scripts.prepare` task is set up to check your new `package.json` file for correctness. So in 137 150 case you get anything wrong, you'll get a short error when running `yarn` after setting your new 138 151 project up. Just in case! 😄 139 - 140 - Lastly, your new package will need to be added to the `tsconfig.json` in the root of the repository. 141 - Add a new entry to `compilerOptions.paths` where the key is the `name` you've used in your 142 - `package.json` and the value is an array with a single entry, the path to your package + `src/`. 143 152 144 153 Afterwards you can check whether everything is working correctly by running: 145 154
+12
exchanges/graphcache/tsconfig.json
··· 1 + { 2 + "extends": "../../tsconfig.json", 3 + "include": ["src"], 4 + "compilerOptions": { 5 + "baseUrl": "./", 6 + "paths": { 7 + "urql": ["../../node_modules/urql/src"], 8 + "*-urql": ["../../node_modules/*-urql/src"], 9 + "@urql/*": ["../../node_modules/@urql/*/src"] 10 + } 11 + } 12 + }
+1
package.json
··· 64 64 "eslint-plugin-react": "^7.18.0", 65 65 "eslint-plugin-react-hooks": "^2.3.0", 66 66 "execa": "^4.0.0", 67 + "glob": "^7.1.6", 67 68 "graphql": "^14.6.0", 68 69 "graphql-tag": "^2.10.1", 69 70 "husky": "^4.2.1",
+12
packages/core/tsconfig.json
··· 1 + { 2 + "extends": "../../tsconfig.json", 3 + "include": ["src"], 4 + "compilerOptions": { 5 + "baseUrl": "./", 6 + "paths": { 7 + "urql": ["../../node_modules/urql/src"], 8 + "*-urql": ["../../node_modules/*-urql/src"], 9 + "@urql/*": ["../../node_modules/@urql/*/src"] 10 + } 11 + } 12 + }
+12
packages/preact-urql/tsconfig.json
··· 1 + { 2 + "extends": "../../tsconfig.json", 3 + "include": ["src"], 4 + "compilerOptions": { 5 + "baseUrl": "./", 6 + "paths": { 7 + "urql": ["../../node_modules/urql/src"], 8 + "*-urql": ["../../node_modules/*-urql/src"], 9 + "@urql/*": ["../../node_modules/@urql/*/src"] 10 + } 11 + } 12 + }
+12
packages/react-urql/tsconfig.json
··· 1 + { 2 + "extends": "../../tsconfig.json", 3 + "include": ["src"], 4 + "compilerOptions": { 5 + "baseUrl": "./", 6 + "paths": { 7 + "urql": ["../../node_modules/urql/src"], 8 + "*-urql": ["../../node_modules/*-urql/src"], 9 + "@urql/*": ["../../node_modules/@urql/*/src"] 10 + } 11 + } 12 + }
+12
packages/svelte-urql/tsconfig.json
··· 1 + { 2 + "extends": "../../tsconfig.json", 3 + "include": ["src"], 4 + "compilerOptions": { 5 + "baseUrl": "./", 6 + "paths": { 7 + "urql": ["../../node_modules/urql/src"], 8 + "*-urql": ["../../node_modules/*-urql/src"], 9 + "@urql/*": ["../../node_modules/@urql/*/src"] 10 + } 11 + } 12 + }
+5 -7
scripts/jest/preset.js
··· 1 - const { pathsToModuleNameMapper } = require('ts-jest/utils'); 2 - const { compilerOptions } = require('../../tsconfig.json'); 3 - 4 1 module.exports = { 5 2 preset: 'ts-jest', 6 3 setupFiles: [ ··· 9 6 transform: { 10 7 '^.+\\.tsx?$': 'ts-jest', 11 8 }, 12 - moduleNameMapper: pathsToModuleNameMapper( 13 - compilerOptions.paths, 14 - { prefix: '<rootDir>/../../' } 15 - ), 9 + moduleNameMapper: { 10 + "^urql$": "<rootDir>/../../node_modules/urql/src", 11 + "^(.*-urql)$": "<rootDir>/../../node_modules/$1/src", 12 + "^@urql/(.*)$": "<rootDir>/../../node_modules/@urql/$1/src", 13 + }, 16 14 watchPlugins: ['jest-watch-yarn-workspaces'], 17 15 testRegex: '(src/.*(\\.|/)(test|spec))\\.tsx?$', 18 16 moduleFileExtensions: ['js', 'jsx', 'ts', 'tsx', 'json'],
+3 -3
scripts/rollup/build.js
··· 1 1 #!/usr/bin/env node 2 2 3 3 const path = require('path'); 4 + const glob = require('glob').sync; 4 5 const execa = require('execa'); 5 6 6 - const { compilerOptions: { paths } } = require('../../tsconfig.json'); 7 7 const workspaceRoot = path.resolve(__dirname, '../../'); 8 8 const rollupConfig = path.resolve(__dirname, './config.js'); 9 9 10 - let packages = Object.keys(paths).map(package => { 11 - return path.resolve(workspaceRoot, paths[package][0], '../'); 10 + let packages = glob('{packages,exchanges}/*/package.json').map(pkg => { 11 + return path.resolve(pkg, '../'); 12 12 }); 13 13 14 14 // CircleCI parallelism
+1 -3
scripts/rollup/plugins.js
··· 36 36 : typescript({ 37 37 useTsconfigDeclarationDir: true, 38 38 objectHashIgnoreUnknownHack: true, 39 - tsconfigDefaults: require('../../tsconfig.json'), 40 39 tsconfigOverride: { 41 40 exclude: [ 42 41 'src/**/*.test.ts', ··· 45 44 ], 46 45 compilerOptions: { 47 46 sourceMap: true, 48 - baseUrl: '.', 49 47 declaration: !isProduction, 50 - declarationDir: './dist/types', 48 + declarationDir: settings.types, 51 49 target: 'es6', 52 50 }, 53 51 },
+2 -1
scripts/rollup/settings.js
··· 1 1 const path = require('path'); 2 - const cwd = process.cwd(); 3 2 3 + export const cwd = process.cwd(); 4 4 export const pkg = require(path.resolve(cwd, './package.json')); 5 + export const types = path.resolve(cwd, 'dist/types/'); 5 6 6 7 const normalize = name => name 7 8 .replace(/[@\s\/\.]+/g, ' ')
+4 -8
tsconfig.json
··· 2 2 "compilerOptions": { 3 3 "baseUrl": "./", 4 4 "paths": { 5 - "@urql/core": ["packages/core/src"], 6 - "@urql/exchange-graphcache": ["exchanges/graphcache/src"], 7 5 "urql": ["packages/react-urql/src"], 8 - "preact-urql": ["packages/preact-urql/src"], 9 - "svelte-urql": ["packages/svelte-urql/src"] 6 + "*-urql": ["packages/*-urql/src"], 7 + "@urql/exchange-*": ["exchanges/*/src"], 8 + "@urql/*": ["packages/*-urql/src", "packages/*/src"] 10 9 }, 11 10 "esModuleInterop": true, 12 11 "forceConsistentCasingInFileNames": true, ··· 21 20 "noImplicitAny": false, 22 21 "noUnusedParameters": true 23 22 }, 24 - "include": [ 25 - "packages", 26 - "exchanges" 27 - ], 23 + "include": ["packages", "exchanges"], 28 24 "exclude": [ 29 25 "scripts", 30 26 "packages/*/examples",