Skip to content

Commit

Permalink
fix(Space in file name): Support dirs with a space in the name
Browse files Browse the repository at this point in the history
  • Loading branch information
nicojs committed Nov 21, 2018
1 parent 1c42b96 commit 2ea3786
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
11 changes: 9 additions & 2 deletions src/LocalInstaller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ export interface ListByPackage {
}

const TEN_MEGA_BYTE = 1024 * 1024 * 10;

function quotify(value: string) {
return `"${value}"`;
}
export class LocalInstaller extends EventEmitter {
private sourcesByTarget: ListByPackage;
private options: Options;
Expand Down Expand Up @@ -81,7 +85,10 @@ export class LocalInstaller extends EventEmitter {
}

private installOne(target: InstallTarget): Promise<void> {
const toInstall = target.sources.map(source => resolvePackFile(this.uniqueDir, source.packageJson)).join(' ');
const toInstall = target.sources
.map(source => resolvePackFile(this.uniqueDir, source.packageJson))
.map(quotify)
.join(' ');
const options: ExecOptions = {
cwd: target.directory,
maxBuffer: TEN_MEGA_BYTE
Expand Down Expand Up @@ -125,7 +132,7 @@ export class LocalInstaller extends EventEmitter {
}

private packOne(directory: string): Promise<void> {
return exec(`npm pack ${directory}`, { cwd: this.uniqueDir, maxBuffer: TEN_MEGA_BYTE })
return exec(`npm pack ${quotify(directory)}`, { cwd: this.uniqueDir, maxBuffer: TEN_MEGA_BYTE })
.then(() => void this.emit('packed', directory));
}

Expand Down
8 changes: 4 additions & 4 deletions test/unit/LocalInstallerSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ describe('LocalInstaller install', () => {

it('should pack correct packages', async () => {
await sut.install();
expect(execStub).calledWith(`npm pack ${resolve('b')}`, { cwd: tmpDir, maxBuffer: TEN_MEGA_BYTE });
expect(execStub).calledWith(`npm pack ${resolve('c')}`, { cwd: tmpDir, maxBuffer: TEN_MEGA_BYTE });
expect(execStub).calledWith(`npm pack ${resolve('/e')}`, { cwd: tmpDir, maxBuffer: TEN_MEGA_BYTE });
expect(execStub).calledWith(`npm pack "${resolve('b')}"`, { cwd: tmpDir, maxBuffer: TEN_MEGA_BYTE });
expect(execStub).calledWith(`npm pack "${resolve('c')}"`, { cwd: tmpDir, maxBuffer: TEN_MEGA_BYTE });
expect(execStub).calledWith(`npm pack "${resolve('/e')}"`, { cwd: tmpDir, maxBuffer: TEN_MEGA_BYTE });
});

it('should install correct packages', async () => {
Expand Down Expand Up @@ -157,7 +157,7 @@ describe('LocalInstaller install', () => {
});
});

const tmp = (file: string) => resolve(tmpDir, file);
const tmp = (file: string) => `"${resolve(tmpDir, file)}"`;

const stubPackageJson = (recipe: { [directory: string]: string }) => {
Object.keys(recipe).forEach((directory, i) => {
Expand Down

0 comments on commit 2ea3786

Please sign in to comment.