-
-
Notifications
You must be signed in to change notification settings - Fork 246
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
feat: enable wxt usage inside of devcontainers #1406
base: main
Are you sure you want to change the base?
The head ref may contain hidden characters: "feat/wxt-\u{1F91D}-devcontainers"
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,8 @@ cli | |
.option('-c, --config <file>', 'use specified config file') | ||
.option('-m, --mode <mode>', 'set env mode') | ||
.option('-b, --browser <browser>', 'specify a browser') | ||
.option('-p, --port <port>', 'specify a port for the dev server') | ||
.option('--host <host>', 'specify a host for the dev server to bind to') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can't use |
||
.option('-p, --port <port>', 'specify a port for the dev server to bind to') | ||
.option( | ||
'-e, --filter-entrypoint <entrypoint>', | ||
'only build specific entrypoints', | ||
|
@@ -28,6 +29,12 @@ cli | |
.option('--mv2', 'target manifest v2') | ||
.action( | ||
wrapAction(async (root, flags) => { | ||
const serverOptions: NonNullable< | ||
NonNullable<Parameters<typeof createServer>[0]>['dev'] | ||
>['server'] = {}; | ||
if (flags.host) serverOptions.host = flags.host; | ||
if (flags.port) serverOptions.port = parseInt(flags.port); | ||
|
||
const server = await createServer({ | ||
root, | ||
mode: flags.mode, | ||
|
@@ -37,13 +44,9 @@ cli | |
debug: flags.debug, | ||
filterEntrypoints: getArrayFromFlags(flags, 'filterEntrypoint'), | ||
dev: | ||
flags.port == null | ||
Object.keys(serverOptions).length === 0 | ||
? undefined | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's a test which requires this to be |
||
: { | ||
server: { | ||
port: parseInt(flags.port), | ||
}, | ||
}, | ||
: { server: serverOptions }, | ||
}); | ||
await server.start(); | ||
return { isOngoing: true }; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,9 +15,9 @@ export function devServerGlobals( | |
|
||
return { | ||
define: { | ||
__DEV_SERVER_PROTOCOL__: JSON.stringify('ws:'), | ||
__DEV_SERVER_HOSTNAME__: JSON.stringify(server.hostname), | ||
__DEV_SERVER_PORT__: JSON.stringify(server.port), | ||
__DEV_SERVER_ORIGIN__: JSON.stringify( | ||
server.origin.replace(/^http(s):/, 'ws$1:'), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The regex replace converts |
||
), | ||
}, | ||
}; | ||
}, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -138,19 +138,37 @@ export async function resolveConfig( | |
|
||
let devServerConfig: ResolvedConfig['dev']['server']; | ||
if (command === 'serve') { | ||
const hostname = mergedConfig.dev?.server?.hostname ?? 'localhost'; | ||
if (mergedConfig.dev?.server?.hostname) | ||
logger.warn( | ||
`The 'hostname' option is deprecated, please use 'host' or 'origin' depending on your circumstances.`, | ||
); | ||
|
||
const host = | ||
mergedConfig.dev?.server?.host ?? | ||
mergedConfig.dev?.server?.hostname ?? | ||
'localhost'; | ||
let port = mergedConfig.dev?.server?.port; | ||
const origin = | ||
mergedConfig.dev?.server?.origin ?? | ||
mergedConfig.dev?.server?.hostname ?? | ||
'localhost'; | ||
if (port == null || !isFinite(port)) { | ||
port = await getPort({ | ||
// Passing host required for Mac, unsure of Windows/Linux | ||
host, | ||
port: 3000, | ||
portRange: [3001, 3010], | ||
// Passing host required for Mac, unsure of Windows/Linux | ||
host: hostname, | ||
}); | ||
} | ||
const originWithProtocolAndPort = [ | ||
origin.match(/^https?:\/\//) ? '' : 'http://', | ||
origin, | ||
origin.match(/:[0-9]+$/) ? '' : `:${port}`, | ||
].join(''); | ||
Comment on lines
+163
to
+167
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As a convenience, the protocol and port are pre/appended when not given, but are left alone when specified by the user. |
||
devServerConfig = { | ||
host, | ||
port, | ||
hostname, | ||
origin: originWithProtocolAndPort, | ||
watchDebounce: safeStringToNumber(process.env.WXT_WATCH_DEBOUNCE) ?? 800, | ||
}; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of constructing a best-guess URL to use to contact the dev server, we can use
ORIGIN
here