📦 Reading JSON Config
5 exercises — read real package.json and tsconfig.json files. Understand scripts, dependencies vs devDependencies, semver ranges (^/~) and compilerOptions.
JSON config quick reference
scripts→ command shortcuts run vianpm run <name>dependencies= runtime ·devDependencies= build/test only^1.2.3→ minor + patch ·~1.2.3→ patch only ·1.2.3→ exactcompilerOptions→ how TypeScript type-checks and emits&&in a script → run next command only if the first succeeds
0 / 5 completed
1 / 5
package.json
{
"name": "checkout-service",
"version": "2.1.0",
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"test": "vitest run",
"lint": "eslint ."
},
"dependencies": {
"react": "^18.2.0",
"zod": "~3.22.4"
},
"devDependencies": {
"typescript": "5.4.5",
"vitest": "^1.5.0",
"eslint": "^8.57.0"
}
} In the
scripts block, what does "build": "tsc && vite build" do when you run npm run build?&& chains commands sequentially, gated on success.The value of a script is a shell command line.
tsc && vite build uses the shell's logical-AND operator:- First run
tsc(the TypeScript compiler / type-check). - Only if it exits with code
0(success) doesvite buildrun. - If
tscreports a type error and exits non-zero, the build stops andvite buildnever runs.
|| runs the second command only if the first fails; a single ; runs both regardless. So && is the "fail fast" pattern — don't bundle broken code.You invoke any script with
npm run <name> (dev, test, lint...). The names are arbitrary labels you define.Collocations: "an npm script", "the build step", "chain commands", "fail fast", "exit code zero".