Primeiro commit do projeto Angular
This commit is contained in:
+27
@@ -0,0 +1,27 @@
|
||||
Copyright (c) Robert Kowalski and Isaac Z. Schlueter ("Authors")
|
||||
All rights reserved.
|
||||
|
||||
The BSD License
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS
|
||||
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
# npm-install-checks
|
||||
|
||||
Check the engines and platform fields in package.json
|
||||
|
||||
## API
|
||||
|
||||
Both functions will throw an error if the check fails, or return
|
||||
`undefined` if everything is ok.
|
||||
|
||||
Errors have a `required` and `current` fields.
|
||||
|
||||
### .checkEngine(pkg, npmVer, nodeVer, force = false)
|
||||
|
||||
Check if a package's `engines.node` and `engines.npm` match the running system.
|
||||
|
||||
`force` argument will override the node version check, but not the npm
|
||||
version check, as this typically would indicate that the current version of
|
||||
npm is unable to install the package properly for some reason.
|
||||
|
||||
Error code: 'EBADENGINE'
|
||||
|
||||
### .checkPlatform(pkg, force, environment)
|
||||
|
||||
Check if a package's `os`, `cpu` and `libc` match the running system.
|
||||
|
||||
`force` argument skips all checks.
|
||||
|
||||
`environment` overrides the execution environment which comes from `process.platform` `process.arch` and current `libc` environment by default. `environment.os` `environment.cpu` and `environment.libc` are available.
|
||||
|
||||
Error code: 'EBADPLATFORM'
|
||||
|
||||
|
||||
### .checkDevEngines(wanted, current, opts)
|
||||
|
||||
Check if a package's `devEngines` property matches the current system environment.
|
||||
|
||||
Returns an array of `Error` objects, some of which may be warnings, this can be checked with `.isError` and `.isWarn`. Errors correspond to an error for a given "engine" failure, reasons for each engine "dependency" failure can be found within `.errors`.
|
||||
+91
@@ -0,0 +1,91 @@
|
||||
const process = require('node:process')
|
||||
const nodeOs = require('node:os')
|
||||
const fs = require('node:fs')
|
||||
|
||||
function isMusl (file) {
|
||||
return file.includes('libc.musl-') || file.includes('ld-musl-')
|
||||
}
|
||||
|
||||
function os () {
|
||||
return process.platform
|
||||
}
|
||||
|
||||
function cpu () {
|
||||
return process.arch
|
||||
}
|
||||
|
||||
const LDD_PATH = '/usr/bin/ldd'
|
||||
function getFamilyFromFilesystem () {
|
||||
try {
|
||||
const content = fs.readFileSync(LDD_PATH, 'utf-8')
|
||||
if (content.includes('musl')) {
|
||||
return 'musl'
|
||||
}
|
||||
if (content.includes('GNU C Library')) {
|
||||
return 'glibc'
|
||||
}
|
||||
return null
|
||||
} catch {
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
|
||||
function getFamilyFromReport () {
|
||||
const originalExclude = process.report.excludeNetwork
|
||||
process.report.excludeNetwork = true
|
||||
const report = process.report.getReport()
|
||||
process.report.excludeNetwork = originalExclude
|
||||
if (report.header?.glibcVersionRuntime) {
|
||||
family = 'glibc'
|
||||
} else if (Array.isArray(report.sharedObjects) && report.sharedObjects.some(isMusl)) {
|
||||
family = 'musl'
|
||||
} else {
|
||||
family = null
|
||||
}
|
||||
return family
|
||||
}
|
||||
|
||||
let family
|
||||
function libc (osName) {
|
||||
if (osName !== 'linux') {
|
||||
return undefined
|
||||
}
|
||||
if (family === undefined) {
|
||||
family = getFamilyFromFilesystem()
|
||||
if (family === undefined) {
|
||||
family = getFamilyFromReport()
|
||||
}
|
||||
}
|
||||
return family
|
||||
}
|
||||
|
||||
function devEngines (env = {}) {
|
||||
const osName = env.os || os()
|
||||
return {
|
||||
cpu: {
|
||||
name: env.cpu || cpu(),
|
||||
},
|
||||
libc: {
|
||||
name: env.libc || libc(osName),
|
||||
},
|
||||
os: {
|
||||
name: osName,
|
||||
version: env.osVersion || nodeOs.release(),
|
||||
},
|
||||
packageManager: {
|
||||
name: 'npm',
|
||||
version: env.npmVersion,
|
||||
},
|
||||
runtime: {
|
||||
name: 'node',
|
||||
version: env.nodeVersion || process.version,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
cpu,
|
||||
libc,
|
||||
os,
|
||||
devEngines,
|
||||
}
|
||||
+145
@@ -0,0 +1,145 @@
|
||||
const satisfies = require('semver/functions/satisfies')
|
||||
const validRange = require('semver/ranges/valid')
|
||||
|
||||
const recognizedOnFail = [
|
||||
'ignore',
|
||||
'warn',
|
||||
'error',
|
||||
'download',
|
||||
]
|
||||
|
||||
const recognizedProperties = [
|
||||
'name',
|
||||
'version',
|
||||
'onFail',
|
||||
]
|
||||
|
||||
const recognizedEngines = [
|
||||
'packageManager',
|
||||
'runtime',
|
||||
'cpu',
|
||||
'libc',
|
||||
'os',
|
||||
]
|
||||
|
||||
/** checks a devEngine dependency */
|
||||
function checkDependency (wanted, current, opts) {
|
||||
const { engine } = opts
|
||||
|
||||
if ((typeof wanted !== 'object' || wanted === null) || Array.isArray(wanted)) {
|
||||
throw new Error(`Invalid non-object value for "${engine}"`)
|
||||
}
|
||||
|
||||
const properties = Object.keys(wanted)
|
||||
|
||||
for (const prop of properties) {
|
||||
if (!recognizedProperties.includes(prop)) {
|
||||
throw new Error(`Invalid property "${prop}" for "${engine}"`)
|
||||
}
|
||||
}
|
||||
|
||||
if (!properties.includes('name')) {
|
||||
throw new Error(`Missing "name" property for "${engine}"`)
|
||||
}
|
||||
|
||||
if (typeof wanted.name !== 'string') {
|
||||
throw new Error(`Invalid non-string value for "name" within "${engine}"`)
|
||||
}
|
||||
|
||||
if (typeof current.name !== 'string' || current.name === '') {
|
||||
throw new Error(`Unable to determine "name" for "${engine}"`)
|
||||
}
|
||||
|
||||
if (properties.includes('onFail')) {
|
||||
if (typeof wanted.onFail !== 'string') {
|
||||
throw new Error(`Invalid non-string value for "onFail" within "${engine}"`)
|
||||
}
|
||||
if (!recognizedOnFail.includes(wanted.onFail)) {
|
||||
throw new Error(`Invalid onFail value "${wanted.onFail}" for "${engine}"`)
|
||||
}
|
||||
}
|
||||
|
||||
if (wanted.name !== current.name) {
|
||||
return new Error(
|
||||
`Invalid name "${wanted.name}" does not match "${current.name}" for "${engine}"`
|
||||
)
|
||||
}
|
||||
|
||||
if (properties.includes('version')) {
|
||||
if (typeof wanted.version !== 'string') {
|
||||
throw new Error(`Invalid non-string value for "version" within "${engine}"`)
|
||||
}
|
||||
if (typeof current.version !== 'string' || current.version === '') {
|
||||
throw new Error(`Unable to determine "version" for "${engine}" "${wanted.name}"`)
|
||||
}
|
||||
if (validRange(wanted.version)) {
|
||||
if (!satisfies(current.version, wanted.version, opts.semver)) {
|
||||
return new Error(
|
||||
// eslint-disable-next-line max-len
|
||||
`Invalid semver version "${wanted.version}" does not match "${current.version}" for "${engine}"`
|
||||
)
|
||||
}
|
||||
} else if (wanted.version !== current.version) {
|
||||
return new Error(
|
||||
`Invalid version "${wanted.version}" does not match "${current.version}" for "${engine}"`
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** checks devEngines package property and returns array of warnings / errors */
|
||||
function checkDevEngines (wanted, current = {}, opts = {}) {
|
||||
if ((typeof wanted !== 'object' || wanted === null) || Array.isArray(wanted)) {
|
||||
throw new Error(`Invalid non-object value for "devEngines"`)
|
||||
}
|
||||
|
||||
const errors = []
|
||||
|
||||
for (const engine of Object.keys(wanted)) {
|
||||
if (!recognizedEngines.includes(engine)) {
|
||||
throw new Error(`Invalid property "devEngines.${engine}"`)
|
||||
}
|
||||
const dependencyAsAuthored = wanted[engine]
|
||||
const dependencies = [dependencyAsAuthored].flat()
|
||||
const currentEngine = current[engine] || {}
|
||||
|
||||
// this accounts for empty array eg { runtime: [] } and ignores it
|
||||
if (dependencies.length === 0) {
|
||||
continue
|
||||
}
|
||||
|
||||
const depErrors = []
|
||||
for (const dep of dependencies) {
|
||||
const result = checkDependency(dep, currentEngine, { ...opts, engine })
|
||||
if (result) {
|
||||
depErrors.push(result)
|
||||
}
|
||||
}
|
||||
|
||||
const invalid = depErrors.length === dependencies.length
|
||||
|
||||
if (invalid) {
|
||||
const lastDependency = dependencies[dependencies.length - 1]
|
||||
let onFail = lastDependency.onFail || 'error'
|
||||
if (onFail === 'download') {
|
||||
onFail = 'error'
|
||||
}
|
||||
|
||||
const err = Object.assign(new Error(`Invalid devEngines.${engine}`), {
|
||||
errors: depErrors,
|
||||
engine,
|
||||
isWarn: onFail === 'warn',
|
||||
isError: onFail === 'error',
|
||||
current: currentEngine,
|
||||
required: dependencyAsAuthored,
|
||||
})
|
||||
|
||||
errors.push(err)
|
||||
}
|
||||
}
|
||||
return errors
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
checkDevEngines,
|
||||
}
|
||||
+90
@@ -0,0 +1,90 @@
|
||||
const semver = require('semver')
|
||||
const currentEnv = require('./current-env')
|
||||
const { checkDevEngines } = require('./dev-engines')
|
||||
|
||||
const checkEngine = (target, npmVer, nodeVer, force = false) => {
|
||||
const nodev = force ? null : nodeVer
|
||||
const eng = target.engines
|
||||
const opt = { includePrerelease: true }
|
||||
if (!eng) {
|
||||
return
|
||||
}
|
||||
|
||||
const nodeFail = nodev && eng.node && !semver.satisfies(nodev, eng.node, opt)
|
||||
const npmFail = npmVer && eng.npm && !semver.satisfies(npmVer, eng.npm, opt)
|
||||
if (nodeFail || npmFail) {
|
||||
throw Object.assign(new Error('Unsupported engine'), {
|
||||
pkgid: target._id,
|
||||
current: { node: nodeVer, npm: npmVer },
|
||||
required: eng,
|
||||
code: 'EBADENGINE',
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
const checkPlatform = (target, force = false, environment = {}) => {
|
||||
if (force) {
|
||||
return
|
||||
}
|
||||
|
||||
const os = environment.os || currentEnv.os()
|
||||
const cpu = environment.cpu || currentEnv.cpu()
|
||||
const libc = environment.libc || currentEnv.libc(os)
|
||||
|
||||
const osOk = target.os ? checkList(os, target.os) : true
|
||||
const cpuOk = target.cpu ? checkList(cpu, target.cpu) : true
|
||||
let libcOk = target.libc ? checkList(libc, target.libc) : true
|
||||
if (target.libc && !libc) {
|
||||
libcOk = false
|
||||
}
|
||||
|
||||
if (!osOk || !cpuOk || !libcOk) {
|
||||
throw Object.assign(new Error('Unsupported platform'), {
|
||||
pkgid: target._id,
|
||||
current: {
|
||||
os,
|
||||
cpu,
|
||||
libc,
|
||||
},
|
||||
required: {
|
||||
os: target.os,
|
||||
cpu: target.cpu,
|
||||
libc: target.libc,
|
||||
},
|
||||
code: 'EBADPLATFORM',
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
const checkList = (value, list) => {
|
||||
if (typeof list === 'string') {
|
||||
list = [list]
|
||||
}
|
||||
if (list.length === 1 && list[0] === 'any') {
|
||||
return true
|
||||
}
|
||||
// match none of the negated values, and at least one of the
|
||||
// non-negated values, if any are present.
|
||||
let negated = 0
|
||||
let match = false
|
||||
for (const entry of list) {
|
||||
const negate = entry.charAt(0) === '!'
|
||||
const test = negate ? entry.slice(1) : entry
|
||||
if (negate) {
|
||||
negated++
|
||||
if (value === test) {
|
||||
return false
|
||||
}
|
||||
} else {
|
||||
match = match || value === test
|
||||
}
|
||||
}
|
||||
return match || negated === list.length
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
checkEngine,
|
||||
checkPlatform,
|
||||
checkDevEngines,
|
||||
currentEnv,
|
||||
}
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
{
|
||||
"name": "npm-install-checks",
|
||||
"version": "8.0.0",
|
||||
"description": "Check the engines and platform fields in package.json",
|
||||
"main": "lib/index.js",
|
||||
"dependencies": {
|
||||
"semver": "^7.1.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@npmcli/eslint-config": "^5.0.0",
|
||||
"@npmcli/template-oss": "4.27.1",
|
||||
"tap": "^16.0.1"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "tap",
|
||||
"lint": "npm run eslint",
|
||||
"postlint": "template-oss-check",
|
||||
"template-oss-apply": "template-oss-apply --force",
|
||||
"lintfix": "npm run eslint -- --fix",
|
||||
"snap": "tap",
|
||||
"posttest": "npm run lint",
|
||||
"eslint": "eslint \"**/*.{js,cjs,ts,mjs,jsx,tsx}\""
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/npm/npm-install-checks.git"
|
||||
},
|
||||
"keywords": [
|
||||
"npm,",
|
||||
"install"
|
||||
],
|
||||
"license": "BSD-2-Clause",
|
||||
"files": [
|
||||
"bin/",
|
||||
"lib/"
|
||||
],
|
||||
"engines": {
|
||||
"node": "^20.17.0 || >=22.9.0"
|
||||
},
|
||||
"author": "GitHub Inc.",
|
||||
"templateOSS": {
|
||||
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
|
||||
"version": "4.27.1",
|
||||
"publish": "true"
|
||||
},
|
||||
"tap": {
|
||||
"nyc-arg": [
|
||||
"--exclude",
|
||||
"tap-snapshots/**"
|
||||
]
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user