Skip to content

Commit

Permalink
Refactor strict checks
Browse files Browse the repository at this point in the history
  • Loading branch information
NoelDeMartin committed Jan 29, 2025
1 parent bdb2c30 commit c1f56c1
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/models/SolidModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ import type { Quad } from 'rdf-js';

import IRI from '@/solid/utils/IRI';
import RDFDocument from '@/solid/RDFDocument';
import { isDevelopment } from '@/utils/env';
import { applyStrictChecks } from '@/utils/env';
import { SolidEngine } from '@/engines/SolidEngine';
import { usingExperimentalActivityPods } from '@/experimental';
import type RDFResource from '@/solid/RDFResource';
Expand Down Expand Up @@ -318,7 +318,7 @@ export class SolidModel extends SolidModelBase {

return model;
} catch (error) {
if (isDevelopment()) {
if (applyStrictChecks()) {
throw new Error;
}

Expand Down
8 changes: 8 additions & 0 deletions src/types/env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import '';

declare global {
interface Window {
// Available in Aerogel apps.
$app?: { environment?: string };
}
}
21 changes: 19 additions & 2 deletions src/utils/env.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
export function isDevelopment(): boolean {
return typeof process !== 'undefined' && process?.env?.NODE_ENV === 'development';
function getEnv(): string | null {
if (typeof globalThis === 'object' && 'Cypress' in globalThis) {
return 'testing';
}

if (typeof window === 'object' && '$app' in window && !!window.$app?.environment) {
return window.$app.environment;
}

if (typeof process === 'object' && process.env?.NODE_ENV) {
return process.env.NODE_ENV;
}

return null;
}
export function applyStrictChecks(): boolean {
const env = getEnv();

return env === 'development' || env === 'testing';
}

0 comments on commit c1f56c1

Please sign in to comment.