Skip to content
This repository has been archived by the owner on Nov 22, 2024. It is now read-only.

Commit

Permalink
build: upgrade to @hapi/hapi (#1218)
Browse files Browse the repository at this point in the history
Fixes #1215
  • Loading branch information
CaerusKaru authored Oct 21, 2019
1 parent 2c303c4 commit 87953dd
Show file tree
Hide file tree
Showing 17 changed files with 444 additions and 316 deletions.
7 changes: 4 additions & 3 deletions integration/hapi-engine-ivy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,17 @@
"@angular/platform-server": "file:../../node_modules/@angular/platform-server",
"@angular/router": "file:../../node_modules/@angular/router",
"@nguniversal/hapi-engine": "file:../../dist/modules-dist/hapi-engine",
"hapi": "file:../../node_modules/hapi",
"inert": "5.1.0",
"@hapi/hapi": "file:../../node_modules/@hapi/hapi",
"@hapi/inert": "5.2.0",
"rxjs": "file:../../node_modules/rxjs",
"zone.js": "file:../../node_modules/zone.js"
},
"devDependencies": {
"@angular-devkit/build-angular": "^0.900.0-next.10",
"@angular/cli": "^9.0.0-next.10",
"@angular/compiler-cli": "file:../../node_modules/@angular/compiler-cli",
"@types/inert": "file:../../node_modules/@types/inert",
"@types/hapi__hapi": "^18.2.5",
"@types/hapi__inert": "^5.2.0",
"@types/node": "file:../../node_modules/@types/node",
"@types/jasmine": "file:../../node_modules/@types/jasmine",
"codelyzer": "5.1.0",
Expand Down
4 changes: 2 additions & 2 deletions integration/hapi-engine-ivy/server.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import 'zone.js/dist/zone-node';

import { ngHapiEngine } from '@nguniversal/hapi-engine';
import * as inert from 'inert';
import { Request, Server, ResponseToolkit } from 'hapi';
import * as inert from '@hapi/inert';
import { Request, Server, ResponseToolkit } from '@hapi/hapi';
import { join } from 'path';
import { readFileSync } from 'fs';

Expand Down
7 changes: 4 additions & 3 deletions integration/hapi-engine-ve/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,17 @@
"@angular/platform-server": "file:../../node_modules/@angular/platform-server",
"@angular/router": "file:../../node_modules/@angular/router",
"@nguniversal/hapi-engine": "file:../../dist/modules-dist/hapi-engine",
"hapi": "file:../../node_modules/hapi",
"inert": "5.1.0",
"@hapi/hapi": "file:../../node_modules/@hapi/hapi",
"@hapi/inert": "5.2.0",
"rxjs": "file:../../node_modules/rxjs",
"zone.js": "file:../../node_modules/zone.js"
},
"devDependencies": {
"@angular-devkit/build-angular": "^0.900.0-next.10",
"@angular/cli": "^9.0.0-next.10",
"@angular/compiler-cli": "file:../../node_modules/@angular/compiler-cli",
"@types/inert": "file:../../node_modules/@types/inert",
"@types/hapi__hapi": "^18.2.5",
"@types/hapi__inert": "^5.2.0",
"@types/node": "file:../../node_modules/@types/node",
"@types/jasmine": "file:../../node_modules/@types/jasmine",
"codelyzer": "5.1.0",
Expand Down
4 changes: 2 additions & 2 deletions integration/hapi-engine-ve/server.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import 'zone.js/dist/zone-node';

import { ngHapiEngine } from '@nguniversal/hapi-engine';
import * as inert from 'inert';
import { Request, Server, ResponseToolkit } from 'hapi';
import * as inert from '@hapi/inert';
import { Request, Server, ResponseToolkit } from '@hapi/hapi';
import { join } from 'path';
import { readFileSync } from 'fs';

Expand Down
3 changes: 2 additions & 1 deletion modules/bazel-tsconfig-build.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"target": "es2015",
"lib": ["es2015", "dom"],
"skipLibCheck": true,
"types": ["tslib", "node"]
"types": ["tslib", "node"],
"typeRoots": ["node_modules/@types"]
},
"bazelOptions": {
"suppressTsconfigOverrideWarnings": true
Expand Down
6 changes: 3 additions & 3 deletions modules/hapi-engine/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ ng_module(
"//modules/common/engine",
"//modules/hapi-engine/tokens",
"@npm//@angular/platform-server",
"@npm//@types/hapi",
"@npm//@types/hapi__hapi",
],
)

