Skip to content

Commit 9218a1e

Browse files
authored
fix: replace webpack references with Rspack (#56)
1 parent 5ba6fe0 commit 9218a1e

File tree

10 files changed

+41
-41
lines changed

10 files changed

+41
-41
lines changed

src/formatter/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export * from './formatter';
22
export * from './basic-formatter';
33
export * from './code-frame-formatter';
4-
export * from './webpack-formatter';
4+
export * from './rspack-formatter';
55
export * from './formatter-options';
66
export * from './formatter-config';
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import { relativeToContext } from '../utils/path/relative-to-context';
99

1010
import type { Formatter, FormatterPathType } from './formatter';
1111

12-
function createWebpackFormatter(formatter: Formatter, pathType: FormatterPathType): Formatter {
13-
// mimics webpack error formatter
14-
return function webpackFormatter(issue) {
12+
function createRspackFormatter(formatter: Formatter, pathType: FormatterPathType): Formatter {
13+
// mimics Rspack error formatter
14+
return function rspackFormatter(issue) {
1515
const color = issue.severity === 'warning' ? pc.yellow : pc.red;
1616

1717
const severity = issue.severity.toUpperCase();
@@ -33,4 +33,4 @@ function createWebpackFormatter(formatter: Formatter, pathType: FormatterPathTyp
3333
};
3434
}
3535

36-
export { createWebpackFormatter };
36+
export { createRspackFormatter };

src/hooks/tap-after-compile-to-get-issues.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type * as rspack from '@rspack/core';
22

33
import { getInfrastructureLogger } from '../infrastructure-logger';
44
import type { Issue } from '../issue';
5-
import { IssueWebpackError } from '../issue/issue-webpack-error';
5+
import { IssueRspackError } from '../issue/issue-rspack-error';
66
import type { TsCheckerRspackPluginConfig } from '../plugin-config';
77
import { getPluginHooks } from '../plugin-hooks';
88
import type { TsCheckerRspackPluginState } from '../plugin-state';
@@ -44,7 +44,7 @@ function tapAfterCompileToGetIssues(
4444
issues = hooks.issues.call(issues, compilation);
4545

4646
issues.forEach((issue) => {
47-
const error = new IssueWebpackError(
47+
const error = new IssueRspackError(
4848
config.formatter.format(issue),
4949
config.formatter.pathType,
5050
issue

src/hooks/tap-after-environment-to-patch-watching.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ function tapAfterEnvironmentToPatchWatching(
1414
compiler.hooks.afterEnvironment.tap('TsCheckerRspackPlugin', () => {
1515
const watchFileSystem = compiler.watchFileSystem;
1616
if (watchFileSystem) {
17-
debug("Overwriting webpack's watch file system.");
17+
debug("Overwriting Rspack's watch file system.");
1818
// wrap original watch file system
1919
compiler.watchFileSystem = new InclusiveNodeWatchFileSystem(
2020
// we use some internals here

src/hooks/tap-done-to-async-get-issues.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import pc from 'picocolors';
22
import type * as rspack from '@rspack/core';
33

44
import { statsFormatter } from '../formatter/stats-formatter';
5-
import { createWebpackFormatter } from '../formatter/webpack-formatter';
5+
import { createRspackFormatter } from '../formatter/rspack-formatter';
66
import { getInfrastructureLogger } from '../infrastructure-logger';
77
import type { Issue } from '../issue';
8-
import { IssueWebpackError } from '../issue/issue-webpack-error';
8+
import { IssueRspackError } from '../issue/issue-rspack-error';
99
import type { TsCheckerRspackPluginConfig } from '../plugin-config';
1010
import { getPluginHooks } from '../plugin-hooks';
1111
import type { TsCheckerRspackPluginState } from '../plugin-state';
@@ -34,7 +34,7 @@ function tapDoneToAsyncGetIssues(
3434
hooks.waiting.call(stats.compilation);
3535
config.logger.log(pc.cyan('[type-check] in progress...'));
3636
} else {
37-
// wait 10ms to log issues after webpack stats
37+
// wait 10ms to log issues after Rspack stats
3838
await wait(10);
3939
}
4040

@@ -59,10 +59,10 @@ function tapDoneToAsyncGetIssues(
5959
// modify list of issues in the plugin hooks
6060
issues = hooks.issues.call(issues, stats.compilation);
6161

62-
const formatter = createWebpackFormatter(config.formatter.format, config.formatter.pathType);
62+
const formatter = createRspackFormatter(config.formatter.format, config.formatter.pathType);
6363

6464
if (issues.length) {
65-
// follow webpack's approach - one process.write to stderr with all errors and warnings
65+
// follow Rspack's approach - one process.write to stderr with all errors and warnings
6666
config.logger.error(issues.map((issue) => formatter(issue)).join('\n'));
6767
}
6868

@@ -73,7 +73,7 @@ function tapDoneToAsyncGetIssues(
7373
// skip reporting if there are no issues, to avoid an extra hot reload
7474
if (issues.length && state.DevServerDoneTap) {
7575
issues.forEach((issue) => {
76-
const error = new IssueWebpackError(
76+
const error = new IssueRspackError(
7777
config.formatter.format(issue),
7878
config.formatter.pathType,
7979
issue
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { relativeToContext } from '../utils/path/relative-to-context';
66
import type { Issue } from './issue';
77
import { formatIssueLocation } from './issue-location';
88

9-
class IssueWebpackError extends Error {
9+
class IssueRspackError extends Error {
1010
readonly hideStack = true;
1111

1212
file?: string;
@@ -32,4 +32,4 @@ class IssueWebpackError extends Error {
3232
}
3333
}
3434

35-
export { IssueWebpackError };
35+
export { IssueRspackError };

src/typescript/type-script-support.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ function assertTypeScriptSupport(config: TypeScriptWorkerConfig) {
99
try {
1010
// eslint-disable-next-line @typescript-eslint/no-var-requires
1111
typescriptVersion = require(config.typescriptPath).version;
12-
} catch (error) {
12+
} catch {
1313
// silent catch
1414
}
1515

@@ -23,9 +23,9 @@ function assertTypeScriptSupport(config: TypeScriptWorkerConfig) {
2323
throw new Error(
2424
[
2525
`Cannot find the "${config.configFile}" file.`,
26-
`Please check webpack and TsCheckerRspackPlugin configuration.`,
26+
`Please check Rspack and TsCheckerRspackPlugin configuration.`,
2727
`Possible errors:`,
28-
' - wrong `context` directory in webpack configuration (if `configFile` is not set or is a relative path in the fork plugin configuration)',
28+
' - wrong `context` directory in Rspack configuration (if `configFile` is not set or is a relative path in the fork plugin configuration)',
2929
' - wrong `typescript.configFile` path in the plugin configuration (should be a relative or absolute path)',
3030
].join(os.EOL)
3131
);

src/typescript/worker/lib/system.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ export interface ControlledTypeScriptSystem extends ts.System {
2424
path: string,
2525
callback: ts.FileWatcherCallback,
2626
pollingInterval?: number,
27-
options?: ts.WatchOptions
27+
options?: ts.WatchOptions,
2828
): ts.FileWatcher;
2929
watchDirectory(
3030
path: string,
3131
callback: ts.DirectoryWatcherCallback,
3232
recursive?: boolean,
33-
options?: ts.WatchOptions
33+
options?: ts.WatchOptions,
3434
): ts.FileWatcher;
3535
getModifiedTime(path: string | undefined): Date | undefined;
3636
setModifiedTime(path: string, time: Date): void;
@@ -109,7 +109,7 @@ export const system: ControlledTypeScriptSystem = {
109109
.filter(
110110
(dirent) =>
111111
dirent.isDirectory() ||
112-
(dirent.isSymbolicLink() && system.directoryExists(join(path, dirent.name)))
112+
(dirent.isSymbolicLink() && system.directoryExists(join(path, dirent.name))),
113113
)
114114
.map((dirent) => dirent.name);
115115
},
@@ -135,12 +135,12 @@ export const system: ControlledTypeScriptSystem = {
135135
watchDirectory(
136136
path: string,
137137
callback: ts.DirectoryWatcherCallback,
138-
recursive = false
138+
recursive = false,
139139
): ts.FileWatcher {
140140
return createWatcher(
141141
recursive ? recursiveDirectoryWatcherCallbacksMap : directoryWatcherCallbacksMap,
142142
path,
143-
callback
143+
callback,
144144
);
145145
},
146146
// use immediate instead of timeout to avoid waiting 250ms for batching files changes
@@ -206,7 +206,7 @@ export const system: ControlledTypeScriptSystem = {
206206
function createWatcher<TCallback>(
207207
watchersMap: Map<string, TCallback[]>,
208208
path: string,
209-
callback: TCallback
209+
callback: TCallback,
210210
) {
211211
const normalizedPath = normalizeAndResolvePath(path);
212212
const watchers = watchersMap.get(normalizedPath) || [];
@@ -230,17 +230,17 @@ function createWatcher<TCallback>(
230230
function invokeFileWatchers(path: string, event: ts.FileWatcherEventKind) {
231231
const normalizedPath = normalizeAndResolvePath(path);
232232
if (normalizedPath.endsWith('.js')) {
233-
// trigger relevant .d.ts file watcher - handles the case, when we have webpack watcher
233+
// trigger relevant .d.ts file watcher - handles the case, when we have Rspack watcher
234234
// that points to a symlinked package
235235
invokeFileWatchers(normalizedPath.slice(0, -3) + '.d.ts', event);
236236
}
237237

238238
const fileWatcherCallbacks = fileWatcherCallbacksMap.get(normalizedPath);
239239
if (fileWatcherCallbacks) {
240240
// typescript expects normalized paths with posix forward slash
241-
fileWatcherCallbacks.forEach((fileWatcherCallback) =>
242-
fileWatcherCallback(forwardSlash(normalizedPath), event)
243-
);
241+
fileWatcherCallbacks.forEach((fileWatcherCallback) => {
242+
fileWatcherCallback(forwardSlash(normalizedPath), event);
243+
});
244244
}
245245
}
246246

@@ -254,9 +254,9 @@ function invokeDirectoryWatchers(path: string) {
254254

255255
const directoryWatcherCallbacks = directoryWatcherCallbacksMap.get(directory);
256256
if (directoryWatcherCallbacks) {
257-
directoryWatcherCallbacks.forEach((directoryWatcherCallback) =>
258-
directoryWatcherCallback(forwardSlash(normalizedPath))
259-
);
257+
directoryWatcherCallbacks.forEach((directoryWatcherCallback) => {
258+
directoryWatcherCallback(forwardSlash(normalizedPath));
259+
});
260260
}
261261

262262
recursiveDirectoryWatcherCallbacksMap.forEach(
@@ -266,11 +266,11 @@ function invokeDirectoryWatchers(path: string) {
266266
(directory.startsWith(watchedDirectory) &&
267267
forwardSlash(directory)[watchedDirectory.length] === '/')
268268
) {
269-
recursiveDirectoryWatcherCallbacks.forEach((recursiveDirectoryWatcherCallback) =>
270-
recursiveDirectoryWatcherCallback(forwardSlash(normalizedPath))
271-
);
269+
recursiveDirectoryWatcherCallbacks.forEach((recursiveDirectoryWatcherCallback) => {
270+
recursiveDirectoryWatcherCallback(forwardSlash(normalizedPath));
271+
});
272272
}
273-
}
273+
},
274274
);
275275
}
276276

test/unit/formatter/webpack-formatter.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import os from 'os';
22
import { join } from 'path';
33

44
import type { Formatter } from 'src/formatter';
5-
import { createBasicFormatter, createWebpackFormatter } from 'src/formatter';
5+
import { createBasicFormatter, createRspackFormatter } from 'src/formatter';
66
import type { Issue } from 'src/issue';
77
import { forwardSlash } from 'src/utils/path/forward-slash';
88

@@ -28,8 +28,8 @@ describe('formatter/webpack-formatter', () => {
2828
let absoluteFormatter: Formatter;
2929

3030
beforeEach(() => {
31-
relativeFormatter = createWebpackFormatter(createBasicFormatter(), 'relative');
32-
absoluteFormatter = createWebpackFormatter(createBasicFormatter(), 'absolute');
31+
relativeFormatter = createRspackFormatter(createBasicFormatter(), 'relative');
32+
absoluteFormatter = createRspackFormatter(createBasicFormatter(), 'absolute');
3333
});
3434

3535
it('decorates existing relativeFormatter', () => {

test/unit/typescript/type-script-support.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ describe('typescript/type-script-support', () => {
4646
expect(() => assertTypeScriptSupport(configuration)).toThrowError(
4747
[
4848
`Cannot find the "./tsconfig.json" file.`,
49-
`Please check webpack and TsCheckerRspackPlugin configuration.`,
49+
`Please check Rspack and TsCheckerRspackPlugin configuration.`,
5050
`Possible errors:`,
51-
' - wrong `context` directory in webpack configuration (if `configFile` is not set or is a relative path in the fork plugin configuration)',
51+
' - wrong `context` directory in Rspack configuration (if `configFile` is not set or is a relative path in the fork plugin configuration)',
5252
' - wrong `typescript.configFile` path in the plugin configuration (should be a relative or absolute path)',
5353
].join(os.EOL)
5454
);

0 commit comments

Comments
 (0)