Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@graphql-tools/load-files

Package Overview
Dependencies
Maintainers
3
Versions
637
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@graphql-tools/load-files - npm Package Compare versions

Comparing version 5.0.1-alpha-63acff1.0 to 5.0.1-alpha-6bafa2b.0

76

index.cjs.js

@@ -5,2 +5,4 @@ 'use strict';

function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
function _interopNamespace(e) {

@@ -25,2 +27,8 @@ if (e && e.__esModule) { return e; } else {

const globby = require('globby');
const globby__default = _interopDefault(globby);
const unixify = _interopDefault(require('unixify'));
const path = require('path');
const fsExtra = require('fs-extra');
const DEFAULT_IGNORED_EXTENSIONS = ['spec', 'test', 'd', 'map'];

@@ -37,8 +45,21 @@ const DEFAULT_EXTENSIONS = ['gql', 'graphql', 'graphqls', 'ts', 'js'];

}
function isDirectory(path) {
const { existsSync, statSync } = require('fs');
return existsSync(path) && statSync(path).isDirectory();
function isDirectorySync(path) {
try {
const pathStat = fsExtra.statSync(path);
return pathStat.isDirectory();
}
catch (e) {
return false;
}
}
function scanForFiles(globStr, globOptions = {}) {
const globby = require('globby');
async function isDirectory(path) {
try {
const pathStat = await fsExtra.stat(path);
return pathStat.isDirectory();
}
catch (e) {
return false;
}
}
function scanForFilesSync(globStr, globOptions = {}) {
return globby.sync(globStr, { absolute: true, ...globOptions });

@@ -82,20 +103,18 @@ }

};
function loadFiles(pattern, options = LoadFilesDefaultOptions) {
function loadFilesSync(pattern, options = LoadFilesDefaultOptions) {
const execOptions = { ...LoadFilesDefaultOptions, ...options };
const unixify = require('unixify');
const relevantPaths = scanForFiles(asArray(pattern).map(path => isDirectory(path)
const relevantPaths = scanForFilesSync(asArray(pattern).map(path => isDirectorySync(path)
? buildGlob(unixify(path), execOptions.extensions, execOptions.ignoredExtensions, execOptions.recursive)
: unixify(path)), options.globOptions);
return relevantPaths
.map(path => {
if (!checkExtension(path, options)) {
.map(path$1 => {
if (!checkExtension(path$1, options)) {
return;
}
if (isIndex(path, execOptions.extensions) && options.ignoreIndex) {
if (isIndex(path$1, execOptions.extensions) && options.ignoreIndex) {
return false;
}
const { extname } = require('path');
const extension = extname(path);
const extension = path.extname(path$1);
if (extension.endsWith('.js') || extension.endsWith('.ts') || execOptions.useRequire) {
const fileExports = (execOptions.requireMethod ? execOptions.requireMethod : require)(path);
const fileExports = (execOptions.requireMethod ? execOptions.requireMethod : require)(path$1);
const extractedExport = extractExports(fileExports, execOptions.exportNames);

@@ -123,4 +142,3 @@ if (extractedExport.typeDefs && extractedExport.resolvers) {

else {
const { readFileSync } = require('fs');
return readFileSync(path, { encoding: 'utf-8' });
return fsExtra.readFileSync(path$1, { encoding: 'utf-8' });
}

@@ -130,5 +148,4 @@ })

}
async function scanForFilesAsync(globStr, globOptions = {}) {
const { default: globby } = await new Promise(function (resolve) { resolve(_interopNamespace(require('globby'))); });
return globby(globStr, { absolute: true, ...globOptions });
async function scanForFiles(globStr, globOptions = {}) {
return globby__default(globStr, { absolute: true, ...globOptions });
}

@@ -153,16 +170,14 @@ const checkExtension = (path, { extensions, ignoredExtensions }) => {

};
async function loadFilesAsync(pattern, options = LoadFilesDefaultOptions) {
async function loadFiles(pattern, options = LoadFilesDefaultOptions) {
const execOptions = { ...LoadFilesDefaultOptions, ...options };
const unixify = await new Promise(function (resolve) { resolve(_interopNamespace(require('unixify'))); }).then(m => m.default || m);
const relevantPaths = await scanForFilesAsync(asArray(pattern).map(path => isDirectory(path)
const relevantPaths = await scanForFiles(asArray(pattern).map(path => isDirectory(path)
? buildGlob(unixify(path), execOptions.extensions, execOptions.ignoredExtensions, execOptions.recursive)
: unixify(path)), options.globOptions);
const require$ = (path) => new Promise(function (resolve) { resolve(_interopNamespace(require(path))); }).catch(async () => require(path));
const { extname } = await new Promise(function (resolve) { resolve(_interopNamespace(require('path'))); });
return Promise.all(relevantPaths
.filter(path => checkExtension(path, options) && !(isIndex(path, execOptions.extensions) && options.ignoreIndex))
.map(async (path) => {
const extension = extname(path);
.map(async (path$1) => {
const extension = path.extname(path$1);
if (extension.endsWith('.js') || extension.endsWith('.ts') || execOptions.useRequire) {
const fileExports = await (execOptions.requireMethod ? execOptions.requireMethod : require$)(path);
const fileExports = await (execOptions.requireMethod ? execOptions.requireMethod : require$)(path$1);
const extractedExport = extractExports(fileExports, execOptions.exportNames);

@@ -178,4 +193,3 @@ if (extractedExport.resolver) {

else {
const { promises: { readFile }, } = await new Promise(function (resolve) { resolve(_interopNamespace(require('fs'))); });
return readFile(path, { encoding: 'utf-8' });
return fsExtra.readFile(path$1, { encoding: 'utf-8' });
}

@@ -190,7 +204,3 @@ }));

exports.loadFiles = loadFiles;
exports.loadFilesAsync = loadFilesAsync;
exports.loadResolversFiles = loadFiles;
exports.loadResolversFilesAsync = loadFilesAsync;
exports.loadSchemaFiles = loadFiles;
exports.loadSchemaFilesAsync = loadFilesAsync;
exports.loadFilesSync = loadFilesSync;
//# sourceMappingURL=index.cjs.js.map

@@ -0,1 +1,2 @@

import { GlobbyOptions } from 'globby';
export interface LoadFilesOptions {

@@ -6,3 +7,3 @@ ignoredExtensions?: string[];

requireMethod?: any;
globOptions?: import('globby').GlobbyOptions;
globOptions?: GlobbyOptions;
exportNames?: string[];

@@ -12,5 +13,3 @@ recursive?: boolean;

}
export declare function loadFiles<T = any>(pattern: string | string[], options?: LoadFilesOptions): T[];
export declare function loadFilesAsync(pattern: string | string[], options?: LoadFilesOptions): Promise<any[]>;
export { loadFilesAsync as loadSchemaFilesAsync, loadFiles as loadSchemaFiles };
export { loadFilesAsync as loadResolversFilesAsync, loadFiles as loadResolversFiles };
export declare function loadFilesSync<T = any>(pattern: string | string[], options?: LoadFilesOptions): T[];
export declare function loadFiles(pattern: string | string[], options?: LoadFilesOptions): Promise<any[]>;

@@ -0,1 +1,6 @@

import globby, { sync } from 'globby';
import unixify from 'unixify';
import { extname } from 'path';
import { readFileSync, readFile, statSync, stat } from 'fs-extra';
const DEFAULT_IGNORED_EXTENSIONS = ['spec', 'test', 'd', 'map'];

@@ -12,10 +17,23 @@ const DEFAULT_EXTENSIONS = ['gql', 'graphql', 'graphqls', 'ts', 'js'];

}
function isDirectory(path) {
const { existsSync, statSync } = require('fs');
return existsSync(path) && statSync(path).isDirectory();
function isDirectorySync(path) {
try {
const pathStat = statSync(path);
return pathStat.isDirectory();
}
catch (e) {
return false;
}
}
function scanForFiles(globStr, globOptions = {}) {
const globby = require('globby');
return globby.sync(globStr, { absolute: true, ...globOptions });
async function isDirectory(path) {
try {
const pathStat = await stat(path);
return pathStat.isDirectory();
}
catch (e) {
return false;
}
}
function scanForFilesSync(globStr, globOptions = {}) {
return sync(globStr, { absolute: true, ...globOptions });
}
function buildGlob(basePath, extensions, ignoredExtensions = [], recursive) {

@@ -57,6 +75,5 @@ const ignored = ignoredExtensions.length > 0 ? `!(${ignoredExtensions.map(e => '*.' + e).join('|')})` : '*';

};
function loadFiles(pattern, options = LoadFilesDefaultOptions) {
function loadFilesSync(pattern, options = LoadFilesDefaultOptions) {
const execOptions = { ...LoadFilesDefaultOptions, ...options };
const unixify = require('unixify');
const relevantPaths = scanForFiles(asArray(pattern).map(path => isDirectory(path)
const relevantPaths = scanForFilesSync(asArray(pattern).map(path => isDirectorySync(path)
? buildGlob(unixify(path), execOptions.extensions, execOptions.ignoredExtensions, execOptions.recursive)

@@ -72,3 +89,2 @@ : unixify(path)), options.globOptions);

}
const { extname } = require('path');
const extension = extname(path);

@@ -99,3 +115,2 @@ if (extension.endsWith('.js') || extension.endsWith('.ts') || execOptions.useRequire) {

else {
const { readFileSync } = require('fs');
return readFileSync(path, { encoding: 'utf-8' });

@@ -106,4 +121,3 @@ }

}
async function scanForFilesAsync(globStr, globOptions = {}) {
const { default: globby } = await import('globby');
async function scanForFiles(globStr, globOptions = {}) {
return globby(globStr, { absolute: true, ...globOptions });

@@ -129,10 +143,8 @@ }

};
async function loadFilesAsync(pattern, options = LoadFilesDefaultOptions) {
async function loadFiles(pattern, options = LoadFilesDefaultOptions) {
const execOptions = { ...LoadFilesDefaultOptions, ...options };
const unixify = await import('unixify').then(m => m.default || m);
const relevantPaths = await scanForFilesAsync(asArray(pattern).map(path => isDirectory(path)
const relevantPaths = await scanForFiles(asArray(pattern).map(path => isDirectory(path)
? buildGlob(unixify(path), execOptions.extensions, execOptions.ignoredExtensions, execOptions.recursive)
: unixify(path)), options.globOptions);
const require$ = (path) => import(path).catch(async () => require(path));
const { extname } = await import('path');
return Promise.all(relevantPaths

@@ -154,3 +166,2 @@ .filter(path => checkExtension(path, options) && !(isIndex(path, execOptions.extensions) && options.ignoreIndex))

else {
const { promises: { readFile }, } = await import('fs');
return readFile(path, { encoding: 'utf-8' });

@@ -165,3 +176,3 @@ }

export { loadFiles, loadFilesAsync, loadFiles as loadResolversFiles, loadFilesAsync as loadResolversFilesAsync, loadFiles as loadSchemaFiles, loadFilesAsync as loadSchemaFilesAsync };
export { loadFiles, loadFilesSync };
//# sourceMappingURL=index.esm.js.map
{
"name": "@graphql-tools/load-files",
"version": "5.0.1-alpha-63acff1.0",
"version": "5.0.1-alpha-6bafa2b.0",
"description": "A set of utils for faster development of GraphQL tools",

@@ -10,3 +10,4 @@ "peerDependencies": {

"globby": "11.0.0",
"unixify": "1.0.0"
"unixify": "1.0.0",
"fs-extra": "9.0.0"
},

@@ -22,2 +23,5 @@ "repository": "git@github.com:ardatan/graphql-tools.git",

},
"devDependencies": {
"@types/fs-extra": "8.1.0"
},
"publishConfig": {

@@ -24,0 +28,0 @@ "access": "public"

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc