Skip to content

Commit 2cb38b8

Browse files
Merge pull request #58 from cloudbeds/fix/issue-52-moduleresolution-stripped
fix: preserve moduleResolution from parsed tsconfig (#52) + dep upgrades
2 parents 8b5352c + 4ff43fe commit 2cb38b8

12 files changed

Lines changed: 2833 additions & 3585 deletions

File tree

biome.jsonc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@
22
"$schema": "./node_modules/@biomejs/biome/configuration_schema.json",
33
"vcs": {
44
"enabled": true,
5-
"clientKind": "git"
5+
"clientKind": "git",
6+
"useIgnoreFile": true
7+
},
8+
"files": {
9+
"includes": ["**", "!dist", "!coverage"]
610
},
711
"formatter": {
812
"indentStyle": "space",
913
"lineWidth": 100,
10-
"ignore": ["**/*.json"]
14+
"includes": ["**", "!**/*.json"]
1115
},
1216
"javascript": {
1317
"formatter": {

package-lock.json

Lines changed: 2787 additions & 3558 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,17 @@
3333
"mkdirp": "^3.0.1"
3434
},
3535
"devDependencies": {
36-
"@biomejs/biome": "^1.9.3",
36+
"@biomejs/biome": "^2.4.13",
3737
"@types/download": "^8.0.5",
3838
"@types/minimist": "^1.2.5",
3939
"@types/mkdirp": "^2.0.0",
40-
"@types/node": "^22.7.5",
41-
"@vitest/coverage-istanbul": "^2.1.3",
42-
"simple-git-hooks": "^2.11.1",
43-
"tsx": "^4.19.1",
44-
"typescript": "^5.6.3",
45-
"vitest": "^2.1.2",
46-
"webpack": "^5.95.0"
40+
"@types/node": "^24.12.2",
41+
"@vitest/coverage-istanbul": "^4.1.5",
42+
"simple-git-hooks": "^2.13.1",
43+
"tsx": "^4.21.0",
44+
"typescript": "^6.0.3",
45+
"vitest": "^4.1.5",
46+
"webpack": "^5.106.2"
4747
},
4848
"simple-git-hooks": {
4949
"pre-commit": "npm run lint"

src/__tests__/plugin.test.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@ import { describe, expect, test, vi } from 'vitest';
22
import webpack, { type Compilation, type Compiler } from 'webpack';
33

44
import { DEFAULT_DIR_DOWNLOADED_TYPES, DEFAULT_DIR_EMITTED_TYPES } from '../constants';
5-
import { downloadTypes } from '../downloadTypes/downloadTypes';
5+
import { downloadTypes } from '../downloadTypes';
66
import type { ModuleFederationPluginOptions, ModuleFederationTypesPluginOptions } from '../models';
77
import { ModuleFederationTypesPlugin } from '../plugin';
88

9-
vi.mock('../downloadTypes/downloadTypes');
9+
vi.mock('../downloadTypes', async importActual => ({
10+
...(await importActual<typeof import('../downloadTypes')>()),
11+
downloadTypes: vi.fn(),
12+
}));
1013

1114
const mockDownloadTypes = vi.mocked(downloadTypes);
1215
const mockAfterEmit = vi.fn();
@@ -37,13 +40,15 @@ function installPlugin(
3740
tap: mockAfterEmit as unknown,
3841
},
3942
beforeRun: {
40-
tapPromise: (_, callback) => callback({} as Compiler) as unknown,
43+
tapPromise: (_: unknown, callback: (compiler: Compiler) => unknown) =>
44+
callback({} as Compiler) as unknown,
4145
},
4246
watchRun: {
43-
tap: (_, callback) => callback({} as Compiler) as unknown,
47+
tap: (_: unknown, callback: (compiler: Compiler) => unknown) =>
48+
callback({} as Compiler) as unknown,
4449
},
4550
},
46-
} as Compiler);
51+
} as unknown as Compiler);
4752

4853
return pluginInstance;
4954
}

src/bin/__tests__/download-federated-types.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ vi.mock('node:fs', async () => ({
1212

1313
vi.mock('minimist', () => ({
1414
default: (args: string[]) => {
15-
const webpackConfigIndex = args.findIndex(arg => arg === '--webpack-config');
15+
const webpackConfigIndex = args.indexOf('--webpack-config');
1616
return webpackConfigIndex > -1 ? { 'webpack-config': args[webpackConfigIndex + 1] } : {};
1717
},
1818
}));

src/compileTypes/compileTypes.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,13 @@ export function compileTypes(
2424
logger: CommonLogger = getLogger(),
2525
): CompileTypesResult {
2626
const exposedFileNames = Object.values(exposedModules);
27-
const { moduleResolution, ...compilerOptions } = getTSConfigCompilerOptions(tsconfigPath, logger);
27+
const compilerOptions = getTSConfigCompilerOptions(tsconfigPath, logger);
28+
29+
// Strip the legacy raw-string `moduleResolution` ("Node") which `ts.createProgram` rejects;
30+
// keep the enum value returned by the TS >= 5.4 parsed-config path.
31+
if (typeof compilerOptions.moduleResolution === 'string') {
32+
delete compilerOptions.moduleResolution;
33+
}
2834

2935
Object.assign(compilerOptions, {
3036
declaration: true,
@@ -64,7 +70,9 @@ export function compileTypes(
6470

6571
const program = ts.createProgram(exposedFileNames, compilerOptions, host);
6672
const { diagnostics, emitSkipped } = program.emit();
67-
diagnostics.forEach(item => reportCompileDiagnostic(item, logger));
73+
for (const item of diagnostics) {
74+
reportCompileDiagnostic(item, logger);
75+
}
6876

6977
if (emitSkipped) {
7078
logger.log('[compileTypes]: TypeScript program emit skipped');

src/compileTypes/helpers/getTSConfigCompilerOptions.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ export function getTSConfigCompilerOptions(
1717

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

20-
if (ts.version.match(/^[5-9]\.([4-9]|[1-9]\d)/)) {
20+
const [major, minor] = ts.version.split('.').map(Number);
21+
const isTs54OrNewer = major > 5 || (major === 5 && minor >= 4);
22+
if (isTs54OrNewer) {
2123
const tsconfigJsonFile = ts.readJsonConfigFile(tsconfigPath, ts.sys.readFile);
2224
const parsedConfig = ts.parseJsonSourceFileConfigFileContent(
2325
tsconfigJsonFile,

src/compileTypes/rewritePathsWithExposedFederatedModules.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ import path from 'node:path';
44
import { mkdirp } from 'mkdirp';
55

66
import { PREFIX_NOT_FOR_IMPORT } from '../constants';
7-
import type { CommonLogger, FederationConfig } from '../models';
8-
97
import { getLogger } from '../helpers';
8+
import type { CommonLogger, FederationConfig } from '../models';
109
import { includeTypesFromNodeModules, substituteAliasedModules } from './helpers';
1110

1211
export function rewritePathsWithExposedFederatedModules(

src/compileTypes/workerLogger.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { parentPort } from 'node:worker_threads';
2-
3-
import type { CommonLogger } from '../models';
4-
import type { LogLevel } from '../models';
2+
import type { CommonLogger, LogLevel } from '../models';
53

64
export function sendLog(level: LogLevel, items: unknown[]) {
75
parentPort?.postMessage({

src/downloadTypes/helpers/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
export * from './downloadRemoteEntryTypes';
21
export * from './downloadRemoteEntryManifest';
2+
export * from './downloadRemoteEntryTypes';
33
export * from './downloadRemoteEntryURLsFromManifests';

0 commit comments

Comments
 (0)