Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Esbuild 0.16.17 #817

Merged
merged 5 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
52 changes: 25 additions & 27 deletions config/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,16 @@ export const buildDir = path.resolve(__dirname, '..', 'docs')
const webIfcShimAliasPlugin = {
name: 'webIfcShimAlias',
setup(build) {
build.onResolve({ filter: /^web-ifc$/ }, (args) => {
build.onResolve({filter: /^web-ifc$/}, (args) => {
return {
path: path.resolve(__dirname, '../node_modules/bldrs-conway/compiled/src/shim/ifc_api.js'),
};
});
}
})
},
};
}

const useWebIfcShim = process.env.USE_WEBIFC_SHIM === 'true';
export const buildConfig = (useWebIfcShim) => {
const entryPoint = path.resolve(__dirname, '..', 'src', 'index.jsx');
const assetsDir = path.resolve(__dirname, '..', 'public');
const buildDir = path.resolve(__dirname, '..', 'docs');

export const buildConfig = (useWebIfcShim) => {
// Initialize plugins array
const plugins = [
progress(),
Expand All @@ -38,45 +34,47 @@ export const buildConfig = (useWebIfcShim) => {
src: assetsDir,
dest: buildDir,
}),
];
]


// Conditionally include webIfcShimAliasPlugin
if (useWebIfcShim) {
console.log("Using Conway shim backend")
plugins.push(webIfcShimAliasPlugin);
console.log('Using Conway shim backend')
plugins.push(webIfcShimAliasPlugin)
} else {
console.log("Using original Web-Ifc backend")
console.log('Using original Web-Ifc backend')
}


// Return the build config
return {
entryPoints: [entryPoint],
bundle: true,
minify: process.env.MINIFY_BUILD === 'true',
keepNames: true,
splitting: false,
metafile: true,
outdir: buildDir,
format: 'esm',
sourcemap: true,
platform: 'browser',
target: ['chrome64', 'firefox62', 'safari11.1', 'edge79', 'es2021'],
bundle: true,
minify: (process.env.MINIFY_BUILD || 'true') === 'true',
keepNames: true, // TODOD(pablo): have had breakage without this
splitting: false,
metafile: true,
sourcemap: true,
logLevel: 'info',
define: {
'process.env.OAUTH2_CLIENT_ID': JSON.stringify(process.env.OAUTH2_CLIENT_ID),
'process.env.OAUTH2_CLIENT_ID': JSON.stringify(process.env.OAUTH2_CLIENT_ID || null),
'process.env.OAUTH2_REDIRECT_URI': JSON.stringify(process.env.OAUTH2_REDIRECT_URI || null),
'process.env.AUTH0_DOMAIN': JSON.stringify(process.env.AUTH0_DOMAIN),
'process.env.GITHUB_API_TOKEN': JSON.stringify(process.env.GITHUB_API_TOKEN),
'process.env.AUTH0_DOMAIN': JSON.stringify(process.env.AUTH0_DOMAIN || null),
'process.env.GITHUB_API_TOKEN': JSON.stringify(process.env.GITHUB_API_TOKEN || null),
'process.env.GITHUB_BASE_URL': JSON.stringify(process.env.GITHUB_BASE_URL || 'https://api.github.com'),
'process.env.SENTRY_DSN': JSON.stringify(process.env.SENTRY_DSN || null),
'process.env.SENTRY_ENVIRONMENT': JSON.stringify(process.env.SENTRY_ENVIRONMENT || process.env.NODE_ENV),
'process.env.DISABLE_MOCK_SERVICE_WORKER': JSON.stringify(process.env.DISABLE_MOCK_SERVICE_WORKER),
'process.env.SENTRY_ENVIRONMENT': JSON.stringify(process.env.SENTRY_ENVIRONMENT || process.env.NODE_ENV || null),
'process.env.DISABLE_MOCK_SERVICE_WORKER': JSON.stringify(process.env.DISABLE_MOCK_SERVICE_WORKER || null),
'process.env.RAW_GIT_PROXY_URL': JSON.stringify(process.env.RAW_GIT_PROXY_URL || 'https://raw.githubusercontent.com'),
'process.env.USE_WEBIFC_SHIM': JSON.stringify(useWebIfcShim),
},
plugins: plugins,
};
};
}
}

