diff --git a/packages/build/src/npm-packages.spec.ts b/packages/build/src/npm-packages.spec.ts index 4cdcd3e14..b41ed44a8 100644 --- a/packages/build/src/npm-packages.spec.ts +++ b/packages/build/src/npm-packages.spec.ts @@ -6,7 +6,8 @@ import { listNpmPackages, markBumpedFilesAsAssumeUnchanged, publishNpmPackages, - spawnSync + spawnSync, + LernaPackageDescription } from './npm-packages'; @@ -58,6 +59,11 @@ describe('npm-packages', () => { ['version', '0.7.0', '--no-changelog', '--no-push', '--exact', '--no-git-tag-version', '--force-publish', '--yes'], sinon.match.any ); + expect(spawnSync).to.have.been.calledWith( + 'git', + ['status', '--porcelain'], + sinon.match.any + ); }); }); @@ -167,16 +173,18 @@ describe('npm-packages', () => { }); describe('markBumpedFilesAsAssumeUnchanged', () => { - let packages: { name: string; version: string }[]; + let packages: LernaPackageDescription[]; let expectedFiles: string[]; let spawnSync: SinonStub; beforeEach(() => { - expectedFiles = ['lerna.json']; + expectedFiles = [ + path.resolve(__dirname, '..', '..', '..', 'lerna.json') + ]; packages = listNpmPackages(); - packages.forEach(({ name }) => { - expectedFiles.push(`packages/${name}/package.json`); - expectedFiles.push(`packages/${name}/package-lock.json`); + packages.forEach(({ location }) => { + expectedFiles.push(path.resolve(location, 'package.json')); + expectedFiles.push(path.resolve(location, 'package-lock.json')); }); spawnSync = sinon.stub(); diff --git a/packages/build/src/npm-packages.ts b/packages/build/src/npm-packages.ts index 81539ba52..a2837a45e 100644 --- a/packages/build/src/npm-packages.ts +++ b/packages/build/src/npm-packages.ts @@ -6,6 +6,13 @@ const PLACEHOLDER_VERSION = '0.0.0-dev.0'; const PROJECT_ROOT = path.resolve(__dirname, '..', '..', '..'); const LERNA_BIN = path.resolve(PROJECT_ROOT, 'node_modules', '.bin', 'lerna'); +export interface LernaPackageDescription { + name: string; + version: string; + private: boolean; + location: string; +} + export function spawnSync(command: string, args: string[], options: SpawnSyncOptionsWithStringEncoding): SpawnSyncReturns { const result = spawn.sync(command, args, options); if (result.error) { @@ -46,6 +53,11 @@ export function bumpNpmPackages( cwd: PROJECT_ROOT, encoding: 'utf8' }); + spawnSyncFn('git', ['status', '--porcelain'], { + stdio: 'inherit', + cwd: PROJECT_ROOT, + encoding: 'utf8' + }); } export function publishNpmPackages( @@ -88,11 +100,12 @@ export function publishNpmPackages( } } -export function listNpmPackages(): { name: string; version: string }[] { +export function listNpmPackages(): LernaPackageDescription[] { const lernaListOutput = spawnSync( LERNA_BIN, [ 'list', '--json', + '--all' ], { cwd: PROJECT_ROOT, @@ -104,15 +117,16 @@ export function listNpmPackages(): { name: string; version: string }[] { } export function markBumpedFilesAsAssumeUnchanged( - packages: { name: string }[], assumeUnchanged: boolean, + packages: LernaPackageDescription[], + assumeUnchanged: boolean, spawnSyncFn: typeof spawnSync = spawnSync ): void { const filesToAssume = [ - 'lerna.json' + path.resolve(PROJECT_ROOT, 'lerna.json') ]; - packages.forEach(({ name }) => { - filesToAssume.push(`packages/${name}/package.json`); - filesToAssume.push(`packages/${name}/package-lock.json`); + packages.forEach(({ location }) => { + filesToAssume.push(path.resolve(location, 'package.json')); + filesToAssume.push(path.resolve(location, 'package-lock.json')); }); filesToAssume.forEach(f => {