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.
### 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
Default: `false`

View File

@ -80,6 +80,14 @@ Type: `boolean`
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
Default: `false`

View File

@ -80,6 +80,14 @@ Type: `boolean`
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
Default: `false`

View File

@ -249,4 +249,4 @@
"pre-push": "yarn checkcommit && yarn documentation && pretty-quick --check"
}
}
}
}

View File

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

View File

@ -70,6 +70,7 @@ export default function compileTypeScriptFiles(
const tsconfig = readTsConfig(tsConfigPath);
tsconfig.options.outDir = options.normalizedOutputPath;
if (options.srcRootForCompilationRoot) {
tsconfig.options.rootDir = options.srcRootForCompilationRoot;
} 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 () => {
const tree = await runSchematic(
'lib',

View File

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

View File

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

View File

@ -64,6 +64,11 @@
"type": "string",
"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": {
"type": "string",
"enum": ["jsdom", "node"],