Skip to content

Commit

Permalink
Add build asserts
Browse files Browse the repository at this point in the history
  • Loading branch information
corrideat committed Aug 19, 2023
1 parent 010283a commit 99f8150
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 0 deletions.
8 changes: 8 additions & 0 deletions @types/build-settings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@
* PERFORMANCE OF THIS SOFTWARE.
*/

/**
* Module that does not exist, specifically to trigger build time errors
* @module
*/
declare module '[[BUILDTIME_ERROR]]' {
// empty
}

/**
* Namespace that encapsulates various build-time settings.
* @namespace
Expand Down
3 changes: 3 additions & 0 deletions esbuild.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,9 @@ const umdOpts = {
},
};

options.define['__buildtimeSettings__.isolationStategyIframeSole'] = 'true';
options.define['__buildtimeSettings__.isolationStategyIframeWorker'] = 'true';

/**
* @param {string[]} entryPoints
* @returns {Promise<void>}
Expand Down
9 changes: 9 additions & 0 deletions src/exports/browser-window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,13 @@
* PERFORMANCE OF THIS SOFTWARE.
*/

if (
!__buildtimeSettings__.isolationStategyIframeSole ||
__buildtimeSettings__.isolationStategyIframeWorker
) {
// This export is meant for iframe sole only
void import('[[BUILDTIME_ERROR]]');
throw new Error('Build time constraint failed');
}

export { default } from '~trusted/impl/browser/browserSandbox.js';
9 changes: 9 additions & 0 deletions src/exports/browser-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,13 @@
* PERFORMANCE OF THIS SOFTWARE.
*/

if (
__buildtimeSettings__.isolationStategyIframeSole ||
!__buildtimeSettings__.isolationStategyIframeWorker
) {
// This export is meant for iframe worker only
void import('[[BUILDTIME_ERROR]]');
throw new Error('Build time constraint failed');
}

export { default } from '~trusted/impl/browser/browserSandbox.js';
9 changes: 9 additions & 0 deletions src/exports/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,13 @@
* PERFORMANCE OF THIS SOFTWARE.
*/

if (
!__buildtimeSettings__.isolationStategyIframeSole &&
!__buildtimeSettings__.isolationStategyIframeWorker
) {
// At least one strategy must be chosen
void import('[[BUILDTIME_ERROR]]');
throw new Error('Build time constraint failed');
}

export { default } from '~trusted/impl/browser/browserSandbox.js';
8 changes: 8 additions & 0 deletions src/trusted/impl/browser/browserSandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ const browserSandbox: ISandbox = async (
abort,
options,
) => {
if (
!__buildtimeSettings__.isolationStategyIframeSole &&
!__buildtimeSettings__.isolationStategyIframeWorker
) {
// At least one strategy must be chosen
throw new Error('Not implemented');
}

if (!__buildtimeSettings__.bidirectionalMessaging && externalMethods) {
throw new TypeError(
'Invalid value for externalMethods. Bidirectional messaging is disabled',
Expand Down
8 changes: 8 additions & 0 deletions src/untrusted/impl/browser/iframeSandboxInit.inline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@
* PERFORMANCE OF THIS SOFTWARE.
*/

if (
!__buildtimeSettings__.isolationStategyIframeSole &&
!__buildtimeSettings__.isolationStategyIframeWorker
) {
// At least one strategy must be chosen
throw new Error('Not implemented');
}

import {
E,
aIsArray,
Expand Down

0 comments on commit 99f8150

Please sign in to comment.