From 555c11093a8e2137f5a9407c88694b5c07d7e6ef Mon Sep 17 00:00:00 2001 From: Hans Larsen Date: Wed, 2 Aug 2017 13:33:12 -0700 Subject: [PATCH] build: use the tar files for dependencies for e2e This adds a new flag to the build script that sets the tar files path as dependencies inside the package.json before tarring the files. --- lib/packages.js | 1 + tests/e2e/setup/010-build.ts | 2 +- tools/publish/src/build.ts | 34 +++++++++++++++++++++++++++++++++- 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/lib/packages.js b/lib/packages.js index 9489df0ca972..7338301873ae 100644 --- a/lib/packages.js +++ b/lib/packages.js @@ -25,6 +25,7 @@ const packages = packages[name] = { dist: path.join(distRoot, pkg.name), packageJson: path.join(pkg.root, 'package.json'), + distPackageJson: path.join(distRoot, pkg.name, 'package.json'), root: pkg.root, relative: path.relative(path.dirname(__dirname), pkg.root), main: path.resolve(pkg.root, 'src/index.ts'), diff --git a/tests/e2e/setup/010-build.ts b/tests/e2e/setup/010-build.ts index fe1e5f7ab3be..f90ed034cd0b 100644 --- a/tests/e2e/setup/010-build.ts +++ b/tests/e2e/setup/010-build.ts @@ -12,7 +12,7 @@ export default function() { return; } - return npm('run', 'build') + return npm('run', 'build', '--', '--local') .then(() => console.log('Updating package.json from dist...')) .then(() => Promise.all(Object.keys(packages).map(pkgName => { return updateJsonFile(join(packages[pkgName].dist, 'package.json'), json => { diff --git a/tools/publish/src/build.ts b/tools/publish/src/build.ts index aca319424539..b06956889e59 100644 --- a/tools/publish/src/build.ts +++ b/tools/publish/src/build.ts @@ -57,7 +57,7 @@ function getDeps(pkg: any): any { } -export default function build(packagesToBuild: string[], _opts: any, +export default function build(packagesToBuild: string[], opts: { local: boolean }, logger: Logger): Promise { const { packages, tools } = require('../../../lib/packages'); @@ -227,6 +227,38 @@ export default function build(packagesToBuild: string[], _opts: any, return copy('LICENSE', path.join(pkg.dist, 'LICENSE')); })); }) + .then(() => { + if (!opts.local) { + return; + } + + logger.info('Changing dependencies between packages to tar files...'); + logger.warn('================================================='); + logger.warn('= THIS SHOULD NOT BE USED FOR PUBLISHING TO NPM ='); + logger.warn('================================================='); + + Object.keys(packages).forEach(pkgName => { + const pkg = packages[pkgName]; + const json = JSON.parse(fs.readFileSync(pkg.packageJson).toString()); + + if (!json['dependencies']) { + json['dependencies'] = {}; + } + if (!json['devDependencies']) { + json['devDependencies'] = {}; + } + + for (const packageName of Object.keys(packages)) { + if (json['dependencies'].hasOwnProperty(packageName)) { + json['dependencies'][packageName] = packages[packageName].tar; + } else if (json['devDependencies'].hasOwnProperty(packageName)) { + json['devDependencies'][packageName] = packages[packageName].tar; + } + } + + fs.writeFileSync(pkg.distPackageJson, JSON.stringify(json, null, 2)); + }); + }) .then(() => { logger.info('Tarring all packages...');