node_modules

This commit is contained in:
saeid
2019-07-15 13:07:31 +04:30
parent d3735c6d30
commit ce1a3ebf9c
35713 changed files with 3639219 additions and 1 deletions
+12
View File
@@ -0,0 +1,12 @@
module.exports = function silence (logName, exports) {
const logs = {}
Object.keys(exports).forEach(key => {
if (key !== 'error') {
exports[key] = (...args) => {
if (!logs[key]) logs[key] = []
logs[key].push(args)
}
}
})
exports[logName] = logs
}
+83
View File
@@ -0,0 +1,83 @@
const { execSync } = require('child_process')
const fs = require('fs')
const path = require('path')
const LRU = require('lru-cache')
let _hasYarn
const _yarnProjects = new LRU({
max: 10,
maxAge: 1000
})
let _hasGit
const _gitProjects = new LRU({
max: 10,
maxAge: 1000
})
// env detection
exports.hasYarn = () => {
if (process.env.VUE_CLI_TEST) {
return true
}
if (_hasYarn != null) {
return _hasYarn
}
try {
execSync('yarnpkg --version', { stdio: 'ignore' })
return (_hasYarn = true)
} catch (e) {
return (_hasYarn = false)
}
}
exports.hasProjectYarn = (cwd) => {
if (_yarnProjects.has(cwd)) {
return checkYarn(_yarnProjects.get(cwd))
}
const lockFile = path.join(cwd, 'yarn.lock')
const result = fs.existsSync(lockFile)
_yarnProjects.set(cwd, result)
return checkYarn(result)
}
function checkYarn (result) {
if (result && !exports.hasYarn()) throw new Error(`The project seems to require yarn but it's not installed.`)
return result
}
exports.hasGit = () => {
if (process.env.VUE_CLI_TEST) {
return true
}
if (_hasGit != null) {
return _hasGit
}
try {
execSync('git --version', { stdio: 'ignore' })
return (_hasGit = true)
} catch (e) {
return (_hasGit = false)
}
}
exports.hasProjectGit = (cwd) => {
if (_gitProjects.has(cwd)) {
return _gitProjects.get(cwd)
}
let result
try {
execSync('git status', { stdio: 'ignore', cwd })
result = true
} catch (e) {
result = false
}
_gitProjects.set(cwd, result)
return result
}
// OS
exports.isWindows = process.platform === 'win32'
exports.isMacintosh = process.platform === 'darwin'
exports.isLinux = process.platform === 'linux'
+9
View File
@@ -0,0 +1,9 @@
exports.exitProcess = !process.env.VUE_CLI_API_MODE && !process.env.VUE_CLI_TEST
exports.exit = function (code) {
if (exports.exitProcess) {
process.exit(code)
} else if (code > 0) {
throw new Error(`Process exited with code ${code}`)
}
}
+142
View File
@@ -0,0 +1,142 @@
const ipc = require('node-ipc')
const DEFAULT_ID = process.env.VUE_CLI_IPC || 'vue-cli'
const DEFAULT_IDLE_TIMEOUT = 3000
const DEFAULT_OPTIONS = {
networkId: DEFAULT_ID,
autoConnect: true,
disconnectOnIdle: false,
idleTimeout: DEFAULT_IDLE_TIMEOUT,
namespaceOnProject: true
}
const PROJECT_ID = process.env.VUE_CLI_PROJECT_ID
exports.IpcMessenger = class IpcMessenger {
constructor (options = {}) {
options = Object.assign({}, DEFAULT_OPTIONS, options)
ipc.config.id = this.id = options.networkId
ipc.config.retry = 1500
ipc.config.silent = true
this.connected = false
this.connecting = false
this.disconnecting = false
this.queue = null
this.options = options
this.listeners = []
this.disconnectTimeout = 15000
this.idleTimer = null
// Prevent forced process exit
// (or else ipc messages may not be sent before kill)
process.exit = code => {
process.exitCode = code
}
this._reset()
}
checkConnection () {
if (!ipc.of[this.id]) {
this.connected = false
}
}
send (data, type = 'message') {
this.checkConnection()
if (this.connected) {
if (this.options.namespaceOnProject && PROJECT_ID) {
data = {
_projectId: PROJECT_ID,
_data: data
}
}
ipc.of[this.id].emit(type, data)
clearTimeout(this.idleTimer)
if (this.options.disconnectOnIdle) {
this.idleTimer = setTimeout(() => {
this.disconnect()
}, this.options.idleTimeout)
}
} else {
this.queue.push(data)
if (this.options.autoConnect && !this.connecting) {
this.connect()
}
}
}
connect () {
this.checkConnection()
if (this.connected || this.connecting) return
this.connecting = true
this.disconnecting = false
ipc.connectTo(this.id, () => {
this.connected = true
this.connecting = false
this.queue && this.queue.forEach(data => this.send(data))
this.queue = null
ipc.of[this.id].on('message', this._onMessage)
})
}
disconnect () {
this.checkConnection()
if (!this.connected || this.disconnecting) return
this.disconnecting = true
this.connecting = false
const ipcTimer = setTimeout(() => {
this._disconnect()
}, this.disconnectTimeout)
this.send({ done: true }, 'ack')
ipc.of[this.id].on('ack', data => {
if (data.ok) {
clearTimeout(ipcTimer)
this._disconnect()
}
})
}
on (listener) {
this.listeners.push(listener)
}
off (listener) {
const index = this.listeners.indexOf(listener)
if (index !== -1) this.listeners.splice(index, 1)
}
_reset () {
this.queue = []
this.connected = false
}
_disconnect () {
this.connected = false
this.disconnecting = false
ipc.disconnect(this.id)
this._reset()
}
_onMessage (data) {
this.listeners.forEach(fn => {
if (this.options.namespaceOnProject && data._projectId) {
if (data._projectId === PROJECT_ID) {
data = data._data
} else {
return
}
}
fn(data)
})
}
}
+16
View File
@@ -0,0 +1,16 @@
const launch = require('launch-editor')
exports.launch = (...args) => {
const file = args[0]
console.log(`Opening ${file}...`)
let cb = args[args.length - 1]
if (typeof cb !== 'function') {
cb = null
}
launch(...args, (fileName, errorMessage) => {
console.error(`Unable to open '${fileName}'`, errorMessage)
console.log(`Try setting the EDITOR env variable. More info: https://github.com/yyx990803/launch-editor`)
if (cb) cb(fileName, errorMessage)
})
}
+72
View File
@@ -0,0 +1,72 @@
const chalk = require('chalk')
const readline = require('readline')
const padStart = require('string.prototype.padstart')
const EventEmitter = require('events')
exports.events = new EventEmitter()
function _log (type, tag, message) {
if (process.env.VUE_CLI_API_MODE && message) {
exports.events.emit('log', {
message,
type,
tag
})
}
}
const format = (label, msg) => {
return msg.split('\n').map((line, i) => {
return i === 0
? `${label} ${line}`
: padStart(line, chalk.reset(label).length)
}).join('\n')
}
const chalkTag = msg => chalk.bgBlackBright.white.dim(` ${msg} `)
exports.log = (msg = '', tag = null) => {
tag ? console.log(format(chalkTag(tag), msg)) : console.log(msg)
_log('log', tag, msg)
}
exports.info = (msg, tag = null) => {
console.log(format(chalk.bgBlue.black(' INFO ') + (tag ? chalkTag(tag) : ''), msg))
_log('info', tag, msg)
}
exports.done = (msg, tag = null) => {
console.log(format(chalk.bgGreen.black(' DONE ') + (tag ? chalkTag(tag) : ''), msg))
_log('done', tag, msg)
}
exports.warn = (msg, tag = null) => {
console.warn(format(chalk.bgYellow.black(' WARN ') + (tag ? chalkTag(tag) : ''), chalk.yellow(msg)))
_log('warn', tag, msg)
}
exports.error = (msg, tag = null) => {
console.error(format(chalk.bgRed(' ERROR ') + (tag ? chalkTag(tag) : ''), chalk.red(msg)))
_log('error', tag, msg)
if (msg instanceof Error) {
console.error(msg.stack)
_log('error', tag, msg.stack)
}
}
exports.clearConsole = title => {
if (process.stdout.isTTY) {
const blank = '\n'.repeat(process.stdout.rows)
console.log(blank)
readline.cursorTo(process.stdout, 0, 0)
readline.clearScreenDown(process.stdout)
if (title) {
console.log(title)
}
}
}
// silent all logs except errors during tests and keep record
if (process.env.VUE_CLI_TEST) {
require('./_silence')('logs', exports)
}
+72
View File
@@ -0,0 +1,72 @@
const semver = require('semver')
function resolveFallback (request, options) {
const Module = require('module')
const isMain = false
const fakeParent = new Module('', null)
const paths = []
for (let i = 0; i < options.paths.length; i++) {
const path = options.paths[i]
fakeParent.paths = Module._nodeModulePaths(path)
const lookupPaths = Module._resolveLookupPaths(request, fakeParent, true)
if (!paths.includes(path)) paths.push(path)
for (let j = 0; j < lookupPaths.length; j++) {
if (!paths.includes(lookupPaths[j])) paths.push(lookupPaths[j])
}
}
const filename = Module._findPath(request, paths, isMain)
if (!filename) {
const err = new Error(`Cannot find module '${request}'`)
err.code = 'MODULE_NOT_FOUND'
throw err
}
return filename
}
const resolve = semver.satisfies(process.version, '>=10.0.0')
? require.resolve
: resolveFallback
exports.resolveModule = function (request, context) {
let resolvedPath
try {
resolvedPath = resolve(request, {
paths: [context]
})
} catch (e) {}
return resolvedPath
}
exports.loadModule = function (request, context, force = false) {
const resolvedPath = exports.resolveModule(request, context)
if (resolvedPath) {
if (force) {
clearRequireCache(resolvedPath)
}
return require(resolvedPath)
}
}
exports.clearModule = function (request, context) {
const resolvedPath = exports.resolveModule(request, context)
if (resolvedPath) {
clearRequireCache(resolvedPath)
}
}
function clearRequireCache (id, map = new Map()) {
const module = require.cache[id]
if (module) {
map.set(id, true)
// Clear children modules
module.children.forEach(child => {
if (!map.get(child.id)) clearRequireCache(child.id, map)
})
delete require.cache[id]
}
}
+49
View File
@@ -0,0 +1,49 @@
exports.set = function (target, path, value) {
const fields = path.split('.')
let obj = target
const l = fields.length
for (let i = 0; i < l - 1; i++) {
const key = fields[i]
if (!obj[key]) {
obj[key] = {}
}
obj = obj[key]
}
obj[fields[l - 1]] = value
}
exports.get = function (target, path) {
const fields = path.split('.')
let obj = target
const l = fields.length
for (let i = 0; i < l - 1; i++) {
const key = fields[i]
if (!obj[key]) {
return undefined
}
obj = obj[key]
}
return obj[fields[l - 1]]
}
exports.unset = function (target, path) {
const fields = path.split('.')
let obj = target
const l = fields.length
const objs = []
for (let i = 0; i < l - 1; i++) {
const key = fields[i]
if (!obj[key]) {
return
}
objs.splice(0, 0, { obj, key, value: obj[key] })
obj = obj[key]
}
delete obj[fields[l - 1]]
// Clear empty objects
for (const { obj, key, value } of objs) {
if (!Object.keys(value).length) {
delete obj[key]
}
}
}
+123
View File
@@ -0,0 +1,123 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file at
* https://github.com/facebookincubator/create-react-app/blob/master/LICENSE
*/
const opn = require('opn')
const execa = require('execa')
const chalk = require('chalk')
const execSync = require('child_process').execSync
// https://github.com/sindresorhus/opn#app
const OSX_CHROME = 'google chrome'
const Actions = Object.freeze({
NONE: 0,
BROWSER: 1,
SCRIPT: 2
})
function getBrowserEnv () {
// Attempt to honor this environment variable.
// It is specific to the operating system.
// See https://github.com/sindresorhus/opn#app for documentation.
const value = process.env.BROWSER
let action
if (!value) {
// Default.
action = Actions.BROWSER
} else if (value.toLowerCase().endsWith('.js')) {
action = Actions.SCRIPT
} else if (value.toLowerCase() === 'none') {
action = Actions.NONE
} else {
action = Actions.BROWSER
}
return { action, value }
}
function executeNodeScript (scriptPath, url) {
const extraArgs = process.argv.slice(2)
const child = execa('node', [scriptPath, ...extraArgs, url], {
stdio: 'inherit'
})
child.on('close', code => {
if (code !== 0) {
console.log()
console.log(
chalk.red(
'The script specified as BROWSER environment variable failed.'
)
)
console.log(chalk.cyan(scriptPath) + ' exited with code ' + code + '.')
console.log()
return
}
})
return true
}
function startBrowserProcess (browser, url) {
// If we're on OS X, the user hasn't specifically
// requested a different browser, we can try opening
// Chrome with AppleScript. This lets us reuse an
// existing tab when possible instead of creating a new one.
const shouldTryOpenChromeWithAppleScript =
process.platform === 'darwin' &&
(typeof browser !== 'string' || browser === OSX_CHROME)
if (shouldTryOpenChromeWithAppleScript) {
try {
// Try our best to reuse existing tab
// on OS X Google Chrome with AppleScript
execSync('ps cax | grep "Google Chrome"')
execSync('osascript openChrome.applescript "' + encodeURI(url) + '"', {
cwd: __dirname,
stdio: 'ignore'
})
return true
} catch (err) {
// Ignore errors.
}
}
// Another special case: on OS X, check if BROWSER has been set to "open".
// In this case, instead of passing `open` to `opn` (which won't work),
// just ignore it (thus ensuring the intended behavior, i.e. opening the system browser):
// https://github.com/facebookincubator/create-react-app/pull/1690#issuecomment-283518768
if (process.platform === 'darwin' && browser === 'open') {
browser = undefined
}
// Fallback to opn
// (It will always open new tab)
try {
var options = { app: browser }
opn(url, options).catch(() => {}) // Prevent `unhandledRejection` error.
return true
} catch (err) {
return false
}
}
/**
* Reads the BROWSER evironment variable and decides what to do with it. Returns
* true if it opened a browser or ran a node.js script, otherwise false.
*/
exports.openBrowser = function (url) {
const { action, value } = getBrowserEnv()
switch (action) {
case Actions.NONE:
// Special case: BROWSER="none" will prevent opening completely.
return false
case Actions.SCRIPT:
return executeNodeScript(value, url)
case Actions.BROWSER:
return startBrowserProcess(value, url)
default:
throw new Error('Not implemented.')
}
}
+84
View File
@@ -0,0 +1,84 @@
(*
Copyright (c) 2015-present, Facebook, Inc.
This source code is licensed under the MIT license found in the
LICENSE file at
https://github.com/facebookincubator/create-react-app/blob/master/LICENSE
*)
property targetTab: null
property targetTabIndex: -1
property targetWindow: null
on run argv
set theURL to item 1 of argv
tell application "Chrome"
if (count every window) = 0 then
make new window
end if
-- 1: Looking for tab running debugger
-- then, Reload debugging tab if found
-- then return
set found to my lookupTabWithUrl(theURL)
if found then
set targetWindow's active tab index to targetTabIndex
tell targetTab to reload
tell targetWindow to activate
set index of targetWindow to 1
return
end if
-- 2: Looking for Empty tab
-- In case debugging tab was not found
-- We try to find an empty tab instead
set found to my lookupTabWithUrl("chrome://newtab/")
if found then
set targetWindow's active tab index to targetTabIndex
set URL of targetTab to theURL
tell targetWindow to activate
return
end if
-- 3: Create new tab
-- both debugging and empty tab were not found
-- make a new tab with url
tell window 1
activate
make new tab with properties {URL:theURL}
end tell
end tell
end run
-- Function:
-- Lookup tab with given url
-- if found, store tab, index, and window in properties
-- (properties were declared on top of file)
on lookupTabWithUrl(lookupUrl)
tell application "Chrome"
-- Find a tab with the given url
set found to false
set theTabIndex to -1
repeat with theWindow in every window
set theTabIndex to 0
repeat with theTab in every tab of theWindow
set theTabIndex to theTabIndex + 1
if (theTab's URL as string) contains lookupUrl then
-- assign tab, tab index, and window to properties
set targetTab to theTab
set targetTabIndex to theTabIndex
set targetWindow to theWindow
set found to true
exit repeat
end if
end repeat
if found then
exit repeat
end if
end repeat
end tell
return found
end lookupTabWithUrl
+59
View File
@@ -0,0 +1,59 @@
const pluginRE = /^(@vue\/|vue-|@[\w-]+\/vue-)cli-plugin-/
const scopeRE = /^@[\w-]+\//
const officialRE = /^@vue\//
exports.isPlugin = id => pluginRE.test(id)
exports.isOfficialPlugin = id => exports.isPlugin(id) && officialRE.test(id)
exports.toShortPluginId = id => id.replace(pluginRE, '')
exports.resolvePluginId = id => {
// already full id
// e.g. vue-cli-plugin-foo, @vue/cli-plugin-foo, @bar/vue-cli-plugin-foo
if (pluginRE.test(id)) {
return id
}
// scoped short
// e.g. @vue/foo, @bar/foo
if (id.charAt(0) === '@') {
const scopeMatch = id.match(scopeRE)
if (scopeMatch) {
const scope = scopeMatch[0]
const shortId = id.replace(scopeRE, '')
return `${scope}${scope === '@vue/' ? `` : `vue-`}cli-plugin-${shortId}`
}
}
// default short
// e.g. foo
return `vue-cli-plugin-${id}`
}
exports.matchesPluginId = (input, full) => {
const short = full.replace(pluginRE, '')
return (
// input is full
full === input ||
// input is short without scope
short === input ||
// input is short with scope
short === input.replace(scopeRE, '')
)
}
exports.getPluginLink = id => {
if (officialRE.test(id)) {
return `https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-${
exports.toShortPluginId(id)
}`
}
let pkg = {}
try {
pkg = require(`${id}/package.json`)
} catch (e) {}
return (
pkg.homepage ||
(pkg.repository && pkg.repository.url) ||
`https://www.npmjs.com/package/${id.replace(`/`, `%2F`)}`
)
}
+15
View File
@@ -0,0 +1,15 @@
exports.request = {
get (uri) {
// lazy require
const request = require('request-promise-native')
const reqOpts = {
method: 'GET',
timeout: 30000,
resolveWithFullResponse: true,
json: true,
uri
}
return request(reqOpts)
}
}
+49
View File
@@ -0,0 +1,49 @@
const ora = require('ora')
const chalk = require('chalk')
const spinner = ora()
let lastMsg = null
exports.logWithSpinner = (symbol, msg) => {
if (!msg) {
msg = symbol
symbol = chalk.green('✔')
}
if (lastMsg) {
spinner.stopAndPersist({
symbol: lastMsg.symbol,
text: lastMsg.text
})
}
spinner.text = ' ' + msg
lastMsg = {
symbol: symbol + ' ',
text: msg
}
spinner.start()
}
exports.stopSpinner = (persist) => {
if (lastMsg && persist !== false) {
spinner.stopAndPersist({
symbol: lastMsg.symbol,
text: lastMsg.text
})
} else {
spinner.stop()
}
lastMsg = null
}
exports.pauseSpinner = () => {
spinner.stop()
}
exports.resumeSpinner = () => {
spinner.start()
}
// silent all logs except errors during tests and keep record
if (process.env.VUE_CLI_TEST) {
require('./_silence')('spinner', exports)
}
+24
View File
@@ -0,0 +1,24 @@
const { exit } = require('./exit')
// proxy to joi for option validation
exports.createSchema = fn => fn(require('joi'))
exports.validate = (obj, schema, cb) => {
require('joi').validate(obj, schema, {}, err => {
if (err) {
cb(err.message)
if (process.env.VUE_CLI_TEST) {
throw err
} else {
exit(1)
}
}
})
}
exports.validateSync = (obj, schema) => {
const result = require('joi').validate(obj, schema)
if (result.error) {
throw result.error
}
}