Skip to content

Commit

Permalink
build: use the tar files for dependencies for e2e
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
hansl committed Aug 3, 2017
1 parent 3aecfa7 commit 555c110
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/packages.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/setup/010-build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
34 changes: 33 additions & 1 deletion tools/publish/src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
const { packages, tools } = require('../../../lib/packages');

Expand Down Expand Up @@ -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...');

Expand Down

0 comments on commit 555c110

Please sign in to comment.