Skip to content

Commit 2dafcee

Browse files
committed
fix(lib): upgraded the lib to angular v9 + fixed the schematics
1 parent d6be89c commit 2dafcee

File tree

8 files changed

+124
-119
lines changed

8 files changed

+124
-119
lines changed

projects/angular-material-extensions/google-maps-autocomplete/schematics/helpers/angular/config.ts

Lines changed: 0 additions & 67 deletions
This file was deleted.
Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
export * from './ast-utils';
22
export * from './change';
33
export * from './component-schema';
4-
export * from './config';
54
export * from './dependencies';
65
export * from './find-module';
76
export * from './json-utils';
87
export * from './latest-versions';
9-
export * from './lint-fix';
108
export * from './ng-ast-utils';
119
export * from './parse-name';
1210
export * from './paths';
1311
export * from './project';
14-
export * from './project-targets';
1512
export * from './validation';
1613
export * from './workspace-models';

projects/angular-material-extensions/google-maps-autocomplete/schematics/helpers/angular/lint-fix.ts

Lines changed: 0 additions & 6 deletions
This file was deleted.

projects/angular-material-extensions/google-maps-autocomplete/schematics/helpers/angular/project-targets.ts

Lines changed: 0 additions & 26 deletions
This file was deleted.

projects/angular-material-extensions/google-maps-autocomplete/schematics/ng-add/index.ts

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
11
import {chain, noop, Rule, SchematicContext, Tree} from '@angular-devkit/schematics';
22
import {NodePackageInstallTask} from '@angular-devkit/schematics/tasks';
3-
import {
4-
addModuleImportToRootModule,
5-
addPackageJsonDependency,
6-
getProjectFromWorkspace,
7-
getWorkspace,
8-
NodeDependency,
9-
NodeDependencyType
10-
} from '../helpers';
11-
3+
import {addPackageJsonDependency, NodeDependency, NodeDependencyType} from '../helpers';
4+
import {getWorkspace} from '@schematics/angular/utility/config';
5+
import {addModuleImportToRootModule, getProjectFromWorkspace,} from '@angular/cdk/schematics';
126

137
/** Loads the full version from the given Angular package gracefully. */
148
function loadPackageVersionGracefully(context: SchematicContext): string | null {
@@ -35,9 +29,9 @@ export function addPackageJsonDependencies(): Rule {
3529
name: '@angular-material-extensions/google-maps-autocomplete'
3630
},
3731
{type: NodeDependencyType.Default, version: '^1.0.0-beta.7', name: '@agm/core'},
38-
{type: NodeDependencyType.Default, version: '^3.37.0', name: '@types/googlemaps'},
39-
{type: NodeDependencyType.Default, version: ngCoreVersionTag || '^8.1.2', name: '@angular/animations'},
40-
{type: NodeDependencyType.Default, version: ngCoreVersionTag || '^8.1.2', name: '@angular/forms'}
32+
{type: NodeDependencyType.Default, version: '^3.39.2', name: '@types/googlemaps'},
33+
{type: NodeDependencyType.Default, version: ngCoreVersionTag || '~9.0.0', name: '@angular/animations'},
34+
{type: NodeDependencyType.Default, version: ngCoreVersionTag || '~9.0.0', name: '@angular/forms'}
4135
];
4236