Expand Down Expand Up @@ -55,9 +55,9 @@ ng_test_library(
":testing",
"@npm//@angular/platform-browser",
"@npm//@angular/platform-server",
"@npm//@types/hapi",
"@npm//@hapi/hapi",
"@npm//@types/hapi__hapi",
"@npm//domino",
"@npm//hapi",
"@npm//xhr2",
"@npm//zone.js",
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import 'zone.js/dist/zone-node';

import { ngHapiEngine } from '@nguniversal/hapi-engine';
import * as inert from 'inert';
import { Request, Server, ResponseToolkit } from 'hapi';
import * as inert from '@hapi/inert';
import { Request, Server, ResponseToolkit } from '@hapi/hapi';
import { join } from 'path';
import { readFileSync } from 'fs';

Expand Down
4 changes: 2 additions & 2 deletions modules/hapi-engine/schematics/install/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ describe('Universal Schematic', () => {
expect(contents).toMatch(/\"@nguniversal\/hapi-engine\": \"/);
});

it('should add dependency: hapi', async () => {
it('should add dependency: @hapi/hapi', async () => {
const tree = await schematicRunner
.runSchematicAsync('ng-add', defaultOptions, appTree)
.toPromise();
const filePath = '/package.json';
const contents = tree.readContent(filePath);
expect(contents).toMatch(/\"hapi\": \"/);
expect(contents).toMatch(/\"@hapi\/hapi\": \"/);
});

it('should install npm dependencies', async () => {
Expand Down
15 changes: 10 additions & 5 deletions modules/hapi-engine/schematics/install/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,23 @@ function addDependencies(options: UniversalOptions): Rule {
});
addPackageJsonDependency(host, {
type: NodeDependencyType.Default,
name: 'hapi',
name: '@hapi/hapi',
version: 'HAPI_VERSION',
});
addPackageJsonDependency(host, {
type: NodeDependencyType.Dev,
name: '@types/hapi__hapi',
version: '^18.2.5',
});
addPackageJsonDependency(host, {
type: NodeDependencyType.Default,
name: 'inert',
version: '^5.1.0',
name: '@hapi/inert',
version: '^5.2.0',
});
addPackageJsonDependency(host, {
type: NodeDependencyType.Dev,
name: '@types/inert',
version: '^5.1.0',
name: '@types/hapi__inert',
version: '^5.2.0',
});
return host;
};
Expand Down
2 changes: 1 addition & 1 deletion modules/hapi-engine/spec/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {destroyPlatform, getPlatform} from '@angular/core';
import {ngHapiEngine} from '@nguniversal/hapi-engine';
import {ServerInjectResponse, Request, Server} from 'hapi';
import {ServerInjectResponse, Request, Server} from '@hapi/hapi';
import {ExampleModuleNgFactory} from '../testing/example.ngfactory';
import 'zone.js';

Expand Down
2 changes: 1 addition & 1 deletion modules/hapi-engine/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
import * as fs from 'fs';
import { Request, ResponseToolkit } from 'hapi';
import { Request, ResponseToolkit } from '@hapi/hapi';

import { NgModuleFactory, Type, StaticProvider } from '@angular/core';
import { ɵCommonEngine as CommonEngine } from '@nguniversal/common/engine';
Expand Down
3 changes: 2 additions & 1 deletion modules/hapi-engine/tokens/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ ng_module(
module_name = "@nguniversal/hapi-engine/tokens",
deps = [
"@npm//@angular/core",
"@npm//@types/hapi",
"@npm//@hapi/hapi",
"@npm//@types/hapi__hapi",
],
)
2 changes: 1 addition & 1 deletion modules/hapi-engine/tokens/injection-tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
* 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 { Request, ResponseToolkit } from 'hapi';
import { InjectionToken } from '@angular/core';
import { Request, ResponseToolkit } from '@hapi/hapi';

export const REQUEST = new InjectionToken<Request>('REQUEST');
export const RESPONSE = new InjectionToken<ResponseToolkit>('RESPONSE');
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"node": ">=10.13.0 <13.0.0"
},
"scripts": {
"postinstall": "ngc -p ./angular-metadata.tsconfig.json",
"postinstall": "ngc -p ./angular-metadata.tsconfig.json && node --preserve-symlinks --preserve-symlinks-main ./tools/postinstall-patches.js",
"lint": "tslint -c tslint.json '+(modules|tools)/**/*.ts' --exclude '**/node_modules/**/*'",
"build": "npm run bazel:build",
"prebuildifier": "bazel build --noshow_progress @com_github_bazelbuild_buildtools//buildifier",
Expand Down Expand Up @@ -55,16 +55,16 @@
"@bazel/jasmine": "^0.38.0",
"@bazel/karma": "^0.38.0",
"@bazel/typescript": "^0.38.0",
"@hapi/hapi": "^18.4.0",
"@schematics/angular": "^9.0.0-next.10",
"@types/express": "^4.17.1",
"@types/fs-extra": "^4.0.5",
"@types/hapi": "^17.0.12",
"@types/inert": "^5.1.2",
"@types/hapi__hapi": "^18.2.5",
"@types/hapi__inert": "^5.2.0",
"@types/jasmine": "^3.4.4",
"@types/node": "^12.11.1",
"domino": "^2.1.2",
"express": "^4.15.2",
"hapi": "^17.5.1",
"jasmine-core": "^2.11.0",
"karma": "^4.1.0",
"karma-chrome-launcher": "^2.2.0",
Expand All @@ -74,6 +74,7 @@
"minimatch": "^3.0.4",
"protractor": "5.4.2",
"rxjs": "^6.5.3",
"shelljs": "^0.8.3",
"source-map-support": "^0.5.9",
"ts-node": "8.4.1",
"tslib": "~1.10.0",
Expand Down
10 changes: 5 additions & 5 deletions tools/defaults.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def ts_library(tsconfig = None, deps = [], testonly = False, **kwargs):

NG_VERSION = "^9.0.0-next.10"
RXJS_VERSION = "^6.5.3"
HAPI_VERSION = "^17.0.0"
HAPI_VERSION = "^18.4.0"
EXPRESS_VERSION = "^4.15.2"
EXPRESS_TYPES_VERSION = "^4.17.0"
DEVKIT_CORE_VERSION = "^9.0.0-next.9"
Expand Down Expand Up @@ -78,7 +78,7 @@ GLOBALS = {
"@nguniversal/hapi-engine/tokens": "nguniversal.hapiEngine.tokens",
"express": "express",
"fs": "fs",
"hapi": "hapi",
"@hapi/hapi": "hapi.hapi",
"rxjs": "rxjs",
"rxjs/operators": "rxjs.operators",
"tslib": "tslib",
Expand Down Expand Up @@ -150,12 +150,12 @@ def npm_package(name, replacements = {}, **kwargs):
def ng_web_test_suite(deps = [], srcs = [], **kwargs):
_ts_web_test_suite(
# Required for running the compiled ng modules that use TypeScript import helpers.
srcs = ["@npm//node_modules/tslib:tslib.js"] + srcs,
srcs = ["@npm//:node_modules/tslib/tslib.js"] + srcs,
# Depend on our custom test initialization script. This needs to be the first dependency.
deps = ["//test:angular_test_init"] + deps,
bootstrap = [
"@npm//node_modules/zone.js:dist/zone-testing-bundle.js",
"@npm//node_modules/reflect-metadata:Reflect.js",
"@npm//:node_modules/zone.js/dist/zone-testing-bundle.js",
"@npm//:node_modules/reflect-metadata/Reflect.js",
],
**kwargs
)
56 changes: 56 additions & 0 deletions tools/postinstall-patches.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
try {
require.resolve('shelljs');
} catch (e) {
// We are in an bazel managed external node_modules repository
// and the resolve has failed because node did not preserve the symlink
// when loading the script.
// This can be fixed using the --preserve-symlinks-main flag which
// is introduced in node 10.2.0
console.warn(
`Running postinstall-patches.js script in an external repository requires --preserve-symlinks-main node flag introduced in node 10.2.0. ` +
`Current node version is ${process.version}. Node called with '${process.argv.join(" ")}'.`);
process.exit(0);
}

const {set, cd, sed, echo, ls} = require('shelljs');
const {readFileSync} = require('fs');
const path = require('path');
const log = console.log;

// COMMENTED OUT BECAUSE WE CURRENTLY REQUIRE NO PATCHES
// UNCOMMENT TO REENABLE PATCHING AND LOG OUTPUT
//
log('===== about to run the postinstall-patches.js script =====');
// fail on first error
set('-e');
// print commands as being executed
set('-v');
// jump to project root
cd(path.join(__dirname, '../'));

/* EXAMPLE PATCH:
// https://github.com/ReactiveX/rxjs/pull/3302
// make node_modules/rxjs compilable with Typescript 2.7
// remove when we update to rxjs v6
log('\n# patch: reactivex/rxjs#3302 make node_modules/rxjs compilable with Typescript 2.7');
sed('-i', '(\'response\' in xhr)', '(\'response\' in (xhr as any))',
'node_modules/rxjs/src/observable/dom/AjaxObservable.ts');
*/

// Workaround https://github.com/bazelbuild/rules_nodejs/issues/1033
// TypeScript doesn't understand typings without "declare module" unless
// they are actually resolved by the @types default mechanism
log('\n# patch: @types/hapi__* adding declare module wrappers');
ls('node_modules/@types').filter(f => f.startsWith('hapi__')).forEach(pkg => {
const modName = '@' + pkg.replace('__', '/');
const typingsFile = `node_modules/@types/${pkg}/index.d.ts`;
// Only add the patch if it is not already there.
if (readFileSync(typingsFile, 'utf8').indexOf('/*added by tools/postinstall_patches.js*/') ===
-1) {
const insertPrefix = `/*added by tools/postinstall_patches.js*/ declare module "${modName}" { `;
sed('-i', `(// Type definitions for ${modName})`, insertPrefix + '$1', typingsFile);
echo('}').toEnd(typingsFile);
}
});

log('===== finished running the postinstall-patches.js script =====');
Loading

0 comments on commit 87953dd

Please sign in to comment.