Skip to content

Commit 08a095f

Browse files
authored
feat: deprecated uglify in favor of cssnano or cleanCSS (#50)
* feat(typescript-transform): clean css * fix: *sigh* * chore: lint * docs: changeset * chore: changesets config
1 parent a928c49 commit 08a095f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+6919
-4253
lines changed

Diff for: .changeset/config.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,7 @@
66
"access": "public",
77
"baseBranch": "main",
88
"updateInternalDependencies": "patch",
9-
"ignore": ["test"]
9+
"ignore": [
10+
"@lit-css/test"
11+
]
1012
}

Diff for: .changeset/cssnano.md

+6

Diff for: .changeset/typescript-min.md

+4

Diff for: .eslintignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
test/*/expected/**/*.js
1+
packages/*/test/expected/**/*.js
2+
packages/*/test/TSPC_OUTPUT/**/*.js
23
packages/*/*.js
34
packages/*/*.cjs
45
packages/*/*.js.map

Diff for: .gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ fsevents-*.node
1010
# Diagnostic reports (https://nodejs.org/api/report.html)
1111
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
1212

13+
TSPC_OUTPUT
14+
1315
# Runtime data
1416
pids
1517
*.pid

Diff for: .npmignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
packages/*/test/**/*

Diff for: package-lock.json

