Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
315e91f
test: ignore the generated `demo` folder in the `bazel` integration test
petebacondarwin Mar 20, 2019
8954205
build: allow build-packages-dist.sh to be run from anywhere
petebacondarwin Mar 20, 2019
8332b90
style(ivy): ngcc - fix typo in comment
petebacondarwin Mar 20, 2019
0452116
feat(ivy): ngcc - support dts compilation via ES5 bundles
petebacondarwin Mar 20, 2019
4cc15da
refactor(ivy): move ngcc into a higher level folder
petebacondarwin Mar 20, 2019
e0d8ce1
refactor(ivy): expose ngcc programmatically
petebacondarwin Mar 20, 2019
a55c2b8
feat(ivy): ngcc - support targeting a start entry-point
petebacondarwin Mar 20, 2019
dd6b428
feat(ivy): ngcc - compile only specified package.json format properties
petebacondarwin Mar 20, 2019
5124838
refactor(ivy): ngcc - remove flat-format and use AbsoluteFsPath
petebacondarwin Mar 20, 2019
7884252
refactor(ivy): ngcc - simplify `Transformer.transform` API
petebacondarwin Mar 20, 2019
8951b19
feat(ivy): ngcc - support only compiling the first format property to…
petebacondarwin Mar 20, 2019
149b592
build(ivy): ngcc - only test under `no-ivy-aot` mode
petebacondarwin Mar 20, 2019
e88356f
fix(ivy): ngcc - empower `Esm5ReflectionHost` to analyze `ModuleWithP…
petebacondarwin Mar 20, 2019
e96eef6
fix(ivy): ngcc - teach Esm5ReflectionHost about aliased variables
petebacondarwin Mar 20, 2019
f0f901a
refactor(ivy): ngcc - use a fixed set of properties to compile if non…
petebacondarwin Mar 20, 2019
8bb1515
refactor(ivy): ngcc - clean up the public API and export `hasBeenProc…
petebacondarwin Mar 20, 2019
9b786f3
fix(ivy): ngcc - fail build-marker check if any formats were compiled…
petebacondarwin Mar 20, 2019
2fba449
refactor(ivy): ngcc - mark target entry-point as processed even if ng…
petebacondarwin Mar 20, 2019
6b555b4
refactor(ivy): ngcc - extract file writing out into a class
petebacondarwin Mar 20, 2019
745d980
feat(ivy): ngcc - support creating a new copy of the entry-point format
petebacondarwin Mar 20, 2019
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
2 changes: 1 addition & 1 deletion aio/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"build": "yarn ~~build",
"prebuild-local": "yarn setup-local",
"build-local": "yarn ~~build",
"prebuild-with-ivy": "yarn setup-local && yarn ivy-ngcc --formats fesm2015 fesm5",
"prebuild-with-ivy": "yarn setup-local && yarn ivy-ngcc --properties module es2015",
"build-with-ivy": "node scripts/build-with-ivy",
"extract-cli-command-docs": "node tools/transforms/cli-docs-package/extract-cli-commands.js cafa558cf",
"lint": "yarn check-env && yarn docs-lint && ng lint && yarn example-lint && yarn tools-lint",
Expand Down
124 changes: 39 additions & 85 deletions aio/tools/examples/example-boilerplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,80 +12,36 @@ const EXAMPLES_BASE_PATH = path.resolve(__dirname, '../../content/examples');

const BOILERPLATE_PATHS = {
cli: [
'src/environments/environment.prod.ts',
'src/environments/environment.ts',
'src/assets/.gitkeep',
'src/browserslist',
'src/favicon.ico',
'src/karma.conf.js',
'src/polyfills.ts',
'src/test.ts',
'src/tsconfig.app.json',
'src/tsconfig.spec.json',
'src/tslint.json',
'e2e/src/app.po.ts',
'e2e/protractor.conf.js',
'e2e/tsconfig.e2e.json',
'.editorconfig',
'angular.json',
'package.json',
'tsconfig.json',
'tslint.json'
'src/environments/environment.prod.ts', 'src/environments/environment.ts',
'src/assets/.gitkeep', 'src/browserslist', 'src/favicon.ico', 'src/karma.conf.js',
'src/polyfills.ts', 'src/test.ts', 'src/tsconfig.app.json', 'src/tsconfig.spec.json',
'src/tslint.json', 'e2e/src/app.po.ts', 'e2e/protractor.conf.js', 'e2e/tsconfig.e2e.json',
'.editorconfig', 'angular.json', 'package.json', 'tsconfig.json', 'tslint.json'
Comment thread
petebacondarwin marked this conversation as resolved.
Resolved
],
systemjs: [
'src/systemjs-angular-loader.js',
'src/systemjs.config.js',
'src/tsconfig.json',
'bs-config.json',
'bs-config.e2e.json',
'package.json',
'tslint.json'
'src/systemjs-angular-loader.js', 'src/systemjs.config.js', 'src/tsconfig.json',
'bs-config.json', 'bs-config.e2e.json', 'package.json', 'tslint.json'
],
common: [
'src/styles.css'
]
common: ['src/styles.css']
};

// All paths in this tool are relative to the current boilerplate folder, i.e boilerplate/i18n
// This maps the CLI files that exists in a parent folder
const cliRelativePath = BOILERPLATE_PATHS.cli.map(file => `../cli/${file}`);

BOILERPLATE_PATHS.elements = [
...cliRelativePath,
'tsconfig.json'
];
BOILERPLATE_PATHS.elements = [...cliRelativePath, 'tsconfig.json'];

BOILERPLATE_PATHS.i18n = [
...cliRelativePath,
'angular.json',
'package.json'
];
BOILERPLATE_PATHS.i18n = [...cliRelativePath, 'angular.json', 'package.json'];

BOILERPLATE_PATHS['service-worker'] = [
...cliRelativePath,
'angular.json',
'package.json'
];
BOILERPLATE_PATHS['service-worker'] = [...cliRelativePath, 'angular.json', 'package.json'];

BOILERPLATE_PATHS.testing = [
...cliRelativePath,
'angular.json'
];
BOILERPLATE_PATHS.testing = [...cliRelativePath, 'angular.json'];

BOILERPLATE_PATHS.universal = [
...cliRelativePath,
'angular.json',
'package.json'
];
BOILERPLATE_PATHS.universal = [...cliRelativePath, 'angular.json', 'package.json'];

BOILERPLATE_PATHS.ivy = {
systemjs: [
'rollup-config.js',
'tsconfig-aot.json'
],
cli: [
'src/tsconfig.app.json'
]
systemjs: ['rollup-config.js', 'tsconfig-aot.json'],
cli: ['src/tsconfig.app.json']
};