4337
dependencies.forEach(dependency => {
@@ -61,11 +55,7 @@ export function installPackageJsonDependencies(): Rule {
6155
export function addModuleToImports(options: any): Rule {
6256
return (host: Tree, context: SchematicContext) => {
6357
const workspace = getWorkspace(host);
64-
const project = getProjectFromWorkspace(
65-
workspace,
66-
// Takes the first project in case it's not provided by CLI
67-
options.project ? options.project : Object.keys(workspace.projects)[0]
68-
);
58+
const project = getProjectFromWorkspace(workspace, options.project);
6959
const moduleName = 'MatGoogleMapsAutocompleteModule';
7060
const agmCoreModule = 'AgmCoreModule.forRoot()';
7161

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"extends": "./tsconfig.lib.json",
3+
"angularCompilerOptions": {
4+
"enableIvy": false
5+
}
6+
}

server.ts.bak

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/**
2+
* *** NOTE ON IMPORTING FROM ANGULAR AND NGUNIVERSAL IN THIS FILE ***
3+
*
4+
* If your application uses third-party dependencies, you'll need to
5+
* either use Webpack or the Angular CLI's `bundleDependencies` feature
6+
* in order to adequately package them for use on the server without a
7+
* node_modules directory.
8+
*
9+
* However, due to the nature of the CLI's `bundleDependencies`, importing
10+
* Angular in this file will create a different instance of Angular than
11+
* the version in the compiled application code. This leads to unavoidable
12+
* conflicts. Therefore, please do not explicitly import from @angular or
13+
* @nguniversal in this file. You can export any needed resources
14+
* from your application's main.server.ts file, as seen below with the
15+
* import for `ngExpressEngine`.
16+
*/
17+
18+
import 'zone.js/dist/zone-node';
19+
20+
import * as express from 'express';
21+
import {join} from 'path';
22+
23+
// Express server
24+
const app = express();
25+
26+
const PORT = process.env.PORT || 4000;
27+
const DIST_FOLDER = join(process.cwd(), 'dist/browser');
28+
29+
// * NOTE :: leave this as require() since this file is built Dynamically from webpack
30+
const {AppServerModuleNgFactory, LAZY_MODULE_MAP, ngExpressEngine, provideModuleMap} = require('./dist/server/main');
31+
32+
// Our Universal express-engine (found @ https://github.com/angular/universal/tree/master/modules/express-engine)
33+
app.engine('html', ngExpressEngine({
34+
bootstrap: AppServerModuleNgFactory,
35+
providers: [
36+
provideModuleMap(LAZY_MODULE_MAP)
37+
]
38+
}));
39+
40+
app.set('view engine', 'html');
41+
app.set('views', DIST_FOLDER);
42+
43+
// Example Express Rest API endpoints
44+
// app.get('/api/**', (req, res) => { });
45+
// Serve static files from /browser
46+
app.get('*.*', express.static(DIST_FOLDER, {
47+
maxAge: '1y'
48+
}));
49+
50+
// All regular routes use the Universal engine
51+
app.get('*', (req, res) => {
52+
res.render('index', { req });
53+
});
54+
55+
// Start up the Node server
56+
app.listen(PORT, () => {
57+
console.log(`Node Express server listening on http://localhost:${PORT}`);
58+
});

webpack.server.config.js.bak

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Work around for https://github.com/angular/angular-cli/issues/7200
2+
3+
const path = require('path');
4+
const webpack = require('webpack');
5+
6+
module.exports = {
7+
mode: 'none',
8+
entry: {
9+
// This is our Express server for Dynamic universal
10+
server: './server.ts',
11+
// This is an example of Static prerendering (generative)
12+
prerender: './prerender.ts'
13+
},
14+
externals: {
15+
'./dist/server/main': 'require("./server/main")'
16+
},
17+
target: 'node',
18+
resolve: { extensions: ['.ts', '.js'] },
19+
optimization: {
20+
minimize: false
21+
},
22+
output: {
23+
// Puts the output at the root of the dist folder
24+
path: path.join(__dirname, 'dist'),
25+
filename: '[name].js'
26+
},
27+
module: {
28+
noParse: /polyfills-.*\.js/,
29+
rules: [
30+
{ test: /\.ts$/, loader: 'ts-loader' },
31+
{
32+
// Mark files inside `@angular/core` as using SystemJS style dynamic imports.
33+
// Removing this will cause deprecation warnings to appear.
34+
test: /(\\|\/)@angular(\\|\/)core(\\|\/).+\.js$/,
35+
parser: { system: true },
36+
},
37+
]
38+
},
39+
plugins: [
40+
new webpack.ContextReplacementPlugin(
41+
// fixes WARNING Critical dependency: the request of a dependency is an expression
42+
/(.+)?angular(\\|\/)core(.+)?/,
43+
path.join(__dirname, 'src'), // location of your src
44+
{} // a map of your routes
45+
),
46+
new webpack.ContextReplacementPlugin(
47+
// fixes WARNING Critical dependency: the request of a dependency is an expression
48+
/(.+)?express(\\|\/)(.+)?/,
49+
path.join(__dirname, 'src'),
50+
{}
51+
)
52+
]
53+
};

0 commit comments

Comments
 (0)