fix(nx): make distribution ivy-friendly

This commit is contained in:
Victor Savkin 2019-05-20 17:11:41 -04:00
parent a5351c9d36
commit f007ca9d17
24 changed files with 106 additions and 64 deletions

View File

@ -60,9 +60,7 @@ describe('app', () => {
const tsconfigApp = JSON.parse( const tsconfigApp = JSON.parse(
stripJsonComments(getFileContent(tree, 'apps/my-app/tsconfig.app.json')) stripJsonComments(getFileContent(tree, 'apps/my-app/tsconfig.app.json'))
); );
expect(tsconfigApp.compilerOptions.outDir).toEqual( expect(tsconfigApp.compilerOptions.outDir).toEqual('../../dist/out-tsc');
'../../dist/out-tsc/apps/my-app'
);
expect(tsconfigApp.extends).toEqual('./tsconfig.json'); expect(tsconfigApp.extends).toEqual('./tsconfig.json');
const tslintJson = JSON.parse( const tslintJson = JSON.parse(
@ -76,9 +74,6 @@ describe('app', () => {
getFileContent(tree, 'apps/my-app-e2e/tsconfig.e2e.json') getFileContent(tree, 'apps/my-app-e2e/tsconfig.e2e.json')
) )
); );
// expect(tsconfigE2E.compilerOptions.outDir).toEqual(
// '../../dist/out-tsc/apps/my-app-e2e'
// );
expect(tsconfigE2E.extends).toEqual('./tsconfig.json'); expect(tsconfigE2E.extends).toEqual('./tsconfig.json');
}); });
@ -206,7 +201,7 @@ describe('app', () => {
{ {
path: 'apps/my-dir/my-app/tsconfig.app.json', path: 'apps/my-dir/my-app/tsconfig.app.json',
lookupFn: json => json.compilerOptions.outDir, lookupFn: json => json.compilerOptions.outDir,
expectedValue: '../../../dist/out-tsc/apps/my-dir/my-app' expectedValue: '../../../dist/out-tsc'
}, },
{ {
path: 'apps/my-dir/my-app-e2e/tsconfig.json', path: 'apps/my-dir/my-app-e2e/tsconfig.json',
@ -335,7 +330,7 @@ describe('app', () => {
); );
expect(tsconfigAppJson.exclude).toEqual(['src/test.ts', '**/*.spec.ts']); expect(tsconfigAppJson.exclude).toEqual(['src/test.ts', '**/*.spec.ts']);
expect(tsconfigAppJson.compilerOptions.outDir).toEqual( expect(tsconfigAppJson.compilerOptions.outDir).toEqual(
'../../dist/out-tsc/apps/my-app' '../../dist/out-tsc'
); );
}); });
}); });

View File

