rman 2.16.0 → 2.17.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.
@@ -0,0 +1,30 @@
1
+ import type { RunBinOptions, RunBinResult } from '../../../../utils/run-bin.js';
2
+ /**
3
+ * The files `copyAssets` copies when it is given no patterns: the data formats a package keeps
4
+ * beside its sources - translations, fixtures, schemas - that `tsc` does not emit.
5
+ */
6
+ export declare const DEFAULT_ASSET_PATTERNS: readonly string[];
7
+ export interface CopyAssetsOptions {
8
+ /** The tsconfig the build compiles with - its `rootDir` and `outDir` say where the files are and
9
+ * where they go. */
10
+ tsconfig: string;
11
+ /** Globs over paths relative to `rootDir`. Default `DEFAULT_ASSET_PATTERNS`. */
12
+ patterns?: readonly string[];
13
+ /** Runs `tsc` - a function step's own `ctx.runBin`, which already resolves the repository's
14
+ * installed copy. */
15
+ runBin: (bin: string, argv: string[], options?: RunBinOptions) => Promise<RunBinResult>;
16
+ }
17
+ /**
18
+ * Copies the files under a tsconfig's `rootDir` that match `patterns` into its `outDir`, keeping
19
+ * their place in the tree - `src/i18n/tr.json` lands at `build/i18n/tr.json`, where the compiled
20
+ * code that reads it expects to find it. Returns the files it wrote, absolute.
21
+ *
22
+ * `tsc` emits none of them: it compiles sources, and a `.json` reaches the output only when code
23
+ * imports it under `resolveJsonModule`. A file read at run time - a translation, an XML template, a
24
+ * fixture - is left behind, and the built package fails on a path that exists only in `src`.
25
+ *
26
+ * A tsconfig with no `outDir` compiles beside its sources, so there is nothing to copy and nothing
27
+ * is. `node_modules`, the output directory itself, `tsconfig*.json`, `package.json` and
28
+ * `package-lock.json` are never copied.
29
+ */
30
+ export declare function copyAssets(options: CopyAssetsOptions): Promise<string[]>;
@@ -0,0 +1,104 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import glob from 'fast-glob';
4
+ /**
5
+ * The files `copyAssets` copies when it is given no patterns: the data formats a package keeps
6
+ * beside its sources - translations, fixtures, schemas - that `tsc` does not emit.
7
+ */
8
+ /* **A list, not "everything that is not TypeScript"** - the user's call, and the reason is what
9
+ * ships: a published package is what lands in a consumer's `node_modules`, and "every other file"
10
+ * puts a stray `.md`, a `.DS_Store` or a test's data file there with nothing saying so. A list
11
+ * leaves out what nobody named, and a repository that needs more names it. */
12
+ export const DEFAULT_ASSET_PATTERNS = ['**/*.json', '**/*.xml', '**/*.yaml', '**/*.yml'];
13
+ /**
14
+ * Copies the files under a tsconfig's `rootDir` that match `patterns` into its `outDir`, keeping
15
+ * their place in the tree - `src/i18n/tr.json` lands at `build/i18n/tr.json`, where the compiled
16
+ * code that reads it expects to find it. Returns the files it wrote, absolute.
17
+ *
18
+ * `tsc` emits none of them: it compiles sources, and a `.json` reaches the output only when code
19
+ * imports it under `resolveJsonModule`. A file read at run time - a translation, an XML template, a
20
+ * fixture - is left behind, and the built package fails on a path that exists only in `src`.
21
+ *
22
+ * A tsconfig with no `outDir` compiles beside its sources, so there is nothing to copy and nothing
23
+ * is. `node_modules`, the output directory itself, `tsconfig*.json`, `package.json` and
24
+ * `package-lock.json` are never copied.
25
+ */
26
+ /* **`rootDir`/`outDir` are asked of `tsc --showConfig`, not read out of the file.** A package's
27
+ * tsconfig usually inherits both through `extends` - a relative path or a package such as
28
+ * `@panates/tsconfig` - and resolving that chain is `tsc`'s own logic: JSON with comments, a list
29
+ * of bases, package `exports`. `--showConfig` prints the resolved result with every path relative
30
+ * to the config it was given, in about 0.4s (measured on `panates/opra`'s `common`), which is small
31
+ * beside the compile it follows.
32
+ *
33
+ * **No `rootDir` means `tsc` computed one** - the common directory of its inputs - and `--showConfig`
34
+ * lists those inputs under `files`, so the same answer is taken from there. Declaration files are
35
+ * left out of it, as `tsc` leaves them out. */
36
+ export async function copyAssets(options) {
37
+ const configDir = path.dirname(path.resolve(options.tsconfig));
38
+ /** **`onLine` swallows the lines**: a step's `runBin` hands every line to the step's log, and the
39
+ * whole resolved configuration printed under the package is noise. `output` still collects them. */
40
+ let output;
41
+ try {
42
+ ({ output } = await options.runBin('tsc', ['--showConfig', '-p', options.tsconfig], {
43
+ stdio: 'pipe',
44
+ onLine: () => undefined,
45
+ }));
46
+ }
47
+ catch (e) {
48
+ throw new Error(`"tsc --showConfig -p ${options.tsconfig}" failed:\n${String(e?.output ?? e?.message).trim()}`, {
49
+ cause: e,
50
+ });
51
+ }
52
+ const config = parseShowConfig(output, options.tsconfig);
53
+ const outDir = config.compilerOptions?.outDir;
54
+ if (!outDir)
55
+ return [];
56
+ const out = path.resolve(configDir, outDir);
57
+ const root = config.compilerOptions?.rootDir
58
+ ? path.resolve(configDir, config.compilerOptions.rootDir)
59
+ : (commonDir((config.files ?? []).filter(f => !/\.d\.[cm]?ts$/.test(f)).map(f => path.resolve(configDir, f))) ??
60
+ configDir);
61
+ /** `package.json` and its lockfile because a `rootDir` of the package itself would otherwise send
62
+ * them along - and the build directory's manifest is `publish`'s (or the preset's) to write. */
63
+ const ignore = ['**/node_modules/**', '**/tsconfig*.json', '**/package.json', '**/package-lock.json'];
64
+ const outInsideRoot = path.relative(root, out);
65
+ if (outInsideRoot && !outInsideRoot.startsWith('..') && !path.isAbsolute(outInsideRoot)) {
66
+ ignore.push(`${outInsideRoot.split(path.sep).join('/')}/**`);
67
+ }
68
+ const files = await glob([...(options.patterns ?? DEFAULT_ASSET_PATTERNS)], {
69
+ cwd: root,
70
+ ignore,
71
+ onlyFiles: true,
72
+ dot: false,
73
+ });
74
+ const written = [];
75
+ for (const rel of files.sort()) {
76
+ const target = path.join(out, rel);
77
+ fs.mkdirSync(path.dirname(target), { recursive: true });
78
+ fs.copyFileSync(path.join(root, rel), target);
79
+ written.push(target);
80
+ }
81
+ return written;
82
+ }
83
+ /** `tsc --showConfig`'s answer. It prints the JSON alone on success; anything else is a tsconfig
84
+ * `tsc` could not read, which is reported with what it said. */
85
+ function parseShowConfig(output, tsconfig) {
86
+ const start = output.indexOf('{');
87
+ try {
88
+ return JSON.parse(output.slice(start));
89
+ }
90
+ catch {
91
+ throw new Error(`"tsc --showConfig -p ${tsconfig}" did not print a configuration:\n${output.trim()}`);
92
+ }
93
+ }
94
+ /** The deepest directory holding every one of `files`, or `undefined` for none. */
95
+ function commonDir(files) {
96
+ if (!files.length)
97
+ return undefined;
98
+ let common = path.dirname(files[0]);
99
+ for (const file of files.slice(1)) {
100
+ while (path.relative(common, file).startsWith('..'))
101
+ common = path.dirname(common);
102
+ }
103
+ return common;
104
+ }
package/constants.js CHANGED
@@ -1 +1 @@
1
- export const version = '2.16.0';
1
+ export const version = '2.17.0';
package/index.d.ts CHANGED
@@ -169,6 +169,7 @@ export { CiService } from './builtins/platforms/node/services/ci.service.js';
169
169
  export { CleanService } from './builtins/platforms/node/services/clean.service.js';
