Skip to content
This repository was archived by the owner on Apr 4, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .monorepo.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@
},
"@angular-devkit/core": {
"name": "Core",
"links": [
{
"label": "README",
"url": "https://github.com/angular/devkit/blob/master/packages/angular_devkit/core/README.md"
}
],
"version": "0.0.23",
"hash": "45c3c8b7d60b038bbedd3000ebca1b88"
},
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ This is a monorepo which contains many packages:
| Project | Package | Version | Links |
|---|---|---|---|
**Build Optimizer** | [`@angular-devkit/build-optimizer`](http://npmjs.com/packages/@angular-devkit/build-optimizer) | [![latest](https://img.shields.io/npm/v/%40angular-devkit%2Fbuild-optimizer/latest.svg)](http://npmjs.com/packages/@angular-devkit/build-optimizer) | [![README](https://img.shields.io/badge/README--green.svg)](https://github.com/angular/devkit/blob/master/packages/angular_devkit/build_optimizer/README.md)
**Core** | [`@angular-devkit/core`](http://npmjs.com/packages/@angular-devkit/core) | [![latest](https://img.shields.io/npm/v/%40angular-devkit%2Fcore/latest.svg)](http://npmjs.com/packages/@angular-devkit/core) |
**Core** | [`@angular-devkit/core`](http://npmjs.com/packages/@angular-devkit/core) | [![latest](https://img.shields.io/npm/v/%40angular-devkit%2Fcore/latest.svg)](http://npmjs.com/packages/@angular-devkit/core) | [![README](https://img.shields.io/badge/README--green.svg)](https://github.com/angular/devkit/blob/master/packages/angular_devkit/core/README.md)
**Schematics** | [`@angular-devkit/schematics`](http://npmjs.com/packages/@angular-devkit/schematics) | [![latest](https://img.shields.io/npm/v/%40angular-devkit%2Fschematics/latest.svg)](http://npmjs.com/packages/@angular-devkit/schematics) | [![README](https://img.shields.io/badge/README--green.svg)](https://github.com/angular/devkit/blob/master/packages/angular_devkit/schematics/README.md)
**Schematics CLI** | [`@angular-devkit/schematics-cli`](http://npmjs.com/packages/@angular-devkit/schematics-cli) | [![latest](https://img.shields.io/npm/v/%40angular-devkit%2Fschematics-cli/latest.svg)](http://npmjs.com/packages/@angular-devkit/schematics-cli) |

Expand Down
12 changes: 8 additions & 4 deletions lib/bootstrap-local.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ const path = require('path');
const ts = require('typescript');


let _istanbulRequireHook = null;
if (process.env['CODE_COVERAGE'] || process.argv.indexOf('--code-coverage') !== -1) {
_istanbulRequireHook = require('./istanbul-local').istanbulRequireHook;
}


// Check if we need to profile this CLI run.
let profiler = null;
if (process.env['DEVKIT_PROFILING']) {
Expand Down Expand Up @@ -45,8 +51,6 @@ Error.stackTraceLimit = Infinity;
global._DevKitIsLocal = true;
global._DevKitRoot = path.resolve(__dirname, '..');

global._DevKitRequireHook = null;


const compilerOptions = ts.readConfigFile(path.join(__dirname, '../tsconfig.json'), p => {
return fs.readFileSync(p, 'utf-8');
Expand All @@ -71,8 +75,8 @@ require.extensions['.ts'] = function (m, filename) {
try {
let result = ts.transpile(source, compilerOptions['compilerOptions'], filename);

if (global._DevKitRequireHook) {
result = global._DevKitRequireHook(result, filename);
if (_istanbulRequireHook) {
result = _istanbulRequireHook(result, filename);
}

// Send it to node to execute.
Expand Down
57 changes: 57 additions & 0 deletions lib/istanbul-local.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
const { SourceMapConsumer } = require('source-map');
const Istanbul = require('istanbul');

const inlineSourceMapRe = /\/\/# sourceMappingURL=data:application\/json;base64,(\S+)$/;


// Use the internal DevKit Hook of the require extension installed by our bootstrapping code to add
// Istanbul (not Constantinople) collection to the code.
const codeMap = new Map();
exports.codeMap = codeMap;

exports.istanbulRequireHook = function(code, filename) {
// Skip spec files.
if (filename.match(/_spec\.ts$/)) {
return code;
}
const codeFile = codeMap.get(filename);
if (codeFile) {
return codeFile.code;
}

const instrumenter = new Istanbul.Instrumenter({
esModules: true,
codeGenerationOptions: {
sourceMap: filename,
sourceMapWithCode: true,
},
});
let instrumentedCode = instrumenter.instrumentSync(code, filename);
const match = code.match(inlineSourceMapRe);

if (match) {
const sourceMapGenerator = instrumenter.sourceMap;
// Fix source maps for exception reporting (since the exceptions happen in the instrumented
// code.
const sourceMapJson = JSON.parse(Buffer.from(match[1], 'base64').toString());
const consumer = new SourceMapConsumer(sourceMapJson);
sourceMapGenerator.applySourceMap(consumer, filename);

instrumentedCode = instrumentedCode.replace(inlineSourceMapRe, '')
+ '//# sourceMappingURL=data:application/json;base64,'
+ new Buffer(sourceMapGenerator.toString()).toString('base64');

// Keep the consumer from the original source map, because the reports from Istanbul (not
// Constantinople) are already mapped against the code.
codeMap.set(filename, { code: instrumentedCode, map: consumer });
}

return instrumentedCode;
};
32 changes: 20 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"@types/source-map": "^0.5.0",
"@types/webpack": "^3.0.2",
"@types/webpack-sources": "^0.1.3",
"ajv": "^5.5.1",
"chokidar": "^1.7.0",
"conventional-changelog": "^1.1.0",
"glob": "^7.0.3",
Expand Down
59 changes: 59 additions & 0 deletions packages/angular_devkit/core/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Core
> Shared utilities for Angular DevKit.

# Exception

# Json

## Schema

### SchemaValidatorResult
```
export interface SchemaValidatorResult {
success: boolean;
errors?: string[];
}
```

### SchemaValidator

```
export interface SchemaValidator {
(data: any): Observable<SchemaValidatorResult>;
}
```

### SchemaFormatter

```
export interface SchemaFormatter {
readonly async: boolean;
validate(data: any): boolean | Observable<boolean>;
}
```

### SchemaRegistry

```
export interface SchemaRegistry {
compile(schema: Object): Observable<SchemaValidator>;
addFormat(name: string, formatter: SchemaFormatter): void;
}
```

### CoreSchemaRegistry

`SchemaRegistry` implementation using https://github.com/epoberezkin/ajv.
Constructor accepts object containing `SchemaFormatter` that will be added automatically.

```
export class CoreSchemaRegistry implements SchemaRegistry {
constructor(formats: { [name: string]: SchemaFormatter} = {}) {}
}
```

# Logger

# Utils

# Virtual FS
1 change: 1 addition & 0 deletions packages/angular_devkit/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"core"
],
"dependencies": {
"ajv": "~5.5.1",
"chokidar": "^1.7.0",
"source-map": "^0.5.6"
}
Expand Down
11 changes: 1 addition & 10 deletions packages/angular_devkit/core/src/json/schema/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,5 @@
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import * as javascript from './serializers/javascript';

export * from './interface';
export * from './registry';
export * from './schema';


export { javascript };

export const serializers = {
JavascriptSerializer: javascript.JavascriptSerializer,
};
35 changes: 35 additions & 0 deletions packages/angular_devkit/core/src/json/schema/interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import { Observable } from 'rxjs/Observable';


export interface SchemaValidatorResult {
success: boolean;
errors?: string[];
}

export interface SchemaValidator {
// tslint:disable-next-line:no-any
(data: any): Observable<SchemaValidatorResult>;
}

export interface SchemaFormatter {
readonly async: boolean;
// tslint:disable-next-line:no-any
validate(data: any): boolean | Observable<boolean>;
}

export interface SchemaFormat {
name: string;
formatter: SchemaFormatter;
}

export interface SchemaRegistry {
compile(schema: Object): Observable<SchemaValidator>;
addFormat(format: SchemaFormat): void;
}
Loading