@rspack/core
Advanced tools
Comparing version 0.0.0-1bce45e7c0-20221109113710 to 0.0.0-2d61de1089-20221122042420
import * as tapable from "tapable"; | ||
import { Source } from "webpack-sources"; | ||
import { JsCompilation, AssetInfo } from "@rspack/binding"; | ||
import { JsCompilation, JsAssetInfo } from "@rspack/binding"; | ||
import { RspackOptionsNormalized } from "./config"; | ||
import { ResolvedOutput } from "./config/output"; | ||
import { ChunkGroup } from "./chunk_group"; | ||
import { Compiler } from "./compiler"; | ||
export declare class Compilation { | ||
@@ -13,3 +16,5 @@ #private; | ||
options: RspackOptionsNormalized; | ||
constructor(options: RspackOptionsNormalized, inner: JsCompilation); | ||
outputOptions: ResolvedOutput; | ||
compiler: Compiler; | ||
constructor(compiler: Compiler, inner: JsCompilation); | ||
/** | ||
@@ -22,2 +27,6 @@ * Get a map of all assets. | ||
/** | ||
* Get a map of all entrypoints. | ||
*/ | ||
get entrypoints(): Map<string, ChunkGroup>; | ||
/** | ||
* Update an existing asset. Trying to update an asset that doesn't exist will throw an error. | ||
@@ -32,5 +41,5 @@ * | ||
* @param {Source | function(Source): Source} newSourceOrFunction new asset source or function converting old to new | ||
* @param {AssetInfo | function(AssetInfo): AssetInfo} assetInfoUpdateOrFunction new asset info or function converting old to new | ||
* @param {JsAssetInfo | function(JsAssetInfo): JsAssetInfo} assetInfoUpdateOrFunction new asset info or function converting old to new | ||
*/ | ||
updateAsset(filename: string, newSourceOrFunction: Source | ((source: Source) => Source), assetInfoUpdateOrFunction: AssetInfo | ((assetInfo: AssetInfo) => AssetInfo)): void; | ||
updateAsset(filename: string, newSourceOrFunction: Source | ((source: Source) => Source), assetInfoUpdateOrFunction: JsAssetInfo | ((assetInfo: JsAssetInfo) => JsAssetInfo)): void; | ||
/** | ||
@@ -44,6 +53,7 @@ * Emit an not existing asset. Trying to emit an asset that already exists will throw an error. | ||
* @param {Source} source asset source | ||
* @param {AssetInfo} assetInfo extra asset information | ||
* @param {JsAssetInfo} assetInfo extra asset information | ||
* @returns {void} | ||
*/ | ||
emitAsset(filename: string, source: Source, assetInfo?: AssetInfo): void; | ||
emitAsset(filename: string, source: Source, assetInfo?: JsAssetInfo): void; | ||
deleteAsset(filename: string): void; | ||
/** | ||
@@ -55,3 +65,3 @@ * Get an array of Asset | ||
* | ||
* @return {Readonly<Asset>[]} | ||
* @return {Readonly<JsAsset>[]} | ||
*/ | ||
@@ -61,4 +71,9 @@ getAssets(): { | ||
name: string; | ||
info: AssetInfo; | ||
info: JsAssetInfo; | ||
}[]; | ||
getAsset(name: string): { | ||
source: Source; | ||
name: string; | ||
info: JsAssetInfo; | ||
}; | ||
getPath(filename: string, data?: Record<string, any>): any; | ||
@@ -70,2 +85,3 @@ getAssetPath(filename: any, data: any): any; | ||
} | ||
export type { JsAssetInfo }; | ||
//# sourceMappingURL=compilation.d.ts.map |
@@ -42,5 +42,7 @@ "use strict"; | ||
const createSource_1 = require("./utils/createSource"); | ||
const chunk_group_1 = require("./chunk_group"); | ||
const hashDigestLength = 8; | ||
const EMPTY_ASSET_INFO = {}; | ||
class Compilation { | ||
constructor(options, inner) { | ||
constructor(compiler, inner) { | ||
_Compilation_inner.set(this, void 0); | ||
@@ -52,5 +54,7 @@ this.hooks = { | ||
}; | ||
this.options = options; | ||
this.compiler = compiler; | ||
this.options = compiler.options; | ||
this.outputOptions = compiler.options.output; | ||
const hash = (0, createHash_1.createHash)(this.options.output.hashFunction); | ||
this.fullHash = hash.digest(options.output.hashDigest); | ||
this.fullHash = hash.digest(this.options.output.hashDigest); | ||
this.hash = this.fullHash.slice(0, hashDigestLength); | ||
@@ -69,2 +73,11 @@ __classPrivateFieldSet(this, _Compilation_inner, inner, "f"); | ||
/** | ||
* Get a map of all entrypoints. | ||
*/ | ||
get entrypoints() { | ||
return new Map(Object.entries(__classPrivateFieldGet(this, _Compilation_inner, "f").entrypoints).map(([n, e]) => [ | ||
n, | ||
new chunk_group_1.ChunkGroup(e) | ||
])); | ||
} | ||
/** | ||
* Update an existing asset. Trying to update an asset that doesn't exist will throw an error. | ||
@@ -79,3 +92,3 @@ * | ||
* @param {Source | function(Source): Source} newSourceOrFunction new asset source or function converting old to new | ||
* @param {AssetInfo | function(AssetInfo): AssetInfo} assetInfoUpdateOrFunction new asset info or function converting old to new | ||
* @param {JsAssetInfo | function(JsAssetInfo): JsAssetInfo} assetInfoUpdateOrFunction new asset info or function converting old to new | ||
*/ | ||
@@ -102,3 +115,3 @@ updateAsset(filename, newSourceOrFunction, assetInfoUpdateOrFunction) { | ||
* @param {Source} source asset source | ||
* @param {AssetInfo} assetInfo extra asset information | ||
* @param {JsAssetInfo} assetInfo extra asset information | ||
* @returns {void} | ||
@@ -109,2 +122,3 @@ */ | ||
development: false, | ||
hotModuleReplacement: false, | ||
related: {} | ||
@@ -114,2 +128,5 @@ }) { | ||
} | ||
deleteAsset(filename) { | ||
__classPrivateFieldGet(this, _Compilation_inner, "f").deleteAsset(filename); | ||
} | ||
/** | ||
@@ -121,3 +138,3 @@ * Get an array of Asset | ||
* | ||
* @return {Readonly<Asset>[]} | ||
* @return {Readonly<JsAsset>[]} | ||
*/ | ||
@@ -134,2 +151,12 @@ getAssets() { | ||
} | ||
getAsset(name) { | ||
const asset = __classPrivateFieldGet(this, _Compilation_inner, "f").getAsset(name); | ||
if (!asset) { | ||
return; | ||
} | ||
return { | ||
...asset, | ||
source: (0, createSource_1.createSourceFromRaw)(asset.source) | ||
}; | ||
} | ||
// TODO: full alignment | ||
@@ -136,0 +163,0 @@ getPath(filename, data = {}) { |
@@ -18,2 +18,3 @@ import * as tapable from "tapable"; | ||
outputFileSystem: any; | ||
context: string; | ||
hooks: { | ||
@@ -36,8 +37,5 @@ done: tapable.AsyncSeriesHook<Stats>; | ||
run(callback: any): void; | ||
build(cb: Callback<Error, binding.StatsCompilation>): void; | ||
rebuild(changedFiles: string[], cb: (error?: Error, stats?: { | ||
diff: binding.DiffStat; | ||
stats: binding.StatsCompilation; | ||
}) => void): void; | ||
watch(watchOptions?: Watch, ws?: any): Promise<Watching>; | ||
build(cb: Callback<Error, binding.JsStatsCompilation>): void; | ||
rebuild(changedFiles: string[], cb: (error?: Error, stats?: binding.JsStatsCompilation) => void): void; | ||
watch(watchOptions?: Watch): Promise<Watching>; | ||
purgeInputFileSystem(): void; | ||
@@ -44,0 +42,0 @@ /** |
@@ -30,6 +30,12 @@ "use strict"; | ||
}; | ||
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { | ||
if (kind === "m") throw new TypeError("Private method is not writable"); | ||
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter"); | ||
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it"); | ||
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
var _Compiler_instances, _Compiler_instance_get, _Compiler_done, _Compiler_processAssets, _Compiler_compilation, _Compiler_newCompilation; | ||
var _Compiler_instances, _Compiler__instance, _Compiler_instance_get, _Compiler_done, _Compiler_processAssets, _Compiler_compilation, _Compiler_newCompilation; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -58,2 +64,3 @@ exports.Compiler = void 0; | ||
_Compiler_instances.add(this); | ||
_Compiler__instance.set(this, void 0); | ||
this.options = options; | ||
@@ -63,4 +70,8 @@ // to workaround some plugin access webpack, we may change dev-server to avoid this hack in the future | ||
EntryPlugin, | ||
HotModuleReplacementPlugin // modernjs/server will auto inject this this plugin not set | ||
HotModuleReplacementPlugin, | ||
get sources() { | ||
return require("webpack-sources"); | ||
} | ||
}; | ||
this.context = context; | ||
this.hooks = { | ||
@@ -215,3 +226,3 @@ initialize: new tapable_1.SyncHook([]), | ||
// TODO: in `dev-server` | ||
async watch(watchOptions, ws) { | ||
async watch(watchOptions) { | ||
const options = (0, watch_1.resolveWatchOption)(watchOptions); | ||
@@ -226,11 +237,5 @@ let logger = this.getInfrastructureLogger("watch"); | ||
let stats = new stats_1.Stats(rawStats); | ||
if (stats.hasErrors()) { | ||
console.log(stats.toString({ | ||
all: false, | ||
warnings: true, | ||
errors: true, | ||
...this.options.stats | ||
})); | ||
} | ||
await this.hooks.done.promise(stats); | ||
// TODO: log stats string should move to cli | ||
console.log(stats.toString(this.options.stats)); | ||
console.log("build success, time cost", Date.now() - begin, "ms"); | ||
@@ -254,13 +259,6 @@ let pendingChangedFilepaths = new Set(); | ||
const begin = Date.now(); | ||
this.rebuild(changedFilepath, (error, { diff, stats: rawStats }) => { | ||
this.rebuild(changedFilepath, (error, rawStats) => { | ||
let stats = new stats_1.Stats(rawStats); | ||
// TODO: log stats string should move to cli | ||
if (stats.hasErrors()) { | ||
console.log(stats.toString({ | ||
all: false, | ||
warnings: true, | ||
errors: true, | ||
...this.options.stats | ||
})); | ||
} | ||
console.log(stats.toString(this.options.stats)); | ||
isBuildFinished = true; | ||
@@ -277,41 +275,7 @@ const hasPending = Boolean(pendingChangedFilepaths.size); | ||
} | ||
for (const [uri, stats] of Object.entries(diff)) { | ||
let relativePath = path_1.default.relative(this.options.context, uri); | ||
if (!(relativePath.startsWith("../") || | ||
relativePath.startsWith("./"))) { | ||
relativePath = "./" + relativePath; | ||
this.hooks.done.callAsync(stats, err => { | ||
if (err) { | ||
throw err; | ||
} | ||
// send Message | ||
if (ws) { | ||
const data = { | ||
uri: relativePath, | ||
content: stats.content | ||
}; | ||
if (/\.[less|css|sass|scss]$/.test(data.uri)) { | ||
const cssOutput = fs_1.default | ||
.readFileSync(path_1.default.resolve(this.options.output.path, "main.css")) | ||
.toString("utf-8"); | ||
// TODO: need support more | ||
data.content = [ | ||
`var cssStyleTag = document.querySelector("style[id='hot-css']")`, | ||
`if (cssStyleTag) {`, | ||
` cssStyleTag.innerText = \`${cssOutput}\``, | ||
`} else {`, | ||
` var newCSStyleTag = document.createElement('style')`, | ||
` newCSStyleTag.setAttribute('id', 'hot-css')`, | ||
` newCSStyleTag.innerText = \`${cssOutput}\``, | ||
` document.head.appendChild(newCSStyleTag)`, | ||
`}`, | ||
``, | ||
`var outdataCSSLinkTag = document.querySelector("link[href='main.css']")`, | ||
`outdataCSSLinkTag && outdataCSSLinkTag.parentNode && outdataCSSLinkTag.parentNode.removeChild(outdataCSSLinkTag)` | ||
].join("\n"); | ||
} | ||
for (const client of ws.clients) { | ||
// the type of "ok" means rebuild success. | ||
// the data should deleted after we had hash in stats. | ||
client.send(JSON.stringify({ type: "ok", data: JSON.stringify(data) })); | ||
} | ||
} | ||
} | ||
}); | ||
console.log("rebuild success, time cost", Date.now() - begin, "ms"); | ||
@@ -369,23 +333,20 @@ }); | ||
exports.Compiler = Compiler; | ||
_Compiler_instances = new WeakSet(), _Compiler_instance_get = function _Compiler_instance_get() { | ||
// @ts-ignored | ||
this._instance = | ||
// @ts-ignored | ||
this._instance || | ||
// @ts-ignored | ||
new binding.Rspack(this.options, { | ||
doneCallback: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_done).bind(this), | ||
processAssetsCallback: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_processAssets).bind(this), | ||
// `Compilation` should be created with hook `thisCompilation`, and here is the reason: | ||
// We know that the hook `thisCompilation` will not be called from a child compiler(it doesn't matter whether the child compiler is created on the Rust or the Node side). | ||
// See webpack's API: https://webpack.js.org/api/compiler-hooks/#thiscompilation | ||
// So it is safe to create a new compilation here. | ||
thisCompilationCallback: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_newCompilation).bind(this), | ||
// The hook `Compilation` should be called whenever it's a call from the child compiler or normal compiler and | ||
// still it does not matter where the child compiler is created(Rust or Node) as calling the hook `compilation` is a required task. | ||
// No matter how it will be implemented, it will be copied to the child compiler. | ||
compilationCallback: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_compilation).bind(this) | ||
}); | ||
// @ts-ignored | ||
return this._instance; | ||
_Compiler__instance = new WeakMap(), _Compiler_instances = new WeakSet(), _Compiler_instance_get = function _Compiler_instance_get() { | ||
// @ts-ignore TODO: fix this | ||
const options = this.options; | ||
__classPrivateFieldSet(this, _Compiler__instance, __classPrivateFieldGet(this, _Compiler__instance, "f") || | ||
new binding.Rspack(options, { | ||
done: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_done).bind(this), | ||
processAssets: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_processAssets).bind(this), | ||
// `Compilation` should be created with hook `thisCompilation`, and here is the reason: | ||
// We know that the hook `thisCompilation` will not be called from a child compiler(it doesn't matter whether the child compiler is created on the Rust or the Node side). | ||
// See webpack's API: https://webpack.js.org/api/compiler-hooks/#thiscompilation | ||
// So it is safe to create a new compilation here. | ||
thisCompilation: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_newCompilation).bind(this), | ||
// The hook `Compilation` should be called whenever it's a call from the child compiler or normal compiler and | ||
// still it does not matter where the child compiler is created(Rust or Node) as calling the hook `compilation` is a required task. | ||
// No matter how it will be implemented, it will be copied to the child compiler. | ||
compilation: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_compilation).bind(this) | ||
}), "f"); | ||
return __classPrivateFieldGet(this, _Compiler__instance, "f"); | ||
}, _Compiler_done = function _Compiler_done(statsJson) { }, _Compiler_processAssets = async function _Compiler_processAssets(assets) { | ||
@@ -401,3 +362,3 @@ let iterator = Object.entries(assets).map(([filename, source]) => [ | ||
}, _Compiler_newCompilation = function _Compiler_newCompilation(native) { | ||
const compilation = new compilation_1.Compilation(this.options, native); | ||
const compilation = new compilation_1.Compilation(this, native); | ||
this.compilation = compilation; | ||
@@ -404,0 +365,0 @@ this.hooks.thisCompilation.call(this.compilation); |
@@ -1,8 +0,10 @@ | ||
import type { RawBuiltins, RawHtmlPluginConfig } from "@rspack/binding"; | ||
import type { RawBuiltins, RawHtmlPluginConfig, RawDecoratorOptions } from "@rspack/binding"; | ||
export declare type BuiltinsHtmlPluginConfig = Omit<RawHtmlPluginConfig, "meta"> & { | ||
meta?: Record<string, string | Record<string, string>>; | ||
}; | ||
export declare type Builtins = Omit<RawBuiltins, "browserslist" | "html"> & { | ||
export declare type Builtins = Omit<RawBuiltins, "define" | "browserslist" | "html" | "decorator"> & { | ||
define?: Record<string, string | undefined>; | ||
polyfillBuiltins?: boolean; | ||
html?: Array<BuiltinsHtmlPluginConfig>; | ||
decorator?: boolean | Partial<RawDecoratorOptions>; | ||
}; | ||
@@ -9,0 +11,0 @@ export declare type ResolvedBuiltins = Omit<RawBuiltins, "html"> & { |
@@ -5,6 +5,6 @@ "use strict"; | ||
const browserslist_1 = require("browserslist"); | ||
function resolveDefine(define = {}) { | ||
function resolveDefine(define) { | ||
const entries = Object.entries(define).map(([key, value]) => [ | ||
key, | ||
JSON.stringify(value) | ||
value === undefined ? "undefined" : value | ||
]); | ||
@@ -27,2 +27,15 @@ return Object.fromEntries(entries); | ||
} | ||
function resolveDecorator(decorator) { | ||
if (decorator === false) { | ||
return undefined; | ||
} | ||
if (decorator === undefined || decorator === true) { | ||
decorator = {}; | ||
} | ||
return Object.assign({ | ||
legacy: true, | ||
emitMetadata: true, | ||
useDefineForClassFields: true | ||
}, decorator); | ||
} | ||
function resolveBuiltinsOptions(builtins, contextPath) { | ||
@@ -32,4 +45,6 @@ const browserslist = (0, browserslist_1.loadConfig)({ path: contextPath }) || []; | ||
...builtins, | ||
define: resolveDefine(builtins.define || {}), | ||
html: resolveHtml(builtins.html || []), | ||
browserslist | ||
browserslist, | ||
decorator: resolveDecorator(builtins.decorator) | ||
}; | ||
@@ -36,0 +51,0 @@ } |
@@ -38,5 +38,6 @@ "use strict"; | ||
}; | ||
const applyOutputDefault = (output) => { | ||
const applyOutputDefaults = (output) => { | ||
D(output, "hashFunction", "xxhash64"); | ||
F(output, "path", () => path_1.default.resolve(process.cwd(), "dist")); | ||
D(output, "publicPath", "auto"); | ||
return output; | ||
@@ -54,3 +55,3 @@ }; | ||
F(options, "devtool", () => (development ? "eval" : "")); | ||
applyOutputDefault(options.output); | ||
applyOutputDefaults(options.output); | ||
D(options.builtins, "minify", production); | ||
@@ -57,0 +58,0 @@ } |
@@ -10,2 +10,3 @@ import type { WatchOptions } from "chokidar"; | ||
export interface Dev { | ||
host?: string; | ||
port?: number | string; | ||
@@ -12,0 +13,0 @@ static?: { |
@@ -56,2 +56,3 @@ import type { Context, ResolvedContext } from "./context"; | ||
export { resolveWatchOption } from "./watch"; | ||
export type { StatsOptions } from "./stats"; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -25,3 +25,3 @@ "use strict"; | ||
const builtins = (0, builtins_1.resolveBuiltinsOptions)(config.builtins || {}, context); | ||
const resolve = (0, resolve_1.resolveResolveOptions)(config.resolve); | ||
const resolve = (0, resolve_1.resolveResolveOptions)(config.resolve, { target }); | ||
const devtool = (0, devtool_1.resolveDevtoolOptions)(config.devtool); | ||
@@ -28,0 +28,0 @@ const module = (0, module_1.resolveModuleOptions)(config.module, { devtool, context }); |
@@ -38,2 +38,11 @@ "use strict"; | ||
(0, node_assert_1.default)("loader" in use); | ||
/** | ||
* support loader as string | ||
*/ | ||
if (typeof use.loader === "string") { | ||
let loaderPath = require.resolve(use.loader, { | ||
paths: [options.context] | ||
}); | ||
use.loader = require(loaderPath); | ||
} | ||
const loaderContext = { | ||
@@ -40,0 +49,0 @@ ...loaderContextInternal, |
@@ -0,1 +1,2 @@ | ||
import type { ResolvedTarget } from "./target"; | ||
export declare type Resolve = { | ||
@@ -21,3 +22,7 @@ preferRelative?: boolean; | ||
}; | ||
export declare function resolveResolveOptions(resolve?: Resolve): ResolvedResolve; | ||
interface ResolveContext { | ||
target: ResolvedTarget; | ||
} | ||
export declare function resolveResolveOptions(resolve: Resolve, { target }: ResolveContext): ResolvedResolve; | ||
export {}; | ||
//# sourceMappingURL=resolve.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.resolveResolveOptions = void 0; | ||
function resolveResolveOptions(resolve = {}) { | ||
function resolveResolveOptions(resolve = {}, { target }) { | ||
var _a, _b, _c, _d, _e, _f, _g, _h; | ||
@@ -15,3 +15,7 @@ const preferRelative = (_a = resolve.preferRelative) !== null && _a !== void 0 ? _a : false; | ||
]; | ||
const mainFields = (_c = resolve.mainFields) !== null && _c !== void 0 ? _c : ["module", "main"]; | ||
const defaultMainFields = ["module", "main"]; | ||
if (target.includes("web")) { | ||
defaultMainFields.unshift("browser"); | ||
} | ||
const mainFields = (_c = resolve.mainFields) !== null && _c !== void 0 ? _c : defaultMainFields; | ||
const mainFiles = (_d = resolve.mainFiles) !== null && _d !== void 0 ? _d : ["index"]; | ||
@@ -18,0 +22,0 @@ const browserField = (_e = resolve.browserField) !== null && _e !== void 0 ? _e : true; |
import * as binding from "@rspack/binding"; | ||
export declare type ResolvedStatsOptions = binding.RawStatsOptions; | ||
export interface StatsOptions { | ||
colors?: boolean; | ||
export interface StatsOptionsObj { | ||
all?: boolean; | ||
preset?: "normal" | "none" | "verbose" | "errors-only" | "errors-warnings"; | ||
assets?: boolean; | ||
chunks?: boolean; | ||
modules?: boolean; | ||
entrypoints?: boolean; | ||
warnings?: boolean; | ||
warningsCount?: boolean; | ||
errors?: boolean; | ||
errorsCount?: boolean; | ||
colors?: boolean; | ||
} | ||
export declare function resolveStatsOptions(options?: StatsOptions): ResolvedStatsOptions; | ||
export declare type StatsOptions = StatsOptionsObj | boolean | string; | ||
/** | ||
* resolve `StatsOptions` to `binding.RawStatsOptions`. | ||
*/ | ||
export declare function resolveStatsOptions(opts?: StatsOptions): ResolvedStatsOptions; | ||
//# sourceMappingURL=stats.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.resolveStatsOptions = void 0; | ||
function resolveStatsOptions(options = {}) { | ||
const colors = optionsOrFallback(options.colors, false); | ||
const stats_1 = require("../stats"); | ||
/** | ||
* resolve `StatsOptions` to `binding.RawStatsOptions`. | ||
*/ | ||
function resolveStatsOptions(opts = {}) { | ||
const options = (0, stats_1.normalizeStatsPreset)(opts); | ||
const colors = (0, stats_1.optionsOrFallback)(options.colors, false); | ||
return { | ||
...options, | ||
colors | ||
@@ -11,7 +17,2 @@ }; | ||
exports.resolveStatsOptions = resolveStatsOptions; | ||
const optionsOrFallback = (...args) => { | ||
let optionValues = []; | ||
optionValues.push(...args); | ||
return optionValues.find(optionValue => optionValue !== undefined); | ||
}; | ||
//# sourceMappingURL=stats.js.map |
export * from "./compiler"; | ||
export * from "./compilation"; | ||
export * from "./config"; | ||
export * from "./rspack"; | ||
export * from "./stats"; | ||
export * from "./chunk_group"; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -18,4 +18,7 @@ "use strict"; | ||
__exportStar(require("./compiler"), exports); | ||
__exportStar(require("./compilation"), exports); | ||
__exportStar(require("./config"), exports); | ||
__exportStar(require("./rspack"), exports); | ||
__exportStar(require("./stats"), exports); | ||
__exportStar(require("./chunk_group"), exports); | ||
//# sourceMappingURL=index.js.map |
@@ -41,5 +41,5 @@ "use strict"; | ||
} | ||
(0, defaults_1.applyRspackOptionsDefaults)(options); | ||
logger.debug("NormalizedOptions:", util_1.default.inspect(options, { colors: true, depth: null })); | ||
new rspackOptionsApply_1.RspackOptionsApply().process(options, compiler); | ||
(0, defaults_1.applyRspackOptionsDefaults)(compiler.options); | ||
logger.debug("NormalizedOptions:", util_1.default.inspect(compiler.options, { colors: true, depth: null })); | ||
new rspackOptionsApply_1.RspackOptionsApply().process(compiler.options, compiler); | ||
compiler.hooks.initialize.call(); | ||
@@ -46,0 +46,0 @@ return compiler; |
@@ -8,4 +8,4 @@ "use strict"; | ||
const graceful_fs_1 = __importDefault(require("graceful-fs")); | ||
const polyfillBuiltins_1 = require("./web/polyfillBuiltins"); | ||
const NodeTargetPlugin_1 = require("./node/NodeTargetPlugin"); | ||
const ResolveSwcPlugin_1 = require("./web/ResolveSwcPlugin"); | ||
class RspackOptionsApply { | ||
@@ -20,5 +20,3 @@ constructor() { } | ||
} | ||
if (compiler.options.builtins.polyfillBuiltins) { | ||
new polyfillBuiltins_1.PolyfillBuiltinsPlugin().apply(compiler); | ||
} | ||
new ResolveSwcPlugin_1.ResolveSwcPlugin().apply(compiler); | ||
} | ||
@@ -25,0 +23,0 @@ } |
import * as binding from "@rspack/binding"; | ||
import { StatsOptions } from "./config/stats"; | ||
import { StatsOptions, StatsOptionsObj } from "./config/stats"; | ||
declare type StatsCompilationInner = Omit<binding.JsStatsCompilation, "entrypoints"> & { | ||
entrypoints: Record<string, binding.JsStatsEntrypoint>; | ||
}; | ||
export declare type StatsCompilation = Partial<StatsCompilationInner> & { | ||
filteredModules?: number; | ||
}; | ||
export declare class Stats { | ||
#private; | ||
constructor(statsJson: binding.StatsCompilation); | ||
constructor(statsJson: binding.JsStatsCompilation); | ||
hasErrors(): boolean; | ||
toJson(options?: StatsOptions): binding.StatsCompilation; | ||
toString(options?: StatsOptions): string; | ||
hasWarnings(): boolean; | ||
toJson(opts?: StatsOptions, forToString?: boolean): StatsCompilation; | ||
toString(opts?: StatsOptions): string; | ||
static jsonToString(obj: any, useColors: boolean): string; | ||
} | ||
export declare const optionsOrFallback: (...args: any[]) => any; | ||
export declare function normalizeStatsPreset(options?: StatsOptions): StatsOptionsObj; | ||
export {}; | ||
//# sourceMappingURL=stats.d.ts.map |
@@ -15,4 +15,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Stats = void 0; | ||
const stats_1 = require("./config/stats"); | ||
exports.normalizeStatsPreset = exports.optionsOrFallback = exports.Stats = void 0; | ||
const Logger_1 = require("./logging/Logger"); | ||
@@ -23,3 +22,9 @@ class Stats { | ||
_Stats_statsJson.set(this, void 0); | ||
__classPrivateFieldSet(this, _Stats_statsJson, statsJson, "f"); | ||
__classPrivateFieldSet(this, _Stats_statsJson, { | ||
...statsJson, | ||
entrypoints: statsJson.entrypoints.reduce((acc, cur) => { | ||
acc[cur.name] = cur; | ||
return acc; | ||
}, {}) | ||
}, "f"); | ||
} | ||
@@ -29,12 +34,54 @@ hasErrors() { | ||
} | ||
toJson(options) { | ||
return __classPrivateFieldGet(this, _Stats_statsJson, "f"); | ||
hasWarnings() { | ||
return __classPrivateFieldGet(this, _Stats_statsJson, "f").warningsCount > 0; | ||
} | ||
toString(options) { | ||
options = (0, stats_1.resolveStatsOptions)(options); | ||
const obj = this.toJson(options); | ||
obj.filteredModules = obj.modules.length - 15; | ||
obj.modules = obj.modules.slice(0, 15); | ||
return Stats.jsonToString(obj, options.colors); | ||
toJson(opts, forToString) { | ||
const options = normalizeStatsPreset(opts); | ||
const all = options.all; | ||
const optionOrLocalFallback = (v, def) => v !== undefined ? v : all !== undefined ? all : def; | ||
const showAssets = optionOrLocalFallback(options.assets, true); | ||
const showChunks = optionOrLocalFallback(options.chunks, !forToString); | ||
const showModules = optionOrLocalFallback(options.modules, true); | ||
const showEntrypoints = optionOrLocalFallback(options.entrypoints, true); | ||
const showErrors = optionOrLocalFallback(options.errors, true); | ||
const showErrorsCount = optionOrLocalFallback(options.errorsCount, true); | ||
const showWarninigs = optionOrLocalFallback(options.warnings, true); | ||
const showWarningsCount = optionOrLocalFallback(options.warningsCount, true); | ||
let obj = {}; | ||
if (showAssets) { | ||
obj.assets = __classPrivateFieldGet(this, _Stats_statsJson, "f").assets; | ||
} | ||
if (showChunks) { | ||
obj.chunks = __classPrivateFieldGet(this, _Stats_statsJson, "f").chunks; | ||
} | ||
if (showModules) { | ||
obj.modules = __classPrivateFieldGet(this, _Stats_statsJson, "f").modules; | ||
} | ||
if (showEntrypoints) { | ||
obj.entrypoints = __classPrivateFieldGet(this, _Stats_statsJson, "f").entrypoints; | ||
} | ||
if (showErrors) { | ||
obj.errors = __classPrivateFieldGet(this, _Stats_statsJson, "f").errors; | ||
} | ||
if (showErrorsCount) { | ||
obj.errorsCount = __classPrivateFieldGet(this, _Stats_statsJson, "f").errorsCount; | ||
} | ||
if (showWarninigs) { | ||
obj.warnings = __classPrivateFieldGet(this, _Stats_statsJson, "f").warnings; | ||
} | ||
if (showWarningsCount) { | ||
obj.warningsCount = __classPrivateFieldGet(this, _Stats_statsJson, "f").warningsCount; | ||
} | ||
if (obj.modules && forToString) { | ||
obj.filteredModules = obj.modules.length - 15; | ||
obj.modules = obj.modules.slice(0, 15); | ||
} | ||
return obj; | ||
} | ||
toString(opts) { | ||
const options = normalizeStatsPreset(opts); | ||
const useColors = (0, exports.optionsOrFallback)(options.colors, false); | ||
const obj = this.toJson(options, true); | ||
return Stats.jsonToString(obj, useColors); | ||
} | ||
static jsonToString(obj, useColors) { | ||
@@ -264,16 +311,16 @@ var _a, _b, _c; | ||
colors.normal(" "); | ||
colors.green(asset); | ||
colors.green(asset.name); | ||
} | ||
for (const name of Object.keys(cg.childAssets)) { | ||
const assets = cg.childAssets[name]; | ||
if (assets && assets.length > 0) { | ||
colors.normal(" "); | ||
colors.magenta(`(${name}:`); | ||
for (const asset of assets) { | ||
colors.normal(" "); | ||
colors.green(asset); | ||
} | ||
colors.magenta(")"); | ||
} | ||
} | ||
// for (const name of Object.keys(cg.childAssets)) { | ||
// const assets = cg.childAssets[name]; | ||
// if (assets && assets.length > 0) { | ||
// colors.normal(" "); | ||
// colors.magenta(`(${name}:`); | ||
// for (const asset of assets) { | ||
// colors.normal(" "); | ||
// colors.green(asset); | ||
// } | ||
// colors.magenta(")"); | ||
// } | ||
// } | ||
newline(); | ||
@@ -777,2 +824,52 @@ } | ||
}; | ||
const optionsOrFallback = (...args) => { | ||
let optionValues = []; | ||
optionValues.push(...args); | ||
return optionValues.find(optionValue => optionValue !== undefined); | ||
}; | ||
exports.optionsOrFallback = optionsOrFallback; | ||
function normalizeStatsPreset(options) { | ||
if (typeof options === "boolean" || typeof options === "string") | ||
return presetToOptions(options); | ||
else if (!options) | ||
return {}; | ||
else { | ||
let obj = { ...presetToOptions(options.preset), ...options }; | ||
delete obj.preset; | ||
return obj; | ||
} | ||
} | ||
exports.normalizeStatsPreset = normalizeStatsPreset; | ||
function presetToOptions(name) { | ||
const pn = (typeof name === "string" && name.toLowerCase()) || name; | ||
switch (pn) { | ||
case "none": | ||
return { | ||
all: false | ||
}; | ||
case "verbose": | ||
return { | ||
all: true | ||
}; | ||
case "errors-only": | ||
return { | ||
all: false, | ||
errors: true, | ||
errorsCount: true | ||
// TODO: moduleTrace: true, | ||
// TODO: logging: "error" | ||
}; | ||
case "errors-warnings": | ||
return { | ||
all: false, | ||
errors: true, | ||
errorsCount: true, | ||
warnings: true, | ||
warningsCount: true | ||
// TODO: logging: "warn" | ||
}; | ||
default: | ||
return {}; | ||
} | ||
} | ||
//# sourceMappingURL=stats.js.map |
{ | ||
"name": "@rspack/core", | ||
"version": "0.0.0-1bce45e7c0-20221109113710", | ||
"version": "0.0.0-2d61de1089-20221122042420", | ||
"main": "./dist/index.js", | ||
@@ -10,3 +10,2 @@ "types": "./dist/index.d.ts", | ||
"devDependencies": { | ||
"@rspack/core": "0.0.0-1bce45e7c0-20221109113710", | ||
"@swc/helpers": "^0.4.12", | ||
@@ -25,9 +24,11 @@ "@types/jest": "29.0.2", | ||
"uvu": "0.5.6", | ||
"util": "0.12.5" | ||
"util": "0.12.5", | ||
"rimraf": "3.0.2", | ||
"@types/rimraf": "3.0.2", | ||
"@rspack/core": "0.0.0-2d61de1089-20221122042420", | ||
"@rspack/plugin-node-polyfill": "^0.0.0-2d61de1089-20221122042420", | ||
"@rspack/plugin-postcss": "^0.0.0-2d61de1089-20221122042420", | ||
"@rspack/plugin-less": "^0.0.0-2d61de1089-20221122042420" | ||
}, | ||
"dependencies": { | ||
"@rspack/binding": "0.0.0-1bce45e7c0-20221109113710", | ||
"@rspack/dev-client": "0.0.0-1bce45e7c0-20221109113710", | ||
"@rspack/plugin-less": "^0.0.0-1bce45e7c0-20221109113710", | ||
"@rspack/plugin-postcss": "^0.0.0-1bce45e7c0-20221109113710", | ||
"browserslist": "^4.21.3", | ||
@@ -39,3 +40,6 @@ "chokidar": "3.5.3", | ||
"neo-async": "2.6.2", | ||
"react-refresh": "0.14.0" | ||
"react-refresh": "0.14.0", | ||
"@swc/helpers": "0.4.13", | ||
"@rspack/dev-client": "0.0.0-2d61de1089-20221122042420", | ||
"@rspack/binding": "0.0.0-2d61de1089-20221122042420" | ||
}, | ||
@@ -42,0 +46,0 @@ "optionalDependencies": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
288371
17
166
4180
20
8
+ Added@swc/helpers@0.4.13
+ Added@jridgewell/gen-mapping@0.3.8(transitive)
+ Added@jridgewell/resolve-uri@3.1.2(transitive)
+ Added@jridgewell/set-array@1.2.1(transitive)
+ Added@jridgewell/source-map@0.3.6(transitive)
+ Added@jridgewell/sourcemap-codec@1.5.0(transitive)
+ Added@jridgewell/trace-mapping@0.3.25(transitive)
+ Added@rspack/binding@0.0.0-2d61de1089-20221122042420(transitive)
+ Added@rspack/dev-client@0.0.0-2d61de1089-20221122042420(transitive)
+ Added@swc/helpers@0.4.13(transitive)
+ Added@types/eslint@9.6.1(transitive)
+ Added@types/eslint-scope@3.7.7(transitive)
+ Added@types/estree@1.0.6(transitive)
+ Added@types/json-schema@7.0.15(transitive)
+ Added@types/node@22.10.7(transitive)
+ Added@webassemblyjs/ast@1.14.1(transitive)
+ Added@webassemblyjs/floating-point-hex-parser@1.13.2(transitive)
+ Added@webassemblyjs/helper-api-error@1.13.2(transitive)
+ Added@webassemblyjs/helper-buffer@1.14.1(transitive)
+ Added@webassemblyjs/helper-numbers@1.13.2(transitive)
+ Added@webassemblyjs/helper-wasm-bytecode@1.13.2(transitive)
+ Added@webassemblyjs/helper-wasm-section@1.14.1(transitive)
+ Added@webassemblyjs/ieee754@1.13.2(transitive)
+ Added@webassemblyjs/leb128@1.13.2(transitive)
+ Added@webassemblyjs/utf8@1.13.2(transitive)
+ Added@webassemblyjs/wasm-edit@1.14.1(transitive)
+ Added@webassemblyjs/wasm-gen@1.14.1(transitive)
+ Added@webassemblyjs/wasm-opt@1.14.1(transitive)
+ Added@webassemblyjs/wasm-parser@1.14.1(transitive)
+ Added@webassemblyjs/wast-printer@1.14.1(transitive)
+ Added@xtuc/ieee754@1.2.0(transitive)
+ Added@xtuc/long@4.2.2(transitive)
+ Addedacorn@8.14.0(transitive)
+ Addedajv@6.12.68.17.1(transitive)
+ Addedajv-formats@2.1.1(transitive)
+ Addedajv-keywords@3.5.25.1.0(transitive)
+ Addedbuffer-from@1.1.2(transitive)
+ Addedchrome-trace-event@1.0.4(transitive)
+ Addedcommander@2.20.3(transitive)
+ Addedenhanced-resolve@5.18.0(transitive)
+ Addedes-module-lexer@1.6.0(transitive)
+ Addedeslint-scope@5.1.1(transitive)
+ Addedesrecurse@4.3.0(transitive)
+ Addedestraverse@4.3.05.3.0(transitive)
+ Addedfast-deep-equal@3.1.3(transitive)
+ Addedfast-json-stable-stringify@2.1.0(transitive)
+ Addedfast-uri@3.0.6(transitive)
+ Addedglob-to-regexp@0.4.1(transitive)
+ Addedgraceful-fs@4.2.11(transitive)
+ Addedhas-flag@4.0.0(transitive)
+ Addedjest-worker@27.5.1(transitive)
+ Addedjson-parse-even-better-errors@2.3.1(transitive)
+ Addedjson-schema-traverse@0.4.11.0.0(transitive)
+ Addedloader-runner@4.3.0(transitive)
+ Addedmerge-stream@2.0.0(transitive)
+ Addedmime-db@1.52.0(transitive)
+ Addedmime-types@2.1.35(transitive)
+ Addedmini-css-extract-plugin@2.6.1(transitive)
+ Addedpunycode@2.3.1(transitive)
+ Addedrandombytes@2.1.0(transitive)
+ Addedrequire-from-string@2.0.2(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedschema-utils@3.3.04.3.0(transitive)
+ Addedserialize-javascript@6.0.2(transitive)
+ Addedsource-map-support@0.5.21(transitive)
+ Addedsupports-color@8.1.1(transitive)
+ Addedterser@5.37.0(transitive)
+ Addedterser-webpack-plugin@5.3.11(transitive)
+ Addedundici-types@6.20.0(transitive)
+ Addeduri-js@4.4.1(transitive)
+ Addedwatchpack@2.4.2(transitive)
+ Addedwebpack@5.97.1(transitive)
- Removed@rspack/plugin-less@^0.0.0-1bce45e7c0-20221109113710
- Removed@rspack/plugin-postcss@^0.0.0-1bce45e7c0-20221109113710
- Removed@rspack/binding@0.0.0-1bce45e7c0-20221109113710(transitive)
- Removed@rspack/dev-client@0.0.0-1bce45e7c0-20221109113710(transitive)
- Removed@rspack/plugin-less@0.0.0-fca72318f7-20221109072118(transitive)
- Removed@rspack/plugin-postcss@0.0.0-fca72318f7-20221109072118(transitive)
- Removedcopy-anything@2.0.6(transitive)
- Removedcssesc@3.0.0(transitive)
- Removeddebug@3.2.7(transitive)
- Removederrno@0.1.8(transitive)
- Removedgeneric-names@4.0.0(transitive)
- Removediconv-lite@0.4.24(transitive)
- Removedicss-replace-symbols@1.1.0(transitive)
- Removedicss-utils@5.1.0(transitive)
- Removedimage-size@0.5.5(transitive)
- Removedis-what@3.14.1(transitive)
- Removedklona@2.0.5(transitive)
- Removedless@4.1.2(transitive)
- Removedloader-utils@3.3.1(transitive)
- Removedlodash.camelcase@4.3.0(transitive)
- Removedmake-dir@2.1.0(transitive)
- Removedmime@1.6.0(transitive)
- Removedms@2.1.3(transitive)
- Removednanoid@3.3.8(transitive)
- Removedneedle@2.9.1(transitive)
- Removedparse-node-version@1.0.1(transitive)
- Removedpify@4.0.1(transitive)
- Removedpostcss@8.5.1(transitive)
- Removedpostcss-modules@5.0.0(transitive)
- Removedpostcss-modules-extract-imports@3.1.0(transitive)
- Removedpostcss-modules-local-by-default@4.2.0(transitive)
- Removedpostcss-modules-scope@3.2.1(transitive)
- Removedpostcss-modules-values@4.0.0(transitive)
- Removedpostcss-pxtorem@6.1.0(transitive)
- Removedpostcss-selector-parser@7.0.0(transitive)
- Removedpostcss-value-parser@4.2.0(transitive)
- Removedprr@1.0.1(transitive)
- Removedsafer-buffer@2.1.2(transitive)
- Removedsax@1.4.1(transitive)
- Removedsemver@5.7.2(transitive)
- Removedsource-map-js@1.2.1(transitive)
- Removedstring-hash@1.1.3(transitive)
- Removedutil-deprecate@1.0.2(transitive)