Skip to content

Commit

Permalink
refactor(typescript): packages/rspack/src/lib from js to ts and esm (#…
Browse files Browse the repository at this point in the history
…7289)

* chore: rename

* chore: save progress

* refactor(typescript): packages/rspack/src/lib from js to ts and esm

* chore: restore the ignoreWarningsPlugin filename

* chore: restore

* chore: restore EnvironmentPlugin

* chore: delete ignoreWarningsPlugin.ts

* chore: restore IgnoreWarningsPlugin.ts

* chore: rebase

* chore: resolve review conversation

---------

Co-authored-by: SoonIter <sooniter@gmail.com>
  • Loading branch information
shulaoda and SoonIter authored Jul 29, 2024
1 parent ed6afda commit ebf8483
Show file tree
Hide file tree
Showing 27 changed files with 2,385 additions and 2,185 deletions.
2,408 changes: 1,273 additions & 1,135 deletions packages/rspack/etc/api.md

Large diffs are not rendered by default.

72 changes: 37 additions & 35 deletions packages/rspack/src/Compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,60 +9,62 @@
*/
import * as binding from "@rspack/binding";
import * as liteTapable from "@rspack/lite-tapable";
import type Watchpack from "watchpack";
import { Compilation, type CompilationParams } from "./Compilation";
import { ContextModuleFactory } from "./ContextModuleFactory";
import { ThreadsafeWritableNodeFS } from "./FileSystem";
import { RuleSetCompiler } from "./RuleSetCompiler";
import { Stats } from "./Stats";
import {
type EntryNormalized,
type OutputNormalized,
type RspackOptionsNormalized,
type RspackPluginInstance,
getRawOptions
} from "./config";
import ConcurrentCompilationError from "./error/ConcurrentCompilationError";
import { rspack } from "./index";
import Cache = require("./lib/Cache");
import CacheFacade = require("./lib/CacheFacade");
import type { Source } from "webpack-sources";

import { Chunk } from "./Chunk";
import ExecuteModulePlugin from "./ExecuteModulePlugin";
import type { FileSystemInfoEntry } from "./FileSystemInfo";
import {
CodeGenerationResult,
type ContextModuleFactoryAfterResolveResult,
Module,
type ResolveData
} from "./Module";
import {
type NormalModuleCreateData,
NormalModuleFactory
} from "./NormalModuleFactory";
import { ResolverFactory } from "./ResolverFactory";
import ConcurrentCompilationError from "./error/ConcurrentCompilationError";
import Cache from "./lib/Cache";
import CacheFacade from "./lib/CacheFacade";

import {
RuntimeGlobals,
__from_binding_runtime_globals,
__to_binding_runtime_globals
} from "./RuntimeGlobals";
import { Watching } from "./Watching";
import {
JavascriptModulesPlugin,
JsLoaderRspackPlugin
} from "./builtin-plugin";

import { Chunk } from "./Chunk";
import { Compilation } from "./Compilation";
import { ContextModuleFactory } from "./ContextModuleFactory";
import { ThreadsafeWritableNodeFS } from "./FileSystem";
import { CodeGenerationResult, Module } from "./Module";
import { NormalModuleFactory } from "./NormalModuleFactory";
import { ResolverFactory } from "./ResolverFactory";
import { RuleSetCompiler } from "./RuleSetCompiler";
import { Stats } from "./Stats";
import { Watching } from "./Watching";
import { getRawOptions } from "./config";
import { rspack } from "./index";
import { unsupported } from "./util";

import { canInherentFromParent } from "./builtin-plugin/base";
import { applyRspackOptionsDefaults } from "./config/defaults";
import { tryRunOrWebpackError } from "./lib/HookWebpackError";
import { Logger } from "./logging/Logger";
import { unsupported } from "./util";
import { assertNotNill } from "./util/assertNotNil";
import { checkVersion } from "./util/bindingVersionCheck";
import { createHash } from "./util/createHash";
import type { OutputFileSystem, WatchFileSystem } from "./util/fs";
import { makePathsRelative } from "./util/identifier";

