Skip to content

Commit 9413291

Browse files
authored
final typescript conversions (#712)
* final typescript conversions * postcss-dir-pseudo-class * export plugin types * fix * fix * fix * postcss-gap-properties * lint * postcss-overflow-shorthand * postcss-place * fix * postcss-pseudo-class-any-link * one more * more fixes and typings * wip * docs * typed options for postcss-preset-env * final fixes * add to list of plugins in execution order * clean up * Update index.ts * update cssdb * update CHANGELOG
1 parent 8bba42a commit 9413291

File tree

186 files changed

+2187
-435
lines changed

Some content is hidden

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

186 files changed

+2187
-435
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import assert from 'assert';
2+
import plugin from 'postcss-preset-env';
3+
import postcss from 'postcss';
4+
5+
const result = await postcss([plugin()]).process(':any-link { color: blue; }').css;
6+
7+
if (process.env.BROWSERSLIST_ENV === 'production') {
8+
assert.equal(
9+
result,
10+
':link, :visited, area[href] { color: blue; }\n' +
11+
':-moz-any-link { color: blue; }\n' +
12+
':any-link { color: blue; }',
13+
);
14+
}
15+
16+
if (process.env.BROWSERSLIST_ENV === 'development') {
17+
assert.equal(result, ':any-link { color: blue; }');
18+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "@csstools/e2e--browserslist--package-json",
3+
"version": "0.0.0",
4+
"private": true,
5+
"description": "Can you use PostCSS Preset Env with a browserslist in package.json?",
6+
"scripts": {
7+
"test": "BROWSERSLIST_ENV=development node ./index.mjs && BROWSERSLIST_ENV=production node ./index.mjs"
8+
},
9+
"devDependencies": {
10+
"postcss": "^8.4.19",
11+
"postcss-preset-env": "^7.8.3"
12+
},
13+
"browserslist": {
14+
"development": [
15+
"chrome > 100"
16+
],
17+
"production": [
18+
"last 1 version",
19+
"> 1%",
20+
"not dead"
21+
]
22+
}
23+
}

package-lock.json

Lines changed: 10 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugin-packs/postcss-preset-env/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changes to PostCSS Preset Env
22

3+
### Unreleased
4+
5+
- Added: TypeScript support.
6+
- Added `@csstools/postcss-media-queries-aspect-ratio-number-values` [Check the plugin README](https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-media-queries-aspect-ratio-number-values#readme) for usage details.
7+
- Fixed: `all-property` and `overflow-wrap-property` now follow the `preserve` plugin option
8+
39
### (8.0.0-alpha.1) (November 14, 2022)
410

511
- Updated Support for Node v14+ (major).

plugin-packs/postcss-preset-env/README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,8 +369,6 @@ Given they have no support they will always be enabled if they match by Stage:
369369

370370
* `blank-pseudo-class`: [Plugin](https://github.com/csstools/postcss-plugins/blob/main/plugins/css-blank-pseudo) / [Polyfill](https://github.com/csstools/postcss-plugins/blob/main/plugins/css-blank-pseudo/README-BROWSER.md)
371371
* `custom-media-queries`: [Plugin](https://github.com/postcss/postcss-custom-media)
372-
* `has-pseudo-class`: [Plugin](https://github.com/csstools/postcss-plugins/blob/main/plugins/css-has-pseudo) / [Polyfill](https://github.com/csstools/postcss-plugins/blob/main/plugins/css-has-pseudo/README-BROWSER.md)
373-
* `image-set-function`: [Plugin](https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-image-set-function)
374372
* `media-query-ranges`: [Plugin](https://github.com/postcss/postcss-media-minmax)
375373
* `nesting-rules`: [Plugin](https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-nesting)
376374

plugin-packs/postcss-preset-env/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
},
1414
"main": "dist/index.cjs",
1515
"module": "dist/index.mjs",
16+
"types": "dist/index.d.ts",
1617
"exports": {
1718
".": {
1819
"import": "./dist/index.mjs",
@@ -33,6 +34,7 @@
3334
"@csstools/postcss-hwb-function": "^1.0.2",
3435
"@csstools/postcss-ic-unit": "^1.0.1",
3536
"@csstools/postcss-is-pseudo-class": "^2.0.7",
37+
"@csstools/postcss-media-queries-aspect-ratio-number-values": "^1.0.0",
3638
"@csstools/postcss-nested-calc": "^1.0.0",
3739
"@csstools/postcss-normalize-display-values": "^1.0.1",
3840
"@csstools/postcss-oklab-function": "^1.1.1",
@@ -47,7 +49,7 @@
4749
"css-blank-pseudo": "^4.1.1",
4850
"css-has-pseudo": "^4.0.1",
4951
"css-prefers-color-scheme": "^7.0.1",
50-
"cssdb": "^7.1.0",
52+
"cssdb": "^7.2.0",
5153
"postcss-attribute-case-insensitive": "^5.0.2",
5254
"postcss-clamp": "^4.1.0",
5355
"postcss-color-functional-notation": "^4.2.4",

plugin-packs/postcss-preset-env/scripts/generate-plugins-data.mjs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
import { readFile, writeFile } from 'fs/promises';
2+
import { existsSync } from 'fs';
3+
import path from 'path';
4+
25
const pluginsData = await readFile('./scripts/plugins-data.json', 'utf8').then(JSON.parse);
36

47
const esmPlugins = `export default ${JSON.stringify(pluginsData, null, 2)}\n`;
@@ -27,7 +30,35 @@ export const pluginsById = new Map(
2730
return result;
2831
}
2932

33+
function generatePluginOptions(data) {
34+
const plugins = data.slice(0).sort((a, b) => a.id.localeCompare(b.id));
35+
let result = '';
36+
37+
for (let i = 0; i < plugins.length; i++) {
38+
const plugin = plugins[i];
39+
40+
if (existsSync(path.join('./src/types/', plugin.packageName, 'plugin-options.ts'))) {
41+
result += `import type { pluginOptions as ${plugin.importName} } from '${path.join('../types/', plugin.packageName, 'plugin-options')}';\n`;
42+
} else {
43+
result += `import type { pluginOptions as ${plugin.importName} } from '${plugin.packageName}';\n`;
44+
}
45+
}
46+
47+
result += '\nexport type pluginsOptions = {\n';
48+
49+
for (let i = 0; i < plugins.length; i++) {
50+
const plugin = plugins[i];
51+
result += `\t/** plugin options for "${plugin.packageName}" */\n`;
52+
result += `\t'${plugin.id}'?: ${plugin.importName} | boolean\n`;
53+
}
54+
55+
result += '};\n';
56+
57+
return result;
58+
}
59+
3060
await Promise.all([
3161
writeFile('./src/plugins/plugins-data.mjs', esmPlugins),
3262
writeFile('./src/plugins/plugins-by-id.mjs', generatePluginsByID(pluginsData)),
63+
writeFile('./src/plugins/plugins-options.ts', generatePluginOptions(pluginsData)),
3364
]);

plugin-packs/postcss-preset-env/scripts/plugins-data.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,11 @@
139139
"id": "media-query-ranges",
140140
"importName": "postcssMediaMinmax"
141141
},
142+
{
143+
"packageName": "@csstools/postcss-media-queries-aspect-ratio-number-values",
144+
"id": "media-queries-aspect-ratio-number-values",
145+
"importName": "postcssMediaQueriesAspectRatioNumberValues"
146+
},
142147
{
143148
"packageName": "postcss-nesting",
144149
"id": "nesting-rules",

plugin-packs/postcss-preset-env/src/index.js renamed to plugin-packs/postcss-preset-env/src/index.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ import { initializeSharedOptions } from './lib/shared-options.mjs';
66
import { listFeatures } from './lib/list-features.mjs';
77
import { newLogger } from './log/helper.mjs';
88
import { pluginIdHelp } from './plugins/plugin-id-help.mjs';
9+
import type { pluginOptions } from './options';
10+
import type { PluginCreator } from 'postcss';
11+
export type { pluginOptions } from './options';
912

10-
11-
const plugin = (opts) => {
13+
const creator: PluginCreator<pluginOptions> = (opts?: pluginOptions) => {
1214
const logger = newLogger();
1315

1416
// initialize options
@@ -58,6 +60,6 @@ const plugin = (opts) => {
5860
};
5961
};
6062

61-
plugin.postcss = true;
63+
creator.postcss = true;
6264

63-
export default plugin;
65+
export default creator;

0 commit comments

Comments
 (0)