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

[PLAT-12160] Convert plugin-browser-context to TypeScript #2146

Draft
wants to merge 8 commits into
base: next
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
jsx: true,
ecmaVersion: 2018
ecmaVersion: 2018,
sourceType: "module"
},
overrides: [
// linting for js files
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr-diff.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
- name: Setup node
uses: actions/setup-node@v1
with:
node-version: 14.x
node-version: 18.x

- name: Checkout base branch
uses: actions/checkout@v1
Expand Down
52 changes: 52 additions & 0 deletions .rollup/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import typescript from '@rollup/plugin-typescript'
import replace from '@rollup/plugin-replace'
import fs from 'fs'

const defaultOptions = () => ({
// additional variables to define with '@rollup/plugin-replace'
// e.g. '{ ABC: 123 }' is equivalent to running 'globalThis.ABC = 123'
additionalReplacements: {},
// additional external dependencies, such as '@bugsnag/browser'
external: [],
// the entry point for the bundle
internal: undefined,
})

function createRollupConfig (options = defaultOptions()) {
const packageJson = JSON.parse(fs.readFileSync(`${process.cwd()}/package.json`))

return {
input: options.internal || 'lib/index.ts',
output: {
dir: 'dist',
format: 'esm',
preserveModules: true,
generatedCode: {
preset: 'es2015',
},
},
external: ['@bugsnag/core'].concat(options.external),
plugins: [
replace({
preventAssignment: true,
values: {
__VERSION__: packageJson.version,
...options.additionalReplacements,
},
}),
typescript({
// don't output anything if there's a TS error
noEmitOnError: true,
// turn on declaration files and declaration maps
compilerOptions: {
declaration: true,
declarationMap: true,
emitDeclarationOnly: true,
declarationDir: 'dist/types',
},
}),
],
}
}

export default createRollupConfig
16 changes: 16 additions & 0 deletions .rollup/no-tree-shaking.plugin.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// when functional components are used in JSX tags, rollup doesn't recognise them as actually being used and tree-shakes them away
// this plugin prevents that from happening by explicity telling rollup not to tree-shake the module
function noTreeShakingPlugin(files) {
return {
name: 'no-treeshaking-plugin',
transform(code, id) {
for (const file of files) {
if (id.indexOf(file) >= 0) {
return { moduleSideEffects: 'no-treeshake' }
}
}
}
}
}

export default noTreeShakingPlugin
2 changes: 1 addition & 1 deletion bin/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ cd /app/bugsnag-js

# "ci" rather than "install" ensures the process doesn't make the work tree dirty by modifying lockfiles
npm ci
npm run bootstrap -- --ci
npm run bootstrap

# check if CDN packages changed – if they didn't we don't need to upload to the CDN
BROWSER_PACKAGE_CHANGED=$(npx lerna changed --parseable | grep -c packages/js$ || test $? = 1;)
Expand Down
19 changes: 10 additions & 9 deletions dockerfiles/Dockerfile.browser
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
# CI test image for unit/lint/type tests
FROM node:14-alpine as browser-feature-builder
FROM node:18-alpine as browser-feature-builder

RUN apk add --update bash python3 make gcc g++ musl-dev xvfb-run

WORKDIR /app

COPY package*.json ./
RUN npm install
RUN npm ci --legacy-peer-deps

COPY babel.config.js lerna.json .eslintignore .eslintrc.js jest.config.js tsconfig.json ./
ADD min_packages.tar .
COPY bin ./bin
COPY .rollup ./.rollup
COPY packages ./packages
RUN npx lerna bootstrap
RUN npm run bootstrap
RUN npm run build

RUN npm pack --verbose packages/js/
Expand All @@ -26,12 +27,12 @@ RUN npm pack --verbose packages/web-worker/
COPY test/browser/features test/browser/features

WORKDIR /app/test/browser/features/fixtures
RUN npm install --no-package-lock --no-save ../../../../bugsnag-browser-*.tgz
RUN npm install --no-package-lock --no-save ../../../../bugsnag-plugin-react-*.tgz
RUN npm install --no-package-lock --no-save ../../../../bugsnag-plugin-vue-*.tgz
RUN npm install --no-package-lock --no-save ../../../../bugsnag-web-worker-*.tgz
RUN npm install --no-package-lock --legacy-peer-deps --no-save ../../../../bugsnag-browser-*.tgz
RUN npm install --no-package-lock --legacy-peer-deps --no-save ../../../../bugsnag-plugin-react-*.tgz
RUN npm install --no-package-lock --legacy-peer-deps --no-save ../../../../bugsnag-plugin-vue-*.tgz
RUN npm install --no-package-lock --legacy-peer-deps --no-save ../../../../bugsnag-web-worker-*.tgz
WORKDIR plugin_angular/ng
RUN npm install --no-package-lock --no-save \
RUN npm install --no-package-lock --legacy-peer-deps --no-save \
../../../../../../bugsnag-plugin-angular-*.tgz \
../../../../../../bugsnag-node-*.tgz \
../../../../../../bugsnag-browser-*.tgz \
Expand All @@ -40,7 +41,7 @@ RUN npm install --no-package-lock --no-save \
# install the dependencies and build each fixture
WORKDIR /app/test/browser/features/fixtures
RUN find . -name package.json -type f -mindepth 2 -maxdepth 3 ! -path "./node_modules/*" | \
xargs -I % bash -c 'cd `dirname %` && npm install --no-package-lock && npm run build'
xargs -I % bash -c 'cd `dirname %` && npm install --no-package-lock --legacy-peer-deps && npm run build'

# once the fixtures are built we no longer need node_modules and
# it makes the COPY later on much faster if we don't have them
Expand Down
7 changes: 4 additions & 3 deletions dockerfiles/Dockerfile.ci
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
# CI test image for unit/lint/type tests
FROM node:14-alpine
FROM node:18-alpine

RUN apk add --update bash python3 make gcc g++ musl-dev xvfb-run

WORKDIR /app

COPY package*.json ./
RUN npm install --unsafe-perm
RUN npm ci --legacy-peer-deps

COPY babel.config.js lerna.json .eslintignore .eslintrc.js jest.config.js tsconfig.json ./
ADD min_packages.tar .
COPY bin ./bin
COPY .rollup ./.rollup
COPY scripts ./scripts
COPY test ./test
COPY packages ./packages
RUN npx lerna bootstrap
RUN npm run bootstrap
RUN npm run build
7 changes: 4 additions & 3 deletions dockerfiles/Dockerfile.node
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
# CI test image for unit/lint/type tests
FROM node:14-alpine as node-feature-builder
FROM node:18-alpine as node-feature-builder

RUN apk add --update bash python3 make gcc g++ musl-dev xvfb-run

WORKDIR /app

COPY package*.json ./
RUN npm install
RUN npm ci --legacy-peer-deps

COPY babel.config.js lerna.json .eslintignore .eslintrc.js jest.config.js tsconfig.json ./
ADD min_packages.tar .
COPY bin ./bin
COPY .rollup ./.rollup
COPY packages ./packages
RUN npx lerna bootstrap
RUN npm run bootstrap
RUN npm run build

RUN npm pack --verbose packages/node/
Expand Down
2 changes: 1 addition & 1 deletion dockerfiles/Dockerfile.react-native-cli-tool
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# CI test image for building the CLI
FROM node:14-alpine as react-native-cli-feature-builder
FROM node:18-alpine as react-native-cli-feature-builder

WORKDIR /app

Expand Down
2 changes: 1 addition & 1 deletion dockerfiles/Dockerfile.release
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:14-alpine
FROM node:18-alpine
RUN apk add --update git bash python3 make gcc g++ openssh-client curl

RUN addgroup -S admins
Expand Down
Loading
Loading