Skip to content

Migrate postcss-place #42

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 28, 2021
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
15 changes: 0 additions & 15 deletions plugins/postcss-place/.editorconfig

This file was deleted.

1 change: 0 additions & 1 deletion plugins/postcss-place/.gitattributes

This file was deleted.

18 changes: 0 additions & 18 deletions plugins/postcss-place/.github/workflows/test.yml

This file was deleted.

6 changes: 3 additions & 3 deletions plugins/postcss-place/.gitignore
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
dist
node_modules
dist
package-lock.json
yarn.lock
*.log*
*.result.css
.*
*.result.css.map
!.editorconfig
!.gitattributes
!.gitignore
!.rollup.js
!.tape.js
!.travis.yml
!.github
26 changes: 0 additions & 26 deletions plugins/postcss-place/.rollup.js

This file was deleted.

65 changes: 0 additions & 65 deletions plugins/postcss-place/CONTRIBUTING.md

This file was deleted.

2 changes: 1 addition & 1 deletion plugins/postcss-place/INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,6 @@ grunt.initConfig({
[PostCSS]: https://github.com/postcss/postcss
[PostCSS CLI]: https://github.com/postcss/postcss-cli
[PostCSS Loader]: https://github.com/postcss/postcss-loader
[PostCSS Place Properties]: https://github.com/csstools/postcss-place
[PostCSS Place Properties]: https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-place
[React App Rewire PostCSS]: https://github.com/csstools/react-app-rewire-postcss
[React App Rewired]: https://github.com/timarney/react-app-rewired
6 changes: 3 additions & 3 deletions plugins/postcss-place/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[<img alt="NPM Version" src="https://img.shields.io/npm/v/postcss-place.svg" height="20">][npm-url]
[<img alt="CSS Standard Status" src="https://cssdb.org/badge/double-position-gradients.svg" height="20">][css-url]
[<img alt="Build Status" src="https://github.com/csstools/postcss-place/workflows/test/badge.svg" height="20">][cli-url]
[<img alt="Build Status" src="https://github.com/csstools/postcss-plugins/workflows/test/badge.svg" height="20">][cli-url]
[<img alt="Support Chat" src="https://img.shields.io/badge/support-chat-blue.svg" height="20">][git-url]

[PostCSS Place Properties] lets you use `place-*` properties as shorthands for `align-*`
Expand Down Expand Up @@ -77,7 +77,7 @@ postcssPlace({ preserve: false })
}
```

[cli-url]: https://github.com/csstools/postcss-place/actions/workflows/test.yml?query=workflow/test
[cli-url]: https://github.com/csstools/postcss-plugins/actions/workflows/test.yml?query=workflow/test
[css-url]: https://cssdb.org/#place-properties
[git-url]: https://gitter.im/postcss/postcss
[npm-url]: https://www.npmjs.com/package/postcss-place
Expand All @@ -87,4 +87,4 @@ postcssPlace({ preserve: false })
[Grunt PostCSS]: https://github.com/nDmitry/grunt-postcss
[PostCSS]: https://github.com/postcss/postcss
[PostCSS Loader]: https://github.com/postcss/postcss-loader
[PostCSS Place Properties]: https://github.com/csstools/postcss-place
[PostCSS Place Properties]: https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-place
70 changes: 26 additions & 44 deletions plugins/postcss-place/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,62 +4,39 @@
"description": "Use a place-* shorthand for align-* and justify-* in CSS",
"author": "Jonathan Neal <jonathantneal@hotmail.com>",
"license": "CC0-1.0",
"repository": "csstools/postcss-place",
"homepage": "https://github.com/csstools/postcss-place#readme",
"bugs": "https://github.com/csstools/postcss-place/issues",
"main": "dist/index.js",
"homepage": "https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-place#readme",
"bugs": "https://github.com/csstools/postcss-plugins/issues",
"main": "dist/index.cjs",
"module": "dist/index.mjs",
"files": [
"CHANGELOG.md",
"INSTALL.md",
"LICENSE.md",
"README.md",
"dist"
],
"bin": {
"postcss-place": "dist/cli.mjs"
},
"scripts": {
"build": "npx rollup -c .rollup.js",
"build:watch": "npx rollup -c .rollup.js --watch",
"lint": "npx eslint --cache src",
"lint:fix": "npx eslint --cache --fix",
"pretest": "npm install && npm run build",
"test": "npm run lint && npm run tape",
"tape": "npx postcss-tape",
"prepublishOnly": "npm test"
"prepublishOnly": "npm run build && npm run test",
"lint": "eslint src/**/*.js",
"test": "postcss-tape",
"build": "rollup -c ../../rollup/default.js",
"stryker": "stryker run --logLevel error"
},
"engines": {
"node": ">=12"
"node": "^12 || ^14 || >=16"
},
"dependencies": {
"postcss-values-parser": "6.0.1"
},
"peerDependencies": {
"postcss": "^8.3"
},
"devDependencies": {
"@babel/core": "^7.16.0",
"@babel/preset-env": "^7.16.4",
"@rollup/plugin-babel": "^5.3.0",
"eslint": "^8.2.0",
"postcss": "^8.3.11",
"postcss-tape": "^6.0.1",
"pre-commit": "^1.2.2",
"rollup": "^2.60.0"
"postcss": "8.3.6",
"postcss-tape": "6.0.1"
},
"babel": {
"presets": [
[
"@babel/env",
{
"targets": "maintained node versions"
}
]
]
},
"eslintConfig": {
"env": {
"es6": true,
"node": true
},
"extends": "eslint:recommended",
"parserOptions": {
"sourceType": "module"
}
"peerDependencies": {
"postcss": "^8.3"
},
"keywords": [
"postcss",
Expand All @@ -72,5 +49,10 @@
"aligns",
"contents",
"selfs"
]
],
"repository": {
"type": "git",
"url": "https://github.com/csstools/postcss-plugins.git",
"directory": "plugins/postcss-place"
}
}
15 changes: 15 additions & 0 deletions plugins/postcss-place/src/cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import plugin from './index';
import { cli, helpTextLogger } from '@csstools/base-cli';

cli(
plugin,
['preserve'],
helpTextLogger(
'postcss-place',
'PostCSS Place',
'Lets you use place-* properties as shorthands for align-* and justify-*, following the CSS Box Alignment specification.',
{
preserve: true,
},
),
);
16 changes: 8 additions & 8 deletions plugins/postcss-place/src/index.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import options from './options'
import onCSSDeclaration, { placeMatch } from './onCSSDeclaration'
import options from './options';
import onCSSDeclaration, { placeMatch } from './onCSSDeclaration';

const creator = opts => {
// prepare options
if ('preserve' in Object(opts)) options.preserve = Boolean(opts.preserve)
if ('preserve' in Object(opts)) options.preserve = Boolean(opts.preserve);

return {
postcssPlugin: 'postcss-place',
Declaration: (decl, { result }) => {
if (placeMatch.test(decl)) {
onCSSDeclaration(decl, { result })
onCSSDeclaration(decl, { result });
}
},
}
}
};
};

creator.postcss = true
creator.postcss = true;

export default creator
export default creator;
38 changes: 19 additions & 19 deletions plugins/postcss-place/src/onCSSDeclaration.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,47 @@
import { parse } from 'postcss-values-parser'
import options from './options'
import { parse } from 'postcss-values-parser';
import options from './options';

export default (decl, { result }) => {
// alignment
const alignment = decl.prop.match(placeMatch)[1]
const alignment = decl.prop.match(placeMatch)[1];

// value ast and child nodes
let value
let value;

try {
value = parse(decl.value)
value = parse(decl.value);
} catch (error) {
decl.warn(
result,
`Failed to parse value '${decl.value}'. Leaving the original value intact.`
)
`Failed to parse value '${decl.value}'. Leaving the original value intact.`,
);
}

if (typeof value === 'undefined') {
return
return;
}

let alignmentValues = []
let alignmentValues = [];
value.walkWords(walk => {
alignmentValues.push(
walk.parent.type === 'root' ? walk.toString() : walk.parent.toString()
)
})
walk.parent.type === 'root' ? walk.toString() : walk.parent.toString(),
);
});

decl.cloneBefore({
prop: `align-${alignment}`,
value: alignmentValues[0]
})
value: alignmentValues[0],
});

decl.cloneBefore({
prop: `justify-${alignment}`,
value: alignmentValues[1] || alignmentValues[0]
})
value: alignmentValues[1] || alignmentValues[0],
});

// conditionally remove place-[alignment]
if (!options.preserve) {
decl.remove()
decl.remove();
}
}
};

export const placeMatch = /^place-(content|items|self)/
export const placeMatch = /^place-(content|items|self)/;
4 changes: 2 additions & 2 deletions plugins/postcss-place/src/options.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default {
/** Whether to preserve the original place value. */
preserve: true
}
preserve: true,
};