Skip to content
This repository was archived by the owner on Sep 1, 2024. It is now read-only.

Commit 3840dc5

Browse files
committed
Rollup exported TypeScript types
Both @unflakable/cypress-plugin and @unflakable/jest-plugin include exported TypeScript types. Since both packages depend on the internal @unflakable/plugins-common package, we need to use rollup-plugin-dts to be sure that the exported types don't refer to this unpublished package.
1 parent bc52139 commit 3840dc5

File tree

6 files changed

+99
-39
lines changed

6 files changed

+99
-39
lines changed

packages/cypress-plugin/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@
3535
"README.md",
3636
"dist/**/*.js",
3737
"dist/**/*.mjs",
38-
"dist/index.d.ts",
39-
"dist/config-wrapper.d.ts",
4038
"dist/config-wrapper-sync.d.ts",
39+
"dist/config-wrapper.d.ts",
40+
"dist/index.d.ts",
4141
"dist/reporter.d.ts",
4242
"dist/skip-tests.d.ts"
4343
],
@@ -83,6 +83,7 @@
8383
"jest": "^29.5.0",
8484
"jest-environment-node": "^29.5.0",
8585
"rollup": "^3.21.1",
86+
"rollup-plugin-dts": "^5.3.0",
8687
"typescript": "^4.9.5",
8788
"widest-line": "3.1.0"
8889
},

packages/cypress-plugin/rollup.config.mjs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
// Copyright (c) 2023 Developer Innovations, LLC
22

33
import pluginCommonJs from "@rollup/plugin-commonjs";
4+
import pluginDts from "rollup-plugin-dts";
45
import pluginJson from "@rollup/plugin-json";
56
import pluginNodeResolve from "@rollup/plugin-node-resolve";
67
import pluginTypescript from "@rollup/plugin-typescript";
78

89
/**
910
* Bundle the internal @unflakable/plugins-common package, along with dependencies used by
1011
* vendored Cypress code that Cypress itself also bundles (i.e., doesn't list in its public
11-
* package.json as deps) in dist/, but leave most other imported packages as an external. Internal
12+
* package.json as deps) in dist/, but leave most other imported packages as external. Internal
1213
* modules begin with `.` or `/`. We don't include `term-size` here because it depends on a
1314
* bundled vendor/ directory that rollup doesn't include.
1415
*
@@ -86,4 +87,29 @@ export default [
8687
plugins,
8788
treeshake,
8889
},
90+
// Rollup types so that UnflakableConfig from @unflakable/plugins-common is bundled. This package
91+
// doesn't get published separately, so our public types shouldn't reference it.
92+
{
93+
input: [
94+
// NB: This should include every exported .d.ts from package.json.
95+
"dist/config-wrapper-sync.d.ts",
96+
"dist/config-wrapper.d.ts",
97+
"dist/index.d.ts",
98+
"dist/reporter.d.ts",
99+
"dist/skip-tests.d.ts",
100+
],
101+
output: {
102+
dir: ".",
103+
entryFileNames: "[name].d.ts",
104+
format: "cjs",
105+
},
106+
external: isExternal,
107+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
108+
plugins: [
109+
pluginNodeResolve({ preferBuiltins: true }),
110+
pluginDts({
111+
respectExternal: true,
112+
}),
113+
],
114+
},
89115
];

packages/jest-plugin/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@
6262
"jest-util": "25.1.0 - 29"
6363
},
6464
"scripts": {
65-
"build": "tsc --noEmit && rollup --config",
66-
"build:watch": "rollup --config --watch"
65+
"build": "yarn clean && tsc --noEmit && rollup --config",
66+
"build:watch": "rollup --config --watch",
67+
"clean": "rm -rf dist/"
6768
}
6869
}
Lines changed: 64 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,73 @@
11
// Copyright (c) 2023 Developer Innovations, LLC
22

3-
import pluginTypescript from "@rollup/plugin-typescript";
4-
import pluginNodeResolve from "@rollup/plugin-node-resolve";
53
import pluginCommonJs from "@rollup/plugin-commonjs";
4+
import pluginDts from "rollup-plugin-dts";
65
import pluginJson from "@rollup/plugin-json";
6+
import pluginNodeResolve from "@rollup/plugin-node-resolve";
7+
import pluginTypescript from "@rollup/plugin-typescript";
8+
9+
/**
10+
* Bundle the internal @unflakable/plugins-common package, but leave most other imported packages
11+
* as external. Internal modules begin with `.` or `/`.
12+
*
13+
* @type {import("rollup").IsExternal}
14+
*/
15+
const isExternal = (id) =>
16+
!id.startsWith(".") &&
17+
!id.startsWith("/") &&
18+
!id.startsWith("src/") &&
19+
!id.startsWith("@unflakable/plugins-common/") &&
20+
![
21+
// Support older versions of Jest that don't support sub-path externals in package.json.
22+
"@unflakable/js-api/consts",
23+
"@unflakable/plugins-common",
24+
].includes(id);
725

