From 3bc9ae985429762c2d547ab44dbaaccdeabd9e7a Mon Sep 17 00:00:00 2001 From: Kristiyan Kostadinov Date: Fri, 29 Sep 2017 00:33:13 +0200 Subject: [PATCH] build: add placeholder for Angular version (#7303) Adds the `0.0.0-NG` placeholder that will ensure that all published packages will have the same Angular requirements. --- build-config.js | 8 +++++++- src/cdk/package.json | 4 ++-- src/lib/package.json | 4 ++-- src/material-examples/package.json | 6 +++--- src/material-moment-adapter/package.json | 2 +- tools/package-tools/build-config.ts | 2 ++ tools/package-tools/version-placeholders.ts | 16 +++++++++++----- 7 files changed, 28 insertions(+), 14 deletions(-) diff --git a/build-config.js b/build-config.js index 26b3f8199bc..46438a76edb 100644 --- a/build-config.js +++ b/build-config.js @@ -4,8 +4,13 @@ */ const {join} = require('path'); +const package = require('./package.json'); + /** Current version of the project*/ -const buildVersion = require('./package.json').version; +const buildVersion = package.version; + +/** Required Angular version for the project. */ +const angularVersion = package.dependencies['@angular/core']; /** License that will be placed inside of all created bundles. */ const buildLicense = `/** @@ -18,6 +23,7 @@ const buildLicense = `/** module.exports = { projectVersion: buildVersion, + angularVersion: angularVersion, projectDir: __dirname, packagesDir: join(__dirname, 'src'), outputDir: join(__dirname, 'dist'), diff --git a/src/cdk/package.json b/src/cdk/package.json index 58d20d0c69d..b6345a26b6a 100644 --- a/src/cdk/package.json +++ b/src/cdk/package.json @@ -23,8 +23,8 @@ }, "homepage": "https://github.com/angular/material2#readme", "peerDependencies": { - "@angular/core": "^4.4.3", - "@angular/common": "^4.4.3" + "@angular/core": "0.0.0-NG", + "@angular/common": "0.0.0-NG" }, "dependencies": { "tslib": "^1.7.1" diff --git a/src/lib/package.json b/src/lib/package.json index 0f65801d568..35915f831e4 100644 --- a/src/lib/package.json +++ b/src/lib/package.json @@ -23,8 +23,8 @@ "homepage": "https://github.com/angular/material2#readme", "peerDependencies": { "@angular/cdk": "0.0.0-PLACEHOLDER", - "@angular/core": "^4.4.3", - "@angular/common": "^4.4.3" + "@angular/core": "0.0.0-NG", + "@angular/common": "0.0.0-NG" }, "dependencies": { "tslib": "^1.7.1" diff --git a/src/material-examples/package.json b/src/material-examples/package.json index bc7eb5584a7..466b289923e 100644 --- a/src/material-examples/package.json +++ b/src/material-examples/package.json @@ -24,9 +24,9 @@ "homepage": "https://github.com/angular/material2#readme", "peerDependencies": { "@angular/cdk": "0.0.0-PLACEHOLDER", - "@angular/core": "^4.4.3", - "@angular/common": "^4.4.3", - "@angular/http": "^4.4.3", + "@angular/core": "0.0.0-NG", + "@angular/common": "0.0.0-NG", + "@angular/http": "0.0.0-NG", "@angular/material": "0.0.0-PLACEHOLDER" }, "dependencies": { diff --git a/src/material-moment-adapter/package.json b/src/material-moment-adapter/package.json index 607510a6bb1..a7ac704cf2b 100644 --- a/src/material-moment-adapter/package.json +++ b/src/material-moment-adapter/package.json @@ -17,7 +17,7 @@ "homepage": "https://github.com/angular/material2#readme", "peerDependencies": { "@angular/material": "0.0.0-PLACEHOLDER", - "@angular/core": "^4.4.3", + "@angular/core": "0.0.0-NG", "moment": "^2.18.1" }, "dependencies": { diff --git a/tools/package-tools/build-config.ts b/tools/package-tools/build-config.ts index 63229d97acf..04f3411f1e6 100644 --- a/tools/package-tools/build-config.ts +++ b/tools/package-tools/build-config.ts @@ -3,6 +3,8 @@ import {findBuildConfig} from './find-build-config'; export interface BuildConfig { /** Current version of the project. */ projectVersion: string; + /** Required Angular version for the project. */ + angularVersion: string; /** Path to the root of the project. */ projectDir: string; /** Path to the directory where all packages are living. */ diff --git a/tools/package-tools/version-placeholders.ts b/tools/package-tools/version-placeholders.ts index 497a8ea1da2..7af4c61dd06 100644 --- a/tools/package-tools/version-placeholders.ts +++ b/tools/package-tools/version-placeholders.ts @@ -6,7 +6,13 @@ import {spawnSync} from 'child_process'; /** Variable that is set to the string for version placeholders. */ const versionPlaceholderText = '0.0.0-PLACEHOLDER'; +/** Placeholder that will be replaced with the required Angular version. */ +const ngVersionPlaceholderText = '0.0.0-NG'; + /** RegExp that matches version placeholders inside of a file. */ +const ngVersionPlaceholderRegex = new RegExp(ngVersionPlaceholderText, 'g'); + +/** Expression that matches Angular version placeholders within a file. */ const versionPlaceholderRegex = new RegExp(versionPlaceholderText, 'g'); /** @@ -21,9 +27,9 @@ export function replaceVersionPlaceholders(packageDir: string) { // Walk through every file that contains version placeholders and replace those with the current // version of the root package.json file. files.forEach(filePath => { - let fileContent = readFileSync(filePath, 'utf-8'); - - fileContent = fileContent.replace(versionPlaceholderRegex, buildConfig.projectVersion); + const fileContent = readFileSync(filePath, 'utf-8') + .replace(ngVersionPlaceholderRegex, buildConfig.angularVersion) + .replace(versionPlaceholderRegex, buildConfig.projectVersion); writeFileSync(filePath, fileContent); }); @@ -43,12 +49,12 @@ function buildPlaceholderFindCommand(packageDir: string) { if (platform() === 'win32') { return { binary: 'findstr', - args: ['/msi', `/c:${versionPlaceholderText}`, `${packageDir}\\*`] + args: ['/msi', `"${ngVersionPlaceholderText} ${versionPlaceholderText}"`, `${packageDir}\\*`] }; } else { return { binary: 'grep', - args: ['-ril', versionPlaceholderText, packageDir] + args: ['-ril', `"${ngVersionPlaceholderText}\\|${versionPlaceholderText}"`, packageDir] }; } }