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,EAAE,QAAQ,CAAC,GAAG,KAAK,CAAC,cAAc,CAAC,CAAC;IAC7D,MAAM,KAAK,GACT,KAAK,GAAG,QAAQ;QAChB,CAAC,KAAK,KAAK,QAAQ;YACjB,CAAC,KAAK,GAAG,QAAQ,IAAI,CAAC,KAAK,KAAK,QAAQ,IAAI,KAAK,IAAI,QAAQ,CAAC,CAAC,CAAC,CAAC;IACrE,IAAI,IAAI,GAAG,IAAI,CAAC;IAChB,IAAI,aAAa,EAAE;QACjB,MAAM,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,GAAG,KAAK,CAAC,aAAa,CAAC,CAAC;QACzD,IAAI;YACF,KAAK,GAAG,OAAO;gBACf,CAAC,KAAK,KAAK,OAAO;oBAChB,CAAC,KAAK,GAAG,OAAO,IAAI,CAAC,KAAK,KAAK,OAAO,IAAI,KAAK,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;KAClE;IACD,OAAO,KAAK,IAAI,IAAI,CAAC;IAErB,SAAS,KAAK,CAAC,WAAmB;QAChC,OAAO,WAAW,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;IAChE,CAAC;AACH,CAAC;AAxBD,oCAwBC","sourcesContent":["import {\n createRequire as nodeCreateRequire,\n createRequireFromPath as nodeCreateRequireFromPath,\n} from 'module';\nimport type _createRequire from 'create-require';\nimport * as ynModule from 'yn';\nimport { dirname } from 'path';\n\n/** @internal */\nexport const createRequire =\n nodeCreateRequire ??\n nodeCreateRequireFromPath ??\n (require('create-require') as typeof _createRequire);\n\n/**\n * Wrapper around yn module that returns `undefined` instead of `null`.\n * This is implemented by yn v4, but we're staying on v3 to avoid v4's node 10 requirement.\n * @internal\n */\nexport function yn(value: string | undefined) {\n return ynModule(value) ?? undefined;\n}\n\n/**\n * Like `Object.assign`, but ignores `undefined` properties.\n *\n * @internal\n */\nexport function assign<T extends object>(\n initialValue: T,\n ...sources: Array<T>\n): T {\n for (const source of sources) {\n for (const key of Object.keys(source)) {\n const value = (source as any)[key];\n if (value !== undefined) (initialValue as any)[key] = value;\n }\n }\n return initialValue;\n}\n\n/**\n * Split a string array of values\n * and remove empty strings from the resulting array.\n * @internal\n */\nexport function split(value: string | undefined) {\n return typeof value === 'string'\n ? value.split(/ *, */g).filter((v) => v !== '')\n : undefined;\n}\n\n/**\n * Parse a string as JSON.\n * @internal\n */\nexport function parse(value: string | undefined): object | undefined {\n return typeof value === 'string' ? JSON.parse(value) : undefined;\n}\n\nconst directorySeparator = '/';\nconst backslashRegExp = /\\\\/g;\n/**\n * Replace backslashes with forward slashes.\n * @internal\n */\nexport function normalizeSlashes(value: string): string {\n return value.replace(backslashRegExp, directorySeparator);\n}\n\n/**\n * Safe `hasOwnProperty`\n * @internal\n */\nexport function hasOwnProperty(object: any, property: string): boolean {\n return Object.prototype.hasOwnProperty.call(object, property);\n}\n\n/**\n * Cached fs operation wrapper.\n */\nexport function cachedLookup<T, R>(fn: (arg: T) => R): (arg: T) => R {\n const cache = new Map<T, R>();\n\n return (arg: T): R => {\n if (!cache.has(arg)) {\n const v = fn(arg);\n cache.set(arg, v);\n return v;\n }\n return cache.get(arg)!;\n };\n}\n\n/**\n * @internal\n * Require something with v8-compile-cache, which should make subsequent requires faster.\n * Do lots of error-handling so that, worst case, we require without the cache, and users are not blocked.\n */\nexport function attemptRequireWithV8CompileCache(\n requireFn: typeof require,\n specifier: string\n) {\n try {\n const v8CC = (\n require('v8-compile-cache-lib') as typeof import('v8-compile-cache-lib')\n ).install();\n try {\n return requireFn(specifier);\n } finally {\n v8CC?.uninstall();\n }\n } catch (e) {\n return requireFn(specifier);\n }\n}\n\n/**\n * Helper to discover dependencies relative to a user's project, optionally\n * falling back to relative to ts-node. This supports global installations of\n * ts-node, for example where someone does `#!/usr/bin/env -S ts-node --swc` and\n * we need to fallback to a global install of @swc/core\n * @internal\n */\nexport function createProjectLocalResolveHelper(localDirectory: string) {\n return function projectLocalResolveHelper(\n specifier: string,\n fallbackToTsNodeRelative: boolean\n ) {\n return require.resolve(specifier, {\n paths: fallbackToTsNodeRelative\n ? [localDirectory, __dirname]\n : [localDirectory],\n });\n };\n}\n/** @internal */\nexport type ProjectLocalResolveHelper = ReturnType<\n typeof createProjectLocalResolveHelper\n>;\n\n/**\n * Used as a reminder of all the factors we must consider when finding project-local dependencies and when a config file\n * on disk may or may not exist.\n * @internal\n */\nexport function getBasePathForProjectLocalDependencyResolution(\n configFilePath: string | undefined,\n projectSearchDirOption: string | undefined,\n projectOption: string | undefined,\n cwdOption: string\n) {\n if (configFilePath != null) return dirname(configFilePath);\n return projectSearchDirOption ?? projectOption ?? cwdOption;\n // TODO technically breaks if projectOption is path to a file, not a directory,\n // and we attempt to resolve relative specifiers. By the time we resolve relative specifiers,\n // should have configFilePath, so not reach this codepath.\n}\n\n/** @internal */\nexport function once<Fn extends (...args: any[]) => any>(fn: Fn) {\n let value: ReturnType<Fn>;\n let ran = false;\n function onceFn(...args: Parameters<Fn>): ReturnType<Fn> {\n if (ran) return value;\n value = fn(...args);\n ran = true;\n return value;\n }\n return onceFn;\n}\n\n/** @internal */\nexport function versionGteLt(\n version: string,\n gteRequirement: string,\n ltRequirement?: string\n) {\n const [major, minor, patch, extra] = parse(version);\n const [gteMajor, gteMinor, gtePatch] = parse(gteRequirement);\n const isGte =\n major > gteMajor ||\n (major === gteMajor &&\n (minor > gteMinor || (minor === gteMinor && patch >= gtePatch)));\n let isLt = true;\n if (ltRequirement) {\n const [ltMajor, ltMinor, ltPatch] = parse(ltRequirement);\n isLt =\n major < ltMajor ||\n (major === ltMajor &&\n (minor < ltMinor || (minor === ltMinor && patch < ltPatch)));\n }\n return isGte && isLt;\n\n function parse(requirement: string) {\n return requirement.split(/[\\.-]/).map((s) => parseInt(s, 10));\n }\n}\n"]}
\No newline at end of file