1 Star 0 Fork 0

quick-source/coc.nvim

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
esbuild.js 2.20 KB
一键复制 编辑 原始数据 按行查看 历史
chemzqm 提交于 2021-01-07 16:04 . refactor(esbuild): check node 10.12
const cp = require('child_process')
const fs = require('fs')
const path = require('path')
let revision = ''
try {
let res = cp.execSync('git rev-parse HEAD', {encoding: 'utf8'})
revision = res.trim().slice(0, 10)
} catch (e) {
// ignore
}
let entryPlugin = {
name: 'entry',
setup(build) {
build.onResolve({filter: /^index.ts$/}, args => {
return {
path: args.path,
namespace: 'entry-ns'
}
})
build.onLoad({filter: /.*/, namespace: 'entry-ns'}, () => {
let contents = `
let version = process.version.replace('v', '')
let parts = version.split('.')
function greatThanOrEqual(nums, major, minor) {
if (nums[0] > major) return true
if (nums[0] == major && nums[1] >= minor) return true
return false
}
let numbers = parts.map(function (s) {
return parseInt(s, 10)
})
if (!greatThanOrEqual(numbers, 10, 12)) {
console.error('node version ' + version + ' < 8.10.0, please upgrade nodejs, or use \`let g:coc_node_path = "/path/to/node"\` in your vimrc')
process.exit()
}
require('./src/main')
`
return {
contents,
resolveDir: __dirname
}
})
}
}
// replace require.main with empty string
let envPlugin = {
name: 'env',
setup(build) {
build.onResolve({filter: /\/appenders/}, args => {
let fullpath = path.join(args.resolveDir, args.path)
return {
path: path.relative(__dirname, fullpath),
namespace: 'env-ns'
}
})
build.onLoad({filter: /^node_modules\/log4js\/lib\/appenders$/, namespace: 'env-ns'}, args => {
let content = fs.readFileSync(path.join(args.path, 'index.js'), 'utf8')
return {
contents: content.replace(/require\.main/g, '""'),
resolveDir: args.path
}
})
}
}
async function start() {
await require('esbuild').build({
entryPoints: ['index.ts'],
bundle: true,
minify: process.env.NODE_ENV === 'production',
sourcemap: process.env.NODE_ENV === 'development',
define: {REVISION: '"' + revision + '"', ESBUILD: 'true'},
mainFields: ['module', 'main'],
platform: 'node',
target: 'node10.12',
outfile: 'build/index.js',
plugins: [entryPlugin, envPlugin]
})
}
start().catch(e => {
console.error(e)
})
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/quick-source/coc.nvim.git
[email protected]:quick-source/coc.nvim.git
quick-source
coc.nvim
coc.nvim
master

搜索帮助