BOILERPLATE_PATHS.schematics = [
Expand All @@ -101,20 +57,19 @@ class ExampleBoilerPlate {
*/
add(ivy = false) {
// Get all the examples folders, indicated by those that contain a `example-config.json` file
const exampleFolders = this.getFoldersContaining(EXAMPLES_BASE_PATH, EXAMPLE_CONFIG_FILENAME, 'node_modules');
const exampleFolders =
this.getFoldersContaining(EXAMPLES_BASE_PATH, EXAMPLE_CONFIG_FILENAME, 'node_modules');

if (!fs.existsSync(SHARED_NODE_MODULES_PATH)) {
throw new Error(`The shared node_modules folder for the examples (${SHARED_NODE_MODULES_PATH}) is missing.\n` +
`Perhaps you need to run "yarn example-use-npm" or "yarn example-use-local" to install the dependencies?`);
throw new Error(
`The shared node_modules folder for the examples (${SHARED_NODE_MODULES_PATH}) is missing.\n` +
`Perhaps you need to run "yarn example-use-npm" or "yarn example-use-local" to install the dependencies?`);
}

if (ivy) {
// We only need the "fesm5" bundles as the CLI webpack build does not need
// any other formats for building and serving. Ngcc currently only updates
// the module typings if we specified an "es2015" format. This means that
// we also need to build with "fesm2015" in order to get updated typings
// which are needed for compilation.
shelljs.exec(`yarn --cwd ${SHARED_PATH} ivy-ngcc --formats fesm2015 fesm5`);
// any other formats for building and serving.
shelljs.exec(`yarn --cwd ${SHARED_PATH} ivy-ngcc --properties module`);
}

exampleFolders.forEach(exampleFolder => {
Expand All @@ -128,40 +83,41 @@ class ExampleBoilerPlate {
const boilerPlateBasePath = path.resolve(BOILERPLATE_BASE_PATH, boilerPlateType);

// Copy the boilerplate specific files
BOILERPLATE_PATHS[boilerPlateType].forEach(filePath => this.copyFile(boilerPlateBasePath, exampleFolder, filePath));
BOILERPLATE_PATHS[boilerPlateType].forEach(
filePath => this.copyFile(boilerPlateBasePath, exampleFolder, filePath));

// Copy the boilerplate common files
BOILERPLATE_PATHS.common.forEach(filePath => this.copyFile(BOILERPLATE_COMMON_BASE_PATH, exampleFolder, filePath));
BOILERPLATE_PATHS.common.forEach(
filePath => this.copyFile(BOILERPLATE_COMMON_BASE_PATH, exampleFolder, filePath));

// Copy Ivy specific files
if (ivy) {
const ivyBoilerPlateType = boilerPlateType === 'systemjs' ? 'systemjs' : 'cli';
const ivyBoilerPlateBasePath = path.resolve(BOILERPLATE_BASE_PATH, 'ivy', ivyBoilerPlateType);
BOILERPLATE_PATHS.ivy[ivyBoilerPlateType].forEach(filePath => this.copyFile(ivyBoilerPlateBasePath, exampleFolder, filePath));
const ivyBoilerPlateBasePath =
path.resolve(BOILERPLATE_BASE_PATH, 'ivy', ivyBoilerPlateType);
BOILERPLATE_PATHS.ivy[ivyBoilerPlateType].forEach(
filePath => this.copyFile(ivyBoilerPlateBasePath, exampleFolder, filePath));
}
});
}

/**
* Remove all the boilerplate files from all the examples
*/
remove() {
shelljs.exec('git clean -xdfq', { cwd: EXAMPLES_BASE_PATH });
}
remove() { shelljs.exec('git clean -xdfq', {cwd: EXAMPLES_BASE_PATH}); }

main() {
yargs
.usage('$0 <cmd> [args]')
.command('add', 'add the boilerplate to each example', (yrgs) => this.add(yrgs.argv.ivy))
.command('remove', 'remove the boilerplate from each example', () => this.remove())
.demandCommand(1, 'Please supply a command from the list above')
.argv;
yargs.usage('$0 <cmd> [args]')
.command('add', 'add the boilerplate to each example', (yrgs) => this.add(yrgs.argv.ivy))
.command('remove', 'remove the boilerplate from each example', () => this.remove())
.demandCommand(1, 'Please supply a command from the list above')
.argv;
}

getFoldersContaining(basePath, filename, ignore) {
const pattern = path.resolve(basePath, '**', filename);
const ignorePattern = path.resolve(basePath, '**', ignore, '**');
return glob.sync(pattern, { ignore: [ignorePattern] }).map(file => path.dirname(file));
return glob.sync(pattern, {ignore: [ignorePattern]}).map(file => path.dirname(file));
}

copyFile(sourceFolder, destinationFolder, filePath) {
Expand All @@ -171,13 +127,11 @@ class ExampleBoilerPlate {
filePath = this.normalizePath(filePath);

const destinationPath = path.resolve(destinationFolder, filePath);
fs.copySync(sourcePath, destinationPath, { overwrite: true });
fs.copySync(sourcePath, destinationPath, {overwrite: true});
fs.chmodSync(destinationPath, 444);
}

loadJsonFile(filePath) {
return fs.readJsonSync(filePath, { throws: false }) || {};
}
loadJsonFile(filePath) { return fs.readJsonSync(filePath, {throws: false}) || {}; }

normalizePath(filePath) {
// transform for example ../cli/src/tsconfig.app.json to src/tsconfig.app.json
Expand Down
1 change: 1 addition & 0 deletions integration/bazel-schematics/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/demo
23 changes: 20 additions & 3 deletions integration/ngcc/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,25 @@ ivy-ngcc --help
ivy-ngcc

# Did it add the appropriate build markers?

# - esm2015
grep '"__processed_by_ivy_ngcc__":[^}]*"esm2015":"' node_modules/@angular/common/package.json
if [[ $? != 0 ]]; then exit 1; fi

# - fesm2015
ls node_modules/@angular/common | grep __modified_by_ngcc_for_fesm2015
grep '"__processed_by_ivy_ngcc__":[^}]*"fesm2015":"' node_modules/@angular/common/package.json
if [[ $? != 0 ]]; then exit 1; fi
# - esm2015
ls node_modules/@angular/common | grep __modified_by_ngcc_for_esm2015
grep '"__processed_by_ivy_ngcc__":[^}]*"es2015":"' node_modules/@angular/common/package.json
if [[ $? != 0 ]]; then exit 1; fi

# - esm5
grep '"__processed_by_ivy_ngcc__":[^}]*"esm5":"' node_modules/@angular/common/package.json
if [[ $? != 0 ]]; then exit 1; fi

# - fesm5
grep '"__processed_by_ivy_ngcc__":[^}]*"module":"' node_modules/@angular/common/package.json
if [[ $? != 0 ]]; then exit 1; fi
grep '"__processed_by_ivy_ngcc__":[^}]*"fesm5":"' node_modules/@angular/common/package.json
if [[ $? != 0 ]]; then exit 1; fi

# Did it replace the PRE_R3 markers correctly?
Expand Down Expand Up @@ -48,6 +62,9 @@ ivy-ngcc
# Can it be safely run again (as a noop)?
ivy-ngcc

# Does running it with --formats fail?
ivy-ngcc --formats fesm2015 && exit 1

# Now try compiling the app using the ngcc compiled libraries
ngc -p tsconfig-app.json

Expand Down
2 changes: 1 addition & 1 deletion packages/common/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ ng_package(
visibility = [
"//packages/bazel/test/ng_package:__pkg__",
"//packages/compiler-cli/integrationtest:__pkg__",
"//packages/compiler-cli/ngcc/test:__pkg__",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to merge this commit into the previous. Can you mark it as a fixup! commit instead of its own separate thing?

This way it'll rebase separately, but when we actually merge the PR the commits will be combined. Otherwise, we'll have a commit in the repo at which the build will be broken (after the move, but before BUILD file updates, etc).

"//packages/compiler-cli/test:__pkg__",
"//packages/compiler-cli/test/diagnostics:__pkg__",
"//packages/compiler-cli/test/ngcc:__pkg__",
Comment thread
petebacondarwin marked this conversation as resolved.
Resolved
"//packages/compiler-cli/test/transformers:__pkg__",
"//packages/compiler/test:__pkg__",
"//packages/language-service/test:__pkg__",
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler-cli/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,6 @@ npm_package(
],
deps = [
":compiler-cli",
"//packages/compiler-cli/src/ngcc",
Comment thread
petebacondarwin marked this conversation as resolved.
Resolved
"//packages/compiler-cli/ngcc",
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@ This conversion will allow such "legacy" packages to be used by the Ivy renderin
The project is built using Bazel:

```bash
yarn bazel build //packages/compiler-cli/src/ngcc
yarn bazel build //packages/compiler-cli/ngcc
```

## Unit Testing

The unit tests are built and run using Bazel:

```bash
yarn bazel test //packages/compiler-cli/src/ngcc/test
yarn bazel test //packages/compiler-cli/ngcc/test
```

## Integration Testing

There are tests that check the behavior of the overall executable:

```bash
yarn bazel test //packages/compiler-cli/test/ngcc
yarn bazel test //packages/compiler-cli/ngcc/test:integration
```
17 changes: 17 additions & 0 deletions packages/compiler-cli/ngcc/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* @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 {hasBeenProcessed as _hasBeenProcessed} from './src/packages/build_marker';
import {EntryPointJsonProperty, EntryPointPackageJson} from './src/packages/entry_point';
Comment thread
petebacondarwin marked this conversation as resolved.
Resolved

export {NgccOptions, mainNgcc as process} from './src/main';

export function hasBeenProcessed(packageJson: object, format: string) {
// We are wrapping this function to hide the internal types.
return _hasBeenProcessed(packageJson as EntryPointPackageJson, format as EntryPointJsonProperty);
}
65 changes: 65 additions & 0 deletions packages/compiler-cli/ngcc/main-ngcc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/usr/bin/env node
/**
* @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 * as path from 'canonical-path';
import * as yargs from 'yargs';

import {mainNgcc} from './src/main';

// CLI entry point
if (require.main === module) {
const args = process.argv.slice(2);
const options =
yargs
.option('s', {
alias: 'source',
describe:
'A path (relative to the working directory) of the `node_modules` folder to process.',
default: './node_modules'
})
.option('f', {alias: 'formats', hidden: true, array: true})
.option('p', {
alias: 'properties',
array: true,
describe:
'An array of names of properties in package.json to compile (e.g. `module` or `es2015`)\n' +
'Each of these properties should hold the path to a bundle-format.\n' +
'If provided, only the specified properties are considered for processing.\n' +
'If not provided, all the supported format properties (e.g. fesm2015, fesm5, es2015, esm2015, esm5, main, module) in the package.json are considered.'
})
.option('t', {
alias: 'target',
describe:
'A relative path (from the `source` path) to a single entry-point to process (plus its dependencies).',
})
.option('first-only', {
describe:
'If specified then only the first matching package.json property will be compiled',
type: 'boolean'
})
.help()
.parse(args);

if (options['f'] && options['f'].length) {
console.error(
'The formats option (-f/--formats) has been removed. Consider the properties option (-p/--properties) instead.');
process.exit(1);
}
const baseSourcePath = path.resolve(options['s'] || './node_modules');
const propertiesToConsider: string[] = options['p'];
const targetEntryPointPath = options['t'] ? options['t'] : undefined;
const compileAllFormats = !options['first-only'];
try {
mainNgcc(
{basePath: baseSourcePath, propertiesToConsider, targetEntryPointPath, compileAllFormats});
process.exitCode = 0;
} catch (e) {
console.error(e.stack || e.message);
process.exitCode = 1;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import * as path from 'canonical-path';
import * as fs from 'fs';
import * as ts from 'typescript';

import {BaseDefDecoratorHandler, ComponentDecoratorHandler, DirectiveDecoratorHandler, InjectableDecoratorHandler, NgModuleDecoratorHandler, PipeDecoratorHandler, ReferencesRegistry, ResourceLoader} from '../../../ngtsc/annotations';
import {CycleAnalyzer, ImportGraph} from '../../../ngtsc/cycles';
import {AbsoluteModuleStrategy, LocalIdentifierStrategy, LogicalProjectStrategy, ModuleResolver, NOOP_DEFAULT_IMPORT_RECORDER, ReferenceEmitter} from '../../../ngtsc/imports';
import {PartialEvaluator} from '../../../ngtsc/partial_evaluator';
import {AbsoluteFsPath, LogicalFileSystem} from '../../../ngtsc/path';
import {LocalModuleScopeRegistry, MetadataDtsModuleScopeResolver} from '../../../ngtsc/scope';
import {CompileResult, DecoratorHandler, DetectResult, HandlerPrecedence} from '../../../ngtsc/transform';
import {BaseDefDecoratorHandler, ComponentDecoratorHandler, DirectiveDecoratorHandler, InjectableDecoratorHandler, NgModuleDecoratorHandler, PipeDecoratorHandler, ReferencesRegistry, ResourceLoader} from '../../../src/ngtsc/annotations';
import {CycleAnalyzer, ImportGraph} from '../../../src/ngtsc/cycles';
import {AbsoluteModuleStrategy, LocalIdentifierStrategy, LogicalProjectStrategy, ModuleResolver, NOOP_DEFAULT_IMPORT_RECORDER, ReferenceEmitter} from '../../../src/ngtsc/imports';
import {PartialEvaluator} from '../../../src/ngtsc/partial_evaluator';
import {AbsoluteFsPath, LogicalFileSystem} from '../../../src/ngtsc/path';
import {LocalModuleScopeRegistry, MetadataDtsModuleScopeResolver} from '../../../src/ngtsc/scope';
import {CompileResult, DecoratorHandler, DetectResult, HandlerPrecedence} from '../../../src/ngtsc/transform';
import {DecoratedClass} from '../host/decorated_class';
import {NgccReflectionHost} from '../host/ngcc_host';
import {isDefined} from '../utils';
Expand Down
Loading