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

Add preLoadModules option to import modules on main thread #1777

Merged
merged 3 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/ServerlessOffline.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ export default class ServerlessOffline {
async start() {
this.#mergeOptions()

this.#preLoadModules()

const {
albEvents,
httpEvents,
Expand Down Expand Up @@ -417,6 +419,18 @@ export default class ServerlessOffline {
}
}

#preLoadModules() {
const { preLoadModules } = this.#options
const modules = preLoadModules.split(",")
modules.forEach((module) => {
try {
import(module)
} catch (err) {
log.error(`Error importing module ${module}: ${err}`)
}
})
}

// TODO FIXME
// TEMP quick fix to expose for testing, look for better solution
internals() {
Expand All @@ -440,6 +454,10 @@ export default class ServerlessOffline {
mergeOptions: () => {
this.#mergeOptions()
},

preLoadModules: () => {
this.#preLoadModules()
},
}
}
}
4 changes: 4 additions & 0 deletions src/config/commandOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,8 @@ export default {
type: "string",
usage: "Websocket port to listen on. Default: 3001.",
},
preLoadModules: {
type: "string",
usage: "A comma separated list of modules to preload on the main thread",
},
}
1 change: 1 addition & 0 deletions src/config/defaultOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ export default {
webSocketHardTimeout: 7200,
webSocketIdleTimeout: 600,
websocketPort: 3001,
preLoadModules: '',
}