@highstate/cli 0.7.4 → 0.7.6
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/dist/main.js +47 -8
- package/package.json +4 -3
- package/src/commands/build.ts +41 -7
- package/src/shared/bin-transformer.ts +23 -0
- package/src/shared/index.ts +1 -0
package/dist/main.js
CHANGED
@@ -17,7 +17,7 @@ import { resolve as resolve$1 } from 'import-meta-resolve';
|
|
17
17
|
import { pipe, mapValues, mapKeys } from 'remeda';
|
18
18
|
import { build } from 'tsup';
|
19
19
|
|
20
|
-
var version = "0.7.
|
20
|
+
var version = "0.7.5";
|
21
21
|
|
22
22
|
const logger = pino(
|
23
23
|
{
|
@@ -1331,6 +1331,25 @@ class SourceHashCalculator {
|
|
1331
1331
|
}
|
1332
1332
|
}
|
1333
1333
|
|
1334
|
+
function createBinTransformerPlugin(sourceFilePaths) {
|
1335
|
+
const filter = new RegExp(`(${sourceFilePaths.join("|")})$`);
|
1336
|
+
logger.debug("created bin transformer plugin with filter: %s", filter);
|
1337
|
+
return {
|
1338
|
+
name: "bin-transformer",
|
1339
|
+
setup(build) {
|
1340
|
+
build.onLoad({ filter }, async (args) => {
|
1341
|
+
const content = await readFile(args.path, "utf-8");
|
1342
|
+
return {
|
1343
|
+
contents: `#!/usr/bin/env node
|
1344
|
+
|
1345
|
+
${content}`,
|
1346
|
+
loader: "ts"
|
1347
|
+
};
|
1348
|
+
});
|
1349
|
+
}
|
1350
|
+
};
|
1351
|
+
}
|
1352
|
+
|
1334
1353
|
class DesignerCommand extends Command {
|
1335
1354
|
static paths = [["designer"]];
|
1336
1355
|
static usage = Command.Usage({
|
@@ -1393,16 +1412,26 @@ class BuildCommand extends Command {
|
|
1393
1412
|
async execute() {
|
1394
1413
|
const packageJson = await readPackageJSON();
|
1395
1414
|
const exports = packageJson.exports;
|
1396
|
-
|
1397
|
-
|
1415
|
+
let bin = packageJson.bin;
|
1416
|
+
if (!packageJson.name) {
|
1417
|
+
throw new Error("package.json must have a name field");
|
1418
|
+
}
|
1419
|
+
if (!exports && !bin) {
|
1420
|
+
logger.warn("no exports or bin found in package.json");
|
1398
1421
|
return;
|
1399
1422
|
}
|
1400
|
-
if (typeof exports !== "object" || Array.isArray(exports)) {
|
1423
|
+
if (exports !== void 0 && (typeof exports !== "object" || Array.isArray(exports))) {
|
1401
1424
|
throw new Error("Exports field in package.json must be an object");
|
1402
1425
|
}
|
1426
|
+
if (bin !== void 0 && typeof bin !== "object") {
|
1427
|
+
bin = { [packageJson.name]: bin };
|
1428
|
+
}
|
1403
1429
|
const entry = pipe(
|
1404
|
-
|
1405
|
-
|
1430
|
+
{
|
1431
|
+
...mapValues(exports ?? {}, (value) => ({ value, isBin: false })),
|
1432
|
+
...mapValues(bin ?? {}, (value) => ({ value, isBin: true }))
|
1433
|
+
},
|
1434
|
+
mapValues(({ value, isBin }, key) => {
|
1406
1435
|
let distPath;
|
1407
1436
|
if (typeof value === "string") {
|
1408
1437
|
distPath = value;
|
@@ -1431,11 +1460,20 @@ class BuildCommand extends Command {
|
|
1431
1460
|
return {
|
1432
1461
|
entryPoint: `./src/${targetName}.ts`,
|
1433
1462
|
targetName,
|
1434
|
-
distPath
|
1463
|
+
distPath,
|
1464
|
+
isBin
|
1435
1465
|
};
|
1436
1466
|
}),
|
1437
1467
|
mapKeys((_, value) => value.targetName)
|
1438
1468
|
);
|
1469
|
+
const esbuildPlugins = [];
|
1470
|
+
const binSourceFilePaths = Object.values(entry).filter((value) => value.isBin).map((value) => value.entryPoint.slice(2));
|
1471
|
+
if (this.library) {
|
1472
|
+
esbuildPlugins.push(schemaTransformerPlugin);
|
1473
|
+
}
|
1474
|
+
if (binSourceFilePaths.length > 0) {
|
1475
|
+
esbuildPlugins.push(createBinTransformerPlugin(binSourceFilePaths));
|
1476
|
+
}
|
1439
1477
|
await build({
|
1440
1478
|
entry: mapValues(entry, (value) => value.entryPoint),
|
1441
1479
|
outDir: "dist",
|
@@ -1445,7 +1483,8 @@ class BuildCommand extends Command {
|
|
1445
1483
|
format: "esm",
|
1446
1484
|
target: "esnext",
|
1447
1485
|
external: ["@pulumi/pulumi"],
|
1448
|
-
esbuildPlugins
|
1486
|
+
esbuildPlugins,
|
1487
|
+
silent: ["warn", "error", "fatal"].includes(logger.level)
|
1449
1488
|
});
|
1450
1489
|
const packageJsonPath = await resolvePackageJSON();
|
1451
1490
|
const upToDatePackageJson = await readPackageJSON();
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@highstate/cli",
|
3
|
-
"version": "0.7.
|
3
|
+
"version": "0.7.6",
|
4
4
|
"description": "The CLI for the Highstate project.",
|
5
5
|
"type": "module",
|
6
6
|
"files": [
|
@@ -18,7 +18,7 @@
|
|
18
18
|
"build": "pkgroll --clean --tsconfig=tsconfig.build.json"
|
19
19
|
},
|
20
20
|
"dependencies": {
|
21
|
-
"@highstate/backend": "^0.7.
|
21
|
+
"@highstate/backend": "^0.7.6",
|
22
22
|
"clipanion": "^4.0.0-rc.4",
|
23
23
|
"consola": "^3.4.0",
|
24
24
|
"crypto-hash": "^3.1.0",
|
@@ -33,7 +33,8 @@
|
|
33
33
|
"tsup": "^8.4.0"
|
34
34
|
},
|
35
35
|
"devDependencies": {
|
36
|
+
"highstate-cli-bootstrap": "npm:@highstate/cli@0.7.4",
|
36
37
|
"pkgroll": "^2.5.1"
|
37
38
|
},
|
38
|
-
"gitHead": "
|
39
|
+
"gitHead": "5acce7f9d8a57bdd1220e381d5b76d7b484b98c2"
|
39
40
|
}
|
package/src/commands/build.ts
CHANGED
@@ -1,8 +1,14 @@
|
|
1
|
+
import type { Plugin } from "esbuild"
|
1
2
|
import { Command, Option } from "clipanion"
|
2
3
|
import { readPackageJSON, resolvePackageJSON } from "pkg-types"
|
3
4
|
import { mapKeys, mapValues, pipe } from "remeda"
|
4
5
|
import { build } from "tsup"
|
5
|
-
import {
|
6
|
+
import {
|
7
|
+
createBinTransformerPlugin,
|
8
|
+
logger,
|
9
|
+
schemaTransformerPlugin,
|
10
|
+
SourceHashCalculator,
|
11
|
+
} from "../shared"
|
6
12
|
|
7
13
|
export class BuildCommand extends Command {
|
8
14
|
static paths = [["build"]]
|
@@ -18,19 +24,31 @@ export class BuildCommand extends Command {
|
|
18
24
|
async execute(): Promise<void> {
|
19
25
|
const packageJson = await readPackageJSON()
|
20
26
|
const exports = packageJson.exports
|
27
|
+
let bin = packageJson.bin
|
21
28
|
|
22
|
-
if (!
|
23
|
-
|
29
|
+
if (!packageJson.name) {
|
30
|
+
throw new Error("package.json must have a name field")
|
31
|
+
}
|
32
|
+
|
33
|
+
if (!exports && !bin) {
|
34
|
+
logger.warn("no exports or bin found in package.json")
|
24
35
|
return
|
25
36
|
}
|
26
37
|
|
27
|
-
if (typeof exports !== "object" || Array.isArray(exports)) {
|
38
|
+
if (exports !== undefined && (typeof exports !== "object" || Array.isArray(exports))) {
|
28
39
|
throw new Error("Exports field in package.json must be an object")
|
29
40
|
}
|
30
41
|
|
42
|
+
if (bin !== undefined && typeof bin !== "object") {
|
43
|
+
bin = { [packageJson.name]: bin }
|
44
|
+
}
|
45
|
+
|
31
46
|
const entry = pipe(
|
32
|
-
|
33
|
-
|
47
|
+
{
|
48
|
+
...mapValues(exports ?? {}, value => ({ value, isBin: false })),
|
49
|
+
...mapValues(bin ?? {}, value => ({ value, isBin: true })),
|
50
|
+
},
|
51
|
+
mapValues(({ value, isBin }, key) => {
|
34
52
|
let distPath
|
35
53
|
|
36
54
|
if (typeof value === "string") {
|
@@ -67,11 +85,26 @@ export class BuildCommand extends Command {
|
|
67
85
|
entryPoint: `./src/${targetName}.ts`,
|
68
86
|
targetName,
|
69
87
|
distPath,
|
88
|
+
isBin,
|
70
89
|
}
|
71
90
|
}),
|
72
91
|
mapKeys((_, value) => value.targetName),
|
73
92
|
)
|
74
93
|
|
94
|
+
const esbuildPlugins: Plugin[] = []
|
95
|
+
|
96
|
+
const binSourceFilePaths = Object.values(entry)
|
97
|
+
.filter(value => value.isBin)
|
98
|
+
.map(value => value.entryPoint.slice(2)) // remove "./"
|
99
|
+
|
100
|
+
if (this.library) {
|
101
|
+
esbuildPlugins.push(schemaTransformerPlugin)
|
102
|
+
}
|
103
|
+
|
104
|
+
if (binSourceFilePaths.length > 0) {
|
105
|
+
esbuildPlugins.push(createBinTransformerPlugin(binSourceFilePaths))
|
106
|
+
}
|
107
|
+
|
75
108
|
await build({
|
76
109
|
entry: mapValues(entry, value => value.entryPoint),
|
77
110
|
outDir: "dist",
|
@@ -81,7 +114,8 @@ export class BuildCommand extends Command {
|
|
81
114
|
format: "esm",
|
82
115
|
target: "esnext",
|
83
116
|
external: ["@pulumi/pulumi"],
|
84
|
-
esbuildPlugins
|
117
|
+
esbuildPlugins,
|
118
|
+
silent: ["warn", "error", "fatal"].includes(logger.level),
|
85
119
|
})
|
86
120
|
|
87
121
|
const packageJsonPath = await resolvePackageJSON()
|
@@ -0,0 +1,23 @@
|
|
1
|
+
import type { Plugin } from "esbuild"
|
2
|
+
import { readFile } from "node:fs/promises"
|
3
|
+
import { logger } from "./logger"
|
4
|
+
|
5
|
+
export function createBinTransformerPlugin(sourceFilePaths: string[]): Plugin {
|
6
|
+
const filter = new RegExp(`(${sourceFilePaths.join("|")})$`)
|
7
|
+
|
8
|
+
logger.debug("created bin transformer plugin with filter: %s", filter)
|
9
|
+
|
10
|
+
return {
|
11
|
+
name: "bin-transformer",
|
12
|
+
setup(build) {
|
13
|
+
build.onLoad({ filter }, async args => {
|
14
|
+
const content = await readFile(args.path, "utf-8")
|
15
|
+
|
16
|
+
return {
|
17
|
+
contents: `#!/usr/bin/env node\n\n${content}`,
|
18
|
+
loader: "ts",
|
19
|
+
}
|
20
|
+
})
|
21
|
+
},
|
22
|
+
}
|
23
|
+
}
|
package/src/shared/index.ts
CHANGED