fix(lit): make copy-spec script cross-platform compatible #389
+35
−4
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Objective: Resolve build failures on Windows operating systems caused by Unix-specific shell commands in the copy-spec script.
1. The Problem
The original
package.jsonscript forcopy-specrelied on shell commands that are native to Linux and macOS but incompatible with the standard Windows Command Prompt (cmd.exe):mkdir -p: The-pflag (create parent directories) is not supported by the Windowsmkdircommand.cp: This is a Unix copy command; Windows usescopyorxcopy.Original Code (Fails on Windows):
2. The Solution
We replaced the platform-dependent shell commands with a Node.js script. Since Node.js is already a requirement for the project, using its built-in
fs(File System) module allows us to perform file operations that work identically on Windows, Linux, and macOS.3. Implementation Details
A. Created
scripts/copy-spec.jsWe added a new script that handles the logic programmatically:
path.resolveto correctly locate the source (../../specification/0.8/json) and destination (src/0.8/schemas) directories relative to the script location, ensuring path separators (/vs\) are handled correctly for the OS.fs.mkdirSync(destDir, { recursive: true }). Therecursive: trueoption is the cross-platform equivalent ofmkdir -p.fs.copyFileSyncto copy them one by one.B. Updated
package.jsonWe modified the
copy-specentry inpackage.jsonto execute this new script using thenoderuntime.New Code (Works Everywhere):
4. Key Benefits