feat(node): added rootDir flag when generating node/lib (#3659)
This commit is contained in:
parent
a9d3fab93b
commit
e10aa455ea
@ -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`
|
||||
|
||||
@ -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`
|
||||
|
||||
@ -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`
|
||||
|
||||
@ -249,4 +249,4 @@
|
||||
"pre-push": "yarn checkcommit && yarn documentation && pretty-quick --check"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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,
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -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',
|
||||
|
||||
@ -126,6 +126,10 @@ function addProject(options: NormalizedSchema): Rule {
|
||||
assets: [`${options.projectRoot}/*.md`],
|
||||
},
|
||||
};
|
||||
|
||||
if (options.rootDir) {
|
||||
architect.build.options.srcRootForCompilationRoot = options.rootDir;
|
||||
}
|
||||
}
|
||||
return json;
|
||||
});
|
||||
|
||||
@ -12,4 +12,5 @@ export interface Schema {
|
||||
publishable?: boolean;
|
||||
importPath?: string;
|
||||
testEnvironment: 'jsdom' | 'node';
|
||||
rootDir?: string;
|
||||
}
|
||||
|
||||
@ -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"],
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user