Skip to content

Commit

Permalink
wip(uts): compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
fxy060608 committed Nov 17, 2022
1 parent 4d31180 commit 350fbcf
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 11 deletions.
33 changes: 32 additions & 1 deletion packages/uni-cli-shared/lib/uts/utils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,37 @@
const fs = require('fs')
const path = require('path')
const {
normalizePath
} = require('../util')

function hasProjectYarn (cwd) {
return fs.existsSync(path.join(cwd, 'yarn.lock'))
}

function hasProjectPnpm (cwd) {
return fs.existsSync(path.join(cwd, 'pnpm-lock.yaml'))
}

function getInstallCommand (cwd) {
return hasProjectYarn(cwd)
? 'yarn add'
: hasProjectPnpm(cwd)
? 'pnpm i'
: 'npm i'
}

function installDepTips (
type,
module,
version
) {
const command =
`${getInstallCommand(process.cwd())} ${module + (version ? '@' + version : '')}${type === 'devDependencies' ? ' -D' : ''}`
return `Cannot find module: ${module}
Please run \`${command}\` and try again.`
}

module.exports = {
normalizePath
normalizePath,
installDepTips
}
18 changes: 8 additions & 10 deletions packages/uni-cli-shared/lib/uts/uts.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,22 +75,20 @@ function resolveUtsFile(dir, extensions = ['.uts', '.ts', '.js']) {
}
function resolveUTSCompiler() {
let compilerPath = '';
if ((0, hbx_1.runByHBuilderX)()) {
if ((0, hbx_1.isInHBuilderX)()) {
try {
compilerPath = require.resolve(path_1.default.resolve(process.env.UNI_HBUILDERX_PLUGINS, 'uniapp-uts-v1'));
}
catch (e) { }
}
if (!compilerPath) {
try {
compilerPath = require.resolve('@dcloudio/uni-uts-v1', {
paths: [process.env.UNI_CLI_CONTEXT],
});
}
catch (e) { }
try {
compilerPath = require.resolve('@dcloudio/uni-uts-v1', {
paths: [process.env.UNI_CLI_CONTEXT],
});
}
if (!compilerPath) {
throw 'uts compiler is not found';
catch (e) {
console.error((0, utils_1.installDepTips)('devDependencies', '@dcloudio/uni-uts-v1', require('@dcloudio/uni-cli-shared/package.json').version));
process.exit(0);
}
return require(compilerPath);
}
Expand Down

0 comments on commit 350fbcf

Please sign in to comment.