Skip to content

Commit

Permalink
fix(node): fix deleteOutputPath implementation
Browse files Browse the repository at this point in the history
    Ensure that generated package.json is retained
    Remove lib from e2e test since it uses @nrwl/js:tsc
    executor
    Add deleteOutputPath to schema normalization
  • Loading branch information
jaytavares committed Jun 8, 2022
1 parent 688d076 commit 845a2f5
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 47 deletions.
93 changes: 46 additions & 47 deletions e2e/node/src/node.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,38 +312,37 @@ ${jslib}();

it('should remove previous output before building with the --deleteOutputPath option set', async () => {
const appName = uniq('app');
const libName = uniq('lib');

runCLI(
`generate @nrwl/node:app ${appName} --no-interactive --compiler swc`
);
runCLI(
`generate @nrwl/node:lib ${libName} --buildable --no-interactive --compiler swc`
);
runCLI(`generate @nrwl/node:app ${appName} --no-interactive`);

// deleteOutputPath should default to true
createFile(`dist/apps/${appName}/_should_remove.txt`);
createFile(`dist/libs/${libName}/_should_remove.txt`);
createFile(`dist/apps/_should_not_remove.txt`);
checkFilesExist(
`dist/apps/${appName}/_should_remove.txt`,
`dist/apps/_should_not_remove.txt`
);
runCLI(`build ${appName} --outputHashing none`);
runCLI(`build ${libName}`);
checkFilesDoNotExist(
runCLI(`build ${appName} --outputHashing none`); // no explicit deleteOutputPath option set
checkFilesDoNotExist(`dist/apps/${appName}/_should_remove.txt`);
checkFilesExist(`dist/apps/_should_not_remove.txt`);

// Explicitly set `deleteOutputPath` to true
createFile(`dist/apps/${appName}/_should_remove.txt`);
createFile(`dist/apps/_should_not_remove.txt`);
checkFilesExist(
`dist/apps/${appName}/_should_remove.txt`,
`dist/libs/${libName}/_should_remove.txt`
`dist/apps/_should_not_remove.txt`
);
runCLI(`build ${appName} --outputHashing none --deleteOutputPath`);
checkFilesDoNotExist(`dist/apps/${appName}/_should_remove.txt`);
checkFilesExist(`dist/apps/_should_not_remove.txt`);

// `delete-output-path`
// Explicitly set `deleteOutputPath` to false
createFile(`dist/apps/${appName}/_should_keep.txt`);
runCLI(`build ${appName} --delete-output-path=false --outputHashing none`);
createFile(`dist/apps/_should_keep.txt`);
runCLI(`build ${appName} --deleteOutputPath=false --outputHashing none`);
checkFilesExist(`dist/apps/${appName}/_should_keep.txt`);

createFile(`dist/libs/${libName}/_should_keep.txt`);
runCLI(`build ${libName} --delete-output-path=false --outputHashing none`);
checkFilesExist(`dist/libs/${libName}/_should_keep.txt`);
checkFilesExist(`dist/apps/_should_keep.txt`);
}, 120000);

describe('NestJS', () => {
Expand All @@ -362,49 +361,49 @@ ${jslib}();
updateFile(
`apps/${nestapp}/src/app/foo.dto.ts`,
`
export class FooDto {
foo: string;
bar: number;
}`
export class FooDto {
foo: string;
bar: number;
}`
);
updateFile(
`apps/${nestapp}/src/app/app.controller.ts`,
`
import { Controller, Get } from '@nestjs/common';
import { FooDto } from './foo.dto';
import { AppService } from './app.service';
import { Controller, Get } from '@nestjs/common';
import { FooDto } from './foo.dto';
import { AppService } from './app.service';
@Controller()
export class AppController {
constructor(private readonly appService: AppService) {}
@Controller()
export class AppController {
constructor(private readonly appService: AppService) {}
@Get()
getData() {
return this.appService.getData();
}
@Get()
getData() {
return this.appService.getData();
}
@Get('foo')
getFoo(): Promise<FooDto> {
return Promise.resolve({
foo: 'foo',
bar: 123
})
}
}`
@Get('foo')
getFoo(): Promise<FooDto> {
return Promise.resolve({
foo: 'foo',
bar: 123
})
}
}`
);

await runCLIAsync(`build ${nestapp}`);

const mainJs = readFile(`dist/apps/${nestapp}/main.js`);
expect(stripIndents`${mainJs}`).toContain(
stripIndents`
class FooDto {
static _OPENAPI_METADATA_FACTORY() {
return { foo: { required: true, type: () => String }, bar: { required: true, type: () => Number } };
}
}
exports.FooDto = FooDto;
`
class FooDto {
static _OPENAPI_METADATA_FACTORY() {
return { foo: { required: true, type: () => String }, bar: { required: true, type: () => Number } };
}
}
exports.FooDto = FooDto;
`
);
}, 300000);
});
Expand Down
1 change: 1 addition & 0 deletions packages/node/src/utils/normalize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export function normalizeBuildOptions(
options.additionalEntryPoints ?? []
),
outputFileName: options.outputFileName ?? 'main.js',
deleteOutputPath: options.deleteOutputPath ?? true,
};
}

Expand Down

0 comments on commit 845a2f5

Please sign in to comment.