import type Watchpack from "watchpack";
import type { Source } from "webpack-sources";
import type { CompilationParams } from "./Compilation";
import type { FileSystemInfoEntry } from "./FileSystemInfo";
import type {
ContextModuleFactoryAfterResolveResult,
ResolveData
} from "./Module";
import type { NormalModuleCreateData } from "./NormalModuleFactory";
import type {
EntryNormalized,
OutputNormalized,
RspackOptionsNormalized,
RspackPluginInstance
} from "./config";
import type { OutputFileSystem, WatchFileSystem } from "./util/fs";

export interface AssetEmittedInfo {
content: Buffer;
source: Source;
Expand Down Expand Up @@ -279,7 +281,7 @@ class Compiler {
return new CacheFacade(
this.cache,
`${this.compilerPath}${name}`,
this.options.output.hashFunction
this.options.output.hashFunction as string
);
}

Expand Down
2 changes: 2 additions & 0 deletions packages/rspack/src/NormalModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,5 @@ export class NormalModule {
return hooks;
}
}

export default NormalModule;
51 changes: 0 additions & 51 deletions packages/rspack/src/lib/AbstractMethodError.js

This file was deleted.

51 changes: 51 additions & 0 deletions packages/rspack/src/lib/AbstractMethodError.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* The following code is modified based on
* https://github.com/webpack/webpack/blob/4b4ca3b/lib/AbstractMethodError.js
*
* MIT Licensed
* Author Tobias Koppers @sokra
* Copyright (c) JS Foundation and other contributors
* https://github.com/webpack/webpack/blob/main/LICENSE
*/

import WebpackError from "./WebpackError";

const CURRENT_METHOD_REGEXP = /at ([a-zA-Z0-9_.]*)/;

/**
* @param method method name
* @returns message
*/
function createMessage(method?: string): string {
return `Abstract method${method ? " " + method : ""}. Must be overridden.`;
}

class Message extends Error {
constructor() {
super();
this.stack = undefined;
Error.captureStackTrace(this);
const match = this.stack!.split("\n")[3].match(CURRENT_METHOD_REGEXP);
this.message =
match && match[1] ? createMessage(match[1]) : createMessage();
}
}

/**
* Error for abstract method
* @example
* class FooClass {
* abstractMethod() {
* throw new AbstractMethodError(); // error message: Abstract method FooClass.abstractMethod. Must be overridden.
* }
* }
*
*/
export class AbstractMethodError extends WebpackError {
constructor() {
super(new Message().message);
this.name = "AbstractMethodError";
}
}

export default AbstractMethodError;
175 changes: 0 additions & 175 deletions packages/rspack/src/lib/Cache.js

This file was deleted.

Loading

2 comments on commit ebf8483

@rspack-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Ran ecosystem CI: Open

suite result
modernjs ❌ failure
_selftest ✅ success
nx ❌ failure
rspress ✅ success
rsbuild ✅ success
examples ✅ success

@rspack-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Benchmark detail: Open

Name Base (2024-07-29 c507fe6) Current Change
10000_development-mode + exec 2.18 s ± 21 ms 2.18 s ± 34 ms -0.13 %
10000_development-mode_hmr + exec 693 ms ± 6.5 ms 701 ms ± 5 ms +1.15 %
10000_production-mode + exec 2.63 s ± 34 ms 2.67 s ± 28 ms +1.43 %
arco-pro_development-mode + exec 1.9 s ± 71 ms 1.87 s ± 41 ms -1.86 %
arco-pro_development-mode_hmr + exec 434 ms ± 1.3 ms 435 ms ± 2.7 ms +0.25 %
arco-pro_production-mode + exec 3.39 s ± 72 ms 3.42 s ± 89 ms +0.84 %
threejs_development-mode_10x + exec 1.77 s ± 26 ms 1.75 s ± 12 ms -1.12 %
threejs_development-mode_10x_hmr + exec 876 ms ± 8.8 ms 863 ms ± 7.8 ms -1.57 %
threejs_production-mode_10x + exec 5.49 s ± 29 ms 5.5 s ± 32 ms +0.06 %

Please sign in to comment.