Skip to content

Commit

Permalink
Merge branch 'main' into enforceSizeThreshold
Browse files Browse the repository at this point in the history
  • Loading branch information
SyMind authored Sep 3, 2024
2 parents 1404ac3 + f9820e4 commit 52bbf67
Show file tree
Hide file tree
Showing 78 changed files with 202 additions and 419 deletions.
2 changes: 1 addition & 1 deletion SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Reporting a vulnerability in Rspack

Report a security vulnerability in Rspack via web-infra-careers@bytedance.com.
Report a security vulnerability in Rspack via web-infra-security@bytedance.com.

Normally, your report will be acknowledged within 24 hours, and you'll receive a more detailed response to your report within 5 days indicating the next steps in handling your submission.

Expand Down
2 changes: 1 addition & 1 deletion crates/rspack_core/src/context_module_factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ impl ContextModuleFactory {
let raw_module = RawModule::new(
"/* (ignored) */".to_owned(),
module_identifier,
format!("{ident} (ignored)"),
format!("{specifier} (ignored)"),
Default::default(),
)
.boxed();
Expand Down
7 changes: 5 additions & 2 deletions crates/rspack_core/src/normal_module_factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ impl NormalModuleFactory {
let raw_module = RawModule::new(
"/* (ignored) */".to_owned(),
module_identifier,
format!("{ident} (ignored)"),
format!("{resource} (ignored)"),
Default::default(),
)
.boxed();
Expand Down Expand Up @@ -791,7 +791,10 @@ impl NormalModuleFactory {
let raw_module = RawModule::new(
"/* (ignored) */".to_owned(),
module_identifier,
format!("{ident} (ignored)"),
format!(
"{} (ignored)",
data.request().expect("normal module should have request")
),
Default::default(),
)
.boxed();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -542,18 +542,26 @@ impl<'parser> JavascriptParser<'parser> {
self.walk_prop_name(&getter.key);
let was_top_level = self.top_level_scope;
self.top_level_scope = TopLevelScope::False;
if let Some(body) = &getter.body {
self.walk_statement(Statement::Block(body));
}
self.in_function_scope(true, std::iter::empty(), |parser| {
if let Some(body) = &getter.body {
parser.walk_statement(Statement::Block(body));
}
});
self.top_level_scope = was_top_level;
}
Prop::Setter(setter) => {
self.walk_prop_name(&setter.key);
let was_top_level = self.top_level_scope;
self.top_level_scope = TopLevelScope::False;
if let Some(body) = &setter.body {
self.walk_statement(Statement::Block(body));
}
self.in_function_scope(
true,
std::iter::once(Cow::Borrowed(setter.param.as_ref())),
|parser| {
if let Some(body) = &setter.body {
parser.walk_statement(Statement::Block(body));
}
},
);
self.top_level_scope = was_top_level;
}
Prop::Method(method) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/create-rspack/template-react-js/src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
}

@media (prefers-reduced-motion: no-preference) {
a:nth-of-type(2) .logo {
a > .logo {
animation: logo-spin infinite 20s linear;
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/create-rspack/template-react-ts/src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
}

@media (prefers-reduced-motion: no-preference) {
a:nth-of-type(2) .logo {
a > .logo {
animation: logo-spin infinite 20s linear;
}
}
Expand Down
8 changes: 7 additions & 1 deletion packages/rspack-test-tools/etc/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ export function createHookCase(name: string, src: string, dist: string, source:
export function createHotCase(name: string, src: string, dist: string, target: TCompilerOptions<ECompilerType.Rspack>["target"]): void;

// @public (undocumented)
export function createHotNewIncrementalCase(name: string, src: string, dist: string, target: TCompilerOptions<ECompilerType.Rspack>["target"]): void;
export function createHotNewIncrementalCase(name: string, src: string, dist: string, target: TCompilerOptions<ECompilerType.Rspack>["target"], documentType: EDocumentType): void;

// @public (undocumented)
export function createHotStepCase(name: string, src: string, dist: string, target: TCompilerOptions<ECompilerType.Rspack>["target"]): void;
Expand Down Expand Up @@ -463,9 +463,13 @@ export class HookTaskProcessor<T extends ECompilerType> extends SnapshotProcesso
export class HotNewIncrementalProcessor<T extends ECompilerType> extends HotProcessor<T> {
constructor(_hotOptions: IHotNewIncrementalProcessorOptions<T>);
// (undocumented)
afterAll(context: ITestContext): Promise<void>;
// (undocumented)
static defaultOptions<T extends ECompilerType>(this: HotNewIncrementalProcessor<T>, context: ITestContext): TCompilerOptions<T>;
// (undocumented)
protected _hotOptions: IHotNewIncrementalProcessorOptions<T>;
// (undocumented)
run(env: ITestEnv, context: ITestContext): Promise<void>;
}

// @public (undocumented)
Expand Down Expand Up @@ -750,6 +754,8 @@ export interface IHookProcessorOptions<T extends ECompilerType> extends ISnapsho

// @public (undocumented)
export interface IHotNewIncrementalProcessorOptions<T extends ECompilerType> extends Omit<IBasicProcessorOptions<T>, "runable"> {
// (undocumented)
documentType?: EDocumentType;
// (undocumented)
target: TCompilerOptions<T>["target"];
}
Expand Down
25 changes: 16 additions & 9 deletions packages/rspack-test-tools/src/case/new-incremental.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,24 @@ import { HotNewIncrementalProcessor } from "../processor/hot-new-incremental";
import { WatchProcessor, WatchStepProcessor } from "../processor/watch";
import { HotRunnerFactory, WatchRunnerFactory } from "../runner";
import { BasicCaseCreator } from "../test/creator";
import { ECompilerType, type TCompilerOptions } from "../type";
import {
ECompilerType,
type EDocumentType,
type TCompilerOptions
} from "../type";

type TTarget = TCompilerOptions<ECompilerType.Rspack>["target"];

const hotCreators: Map<
TTarget,
string,
BasicCaseCreator<ECompilerType.Rspack>
> = new Map();

function getHotCreator(target: TTarget) {
if (!hotCreators.has(target)) {
function getHotCreator(target: TTarget, documentType: EDocumentType) {
const key = JSON.stringify({ target, documentType });
if (!hotCreators.has(key)) {
hotCreators.set(
target,
key,
new BasicCaseCreator({
clean: true,
describe: true,
Expand All @@ -27,23 +32,25 @@ function getHotCreator(target: TTarget) {
name,
target: target as TTarget,
compilerType: ECompilerType.Rspack,
configFiles: ["rspack.config.js", "webpack.config.js"]
configFiles: ["rspack.config.js", "webpack.config.js"],
documentType
})
],
runner: HotRunnerFactory
})
);
}
return hotCreators.get(target)!;
return hotCreators.get(key)!;
}

export function createHotNewIncrementalCase(
name: string,
src: string,
dist: string,
target: TCompilerOptions<ECompilerType.Rspack>["target"]
target: TCompilerOptions<ECompilerType.Rspack>["target"],
documentType: EDocumentType
) {
const creator = getHotCreator(target);
const creator = getHotCreator(target, documentType);
creator.create(name, src, dist);
}

Expand Down
24 changes: 24 additions & 0 deletions packages/rspack-test-tools/src/processor/hot-new-incremental.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import {
ECompilerType,
EDocumentType,
type ITestContext,
type ITestEnv,
type TCompilerOptions
} from "../type";
import type { IBasicProcessorOptions } from "./basic";
Expand All @@ -9,6 +11,7 @@ import { HotProcessor } from "./hot";
export interface IHotNewIncrementalProcessorOptions<T extends ECompilerType>
extends Omit<IBasicProcessorOptions<T>, "runable"> {
target: TCompilerOptions<T>["target"];
documentType?: EDocumentType;
}

export class HotNewIncrementalProcessor<
Expand All @@ -18,6 +21,27 @@ export class HotNewIncrementalProcessor<
super(_hotOptions);
}

async run(env: ITestEnv, context: ITestContext) {
context.setValue(
this._options.name,
"documentType",
this._hotOptions.documentType
);
await super.run(env, context);
}

async afterAll(context: ITestContext) {
try {
await super.afterAll(context);
} catch (e: any) {
const isFake =
context.getValue(this._options.name, "documentType") ===
EDocumentType.Fake;
if (isFake && /Should run all hot steps/.test(e.message)) return;
throw e;
}
}

static defaultOptions<T extends ECompilerType>(
this: HotNewIncrementalProcessor<T>,
context: ITestContext
Expand Down
93 changes: 70 additions & 23 deletions packages/rspack-test-tools/tests/NewIncremental.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,41 @@ process.env.RSPACK_CONFIG_VALIDATE = 'loose-silent';
const path = require("path");
const { describeByWalk, createHotNewIncrementalCase, createWatchNewIncrementalCase } = require("../dist");

function postfixName(name) {
return `${name} (newIncremental)`
function v(name) {
return path.join(__dirname, `new-incremental ${name}`)
}

describeByWalk(__filename, (name, src, dist) => {
createHotNewIncrementalCase(postfixName(name), src, dist, "async-node");
// Run tests rspack-test-tools/tests/hotCases in target async-node
describeByWalk(v("hot async-node"), (name, src, dist) => {
createHotNewIncrementalCase(name, src, dist, "async-node", "jsdom");
}, {
source: path.resolve(__dirname, "./hotCases"),
dist: path.resolve(__dirname, `./js/new-incremental/hot-node`),
dist: path.resolve(__dirname, `./js/new-incremental/hot-async-node`),
exclude: [/^css$/]
});

describeByWalk(__filename, (name, src, dist) => {
createHotNewIncrementalCase(postfixName(name), src, dist, "web");
// Run tests rspack-test-tools/tests/hotCases in target web
describeByWalk(v("hot web"), (name, src, dist) => {
createHotNewIncrementalCase(name, src, dist, "web", "jsdom");
}, {
source: path.resolve(__dirname, "./hotCases"),
dist: path.resolve(__dirname, `./js/new-incremental/hot-web`)
});

describeByWalk(__filename, (name, src, dist) => {
createHotNewIncrementalCase(postfixName(name), src, dist, "webworker");
// Run tests rspack-test-tools/tests/hotCases in target webworker
describeByWalk(v("hot webworker"), (name, src, dist) => {
createHotNewIncrementalCase(name, src, dist, "webworker", "jsdom");
}, {
source: path.resolve(__dirname, "./hotCases"),
dist: path.resolve(__dirname, `./js/new-incremental/hot-worker`),
exclude: [/^css$/]
});

// Run tests in rspack-test-tools/tests/watchCases
describeByWalk(__filename, (name, src, dist) => {
// Run tests rspack-test-tools/tests/watchCases
describeByWalk(v("watch"), (name, src, dist) => {
const tempDir = path.resolve(__dirname, `./js/new-incremental/temp`);
createWatchNewIncrementalCase(
postfixName(name),
name,
src,
dist,
path.join(tempDir, name),
Expand All @@ -45,23 +48,67 @@ describeByWalk(__filename, (name, src, dist) => {
dist: path.resolve(__dirname, `./js/new-incremental/watch`),
});

// Run tests in webpack-test/watchCases
describeByWalk(__filename, (name, src, dist) => {
const tempDir = path.resolve(__dirname, `./js/new-incremental/temp`);
// Run tests webpack-test/hotCases in target async-node
describeByWalk(v("hot async-node (webpack-test)"), (name, src, dist) => {
createHotNewIncrementalCase(name, src, dist, "async-node", "fake");
}, {
source: path.resolve(__dirname, "../../../tests/webpack-test/hotCases"),
dist: path.resolve(__dirname, `./js/new-incremental/webpack-test/hot-async-node`),
exclude: [
/move-between-runtime/,
]
});

// Run tests webpack-test/hotCases in target node
describeByWalk(v("hot node (webpack-test)"), (name, src, dist) => {
createHotNewIncrementalCase(name, src, dist, "node", "fake");
}, {
source: path.resolve(__dirname, "../../../tests/webpack-test/hotCases"),
dist: path.resolve(__dirname, `./js/new-incremental/webpack-test/hot-node`),
exclude: [
/move-between-runtime/,
]
});

// Run tests webpack-test/hotCases in target web
describeByWalk(v("hot web (webpack-test)"), (name, src, dist) => {
createHotNewIncrementalCase(name, src, dist, "web", "fake");
}, {
source: path.resolve(__dirname, "../../../tests/webpack-test/hotCases"),
dist: path.resolve(__dirname, `./js/new-incremental/webpack-test/hot-web`),
exclude: [
/move-between-runtime/,
]
});

// Run tests webpack-test/hotCases in target webworker
describeByWalk(v("hot webworker (webpack-test)"), (name, src, dist) => {
createHotNewIncrementalCase(name, src, dist, "webworker", "fake");
}, {
source: path.resolve(__dirname, "../../../tests/webpack-test/hotCases"),
dist: path.resolve(__dirname, `./js/new-incremental/webpack-test/hot-webworker`),
exclude: [
/move-between-runtime/,
]
});

// Run tests webpack-test/watchCases
describeByWalk(v("watch (webpack-test)"), (name, src, dist) => {
const tempDir = path.resolve(__dirname, `./js/new-incremental/webpack-test/temp`);
createWatchNewIncrementalCase(
postfixName(name),
name,
src,
dist,
path.join(tempDir, name),
);
}, {
source: path.resolve(__dirname, "../../../tests/webpack-test/watchCases"),
dist: path.resolve(__dirname, `./js/new-incremental/webpack-test/watch`),
exclude: [
/module-concatenation-plugin/,
/missing-module/,
/caching-inner-source/,
/production/,
/warnings-contribute-to-hash/,
]
exclude: [
/module-concatenation-plugin/,
/missing-module/,
/caching-inner-source/,
/production/,
/warnings-contribute-to-hash/,
]
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import "./index.css";
import "./main";

it("css recovery", done => {
NEXT(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import "./index.css";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export class Texture {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Texture as e } from "./a.js";

it("should not parse when logical and with `false && unknown = false`", function () {
var index_es_e = {};
var index_es_Ce = {
get exports() {
return index_es_e;
},
set exports(e) {
index_es_e = e;
}
};
console.log.bind(null, e);
index_es_Ce.exports = 1;
expect(index_es_Ce.exports).toBe(1)
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const {
SingleEntryPlugin,
EntryPlugin: SingleEntryPlugin,
node: { NodeTemplatePlugin }
} = require("@rspack/core");

Expand Down

This file was deleted.

Loading

0 comments on commit 52bbf67

Please sign in to comment.