Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions packages/build/src/npm-packages.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import {
listNpmPackages,
markBumpedFilesAsAssumeUnchanged,
publishNpmPackages,
spawnSync
spawnSync,
LernaPackageDescription
} from './npm-packages';


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

Expand Down Expand Up @@ -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();
Expand Down
26 changes: 20 additions & 6 deletions packages/build/src/npm-packages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> {
const result = spawn.sync(command, args, options);
if (result.error) {
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand All @@ -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 => {
Expand Down