-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(module-federation): clean up module-federation executors for react
- Loading branch information
Showing
21 changed files
with
450 additions
and
426 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
packages/react/src/executors/module-federation-dev-server/lib/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './normalize-options'; | ||
export * from './start-remotes'; |
29 changes: 29 additions & 0 deletions
29
packages/react/src/executors/module-federation-dev-server/lib/normalize-options.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { | ||
ExecutorContext, | ||
parseTargetString, | ||
readTargetOptions, | ||
} from '@nx/devkit'; | ||
import { | ||
ModuleFederationDevServerOptions, | ||
NormalizedModuleFederationDevServerOptions, | ||
} from '../schema'; | ||
|
||
export function getBuildOptions(buildTarget: string, context: ExecutorContext) { | ||
const target = parseTargetString(buildTarget, context); | ||
|
||
const buildOptions = readTargetOptions(target, context); | ||
|
||
return { | ||
...buildOptions, | ||
}; | ||
} | ||
|
||
export function normalizeOptions( | ||
options: ModuleFederationDevServerOptions | ||
): NormalizedModuleFederationDevServerOptions { | ||
return { | ||
...options, | ||
devRemotes: options.devRemotes ?? [], | ||
verbose: options.verbose ?? false, | ||
}; | ||
} |
62 changes: 62 additions & 0 deletions
62
packages/react/src/executors/module-federation-dev-server/lib/start-remotes.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { ExecutorContext, ProjectConfiguration, runExecutor } from '@nx/devkit'; | ||
import { NormalizedModuleFederationDevServerOptions } from '../schema'; | ||
|
||
export async function startRemotes( | ||
remotes: string[], | ||
workspaceProjects: Record<string, ProjectConfiguration>, | ||
options: Pick< | ||
NormalizedModuleFederationDevServerOptions, | ||
'devRemotes' | 'host' | 'ssl' | 'sslCert' | 'sslKey' | 'verbose' | ||
>, | ||
context: ExecutorContext, | ||
target: 'serve' | 'serve-static' = 'serve' | ||
) { | ||
const remoteIters: AsyncIterable<{ success: boolean }>[] = []; | ||
|
||
for (const app of remotes) { | ||
const remoteProjectServeTarget = workspaceProjects[app].targets[target]; | ||
const isUsingModuleFederationDevServerExecutor = | ||
remoteProjectServeTarget.executor.includes( | ||
'module-federation-dev-server' | ||
); | ||
|
||
const configurationOverride = options.devRemotes?.find( | ||
( | ||
r | ||
): r is { | ||
remoteName: string; | ||
configuration: string; | ||
} => typeof r !== 'string' && r.remoteName === app | ||
)?.configuration; | ||
|
||
const defaultOverrides = { | ||
...(options.host ? { host: options.host } : {}), | ||
...(options.ssl ? { ssl: options.ssl } : {}), | ||
...(options.sslCert ? { sslCert: options.sslCert } : {}), | ||
...(options.sslKey ? { sslKey: options.sslKey } : {}), | ||
}; | ||
const overrides = | ||
target === 'serve' | ||
? { | ||
watch: true, | ||
...(isUsingModuleFederationDevServerExecutor | ||
? { isInitialHost: false } | ||
: {}), | ||
...defaultOverrides, | ||
} | ||
: { ...defaultOverrides }; | ||
|
||
remoteIters.push( | ||
await runExecutor( | ||
{ | ||
project: app, | ||
target, | ||
configuration: configurationOverride ?? context.configurationName, | ||
}, | ||
overrides, | ||
context | ||
) | ||
); | ||
} | ||
return remoteIters; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
packages/react/src/executors/module-federation-ssr-dev-server/lib/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './normalize-options'; | ||
export * from './start-remotes'; |
34 changes: 34 additions & 0 deletions
34
packages/react/src/executors/module-federation-ssr-dev-server/lib/normalize-options.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { | ||
ModuleFederationSsrDevServerOptions, | ||
NormalizedModuleFederationSsrDevServerOptions, | ||
} from '../schema'; | ||
import { join } from 'path'; | ||
import { | ||
workspaceRoot, | ||
ExecutorContext, | ||
parseTargetString, | ||
readTargetOptions, | ||
} from '@nx/devkit'; | ||
|
||
export function normalizeOptions( | ||
options: ModuleFederationSsrDevServerOptions | ||
): NormalizedModuleFederationSsrDevServerOptions { | ||
return { | ||
...options, | ||
devRemotes: options.devRemotes ?? [], | ||
verbose: options.verbose ?? false, | ||
ssl: options.ssl ?? false, | ||
sslCert: options.sslCert ? join(workspaceRoot, options.sslCert) : undefined, | ||
sslKey: options.sslKey ? join(workspaceRoot, options.sslKey) : undefined, | ||
}; | ||
} | ||
|
||
export function getBuildOptions(buildTarget: string, context: ExecutorContext) { | ||
const target = parseTargetString(buildTarget, context); | ||
|
||
const buildOptions = readTargetOptions(target, context); | ||
|
||
return { | ||
...buildOptions, | ||
}; | ||
} |
58 changes: 58 additions & 0 deletions
58
packages/react/src/executors/module-federation-ssr-dev-server/lib/start-remotes.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { ModuleFederationSsrDevServerOptions } from '../schema'; | ||
import { runExecutor, ExecutorContext, ProjectConfiguration } from '@nx/devkit'; | ||
|
||
export async function startRemotes( | ||
remotes: string[], | ||
workspaceProjects: Record<string, ProjectConfiguration>, | ||
options: Partial< | ||
Pick< | ||
ModuleFederationSsrDevServerOptions, | ||
'devRemotes' | 'host' | 'ssl' | 'sslCert' | 'sslKey' | 'verbose' | ||
> | ||
>, | ||
context: ExecutorContext | ||
) { | ||
const remoteIters: AsyncIterable<{ success: boolean }>[] = []; | ||
const target = 'serve'; | ||
for (const app of remotes) { | ||
const remoteProjectServeTarget = workspaceProjects[app].targets[target]; | ||
const isUsingModuleFederationSsrDevServerExecutor = | ||
remoteProjectServeTarget.executor.includes( | ||
'module-federation-ssr-dev-server' | ||
); | ||
|
||
const configurationOverride = options.devRemotes?.find( | ||
(remote): remote is { remoteName: string; configuration: string } => | ||
typeof remote !== 'string' && remote.remoteName === app | ||
)?.configuration; | ||
{ | ||
const defaultOverrides = { | ||
...(options.host ? { host: options.host } : {}), | ||
...(options.ssl ? { ssl: options.ssl } : {}), | ||
...(options.sslCert ? { sslCert: options.sslCert } : {}), | ||
...(options.sslKey ? { sslKey: options.sslKey } : {}), | ||
}; | ||
|
||
const overrides = { | ||
watch: true, | ||
...defaultOverrides, | ||
...(isUsingModuleFederationSsrDevServerExecutor | ||
? { isInitialHost: false } | ||
: {}), | ||
}; | ||
|
||
remoteIters.push( | ||
await runExecutor( | ||
{ | ||
project: app, | ||
target, | ||
configuration: configurationOverride ?? context.configurationName, | ||
}, | ||
overrides, | ||
context | ||
) | ||
); | ||
} | ||
} | ||
return remoteIters; | ||
} |
Oops, something went wrong.