fix(schematics): set lib npmScope when publishable
Update the lib's `package.json` name with the right prefix, when generating a lib with the `publishable` option set to 'true'. close #677
This commit is contained in:
parent
22c9fb5c3b
commit
cca6b9f03b
@ -369,6 +369,14 @@ function updateTsConfig(options: NormalizedSchema): Rule {
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function updateLibPackageNpmScope(options: NormalizedSchema): Rule {
|
||||||
|
return updateJsonInTree(`${options.projectRoot}/package.json`, json => {
|
||||||
|
console.log(json);
|
||||||
|
json.name = `@${options.prefix}/${options.name}`;
|
||||||
|
return json;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
export default function(schema: Schema): Rule {
|
export default function(schema: Schema): Rule {
|
||||||
return (host: Tree, context: SchematicContext) => {
|
return (host: Tree, context: SchematicContext) => {
|
||||||
const options = normalizeOptions(host, schema);
|
const options = normalizeOptions(host, schema);
|
||||||
@ -394,6 +402,7 @@ export default function(schema: Schema): Rule {
|
|||||||
}),
|
}),
|
||||||
updateTsConfig(options),
|
updateTsConfig(options),
|
||||||
|
|
||||||
|
options.publishable ? updateLibPackageNpmScope(options) : noop(),
|
||||||
options.routing && options.lazy
|
options.routing && options.lazy
|
||||||
? addLazyLoadedRouterConfiguration(options)
|
? addLazyLoadedRouterConfiguration(options)
|
||||||
: noop(),
|
: noop(),
|
||||||
|
|||||||
@ -60,6 +60,16 @@ describe('lib', () => {
|
|||||||
expect(packageJson.devDependencies['ng-packagr']).toBeDefined();
|
expect(packageJson.devDependencies['ng-packagr']).toBeDefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should update npmScope of lib's package.json when publishable", () => {
|
||||||
|
const tree = schematicRunner.runSchematic(
|
||||||
|
'lib',
|
||||||
|
{ name: 'myLib', publishable: true },
|
||||||
|
appTree
|
||||||
|
);
|
||||||
|
const packageJson = readJsonInTree(tree, '/libs/my-lib/package.json');
|
||||||
|
expect(packageJson.name).toEqual('@proj/my-lib');
|
||||||
|
});
|
||||||
|
|
||||||
it('should update angular.json', () => {
|
it('should update angular.json', () => {
|
||||||
const tree = schematicRunner.runSchematic(
|
const tree = schematicRunner.runSchematic(
|
||||||
'lib',
|
'lib',
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user