@liuli-util/cli 3.21.0 → 3.22.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin.js +1 -1
- package/dist/bin.js +152 -106
- package/dist/bin.js.map +3 -3
- package/dist/commands/deploy/util/execPromise.d.ts +1 -0
- package/dist/commands/deploy/util/execPromise.d.ts.map +1 -1
- package/dist/commands/esbuild/ESBuildProgram.d.ts +0 -6
- package/dist/commands/esbuild/ESBuildProgram.d.ts.map +1 -1
- package/dist/commands/esbuild/util/autoExternal.d.ts +7 -0
- package/dist/commands/esbuild/util/autoExternal.d.ts.map +1 -0
- package/dist/commands/esbuild/util/env.d.ts +16 -0
- package/dist/commands/esbuild/util/env.d.ts.map +1 -0
- package/dist/commands/esbuild/util/index.d.ts +11 -0
- package/dist/commands/esbuild/util/index.d.ts.map +1 -0
- package/dist/commands/esbuild/util/log.d.ts +3 -0
- package/dist/commands/esbuild/util/log.d.ts.map +1 -0
- package/dist/commands/esbuild/util/metafile.d.ts +7 -0
- package/dist/commands/esbuild/util/metafile.d.ts.map +1 -0
- package/dist/commands/esbuild/util/nativeNodeModules.d.ts +7 -0
- package/dist/commands/esbuild/util/nativeNodeModules.d.ts.map +1 -0
- package/dist/commands/esbuild/util/nodeExternal.d.ts +6 -0
- package/dist/commands/esbuild/util/nodeExternal.d.ts.map +1 -0
- package/dist/commands/esbuild/util/raw.d.ts +7 -0
- package/dist/commands/esbuild/util/raw.d.ts.map +1 -0
- package/dist/commands/esbuild/util/resolve.d.ts +8 -0
- package/dist/commands/esbuild/util/resolve.d.ts.map +1 -0
- package/dist/commands/esbuild/util/sideEffect.d.ts +8 -0
- package/dist/commands/esbuild/util/sideEffect.d.ts.map +1 -0
- package/dist/commands/esbuild/util/userJS.d.ts +3 -0
- package/dist/commands/esbuild/util/userJS.d.ts.map +1 -0
- package/dist/index.esm.js +3 -3
- package/dist/index.esm.js.map +3 -3
- package/dist/index.js +3 -3
- package/dist/index.js.map +3 -3
- package/package.json +40 -36
- package/src/commands/esbuild/ESBuildProgram.ts +5 -9
- package/src/commands/esbuild/__tests__/ESBuildProgram.test.ts +2 -2
- package/src/commands/esbuild/util/autoExternal.ts +22 -0
- package/src/commands/esbuild/util/env.ts +67 -0
- package/src/commands/esbuild/util/index.ts +10 -0
- package/src/commands/esbuild/util/log.ts +20 -0
- package/src/commands/esbuild/util/metafile.ts +17 -0
- package/src/commands/esbuild/util/nativeNodeModules.ts +43 -0
- package/src/commands/esbuild/util/nodeExternal.ts +16 -0
- package/src/commands/esbuild/util/raw.ts +27 -0
- package/src/commands/esbuild/util/resolve.ts +22 -0
- package/src/commands/esbuild/util/sideEffect.ts +29 -0
- package/src/commands/esbuild/util/userJS.ts +38 -0
- package/templates/cli/package.json +35 -33
- package/templates/lib/package.json +24 -19
- package/dist/commands/esbuild/util/esbuildPlugins.d.ts +0 -32
- package/dist/commands/esbuild/util/esbuildPlugins.d.ts.map +0 -1
- package/src/commands/esbuild/__tests__/.temp/package.json +0 -1
- package/src/commands/esbuild/__tests__/.temp/src/index.ts +0 -1
- package/src/commands/esbuild/util/__tests__/.temp/index.js +0 -1
- package/src/commands/esbuild/util/__tests__/esbuildPlugins.test.ts +0 -52
- package/src/commands/esbuild/util/esbuildPlugins.ts +0 -196
- package/src/commands/generate/__tests__/.temp/README.md +0 -1
- package/src/commands/generate/__tests__/.temp/package.json +0 -3
- package/src/commands/generate/__tests__/.temp/test-cli/CHANGELOG.md +0 -1
- package/src/commands/generate/__tests__/.temp/test-cli/README.md +0 -1
- package/src/commands/generate/__tests__/.temp/test-cli/bin.js +0 -3
- package/src/commands/generate/__tests__/.temp/test-cli/package.json +0 -33
- package/src/commands/generate/__tests__/.temp/test-cli/src/bin.ts +0 -13
- package/src/commands/generate/__tests__/.temp/test-cli/src/index.ts +0 -1
- package/src/commands/generate/__tests__/.temp/test-cli/tsconfig.json +0 -28
- package/src/commands/sync/__tests__/.temp/package.json +0 -16
- package/wallaby.conf.js +0 -3
@@ -1,196 +0,0 @@
|
|
1
|
-
import { Plugin } from 'esbuild'
|
2
|
-
import { readFile, readJson, writeJson } from 'fs-extra'
|
3
|
-
import * as path from 'path'
|
4
|
-
|
5
|
-
/**
|
6
|
-
* 处理 nodejs 原生模块
|
7
|
-
* @link https://github.com/evanw/esbuild/issues/1051#issuecomment-806325487
|
8
|
-
*/
|
9
|
-
export function nativeNodeModules(): Plugin {
|
10
|
-
return {
|
11
|
-
name: 'native-node-modules',
|
12
|
-
setup(build) {
|
13
|
-
// If a ".node" file is imported within a module in the "file" namespace, resolve
|
14
|
-
// it to an absolute path and put it into the "node-file" virtual namespace.
|
15
|
-
build.onResolve({ filter: /\.node$/, namespace: 'file' }, (args) => ({
|
16
|
-
path: require.resolve(args.path, { paths: [args.resolveDir] }),
|
17
|
-
namespace: 'node-file',
|
18
|
-
}))
|
19
|
-
|
20
|
-
// Files in the "node-file" virtual namespace call "require()" on the
|
21
|
-
// path from esbuild of the ".node" file in the output directory.
|
22
|
-
build.onLoad({ filter: /.*/, namespace: 'node-file' }, (args) => ({
|
23
|
-
contents: `
|
24
|
-
import path from ${JSON.stringify(args.path)}
|
25
|
-
try { module.exports = require(path) }
|
26
|
-
catch {}
|
27
|
-
`,
|
28
|
-
}))
|
29
|
-
|
30
|
-
// If a ".node" file is imported within a module in the "node-file" namespace, put
|
31
|
-
// it in the "file" namespace where esbuild's default loading behavior will handle
|
32
|
-
// it. It is already an absolute path since we resolved it to one above.
|
33
|
-
build.onResolve({ filter: /\.node$/, namespace: 'node-file' }, (args) => ({
|
34
|
-
path: args.path,
|
35
|
-
namespace: 'file',
|
36
|
-
}))
|
37
|
-
|
38
|
-
// Tell esbuild's default loading behavior to use the "file" loader for
|
39
|
-
// these ".node" files.
|
40
|
-
const opts = build.initialOptions
|
41
|
-
opts.loader = opts.loader || {}
|
42
|
-
opts.loader['.node'] = 'file'
|
43
|
-
},
|
44
|
-
}
|
45
|
-
}
|
46
|
-
|
47
|
-
/**
|
48
|
-
* 排除和替换 node 内置模块
|
49
|
-
*/
|
50
|
-
export function nodeExternals(): Plugin {
|
51
|
-
return {
|
52
|
-
name: 'esbuild-plugin-node-externals',
|
53
|
-
setup(build) {
|
54
|
-
build.onResolve({ filter: /(^node:)/ }, (args) => ({
|
55
|
-
path: args.path.slice(5),
|
56
|
-
external: true,
|
57
|
-
}))
|
58
|
-
},
|
59
|
-
}
|
60
|
-
}
|
61
|
-
|
62
|
-
/**
|
63
|
-
* 自动排除所有依赖项
|
64
|
-
* golang 不支持 js 的一些语法,参考 https://github.com/evanw/esbuild/issues/1634
|
65
|
-
*/
|
66
|
-
export function autoExternal(): Plugin {
|
67
|
-
return {
|
68
|
-
name: 'esbuild-plugin-auto-external',
|
69
|
-
setup(build) {
|
70
|
-
build.onResolve({ filter: /.*/ }, (args) => {
|
71
|
-
if (/^\.{1,2}\//.test(args.path)) {
|
72
|
-
return
|
73
|
-
}
|
74
|
-
return {
|
75
|
-
path: args.path,
|
76
|
-
external: true,
|
77
|
-
}
|
78
|
-
})
|
79
|
-
},
|
80
|
-
}
|
81
|
-
}
|
82
|
-
|
83
|
-
/**
|
84
|
-
* 通过 ?raw 将资源作为字符串打包进来
|
85
|
-
* @returns
|
86
|
-
*/
|
87
|
-
export function raw(): Plugin {
|
88
|
-
return {
|
89
|
-
name: 'esbuild-plugin-raw',
|
90
|
-
setup(build) {
|
91
|
-
build.onResolve({ filter: /\?raw$/ }, (args) => {
|
92
|
-
return {
|
93
|
-
path: path.isAbsolute(args.path) ? args.path : path.join(args.resolveDir, args.path),
|
94
|
-
namespace: 'raw-loader',
|
95
|
-
}
|
96
|
-
})
|
97
|
-
build.onLoad({ filter: /\?raw$/, namespace: 'raw-loader' }, async (args) => {
|
98
|
-
return {
|
99
|
-
contents: await readFile(args.path.replace(/\?raw$/, '')),
|
100
|
-
loader: 'text',
|
101
|
-
}
|
102
|
-
})
|
103
|
-
},
|
104
|
-
}
|
105
|
-
}
|
106
|
-
|
107
|
-
/**
|
108
|
-
* @param {string} str
|
109
|
-
*/
|
110
|
-
function isValidId(str: string) {
|
111
|
-
try {
|
112
|
-
new Function(`var ${str};`)
|
113
|
-
} catch (err) {
|
114
|
-
return false
|
115
|
-
}
|
116
|
-
return true
|
117
|
-
}
|
118
|
-
|
119
|
-
function defineImportEnv() {
|
120
|
-
const definitions: Record<string, string> = {}
|
121
|
-
Object.keys(process.env).forEach((key) => {
|
122
|
-
if (isValidId(key)) {
|
123
|
-
definitions[`import.meta.env.${key}`] = JSON.stringify(process.env[key])
|
124
|
-
}
|
125
|
-
})
|
126
|
-
definitions['import.meta.env'] = '{}'
|
127
|
-
return definitions
|
128
|
-
}
|
129
|
-
|
130
|
-
/**
|
131
|
-
* Pass environment variables to esbuild.
|
132
|
-
* @return An esbuild plugin.
|
133
|
-
*/
|
134
|
-
export function envPlugin(): Plugin {
|
135
|
-
return {
|
136
|
-
name: 'esbuild-plugin-env',
|
137
|
-
setup(build) {
|
138
|
-
const { platform, define = {} } = build.initialOptions
|
139
|
-
if (platform === 'node') {
|
140
|
-
return
|
141
|
-
}
|
142
|
-
build.initialOptions.define = define
|
143
|
-
Object.assign(build.initialOptions.define, defineImportEnv())
|
144
|
-
},
|
145
|
-
}
|
146
|
-
}
|
147
|
-
|
148
|
-
/**
|
149
|
-
* 生成 metafile 的插件
|
150
|
-
* @param metafilePath
|
151
|
-
*/
|
152
|
-
export function metafile(metafilePath: string): Plugin {
|
153
|
-
return {
|
154
|
-
name: 'esbuild-plugin-metafile',
|
155
|
-
setup(builder) {
|
156
|
-
builder.onEnd(async (result) => {
|
157
|
-
await writeJson(metafilePath, result.metafile)
|
158
|
-
})
|
159
|
-
},
|
160
|
-
}
|
161
|
-
}
|
162
|
-
|
163
|
-
function generateBanner(meta: object) {
|
164
|
-
return (
|
165
|
-
[
|
166
|
-
'// ==UserScript==',
|
167
|
-
...Object.entries(meta)
|
168
|
-
.map(([key, value]) => {
|
169
|
-
if (Array.isArray(value)) {
|
170
|
-
return value.map((item) => `// @${key} ${item}`)
|
171
|
-
}
|
172
|
-
return `// @${key} ${value}`
|
173
|
-
})
|
174
|
-
.flat(),
|
175
|
-
'// ==/UserScript==',
|
176
|
-
].join('\n') + '\n'
|
177
|
-
)
|
178
|
-
}
|
179
|
-
|
180
|
-
export function userJS(): Plugin {
|
181
|
-
return {
|
182
|
-
name: 'esbuild-plugin-userjs',
|
183
|
-
async setup(build) {
|
184
|
-
const json = (await readJson(path.resolve(build.initialOptions.absWorkingDir!, 'package.json'))) as {
|
185
|
-
userjs: object
|
186
|
-
}
|
187
|
-
if (!json.userjs) {
|
188
|
-
throw new Error('userjs is not supported')
|
189
|
-
}
|
190
|
-
if (!build.initialOptions.banner) {
|
191
|
-
build.initialOptions.banner = {}
|
192
|
-
}
|
193
|
-
build.initialOptions.banner!['js'] = generateBanner(json.userjs)
|
194
|
-
},
|
195
|
-
}
|
196
|
-
}
|
@@ -1 +0,0 @@
|
|
1
|
-
# @liuli-util/.temp
|
@@ -1 +0,0 @@
|
|
1
|
-
# CHANGELOG
|
@@ -1 +0,0 @@
|
|
1
|
-
# @liuli-util/cli-test-cli
|
@@ -1,33 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"name": "test-cli",
|
3
|
-
"version": "0.1.0",
|
4
|
-
"main": "dist/index.js",
|
5
|
-
"module": "dist/index.esm.js",
|
6
|
-
"types": "dist/index.d.ts",
|
7
|
-
"license": "MIT",
|
8
|
-
"scripts": {
|
9
|
-
"build": "liuli-cli build cli",
|
10
|
-
"dev": "liuli-cli build cli -w",
|
11
|
-
"start": "esno src/bin.ts"
|
12
|
-
},
|
13
|
-
"bin": {
|
14
|
-
"cli-name": "./bin.js"
|
15
|
-
},
|
16
|
-
"dependencies": {
|
17
|
-
"commander": "^8.2.0",
|
18
|
-
"enquirer": "^2.3.6",
|
19
|
-
"fs-extra": "^10.0.0"
|
20
|
-
},
|
21
|
-
"devDependencies": {
|
22
|
-
"@liuli-util/cli": "^3.18.0",
|
23
|
-
"@types/fs-extra": "^9.0.13",
|
24
|
-
"@types/jest": "^27.0.2",
|
25
|
-
"@types/node": "^16.9.6",
|
26
|
-
"esno": "^0.9.1",
|
27
|
-
"jest": "^27.4.7",
|
28
|
-
"rimraf": "^3.0.2",
|
29
|
-
"ts-jest": "^27.1.3",
|
30
|
-
"type-fest": "^2.3.4",
|
31
|
-
"typescript": "^4.5.5"
|
32
|
-
}
|
33
|
-
}
|
@@ -1,13 +0,0 @@
|
|
1
|
-
import { Command } from 'commander'
|
2
|
-
import { prompt } from 'enquirer'
|
3
|
-
|
4
|
-
new Command()
|
5
|
-
.action(async () => {
|
6
|
-
const { name } = await prompt<{ name: string }>({
|
7
|
-
type: 'input',
|
8
|
-
name: 'name',
|
9
|
-
message: '请输入名字',
|
10
|
-
})
|
11
|
-
console.log(`hello ${name}`)
|
12
|
-
})
|
13
|
-
.parse()
|
@@ -1 +0,0 @@
|
|
1
|
-
export {}
|
@@ -1,28 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"compilerOptions": {
|
3
|
-
"target": "ESNext",
|
4
|
-
"lib": [
|
5
|
-
"ESNext"
|
6
|
-
],
|
7
|
-
"outDir": "./dist",
|
8
|
-
"skipLibCheck": true,
|
9
|
-
"esModuleInterop": true,
|
10
|
-
"strict": true,
|
11
|
-
"module": "ESNext",
|
12
|
-
"moduleResolution": "node",
|
13
|
-
"sourceMap": true,
|
14
|
-
"declaration": true,
|
15
|
-
"declarationMap": true
|
16
|
-
},
|
17
|
-
"include": [
|
18
|
-
"src"
|
19
|
-
],
|
20
|
-
"typedocOptions": {
|
21
|
-
"entryPoints": [
|
22
|
-
"src/index.ts"
|
23
|
-
],
|
24
|
-
"out": "docs",
|
25
|
-
"readme": "README.md",
|
26
|
-
"gitRemote": "origin"
|
27
|
-
}
|
28
|
-
}
|
package/wallaby.conf.js
DELETED