+6,476-4,136
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+16-14
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"build:runtime": "node build.js",
2020
"build:types": "tsc",
2121
"lint": "eslint .",
22-
"test": "npm run build:runtime && tape 'test/*/*.test.js' | tap-spec",
22+
"test": "npm run build:runtime && tape 'packages/*/test/*.test.js' | tap-spec",
2323
"release": "npm run build && npm run test && npx changeset publish",
2424
"clean": "rimraf 'packages/*/*.{cjs,js,d.ts,js.map,cjs.map}'"
2525
},
@@ -28,35 +28,37 @@
2828
"test"
2929
],
3030
"devDependencies": {
31-
"@babel/core": "^7.23.2",
32-
"@babel/preset-env": "^7.23.2",
31+
"@babel/core": "^7.23.3",
32+
"@babel/preset-env": "^7.23.3",
3333
"@changesets/cli": "^2.26.2",
3434
"@microsoft/fast-element": "^1.12.0",
3535
"@pwrs/eslint-config": "^0.0.26",
36-
"@rollup/plugin-alias": "^3.1.9",
37-
"@types/node": "^18.15.11",
38-
"@types/uglifycss": "^0.0.9",
39-
"@web/dev-server-core": "^0.6.3",
36+
"@rollup/plugin-alias": "^5.0.1",
37+
"@types/node": "^20.9.0",
38+
"@types/uglifycss": "^0.0.10",
39+
"@web/dev-server-core": "^0.7.0",
4040
"arraybuffer-to-string": "^1.0.2",
4141
"cross-env": "^7.0.3",
4242
"cz-conventional-changelog": "^3.3.0",
4343
"esbuild": "^0.19.5",
4444
"esbuild-plugin-alias": "^0.2.1",
4545
"esm": "^3.2.25",
46-
"globby": "^13.2.2",
47-
"lit": "^3.0.1",
48-
"memfs": "^3.5.0",
49-
"nodemon": "^2.0.22",
46+
"execa": "^8.0.1",
47+
"globby": "^14.0.0",
48+
"lit": "^3.0.2",
49+
"memfs": "^4.6.0",
50+
"nodemon": "^3.0.1",
5051
"npm-run-all": "^4.1.5",
5152
"postcss": "^8.4.31",
52-
"postcss-nesting": "^10.2.0",
53-
"rollup": "^2.79.1",
53+
"postcss-nesting": "^12.0.1",
54+
"rollup": "^4.4.1",
5455
"rollup-plugin-alias": "^2.2.0",
5556
"sass": "^1.69.5",
56-
"semantic-release": "^19.0.5",
57+
"semantic-release": "^22.0.7",
5758
"tap-spec": "^5.0.0",
5859
"tap-summary": "^4.0.0",
5960
"tape": "^5.7.2",
61+
"ts-patch": "^3.0.2",
6062
"typescript": "^5.2.2",
6163
"webpack": "^5.89.0",
6264
"wsrun": "^5.2.4"

Diff for: packages/esbuild-plugin-lit-css/README.md

+21-10

Diff for: test/esbuild-plugin-lit-css/esbuild-plugin-lit-css.test.js renamed to packages/esbuild-plugin-lit-css/test/esbuild-plugin-lit-css.test.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,32 @@ import { litCssPlugin } from 'esbuild-plugin-lit-css';
22
import esbuild from 'esbuild';
33
import aliasPlugin from 'esbuild-plugin-alias';
44

5-
import { dirname, resolve } from 'node:path';
5+
import { dirname, join, resolve } from 'node:path';
66
import { fileURLToPath } from 'node:url';
77

8-
import { run } from '../test.js';
8+
import { run } from '@lit-css/test/test.js';
9+
910
import ab2str from 'arraybuffer-to-string';
1011

1112
// type check
1213
litCssPlugin({ filter: /hi/ });
1314

1415
const dir = dirname(fileURLToPath(import.meta.url));
1516

17+
const FIXTURES_DIR = join(dir, '..', '..', '..', 'test', '😁-FIXTURES');
18+
1619
async function getCode(path, { options, alias } = {}) {
1720
const additionalPlugins = [...alias ? [
1821
aliasPlugin(
1922
Object.fromEntries(
2023
Object.entries(alias)
2124
.map(([k, v]) =>
22-
[k, resolve(dir, '..', '😁-FIXTURES', 'bare', v)])
25+
[k, resolve(FIXTURES_DIR, 'bare', v)])
2326
)
2427
),
2528
] : []];
2629

27-
const input = resolve(dir, '..', '😁-FIXTURES', path);
30+
const input = resolve(FIXTURES_DIR, path);
2831
const bundle = await esbuild.build({
2932
entryPoints: [input],
3033
target: 'es2020',

Diff for: test/esbuild-plugin-minify-html-literals/esbuild-plugin-minify-html-literals.test.js renamed to packages/esbuild-plugin-minify-html-literals/test/esbuild-plugin-minify-html-literals.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ test('esbuild-plugin-minify-html-literals', async function(assert) {
3232
],
3333
});
3434

35-
const expected = `// test/esbuild-plugin-minify-html-literals/fixture.js
35+
const expected = `// packages/esbuild-plugin-minify-html-literals/test/fixture.js
3636
import { html } from "lit";
3737
var tpl = html\`<p>hello, world</p><input type="text"> <button type="button">button</button>\`;
3838
export {

Diff for: packages/lit-css-loader/README.md

+22-11

Diff for: test/lit-css-loader/compiler.js renamed to packages/lit-css-loader/test/compiler.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import { createFsFromVolume, Volume } from 'memfs';
88

99
const __dirname = dirname(fileURLToPath(import.meta.url));
1010

11+
const FIXTURES_DIR = join(__dirname, '..', '..', '..', 'test', '😁-FIXTURES');
12+
1113
/**
1214
* @param {object} fixture
1315
* @param {import('../../packages/lit-css-loader/lit-css-loader').LitCSSOptions} [options={}]
@@ -20,7 +22,7 @@ export const compiler = ({
2022
}) => {
2123
const compiler = webpack({
2224
mode: 'development',
23-
context: resolve(__dirname, '..', '😁-FIXTURES'),
25+
context: FIXTURES_DIR,
2426
entry: `./${path}`,
2527
output: {
2628
path: resolve(__dirname),

Diff for: test/lit-css-loader/lit-css-loader.test.js renamed to packages/lit-css-loader/test/lit-css-loader.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { compiler } from './compiler.js';
22
import { dirname } from 'node:path';
33
import { fileURLToPath } from 'node:url';
4-
import { run } from '../test.js';
4+
import { run } from '@lit-css/test/test.js';
55

66
const dir = dirname(fileURLToPath(import.meta.url));
77

Diff for: packages/lit-css/lit-css.ts

+25-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import stringToTemplateLiteral from 'string-to-template-literal';
22

33
import { processString, UglifyCSSOptions } from 'uglifycss';
4+
import cssnano, { Options as CssnanoOptions } from 'cssnano';
45

56
export interface Meta {
67
/**
@@ -33,8 +34,14 @@ export interface Options {
3334
/**
3435
* Whether to uglify the CSS. Can also be an object of uglifycss options
3536
* @default false
37+
* @deprecated: use `minify`
3638
*/
3739
uglify?: boolean|UglifyCSSOptions;
40+
/**
41+
* Whether to minify the CSS using cssnano. can also be an object of css nano options.
42+
* @default false
43+
*/
44+
cssnano?: boolean|CssnanoOptions;
3845
/**
3946
* Transform sources using tools like sass or postcss
4047
* @param source Source file contents e.g. scss or postcss sources
@@ -44,17 +51,33 @@ export interface Options {
4451
transform?(source: string, meta: Meta): string|Promise<string>;
4552
}
4653

54+
async function cssnanoify(css: string, options: boolean|CssnanoOptions) {
55+
const cssnanoOptions = typeof options === 'object' ? options : undefined;
56+
const result = await cssnano(cssnanoOptions).process(css);
57+
return result.css;
58+
}
59+
60+
/** @deprecated */
61+
async function uglifycssify(css: string, options: boolean|UglifyCSSOptions) {
62+
const uglifyOptions = typeof options === 'object' ? options : undefined;
63+
const result = processString(css, uglifyOptions);
64+
return result;
65+
}
66+
4767
export async function transform({
4868
css: source,
4969
filePath,
5070
specifier = 'lit',
5171
tag = 'css',
5272
uglify = false,
73+
cssnano = false,
5374
transform = x => x,
5475
}: Options): Promise<string> {
5576
const css = await transform(source, { filePath });
56-
const uglifyOptions = typeof uglify === 'object' ? uglify : undefined;
57-
const cssContent = !uglify ? css : processString(css, uglifyOptions);
77+
const cssContent =
78+
cssnano ? await cssnanoify(css, cssnano)
79+
: uglify ? await uglifycssify(css, uglify)
80+
: css;
5881
return `import {${tag}} from '${specifier}';
5982
export const styles = ${tag}${stringToTemplateLiteral(cssContent)};
6083
export default styles;

Diff for: packages/lit-css/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"lit-css.d.ts"
3131
],
3232
"dependencies": {
33+
"cssnano": "^6.0.1",
3334
"string-to-template-literal": "^2.0.0",
3435
"uglifycss": "^0.0.29"
3536
}

Diff for: test/rollup-plugin-lit-css/rollup-plugin-lit-css.test.js renamed to packages/rollup-plugin-lit-css/test/rollup-plugin-lit-css.test.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
import litcss from 'rollup-plugin-lit-css';
22
import aliasPlugin from '@rollup/plugin-alias';
33

4-
import { dirname, resolve } from 'node:path';
4+
import { dirname, join, resolve } from 'node:path';
55
import { fileURLToPath } from 'node:url';
66
import { rollup } from 'rollup';
77

8-
import { run } from '../test.js';
8+
import { run } from '@lit-css/test/test.js';
99

1010
const dir = dirname(fileURLToPath(import.meta.url));
1111

12+
const FIXTURES_DIR = join(dir, '..', '..', '..', 'test', '😁-FIXTURES');
13+
1214
// type check
1315
litcss({
1416
include: ['*'],
@@ -21,7 +23,7 @@ run({
2123
async getCode(path, { options, alias } = {}) {
2224
const additionalPlugins = [...alias ? [aliasPlugin({ entries: alias })] : []];
2325

24-
const input = resolve(dir, '..', '😁-FIXTURES', path);
26+
const input = resolve(FIXTURES_DIR, path);
2527

2628
const bundle = await rollup({
2729
input,

0 commit comments

Comments
 (0)