Skip to content
Closed
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
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ workflows:
- test-large:
name: test-large-ivy
ivy: true
glob: "packages/angular_devkit/build_angular/test/browser/*_spec_large.ts"
glob: "packages/angular_devkit/@(build_angular|build_ng_packagr)/@(src|test)/@(build|browser)/*_spec_large.ts"
requires:
- build
- e2e-cli:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,9 @@ describe('Browser Builder Web Worker support', () => {
"outDir": "../out-tsc/worker",
"types": []
},
"exclude": [
"test.ts",
"**/*.spec.ts",
"**/*.worker.ts",
"app/dep.ts",
"files": [
"main.ts",
"polyfills.ts"
]
}`,
};
Expand Down
2 changes: 1 addition & 1 deletion packages/angular_devkit/build_ng_packagr/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"@angular/compiler": "~8.2.0-rc.0",
"@angular/compiler-cli": "~8.2.0-rc.0",
"@angular-devkit/core": "0.0.0",
"ng-packagr": "^5.3.0",
"ng-packagr": "^5.4.0",
"tslib": "^1.10.0"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,25 @@ import { Architect } from '@angular-devkit/architect';
import { WorkspaceNodeModulesArchitectHost } from '@angular-devkit/architect/node';
import { TestProjectHost, TestingArchitectHost } from '@angular-devkit/architect/testing';
import {
experimental,
getSystemPath,
join,
normalize,
schema,
virtualFs,
workspaces,
} from '@angular-devkit/core'; // tslint:disable-line:no-implicit-dependencies
import { map, take, tap } from 'rxjs/operators';

export const ivyEnabled = process.argv.includes('--ivy');
if (ivyEnabled) {
// tslint:disable-next-line:no-console
console.warn('********* IVY Enabled ***********');
}

const devkitRoot = (global as unknown as { _DevKitRoot: string})._DevKitRoot;
const workspaceRoot = join(
normalize(devkitRoot),
'tests/angular_devkit/build_ng_packagr/ng-packaged/',
`tests/angular_devkit/build_ng_packagr/ng-packaged${ivyEnabled ? '-ivy' : ''}/`,
);

describe('NgPackagr Builder', () => {
Expand All @@ -33,15 +40,14 @@ describe('NgPackagr Builder', () => {
const registry = new schema.CoreSchemaRegistry();
registry.addPostTransform(schema.transforms.addUndefinedDefaults);

const { workspace } = await workspaces.readWorkspace(
host.root(),
workspaces.createWorkspaceHost(host),
);
const workspaceSysPath = getSystemPath(host.root());
const workspace = await experimental.workspace.Workspace.fromPath(host, host.root(), registry);
const architectHost = new TestingArchitectHost(
host.root(),
host.root(),
new WorkspaceNodeModulesArchitectHost(workspace, host.root()),
workspaceSysPath,
workspaceSysPath,
new WorkspaceNodeModulesArchitectHost(workspace, workspaceSysPath),
);

architect = new Architect(architectHost, registry);
});

Expand All @@ -59,6 +65,12 @@ describe('NgPackagr Builder', () => {
host.scopedSync().read(normalize('./dist/lib/fesm5/lib.js')),
);
expect(content).toContain('lib works');

if (ivyEnabled) {
expect(content).toContain('ngComponentDef');
} else {
expect(content).not.toContain('ngComponentDef');
}
});

it('rebuilds on TS file changes', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,5 @@
]<% } %><% if (enableIvy) { %>
"include": [
"src/**/*.d.ts"
],
"angularCompilerOptions": {
"enableIvy": true
}<% } %>
]<% } %>
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,5 @@
"include": [
"src/**/*.spec.ts",
"src/**/*.d.ts"
]<% if (enableIvy) { %>,
"angularCompilerOptions": {
"enableIvy": true
}<% } %>
]
}
11 changes: 7 additions & 4 deletions packages/schematics/angular/application/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import { latestVersions } from '../utility/latest-versions';
import { applyLintFix } from '../utility/lint-fix';
import { relativePathToWorkspaceRoot } from '../utility/paths';
import { validateProjectName } from '../utility/validation';
import { getWorkspace, updateWorkspace } from '../utility/workspace';
import { getWorkspace, isIvyWorkspace, updateWorkspace } from '../utility/workspace';
import { Builders, ProjectType } from '../utility/workspace-models';
import { Schema as ApplicationOptions, Style } from './schema';

Expand Down Expand Up @@ -143,7 +143,7 @@ function mergeWithRootTsLint(parentHost: Tree) {
};
}

function addAppToWorkspaceFile(options: ApplicationOptions, appDir: string): Rule {
function addAppToWorkspaceFile(options: ApplicationOptions, appDir: string, enableIvy: boolean): Rule {
let projectRoot = appDir;
if (projectRoot) {
projectRoot += '/';
Expand Down Expand Up @@ -194,7 +194,7 @@ function addAppToWorkspaceFile(options: ApplicationOptions, appDir: string): Rul
main: `${sourceRoot}/main.ts`,
polyfills: `${sourceRoot}/polyfills.ts`,
tsConfig: `${projectRoot}tsconfig.app.json`,
aot: !!options.enableIvy,
aot: enableIvy,
assets: [
`${sourceRoot}/favicon.ico`,
`${sourceRoot}/assets`,
Expand Down Expand Up @@ -336,14 +336,17 @@ export default function (options: ApplicationOptions): Rule {
rootSelector: appRootSelector,
};

const enableIvy = isIvyWorkspace(host);

return chain([
addAppToWorkspaceFile(options, appDir),
addAppToWorkspaceFile(options, appDir, enableIvy),
mergeWith(
apply(url('./files'), [
options.minimal ? filter(minimalPathFilter) : noop(),
applyTemplates({
utils: strings,
...options,
enableIvy,
relativePathToWorkspaceRoot: relativePathToWorkspaceRoot(appDir),
appName: options.name,
isRootApp,
Expand Down
48 changes: 27 additions & 21 deletions packages/schematics/angular/application/index_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,15 +222,6 @@ describe('Application Schematic', () => {
expect(workspace.projects.foo.architect.build.options.aot).toEqual(false);
});

it('should set AOT option to true for Ivy projects', async () => {
const options = { ...defaultOptions, enableIvy: true };

const tree = await schematicRunner.runSchematicAsync('application', options, workspaceTree)
.toPromise();
const workspace = JSON.parse(tree.readContent('/angular.json'));
expect(workspace.projects.foo.architect.build.options.aot).toEqual(true);
});

it('should set the right files, exclude, include in the tsconfig for VE projects', async () => {
const tree = await schematicRunner.runSchematicAsync('application', defaultOptions, workspaceTree)
.toPromise();
Expand All @@ -241,18 +232,7 @@ describe('Application Schematic', () => {
expect(tsConfig.include).toEqual(['src/**/*.ts']);
});

it('should set the right files, exclude, include in the tsconfig for Ivy projects', async () => {
const options = { ...defaultOptions, enableIvy: true };
const tree = await schematicRunner.runSchematicAsync('application', options, workspaceTree)
.toPromise();
const path = '/projects/foo/tsconfig.app.json';
const tsConfig = JSON.parse(tree.readContent(path));
expect(tsConfig.files).toEqual(['src/main.ts', 'src/polyfills.ts']);
expect(tsConfig.exclude).toBeUndefined();
expect(tsConfig.include).toEqual(['src/**/*.d.ts']);
});

describe(`update package.json`, () => {
describe('update package.json', () => {
it(`should add build-angular to devDependencies`, async () => {
const tree = await schematicRunner.runSchematicAsync('application', defaultOptions, workspaceTree)
.toPromise();
Expand Down Expand Up @@ -427,4 +407,30 @@ describe('Application Schematic', () => {
expect(specTsConfig.extends).toEqual('../tsconfig.json');
});
});

describe('IVY application', () => {
beforeEach(() => {
// Enable an Ivy workspace
const tsconfig = JSON.parse(workspaceTree.readContent('./tsconfig.json'));
tsconfig.angularCompilerOptions.enableIvy = true;
workspaceTree.overwrite('./tsconfig.json', JSON.stringify(tsconfig, undefined, 2));
});

it('should set the right files, exclude, include in the tsconfig for Ivy projects', async () => {
const tree = await schematicRunner.runSchematicAsync('application', defaultOptions, workspaceTree)
.toPromise();
const path = '/projects/foo/tsconfig.app.json';
const tsConfig = JSON.parse(tree.readContent(path));
expect(tsConfig.files).toEqual(['src/main.ts', 'src/polyfills.ts']);
expect(tsConfig.exclude).toBeUndefined();
expect(tsConfig.include).toEqual(['src/**/*.d.ts']);
});

it('should set AOT option to true for Ivy projects', async () => {
const tree = await schematicRunner.runSchematicAsync('application', defaultOptions, workspaceTree)
.toPromise();
const workspace = JSON.parse(tree.readContent('/angular.json'));
expect(workspace.projects.foo.architect.build.options.aot).toEqual(true);
});
});
});
6 changes: 0 additions & 6 deletions packages/schematics/angular/application/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@
},
"x-prompt": "What name would you like to use for the application?"
},
"enableIvy": {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Since this is experimental, I don't think we need to deprecate.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah I think that's ok.

Copy link
Member

Choose a reason for hiding this comment

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

Don't we still need this option? The migration won't run until 9 so the option won't be at the root tsconfig yet.

"description": "**EXPERIMENTAL** True to create a new app that uses the Ivy rendering engine.",
"type": "boolean",
"default": false,
"x-user-analytics": 8
},
"inlineStyle": {
"description": "When true, includes styles inline in the root component.ts file. Only CSS styles can be included inline. Default is false, meaning that an external styles file is created and referenced in the root component.ts file.",
"type": "boolean",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@
]
},
"angularCompilerOptions": {
"annotateForClosureCompiler": true,
"annotateForClosureCompiler": true<% if (!enableIvy) { %>,
"skipTemplateCodegen": true,
"strictMetadataEmit": true,
"fullTemplateTypeCheck": true,
"strictInjectionParameters": true,
"enableResourceInlining": true
"enableResourceInlining": true<% } %>
},
"exclude": [
"src/test.ts",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "./tsconfig.lib.json",
"angularCompilerOptions": {
"skipTemplateCodegen": true,
"strictMetadataEmit": true,
"enableResourceInlining": true,
"enableIvy": false
}
}
17 changes: 13 additions & 4 deletions packages/schematics/angular/library/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
apply,
applyTemplates,
chain,
filter,
mergeWith,
move,
noop,
Expand All @@ -26,7 +27,7 @@ import { latestVersions } from '../utility/latest-versions';
import { applyLintFix } from '../utility/lint-fix';
import { relativePathToWorkspaceRoot } from '../utility/paths';
import { validateProjectName } from '../utility/validation';
import { getWorkspace, updateWorkspace } from '../utility/workspace';
import { getWorkspace, isIvyWorkspace, updateWorkspace } from '../utility/workspace';
import { Builders, ProjectType } from '../utility/workspace-models';
import { Schema as LibraryOptions } from './schema';

Expand Down Expand Up @@ -124,10 +125,11 @@ function addDependenciesToPackageJson() {
};
}

function addAppToWorkspaceFile(
function addLibToWorkspaceFile(
options: LibraryOptions,
projectRoot: string,
projectName: string,
enableIvy: boolean,
): Rule {
return updateWorkspace(workspace => {
if (workspace.projects.size === 0) {
Expand All @@ -147,6 +149,11 @@ function addAppToWorkspaceFile(
tsConfig: `${projectRoot}/tsconfig.lib.json`,
project: `${projectRoot}/ng-package.json`,
},
configurations: enableIvy ? {
production: {
tsConfig: `${projectRoot}/tsconfig.lib.prod.json`,
},
} : undefined,
},
test: {
builder: Builders.Karma,
Expand Down Expand Up @@ -199,16 +206,18 @@ export default function (options: LibraryOptions): Rule {
const folderName = `${scopeFolder}${strings.dasherize(options.name)}`;
const projectRoot = join(normalize(newProjectRoot), folderName);
const distRoot = `dist/${folderName}`;

const sourceDir = `${projectRoot}/src/lib`;
const enableIvy = isIvyWorkspace(host);

const templateSource = apply(url('./files'), [
enableIvy ? noop() : filter(f => !f.endsWith('tsconfig.lib.prod.json.template')),
applyTemplates({
...strings,
...options,
packageName,
projectRoot,
distRoot,
enableIvy,
relativePathToWorkspaceRoot: relativePathToWorkspaceRoot(projectRoot),
prefix,
angularLatestVersion: latestVersions.Angular.replace('~', '').replace('^', ''),
Expand All @@ -219,7 +228,7 @@ export default function (options: LibraryOptions): Rule {

return chain([
mergeWith(templateSource),
addAppToWorkspaceFile(options, projectRoot, projectName),
addLibToWorkspaceFile(options, projectRoot, projectName, enableIvy),
options.skipPackageJson ? noop() : addDependenciesToPackageJson(),
options.skipTsConfig ? noop() : updateTsConfig(packageName, distRoot),
schematic('module', {
Expand Down
Loading