diff --git a/.changeset/wet-rockets-taste.md b/.changeset/wet-rockets-taste.md new file mode 100644 index 0000000000..925f30e801 --- /dev/null +++ b/.changeset/wet-rockets-taste.md @@ -0,0 +1,6 @@ +--- +"@lynx-js/template-webpack-plugin": patch +"@lynx-js/css-serializer": patch +--- + +Move `cssChunksToMap` implementation from `@lynx-js/template-webpack-plugin` to `@lynx-js/css-serializer` for future reuse. diff --git a/packages/webpack/template-webpack-plugin/src/css/ast.ts b/packages/tools/css-serializer/src/css/ast.ts similarity index 80% rename from packages/webpack/template-webpack-plugin/src/css/ast.ts rename to packages/tools/css-serializer/src/css/ast.ts index f6a3ff07e9..e31e4815d3 100644 --- a/packages/webpack/template-webpack-plugin/src/css/ast.ts +++ b/packages/tools/css-serializer/src/css/ast.ts @@ -1,8 +1,8 @@ // Copyright 2024 The Lynx Authors. All rights reserved. // Licensed under the Apache License Version 2.0 that can be found in the // LICENSE file in the root directory of this source tree. -import * as CSS from '@lynx-js/css-serializer'; -import type { Plugin } from '@lynx-js/css-serializer'; +import * as CSS from '../index.js'; +import type { Plugin } from '../index.js'; export function cssToAst( content: string, diff --git a/packages/webpack/template-webpack-plugin/src/css/cssChunksToMap.ts b/packages/tools/css-serializer/src/css/cssChunksToMap.ts similarity index 96% rename from packages/webpack/template-webpack-plugin/src/css/cssChunksToMap.ts rename to packages/tools/css-serializer/src/css/cssChunksToMap.ts index e2cbfe1cfb..79b9f428a2 100644 --- a/packages/webpack/template-webpack-plugin/src/css/cssChunksToMap.ts +++ b/packages/tools/css-serializer/src/css/cssChunksToMap.ts @@ -1,7 +1,7 @@ // Copyright 2024 The Lynx Authors. All rights reserved. // Licensed under the Apache License Version 2.0 that can be found in the // LICENSE file in the root directory of this source tree. -import type * as CSS from '@lynx-js/css-serializer'; +import type * as CSS from '../index.js'; import { cssToAst } from './ast.js'; import { debundleCSS } from './debundle.js'; diff --git a/packages/webpack/template-webpack-plugin/src/css/debundle.ts b/packages/tools/css-serializer/src/css/debundle.ts similarity index 100% rename from packages/webpack/template-webpack-plugin/src/css/debundle.ts rename to packages/tools/css-serializer/src/css/debundle.ts diff --git a/packages/webpack/template-webpack-plugin/src/css/plugins/index.ts b/packages/tools/css-serializer/src/css/index.ts similarity index 73% rename from packages/webpack/template-webpack-plugin/src/css/plugins/index.ts rename to packages/tools/css-serializer/src/css/index.ts index 11ecec36c8..52b3884773 100644 --- a/packages/webpack/template-webpack-plugin/src/css/plugins/index.ts +++ b/packages/tools/css-serializer/src/css/index.ts @@ -1,4 +1,4 @@ // Copyright 2024 The Lynx Authors. All rights reserved. // Licensed under the Apache License Version 2.0 that can be found in the // LICENSE file in the root directory of this source tree. -export { Plugins as parserPlugins } from '@lynx-js/css-serializer'; +export { cssChunksToMap } from './cssChunksToMap.js'; diff --git a/packages/tools/css-serializer/src/index.ts b/packages/tools/css-serializer/src/index.ts index 46bdb0f90e..cecf59375f 100644 --- a/packages/tools/css-serializer/src/index.ts +++ b/packages/tools/css-serializer/src/index.ts @@ -7,3 +7,4 @@ export * as csstree from 'css-tree'; export * as Plugins from './plugins/index.js'; export type * from './types/index.js'; export { parse } from './parse.js'; +export * from './css/index.js'; diff --git a/packages/webpack/template-webpack-plugin/test/css.test.ts b/packages/tools/css-serializer/test/css.test.ts similarity index 99% rename from packages/webpack/template-webpack-plugin/test/css.test.ts rename to packages/tools/css-serializer/test/css.test.ts index bb3bcb4ed8..60b3457ad1 100644 --- a/packages/webpack/template-webpack-plugin/test/css.test.ts +++ b/packages/tools/css-serializer/test/css.test.ts @@ -3,11 +3,14 @@ // LICENSE file in the root directory of this source tree. import { describe, expect, test } from 'vitest'; -import type { LynxStyleNode } from '@lynx-js/css-serializer'; +import type { LynxStyleNode } from '../src'; -import { cssChunksToMap } from '../src/css/cssChunksToMap.js'; +import { cssChunksToMap, Plugins as parserPlugins } from '../src'; import { debundleCSS } from '../src/css/debundle.js'; -import { CSSPlugins } from '../src/index.js'; + +const CSSPlugins = { + parserPlugins, +}; describe('CSS', () => { describe('cssChunksToMap', () => { diff --git a/packages/tools/css-serializer/vitest.config.ts b/packages/tools/css-serializer/vitest.config.ts index 2eb5f149a2..8b96ba532e 100644 --- a/packages/tools/css-serializer/vitest.config.ts +++ b/packages/tools/css-serializer/vitest.config.ts @@ -2,7 +2,7 @@ import { defineConfig } from 'vitest/config'; export default defineConfig({ test: { - include: ['**/test/*.spec.ts'], + include: ['**/test/*.spec.ts', '**/test/*.test.ts'], name: 'tools/css-serializer', }, }); diff --git a/packages/webpack/template-webpack-plugin/etc/template-webpack-plugin.api.md b/packages/webpack/template-webpack-plugin/etc/template-webpack-plugin.api.md index 1e75f58964..1d2994c9d1 100644 --- a/packages/webpack/template-webpack-plugin/etc/template-webpack-plugin.api.md +++ b/packages/webpack/template-webpack-plugin/etc/template-webpack-plugin.api.md @@ -9,50 +9,20 @@ import { AsyncSeriesBailHook } from '@rspack/lite-tapable'; import { AsyncSeriesWaterfallHook } from '@rspack/lite-tapable'; import type { Compilation } from 'webpack'; import type { Compiler } from 'webpack'; -import type * as CSS_2 from '@lynx-js/css-serializer'; -import { csstree } from '@lynx-js/css-serializer'; -import { Declaration } from '@lynx-js/css-serializer'; -import { FontFaceRule } from '@lynx-js/css-serializer'; -import { ImportRule } from '@lynx-js/css-serializer'; -import { KeyframesRule } from '@lynx-js/css-serializer'; -import { LynxStyleNode } from '@lynx-js/css-serializer'; -import { parse } from '@lynx-js/css-serializer'; -import { Plugin } from '@lynx-js/css-serializer'; +import * as CSS from '@lynx-js/css-serializer'; +import { cssChunksToMap } from '@lynx-js/css-serializer'; import { Plugins } from '@lynx-js/css-serializer'; -import { StyleRule } from '@lynx-js/css-serializer'; import { SyncWaterfallHook } from '@rspack/lite-tapable'; -declare namespace CSS { - export { - csstree, - Plugins, - parse, - Plugin, - Declaration, - LynxStyleNode, - StyleRule, - FontFaceRule, - ImportRule, - KeyframesRule, - cssChunksToMap - } -} +export { CSS } -// 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) +// 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) // // @public (undocumented) -function cssChunksToMap(cssChunks: string[], plugins: CSS_2.Plugin[], enableCSSSelector: boolean): { - cssMap: Record; - cssSource: Record; - contentMap: Map; +export const CSSPlugins: { + parserPlugins: typeof Plugins; }; -declare namespace CSSPlugins { - export { - Plugins as parserPlugins - } -} - // @public export interface EncodeOptions { // (undocumented) @@ -98,8 +68,8 @@ export interface LynxEncodePluginOptions { export class LynxTemplatePlugin { constructor(options?: LynxTemplatePluginOptions | undefined); apply(compiler: Compiler): void; - static convertCSSChunksToMap(cssChunks: string[], plugins: CSS_2.Plugin[], enableCSSSelector: boolean): { - cssMap: Record; + static convertCSSChunksToMap(cssChunks: string[], plugins: CSS.Plugin[], enableCSSSelector: boolean): { + cssMap: Record; cssSource: Record; }; static defaultOptions: Readonly>; @@ -109,7 +79,7 @@ export class LynxTemplatePlugin { // @public export interface LynxTemplatePluginOptions { chunks?: 'all' | string[]; - cssPlugins: CSS_2.Plugin[]; + cssPlugins: CSS.Plugin[]; customCSSInheritanceList: string[] | undefined; debugInfoOutside: boolean; defaultDisplayLinear: boolean; diff --git a/packages/webpack/template-webpack-plugin/src/LynxTemplatePlugin.ts b/packages/webpack/template-webpack-plugin/src/LynxTemplatePlugin.ts index 5f16bda3ea..574cd61ad4 100644 --- a/packages/webpack/template-webpack-plugin/src/LynxTemplatePlugin.ts +++ b/packages/webpack/template-webpack-plugin/src/LynxTemplatePlugin.ts @@ -20,9 +20,9 @@ import type { } from 'webpack'; import type * as CSS from '@lynx-js/css-serializer'; +import { cssChunksToMap } from '@lynx-js/css-serializer'; import { RuntimeGlobals } from '@lynx-js/webpack-runtime-globals'; -import { cssChunksToMap } from './css/cssChunksToMap.js'; import { createLynxAsyncChunksRuntimeModule } from './LynxAsyncChunksRuntimeModule.js'; export type OriginManifest = Record,