Repository navigation
fix(scripts): fix escaping and shell commands - #560
Conversation
Escape backslashes before backticks when writing generated CSS into a
template literal, and also escape `${`. The old order turned a backtick
into two backslashes and a bare backtick, which ended the literal.
Run the build commands without a shell, so that a checkout path with a
space or a shell metacharacter no longer breaks the build or runs as a
command.
Closes #558
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_011FSoqMUX3EU35poH13xMgG
Reviewer's GuideHardens the build scripts by using argument-safe process execution and fixes template-literal escaping through a shared, tested utility, while extending CI to run the new utility tests; generated styles are intended to remain byte-identical. Sequence diagram for argument-safe build command executionsequenceDiagram
participant Build as scripts/build.js
participant Node as process.execPath
participant Metadata as make-metadata.js
participant CEM as custom-elements-manifest
participant TSC as tsc
Build->>Node: execFileSync(make-CEMconfig.js)
Build->>Node: execFileSync(make-metadata.js, --outdir, dir)
Node->>Metadata: Run with argument list
Metadata->>CEM: execFileSync(analyze, --litelement, --outdir, outdir)
Build->>Node: execFileSync(make-react.js, -p, prefix)
Build->>TSC: execFileSync(--project, --outdir, npmDir)
Sequence diagram for safe Tailwind style generationsequenceDiagram
participant Tailwind as scripts/tailwind/index.js
participant Npx as npx
participant CSS as Generated CSS file
participant Utils as escapeTemplateLiteral
participant TS as tw-styles.ts
Tailwind->>Npx: execFileSync(@tailwindcss/cli, -i, configPath, -o, componentCssPath)
Npx->>CSS: Write CSS
Tailwind->>CSS: readFileSync(componentCssPath, utf8)
Tailwind->>Utils: escapeTemplateLiteral(text)
Utils-->>Tailwind: Escaped backslashes, backticks, and ${
Tailwind->>TS: Write CSS inside Lit template
Flow diagram for script test coverage in CIflowchart LR
Lint[Lint job] --> Tests[node --test]
Tests --> Release[release.test.js]
Tests --> Utils[utils.test.js]
Utils --> Escape[escapeTemplateLiteral]
Escape --> Verify[Original text preserved]
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #560 +/- ##
=======================================
Coverage 70.89% 70.89%
=======================================
Files 23 23
Lines 5638 5638
Branches 190 190
=======================================
Hits 3997 3997
Misses 1636 1636
Partials 5 5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Hey - I've found 1 issue
Fixed security issues:
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="scripts/tailwind/index.js" line_range="168" />
<code_context>
- execSync(
- `npx @tailwindcss/cli -i ${configPath} -o ${componentCssPath}`,
+ execFileSync(
+ "npx",
+ ["@tailwindcss/cli", "-i", configPath, "-o", componentCssPath],
{
</code_context>
<issue_to_address>
**Build exits on Windows**
When the build runs on Windows and these CLIs resolve to `.cmd` shims, `execFileSync` cannot launch the `npx`, `tsc`, or `custom-elements-manifest` shims without a shell, so the first affected command fails and aborts the build.
Run these commands in a way that supports Windows `.cmd` shims, such as enabling a shell.
Also at `scripts/make-metadata.js:12-15`, `scripts/build.js:105-111`.
</issue_to_address>Linked issues
#558 fix(scripts): fix escaping and shell commands · 3 of 3 met
| # | Requirement | Status | Notes |
|---|---|---|---|
| 1 | Escape generated CSS correctly in a tested helper, including backticks and ${. |
✅ Met | The helper escapes backslashes first, then backticks and ${; tests check the escaped text evaluates to its original value. |
| 2 | Run build and Tailwind commands without a shell so paths with spaces or shell metacharacters are safe. | ✅ Met | The affected commands use execFileSync with separate arguments; the Tailwind watch path uses spawn with an argument array. |
| 3 | Keep generated styles byte-identical. | ✅ Met | The PR reports that all 28 generated tw-styles.ts files matched a baseline build of dev. |
Sourcery assessment
Approval pending. 1 finding to address first.
Blocking findings: scripts/tailwind/index.js:168
Summary
Fixes the CodeQL findings in the build scripts (alerts 1 to 7). No component code changes: the generated styles stay byte-identical.
js/double-escaping):escapeTemplateLiteralinscripts/utils.jsescapes backslashes first, then backticks and${. The old order turned a backtick into two backslashes and a bare backtick, which ended the template literal.scripts/tailwind/index.jsnow uses the helper in all three places.js/shell-command-injection-from-environment):scripts/build.js,scripts/tailwind/index.jsandscripts/make-metadata.jsrun their commands withexecFileSyncand an argument list. Thetscandmake-metadata.jscalls weren't flagged, but they are converted too, so that no shell string is left in the build.Lintjob's script test step also runsscripts/utils.test.js, and is now called "Test the scripts".How it was verified
node --test scripts/release.test.js scripts/utils.test.js: 27 of 27 pass. The new tests failed before the fix.npm run build -- --force: all 9 tasks pass.tw-styles.tsfiles are byte-identical to a baseline build ofdev.node "<dir with a space>/scripts/build.js"failed withCannot find module '.../sp'. It now builds the package.scripts/tailwind/index.jsalso works in a package directory with a space, with the same output.Declined review findings
execFileSyncwithout a shell can't start the.cmdshims ofnpx,tscandcustom-elements-manifest, so building on Windows would stop working. The repository doesn't document Windows support, CI runs only on Linux, thecleanscripts userm -rf, and the watch mode'sspawn("npx", ...)already has this limit.devand the three copies differ in whitespace, so merging them would change the output in watch mode. Out of scope here.commanderOpts.prefix: kept on purpose. It makes explicit that a missing prefix stays the literal stringundefined, whichmake-react.jshandles.for...ofwith messages, atest:scriptsnpm script, carriage returns in the helper's comment: minor.assert.strictEqualalready shows the failing input, and the old code handled carriage returns the same way.Closes #558
🤖 Generated with Claude Code
https://claude.ai/code/session_011FSoqMUX3EU35poH13xMgG
Summary by Sourcery
Harden build-time scripts against command injection and invalid template-literal escaping while preserving generated styles.
Bug Fixes:
Enhancements:
CI:
Tests: