diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4c009ac08166..d35d83396317 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -276,9 +276,26 @@ jobs: ${{ github.workspace }}/packages/serverless/dist-awslambda-layer/*.zip job_browser_playwright_tests: - name: Browser Playwright Tests + name: Browser Playwright Tests (${{ matrix.bundle }} - tracing_only = ${{ matrix.tracing_only }}) needs: job_build runs-on: ubuntu-latest + strategy: + matrix: + bundle: + - esm + - cjs + - bundle_es5 + - bundle_es5_min + - bundle_es6 + - bundle_es6_min + tracing_only: + - true + - false + exclude: + - bundle: esm + tracing_only: true + - bundle: cjs + tracing_only: true steps: - name: Check out current commit (${{ github.sha }}) uses: actions/checkout@v2 @@ -297,6 +314,9 @@ jobs: path: ${{ env.CACHED_BUILD_PATHS }} key: ${{ env.BUILD_CACHE_KEY }} - name: Run Playwright tests + env: + PW_BUNDLE: ${{ matrix.bundle }} + PW_TRACING_ONLY: ${{ matrix.tracing_only }} run: | cd packages/integration-tests yarn run playwright install-deps webkit diff --git a/packages/integration-tests/README.md b/packages/integration-tests/README.md index 98555b642fd0..47aa171cec21 100644 --- a/packages/integration-tests/README.md +++ b/packages/integration-tests/README.md @@ -56,6 +56,9 @@ To filter tests by their title: You can refer to [Playwright documentation](https://playwright.dev/docs/test-cli) for other CLI options. +You can set env variable `PW_BUNDLE` to set specific build or bundle to test against. +Available options: `esm`, `cjs`, `bundle_es5`, `bundle_es5_min`, `bundle_es6`, `bundle_es6_min` + ### Troubleshooting Apart from [Playwright-specific issues](https://playwright.dev/docs/troubleshooting), below are common issues that might occur while writing tests for Sentry Browser SDK. diff --git a/packages/integration-tests/package.json b/packages/integration-tests/package.json index b4aa93b57139..daaace6ea9b8 100644 --- a/packages/integration-tests/package.json +++ b/packages/integration-tests/package.json @@ -13,16 +13,21 @@ "lint": "run-s lint:prettier lint:eslint", "lint:eslint": "eslint . --cache --cache-location '../../eslintcache/' --format stylish", "lint:prettier": "prettier --check \"{suites,utils}/**/*.ts\"", - "test:ci": "playwright test ./suites --browser='all' --reporter='line'", "type-check": "tsc", "pretest": "yarn clean && yarn type-check", - "test": "playwright test ./suites" + "test": "playwright test ./suites", + "test:bundle:es5": "PW_BUNDLE=bundle_es5 yarn test", + "test:bundle:es5:min": "PW_BUNDLE=bundle_es5_min yarn test", + "test:bundle:es6": "PW_BUNDLE=bundle_es6 yarn test", + "test:bundle:es6:min": "PW_BUNDLE=bundle_es6_min yarn test", + "test:cjs": "PW_BUNDLE=cjs yarn test", + "test:esm": "PW_BUNDLE=esm yarn test", + "test:ci": "playwright test ./suites --browser='all' --reporter='line'" }, "dependencies": { "@babel/preset-typescript": "^7.16.7", "@playwright/test": "^1.17.0", "babel-loader": "^8.2.2", - "handlebars-loader": "^1.7.1", "html-webpack-plugin": "^5.5.0", "playwright": "^1.17.1", "typescript": "^4.5.2", diff --git a/packages/integration-tests/suites/public-api/addBreadcrumb/template.hbs b/packages/integration-tests/suites/public-api/addBreadcrumb/template.hbs deleted file mode 100644 index a28a09b7b485..000000000000 --- a/packages/integration-tests/suites/public-api/addBreadcrumb/template.hbs +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - diff --git a/packages/integration-tests/suites/public-api/captureException/template.hbs b/packages/integration-tests/suites/public-api/captureException/template.hbs deleted file mode 100644 index a28a09b7b485..000000000000 --- a/packages/integration-tests/suites/public-api/captureException/template.hbs +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - diff --git a/packages/integration-tests/suites/public-api/captureMessage/template.hbs b/packages/integration-tests/suites/public-api/captureMessage/template.hbs deleted file mode 100644 index a28a09b7b485..000000000000 --- a/packages/integration-tests/suites/public-api/captureMessage/template.hbs +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - diff --git a/packages/integration-tests/suites/public-api/configureScope/template.hbs b/packages/integration-tests/suites/public-api/configureScope/template.hbs deleted file mode 100644 index a28a09b7b485..000000000000 --- a/packages/integration-tests/suites/public-api/configureScope/template.hbs +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - diff --git a/packages/integration-tests/suites/public-api/setContext/template.hbs b/packages/integration-tests/suites/public-api/setContext/template.hbs deleted file mode 100644 index a28a09b7b485..000000000000 --- a/packages/integration-tests/suites/public-api/setContext/template.hbs +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - diff --git a/packages/integration-tests/suites/public-api/setExtra/template.hbs b/packages/integration-tests/suites/public-api/setExtra/template.hbs deleted file mode 100644 index a28a09b7b485..000000000000 --- a/packages/integration-tests/suites/public-api/setExtra/template.hbs +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - diff --git a/packages/integration-tests/suites/public-api/setExtras/template.hbs b/packages/integration-tests/suites/public-api/setExtras/template.hbs deleted file mode 100644 index a28a09b7b485..000000000000 --- a/packages/integration-tests/suites/public-api/setExtras/template.hbs +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - diff --git a/packages/integration-tests/suites/public-api/setTag/template.hbs b/packages/integration-tests/suites/public-api/setTag/template.hbs deleted file mode 100644 index a28a09b7b485..000000000000 --- a/packages/integration-tests/suites/public-api/setTag/template.hbs +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - diff --git a/packages/integration-tests/suites/public-api/setTags/template.hbs b/packages/integration-tests/suites/public-api/setTags/template.hbs deleted file mode 100644 index a28a09b7b485..000000000000 --- a/packages/integration-tests/suites/public-api/setTags/template.hbs +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - diff --git a/packages/integration-tests/suites/public-api/setUser/template.hbs b/packages/integration-tests/suites/public-api/setUser/template.hbs deleted file mode 100644 index a28a09b7b485..000000000000 --- a/packages/integration-tests/suites/public-api/setUser/template.hbs +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - diff --git a/packages/integration-tests/suites/public-api/showReportDialog/template.hbs b/packages/integration-tests/suites/public-api/showReportDialog/template.hbs deleted file mode 100644 index a28a09b7b485..000000000000 --- a/packages/integration-tests/suites/public-api/showReportDialog/template.hbs +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - diff --git a/packages/integration-tests/suites/public-api/startTransaction/template.hbs b/packages/integration-tests/suites/public-api/startTransaction/template.hbs deleted file mode 100644 index a28a09b7b485..000000000000 --- a/packages/integration-tests/suites/public-api/startTransaction/template.hbs +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - diff --git a/packages/integration-tests/suites/public-api/withScope/template.hbs b/packages/integration-tests/suites/public-api/withScope/template.hbs deleted file mode 100644 index a28a09b7b485..000000000000 --- a/packages/integration-tests/suites/public-api/withScope/template.hbs +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - diff --git a/packages/integration-tests/suites/sessions/start-session/template.hbs b/packages/integration-tests/suites/sessions/start-session/template.hbs deleted file mode 100644 index 49ff0beab214..000000000000 --- a/packages/integration-tests/suites/sessions/start-session/template.hbs +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - Navigate - - - diff --git a/packages/integration-tests/suites/sessions/start-session/template.html b/packages/integration-tests/suites/sessions/start-session/template.html new file mode 100644 index 000000000000..56f0ebd79a95 --- /dev/null +++ b/packages/integration-tests/suites/sessions/start-session/template.html @@ -0,0 +1,8 @@ + + + + + + Navigate + + diff --git a/packages/integration-tests/suites/sessions/update-session/template.hbs b/packages/integration-tests/suites/sessions/update-session/template.hbs deleted file mode 100644 index 114ce1f75f83..000000000000 --- a/packages/integration-tests/suites/sessions/update-session/template.hbs +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - diff --git a/packages/integration-tests/suites/sessions/update-session/template.html b/packages/integration-tests/suites/sessions/update-session/template.html new file mode 100644 index 000000000000..9c47c4b43402 --- /dev/null +++ b/packages/integration-tests/suites/sessions/update-session/template.html @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/packages/integration-tests/suites/tracing/browsertracing/backgroundtab-custom/template.hbs b/packages/integration-tests/suites/tracing/browsertracing/backgroundtab-custom/template.html similarity index 51% rename from packages/integration-tests/suites/tracing/browsertracing/backgroundtab-custom/template.hbs rename to packages/integration-tests/suites/tracing/browsertracing/backgroundtab-custom/template.html index 4dbbc15044dc..01d89ea55e60 100644 --- a/packages/integration-tests/suites/tracing/browsertracing/backgroundtab-custom/template.hbs +++ b/packages/integration-tests/suites/tracing/browsertracing/backgroundtab-custom/template.html @@ -1,11 +1,9 @@ - - + - diff --git a/packages/integration-tests/suites/tracing/browsertracing/backgroundtab-pageload/template.hbs b/packages/integration-tests/suites/tracing/browsertracing/backgroundtab-pageload/template.hbs deleted file mode 100644 index 1171fc0676c3..000000000000 --- a/packages/integration-tests/suites/tracing/browsertracing/backgroundtab-pageload/template.hbs +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - ] - - - - diff --git a/packages/integration-tests/suites/tracing/browsertracing/backgroundtab-pageload/template.html b/packages/integration-tests/suites/tracing/browsertracing/backgroundtab-pageload/template.html new file mode 100644 index 000000000000..b92533a08f01 --- /dev/null +++ b/packages/integration-tests/suites/tracing/browsertracing/backgroundtab-pageload/template.html @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/packages/integration-tests/suites/tracing/browsertracing/meta/template.hbs b/packages/integration-tests/suites/tracing/browsertracing/meta/template.hbs deleted file mode 100644 index d04e3bf11602..000000000000 --- a/packages/integration-tests/suites/tracing/browsertracing/meta/template.hbs +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - diff --git a/packages/integration-tests/suites/tracing/browsertracing/meta/template.html b/packages/integration-tests/suites/tracing/browsertracing/meta/template.html new file mode 100644 index 000000000000..0afff8864522 --- /dev/null +++ b/packages/integration-tests/suites/tracing/browsertracing/meta/template.html @@ -0,0 +1,6 @@ + + + + + + diff --git a/packages/integration-tests/suites/tracing/browsertracing/template.hbs b/packages/integration-tests/suites/tracing/browsertracing/template.hbs deleted file mode 100644 index d91677daaab5..000000000000 --- a/packages/integration-tests/suites/tracing/browsertracing/template.hbs +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - diff --git a/packages/integration-tests/suites/tracing/metrics/connection-rtt/template.hbs b/packages/integration-tests/suites/tracing/metrics/connection-rtt/template.hbs deleted file mode 100644 index c798102c2014..000000000000 --- a/packages/integration-tests/suites/tracing/metrics/connection-rtt/template.hbs +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - -
Rendered
- - diff --git a/packages/integration-tests/suites/tracing/metrics/connection-rtt/template.html b/packages/integration-tests/suites/tracing/metrics/connection-rtt/template.html new file mode 100644 index 000000000000..ae6d3eaf7b5c --- /dev/null +++ b/packages/integration-tests/suites/tracing/metrics/connection-rtt/template.html @@ -0,0 +1,8 @@ + + + + + +
Rendered
+ + diff --git a/packages/integration-tests/suites/tracing/metrics/pageload-resource-spans/template.hbs b/packages/integration-tests/suites/tracing/metrics/pageload-resource-spans/template.html similarity index 55% rename from packages/integration-tests/suites/tracing/metrics/pageload-resource-spans/template.hbs rename to packages/integration-tests/suites/tracing/metrics/pageload-resource-spans/template.html index 4f0f2567a2f7..7f1041910665 100644 --- a/packages/integration-tests/suites/tracing/metrics/pageload-resource-spans/template.hbs +++ b/packages/integration-tests/suites/tracing/metrics/pageload-resource-spans/template.html @@ -1,14 +1,11 @@ - - - - + - + Rendered diff --git a/packages/integration-tests/suites/tracing/metrics/template.hbs b/packages/integration-tests/suites/tracing/metrics/template.hbs deleted file mode 100644 index 17beca810fbd..000000000000 --- a/packages/integration-tests/suites/tracing/metrics/template.hbs +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - Rendered - - diff --git a/packages/integration-tests/suites/tracing/metrics/web-vitals-cls/template.hbs b/packages/integration-tests/suites/tracing/metrics/web-vitals-cls/template.hbs deleted file mode 100644 index faa6f236b9a4..000000000000 --- a/packages/integration-tests/suites/tracing/metrics/web-vitals-cls/template.hbs +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - -
- - - diff --git a/packages/integration-tests/suites/tracing/metrics/web-vitals-cls/template.html b/packages/integration-tests/suites/tracing/metrics/web-vitals-cls/template.html new file mode 100644 index 000000000000..f778ca4d3726 --- /dev/null +++ b/packages/integration-tests/suites/tracing/metrics/web-vitals-cls/template.html @@ -0,0 +1,8 @@ + + + + + +
+ + diff --git a/packages/integration-tests/suites/tracing/metrics/web-vitals-fid/template.hbs b/packages/integration-tests/suites/tracing/metrics/web-vitals-fid/template.html similarity index 57% rename from packages/integration-tests/suites/tracing/metrics/web-vitals-fid/template.hbs rename to packages/integration-tests/suites/tracing/metrics/web-vitals-fid/template.html index 40c850ddb608..424014a6e194 100644 --- a/packages/integration-tests/suites/tracing/metrics/web-vitals-fid/template.hbs +++ b/packages/integration-tests/suites/tracing/metrics/web-vitals-fid/template.html @@ -1,9 +1,6 @@ - - - diff --git a/packages/integration-tests/suites/tracing/metrics/web-vitals-fp-fcp/template.hbs b/packages/integration-tests/suites/tracing/metrics/web-vitals-fp-fcp/template.hbs deleted file mode 100644 index c798102c2014..000000000000 --- a/packages/integration-tests/suites/tracing/metrics/web-vitals-fp-fcp/template.hbs +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - -
Rendered
- - diff --git a/packages/integration-tests/suites/tracing/metrics/web-vitals-fp-fcp/template.html b/packages/integration-tests/suites/tracing/metrics/web-vitals-fp-fcp/template.html new file mode 100644 index 000000000000..ae6d3eaf7b5c --- /dev/null +++ b/packages/integration-tests/suites/tracing/metrics/web-vitals-fp-fcp/template.html @@ -0,0 +1,8 @@ + + + + + +
Rendered
+ + diff --git a/packages/integration-tests/suites/tracing/metrics/web-vitals-lcp/template.hbs b/packages/integration-tests/suites/tracing/metrics/web-vitals-lcp/template.hbs deleted file mode 100644 index d37c2df3da81..000000000000 --- a/packages/integration-tests/suites/tracing/metrics/web-vitals-lcp/template.hbs +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - -
- - - - diff --git a/packages/integration-tests/suites/tracing/metrics/web-vitals-lcp/template.html b/packages/integration-tests/suites/tracing/metrics/web-vitals-lcp/template.html new file mode 100644 index 000000000000..2605d0a2595e --- /dev/null +++ b/packages/integration-tests/suites/tracing/metrics/web-vitals-lcp/template.html @@ -0,0 +1,9 @@ + + + + + +
+ + + diff --git a/packages/integration-tests/suites/tracing/metrics/web-vitals-ttfb/template.hbs b/packages/integration-tests/suites/tracing/metrics/web-vitals-ttfb/template.hbs deleted file mode 100644 index c798102c2014..000000000000 --- a/packages/integration-tests/suites/tracing/metrics/web-vitals-ttfb/template.hbs +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - -
Rendered
- - diff --git a/packages/integration-tests/suites/tracing/metrics/web-vitals-ttfb/template.html b/packages/integration-tests/suites/tracing/metrics/web-vitals-ttfb/template.html new file mode 100644 index 000000000000..ae6d3eaf7b5c --- /dev/null +++ b/packages/integration-tests/suites/tracing/metrics/web-vitals-ttfb/template.html @@ -0,0 +1,8 @@ + + + + + +
Rendered
+ + diff --git a/packages/integration-tests/suites/tracing/request/template.hbs b/packages/integration-tests/suites/tracing/request/template.hbs deleted file mode 100644 index a28a09b7b485..000000000000 --- a/packages/integration-tests/suites/tracing/request/template.hbs +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - diff --git a/packages/integration-tests/utils/defaults/template.html b/packages/integration-tests/utils/defaults/template.html new file mode 100644 index 000000000000..132155c6a181 --- /dev/null +++ b/packages/integration-tests/utils/defaults/template.html @@ -0,0 +1,6 @@ + + + + + + diff --git a/packages/integration-tests/utils/fixtures.ts b/packages/integration-tests/utils/fixtures.ts index 327bfa540252..845a7637b177 100644 --- a/packages/integration-tests/utils/fixtures.ts +++ b/packages/integration-tests/utils/fixtures.ts @@ -11,7 +11,13 @@ const getAsset = (assetDir: string, asset: string): string => { return assetPath; } - return `${path.dirname(assetDir)}/${asset}`; + const parentDirAssetPath = `${path.dirname(assetDir)}/${asset}`; + + if (fs.existsSync(parentDirAssetPath)) { + return parentDirAssetPath; + } + + return `utils/defaults/${asset}`; }; export type TestOptions = { @@ -33,7 +39,7 @@ const sentryTest = base.extend({ if (!fs.existsSync(pagePath)) { const testDir = path.dirname(testInfo.file); const subject = getAsset(testDir, 'subject.js'); - const template = getAsset(testDir, 'template.hbs'); + const template = getAsset(testDir, 'template.html'); const init = getAsset(testDir, 'init.js'); await generatePage(init, subject, template, testDir); diff --git a/packages/integration-tests/utils/generatePage.ts b/packages/integration-tests/utils/generatePage.ts index 63ddcc3f4ced..fea623129e93 100644 --- a/packages/integration-tests/utils/generatePage.ts +++ b/packages/integration-tests/utils/generatePage.ts @@ -1,33 +1,9 @@ -import { Package } from '@sentry/types'; -import { existsSync, mkdirSync, promises } from 'fs'; +import { existsSync, mkdirSync } from 'fs'; import HtmlWebpackPlugin from 'html-webpack-plugin'; -import path from 'path'; import webpack from 'webpack'; import webpackConfig from '../webpack.config'; - -const PACKAGE_PATH = '../../packages'; - -/** - * Generate webpack aliases based on packages in monorepo - * Example of an alias: '@sentry/serverless': 'path/to/sentry-javascript/packages/serverless', - */ -async function generateSentryAlias(): Promise> { - const dirents = (await promises.readdir(PACKAGE_PATH, { withFileTypes: true })) - .filter(dirent => dirent.isDirectory()) - .map(dir => dir.name); - - return Object.fromEntries( - await Promise.all( - dirents.map(async d => { - const packageJSON: Package = JSON.parse( - (await promises.readFile(path.resolve(PACKAGE_PATH, d, 'package.json'), { encoding: 'utf-8' })).toString(), - ); - return [packageJSON['name'], path.resolve(PACKAGE_PATH, d)]; - }), - ), - ); -} +import SentryScenarioGenerationPlugin from './generatePlugin'; export async function generatePage( initializationPath: string, @@ -38,8 +14,6 @@ export async function generatePage( const localPath = `${outPath}/dist`; const bundlePath = `${localPath}/index.html`; - const alias = await generateSentryAlias(); - if (!existsSync(localPath)) { mkdirSync(localPath, { recursive: true }); } @@ -48,9 +22,6 @@ export async function generatePage( await new Promise((resolve, reject) => { const compiler = webpack( webpackConfig({ - resolve: { - alias, - }, entry: { initialization: initializationPath, subject: subjectPath, @@ -60,12 +31,11 @@ export async function generatePage( filename: '[name].bundle.js', }, plugins: [ + new SentryScenarioGenerationPlugin(), new HtmlWebpackPlugin({ filename: 'index.html', template: templatePath, - initialization: 'initialization.bundle.js', - subject: `subject.bundle.js`, - inject: false, + inject: 'body', }), ], }), diff --git a/packages/integration-tests/utils/generatePlugin.ts b/packages/integration-tests/utils/generatePlugin.ts new file mode 100644 index 000000000000..994b2a1a9125 --- /dev/null +++ b/packages/integration-tests/utils/generatePlugin.ts @@ -0,0 +1,125 @@ +import { Package } from '@sentry/types'; +import { readdirSync, readFileSync } from 'fs'; +import HtmlWebpackPlugin, { createHtmlTagObject } from 'html-webpack-plugin'; +import path from 'path'; +import { Compiler } from 'webpack'; + +const PACKAGES_DIR = '../../packages'; + +const tracingOnly = process.env.PW_TRACING_ONLY === 'true'; +const bundleKey = process.env.PW_BUNDLE; + +// `esm` and `cjs` builds are modules that can be imported / aliased by webpack +const useCompiledModule = bundleKey === 'esm' || bundleKey === 'cjs'; + +// Bundles need to be injected into HTML before Sentry initialization. +const useBundle = bundleKey && !useCompiledModule; + +const BUNDLE_PATHS: Record> = { + browser: { + cjs: 'dist/index.js', + esm: 'esm/index.js', + bundle_es5: 'build/bundle.js', + bundle_es5_min: 'build/bundle.min.js', + bundle_es6: 'build/bundle.es6.js', + bundle_es6_min: 'build/bundle.es6.min.js', + }, + tracing: { + cjs: 'dist/index.js', + esm: 'esm/index.js', + bundle_es5: 'build/bundle.tracing.js', + bundle_es5_min: 'build/bundle.tracing.min.js', + // `tracing` doesn't have an es6 build yet + bundle_es6: 'build/bundle.tracing.js', + bundle_es6_min: 'build/bundle.tracing.min.js', + }, +}; + +/* + * Generate webpack aliases based on packages in monorepo + * + * When using compiled versions of the tracing and browser packages, their aliases look for example like + * '@sentry/browser': 'path/to/sentry-javascript/packages/browser/esm/index.js' + * and all other monorepo packages' aliases look for example like + * '@sentry/hub': 'path/to/sentry-javascript/packages/hub' + * + * When using bundled versions of the tracing and browser packages, all aliases look for example like + * '@sentry/browser': false + * so that the compiled versions aren't included + */ +function generateSentryAlias(): Record { + const packageNames = readdirSync(PACKAGES_DIR, { withFileTypes: true }) + .filter(dirent => dirent.isDirectory()) + .map(dir => dir.name); + + return Object.fromEntries( + packageNames.map(packageName => { + const packageJSON: Package = JSON.parse( + readFileSync(path.resolve(PACKAGES_DIR, packageName, 'package.json'), { encoding: 'utf-8' }).toString(), + ); + + const modulePath = path.resolve(PACKAGES_DIR, packageName); + + if (useCompiledModule && bundleKey && BUNDLE_PATHS[packageName]?.[bundleKey]) { + const bundlePath = path.resolve(modulePath, BUNDLE_PATHS[packageName][bundleKey]); + + return [packageJSON['name'], bundlePath]; + } + + if (useBundle && bundleKey) { + // If we're injecting a bundle, ignore the webpack imports. + return [packageJSON['name'], false]; + } + + return [packageJSON['name'], modulePath]; + }), + ); +} + +class SentryScenarioGenerationPlugin { + public requiresTracing: boolean = false; + + private _name: string = 'SentryScenarioGenerationPlugin'; + + public apply(compiler: Compiler): void { + compiler.options.resolve.alias = generateSentryAlias(); + compiler.options.externals = + useBundle && bundleKey + ? { + // To help Webpack resolve Sentry modules in `import` statements in cases where they're provided in bundles rather than in `node_modules` + '@sentry/browser': 'Sentry', + '@sentry/tracing': 'Sentry', + } + : {}; + + // Checking if the current scenario has imported `@sentry/tracing`. + compiler.hooks.normalModuleFactory.tap(this._name, factory => { + factory.hooks.parser.for('javascript/auto').tap(this._name, parser => { + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access + parser.hooks.import.tap(this._name, (_statement: unknown, source: string) => { + if (source === '@sentry/tracing') { + this.requiresTracing = true; + } + }); + }); + }); + + compiler.hooks.compilation.tap(this._name, compilation => { + HtmlWebpackPlugin.getHooks(compilation).alterAssetTags.tapAsync(this._name, (data, cb) => { + if (useBundle && bundleKey) { + const useTracingBundle = tracingOnly || this.requiresTracing; + const bundleName = useTracingBundle ? 'tracing' : 'browser'; + const bundleObject = createHtmlTagObject('script', { + src: path.resolve(PACKAGES_DIR, bundleName, BUNDLE_PATHS[bundleName][bundleKey]), + }); + + data.assetTags.scripts.unshift(bundleObject); + } + + cb(null, data); + }); + }); + } +} + +export default SentryScenarioGenerationPlugin; diff --git a/packages/integration-tests/webpack.config.ts b/packages/integration-tests/webpack.config.ts index 44f62e029ba9..ff065a044208 100644 --- a/packages/integration-tests/webpack.config.ts +++ b/packages/integration-tests/webpack.config.ts @@ -1,6 +1,6 @@ import { Configuration } from 'webpack'; -const config = function(userConfig: Record): Configuration { +const config = function (userConfig: Record): Configuration { return { ...userConfig, mode: 'none', @@ -12,11 +12,6 @@ const config = function(userConfig: Record): Configuration { loader: 'babel-loader', options: { presets: [['@babel/preset-typescript', { allowNamespaces: true }]] }, }, - { - test: /\.hbs$/, - exclude: /node_modules/, - loader: 'handlebars-loader', - }, ], }, stats: 'errors-only', diff --git a/yarn.lock b/yarn.lock index d6f23d692ba3..13775efb1838 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5038,7 +5038,7 @@ async@^3.0.1: resolved "https://registry.yarnpkg.com/async/-/async-3.2.0.tgz#b3a2685c5ebb641d3de02d161002c60fc9f85720" integrity sha512-TR2mEZFVOj2pLStYxLht7TyfuRzaydfpxr3k9RpHIzMgw7A64dzsdqCxH1WJyQdoe8T10nDXd9wnEigmiuHIZw== -async@~0.2.10, async@~0.2.9: +async@~0.2.9: version "0.2.10" resolved "https://registry.yarnpkg.com/async/-/async-0.2.10.tgz#b6bbe0b0674b9d719708ca38de8c237cb526c3d1" integrity sha1-trvgsGdLnXGXCMo43owjfLUmw9E= @@ -5919,11 +5919,6 @@ better-assert@~1.0.0: dependencies: callsite "1.0.0" -big.js@^3.1.3: - version "3.2.0" - resolved "https://registry.yarnpkg.com/big.js/-/big.js-3.2.0.tgz#a5fc298b81b9e0dca2e458824784b65c52ba588e" - integrity sha512-+hN/Zh2D08Mx65pZ/4g5bsmNiZUuChDiQfTUQ7qJr4/kuopCr88xZsAXv6mBoZEsUI4OuGHlX59qE94K2mMW8Q== - big.js@^5.2.2: version "5.2.2" resolved "https://registry.yarnpkg.com/big.js/-/big.js-5.2.2.tgz#65f0af382f578bcdc742bd9c281e9cb2d7768328" @@ -10649,11 +10644,6 @@ fast-text-encoding@^1.0.0, fast-text-encoding@^1.0.3: resolved "https://registry.yarnpkg.com/fast-text-encoding/-/fast-text-encoding-1.0.3.tgz#ec02ac8e01ab8a319af182dae2681213cfe9ce53" integrity sha512-dtm4QZH9nZtcDt8qJiOH9fcQd1NAgi+K1O2DbE6GG1PPCK/BWfOH3idCTRQ4ImXRUOyopDEgDEnVEE7Y/2Wrig== -fastparse@^1.0.0: - version "1.1.2" - resolved "https://registry.yarnpkg.com/fastparse/-/fastparse-1.1.2.tgz#91728c5a5942eced8531283c79441ee4122c35a9" - integrity sha512-483XLLxTVIwWK3QTrMGRqUfUpoOs/0hbQrl2oz4J0pAcm3A3bu84wxTFqGqkJzewCLdME38xJLJAxBABfQT8sQ== - fastq@^1.6.0: version "1.11.0" resolved "https://registry.yarnpkg.com/fastq/-/fastq-1.11.0.tgz#bb9fb955a07130a918eb63c1f5161cc32a5d0858" @@ -11863,16 +11853,6 @@ gzip-size@^6.0.0: dependencies: duplexer "^0.1.2" -handlebars-loader@^1.7.1: - version "1.7.1" - resolved "https://registry.yarnpkg.com/handlebars-loader/-/handlebars-loader-1.7.1.tgz#07088f09d8a559344908f7c88c68c0ffdacc555d" - integrity sha512-Q+Z/hDPQzU8ZTlVnAe/0T1LHABlyhL7opNcSKcQDhmUXK2ByGTqib1Z2Tfv4Ic50WqDcLFWQcOb3mhjcBRbscQ== - dependencies: - async "~0.2.10" - fastparse "^1.0.0" - loader-utils "1.0.x" - object-assign "^4.1.0" - handlebars@^4.0.1, handlebars@^4.0.4, handlebars@^4.3.1, handlebars@^4.7.3, handlebars@^4.7.6: version "4.7.7" resolved "https://registry.yarnpkg.com/handlebars/-/handlebars-4.7.7.tgz#9ce33416aad02dbd6c8fafa8240d5d98004945a1" @@ -14052,7 +14032,7 @@ json5@2.x, json5@^2.1.2: dependencies: minimist "^1.2.5" -json5@^0.5.0, json5@^0.5.1: +json5@^0.5.1: version "0.5.1" resolved "https://registry.yarnpkg.com/json5/-/json5-0.5.1.tgz#1eade7acc012034ad84e2396767ead9fa5495821" integrity sha1-Hq3nrMASA0rYTiOWdn6tn6VJWCE= @@ -14555,15 +14535,6 @@ loader-runner@^4.2.0: resolved "https://registry.yarnpkg.com/loader-runner/-/loader-runner-4.2.0.tgz#d7022380d66d14c5fb1d496b89864ebcfd478384" integrity sha512-92+huvxMvYlMzMt0iIOukcwYBFpkYJdpl2xsZ7LrlayO7E8SOv+JJUEK17B/dJIHAOLMfh2dZZ/Y18WgmGtYNw== -loader-utils@1.0.x: - version "1.0.4" - resolved "https://registry.yarnpkg.com/loader-utils/-/loader-utils-1.0.4.tgz#13f56197f1523a305891248b4c7244540848426c" - integrity sha1-E/Vhl/FSOjBYkSSLTHJEVAhIQmw= - dependencies: - big.js "^3.1.3" - emojis-list "^2.0.0" - json5 "^0.5.0" - loader-utils@1.2.3: version "1.2.3" resolved "https://registry.yarnpkg.com/loader-utils/-/loader-utils-1.2.3.tgz#1ff5dc6911c9f0a062531a4c04b609406108c2c7"