Skip to content

Commit 7d09ed8

Browse files
fix(dts-plugin): emit dts relative to remote or manifest (#2641)
Co-authored-by: ScriptedAlchemy <[email protected]> Co-authored-by: Matteo Pietro Dazzi <[email protected]>
1 parent 8941ef4 commit 7d09ed8

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

.changeset/unlucky-jars-drum.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@module-federation/dts-plugin': patch
3+
---
4+
5+
Emit DTS relative to remote entry location

.github/workflows/build-and-test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ jobs:
3838
run: npx nx format:check
3939

4040
- name: Update NX Build Cache
41-
run: npx nx run-many --targets=build --exclude='*,!tag:type:pkg'
41+
run: npx nx run-many --targets=build --projects=tag:type:pkg
4242

4343
- name: Run Build for All
44-
run: npx nx run-many --targets=build --exclude='*,!tag:type:pkg' --skip-nx-cache
44+
run: npx nx run-many --targets=build --projects=tag:type:pkg --skip-nx-cache
4545

4646
- name: Run Affected Lint
4747
run: npx nx affected -t lint --parallel=7 --exclude='*,!tag:type:pkg'

packages/dts-plugin/src/plugins/GenerateTypesPlugin.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
generateTypesInChildProcess,
1212
retrieveTypesAssetsInfo,
1313
} from '../core/index';
14+
import path from 'path';
1415

1516
export class GenerateTypesPlugin implements WebpackPluginInstance {
1617
pluginOptions: moduleFederationPlugin.ModuleFederationPluginOptions;
@@ -88,10 +89,20 @@ export class GenerateTypesPlugin implements WebpackPluginInstance {
8889
return;
8990
}
9091
await generateTypesFn(finalOptions);
92+
const config = finalOptions.remote.moduleFederationConfig;
93+
let zipPrefix = '';
94+
const isManifestObject = typeof config.manifest === 'object';
95+
if (isManifestObject && config.manifest.filePath) {
96+
zipPrefix = config.manifest.filePath;
97+
} else if (isManifestObject && config.manifest.fileName) {
98+
zipPrefix = path.dirname(config.manifest.fileName);
99+
} else if (config.filename) {
100+
zipPrefix = path.dirname(config.filename);
101+
}
91102

92103
if (zipTypesPath) {
93104
compilation.emitAsset(
94-
zipName,
105+
path.join(zipPrefix, zipName),
95106
new compiler.webpack.sources.RawSource(
96107
fs.readFileSync(zipTypesPath),
97108
false,
@@ -101,7 +112,7 @@ export class GenerateTypesPlugin implements WebpackPluginInstance {
101112

102113
if (apiTypesPath) {
103114
compilation.emitAsset(
104-
apiFileName,
115+
path.join(zipPrefix, apiFileName),
105116
new compiler.webpack.sources.RawSource(
106117
fs.readFileSync(apiTypesPath),
107118
false,

0 commit comments

Comments
 (0)