UNPKG

@strapi/strapi

Version:

An open source headless CMS solution to create and manage your own API. It provides a powerful dashboard and features to make your life easier. Databases supported: MySQL, MariaDB, PostgreSQL, SQLite

1 lines 3.37 kB
{"version":3,"file":"files.mjs","sources":["../../../../src/node/core/files.ts"],"sourcesContent":["import path from 'node:path';\nimport { access } from 'node:fs/promises';\nimport { register } from 'esbuild-register/dist/node';\n\n/**\n * @internal\n */\nconst pathExists = async (path: string) => {\n try {\n await access(path);\n return true;\n } catch (error) {\n return false;\n }\n};\n\n/**\n * @internal\n */\nconst loadFile = async (path: string): Promise<undefined | any> => {\n if (await pathExists(path)) {\n const esbuildOptions: Parameters<typeof register>[0] = {\n extensions: ['.js', '.mjs', '.ts'],\n };\n\n const { unregister } = register(esbuildOptions);\n\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n const mod = require(path);\n\n unregister();\n\n /**\n * handles esm or cjs exporting.\n */\n const file = mod?.default || mod || undefined;\n\n return file;\n }\n\n return undefined;\n};\n\n/**\n * @internal\n *\n * @description Converts a system path to a module path mainly for `Windows` systems.\n * where the path separator is `\\` instead of `/`, on linux systems the path separator\n * is identical to the module path separator.\n */\nconst convertSystemPathToModulePath = (sysPath: string) => {\n if (process.platform === 'win32') {\n return sysPath.split(path.sep).join(path.posix.sep);\n }\n\n return sysPath;\n};\n\n/**\n * @internal\n *\n * @description Converts a module path to a system path, again largely used for Windows systems.\n * The original use case was plugins where the resolve path was in module format but we want to\n * have it relative to the runtime directory.\n */\nconst convertModulePathToSystemPath = (modulePath: string) => {\n if (process.platform === 'win32') {\n return modulePath.split(path.posix.sep).join(path.sep);\n }\n\n return modulePath;\n};\n\nexport { pathExists, loadFile, convertSystemPathToModulePath, convertModulePathToSystemPath };\n"],"names":["pathExists","path","access","error","loadFile","esbuildOptions","extensions","unregister","register","mod","require","file","default","undefined","convertSystemPathToModulePath","sysPath","process","platform","split","sep","join","posix","convertModulePathToSystemPath","modulePath"],"mappings":";;;;AAIA;;IAGA,MAAMA,aAAa,OA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