diff --git a/.eslintrc.js b/.eslintrc.js index 3608aed77d00..c3e7307c6eaf 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -5,15 +5,10 @@ * LICENSE file in the root directory of this source tree. */ -const {sync: readPkg} = require('read-pkg'); const {getPackages} = require('./scripts/buildUtils'); const internalPackages = getPackages() - .map(packageDir => { - const pkg = readPkg({cwd: packageDir}); - - return pkg.name; - }) + .map(({pkg}) => pkg.name) .sort(); module.exports = { diff --git a/scripts/build.js b/scripts/build.js index ac0f2255e0a3..576474296a13 100644 --- a/scripts/build.js +++ b/scripts/build.js @@ -142,5 +142,5 @@ if (files.length) { } else { const packages = getPackages(); process.stdout.write(chalk.inverse(' Building packages \n')); - packages.forEach(buildNodePackage); + packages.map(({packageDir}) => packageDir).forEach(buildNodePackage); } diff --git a/scripts/buildTs.js b/scripts/buildTs.js index adb7cfc9fa00..035623289b76 100644 --- a/scripts/buildTs.js +++ b/scripts/buildTs.js @@ -25,7 +25,7 @@ const readFilePromise = util.promisify(fs.readFile); const packages = getPackages(); const packagesWithTs = packages.filter(p => - fs.existsSync(path.resolve(p, 'tsconfig.json')), + fs.existsSync(path.resolve(p.packageDir, 'tsconfig.json')), ); const {stdout: allWorkspacesString} = await execa('yarn', [ @@ -37,14 +37,12 @@ const readFilePromise = util.promisify(fs.readFile); const workspacesWithTs = new Map( JSON.parse(`[${allWorkspacesString.split('\n').join(',')}]`) .filter(({location}) => - packagesWithTs.some(pkg => pkg.endsWith(location)), + packagesWithTs.some(({packageDir}) => packageDir.endsWith(location)), ) .map(({location, name}) => [name, location]), ); - packagesWithTs.forEach(pkgDir => { - const pkg = require(`${pkgDir}/package.json`); - + packagesWithTs.forEach(({packageDir, pkg}) => { assert.ok(pkg.types, `Package ${pkg.name} is missing \`types\` field`); assert.strictEqual( @@ -72,13 +70,18 @@ const readFilePromise = util.promisify(fs.readFile); return true; }) .map(dep => - path.relative(pkgDir, `${pkgDir}/../../${workspacesWithTs.get(dep)}`), + path.relative( + packageDir, + `${packageDir}/../../${workspacesWithTs.get(dep)}`, + ), ) .sort(); if (jestDependenciesOfPackage.length > 0) { const tsConfig = JSON.parse( - stripJsonComments(fs.readFileSync(`${pkgDir}/tsconfig.json`, 'utf8')), + stripJsonComments( + fs.readFileSync(`${packageDir}/tsconfig.json`, 'utf8'), + ), ); const references = tsConfig.references.map(({path}) => path); @@ -95,7 +98,12 @@ const readFilePromise = util.promisify(fs.readFile); } }); - const args = ['tsc', '-b', ...packagesWithTs, ...process.argv.slice(2)]; + const args = [ + 'tsc', + '-b', + ...packagesWithTs.map(({packageDir}) => packageDir), + ...process.argv.slice(2), + ]; console.log(chalk.inverse(' Building TypeScript definition files ')); @@ -119,11 +127,10 @@ const readFilePromise = util.promisify(fs.readFile); try { await Promise.all( packagesWithTs.map( - throat(cpus, async pkgDir => { - const buildDir = path.resolve(pkgDir, 'build/**/*.d.ts'); - const ts3dot4 = path.resolve(pkgDir, 'build/ts3.4'); + throat(cpus, async ({packageDir, pkg}) => { + const buildDir = path.resolve(packageDir, 'build/**/*.d.ts'); - const globbed = await globby([buildDir, `!${ts3dot4}`]); + const globbed = await globby([buildDir]); const files = await Promise.all( globbed.map(file => @@ -164,8 +171,6 @@ const readFilePromise = util.promisify(fs.readFile); ); if (filesWithNodeReference.length > 0) { - const pkg = require(pkgDir + '/package.json'); - assert.ok( pkg.dependencies, `Package \`${pkg.name}\` is missing \`dependencies\``, diff --git a/scripts/buildUtils.js b/scripts/buildUtils.js index 5f69966efaf1..6a8b79298f61 100644 --- a/scripts/buildUtils.js +++ b/scripts/buildUtils.js @@ -28,7 +28,7 @@ module.exports.getPackages = function getPackages() { const nodeEngineRequirement = rootPackage.engines.node; - packages.forEach(packageDir => { + return packages.map(packageDir => { const pkg = readPkg({cwd: packageDir}); assert.ok(pkg.engines, `Engine requirement in ${pkg.name} should exist`); @@ -83,9 +83,9 @@ module.exports.getPackages = function getPackages() { } }); } - }); - return packages; + return {packageDir, pkg}; + }); }; module.exports.adjustToTerminalWidth = function adjustToTerminalWidth(str) { diff --git a/scripts/watch.js b/scripts/watch.js index 9c340b084c84..8c93185108fd 100644 --- a/scripts/watch.js +++ b/scripts/watch.js @@ -30,7 +30,7 @@ const rebuild = filename => filesToBuild.set(filename, true); chokidar .watch( - getPackages().map(p => path.resolve(p, 'src')), + getPackages().map(p => path.resolve(p.packageDir, 'src')), { ignoreInitial: true, ignored: /(^|[\/\\])\../, // ignore dotfiles