Skip to content

Commit 3adc24d

Browse files
authored
Introduce NUSMODS_ENV and fix deploy preview robots.txt and Sentry env (#3137)
1 parent 1c8d0d2 commit 3adc24d

32 files changed

+98
-112
lines changed

export/src/render-serverless.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ async function setViewport(page: Page, options: ViewportOptions = {}) {
2424

2525
export async function open(url: string) {
2626
const browser = await chromium.puppeteer.launch({
27-
// devtools: !!process.env.DEVTOOLS, // TODO: Query string && __DEV__?
27+
// devtools: !!process.env.DEVTOOLS, // TODO: Query string && NODE_ENV === 'development'?
2828
args: chromium.args,
2929
defaultViewport: chromium.defaultViewport,
3030
executablePath: await chromium.executablePath,

website/jest.common.config.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,11 @@ module.exports = {
1515
},
1616
// Mimic the globals we set with Webpack's DefinePlugin
1717
globals: {
18-
// Default to development
19-
__DEV__: process.env.NODE_ENV === 'development',
20-
__TEST__: process.env.NODE_ENV === 'test',
18+
NUSMODS_ENV: 'test',
2119
DATA_API_BASE_URL: '',
2220
VERSION_STR: '',
2321
DISPLAY_COMMIT_HASH: '',
2422
DEBUG_SERVICE_WORKER: false,
25-
VERCEL_ENV: '',
26-
VERCEL_GIT_COMMIT_REF: '',
2723
},
2824
// Allow us to directly use enzyme wrappers for snapshotting
2925
// Usage: expect(enzyme.shallow(<div/>)).toMatchSnapshot();

website/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@
7373
"babel-plugin-transform-react-remove-prop-types": "0.4.24",
7474
"chalk": "4.1.0",
7575
"codecov": "3.8.1",
76-
"compression-webpack-plugin": "7.1.2",
7776
"copy-webpack-plugin": "7.0.0",
7877
"cross-env": "7.0.3",
7978
"css-loader": "5.0.1",

website/src/.eslintrc.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,10 @@ module.exports = {
104104

105105
// Mimic the globals we set with Webpack's DefinePlugin
106106
globals: {
107-
__DEV__: 'readonly',
108-
__TEST__: 'readonly',
107+
NUSMODS_ENV: 'readonly',
109108
DATA_API_BASE_URL: 'readonly',
110109
VERSION_STR: 'readonly',
111110
DISPLAY_COMMIT_HASH: 'readonly',
112111
DEBUG_SERVICE_WORKER: 'readonly',
113-
VERCEL_ENV: 'readonly',
114-
VERCEL_GIT_COMMIT_REF: 'readonly',
115112
},
116113
};

website/src/bootstrapping/configure-store.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export default function configureStore(defaultState?: State) {
2727

2828
const middlewares = [ravenMiddleware, thunk, requestsMiddleware];
2929

30-
if (__DEV__) {
30+
if (NUSMODS_ENV === 'development') {
3131
// eslint-disable-next-line @typescript-eslint/no-var-requires, global-require, import/no-extraneous-dependencies
3232
const { createLogger } = require('redux-logger');
3333
const logger = createLogger({

website/src/bootstrapping/sentry.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,22 @@ import { Integrations } from '@sentry/tracing';
44

55
import { isBrowserSupported } from './browser';
66

7-
// Decide Sentry environment based on some basic heuristics.
8-
function sentryEnv(): string | undefined {
9-
if (VERCEL_ENV === 'production') return 'production';
10-
if (VERCEL_ENV === 'preview') {
11-
if (VERCEL_GIT_COMMIT_REF === 'master') return 'staging';
12-
return 'preview';
7+
function sentryEnv() {
8+
if (NUSMODS_ENV === 'test') {
9+
throw new Error('Do not load Sentry in tests');
1310
}
14-
return 'development';
11+
return NUSMODS_ENV;
1512
}
1613

17-
// Configure Raven - the client for Sentry, which we use to handle errors
18-
const loadRaven = !__DEV__ && !__TEST__;
19-
if (loadRaven) {
14+
// Configure Sentry client, which we use to handle errors
15+
if (NUSMODS_ENV === 'production') {
2016
Sentry.init({
2117
dsn: 'https://[email protected]/213986',
2218

2319
release: VERSION_STR || 'UNKNOWN_RELEASE',
2420

2521
integrations: [new Integrations.BrowserTracing()],
26-
tracesSampleRate: 1.0,
22+
tracesSampleRate: NUSMODS_ENV === 'production' ? 0.2 : 1.0,
2723

2824
environment: sentryEnv(),
2925

website/src/entry/main.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ ReactModal.setAppElement('#app');
2828
ReactDOM.render(<App store={store} persistor={persistor} />, document.getElementById('app'));
2929

3030
if (
31-
(!__DEV__ &&
32-
!__TEST__ &&
31+
((NUSMODS_ENV === 'preview' || NUSMODS_ENV === 'staging' || NUSMODS_ENV === 'production') &&
3332
'serviceWorker' in navigator &&
3433
window.location.protocol === 'https:') ||
3534
// Allow us to force service worker to be enabled for debugging
@@ -38,6 +37,6 @@ if (
3837
registerServiceWorker(store);
3938
}
4039

41-
if (!__DEV__ && !__TEST__) {
40+
if (NUSMODS_ENV === 'production') {
4241
initializeMamoto();
4342
}

website/src/storage/persistReducer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export default function persistReducer<S>(
2323
{
2424
key,
2525
storage,
26-
debug: __DEV__,
26+
debug: NUSMODS_ENV === 'development',
2727
...options,
2828
},
2929
reducer,

website/src/types/global.d.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,27 @@
11
// Globals injected by Webpack DefinePlugin
22
/* eslint-disable no-underscore-dangle */
3-
declare const __DEV__: boolean;
4-
declare const __TEST__: boolean;
3+
/**
4+
* NUSMods deployment environment.
5+
*
6+
* **Note:** although these environments may share the same name as
7+
* `NODE_ENV` and other envs, there are subtle differences. Definitions:
8+
*
9+
* - `production`: a production deployment of NUSMods, i.e. a deployment meant to
10+
* be used by the general public.
11+
* - `staging`: a deployment of NUSMods's main development branch, which is
12+
* not meant to be used by the general public but which may be promoted to
13+
* production at any point.
14+
* - `preview`: a deployment of work-in-progress branches, e.g. PR deploy
15+
* previews.
16+
* - `test`: we are in a test environment, e.g. a jest test run.
17+
* - `development`: all other situations.
18+
*/
19+
declare const NUSMODS_ENV: 'development' | 'production' | 'staging' | 'preview' | 'test';
20+
521
declare const DATA_API_BASE_URL: string | undefined;
622
declare const VERSION_STR: string | undefined;
723
declare const DISPLAY_COMMIT_HASH: string | undefined;
824
declare const DEBUG_SERVICE_WORKER: boolean;
9-
declare const VERCEL_ENV: string;
10-
declare const VERCEL_GIT_COMMIT_REF: string;
1125
/* eslint-enable no-underscore-dangle */
1226

1327
/**

website/src/views/modules/ReportError.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ const ReportError = memo<Props>(({ module }) => {
114114

115115
// Causes the error reporting function to email modules@nusmods.com instead.
116116
// In production, use SET_ERROR_REPORTING_DEBUG(true) to enable debug mode
117-
const debug = useGlobalDebugValue('SET_ERROR_REPORTING_DEBUG', __DEV__);
117+
const debug = useGlobalDebugValue('SET_ERROR_REPORTING_DEBUG', NUSMODS_ENV === 'development');
118118

119119
const [formData, setFormData] = useState<ReportErrorForm>(() => ({
120120
...retrieveContactInfo(),

0 commit comments

Comments
 (0)