UNPKG

@modern-js/utils

Version:

A Progressive React Framework for modern web development.

148 lines (147 loc) • 6.61 kB
"use strict"; var __webpack_require__ = {}; (()=>{ __webpack_require__.n = (module)=>{ var getter = module && module.__esModule ? ()=>module['default'] : ()=>module; __webpack_require__.d(getter, { a: getter }); return getter; }; })(); (()=>{ __webpack_require__.d = (exports1, definition)=>{ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, { enumerable: true, get: definition[key] }); }; })(); (()=>{ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop); })(); (()=>{ __webpack_require__.r = (exports1)=>{ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, { value: 'Module' }); Object.defineProperty(exports1, '__esModule', { value: true }); }; })(); var __webpack_exports__ = {}; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { getReactVersion: ()=>getReactVersion, isApiOnly: ()=>isApiOnly, isBeyondReact17: ()=>isBeyondReact17, isDepExists: ()=>isDepExists, isPackageInstalled: ()=>isPackageInstalled, isReact18: ()=>isReact18, isSupportAutomaticJsx: ()=>isSupportAutomaticJsx, isTypescript: ()=>isTypescript, isVersionBeyond17: ()=>isVersionBeyond17, isWebOnly: ()=>isWebOnly }); const external_path_namespaceObject = require("path"); var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject); const index_js_namespaceObject = require("../../../compiled/pkg-up/index.js"); var index_js_default = /*#__PURE__*/ __webpack_require__.n(index_js_namespaceObject); const external_compiled_js_namespaceObject = require("../../compiled.js"); const external_commands_js_namespaceObject = require("../commands.js"); const external_common_js_namespaceObject = require("../common.js"); const external_ensure_js_namespaceObject = require("../ensure.js"); const external_require_js_namespaceObject = require("../require.js"); const debug = (0, external_common_js_namespaceObject.createDebugger)('judge-depExists'); const isDepExists = (appDirectory, name)=>{ const pkgPath = external_path_default().resolve(appDirectory, './package.json'); if (!external_compiled_js_namespaceObject.fs.existsSync(pkgPath)) { debug("can't find package.json under: %s", appDirectory); return false; } const json = external_compiled_js_namespaceObject.fs.readJSONSync(pkgPath); const { dependencies = {}, devDependencies = {} } = json; return dependencies.hasOwnProperty(name) || devDependencies.hasOwnProperty(name); }; const isPackageInstalled = (name, resolvePaths)=>{ try { (0, external_require_js_namespaceObject.tryResolve)(name, ...(0, external_ensure_js_namespaceObject.ensureArray)(resolvePaths)); return true; } catch (err) { return false; } }; const isApiOnly = async (appDirectory, entryDir, apiDir)=>{ const existApi = await external_compiled_js_namespaceObject.fs.pathExists(apiDir ?? external_path_default().join(appDirectory, 'api')); const existSrc = await external_compiled_js_namespaceObject.fs.pathExists(external_path_default().join(appDirectory, entryDir ?? 'src')); const options = (0, external_compiled_js_namespaceObject.minimist)((0, external_commands_js_namespaceObject.getArgv)()); if (options['api-only']) return true; return existApi && !existSrc; }; const isWebOnly = async ()=>{ const options = (0, external_compiled_js_namespaceObject.minimist)((0, external_commands_js_namespaceObject.getArgv)()); return Boolean(options['web-only']); }; const isVersionBeyond17 = (version)=>external_compiled_js_namespaceObject.semver.gte(external_compiled_js_namespaceObject.semver.minVersion(version), '17.0.0'); const getReactVersion = (cwd)=>{ const pkgPath = index_js_default().sync({ cwd }); if (!pkgPath) return false; const pkgInfo = JSON.parse(external_compiled_js_namespaceObject.fs.readFileSync(pkgPath, 'utf8')); const deps = { ...pkgInfo.devDependencies, ...pkgInfo.dependencies }; if ('string' != typeof deps.react) return false; try { const reactPath = (0, external_require_js_namespaceObject.tryResolve)('react/package.json', cwd); const reactVersion = JSON.parse(external_compiled_js_namespaceObject.fs.readFileSync(reactPath, 'utf8')).version; return reactVersion; } catch (error) { console.error('Failed to resolve React version:', error); return false; } }; const isBeyondReact17 = (cwd)=>{ const reactVersion = getReactVersion(cwd); if (!reactVersion) return false; return isVersionBeyond17(reactVersion); }; const isSupportAutomaticJsx = (cwd)=>{ const reactVersion = getReactVersion(cwd); if (!reactVersion) return false; return external_compiled_js_namespaceObject.semver.satisfies(external_compiled_js_namespaceObject.semver.minVersion(reactVersion), '>=16.14.0'); }; const isReact18 = (cwd = process.cwd())=>{ const reactVersion = getReactVersion(cwd); if (!reactVersion) return false; return external_compiled_js_namespaceObject.semver.gte(external_compiled_js_namespaceObject.semver.minVersion(reactVersion), '18.0.0'); }; const isTypescript = (root)=>external_compiled_js_namespaceObject.fs.existsSync(external_path_default().resolve(root, './tsconfig.json')); exports.getReactVersion = __webpack_exports__.getReactVersion; exports.isApiOnly = __webpack_exports__.isApiOnly; exports.isBeyondReact17 = __webpack_exports__.isBeyondReact17; exports.isDepExists = __webpack_exports__.isDepExists; exports.isPackageInstalled = __webpack_exports__.isPackageInstalled; exports.isReact18 = __webpack_exports__.isReact18; exports.isSupportAutomaticJsx = __webpack_exports__.isSupportAutomaticJsx; exports.isTypescript = __webpack_exports__.isTypescript; exports.isVersionBeyond17 = __webpack_exports__.isVersionBeyond17; exports.isWebOnly = __webpack_exports__.isWebOnly; for(var __rspack_i in __webpack_exports__)if (-1 === [ "getReactVersion", "isApiOnly", "isBeyondReact17", "isDepExists", "isPackageInstalled", "isReact18", "isSupportAutomaticJsx", "isTypescript", "isVersionBeyond17", "isWebOnly" ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i]; Object.defineProperty(exports, '__esModule', { value: true });