Skip to content

Commit

Permalink
feat(angular): official v9 ivy support (#201)
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanWalker authored Jun 11, 2020
1 parent cc6ced2 commit a5f2e62
Show file tree
Hide file tree
Showing 28 changed files with 378 additions and 80 deletions.
4 changes: 3 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@
"titleBar.inactiveForeground": "#e7e7e799",
"statusBar.background": "#eb5324",
"statusBarItem.hoverBackground": "#ef7853",
"statusBar.foreground": "#e7e7e7"
"statusBar.foreground": "#e7e7e7",
"statusBar.border": "#eb5324",
"titleBar.border": "#eb5324"
},
"peacock.color": "#eb5324"
}
9 changes: 8 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ yarn publish-local
yarn create-nx-test myworkspace
```

This will setup a fresh Nx workspace at `tmp/myworkspace` and auto open in VS Code. It will already be preconfigured to install @nstudio/xplat tools from a local build.
This will setup a fresh Nx workspace at `tmp/myworkspace` and auto open in VS Code. It will already be preconfigured to install @nstudio/xplat tools from the local build which is published to verdaccio (if you followed these steps in order)

3. You can now install your schematic changes with:

Expand All @@ -53,6 +53,13 @@ yarn publish-local unpublish
yarn publish-local
```

You can then remove the dependency and reinstall to ensure you get the latest local changes in your test workspace:

```
rm -rf node_modules/@nstudio
npm i -D @nstudio/xplat
```

### Unit Tests

