@dbx-tools/projen 0.6.61 → 0.6.63
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/package.json +4 -4
- package/src/codegen.ts +1 -1
- package/src/dbx-tools-config.ts +2 -1
- package/src/openapi.ts +2 -2
- package/src/packages.ts +1 -1
- package/src/project-predicate.ts +4 -4
- package/src/project.ts +30 -20
- package/src/publish.ts +1 -1
- package/src/tags.ts +2 -2
- package/tasks/barrels.ts +2 -2
- package/tasks/bump.ts +8 -6
- package/tasks/clean.ts +1 -1
- package/tasks/openapi.ts +1 -1
- package/tasks/projenrc.ts +1 -1
- package/tasks/publish.ts +77 -6
- package/tasks/sync.ts +1 -1
package/package.json
CHANGED
|
@@ -26,9 +26,9 @@
|
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@clack/prompts": "^1.7.0",
|
|
29
|
-
"@dbx-tools/core": "0.6.
|
|
30
|
-
"@dbx-tools/path": "0.6.
|
|
31
|
-
"@dbx-tools/shared-core": "0.6.
|
|
29
|
+
"@dbx-tools/core": "0.6.63",
|
|
30
|
+
"@dbx-tools/path": "0.6.63",
|
|
31
|
+
"@dbx-tools/shared-core": "0.6.63",
|
|
32
32
|
"commander": "^15.0.0",
|
|
33
33
|
"concurrently": "^10.0.3",
|
|
34
34
|
"constructs": "^10.6.0",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
},
|
|
48
48
|
"main": "index.ts",
|
|
49
49
|
"license": "Apache-2.0",
|
|
50
|
-
"version": "0.6.
|
|
50
|
+
"version": "0.6.63",
|
|
51
51
|
"types": "index.ts",
|
|
52
52
|
"type": "module",
|
|
53
53
|
"exports": {
|
package/src/codegen.ts
CHANGED
|
@@ -46,10 +46,10 @@
|
|
|
46
46
|
import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
47
47
|
import { createRequire } from "node:module";
|
|
48
48
|
import { basename, dirname, join, resolve } from "node:path";
|
|
49
|
+
import { log, object } from "@dbx-tools/shared-core";
|
|
49
50
|
import type * as ts from "typescript";
|
|
50
51
|
import { lazyRequire } from "./_lazy-require.ts";
|
|
51
52
|
import { header, isReadonly, makeReadonly, makeWritable } from "./generated.ts";
|
|
52
|
-
import { log, object } from "@dbx-tools/shared-core";
|
|
53
53
|
import { readPackageManifest, repoRoot, recordedPackages } from "./packages.ts";
|
|
54
54
|
|
|
55
55
|
const logger = log.logger("projen:codegen");
|
package/src/dbx-tools-config.ts
CHANGED
|
@@ -31,11 +31,12 @@ function readDBXToolsConfig(pkg: javascript.NodePackage): Record<string, unknown
|
|
|
31
31
|
|
|
32
32
|
function loadConfig(dbxToolsConfig: DBXToolsConfig, pkg: javascript.NodePackage) {
|
|
33
33
|
const { tags, ...config } = readDBXToolsConfig(pkg);
|
|
34
|
-
if (Array.isArray(tags))
|
|
34
|
+
if (Array.isArray(tags)) {
|
|
35
35
|
object
|
|
36
36
|
.sequence(tags)
|
|
37
37
|
.filter((v: unknown) => typeof v === "string")
|
|
38
38
|
.forEach((v: string) => dbxToolsConfig.tags.push(v));
|
|
39
|
+
}
|
|
39
40
|
Object.entries(config).forEach(([key, value]) => {
|
|
40
41
|
dbxToolsConfig[key] = value;
|
|
41
42
|
});
|
package/src/openapi.ts
CHANGED
|
@@ -23,11 +23,11 @@
|
|
|
23
23
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
24
24
|
import { createRequire } from "node:module";
|
|
25
25
|
import { join } from "node:path";
|
|
26
|
-
import type * as ts from "typescript";
|
|
27
26
|
import { find } from "@dbx-tools/path";
|
|
27
|
+
import { log } from "@dbx-tools/shared-core";
|
|
28
|
+
import type * as ts from "typescript";
|
|
28
29
|
import { lazyRequire } from "./_lazy-require.ts";
|
|
29
30
|
import { makeReadonly, makeWritable, stampGenerated } from "./generated.ts";
|
|
30
|
-
import { log } from "@dbx-tools/shared-core";
|
|
31
31
|
import {
|
|
32
32
|
type RecordedPackage,
|
|
33
33
|
isModuleFile,
|
package/src/packages.ts
CHANGED
|
@@ -26,8 +26,8 @@
|
|
|
26
26
|
import { existsSync, readFileSync } from "node:fs";
|
|
27
27
|
import { extname, relative, resolve, sep } from "node:path";
|
|
28
28
|
import { project as coreProject } from "@dbx-tools/core";
|
|
29
|
-
import { json, object, string } from "@dbx-tools/shared-core";
|
|
30
29
|
import { find } from "@dbx-tools/path";
|
|
30
|
+
import { json, object, string } from "@dbx-tools/shared-core";
|
|
31
31
|
import { parse } from "yaml";
|
|
32
32
|
|
|
33
33
|
/**
|
package/src/project-predicate.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { relative } from "node:path";
|
|
2
|
+
import { match, PathMatchInput, PathMatchPredicate } from "@dbx-tools/path";
|
|
1
3
|
import {
|
|
2
4
|
object,
|
|
3
5
|
predicate,
|
|
@@ -7,11 +9,9 @@ import {
|
|
|
7
9
|
} from "@dbx-tools/shared-core";
|
|
8
10
|
import { IConstruct } from "constructs";
|
|
9
11
|
import { Project } from "projen";
|
|
10
|
-
import { DBXToolsProject, DBXToolsNodeProject, DBXToolsTypeScriptProject } from "./project.ts";
|
|
11
|
-
import { toPosix } from "./packages.ts";
|
|
12
|
-
import { relative } from "node:path";
|
|
13
|
-
import { match, PathMatchInput, PathMatchPredicate } from "@dbx-tools/path";
|
|
14
12
|
import { project } from "..";
|
|
13
|
+
import { toPosix } from "./packages.ts";
|
|
14
|
+
import { DBXToolsProject, DBXToolsNodeProject, DBXToolsTypeScriptProject } from "./project.ts";
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* Guard: the construct is a projen {@link Project} - the base every builder here
|
package/src/project.ts
CHANGED
|
@@ -6,22 +6,16 @@
|
|
|
6
6
|
* {@link DBXToolsNodeProject} (monorepo root) and {@link DBXToolsTypeScriptProject}
|
|
7
7
|
* (a package, or a standalone compiling root) both implement {@link DBXToolsProject}.
|
|
8
8
|
*/
|
|
9
|
-
import { object, string, type OneOrMany } from "@dbx-tools/shared-core";
|
|
10
|
-
import { ignore, match, PathMatchInput } from "@dbx-tools/path";
|
|
11
|
-
import { project as coreProject } from "@dbx-tools/core";
|
|
12
9
|
import { existsSync, readdirSync } from "node:fs";
|
|
13
10
|
import { dirname, join, relative, resolve } from "node:path";
|
|
11
|
+
import { project as coreProject } from "@dbx-tools/core";
|
|
12
|
+
import { ignore, match, PathMatchInput } from "@dbx-tools/path";
|
|
13
|
+
import { object, string, type OneOrMany } from "@dbx-tools/shared-core";
|
|
14
|
+
import { IConstruct } from "constructs";
|
|
14
15
|
import { Component, IgnoreFile, Project, type TaskOptions, javascript, typescript } from "projen";
|
|
15
16
|
import { ReleaseTrigger } from "projen/lib/release";
|
|
17
|
+
import { mixin, projectPredicate } from "..";
|
|
16
18
|
import { generateBarrels } from "./barrels.ts";
|
|
17
|
-
import { codegenModulePaths, generateCodegen } from "./codegen.ts";
|
|
18
|
-
import { DBXToolsConfig, type DBXToolsConfigOptions } from "./dbx-tools-config.ts";
|
|
19
|
-
import { resolvePkgRoot } from "./engine-root.ts";
|
|
20
|
-
import { PnpmWorkspaceState, type DBXToolsPNPMWorkspaceOptions } from "./pnpm-workspace.ts";
|
|
21
|
-
import { applyCompiledPublish } from "./publish.ts";
|
|
22
|
-
import { DBXToolsRelease, type StandaloneRelease } from "./release.ts";
|
|
23
|
-
import { AGNOSTIC_COMPILER_OPTIONS, PACKAGE_TAG_MIXINS, type PackageTag } from "./tags.ts";
|
|
24
|
-
import { DBXToolsRootTsconfig } from "./tsconfig.ts";
|
|
25
19
|
import {
|
|
26
20
|
BUN_APP_OVERRIDES,
|
|
27
21
|
BunBuildFile,
|
|
@@ -29,7 +23,9 @@ import {
|
|
|
29
23
|
BunfigFile,
|
|
30
24
|
RootBunfigFile,
|
|
31
25
|
} from "./bun-app.ts";
|
|
32
|
-
import {
|
|
26
|
+
import { codegenModulePaths, generateCodegen } from "./codegen.ts";
|
|
27
|
+
import { DBXToolsConfig, type DBXToolsConfigOptions } from "./dbx-tools-config.ts";
|
|
28
|
+
import { resolvePkgRoot } from "./engine-root.ts";
|
|
33
29
|
import {
|
|
34
30
|
DEFAULT_PACKAGE_ROOTS,
|
|
35
31
|
type DiscoveredPackage,
|
|
@@ -39,8 +35,12 @@ import {
|
|
|
39
35
|
scanPackages,
|
|
40
36
|
toPosix,
|
|
41
37
|
} from "./packages.ts";
|
|
42
|
-
import {
|
|
43
|
-
import {
|
|
38
|
+
import { PnpmWorkspaceState, type DBXToolsPNPMWorkspaceOptions } from "./pnpm-workspace.ts";
|
|
39
|
+
import { applyCompiledPublish } from "./publish.ts";
|
|
40
|
+
import { DBXToolsRelease, type StandaloneRelease } from "./release.ts";
|
|
41
|
+
import { AGNOSTIC_COMPILER_OPTIONS, PACKAGE_TAG_MIXINS, type PackageTag } from "./tags.ts";
|
|
42
|
+
import { DBXToolsRootTsconfig } from "./tsconfig.ts";
|
|
43
|
+
import { DBXToolsVsCode } from "./vscode.ts";
|
|
44
44
|
|
|
45
45
|
/**
|
|
46
46
|
* The dbx-tools project surface, backed by projen's Node toolchain. A single
|
|
@@ -953,14 +953,20 @@ function initProject(
|
|
|
953
953
|
// each file to its own package tsconfig (so type-aware rules work tree-wide), and
|
|
954
954
|
// `import/no-extraneous-dependencies` still checks each file against its nearest
|
|
955
955
|
// package.json. Formatting defers to the root Prettier to avoid rule/formatter
|
|
956
|
-
// conflicts (e.g. quote style).
|
|
957
|
-
//
|
|
956
|
+
// conflicts (e.g. quote style). The normal task is check-only so CI never
|
|
957
|
+
// repairs the worktree it is meant to validate; `eslint:fix` is the explicit
|
|
958
|
+
// local mutation path.
|
|
958
959
|
const eslint = new javascript.Eslint(project, {
|
|
959
|
-
dirs: [...roots],
|
|
960
|
+
dirs: [...roots, "projen"],
|
|
960
961
|
fileExtensions: [".ts", ".tsx"],
|
|
961
962
|
projectService: true,
|
|
962
963
|
prettier: Boolean(project.prettier),
|
|
963
964
|
tsconfigPath: "./tsconfig.json",
|
|
965
|
+
commandOptions: { fix: false },
|
|
966
|
+
});
|
|
967
|
+
project.addTask("eslint:fix", {
|
|
968
|
+
description: "Fix ESLint issues across the codebase",
|
|
969
|
+
exec: "bun run eslint -- --fix",
|
|
964
970
|
});
|
|
965
971
|
// Generated read-only outputs (barrels, openapi clients, app scripts, codegen).
|
|
966
972
|
// ESLint --fix cannot rewrite them; they are stamped by the barrel generator /
|
|
@@ -969,6 +975,7 @@ function initProject(
|
|
|
969
975
|
eslint.addIgnorePattern(`${root}/openapi/**`);
|
|
970
976
|
eslint.addIgnorePattern(`${root}/**/index.ts`);
|
|
971
977
|
}
|
|
978
|
+
eslint.addIgnorePattern("projen/index.ts");
|
|
972
979
|
// The generated bun app scripts + unmanaged overrides live at the package root,
|
|
973
980
|
// outside any `src/**` tsconfig include, so the type-aware parser cannot resolve
|
|
974
981
|
// them to a project. ESLint still cannot parse them.
|
|
@@ -1242,21 +1249,24 @@ export function applyToProjects<P extends Project>(
|
|
|
1242
1249
|
let pred = projectPredicate.isProject();
|
|
1243
1250
|
if (!options?.includeNonDBXToolsProjects) pred = pred.and(projectPredicate.isDBXToolsProject());
|
|
1244
1251
|
if (!options?.includeRoots) pred = pred.and((p) => p.parent != null);
|
|
1245
|
-
if (options?.identifierPackageName)
|
|
1252
|
+
if (options?.identifierPackageName) {
|
|
1246
1253
|
pred = pred.and(
|
|
1247
1254
|
projectPredicate.hasIdentifierPackageName(
|
|
1248
1255
|
...object.toOneOrMany(options.identifierPackageName),
|
|
1249
1256
|
),
|
|
1250
1257
|
);
|
|
1258
|
+
}
|
|
1251
1259
|
if (options?.name) pred = pred.and(projectPredicate.hasName(...object.toOneOrMany(options.name)));
|
|
1252
|
-
if (options?.identifierScope)
|
|
1260
|
+
if (options?.identifierScope) {
|
|
1253
1261
|
pred = pred.and(
|
|
1254
1262
|
projectPredicate.hasIdentifierScope(...object.toOneOrMany(options.identifierScope)),
|
|
1255
1263
|
);
|
|
1256
|
-
|
|
1264
|
+
}
|
|
1265
|
+
if (options?.identifierName) {
|
|
1257
1266
|
pred = pred.and(
|
|
1258
1267
|
projectPredicate.hasIdentifierName(...object.toOneOrMany(options.identifierName)),
|
|
1259
1268
|
);
|
|
1269
|
+
}
|
|
1260
1270
|
if (options?.tags) pred = pred.and(projectPredicate.hasTag(...object.toOneOrMany(options.tags)));
|
|
1261
1271
|
if (options?.path) pred = pred.and(projectPredicate.hasPath(...object.toOneOrMany(options.path)));
|
|
1262
1272
|
const projectMixin = mixin.create(pred, (p) => {
|
package/src/publish.ts
CHANGED
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
*/
|
|
30
30
|
import type { javascript } from "projen";
|
|
31
31
|
import { typescript } from "projen";
|
|
32
|
-
import { addPackageFiles, applyCompilerOptions, applyIncludes } from "./project.ts";
|
|
33
32
|
import { isDBXToolsProject } from "./project-predicate.ts";
|
|
33
|
+
import { addPackageFiles, applyCompilerOptions, applyIncludes } from "./project.ts";
|
|
34
34
|
|
|
35
35
|
/** Directory `tsc` emits into, and the root of every published entry point. */
|
|
36
36
|
export const COMPILED_DIR = "lib";
|
package/src/tags.ts
CHANGED
|
@@ -17,6 +17,7 @@ import type { IMixin as ConstructsMixin } from "constructs";
|
|
|
17
17
|
import { javascript } from "projen";
|
|
18
18
|
import { BunBuildFile, BunDevServerFile, BunfigFile } from "./bun-app.ts";
|
|
19
19
|
import { create } from "./mixin.ts";
|
|
20
|
+
import * as projectPredicate from "./project-predicate.ts";
|
|
20
21
|
import {
|
|
21
22
|
addPackageFiles,
|
|
22
23
|
applyCompilerOptions,
|
|
@@ -25,7 +26,6 @@ import {
|
|
|
25
26
|
applyTasks,
|
|
26
27
|
srcModuleExports,
|
|
27
28
|
} from "./project.ts";
|
|
28
|
-
import * as projectPredicate from "./project-predicate.ts";
|
|
29
29
|
|
|
30
30
|
/** Node compiler options: ES2022 lib + node types, deliberately no DOM. */
|
|
31
31
|
const NODE_COMPILER_OPTIONS: javascript.TypeScriptCompilerOptions = {
|
|
@@ -137,7 +137,7 @@ export const PACKAGE_TAG_MIXINS = {
|
|
|
137
137
|
// register and no launcher shim to generate. In a WORKSPACE checkout the
|
|
138
138
|
// manifest still points at the `.ts` entry, which Node type-strips on its own
|
|
139
139
|
// because the package is not under `node_modules`.
|
|
140
|
-
p.addDeps("commander@catalog:"
|
|
140
|
+
p.addDeps("commander@catalog:");
|
|
141
141
|
p.addDevDeps("@types/node@catalog:");
|
|
142
142
|
// A CLI compiles code OUTSIDE `src/` - its root `index.ts` barrel and the
|
|
143
143
|
// `bin/` entries - which the src-only tag default doesn't reach.
|
package/tasks/barrels.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env -S bun
|
|
2
2
|
import { sep } from "node:path";
|
|
3
|
-
import { generateBarrels } from "../src/barrels.ts";
|
|
4
3
|
import { log, string } from "@dbx-tools/shared-core";
|
|
5
|
-
import {
|
|
4
|
+
import { generateBarrels } from "../src/barrels.ts";
|
|
6
5
|
import { recordedPackages } from "../src/packages.ts";
|
|
6
|
+
import { watchLoop, watchRoots } from "../src/watch.ts";
|
|
7
7
|
|
|
8
8
|
const logger = log.logger("projen:barrels");
|
|
9
9
|
|
package/tasks/bump.ts
CHANGED
|
@@ -39,12 +39,12 @@
|
|
|
39
39
|
* - `false`: never publish locally.
|
|
40
40
|
* - a URL: always publish to that registry.
|
|
41
41
|
*/
|
|
42
|
-
import { exec, project } from "@dbx-tools/core";
|
|
43
|
-
import { log, net } from "@dbx-tools/shared-core";
|
|
44
|
-
import { Command, Option } from "commander";
|
|
45
42
|
import { chmodSync, existsSync, readFileSync, statSync, writeFileSync } from "node:fs";
|
|
46
43
|
import { resolve } from "node:path";
|
|
47
44
|
import { fileURLToPath } from "node:url";
|
|
45
|
+
import { exec, project } from "@dbx-tools/core";
|
|
46
|
+
import { log, net } from "@dbx-tools/shared-core";
|
|
47
|
+
import { Command, Option } from "commander";
|
|
48
48
|
|
|
49
49
|
const logger = log.logger("projen:bump");
|
|
50
50
|
const LEVELS = ["patch", "minor", "major"] as const;
|
|
@@ -294,9 +294,11 @@ program
|
|
|
294
294
|
// keep `0.0.0` on disk, projen-owned, so it unlocks each briefly), then
|
|
295
295
|
// `bun publish`es each non-private one - and bun natively strips the
|
|
296
296
|
// `workspace:`/`catalog:` protocols in the packed tarball, resolving each
|
|
297
|
-
// to the version just set.
|
|
298
|
-
//
|
|
299
|
-
//
|
|
297
|
+
// to the version just set. `publish.ts` restores every manifest it touched
|
|
298
|
+
// at exit, so this leaves the worktree matching the release commit that was
|
|
299
|
+
// just pushed - the release version lives in the git tag, not on disk.
|
|
300
|
+
// Provenance is off for a local registry (no OIDC), so
|
|
301
|
+
// `NPM_CONFIG_PROVENANCE` is unset.
|
|
300
302
|
// `publish.ts` is this task's SIBLING in the engine's `tasks/` dir; resolve
|
|
301
303
|
// it off `import.meta.url` (works whether the engine is source-linked in-repo
|
|
302
304
|
// or installed under node_modules) rather than a repo-relative `tasks/...`
|
package/tasks/clean.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env -S bun
|
|
2
2
|
import { relative } from "node:path";
|
|
3
|
-
import { listGeneratedFiles, listNodeModulesDirs, removePaths } from "../src/clean.ts";
|
|
4
3
|
import { log, string } from "@dbx-tools/shared-core";
|
|
4
|
+
import { listGeneratedFiles, listNodeModulesDirs, removePaths } from "../src/clean.ts";
|
|
5
5
|
import { repoRoot, toPosix } from "../src/packages.ts";
|
|
6
6
|
|
|
7
7
|
const logger = log.logger("projen:clean");
|
package/tasks/openapi.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env -S bun
|
|
2
|
-
import { generateBarrels } from "../src/barrels.ts";
|
|
3
2
|
import { log, string } from "@dbx-tools/shared-core";
|
|
3
|
+
import { generateBarrels } from "../src/barrels.ts";
|
|
4
4
|
import { generateOpenapi, isTsoaController } from "../src/openapi.ts";
|
|
5
5
|
import { runSynth } from "../src/scaffold.ts";
|
|
6
6
|
import { watchLoop, watchRoots } from "../src/watch.ts";
|
package/tasks/projenrc.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env -S bun
|
|
2
2
|
import { resolve } from "node:path";
|
|
3
3
|
import { log } from "@dbx-tools/shared-core";
|
|
4
|
+
import { repoRoot, syncResynthPaths } from "../src/packages.ts";
|
|
4
5
|
import { runSynth } from "../src/scaffold.ts";
|
|
5
6
|
import { watchLoop } from "../src/watch.ts";
|
|
6
|
-
import { repoRoot, syncResynthPaths } from "../src/packages.ts";
|
|
7
7
|
|
|
8
8
|
const logger = log.logger("projen:projenrc");
|
|
9
9
|
|
package/tasks/publish.ts
CHANGED
|
@@ -37,9 +37,15 @@
|
|
|
37
37
|
* repo-relative) skips a member that releases on its OWN tag namespace (e.g.
|
|
38
38
|
* `projen`, published by `projen-release`, not the main `release`).
|
|
39
39
|
*
|
|
40
|
+
* `--no-restore` keeps the edits on disk instead of undoing them at exit. Only
|
|
41
|
+
* needed when a LATER process must still see them - `--stamp-only` implies it,
|
|
42
|
+
* since its whole job is to stamp the workspace for a `bun publish` that runs
|
|
43
|
+
* afterwards from another directory.
|
|
44
|
+
*
|
|
40
45
|
* The disk manifests normally carry `version: 0.0.0` (projen owns them, read-only);
|
|
41
|
-
* this unlocks each only long enough to set the version + publish
|
|
42
|
-
*
|
|
46
|
+
* this unlocks each only long enough to set the version + publish, then RESTORES
|
|
47
|
+
* every one it touched byte-for-byte (and re-locks the mode) on the way out - see
|
|
48
|
+
* {@link restoreManifests}. The release version lives in the git tag, not on disk.
|
|
43
49
|
*/
|
|
44
50
|
import { chmodSync, existsSync, readFileSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
45
51
|
import { dirname, join, resolve } from "node:path";
|
|
@@ -49,6 +55,29 @@ import { parse } from "yaml";
|
|
|
49
55
|
|
|
50
56
|
const logger = log.logger("dbx-tools:publish");
|
|
51
57
|
|
|
58
|
+
/** A manifest's on-disk bytes + mode, captured before this task edits it. */
|
|
59
|
+
interface ManifestBackup {
|
|
60
|
+
readonly content: string;
|
|
61
|
+
readonly mode: number;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Original state of every manifest this task has unlocked, keyed by path.
|
|
66
|
+
*
|
|
67
|
+
* Publishing has to mutate manifests projen owns (the version stamp, so a
|
|
68
|
+
* `workspace:*` sibling resolves to the release version, and the `publishConfig`
|
|
69
|
+
* entry-point substitution bun won't do itself). Those edits are only ever meant
|
|
70
|
+
* to reach the packed TARBALL, so every one is undone by {@link restoreManifests}
|
|
71
|
+
* before the process ends.
|
|
72
|
+
*
|
|
73
|
+
* Leaving them on disk is what used to strand a local `bun run bump` with ~34
|
|
74
|
+
* modified `package.json` files - version stamps and `lib/` entry points - after
|
|
75
|
+
* the release commit was already made, so the tree diverged from the commit that
|
|
76
|
+
* was just pushed and every subsequent `git status` needed a manual revert. CI
|
|
77
|
+
* never noticed because a fresh checkout is discarded.
|
|
78
|
+
*/
|
|
79
|
+
const manifestBackups = new Map<string, ManifestBackup>();
|
|
80
|
+
|
|
52
81
|
/**
|
|
53
82
|
* Workspace member dirs (absolute), read from the root `pnpm-workspace.yaml` - the
|
|
54
83
|
* file the engine keeps for the Databricks Apps pnpm deploy, which also lists every
|
|
@@ -74,9 +103,43 @@ function run(cwd: string, command: string, args: string[], path: string): void {
|
|
|
74
103
|
});
|
|
75
104
|
}
|
|
76
105
|
|
|
77
|
-
/**
|
|
106
|
+
/**
|
|
107
|
+
* Make a projen-readonly manifest writable so `bun pm pkg set` / `bun publish` can
|
|
108
|
+
* edit it, recording its original bytes + mode for {@link restoreManifests} the
|
|
109
|
+
* first time it is seen. Idempotent, so a manifest unlocked twice (version stamp,
|
|
110
|
+
* then `publishConfig`) keeps its PRE-EDIT backup rather than overwriting it with
|
|
111
|
+
* the already-stamped content.
|
|
112
|
+
*/
|
|
78
113
|
function unlockManifest(pkgPath: string): void {
|
|
79
|
-
|
|
114
|
+
const mode = statSync(pkgPath).mode;
|
|
115
|
+
if (!manifestBackups.has(pkgPath)) {
|
|
116
|
+
manifestBackups.set(pkgPath, { content: readFileSync(pkgPath, "utf8"), mode });
|
|
117
|
+
}
|
|
118
|
+
chmodSync(pkgPath, mode | 0o200);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Put every manifest this task edited back exactly as it was found, mode included.
|
|
123
|
+
*
|
|
124
|
+
* Runs from an `exit` handler so a clean finish and a failure partway through the
|
|
125
|
+
* publish loop are covered alike - a `bun publish` that dies on package 12 of 34
|
|
126
|
+
* must not leave the first 11 stamped. Best-effort per file: one unwritable
|
|
127
|
+
* manifest is logged and the rest are still restored, since a partial restore
|
|
128
|
+
* beats none.
|
|
129
|
+
*
|
|
130
|
+
* Not registered under `--stamp-only`, where the stamps ARE the deliverable.
|
|
131
|
+
*/
|
|
132
|
+
function restoreManifests(): void {
|
|
133
|
+
for (const [pkgPath, backup] of manifestBackups) {
|
|
134
|
+
try {
|
|
135
|
+
chmodSync(pkgPath, backup.mode | 0o200);
|
|
136
|
+
writeFileSync(pkgPath, backup.content);
|
|
137
|
+
chmodSync(pkgPath, backup.mode);
|
|
138
|
+
} catch (cause) {
|
|
139
|
+
logger.warn(`could not restore ${pkgPath}`, { cause });
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
manifestBackups.clear();
|
|
80
143
|
}
|
|
81
144
|
|
|
82
145
|
/** Entry-point fields projen writes as `.ts` source in-repo and rewrites to `lib/` for publish. */
|
|
@@ -87,8 +150,9 @@ const PUBLISH_CONFIG_ENTRY_FIELDS = ["main", "types", "bin", "exports"] as const
|
|
|
87
150
|
* the way pnpm/npm do at pack time but `bun publish` does NOT (see the module
|
|
88
151
|
* doc). Idempotent, writes only when something changes, and leaves `publishConfig`
|
|
89
152
|
* in place (npm ignores it once the top-level fields already point at `lib/`). The
|
|
90
|
-
* manifest must already be unlocked.
|
|
91
|
-
*
|
|
153
|
+
* manifest must already be unlocked. {@link restoreManifests} puts the `.ts` entry
|
|
154
|
+
* points back at exit, so this only ever affects the packed tarball - like the
|
|
155
|
+
* version stamp.
|
|
92
156
|
*/
|
|
93
157
|
function applyPublishConfig(pkgPath: string): void {
|
|
94
158
|
const pkg = JSON.parse(readFileSync(pkgPath, "utf8")) as Record<string, unknown>;
|
|
@@ -133,12 +197,19 @@ const dryRun = rest.includes("--dry-run");
|
|
|
133
197
|
// own `bun publish` (run separately, in `projen/`) resolves `workspace:*` siblings
|
|
134
198
|
// to the release version; publishing every member here would double-publish them.
|
|
135
199
|
const stampOnly = rest.includes("--stamp-only");
|
|
200
|
+
// Undo the manifest edits at exit unless a later process still needs them. Implied
|
|
201
|
+
// off by `--stamp-only`, whose stamps exist precisely for a subsequent `bun publish`.
|
|
202
|
+
const restore = !stampOnly && !rest.includes("--no-restore");
|
|
136
203
|
const excluded = new Set(
|
|
137
204
|
rest.reduce<string[]>((acc, arg, i) => (arg === "--exclude" ? [...acc, rest[i + 1]] : acc), []),
|
|
138
205
|
);
|
|
139
206
|
|
|
140
207
|
const root = process.cwd();
|
|
141
208
|
const path = enrichedPath(root);
|
|
209
|
+
// Registered BEFORE the first manifest edit so no exit path can skip it: a clean
|
|
210
|
+
// finish and a `bun publish` failure mid-loop both land here, so a publish that
|
|
211
|
+
// dies partway does not leave half the workspace stamped.
|
|
212
|
+
if (restore) process.on("exit", restoreManifests);
|
|
142
213
|
const members = workspaceMembers(root)
|
|
143
214
|
.filter((dir) => existsSync(join(dir, "package.json")))
|
|
144
215
|
.filter((dir) => !excluded.has(resolve(root, dir).replace(`${resolve(root)}/`, "")));
|
package/tasks/sync.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env -S bun
|
|
2
2
|
import { fileURLToPath } from "node:url";
|
|
3
|
-
import concurrently from "concurrently";
|
|
4
3
|
import { log } from "@dbx-tools/shared-core";
|
|
4
|
+
import concurrently from "concurrently";
|
|
5
5
|
import { runSynth } from "../src/scaffold.ts";
|
|
6
6
|
|
|
7
7
|
const logger = log.logger("projen:sync");
|