From e10faeaf72a7343033aa9af6659a77cd233c84f4 Mon Sep 17 00:00:00 2001 From: Filipe Silva Date: Tue, 26 Jul 2016 04:14:51 +0100 Subject: [PATCH] feat: use @types instead of typings --- README.md | 7 +- .../ng2/files/__path__/tsconfig.json | 8 +- .../ng2/files/__path__/typings.d.ts | 5 +- .../blueprints/ng2/files/config/karma.conf.js | 5 +- .../blueprints/ng2/files/e2e/tsconfig.json | 5 +- .../ng2/blueprints/ng2/files/e2e/typings.d.ts | 1 - addon/ng2/blueprints/ng2/files/package.json | 16 +- addon/ng2/blueprints/ng2/files/typings.json | 10 - addon/ng2/models/webpack-build-common.ts | 18 +- addon/ng2/models/webpack-build-test.js | 1 - .../ts-path-mappings-webpack-plugin.ts | 252 ------------------ package.json | 4 +- typings.json | 18 -- 13 files changed, 31 insertions(+), 319 deletions(-) delete mode 100644 addon/ng2/blueprints/ng2/files/e2e/typings.d.ts delete mode 100644 addon/ng2/blueprints/ng2/files/typings.json delete mode 100644 addon/ng2/utilities/ts-path-mappings-webpack-plugin.ts delete mode 100644 typings.json diff --git a/README.md b/README.md index a8c01ca1d7ac..968a5bb591c7 100644 --- a/README.md +++ b/README.md @@ -265,16 +265,13 @@ ng new sassy-project --style=sass Simply install your library via `npm install lib-name` and import it in your code. -If the library does not include typings, you can search and install them using `npm run typings` npm script provided: +If the library does not include typings, you can install them using npm: ```bash npm install moment -npm run typings -- search moment -npm run typings -- install dt~moment --global +npm install @types/moment ``` -See https://github.com/typings/typings for more information about the `typings` tool. - ### Updating angular-cli To update `angular-cli` to a new version, you must update both the global package and your project's local package. diff --git a/addon/ng2/blueprints/ng2/files/__path__/tsconfig.json b/addon/ng2/blueprints/ng2/files/__path__/tsconfig.json index fc08b73a705b..e01a1794bfb5 100644 --- a/addon/ng2/blueprints/ng2/files/__path__/tsconfig.json +++ b/addon/ng2/blueprints/ng2/files/__path__/tsconfig.json @@ -9,6 +9,12 @@ "moduleResolution": "node", "outDir": "<%= relativeRootPath %>/dist/out-tsc", "sourceMap": true, - "target": "es5" + "target": "es5", + "typeRoots": [ + "../node_modules/@types" + ], + "types": [ + "jasmine" + ] } } diff --git a/addon/ng2/blueprints/ng2/files/__path__/typings.d.ts b/addon/ng2/blueprints/ng2/files/__path__/typings.d.ts index c9d1541fdc09..dc0276ded1cd 100644 --- a/addon/ng2/blueprints/ng2/files/__path__/typings.d.ts +++ b/addon/ng2/blueprints/ng2/files/__path__/typings.d.ts @@ -2,10 +2,7 @@ // https://github.com/typings/typings // https://www.typescriptlang.org/docs/handbook/writing-declaration-files.html -/// -<% if(!isMobile) { %> declare var System: any; -<% if(!isMobile) { %>declare var module: { id: string };<% } %> +declare var module: { id: string }; declare var require: any; -<% } %> diff --git a/addon/ng2/blueprints/ng2/files/config/karma.conf.js b/addon/ng2/blueprints/ng2/files/config/karma.conf.js index c86d3243662a..118cdc2e7721 100644 --- a/addon/ng2/blueprints/ng2/files/config/karma.conf.js +++ b/addon/ng2/blueprints/ng2/files/config/karma.conf.js @@ -1,3 +1,6 @@ +// Karma configuration file, see link for more information +// https://karma-runner.github.io/0.13/config/configuration-file.html + module.exports = function (config) { config.set({ basePath: '..', @@ -22,7 +25,7 @@ module.exports = function (config) { './src/test.ts': ['angular-cli'] }, angularCliConfig: './angular-cli.json', - reporters: ['progress'], + reporters: ['coverage', 'progress'], port: 9876, colors: true, logLevel: config.LOG_INFO, diff --git a/addon/ng2/blueprints/ng2/files/e2e/tsconfig.json b/addon/ng2/blueprints/ng2/files/e2e/tsconfig.json index 3c9a6d4169cd..656bdb14ff14 100644 --- a/addon/ng2/blueprints/ng2/files/e2e/tsconfig.json +++ b/addon/ng2/blueprints/ng2/files/e2e/tsconfig.json @@ -8,6 +8,9 @@ "moduleResolution": "node", "outDir": "../dist/out-tsc-e2e", "sourceMap": true, - "target": "es5" + "target": "es5", + "typeRoots": [ + "../node_modules/@types" + ] } } diff --git a/addon/ng2/blueprints/ng2/files/e2e/typings.d.ts b/addon/ng2/blueprints/ng2/files/e2e/typings.d.ts deleted file mode 100644 index eebc2728b868..000000000000 --- a/addon/ng2/blueprints/ng2/files/e2e/typings.d.ts +++ /dev/null @@ -1 +0,0 @@ -/// diff --git a/addon/ng2/blueprints/ng2/files/package.json b/addon/ng2/blueprints/ng2/files/package.json index c3d3b13f9284..e7dfbbcc5608 100644 --- a/addon/ng2/blueprints/ng2/files/package.json +++ b/addon/ng2/blueprints/ng2/files/package.json @@ -5,12 +5,10 @@ "angular-cli": {}, "scripts": { "start": "ng serve", - "postinstall": "typings install", "lint": "tslint \"<%= sourceDir %>/**/*.ts\"", "test": "ng test", "pree2e": "webdriver-manager update", - "e2e": "protractor", - "typings": "typings" + "e2e": "protractor" }, "private": true, "dependencies": { @@ -36,9 +34,10 @@ "angular2-universal-polyfills": "0.4.1", "preboot": "2.1.2", "parse5": "1.5.1",<% } %> + "@types/jasmine": "^2.2.30", + "@types/protractor": "^1.5.16", "angular-cli": "^<%= version %>", - "codelyzer": "0.0.20", - "ember-cli-inject-live-reload": "1.4.0", + "codelyzer": "0.0.26", "jasmine-core": "2.4.1", "jasmine-spec-reporter": "2.5.0", "karma": "0.13.22", @@ -46,9 +45,8 @@ "karma-coverage": "^1.0.0", "karma-jasmine": "0.3.8", "protractor": "3.3.0", - "ts-node": "0.9.1", - "tslint": "3.11.0", - "typescript": "^1.9.0-dev.20160627-1.0", - "typings": "^1.3.1" + "ts-node": "1.2.1", + "tslint": "3.13.0", + "typescript": "^2.0.0" } } diff --git a/addon/ng2/blueprints/ng2/files/typings.json b/addon/ng2/blueprints/ng2/files/typings.json deleted file mode 100644 index 6d8375bdd9a0..000000000000 --- a/addon/ng2/blueprints/ng2/files/typings.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "globalDevDependencies": { - "angular-protractor": "registry:dt/angular-protractor#1.5.0+20160425143459", - "jasmine": "registry:dt/jasmine#2.2.0+20160412134438", - "selenium-webdriver": "registry:dt/selenium-webdriver#2.44.0+20160317120654" - }, - "globalDependencies": { - <% if (isMobile) {%>"node": "registry:dt/node#6.0.0+20160621231320" <% } %> - } -} diff --git a/addon/ng2/models/webpack-build-common.ts b/addon/ng2/models/webpack-build-common.ts index dd184195cac1..edb412f710b1 100644 --- a/addon/ng2/models/webpack-build-common.ts +++ b/addon/ng2/models/webpack-build-common.ts @@ -3,25 +3,14 @@ import * as CopyWebpackPlugin from 'copy-webpack-plugin'; import * as HtmlWebpackPlugin from 'html-webpack-plugin'; import * as webpack from 'webpack'; import { ForkCheckerPlugin } from 'awesome-typescript-loader'; -import { LoaderConfig, PathsPlugin } from '../utilities/ts-path-mappings-webpack-plugin'; import { CliConfig } from './config'; export function getWebpackCommonConfig(projectRoot: string, sourceDir: string) { - const awesomeTypescriptLoaderConfig: LoaderConfig | any = { - useWebpackText: true, - useForkChecker: true, - tsconfig: path.resolve(projectRoot, `./${sourceDir}/tsconfig.json`) - } - return { devtool: 'inline-source-map', resolve: { extensions: ['', '.ts', '.js'], - root: path.resolve(projectRoot, `./${sourceDir}`), - moduleDirectories: ['node_modules'], - plugins: [ - new PathsPlugin(awesomeTypescriptLoaderConfig); - ] + root: path.resolve(projectRoot, `./${sourceDir}`) }, context: path.resolve(__dirname, './'), entry: { @@ -49,7 +38,10 @@ export function getWebpackCommonConfig(projectRoot: string, sourceDir: string) { loaders: [ { loader: 'awesome-typescript-loader', - query: awesomeTypescriptLoaderConfig + query: { + useForkChecker: true, + tsconfig: path.resolve(projectRoot, `./${sourceDir}/tsconfig.json`) + } }, { loader: 'angular2-template-loader' diff --git a/addon/ng2/models/webpack-build-test.js b/addon/ng2/models/webpack-build-test.js index 0161dac8d922..cada4fefd3f9 100644 --- a/addon/ng2/models/webpack-build-test.js +++ b/addon/ng2/models/webpack-build-test.js @@ -42,7 +42,6 @@ const getWebpackTestConfig = function(projectRoot, sourceDir) { { loader: 'awesome-typescript-loader', query: { - useWebpackText: true, tsconfig: path.resolve(projectRoot, `./${sourceDir}/tsconfig.json`), module: 'commonjs', target: 'es5', diff --git a/addon/ng2/utilities/ts-path-mappings-webpack-plugin.ts b/addon/ng2/utilities/ts-path-mappings-webpack-plugin.ts deleted file mode 100644 index 6c35b7fd3183..000000000000 --- a/addon/ng2/utilities/ts-path-mappings-webpack-plugin.ts +++ /dev/null @@ -1,252 +0,0 @@ -import * as path from 'path'; -import * as ts from 'typescript'; -import * as _ from 'lodash'; - -const ModulesInRootPlugin: new (a: string, b: string, c: string) => ResolverPlugin = require('enhanced-resolve/lib/ModulesInRootPlugin'); - -const createInnerCallback: CreateInnerCallback = require('enhanced-resolve/lib/createInnerCallback'); -const getInnerRequest: getInnerRequest = require('enhanced-resolve/lib/getInnerRequest'); - -export type ResolverCallback = (request: Request, callback: Callback) => void; -export type QueryOptions = LoaderConfig & ts.CompilerOptions; -export type TsConfig = ts.ParsedCommandLine; - -export type CreateInnerCallback = (callback: Callback, options: Callback, message?: string, messageOptional?: string) => Callback; -type getInnerRequest = (resolver: Resolver, request: Request) => string; - -export interface TSCompilerInfo { - compilerPath: string; - tsImpl: typeof ts; -} - -export interface Request { - request?: Request; - relativePath: string; -} - -export interface Callback { - (err?: Error, result?: any): void; - - log?: any; - stack?: any; - missing?: any; -} - -export interface Configs { - configFilePath: string; - compilerConfig: TsConfig; - loaderConfig: LoaderConfig; -} - -export interface LoaderConfig { - instanceName?: string; - showRecompileReason?: boolean; - compiler?: string; - emitRequireType?: boolean; - reEmitDependentFiles?: boolean; - tsconfig?: string; - useWebpackText?: boolean; - externals?: string[]; - doTypeCheck?: boolean; - ignoreDiagnostics?: number[]; - forkChecker?: boolean; - forkCheckerSilent?: boolean; - useBabel?: boolean; - babelCore?: string; - babelOptions?: any; - usePrecompiledFiles?: boolean; - skipDeclarationFilesCheck?: boolean; - useCache?: boolean; - cacheDirectory?: string; - resolveGlobs?: boolean; - library: string; -} - -export interface ResolverPlugin { - apply(resolver: Resolver): void; -} - -export interface Resolver { - apply(plugin: ResolverPlugin): void; - plugin(source: string, cb: ResolverCallback): void; - doResolve(target: string, req: Request, desc: string, Callback: any): void; - join(relativePath: string, innerRequest: Request): Request; -} - -export interface Mapping { - onlyModule: boolean; - alias: string; - aliasPattern: RegExp; - target: string; -} - -export function readConfigFile(baseDir: string, query: QueryOptions, tsImpl: typeof ts): Configs { - let configFilePath: string; - if (query.tsconfig && query.tsconfig.match(/\.json$/)) { - configFilePath = path.dirname(path.resolve(process.cwd(),query.tsconfig)); - } else { - configFilePath = tsImpl.findConfigFile(process.cwd(), tsImpl.sys.fileExists); - } - - let existingOptions = tsImpl.convertCompilerOptionsFromJson(query, process.cwd(), 'atl.query'); - - if (!configFilePath) { - return { - configFilePath: process.cwd(), - compilerConfig: tsImpl.parseJsonConfigFileContent( - {}, - tsImpl.sys, - process.cwd(), - _.extend({}, ts.getDefaultCompilerOptions(), existingOptions.options) as ts.CompilerOptions, - process.cwd() - ), - loaderConfig: query as LoaderConfig - }; - } - - debugger; - - let jsonConfigFile = tsImpl.readConfigFile(configFilePath, tsImpl.sys.readFile); - - let compilerConfig = tsImpl.parseJsonConfigFileContent( - jsonConfigFile.config, - tsImpl.sys, - process.cwd(), - existingOptions.options, - configFilePath - ); - - return { - jsonConfigFile, - configFilePath, - compilerConfig, - loaderConfig: _.defaults( - query, - jsonConfigFile.config.awesomeTypescriptLoaderOptions) - }; -} - - - -export function setupTs(compiler: string): TSCompilerInfo { - let compilerPath = compiler || 'typescript'; - - let tsImpl: typeof ts; - let tsImplPath: string; - try { - tsImplPath = require.resolve(compilerPath); - tsImpl = require(tsImplPath); - } catch (e) { - console.error(e); - process.exit(1); - } - - let compilerInfo: TSCompilerInfo = { - compilerPath, - tsImpl, - }; - - return compilerInfo; -} - - -function escapeRegExp(str: string) { - return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); -} - -export class PathsPlugin implements ResolverPlugin { - source: string; - target: string; - ts: typeof ts; - configFilePath: string; - options: ts.CompilerOptions; - - baseUrl: string; - mappings: Mapping[]; - absoluteBaseUrl: string; - - - constructor(config: LoaderConfig & ts.CompilerOptions = {} as any) { - this.source = 'described-resolve'; - this.target = 'resolve'; - - this.ts = setupTs(config.compiler).tsImpl; - - let { configFilePath, compilerConfig, jsonConfigFile } = readConfigFile(process.cwd(), config, this.ts); - this.options = compilerConfig.options; - this.configFilePath = configFilePath; - - this.baseUrl = this.options.configFilePath ? this.options.configFilePath : './'; - - this.absoluteBaseUrl = path.resolve( - path.dirname(this.configFilePath), - this.baseUrl - ); - - this.mappings = []; - let paths = this.options.paths || {}; - Object.keys(paths).forEach(alias => { - let onlyModule = alias.indexOf('*') === -1; - let excapedAlias = escapeRegExp(alias); - let targets = paths[alias]; - targets.forEach(target => { - let aliasPattern: RegExp; - if (onlyModule) { - aliasPattern = new RegExp(`^${excapedAlias}$`); - } else { - let withStarCapturing = excapedAlias.replace('\\*', '(.*)'); - aliasPattern = new RegExp(`^${withStarCapturing}`); - } - - this.mappings.push({ - onlyModule, - alias, - aliasPattern, - target: target - }); - }); - }); - } - - apply(resolver: Resolver) { - let { baseUrl, mappings, absoluteBaseUrl } = this; - - if (baseUrl) { - resolver.apply(new ModulesInRootPlugin("module", absoluteBaseUrl, "resolve")); - } - - mappings.forEach(mapping => { - // resolver.plugin(this.source, this.createPlugin(resolver, mapping)); - resolver.plugin(this.source, function(request, callback) { - var innerRequest = getInnerRequest(resolver, request); - if(!innerRequest) return callback(); - - var newRequestStr = mapping.target; - var match = innerRequest.match(mapping.aliasPattern); - if (!match) { - return callback(); - } - if (!mapping.onlyModule) { - newRequestStr = newRequestStr.replace('*', match[1]); - } - if (newRequestStr[0] === '.') { - newRequestStr = path.resolve(absoluteBaseUrl, newRequestStr); - } - var obj: Request = Object.assign({}, request, { - request: newRequestStr - }); - - console.log("aliased'" + innerRequest + "': '" + mapping.alias + "' to '" + newRequestStr + "'", newRequest); - - return resolver.doResolve(this.target, obj,"aliased with mapping '" + innerRequest + "': '" + mapping.alias + "' to '" + newRequestStr + "'", createInnerCallback(function(err, result) { - if(arguments.length > 0) return callback(err, result); - - // don't allow other aliasing or raw request - callback(null, null); - }, callback)); - - return callback(); - }); - }); - } -} diff --git a/package.json b/package.json index 38bb352dfe13..a328abfea19f 100644 --- a/package.json +++ b/package.json @@ -32,12 +32,11 @@ }, "homepage": "https://github.com/angular/angular-cli", "dependencies": { - "@angular/compiler-cli": "^0.2.0", "@types/lodash": "^4.0.25-alpha", "@types/rimraf": "0.0.25-alpha", "@types/webpack": "^1.12.22-alpha", "angular2-template-loader": "^0.4.0", - "awesome-typescript-loader": "^2.1.0", + "awesome-typescript-loader": "^2.1.1", "chalk": "^1.1.3", "compression-webpack-plugin": "^0.3.1", "copy-webpack-plugin": "^3.0.1", @@ -90,7 +89,6 @@ "tslint-loader": "^2.1.4", "typedoc": "^0.4.2", "typescript": "^2.0.0", - "typings": "^0.8.1", "url-loader": "^0.5.7", "webpack": "2.1.0-beta.18", "webpack-dev-server": "2.1.0-beta.0", diff --git a/typings.json b/typings.json deleted file mode 100644 index 5d47c2fc7a0b..000000000000 --- a/typings.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "dependencies": { - "es6-promise": "registry:npm/es6-promise#3.0.0+20160211003958" - }, - "devDependencies": { - "chalk": "github:typings/typed-chalk#a7e422c5455e70292e5675a727d43a7b05fc3e58" - }, - "ambientDevDependencies": { - "assertion-error": "github:DefinitelyTyped/DefinitelyTyped/assertion-error/assertion-error.d.ts#800a7047cf275cc9f695cbd116748cd408a09d6d", - "chai": "github:DefinitelyTyped/DefinitelyTyped/chai/chai.d.ts#9c25433c84251bfe72bf0030a95edbbb2c81c9d5", - "glob": "github:DefinitelyTyped/DefinitelyTyped/glob/glob.d.ts#a14d724826174d1669d4df04c80f4838b7e71fdf", - "minimatch": "github:DefinitelyTyped/DefinitelyTyped/minimatch/minimatch.d.ts#a3900b896f7b3361b79f9b503224777619907d53", - "mocha": "github:DefinitelyTyped/DefinitelyTyped/mocha/mocha.d.ts#d6dd320291705694ba8e1a79497a908e9f5e6617", - "node": "github:DefinitelyTyped/DefinitelyTyped/node/node.d.ts#8cf8164641be73e8f1e652c2a5b967c7210b6729", - "shelljs": "github:DefinitelyTyped/DefinitelyTyped/shelljs/shelljs.d.ts#ce14ae27a020194da3d35aa3468ca1e9e5296316", - "through": "github:DefinitelyTyped/DefinitelyTyped/through/through.d.ts#4ffee4a839f36d4f13ea7b0bc03ed2ca853e79d5" - } -}