Skip to content

Commit fa3a60f

Browse files
authored
Merge pull request #2736 from bugsnag/rollup-config-rework
Reworked rollup builds
2 parents a860e5d + a65ab97 commit fa3a60f

265 files changed

Lines changed: 30113 additions & 44279 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.buildkite/basic/browser-pipeline.yml

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ steps:
5959
run: "browser-maze-runner-bs"
6060
use-aliases: true
6161
command:
62-
- "--fail-fast"
6362
- "--farm=bs"
6463
- "--browser={{matrix}}"
6564
artifacts#v1.5.0:
@@ -83,7 +82,7 @@ steps:
8382
- "safari_10"
8483
- "ios_15"
8584
- "android_9"
86-
- "chrome_43"
85+
- "chrome_53" # TODO: Revert to Chrome 47 when Maze Runner supports it again (see PLAT-16280)
8786
- "chrome_72"
8887
- "firefox_78"
8988
depends_on: "browser-maze-runner-bs"
@@ -94,7 +93,6 @@ steps:
9493
run: "browser-maze-runner-bs"
9594
use-aliases: true
9695
command:
97-
- "--fail-fast"
9896
- "--https"
9997
- "--farm=bs"
10098
- "--browser={{matrix}}"
@@ -127,7 +125,6 @@ steps:
127125
service-ports: true
128126
use-aliases: true
129127
command:
130-
- "--fail-fast"
131128
- "--https"
132129
- "--farm=bb"
133130
- "--browser={{matrix}}"
@@ -145,31 +142,3 @@ steps:
145142
concurrency_group: "bitbar"
146143
concurrency_method: "eager"
147144

148-
- label: ":bitbar: ie_11 Browser tests (EU hub)"
149-
depends_on: "browser-maze-runner-bb"
150-
timeout_in_minutes: 30
151-
plugins:
152-
docker-compose#v4.12.0:
153-
pull: "browser-maze-runner-bb"
154-
run: "browser-maze-runner-bb"
155-
service-ports: true
156-
use-aliases: true
157-
command:
158-
- "--fail-fast"
159-
- "--farm=bb"
160-
- "--browser=ie_11"
161-
- "--no-tunnel"
162-
- "--aws-public-ip"
163-
artifacts#v1.5.0:
164-
upload:
165-
- "./test/browser/maze_output/failed/**/*"
166-
test-collector#v1.10.2:
167-
files: "reports/TEST-*.xml"
168-
format: "junit"
169-
branch: "^main|next$$"
170-
api-token-env-name: "BROWSER_BUILDKITE_ANALYTICS_TOKEN"
171-
concurrency: 25
172-
concurrency_group: "bitbar"
173-
concurrency_method: "eager"
174-
env:
175-
HOST: "localhost" # IE11 needs the host set to localhost

.buildkite/pipeline.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ steps:
7777
plugins:
7878
docker-compose#v4.12.0:
7979
run: ci
80-
command: "npm run test:unit"
80+
command:
81+
- "npm run test:unit"
8182

8283
- label: "Type checks/tests"
8384
depends_on: "ci-image"

.rollup/index.mjs

Lines changed: 87 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
12
import typescript from '@rollup/plugin-typescript'
3+
import commonjs from '@rollup/plugin-commonjs'
4+
import nodeResolve from '@rollup/plugin-node-resolve'
25
import replace from '@rollup/plugin-replace'
36
import fs from 'fs'
47

@@ -10,59 +13,96 @@ const defaultOptions = () => ({
1013
external: [],
1114
// the entry point for the bundle
1215
input: undefined,
13-
// output directory for the bundle
14-
output: undefined
16+
// additional rollup plugins
17+
plugins: []
1518
})
1619

