question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Use "Yaml", "Toml" or "JS" instead of "JSON" for Nx related files

See original GitHub issue

Description

The basic idea, behind it is, JSON, is not suited for configuration files. Personally, I like Yaml, TOML, but JS is a very nice alternative as well. There are a number of guides that describe why JSON isn’t a very good candidate for configuration files, but here are the top issues for me:

  • Too much noise, especially in long JSON Files, makes it hard to find the information you want.
  • Cannot handle Long String and different types of Numbers properly.
  • Lack of programmatic nature. Can be extremely useful for configuration files.

It is also, a step towards other projects allowing more than JSON for their configs. ESLint, and Prettier use all of the above options. It would be good if Nx allowed it as well.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:12
  • Comments:5

github_iconTop GitHub Comments

1reaction
maxisamcommented, Jun 4, 2021

one big issue is we can’t use comments in JSON. There are workaround but I think we should move to yaml. I think yaml is the choice for configuration file now after k8s is getting popular.

1reaction
kenptrcommented, Mar 19, 2021

I also recommend https://jsonnet.org/, which adds tons of useful features to JSON: functions, imports, conditionals, etc.

It would allow creating helper functions, so the config like this:

  "project": {
    "servak": {
      "root": "apps/servak",
      "sourceRoot": "apps/servak/src",
      "projectType": "application",
      "prefix": "servak",
      "targets": {
        "build": {
          "executor": "@nrwl/node:build",
          "outputs": ["{options.outputPath}"],
          "options": {
            "outputPath": "dist/apps/servak",
            "main": "apps/servak/src/main.ts",
            "tsConfig": "apps/servak/tsconfig.app.json",
            "assets": ["apps/servak/src/assets", "apps/servak/src/views"],
            "webpackConfig": "tools/webpack/servak_config.js"
          },
          "configurations": {
            "production": {
              "optimization": true,
              "extractLicenses": true,
              "inspect": false,
              "fileReplacements": [
                {
                  "replace": "apps/servak/src/environments/environment.ts",
                  "with": "apps/servak/src/environments/environment.prod.ts"
                }
              ]
            }
          }
        },
        "serve": {
          "executor": "@nrwl/node:execute",
          "options": {
            "buildTarget": "servak:build",
            "waitUntilTargets": ["iibutton:build"]
          }
        },
        "lint": {
          "executor": "@nrwl/linter:eslint",
          "options": {
            "lintFilePatterns": ["apps/servak/**/*.ts"]
          }
        },
        "test": {
          "executor": "@nrwl/jest:jest",
          "outputs": ["coverage/apps/servak"],
          "options": {
            "jestConfig": "apps/servak/jest.config.js",
            "passWithNoTests": true
          }
        },
        "version": {
          "executor": "@jscutlery/semver:version",
          "options": {
            "syncVersions": false
          }
        }
      }
    }
}}

will become

local NodeProject(opts) = { ... }; // will contain default project configs as above

projects: {
  servak: NodeProject({
    name: "servak",
    target: {
      options: {
          webpackConfig: "tools/webpack/servak_config.js"
      }
    }
  })
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

JSON vs XML vs TOML vs CSON vs YAML - Zion & Zion
Here's the ultimate breakdown: If you are writing code for other code to read, use YAML. If you are writing code that writes...
Read more >
JSON vs. YAML vs. TOML - Martin Ueding
There are a bunch of data formats which can store structured data. The most popular seem to be JSON and YAML. A relatively...
Read more >
YAML vs JSON – Which is better? - Linux Hint
YAML is an abbreviation of Yet Another Markup Language and is used to define configurations. It is lightweight and represents data in a...
Read more >
How to create Kubernetes YAML files | by Piotr - ITNEXT
It is relatively straightforward to create a simple YAML file, but for production use, many more settings are required.
Read more >
Dockerizing a Node.js Web Application - Semaphore Tutorial
json file that pm2 can use to run our application in production. $ npm install --save pm2. To make it easier to run...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found