826
/**
927
* @type {import("rollup").NormalizedInputOptions}
1028
*/
11-
export default {
12-
input: ["src/reporter.ts", "src/runner.ts"],
13-
output: {
14-
dir: "dist",
15-
format: "cjs",
16-
// Mimicks TypeScript `esModuleInterop` (see
17-
// https://rollupjs.org/configuration-options/#output-format).
18-
interop: "auto",
19-
sourcemap: true,
29+
export default [
30+
{
31+
input: ["src/reporter.ts", "src/runner.ts"],
32+
output: {
33+
dir: "dist",
34+
format: "cjs",
35+
// Mimicks TypeScript `esModuleInterop` (see
36+
// https://rollupjs.org/configuration-options/#output-format).
37+
interop: "auto",
38+
},
39+
// Bundle the internal @unflakable/plugins-common package in dist/, but leave most other
40+
// imported packages as an external. Internal modules begin with `.` or `/`.
41+
external: isExternal,
42+
// Unclear why this is necessary.
43+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
44+
plugins: [
45+
pluginCommonJs(),
46+
pluginJson(),
47+
pluginNodeResolve(),
48+
pluginTypescript(),
49+
],
50+
},
51+
// Rollup types so that UnflakableConfig from @unflakable/plugins-common is bundled. This package
52+
// doesn't get published separately, so our public types shouldn't reference it.
53+
{
54+
input: [
55+
// NB: This should include every exported .d.ts from package.json.
56+
"dist/reporter.d.ts",
57+
"dist/runner.d.ts",
58+
],
59+
output: {
60+
dir: ".",
61+
entryFileNames: "[name].d.ts",
62+
format: "cjs",
63+
},
64+
external: isExternal,
65+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
66+
plugins: [
67+
pluginNodeResolve({ preferBuiltins: true }),
68+
pluginDts({
69+
respectExternal: true,
70+
}),
71+
],
2072
},
21-
// Bundle the internal @unflakable/plugins-common package in dist/, but leave most other
22-
// imported packages as an external. Internal modules begin with `.` or `/`.
23-
external: (id) =>
24-
!id.startsWith(".") &&
25-
!id.startsWith("/") &&
26-
!id.startsWith("src/") &&
27-
!id.startsWith("@unflakable/plugins-common/") &&
28-
![
29-
// Support older versions of Jest that don't support sub-path externals in package.json.
30-
"@unflakable/js-api/consts",
31-
"@unflakable/plugins-common",
32-
].includes(id),
33-
// Unclear why this is necessary.
34-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
35-
plugins: [
36-
pluginCommonJs(),
37-
pluginJson(),
38-
pluginNodeResolve(),
39-
pluginTypescript(),
40-
],
41-
};
73+
];

packages/jest-plugin/tsconfig.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
// Avoids conflicting global definitions from, e.g., jasmine.
1313
"types": ["node", "jest"],
1414
// Some versions of Jest (e.g., 28.0.0) have internally broken types.
15-
"skipLibCheck": true,
16-
"sourceMap": true
15+
"skipLibCheck": true
1716
},
1817
"include": [
1918
".eslintrc.js",

yarn.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2678,6 +2678,7 @@ __metadata:
26782678
ms: 2.1.1
26792679
path-browserify: ^1.0.1
26802680
rollup: ^3.21.1
2681+
rollup-plugin-dts: ^5.3.0
26812682
simple-git: ^3.16.0
26822683
term-size: 2.1.0
26832684
tmp: ~0.2.1

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy