Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(zone.js): add missing types field in package.json #38585

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,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.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.d.ts",
"dependencies": {
"tslib": "^2.0.0"
},
Expand Down
18 changes: 8 additions & 10 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.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');
it('should have an zone.d.ts file', () => {
expect(shx.cat('zone.d.ts')).toContain('declare const');
expect(shx.cat('zone.d.ts')).toContain('interface EventTarget');
expect(shx.cat('zone.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"
}
}
27 changes: 27 additions & 0 deletions packages/zone.js/test/typings/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"compilerOptions": {
JiaLiPassion marked this conversation as resolved.
Show resolved Hide resolved
"forceConsistentCasingInFileNames": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"experimentalDecorators": true,
"module": "commonjs",
"moduleResolution": "node",
"outDir": "./build",
"rootDir": ".",
"target": "es5",
"noEmitOnError": false,
"stripInternal": false,
"strict": true,
"lib": [
"es5",
"dom",
"es2015.collection",
"es2015.iterable",
"es2015.promise",
],
},
"files": [
"./type.test.ts",
"./node_modules/zone.js/zone.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;
JiaLiPassion marked this conversation as resolved.
Show resolved Hide resolved