Среда выполнения JavaScript
Установленные пакеты
.bin - "бинарные" файлы. Выполняемые не через node
npx tsc - ищет вначале в node_modules/.bin
Информация о проекте (пакете)
| Code status | Stage | Rule | Example version |
|---|---|---|---|
| First release | New product | Start with 1.0.0 | 1.0.0 |
| Backward compatible bug fixes | Patch release | Increment the third digit | 1.0.1 |
| Backward compatible new features | Minor release | Increment the middle digit and reset last digit to zero | 1.1.0 |
| Changes that break backward compatibility | Major release | Increment the first digit and reset middle and last digits to zero | 2.0.0 |
// 1_0_0
class Engine {}
class Car {
async start(): Promise<Engine> {
return new Engine()
}
}
// 2_0_0
class Engine {}
class Car {
async start(): Promise<void> {
// some code
}
}// 1_0_0
class Engine {}
class Car {
async start(): Promise<Engine> {
return new Engine()
}
}
// 1_1_0
class Engine {}
class Car {
async start(): Promise<Engine> {
return new Engine()
}
async stop(): Promise<void>{}
}{
"dependencies": {
"my_dep": "^1.0.0", // < 2.0.0
"another_dep": "~2.2.0" // < 2.3.0
}
}
bundleDependencies - npm pack
npm i typescript -D
npm i commander
npm uninstall commander
npm i jest --no-save
npm cinpm init -y
// CJS
const { Console } = require('node:console');
// ESM
import { Console } from 'node:console';
Common JS - поставляет 2 глобальных объекта - require и module.exports
Постепенно умирает
// a.js
class Parrot {
say(){
console.log('Im parrot!')
}
}
module.exports = { Parrot: Parrot }
// index.js
const { Parrot } = require('./a.js')
const myParrot = new Parrot()
myParrot.say() // Im parrot!
// a.js
class Parrot {
say(){
console.log('Im parrot!')
}
}
exports = Parrot
// index.js
const Parrot = require('./a.js')
const myParrot = new Parrot()
myParrot.say() // Im parrot!
(function(exports, require, module, __filename, __dirname) {
class Parrot { }
/** rest code */
});
npmjs - package.json
github - ajv-ts
npmjs - bundleDependencies
nodejs - cjs modules