feat(node): added rootDir flag when generating node/lib (#3659)

This commit is contained in:
Katerina Skroumpelou 2020-09-08 18:36:24 +03:00 committed by GitHub
parent a9d3fab93b
commit e10aa455ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 50 additions and 1 deletions

View File

@ -80,6 +80,14 @@ Type: `boolean`
Create a publishable library. Create a publishable library.
### rootDir
Alias(es): srcRootForCompilationRoot
Type: `string`
Sets the rootDir for TypeScript compilation. When not defined, it uses the project's root property, or srcRootForCompilationRoot if it is defined.
### skipFormat ### skipFormat
Default: `false` Default: `false`

View File

@ -80,6 +80,14 @@ Type: `boolean`
Create a publishable library. Create a publishable library.
### rootDir
Alias(es): srcRootForCompilationRoot
Type: `string`
Sets the rootDir for TypeScript compilation. When not defined, it uses the project's root property, or srcRootForCompilationRoot if it is defined.
### skipFormat ### skipFormat
Default: `false` Default: `false`

View File

@ -80,6 +80,14 @@ Type: `boolean`
Create a publishable library. Create a publishable library.
### rootDir
Alias(es): srcRootForCompilationRoot
Type: `string`
Sets the rootDir for TypeScript compilation. When not defined, it uses the project's root property, or srcRootForCompilationRoot if it is defined.
### skipFormat ### skipFormat
Default: `false` Default: `false`

View File

@ -19,6 +19,7 @@ export function runNodePackageBuilder(
) { ) {
const projGraph = createProjectGraph(); const projGraph = createProjectGraph();
const libRoot = projGraph.nodes[context.target.project].data.root; const libRoot = projGraph.nodes[context.target.project].data.root;
const normalizedOptions = normalizeOptions(options, context, libRoot); const normalizedOptions = normalizeOptions(options, context, libRoot);
const { target, dependencies } = calculateProjectDependencies( const { target, dependencies } = calculateProjectDependencies(
projGraph, projGraph,

View File

@ -70,6 +70,7 @@ export default function compileTypeScriptFiles(
const tsconfig = readTsConfig(tsConfigPath); const tsconfig = readTsConfig(tsConfigPath);
tsconfig.options.outDir = options.normalizedOutputPath; tsconfig.options.outDir = options.normalizedOutputPath;
if (options.srcRootForCompilationRoot) { if (options.srcRootForCompilationRoot) {
tsconfig.options.rootDir = options.srcRootForCompilationRoot; tsconfig.options.rootDir = options.srcRootForCompilationRoot;
} else { } else {

View File

@ -37,6 +37,19 @@ describe('lib', () => {
}); });
}); });
it('adds srcRootForCompilationRoot in workspace.json', async () => {
const tree = await runSchematic(
'lib',
{ name: 'myLib', rootDir: './src', buildable: true },
appTree
);
const workspaceJson = readJsonInTree(tree, '/workspace.json');
expect(
workspaceJson.projects['my-lib'].architect.build.options
.srcRootForCompilationRoot
).toEqual('./src');
});
it('should update nx.json', async () => { it('should update nx.json', async () => {
const tree = await runSchematic( const tree = await runSchematic(
'lib', 'lib',

View File

@ -126,6 +126,10 @@ function addProject(options: NormalizedSchema): Rule {
assets: [`${options.projectRoot}/*.md`], assets: [`${options.projectRoot}/*.md`],
}, },
}; };
if (options.rootDir) {
architect.build.options.srcRootForCompilationRoot = options.rootDir;
}
} }
return json; return json;
}); });

View File

@ -12,4 +12,5 @@ export interface Schema {
publishable?: boolean; publishable?: boolean;
importPath?: string; importPath?: string;
testEnvironment: 'jsdom' | 'node'; testEnvironment: 'jsdom' | 'node';
rootDir?: string;
} }

View File

@ -64,6 +64,11 @@
"type": "string", "type": "string",
"description": "The library name used to import it, like @myorg/my-awesome-lib. Must be a valid npm name." "description": "The library name used to import it, like @myorg/my-awesome-lib. Must be a valid npm name."
}, },
"rootDir": {
"type": "string",
"alias": "srcRootForCompilationRoot",
"description": "Sets the rootDir for TypeScript compilation. When not defined, it uses the project's root property, or srcRootForCompilationRoot if it is defined."
},
"testEnvironment": { "testEnvironment": {
"type": "string", "type": "string",
"enum": ["jsdom", "node"], "enum": ["jsdom", "node"],