Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/wet-rockets-taste.md
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
1 change: 1 addition & 0 deletions packages/tools/css-serializer/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/tools/css-serializer/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, CSS_2.LynxStyleNode[]>;
cssSource: Record<string, string>;
contentMap: Map<number, string[]>;
export const CSSPlugins: {
parserPlugins: typeof Plugins;
};

declare namespace CSSPlugins {
export {
Plugins as parserPlugins
}
}

// @public
export interface EncodeOptions {
// (undocumented)
Expand Down Expand Up @@ -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<string, CSS_2.LynxStyleNode[]>;
static convertCSSChunksToMap(cssChunks: string[], plugins: CSS.Plugin[], enableCSSSelector: boolean): {
cssMap: Record<string, CSS.LynxStyleNode[]>;
cssSource: Record<string, string>;
};
static defaultOptions: Readonly<Required<LynxTemplatePluginOptions>>;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

import type { Compilation, Compiler } from 'webpack';

import type { LynxStyleNode } from '@lynx-js/css-serializer';
import type { TasmJSONInfo } from '@lynx-js/web-core-wasm/encode';

import type { LynxStyleNode } from './css/index.js';
import {
LynxTemplatePlugin,
isDebug,
Expand Down
15 changes: 0 additions & 15 deletions packages/webpack/template-webpack-plugin/src/css/index.ts

This file was deleted.

11 changes: 9 additions & 2 deletions packages/webpack/template-webpack-plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
* A webpack plugin that simplifies creation of `template.js` files to serve your bundles.
*/

import { Plugins } from '@lynx-js/css-serializer';
import * as CSS from '@lynx-js/css-serializer';

export { LynxTemplatePlugin } from './LynxTemplatePlugin.js';
export type {
LynxTemplatePluginOptions,
Expand All @@ -17,5 +20,9 @@ export type {
export { LynxEncodePlugin } from './LynxEncodePlugin.js';
export type { LynxEncodePluginOptions } from './LynxEncodePlugin.js';
export { WebEncodePlugin } from './WebEncodePlugin.js';
export * as CSSPlugins from './css/plugins/index.js';
export * as CSS from './css/index.js';
export const CSSPlugins: {
parserPlugins: typeof Plugins;
} = {
parserPlugins: Plugins,
};
Comment thread
upupming marked this conversation as resolved.
export { CSS };
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
// 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 { CSSRule, OneInfo, StyleInfo } from './StyleInfo.js';
import * as CSS from '../css/index.js';

export function genStyleInfo(
cssMap: Record<string, CSS.LynxStyleNode[]>,
Expand Down
Loading