Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/web-infra-dev/rspack into i…
Browse files Browse the repository at this point in the history
…gnore-plugin-check-resource
  • Loading branch information
9aoy committed Apr 16, 2024
2 parents 2483aec + d4e493e commit dff6e77
Show file tree
Hide file tree
Showing 15 changed files with 98 additions and 44 deletions.
2 changes: 1 addition & 1 deletion api-extractor.json
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@
* SUPPORTED TOKENS: <packageName>, <unscopedPackageName>
* DEFAULT VALUE: "<unscopedPackageName>.api.md"
*/
// "reportFileName": "<unscopedPackageName>.api.md",
"reportFileName": "api.md",

/**
* Specifies the folder where the API report file is written. The file name portion is determined by
Expand Down
52 changes: 28 additions & 24 deletions crates/rspack_plugin_css/src/parser_and_generator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ impl ParserAndGenerator for CssParserAndGenerator {

let mut exports_pairs = vec![];
let mut presentational_dependencies = None;
if is_enable_css_modules {
let mut exports = if is_enable_css_modules {
let mut stylesheet = swc_compiler.parse_file(
&resource_path.to_string_lossy(),
source_code.clone(),
Expand All @@ -138,11 +138,6 @@ impl ParserAndGenerator for CssParserAndGenerator {
},
)?;

let mut exports_analyzer = ExportsAnalyzer::new(&source_code);
stylesheet.visit_with(&mut exports_analyzer);

presentational_dependencies = Some(exports_analyzer.presentation_deps);

let result = swc_core::css::modules::compile(
&mut stylesheet,
ModulesTransformConfig::new(
Expand All @@ -154,7 +149,33 @@ impl ParserAndGenerator for CssParserAndGenerator {
compiler_options,
),
);
let mut exports: IndexMap<Atom, _> = result.renamed.into_iter().collect();
let exports: IndexMap<Atom, _> = result.renamed.into_iter().collect();

let (code, map) = swc_compiler.codegen(
&stylesheet,
SwcCssSourceMapGenConfig {
enable: !matches!(module_source_map_kind, SourceMapKind::None),
inline_sources_content: false,
emit_columns: matches!(module_source_map_kind, SourceMapKind::SourceMap),
},
)?;
source_code = code;
source_map = map;
Some(exports)
} else {
None
};

let new_stylesheet_ast = SwcCssCompiler::default().parse_file(
&parse_context.resource_data.resource_path.to_string_lossy(),
source_code.clone(),
Default::default(),
)?;

if let Some(exports) = &mut exports {
let mut exports_analyzer = ExportsAnalyzer::new(&source_code);
new_stylesheet_ast.visit_with(&mut exports_analyzer);
presentational_dependencies = Some(exports_analyzer.presentation_deps);

for (key, value) in exports_analyzer.exports {
exports.insert(key, vec![value]);
Expand All @@ -180,25 +201,8 @@ impl ParserAndGenerator for CssParserAndGenerator {
}

self.exports = Some(normalized_exports);

let (code, map) = swc_compiler.codegen(
&stylesheet,
SwcCssSourceMapGenConfig {
enable: !matches!(module_source_map_kind, SourceMapKind::None),
inline_sources_content: false,
emit_columns: matches!(module_source_map_kind, SourceMapKind::SourceMap),
},
)?;
source_code = code;
source_map = map;
}

let new_stylesheet_ast = SwcCssCompiler::default().parse_file(
&parse_context.resource_data.resource_path.to_string_lossy(),
source_code.clone(),
Default::default(),
)?;

let mut dependencies = analyze_dependencies(
&new_stylesheet_ast,
code_generation_dependencies,
Expand Down
13 changes: 8 additions & 5 deletions lint-staged.config.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
export default {
"*.rs": "rustfmt --edition 2021",
"*.{ts,js}": "pnpm run format:js",
"*.toml": "npx @taplo/cli format",
"*.{ts,js,mjs}": () => "pnpm run lint:js"
}
"*.rs": "rustfmt --edition 2021",
"*.{ts,js}": "pnpm run format:js",
"*.toml": "npx @taplo/cli format",
"*.{ts,js,cts,cjs,mts,mjs}": () => [
"pnpm run lint:js",
"pnpm run api-extractor:ci"
]
};
File renamed without changes.
2 changes: 1 addition & 1 deletion packages/rspack-dev-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"dev": "tsc -w -b ./tsconfig.build.json",
"test": "rimraf .test-temp && jest --runInBand",
"api-extractor": "api-extractor run --verbose",
"api-extractor:ci": "api-extractor run --verbose || diff temp/core.api.md etc/core.api.md"
"api-extractor:ci": "api-extractor run --verbose || diff temp/api.md etc/api.md"
},
"files": [
"dist",
Expand Down
2 changes: 1 addition & 1 deletion packages/rspack-plugin-react-refresh/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"dev": "tsc -b -w",
"test": "jest --runInBand",
"api-extractor": "api-extractor run --verbose",
"api-extractor:ci": "api-extractor run --verbose || diff temp/core.api.md etc/core.api.md"
"api-extractor:ci": "api-extractor run --verbose || diff temp/api.md etc/api.md"
},
"files": [
"client",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { RspackOptionsNormalized } from '@rspack/core';
import { RspackPluginInstance } from '@rspack/core';
import { Stats } from '@rspack/core';
import type { Stats as Stats_2 } from 'webpack';
import { StatsCompilation } from '@rspack/core';
import { WebpackOptionsNormalized } from 'webpack';

// @public (undocumented)
Expand Down Expand Up @@ -91,6 +92,9 @@ export function createHashCase(name: string, src: string, dist: string): void;
// @public (undocumented)
export function createHotCase(name: string, src: string, dist: string, target: TCompilerOptions<ECompilerType.Rspack>["target"]): void;

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

// @public (undocumented)
export function createNormalCase(name: string, src: string, dist: string): void;

Expand Down Expand Up @@ -225,6 +229,12 @@ export class HotRunnerFactory<T extends ECompilerType> extends BasicRunnerFactor
protected createRunner(file: string, compilerOptions: TCompilerOptions<T>, env: ITestEnv): ITestRunner;
}

// @public (undocumented)
export class HotStepRunnerFactory<T extends ECompilerType> extends HotRunnerFactory<T> {
// (undocumented)
protected createRunner(file: string, compilerOptions: TCompilerOptions<T>, env: ITestEnv): ITestRunner;
}

// @public (undocumented)
export interface IBasicGlobalContext {
// (undocumented)
Expand Down Expand Up @@ -461,6 +471,10 @@ export interface IRspackHotProcessorOptions {
target: TCompilerOptions<ECompilerType.Rspack>["target"];
}

// @public (undocumented)
export interface IRspackHotStepProcessorOptions extends IRspackHotProcessorOptions {
}

// @public (undocumented)
export interface IRspackStatsProcessorOptions<T extends ECompilerType.Rspack> {
// (undocumented)
Expand Down Expand Up @@ -816,12 +830,23 @@ export class RspackHotProcessor extends BasicTaskProcessor<ECompilerType.Rspack>
run(env: ITestEnv, context: ITestContext): Promise<void>;
// (undocumented)
protected runner: ITestRunner | null;
// Warning: (ae-forgotten-export) The symbol "TUpdateOptions" needs to be exported by the entry point index.d.ts
//
// (undocumented)
protected updateOptions: TUpdateOptions;
}

// @public (undocumented)
export class RspackHotStepProcessor extends RspackHotProcessor {
constructor(_hotOptions: IRspackHotProcessorOptions);
// (undocumented)
check(env: ITestEnv, context: ITestContext): Promise<void>;
// (undocumented)
protected _hotOptions: IRspackHotProcessorOptions;
// (undocumented)
protected matchStepSnapshot(context: ITestContext, step: number, stats: StatsCompilation): void;
// (undocumented)
run(env: ITestEnv, context: ITestContext): Promise<void>;
}

// @public (undocumented)
export class RspackStatsProcessor extends MultiTaskProcessor<ECompilerType.Rspack> {
constructor(options: IRspackStatsProcessorOptions<ECompilerType.Rspack>);
Expand Down Expand Up @@ -1103,6 +1128,11 @@ export type TTestFilter<T extends ECompilerType> = (creatorConfig: Record<string
// @public (undocumented)
export type TTestRunResult = Record<string, any>;

// @public (undocumented)
export type TUpdateOptions = {
updateIndex: number;
};

// @public (undocumented)
export class WatchRunnerFactory<T extends ECompilerType> extends BasicRunnerFactory<T> {
// (undocumented)
Expand Down
2 changes: 1 addition & 1 deletion packages/rspack-test-tools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"test:ng": "cross-env SNAPSHOT=legacy NO_COLOR=1 node --expose-gc --max-old-space-size=8192 --experimental-vm-modules ../../node_modules/jest-cli/bin/jest --logHeapUsage --config ./jest.config.legacy.js",
"test:diff": "cross-env RSPACK_DIFF=true NO_COLOR=1 node --expose-gc --max-old-space-size=8192 --experimental-vm-modules ../../node_modules/jest-cli/bin/jest --logHeapUsage --config ./jest.config.diff.js",
"api-extractor": "api-extractor run --verbose",
"api-extractor:ci": "api-extractor run --verbose || diff temp/core.api.md etc/core.api.md"
"api-extractor:ci": "api-extractor run --verbose || diff temp/api.md etc/api.md"
},
"files": [
"client",
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion packages/rspack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"dev": "tsc -w",
"test": "cross-env NO_COLOR=1 node --expose-gc --max-old-space-size=8192 --experimental-vm-modules ../../node_modules/jest-cli/bin/jest --logHeapUsage",
"api-extractor": "api-extractor run --verbose",
"api-extractor:ci": "api-extractor run --verbose || diff temp/core.api.md etc/core.api.md"
"api-extractor:ci": "api-extractor run --verbose || diff temp/api.md etc/api.md"
},
"files": [
"dist",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,19 @@ exports[`ConfigTestCases css at-import-in-the-top exported tests at-import-in-th
"
`;

exports[`ConfigTestCases css export-selector exported tests should have correct css result 1`] = `
"/* #region \\"./style.module.css?imported\\" */
/*
- type: css/auto
*/
.local {}
/* #endregion \\"./style.module.css?imported\\" */
"
`;

exports[`ConfigTestCases css rewrite-url exported tests should rewrite the css url() 1`] = `"eb587e4780c414fe3a22.png"`;

exports[`ConfigTestCases css rewrite-url exported tests should rewrite the css url() 2`] = `"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAOCAYAAAAbvf3sAAAACXBIWXMAABYlAAAWJQFJUiTwAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAEWSURBVHgBjZFRSsNAEIb/3fQAOUK9gfpe6YIovjU3UE+gJ2g8gTcw3sC+itUFrW+BeAN7ATFSKAjbHWcSC+mSlszLDrvfzvzzj0LHmNpZBtBQd4Gf7fuYgHPPueoCe1DK1UsHd7Dzw+P0daQj/SC5h09OzdGktw221vZXUBlVMN0ILPd6O9yzBBXX8CBdv6kWOGa4YLivQJNjM0ia73oTLsBwJjCB5gu4i7CgbsIey5ThEcOfKziTGFOGHypJeZ7jZ/Gbst4x2/fN9h2eGTNvgk92VrDEWLNmfJXLpIYrRy5b4Fs+9v2/pL0oUncI7FuHLI6PK5lJZGoe8qXNvrry27DesoRLpLPmNkTw9yEcxPWJMR+S/AFbfpAZqxwUNQAAAABJRU5ErkJggg=="`;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
const fs = require('fs')
const path = require('path')

it('should have correct css result', async () => {
const css = await fs.promises.readFile(path.resolve(__dirname, './imported_js.bundle0.css'))
expect(css.toString()).toMatchSnapshot()
})

it("should allow to dynamic import a css module", done => {
import("./style.module.css").then(x => {
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
:export {
foo: foo;
bar: b a r;
}
:export {foo:foo;bar:b a r}

.local {}

:export {
dash-name: dashName;
}
:export {dash-name:dashName}

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ module.exports = {
generator: {
'css/auto': {
exportsConvention: 'camel-case-only',
localIdentName: '[local]'
localIdentName: '[local]',
exportsOnly: false
}
}
},
Expand Down

0 comments on commit dff6e77

Please sign in to comment.