Skip to content

Commit 6389f7d

Browse files
committed
Simplify generation logic.
1 parent f64c953 commit 6389f7d

File tree

1 file changed

+17
-22
lines changed

1 file changed

+17
-22
lines changed

packages/integration-tests/utils/generatePage.ts

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable no-console */
21
import { Package } from '@sentry/types';
32
import { existsSync, mkdirSync, promises } from 'fs';
43
import HtmlWebpackPlugin from 'html-webpack-plugin';
@@ -9,11 +8,11 @@ import webpackConfig from '../webpack.config';
98

109
const PACKAGE_PATH = '../../packages';
1110

12-
const bundleKey = process.env.PW_BUNDLE || '';
13-
const useCompiledModule = (bundleKey && bundleKey === 'esm') || bundleKey === 'dist';
11+
const bundleKey = process.env.PW_BUNDLE;
12+
const useCompiledModule = bundleKey && (bundleKey === 'esm' || bundleKey === 'dist');
1413
const useBundle = bundleKey && !useCompiledModule;
1514

16-
const TEST_PATHS: Record<string, Record<string, string>> = {
15+
const BUNDLE_PATHS: Record<string, Record<string, string>> = {
1716
browser: {
1817
dist: 'dist/index.js',
1918
esm: 'esm/index.js',
@@ -43,26 +42,20 @@ async function generateSentryAlias(): Promise<Record<string, string>> {
4342

4443
return Object.fromEntries(
4544
await Promise.all(
46-
dirents.map(async packageName => {
45+
dirents.map(async d => {
4746
const packageJSON: Package = JSON.parse(
48-
(
49-
await promises.readFile(path.resolve(PACKAGE_PATH, packageName, 'package.json'), { encoding: 'utf-8' })
50-
).toString(),
47+
(await promises.readFile(path.resolve(PACKAGE_PATH, d, 'package.json'), { encoding: 'utf-8' })).toString(),
5148
);
5249

53-
const packagePath = path.resolve(PACKAGE_PATH, packageName);
50+
const modulePath = path.resolve(PACKAGE_PATH, d);
5451

55-
if (useCompiledModule && TEST_PATHS[packageName]) {
56-
const bundlePath = path.resolve(packagePath, TEST_PATHS[packageName][bundleKey]);
57-
58-
if (!existsSync(bundlePath)) {
59-
console.warn(`${bundlePath} is not found. Try building the package before running tests.`);
60-
}
52+
if (useCompiledModule && bundleKey && BUNDLE_PATHS[d][bundleKey]) {
53+
const bundlePath = path.resolve(modulePath, BUNDLE_PATHS[d][bundleKey]);
6154

6255
return [packageJSON['name'], bundlePath];
6356
}
6457

65-
return [packageJSON['name'], packagePath];
58+
return [packageJSON['name'], modulePath];
6659
}),
6760
),
6861
);
@@ -83,11 +76,12 @@ export async function generatePage(
8376
mkdirSync(localPath, { recursive: true });
8477
}
8578

86-
const bundlesToInject = useBundle
87-
? ['browser', 'tracing'].map(sentryPackage =>
88-
path.resolve(PACKAGE_PATH, sentryPackage, TEST_PATHS[sentryPackage][bundleKey]),
89-
)
90-
: [];
79+
const bundlesToInject =
80+
useBundle && bundleKey
81+
? ['browser', 'tracing'].map(sentryPackage =>
82+
path.resolve(PACKAGE_PATH, sentryPackage, BUNDLE_PATHS[sentryPackage][bundleKey]),
83+
)
84+
: [];
9185

9286
const initializationEntry = bundlesToInject.concat(initializationPath);
9387

@@ -111,7 +105,8 @@ export async function generatePage(
111105
filename: 'index.html',
112106
template: templatePath,
113107
initialization: 'initialization.bundle.js',
114-
subject: `subject.bundle.js`,
108+
subject: 'subject.bundle.js',
109+
inject: false,
115110
}),
116111
],
117112
}),

0 commit comments

Comments
 (0)