update
This commit is contained in:
@@ -0,0 +1,224 @@
|
||||
'use strict'
|
||||
|
||||
const EE = require('events').EventEmitter
|
||||
const cons = require('constants')
|
||||
const fs = require('fs')
|
||||
|
||||
module.exports = (f, options, cb) => {
|
||||
if (typeof options === 'function')
|
||||
cb = options, options = {}
|
||||
|
||||
const p = new Promise((res, rej) => {
|
||||
new Touch(validOpts(options, f, null))
|
||||
.on('done', res).on('error', rej)
|
||||
})
|
||||
|
||||
return cb ? p.then(res => cb(null, res), cb) : p
|
||||
}
|
||||
|
||||
module.exports.sync = module.exports.touchSync = (f, options) =>
|
||||
(new TouchSync(validOpts(options, f, null)), undefined)
|
||||
|
||||
module.exports.ftouch = (fd, options, cb) => {
|
||||
if (typeof options === 'function')
|
||||
cb = options, options = {}
|
||||
|
||||
const p = new Promise((res, rej) => {
|
||||
new Touch(validOpts(options, null, fd))
|
||||
.on('done', res).on('error', rej)
|
||||
})
|
||||
|
||||
return cb ? p.then(res => cb(null, res), cb) : p
|
||||
}
|
||||
|
||||
module.exports.ftouchSync = (fd, opt) =>
|
||||
(new TouchSync(validOpts(opt, null, fd)), undefined)
|
||||
|
||||
const validOpts = (options, path, fd) => {
|
||||
options = Object.create(options || {})
|
||||
options.fd = fd
|
||||
options.path = path
|
||||
|
||||
// {mtime: true}, {ctime: true}
|
||||
// If set to something else, then treat as epoch ms value
|
||||
const now = new Date(options.time || Date.now()).getTime() / 1000
|
||||
if (!options.atime && !options.mtime)
|
||||
options.atime = options.mtime = now
|
||||
else {
|
||||
if (true === options.atime)
|
||||
options.atime = now
|
||||
|
||||
if (true === options.mtime)
|
||||
options.mtime = now
|
||||
}
|
||||
|
||||
let oflags = 0
|
||||
if (!options.force)
|
||||
oflags = oflags | cons.O_RDWR
|
||||
|
||||
if (!options.nocreate)
|
||||
oflags = oflags | cons.O_CREAT
|
||||
|
||||
options.oflags = oflags
|
||||
return options
|
||||
}
|
||||
|
||||
class Touch extends EE {
|
||||
constructor (options) {
|
||||
super(options)
|
||||
this.fd = options.fd
|
||||
this.path = options.path
|
||||
this.atime = options.atime
|
||||
this.mtime = options.mtime
|
||||
this.ref = options.ref
|
||||
this.nocreate = !!options.nocreate
|
||||
this.force = !!options.force
|
||||
this.closeAfter = options.closeAfter
|
||||
this.oflags = options.oflags
|
||||
this.options = options
|
||||
|
||||
if (typeof this.fd !== 'number') {
|
||||
this.closeAfter = true
|
||||
this.open()
|
||||
} else
|
||||
this.onopen(null, this.fd)
|
||||
}
|
||||
|
||||
emit (ev, data) {
|
||||
// we only emit when either done or erroring
|
||||
// in both cases, need to close
|
||||
this.close()
|
||||
return super.emit(ev, data)
|
||||
}
|
||||
|
||||
close () {
|
||||
if (typeof this.fd === 'number' && this.closeAfter)
|
||||
fs.close(this.fd, () => {})
|
||||
}
|
||||
|
||||
open () {
|
||||
fs.open(this.path, this.oflags, (er, fd) => this.onopen(er, fd))
|
||||
}
|
||||
|
||||
onopen (er, fd) {
|
||||
if (er) {
|
||||
if (er.code === 'EISDIR')
|
||||
this.onopen(null, null)
|
||||
else if (er.code === 'ENOENT' && this.nocreate)
|
||||
this.emit('done')
|
||||
else
|
||||
this.emit('error', er)
|
||||
} else {
|
||||
this.fd = fd
|
||||
if (this.ref)
|
||||
this.statref()
|
||||
else if (!this.atime || !this.mtime)
|
||||
this.fstat()
|
||||
else
|
||||
this.futimes()
|
||||
}
|
||||
}
|
||||
|
||||
statref () {
|
||||
fs.stat(this.ref, (er, st) => {
|
||||
if (er)
|
||||
this.emit('error', er)
|
||||
else
|
||||
this.onstatref(st)
|
||||
})
|
||||
}
|
||||
|
||||
onstatref (st) {
|
||||
this.atime = this.atime && st.atime.getTime()/1000
|
||||
this.mtime = this.mtime && st.mtime.getTime()/1000
|
||||
if (!this.atime || !this.mtime)
|
||||
this.fstat()
|
||||
else
|
||||
this.futimes()
|
||||
}
|
||||
|
||||
fstat () {
|
||||
const stat = this.fd ? 'fstat' : 'stat'
|
||||
const target = this.fd || this.path
|
||||
fs[stat](target, (er, st) => {
|
||||
if (er)
|
||||
this.emit('error', er)
|
||||
else
|
||||
this.onfstat(st)
|
||||
})
|
||||
}
|
||||
|
||||
onfstat (st) {
|
||||
if (typeof this.atime !== 'number')
|
||||
this.atime = st.atime.getTime()/1000
|
||||
|
||||
if (typeof this.mtime !== 'number')
|
||||
this.mtime = st.mtime.getTime()/1000
|
||||
|
||||
this.futimes()
|
||||
}
|
||||
|
||||
futimes () {
|
||||
const utimes = this.fd ? 'futimes' : 'utimes'
|
||||
const target = this.fd || this.path
|
||||
fs[utimes](target, ''+this.atime, ''+this.mtime, er => {
|
||||
if (er)
|
||||
this.emit('error', er)
|
||||
else
|
||||
this.emit('done')
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
class TouchSync extends Touch {
|
||||
open () {
|
||||
try {
|
||||
this.onopen(null, fs.openSync(this.path, this.oflags))
|
||||
} catch (er) {
|
||||
this.onopen(er)
|
||||
}
|
||||
}
|
||||
|
||||
statref () {
|
||||
let threw = true
|
||||
try {
|
||||
this.onstatref(fs.statSync(this.ref))
|
||||
threw = false
|
||||
} finally {
|
||||
if (threw)
|
||||
this.close()
|
||||
}
|
||||
}
|
||||
|
||||
fstat () {
|
||||
let threw = true
|
||||
const stat = this.fd ? 'fstatSync' : 'statSync'
|
||||
const target = this.fd || this.path
|
||||
try {
|
||||
this.onfstat(fs[stat](target))
|
||||
threw = false
|
||||
} finally {
|
||||
if (threw)
|
||||
this.close()
|
||||
}
|
||||
}
|
||||
|
||||
futimes () {
|
||||
let threw = true
|
||||
const utimes = this.fd ? 'futimesSync' : 'utimesSync'
|
||||
const target = this.fd || this.path
|
||||
try {
|
||||
fs[utimes](target, this.atime, this.mtime)
|
||||
threw = false
|
||||
} finally {
|
||||
if (threw)
|
||||
this.close()
|
||||
}
|
||||
this.emit('done')
|
||||
}
|
||||
|
||||
close () {
|
||||
if (typeof this.fd === 'number' && this.closeAfter)
|
||||
try { fs.closeSync(this.fd) } catch (er) {}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,211 @@
|
||||
/*!
|
||||
* mime-types
|
||||
* Copyright(c) 2014 Jonathan Ong
|
||||
* Copyright(c) 2015 Douglas Christopher Wilson
|
||||
* MIT Licensed
|
||||
*/
|
||||
|
||||
'use strict'
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
* @private
|
||||
*/
|
||||
|
||||
var db = require('mime-db')
|
||||
var extname = require('path').extname
|
||||
var mimeScore = require('./mimeScore')
|
||||
|
||||
/**
|
||||
* Module variables.
|
||||
* @private
|
||||
*/
|
||||
|
||||
var EXTRACT_TYPE_REGEXP = /^\s*([^;\s]*)(?:;|\s|$)/
|
||||
var TEXT_TYPE_REGEXP = /^text\//i
|
||||
|
||||
/**
|
||||
* Module exports.
|
||||
* @public
|
||||
*/
|
||||
|
||||
exports.charset = charset
|
||||
exports.charsets = { lookup: charset }
|
||||
exports.contentType = contentType
|
||||
exports.extension = extension
|
||||
exports.extensions = Object.create(null)
|
||||
exports.lookup = lookup
|
||||
exports.types = Object.create(null)
|
||||
exports._extensionConflicts = []
|
||||
|
||||
// Populate the extensions/types maps
|
||||
populateMaps(exports.extensions, exports.types)
|
||||
|
||||
/**
|
||||
* Get the default charset for a MIME type.
|
||||
*
|
||||
* @param {string} type
|
||||
* @return {boolean|string}
|
||||
*/
|
||||
|
||||
function charset (type) {
|
||||
if (!type || typeof type !== 'string') {
|
||||
return false
|
||||
}
|
||||
|
||||
// TODO: use media-typer
|
||||
var match = EXTRACT_TYPE_REGEXP.exec(type)
|
||||
var mime = match && db[match[1].toLowerCase()]
|
||||
|
||||
if (mime && mime.charset) {
|
||||
return mime.charset
|
||||
}
|
||||
|
||||
// default text/* to utf-8
|
||||
if (match && TEXT_TYPE_REGEXP.test(match[1])) {
|
||||
return 'UTF-8'
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a full Content-Type header given a MIME type or extension.
|
||||
*
|
||||
* @param {string} str
|
||||
* @return {boolean|string}
|
||||
*/
|
||||
|
||||
function contentType (str) {
|
||||
// TODO: should this even be in this module?
|
||||
if (!str || typeof str !== 'string') {
|
||||
return false
|
||||
}
|
||||
|
||||
var mime = str.indexOf('/') === -1 ? exports.lookup(str) : str
|
||||
|
||||
if (!mime) {
|
||||
return false
|
||||
}
|
||||
|
||||
// TODO: use content-type or other module
|
||||
if (mime.indexOf('charset') === -1) {
|
||||
var charset = exports.charset(mime)
|
||||
if (charset) mime += '; charset=' + charset.toLowerCase()
|
||||
}
|
||||
|
||||
return mime
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default extension for a MIME type.
|
||||
*
|
||||
* @param {string} type
|
||||
* @return {boolean|string}
|
||||
*/
|
||||
|
||||
function extension (type) {
|
||||
if (!type || typeof type !== 'string') {
|
||||
return false
|
||||
}
|
||||
|
||||
// TODO: use media-typer
|
||||
var match = EXTRACT_TYPE_REGEXP.exec(type)
|
||||
|
||||
// get extensions
|
||||
var exts = match && exports.extensions[match[1].toLowerCase()]
|
||||
|
||||
if (!exts || !exts.length) {
|
||||
return false
|
||||
}
|
||||
|
||||
return exts[0]
|
||||
}
|
||||
|
||||
/**
|
||||
* Lookup the MIME type for a file path/extension.
|
||||
*
|
||||
* @param {string} path
|
||||
* @return {boolean|string}
|
||||
*/
|
||||
|
||||
function lookup (path) {
|
||||
if (!path || typeof path !== 'string') {
|
||||
return false
|
||||
}
|
||||
|
||||
// get the extension ("ext" or ".ext" or full path)
|
||||
var extension = extname('x.' + path)
|
||||
.toLowerCase()
|
||||
.slice(1)
|
||||
|
||||
if (!extension) {
|
||||
return false
|
||||
}
|
||||
|
||||
return exports.types[extension] || false
|
||||
}
|
||||
|
||||
/**
|
||||
* Populate the extensions and types maps.
|
||||
* @private
|
||||
*/
|
||||
|
||||
function populateMaps (extensions, types) {
|
||||
Object.keys(db).forEach(function forEachMimeType (type) {
|
||||
var mime = db[type]
|
||||
var exts = mime.extensions
|
||||
|
||||
if (!exts || !exts.length) {
|
||||
return
|
||||
}
|
||||
|
||||
// mime -> extensions
|
||||
extensions[type] = exts
|
||||
|
||||
// extension -> mime
|
||||
for (var i = 0; i < exts.length; i++) {
|
||||
var extension = exts[i]
|
||||
types[extension] = _preferredType(extension, types[extension], type)
|
||||
|
||||
// DELETE (eventually): Capture extension->type maps that change as a
|
||||
// result of switching to mime-score. This is just to help make reviewing
|
||||
// PR #119 easier, and can be removed once that PR is approved.
|
||||
const legacyType = _preferredTypeLegacy(
|
||||
extension,
|
||||
types[extension],
|
||||
type
|
||||
)
|
||||
if (legacyType !== types[extension]) {
|
||||
exports._extensionConflicts.push([extension, legacyType, types[extension]])
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Resolve type conflict using mime-score
|
||||
function _preferredType (ext, type0, type1) {
|
||||
var score0 = type0 ? mimeScore(type0, db[type0].source) : 0
|
||||
var score1 = type1 ? mimeScore(type1, db[type1].source) : 0
|
||||
|
||||
return score0 > score1 ? type0 : type1
|
||||
}
|
||||
|
||||
// Resolve type conflict using pre-mime-score logic
|
||||
function _preferredTypeLegacy (ext, type0, type1) {
|
||||
var SOURCE_RANK = ['nginx', 'apache', undefined, 'iana']
|
||||
|
||||
var score0 = type0 ? SOURCE_RANK.indexOf(db[type0].source) : 0
|
||||
var score1 = type1 ? SOURCE_RANK.indexOf(db[type1].source) : 0
|
||||
|
||||
if (
|
||||
exports.types[extension] !== 'application/octet-stream' &&
|
||||
(score0 > score1 ||
|
||||
(score0 === score1 &&
|
||||
exports.types[extension]?.slice(0, 12) === 'application/'))
|
||||
) {
|
||||
return type0
|
||||
}
|
||||
|
||||
return score0 > score1 ? type0 : type1
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import { Parser } from "../index.js";
|
||||
|
||||
export declare const parsers: {
|
||||
__babel_estree: Parser;
|
||||
__js_expression: Parser;
|
||||
__ts_expression: Parser;
|
||||
__vue_event_binding: Parser;
|
||||
__vue_expression: Parser;
|
||||
__vue_ts_event_binding: Parser;
|
||||
__vue_ts_expression: Parser;
|
||||
babel: Parser;
|
||||
"babel-flow": Parser;
|
||||
"babel-ts": Parser;
|
||||
json: Parser;
|
||||
"json-stringify": Parser;
|
||||
json5: Parser;
|
||||
jsonc: Parser;
|
||||
};
|
||||
@@ -0,0 +1,21 @@
|
||||
# Changelog
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [v1.0.1](https://github.com/ljharb/get-proto/compare/v1.0.0...v1.0.1) - 2025-01-02
|
||||
|
||||
### Commits
|
||||
|
||||
- [Fix] for the `Object.getPrototypeOf` window, throw for non-objects [`7fe6508`](https://github.com/ljharb/get-proto/commit/7fe6508b71419ebe1976bedb86001d1feaeaa49a)
|
||||
|
||||
## v1.0.0 - 2025-01-01
|
||||
|
||||
### Commits
|
||||
|
||||
- Initial implementation, tests, readme, types [`5c70775`](https://github.com/ljharb/get-proto/commit/5c707751e81c3deeb2cf980d185fc7fd43611415)
|
||||
- Initial commit [`7c65c2a`](https://github.com/ljharb/get-proto/commit/7c65c2ad4e33d5dae2f219ebe1a046ae2256972c)
|
||||
- npm init [`0b8cf82`](https://github.com/ljharb/get-proto/commit/0b8cf824c9634e4a34ef7dd2a2cdc5be6ac79518)
|
||||
- Only apps should have lockfiles [`a6d1bff`](https://github.com/ljharb/get-proto/commit/a6d1bffc364f5828377cea7194558b2dbef7aea2)
|
||||
@@ -0,0 +1,103 @@
|
||||
2.0.0 / 2018-10-26
|
||||
==================
|
||||
|
||||
* Drop support for Node.js 0.6
|
||||
* Replace internal `eval` usage with `Function` constructor
|
||||
* Use instance methods on `process` to check for listeners
|
||||
|
||||
1.1.2 / 2018-01-11
|
||||
==================
|
||||
|
||||
* perf: remove argument reassignment
|
||||
* Support Node.js 0.6 to 9.x
|
||||
|
||||
1.1.1 / 2017-07-27
|
||||
==================
|
||||
|
||||
* Remove unnecessary `Buffer` loading
|
||||
* Support Node.js 0.6 to 8.x
|
||||
|
||||
1.1.0 / 2015-09-14
|
||||
==================
|
||||
|
||||
* Enable strict mode in more places
|
||||
* Support io.js 3.x
|
||||
* Support io.js 2.x
|
||||
* Support web browser loading
|
||||
- Requires bundler like Browserify or webpack
|
||||
|
||||
1.0.1 / 2015-04-07
|
||||
==================
|
||||
|
||||
* Fix `TypeError`s when under `'use strict'` code
|
||||
* Fix useless type name on auto-generated messages
|
||||
* Support io.js 1.x
|
||||
* Support Node.js 0.12
|
||||
|
||||
1.0.0 / 2014-09-17
|
||||
==================
|
||||
|
||||
* No changes
|
||||
|
||||
0.4.5 / 2014-09-09
|
||||
==================
|
||||
|
||||
* Improve call speed to functions using the function wrapper
|
||||
* Support Node.js 0.6
|
||||
|
||||
0.4.4 / 2014-07-27
|
||||
==================
|
||||
|
||||
* Work-around v8 generating empty stack traces
|
||||
|
||||
0.4.3 / 2014-07-26
|
||||
==================
|
||||
|
||||
* Fix exception when global `Error.stackTraceLimit` is too low
|
||||
|
||||
0.4.2 / 2014-07-19
|
||||
==================
|
||||
|
||||
* Correct call site for wrapped functions and properties
|
||||
|
||||
0.4.1 / 2014-07-19
|
||||
==================
|
||||
|
||||
* Improve automatic message generation for function properties
|
||||
|
||||
0.4.0 / 2014-07-19
|
||||
==================
|
||||
|
||||
* Add `TRACE_DEPRECATION` environment variable
|
||||
* Remove non-standard grey color from color output
|
||||
* Support `--no-deprecation` argument
|
||||
* Support `--trace-deprecation` argument
|
||||
* Support `deprecate.property(fn, prop, message)`
|
||||
|
||||
0.3.0 / 2014-06-16
|
||||
==================
|
||||
|
||||
* Add `NO_DEPRECATION` environment variable
|
||||
|
||||
0.2.0 / 2014-06-15
|
||||
==================
|
||||
|
||||
* Add `deprecate.property(obj, prop, message)`
|
||||
* Remove `supports-color` dependency for node.js 0.8
|
||||
|
||||
0.1.0 / 2014-06-15
|
||||
==================
|
||||
|
||||
* Add `deprecate.function(fn, message)`
|
||||
* Add `process.on('deprecation', fn)` emitter
|
||||
* Automatically generate message when omitted from `deprecate()`
|
||||
|
||||
0.0.1 / 2014-06-15
|
||||
==================
|
||||
|
||||
* Fix warning for dynamic calls at singe call site
|
||||
|
||||
0.0.0 / 2014-06-15
|
||||
==================
|
||||
|
||||
* Initial implementation
|
||||
Reference in New Issue
Block a user