17-
export const sharedOutput = {
18-
dir: 'dist',
19-
generatedCode: {
20-
preset: 'es2015',
21-
}
22-
}
23-
2420
function createRollupConfig (options = defaultOptions()) {
2521
const packageJson = JSON.parse(fs.readFileSync(`${process.cwd()}/package.json`))
2622

27-
return {
28-
input: options.input || 'src/index.ts',
29-
output: options.output || [
30-
{
31-
...sharedOutput,
23+
return [
24+
// ESM build
25+
{
26+
input: options.input || './src/index.ts',
27+
output: {
28+
dir: 'dist/esm',
3229
entryFileNames: '[name].js',
33-
format: 'cjs'
34-
},
35-
{
36-
...sharedOutput,
37-
preserveModules: true,
38-
entryFileNames: '[name].mjs',
39-
format: 'esm'
40-
}
41-
],
42-
external: options.external,
43-
plugins: [
44-
replace({
45-
preventAssignment: true,
46-
values: {
47-
__VERSION__: packageJson.version,
48-
...options.additionalReplacements,
30+
format: 'es',
31+
sourcemap: true,
32+
generatedCode: {
33+
preset: 'es2015',
4934
}
50-
}),
51-
typescript({
52-
removeComments: true,
53-
// don't output anything if there's a TS error
54-
noEmitOnError: true,
55-
// turn on declaration files and declaration maps
56-
compilerOptions: {
57-
declaration: true,
58-
declarationMap: true,
59-
emitDeclarationOnly: true,
60-
declarationDir: 'dist/types',
61-
}
62-
}),
63-
...(options.plugins ?? [])
64-
]
65-
}
35+
},
36+
external: options.external,
37+
plugins: [
38+
replace({
39+
preventAssignment: true,
40+
values: {
41+
__BUGSNAG_NOTIFIER_VERSION__: packageJson.version,
42+
...options.additionalReplacements,
43+
}
44+
}),
45+
nodeResolve({
46+
preferBuiltins: true
47+
}),
48+
commonjs(),
49+
typescript({
50+
tsconfig: './tsconfig.json',
51+
declarationDir: 'dist/esm',
52+
outDir: 'dist/esm',
53+
noEmitOnError: true
54+
}),
55+
...(options.plugins ?? [])
56+
]
57+
},
58+
// CJS build
59+
{
60+
input: options.input || './src/index.ts',
61+
output: {
62+
dir: 'dist/cjs',
63+
entryFileNames: '[name].js',
64+
format: 'cjs',
65+
sourcemap: true,
66+
generatedCode: {
67+
preset: 'es2015',
68+
},
69+
exports: 'named',
70+
interop: 'auto',
71+
footer: 'module.exports = Object.assign(exports.default || {}, exports);'
72+
},
73+
external: options.external,
74+
plugins: [
75+
replace({
76+
preventAssignment: true,
77+
values: {
78+
__BUGSNAG_NOTIFIER_VERSION__: packageJson.version,
79+
...options.additionalReplacements,
80+
}
81+
}),
82+
nodeResolve({
83+
preferBuiltins: true
84+
}),
85+
commonjs(),
86+
typescript({
87+
tsconfig: './tsconfig.json',
88+
declarationDir: 'dist/cjs',
89+
outDir: 'dist/cjs',
90+
noEmitOnError: true
91+
}),
92+
{
93+
name: 'emit-cjs-package-json',
94+
generateBundle() {
95+
this.emitFile({
96+
type: 'asset',
97+
fileName: 'package.json',
98+
source: JSON.stringify({ type: 'commonjs' }, null, 2)
99+
});
100+
}
101+
},
102+
...(options.plugins ?? [])
103+
]
104+
}
105+
]
66106
}
67107

68-
export default createRollupConfig
108+
export default createRollupConfig

babel.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module.exports = api => {
99
presets.push(['@babel/preset-env', {targets: {node: 'current'}}])
1010
presets.push('@babel/preset-typescript')
1111
overrides.push({
12-
test: '**/node_modules/react-native/**/*',
12+
test: ['node_modules/react-native/**/*', 'node_modules/@react-native/**/*'],
1313
presets: ['module:metro-react-native-babel-preset', '@babel/preset-typescript']
1414
})
1515
overrides.push({

config/electron-jest.config.js

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,64 @@
1+
// these paths must be specified because otherwise typescript relies on the
2+
// "main" field in each package.json file, which points to the compiled JS and
3+
// we want to run Jest against the TS source
4+
const paths = {
5+
// @bugsnag/core must resolve to source so that module-level singleton state
6+
// (e.g. clone-client's onCloneCallbacks) is shared across jest.isolateModules
7+
// boundaries. Without this, bundled dist creates duplicate state.
8+
'@bugsnag/core': ['./packages/core/src/index.ts']
9+
}
10+
11+
const moduleNameMapper = Object.fromEntries(
12+
Object.entries(paths)
13+
.map(([name, directories]) => [
14+
`^${name}$`,
15+
directories.map(directory => directory.replace('./', '<rootDir>/'))
16+
])
17+
)
18+
19+
const defaultModuleConfig = {
20+
preset: 'ts-jest/presets/js-with-ts',
21+
moduleNameMapper,
22+
transform: {
23+
'^.+\\.m?[tj]sx?$': [
24+
'ts-jest',
25+
{
26+
isolatedModules: true,
27+
tsconfig: {
28+
module: 'commonjs',
29+
target: 'ES2019',
30+
esModuleInterop: true,
31+
allowSyntheticDefaultImports: true,
32+
allowJs: true,
33+
skipLibCheck: true,
34+
jsx: 'react',
35+
paths
36+
}
37+
}
38+
]
39+
}
40+
}
41+
142
module.exports = {
243
projects: [
344
{
4-
resolver: '<rootDir>/jest/node-exports-resolver',
45+
...defaultModuleConfig,
546
setupFilesAfterEnv: ['<rootDir>/test/electron/setup.ts'],
647
clearMocks: true,
748
modulePathIgnorePatterns: ['.verdaccio', 'fixtures', 'examples'],
849
displayName: 'electron main',
9-
runner: '@jest-runner/electron/main',
50+
runner: '@kayahr/jest-electron-runner/main',
51+
testEnvironment: 'node',
1052
testMatch: ['**/test/**/*.test-main.ts']
1153
},
1254
{
13-
resolver: '<rootDir>/jest/node-exports-resolver',
55+
...defaultModuleConfig,
1456
setupFilesAfterEnv: ['<rootDir>/test/electron/setup.ts'],
1557
clearMocks: true,
1658
modulePathIgnorePatterns: ['.verdaccio', 'fixtures', 'examples'],
1759
displayName: 'electron renderer',
18-
runner: '@jest-runner/electron',
60+
runner: '@kayahr/jest-electron-runner',
61+
testEnvironment: '@kayahr/jest-electron-runner/environment',
1962
testMatch: ['**/test/**/*.test-renderer.ts']
2063
}
2164
]

dockerfiles/Dockerfile.ci

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ RUN apk add --update bash python3 make gcc g++ musl-dev xvfb-run curl
66
WORKDIR /app
77

88
COPY package*.json ./
9-
COPY babel.config.js lerna.json eslint.config.mjs jest.config.js tsconfig.json ./
9+
COPY babel.config.js lerna.json eslint.config.mjs jest.config.js tsconfig.json tsconfig.test.json ./
1010
COPY jest ./jest
1111
ADD min_packages.tar .
1212
COPY .rollup ./.rollup

0 commit comments

Comments
 (0)