diff --git a/packages/rspack/package.json b/packages/rspack/package.json index c5bd9d1b84d..8f5068f5040 100644 --- a/packages/rspack/package.json +++ b/packages/rspack/package.json @@ -38,7 +38,6 @@ "@rspack/plugin-minify": "workspace:^", "@rspack/plugin-node-polyfill": "workspace:^", "@types/watchpack": "^2.4.0", - "@types/webpack-sources": "3.2.3", "@types/ws": "8.5.10", "babel-loader": "^9.1.0", "babel-plugin-import": "^1.13.5", diff --git a/packages/rspack/src/exports.ts b/packages/rspack/src/exports.ts index 5dd33b0fe30..60677a62a17 100644 --- a/packages/rspack/src/exports.ts +++ b/packages/rspack/src/exports.ts @@ -46,13 +46,14 @@ export const WebpackError = Error; export type { Watching } from "./Watching"; -const sources = require("webpack-sources"); // use require to avoid wrong types, @types/webpack-sources is outdate -export { sources }; - +import sources from "webpack-sources"; import { getNormalizedRspackOptions, applyRspackOptionsDefaults } from "./config"; + +export { sources }; + export const config = { getNormalizedRspackOptions, applyRspackOptionsDefaults, diff --git a/packages/rspack/src/global.d.ts b/packages/rspack/src/global.d.ts index 6e3581a6a56..06d2f1b9fd4 100644 --- a/packages/rspack/src/global.d.ts +++ b/packages/rspack/src/global.d.ts @@ -109,3 +109,122 @@ declare module "neo-async" { export const forEach: typeof each; export const forEachLimit: typeof eachLimit; } + +declare module "webpack-sources" { + export type MapOptions = { columns?: boolean; module?: boolean }; + + export type RawSourceMap = { + version: number; + sources: string[]; + names: string[]; + sourceRoot?: string; + sourcesContent?: string[]; + mappings: string; + file: string; + }; + + export abstract class Source { + size(): number; + + map(options?: MapOptions): RawSourceMap | null; + + sourceAndMap(options?: MapOptions): { + source: string | Buffer; + map: Object; + }; + + updateHash(hash: Object): void; + + source(): string | Buffer; + + buffer(): Buffer; + } + + export class RawSource extends Source { + constructor(source: string | Buffer, convertToString?: boolean); + + isBuffer(): boolean; + } + + export class OriginalSource extends Source { + constructor(source: string | Buffer, name: string); + + getName(): string; + } + + export class ReplaceSource extends Source { + constructor(source: Source, name?: string); + + replace(start: number, end: number, newValue: string, name?: string): void; + insert(pos: number, newValue: string, name?: string): void; + + getName(): string; + original(): string; + getReplacements(): { + start: number; + end: number; + content: string; + insertIndex: number; + name: string; + }[]; + } + + export class SourceMapSource extends Source { + constructor( + source: string | Buffer, + name: string, + sourceMap: Object | string | Buffer, + originalSource?: string | Buffer, + innerSourceMap?: Object | string | Buffer, + removeOriginalSource?: boolean + ); + + getArgsAsBuffers(): [ + Buffer, + string, + Buffer, + Buffer | undefined, + Buffer | undefined, + boolean + ]; + } + + export class ConcatSource extends Source { + constructor(...args: (string | Source)[]); + + getChildren(): Source[]; + + add(item: string | Source): void; + addAllSkipOptimizing(items: Source[]): void; + } + + export class PrefixSource extends Source { + constructor(prefix: string, source: string | Source); + + original(): Source; + getPrefix(): string; + } + + export class CachedSource extends Source { + constructor(source: Source); + constructor(source: Source | (() => Source), cachedData?: any); + + original(): Source; + originalLazy(): Source | (() => Source); + getCachedData(): any; + } + + export class SizeOnlySource extends Source { + constructor(size: number); + } + + interface SourceLike { + source(): string | Buffer; + } + + export class CompatSource extends Source { + constructor(sourceLike: SourceLike); + + static from(sourceLike: SourceLike): Source; + } +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9a235c7c075..870a08f166e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -472,9 +472,6 @@ importers: '@types/watchpack': specifier: ^2.4.0 version: 2.4.0 - '@types/webpack-sources': - specifier: 3.2.3 - version: 3.2.3 '@types/ws': specifier: 8.5.10 version: 8.5.10