export const build = buildConfig(useWebIfcShim)
const useShim = process.env.USE_WEBIFC_SHIM === 'true'
export const build = buildConfig(useShim)
2 changes: 1 addition & 1 deletion config/serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const proxyRequestHandler = ((options, res) => http.request(options, (proxyRes)
* See https://esbuild.github.io/api/#customizing-server-behavior
*/
// Read the environment variable
const useWebIfcShim = process.env.USE_WEBIFC_SHIM === 'true';
const useWebIfcShim = process.env.USE_WEBIFC_SHIM === 'true'

esbuild.serve({
port: SERVE_PORT - 1,
Expand Down
198 changes: 106 additions & 92 deletions cypress/fixtures/bldrs-inside-iframe.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// TODO(pablo): just including this to fix lint. Not sure why wasn't
// being used.
import mxwidgets from 'matrix-widget-api'


/**
* The Bldrs widget.
*/
Expand All @@ -10,147 +15,156 @@ class BldrsWidget {
}

/**
* The Bldrs Widget Driver.
*/
* The Bldrs Widget Driver.
*/
class BldrsWidgetDriver {
/** */
askOpenID(observer) {
// not implemented yet
}

/** @return {undefined} */
getTurnServers() {
return undefined
}

navigate(uri){
/** @return {Promise} */
navigate(uri) {
return Promise.resolve(undefined)
}

// NOSONAR
/**
* @return {Promise}
*/
readEventRelations(
eventId,
roomId,
relationType,
eventType,
from,
to,
limit,
direction
eventId,
roomId,
relationType,
eventType,
from,
to,
limit,
direction,
) {
return Promise.resolve(undefined)
}

/** @return {Promise} */
readRoomEvents(eventType, msgtype, limit, roomIds) {
return Promise.resolve([])
}

/** @return {Promise} */
readStateEvents(eventType, stateKey, limit, roomIds) {
return Promise.resolve([])
}

/** @return {Promise} */
sendEvent(eventType, content, stateKey, roomId) {
return Promise.resolve(undefined)
}

/** @return {Promise} */
sendToDevice(eventType, encrypted, contentMap) {
return Promise.resolve(undefined)
}

/** @return {Promise} */
validateCapabilities(requested) {
return Promise.resolve(requested)
}
}

/**
* Message types.
*/
* Message types.
*/
const EVENT_CLIENT_SELECTIONCHANGED_ELEMENTS = 'ai.bldrs-share.SelectionChanged'
const EVENT_CLIENT_MODEL_LOADED = 'ai.bldrs-share.ModelLoaded'
const EVENT_CLIENT_HIDDEN_ELEMENTS = 'ai.bldrs-share.HiddenElements'

document.addEventListener("DOMContentLoaded", function(event) {
const container = document.getElementById('bldrs-widget-iframe')
const bldrsWidget = new BldrsWidget()
bldrsWidget.url = location.protocol + '//' + location.host
const widget = new mxwidgets.Widget(bldrsWidget)
const driver = new BldrsWidgetDriver()
const api = new mxwidgets.ClientWidgetApi(widget, container, driver)

const cbxIsReady = document.getElementById('cbxIsReady')
const txtLastMsg = document.getElementById('txtLastMsg')
const txtSendMessageType = document.getElementById('txtSendMessageType')
const txtSendMessagePayload = document.getElementById('txtSendMessagePayload')
const btnSendMessage = document.getElementById('btnSendMessage')

const txtMessagesCount = document.getElementById('messagesCount')
const txtLastMessageReceivedAction = document.getElementById('lastMessageReceivedAction')


container.src = bldrsWidget.url

api.on('ready', () => {
cbxIsReady.checked = true
console.log("message: ready")
})

// api.on('action:' + EVENT_CLIENT_SELECT_ELEMENTS, (event) => {
// event.preventDefault()
// txtLastMsg.value = JSON.stringify(event.detail)
// api.transport.reply(event.detail, {})
// })

// api.on('action:' + EVENT_CLIENT_DESELECT_ELEMENTS, (event) => {
// event.preventDefault()
// txtLastMsg.value = JSON.stringify(event.detail)
// api.transport.reply(event.detail, {})
// })

// api.on('action:' + EVENT_CLIENT_SELECTIONCHANGED_ELEMENTS, (event) => {
// event.preventDefault()
// txtLastMsg.value = JSON.stringify(event.detail)
// api.transport.reply(event.detail, {})
// })

ListenToApiAction(EVENT_CLIENT_SELECTIONCHANGED_ELEMENTS,
event=>
{
txtLastMsg.value = JSON.stringify(event.detail ?? "")
}
)
document.addEventListener('DOMContentLoaded', (event) => {
const container = document.getElementById('bldrs-widget-iframe')
const bldrsWidget = new BldrsWidget()
bldrsWidget.url = `${location.protocol}//${location.host}`
const widget = new mxwidgets.Widget(bldrsWidget)
const driver = new BldrsWidgetDriver()
const api = new mxwidgets.ClientWidgetApi(widget, container, driver)

ListenToApiAction(EVENT_CLIENT_MODEL_LOADED,
event=>
{
txtLastMsg.value = JSON.stringify(event.detail??"")
}
)
const cbxIsReady = document.getElementById('cbxIsReady')
const txtLastMsg = document.getElementById('txtLastMsg')
const txtSendMessageType = document.getElementById('txtSendMessageType')
const txtSendMessagePayload = document.getElementById('txtSendMessagePayload')
const btnSendMessage = document.getElementById('btnSendMessage')

ListenToApiAction(EVENT_CLIENT_HIDDEN_ELEMENTS,
event=>
{
txtLastMsg.value = JSON.stringify(event.detail??"")
}
)
const txtMessagesCount = document.getElementById('messagesCount')
const txtLastMessageReceivedAction = document.getElementById('lastMessageReceivedAction')

container.src = bldrsWidget.url

btnSendMessage.addEventListener('click', () => {
const messageType = txtSendMessageType.value
const messagePayload = JSON.parse(txtSendMessagePayload.value)
api.transport.send(messageType, messagePayload)
})
api.on('ready', () => {
cbxIsReady.checked = true
console.log('message: ready')
})

let messagesReceivedCount = 0
function ListenToApiAction(actionName, callback)
{
api.on('action:' + actionName, (event) => {
event.preventDefault()
messagesReceivedCount++
if(callback) callback(event)
api.transport.reply(event.detail, {})
txtMessagesCount.innerText = messagesReceivedCount
txtLastMessageReceivedAction.innerText = event.detail.action
// api.on('action:' + EVENT_CLIENT_SELECT_ELEMENTS, (event) => {
// event.preventDefault()
// txtLastMsg.value = JSON.stringify(event.detail)
// api.transport.reply(event.detail, {})
// })

// api.on('action:' + EVENT_CLIENT_DESELECT_ELEMENTS, (event) => {
// event.preventDefault()
// txtLastMsg.value = JSON.stringify(event.detail)
// api.transport.reply(event.detail, {})
// })

// api.on('action:' + EVENT_CLIENT_SELECTIONCHANGED_ELEMENTS, (event) => {
// event.preventDefault()
// txtLastMsg.value = JSON.stringify(event.detail)
// api.transport.reply(event.detail, {})
// })

listenToApiAction(
EVENT_CLIENT_SELECTIONCHANGED_ELEMENTS,
(ev) => {
txtLastMsg.value = JSON.stringify(ev.detail ?? '')
},
)

listenToApiAction(
EVENT_CLIENT_MODEL_LOADED,
(ev) => {
txtLastMsg.value = JSON.stringify(ev.detail ?? '')
},
)

listenToApiAction(
EVENT_CLIENT_HIDDEN_ELEMENTS,
(ev) => {
txtLastMsg.value = JSON.stringify(ev.detail ?? '')
},
)

btnSendMessage.addEventListener('click', () => {
const messageType = txtSendMessageType.value
const messagePayload = JSON.parse(txtSendMessagePayload.value)
api.transport.send(messageType, messagePayload)
})
}

let messagesReceivedCount = 0

/** */
function listenToApiAction(actionName, callback) {
api.on(`action:${actionName}`, (ev) => {
event.preventDefault()
messagesReceivedCount++
if (callback) {
callback(ev)
}
api.transport.reply(event.detail, {})
txtMessagesCount.innerText = messagesReceivedCount
txtLastMessageReceivedAction.innerText = event.detail.action
})
}
})


17 changes: 10 additions & 7 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,18 @@
import '@testing-library/cypress/add-commands'
import 'cypress-react-router/add-commands'


/* eslint-disable no-empty-function */
/**
* Allow access to elements inside iframe and chain commands from there.
* @source https://www.nicknish.co/blog/cypress-targeting-elements-inside-iframes
*
* @see https://www.nicknish.co/blog/cypress-targeting-elements-inside-iframes
*/
Cypress.Commands.add('iframe', { prevSubject: 'element' }, ($iframe, callback = () => {}) => {
return cy
.wrap($iframe)
.should(iframe => expect(iframe.contents().find('body')).to.exist)
.then(iframe => cy.wrap(iframe.contents().find('body')))
.within({}, callback)
Cypress.Commands.add('iframe', {prevSubject: 'element'}, ($iframe, callback = () => {}) => {
return cy
.wrap($iframe)
.should((iframe) => expect(iframe.contents().find('body')).to.exist)
.then((iframe) => cy.wrap(iframe.contents().find('body')))
.within({}, callback)
})