Skip to content

Commit

Permalink
fix: sentry issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Razboy20 committed Oct 23, 2024
1 parent d357735 commit ab6044b
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 20 deletions.
1 change: 1 addition & 0 deletions @types/vite-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

interface ImportMetaEnv {
readonly VITE_PACKAGE_VERSION: string;
readonly VITE_SENTRY_ENVIRONMENT: string;
readonly VITE_BETA_BUILD?: 'true';
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"dev": "vite",
"build": "tsc && vite build",
"build:watch": "NODE_ENV='development' vite build --mode development -w",
"zip": "pnpm build && pnpm gulp zip",
"zip": "PROD=true pnpm build && pnpm gulp zip",
"prettier": "prettier src --check",
"prettier:fix": "prettier src --write",
"lint": "eslint src --ext ts,tsx --report-unused-disable-directives",
Expand Down
3 changes: 2 additions & 1 deletion src/views/contexts/SentryContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@ export default function SentryProvider({
integrations,
transport: makeFetchTransport,
stackParser: defaultStackParser,
// debug: true,
debug: import.meta.env.DEV,
release: import.meta.env.VITE_PACKAGE_VERSION,
environment: import.meta.env.VITE_SENTRY_ENVIRONMENT,
};

let client: Client;
Expand Down
58 changes: 40 additions & 18 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ if (isBeta) {
process.env.VITE_BETA_BUILD = 'true';
}
process.env.VITE_PACKAGE_VERSION = packageJson.version;
if (process.env.PROD) {
process.env.VITE_SENTRY_ENVIRONMENT = 'production';
} else if (isBeta) {
process.env.VITE_SENTRY_ENVIRONMENT = 'beta';
} else {
process.env.VITE_SENTRY_ENVIRONMENT = 'development';
}

export const preambleCode = `
import RefreshRuntime from "__BASE__@react-refresh"
Expand Down Expand Up @@ -89,10 +96,13 @@ export default defineConfig({
apply: 'serve',
transform(code, id) {
if (id.endsWith('.tsx') || id.endsWith('.ts') || id.endsWith('?url')) {
return code.replace(
/(['"])(\/public\/.*?)(['"])/g,
(_, quote1, path, quote2) => `chrome.runtime.getURL(${quote1}${path}${quote2})`
);
return {
code: code.replace(
/(['"])(\/public\/.*?)(['"])/g,
(_, quote1, path, quote2) => `chrome.runtime.getURL(${quote1}${path}${quote2})`
),
map: null,
};
}
},
},
Expand All @@ -101,10 +111,13 @@ export default defineConfig({
apply: 'build',
transform(code, id) {
if (id.endsWith('.tsx') || id.endsWith('.ts') || id.endsWith('?url')) {
return code.replace(
/(['"])(__VITE_ASSET__.*?__)(['"])/g,
(_, quote1, path, quote2) => `chrome.runtime.getURL(${quote1}${path}${quote2})`
);
return {
code: code.replace(
/(['"])(__VITE_ASSET__.*?__)(['"])/g,
(_, quote1, path, quote2) => `chrome.runtime.getURL(${quote1}${path}${quote2})`
),
map: null,
};
}
},
},
Expand All @@ -114,13 +127,16 @@ export default defineConfig({
enforce: 'post',
transform(code, id) {
if (process.env.NODE_ENV === 'development' && (id.endsWith('.css') || id.endsWith('.scss'))) {
return code.replace(
/url\((.*?)\)/g,
(_, path) =>
`url(\\"" + chrome.runtime.getURL(${path
.replaceAll(`\\"`, `"`)
.replace(/public\//, '')}) + "\\")`
);
return {
code: code.replace(
/url\((.*?)\)/g,
(_, path) =>
`url(\\"" + chrome.runtime.getURL(${path
.replaceAll(`\\"`, `"`)
.replace(/public\//, '')}) + "\\")`
),
map: null,
};
}
},
},
Expand All @@ -133,17 +149,16 @@ export default defineConfig({
/(__VITE_ASSET__.*?__)/g,
(_, path) => `chrome-extension://__MSG_@@extension_id__${path}`
);
return transformedCode;
return { code: transformedCode, map: null };
}
return code;
},
},
renameFile('src/pages/debug/index.html', 'debug.html'),
renameFile('src/pages/options/index.html', 'options.html'),
renameFile('src/pages/calendar/index.html', 'calendar.html'),
renameFile('src/pages/report/index.html', 'report.html'),
vitePluginRunCommandOnDemand({
afterServerStart: 'pnpm gulp forceDisableUseDynamicUrl',
// afterServerStart: 'pnpm gulp forceDisableUseDynamicUrl',
closeBundle: 'pnpm gulp forceDisableUseDynamicUrl',
}),
],
Expand Down Expand Up @@ -206,4 +221,11 @@ export default defineConfig({
provider: 'v8',
},
},
css: {
preprocessorOptions: {
scss: {
api: 'modern-compiler',
},
},
},
});

0 comments on commit ab6044b

Please sign in to comment.