diff --git a/package.json b/package.json index 63d954c77e02..4282de5d4ccc 100644 --- a/package.json +++ b/package.json @@ -76,6 +76,7 @@ "stealthy-require": "^1.1.1", "string-length": "^4.0.1", "strip-ansi": "^6.0.0", + "strip-json-comments": "^3.1.1", "tempy": "^1.0.0", "throat": "^5.0.0", "ts-node": "^9.0.0", diff --git a/packages/jest-circus/tsconfig.json b/packages/jest-circus/tsconfig.json index cc427109b912..630f21878c72 100644 --- a/packages/jest-circus/tsconfig.json +++ b/packages/jest-circus/tsconfig.json @@ -5,6 +5,7 @@ "rootDir": "src" }, "references": [ + {"path": "../expect"}, {"path": "../jest-each"}, {"path": "../jest-environment"}, {"path": "../jest-matcher-utils"}, diff --git a/packages/jest-cli/tsconfig.json b/packages/jest-cli/tsconfig.json index 214e78d81180..2a48dd03ef8f 100644 --- a/packages/jest-cli/tsconfig.json +++ b/packages/jest-cli/tsconfig.json @@ -5,11 +5,12 @@ "outDir": "build" }, "references": [ - {"path": "../jest-core"}, {"path": "../jest-config"}, + {"path": "../jest-core"}, {"path": "../jest-test-result"}, {"path": "../jest-types"}, {"path": "../jest-util"}, - {"path": "../jest-validate"} + {"path": "../jest-validate"}, + {"path": "../test-utils"} ] } diff --git a/packages/jest-config/tsconfig.json b/packages/jest-config/tsconfig.json index b33c1679180a..7c9dc85e0510 100644 --- a/packages/jest-config/tsconfig.json +++ b/packages/jest-config/tsconfig.json @@ -4,8 +4,9 @@ "rootDir": "src", "outDir": "build" }, - // TODO: This is missing `jest-jasmine2`, but that is just - // `require.resolve`d, so no real use for its types + // TODO: This is missing `babel-jest`, `jest-jasmine2`, `jest-circus` and + // jest-test-sequencer, but that is just `require.resolve`d, so no real use + // for their types "references": [ {"path": "../jest-environment-jsdom"}, {"path": "../jest-environment-node"}, diff --git a/packages/jest-core/tsconfig.json b/packages/jest-core/tsconfig.json index 2dc89063bc95..6010315e6eeb 100644 --- a/packages/jest-core/tsconfig.json +++ b/packages/jest-core/tsconfig.json @@ -12,14 +12,15 @@ {"path": "../jest-message-util"}, {"path": "../jest-regex-util"}, {"path": "../jest-reporters"}, + {"path": "../jest-resolve"}, {"path": "../jest-resolve-dependencies"}, {"path": "../jest-runner"}, {"path": "../jest-runtime"}, {"path": "../jest-snapshot"}, {"path": "../jest-test-result"}, {"path": "../jest-test-sequencer"}, - {"path": "../jest-types"}, {"path": "../jest-transform"}, + {"path": "../jest-types"}, {"path": "../jest-util"}, {"path": "../jest-validate"}, {"path": "../jest-watcher"}, diff --git a/packages/jest-environment/tsconfig.json b/packages/jest-environment/tsconfig.json index efa01e2b2db4..7e0bf445fb1a 100644 --- a/packages/jest-environment/tsconfig.json +++ b/packages/jest-environment/tsconfig.json @@ -8,7 +8,7 @@ }, "references": [ {"path": "../jest-fake-timers"}, - {"path": "../jest-types"}, - {"path": "../jest-util"} + {"path": "../jest-mock"}, + {"path": "../jest-types"} ] } diff --git a/packages/jest-fake-timers/tsconfig.json b/packages/jest-fake-timers/tsconfig.json index 7105524da628..9db8e6cc0ed9 100644 --- a/packages/jest-fake-timers/tsconfig.json +++ b/packages/jest-fake-timers/tsconfig.json @@ -7,6 +7,7 @@ "references": [ {"path": "../jest-message-util"}, {"path": "../jest-mock"}, + {"path": "../jest-types"}, {"path": "../jest-util"} ] } diff --git a/packages/jest-haste-map/tsconfig.json b/packages/jest-haste-map/tsconfig.json index 9bec851aaddb..1174b5fae123 100644 --- a/packages/jest-haste-map/tsconfig.json +++ b/packages/jest-haste-map/tsconfig.json @@ -9,6 +9,7 @@ {"path": "../jest-serializer"}, {"path": "../jest-types"}, {"path": "../jest-util"}, - {"path": "../jest-worker"} + {"path": "../jest-worker"}, + {"path": "../test-utils"} ] } diff --git a/packages/jest-leak-detector/tsconfig.json b/packages/jest-leak-detector/tsconfig.json index 3e70b10372b1..02131be76e97 100644 --- a/packages/jest-leak-detector/tsconfig.json +++ b/packages/jest-leak-detector/tsconfig.json @@ -5,6 +5,7 @@ "outDir": "build" }, "references": [ + {"path": "../jest-get-type"}, {"path": "../pretty-format"} ] } diff --git a/packages/jest-reporters/tsconfig.json b/packages/jest-reporters/tsconfig.json index de566bfd2c4f..90e8ebceb1d5 100644 --- a/packages/jest-reporters/tsconfig.json +++ b/packages/jest-reporters/tsconfig.json @@ -9,6 +9,7 @@ {"path": "../jest-haste-map"}, {"path": "../jest-resolve"}, {"path": "../jest-test-result"}, + {"path": "../jest-transform"}, {"path": "../jest-types"}, {"path": "../jest-util"}, {"path": "../jest-worker"}, diff --git a/packages/jest-resolve-dependencies/tsconfig.json b/packages/jest-resolve-dependencies/tsconfig.json index 5d09fe96e244..433e2ed3f351 100644 --- a/packages/jest-resolve-dependencies/tsconfig.json +++ b/packages/jest-resolve-dependencies/tsconfig.json @@ -5,7 +5,10 @@ "outDir": "build" }, "references": [ + {"path": "../jest-haste-map"}, {"path": "../jest-regex-util"}, + {"path": "../jest-resolve"}, + {"path": "../jest-runtime"}, {"path": "../jest-snapshot"}, {"path": "../jest-types"}, {"path": "../test-utils"} diff --git a/packages/jest-resolve/tsconfig.json b/packages/jest-resolve/tsconfig.json index befa0d307f51..c134ea4e4c28 100644 --- a/packages/jest-resolve/tsconfig.json +++ b/packages/jest-resolve/tsconfig.json @@ -4,5 +4,9 @@ "rootDir": "src", "outDir": "build" }, - "references": [{"path": "../jest-types"}, {"path": "../jest-haste-map"}] + "references": [ + {"path": "../jest-haste-map"}, + {"path": "../jest-types"}, + {"path": "../jest-util"} + ] } diff --git a/packages/jest-runner/tsconfig.json b/packages/jest-runner/tsconfig.json index d89ad8ced039..7cb8d3a00c88 100644 --- a/packages/jest-runner/tsconfig.json +++ b/packages/jest-runner/tsconfig.json @@ -17,7 +17,7 @@ {"path": "../jest-test-result"}, {"path": "../jest-transform"}, {"path": "../jest-types"}, - {"path": "../jest-worker"}, - {"path": "../jest-util"} + {"path": "../jest-util"}, + {"path": "../jest-worker"} ] } diff --git a/packages/jest-runtime/tsconfig.json b/packages/jest-runtime/tsconfig.json index f02568529755..74421a130e70 100644 --- a/packages/jest-runtime/tsconfig.json +++ b/packages/jest-runtime/tsconfig.json @@ -22,7 +22,6 @@ {"path": "../jest-types"}, {"path": "../jest-util"}, {"path": "../jest-validate"}, - {"path": "../pretty-format"}, {"path": "../test-utils"} ] } diff --git a/packages/jest-test-sequencer/tsconfig.json b/packages/jest-test-sequencer/tsconfig.json index 78fc3a6be9ed..fd37f0a8849a 100644 --- a/packages/jest-test-sequencer/tsconfig.json +++ b/packages/jest-test-sequencer/tsconfig.json @@ -7,7 +7,7 @@ "references": [ {"path": "../jest-haste-map"}, {"path": "../jest-runner"}, - {"path": "../jest-test-result"}, - {"path": "../jest-types"} + {"path": "../jest-runtime"}, + {"path": "../jest-test-result"} ] } diff --git a/packages/pretty-format/tsconfig.json b/packages/pretty-format/tsconfig.json index 3046cb6b9b6a..23c08b0da24e 100644 --- a/packages/pretty-format/tsconfig.json +++ b/packages/pretty-format/tsconfig.json @@ -4,5 +4,5 @@ "rootDir": "src", "outDir": "build" }, - "references": [{"path": "../jest-types"}] + "references": [{"path": "../jest-types"}, {"path": "../jest-util"}] } diff --git a/scripts/buildTs.js b/scripts/buildTs.js index 5630d61f9315..adb7cfc9fa00 100644 --- a/scripts/buildTs.js +++ b/scripts/buildTs.js @@ -15,6 +15,7 @@ const util = require('util'); const chalk = require('chalk'); const execa = require('execa'); const globby = require('globby'); +const stripJsonComments = require('strip-json-comments'); const throat = require('throat'); const {getPackages} = require('./buildUtils'); @@ -27,8 +28,22 @@ const readFilePromise = util.promisify(fs.readFile); fs.existsSync(path.resolve(p, 'tsconfig.json')), ); + const {stdout: allWorkspacesString} = await execa('yarn', [ + 'workspaces', + 'list', + '--json', + ]); + + const workspacesWithTs = new Map( + JSON.parse(`[${allWorkspacesString.split('\n').join(',')}]`) + .filter(({location}) => + packagesWithTs.some(pkg => pkg.endsWith(location)), + ) + .map(({location, name}) => [name, location]), + ); + packagesWithTs.forEach(pkgDir => { - const pkg = require(pkgDir + '/package.json'); + const pkg = require(`${pkgDir}/package.json`); assert.ok(pkg.types, `Package ${pkg.name} is missing \`types\` field`); @@ -37,6 +52,47 @@ const readFilePromise = util.promisify(fs.readFile); pkg.main.replace(/\.js$/, '.d.ts'), `\`main\` and \`types\` field of ${pkg.name} does not match`, ); + + const jestDependenciesOfPackage = Object.keys(pkg.dependencies || {}) + .concat(Object.keys(pkg.devDependencies || {})) + .filter(dep => workspacesWithTs.has(dep)) + .filter(dep => { + // nothing should depend on these + if (dep === 'jest-circus' || dep === 'jest-jasmine2') { + return false; + } + + // these are just `require.resolve`-ed + if (pkg.name === 'jest-config') { + if (dep === '@jest/test-sequencer' || dep === 'babel-jest') { + return false; + } + } + + return true; + }) + .map(dep => + path.relative(pkgDir, `${pkgDir}/../../${workspacesWithTs.get(dep)}`), + ) + .sort(); + + if (jestDependenciesOfPackage.length > 0) { + const tsConfig = JSON.parse( + stripJsonComments(fs.readFileSync(`${pkgDir}/tsconfig.json`, 'utf8')), + ); + + const references = tsConfig.references.map(({path}) => path); + + assert.deepStrictEqual( + references, + jestDependenciesOfPackage, + `Expected declared references to match dependencies in packages ${ + pkg.name + }. Got:\n\n${references.join( + '\n', + )}\nExpected:\n\n${jestDependenciesOfPackage.join('\n')}`, + ); + } }); const args = ['tsc', '-b', ...packagesWithTs, ...process.argv.slice(2)]; diff --git a/yarn.lock b/yarn.lock index 9289b851c558..ff658db33ebe 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1956,6 +1956,7 @@ __metadata: stealthy-require: ^1.1.1 string-length: ^4.0.1 strip-ansi: ^6.0.0 + strip-json-comments: ^3.1.1 tempy: ^1.0.0 throat: ^5.0.0 ts-node: ^9.0.0