```
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"esModuleInterop": true,
"target": "es5",
"typeRoots": ["../../node_modules/@types"],
"lib": ["es2017", "es2016", "es2015", "dom"]
"types": ["node", "jest"]
},
"include": ["src/index.ts"]
}
5 changes: 5 additions & 0 deletions packages/nativescript-angular/migrations.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
"version": "8.1.2",
"description": "Migrate NativeScript apps to 6.3",
"factory": "./migrations/update-8-1-2/update-8-1-2"
},
"update-to-9.0.4": {
"version": "9.0.4",
"description": "Migrate NativeScript apps to Angular 9",
"factory": "./migrations/update-9-0-4/update-9-0-4"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import * as fs from 'fs';
import { updateJsonInTree, createOrUpdate } from '@nrwl/workspace';
import { getJsonFromFile, updateJsonFile, output } from '@nstudio/xplat';
import {
nsNgVersion,
nsCoreVersion,
terserWebpackVersion
terserWebpackVersion,
nsNgScopedVersion
} from '../../src/utils/versions';

function updateNativeScriptApps(tree: Tree, context: SchematicContext) {
Expand Down Expand Up @@ -82,7 +82,7 @@ function updateRootPackage(tree: Tree, context: SchematicContext) {
json.dependencies = json.dependencies || {};
json.dependencies = {
...json.dependencies,
'nativescript-angular': nsNgVersion,
'nativescript-angular': nsNgScopedVersion,
'tns-core-modules': nsCoreVersion
};
json.devDependencies = json.devDependencies || {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import * as fs from 'fs';
import { updateJsonInTree, createOrUpdate } from '@nrwl/workspace';
import { getJsonFromFile, updateJsonFile, output } from '@nstudio/xplat';
import {
nsNgVersion,
nsCoreVersion,
terserWebpackVersion
terserWebpackVersion,
nsNgScopedVersion
} from '../../src/utils/versions';

function updateNativeScriptApps(tree: Tree, context: SchematicContext) {
Expand Down Expand Up @@ -82,7 +82,7 @@ function updateRootPackage(tree: Tree, context: SchematicContext) {
json.dependencies = json.dependencies || {};
json.dependencies = {
...json.dependencies,
'nativescript-angular': nsNgVersion,
'nativescript-angular': nsNgScopedVersion,
'tns-core-modules': nsCoreVersion
};
json.devDependencies = json.devDependencies || {};
Expand Down
140 changes: 140 additions & 0 deletions packages/nativescript-angular/migrations/update-9-0-4/update-9-0-4.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
import {
chain,
Rule,
SchematicContext,
Tree
} from '@angular-devkit/schematics';
import { join } from 'path';
import * as fs from 'fs';
import { updateJsonInTree, createOrUpdate } from '@nrwl/workspace';
import { getJsonFromFile, updateJsonFile, output } from '@nstudio/xplat';
import {
nsCoreVersion,
terserWebpackVersion,
nsNgScopedVersion,
ngxTranslateVersion,
nsDevWebpackVersion,
typescriptVersion,
angularVersion
} from '../../src/utils/versions';

const ngDeps = {
'@angular/animations': angularVersion,
'@angular/common': angularVersion,
'@angular/compiler': angularVersion,
'@angular/core': angularVersion,
'@angular/forms': angularVersion,
'@angular/platform-browser': angularVersion,
'@angular/platform-browser-dynamic': angularVersion,
'@angular/router': angularVersion
};

function updateNativeScriptApps(tree: Tree, context: SchematicContext) {
const appsDir = tree.getDir('apps');
const appFolders = appsDir.subdirs;
const cwd = process.cwd();
const webpackConfigPath = join(
cwd,
'node_modules/@nstudio/nativescript-angular/src/schematics/application/_files/webpack.config.js'
);
// console.log('webpackConfigPath:', webpackConfigPath);
const webpackConfig = fs.readFileSync(webpackConfigPath, 'UTF-8');
const srcPackagePath = join(
cwd,
'node_modules/@nstudio/nativescript-angular/src/schematics/application/_files/src/package.json'
);
// console.log('webpackConfigPath:', webpackConfigPath);
const srcPackage = fs.readFileSync(srcPackagePath, 'UTF-8');
const ngccConfigPath = join(
cwd,
'node_modules/@nstudio/nativescript-angular/src/schematics/application/_files/ngcc.config.js'
);
const ngccConfig = fs.readFileSync(ngccConfigPath, 'UTF-8');

const tsconfigTnsPath = join(
cwd,
'node_modules/@nstudio/nativescript-angular/src/schematics/application/_files/tsconfig.tns.json'
);
const tsconfigTns = fs.readFileSync(tsconfigTnsPath, 'UTF-8');

const appsNames = [];
// update {N} apps and configs
for (const dir of appFolders) {
// console.log(dir);
if (
dir.indexOf('nativescript-') === 0 ||
dir.indexOf('-nativescript') === 0
) {
const appDir = `${appsDir.path}/${dir}`;
// console.log('appDir:', appDir);
appsNames.push(dir);

createOrUpdate(tree, `${appDir}/webpack.config.js`, webpackConfig);
createOrUpdate(tree, `${appDir}/src/package.json`, srcPackage);
createOrUpdate(tree, `${appDir}/ngcc.config.js`, ngccConfig);
createOrUpdate(tree, `${appDir}/tsconfig.tns.json`, tsconfigTns);

// update {N} app deps
const packagePath = `${appDir}/package.json`;
const packageJson = getJsonFromFile(tree, packagePath);

if (packageJson) {
packageJson.dependencies = packageJson.dependencies || {};
packageJson.dependencies = {
...packageJson.dependencies,
...ngDeps,
'@nativescript/angular': nsNgScopedVersion,
'@nativescript/core': nsCoreVersion,
'@ngx-translate/core': ngxTranslateVersion
};
delete packageJson.dependencies['nativescript-angular'];
delete packageJson.dependencies['tns-core-modules'];
packageJson.devDependencies = packageJson.devDependencies || {};
packageJson.devDependencies = {
...packageJson.devDependencies,
'@angular/compiler-cli': angularVersion,
'@ngtools/webpack': angularVersion,
'nativescript-dev-webpack': nsDevWebpackVersion,
'terser-webpack-plugin': terserWebpackVersion,
'tns-platform-declarations': nsCoreVersion,
typescript: typescriptVersion
};

// console.log('path:',path);
// console.log('packageJson overwrite:', JSON.stringify(packageJson));
tree = updateJsonFile(tree, packagePath, packageJson);
}
}
output.log({
title: 'Migration Note:',
bodyLines: [
`Please ensure you have the latest NativeScript cli installed: npm i -g nativescript`,
`The following NativeScript apps have been updated to 9.0: ${appsNames}. The following files in those apps have been updated: webpack.config.js, src/package.json, ngcc.config.js and package.json. You may want to check the changeset to keep any customizations you may have made.`,
`Please note that you may still need to update your project imports to @nativescript/angular instead of nativescript-angular.`
]
});
}
return tree;
}

function updateRootPackage(tree: Tree, context: SchematicContext) {
return updateJsonInTree('package.json', json => {
json.scripts = json.scripts || {};
json.dependencies = json.dependencies || {};
json.dependencies = {
...json.dependencies,
...ngDeps,
'@nativescript/angular': nsNgScopedVersion,
'@ngx-translate/core': ngxTranslateVersion
};
delete json.dependencies['nativescript-angular'];
delete json.dependencies['tns-core-modules'];
json.devDependencies = json.devDependencies || {};

return json;
})(tree, context);
}

export default function(): Rule {
return chain([updateNativeScriptApps, updateRootPackage]);
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ npm-debug.log
# app
!*.d.ts
!src/assets/fontawesome.min.css
!src/app.module.ngfactory.d.ts
!webpack.config.js
/report/
.nsbuildinfo
/temp/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
module.exports = {
packages: {
'@nativescript/angular': {
entryPoints: {
'.': {
override: {
main: './index.js',
typings: './index.d.ts'
},
ignoreMissingDependencies: true
}
},
ignorableDeepImportMatchers: [
/zone.js\//,
/tns-core-modules\//,
/@nativescript\/core\//
]
},
'nativescript-datetimepicker': {
entryPoints: {
'.': {
override: {
main: './index.js',
typings: './index.d.ts'
},
ignoreMissingDependencies: true
},
angular: {
override: {
main: './index.js',
typings: './index.d.ts'
},
ignoreMissingDependencies: true
}
},
ignorableDeepImportMatchers: [
/tns-core-modules\//,
/@nativescript\/core\//,
/@nativescript\/angular\//
]
},
'nativescript-ui-sidedrawer': {
entryPoints: {
angular: {
override: {
main: './side-drawer-directives.js',
typings: './side-drawer-directives.d.ts'
},
ignoreMissingDependencies: true
}
},
ignorableDeepImportMatchers: [
/tns-core-modules\//,
/@nativescript\/core\//,
/@nativescript\/angular\//
]
},
'nativescript-ui-listview': {
entryPoints: {
angular: {
override: {
main: './listview-directives.js',
typings: './listview-directives.d.ts'
},
ignoreMissingDependencies: true
}
},
ignorableDeepImportMatchers: [
/tns-core-modules\//,
/@nativescript\/core\//,
/@nativescript\/angular\//
]
}
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,14 @@
"@angular/platform-browser-dynamic": "<%= angularVersion %>",
"@angular/router": "<%= angularVersion %>",
"@nativescript/angular": "<%= nsNgScopedVersion %>",
"@nativescript/core": "<%= nsCoreVersion %>",
"@ngx-translate/core": "<%= ngxTranslateVersion %>",
"@<%= npmScope %>/scss": "file:<%= pathOffset %>libs/scss",
"@<%= npmScope %>/nativescript-scss": "file:<%= pathOffset %>xplat/<%= xplatFolderName %>/scss",
"nativescript-angular": "<%= nsNgVersion %>",
"nativescript-intl": "<%= nsIntlVersion %>",
"nativescript-ngx-fonticon": "<%= nsNgFonticonVersion %>",
"nativescript-theme-core": "<%= nsThemeCoreVersion %>",
"rxjs": "<%= rxjsVersion %>",
"tns-core-modules": "<%= nsCoreVersion %>",
"tslib": "<%= tslibVersion %>",
"zone.js": "<%= zonejsVersion %>"
},
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@
"*": ["./node_modules/*"]
}
},
"files": [
"./references.d.ts",
"./src/app.module.ngfactory.d.ts",
"./src/main.ts"
],
"files": ["./references.d.ts", "./src/main.ts"],
"include": [
"./src/**/*.module.ts",
"<%= pathOffset %>xplat/**/*.{ios,android}.ts",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ platforms/
*.js.map
*.js
!webpack.config.js
!ngcc.config.js

# Logs
logs
Expand Down
Loading

0 comments on commit a5f2e62

Please sign in to comment.