|
1 | | -import { existsSync, mkdirSync, readFileSync, symlinkSync, unlinkSync, writeFileSync } from 'fs'; |
| 1 | +import { existsSync, mkdirSync } from 'fs'; |
2 | 2 | import HtmlWebpackPlugin from 'html-webpack-plugin'; |
3 | | -import path from 'path'; |
4 | 3 | import webpack from 'webpack'; |
5 | 4 |
|
6 | 5 | import webpackConfig from '../webpack.config'; |
7 | | -import { TEST_HOST } from './fixtures'; |
8 | 6 | import SentryScenarioGenerationPlugin from './generatePlugin'; |
9 | 7 |
|
10 | | -const LOADER_TEMPLATE = readFileSync(path.join(__dirname, '../fixtures/loader.js'), 'utf-8'); |
11 | | - |
12 | | -export const LOADER_CONFIGS: Record<string, { bundle: string; options: Record<string, unknown>; lazy: boolean }> = { |
13 | | - loader_base: { |
14 | | - bundle: 'browser/build/bundles/bundle.es5.min.js', |
15 | | - options: {}, |
16 | | - lazy: true, |
17 | | - }, |
18 | | - loader_eager: { |
19 | | - bundle: 'browser/build/bundles/bundle.es5.min.js', |
20 | | - options: {}, |
21 | | - lazy: false, |
22 | | - }, |
23 | | - loader_debug: { |
24 | | - bundle: 'browser/build/bundles/bundle.es5.debug.min.js', |
25 | | - options: { debug: true }, |
26 | | - lazy: true, |
27 | | - }, |
28 | | - loader_tracing: { |
29 | | - bundle: 'browser/build/bundles/bundle.tracing.es5.min.js', |
30 | | - options: { tracesSampleRate: 1 }, |
31 | | - lazy: false, |
32 | | - }, |
33 | | - loader_replay: { |
34 | | - bundle: 'browser/build/bundles/bundle.replay.min.js', |
35 | | - options: { replaysSessionSampleRate: 1, replaysOnErrorSampleRate: 1 }, |
36 | | - lazy: false, |
37 | | - }, |
38 | | - loader_tracing_replay: { |
39 | | - bundle: 'browser/build/bundles/bundle.tracing.replay.debug.min.js', |
40 | | - options: { tracesSampleRate: 1, replaysSessionSampleRate: 1, replaysOnErrorSampleRate: 1, debug: true }, |
41 | | - lazy: false, |
42 | | - }, |
43 | | -}; |
44 | | - |
45 | | -const bundleKey = process.env.PW_BUNDLE || ''; |
46 | | - |
47 | | -export function generateLoader(outPath: string): void { |
48 | | - const localPath = `${outPath}/dist`; |
49 | | - |
50 | | - if (!existsSync(localPath)) { |
51 | | - return; |
52 | | - } |
53 | | - |
54 | | - // Generate loader files |
55 | | - const loaderConfig = LOADER_CONFIGS[bundleKey]; |
56 | | - |
57 | | - if (!loaderConfig) { |
58 | | - throw new Error(`Unknown loader bundle key: ${bundleKey}`); |
59 | | - } |
60 | | - |
61 | | - const localCdnBundlePath = path.join(localPath, 'cdn.bundle.js'); |
62 | | - |
63 | | - try { |
64 | | - unlinkSync(localCdnBundlePath); |
65 | | - } catch { |
66 | | - // ignore if this didn't exist |
67 | | - } |
68 | | - |
69 | | - const cdnSourcePath = path.resolve(__dirname, `../../${loaderConfig.bundle}`); |
70 | | - symlinkSync(cdnSourcePath, localCdnBundlePath); |
71 | | - |
72 | | - const loaderPath = path.join(localPath, 'loader.js'); |
73 | | - const loaderContent = LOADER_TEMPLATE.replace('__LOADER_BUNDLE__', `'${TEST_HOST}/cdn.bundle.js'`) |
74 | | - .replace( |
75 | | - '__LOADER_OPTIONS__', |
76 | | - JSON.stringify({ |
77 | | - dsn: 'https://public@dsn.ingest.sentry.io/1337', |
78 | | - ...loaderConfig.options, |
79 | | - }), |
80 | | - ) |
81 | | - .replace('__LOADER_LAZY__', loaderConfig.lazy ? 'true' : 'false'); |
82 | | - |
83 | | - writeFileSync(loaderPath, loaderContent, 'utf-8'); |
84 | | -} |
85 | | - |
86 | 8 | export async function generatePage( |
87 | 9 | initPath: string, |
88 | 10 | subjectPath: string, |
@@ -110,7 +32,7 @@ export async function generatePage( |
110 | 32 | filename: '[name].bundle.js', |
111 | 33 | }, |
112 | 34 | plugins: [ |
113 | | - new SentryScenarioGenerationPlugin(), |
| 35 | + new SentryScenarioGenerationPlugin(localPath), |
114 | 36 | new HtmlWebpackPlugin({ |
115 | 37 | filename: outPageName, |
116 | 38 | template: templatePath, |
|
0 commit comments