Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 6 additions & 2 deletions biome.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@
"$schema": "./node_modules/@biomejs/biome/configuration_schema.json",
"vcs": {
"enabled": true,
"clientKind": "git"
"clientKind": "git",
"useIgnoreFile": true
},
"files": {
"includes": ["**", "!dist", "!coverage"]
},
"formatter": {
"indentStyle": "space",
"lineWidth": 100,
"ignore": ["**/*.json"]
"includes": ["**", "!**/*.json"]
},
"javascript": {
"formatter": {
Expand Down
6,345 changes: 2,787 additions & 3,558 deletions package-lock.json

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@
"mkdirp": "^3.0.1"
},
"devDependencies": {
"@biomejs/biome": "^1.9.3",
"@biomejs/biome": "^2.4.13",
"@types/download": "^8.0.5",
"@types/minimist": "^1.2.5",
"@types/mkdirp": "^2.0.0",
"@types/node": "^22.7.5",
"@vitest/coverage-istanbul": "^2.1.3",
"simple-git-hooks": "^2.11.1",
"tsx": "^4.19.1",
"typescript": "^5.6.3",
"vitest": "^2.1.2",
"webpack": "^5.95.0"
"@types/node": "^24.12.2",
"@vitest/coverage-istanbul": "^4.1.5",
"simple-git-hooks": "^2.13.1",
"tsx": "^4.21.0",
"typescript": "^6.0.3",
"vitest": "^4.1.5",
"webpack": "^5.106.2"
},
"simple-git-hooks": {
"pre-commit": "npm run lint"
Expand Down
15 changes: 10 additions & 5 deletions src/__tests__/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ import { describe, expect, test, vi } from 'vitest';
import webpack, { type Compilation, type Compiler } from 'webpack';

import { DEFAULT_DIR_DOWNLOADED_TYPES, DEFAULT_DIR_EMITTED_TYPES } from '../constants';
import { downloadTypes } from '../downloadTypes/downloadTypes';
import { downloadTypes } from '../downloadTypes';
import type { ModuleFederationPluginOptions, ModuleFederationTypesPluginOptions } from '../models';
import { ModuleFederationTypesPlugin } from '../plugin';

vi.mock('../downloadTypes/downloadTypes');
vi.mock('../downloadTypes', async importActual => ({
...(await importActual<typeof import('../downloadTypes')>()),
downloadTypes: vi.fn(),
}));

const mockDownloadTypes = vi.mocked(downloadTypes);
const mockAfterEmit = vi.fn();
Expand Down Expand Up @@ -37,13 +40,15 @@ function installPlugin(
tap: mockAfterEmit as unknown,
},
beforeRun: {
tapPromise: (_, callback) => callback({} as Compiler) as unknown,
tapPromise: (_: unknown, callback: (compiler: Compiler) => unknown) =>
callback({} as Compiler) as unknown,
},
watchRun: {
tap: (_, callback) => callback({} as Compiler) as unknown,
tap: (_: unknown, callback: (compiler: Compiler) => unknown) =>
callback({} as Compiler) as unknown,
},
},
} as Compiler);
} as unknown as Compiler);

return pluginInstance;
}
Expand Down
2 changes: 1 addition & 1 deletion src/bin/__tests__/download-federated-types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ vi.mock('node:fs', async () => ({

vi.mock('minimist', () => ({
default: (args: string[]) => {
const webpackConfigIndex = args.findIndex(arg => arg === '--webpack-config');
const webpackConfigIndex = args.indexOf('--webpack-config');
return webpackConfigIndex > -1 ? { 'webpack-config': args[webpackConfigIndex + 1] } : {};
},
}));
Expand Down
12 changes: 10 additions & 2 deletions src/compileTypes/compileTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,13 @@ export function compileTypes(
logger: CommonLogger = getLogger(),
): CompileTypesResult {
const exposedFileNames = Object.values(exposedModules);
const { moduleResolution, ...compilerOptions } = getTSConfigCompilerOptions(tsconfigPath, logger);
const compilerOptions = getTSConfigCompilerOptions(tsconfigPath, logger);

// Strip the legacy raw-string `moduleResolution` ("Node") which `ts.createProgram` rejects;
// keep the enum value returned by the TS >= 5.4 parsed-config path.
if (typeof compilerOptions.moduleResolution === 'string') {
delete compilerOptions.moduleResolution;
}
Comment thread
steven-pribilinskiy marked this conversation as resolved.

Object.assign(compilerOptions, {
declaration: true,
Expand Down Expand Up @@ -64,7 +70,9 @@ export function compileTypes(

const program = ts.createProgram(exposedFileNames, compilerOptions, host);
const { diagnostics, emitSkipped } = program.emit();
diagnostics.forEach(item => reportCompileDiagnostic(item, logger));
for (const item of diagnostics) {
reportCompileDiagnostic(item, logger);
}

if (emitSkipped) {
logger.log('[compileTypes]: TypeScript program emit skipped');
Expand Down
4 changes: 3 additions & 1 deletion src/compileTypes/helpers/getTSConfigCompilerOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ export function getTSConfigCompilerOptions(

logger.log('tsc compiler version:', ts.version);

if (ts.version.match(/^[5-9]\.([4-9]|[1-9]\d)/)) {
const [major, minor] = ts.version.split('.').map(Number);
const isTs54OrNewer = major > 5 || (major === 5 && minor >= 4);
if (isTs54OrNewer) {
const tsconfigJsonFile = ts.readJsonConfigFile(tsconfigPath, ts.sys.readFile);
const parsedConfig = ts.parseJsonSourceFileConfigFileContent(
tsconfigJsonFile,
Expand Down
3 changes: 1 addition & 2 deletions src/compileTypes/rewritePathsWithExposedFederatedModules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ import path from 'node:path';
import { mkdirp } from 'mkdirp';

import { PREFIX_NOT_FOR_IMPORT } from '../constants';
import type { CommonLogger, FederationConfig } from '../models';

import { getLogger } from '../helpers';
import type { CommonLogger, FederationConfig } from '../models';
import { includeTypesFromNodeModules, substituteAliasedModules } from './helpers';

export function rewritePathsWithExposedFederatedModules(
Expand Down
4 changes: 1 addition & 3 deletions src/compileTypes/workerLogger.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { parentPort } from 'node:worker_threads';

import type { CommonLogger } from '../models';
import type { LogLevel } from '../models';
import type { CommonLogger, LogLevel } from '../models';

export function sendLog(level: LogLevel, items: unknown[]) {
parentPort?.postMessage({
Expand Down
2 changes: 1 addition & 1 deletion src/downloadTypes/helpers/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from './downloadRemoteEntryTypes';
export * from './downloadRemoteEntryManifest';
export * from './downloadRemoteEntryTypes';
export * from './downloadRemoteEntryURLsFromManifests';
5 changes: 3 additions & 2 deletions src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@ export class ModuleFederationTypesPlugin implements WebpackPluginInstance {
moduleFederationPluginNames.includes(plugin!.constructor.name.replace(/^_/, '')),
);

const federationPluginOptions: ModuleFederationPluginOptions = (federationOptions as Dict)
?._options as ModuleFederationPluginOptions;
// webpack >= 5.100 exposes `options`; earlier versions used `_options`.
const federationPluginOptions: ModuleFederationPluginOptions = ((federationOptions as Dict)
?.options ?? (federationOptions as Dict)?._options) as ModuleFederationPluginOptions;

if (!federationPluginOptions?.name) {
logger.warn(
Expand Down
2 changes: 2 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"allowSyntheticDefaultImports": true,
"declaration": true,
"esModuleInterop": true,
"ignoreDeprecations": "6.0",
"lib": ["esnext"],
"module": "CommonJS",
"moduleResolution": "Node",
Expand All @@ -12,6 +13,7 @@
"noUnusedLocals": true,
"noUnusedParameters": true,
"outDir": "./dist",
"rootDir": "./src",
"skipLibCheck": true,
"sourceMap": true,
"strict": true,
Expand Down
Loading