Skip to content
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

yaml parse and stringfy can not reproduce the source yaml content #599

Open
ZhouLihua opened this issue Jan 7, 2025 · 1 comment
Open

Comments

@ZhouLihua
Copy link

ZhouLihua commented Jan 7, 2025

Describe the bug
yaml different version parse and stringfy output is different and also different from the source yaml file.

To Reproduce
0. my source yaml file content is.

---
name: lichtblick
description: Install Lichtblick
platform: Linux
schemaVersion: 1.0
parameters:
  - user:
      type: string
      default: ubuntu
      
phases:
  - name: build
    steps:
      - name: InstallRequiredDependencies
        action: ExecuteBash
        inputs:
          commands:
            - |
              set -e
              curl -fsSL https://deb.nodesource.com/setup_20.x | sudo bash
              sudo apt update -y nodejs
              sudo corepack enable
              curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | sudo bash
              sudo apt install -y git-lfs
              git lfs install
              git lfs pull

      - name: BuildLichtblick
        action: ExecuteBash
        inputs:
          commands:
            - |
              set -e
              git clone https://github.com/lichtblick-suite/lichtblick.git --depth=1
              cd lichtblick
              export COREPACK_ENABLE_DOWNLOAD_PROMPT=0
              yarn install -y
              yarn run desktop:build:prod
              yarn run package:linux
              ls -al ./dist
      - name: InstallLichtblick
        action: ExecuteBash
        inputs:
          commands:
            - |
              set -e
              sudo apt install libasound2 -y
              sudo apt install -y ./dist/lichtblick-1.7.12-linux-amd64.deb
      - name: CleanUp
        action: ExecuteBash
        inputs:
          commands:
            - |
              set -e
              cd ~
              rm -rf lichtblick/

  1. npm install [email protected], and run below js code.
import { readFileSync } from "fs";
import { parse, stringify } from "yaml";

const content = parse(readFileSync("./1.0.0.yml", "utf8"));
console.log(stringify(content));

output is

name: lichtblick
description: Install Lichtblick
platform: Linux
schemaVersion: 1
parameters:
  - user:
      type: string
      default: ubuntu
phases:
  - name: build
    steps:
      - name: InstallRequiredDependencies
        action: ExecuteBash
        inputs:
          commands:
            - >
              set -e

              curl -fsSL https://deb.nodesource.com/setup_20.x | sudo bash

              sudo apt update -y nodejs

              sudo corepack enable

              curl -s
              https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh
              | sudo bash

              sudo apt install -y git-lfs

              git lfs install

              git lfs pull
      - name: BuildLichtblick
        action: ExecuteBash
        inputs:
          commands:
            - >
              set -e

              git clone https://github.com/lichtblick-suite/lichtblick.git
              --depth=1

              cd lichtblick

              export COREPACK_ENABLE_DOWNLOAD_PROMPT=0

              yarn install -y

              yarn run desktop:build:prod

              yarn run package:linux

              ls -al ./dist
      - name: InstallLichtblick
        action: ExecuteBash
        inputs:
          commands:
            - |
              set -e
              sudo apt install libasound2 -y
              sudo apt install -y ./dist/lichtblick-1.7.12-linux-amd64.deb
      - name: CleanUp
        action: ExecuteBash
        inputs:
          commands:
            - |
              set -e
              cd ~
              rm -rf lichtblick/
  1. npm install [email protected], and the same js code.
    output is
name: lichtblick
description: Install Lichtblick
platform: Linux
schemaVersion: 1
parameters:
  - user:
      type: string
      default: ubuntu
phases:
  - name: build
    steps:
      - name: InstallRequiredDependencies
        action: ExecuteBash
        inputs:
          commands:
            - |
              set -e
              curl -fsSL https://deb.nodesource.com/setup_20.x | sudo bash
              sudo apt update -y nodejs
              sudo corepack enable
              curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | sudo bash
              sudo apt install -y git-lfs
              git lfs install
              git lfs pull
      - name: BuildLichtblick
        action: ExecuteBash
        inputs:
          commands:
            - >
              set -e

              git clone https://github.com/lichtblick-suite/lichtblick.git
              --depth=1

              cd lichtblick

              export COREPACK_ENABLE_DOWNLOAD_PROMPT=0

              yarn install -y

              yarn run desktop:build:prod

              yarn run package:linux

              ls -al ./dist
      - name: InstallLichtblick
        action: ExecuteBash
        inputs:
          commands:
            - |
              set -e
              sudo apt install libasound2 -y
              sudo apt install -y ./dist/lichtblick-1.7.12-linux-amd64.deb
      - name: CleanUp
        action: ExecuteBash
        inputs:
          commands:
            - |
              set -e
              cd ~
              rm -rf lichtblick/

Expected behaviour
all two yaml version should return the same content as the source yaml.

Versions (please complete the following information):
[email protected], [email protected]

  • Environment: [e.g. Node.js 14.7.0 or Chrome 87.0]
  • yaml: [e.g. 1.10.0 or 2.0.0-2]

Additional context

@ZhouLihua ZhouLihua added the bug Something isn't working label Jan 7, 2025
@eemeli
Copy link
Owner

eemeli commented Jan 8, 2025

The parse() method does not retain any of the formatting information of the source, only the data. If that's important to you, parseDocument() retains a bit more, but not everything.

This is by design, and is not a bug.

@eemeli eemeli removed the bug Something isn't working label Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants