Skip to content

Commit 6c591c1

Browse files
authored
chore: enable trusted package publishing (#349)
1 parent 11b4f3e commit 6c591c1

File tree

6 files changed

+2029
-2073
lines changed

6 files changed

+2029
-2073
lines changed

.github/workflows/pr.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ jobs:
88
name: Test
99
runs-on: ubuntu-latest
1010
steps:
11-
- uses: actions/checkout@v3
12-
- uses: actions/setup-node@v3
11+
- uses: actions/checkout@v4
12+
- uses: actions/setup-node@v4
1313
with:
14-
node-version: 16
14+
node-version: 24
1515
- name: Build
1616
run: >
1717
yarn run build:ci

.github/workflows/release.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,19 @@ on:
77
default: false
88
type: boolean
99

10+
permissions:
11+
id-token: write # Required for OIDC
12+
contents: write
13+
1014
jobs:
1115
package_release:
1216
name: Release from "${{ github.ref_name }}" branch
1317
runs-on: ubuntu-latest
1418
steps:
15-
- uses: actions/checkout@v3
16-
- uses: actions/setup-node@v3
19+
- uses: actions/checkout@v4
20+
- uses: actions/setup-node@v4
1721
with:
18-
node-version: 16
22+
node-version: 24
1923
- name: Build
2024
run: >
2125
yarn run build:ci

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v16
1+
v24

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,13 @@
5959
"@types/prettier": "^2.6.3",
6060
"dedent": "^0.7.0",
6161
"glob": "^8.0.3",
62+
"postcss": "^8.5.6",
6263
"prettier": "^2.7.1",
6364
"sass": "^1.85.1",
64-
"semantic-release": "^18.0.1",
65+
"semantic-release": "^25.0.2",
6566
"stylelint": "^13.13.1",
6667
"stylelint-config-prettier": "^9.0.3",
6768
"stylelint-config-sass-guidelines": "^8.0.0",
68-
"tree-sitter": "^0.20.0",
69-
"tree-sitter-css": "^0.19.0",
7069
"ts-node": "^10.8.2",
7170
"typescript": "^4.7.4"
7271
},

scripts/parser.ts

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ import * as fs from 'fs';
22
import * as path from 'path';
33
import glob from 'glob';
44
import * as sass from 'sass';
5-
import Parser, { SyntaxNode } from 'tree-sitter';
6-
// @ts-ignore
7-
import CSS from 'tree-sitter-css';
5+
import postcss, { Root, Rule, Declaration, Comment, Container } from 'postcss';
86

97
type SDK = 'Angular' | 'React';
108

@@ -15,11 +13,9 @@ export type ComponentInfo = {
1513
};
1614

1715
export const extractComponents = (fromGlob: string) => {
18-
const parser = new Parser();
19-
parser.setLanguage(CSS);
20-
2116
const componentInfos: ComponentInfo[] = [];
2217
const files = glob.sync(fromGlob);
18+
2319
files.forEach((file) => {
2420
const [, componentName] = file.split(/.*\/(.*)-(theme|layout|variables)\.scss$/);
2521
// sass fails to resolve the `../utils` file for some reason, therefore
@@ -33,25 +29,27 @@ export const extractComponents = (fromGlob: string) => {
3329
loadPaths: [path.resolve('./src/v2/styles')],
3430
});
3531

32+
const css = compilation.css;
33+
const root: Root = postcss.parse(css);
34+
3635
let sdkRestriction: SDK | undefined = undefined;
3736
let variableType: 'layout' | 'theme' | undefined = undefined;
38-
const ast = parser.parse(compilation.css);
39-
ast.rootNode.descendantsOfType('rule_set').forEach((ruleSet) => {
40-
const ruleSetComment = extractComment(ruleSet);
37+
38+
root.walkRules((rule: Rule) => {
39+
const ruleSetComment = extractLeadingComment(rule);
4140
if (ruleSetComment) {
4241
const matches = ruleSetComment.match(/Angular|React/g);
4342
if (matches) {
4443
sdkRestriction = matches[0] as SDK;
4544
}
4645
}
47-
for (let i = 0; i < ruleSet.descendantsOfType('declaration').length; i++) {
48-
const node = ruleSet.descendantsOfType('declaration')[i];
49-
const identifier = node.text;
50-
if (identifier.startsWith('--str-chat')) {
46+
47+
rule.walkDecls((decl: Declaration) => {
48+
// custom property name is in decl.prop
49+
if (decl.prop.startsWith('--str-chat')) {
5150
variableType = file.includes('theme') ? 'theme' : 'layout';
52-
break;
5351
}
54-
}
52+
});
5553
});
5654

5755
if (variableType) {
@@ -73,14 +71,19 @@ export const extractComponents = (fromGlob: string) => {
7371
return componentInfos;
7472
};
7573

76-
const extractComment = (node: SyntaxNode) => {
77-
if (node.previousSibling?.type === 'comment') {
78-
const match = node.previousSibling.text.match(/\*\s*(.+?)\*\//)!;
79-
if (match) {
80-
const [, comment] = match;
81-
return comment.trim();
82-
}
83-
} else {
84-
return undefined;
74+
const extractLeadingComment = (rule: Rule): string | undefined => {
75+
const parent = rule.parent as Container | undefined;
76+
if (!parent || !('nodes' in parent) || !parent.nodes) return;
77+
78+
const idx = parent.nodes.indexOf(rule);
79+
if (idx <= 0) return;
80+
81+
const prev = parent.nodes[idx - 1];
82+
if (prev.type === 'comment') {
83+
// PostCSS comment text is everything inside /* ... */
84+
const comment = (prev as Comment).text;
85+
return comment.trim();
8586
}
87+
88+
return undefined;
8689
};

0 commit comments

Comments
 (0)