WIP: bootstrap and partial real Solana watcher implementation
This commit is contained in:
@@ -0,0 +1,171 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const utils_1 = require("@typescript-eslint/utils");
|
||||
const util_1 = require("../util");
|
||||
function removeSpaces(str) {
|
||||
return str.replaceAll(/\s/g, '');
|
||||
}
|
||||
function stringifyNode(node, sourceCode) {
|
||||
return removeSpaces(sourceCode.getText(node));
|
||||
}
|
||||
function getCustomMessage(bannedType) {
|
||||
if (!bannedType || bannedType === true) {
|
||||
return '';
|
||||
}
|
||||
if (typeof bannedType === 'string') {
|
||||
return ` ${bannedType}`;
|
||||
}
|
||||
if (bannedType.message) {
|
||||
return ` ${bannedType.message}`;
|
||||
}
|
||||
return '';
|
||||
}
|
||||
const TYPE_KEYWORDS = {
|
||||
bigint: utils_1.AST_NODE_TYPES.TSBigIntKeyword,
|
||||
boolean: utils_1.AST_NODE_TYPES.TSBooleanKeyword,
|
||||
never: utils_1.AST_NODE_TYPES.TSNeverKeyword,
|
||||
null: utils_1.AST_NODE_TYPES.TSNullKeyword,
|
||||
number: utils_1.AST_NODE_TYPES.TSNumberKeyword,
|
||||
object: utils_1.AST_NODE_TYPES.TSObjectKeyword,
|
||||
string: utils_1.AST_NODE_TYPES.TSStringKeyword,
|
||||
symbol: utils_1.AST_NODE_TYPES.TSSymbolKeyword,
|
||||
undefined: utils_1.AST_NODE_TYPES.TSUndefinedKeyword,
|
||||
unknown: utils_1.AST_NODE_TYPES.TSUnknownKeyword,
|
||||
void: utils_1.AST_NODE_TYPES.TSVoidKeyword,
|
||||
};
|
||||
exports.default = (0, util_1.createRule)({
|
||||
name: 'no-restricted-types',
|
||||
meta: {
|
||||
type: 'suggestion',
|
||||
docs: {
|
||||
description: 'Disallow certain types',
|
||||
},
|
||||
fixable: 'code',
|
||||
hasSuggestions: true,
|
||||
messages: {
|
||||
bannedTypeMessage: "Don't use `{{name}}` as a type.{{customMessage}}",
|
||||
bannedTypeReplacement: 'Replace `{{name}}` with `{{replacement}}`.',
|
||||
},
|
||||
schema: [
|
||||
{
|
||||
type: 'object',
|
||||
$defs: {
|
||||
banConfig: {
|
||||
oneOf: [
|
||||
{
|
||||
type: 'boolean',
|
||||
description: 'Bans the type with the default message.',
|
||||
enum: [true],
|
||||
},
|
||||
{
|
||||
type: 'string',
|
||||
description: 'Bans the type with a custom message.',
|
||||
},
|
||||
{
|
||||
type: 'object',
|
||||
additionalProperties: false,
|
||||
description: 'Bans a type.',
|
||||
properties: {
|
||||
fixWith: {
|
||||
type: 'string',
|
||||
description: 'Type to autofix replace with. Note that autofixers can be applied automatically - so you need to be careful with this option.',
|
||||
},
|
||||
message: {
|
||||
type: 'string',
|
||||
description: 'Custom error message.',
|
||||
},
|
||||
suggest: {
|
||||
type: 'array',
|
||||
description: 'Types to suggest replacing with.',
|
||||
items: { type: 'string' },
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
types: {
|
||||
type: 'object',
|
||||
additionalProperties: {
|
||||
$ref: '#/items/0/$defs/banConfig',
|
||||
},
|
||||
description: 'An object whose keys are the types you want to ban, and the values are error messages.',
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
defaultOptions: [{}],
|
||||
create(context, [{ types = {} }]) {
|
||||
const bannedTypes = new Map(Object.entries(types).map(([type, data]) => [removeSpaces(type), data]));
|
||||
function checkBannedTypes(typeNode, name = stringifyNode(typeNode, context.sourceCode)) {
|
||||
const bannedType = bannedTypes.get(name);
|
||||
if (bannedType == null || bannedType === false) {
|
||||
return;
|
||||
}
|
||||
const customMessage = getCustomMessage(bannedType);
|
||||
const fixWith = bannedType && typeof bannedType === 'object' && bannedType.fixWith;
|
||||
const suggest = bannedType && typeof bannedType === 'object'
|
||||
? bannedType.suggest
|
||||
: undefined;
|
||||
context.report({
|
||||
node: typeNode,
|
||||
messageId: 'bannedTypeMessage',
|
||||
data: {
|
||||
name,
|
||||
customMessage,
|
||||
},
|
||||
fix: fixWith
|
||||
? (fixer) => fixer.replaceText(typeNode, fixWith)
|
||||
: null,
|
||||
suggest: suggest?.map(replacement => ({
|
||||
messageId: 'bannedTypeReplacement',
|
||||
data: {
|
||||
name,
|
||||
replacement,
|
||||
},
|
||||
fix: (fixer) => fixer.replaceText(typeNode, replacement),
|
||||
})),
|
||||
});
|
||||
}
|
||||
const keywordSelectors = (0, util_1.objectReduceKey)(TYPE_KEYWORDS, (acc, keyword) => {
|
||||
if (bannedTypes.has(keyword)) {
|
||||
acc[TYPE_KEYWORDS[keyword]] = (node) => checkBannedTypes(node, keyword);
|
||||
}
|
||||
return acc;
|
||||
}, {});
|
||||
return {
|
||||
...keywordSelectors,
|
||||
TSClassImplements(node) {
|
||||
checkBannedTypes(node.expression);
|
||||
if (node.typeArguments) {
|
||||
checkBannedTypes(node);
|
||||
}
|
||||
},
|
||||
TSInterfaceHeritage(node) {
|
||||
checkBannedTypes(node.expression);
|
||||
if (node.typeArguments) {
|
||||
checkBannedTypes(node);
|
||||
}
|
||||
},
|
||||
TSTupleType(node) {
|
||||
if (!node.elementTypes.length) {
|
||||
checkBannedTypes(node);
|
||||
}
|
||||
},
|
||||
TSTypeLiteral(node) {
|
||||
if (!node.members.length) {
|
||||
checkBannedTypes(node);
|
||||
}
|
||||
},
|
||||
TSTypeReference(node) {
|
||||
checkBannedTypes(node.typeName);
|
||||
if (node.typeArguments) {
|
||||
checkBannedTypes(node);
|
||||
}
|
||||
},
|
||||
};
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,439 @@
|
||||
"use strict";
|
||||
|
||||
/* This file is automatically generated and should not be manually edited. */
|
||||
/* To modify this file, please run the `npm run build` command instead. */
|
||||
|
||||
0 && (module.exports = {
|
||||
/* @Annotate_start: the CommonJS named exports for ESM import in node */
|
||||
_apply_decorated_descriptor: null,
|
||||
_apply_decs_2203_r: null,
|
||||
_apply_decs_2311: null,
|
||||
_array_like_to_array: null,
|
||||
_array_with_holes: null,
|
||||
_array_without_holes: null,
|
||||
_assert_this_initialized: null,
|
||||
_async_generator: null,
|
||||
_async_generator_delegate: null,
|
||||
_async_iterator: null,
|
||||
_async_to_generator: null,
|
||||
_await_async_generator: null,
|
||||
_await_value: null,
|
||||
_call_super: null,
|
||||
_check_private_redeclaration: null,
|
||||
_class_apply_descriptor_destructure: null,
|
||||
_class_apply_descriptor_get: null,
|
||||
_class_apply_descriptor_set: null,
|
||||
_class_apply_descriptor_update: null,
|
||||
_class_call_check: null,
|
||||
_class_check_private_static_access: null,
|
||||
_class_check_private_static_field_descriptor: null,
|
||||
_class_extract_field_descriptor: null,
|
||||
_class_name_tdz_error: null,
|
||||
_class_private_field_destructure: null,
|
||||
_class_private_field_get: null,
|
||||
_class_private_field_init: null,
|
||||
_class_private_field_loose_base: null,
|
||||
_class_private_field_loose_key: null,
|
||||
_class_private_field_set: null,
|
||||
_class_private_field_update: null,
|
||||
_class_private_method_get: null,
|
||||
_class_private_method_init: null,
|
||||
_class_private_method_set: null,
|
||||
_class_static_private_field_destructure: null,
|
||||
_class_static_private_field_spec_get: null,
|
||||
_class_static_private_field_spec_set: null,
|
||||
_class_static_private_field_update: null,
|
||||
_class_static_private_method_get: null,
|
||||
_construct: null,
|
||||
_create_class: null,
|
||||
_create_for_of_iterator_helper_loose: null,
|
||||
_create_super: null,
|
||||
_decorate: null,
|
||||
_defaults: null,
|
||||
_define_enumerable_properties: null,
|
||||
_define_property: null,
|
||||
_dispose: null,
|
||||
_export_star: null,
|
||||
_extends: null,
|
||||
_get: null,
|
||||
_get_prototype_of: null,
|
||||
_identity: null,
|
||||
_inherits: null,
|
||||
_inherits_loose: null,
|
||||
_initializer_define_property: null,
|
||||
_initializer_warning_helper: null,
|
||||
_instanceof: null,
|
||||
_interop_require_default: null,
|
||||
_interop_require_wildcard: null,
|
||||
_is_native_function: null,
|
||||
_is_native_reflect_construct: null,
|
||||
_iterable_to_array: null,
|
||||
_iterable_to_array_limit: null,
|
||||
_iterable_to_array_limit_loose: null,
|
||||
_jsx: null,
|
||||
_new_arrow_check: null,
|
||||
_non_iterable_rest: null,
|
||||
_non_iterable_spread: null,
|
||||
_object_destructuring_empty: null,
|
||||
_object_spread: null,
|
||||
_object_spread_props: null,
|
||||
_object_without_properties: null,
|
||||
_object_without_properties_loose: null,
|
||||
_overload_yield: null,
|
||||
_possible_constructor_return: null,
|
||||
_read_only_error: null,
|
||||
_set: null,
|
||||
_set_prototype_of: null,
|
||||
_skip_first_generator_next: null,
|
||||
_sliced_to_array: null,
|
||||
_sliced_to_array_loose: null,
|
||||
_super_prop_base: null,
|
||||
_tagged_template_literal: null,
|
||||
_tagged_template_literal_loose: null,
|
||||
_throw: null,
|
||||
_to_array: null,
|
||||
_to_consumable_array: null,
|
||||
_to_primitive: null,
|
||||
_to_property_key: null,
|
||||
_ts_add_disposable_resource: null,
|
||||
_ts_decorate: null,
|
||||
_ts_dispose_resources: null,
|
||||
_ts_generator: null,
|
||||
_ts_metadata: null,
|
||||
_ts_param: null,
|
||||
_ts_rewrite_relative_import_extension: null,
|
||||
_ts_values: null,
|
||||
_type_of: null,
|
||||
_unsupported_iterable_to_array: null,
|
||||
_update: null,
|
||||
_using: null,
|
||||
_using_ctx: null,
|
||||
_wrap_async_generator: null,
|
||||
_wrap_native_super: null,
|
||||
_wrap_reg_exp: null,
|
||||
_write_only_error: null
|
||||
/* @Annotate_end */
|
||||
});
|
||||
module.exports = {
|
||||
get _apply_decorated_descriptor() {
|
||||
return require("./_apply_decorated_descriptor.cjs")._;
|
||||
},
|
||||
get _apply_decs_2203_r() {
|
||||
return require("./_apply_decs_2203_r.cjs")._;
|
||||
},
|
||||
get _apply_decs_2311() {
|
||||
return require("./_apply_decs_2311.cjs")._;
|
||||
},
|
||||
get _array_like_to_array() {
|
||||
return require("./_array_like_to_array.cjs")._;
|
||||
},
|
||||
get _array_with_holes() {
|
||||
return require("./_array_with_holes.cjs")._;
|
||||
},
|
||||
get _array_without_holes() {
|
||||
return require("./_array_without_holes.cjs")._;
|
||||
},
|
||||
get _assert_this_initialized() {
|
||||
return require("./_assert_this_initialized.cjs")._;
|
||||
},
|
||||
get _async_generator() {
|
||||
return require("./_async_generator.cjs")._;
|
||||
},
|
||||
get _async_generator_delegate() {
|
||||
return require("./_async_generator_delegate.cjs")._;
|
||||
},
|
||||
get _async_iterator() {
|
||||
return require("./_async_iterator.cjs")._;
|
||||
},
|
||||
get _async_to_generator() {
|
||||
return require("./_async_to_generator.cjs")._;
|
||||
},
|
||||
get _await_async_generator() {
|
||||
return require("./_await_async_generator.cjs")._;
|
||||
},
|
||||
get _await_value() {
|
||||
return require("./_await_value.cjs")._;
|
||||
},
|
||||
get _call_super() {
|
||||
return require("./_call_super.cjs")._;
|
||||
},
|
||||
get _check_private_redeclaration() {
|
||||
return require("./_check_private_redeclaration.cjs")._;
|
||||
},
|
||||
get _class_apply_descriptor_destructure() {
|
||||
return require("./_class_apply_descriptor_destructure.cjs")._;
|
||||
},
|
||||
get _class_apply_descriptor_get() {
|
||||
return require("./_class_apply_descriptor_get.cjs")._;
|
||||
},
|
||||
get _class_apply_descriptor_set() {
|
||||
return require("./_class_apply_descriptor_set.cjs")._;
|
||||
},
|
||||
get _class_apply_descriptor_update() {
|
||||
return require("./_class_apply_descriptor_update.cjs")._;
|
||||
},
|
||||
get _class_call_check() {
|
||||
return require("./_class_call_check.cjs")._;
|
||||
},
|
||||
get _class_check_private_static_access() {
|
||||
return require("./_class_check_private_static_access.cjs")._;
|
||||
},
|
||||
get _class_check_private_static_field_descriptor() {
|
||||
return require("./_class_check_private_static_field_descriptor.cjs")._;
|
||||
},
|
||||
get _class_extract_field_descriptor() {
|
||||
return require("./_class_extract_field_descriptor.cjs")._;
|
||||
},
|
||||
get _class_name_tdz_error() {
|
||||
return require("./_class_name_tdz_error.cjs")._;
|
||||
},
|
||||
get _class_private_field_destructure() {
|
||||
return require("./_class_private_field_destructure.cjs")._;
|
||||
},
|
||||
get _class_private_field_get() {
|
||||
return require("./_class_private_field_get.cjs")._;
|
||||
},
|
||||
get _class_private_field_init() {
|
||||
return require("./_class_private_field_init.cjs")._;
|
||||
},
|
||||
get _class_private_field_loose_base() {
|
||||
return require("./_class_private_field_loose_base.cjs")._;
|
||||
},
|
||||
get _class_private_field_loose_key() {
|
||||
return require("./_class_private_field_loose_key.cjs")._;
|
||||
},
|
||||
get _class_private_field_set() {
|
||||
return require("./_class_private_field_set.cjs")._;
|
||||
},
|
||||
get _class_private_field_update() {
|
||||
return require("./_class_private_field_update.cjs")._;
|
||||
},
|
||||
get _class_private_method_get() {
|
||||
return require("./_class_private_method_get.cjs")._;
|
||||
},
|
||||
get _class_private_method_init() {
|
||||
return require("./_class_private_method_init.cjs")._;
|
||||
},
|
||||
get _class_private_method_set() {
|
||||
return require("./_class_private_method_set.cjs")._;
|
||||
},
|
||||
get _class_static_private_field_destructure() {
|
||||
return require("./_class_static_private_field_destructure.cjs")._;
|
||||
},
|
||||
get _class_static_private_field_spec_get() {
|
||||
return require("./_class_static_private_field_spec_get.cjs")._;
|
||||
},
|
||||
get _class_static_private_field_spec_set() {
|
||||
return require("./_class_static_private_field_spec_set.cjs")._;
|
||||
},
|
||||
get _class_static_private_field_update() {
|
||||
return require("./_class_static_private_field_update.cjs")._;
|
||||
},
|
||||
get _class_static_private_method_get() {
|
||||
return require("./_class_static_private_method_get.cjs")._;
|
||||
},
|
||||
get _construct() {
|
||||
return require("./_construct.cjs")._;
|
||||
},
|
||||
get _create_class() {
|
||||
return require("./_create_class.cjs")._;
|
||||
},
|
||||
get _create_for_of_iterator_helper_loose() {
|
||||
return require("./_create_for_of_iterator_helper_loose.cjs")._;
|
||||
},
|
||||
get _create_super() {
|
||||
return require("./_create_super.cjs")._;
|
||||
},
|
||||
get _decorate() {
|
||||
return require("./_decorate.cjs")._;
|
||||
},
|
||||
get _defaults() {
|
||||
return require("./_defaults.cjs")._;
|
||||
},
|
||||
get _define_enumerable_properties() {
|
||||
return require("./_define_enumerable_properties.cjs")._;
|
||||
},
|
||||
get _define_property() {
|
||||
return require("./_define_property.cjs")._;
|
||||
},
|
||||
get _dispose() {
|
||||
return require("./_dispose.cjs")._;
|
||||
},
|
||||
get _export_star() {
|
||||
return require("./_export_star.cjs")._;
|
||||
},
|
||||
get _extends() {
|
||||
return require("./_extends.cjs")._;
|
||||
},
|
||||
get _get() {
|
||||
return require("./_get.cjs")._;
|
||||
},
|
||||
get _get_prototype_of() {
|
||||
return require("./_get_prototype_of.cjs")._;
|
||||
},
|
||||
get _identity() {
|
||||
return require("./_identity.cjs")._;
|
||||
},
|
||||
get _inherits() {
|
||||
return require("./_inherits.cjs")._;
|
||||
},
|
||||
get _inherits_loose() {
|
||||
return require("./_inherits_loose.cjs")._;
|
||||
},
|
||||
get _initializer_define_property() {
|
||||
return require("./_initializer_define_property.cjs")._;
|
||||
},
|
||||
get _initializer_warning_helper() {
|
||||
return require("./_initializer_warning_helper.cjs")._;
|
||||
},
|
||||
get _instanceof() {
|
||||
return require("./_instanceof.cjs")._;
|
||||
},
|
||||
get _interop_require_default() {
|
||||
return require("./_interop_require_default.cjs")._;
|
||||
},
|
||||
get _interop_require_wildcard() {
|
||||
return require("./_interop_require_wildcard.cjs")._;
|
||||
},
|
||||
get _is_native_function() {
|
||||
return require("./_is_native_function.cjs")._;
|
||||
},
|
||||
get _is_native_reflect_construct() {
|
||||
return require("./_is_native_reflect_construct.cjs")._;
|
||||
},
|
||||
get _iterable_to_array() {
|
||||
return require("./_iterable_to_array.cjs")._;
|
||||
},
|
||||
get _iterable_to_array_limit() {
|
||||
return require("./_iterable_to_array_limit.cjs")._;
|
||||
},
|
||||
get _iterable_to_array_limit_loose() {
|
||||
return require("./_iterable_to_array_limit_loose.cjs")._;
|
||||
},
|
||||
get _jsx() {
|
||||
return require("./_jsx.cjs")._;
|
||||
},
|
||||
get _new_arrow_check() {
|
||||
return require("./_new_arrow_check.cjs")._;
|
||||
},
|
||||
get _non_iterable_rest() {
|
||||
return require("./_non_iterable_rest.cjs")._;
|
||||
},
|
||||
get _non_iterable_spread() {
|
||||
return require("./_non_iterable_spread.cjs")._;
|
||||
},
|
||||
get _object_destructuring_empty() {
|
||||
return require("./_object_destructuring_empty.cjs")._;
|
||||
},
|
||||
get _object_spread() {
|
||||
return require("./_object_spread.cjs")._;
|
||||
},
|
||||
get _object_spread_props() {
|
||||
return require("./_object_spread_props.cjs")._;
|
||||
},
|
||||
get _object_without_properties() {
|
||||
return require("./_object_without_properties.cjs")._;
|
||||
},
|
||||
get _object_without_properties_loose() {
|
||||
return require("./_object_without_properties_loose.cjs")._;
|
||||
},
|
||||
get _overload_yield() {
|
||||
return require("./_overload_yield.cjs")._;
|
||||
},
|
||||
get _possible_constructor_return() {
|
||||
return require("./_possible_constructor_return.cjs")._;
|
||||
},
|
||||
get _read_only_error() {
|
||||
return require("./_read_only_error.cjs")._;
|
||||
},
|
||||
get _set() {
|
||||
return require("./_set.cjs")._;
|
||||
},
|
||||
get _set_prototype_of() {
|
||||
return require("./_set_prototype_of.cjs")._;
|
||||
},
|
||||
get _skip_first_generator_next() {
|
||||
return require("./_skip_first_generator_next.cjs")._;
|
||||
},
|
||||
get _sliced_to_array() {
|
||||
return require("./_sliced_to_array.cjs")._;
|
||||
},
|
||||
get _sliced_to_array_loose() {
|
||||
return require("./_sliced_to_array_loose.cjs")._;
|
||||
},
|
||||
get _super_prop_base() {
|
||||
return require("./_super_prop_base.cjs")._;
|
||||
},
|
||||
get _tagged_template_literal() {
|
||||
return require("./_tagged_template_literal.cjs")._;
|
||||
},
|
||||
get _tagged_template_literal_loose() {
|
||||
return require("./_tagged_template_literal_loose.cjs")._;
|
||||
},
|
||||
get _throw() {
|
||||
return require("./_throw.cjs")._;
|
||||
},
|
||||
get _to_array() {
|
||||
return require("./_to_array.cjs")._;
|
||||
},
|
||||
get _to_consumable_array() {
|
||||
return require("./_to_consumable_array.cjs")._;
|
||||
},
|
||||
get _to_primitive() {
|
||||
return require("./_to_primitive.cjs")._;
|
||||
},
|
||||
get _to_property_key() {
|
||||
return require("./_to_property_key.cjs")._;
|
||||
},
|
||||
get _ts_add_disposable_resource() {
|
||||
return require("./_ts_add_disposable_resource.cjs")._;
|
||||
},
|
||||
get _ts_decorate() {
|
||||
return require("./_ts_decorate.cjs")._;
|
||||
},
|
||||
get _ts_dispose_resources() {
|
||||
return require("./_ts_dispose_resources.cjs")._;
|
||||
},
|
||||
get _ts_generator() {
|
||||
return require("./_ts_generator.cjs")._;
|
||||
},
|
||||
get _ts_metadata() {
|
||||
return require("./_ts_metadata.cjs")._;
|
||||
},
|
||||
get _ts_param() {
|
||||
return require("./_ts_param.cjs")._;
|
||||
},
|
||||
get _ts_rewrite_relative_import_extension() {
|
||||
return require("./_ts_rewrite_relative_import_extension.cjs")._;
|
||||
},
|
||||
get _ts_values() {
|
||||
return require("./_ts_values.cjs")._;
|
||||
},
|
||||
get _type_of() {
|
||||
return require("./_type_of.cjs")._;
|
||||
},
|
||||
get _unsupported_iterable_to_array() {
|
||||
return require("./_unsupported_iterable_to_array.cjs")._;
|
||||
},
|
||||
get _update() {
|
||||
return require("./_update.cjs")._;
|
||||
},
|
||||
get _using() {
|
||||
return require("./_using.cjs")._;
|
||||
},
|
||||
get _using_ctx() {
|
||||
return require("./_using_ctx.cjs")._;
|
||||
},
|
||||
get _wrap_async_generator() {
|
||||
return require("./_wrap_async_generator.cjs")._;
|
||||
},
|
||||
get _wrap_native_super() {
|
||||
return require("./_wrap_native_super.cjs")._;
|
||||
},
|
||||
get _wrap_reg_exp() {
|
||||
return require("./_wrap_reg_exp.cjs")._;
|
||||
},
|
||||
get _write_only_error() {
|
||||
return require("./_write_only_error.cjs")._;
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,206 @@
|
||||
# is-glob [](https://www.npmjs.com/package/is-glob) [](https://npmjs.org/package/is-glob) [](https://npmjs.org/package/is-glob) [](https://github.com/micromatch/is-glob/actions)
|
||||
|
||||
> Returns `true` if the given string looks like a glob pattern or an extglob pattern. This makes it easy to create code that only uses external modules like node-glob when necessary, resulting in much faster code execution and initialization time, and a better user experience.
|
||||
|
||||
Please consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support.
|
||||
|
||||
## Install
|
||||
|
||||
Install with [npm](https://www.npmjs.com/):
|
||||
|
||||
```sh
|
||||
$ npm install --save is-glob
|
||||
```
|
||||
|
||||
You might also be interested in [is-valid-glob](https://github.com/jonschlinkert/is-valid-glob) and [has-glob](https://github.com/jonschlinkert/has-glob).
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
var isGlob = require('is-glob');
|
||||
```
|
||||
|
||||
### Default behavior
|
||||
|
||||
**True**
|
||||
|
||||
Patterns that have glob characters or regex patterns will return `true`:
|
||||
|
||||
```js
|
||||
isGlob('!foo.js');
|
||||
isGlob('*.js');
|
||||
isGlob('**/abc.js');
|
||||
isGlob('abc/*.js');
|
||||
isGlob('abc/(aaa|bbb).js');
|
||||
isGlob('abc/[a-z].js');
|
||||
isGlob('abc/{a,b}.js');
|
||||
//=> true
|
||||
```
|
||||
|
||||
Extglobs
|
||||
|
||||
```js
|
||||
isGlob('abc/@(a).js');
|
||||
isGlob('abc/!(a).js');
|
||||
isGlob('abc/+(a).js');
|
||||
isGlob('abc/*(a).js');
|
||||
isGlob('abc/?(a).js');
|
||||
//=> true
|
||||
```
|
||||
|
||||
**False**
|
||||
|
||||
Escaped globs or extglobs return `false`:
|
||||
|
||||
```js
|
||||
isGlob('abc/\\@(a).js');
|
||||
isGlob('abc/\\!(a).js');
|
||||
isGlob('abc/\\+(a).js');
|
||||
isGlob('abc/\\*(a).js');
|
||||
isGlob('abc/\\?(a).js');
|
||||
isGlob('\\!foo.js');
|
||||
isGlob('\\*.js');
|
||||
isGlob('\\*\\*/abc.js');
|
||||
isGlob('abc/\\*.js');
|
||||
isGlob('abc/\\(aaa|bbb).js');
|
||||
isGlob('abc/\\[a-z].js');
|
||||
isGlob('abc/\\{a,b}.js');
|
||||
//=> false
|
||||
```
|
||||
|
||||
Patterns that do not have glob patterns return `false`:
|
||||
|
||||
```js
|
||||
isGlob('abc.js');
|
||||
isGlob('abc/def/ghi.js');
|
||||
isGlob('foo.js');
|
||||
isGlob('abc/@.js');
|
||||
isGlob('abc/+.js');
|
||||
isGlob('abc/?.js');
|
||||
isGlob();
|
||||
isGlob(null);
|
||||
//=> false
|
||||
```
|
||||
|
||||
Arrays are also `false` (If you want to check if an array has a glob pattern, use [has-glob](https://github.com/jonschlinkert/has-glob)):
|
||||
|
||||
```js
|
||||
isGlob(['**/*.js']);
|
||||
isGlob(['foo.js']);
|
||||
//=> false
|
||||
```
|
||||
|
||||
### Option strict
|
||||
|
||||
When `options.strict === false` the behavior is less strict in determining if a pattern is a glob. Meaning that
|
||||
some patterns that would return `false` may return `true`. This is done so that matching libraries like [micromatch](https://github.com/micromatch/micromatch) have a chance at determining if the pattern is a glob or not.
|
||||
|
||||
**True**
|
||||
|
||||
Patterns that have glob characters or regex patterns will return `true`:
|
||||
|
||||
```js
|
||||
isGlob('!foo.js', {strict: false});
|
||||
isGlob('*.js', {strict: false});
|
||||
isGlob('**/abc.js', {strict: false});
|
||||
isGlob('abc/*.js', {strict: false});
|
||||
isGlob('abc/(aaa|bbb).js', {strict: false});
|
||||
isGlob('abc/[a-z].js', {strict: false});
|
||||
isGlob('abc/{a,b}.js', {strict: false});
|
||||
//=> true
|
||||
```
|
||||
|
||||
Extglobs
|
||||
|
||||
```js
|
||||
isGlob('abc/@(a).js', {strict: false});
|
||||
isGlob('abc/!(a).js', {strict: false});
|
||||
isGlob('abc/+(a).js', {strict: false});
|
||||
isGlob('abc/*(a).js', {strict: false});
|
||||
isGlob('abc/?(a).js', {strict: false});
|
||||
//=> true
|
||||
```
|
||||
|
||||
**False**
|
||||
|
||||
Escaped globs or extglobs return `false`:
|
||||
|
||||
```js
|
||||
isGlob('\\!foo.js', {strict: false});
|
||||
isGlob('\\*.js', {strict: false});
|
||||
isGlob('\\*\\*/abc.js', {strict: false});
|
||||
isGlob('abc/\\*.js', {strict: false});
|
||||
isGlob('abc/\\(aaa|bbb).js', {strict: false});
|
||||
isGlob('abc/\\[a-z].js', {strict: false});
|
||||
isGlob('abc/\\{a,b}.js', {strict: false});
|
||||
//=> false
|
||||
```
|
||||
|
||||
## About
|
||||
|
||||
<details>
|
||||
<summary><strong>Contributing</strong></summary>
|
||||
|
||||
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary><strong>Running Tests</strong></summary>
|
||||
|
||||
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
|
||||
|
||||
```sh
|
||||
$ npm install && npm test
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary><strong>Building docs</strong></summary>
|
||||
|
||||
_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_
|
||||
|
||||
To generate the readme, run the following command:
|
||||
|
||||
```sh
|
||||
$ npm install -g verbose/verb#dev verb-generate-readme && verb
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
### Related projects
|
||||
|
||||
You might also be interested in these projects:
|
||||
|
||||
* [assemble](https://www.npmjs.com/package/assemble): Get the rocks out of your socks! Assemble makes you fast at creating web projects… [more](https://github.com/assemble/assemble) | [homepage](https://github.com/assemble/assemble "Get the rocks out of your socks! Assemble makes you fast at creating web projects. Assemble is used by thousands of projects for rapid prototyping, creating themes, scaffolds, boilerplates, e-books, UI components, API documentation, blogs, building websit")
|
||||
* [base](https://www.npmjs.com/package/base): Framework for rapidly creating high quality, server-side node.js applications, using plugins like building blocks | [homepage](https://github.com/node-base/base "Framework for rapidly creating high quality, server-side node.js applications, using plugins like building blocks")
|
||||
* [update](https://www.npmjs.com/package/update): Be scalable! Update is a new, open source developer framework and CLI for automating updates… [more](https://github.com/update/update) | [homepage](https://github.com/update/update "Be scalable! Update is a new, open source developer framework and CLI for automating updates of any kind in code projects.")
|
||||
* [verb](https://www.npmjs.com/package/verb): Documentation generator for GitHub projects. Verb is extremely powerful, easy to use, and is used… [more](https://github.com/verbose/verb) | [homepage](https://github.com/verbose/verb "Documentation generator for GitHub projects. Verb is extremely powerful, easy to use, and is used on hundreds of projects of all sizes to generate everything from API docs to readmes.")
|
||||
|
||||
### Contributors
|
||||
|
||||
| **Commits** | **Contributor** |
|
||||
| --- | --- |
|
||||
| 47 | [jonschlinkert](https://github.com/jonschlinkert) |
|
||||
| 5 | [doowb](https://github.com/doowb) |
|
||||
| 1 | [phated](https://github.com/phated) |
|
||||
| 1 | [danhper](https://github.com/danhper) |
|
||||
| 1 | [paulmillr](https://github.com/paulmillr) |
|
||||
|
||||
### Author
|
||||
|
||||
**Jon Schlinkert**
|
||||
|
||||
* [GitHub Profile](https://github.com/jonschlinkert)
|
||||
* [Twitter Profile](https://twitter.com/jonschlinkert)
|
||||
* [LinkedIn Profile](https://linkedin.com/in/jonschlinkert)
|
||||
|
||||
### License
|
||||
|
||||
Copyright © 2019, [Jon Schlinkert](https://github.com/jonschlinkert).
|
||||
Released under the [MIT License](LICENSE).
|
||||
|
||||
***
|
||||
|
||||
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.8.0, on March 27, 2019._
|
||||
@@ -0,0 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
try {
|
||||
module.exports = require('node-gyp-build')(__dirname);
|
||||
} catch (e) {
|
||||
module.exports = require('./fallback');
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
{
|
||||
"name": "fast-json-stable-stringify",
|
||||
"version": "2.1.0",
|
||||
"description": "deterministic `JSON.stringify()` - a faster version of substack's json-stable-strigify without jsonify",
|
||||
"main": "index.js",
|
||||
"types": "index.d.ts",
|
||||
"dependencies": {},
|
||||
"devDependencies": {
|
||||
"benchmark": "^2.1.4",
|
||||
"coveralls": "^3.0.0",
|
||||
"eslint": "^6.7.0",
|
||||
"fast-stable-stringify": "latest",
|
||||
"faster-stable-stringify": "latest",
|
||||
"json-stable-stringify": "latest",
|
||||
"nyc": "^14.1.0",
|
||||
"pre-commit": "^1.2.2",
|
||||
"tape": "^4.11.0"
|
||||
},
|
||||
"scripts": {
|
||||
"eslint": "eslint index.js test",
|
||||
"test-spec": "tape test/*.js",
|
||||
"test": "npm run eslint && nyc npm run test-spec"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/epoberezkin/fast-json-stable-stringify.git"
|
||||
},
|
||||
"homepage": "https://github.com/epoberezkin/fast-json-stable-stringify",
|
||||
"keywords": [
|
||||
"json",
|
||||
"stringify",
|
||||
"deterministic",
|
||||
"hash",
|
||||
"stable"
|
||||
],
|
||||
"author": {
|
||||
"name": "James Halliday",
|
||||
"email": "mail@substack.net",
|
||||
"url": "http://substack.net"
|
||||
},
|
||||
"license": "MIT",
|
||||
"nyc": {
|
||||
"exclude": [
|
||||
"test",
|
||||
"node_modules"
|
||||
],
|
||||
"reporter": [
|
||||
"lcov",
|
||||
"text-summary"
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/* @minVersion 7.22.0 */
|
||||
function dispose_SuppressedError(error, suppressed) {
|
||||
if (typeof SuppressedError !== "undefined") {
|
||||
// eslint-disable-next-line no-undef
|
||||
dispose_SuppressedError = SuppressedError;
|
||||
} else {
|
||||
dispose_SuppressedError = function SuppressedError(error, suppressed) {
|
||||
this.suppressed = suppressed;
|
||||
this.error = error;
|
||||
this.stack = new Error().stack;
|
||||
};
|
||||
dispose_SuppressedError.prototype = Object.create(Error.prototype, { constructor: { value: dispose_SuppressedError, writable: true, configurable: true } });
|
||||
}
|
||||
return new dispose_SuppressedError(error, suppressed);
|
||||
}
|
||||
|
||||
function _dispose(stack, error, hasError) {
|
||||
function next() {
|
||||
while (stack.length > 0) {
|
||||
try {
|
||||
var r = stack.pop();
|
||||
var p = r.d.call(r.v);
|
||||
if (r.a) return Promise.resolve(p).then(next, err);
|
||||
} catch (e) {
|
||||
return err(e);
|
||||
}
|
||||
}
|
||||
if (hasError) throw error;
|
||||
}
|
||||
|
||||
function err(e) {
|
||||
error = hasError ? new dispose_SuppressedError(e, error) : e;
|
||||
hasError = true;
|
||||
|
||||
return next();
|
||||
}
|
||||
|
||||
return next();
|
||||
}
|
||||
|
||||
export { _dispose as _ };
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"_blake.js","sourceRoot":"","sources":["../src/_blake.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAElC;;;GAGG;AACH,kBAAkB;AAClB,MAAM,CAAC,MAAM,MAAM,GAAe,eAAe,CAAC,UAAU,CAAC,IAAI,CAAC;IAChE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE;IACpD,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;IACpD,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;IACpD,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC;IACpD,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE;IACpD,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC;IACpD,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE;IACpD,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE;IACpD,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC;IACpD,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC;IACpD,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE;IACpD,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;IACpD,2BAA2B;IAC3B,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;IACpD,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC;IACpD,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE;IACpD,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC;CACrD,CAAC,CAAC;AAKH,0CAA0C;AAC1C,MAAM,UAAU,GAAG,CAAC,CAAS,EAAE,CAAS,EAAE,CAAS,EAAE,CAAS,EAAE,CAAS;IACvE,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;IACpB,CAAC,GAAG,IAAI,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC;IACpB,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;IAChB,CAAC,GAAG,IAAI,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC;IACpB,OAAO,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;AACxB,CAAC;AAED,MAAM,UAAU,GAAG,CAAC,CAAS,EAAE,CAAS,EAAE,CAAS,EAAE,CAAS,EAAE,CAAS;IACvE,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;IACpB,CAAC,GAAG,IAAI,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;IACnB,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;IAChB,CAAC,GAAG,IAAI,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;IACnB,OAAO,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;AACxB,CAAC"}
|
||||
@@ -0,0 +1 @@
|
||||
"use strict";var s=require("node:path"),r=require("node:os");const{geteuid:e}=process,t=e?e():r.userInfo().username,i=s.join(r.tmpdir(),`tsx-${t}`);exports.tmpdir=i;
|
||||
@@ -0,0 +1,41 @@
|
||||
function isSecure(wsComponents) {
|
||||
return typeof wsComponents.secure === 'boolean' ? wsComponents.secure : String(wsComponents.scheme).toLowerCase() === "wss";
|
||||
}
|
||||
//RFC 6455
|
||||
const handler = {
|
||||
scheme: "ws",
|
||||
domainHost: true,
|
||||
parse: function (components, options) {
|
||||
const wsComponents = components;
|
||||
//indicate if the secure flag is set
|
||||
wsComponents.secure = isSecure(wsComponents);
|
||||
//construct resouce name
|
||||
wsComponents.resourceName = (wsComponents.path || '/') + (wsComponents.query ? '?' + wsComponents.query : '');
|
||||
wsComponents.path = undefined;
|
||||
wsComponents.query = undefined;
|
||||
return wsComponents;
|
||||
},
|
||||
serialize: function (wsComponents, options) {
|
||||
//normalize the default port
|
||||
if (wsComponents.port === (isSecure(wsComponents) ? 443 : 80) || wsComponents.port === "") {
|
||||
wsComponents.port = undefined;
|
||||
}
|
||||
//ensure scheme matches secure flag
|
||||
if (typeof wsComponents.secure === 'boolean') {
|
||||
wsComponents.scheme = (wsComponents.secure ? 'wss' : 'ws');
|
||||
wsComponents.secure = undefined;
|
||||
}
|
||||
//reconstruct path from resource name
|
||||
if (wsComponents.resourceName) {
|
||||
const [path, query] = wsComponents.resourceName.split('?');
|
||||
wsComponents.path = (path && path !== '/' ? path : undefined);
|
||||
wsComponents.query = query;
|
||||
wsComponents.resourceName = undefined;
|
||||
}
|
||||
//forbid fragment component
|
||||
wsComponents.fragment = undefined;
|
||||
return wsComponents;
|
||||
}
|
||||
};
|
||||
export default handler;
|
||||
//# sourceMappingURL=ws.js.map
|
||||
@@ -0,0 +1,498 @@
|
||||
declare module "node:os" {
|
||||
import { NonSharedBuffer } from "buffer";
|
||||
interface CpuInfo {
|
||||
model: string;
|
||||
speed: number;
|
||||
times: {
|
||||
/** The number of milliseconds the CPU has spent in user mode. */
|
||||
user: number;
|
||||
/** The number of milliseconds the CPU has spent in nice mode. */
|
||||
nice: number;
|
||||
/** The number of milliseconds the CPU has spent in sys mode. */
|
||||
sys: number;
|
||||
/** The number of milliseconds the CPU has spent in idle mode. */
|
||||
idle: number;
|
||||
/** The number of milliseconds the CPU has spent in irq mode. */
|
||||
irq: number;
|
||||
};
|
||||
}
|
||||
interface NetworkInterfaceBase {
|
||||
address: string;
|
||||
netmask: string;
|
||||
mac: string;
|
||||
internal: boolean;
|
||||
cidr: string | null;
|
||||
scopeid?: number;
|
||||
}
|
||||
interface NetworkInterfaceInfoIPv4 extends NetworkInterfaceBase {
|
||||
family: "IPv4";
|
||||
}
|
||||
interface NetworkInterfaceInfoIPv6 extends NetworkInterfaceBase {
|
||||
family: "IPv6";
|
||||
scopeid: number;
|
||||
}
|
||||
interface UserInfo<T> {
|
||||
username: T;
|
||||
uid: number;
|
||||
gid: number;
|
||||
shell: T | null;
|
||||
homedir: T;
|
||||
}
|
||||
type NetworkInterfaceInfo = NetworkInterfaceInfoIPv4 | NetworkInterfaceInfoIPv6;
|
||||
/**
|
||||
* Returns the host name of the operating system as a string.
|
||||
* @since v0.3.3
|
||||
*/
|
||||
function hostname(): string;
|
||||
/**
|
||||
* Returns an array containing the 1, 5, and 15 minute load averages.
|
||||
*
|
||||
* The load average is a measure of system activity calculated by the operating
|
||||
* system and expressed as a fractional number.
|
||||
*
|
||||
* The load average is a Unix-specific concept. On Windows, the return value is
|
||||
* always `[0, 0, 0]`.
|
||||
* @since v0.3.3
|
||||
*/
|
||||
function loadavg(): number[];
|
||||
/**
|
||||
* Returns the system uptime in number of seconds.
|
||||
* @since v0.3.3
|
||||
*/
|
||||
function uptime(): number;
|
||||
/**
|
||||
* Returns the amount of free system memory in bytes as an integer.
|
||||
* @since v0.3.3
|
||||
*/
|
||||
function freemem(): number;
|
||||
/**
|
||||
* Returns the total amount of system memory in bytes as an integer.
|
||||
* @since v0.3.3
|
||||
*/
|
||||
function totalmem(): number;
|
||||
/**
|
||||
* Returns an array of objects containing information about each logical CPU core.
|
||||
* The array will be empty if no CPU information is available, such as if the `/proc` file system is unavailable.
|
||||
*
|
||||
* The properties included on each object include:
|
||||
*
|
||||
* ```js
|
||||
* [
|
||||
* {
|
||||
* model: 'Intel(R) Core(TM) i7 CPU 860 @ 2.80GHz',
|
||||
* speed: 2926,
|
||||
* times: {
|
||||
* user: 252020,
|
||||
* nice: 0,
|
||||
* sys: 30340,
|
||||
* idle: 1070356870,
|
||||
* irq: 0,
|
||||
* },
|
||||
* },
|
||||
* {
|
||||
* model: 'Intel(R) Core(TM) i7 CPU 860 @ 2.80GHz',
|
||||
* speed: 2926,
|
||||
* times: {
|
||||
* user: 306960,
|
||||
* nice: 0,
|
||||
* sys: 26980,
|
||||
* idle: 1071569080,
|
||||
* irq: 0,
|
||||
* },
|
||||
* },
|
||||
* {
|
||||
* model: 'Intel(R) Core(TM) i7 CPU 860 @ 2.80GHz',
|
||||
* speed: 2926,
|
||||
* times: {
|
||||
* user: 248450,
|
||||
* nice: 0,
|
||||
* sys: 21750,
|
||||
* idle: 1070919370,
|
||||
* irq: 0,
|
||||
* },
|
||||
* },
|
||||
* {
|
||||
* model: 'Intel(R) Core(TM) i7 CPU 860 @ 2.80GHz',
|
||||
* speed: 2926,
|
||||
* times: {
|
||||
* user: 256880,
|
||||
* nice: 0,
|
||||
* sys: 19430,
|
||||
* idle: 1070905480,
|
||||
* irq: 20,
|
||||
* },
|
||||
* },
|
||||
* ];
|
||||
* ```
|
||||
*
|
||||
* `nice` values are POSIX-only. On Windows, the `nice` values of all processors
|
||||
* are always 0.
|
||||
*
|
||||
* `os.cpus().length` should not be used to calculate the amount of parallelism
|
||||
* available to an application. Use {@link availableParallelism} for this purpose.
|
||||
* @since v0.3.3
|
||||
*/
|
||||
function cpus(): CpuInfo[];
|
||||
/**
|
||||
* Returns an estimate of the default amount of parallelism a program should use.
|
||||
* Always returns a value greater than zero.
|
||||
*
|
||||
* This function is a small wrapper about libuv's [`uv_available_parallelism()`](https://docs.libuv.org/en/v1.x/misc.html#c.uv_available_parallelism).
|
||||
* @since v19.4.0, v18.14.0
|
||||
*/
|
||||
function availableParallelism(): number;
|
||||
/**
|
||||
* Returns the operating system name as returned by [`uname(3)`](https://linux.die.net/man/3/uname). For example, it
|
||||
* returns `'Linux'` on Linux, `'Darwin'` on macOS, and `'Windows_NT'` on Windows.
|
||||
*
|
||||
* See [https://en.wikipedia.org/wiki/Uname#Examples](https://en.wikipedia.org/wiki/Uname#Examples) for additional information
|
||||
* about the output of running [`uname(3)`](https://linux.die.net/man/3/uname) on various operating systems.
|
||||
* @since v0.3.3
|
||||
*/
|
||||
function type(): string;
|
||||
/**
|
||||
* Returns the operating system as a string.
|
||||
*
|
||||
* On POSIX systems, the operating system release is determined by calling [`uname(3)`](https://linux.die.net/man/3/uname). On Windows, `GetVersionExW()` is used. See
|
||||
* [https://en.wikipedia.org/wiki/Uname#Examples](https://en.wikipedia.org/wiki/Uname#Examples) for more information.
|
||||
* @since v0.3.3
|
||||
*/
|
||||
function release(): string;
|
||||
/**
|
||||
* Returns an object containing network interfaces that have been assigned a
|
||||
* network address.
|
||||
*
|
||||
* Each key on the returned object identifies a network interface. The associated
|
||||
* value is an array of objects that each describe an assigned network address.
|
||||
*
|
||||
* The properties available on the assigned network address object include:
|
||||
*
|
||||
* ```json
|
||||
* {
|
||||
* "lo": [
|
||||
* {
|
||||
* "address:": "127.0.0.1",
|
||||
* "netmask:": "255.0.0.0",
|
||||
* "family:": "IPv4",
|
||||
* "mac:": "00:00:00:00:00:00",
|
||||
* "internal:": true,
|
||||
* "cidr:": "127.0.0.1/8"
|
||||
* },
|
||||
* {
|
||||
* "address:": "::1",
|
||||
* "netmask:": "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff",
|
||||
* "family:": "IPv6",
|
||||
* "mac:": "00:00:00:00:00:00",
|
||||
* "scopeid:": 0,
|
||||
* "internal:": true,
|
||||
* "cidr:": "::1/128"
|
||||
* }
|
||||
* ],
|
||||
* "eth0": [
|
||||
* {
|
||||
* "address:": "192.168.1.108",
|
||||
* "netmask:": "255.255.255.0",
|
||||
* "family:": "IPv4",
|
||||
* "mac:": "01:02:03:0a:0b:0c",
|
||||
* "internal:": false,
|
||||
* "cidr:": "192.168.1.108/24"
|
||||
* },
|
||||
* {
|
||||
* "address:": "fe80::a00:27ff:fe4e:66a1",
|
||||
* "netmask:": "ffff:ffff:ffff:ffff::",
|
||||
* "family:": "IPv6",
|
||||
* "mac:": "01:02:03:0a:0b:0c",
|
||||
* "scopeid:": 1,
|
||||
* "internal:": false,
|
||||
* "cidr:": "fe80::a00:27ff:fe4e:66a1/64"
|
||||
* }
|
||||
* ]
|
||||
* }
|
||||
* ```
|
||||
* @since v0.6.0
|
||||
*/
|
||||
function networkInterfaces(): NodeJS.Dict<NetworkInterfaceInfo[]>;
|
||||
/**
|
||||
* Returns the string path of the current user's home directory.
|
||||
*
|
||||
* On POSIX, it uses the `$HOME` environment variable if defined. Otherwise it
|
||||
* uses the [effective UID](https://en.wikipedia.org/wiki/User_identifier#Effective_user_ID) to look up the user's home directory.
|
||||
*
|
||||
* On Windows, it uses the `USERPROFILE` environment variable if defined.
|
||||
* Otherwise it uses the path to the profile directory of the current user.
|
||||
* @since v2.3.0
|
||||
*/
|
||||
function homedir(): string;
|
||||
interface UserInfoOptions {
|
||||
encoding?: BufferEncoding | "buffer" | undefined;
|
||||
}
|
||||
interface UserInfoOptionsWithBufferEncoding extends UserInfoOptions {
|
||||
encoding: "buffer";
|
||||
}
|
||||
interface UserInfoOptionsWithStringEncoding extends UserInfoOptions {
|
||||
encoding?: BufferEncoding | undefined;
|
||||
}
|
||||
/**
|
||||
* Returns information about the currently effective user. On POSIX platforms,
|
||||
* this is typically a subset of the password file. The returned object includes
|
||||
* the `username`, `uid`, `gid`, `shell`, and `homedir`. On Windows, the `uid` and `gid` fields are `-1`, and `shell` is `null`.
|
||||
*
|
||||
* The value of `homedir` returned by `os.userInfo()` is provided by the operating
|
||||
* system. This differs from the result of `os.homedir()`, which queries
|
||||
* environment variables for the home directory before falling back to the
|
||||
* operating system response.
|
||||
*
|
||||
* Throws a [`SystemError`](https://nodejs.org/docs/latest-v26.x/api/errors.html#class-systemerror) if a user has no `username` or `homedir`.
|
||||
* @since v6.0.0
|
||||
*/
|
||||
function userInfo(options?: UserInfoOptionsWithStringEncoding): UserInfo<string>;
|
||||
function userInfo(options: UserInfoOptionsWithBufferEncoding): UserInfo<NonSharedBuffer>;
|
||||
function userInfo(options: UserInfoOptions): UserInfo<string | NonSharedBuffer>;
|
||||
type SignalConstants = {
|
||||
[key in NodeJS.Signals]: number;
|
||||
};
|
||||
namespace constants {
|
||||
const UV_UDP_REUSEADDR: number;
|
||||
namespace signals {}
|
||||
const signals: SignalConstants;
|
||||
namespace errno {
|
||||
const E2BIG: number;
|
||||
const EACCES: number;
|
||||
const EADDRINUSE: number;
|
||||
const EADDRNOTAVAIL: number;
|
||||
const EAFNOSUPPORT: number;
|
||||
const EAGAIN: number;
|
||||
const EALREADY: number;
|
||||
const EBADF: number;
|
||||
const EBADMSG: number;
|
||||
const EBUSY: number;
|
||||
const ECANCELED: number;
|
||||
const ECHILD: number;
|
||||
const ECONNABORTED: number;
|
||||
const ECONNREFUSED: number;
|
||||
const ECONNRESET: number;
|
||||
const EDEADLK: number;
|
||||
const EDESTADDRREQ: number;
|
||||
const EDOM: number;
|
||||
const EDQUOT: number;
|
||||
const EEXIST: number;
|
||||
const EFAULT: number;
|
||||
const EFBIG: number;
|
||||
const EHOSTUNREACH: number;
|
||||
const EIDRM: number;
|
||||
const EILSEQ: number;
|
||||
const EINPROGRESS: number;
|
||||
const EINTR: number;
|
||||
const EINVAL: number;
|
||||
const EIO: number;
|
||||
const EISCONN: number;
|
||||
const EISDIR: number;
|
||||
const ELOOP: number;
|
||||
const EMFILE: number;
|
||||
const EMLINK: number;
|
||||
const EMSGSIZE: number;
|
||||
const EMULTIHOP: number;
|
||||
const ENAMETOOLONG: number;
|
||||
const ENETDOWN: number;
|
||||
const ENETRESET: number;
|
||||
const ENETUNREACH: number;
|
||||
const ENFILE: number;
|
||||
const ENOBUFS: number;
|
||||
const ENODATA: number;
|
||||
const ENODEV: number;
|
||||
const ENOENT: number;
|
||||
const ENOEXEC: number;
|
||||
const ENOLCK: number;
|
||||
const ENOLINK: number;
|
||||
const ENOMEM: number;
|
||||
const ENOMSG: number;
|
||||
const ENOPROTOOPT: number;
|
||||
const ENOSPC: number;
|
||||
const ENOSR: number;
|
||||
const ENOSTR: number;
|
||||
const ENOSYS: number;
|
||||
const ENOTCONN: number;
|
||||
const ENOTDIR: number;
|
||||
const ENOTEMPTY: number;
|
||||
const ENOTSOCK: number;
|
||||
const ENOTSUP: number;
|
||||
const ENOTTY: number;
|
||||
const ENXIO: number;
|
||||
const EOPNOTSUPP: number;
|
||||
const EOVERFLOW: number;
|
||||
const EPERM: number;
|
||||
const EPIPE: number;
|
||||
const EPROTO: number;
|
||||
const EPROTONOSUPPORT: number;
|
||||
const EPROTOTYPE: number;
|
||||
const ERANGE: number;
|
||||
const EROFS: number;
|
||||
const ESPIPE: number;
|
||||
const ESRCH: number;
|
||||
const ESTALE: number;
|
||||
const ETIME: number;
|
||||
const ETIMEDOUT: number;
|
||||
const ETXTBSY: number;
|
||||
const EWOULDBLOCK: number;
|
||||
const EXDEV: number;
|
||||
const WSAEINTR: number;
|
||||
const WSAEBADF: number;
|
||||
const WSAEACCES: number;
|
||||
const WSAEFAULT: number;
|
||||
const WSAEINVAL: number;
|
||||
const WSAEMFILE: number;
|
||||
const WSAEWOULDBLOCK: number;
|
||||
const WSAEINPROGRESS: number;
|
||||
const WSAEALREADY: number;
|
||||
const WSAENOTSOCK: number;
|
||||
const WSAEDESTADDRREQ: number;
|
||||
const WSAEMSGSIZE: number;
|
||||
const WSAEPROTOTYPE: number;
|
||||
const WSAENOPROTOOPT: number;
|
||||
const WSAEPROTONOSUPPORT: number;
|
||||
const WSAESOCKTNOSUPPORT: number;
|
||||
const WSAEOPNOTSUPP: number;
|
||||
const WSAEPFNOSUPPORT: number;
|
||||
const WSAEAFNOSUPPORT: number;
|
||||
const WSAEADDRINUSE: number;
|
||||
const WSAEADDRNOTAVAIL: number;
|
||||
const WSAENETDOWN: number;
|
||||
const WSAENETUNREACH: number;
|
||||
const WSAENETRESET: number;
|
||||
const WSAECONNABORTED: number;
|
||||
const WSAECONNRESET: number;
|
||||
const WSAENOBUFS: number;
|
||||
const WSAEISCONN: number;
|
||||
const WSAENOTCONN: number;
|
||||
const WSAESHUTDOWN: number;
|
||||
const WSAETOOMANYREFS: number;
|
||||
const WSAETIMEDOUT: number;
|
||||
const WSAECONNREFUSED: number;
|
||||
const WSAELOOP: number;
|
||||
const WSAENAMETOOLONG: number;
|
||||
const WSAEHOSTDOWN: number;
|
||||
const WSAEHOSTUNREACH: number;
|
||||
const WSAENOTEMPTY: number;
|
||||
const WSAEPROCLIM: number;
|
||||
const WSAEUSERS: number;
|
||||
const WSAEDQUOT: number;
|
||||
const WSAESTALE: number;
|
||||
const WSAEREMOTE: number;
|
||||
const WSASYSNOTREADY: number;
|
||||
const WSAVERNOTSUPPORTED: number;
|
||||
const WSANOTINITIALISED: number;
|
||||
const WSAEDISCON: number;
|
||||
const WSAENOMORE: number;
|
||||
const WSAECANCELLED: number;
|
||||
const WSAEINVALIDPROCTABLE: number;
|
||||
const WSAEINVALIDPROVIDER: number;
|
||||
const WSAEPROVIDERFAILEDINIT: number;
|
||||
const WSASYSCALLFAILURE: number;
|
||||
const WSASERVICE_NOT_FOUND: number;
|
||||
const WSATYPE_NOT_FOUND: number;
|
||||
const WSA_E_NO_MORE: number;
|
||||
const WSA_E_CANCELLED: number;
|
||||
const WSAEREFUSED: number;
|
||||
}
|
||||
namespace dlopen {
|
||||
const RTLD_LAZY: number;
|
||||
const RTLD_NOW: number;
|
||||
const RTLD_GLOBAL: number;
|
||||
const RTLD_LOCAL: number;
|
||||
const RTLD_DEEPBIND: number;
|
||||
}
|
||||
namespace priority {
|
||||
const PRIORITY_LOW: number;
|
||||
const PRIORITY_BELOW_NORMAL: number;
|
||||
const PRIORITY_NORMAL: number;
|
||||
const PRIORITY_ABOVE_NORMAL: number;
|
||||
const PRIORITY_HIGH: number;
|
||||
const PRIORITY_HIGHEST: number;
|
||||
}
|
||||
}
|
||||
const devNull: string;
|
||||
/**
|
||||
* The operating system-specific end-of-line marker.
|
||||
* * `\n` on POSIX
|
||||
* * `\r\n` on Windows
|
||||
*/
|
||||
const EOL: string;
|
||||
/**
|
||||
* Returns the operating system CPU architecture for which the Node.js binary was
|
||||
* compiled. Possible values are `'arm'`, `'arm64'`, `'ia32'`, `'loong64'`,
|
||||
* `'mips'`, `'mipsel'`, `'ppc64'`, `'riscv64'`, `'s390x'`, and `'x64'`.
|
||||
*
|
||||
* The return value is equivalent to [process.arch](https://nodejs.org/docs/latest-v26.x/api/process.html#processarch).
|
||||
* @since v0.5.0
|
||||
*/
|
||||
function arch(): NodeJS.Architecture;
|
||||
/**
|
||||
* Returns a string identifying the kernel version.
|
||||
*
|
||||
* On POSIX systems, the operating system release is determined by calling [`uname(3)`](https://linux.die.net/man/3/uname). On Windows, `RtlGetVersion()` is used, and if it is not
|
||||
* available, `GetVersionExW()` will be used. See [https://en.wikipedia.org/wiki/Uname#Examples](https://en.wikipedia.org/wiki/Uname#Examples) for more information.
|
||||
* @since v13.11.0, v12.17.0
|
||||
*/
|
||||
function version(): string;
|
||||
/**
|
||||
* Returns a string identifying the operating system platform for which
|
||||
* the Node.js binary was compiled. The value is set at compile time.
|
||||
* Possible values are `'aix'`, `'darwin'`, `'freebsd'`, `'linux'`, `'openbsd'`, `'sunos'`, and `'win32'`.
|
||||
*
|
||||
* The return value is equivalent to `process.platform`.
|
||||
*
|
||||
* The value `'android'` may also be returned if Node.js is built on the Android
|
||||
* operating system. [Android support is experimental](https://github.com/nodejs/node/blob/HEAD/BUILDING.md#androidandroid-based-devices-eg-firefox-os).
|
||||
* @since v0.5.0
|
||||
*/
|
||||
function platform(): NodeJS.Platform;
|
||||
/**
|
||||
* Returns the machine type as a string, such as `arm`, `arm64`, `aarch64`,
|
||||
* `mips`, `mips64`, `ppc64`, `ppc64le`, `s390x`, `i386`, `i686`, `x86_64`.
|
||||
*
|
||||
* On POSIX systems, the machine type is determined by calling [`uname(3)`](https://linux.die.net/man/3/uname). On Windows, `RtlGetVersion()` is used, and if it is not
|
||||
* available, `GetVersionExW()` will be used. See [https://en.wikipedia.org/wiki/Uname#Examples](https://en.wikipedia.org/wiki/Uname#Examples) for more information.
|
||||
* @since v18.9.0, v16.18.0
|
||||
*/
|
||||
function machine(): string;
|
||||
/**
|
||||
* Returns the operating system's default directory for temporary files as a
|
||||
* string.
|
||||
* @since v0.9.9
|
||||
*/
|
||||
function tmpdir(): string;
|
||||
/**
|
||||
* Returns a string identifying the endianness of the CPU for which the Node.js
|
||||
* binary was compiled.
|
||||
*
|
||||
* Possible values are `'BE'` for big endian and `'LE'` for little endian.
|
||||
* @since v0.9.4
|
||||
*/
|
||||
function endianness(): "BE" | "LE";
|
||||
/**
|
||||
* Returns the scheduling priority for the process specified by `pid`. If `pid` is
|
||||
* not provided or is `0`, the priority of the current process is returned.
|
||||
* @since v10.10.0
|
||||
* @param [pid=0] The process ID to retrieve scheduling priority for.
|
||||
*/
|
||||
function getPriority(pid?: number): number;
|
||||
/**
|
||||
* Attempts to set the scheduling priority for the process specified by `pid`. If `pid` is not provided or is `0`, the process ID of the current process is used.
|
||||
*
|
||||
* The `priority` input must be an integer between `-20` (high priority) and `19` (low priority). Due to differences between Unix priority levels and Windows
|
||||
* priority classes, `priority` is mapped to one of six priority constants in `os.constants.priority`. When retrieving a process priority level, this range
|
||||
* mapping may cause the return value to be slightly different on Windows. To avoid
|
||||
* confusion, set `priority` to one of the priority constants.
|
||||
*
|
||||
* On Windows, setting priority to `PRIORITY_HIGHEST` requires elevated user
|
||||
* privileges. Otherwise the set priority will be silently reduced to `PRIORITY_HIGH`.
|
||||
* @since v10.10.0
|
||||
* @param [pid=0] The process ID to set scheduling priority for.
|
||||
* @param priority The scheduling priority to assign to the process.
|
||||
*/
|
||||
function setPriority(priority: number): void;
|
||||
function setPriority(pid: number, priority: number): void;
|
||||
}
|
||||
declare module "os" {
|
||||
export * from "node:os";
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"pasta.d.ts","sourceRoot":"","sources":["src/pasta.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,MAAM,IAAI,EAAE,EAAE,KAAK,IAAI,EAAE,EAAE,MAAM,WAAW,CAAC;AACtD,kBAAkB;AAClB,eAAO,MAAM,MAAM,EAAE,OAAO,EAAO,CAAC;AACpC,kBAAkB;AAClB,eAAO,MAAM,KAAK,EAAE,OAAO,EAAO,CAAC"}
|
||||
@@ -0,0 +1,140 @@
|
||||
/**
|
||||
* @fileoverview Rule to require sorting of variables within a single Variable Declaration block
|
||||
* @author Ilya Volodin
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Rule Definition
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/** @type {import('../types').Rule.RuleModule} */
|
||||
module.exports = {
|
||||
meta: {
|
||||
type: "suggestion",
|
||||
|
||||
defaultOptions: [
|
||||
{
|
||||
ignoreCase: false,
|
||||
},
|
||||
],
|
||||
|
||||
docs: {
|
||||
description:
|
||||
"Require variables within the same declaration block to be sorted",
|
||||
recommended: false,
|
||||
frozen: true,
|
||||
url: "https://eslint.org/docs/latest/rules/sort-vars",
|
||||
},
|
||||
|
||||
schema: [
|
||||
{
|
||||
type: "object",
|
||||
properties: {
|
||||
ignoreCase: {
|
||||
type: "boolean",
|
||||
},
|
||||
},
|
||||
additionalProperties: false,
|
||||
},
|
||||
],
|
||||
|
||||
fixable: "code",
|
||||
|
||||
messages: {
|
||||
sortVars:
|
||||
"Variables within the same declaration block should be sorted alphabetically.",
|
||||
},
|
||||
},
|
||||
|
||||
create(context) {
|
||||
const [{ ignoreCase }] = context.options;
|
||||
const sourceCode = context.sourceCode;
|
||||
|
||||
return {
|
||||
VariableDeclaration(node) {
|
||||
const idDeclarations = node.declarations.filter(
|
||||
decl => decl.id.type === "Identifier",
|
||||
);
|
||||
const getSortableName = ignoreCase
|
||||
? decl => decl.id.name.toLowerCase()
|
||||
: decl => decl.id.name;
|
||||
const unfixable = idDeclarations.some(
|
||||
decl => decl.init !== null && decl.init.type !== "Literal",
|
||||
);
|
||||
let fixed = false;
|
||||
|
||||
idDeclarations.slice(1).reduce((memo, decl) => {
|
||||
const lastVariableName = getSortableName(memo),
|
||||
currentVariableName = getSortableName(decl);
|
||||
|
||||
if (currentVariableName < lastVariableName) {
|
||||
context.report({
|
||||
node: decl,
|
||||
messageId: "sortVars",
|
||||
fix(fixer) {
|
||||
if (unfixable || fixed) {
|
||||
return null;
|
||||
}
|
||||
return fixer.replaceTextRange(
|
||||
[
|
||||
idDeclarations[0].range[0],
|
||||
idDeclarations.at(-1).range[1],
|
||||
],
|
||||
idDeclarations
|
||||
|
||||
// Clone the idDeclarations array to avoid mutating it
|
||||
.slice()
|
||||
|
||||
// Sort the array into the desired order
|
||||
.sort((declA, declB) => {
|
||||
const aName =
|
||||
getSortableName(declA);
|
||||
const bName =
|
||||
getSortableName(declB);
|
||||
|
||||
return aName > bName ? 1 : -1;
|
||||
})
|
||||
|
||||
// Build a string out of the sorted list of identifier declarations and the text between the originals
|
||||
.reduce(
|
||||
(sourceText, identifier, index) => {
|
||||
const textAfterIdentifier =
|
||||
index ===
|
||||
idDeclarations.length - 1
|
||||
? ""
|
||||
: sourceCode
|
||||
.getText()
|
||||
.slice(
|
||||
idDeclarations[
|
||||
index
|
||||
].range[1],
|
||||
idDeclarations[
|
||||
index +
|
||||
1
|
||||
].range[0],
|
||||
);
|
||||
|
||||
return (
|
||||
sourceText +
|
||||
sourceCode.getText(
|
||||
identifier,
|
||||
) +
|
||||
textAfterIdentifier
|
||||
);
|
||||
},
|
||||
"",
|
||||
),
|
||||
);
|
||||
},
|
||||
});
|
||||
fixed = true;
|
||||
return memo;
|
||||
}
|
||||
return decl;
|
||||
}, idDeclarations[0]);
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,30 @@
|
||||
import { expectType } from "tsd";
|
||||
|
||||
import * as pinoStar from "../../pino";
|
||||
import { default as P, default as pino, pino as pinoNamed } from '../../pino';
|
||||
import pinoCjsImport = require ("../../pino");
|
||||
const pinoCjs = require("../../pino");
|
||||
const { P: pinoCjsNamed } = require('pino')
|
||||
|
||||
const log = pino();
|
||||
expectType<P.LogFn>(log.info);
|
||||
expectType<P.LogFn>(log.error);
|
||||
|
||||
expectType<pino.Logger>(pinoNamed());
|
||||
expectType<P.Logger>(pinoNamed());
|
||||
expectType<pino.Logger>(pinoStar.default());
|
||||
expectType<pino.Logger>(pinoStar.pino());
|
||||
// expectType<pino.Logger>(pinoCjsImport.default());
|
||||
expectType<pino.Logger>(pinoCjsImport.pino());
|
||||
expectType<any>(pinoCjsNamed());
|
||||
expectType<any>(pinoCjs());
|
||||
expectType<P.TimeFn>(pinoNamed.stdTimeFunctions.isoTimeNano)
|
||||
expectType<string>(pinoNamed.stdTimeFunctions.isoTimeNano())
|
||||
|
||||
const levelChangeEventListener: P.LevelChangeEventListener = (
|
||||
lvl: P.LevelWithSilent | string,
|
||||
val: number,
|
||||
prevLvl: P.LevelWithSilent | string,
|
||||
prevVal: number,
|
||||
) => {}
|
||||
expectType<P.LevelChangeEventListener>(levelChangeEventListener)
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"extends": [
|
||||
"standard"
|
||||
],
|
||||
"rules": {
|
||||
"no-var": "off"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,893 @@
|
||||
'use strict'
|
||||
|
||||
const test = require('node:test')
|
||||
const assert = require('node:assert')
|
||||
|
||||
const { sink, once } = require('./helper')
|
||||
const pino = require('../')
|
||||
|
||||
test('redact option – throws if not array', async () => {
|
||||
assert.throws(() => {
|
||||
pino({ redact: 'req.headers.cookie' })
|
||||
})
|
||||
})
|
||||
|
||||
test('redact option – throws if array does not only contain strings', async () => {
|
||||
assert.throws(() => {
|
||||
pino({ redact: ['req.headers.cookie', {}] })
|
||||
})
|
||||
})
|
||||
|
||||
test('redact option – throws if array contains an invalid path', async () => {
|
||||
assert.throws(() => {
|
||||
pino({ redact: ['req,headers.cookie'] })
|
||||
})
|
||||
})
|
||||
|
||||
test('redact.paths option – throws if not array', async () => {
|
||||
assert.throws(() => {
|
||||
pino({ redact: { paths: 'req.headers.cookie' } })
|
||||
})
|
||||
})
|
||||
|
||||
test('redact.paths option – throws if array does not only contain strings', async () => {
|
||||
assert.throws(() => {
|
||||
pino({ redact: { paths: ['req.headers.cookie', {}] } })
|
||||
})
|
||||
})
|
||||
|
||||
test('redact.paths option – throws if array contains an invalid path', async () => {
|
||||
assert.throws(() => {
|
||||
pino({ redact: { paths: ['req,headers.cookie'] } })
|
||||
})
|
||||
})
|
||||
|
||||
test('redact option – top level key', async () => {
|
||||
const stream = sink()
|
||||
const instance = pino({ redact: ['key'] }, stream)
|
||||
instance.info({
|
||||
key: { redact: 'me' }
|
||||
})
|
||||
const { key } = await once(stream, 'data')
|
||||
assert.equal(key, '[Redacted]')
|
||||
})
|
||||
|
||||
test('redact option – top level key next level key', async () => {
|
||||
const stream = sink()
|
||||
const instance = pino({ redact: ['key', 'key.foo'] }, stream)
|
||||
instance.info({
|
||||
key: { redact: 'me' }
|
||||
})
|
||||
const { key } = await once(stream, 'data')
|
||||
assert.equal(key, '[Redacted]')
|
||||
})
|
||||
|
||||
test('redact option – next level key then top level key', async () => {
|
||||
const stream = sink()
|
||||
const instance = pino({ redact: ['key.foo', 'key'] }, stream)
|
||||
instance.info({
|
||||
key: { redact: 'me' }
|
||||
})
|
||||
const { key } = await once(stream, 'data')
|
||||
assert.equal(key, '[Redacted]')
|
||||
})
|
||||
|
||||
test('redact option – object', async () => {
|
||||
const stream = sink()
|
||||
const instance = pino({ redact: ['req.headers.cookie'] }, stream)
|
||||
instance.info({
|
||||
req: {
|
||||
id: 7915,
|
||||
method: 'GET',
|
||||
url: '/',
|
||||
headers: {
|
||||
host: 'localhost:3000',
|
||||
connection: 'keep-alive',
|
||||
cookie: 'SESSID=298zf09hf012fh2; csrftoken=u32t4o3tb3gg43; _gat=1;'
|
||||
},
|
||||
remoteAddress: '::ffff:127.0.0.1',
|
||||
remotePort: 58022
|
||||
}
|
||||
})
|
||||
const { req } = await once(stream, 'data')
|
||||
assert.equal(req.headers.cookie, '[Redacted]')
|
||||
})
|
||||
|
||||
test('redact option – child object', async () => {
|
||||
const stream = sink()
|
||||
const instance = pino({ redact: ['req.headers.cookie'] }, stream)
|
||||
instance.child({
|
||||
req: {
|
||||
id: 7915,
|
||||
method: 'GET',
|
||||
url: '/',
|
||||
headers: {
|
||||
host: 'localhost:3000',
|
||||
connection: 'keep-alive',
|
||||
cookie: 'SESSID=298zf09hf012fh2; csrftoken=u32t4o3tb3gg43; _gat=1;'
|
||||
},
|
||||
remoteAddress: '::ffff:127.0.0.1',
|
||||
remotePort: 58022
|
||||
}
|
||||
}).info('message completed')
|
||||
const { req } = await once(stream, 'data')
|
||||
assert.equal(req.headers.cookie, '[Redacted]')
|
||||
})
|
||||
|
||||
test('redact option – interpolated object', async () => {
|
||||
const stream = sink()
|
||||
const instance = pino({ redact: ['req.headers.cookie'] }, stream)
|
||||
|
||||
instance.info('test %j', {
|
||||
req: {
|
||||
id: 7915,
|
||||
method: 'GET',
|
||||
url: '/',
|
||||
headers: {
|
||||
host: 'localhost:3000',
|
||||
connection: 'keep-alive',
|
||||
cookie: 'SESSID=298zf09hf012fh2; csrftoken=u32t4o3tb3gg43; _gat=1;'
|
||||
},
|
||||
remoteAddress: '::ffff:127.0.0.1',
|
||||
remotePort: 58022
|
||||
}
|
||||
})
|
||||
const { msg } = await once(stream, 'data')
|
||||
assert.equal(JSON.parse(msg.replace(/test /, '')).req.headers.cookie, '[Redacted]')
|
||||
})
|
||||
|
||||
test('redact.paths option – object', async () => {
|
||||
const stream = sink()
|
||||
const instance = pino({ redact: { paths: ['req.headers.cookie'] } }, stream)
|
||||
instance.info({
|
||||
req: {
|
||||
id: 7915,
|
||||
method: 'GET',
|
||||
url: '/',
|
||||
headers: {
|
||||
host: 'localhost:3000',
|
||||
connection: 'keep-alive',
|
||||
cookie: 'SESSID=298zf09hf012fh2; csrftoken=u32t4o3tb3gg43; _gat=1;'
|
||||
},
|
||||
remoteAddress: '::ffff:127.0.0.1',
|
||||
remotePort: 58022
|
||||
}
|
||||
})
|
||||
const { req } = await once(stream, 'data')
|
||||
assert.equal(req.headers.cookie, '[Redacted]')
|
||||
})
|
||||
|
||||
test('redact.paths option – child object', async () => {
|
||||
const stream = sink()
|
||||
const instance = pino({ redact: { paths: ['req.headers.cookie'] } }, stream)
|
||||
instance.child({
|
||||
req: {
|
||||
id: 7915,
|
||||
method: 'GET',
|
||||
url: '/',
|
||||
headers: {
|
||||
host: 'localhost:3000',
|
||||
connection: 'keep-alive',
|
||||
cookie: 'SESSID=298zf09hf012fh2; csrftoken=u32t4o3tb3gg43; _gat=1;'
|
||||
},
|
||||
remoteAddress: '::ffff:127.0.0.1',
|
||||
remotePort: 58022
|
||||
}
|
||||
}).info('message completed')
|
||||
const { req } = await once(stream, 'data')
|
||||
assert.equal(req.headers.cookie, '[Redacted]')
|
||||
})
|
||||
|
||||
test('redact.paths option – interpolated object', async () => {
|
||||
const stream = sink()
|
||||
const instance = pino({ redact: { paths: ['req.headers.cookie'] } }, stream)
|
||||
|
||||
instance.info('test %j', {
|
||||
req: {
|
||||
id: 7915,
|
||||
method: 'GET',
|
||||
url: '/',
|
||||
headers: {
|
||||
host: 'localhost:3000',
|
||||
connection: 'keep-alive',
|
||||
cookie: 'SESSID=298zf09hf012fh2; csrftoken=u32t4o3tb3gg43; _gat=1;'
|
||||
},
|
||||
remoteAddress: '::ffff:127.0.0.1',
|
||||
remotePort: 58022
|
||||
}
|
||||
})
|
||||
const { msg } = await once(stream, 'data')
|
||||
assert.equal(JSON.parse(msg.replace(/test /, '')).req.headers.cookie, '[Redacted]')
|
||||
})
|
||||
|
||||
test('redact.censor option – sets the redact value', async () => {
|
||||
const stream = sink()
|
||||
const instance = pino({ redact: { paths: ['req.headers.cookie'], censor: 'test' } }, stream)
|
||||
instance.info({
|
||||
req: {
|
||||
id: 7915,
|
||||
method: 'GET',
|
||||
url: '/',
|
||||
headers: {
|
||||
host: 'localhost:3000',
|
||||
connection: 'keep-alive',
|
||||
cookie: 'SESSID=298zf09hf012fh2; csrftoken=u32t4o3tb3gg43; _gat=1;'
|
||||
},
|
||||
remoteAddress: '::ffff:127.0.0.1',
|
||||
remotePort: 58022
|
||||
}
|
||||
})
|
||||
const { req } = await once(stream, 'data')
|
||||
assert.equal(req.headers.cookie, 'test')
|
||||
})
|
||||
|
||||
test('redact.censor option – can be a function that accepts value and path arguments', async () => {
|
||||
const stream = sink()
|
||||
const instance = pino({ redact: { paths: ['topLevel'], censor: (value, path) => value + ' ' + path.join('.') } }, stream)
|
||||
instance.info({
|
||||
topLevel: 'test'
|
||||
})
|
||||
const { topLevel } = await once(stream, 'data')
|
||||
assert.equal(topLevel, 'test topLevel')
|
||||
})
|
||||
|
||||
test('redact.censor option – can be a function that accepts value and path arguments (nested path)', async () => {
|
||||
const stream = sink()
|
||||
const instance = pino({ redact: { paths: ['req.headers.cookie'], censor: (value, path) => value + ' ' + path.join('.') } }, stream)
|
||||
instance.info({
|
||||
req: {
|
||||
id: 7915,
|
||||
method: 'GET',
|
||||
url: '/',
|
||||
headers: {
|
||||
host: 'localhost:3000',
|
||||
connection: 'keep-alive',
|
||||
cookie: 'SESSID=298zf09hf012fh2; csrftoken=u32t4o3tb3gg43; _gat=1;'
|
||||
},
|
||||
remoteAddress: '::ffff:127.0.0.1',
|
||||
remotePort: 58022
|
||||
}
|
||||
})
|
||||
const { req } = await once(stream, 'data')
|
||||
assert.equal(req.headers.cookie, 'SESSID=298zf09hf012fh2; csrftoken=u32t4o3tb3gg43; _gat=1; req.headers.cookie')
|
||||
})
|
||||
|
||||
test('redact.remove option – removes both key and value', async () => {
|
||||
const stream = sink()
|
||||
const instance = pino({ redact: { paths: ['req.headers.cookie'], remove: true } }, stream)
|
||||
instance.info({
|
||||
req: {
|
||||
id: 7915,
|
||||
method: 'GET',
|
||||
url: '/',
|
||||
headers: {
|
||||
host: 'localhost:3000',
|
||||
connection: 'keep-alive',
|
||||
cookie: 'SESSID=298zf09hf012fh2; csrftoken=u32t4o3tb3gg43; _gat=1;'
|
||||
},
|
||||
remoteAddress: '::ffff:127.0.0.1',
|
||||
remotePort: 58022
|
||||
}
|
||||
})
|
||||
const { req } = await once(stream, 'data')
|
||||
assert.equal('cookie' in req.headers, false)
|
||||
})
|
||||
|
||||
test('redact.remove – top level key - object value', async () => {
|
||||
const stream = sink()
|
||||
const instance = pino({ redact: { paths: ['key'], remove: true } }, stream)
|
||||
instance.info({
|
||||
key: { redact: 'me' }
|
||||
})
|
||||
const o = await once(stream, 'data')
|
||||
assert.equal('key' in o, false)
|
||||
})
|
||||
|
||||
test('redact.remove – top level key - number value', async () => {
|
||||
const stream = sink()
|
||||
const instance = pino({ redact: { paths: ['key'], remove: true } }, stream)
|
||||
instance.info({
|
||||
key: 1
|
||||
})
|
||||
const o = await once(stream, 'data')
|
||||
assert.equal('key' in o, false)
|
||||
})
|
||||
|
||||
test('redact.remove – top level key - boolean value', async () => {
|
||||
const stream = sink()
|
||||
const instance = pino({ redact: { paths: ['key'], remove: true } }, stream)
|
||||
instance.info({
|
||||
key: false
|
||||
})
|
||||
const o = await once(stream, 'data')
|
||||
assert.equal('key' in o, false)
|
||||
})
|
||||
|
||||
test('redact.remove – top level key in child logger', async () => {
|
||||
const stream = sink()
|
||||
const opts = { redact: { paths: ['key'], remove: true } }
|
||||
const instance = pino(opts, stream).child({ key: { redact: 'me' } })
|
||||
instance.info('test')
|
||||
const o = await once(stream, 'data')
|
||||
assert.equal('key' in o, false)
|
||||
})
|
||||
|
||||
test('redact.paths preserves original object values after the log write', async () => {
|
||||
const stream = sink()
|
||||
const instance = pino({ redact: ['req.headers.cookie'] }, stream)
|
||||
const obj = {
|
||||
req: {
|
||||
id: 7915,
|
||||
method: 'GET',
|
||||
url: '/',
|
||||
headers: {
|
||||
host: 'localhost:3000',
|
||||
connection: 'keep-alive',
|
||||
cookie: 'SESSID=298zf09hf012fh2; csrftoken=u32t4o3tb3gg43; _gat=1;'
|
||||
},
|
||||
remoteAddress: '::ffff:127.0.0.1',
|
||||
remotePort: 58022
|
||||
}
|
||||
}
|
||||
instance.info(obj)
|
||||
const o = await once(stream, 'data')
|
||||
assert.equal(o.req.headers.cookie, '[Redacted]')
|
||||
assert.equal(obj.req.headers.cookie, 'SESSID=298zf09hf012fh2; csrftoken=u32t4o3tb3gg43; _gat=1;')
|
||||
})
|
||||
|
||||
test('redact.paths preserves original object values after the log write', async () => {
|
||||
const stream = sink()
|
||||
const instance = pino({ redact: { paths: ['req.headers.cookie'] } }, stream)
|
||||
const obj = {
|
||||
req: {
|
||||
id: 7915,
|
||||
method: 'GET',
|
||||
url: '/',
|
||||
headers: {
|
||||
host: 'localhost:3000',
|
||||
connection: 'keep-alive',
|
||||
cookie: 'SESSID=298zf09hf012fh2; csrftoken=u32t4o3tb3gg43; _gat=1;'
|
||||
},
|
||||
remoteAddress: '::ffff:127.0.0.1',
|
||||
remotePort: 58022
|
||||
}
|
||||
}
|
||||
instance.info(obj)
|
||||
const o = await once(stream, 'data')
|
||||
assert.equal(o.req.headers.cookie, '[Redacted]')
|
||||
assert.equal(obj.req.headers.cookie, 'SESSID=298zf09hf012fh2; csrftoken=u32t4o3tb3gg43; _gat=1;')
|
||||
})
|
||||
|
||||
test('redact.censor preserves original object values after the log write', async () => {
|
||||
const stream = sink()
|
||||
const instance = pino({ redact: { paths: ['req.headers.cookie'], censor: 'test' } }, stream)
|
||||
const obj = {
|
||||
req: {
|
||||
id: 7915,
|
||||
method: 'GET',
|
||||
url: '/',
|
||||
headers: {
|
||||
host: 'localhost:3000',
|
||||
connection: 'keep-alive',
|
||||
cookie: 'SESSID=298zf09hf012fh2; csrftoken=u32t4o3tb3gg43; _gat=1;'
|
||||
},
|
||||
remoteAddress: '::ffff:127.0.0.1',
|
||||
remotePort: 58022
|
||||
}
|
||||
}
|
||||
instance.info(obj)
|
||||
const o = await once(stream, 'data')
|
||||
assert.equal(o.req.headers.cookie, 'test')
|
||||
assert.equal(obj.req.headers.cookie, 'SESSID=298zf09hf012fh2; csrftoken=u32t4o3tb3gg43; _gat=1;')
|
||||
})
|
||||
|
||||
test('redact.remove preserves original object values after the log write', async () => {
|
||||
const stream = sink()
|
||||
const instance = pino({ redact: { paths: ['req.headers.cookie'], remove: true } }, stream)
|
||||
const obj = {
|
||||
req: {
|
||||
id: 7915,
|
||||
method: 'GET',
|
||||
url: '/',
|
||||
headers: {
|
||||
host: 'localhost:3000',
|
||||
connection: 'keep-alive',
|
||||
cookie: 'SESSID=298zf09hf012fh2; csrftoken=u32t4o3tb3gg43; _gat=1;'
|
||||
},
|
||||
remoteAddress: '::ffff:127.0.0.1',
|
||||
remotePort: 58022
|
||||
}
|
||||
}
|
||||
instance.info(obj)
|
||||
const o = await once(stream, 'data')
|
||||
assert.equal('cookie' in o.req.headers, false)
|
||||
assert.equal('cookie' in obj.req.headers, true)
|
||||
})
|
||||
|
||||
test('redact – supports last position wildcard paths', async () => {
|
||||
const stream = sink()
|
||||
const instance = pino({ redact: ['req.headers.*'] }, stream)
|
||||
instance.info({
|
||||
req: {
|
||||
id: 7915,
|
||||
method: 'GET',
|
||||
url: '/',
|
||||
headers: {
|
||||
host: 'localhost:3000',
|
||||
connection: 'keep-alive',
|
||||
cookie: 'SESSID=298zf09hf012fh2; csrftoken=u32t4o3tb3gg43; _gat=1;'
|
||||
},
|
||||
remoteAddress: '::ffff:127.0.0.1',
|
||||
remotePort: 58022
|
||||
}
|
||||
})
|
||||
const { req } = await once(stream, 'data')
|
||||
assert.equal(req.headers.cookie, '[Redacted]')
|
||||
assert.equal(req.headers.host, '[Redacted]')
|
||||
assert.equal(req.headers.connection, '[Redacted]')
|
||||
})
|
||||
|
||||
test('redact – supports first position wildcard paths', async () => {
|
||||
const stream = sink()
|
||||
const instance = pino({ redact: ['*.headers'] }, stream)
|
||||
instance.info({
|
||||
req: {
|
||||
id: 7915,
|
||||
method: 'GET',
|
||||
url: '/',
|
||||
headers: {
|
||||
host: 'localhost:3000',
|
||||
connection: 'keep-alive',
|
||||
cookie: 'SESSID=298zf09hf012fh2; csrftoken=u32t4o3tb3gg43; _gat=1;'
|
||||
},
|
||||
remoteAddress: '::ffff:127.0.0.1',
|
||||
remotePort: 58022
|
||||
}
|
||||
})
|
||||
const { req } = await once(stream, 'data')
|
||||
assert.equal(req.headers, '[Redacted]')
|
||||
})
|
||||
|
||||
test('redact – supports first position wildcards before other paths', async () => {
|
||||
const stream = sink()
|
||||
const instance = pino({ redact: ['*.headers.cookie', 'req.id'] }, stream)
|
||||
instance.info({
|
||||
req: {
|
||||
id: 7915,
|
||||
method: 'GET',
|
||||
url: '/',
|
||||
headers: {
|
||||
host: 'localhost:3000',
|
||||
connection: 'keep-alive',
|
||||
cookie: 'SESSID=298zf09hf012fh2; csrftoken=u32t4o3tb3gg43; _gat=1;'
|
||||
},
|
||||
remoteAddress: '::ffff:127.0.0.1',
|
||||
remotePort: 58022
|
||||
}
|
||||
})
|
||||
const { req } = await once(stream, 'data')
|
||||
assert.equal(req.headers.cookie, '[Redacted]')
|
||||
assert.equal(req.id, '[Redacted]')
|
||||
})
|
||||
|
||||
test('redact – supports first position wildcards after other paths', async () => {
|
||||
const stream = sink()
|
||||
const instance = pino({ redact: ['req.id', '*.headers.cookie'] }, stream)
|
||||
instance.info({
|
||||
req: {
|
||||
id: 7915,
|
||||
method: 'GET',
|
||||
url: '/',
|
||||
headers: {
|
||||
host: 'localhost:3000',
|
||||
connection: 'keep-alive',
|
||||
cookie: 'SESSID=298zf09hf012fh2; csrftoken=u32t4o3tb3gg43; _gat=1;'
|
||||
},
|
||||
remoteAddress: '::ffff:127.0.0.1',
|
||||
remotePort: 58022
|
||||
}
|
||||
})
|
||||
const { req } = await once(stream, 'data')
|
||||
assert.equal(req.headers.cookie, '[Redacted]')
|
||||
assert.equal(req.id, '[Redacted]')
|
||||
})
|
||||
|
||||
test('redact – supports first position wildcards after top level keys', async () => {
|
||||
const stream = sink()
|
||||
const instance = pino({ redact: ['key', '*.headers.cookie'] }, stream)
|
||||
instance.info({
|
||||
req: {
|
||||
id: 7915,
|
||||
method: 'GET',
|
||||
url: '/',
|
||||
headers: {
|
||||
host: 'localhost:3000',
|
||||
connection: 'keep-alive',
|
||||
cookie: 'SESSID=298zf09hf012fh2; csrftoken=u32t4o3tb3gg43; _gat=1;'
|
||||
},
|
||||
remoteAddress: '::ffff:127.0.0.1',
|
||||
remotePort: 58022
|
||||
}
|
||||
})
|
||||
const { req } = await once(stream, 'data')
|
||||
assert.equal(req.headers.cookie, '[Redacted]')
|
||||
})
|
||||
|
||||
test('redact – supports top level wildcard', async () => {
|
||||
const stream = sink()
|
||||
const instance = pino({ redact: ['*'] }, stream)
|
||||
instance.info({
|
||||
req: {
|
||||
id: 7915,
|
||||
method: 'GET',
|
||||
url: '/',
|
||||
headers: {
|
||||
host: 'localhost:3000',
|
||||
connection: 'keep-alive',
|
||||
cookie: 'SESSID=298zf09hf012fh2; csrftoken=u32t4o3tb3gg43; _gat=1;'
|
||||
},
|
||||
remoteAddress: '::ffff:127.0.0.1',
|
||||
remotePort: 58022
|
||||
}
|
||||
})
|
||||
const { req } = await once(stream, 'data')
|
||||
assert.equal(req, '[Redacted]')
|
||||
})
|
||||
|
||||
test('redact – supports top level wildcard with a censor function', async () => {
|
||||
const stream = sink()
|
||||
const instance = pino({
|
||||
redact: {
|
||||
paths: ['*'],
|
||||
censor: () => '[Redacted]'
|
||||
}
|
||||
}, stream)
|
||||
instance.info({
|
||||
req: {
|
||||
id: 7915,
|
||||
method: 'GET',
|
||||
url: '/',
|
||||
headers: {
|
||||
host: 'localhost:3000',
|
||||
connection: 'keep-alive',
|
||||
cookie: 'SESSID=298zf09hf012fh2; csrftoken=u32t4o3tb3gg43; _gat=1;'
|
||||
},
|
||||
remoteAddress: '::ffff:127.0.0.1',
|
||||
remotePort: 58022
|
||||
}
|
||||
})
|
||||
const { req } = await once(stream, 'data')
|
||||
assert.equal(req, '[Redacted]')
|
||||
})
|
||||
|
||||
test('redact – supports top level wildcard and leading wildcard', async () => {
|
||||
const stream = sink()
|
||||
const instance = pino({ redact: ['*', '*.req'] }, stream)
|
||||
instance.info({
|
||||
req: {
|
||||
id: 7915,
|
||||
method: 'GET',
|
||||
url: '/',
|
||||
headers: {
|
||||
host: 'localhost:3000',
|
||||
connection: 'keep-alive',
|
||||
cookie: 'SESSID=298zf09hf012fh2; csrftoken=u32t4o3tb3gg43; _gat=1;'
|
||||
},
|
||||
remoteAddress: '::ffff:127.0.0.1',
|
||||
remotePort: 58022
|
||||
}
|
||||
})
|
||||
const { req } = await once(stream, 'data')
|
||||
assert.equal(req, '[Redacted]')
|
||||
})
|
||||
|
||||
test('redact – supports intermediate wildcard paths', async () => {
|
||||
const stream = sink()
|
||||
const instance = pino({ redact: ['req.*.cookie'] }, stream)
|
||||
instance.info({
|
||||
req: {
|
||||
id: 7915,
|
||||
method: 'GET',
|
||||
url: '/',
|
||||
headers: {
|
||||
host: 'localhost:3000',
|
||||
connection: 'keep-alive',
|
||||
cookie: 'SESSID=298zf09hf012fh2; csrftoken=u32t4o3tb3gg43; _gat=1;'
|
||||
},
|
||||
remoteAddress: '::ffff:127.0.0.1',
|
||||
remotePort: 58022
|
||||
}
|
||||
})
|
||||
const { req } = await once(stream, 'data')
|
||||
assert.equal(req.headers.cookie, '[Redacted]')
|
||||
})
|
||||
|
||||
test('redacts numbers at the top level', async () => {
|
||||
const stream = sink()
|
||||
const instance = pino({ redact: ['id'] }, stream)
|
||||
const obj = {
|
||||
id: 7915
|
||||
}
|
||||
instance.info(obj)
|
||||
const o = await once(stream, 'data')
|
||||
assert.equal(o.id, '[Redacted]')
|
||||
})
|
||||
|
||||
test('redacts booleans at the top level', async () => {
|
||||
const stream = sink()
|
||||
const instance = pino({ redact: ['maybe'] }, stream)
|
||||
const obj = {
|
||||
maybe: true
|
||||
}
|
||||
instance.info(obj)
|
||||
const o = await once(stream, 'data')
|
||||
assert.equal(o.maybe, '[Redacted]')
|
||||
})
|
||||
|
||||
test('redacts strings at the top level', async () => {
|
||||
const stream = sink()
|
||||
const instance = pino({ redact: ['s'] }, stream)
|
||||
const obj = {
|
||||
s: 's'
|
||||
}
|
||||
instance.info(obj)
|
||||
const o = await once(stream, 'data')
|
||||
assert.equal(o.s, '[Redacted]')
|
||||
})
|
||||
|
||||
test('does not redact primitives if not objects', async () => {
|
||||
const stream = sink()
|
||||
const instance = pino({ redact: ['a.b'] }, stream)
|
||||
const obj = {
|
||||
a: 42
|
||||
}
|
||||
instance.info(obj)
|
||||
const o = await once(stream, 'data')
|
||||
assert.equal(o.a, 42)
|
||||
})
|
||||
|
||||
test('redacts null at the top level', async () => {
|
||||
const stream = sink()
|
||||
const instance = pino({ redact: ['n'] }, stream)
|
||||
const obj = {
|
||||
n: null
|
||||
}
|
||||
instance.info(obj)
|
||||
const o = await once(stream, 'data')
|
||||
assert.equal(o.n, '[Redacted]')
|
||||
})
|
||||
|
||||
test('supports bracket notation', async () => {
|
||||
const stream = sink()
|
||||
const instance = pino({ redact: ['a["b.b"]'] }, stream)
|
||||
const obj = {
|
||||
a: { 'b.b': 'c' }
|
||||
}
|
||||
instance.info(obj)
|
||||
const o = await once(stream, 'data')
|
||||
assert.equal(o.a['b.b'], '[Redacted]')
|
||||
})
|
||||
|
||||
test('supports bracket notation with further nesting', async () => {
|
||||
const stream = sink()
|
||||
const instance = pino({ redact: ['a["b.b"].c'] }, stream)
|
||||
const obj = {
|
||||
a: { 'b.b': { c: 'd' } }
|
||||
}
|
||||
instance.info(obj)
|
||||
const o = await once(stream, 'data')
|
||||
assert.equal(o.a['b.b'].c, '[Redacted]')
|
||||
})
|
||||
|
||||
test('supports bracket notation with empty string as path segment', async () => {
|
||||
const stream = sink()
|
||||
const instance = pino({ redact: ['a[""].c'] }, stream)
|
||||
const obj = {
|
||||
a: { '': { c: 'd' } }
|
||||
}
|
||||
instance.info(obj)
|
||||
const o = await once(stream, 'data')
|
||||
assert.equal(o.a[''].c, '[Redacted]')
|
||||
})
|
||||
|
||||
test('supports leading bracket notation (single quote)', async () => {
|
||||
const stream = sink()
|
||||
const instance = pino({ redact: ['[\'a.a\'].b'] }, stream)
|
||||
const obj = {
|
||||
'a.a': { b: 'c' }
|
||||
}
|
||||
instance.info(obj)
|
||||
const o = await once(stream, 'data')
|
||||
assert.equal(o['a.a'].b, '[Redacted]')
|
||||
})
|
||||
|
||||
test('supports leading bracket notation (double quote)', async () => {
|
||||
const stream = sink()
|
||||
const instance = pino({ redact: ['["a.a"].b'] }, stream)
|
||||
const obj = {
|
||||
'a.a': { b: 'c' }
|
||||
}
|
||||
instance.info(obj)
|
||||
const o = await once(stream, 'data')
|
||||
assert.equal(o['a.a'].b, '[Redacted]')
|
||||
})
|
||||
|
||||
test('supports leading bracket notation (backtick quote)', async () => {
|
||||
const stream = sink()
|
||||
const instance = pino({ redact: ['[`a.a`].b'] }, stream)
|
||||
const obj = {
|
||||
'a.a': { b: 'c' }
|
||||
}
|
||||
instance.info(obj)
|
||||
const o = await once(stream, 'data')
|
||||
assert.equal(o['a.a'].b, '[Redacted]')
|
||||
})
|
||||
|
||||
test('supports leading bracket notation (single-segment path)', async () => {
|
||||
const stream = sink()
|
||||
const instance = pino({ redact: ['[`a.a`]'] }, stream)
|
||||
const obj = {
|
||||
'a.a': { b: 'c' }
|
||||
}
|
||||
instance.info(obj)
|
||||
const o = await once(stream, 'data')
|
||||
assert.equal(o['a.a'], '[Redacted]')
|
||||
})
|
||||
|
||||
test('supports leading bracket notation (single-segment path, wildcard)', async () => {
|
||||
const stream = sink()
|
||||
const instance = pino({ redact: ['[*]'] }, stream)
|
||||
const obj = {
|
||||
'a.a': { b: 'c' }
|
||||
}
|
||||
instance.info(obj)
|
||||
const o = await once(stream, 'data')
|
||||
assert.equal(o['a.a'], '[Redacted]')
|
||||
})
|
||||
|
||||
test('child bindings are redacted using wildcard path', async () => {
|
||||
const stream = sink()
|
||||
const instance = pino({ redact: ['*.headers.cookie'] }, stream)
|
||||
instance.child({
|
||||
req: {
|
||||
method: 'GET',
|
||||
url: '/',
|
||||
headers: {
|
||||
cookie: 'SESSID=298zf09hf012fh2; csrftoken=u32t4o3tb3gg43; _gat=1;'
|
||||
}
|
||||
}
|
||||
}).info('message completed')
|
||||
const { req } = await once(stream, 'data')
|
||||
assert.equal(req.headers.cookie, '[Redacted]')
|
||||
})
|
||||
|
||||
test('child bindings are redacted using wildcard and plain path keys', async () => {
|
||||
const stream = sink()
|
||||
const instance = pino({ redact: ['req.method', '*.headers.cookie'] }, stream)
|
||||
instance.child({
|
||||
req: {
|
||||
method: 'GET',
|
||||
url: '/',
|
||||
headers: {
|
||||
cookie: 'SESSID=298zf09hf012fh2; csrftoken=u32t4o3tb3gg43; _gat=1;'
|
||||
}
|
||||
}
|
||||
}).info('message completed')
|
||||
const { req } = await once(stream, 'data')
|
||||
assert.equal(req.headers.cookie, '[Redacted]')
|
||||
assert.equal(req.method, '[Redacted]')
|
||||
})
|
||||
|
||||
test('redacts boolean at the top level', async () => {
|
||||
const stream = sink()
|
||||
const instance = pino({ redact: ['msg'] }, stream)
|
||||
const obj = {
|
||||
s: 's'
|
||||
}
|
||||
instance.info(obj, true)
|
||||
const o = await once(stream, 'data')
|
||||
assert.equal(o.s, 's')
|
||||
assert.equal(o.msg, '[Redacted]')
|
||||
})
|
||||
|
||||
test('child can customize redact', async () => {
|
||||
const stream = sink()
|
||||
const instance = pino({ redact: ['req.method', '*.headers.cookie'] }, stream)
|
||||
instance.child({
|
||||
req: {
|
||||
method: 'GET',
|
||||
url: '/',
|
||||
headers: {
|
||||
cookie: 'SESSID=298zf09hf012fh2; csrftoken=u32t4o3tb3gg43; _gat=1;'
|
||||
}
|
||||
}
|
||||
}, {
|
||||
redact: ['req.url']
|
||||
}).info('message completed')
|
||||
const { req } = await once(stream, 'data')
|
||||
assert.equal(req.headers.cookie, 'SESSID=298zf09hf012fh2; csrftoken=u32t4o3tb3gg43; _gat=1;')
|
||||
assert.equal(req.method, 'GET')
|
||||
assert.equal(req.url, '[Redacted]')
|
||||
})
|
||||
|
||||
test('child can remove parent redact by array', async () => {
|
||||
const stream = sink()
|
||||
const instance = pino({ redact: ['req.method', '*.headers.cookie'] }, stream)
|
||||
instance.child({
|
||||
req: {
|
||||
method: 'GET',
|
||||
url: '/',
|
||||
headers: {
|
||||
cookie: 'SESSID=298zf09hf012fh2; csrftoken=u32t4o3tb3gg43; _gat=1;'
|
||||
}
|
||||
}
|
||||
}, {
|
||||
redact: []
|
||||
}).info('message completed')
|
||||
const { req } = await once(stream, 'data')
|
||||
assert.equal(req.headers.cookie, 'SESSID=298zf09hf012fh2; csrftoken=u32t4o3tb3gg43; _gat=1;')
|
||||
assert.equal(req.method, 'GET')
|
||||
})
|
||||
|
||||
test('redact safe stringify', async () => {
|
||||
const stream = sink()
|
||||
const instance = pino({ redact: { paths: ['that.secret'] } }, stream)
|
||||
|
||||
instance.info({
|
||||
that: {
|
||||
secret: 'please hide me',
|
||||
myBigInt: 123n
|
||||
},
|
||||
other: {
|
||||
mySecondBigInt: 222n
|
||||
}
|
||||
})
|
||||
const { that, other } = await once(stream, 'data')
|
||||
assert.equal(that.secret, '[Redacted]')
|
||||
assert.equal(that.myBigInt, 123)
|
||||
assert.equal(other.mySecondBigInt, 222)
|
||||
})
|
||||
|
||||
test('censor function should not be called for non-existent nested paths (issue #2313)', async () => {
|
||||
const stream = sink()
|
||||
const censorCalls = []
|
||||
|
||||
const instance = pino({
|
||||
redact: {
|
||||
paths: ['a.b.c', 'req.authorization', 'url'],
|
||||
censor (value, path) {
|
||||
censorCalls.push({ value, path: path.join('.') })
|
||||
if (typeof value !== 'string') {
|
||||
return '***'
|
||||
}
|
||||
return '***'
|
||||
}
|
||||
}
|
||||
}, stream)
|
||||
|
||||
// Test case 1: parent exists but nested path doesn't
|
||||
censorCalls.length = 0
|
||||
instance.info({ req: { id: 'test' } }, 'test message')
|
||||
await once(stream, 'data')
|
||||
assert.equal(censorCalls.length, 0, 'censor should not be called when req.authorization does not exist')
|
||||
|
||||
// Test case 2: parent exists but deeply nested path doesn't
|
||||
censorCalls.length = 0
|
||||
instance.info({ a: { d: 'test' } }, 'test message')
|
||||
await once(stream, 'data')
|
||||
assert.equal(censorCalls.length, 0, 'censor should not be called when a.b.c does not exist')
|
||||
|
||||
// Test case 3: multiple parent keys exist but nested paths don't
|
||||
censorCalls.length = 0
|
||||
instance.info({ a: { c: 'should-not-show-me' }, req: { id: 'test' } }, 'test message')
|
||||
await once(stream, 'data')
|
||||
assert.equal(censorCalls.length, 0, 'censor should not be called when neither a.b.c nor req.authorization exist')
|
||||
|
||||
// Test case 4: verify censor IS called when path exists
|
||||
censorCalls.length = 0
|
||||
instance.info({ req: { authorization: 'bearer token' } }, 'test message')
|
||||
await once(stream, 'data')
|
||||
assert.equal(censorCalls.length, 1, 'censor should be called when req.authorization exists')
|
||||
assert.equal(censorCalls[0].path, 'req.authorization')
|
||||
assert.equal(censorCalls[0].value, 'bearer token')
|
||||
})
|
||||
@@ -0,0 +1,376 @@
|
||||
'use strict'
|
||||
|
||||
let { dirname, relative, resolve, sep } = require('path')
|
||||
let { SourceMapConsumer, SourceMapGenerator } = require('source-map-js')
|
||||
let { pathToFileURL } = require('url')
|
||||
|
||||
let Input = require('./input')
|
||||
|
||||
let sourceMapAvailable = Boolean(SourceMapConsumer && SourceMapGenerator)
|
||||
let pathAvailable = Boolean(dirname && resolve && relative && sep)
|
||||
|
||||
class MapGenerator {
|
||||
constructor(stringify, root, opts, cssString) {
|
||||
this.stringify = stringify
|
||||
this.mapOpts = opts.map || {}
|
||||
this.root = root
|
||||
this.opts = opts
|
||||
this.css = cssString
|
||||
this.originalCSS = cssString
|
||||
this.usesFileUrls = !this.mapOpts.from && this.mapOpts.absolute
|
||||
|
||||
this.memoizedFileURLs = new Map()
|
||||
this.memoizedPaths = new Map()
|
||||
this.memoizedURLs = new Map()
|
||||
}
|
||||
|
||||
addAnnotation() {
|
||||
let content
|
||||
|
||||
if (this.isInline()) {
|
||||
content =
|
||||
'data:application/json;base64,' + this.toBase64(this.map.toString())
|
||||
} else if (typeof this.mapOpts.annotation === 'string') {
|
||||
content = this.mapOpts.annotation
|
||||
} else if (typeof this.mapOpts.annotation === 'function') {
|
||||
content = this.mapOpts.annotation(this.opts.to, this.root)
|
||||
} else {
|
||||
content = this.outputFile() + '.map'
|
||||
}
|
||||
let eol = '\n'
|
||||
if (this.css.includes('\r\n')) eol = '\r\n'
|
||||
|
||||
this.css += eol + '/*# sourceMappingURL=' + content + ' */'
|
||||
}
|
||||
|
||||
applyPrevMaps() {
|
||||
for (let prev of this.previous()) {
|
||||
let from = this.toUrl(this.path(prev.file))
|
||||
let root = prev.root || dirname(prev.file)
|
||||
let map
|
||||
|
||||
if (this.mapOpts.sourcesContent === false) {
|
||||
map = new SourceMapConsumer(prev.text)
|
||||
if (map.sourcesContent) {
|
||||
map.sourcesContent = null
|
||||
}
|
||||
} else {
|
||||
map = prev.consumer()
|
||||
}
|
||||
|
||||
this.map.applySourceMap(map, from, this.toUrl(this.path(root)))
|
||||
}
|
||||
}
|
||||
|
||||
clearAnnotation() {
|
||||
if (this.mapOpts.annotation === false) return
|
||||
|
||||
if (this.root) {
|
||||
let node
|
||||
for (let i = this.root.nodes.length - 1; i >= 0; i--) {
|
||||
node = this.root.nodes[i]
|
||||
if (node.type !== 'comment') continue
|
||||
if (node.text.startsWith('# sourceMappingURL=')) {
|
||||
this.root.removeChild(i)
|
||||
}
|
||||
}
|
||||
} else if (this.css) {
|
||||
let startIndex
|
||||
while ((startIndex = this.css.lastIndexOf('/*#')) !== -1) {
|
||||
let endIndex = this.css.indexOf('*/', startIndex + 3)
|
||||
if (endIndex === -1) break
|
||||
while (startIndex > 0 && this.css[startIndex - 1] === '\n') {
|
||||
startIndex--
|
||||
}
|
||||
this.css = this.css.slice(0, startIndex) + this.css.slice(endIndex + 2)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
generate() {
|
||||
this.clearAnnotation()
|
||||
if (pathAvailable && sourceMapAvailable && this.isMap()) {
|
||||
return this.generateMap()
|
||||
} else {
|
||||
let result = ''
|
||||
this.stringify(this.root, i => {
|
||||
result += i
|
||||
})
|
||||
return [result]
|
||||
}
|
||||
}
|
||||
|
||||
generateMap() {
|
||||
if (this.root) {
|
||||
this.generateString()
|
||||
} else if (this.previous().length === 1) {
|
||||
let prev = this.previous()[0].consumer()
|
||||
prev.file = this.outputFile()
|
||||
this.map = SourceMapGenerator.fromSourceMap(prev, {
|
||||
ignoreInvalidMapping: true
|
||||
})
|
||||
} else {
|
||||
this.map = new SourceMapGenerator({
|
||||
file: this.outputFile(),
|
||||
ignoreInvalidMapping: true
|
||||
})
|
||||
this.map.addMapping({
|
||||
generated: { column: 0, line: 1 },
|
||||
original: { column: 0, line: 1 },
|
||||
source: this.opts.from
|
||||
? this.toUrl(this.path(this.opts.from))
|
||||
: '<no source>'
|
||||
})
|
||||
}
|
||||
|
||||
if (this.isSourcesContent()) this.setSourcesContent()
|
||||
if (this.root && this.previous().length > 0) this.applyPrevMaps()
|
||||
if (this.isAnnotation()) this.addAnnotation()
|
||||
|
||||
if (this.isInline()) {
|
||||
return [this.css]
|
||||
} else {
|
||||
return [this.css, this.map]
|
||||
}
|
||||
}
|
||||
|
||||
generateString() {
|
||||
this.css = ''
|
||||
this.map = new SourceMapGenerator({
|
||||
file: this.outputFile(),
|
||||
ignoreInvalidMapping: true
|
||||
})
|
||||
|
||||
let line = 1
|
||||
let column = 1
|
||||
|
||||
let noSource = '<no source>'
|
||||
let mapping = {
|
||||
generated: { column: 0, line: 0 },
|
||||
original: { column: 0, line: 0 },
|
||||
source: ''
|
||||
}
|
||||
|
||||
let last, lines
|
||||
this.stringify(this.root, (str, node, type) => {
|
||||
this.css += str
|
||||
|
||||
if (node && type !== 'end') {
|
||||
mapping.generated.line = line
|
||||
mapping.generated.column = column - 1
|
||||
if (node.source && node.source.start) {
|
||||
mapping.source = this.sourcePath(node)
|
||||
mapping.original.line = node.source.start.line
|
||||
mapping.original.column = node.source.start.column - 1
|
||||
this.map.addMapping(mapping)
|
||||
} else {
|
||||
mapping.source = noSource
|
||||
mapping.original.line = 1
|
||||
mapping.original.column = 0
|
||||
this.map.addMapping(mapping)
|
||||
}
|
||||
}
|
||||
|
||||
lines = str.match(/\n/g)
|
||||
if (lines) {
|
||||
line += lines.length
|
||||
last = str.lastIndexOf('\n')
|
||||
column = str.length - last
|
||||
} else {
|
||||
column += str.length
|
||||
}
|
||||
|
||||
if (node && type !== 'start') {
|
||||
let p = node.parent || { raws: {} }
|
||||
let childless =
|
||||
node.type === 'decl' || (node.type === 'atrule' && !node.nodes)
|
||||
if (!childless || node !== p.last || p.raws.semicolon) {
|
||||
if (node.source && node.source.end) {
|
||||
mapping.source = this.sourcePath(node)
|
||||
mapping.original.line = node.source.end.line
|
||||
mapping.original.column = node.source.end.column - 1
|
||||
mapping.generated.line = line
|
||||
mapping.generated.column = column - 2
|
||||
this.map.addMapping(mapping)
|
||||
} else {
|
||||
mapping.source = noSource
|
||||
mapping.original.line = 1
|
||||
mapping.original.column = 0
|
||||
mapping.generated.line = line
|
||||
mapping.generated.column = column - 1
|
||||
this.map.addMapping(mapping)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
isAnnotation() {
|
||||
if (this.isInline()) {
|
||||
return true
|
||||
}
|
||||
if (typeof this.mapOpts.annotation !== 'undefined') {
|
||||
return this.mapOpts.annotation
|
||||
}
|
||||
if (this.previous().length) {
|
||||
return this.previous().some(i => i.annotation)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
isInline() {
|
||||
if (typeof this.mapOpts.inline !== 'undefined') {
|
||||
return this.mapOpts.inline
|
||||
}
|
||||
|
||||
let annotation = this.mapOpts.annotation
|
||||
if (typeof annotation !== 'undefined' && annotation !== true) {
|
||||
return false
|
||||
}
|
||||
|
||||
if (this.previous().length) {
|
||||
return this.previous().some(i => i.inline)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
isMap() {
|
||||
if (typeof this.opts.map !== 'undefined') {
|
||||
return !!this.opts.map
|
||||
}
|
||||
return this.previous().length > 0
|
||||
}
|
||||
|
||||
isSourcesContent() {
|
||||
if (typeof this.mapOpts.sourcesContent !== 'undefined') {
|
||||
return this.mapOpts.sourcesContent
|
||||
}
|
||||
if (this.previous().length) {
|
||||
return this.previous().some(i => i.withContent())
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
outputFile() {
|
||||
if (this.opts.to) {
|
||||
return this.path(this.opts.to)
|
||||
} else if (this.opts.from) {
|
||||
return this.path(this.opts.from)
|
||||
} else {
|
||||
return 'to.css'
|
||||
}
|
||||
}
|
||||
|
||||
path(file) {
|
||||
if (this.mapOpts.absolute) return file
|
||||
if (file.charCodeAt(0) === 60 /* `<` */) return file
|
||||
if (/^\w+:\/\//.test(file)) return file
|
||||
let cached = this.memoizedPaths.get(file)
|
||||
if (cached) return cached
|
||||
|
||||
let from = this.opts.to ? dirname(this.opts.to) : '.'
|
||||
|
||||
if (typeof this.mapOpts.annotation === 'string') {
|
||||
from = dirname(resolve(from, this.mapOpts.annotation))
|
||||
}
|
||||
|
||||
let path = relative(from, file)
|
||||
this.memoizedPaths.set(file, path)
|
||||
|
||||
return path
|
||||
}
|
||||
|
||||
previous() {
|
||||
if (!this.previousMaps) {
|
||||
this.previousMaps = []
|
||||
if (this.root) {
|
||||
this.root.walk(node => {
|
||||
if (node.source && node.source.input.map) {
|
||||
let map = node.source.input.map
|
||||
if (!this.previousMaps.includes(map)) {
|
||||
this.previousMaps.push(map)
|
||||
}
|
||||
}
|
||||
})
|
||||
} else {
|
||||
let input = new Input(this.originalCSS, this.opts)
|
||||
if (input.map) this.previousMaps.push(input.map)
|
||||
}
|
||||
}
|
||||
|
||||
return this.previousMaps
|
||||
}
|
||||
|
||||
setSourcesContent() {
|
||||
let already = {}
|
||||
if (this.root) {
|
||||
this.root.walk(node => {
|
||||
if (node.source) {
|
||||
let from = node.source.input.from
|
||||
if (from && !already[from]) {
|
||||
already[from] = true
|
||||
let fromUrl = this.usesFileUrls
|
||||
? this.toFileUrl(from)
|
||||
: this.toUrl(this.path(from))
|
||||
this.map.setSourceContent(fromUrl, node.source.input.css)
|
||||
}
|
||||
}
|
||||
})
|
||||
} else if (this.css) {
|
||||
let from = this.opts.from
|
||||
? this.toUrl(this.path(this.opts.from))
|
||||
: '<no source>'
|
||||
this.map.setSourceContent(from, this.css)
|
||||
}
|
||||
}
|
||||
|
||||
sourcePath(node) {
|
||||
if (this.mapOpts.from) {
|
||||
return this.toUrl(this.mapOpts.from)
|
||||
} else if (this.usesFileUrls) {
|
||||
return this.toFileUrl(node.source.input.from)
|
||||
} else {
|
||||
return this.toUrl(this.path(node.source.input.from))
|
||||
}
|
||||
}
|
||||
|
||||
toBase64(str) {
|
||||
if (Buffer) {
|
||||
return Buffer.from(str).toString('base64')
|
||||
} else {
|
||||
return window.btoa(unescape(encodeURIComponent(str)))
|
||||
}
|
||||
}
|
||||
|
||||
toFileUrl(path) {
|
||||
let cached = this.memoizedFileURLs.get(path)
|
||||
if (cached) return cached
|
||||
|
||||
if (pathToFileURL) {
|
||||
let fileURL = pathToFileURL(path).toString()
|
||||
this.memoizedFileURLs.set(path, fileURL)
|
||||
|
||||
return fileURL
|
||||
} else {
|
||||
throw new Error(
|
||||
'`map.absolute` option is not available in this PostCSS build'
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
toUrl(path) {
|
||||
let cached = this.memoizedURLs.get(path)
|
||||
if (cached) return cached
|
||||
|
||||
if (sep === '\\') {
|
||||
path = path.replace(/\\/g, '/')
|
||||
}
|
||||
|
||||
let url = encodeURI(path).replace(/[#?]/g, encodeURIComponent)
|
||||
this.memoizedURLs.set(path, url)
|
||||
|
||||
return url
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = MapGenerator
|
||||
@@ -0,0 +1,35 @@
|
||||
"use strict";
|
||||
|
||||
function _apply_decorated_descriptor(target, property, decorators, descriptor, context) {
|
||||
var desc = {};
|
||||
|
||||
Object["ke" + "ys"](descriptor).forEach(function(key) {
|
||||
desc[key] = descriptor[key];
|
||||
});
|
||||
desc.enumerable = !!desc.enumerable;
|
||||
desc.configurable = !!desc.configurable;
|
||||
|
||||
if ("value" in desc || desc.initializer) desc.writable = true;
|
||||
desc = decorators.slice().reverse().reduce(function(desc, decorator) {
|
||||
return decorator ? decorator(target, property, desc) || desc : desc;
|
||||
}, desc);
|
||||
|
||||
var hasAccessor = Object.prototype.hasOwnProperty.call(desc, "get") || Object.prototype.hasOwnProperty.call(desc, "set");
|
||||
|
||||
if (context && desc.initializer !== void 0 && !hasAccessor) {
|
||||
desc.value = desc.initializer ? desc.initializer.call(context) : void 0;
|
||||
desc.initializer = undefined;
|
||||
}
|
||||
if (hasAccessor) {
|
||||
delete desc.writable;
|
||||
delete desc.initializer;
|
||||
delete desc.value;
|
||||
}
|
||||
if (desc.initializer === void 0) {
|
||||
Object["define" + "Property"](target, property, desc);
|
||||
desc = null;
|
||||
}
|
||||
|
||||
return desc;
|
||||
}
|
||||
exports._ = _apply_decorated_descriptor;
|
||||
@@ -0,0 +1,191 @@
|
||||
function ImplementingToJSON() {}
|
||||
ImplementingToJSON.prototype.toJSON = function() {
|
||||
return 'dummy!';
|
||||
};
|
||||
|
||||
function NotImplementingToJSON() {}
|
||||
|
||||
module.exports = {
|
||||
"objects": {
|
||||
"string": {
|
||||
"VALUES_WITH_SPACES": "a b c",
|
||||
"LOWERCASE": "abc",
|
||||
"UPPERCASE": "ABC",
|
||||
"NUMBER_ONLY": "123",
|
||||
"EMPTY_STRING": "",
|
||||
"ESCAPE_RANGE": "\u0000\u001F",
|
||||
"NON_ESCAPE_RANGE": "\u0020\uFFFF",
|
||||
"UTF16": "☃",
|
||||
"QUOTATION_MARK": "\"",
|
||||
"REVERSE_SOLIDUS": "\\",
|
||||
"SOLIDUS": "\/",
|
||||
"FORM_FEED": "\f",
|
||||
"LINE_FEED": "\n",
|
||||
"CARRIAGE_RETURN": "\r",
|
||||
"TAB": "\t",
|
||||
"BACKSPACE": "\b",
|
||||
"MIXED": "Aa1 Bb2 Cc3 \u0000\u001F\u0020\uFFFF☃\"\\\/\f\n\r\t\b"
|
||||
},
|
||||
"key": {
|
||||
"a b c": "VALUES_WITH_SPACES",
|
||||
"abc": "LOWERCASE",
|
||||
"ABC": "UPPERCASE",
|
||||
"NUMBER_ONLY": "123",
|
||||
"": "EMPTY_STRING",
|
||||
"\u0000\u001F": "ESCAPE_RANGE",
|
||||
"\u0020\uFFFF": "NON_ESCAPE_RANGE",
|
||||
"☃": "UTF16",
|
||||
"\"": "QUOTATION_MARK",
|
||||
"\\": "REVERSE_SOLIDUS",
|
||||
"\/": "SOLIDUS",
|
||||
"\f": "FORM_FEED",
|
||||
"\n": "LINE_FEED",
|
||||
"\r": "CARRIAGE_RETURN",
|
||||
"\t": "TAB",
|
||||
"\b": "BACKSPACE",
|
||||
"Aa1 Bb2 Cc3 \u0000\u001F\u0020\uFFFF☃\"\\\/\f\n\r\t\b": "MIXED"
|
||||
},
|
||||
"number": {
|
||||
"MAX_SAFE_INTEGER": 9007199254740991,
|
||||
"MIN_SAFE_INTEGER": -9007199254740991,
|
||||
"FALSY": 0,
|
||||
"NEGATIVE": -1,
|
||||
"FLOAT": 0.1234567,
|
||||
"NEGATIVE_FLOAT": -0.9876543,
|
||||
"MAX_VALUE": 1.7976931348623157e+308,
|
||||
"MIN_VALUE": 5e-324,
|
||||
"NEGATIVE_MAX_VALUE": -1.7976931348623157e+308,
|
||||
"NEGATIVE_MIN_VALUE": -5e-324,
|
||||
"INFINITY": Infinity,
|
||||
"NEG_INFINITY": -Infinity,
|
||||
"NAN": NaN
|
||||
},
|
||||
"boolean": {
|
||||
"TRUE": true,
|
||||
"FALSE": false
|
||||
},
|
||||
"null": {
|
||||
"NULL": null
|
||||
},
|
||||
"undefined": undefined,
|
||||
"undefineds": {
|
||||
"ONE": undefined,
|
||||
"TWO": undefined,
|
||||
"THREE": undefined
|
||||
},
|
||||
"date": new Date('2017'),
|
||||
"function": function() {},
|
||||
"instances": {
|
||||
'implementingToJSON': new ImplementingToJSON(),
|
||||
'notImplementingToJSON': new NotImplementingToJSON()
|
||||
},
|
||||
"mixed": {
|
||||
"Aa1 Bb2 Cc3 \u0000\u001F\u0020\uFFFF☃\"\\\/\f\n\r\t\b": "MIXED",
|
||||
"MIXED": "Aa1 Bb2 Cc3 \u0000\u001F\u0020\uFFFF☃\"\\\/\f\n\r\t\b",
|
||||
"MAX_VALUE": 1.7976931348623157e+308,
|
||||
"MIN_VALUE": 5e-324,
|
||||
"NEGATIVE_MAX_VALUE": -1.7976931348623157e+308,
|
||||
"NEGATIVE_MIN_VALUE": -5e-324,
|
||||
"TRUE": true,
|
||||
"FALSE": false,
|
||||
"NULL": null,
|
||||
"UNDEFINED": undefined,
|
||||
"zzz": "ending"
|
||||
}
|
||||
},
|
||||
"arrays": {
|
||||
"number": [
|
||||
9007199254740991,
|
||||
-9007199254740991,
|
||||
0,
|
||||
-1,
|
||||
0.1234567,
|
||||
-0.9876543,
|
||||
1.7976931348623157e+308,
|
||||
5e-324,
|
||||
-1.7976931348623157e+308,
|
||||
-5e-324,
|
||||
Infinity,
|
||||
-Infinity,
|
||||
NaN
|
||||
],
|
||||
"string": [
|
||||
"a b c",
|
||||
"abc",
|
||||
"ABC",
|
||||
"NUMBER_ONLY",
|
||||
"",
|
||||
"\u0000\u001F",
|
||||
"\u0020\uFFFF",
|
||||
"☃",
|
||||
"\"",
|
||||
"\\",
|
||||
"\/",
|
||||
"\f",
|
||||
"\n",
|
||||
"\r",
|
||||
"\t",
|
||||
"\b",
|
||||
"Aa1 Bb2 Cc3 \u0000\u001F\u0020\uFFFF☃\"\\\/\f\n\r\t\b"
|
||||
],
|
||||
"boolean": [
|
||||
true,
|
||||
false
|
||||
],
|
||||
"null": [
|
||||
null
|
||||
],
|
||||
"undefined": [
|
||||
undefined
|
||||
],
|
||||
"date": [
|
||||
new Date('2017')
|
||||
],
|
||||
"instances": [
|
||||
new ImplementingToJSON(),
|
||||
new NotImplementingToJSON()
|
||||
],
|
||||
"function": [
|
||||
function(){}
|
||||
],
|
||||
"mixed": [
|
||||
-1.7976931348623157e+308,
|
||||
-5e-324,
|
||||
"Aa1 Bb2 Cc3 \u0000\u001F\u0020\uFFFF☃\"\\\/\f\n\r\t\b",
|
||||
true,
|
||||
false,
|
||||
null,
|
||||
undefined
|
||||
]
|
||||
},
|
||||
"mixed": [
|
||||
{
|
||||
"Aa1 Bb2 Cc3 \u0000\u001F\u0020\uFFFF☃\"\\\/\f\n\r\t\b": "MIXED",
|
||||
"MIXED": "Aa1 Bb2 Cc3 \u0000\u001F\u0020\uFFFF☃\"\\\/\f\n\r\t\b",
|
||||
"MAX_VALUE": 1.7976931348623157e+308,
|
||||
"MIN_VALUE": 5e-324,
|
||||
"NEGATIVE_MAX_VALUE": -1.7976931348623157e+308,
|
||||
"NEGATIVE_MIN_VALUE": -5e-324,
|
||||
"TRUE": true,
|
||||
"FALSE": false,
|
||||
"NULL": null,
|
||||
"UNDEFINED": undefined,
|
||||
"DATE": new Date('2017'),
|
||||
"IMPLEMENTING_TO_JSON": new ImplementingToJSON(),
|
||||
"NOT_IMPLEMENTING_TO_JSON": new NotImplementingToJSON(),
|
||||
"FUNCTION": function(){},
|
||||
"zzz": "ending"
|
||||
},
|
||||
-1.7976931348623157e+308,
|
||||
-5e-324,
|
||||
"Aa1 Bb2 Cc3 \u0000\u001F\u0020\uFFFF☃\"\\\/\f\n\r\t\b",
|
||||
true,
|
||||
false,
|
||||
null,
|
||||
undefined,
|
||||
new Date('2017'),
|
||||
function(){},
|
||||
new ImplementingToJSON(),
|
||||
new NotImplementingToJSON()
|
||||
]
|
||||
};
|
||||
@@ -0,0 +1,100 @@
|
||||
'use strict'
|
||||
|
||||
module.exports = {
|
||||
mapHttpRequest,
|
||||
reqSerializer
|
||||
}
|
||||
|
||||
const rawSymbol = Symbol('pino-raw-req-ref')
|
||||
const pinoReqProto = Object.create({}, {
|
||||
id: {
|
||||
enumerable: true,
|
||||
writable: true,
|
||||
value: ''
|
||||
},
|
||||
method: {
|
||||
enumerable: true,
|
||||
writable: true,
|
||||
value: ''
|
||||
},
|
||||
url: {
|
||||
enumerable: true,
|
||||
writable: true,
|
||||
value: ''
|
||||
},
|
||||
query: {
|
||||
enumerable: true,
|
||||
writable: true,
|
||||
value: ''
|
||||
},
|
||||
params: {
|
||||
enumerable: true,
|
||||
writable: true,
|
||||
value: ''
|
||||
},
|
||||
headers: {
|
||||
enumerable: true,
|
||||
writable: true,
|
||||
value: {}
|
||||
},
|
||||
remoteAddress: {
|
||||
enumerable: true,
|
||||
writable: true,
|
||||
value: ''
|
||||
},
|
||||
remotePort: {
|
||||
enumerable: true,
|
||||
writable: true,
|
||||
value: ''
|
||||
},
|
||||
raw: {
|
||||
enumerable: false,
|
||||
get: function () {
|
||||
return this[rawSymbol]
|
||||
},
|
||||
set: function (val) {
|
||||
this[rawSymbol] = val
|
||||
}
|
||||
}
|
||||
})
|
||||
Object.defineProperty(pinoReqProto, rawSymbol, {
|
||||
writable: true,
|
||||
value: {}
|
||||
})
|
||||
|
||||
function reqSerializer (req) {
|
||||
// req.info is for hapi compat.
|
||||
const connection = req.info || req.socket
|
||||
const _req = Object.create(pinoReqProto)
|
||||
_req.id = (typeof req.id === 'function' ? req.id() : (req.id || (req.info ? req.info.id : undefined)))
|
||||
_req.method = req.method
|
||||
// req.originalUrl is for expressjs compat.
|
||||
if (req.originalUrl) {
|
||||
_req.url = req.originalUrl
|
||||
} else {
|
||||
const path = req.path
|
||||
// path for safe hapi compat.
|
||||
_req.url = typeof path === 'string' ? path : (req.url ? req.url.path || req.url : undefined)
|
||||
}
|
||||
|
||||
if (req.query) {
|
||||
_req.query = req.query
|
||||
}
|
||||
|
||||
if (req.params) {
|
||||
_req.params = req.params
|
||||
}
|
||||
|
||||
_req.headers = req.headers
|
||||
_req.remoteAddress = connection && connection.remoteAddress
|
||||
_req.remotePort = connection && connection.remotePort
|
||||
// req.raw is for hapi compat/equivalence
|
||||
_req.raw = req.raw || req
|
||||
return _req
|
||||
}
|
||||
|
||||
function mapHttpRequest (req) {
|
||||
return {
|
||||
req: reqSerializer(req)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
export var RegularExpressionFlags;
|
||||
(function (RegularExpressionFlags) {
|
||||
RegularExpressionFlags[RegularExpressionFlags["None"] = 0] = "None";
|
||||
RegularExpressionFlags[RegularExpressionFlags["HasIndices"] = 1] = "HasIndices";
|
||||
RegularExpressionFlags[RegularExpressionFlags["Global"] = 2] = "Global";
|
||||
RegularExpressionFlags[RegularExpressionFlags["IgnoreCase"] = 4] = "IgnoreCase";
|
||||
RegularExpressionFlags[RegularExpressionFlags["Multiline"] = 8] = "Multiline";
|
||||
RegularExpressionFlags[RegularExpressionFlags["DotAll"] = 16] = "DotAll";
|
||||
RegularExpressionFlags[RegularExpressionFlags["Unicode"] = 32] = "Unicode";
|
||||
RegularExpressionFlags[RegularExpressionFlags["UnicodeSets"] = 64] = "UnicodeSets";
|
||||
RegularExpressionFlags[RegularExpressionFlags["Sticky"] = 128] = "Sticky";
|
||||
RegularExpressionFlags[RegularExpressionFlags["AnyUnicodeMode"] = 96] = "AnyUnicodeMode";
|
||||
})(RegularExpressionFlags || (RegularExpressionFlags = {}));
|
||||
//# sourceMappingURL=regularExpressionFlags.js.map
|
||||
@@ -0,0 +1,44 @@
|
||||
'use strict';
|
||||
|
||||
const StreamBase = require('./StreamBase');
|
||||
const withParser = require('../utils/withParser');
|
||||
|
||||
class StreamArray extends StreamBase {
|
||||
static make(options) {
|
||||
return new StreamArray(options);
|
||||
}
|
||||
|
||||
static withParser(options) {
|
||||
return withParser(StreamArray.make, options);
|
||||
}
|
||||
|
||||
constructor(options) {
|
||||
super(options);
|
||||
this._level = 1;
|
||||
this._counter = 0;
|
||||
}
|
||||
|
||||
_wait(chunk, _, callback) {
|
||||
// first chunk should open an array
|
||||
if (chunk.name !== 'startArray') {
|
||||
return callback(new Error('Top-level object should be an array.'));
|
||||
}
|
||||
this._transform = this._filter;
|
||||
return this._transform(chunk, _, callback);
|
||||
}
|
||||
|
||||
_push(discard) {
|
||||
if (this._assembler.current.length) {
|
||||
if (discard) {
|
||||
++this._counter;
|
||||
this._assembler.current.pop();
|
||||
} else {
|
||||
this.push({key: this._counter++, value: this._assembler.current.pop()});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
StreamArray.streamArray = StreamArray.make;
|
||||
StreamArray.make.Constructor = StreamArray;
|
||||
|
||||
module.exports = StreamArray;
|
||||
@@ -0,0 +1,23 @@
|
||||
/*! *****************************************************************************
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
||||
this file except in compliance with the License. You may obtain a copy of the
|
||||
License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
||||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
||||
MERCHANTABLITY OR NON-INFRINGEMENT.
|
||||
|
||||
See the Apache Version 2.0 License for specific language governing permissions
|
||||
and limitations under the License.
|
||||
***************************************************************************** */
|
||||
|
||||
|
||||
/// <reference no-default-lib="true"/>
|
||||
|
||||
/// <reference lib="es2015" />
|
||||
/// <reference lib="dom" />
|
||||
/// <reference lib="dom.iterable" />
|
||||
/// <reference lib="webworker.importscripts" />
|
||||
/// <reference lib="scripthost" />
|
||||
@@ -0,0 +1,2 @@
|
||||
declare function getExePath(): string;
|
||||
export default getExePath;
|
||||
@@ -0,0 +1,8 @@
|
||||
import { createWriteStream } from 'fs'
|
||||
import { once } from 'events'
|
||||
|
||||
export default async function run (opts) {
|
||||
const stream = createWriteStream(opts.dest)
|
||||
await once(stream, 'open')
|
||||
return stream
|
||||
}
|
||||
Reference in New Issue
Block a user