Skip to content
This repository has been archived by the owner on Jan 5, 2022. It is now read-only.

Fix package command problems #41

Merged
merged 8 commits into from
Jan 8, 2020
Merged
Show file tree
Hide file tree
Changes from 3 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
12 changes: 6 additions & 6 deletions src/commands/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@ export default class Package extends Command {
cwd: projectDir
})
: [];
const filtered = include.filter(filepath => !exclude.includes(filepath)).map(filepath => path.relative(projectDir, filepath));
const filtered = include.filter(filepath => !exclude.includes(filepath));

filtered.forEach(filepath => {
const outputFilePath = path.resolve(outputDir, filepath);
const outputFilePath = path.resolve(outputDir, path.relative(projectDir, filepath));
fs.mkdirSync(path.dirname(outputFilePath), { recursive: true });
fs.copyFileSync(filepath, outputFilePath);
});
Expand All @@ -102,13 +102,13 @@ export default class Package extends Command {
{
title: 'Install productive dependencies',
enabled: () => !flags.skipInstall,
task: async () => {
task: async () =>
execa('npm', ['install', '--production', '--prefix', outputDir], { stdio: flags.verbose ? 'inherit' : 'ignore' }).catch(e =>
this.error(e, { exit: 10 })
);
}
)
}
]);
tasks.run();

await tasks.run();
}
}
5 changes: 2 additions & 3 deletions test/init.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,10 @@ import Init from '../src/commands/init';
import { getCleanProjectDir, getTestOutputDir } from './test-utils';

const testOutputDir = getTestOutputDir(__filename);
const expressAppDir = path.resolve('test', 'express');
const nestAppDir = path.resolve('test', 'nest');

describe('Init', () => {
const expressAppDir = path.resolve('test', 'express');
const nestAppDir = path.resolve('test', 'nest');

afterAll(() => {
fs.removeSync(testOutputDir);
});
Expand Down
46 changes: 38 additions & 8 deletions test/package.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,50 @@
* Copyright (c) 2019 SAP SE or an SAP affiliate company. All rights reserved.
*/

import * as fs from 'fs-extra';
import * as path from 'path';
import Package from '../src/commands/package';
import { getCleanProjectDir, getTestOutputDir } from './test-utils';

const testOutputDir = getTestOutputDir(__filename);
const nestAppDir = path.resolve('test', 'nest');

describe('Package', () => {
it('should copy files correctly without parameters', () => {
expect(true).toBeTruthy();
afterAll(() => {
// fs.removeSync(testOutputDir);
florian-richter marked this conversation as resolved.
Show resolved Hide resolved
});

it('should copy files correctly with custom globs', () => {
expect(true).toBeTruthy();
it('should copy files correctly without parameters', async () => {
const projectDir = getCleanProjectDir(testOutputDir, 'no-params');
fs.copySync(nestAppDir, projectDir, { recursive: true });
await Package.run([projectDir, '--skipInstall']);

expect(fs.readdirSync(path.resolve(projectDir, 'deployment'))).toIncludeAllMembers(['package.json', 'package-lock.json']);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From my understanding this tests the default value for --include. Shouldn't this test assert then that all files included by default are copied (i.e. package.json, package-lock.json, index.js, dist/**/*)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for the default nest.js app does not have an index.js and the dist/** only appear after compiling (which I dont test here). That's why I implemented it this way, but I am open for improvement suggestions.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Is there something like toIncludeAndOnlyIncludeAllMembers? =P

});

it('should overwrite output folder', () => {
expect(true).toBe(true);
it('should copy files correctly with custom globs', async () => {
const projectDir = getCleanProjectDir(testOutputDir, 'globs');
fs.copySync(nestAppDir, projectDir, { recursive: true });
await Package.run([projectDir, '--include=*.json', '--exclude=package*,tsconfig*', '--skipInstall']);

expect(fs.readdirSync(path.resolve(projectDir, 'deployment'))).toIncludeAllMembers(['nest-cli.json', 'tslint.json']);
florian-richter marked this conversation as resolved.
Show resolved Hide resolved
});

it('should install productive dependencies only', () => {
expect(true).toBe(true);
it('should overwrite output folder', async () => {
const projectDir = getCleanProjectDir(testOutputDir, 'folder-overwrite');
fs.copySync(nestAppDir, projectDir, { recursive: true });
await Package.run([projectDir, '--include=.gitignore', '--skipInstall']);
await Package.run([projectDir, '--include=README.md', '--skipInstall']);

expect(fs.readdirSync(path.resolve(projectDir, 'deployment'))).toEqual(['README.md']);
florian-richter marked this conversation as resolved.
Show resolved Hide resolved
});

it('should install productive dependencies only', async () => {
const projectDir = getCleanProjectDir(testOutputDir, 'productive-dependencies');
fs.copySync(nestAppDir, projectDir, { recursive: true });
await Package.run([projectDir]);

expect(fs.readdirSync(path.resolve(projectDir, 'deployment'))).toIncludeAllMembers(['package.json', 'package-lock.json', 'node_modules']);
expect(fs.readdirSync(path.resolve(projectDir, 'deployment', 'node_modules', '@nestjs'))).not.toContain('cli');
}, 60000);
});