Skip to content

Commit f38860b

Browse files
jaslongactions-user
authored andcommitted
[PLA-11816] upgrade/remove vulnerable dependencies (#596)
* remove unused blink-diff which depends on vuln in [email protected] * delete unused dependency-cruiser script * upgrade set-getter to 0.1.1 to fix vuln * remove unused package optimist * replace theo with custom gen-theo.ts script The new script replaces theo, which was responsible for converting tokens defined in Plasmic to .sass and .ts files for usage in our code. There were multiple problems with the theo package: - It had a dependency on a vulnerable version of the optimist. - It is no longer actively maintained. - It did not handle duplicate token names. GitOrigin-RevId: cc785fdbe595c621c748920d69abb902f312bc05
1 parent 5355c7b commit f38860b

File tree

9 files changed

+130
-1363
lines changed

9 files changed

+130
-1363
lines changed

docs/contributing/platform/01-config-tooling.md

-16
Original file line numberDiff line numberDiff line change
@@ -333,22 +333,6 @@ Some pointers:
333333
auto-scroll things into view (which we almost never want since there's no real
334334
scrolling in our app).
335335

336-
## Debugging module graph
337-
338-
Look at what modules are big (you may want to compare the results from
339-
before and after your commit):
340-
341-
yarn source-map-explorer build/static/js/canvas.js
342-
343-
If you want to figure out how a particular module is getting included, use:
344-
345-
rm graph.json
346-
bash tools/import-chains.bash
347-
348-
import-chains.bash currently just works for canvas-entry.tsx (which is the
349-
entrypoint for the canvas.js bundle), but it can be easily updated to analyze a
350-
different entrypoint.
351-
352336
## Audit licenses of dependencies
353337

354338
For node dependencies, do this from each project directory:

platform/wab/Makefile

+2-4
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,9 @@ src/wab/shared/model/classes.ts: src/wab/gen/modelPegParser.js src/wab/shared/mo
2424
src/wab/shared/model/classes-metas.ts: src/wab/gen/modelPegParser.js src/wab/shared/model/model-schema.ts tools/gen-models.ts src/wab/shared/model/model-generator.ts
2525
yarn gen:models
2626
src/wab/styles/_tokens.sass: src/wab/styles/plasmic-tokens.theo.json
27-
yarn run theo src/wab/styles/plasmic-tokens.theo.json --transform web --format sass --dest src/wab/styles
28-
mv src/wab/styles/plasmic-tokens.theo.sass src/wab/styles/_tokens.sass
27+
yarn gen:plasmic-tokens-sass
2928
src/wab/styles/_tokens.ts: src/wab/styles/plasmic-tokens.theo.json
30-
yarn run theo src/wab/styles/plasmic-tokens.theo.json --transform web --format module.js --dest src/wab/styles
31-
mv src/wab/styles/plasmic-tokens.theo.module.js src/wab/styles/_tokens.ts
29+
yarn gen:plasmic-tokens-ts
3230
src/wab/styles/css-variables.ts: src/wab/styles/css-variables.json
3331
node src/wab/styles/css-variables.gen.js
3432
src/wab/styles/css-variables.scss: src/wab/styles/css-variables.json

platform/wab/cypress/plugins/index.ts

-52
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ require("cypress-log-to-output");
1818

1919
const webpack = require("webpack");
2020
const wp = require("@cypress/webpack-preprocessor");
21-
const BlinkDiff = require("blink-diff");
2221
const fs = require("fs");
2322
const path = require("path");
2423

@@ -93,57 +92,6 @@ module.exports = (on, config) => {
9392
// `config` is the resolved Cypress config
9493
on("file:preprocessor", wp(options));
9594

96-
on("after:screenshot", (details) => {
97-
// If the screenshot was taken with name matching check-X, then we will
98-
// compare it to a reference screenshot located at screenshot_refs/X (which
99-
// should exist already).
100-
if (!details.name || !details.name.startsWith("check-")) {
101-
return;
102-
}
103-
const testImage = details.path;
104-
const refImage = path.join(
105-
__dirname,
106-
"/../screenshotRefs/",
107-
details.name + ".png"
108-
);
109-
110-
console.log(
111-
"Comparing screenshots:",
112-
"\ntestImage:",
113-
testImage,
114-
"\n refImage:",
115-
refImage
116-
);
117-
118-
if (!fs.existsSync(refImage)) {
119-
console.log("Reference image doesn't exist.");
120-
return Promise.reject(false);
121-
}
122-
123-
// An alternative image comparison library that seems good is resemblejs
124-
// https://github.com/HuddleEng/Resemble.js
125-
const diff = new BlinkDiff({
126-
imageAPath: refImage,
127-
imageBPath: testImage,
128-
thresholdType: BlinkDiff.THRESHOLD_PERCENT,
129-
threshold: 0.2, // allow 20% of pixels to differ
130-
});
131-
132-
return new Promise((resolve, reject) => {
133-
diff.run((error, result) => {
134-
if (error) {
135-
throw error;
136-
} else {
137-
if (diff.hasPassed(result.code)) {
138-
resolve(true);
139-
} else {
140-
reject(false);
141-
}
142-
}
143-
});
144-
});
145-
});
146-
14795
on("task", {
14896
getFetchPolyfill() {
14997
return fetchPolyfill;

platform/wab/package.json

+2-4
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
"backend:debug": "debug=1 bash tools/backend-server.bash",
4545
"gen:models": "npm run run-ts -- tools/gen-models.ts",
4646
"gen:component-metas": "npm run run-ts -- tools/gen-react-meta.ts",
47+
"gen:plasmic-tokens-sass": "npm run run-ts -- tools/gen-theo.ts src/wab/styles/plasmic-tokens.theo.json src/wab/styles/_tokens.sass",
48+
"gen:plasmic-tokens-ts": "npm run run-ts -- tools/gen-theo.ts src/wab/styles/plasmic-tokens.theo.json src/wab/styles/_tokens.ts",
4749
"start-backend": "pm2 start ts-node -i 1 --wait-ready --listen-timeout 19999 --kill-timeout 7999 -- -T -P tsconfig.tools.json src/wab/server/main.ts",
4850
"perftool": "npm run run-ts -- tools/perf.ts",
4951
"build-css": "sass src/wab/styles/canvas/:dev-build/static/styles/canvas/",
@@ -161,7 +163,6 @@
161163
"@types/xmldom": "^0.1.30",
162164
"babel-jest": "^29.7.0",
163165
"babel-plugin-implicit-return": "^1.0.1",
164-
"blink-diff": "^1.0.13",
165166
"concurrently": "^5.3.0",
166167
"cypress": "^13.4.0",
167168
"cypress-fail-fast": "^7.1.1",
@@ -171,7 +172,6 @@
171172
"cypress-real-events": "^1.13.0",
172173
"cypress-split": "^1.24.7",
173174
"depcheck": "^1.4.3",
174-
"dependency-cruiser": "^9.21.6",
175175
"diff": "^4.0.2",
176176
"enzyme": "^3.11.0",
177177
"enzyme-to-json": "^3.6.2",
@@ -188,7 +188,6 @@
188188
"less-loader": "^6.2.0",
189189
"less-vars-to-js": "^1.3.0",
190190
"monaco-editor-webpack-plugin": "7.1.0",
191-
"optimist": "^0.6.1",
192191
"pegjs": "~0.10.0",
193192
"pegjs-coffee-plugin": "~0.3.0",
194193
"prando": "^6.0.1",
@@ -200,7 +199,6 @@
200199
"sucrase": "^3.35.0",
201200
"swc-loader": "^0.2.3",
202201
"terser": "^3.17.0",
203-
"theo": "^8.1.5",
204202
"ts-loader": "^9.4.2",
205203
"tsx": "^3.13.0",
206204
"type-fest": "^4.15.0",

platform/wab/tools/depcruise-config.js

-16
This file was deleted.

platform/wab/tools/gen-theo.ts

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import * as fs from "fs";
2+
import { groupBy } from "lodash";
3+
import { TheoToken } from "../src/wab/shared/codegen/style-tokens";
4+
5+
function main() {
6+
// Get command line arguments
7+
const [inputFile, outputFile] = process.argv.slice(2);
8+
9+
// Read the tokens from the input theo JSON file
10+
const tokens: TheoToken[] = JSON.parse(
11+
fs.readFileSync(inputFile, "utf8")
12+
).props;
13+
14+
// Generate code based on output file extension
15+
let output: string;
16+
if (outputFile.endsWith(".sass")) {
17+
output = generateOutput(
18+
tokens,
19+
toSassVarName,
20+
(varName, cssValue) => `$${varName}: ${cssValue}`
21+
);
22+
} else if (outputFile.endsWith(".ts")) {
23+
output = generateOutput(
24+
tokens,
25+
toTsVarName,
26+
(varName, cssValue) => `export const ${varName} = "${cssValue}";`
27+
);
28+
} else {
29+
throw new Error(`can only output .sass and .ts, not ${outputFile}`);
30+
}
31+
32+
// Write output files
33+
fs.writeFileSync(outputFile, output);
34+
console.log(`✅ Generated ${outputFile}`);
35+
}
36+
37+
function generateOutput(
38+
tokens: TheoToken[],
39+
toVarName: (tokenName: string) => string,
40+
toCode: (varName: string, cssValue: string) => string
41+
): string {
42+
return [...Object.entries(groupBy(tokens, (token) => toVarName(token.name)))]
43+
.map(([varName, dupTokens]) => {
44+
const code = toCode(varName, dupTokens[0].value);
45+
if (dupTokens.length === 1) {
46+
return code;
47+
} else {
48+
console.warn(`Token "${varName}" has ${dupTokens.length} duplicates`);
49+
return code + ` // WARNING: ${dupTokens.length} duplicates`;
50+
}
51+
})
52+
.map((line) => line + "\n")
53+
.join("");
54+
}
55+
56+
function toSassVarName(str: string): string {
57+
return str
58+
.replace(/([a-z])([A-Z])/g, "$1-$2") // Add hyphens between camelCase
59+
.replace(/[^a-zA-Z0-9]+/g, "-")
60+
.toLowerCase();
61+
}
62+
63+
function toTsVarName(str: string): string {
64+
// First convert to kebab style to normalize
65+
const kebab = toSassVarName(str);
66+
67+
// Then convert to camelCase, handling numbers properly
68+
return kebab.replace(/-([a-z0-9])/gi, (_, char) => char.toUpperCase());
69+
}
70+
71+
main();

platform/wab/tools/import-chains.bash

-17
This file was deleted.

platform/wab/tools/import-chains.ts

-120
This file was deleted.

0 commit comments

Comments
 (0)