170
170
  export { PublishService } from './builtins/platforms/node/services/publish.service.js';
171
171
  export { NodeVersionPlanService } from './builtins/platforms/node/services/version-plan.service.js';
172
+ export { copyAssets, type CopyAssetsOptions, DEFAULT_ASSET_PATTERNS, } from './builtins/platforms/node/utils/copy-assets.js';
172
173
  export type { ParsedWorkspaceRange } from './builtins/platforms/node/utils/workspace-range.js';
173
174
  export { NPM_TARGET, NpmPublishTarget } from './builtins/publish-targets/npm/npm-publish-target.js';
174
175
  export { isCalendarVersion } from './utils/release-version.js';
package/index.js CHANGED
@@ -135,6 +135,7 @@ export { CiService } from './builtins/platforms/node/services/ci.service.js';
135
135
  export { CleanService } from './builtins/platforms/node/services/clean.service.js';
136
136
  export { PublishService } from './builtins/platforms/node/services/publish.service.js';
137
137
  export { NodeVersionPlanService } from './builtins/platforms/node/services/version-plan.service.js';
138
+ export { copyAssets, DEFAULT_ASSET_PATTERNS, } from './builtins/platforms/node/utils/copy-assets.js';
138
139
  export { NPM_TARGET, NpmPublishTarget } from './builtins/publish-targets/npm/npm-publish-target.js';
139
140
  export { isCalendarVersion } from './utils/release-version.js';
140
141
  export { runBin } from './utils/run-bin.js';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "rman",
3
3
  "description": "Repository manager",
4
- "version": "2.16.0",
4
+ "version": "2.17.0",
5
5
  "author": "Panates",
6
6
  "license": "MIT",
7
7
  "dependencies": {