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.
|
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`
|
||||||
|
|||||||
@ -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`
|
||||||
|
|||||||
@ -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`
|
||||||
|
|||||||
@ -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,
|
||||||
|
|||||||
@ -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 {
|
||||||
|
|||||||
@ -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',
|
||||||
|
|||||||
@ -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;
|
||||||
});
|
});
|
||||||
|
|||||||
@ -12,4 +12,5 @@ export interface Schema {
|
|||||||
publishable?: boolean;
|
publishable?: boolean;
|
||||||
importPath?: string;
|
importPath?: string;
|
||||||
testEnvironment: 'jsdom' | 'node';
|
testEnvironment: 'jsdom' | 'node';
|
||||||
|
rootDir?: string;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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"],
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user