@liuli-util/cli 3.20.2 → 3.22.0
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/CHANGELOG.md +22 -0
- package/README.md +69 -25
- package/README.zh-CN.md +7 -7
- package/package.json +40 -36
- package/src/commands/deploy/DeployService.ts +20 -2
- package/src/commands/deploy/__tests__/DeployService.test.ts +23 -4
- 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/PathUtil.d.ts +0 -7
- package/dist/PathUtil.d.ts.map +0 -1
- package/dist/bin.d.ts +0 -2
- package/dist/bin.d.ts.map +0 -1
- package/dist/bin.js +0 -171
- package/dist/bin.js.map +0 -7
- package/dist/commands/deploy/DeployService.d.ts +0 -70
- package/dist/commands/deploy/DeployService.d.ts.map +0 -1
- package/dist/commands/deploy/deploy.d.ts +0 -3
- package/dist/commands/deploy/deploy.d.ts.map +0 -1
- package/dist/commands/deploy/index.d.ts +0 -3
- package/dist/commands/deploy/index.d.ts.map +0 -1
- package/dist/commands/deploy/util/PromiseUtil.d.ts +0 -14
- package/dist/commands/deploy/util/PromiseUtil.d.ts.map +0 -1
- package/dist/commands/deploy/util/createArchive.d.ts +0 -10
- package/dist/commands/deploy/util/createArchive.d.ts.map +0 -1
- package/dist/commands/deploy/util/execPromise.d.ts +0 -4
- package/dist/commands/deploy/util/execPromise.d.ts.map +0 -1
- package/dist/commands/deploy/util/validate.d.ts +0 -8
- package/dist/commands/deploy/util/validate.d.ts.map +0 -1
- package/dist/commands/deploy/util/wait.d.ts +0 -9
- package/dist/commands/deploy/util/wait.d.ts.map +0 -1
- package/dist/commands/esbuild/ESBuildProgram.d.ts +0 -83
- package/dist/commands/esbuild/ESBuildProgram.d.ts.map +0 -1
- package/dist/commands/esbuild/index.d.ts +0 -3
- package/dist/commands/esbuild/index.d.ts.map +0 -1
- package/dist/commands/esbuild/util/debounce.d.ts +0 -15
- package/dist/commands/esbuild/util/debounce.d.ts.map +0 -1
- package/dist/commands/esbuild/util/esbuildPlugins.d.ts +0 -32
- package/dist/commands/esbuild/util/esbuildPlugins.d.ts.map +0 -1
- package/dist/commands/esbuild/util/getPkgGlobalName.d.ts +0 -6
- package/dist/commands/esbuild/util/getPkgGlobalName.d.ts.map +0 -1
- package/dist/commands/generate/GenerateProgram.d.ts +0 -18
- package/dist/commands/generate/GenerateProgram.d.ts.map +0 -1
- package/dist/commands/generate/index.d.ts +0 -3
- package/dist/commands/generate/index.d.ts.map +0 -1
- package/dist/commands/sync/SyncProgram.d.ts +0 -15
- package/dist/commands/sync/SyncProgram.d.ts.map +0 -1
- package/dist/commands/sync/index.d.ts +0 -3
- package/dist/commands/sync/index.d.ts.map +0 -1
- package/dist/commands/sync/when.d.ts +0 -21
- package/dist/commands/sync/when.d.ts.map +0 -1
- package/dist/index.d.ts +0 -4
- package/dist/index.d.ts.map +0 -1
- package/dist/index.esm.js +0 -8
- package/dist/index.esm.js.map +0 -7
- package/dist/index.js +0 -8
- package/dist/index.js.map +0 -7
- package/dist/utils/AsyncArray.d.ts +0 -21
- package/dist/utils/AsyncArray.d.ts.map +0 -1
- package/dist/utils/appendScript.d.ts +0 -7
- package/dist/utils/appendScript.d.ts.map +0 -1
- package/dist/utils/arrayToMap.d.ts +0 -3
- package/dist/utils/arrayToMap.d.ts.map +0 -1
- package/dist/utils/findParent.d.ts +0 -8
- package/dist/utils/findParent.d.ts.map +0 -1
- package/dist/utils/index.d.ts +0 -5
- package/dist/utils/index.d.ts.map +0 -1
- package/dist/utils/nodeCacheDir.d.ts +0 -2
- package/dist/utils/nodeCacheDir.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
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Plugin } from 'esbuild'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 处理 nodejs 原生模块
|
|
5
|
+
* @link https://github.com/evanw/esbuild/issues/1051#issuecomment-806325487
|
|
6
|
+
*/
|
|
7
|
+
export function nativeNodeModules(): Plugin {
|
|
8
|
+
return {
|
|
9
|
+
name: 'native-node-modules',
|
|
10
|
+
setup(build) {
|
|
11
|
+
// If a ".node" file is imported within a module in the "file" namespace, resolve
|
|
12
|
+
// it to an absolute path and put it into the "node-file" virtual namespace.
|
|
13
|
+
build.onResolve({ filter: /\.node$/, namespace: 'file' }, (args) => ({
|
|
14
|
+
path: require.resolve(args.path, { paths: [args.resolveDir] }),
|
|
15
|
+
namespace: 'node-file',
|
|
16
|
+
}))
|
|
17
|
+
|
|
18
|
+
// Files in the "node-file" virtual namespace call "require()" on the
|
|
19
|
+
// path from esbuild of the ".node" file in the output directory.
|
|
20
|
+
build.onLoad({ filter: /.*/, namespace: 'node-file' }, (args) => ({
|
|
21
|
+
contents: `
|
|
22
|
+
import path from ${JSON.stringify(args.path)}
|
|
23
|
+
try { module.exports = require(path) }
|
|
24
|
+
catch {}
|
|
25
|
+
`,
|
|
26
|
+
}))
|
|
27
|
+
|
|
28
|
+
// If a ".node" file is imported within a module in the "node-file" namespace, put
|
|
29
|
+
// it in the "file" namespace where esbuild's default loading behavior will handle
|
|
30
|
+
// it. It is already an absolute path since we resolved it to one above.
|
|
31
|
+
build.onResolve({ filter: /\.node$/, namespace: 'node-file' }, (args) => ({
|
|
32
|
+
path: args.path,
|
|
33
|
+
namespace: 'file',
|
|
34
|
+
}))
|
|
35
|
+
|
|
36
|
+
// Tell esbuild's default loading behavior to use the "file" loader for
|
|
37
|
+
// these ".node" files.
|
|
38
|
+
const opts = build.initialOptions
|
|
39
|
+
opts.loader = opts.loader || {}
|
|
40
|
+
opts.loader['.node'] = 'file'
|
|
41
|
+
},
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Plugin } from 'esbuild'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 排除和替换 node 内置模块
|
|
5
|
+
*/
|
|
6
|
+
export function nodeExternal(): Plugin {
|
|
7
|
+
return {
|
|
8
|
+
name: 'nodeExternals',
|
|
9
|
+
setup(build) {
|
|
10
|
+
build.onResolve({ filter: /(^node:)/ }, (args) => ({
|
|
11
|
+
path: args.path.slice(5),
|
|
12
|
+
external: true,
|
|
13
|
+
}))
|
|
14
|
+
},
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Plugin } from 'esbuild'
|
|
2
|
+
import { readFile } from 'fs-extra'
|
|
3
|
+
import * as path from 'path'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 通过 ?raw 将资源作为字符串打包进来
|
|
7
|
+
* @returns
|
|
8
|
+
*/
|
|
9
|
+
export function raw(): Plugin {
|
|
10
|
+
return {
|
|
11
|
+
name: 'raw',
|
|
12
|
+
setup(build) {
|
|
13
|
+
build.onResolve({ filter: /\?raw$/ }, (args) => {
|
|
14
|
+
return {
|
|
15
|
+
path: path.isAbsolute(args.path) ? args.path : path.join(args.resolveDir, args.path),
|
|
16
|
+
namespace: 'raw-loader',
|
|
17
|
+
}
|
|
18
|
+
})
|
|
19
|
+
build.onLoad({ filter: /\?raw$/, namespace: 'raw-loader' }, async (args) => {
|
|
20
|
+
return {
|
|
21
|
+
contents: await readFile(args.path.replace(/\?raw$/, '')),
|
|
22
|
+
loader: 'text',
|
|
23
|
+
}
|
|
24
|
+
})
|
|
25
|
+
},
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { build, Plugin } from 'esbuild'
|
|
2
|
+
import path from 'path'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 将指定的 import 重写为另一个
|
|
6
|
+
* @param entries
|
|
7
|
+
* @returns
|
|
8
|
+
*/
|
|
9
|
+
export function resolve(entries: [from: string, to: string][]): Plugin {
|
|
10
|
+
return {
|
|
11
|
+
name: 'resolve',
|
|
12
|
+
setup(build) {
|
|
13
|
+
build.onResolve({ filter: /.*/ }, async (args) => {
|
|
14
|
+
const findEntries = entries.find((item) => item[0] === args.path)
|
|
15
|
+
if (!findEntries) {
|
|
16
|
+
return
|
|
17
|
+
}
|
|
18
|
+
return await build.resolve(findEntries[1])
|
|
19
|
+
})
|
|
20
|
+
},
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Plugin } from 'esbuild'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 设置指定模块为没有副作用的包,由于 webpack/esbuild 的配置不兼容,所以先使用插件来完成这件事
|
|
5
|
+
* @param packages
|
|
6
|
+
* @returns
|
|
7
|
+
*/
|
|
8
|
+
export function sideEffects(packages: string[]): Plugin {
|
|
9
|
+
return {
|
|
10
|
+
name: 'sideEffects',
|
|
11
|
+
setup(build) {
|
|
12
|
+
build.onResolve({ filter: /.*/ }, async (args) => {
|
|
13
|
+
if (
|
|
14
|
+
args.pluginData || // Ignore this if we called ourselves
|
|
15
|
+
!packages.includes(args.path)
|
|
16
|
+
) {
|
|
17
|
+
return
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const { path, ...rest } = args
|
|
21
|
+
rest.pluginData = true // Avoid infinite recursion
|
|
22
|
+
const result = await build.resolve(path, rest)
|
|
23
|
+
|
|
24
|
+
result.sideEffects = false
|
|
25
|
+
return result
|
|
26
|
+
})
|
|
27
|
+
},
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Plugin } from 'esbuild'
|
|
2
|
+
import { readJson } from 'fs-extra'
|
|
3
|
+
import path from 'path'
|
|
4
|
+
|
|
5
|
+
function generateBanner(meta: object) {
|
|
6
|
+
return (
|
|
7
|
+
[
|
|
8
|
+
'// ==UserScript==',
|
|
9
|
+
...Object.entries(meta)
|
|
10
|
+
.map(([key, value]) => {
|
|
11
|
+
if (Array.isArray(value)) {
|
|
12
|
+
return value.map((item) => `// @${key} ${item}`)
|
|
13
|
+
}
|
|
14
|
+
return `// @${key} ${value}`
|
|
15
|
+
})
|
|
16
|
+
.flat(),
|
|
17
|
+
'// ==/UserScript==',
|
|
18
|
+
].join('\n') + '\n'
|
|
19
|
+
)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function userJS(): Plugin {
|
|
23
|
+
return {
|
|
24
|
+
name: 'userJS',
|
|
25
|
+
async setup(build) {
|
|
26
|
+
const json = (await readJson(path.resolve(build.initialOptions.absWorkingDir!, 'package.json'))) as {
|
|
27
|
+
userjs: object
|
|
28
|
+
}
|
|
29
|
+
if (!json.userjs) {
|
|
30
|
+
throw new Error('userjs is not supported')
|
|
31
|
+
}
|
|
32
|
+
if (!build.initialOptions.banner) {
|
|
33
|
+
build.initialOptions.banner = {}
|
|
34
|
+
}
|
|
35
|
+
build.initialOptions.banner!['js'] = generateBanner(json.userjs)
|
|
36
|
+
},
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -1,33 +1,35 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@liuli-util/cli-template",
|
|
3
|
-
"version": "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": "^
|
|
18
|
-
"enquirer": "^2.3.6",
|
|
19
|
-
"fs-extra": "^10.
|
|
20
|
-
},
|
|
21
|
-
"devDependencies": {
|
|
22
|
-
"@liuli-util/cli": "
|
|
23
|
-
"@types/fs-extra": "^9.0.13",
|
|
24
|
-
"@types/
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
"
|
|
32
|
-
|
|
33
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@liuli-util/cli-template",
|
|
3
|
+
"version": "0.2.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": "^9.4.0",
|
|
18
|
+
"enquirer": "^2.3.6",
|
|
19
|
+
"fs-extra": "^10.1.0"
|
|
20
|
+
},
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@liuli-util/cli": "workspace:^3.21.0",
|
|
23
|
+
"@types/fs-extra": "^9.0.13",
|
|
24
|
+
"@types/node": "^18.6.4",
|
|
25
|
+
"esno": "^0.16.3",
|
|
26
|
+
"rimraf": "^3.0.2",
|
|
27
|
+
"type-fest": "^2.18.0",
|
|
28
|
+
"typescript": "^4.7.4"
|
|
29
|
+
},
|
|
30
|
+
"exports": {
|
|
31
|
+
"import": "./dist/index.esm.js",
|
|
32
|
+
"require": "./dist/index.js",
|
|
33
|
+
"types": "./dist/index.d.ts"
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -1,19 +1,24 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@liuli-util/lib-template",
|
|
3
|
-
"private": true,
|
|
4
|
-
"version": "0.
|
|
5
|
-
"main": "dist/index.js",
|
|
6
|
-
"module": "dist/index.esm.js",
|
|
7
|
-
"types": "dist/index.d.ts",
|
|
8
|
-
"license": "MIT",
|
|
9
|
-
"scripts": {
|
|
10
|
-
"build": "liuli-cli build lib",
|
|
11
|
-
"dev": "liuli-cli build lib -w"
|
|
12
|
-
},
|
|
13
|
-
"devDependencies": {
|
|
14
|
-
"@liuli-util/cli": "
|
|
15
|
-
"rimraf": "^3.0.2",
|
|
16
|
-
"type-fest": "^2.
|
|
17
|
-
"typescript": "^4.
|
|
18
|
-
}
|
|
19
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@liuli-util/lib-template",
|
|
3
|
+
"private": true,
|
|
4
|
+
"version": "0.2.0",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.esm.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"scripts": {
|
|
10
|
+
"build": "liuli-cli build lib",
|
|
11
|
+
"dev": "liuli-cli build lib -w"
|
|
12
|
+
},
|
|
13
|
+
"devDependencies": {
|
|
14
|
+
"@liuli-util/cli": "workspace:^3.21.0",
|
|
15
|
+
"rimraf": "^3.0.2",
|
|
16
|
+
"type-fest": "^2.18.0",
|
|
17
|
+
"typescript": "^4.7.4"
|
|
18
|
+
},
|
|
19
|
+
"exports": {
|
|
20
|
+
"import": "./dist/index.esm.js",
|
|
21
|
+
"require": "./dist/index.js",
|
|
22
|
+
"types": "./dist/index.d.ts"
|
|
23
|
+
}
|
|
24
|
+
}
|
package/dist/PathUtil.d.ts
DELETED
package/dist/PathUtil.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PathUtil.d.ts","sourceRoot":"","sources":["../src/PathUtil.ts"],"names":[],"mappings":"AAEA,qBAAa,QAAQ;IACnB;;OAEG;IACH,MAAM,CAAC,QAAQ,CAAC,QAAQ,SAAgC;CACzD"}
|
package/dist/bin.d.ts
DELETED
package/dist/bin.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bin.d.ts","sourceRoot":"","sources":["../src/bin.ts"],"names":[],"mappings":""}
|