Tooling: npm, linting and formatting

This part of the JavaScript course is about the tools around a project: a package is described by package.json, and npm reads it, the fields that decide the module system and the entry point, the scripts that wrap a build, and the version ranges of the dependencies with the lockfile that pins them. The module resolution then explains which file a require or an import finds. ESLint and its flat config report a rule, a fix repairs part of the report, and Prettier settles the formatting while EditorConfig keeps the files consistent. One script runs lint, format and test together, and the part ends with the bin field, npx and the files a published package ships.

11.1 package.json: the fields that matter npm init -y and the file it writes, name and version, type that chooses the module system, main that names the entry, and scripts read by a program Open 11.2 npm scripts: run, pre and post the scripts table and npm run, pre and post names around a build, the shortcuts that skip run, arguments after two dashes, and the exit status Open 11.3 Dependencies and version ranges dependencies against devDependencies, the caret and tilde expanded by semver, the tree of npm ls, and the three versions of npm outdated Open 11.4 Lockfiles and npm ci the lock entry with its version and integrity hash, why it is committed, npm ci in a fresh copy, and the error of a lock out of sync with the manifest Open 11.5 How a module is found: node_modules, main and exports the node_modules lookup from the calling file upward, main and index.js for a folder, the exports map that closes subpaths, and MODULE_NOT_FOUND Open 11.6 ESLint and the flat config the install of ESLint and @eslint/js, eslint.config.js with the recommended rules, ecmaVersion and sourceType, a silent clean run, and one rule that fires Open 11.7 Reading and fixing lint errors a report read as line, column, rule and message, three rules added to the config, what --fix repairs, and the two problems it leaves to a person Open 11.8 Prettier: check and write prettier --check with its list and its status, --write with the silenced log, the formatted file, and the split from ESLint on the same two files Open 11.9 EditorConfig and consistency one .editorconfig for line endings, indentation and the final newline, a checker that reads it, CRLF counted as bytes, and Prettier as the repair Open 11.10 All the checks in one script lint, format and test joined by &&, the two lines of a passing run, the status of a run that stops, and a runner that reports a table of every step Open 11.11 The bin field and npx a package that ships a command, the shebang, the link in node_modules/.bin, the file: dependency from a folder, npx --no-install, and the three exit codes Open 11.12 What a package ships: npm pack and the files list npm pack --dry-run --json read by a program, the files whitelist and the entry that ships anyway, .npmignore with its fixed rules, and the tarball listing Open

Lessons