Skip to content

Commit

Permalink
fix(@schematics/angular): don't add scripts in library schematic
Browse files Browse the repository at this point in the history
  • Loading branch information
filipesilva authored and hansl committed Jun 6, 2018
1 parent acf8375 commit e5271e4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 21 deletions.
16 changes: 4 additions & 12 deletions packages/schematics/angular/library/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ function updateTsConfig(npmPackageName: string, entryFilePath: string) {
};
}

function addDependenciesAndScriptsToPackageJson(name: string, sourceDir: string) {
function addDependenciesAndScriptsToPackageJson() {

return (host: Tree) => {
if (!host.exists('package.json')) { return host; }
Expand All @@ -92,19 +92,13 @@ function addDependenciesAndScriptsToPackageJson(name: string, sourceDir: string)
json.devDependencies = {
'@angular/compiler': '^5.0.0',
'@angular/compiler-cli': '^5.0.0',
'ng-packagr': '^2.1.0',
'ng-packagr': '^2.2.0',
'tsickle': '>=0.25.5',
'tslib': '^1.7.1',
'typescript': '>=2.4.2',
// de-structure last keeps existing user dependencies
...json.devDependencies,
};

// Add package.json script
if (!json.scripts) {
json.scripts = {};
}
json.scripts[`libs:${name}:build`] = `ng-packagr -p ${sourceDir}/package.json`;
});
};
}
Expand Down Expand Up @@ -138,10 +132,8 @@ export default function (options: GenerateLibraryOptions): Rule {
branchAndMerge(chain([
mergeWith(templateSource),
])),
options.skipPackageJson ? noop() : addDependenciesAndScriptsToPackageJson(name,
forwardSlashes(sourceDir)),
options.skipTsConfig ? noop() : updateTsConfig(name,
forwardSlashes(entryFilePath)),
options.skipPackageJson ? noop() : addDependenciesAndScriptsToPackageJson(),
options.skipTsConfig ? noop() : updateTsConfig(name, forwardSlashes(entryFilePath)),
])(host, context);
};
}
10 changes: 1 addition & 9 deletions packages/schematics/angular/library/index_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,18 +125,10 @@ describe('Library Schematic', () => {
const tree = schematicRunner.runSchematic('library', defaultOptions, mockTree);

const packageJson = getJsonFileContent(tree, 'package.json');
expect(packageJson.devDependencies['ng-packagr']).toEqual('^2.1.0');
expect(packageJson.devDependencies['ng-packagr']).toEqual('^2.2.0');
// TODO ...
});

it(`should add a script for ng-packagr`, () => {
const tree = schematicRunner.runSchematic('library', defaultOptions, mockTree);

const packageJson = getJsonFileContent(tree, 'package.json');
expect(packageJson.scripts['libs:foo:build'])
.toEqual('ng-packagr -p my-libs/foo/package.json');
});

it(`should not override existing users dependencies`, () => {
const tree = schematicRunner.runSchematic('library', defaultOptions, mockTree);

Expand Down

0 comments on commit e5271e4

Please sign in to comment.