From cca6b9f03b3a59650b1c57bcc46b83204b7725a7 Mon Sep 17 00:00:00 2001 From: ben Date: Fri, 17 Aug 2018 11:45:28 -0400 Subject: [PATCH] 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 --- packages/schematics/src/collection/library/index.ts | 9 +++++++++ .../schematics/src/collection/library/library.spec.ts | 10 ++++++++++ 2 files changed, 19 insertions(+) diff --git a/packages/schematics/src/collection/library/index.ts b/packages/schematics/src/collection/library/index.ts index da5218133d..c316f70494 100644 --- a/packages/schematics/src/collection/library/index.ts +++ b/packages/schematics/src/collection/library/index.ts @@ -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 { return (host: Tree, context: SchematicContext) => { const options = normalizeOptions(host, schema); @@ -394,6 +402,7 @@ export default function(schema: Schema): Rule { }), updateTsConfig(options), + options.publishable ? updateLibPackageNpmScope(options) : noop(), options.routing && options.lazy ? addLazyLoadedRouterConfiguration(options) : noop(), diff --git a/packages/schematics/src/collection/library/library.spec.ts b/packages/schematics/src/collection/library/library.spec.ts index e2c3dde466..318c0f78de 100644 --- a/packages/schematics/src/collection/library/library.spec.ts +++ b/packages/schematics/src/collection/library/library.spec.ts @@ -60,6 +60,16 @@ describe('lib', () => { 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', () => { const tree = schematicRunner.runSchematic( 'lib',