Skip to content

Commit

Permalink
fix: move @types/webpack-sources to dependencies (close: #5867)
Browse files Browse the repository at this point in the history
  • Loading branch information
Amour1688 committed Mar 6, 2024
1 parent debe2bc commit 5b738a0
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 7 deletions.
1 change: 0 additions & 1 deletion packages/rspack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 4 additions & 3 deletions packages/rspack/src/exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
119 changes: 119 additions & 0 deletions packages/rspack/src/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
3 changes: 0 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5b738a0

Please sign in to comment.