Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: some question #1139

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/core/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,11 @@ export class Config {
return `node "${path.resolve(this.extensionPath!, config)}"`
}

static get tsConfigPathsRegisterPath(): string {
const register = 'node_modules/tsconfig-paths/register'
return path.resolve(this.extensionPath!, register)
}

static get parsersTypescriptCompilerOption(): any {
return this.getConfig<any>('parsers.typescript.compilerOptions') || {}
}
Expand Down
18 changes: 13 additions & 5 deletions src/parsers/ecmascript.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import child_process from 'child_process'
import path from 'path'
import { existsSync } from 'fs'
import { Parser } from './base'
import i18n from '~/i18n'
import { Log } from '~/utils'
Expand Down Expand Up @@ -34,21 +35,28 @@ export class EcmascriptParser extends Parser {
const loader = path.resolve(Config.extensionPath!, 'assets/loader.js')
const tsNode = Config.parsersTypescriptTsNodePath
const dir = Global.rootpath
const projectTsConfig = `${dir}/tsconfig.json`

const { paths, ...restCompilerOption } = Config.parsersTypescriptCompilerOption
const compilerOptions = {
importHelpers: false,
allowJs: true,
module: 'commonjs',
...Config.parsersTypescriptCompilerOption,
...restCompilerOption,
}
let tsConfigPathsRegister = ''
if (paths && existsSync(projectTsConfig))
tsConfigPathsRegister = `-P "${projectTsConfig}" -r "${Config.tsConfigPathsRegisterPath}"`

const options = JSON.stringify(compilerOptions).replace(/"/g, '\\"')

return new Promise<any>((resolve, reject) => {
const cmd = `${tsNode} --dir "${dir}" --transpile-only --compiler-options "${options}" "${loader}" "${filepath}"`
const cmd = `${tsNode} ${tsConfigPathsRegister} --dir "${dir}" --transpile-only --compiler-options "${options}" "${loader}" "${filepath}"`
// eslint-disable-next-line no-console
console.log(`[i18n-ally] spawn: ${cmd}`)
child_process.exec(cmd, (err, stdout) => {
if (err)
return reject(err)
child_process.exec(cmd, (err, stdout, stderr) => {
if (err || stderr)
return reject(err || stderr)
try {
resolve(JSON.parse(stdout.trim()))
}
Expand Down