Skip to content

Fix TypeError for invalid package.json dependencies

Vasilii Iakliushin requested to merge 436953_fix_type_error into master

What does this MR do and why?

Contributes to #436953 (closed)

Problem

Linker expects the dependency files to be valid. However, they are created by users and not guaranteed to have a valid format.

Solution

Explicitly convert dependency values to String object before verification.

Screenshots or screen recordings

Before After
Screenshot_2024-01-02_at_14.13.21 Screenshot_2024-01-02_at_14.13.41

How to set up and validate locally

  1. Create a package.json file in the project with the following content
{
  "name": "module-name",
  "version": "10.3.1",
  "repository": {
    "type": "git",
    "url": "https://github.com/vuejs/vue.git"
  },
  "homepage": "https://github.com/vuejs/vue#readme",
  "scripts": {
    "karma": "karma start config/karma.config.js --single-run"
  },
  "dependencies": {
    "primus": "*",
    "async": "~0.8.0",
    "wrong": {
      "key": "value"
    },
    "express": "4.2.x",
    "bigpipe": "bigpipe/pagelet",
    "plates": "https://github.com/flatiron/plates/tarball/master",
    "karma": "^1.4.1",
    "random": "git+https://EdOverflow@github.com/example/example.git"
  },
  "devDependencies": {
    "vows": "^0.7.0",
    "assume": "<1.0.0 || >=2.3.1 <2.4.5 || >=2.5.2 <3.0.0",
    "pre-commit": "*"
  },
  "license": "MIT"
}
  1. Visit the latest commit page
  2. You should see diffs without any errors

Merge request reports