Skip to content

Commit

Permalink
chore: refactor util from js to ts
Browse files Browse the repository at this point in the history
  • Loading branch information
jithyaniag authored and SoonIter committed Jul 21, 2024
1 parent 0110aad commit 6180152
Show file tree
Hide file tree
Showing 15 changed files with 423 additions and 406 deletions.
17 changes: 11 additions & 6 deletions packages/rspack/etc/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@ import CacheFacade = require('./lib/CacheFacade');
import type { Callback } from '@rspack/lite-tapable';
import { cleanupGlobalTrace } from '@rspack/binding';
import { Compiler as Compiler_2 } from '../Compiler';
import { default as default_2 } from './util/hash';
import { RawEvalDevToolModulePluginOptions as EvalDevToolModulePluginOptions } from '@rspack/binding';
import { EventEmitter } from 'events';
import { ExternalObject } from '@rspack/binding';
import fs from 'graceful-fs';
import { fs as fs_2 } from 'fs';
import Hash_2 = require('./util/hash');
import Hash_3 = require('../util/hash');
import { HookMap } from '@rspack/lite-tapable';
import type { JsAssetInfo } from '@rspack/binding';
import { JsChunk } from '@rspack/binding';
Expand Down Expand Up @@ -1118,7 +1117,7 @@ export class Compilation {

// @public (undocumented)
type CompilationHooks = {
chunkHash: liteTapable.SyncHook<[Chunk, Hash_3]>;
chunkHash: liteTapable.SyncHook<[Chunk, Hash_2]>;
};

// @public (undocumented)
Expand Down Expand Up @@ -3952,6 +3951,12 @@ class Hash {
update(data: string | Buffer, inputEncoding?: string): Hash;
}

// @public (undocumented)
class Hash_2 {
digest(encoding?: string): string | Buffer;
update(data: string | Buffer, inputEncoding?: string): this;
}

// @public (undocumented)
export type HashDigest = z.infer<typeof hashDigest>;

Expand Down Expand Up @@ -4924,7 +4929,7 @@ export interface LoaderContext<OptionsType = {}> {
utils: {
absolutify: (context: string, request: string) => string;
contextify: (context: string, request: string) => string;
createHash: (algorithm?: string) => Hash_3;
createHash: (algorithm?: string) => Hash_2;
};
// (undocumented)
version: 2;
Expand Down Expand Up @@ -13818,8 +13823,8 @@ const uniqueName: z.ZodString;

// @public (undocumented)
export const util: {
createHash: (algorithm: any) => any;
cleverMerge: <T, O>(first: T, second: O) => T | O | (T & O);
createHash: (algorithm: "debug" | "md4" | "xxhash64" | (string & {}) | "native-md4" | (new () => default_2)) => default_2;
cleverMerge: <First, Second>(first: First, second: Second) => First | Second | (First & Second);
};

// @public (undocumented)
Expand Down
4 changes: 2 additions & 2 deletions packages/rspack/src/Compilation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { cutOffLoaderExecution } from "./ErrorHelpers";
import { type CodeGenerationResult, Module } from "./Module";
import type { NormalModuleFactory } from "./NormalModuleFactory";
import type { ResolverFactory } from "./ResolverFactory";
import { JsDiagnostic, type RspackError } from "./RspackError";
import {
Stats,
type StatsAsset,
Expand All @@ -48,10 +49,9 @@ import { StatsPrinter } from "./stats/StatsPrinter";
import { type AssetInfo, JsAssetInfo } from "./util/AssetInfo";
import MergeCaller from "./util/MergeCaller";
import { createFakeCompilationDependencies } from "./util/fake";
import type Hash from "./util/hash";
import { memoizeValue } from "./util/memoize";
import { JsSource } from "./util/source";
import Hash = require("./util/hash");
import { JsDiagnostic, type RspackError } from "./RspackError";
export { type AssetInfo } from "./util/AssetInfo";

export type Assets = Record<string, Source>;
Expand Down
6 changes: 6 additions & 0 deletions packages/rspack/src/Compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -976,6 +976,9 @@ class Compiler {
binding.RegisterJsTapKind.CompilationChunkHash,
() => this.#compilation!.hooks.chunkHash,
queried => (chunk: binding.JsChunk) => {
if (!this.options.output.hashFunction) {
throw new Error("'output.hashFunction' cannot be undefined");
}
const hash = createHash(this.options.output.hashFunction);
queried.call(Chunk.__from_binding(chunk, this.#compilation!), hash);
const digestResult = hash.digest(this.options.output.hashDigest);
Expand Down Expand Up @@ -1175,6 +1178,9 @@ class Compiler {
JavascriptModulesPlugin.getCompilationHooks(this.#compilation!)
.chunkHash,
queried => (chunk: binding.JsChunk) => {
if (!this.options.output.hashFunction) {
throw new Error("'output.hashFunction' cannot be undefined");
}
const hash = createHash(this.options.output.hashFunction);
queried.call(Chunk.__from_binding(chunk, this.#compilation!), hash);
const digestResult = hash.digest(this.options.output.hashDigest);
Expand Down
169 changes: 0 additions & 169 deletions packages/rspack/src/ModuleTypeConstants.js

This file was deleted.

Loading

0 comments on commit 6180152

Please sign in to comment.