Skip to content

Commit

Permalink
fix(dts-plugin): emit dts relative to remote or manifest (#2641)
Browse files Browse the repository at this point in the history
Co-authored-by: ScriptedAlchemy <zackaryjackson@bytedance.com>
Co-authored-by: Matteo Pietro Dazzi <matteopietro.dazzi@gmail.com>
  • Loading branch information
3 people authored Jun 26, 2024
1 parent 8941ef4 commit 7d09ed8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/unlucky-jars-drum.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@module-federation/dts-plugin': patch
---

Emit DTS relative to remote entry location
4 changes: 2 additions & 2 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ jobs:
run: npx nx format:check

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

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

- name: Run Affected Lint
run: npx nx affected -t lint --parallel=7 --exclude='*,!tag:type:pkg'
Expand Down
15 changes: 13 additions & 2 deletions packages/dts-plugin/src/plugins/GenerateTypesPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
generateTypesInChildProcess,
retrieveTypesAssetsInfo,
} from '../core/index';
import path from 'path';

export class GenerateTypesPlugin implements WebpackPluginInstance {
pluginOptions: moduleFederationPlugin.ModuleFederationPluginOptions;
Expand Down Expand Up @@ -88,10 +89,20 @@ export class GenerateTypesPlugin implements WebpackPluginInstance {
return;
}
await generateTypesFn(finalOptions);
const config = finalOptions.remote.moduleFederationConfig;
let zipPrefix = '';
const isManifestObject = typeof config.manifest === 'object';
if (isManifestObject && config.manifest.filePath) {
zipPrefix = config.manifest.filePath;
} else if (isManifestObject && config.manifest.fileName) {
zipPrefix = path.dirname(config.manifest.fileName);
} else if (config.filename) {
zipPrefix = path.dirname(config.filename);
}

if (zipTypesPath) {
compilation.emitAsset(
zipName,
path.join(zipPrefix, zipName),
new compiler.webpack.sources.RawSource(
fs.readFileSync(zipTypesPath),
false,
Expand All @@ -101,7 +112,7 @@ export class GenerateTypesPlugin implements WebpackPluginInstance {

if (apiTypesPath) {
compilation.emitAsset(
apiFileName,
path.join(zipPrefix, apiFileName),
new compiler.webpack.sources.RawSource(
fs.readFileSync(apiTypesPath),
false,
Expand Down

0 comments on commit 7d09ed8

Please sign in to comment.