New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@rspack/core

Package Overview
Dependencies
Maintainers
1
Versions
1109
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@rspack/core - npm Package Compare versions

Comparing version 0.0.0-9a86d8579-20221114102256 to 0.0.0-b5c070c112-20221123080430

dist/chunk_group.d.ts

32

dist/compilation.d.ts
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: {

@@ -31,2 +32,3 @@ done: tapable.AsyncSeriesHook<Stats>;

failed: tapable.SyncHook<[Error]>;
watchRun: tapable.AsyncSeriesHook<[Compiler]>;
};

@@ -37,8 +39,5 @@ options: RspackOptionsNormalized;

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;

@@ -45,0 +44,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 = {

@@ -80,3 +91,4 @@ initialize: new tapable_1.SyncHook([]),

infrastructureLog: new tapable_1.SyncBailHook(["origin", "type", "args"]),
failed: new tapable_1.SyncHook(["error"])
failed: new tapable_1.SyncHook(["error"]),
watchRun: new tapable.AsyncSeriesHook(["compiler"])
};

@@ -174,3 +186,3 @@ }

}
const stats = new stats_1.Stats(rawStats);
const stats = new stats_1.Stats(rawStats, this.compilation);
this.hooks.done.callAsync(stats, err => {

@@ -217,3 +229,3 @@ if (err) {

// TODO: in `dev-server`
async watch(watchOptions, ws) {
async watch(watchOptions) {
const options = (0, watch_1.resolveWatchOption)(watchOptions);

@@ -227,3 +239,4 @@ let logger = this.getInfrastructureLogger("watch");

let rawStats = await util_1.default.promisify(this.build.bind(this))();
let stats = new stats_1.Stats(rawStats);
let stats = new stats_1.Stats(rawStats, this.compilation);
await this.hooks.done.promise(stats);
// TODO: log stats string should move to cli

@@ -249,4 +262,4 @@ console.log(stats.toString(this.options.stats));

const begin = Date.now();
this.rebuild(changedFilepath, (error, { diff, stats: rawStats }) => {
let stats = new stats_1.Stats(rawStats);
this.rebuild(changedFilepath, (error, rawStats) => {
let stats = new stats_1.Stats(rawStats, this.compilation);
// TODO: log stats string should move to cli

@@ -265,41 +278,7 @@ console.log(stats.toString(this.options.stats));

}
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");

@@ -357,23 +336,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) {

@@ -389,3 +365,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;

@@ -392,0 +368,0 @@ this.hooks.thisCompilation.call(this.compilation);

@@ -5,3 +5,4 @@ import type { RawBuiltins, RawHtmlPluginConfig, RawDecoratorOptions } from "@rspack/binding";

};
export declare type Builtins = Omit<RawBuiltins, "browserslist" | "html" | "decorator"> & {
export declare type Builtins = Omit<RawBuiltins, "define" | "browserslist" | "html" | "decorator"> & {
define?: Record<string, string | undefined>;
polyfillBuiltins?: boolean;

@@ -8,0 +9,0 @@ html?: Array<BuiltinsHtmlPluginConfig>;

@@ -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
]);

@@ -44,2 +44,3 @@ return Object.fromEntries(entries);

...builtins,
define: resolveDefine(builtins.define || {}),
html: resolveHtml(builtins.html || []),

@@ -46,0 +47,0 @@ browserslist,

@@ -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?: {

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

@@ -9,2 +9,3 @@ "use strict";

const NodeTargetPlugin_1 = require("./node/NodeTargetPlugin");
const ResolveSwcPlugin_1 = require("./web/ResolveSwcPlugin");
class RspackOptionsApply {

@@ -19,2 +20,3 @@ constructor() { }

}
new ResolveSwcPlugin_1.ResolveSwcPlugin().apply(compiler);
}

@@ -21,0 +23,0 @@ }

import * as binding from "@rspack/binding";
import { Compilation } from ".";
import { StatsOptions, StatsOptionsObj } from "./config/stats";
declare type StatsCompilationInner = Omit<binding.StatsCompilation, "entrypoints"> & {
entrypoints: Record<string, binding.StatsEntrypoint>;
declare type StatsCompilationInner = Omit<binding.JsStatsCompilation, "entrypoints"> & {
entrypoints: Record<string, binding.JsStatsEntrypoint>;
};

@@ -11,3 +12,4 @@ export declare type StatsCompilation = Partial<StatsCompilationInner> & {

#private;
constructor(statsJson: binding.StatsCompilation);
compilation: Compilation;
constructor(statsJson: binding.JsStatsCompilation, compilation: Compilation);
hasErrors(): boolean;

@@ -14,0 +16,0 @@ hasWarnings(): boolean;

@@ -18,3 +18,3 @@ "use strict";

class Stats {
constructor(statsJson) {
constructor(statsJson, compilation) {
// remove this when support delegate compilation to rust side

@@ -29,2 +29,3 @@ _Stats_statsJson.set(this, void 0);

}, "f");
this.compilation = compilation;
}

@@ -31,0 +32,0 @@ hasErrors() {

{
"name": "@rspack/core",
"version": "0.0.0-9a86d8579-20221114102256",
"version": "0.0.0-b5c070c112-20221123080430",
"main": "./dist/index.js",

@@ -10,3 +10,2 @@ "types": "./dist/index.d.ts",

"devDependencies": {
"@rspack/core": "0.0.0-9a86d8579-20221114102256",
"@swc/helpers": "^0.4.12",

@@ -26,9 +25,10 @@ "@types/jest": "29.0.2",

"util": "0.12.5",
"@rspack/plugin-less": "^0.0.0-9a86d8579-20221114102256",
"@rspack/plugin-postcss": "^0.0.0-9a86d8579-20221114102256",
"@rspack/plugin-node-polyfill": "^0.0.0-9a86d8579-20221114102256"
"rimraf": "3.0.2",
"@types/rimraf": "3.0.2",
"@rspack/plugin-less": "^0.0.0-b5c070c112-20221123080430",
"@rspack/plugin-postcss": "^0.0.0-b5c070c112-20221123080430",
"@rspack/core": "0.0.0-b5c070c112-20221123080430",
"@rspack/plugin-node-polyfill": "^0.0.0-b5c070c112-20221123080430"
},
"dependencies": {
"@rspack/binding": "0.0.0-9a86d8579-20221114102256",
"@rspack/dev-client": "0.0.0-9a86d8579-20221114102256",
"browserslist": "^4.21.3",

@@ -40,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-b5c070c112-20221123080430",
"@rspack/binding": "0.0.0-b5c070c112-20221123080430"
},

@@ -43,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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc