Skip to content

Commit

Permalink
fix(zone.js): add missing types field in package.json
Browse files Browse the repository at this point in the history
Close #38584

In zone.js 0.11.1, the `types` field is missing in the `package.json`,
the reason is in zone.js 0.11.0, the `files` field is used to specify the
types, but it cause the npm package not contain any bundles issue, so zone.js
0.11.1 remove the `files` field, which cause the `type` definition gone.

This PR concat the `zone.js.d.ts`, `zone.configurations.api.ts`, `zone.api.extensions.ts`
types into a single `zone.js.d.ts` file.
  • Loading branch information
JiaLiPassion committed Aug 27, 2020
1 parent 956b25a commit 8b77caa
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 33 deletions.
2 changes: 2 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,8 @@ jobs:
cp dist/bin/packages/zone.js/npm_package/bundles/zone-patch-electron.umd.js ./packages/zone.js/test/extra/ &&
yarn --cwd packages/zone.js electrontest
- run: yarn --cwd packages/zone.js jesttest
- run: yarn --cwd packages/zone.js/test/typings install --frozen-lockfile --non-interactive
- run: yarn --cwd packages/zone.js/test/typings test

# Windows jobs
# Docs: https://circleci.com/docs/2.0/hello-world-windows/
Expand Down
31 changes: 6 additions & 25 deletions packages/zone.js/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -34,32 +34,13 @@ genrule(

genrule(
name = "zone_js_d_ts",
srcs = ["//packages/zone.js/lib:zone_d_ts"],
outs = ["zone.js.d.ts"],
cmd = "cp $< $@",
)

genrule(
name = "zone_extensions_d_ts",
srcs = ["//packages/zone.js/lib:zone.api.extensions.ts"],
outs = ["zone.api.extensions.ts"],
cmd = "cp $< $@",
)

genrule(
name = "zone_configurations_d_ts",
srcs = ["//packages/zone.js/lib:zone.configurations.api.ts"],
outs = ["zone.configurations.api.ts"],
cmd = "cp $< $@",
)

filegroup(
name = "zone_d_ts",
srcs = [
":zone_configurations_d_ts",
":zone_extensions_d_ts",
":zone_js_d_ts",
"//packages/zone.js/lib:zone_d_ts",
"//packages/zone.js/lib:zone.api.extensions.ts",
"//packages/zone.js/lib:zone.configurations.api.ts",
],
outs = ["zone.js.d.ts"],
cmd = "cat $(SRCS) > $@",
)

generate_rollup_bundle(
Expand Down Expand Up @@ -95,5 +76,5 @@ pkg_npm(
] + [
"//packages/zone.js/fesm2015:" + b + "-es2015.min.dist"
for b in BUNDLES_ENTRY_POINTS.keys()
] + [":zone_d_ts"],
] + [":zone_js_d_ts"],
)
1 change: 1 addition & 0 deletions packages/zone.js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"module": "./fesm2015/zone.js",
"es2015": "./fesm2015/zone.js",
"fesm2015": "./fesm2015/zone.js",
"typings": "./zone.js.d.ts",
"dependencies": {
"tslib": "^2.0.0"
},
Expand Down
14 changes: 6 additions & 8 deletions packages/zone.js/test/npm_package/npm_package.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,18 @@ describe('Zone.js npm_package', () => {
it('should contain module resolution mappings', () => {
expect(shx.grep('"main":', packageJson)).toContain(`zone.umd.js`);
});

it('should contain typings', () => {
expect(shx.grep('"typings":', packageJson)).toContain(`./zone.js.d.ts`);
});
});

describe('check npm_package root folder', () => {
describe('typescript support', () => {
it('should have an zone.js.d.ts file', () => {
expect(shx.cat('zone.js.d.ts')).toContain('declare const');
});

it('should have an zone.api.extensions.ts file', () => {
expect(shx.cat('zone.api.extensions.ts')).toContain('EventTarget');
});

it('should have an zone.configurations.api.ts file', () => {
expect(shx.cat('zone.configurations.api.ts')).toContain('ZoneGlobalConfigurations');
expect(shx.cat('zone.js.d.ts')).toContain('interface EventTarget');
expect(shx.cat('zone.js.d.ts')).toContain('ZoneGlobalConfigurations');
});
});

Expand Down
3 changes: 3 additions & 0 deletions packages/zone.js/test/typings/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
build
*.log
19 changes: 19 additions & 0 deletions packages/zone.js/test/typings/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "typings",
"version": "1.0.0",
"description": "typing test package to test zone.js.d.ts",
"scripts": {
"test": "tsc -p ."
},
"keywords": [],
"author": "",
"license": "MIT",
"dependencies": {
"@types/node": "12.11.1",
"domino": "^2.1.6",
"zone.js": "file:../../../../dist/bin/packages/zone.js/npm_package"
},
"devDependencies": {
"typescript": "^4.0.2"
}
}
25 changes: 25 additions & 0 deletions packages/zone.js/test/typings/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"outDir": "build",
"noEmitOnError": false,
"stripInternal": false,
"strict": true,
"lib": [
"es5",
"dom",
"es2015.iterable",
"es2015.promise",
"es2015.symbol",
"es2015.symbol.wellknown"
],
"typeRoots": [
"./node_modules/@types"
],
},
"files": [
"./type.test.ts",
"./node_modules/zone.js/zone.js.d.ts"
],
}
18 changes: 18 additions & 0 deletions packages/zone.js/test/typings/type.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import * as domino from 'domino';
require('zone.js/bundles/zone.umd');

// Zone public API should be included
Zone.current.fork({name: 'testZone'}).run(() => {});

// Zone extra APIs for EventTarget should be available
const w = domino.createWindow('<h1>Hello zone.js</h1>');
const h1 = w.document.querySelector('h1');
const listener = () => {};
h1!.addEventListener('click', listener);
const clickListeners = h1!.eventListeners!('click');
if (!clickListeners || clickListeners.length === 0 || clickListeners[0] !== listener) {
throw new Error('eventListeners not work!!!');
}

const globalZoneConfig = w as ZoneGlobalConfigurations;
globalZoneConfig.__Zone_disable_EventEmitter = true;

0 comments on commit 8b77caa

Please sign in to comment.