Skip to content

Commit 9033e2d

Browse files
authored
feat: move cssChunksToMap implementation to @lynx-js/css-serializer (#2269)
<!-- Thank you for submitting a pull request! We appreciate the time and effort you have invested in making these changes. Please ensure that you provide enough information to allow others to review your pull request. Upon submission, your pull request will be automatically assigned with reviewers. If you want to learn more about contributing to this project, please visit: https://github.com/lynx-family/lynx-stack/blob/main/CONTRIBUTING.md. --> <!-- The AI summary below will be auto-generated - feel free to replace it with your own. --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes * **Bug Fixes** * Patched @lynx-js/template-webpack-plugin and @lynx-js/css-serializer. * **New Features** * Exposed CSS namespace directly from @lynx-js/css-serializer. * Added CSSPlugins export with parserPlugins property. * Made cssChunksToMap available as a public export from @lynx-js/css-serializer. * **Chores** * Updated test imports and configuration for improved module resolution. <!-- end of auto-generated comment: release notes by coderabbit.ai --> In #2143, we need to use `cssChunksToMap` in `@lynx-js/lynx-bundle-rslib-config` package. To avoid repeating ourselves, we extract the `cssChunksToMap` API from `@lynx-js/template-webpack-plugin` to `@lynx-js/css-serializer`. ## Checklist <!--- Check and mark with an "x" --> - [x] Tests updated (or not required). - [ ] Documentation updated (or not required). - [x] Changeset added, and when a BREAKING CHANGE occurs, it needs to be clearly marked (or not required).
1 parent d7ab847 commit 9033e2d

File tree

14 files changed

+40
-67
lines changed

14 files changed

+40
-67
lines changed

.changeset/wet-rockets-taste.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@lynx-js/template-webpack-plugin": patch
3+
"@lynx-js/css-serializer": patch
4+
---
5+
6+
Move `cssChunksToMap` implementation from `@lynx-js/template-webpack-plugin` to `@lynx-js/css-serializer` for future reuse.

packages/webpack/template-webpack-plugin/src/css/ast.ts renamed to packages/tools/css-serializer/src/css/ast.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// Copyright 2024 The Lynx Authors. All rights reserved.
22
// Licensed under the Apache License Version 2.0 that can be found in the
33
// LICENSE file in the root directory of this source tree.
4-
import * as CSS from '@lynx-js/css-serializer';
5-
import type { Plugin } from '@lynx-js/css-serializer';
4+
import * as CSS from '../index.js';
5+
import type { Plugin } from '../index.js';
66

77
export function cssToAst(
88
content: string,

packages/webpack/template-webpack-plugin/src/css/cssChunksToMap.ts renamed to packages/tools/css-serializer/src/css/cssChunksToMap.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright 2024 The Lynx Authors. All rights reserved.
22
// Licensed under the Apache License Version 2.0 that can be found in the
33
// LICENSE file in the root directory of this source tree.
4-
import type * as CSS from '@lynx-js/css-serializer';
4+
import type * as CSS from '../index.js';
55

66
import { cssToAst } from './ast.js';
77
import { debundleCSS } from './debundle.js';

packages/webpack/template-webpack-plugin/src/css/debundle.ts renamed to packages/tools/css-serializer/src/css/debundle.ts

File renamed without changes.

packages/webpack/template-webpack-plugin/src/css/plugins/index.ts renamed to packages/tools/css-serializer/src/css/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
// Copyright 2024 The Lynx Authors. All rights reserved.
22
// Licensed under the Apache License Version 2.0 that can be found in the
33
// LICENSE file in the root directory of this source tree.
4-
export { Plugins as parserPlugins } from '@lynx-js/css-serializer';
4+
export { cssChunksToMap } from './cssChunksToMap.js';

packages/tools/css-serializer/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ export * as csstree from 'css-tree';
77
export * as Plugins from './plugins/index.js';
88
export type * from './types/index.js';
99
export { parse } from './parse.js';
10+
export * from './css/index.js';

packages/webpack/template-webpack-plugin/test/css.test.ts renamed to packages/tools/css-serializer/test/css.test.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@
33
// LICENSE file in the root directory of this source tree.
44
import { describe, expect, test } from 'vitest';
55

6-
import type { LynxStyleNode } from '@lynx-js/css-serializer';
6+
import type { LynxStyleNode } from '../src';
77

8-
import { cssChunksToMap } from '../src/css/cssChunksToMap.js';
8+
import { cssChunksToMap, Plugins as parserPlugins } from '../src';
99
import { debundleCSS } from '../src/css/debundle.js';
10-
import { CSSPlugins } from '../src/index.js';
10+
11+
const CSSPlugins = {
12+
parserPlugins,
13+
};
1114

1215
describe('CSS', () => {
1316
describe('cssChunksToMap', () => {

packages/tools/css-serializer/vitest.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { defineConfig } from 'vitest/config';
22

33
export default defineConfig({
44
test: {
5-
include: ['**/test/*.spec.ts'],
5+
include: ['**/test/*.spec.ts', '**/test/*.test.ts'],
66
name: 'tools/css-serializer',
77
},
88
});

packages/webpack/template-webpack-plugin/etc/template-webpack-plugin.api.md

Lines changed: 9 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -9,50 +9,20 @@ import { AsyncSeriesBailHook } from '@rspack/lite-tapable';
99
import { AsyncSeriesWaterfallHook } from '@rspack/lite-tapable';
1010
import type { Compilation } from 'webpack';
1111
import type { Compiler } from 'webpack';
12-
import type * as CSS_2 from '@lynx-js/css-serializer';
13-
import { csstree } from '@lynx-js/css-serializer';
14-
import { Declaration } from '@lynx-js/css-serializer';
15-
import { FontFaceRule } from '@lynx-js/css-serializer';
16-
import { ImportRule } from '@lynx-js/css-serializer';
17-
import { KeyframesRule } from '@lynx-js/css-serializer';
18-
import { LynxStyleNode } from '@lynx-js/css-serializer';
19-
import { parse } from '@lynx-js/css-serializer';
20-
import { Plugin } from '@lynx-js/css-serializer';
12+
import * as CSS from '@lynx-js/css-serializer';
13+
import { cssChunksToMap } from '@lynx-js/css-serializer';
2114
import { Plugins } from '@lynx-js/css-serializer';
22-
import { StyleRule } from '@lynx-js/css-serializer';
2315
import { SyncWaterfallHook } from '@rspack/lite-tapable';
2416

25-
declare namespace CSS {
26-
export {
27-
csstree,
28-
Plugins,
29-
parse,
30-
Plugin,
31-
Declaration,
32-
LynxStyleNode,
33-
StyleRule,
34-
FontFaceRule,
35-
ImportRule,
36-
KeyframesRule,
37-
cssChunksToMap
38-
}
39-
}
17+
export { CSS }
4018

41-
// Warning: (ae-missing-release-tag) "cssChunksToMap" is part of the package's API, but it is missing a release tag (@alpha, @beta, @public, or @internal)
19+
// Warning: (ae-missing-release-tag) "CSSPlugins" is part of the package's API, but it is missing a release tag (@alpha, @beta, @public, or @internal)
4220
//
4321
// @public (undocumented)
44-
function cssChunksToMap(cssChunks: string[], plugins: CSS_2.Plugin[], enableCSSSelector: boolean): {
45-
cssMap: Record<string, CSS_2.LynxStyleNode[]>;
46-
cssSource: Record<string, string>;
47-
contentMap: Map<number, string[]>;
22+
export const CSSPlugins: {
23+
parserPlugins: typeof Plugins;
4824
};
4925

50-
declare namespace CSSPlugins {
51-
export {
52-
Plugins as parserPlugins
53-
}
54-
}
55-
5626
// @public
5727
export interface EncodeOptions {
5828
// (undocumented)
@@ -98,8 +68,8 @@ export interface LynxEncodePluginOptions {
9868
export class LynxTemplatePlugin {
9969
constructor(options?: LynxTemplatePluginOptions | undefined);
10070
apply(compiler: Compiler): void;
101-
static convertCSSChunksToMap(cssChunks: string[], plugins: CSS_2.Plugin[], enableCSSSelector: boolean): {
102-
cssMap: Record<string, CSS_2.LynxStyleNode[]>;
71+
static convertCSSChunksToMap(cssChunks: string[], plugins: CSS.Plugin[], enableCSSSelector: boolean): {
72+
cssMap: Record<string, CSS.LynxStyleNode[]>;
10373
cssSource: Record<string, string>;
10474
};
10575
static defaultOptions: Readonly<Required<LynxTemplatePluginOptions>>;
@@ -109,7 +79,7 @@ export class LynxTemplatePlugin {
10979
// @public
11080
export interface LynxTemplatePluginOptions {
11181
chunks?: 'all' | string[];
112-
cssPlugins: CSS_2.Plugin[];
82+
cssPlugins: CSS.Plugin[];
11383
customCSSInheritanceList: string[] | undefined;
11484
debugInfoOutside: boolean;
11585
defaultDisplayLinear: boolean;

packages/webpack/template-webpack-plugin/src/LynxTemplatePlugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ import type {
2020
} from 'webpack';
2121

2222
import type * as CSS from '@lynx-js/css-serializer';
23+
import { cssChunksToMap } from '@lynx-js/css-serializer';
2324
import { RuntimeGlobals } from '@lynx-js/webpack-runtime-globals';
2425

25-
import { cssChunksToMap } from './css/cssChunksToMap.js';
2626
import { createLynxAsyncChunksRuntimeModule } from './LynxAsyncChunksRuntimeModule.js';
2727

2828
export type OriginManifest = Record<string, {

0 commit comments

Comments
 (0)