@ -229,9 +229,7 @@ function updateProject(options: NormalizedSchema): Rule {
extends: `./tsconfig.json`, extends: `./tsconfig.json`,
compilerOptions: { compilerOptions: {
...json.compilerOptions, ...json.compilerOptions,
outDir: `${offsetFromRoot(options.appProjectRoot)}dist/out-tsc/${ outDir: `${offsetFromRoot(options.appProjectRoot)}dist/out-tsc`
options.appProjectRoot
}`
}, },
exclude: exclude:
options.unitTestRunner === 'jest' options.unitTestRunner === 'jest'
@ -307,9 +305,7 @@ function updateE2eProject(options: NormalizedSchema): Rule {
extends: `./tsconfig.json`, extends: `./tsconfig.json`,
compilerOptions: { compilerOptions: {
...json.compilerOptions, ...json.compilerOptions,
outDir: `${offsetFromRoot(options.e2eProjectRoot)}dist/out-tsc/${ outDir: `${offsetFromRoot(options.e2eProjectRoot)}dist/out-tsc`
options.e2eProjectRoot
}`
} }
}; };
}) })
@ -345,6 +341,7 @@ export default function(schema: Schema): Rule {
skipTests: options.skipTests, skipTests: options.skipTests,
style: options.style, style: options.style,
viewEncapsulation: options.viewEncapsulation, viewEncapsulation: options.viewEncapsulation,
enableIvy: options.enableIvy,
routing: false, routing: false,
skipInstall: true, skipInstall: true,
skipPackageJson: false skipPackageJson: false

View File

@ -8,6 +8,7 @@ export interface Schema {
inlineTemplate?: boolean; inlineTemplate?: boolean;
viewEncapsulation?: 'Emulated' | 'Native' | 'None'; viewEncapsulation?: 'Emulated' | 'Native' | 'None';
routing?: boolean; routing?: boolean;
enableIvy?: boolean;
prefix?: string; prefix?: string;
style?: string; style?: string;
skipTests?: boolean; skipTests?: boolean;

View File

@ -40,6 +40,11 @@
"description": "Generates a routing module.", "description": "Generates a routing module.",
"default": false "default": false
}, },
"enablyIvy": {
"description": "**EXPERIMENTAL** True to create a new app that uses the Ivy rendering engine.",
"type": "boolean",
"default": false
},
"prefix": { "prefix": {
"type": "string", "type": "string",
"format": "html-selector", "format": "html-selector",

View File

@ -1,7 +1,7 @@
{ {
"extends": "./tsconfig.json", "extends": "./tsconfig.json",
"compilerOptions": { "compilerOptions": {
"outDir": "<%= offsetFromRoot %>dist/out-tsc/<%= projectRoot %>", "outDir": "<%= offsetFromRoot %>dist/out-tsc",
"types": ["jasmine", "node"] "types": ["jasmine", "node"]
}, },
"files": ["src/test.ts"], "files": ["src/test.ts"],

View File

@ -118,7 +118,7 @@ module.exports = function(config) {
expect(tsConfig).toEqual({ expect(tsConfig).toEqual({
extends: './tsconfig.json', extends: './tsconfig.json',
compilerOptions: { compilerOptions: {
outDir: '../../dist/out-tsc/libs/lib1', outDir: '../../dist/out-tsc',
types: ['jasmine', 'node'] types: ['jasmine', 'node']
}, },
files: ['src/test.ts'], files: ['src/test.ts'],
@ -182,7 +182,7 @@ module.exports = function(config) {
expect(tsConfig).toEqual({ expect(tsConfig).toEqual({
extends: './tsconfig.json', extends: './tsconfig.json',
compilerOptions: { compilerOptions: {
outDir: '../../dist/out-tsc/apps/app1', outDir: '../../dist/out-tsc',
types: ['jasmine', 'node'] types: ['jasmine', 'node']
}, },
files: ['src/test.ts', 'src/polyfills.ts'], files: ['src/test.ts', 'src/polyfills.ts'],

View File

@ -345,9 +345,7 @@ function updateProject(options: NormalizedSchema): Rule {
extends: `./tsconfig.json`, extends: `./tsconfig.json`,
compilerOptions: { compilerOptions: {
...json.compilerOptions, ...json.compilerOptions,
outDir: `${offsetFromRoot(options.projectRoot)}dist/out-tsc/${ outDir: `${offsetFromRoot(options.projectRoot)}dist/out-tsc`
options.projectRoot
}`
} }
}; };
}), }),

View File

@ -101,9 +101,7 @@ describe('schematic:cypress-project', () => {
); );
expect(tsconfigJson.extends).toEqual('./tsconfig.json'); expect(tsconfigJson.extends).toEqual('./tsconfig.json');
expect(tsconfigJson.compilerOptions.outDir).toEqual( expect(tsconfigJson.compilerOptions.outDir).toEqual('../../dist/out-tsc');
'../../dist/out-tsc/apps/my-app-e2e/src'
);
}); });
describe('nested', () => { describe('nested', () => {
@ -180,7 +178,7 @@ describe('schematic:cypress-project', () => {
); );
expect(tsconfigJson.compilerOptions.outDir).toEqual( expect(tsconfigJson.compilerOptions.outDir).toEqual(
'../../../dist/out-tsc/apps/my-dir/my-app-e2e/src' '../../../dist/out-tsc'
); );
}); });
}); });

View File

@ -2,7 +2,7 @@
"extends": "./tsconfig.json", "extends": "./tsconfig.json",
"compilerOptions": { "compilerOptions": {
"sourceMap": false, "sourceMap": false,
"outDir": "<%= offsetFromRoot %>dist/out-tsc/<%= projectRoot %>/src" "outDir": "<%= offsetFromRoot %>dist/out-tsc"
}, },
"include": ["src/**/*.ts"] "include": ["src/**/*.ts"]
} }

View File

@ -1,7 +1,7 @@
{ {
"extends": "./tsconfig.json", "extends": "./tsconfig.json",
"compilerOptions": { "compilerOptions": {
"outDir": "<%= offsetFromRoot %>dist/out-tsc/<%= projectRoot %>", "outDir": "<%= offsetFromRoot %>dist/out-tsc",
"module": "commonjs", "module": "commonjs",
"types": ["jest", "node"] "types": ["jest", "node"]
},<% if(setupFile !== 'none') { %> },<% if(setupFile !== 'none') { %>

View File

@ -123,7 +123,7 @@ describe('jestProject', () => {
extends: './tsconfig.json', extends: './tsconfig.json',
compilerOptions: { compilerOptions: {
module: 'commonjs', module: 'commonjs',
outDir: '../../dist/out-tsc/libs/lib1', outDir: '../../dist/out-tsc',
types: ['jest', 'node'] types: ['jest', 'node']
}, },
files: ['src/test-setup.ts'], files: ['src/test-setup.ts'],

View File

@ -87,9 +87,7 @@ describe('app', () => {
getFileContent(tree, 'apps/my-node-app/tsconfig.app.json') getFileContent(tree, 'apps/my-node-app/tsconfig.app.json')
) )
); );
expect(tsconfigApp.compilerOptions.outDir).toEqual( expect(tsconfigApp.compilerOptions.outDir).toEqual('../../dist/out-tsc');
'../../dist/out-tsc/apps/my-node-app'
);
expect(tsconfigApp.extends).toEqual('./tsconfig.json'); expect(tsconfigApp.extends).toEqual('./tsconfig.json');
const tslintJson = JSON.parse( const tslintJson = JSON.parse(
@ -162,7 +160,7 @@ describe('app', () => {
{ {
path: 'apps/my-dir/my-node-app/tsconfig.app.json', path: 'apps/my-dir/my-node-app/tsconfig.app.json',
lookupFn: json => json.compilerOptions.outDir, lookupFn: json => json.compilerOptions.outDir,
expectedValue: '../../../dist/out-tsc/apps/my-dir/my-node-app' expectedValue: '../../../dist/out-tsc'
}, },
{ {
path: 'apps/my-dir/my-node-app/tsconfig.app.json', path: 'apps/my-dir/my-node-app/tsconfig.app.json',

View File

@ -1,7 +1,7 @@
{ {
"extends": "./tsconfig.json", "extends": "./tsconfig.json",
"compilerOptions": { "compilerOptions": {
"outDir": "<%= offset %>dist/out-tsc/<%= root %>", "outDir": "<%= offset %>dist/out-tsc",
"types": ["node"] "types": ["node"]
}, },
"exclude": ["**/*.spec.ts"], "exclude": ["**/*.spec.ts"],

View File

@ -57,9 +57,7 @@ describe('app', () => {
const tsconfigApp = JSON.parse( const tsconfigApp = JSON.parse(
stripJsonComments(tree.readContent('apps/my-app/tsconfig.app.json')) stripJsonComments(tree.readContent('apps/my-app/tsconfig.app.json'))
); );
expect(tsconfigApp.compilerOptions.outDir).toEqual( expect(tsconfigApp.compilerOptions.outDir).toEqual('../../dist/out-tsc');
'../../dist/out-tsc/apps/my-app'
);
expect(tsconfigApp.extends).toEqual('./tsconfig.json'); expect(tsconfigApp.extends).toEqual('./tsconfig.json');
const tslintJson = JSON.parse( const tslintJson = JSON.parse(
@ -71,9 +69,7 @@ describe('app', () => {
const tsconfigE2E = JSON.parse( const tsconfigE2E = JSON.parse(
stripJsonComments(tree.readContent('apps/my-app-e2e/tsconfig.e2e.json')) stripJsonComments(tree.readContent('apps/my-app-e2e/tsconfig.e2e.json'))
); );
expect(tsconfigE2E.compilerOptions.outDir).toEqual( expect(tsconfigE2E.compilerOptions.outDir).toEqual('../../dist/out-tsc');
'../../dist/out-tsc/apps/my-app-e2e/src'
);
expect(tsconfigE2E.extends).toEqual('./tsconfig.json'); expect(tsconfigE2E.extends).toEqual('./tsconfig.json');
}); });
}); });
@ -148,7 +144,7 @@ describe('app', () => {
{ {
path: 'apps/my-dir/my-app/tsconfig.app.json', path: 'apps/my-dir/my-app/tsconfig.app.json',
lookupFn: json => json.compilerOptions.outDir, lookupFn: json => json.compilerOptions.outDir,
expectedValue: '../../../dist/out-tsc/apps/my-dir/my-app' expectedValue: '../../../dist/out-tsc'
}, },
{ {
path: 'apps/my-dir/my-app-e2e/tsconfig.json', path: 'apps/my-dir/my-app-e2e/tsconfig.json',
@ -158,7 +154,7 @@ describe('app', () => {
{ {
path: 'apps/my-dir/my-app-e2e/tsconfig.e2e.json', path: 'apps/my-dir/my-app-e2e/tsconfig.e2e.json',
lookupFn: json => json.compilerOptions.outDir, lookupFn: json => json.compilerOptions.outDir,
expectedValue: '../../../dist/out-tsc/apps/my-dir/my-app-e2e/src' expectedValue: '../../../dist/out-tsc'
}, },
{ {
path: 'apps/my-dir/my-app/tslint.json', path: 'apps/my-dir/my-app/tslint.json',

View File

@ -1,7 +1,7 @@
{ {
"extends": "./tsconfig.json", "extends": "./tsconfig.json",
"compilerOptions": { "compilerOptions": {
"outDir": "<%= offsetFromRoot %>dist/out-tsc/<%= appProjectRoot %>", "outDir": "<%= offsetFromRoot %>dist/out-tsc",
"types": [] "types": []
}, },
"exclude": ["**/*.spec.ts"], "exclude": ["**/*.spec.ts"],

View File

@ -1,7 +1,7 @@
{ {
"extends": "./tsconfig.json", "extends": "./tsconfig.json",
"compilerOptions": { "compilerOptions": {
"outDir": "<%= offsetFromRoot %>dist/out-tsc/<%= projectRoot %>", "outDir": "<%= offsetFromRoot %>dist/out-tsc",
"types": [] "types": []
}, },
"exclude": ["**/*.spec.ts", "**/*.spec.tsx"], "exclude": ["**/*.spec.ts", "**/*.spec.tsx"],

View File

@ -36,6 +36,24 @@ describe('Update 8-0-0', () => {
initialTree initialTree
) )
.toPromise(); .toPromise();
initialTree = await schematicRunner
.callRule(
updateJsonInTree('tsconfig.json', json => ({
compilerOptions: {}
})),
initialTree
)
.toPromise();
initialTree = await schematicRunner
.callRule(
updateJsonInTree('tsconfig.app.json', json => ({
compilerOptions: {
outDir: '../../dist/out-tsc/apps/blah'
}
})),
initialTree
)
.toPromise();
initialTree = await schematicRunner initialTree = await schematicRunner
.callRule( .callRule(
updateJsonInTree('angular.json', json => ({ updateJsonInTree('angular.json', json => ({
@ -164,6 +182,20 @@ describe('Update 8-0-0', () => {
}); });
}); });
describe('set root dir', () => {
it('should set root dir and update out dirs', async () => {
const tree = await schematicRunner
.runSchematicAsync('update-8.0.0', {}, initialTree)
.toPromise();
const rootTsConfig = readJsonInTree(tree, 'tsconfig.json');
expect(rootTsConfig.compilerOptions.rootDir).toEqual('.');
const appTsConfig = readJsonInTree(tree, 'tsconfig.app.json');
console.log(appTsConfig);
expect(appTsConfig.compilerOptions.outDir).toEqual('../../dist/out-tsc');
});
});
describe('jest config', () => { describe('jest config', () => {
it('should have the plugin path migrated', async () => { it('should have the plugin path migrated', async () => {
initialTree.create( initialTree.create(

View File

@ -262,6 +262,33 @@ const updateDefaultCollection = (host: Tree) => {
}); });
}; };
const setRootDirAndUpdateOurDir = (host: Tree) => {
host.visit(path => {
if (!path.endsWith('.json')) {
return;
}
const json = host.read(path).toString();
const match = json.match(/"outDir"\s*:\s*"([^"]+)"/);
if (match) {
const outParts = match[1].split('out-tsc');
if (outParts.length > 1) {
const updatedJson = json.replace(
/"outDir"\s*:\s*"([^"]+)"/,
`"outDir": "${outParts[0]}out-tsc"`
);
host.overwrite(path, updatedJson);
}
}
});
updateJsonInTree('tsconfig.json', json => {
json.compilerOptions = json.compilerOptions || {};
json.compilerOptions.rootDir = '.';
return json;
})(host, null);
};
export const runAngularMigrations: Rule = ( export const runAngularMigrations: Rule = (
host: Tree, host: Tree,
context: SchematicContext context: SchematicContext
@ -314,6 +341,7 @@ export default function(): Rule {
updateTslintRules, updateTslintRules,
addDependencies(), addDependencies(),
updateDefaultCollection, updateDefaultCollection,
setRootDirAndUpdateOurDir,
formatFiles() formatFiles()
]); ]);
} }

View File

@ -59,9 +59,7 @@ describe('app', () => {
const tsconfigApp = JSON.parse( const tsconfigApp = JSON.parse(
stripJsonComments(tree.readContent('apps/my-app/tsconfig.app.json')) stripJsonComments(tree.readContent('apps/my-app/tsconfig.app.json'))
); );
expect(tsconfigApp.compilerOptions.outDir).toEqual( expect(tsconfigApp.compilerOptions.outDir).toEqual('../../dist/out-tsc');
'../../dist/out-tsc/apps/my-app'
);
expect(tsconfigApp.extends).toEqual('./tsconfig.json'); expect(tsconfigApp.extends).toEqual('./tsconfig.json');
const tslintJson = JSON.parse( const tslintJson = JSON.parse(
@ -73,9 +71,7 @@ describe('app', () => {
const tsconfigE2E = JSON.parse( const tsconfigE2E = JSON.parse(
stripJsonComments(tree.readContent('apps/my-app-e2e/tsconfig.e2e.json')) stripJsonComments(tree.readContent('apps/my-app-e2e/tsconfig.e2e.json'))
); );
expect(tsconfigE2E.compilerOptions.outDir).toEqual( expect(tsconfigE2E.compilerOptions.outDir).toEqual('../../dist/out-tsc');
'../../dist/out-tsc/apps/my-app-e2e/src'
);
expect(tsconfigE2E.extends).toEqual('./tsconfig.json'); expect(tsconfigE2E.extends).toEqual('./tsconfig.json');
}); });
}); });
@ -150,7 +146,7 @@ describe('app', () => {
{ {
path: 'apps/my-dir/my-app/tsconfig.app.json', path: 'apps/my-dir/my-app/tsconfig.app.json',
lookupFn: json => json.compilerOptions.outDir, lookupFn: json => json.compilerOptions.outDir,
expectedValue: '../../../dist/out-tsc/apps/my-dir/my-app' expectedValue: '../../../dist/out-tsc'
}, },
{ {
path: 'apps/my-dir/my-app-e2e/tsconfig.json', path: 'apps/my-dir/my-app-e2e/tsconfig.json',
@ -160,7 +156,7 @@ describe('app', () => {
{ {
path: 'apps/my-dir/my-app-e2e/tsconfig.e2e.json', path: 'apps/my-dir/my-app-e2e/tsconfig.e2e.json',
lookupFn: json => json.compilerOptions.outDir, lookupFn: json => json.compilerOptions.outDir,
expectedValue: '../../../dist/out-tsc/apps/my-dir/my-app-e2e/src' expectedValue: '../../../dist/out-tsc'
}, },
{ {
path: 'apps/my-dir/my-app/tslint.json', path: 'apps/my-dir/my-app/tslint.json',

View File

@ -1,7 +1,7 @@
{ {
"extends": "./tsconfig.json", "extends": "./tsconfig.json",
"compilerOptions": { "compilerOptions": {
"outDir": "<%= offsetFromRoot %>dist/out-tsc/<%= appProjectRoot %>", "outDir": "<%= offsetFromRoot %>dist/out-tsc",
"types": [] "types": []
}, },
"exclude": ["**/*.spec.ts"], "exclude": ["**/*.spec.ts"],

View File

@ -1,7 +1,7 @@
{ {
"extends": "./tsconfig.json", "extends": "./tsconfig.json",
"compilerOptions": { "compilerOptions": {
"outDir": "<%= offsetFromRoot %>dist/out-tsc/<%= projectRoot %>", "outDir": "<%= offsetFromRoot %>dist/out-tsc",
"types": [] "types": []
}, },
"exclude": ["**/*.spec.ts"], "exclude": ["**/*.spec.ts"],

View File

@ -249,23 +249,17 @@ function updateTsConfigsJson(options: Schema) {
const offset = '../../'; const offset = '../../';
updateJsonFile(app.architect.build.options.tsConfig, json => { updateJsonFile(app.architect.build.options.tsConfig, json => {
json.extends = `${offset}tsconfig.json`; json.extends = `${offset}tsconfig.json`;
json.compilerOptions.outDir = `${offset}dist/out-tsc/apps/${ json.compilerOptions.outDir = `${offset}dist/out-tsc`;
options.name
}`;
}); });
updateJsonFile(app.architect.test.options.tsConfig, json => { updateJsonFile(app.architect.test.options.tsConfig, json => {
json.extends = `${offset}tsconfig.json`; json.extends = `${offset}tsconfig.json`;
json.compilerOptions.outDir = `${offset}dist/out-tsc/apps/${ json.compilerOptions.outDir = `${offset}dist/out-tsc`;
options.name
}`;
}); });
if (app.architect.server) { if (app.architect.server) {
updateJsonFile(app.architect.server.options.tsConfig, json => { updateJsonFile(app.architect.server.options.tsConfig, json => {
json.compilerOptions.outDir = `${offset}dist/out-tsc/apps/${ json.compilerOptions.outDir = `${offset}dist/out-tsc`;
options.name
}-server`;
}); });
} }
@ -274,9 +268,7 @@ function updateTsConfigsJson(options: Schema) {
json.extends = `${offsetFromRoot(e2eProject.root)}tsconfig.json`; json.extends = `${offsetFromRoot(e2eProject.root)}tsconfig.json`;
json.compilerOptions = { json.compilerOptions = {
...json.compilerOptions, ...json.compilerOptions,
outDir: `${offsetFromRoot(e2eProject.root)}dist/out-tsc/${ outDir: `${offsetFromRoot(e2eProject.root)}dist/out-tsc`
e2eProject.root
}`
}; };
}); });
} }

View File

@ -1,6 +1,7 @@
{ {
"compileOnSave": false, "compileOnSave": false,
"compilerOptions": { "compilerOptions": {
"rootDir": ".",
"sourceMap": true, "sourceMap": true,
"declaration": false, "declaration": false,
"moduleResolution": "node", "moduleResolution": "node",

View File

@ -14,6 +14,11 @@ echo "Compiling Typescript..."
./node_modules/.bin/ngc ./node_modules/.bin/ngc
echo "Compiled Typescript" echo "Compiled Typescript"
rm build/packages/angular/testing/nrwl-angular-testing.metadata.json
rm build/packages/angular/testing/index.metadata.json
rm build/packages/workspace/index.metadata.json
rm build/packages/workspace/testing.metadata.json
#TODO This is a temporary hack until we can publish named umds #TODO This is a temporary hack until we can publish named umds
sed -i.bak "s/define(\[/define('@nrwl\/angular',\[/" build/packages/angular/bundles/nrwl-angular.umd.js sed -i.bak "s/define(\[/define('@nrwl\/angular',\[/" build/packages/angular/bundles/nrwl-angular.umd.js
sed -i.bak "s/define(\[/define('@nrwl\/angular',\[/" build/packages/angular/bundles/nrwl-angular.umd.min.js sed -i.bak "s/define(\[/define('@nrwl\/angular',\[/" build/packages/angular/bundles/nrwl-angular.umd.min.js