@deltabox/toolchain 1.11.4 → 2.1.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 +336 -4
- package/README.md +21 -14
- package/dist/_virtual/_rolldown/runtime.js +1 -1
- package/dist/changelog.d.ts +10 -6
- package/dist/changelog.js +1 -1
- package/dist/cli/commands/index.js +1 -1
- package/dist/cli/commands/providers.js +1 -1
- package/dist/cli/commands/reset.js +1 -1
- package/dist/cli/commands/shared.js +1 -1
- package/dist/cli/commands/sync.js +1 -1
- package/dist/cli/commands/watch.js +1 -1
- package/dist/cli/config-selection.d.ts +23 -0
- package/dist/cli/config-selection.js +1 -0
- package/dist/cli/context.js +1 -1
- package/dist/cli/index.d.ts +5 -3
- package/dist/cli/index.js +1 -1
- package/dist/cli/register.js +1 -1
- package/dist/config.d.ts +8 -8
- package/dist/config.js +1 -1
- package/dist/core.d.ts +7 -6
- package/dist/core.js +1 -1
- package/dist/globals.d.ts +31 -0
- package/dist/globals.js +1 -0
- package/dist/index.d.ts +33 -11
- package/dist/index.js +1 -1
- package/dist/migrate.d.ts +3 -2
- package/dist/migrate.js +1 -1
- package/dist/package.js +1 -1
- package/dist/packages/biome/src/index.d.ts +2 -1
- package/dist/packages/biome/src/index.js +1 -1
- package/dist/packages/changelog/src/cli/index.js +1 -1
- package/dist/packages/changelog/src/index.d.ts +11 -7
- package/dist/packages/changelog/src/index.js +1 -1
- package/dist/packages/changelog/src/run-workflows.d.ts +19 -4
- package/dist/packages/changelog/src/run-workflows.js +1 -1
- package/dist/packages/changelog/src/run.d.ts +4 -3
- package/dist/packages/changelog/src/run.js +1 -1
- package/dist/packages/changelog/src/sync.d.ts +7 -4
- package/dist/packages/changelog/src/sync.js +1 -1
- package/dist/packages/changelog/src/utils/args.js +1 -1
- package/dist/packages/changelog/src/utils/breaking.d.ts +16 -0
- package/dist/packages/changelog/src/utils/breaking.js +1 -0
- package/dist/packages/changelog/src/utils/format.d.ts +2 -1
- package/dist/packages/changelog/src/utils/format.js +5 -5
- package/dist/packages/changelog/src/utils/git.d.ts +3 -1
- package/dist/packages/changelog/src/utils/git.js +1 -1
- package/dist/packages/changelog/src/utils/reformat.d.ts +4 -1
- package/dist/packages/changelog/src/utils/reformat.js +4 -4
- package/dist/packages/changelog/src/utils/release-notes.d.ts +18 -0
- package/dist/packages/changelog/src/utils/release-notes.js +1 -0
- package/dist/packages/changelog/src/utils/summary.d.ts +29 -2
- package/dist/packages/changelog/src/utils/summary.js +3 -1
- package/dist/packages/changelog/src/utils/types.d.ts +39 -2
- package/dist/packages/changelog/src/utils/version.d.ts +1 -0
- package/dist/packages/changelog/src/utils/versioning.d.ts +30 -4
- package/dist/packages/changelog/src/utils/versioning.js +1 -1
- package/dist/packages/changelog/src/utils/write.js +1 -1
- package/dist/packages/changelog/src/workflows.d.ts +27 -7
- package/dist/packages/changelog/src/workflows.js +5 -5
- package/dist/packages/config/src/cli/index.js +1 -1
- package/dist/packages/config/src/collect.d.ts +10 -8
- package/dist/packages/config/src/collect.js +1 -1
- package/dist/packages/config/src/config-json.d.ts +4 -4
- package/dist/packages/config/src/config-json.js +1 -1
- package/dist/packages/config/src/engine.d.ts +14 -25
- package/dist/packages/config/src/engine.js +1 -1
- package/dist/packages/config/src/env-file.d.ts +4 -4
- package/dist/packages/config/src/env-file.js +2 -2
- package/dist/packages/config/src/env.d.ts +4 -6
- package/dist/packages/config/src/env.js +1 -1
- package/dist/packages/config/src/generators/cli.d.ts +6 -6
- package/dist/packages/config/src/generators/cli.js +1 -1
- package/dist/packages/config/src/generators/env.d.ts +9 -9
- package/dist/packages/config/src/generators/env.js +2 -2
- package/dist/packages/config/src/generators/index.d.ts +4 -4
- package/dist/packages/config/src/generators/index.js +1 -1
- package/dist/packages/config/src/generators/json.d.ts +5 -7
- package/dist/packages/config/src/generators/json.js +1 -1
- package/dist/packages/config/src/generators/markdown.d.ts +57 -35
- package/dist/packages/config/src/generators/markdown.js +18 -19
- package/dist/packages/config/src/generators/types.d.ts +28 -23
- package/dist/packages/config/src/generators/types.js +3 -3
- package/dist/packages/config/src/index.d.ts +9 -9
- package/dist/packages/config/src/index.js +1 -1
- package/dist/packages/config/src/schema.d.ts +31 -3
- package/dist/packages/config/src/schema.js +1 -1
- package/dist/packages/config/src/types.d.ts +134 -28
- package/dist/packages/core/src/editor-config.d.ts +14 -0
- package/dist/packages/core/src/editor-config.js +1 -0
- package/dist/packages/core/src/graph.js +1 -1
- package/dist/packages/core/src/index.d.ts +8 -7
- package/dist/packages/core/src/index.js +1 -1
- package/dist/packages/core/src/loader.d.ts +20 -2
- package/dist/packages/core/src/loader.js +1 -1
- package/dist/packages/core/src/manifest.d.ts +20 -1
- package/dist/packages/core/src/manifest.js +1 -1
- package/dist/packages/core/src/provider-registry.d.ts +48 -3
- package/dist/packages/core/src/provider-registry.js +1 -1
- package/dist/packages/core/src/reset.d.ts +15 -0
- package/dist/packages/core/src/reset.js +1 -1
- package/dist/packages/core/src/sync.d.ts +10 -0
- package/dist/packages/core/src/sync.js +1 -1
- package/dist/packages/core/src/watch.d.ts +9 -0
- package/dist/packages/core/src/watch.js +1 -1
- package/dist/packages/migrate/src/cli/index.js +1 -1
- package/dist/packages/migrate/src/index.d.ts +3 -2
- package/dist/packages/migrate/src/index.js +1 -1
- package/dist/packages/migrate/src/oxc.d.ts +13 -0
- package/dist/packages/migrate/src/oxc.js +1 -0
- package/dist/packages/migrate/src/registry.js +1 -1
- package/dist/packages/migrate/src/vite-target.js +1 -1
- package/dist/packages/migrate/src/vite.d.ts +25 -3
- package/dist/packages/migrate/src/vite.js +7 -2
- package/dist/packages/project/src/catalogs.d.ts +7 -0
- package/dist/packages/project/src/catalogs.js +1 -1
- package/dist/packages/project/src/cli/index.js +1 -1
- package/dist/packages/project/src/config.d.ts +6 -0
- package/dist/packages/project/src/config.js +1 -1
- package/dist/packages/project/src/index.d.ts +5 -4
- package/dist/packages/project/src/index.js +1 -1
- package/dist/packages/project/src/sync.js +1 -1
- package/dist/packages/project/src/typescript.d.ts +64 -12
- package/dist/packages/project/src/typescript.js +12 -7
- package/dist/packages/shared/src/changelog-breaking.d.ts +31 -0
- package/dist/packages/shared/src/changelog-groups.d.ts +59 -0
- package/dist/packages/shared/src/config-schema/biome.d.ts +10 -0
- package/dist/packages/shared/src/config-schema/biome.js +1 -0
- package/dist/packages/shared/src/config-schema/catalogs.d.ts +14 -0
- package/dist/packages/shared/src/config-schema/catalogs.js +1 -0
- package/dist/packages/shared/src/config-schema/changelog.d.ts +248 -0
- package/dist/packages/shared/src/config-schema/changelog.js +1 -0
- package/dist/packages/shared/src/config-schema/ci.d.ts +390 -0
- package/dist/packages/shared/src/config-schema/ci.js +1 -0
- package/dist/packages/shared/src/config-schema/format.d.ts +38 -0
- package/dist/packages/shared/src/config-schema/format.js +1 -0
- package/dist/packages/shared/src/config-schema/index.d.ts +1654 -0
- package/dist/packages/shared/src/config-schema/index.js +1 -0
- package/dist/packages/shared/src/config-schema/logger.d.ts +19 -0
- package/dist/packages/shared/src/config-schema/logger.js +1 -0
- package/dist/packages/shared/src/config-schema/meta.d.ts +16 -0
- package/dist/packages/shared/src/config-schema/meta.js +1 -0
- package/dist/packages/shared/src/config-schema/project.d.ts +35 -0
- package/dist/packages/shared/src/config-schema/project.js +1 -0
- package/dist/packages/shared/src/config-schema/providers.d.ts +9 -0
- package/dist/packages/shared/src/config-schema/providers.js +1 -0
- package/dist/packages/shared/src/config-schema/registry.d.ts +21 -0
- package/dist/packages/shared/src/config-schema/registry.js +1 -0
- package/dist/packages/shared/src/config-schema/templates.d.ts +81 -0
- package/dist/packages/shared/src/config-schema/templates.js +1 -0
- package/dist/packages/shared/src/config-schema/tsconfig.d.ts +30 -0
- package/dist/packages/shared/src/config-schema/tsconfig.js +1 -0
- package/dist/packages/shared/src/config-schema/vite.d.ts +26 -0
- package/dist/packages/shared/src/config-schema/vite.js +1 -0
- package/dist/packages/shared/src/config-schema/watch.d.ts +11 -0
- package/dist/packages/shared/src/config-schema/watch.js +1 -0
- package/dist/packages/shared/src/config-schema/workflow.d.ts +590 -0
- package/dist/packages/shared/src/config-schema/workflow.js +1 -0
- package/dist/packages/shared/src/config-types.d.ts +295 -90
- package/dist/packages/shared/src/fs-utils.js +1 -1
- package/dist/packages/shared/src/index.d.ts +27 -7
- package/dist/packages/shared/src/index.js +1 -1
- package/dist/packages/shared/src/logger.d.ts +26 -3
- package/dist/packages/shared/src/logger.js +1 -1
- package/dist/packages/shared/src/messages.d.ts +36 -0
- package/dist/packages/shared/src/messages.js +1 -0
- package/dist/packages/shared/src/object-utils.d.ts +5 -0
- package/dist/packages/shared/src/object-utils.js +1 -1
- package/dist/packages/shared/src/registry-policy.d.ts +17 -0
- package/dist/packages/shared/src/registry-policy.js +1 -0
- package/dist/packages/shared/src/toolchain.d.ts +90 -11
- package/dist/packages/shared/src/toolchain.js +1 -1
- package/dist/packages/shared/src/types.d.ts +6 -0
- package/dist/packages/shared/src/vite-defaults.d.ts +29 -0
- package/dist/packages/shared/src/vite-defaults.js +1 -0
- package/dist/packages/template/src/builtin.js +1 -1
- package/dist/packages/template/src/cli/index.js +1 -1
- package/dist/packages/template/src/global.d.ts +130 -0
- package/dist/packages/template/src/global.js +3 -0
- package/dist/packages/template/src/index.d.ts +3 -2
- package/dist/packages/template/src/index.js +1 -1
- package/dist/packages/template/src/online.d.ts +13 -4
- package/dist/packages/template/src/online.js +1 -1
- package/dist/packages/template/src/registry.d.ts +2 -1
- package/dist/packages/template/src/registry.js +1 -1
- package/dist/packages/template/src/scaffold.d.ts +5 -1
- package/dist/packages/template/src/scaffold.js +1 -1
- package/dist/packages/tsconfig/src/cli/generate/index.d.ts +3 -0
- package/dist/packages/tsconfig/src/cli/generate/index.js +1 -1
- package/dist/packages/tsconfig/src/cli/generate/utils.d.ts +10 -1
- package/dist/packages/tsconfig/src/cli/generate/utils.js +1 -1
- package/dist/packages/tsconfig/src/cli/index.js +1 -1
- package/dist/packages/tsconfig/src/index.d.ts +7 -4
- package/dist/packages/tsconfig/src/index.js +1 -1
- package/dist/packages/tsconfig/src/overrides.d.ts +74 -0
- package/dist/packages/tsconfig/src/overrides.js +1 -0
- package/dist/packages/tsconfig/src/resolve.d.ts +62 -0
- package/dist/packages/tsconfig/src/resolve.js +3 -0
- package/dist/packages/tsconfig/src/snapshots.d.ts +50 -0
- package/dist/packages/tsconfig/src/snapshots.js +1 -0
- package/dist/packages/tsconfig/src/sync.d.ts +14 -5
- package/dist/packages/tsconfig/src/sync.js +1 -1
- package/dist/packages/tsconfig/src/templates/tsconfig.default.js +1 -1
- package/dist/packages/tsconfig/src/templates.d.ts +12 -4
- package/dist/packages/tsconfig/src/templates.js +1 -1
- package/dist/packages/vite/src/index.d.ts +2 -2
- package/dist/packages/vite/src/index.js +1 -1
- package/dist/packages/vite/src/resolve.d.ts +13 -3
- package/dist/packages/vite/src/resolve.js +1 -1
- package/dist/packages/vite/src/sync.d.ts +46 -5
- package/dist/packages/vite/src/sync.js +5 -2
- package/dist/project.d.ts +4 -3
- package/dist/project.js +1 -1
- package/dist/providers.d.ts +11 -4
- package/dist/providers.js +1 -1
- package/dist/shared.d.ts +26 -6
- package/dist/shared.js +1 -1
- package/dist/sync.js +1 -1
- package/dist/template.d.ts +3 -2
- package/dist/template.js +1 -1
- package/dist/tooling.d.ts +21 -0
- package/dist/tooling.js +1 -0
- package/dist/tsconfig.d.ts +6 -3
- package/dist/tsconfig.js +1 -1
- package/dist/vite.d.ts +2 -2
- package/dist/vite.js +1 -1
- package/package.json +28 -23
- package/dist/packages/config/src/types.js +0 -1
- package/dist/packages/shared/src/config-schema.d.ts +0 -3928
- package/dist/packages/shared/src/config-schema.js +0 -1
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import __tsdown_shims_path from 'node:path';
|
|
2
|
+
import __tsdown_shims_url from 'node:url';
|
|
3
|
+
import { ToolchainTemplateSource } from "../../shared/src/config-types.js";
|
|
4
|
+
import { RegistryPolicy } from "../../shared/src/registry-policy.js";
|
|
5
|
+
import "../../shared/src/index.js";
|
|
6
|
+
import { Template } from "./types.js";
|
|
7
|
+
//#region packages/template/src/global.d.ts
|
|
8
|
+
/** The VS Code setting that lists the template search paths. */
|
|
9
|
+
export declare const VSCODE_REGISTRY_SEARCH_PATHS = "deltabox.registrySearchPaths";
|
|
10
|
+
/** `~/.dbx/toolchain`. */
|
|
11
|
+
export declare function globalToolchainDir(): string;
|
|
12
|
+
/** `~/.dbx/toolchain/cli/config.json`. */
|
|
13
|
+
export declare function cliConfigPath(): string;
|
|
14
|
+
/** `~/.dbx/toolchain/.registry/templates` (the default global templates dir). */
|
|
15
|
+
export declare function defaultGlobalTemplatesDir(): string;
|
|
16
|
+
/** `~/.dbx/toolchain/.registry/sources.json` (non-local global sources). */
|
|
17
|
+
export declare function globalSourcesPath(): string;
|
|
18
|
+
/** `~/.dbx/toolchain/.registry/providers.json`. */
|
|
19
|
+
export declare function globalProvidersPath(): string;
|
|
20
|
+
/** The default project-scoped template registry (`<cwd>/.dbx/toolchain/.registry/templates`). */
|
|
21
|
+
export declare function defaultProjectTemplatesRegistry(cwd: string): string;
|
|
22
|
+
/** `<cwd>/.dbx/toolchain/registries.json` (the project-scoped search paths). */
|
|
23
|
+
export declare function projectRegistriesPath(cwd: string): string;
|
|
24
|
+
/** The project-scoped registry search paths. */
|
|
25
|
+
export declare function readProjectRegistries(cwd: string): {
|
|
26
|
+
templates: string[];
|
|
27
|
+
providers: string[];
|
|
28
|
+
};
|
|
29
|
+
/** Write the project-scoped registry search paths (preserving provider paths). */
|
|
30
|
+
export declare function writeProjectRegistries(cwd: string, templates: string[]): void;
|
|
31
|
+
/** Add a project-scoped template registry directory (or remote URL). */
|
|
32
|
+
export declare function addProjectRegistry(cwd: string, entry: string): void;
|
|
33
|
+
/** Remove a project-scoped template registry directory (never the implicit default). */
|
|
34
|
+
export declare function removeProjectRegistry(cwd: string, entry: string): void;
|
|
35
|
+
/** The persisted CLI config (`~/.dbx/toolchain/cli/config.json`). */
|
|
36
|
+
export interface GlobalCliConfig {
|
|
37
|
+
/** Template search paths (directories and/or `http(s)` registry URLs). */
|
|
38
|
+
registrySearchPaths?: string | string[];
|
|
39
|
+
/** The VS Code user directory (its `settings.json` holds the search paths). */
|
|
40
|
+
vscodeDir?: string;
|
|
41
|
+
}
|
|
42
|
+
/** Options that only read or write the persisted config. */
|
|
43
|
+
export declare function readGlobalCliConfig(): GlobalCliConfig;
|
|
44
|
+
/** Merge a patch into the persisted CLI config and return the result. */
|
|
45
|
+
export declare function writeGlobalCliConfig(patch: Partial<GlobalCliConfig>): GlobalCliConfig;
|
|
46
|
+
/** Expand a leading `~` to the user's home directory. */
|
|
47
|
+
export declare function expandHome(value: string): string;
|
|
48
|
+
/** Normalize a string-or-array path setting into an array (home-expanded). */
|
|
49
|
+
export declare function normalizeSearchPaths(value: string | string[] | undefined): string[];
|
|
50
|
+
/** Whether a search path is a remote registry URL. */
|
|
51
|
+
export declare function isRemoteRegistry(value: string): boolean;
|
|
52
|
+
/** Set a top-level JSON/JSONC key, preserving the rest of the file (incl. comments). */
|
|
53
|
+
export declare function setJsoncValue(text: string, key: string, value: unknown): string;
|
|
54
|
+
/** The path of the VS Code user `settings.json` for a `vscodeDir`. */
|
|
55
|
+
export declare function vscodeSettingsPath(vscodeDir: string): string;
|
|
56
|
+
/** Read the `deltabox.registrySearchPaths` setting from a VS Code user dir. */
|
|
57
|
+
export declare function readVscodeSearchPaths(vscodeDir: string | undefined): string[];
|
|
58
|
+
/**
|
|
59
|
+
* Write the `deltabox.registrySearchPaths` setting into a VS Code user dir.
|
|
60
|
+
* Best-effort JSONC edit: other settings/comments are preserved.
|
|
61
|
+
*/
|
|
62
|
+
export declare function writeVscodeSearchPaths(vscodeDir: string | undefined, paths: string[]): boolean;
|
|
63
|
+
/** Where the resolved template search paths came from. */
|
|
64
|
+
export type SearchPathSource = 'cli' | 'vscode' | 'default';
|
|
65
|
+
export interface ResolvedSearchPaths {
|
|
66
|
+
/** Project + global paths in load order (project first). */
|
|
67
|
+
paths: string[];
|
|
68
|
+
/** Project-scoped registries. */
|
|
69
|
+
project: string[];
|
|
70
|
+
/** Global registries (CLI config / VS Code setting / default). */
|
|
71
|
+
global: string[];
|
|
72
|
+
source: SearchPathSource;
|
|
73
|
+
vscodeDir?: string;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Resolve the registry search paths: project-scoped paths first (the implicit
|
|
77
|
+
* `<cwd>/.dbx/toolchain/.registry/templates` plus `registries.json`), then the
|
|
78
|
+
* global ones (CLI config wins, then the VS Code setting, then the default).
|
|
79
|
+
*/
|
|
80
|
+
export declare function resolveTemplateSearchPaths(cwd?: string): ResolvedSearchPaths;
|
|
81
|
+
/** A detected registry (rendered by the CLI and the VS Code Registries view). */
|
|
82
|
+
export interface RegistryEntry {
|
|
83
|
+
path: string;
|
|
84
|
+
scope: 'project' | 'global';
|
|
85
|
+
remote: boolean;
|
|
86
|
+
kind: 'templates' | 'providers';
|
|
87
|
+
}
|
|
88
|
+
/** List the detected template and provider registries. */
|
|
89
|
+
export declare function listRegistries(cwd: string): {
|
|
90
|
+
templates: RegistryEntry[];
|
|
91
|
+
providers: RegistryEntry[];
|
|
92
|
+
};
|
|
93
|
+
/** A unique variant of `id` (`foo-2`, `foo-3`, ...). */
|
|
94
|
+
export declare function uniqueTemplateId(id: string, taken: Iterable<string>): string;
|
|
95
|
+
/**
|
|
96
|
+
* Every template id that already exists: builtins, global/local templates and
|
|
97
|
+
* the ids declared by global sources. The project registry is added by the
|
|
98
|
+
* caller when it has one.
|
|
99
|
+
*/
|
|
100
|
+
export declare function existingTemplateIds(cwd?: string, options?: {
|
|
101
|
+
global?: boolean;
|
|
102
|
+
}): Promise<Set<string>>;
|
|
103
|
+
/** The non-local global sources (git/npm/http) stored in the registry. */
|
|
104
|
+
export declare function readGlobalSources(): ToolchainTemplateSource[];
|
|
105
|
+
/** Add/replace a non-local source in the global sources registry. */
|
|
106
|
+
export declare function addGlobalSource(source: ToolchainTemplateSource): ToolchainTemplateSource[];
|
|
107
|
+
/**
|
|
108
|
+
* Remove a template from the global registry: delete its stored directory and/or
|
|
109
|
+
* drop a matching global source. Returns whether anything was removed.
|
|
110
|
+
*/
|
|
111
|
+
export declare function removeGlobalTemplate(id: string): boolean;
|
|
112
|
+
/**
|
|
113
|
+
* Store a local template directory in the first writable global directory.
|
|
114
|
+
* Returns the destination path (or the original when it is already global).
|
|
115
|
+
*/
|
|
116
|
+
export declare function addGlobalTemplate(dir: string, id?: string): string;
|
|
117
|
+
export interface GlobalTemplates {
|
|
118
|
+
/** Templates discovered in the local search paths. */
|
|
119
|
+
templates: Template[];
|
|
120
|
+
/** Sources declared by remote (`http(s)`) registries. */
|
|
121
|
+
sources: ToolchainTemplateSource[];
|
|
122
|
+
/** The resolved search paths. */
|
|
123
|
+
paths: string[];
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Load the global templates: local search paths are scanned for template dirs,
|
|
127
|
+
* and remote registry URLs are fetched (their `{ sources }` / array is merged).
|
|
128
|
+
*/
|
|
129
|
+
export declare function loadGlobalTemplates(cwd?: string, policy?: RegistryPolicy): Promise<GlobalTemplates>;
|
|
130
|
+
//#endregion
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import{default as e}from"node:path";import"node:url";import.meta.url;import{registrySourceAllowed as t}from"../../shared/src/registry-policy.js";import"../../shared/src/index.js";import{providerRegistryPaths as n}from"../../core/src/provider-registry.js";import"../../core/src/index.js";import{BUILTIN_TEMPLATES as r}from"./builtin.js";import{loadLocalTemplates as i}from"./local.js";import a from"node:fs";import o from"node:os";const s=`deltabox.registrySearchPaths`;function c(){return e.join(o.homedir(),`.dbx`,`toolchain`)}function l(){return e.join(c(),`cli`,`config.json`)}function u(){return e.join(c(),`.registry`,`templates`)}function d(){return e.join(c(),`.registry`,`sources.json`)}function f(){return e.join(c(),`.registry`,`providers.json`)}function p(t){return e.join(t,`.dbx`,`toolchain`,`.registry`,`templates`)}function m(t){return e.join(t,`.dbx`,`toolchain`,`registries.json`)}function h(e){try{let t=a.readFileSync(m(e),`utf-8`).replace(/^\uFEFF/,``),n=JSON.parse(t);return{templates:Array.isArray(n.templates)?n.templates.map(String).filter(Boolean):[],providers:Array.isArray(n.providers)?n.providers.map(String).filter(Boolean):[]}}catch{return{templates:[],providers:[]}}}function g(t,n){let r=m(t),i=h(t).providers,o={...n.length>0?{templates:n}:{},...i.length>0?{providers:i}:{}};Object.keys(o).length===0?a.rmSync(r,{force:!0}):(a.mkdirSync(e.dirname(r),{recursive:!0}),a.writeFileSync(r,`${JSON.stringify(o,null,4)}\n`,`utf-8`))}function _(t,n){let r=C(n),i=r?n:e.resolve(t,x(n));r||a.mkdirSync(i,{recursive:!0});let o=h(t);o.templates.some(n=>(C(n)?n:e.resolve(t,x(n)))===i)||g(t,[...o.templates,n])}function v(t,n){let r=C(n)?n:e.resolve(t,x(n));g(t,h(t).templates.filter(n=>(C(n)?n:e.resolve(t,x(n)))!==r))}function y(){try{let e=a.readFileSync(l(),`utf-8`).replace(/^\uFEFF/,``),t=JSON.parse(e);return t&&typeof t==`object`?t:{}}catch{return{}}}function b(t){let n={...y(),...t};for(let e of Object.keys(n))n[e]===void 0&&delete n[e];let r=l();return a.mkdirSync(e.dirname(r),{recursive:!0}),a.writeFileSync(r,`${JSON.stringify(n,null,4)}\n`,`utf-8`),n}function x(t){return t===`~`?o.homedir():t.startsWith(`~/`)||t.startsWith(`~\\`)?e.join(o.homedir(),t.slice(2)):t}function S(e){return e?(Array.isArray(e)?e:[e]).map(e=>x(String(e))).filter(Boolean):[]}function C(e){return/^https?:\/\//i.test(e)}function w(e,t){let n=e.search(RegExp(`"${t.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}"\\s*:`));if(n===-1)return;let r=e.indexOf(`:`,n);if(r===-1)return;let i=r+1;for(;i<e.length&&/\s/.test(e[i]);)i++;let a=e[i];if(a===`[`||a===`{`){let t=a===`[`?`]`:`}`,n=0;for(let r=i;r<e.length;r++)if(e[r]===a)n++;else if(e[r]===t&&(n--,n===0))return[i,r+1];return}if(a===`"`){let t=i+1;for(;t<e.length&&e[t]!==`"`;)e[t]===`\\`&&t++,t++;return[i,t+1]}let o=i;for(;o<e.length&&e[o]!==`,`&&e[o]!==`}`;)o++;for(;o>i&&/\s/.test(e[o-1]);)o--;return[i,o]}function T(e,t){let n=w(e,t);if(n)try{return JSON.parse(e.slice(n[0],n[1]))}catch{return}}function E(e,t,n){let r=JSON.stringify(n),i=w(e,t);if(i)return`${e.slice(0,i[0])}${r}${e.slice(i[1])}`;let a=e.indexOf(`{`);return a===-1?`{\n "${t}": ${r}\n}\n`:`${e.slice(0,a+1)}\n "${t}": ${r},${e.slice(a+1)}`}function D(t){return e.join(x(t),`settings.json`)}function O(e){if(!e)return[];try{return S(T(a.readFileSync(D(e),`utf-8`),s))}catch{return[]}}function k(t,n){if(!t||n.length===0)return!1;let r=D(t),i=``;try{i=a.readFileSync(r,`utf-8`)}catch{i=`{
|
|
2
|
+
}
|
|
3
|
+
`}if(JSON.stringify(T(i,`deltabox.registrySearchPaths`))===JSON.stringify(n))return!1;let o=E(i,s,n);return a.mkdirSync(e.dirname(r),{recursive:!0}),a.writeFileSync(r,o,`utf-8`),!0}function A(t){let n=[];if(t){let r=p(t);a.existsSync(r)&&n.push(r);for(let r of h(t).templates){let i=C(r)?r:e.resolve(t,x(r));n.includes(i)||n.push(i)}}let r=y(),i=r.vscodeDir?x(r.vscodeDir):void 0,o=S(r.registrySearchPaths),s,c;if(o.length>0)s=o,c=`cli`;else{let e=O(i);e.length>0?(s=e,c=`vscode`):(s=[u()],c=`default`)}return{paths:[...n,...s.filter(e=>!n.includes(e))],project:n,global:s,source:c,...i?{vscodeDir:i}:{}}}function j(e){let t=A(e);return{templates:[...t.project.map(e=>({path:e,scope:`project`,remote:C(e),kind:`templates`})),...t.global.map(e=>({path:e,scope:`global`,remote:C(e),kind:`templates`}))],providers:n(e).map(e=>({...e,kind:`providers`}))}}function M(e,t){let n=new Set(t);if(!n.has(e))return e;let r=2;for(;n.has(`${e}-${r}`);)r+=1;return`${e}-${r}`}async function N(e,t={}){let n=new Set(r.map(e=>e.id));if(t.global===!1)return n;let i=await z(e);for(let e of i.templates)n.add(e.id);for(let e of[...i.sources,...P()])e.id&&n.add(e.id);return n}function P(){try{let e=a.readFileSync(d(),`utf-8`).replace(/^\uFEFF/,``),t=JSON.parse(e),n=Array.isArray(t)?t:t.sources;return Array.isArray(n)?n:[]}catch{return[]}}function F(t){let n=e=>`${e.type}:${e.locate}`,r=P().filter(e=>n(e)!==n(t));r.push(t);let i=d();return a.mkdirSync(e.dirname(i),{recursive:!0}),a.writeFileSync(i,`${JSON.stringify({sources:r},null,4)}\n`,`utf-8`),r}function I(t){let{global:n}=A(),r=!1;for(let i of n){if(C(i))continue;let n=e.join(i,t);a.existsSync(e.join(n,`template.json`))&&(a.rmSync(n,{recursive:!0,force:!0}),r=!0)}let i=P(),o=i.filter(e=>(e.id??e.locate)!==t);if(o.length!==i.length){let e=d();o.length===0?a.rmSync(e,{force:!0}):a.writeFileSync(e,`${JSON.stringify({sources:o},null,4)}\n`,`utf-8`),r=!0}return r}const L=/* @__PURE__ */ new Set([`node_modules`,`.git`,`dist`,`.dbx`,`.turbo`,`.DS_Store`]);function R(t,n){let{paths:r}=A(),i=r.filter(e=>!C(e))[0]??u(),o=(n??e.basename(t)).replace(/[\\/]+/g,`-`),s=e.join(i,o);return e.resolve(s)===e.resolve(t)||a.existsSync(e.join(s,`template.json`))||(a.mkdirSync(i,{recursive:!0}),a.cpSync(t,s,{recursive:!0,filter:t=>!L.has(e.basename(t))})),s}async function z(n,r){let{paths:a}=A(n),o=a.filter(n=>t(C(n)?n:e.resolve(n),r)),s=[],c=P().filter(i=>t(i.type===`local`&&n?e.resolve(n,i.locate):i.locate,r));for(let a of o)if(C(a))try{let i=await fetch(a);if(!i.ok)continue;let o=await i.json(),s=Array.isArray(o)?o:o.sources??o.templates;if(Array.isArray(s))for(let i of s){if(!i||typeof i!=`object`||!(`type`in i)||!(`locate`in i))continue;let a=i;t(a.type===`local`&&n?e.resolve(n,a.locate):a.locate,r)&&c.push(a)}}catch{}else s.push(...i(a));return{templates:s,sources:c,paths:o}}export{s as VSCODE_REGISTRY_SEARCH_PATHS,F as addGlobalSource,R as addGlobalTemplate,_ as addProjectRegistry,l as cliConfigPath,u as defaultGlobalTemplatesDir,p as defaultProjectTemplatesRegistry,N as existingTemplateIds,x as expandHome,f as globalProvidersPath,d as globalSourcesPath,c as globalToolchainDir,C as isRemoteRegistry,j as listRegistries,z as loadGlobalTemplates,S as normalizeSearchPaths,m as projectRegistriesPath,y as readGlobalCliConfig,P as readGlobalSources,h as readProjectRegistries,O as readVscodeSearchPaths,I as removeGlobalTemplate,v as removeProjectRegistry,A as resolveTemplateSearchPaths,E as setJsoncValue,M as uniqueTemplateId,D as vscodeSettingsPath,b as writeGlobalCliConfig,g as writeProjectRegistries,k as writeVscodeSearchPaths};
|
|
@@ -3,8 +3,9 @@ import __tsdown_shims_url from 'node:url';
|
|
|
3
3
|
import { Template, TemplateAction, TemplateActionContext, TemplateKind, TemplateManifest, TemplateVariable } from "./types.js";
|
|
4
4
|
import { BUILTIN_TEMPLATES } from "./builtin.js";
|
|
5
5
|
import { templateCommands } from "./cli/index.js";
|
|
6
|
+
import { GlobalCliConfig, GlobalTemplates, RegistryEntry, ResolvedSearchPaths, SearchPathSource, VSCODE_REGISTRY_SEARCH_PATHS, addGlobalSource, addGlobalTemplate, addProjectRegistry, cliConfigPath, defaultGlobalTemplatesDir, defaultProjectTemplatesRegistry, existingTemplateIds, expandHome, globalProvidersPath, globalSourcesPath, globalToolchainDir, isRemoteRegistry, listRegistries, loadGlobalTemplates, normalizeSearchPaths, projectRegistriesPath, readGlobalCliConfig, readGlobalSources, readProjectRegistries, readVscodeSearchPaths, removeGlobalTemplate, removeProjectRegistry, resolveTemplateSearchPaths, setJsoncValue, uniqueTemplateId, vscodeSettingsPath, writeGlobalCliConfig, writeProjectRegistries, writeVscodeSearchPaths } from "./global.js";
|
|
6
7
|
import { TEMPLATE_MANIFEST, isTemplateDir, loadLocalTemplates, readTemplateDir, readTemplateManifest, writeTemplateManifest } from "./local.js";
|
|
7
|
-
import { gitTemplate, loadNpmTemplates, parseSourceSpec } from "./online.js";
|
|
8
|
+
import { detectNpmRegistry, gitTemplate, loadNpmTemplates, parseSourceSpec } from "./online.js";
|
|
8
9
|
import { LoadTemplatesOptions, REGISTRY_DIR, REGISTRY_FILE, TemplateRegistry, addTemplateSource, collectSources, loadTemplates, readTemplateRegistry, removeTemplateSource, writeTemplateRegistry } from "./registry.js";
|
|
9
10
|
import { ScaffoldOptions, ScaffoldResult, scaffoldTemplate } from "./scaffold.js";
|
|
10
|
-
export { BUILTIN_TEMPLATES, LoadTemplatesOptions, REGISTRY_DIR, REGISTRY_FILE, ScaffoldOptions, ScaffoldResult, TEMPLATE_MANIFEST, Template, TemplateAction, TemplateActionContext, TemplateKind, TemplateManifest, TemplateRegistry, TemplateVariable, addTemplateSource, collectSources, gitTemplate, isTemplateDir, loadLocalTemplates, loadNpmTemplates, loadTemplates, parseSourceSpec, readTemplateDir, readTemplateManifest, readTemplateRegistry, removeTemplateSource, scaffoldTemplate, templateCommands, writeTemplateManifest, writeTemplateRegistry };
|
|
11
|
+
export { BUILTIN_TEMPLATES, GlobalCliConfig, GlobalTemplates, LoadTemplatesOptions, REGISTRY_DIR, REGISTRY_FILE, RegistryEntry, ResolvedSearchPaths, ScaffoldOptions, ScaffoldResult, SearchPathSource, TEMPLATE_MANIFEST, Template, TemplateAction, TemplateActionContext, TemplateKind, TemplateManifest, TemplateRegistry, TemplateVariable, VSCODE_REGISTRY_SEARCH_PATHS, addGlobalSource, addGlobalTemplate, addProjectRegistry, addTemplateSource, cliConfigPath, collectSources, defaultGlobalTemplatesDir, defaultProjectTemplatesRegistry, detectNpmRegistry, existingTemplateIds, expandHome, gitTemplate, globalProvidersPath, globalSourcesPath, globalToolchainDir, isRemoteRegistry, isTemplateDir, listRegistries, loadGlobalTemplates, loadLocalTemplates, loadNpmTemplates, loadTemplates, normalizeSearchPaths, parseSourceSpec, projectRegistriesPath, readGlobalCliConfig, readGlobalSources, readProjectRegistries, readTemplateDir, readTemplateManifest, readTemplateRegistry, readVscodeSearchPaths, removeGlobalTemplate, removeProjectRegistry, removeTemplateSource, resolveTemplateSearchPaths, scaffoldTemplate, setJsoncValue, templateCommands, uniqueTemplateId, vscodeSettingsPath, writeGlobalCliConfig, writeProjectRegistries, writeTemplateManifest, writeTemplateRegistry, writeVscodeSearchPaths };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import"node:path";import"node:url";import.meta.url;import{TEMPLATE_MANIFEST as
|
|
1
|
+
import"node:path";import"node:url";import.meta.url;import{BUILTIN_TEMPLATES as e}from"./builtin.js";import{TEMPLATE_MANIFEST as t,isTemplateDir as n,loadLocalTemplates as r,readTemplateDir as i,readTemplateManifest as a,writeTemplateManifest as o}from"./local.js";import{VSCODE_REGISTRY_SEARCH_PATHS as s,addGlobalSource as c,addGlobalTemplate as l,addProjectRegistry as u,cliConfigPath as d,defaultGlobalTemplatesDir as f,defaultProjectTemplatesRegistry as p,existingTemplateIds as m,expandHome as h,globalProvidersPath as g,globalSourcesPath as _,globalToolchainDir as v,isRemoteRegistry as y,listRegistries as b,loadGlobalTemplates as x,normalizeSearchPaths as S,projectRegistriesPath as C,readGlobalCliConfig as w,readGlobalSources as T,readProjectRegistries as E,readVscodeSearchPaths as D,removeGlobalTemplate as O,removeProjectRegistry as k,resolveTemplateSearchPaths as A,setJsoncValue as j,uniqueTemplateId as M,vscodeSettingsPath as N,writeGlobalCliConfig as P,writeProjectRegistries as F,writeVscodeSearchPaths as I}from"./global.js";import{detectNpmRegistry as L,gitTemplate as R,loadNpmTemplates as z,parseSourceSpec as B}from"./online.js";import{REGISTRY_DIR as V,REGISTRY_FILE as H,addTemplateSource as U,collectSources as W,loadTemplates as G,readTemplateRegistry as K,removeTemplateSource as q,writeTemplateRegistry as J}from"./registry.js";import{scaffoldTemplate as Y}from"./scaffold.js";import{templateCommands as X}from"./cli/index.js";export{e as BUILTIN_TEMPLATES,V as REGISTRY_DIR,H as REGISTRY_FILE,t as TEMPLATE_MANIFEST,s as VSCODE_REGISTRY_SEARCH_PATHS,c as addGlobalSource,l as addGlobalTemplate,u as addProjectRegistry,U as addTemplateSource,d as cliConfigPath,W as collectSources,f as defaultGlobalTemplatesDir,p as defaultProjectTemplatesRegistry,L as detectNpmRegistry,m as existingTemplateIds,h as expandHome,R as gitTemplate,g as globalProvidersPath,_ as globalSourcesPath,v as globalToolchainDir,y as isRemoteRegistry,n as isTemplateDir,b as listRegistries,x as loadGlobalTemplates,r as loadLocalTemplates,z as loadNpmTemplates,G as loadTemplates,S as normalizeSearchPaths,B as parseSourceSpec,C as projectRegistriesPath,w as readGlobalCliConfig,T as readGlobalSources,E as readProjectRegistries,i as readTemplateDir,a as readTemplateManifest,K as readTemplateRegistry,D as readVscodeSearchPaths,O as removeGlobalTemplate,k as removeProjectRegistry,q as removeTemplateSource,A as resolveTemplateSearchPaths,Y as scaffoldTemplate,j as setJsoncValue,X as templateCommands,M as uniqueTemplateId,N as vscodeSettingsPath,P as writeGlobalCliConfig,F as writeProjectRegistries,o as writeTemplateManifest,J as writeTemplateRegistry,I as writeVscodeSearchPaths};
|
|
@@ -4,14 +4,23 @@ import { ToolchainTemplateSource } from "../../shared/src/config-types.js";
|
|
|
4
4
|
import "../../shared/src/index.js";
|
|
5
5
|
import { Template } from "./types.js";
|
|
6
6
|
//#region packages/template/src/online.d.ts
|
|
7
|
-
/**
|
|
8
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Detect the project's npm registry: Yarn's `npmRegistryServer`, then `.npmrc`
|
|
9
|
+
* `registry` (npm/pnpm), then the public npm registry.
|
|
10
|
+
*/
|
|
11
|
+
export declare function detectNpmRegistry(cwd?: string): string;
|
|
12
|
+
/**
|
|
13
|
+
* List the templates an npm create package publishes. Scoped (`@scope/create`)
|
|
14
|
+
* and unscoped (`create-acme`, `acme-create`) packages are supported; the
|
|
15
|
+
* registry defaults to the project package manager's registry.
|
|
16
|
+
*/
|
|
17
|
+
export declare function loadNpmTemplates(pkg: string, registry?: string): Promise<Template[]>;
|
|
9
18
|
/** A single template backed by a git repository. */
|
|
10
19
|
export declare function gitTemplate(source: ToolchainTemplateSource): Template;
|
|
11
20
|
/**
|
|
12
21
|
* Parse a `template:add` spec: `type:locate` (eg. `local:./tpl`, `git:https://…`,
|
|
13
|
-
* `npm:@acme/create`) or an inferred source (a path that
|
|
14
|
-
*
|
|
22
|
+
* `npm:@acme/create`, `npm:create-acme`) or an inferred source (a path that
|
|
23
|
+
* exists -> local, a scoped/create-* package -> npm, a URL/scp -> git).
|
|
15
24
|
*/
|
|
16
25
|
export declare function parseSourceSpec(spec: string, cwd?: string): ToolchainTemplateSource;
|
|
17
26
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{default as e}from"node:path";import"node:url";import.meta.url;function t(e){if(!Array.isArray(e))return;let t=e.map(String).filter(Boolean);return t.length?t:void 0}function
|
|
1
|
+
import{default as e}from"node:path";import"node:url";import.meta.url;import t from"node:fs";const n=`https://registry.npmjs.org`;function r(e,n){try{let r=t.readFileSync(e,`utf-8`);return RegExp(`^\\s*${n}\\s*[:=]\\s*["']?([^"'\\s#]+)["']?`,`m`).exec(r)?.[1]?.replace(/\/+$/,``)}catch{return}}function i(t=process.cwd()){return r(e.join(t,`.yarnrc.yml`),`npmRegistryServer`)||r(e.join(t,`.npmrc`),`registry`)||n}function a(e){if(!Array.isArray(e))return;let t=e.map(String).filter(Boolean);return t.length?t:void 0}function o(e,t,r){if(!Array.isArray(t))return[];let i=[];for(let o of t){let t=typeof o==`string`?{name:o}:o&&typeof o==`object`?o:void 0;if(!t)continue;let s=String(t.name??t.template??`template`),c=String(t.label??s),l=typeof t.description==`string`?t.description:void 0,u=a(t.tags);i.push({id:`${e}/${s}`,name:c,...l?{description:l}:{},kind:`project`,source:{type:`npm`,locate:e,subdir:s,...r===n?{}:{registry:r},online:!0},online:!0,...u?{tags:u}:{}})}return i}async function s(e,t=n){let r=e.replace(/^npm:/,``),i=t.replace(/\/+$/,``);try{let e=await fetch(`${i}/${encodeURIComponent(r).replace(/^%40/,`@`)}/latest`,{headers:{accept:`application/json`}});if(!e.ok)return[];let t=await e.json();return o(r,t.createConfig?.templates??t.dbx?.templates??t.dbxTemplates,i)}catch{return[]}}function c(e){let t=e.locate.replace(/\.git$/,``).split(/[/:]/).filter(Boolean).pop()??`template`;return{id:e.id??`git:${t}`,name:e.name??t,...e.description?{description:e.description}:{},kind:e.kind??`project`,source:e,...e.tags?{tags:e.tags}:{},online:!0}}function l(t,n=process.cwd()){let r=t.match(/^(builtin|local|npm|git|vite-plus|remote):(.+)$/i);if(r?.[1]&&r[2]){let e=r[1].toLowerCase();return{type:e,locate:r[2],...e===`local`?{}:{online:!0}}}return/^(https?:|git@|git:\/\/|ssh:\/\/)/.test(t)||t.endsWith(`.git`)?{type:`git`,locate:t,online:!0}:/^@[^/]+\/[^/]+$/.test(t)||/^(?:create-[a-z0-9-]+|[a-z0-9-]+-create)$/i.test(t)?{type:`npm`,locate:t,online:!0}:{type:`local`,locate:e.resolve(n,t)}}export{i as detectNpmRegistry,c as gitTemplate,s as loadNpmTemplates,l as parseSourceSpec};
|
|
@@ -42,7 +42,8 @@ export interface LoadTemplatesOptions {
|
|
|
42
42
|
export declare function collectSources(options: LoadTemplatesOptions): ToolchainTemplateSource[];
|
|
43
43
|
/**
|
|
44
44
|
* Resolve every template: builtin, local directories (offline, always), and —
|
|
45
|
-
* when `online` — npm
|
|
45
|
+
* when `online` — npm create packages, git repositories and remote source
|
|
46
|
+
* registries.
|
|
46
47
|
*/
|
|
47
48
|
export declare function loadTemplates(options: LoadTemplatesOptions): Promise<Template[]>;
|
|
48
49
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{default as e}from"node:path";import"node:url";import.meta.url;import{sectionConfig as
|
|
1
|
+
import{default as e}from"node:path";import"node:url";import.meta.url;import{registrySourceAllowed as t}from"../../shared/src/registry-policy.js";import{sectionConfig as n,sectionEnabled as r}from"../../shared/src/toolchain.js";import"../../shared/src/index.js";import{BUILTIN_TEMPLATES as i}from"./builtin.js";import{loadLocalTemplates as a}from"./local.js";import{loadGlobalTemplates as o}from"./global.js";import{detectNpmRegistry as s,gitTemplate as c,loadNpmTemplates as l}from"./online.js";import u from"node:fs";const d=`.dbx/toolchain`,f=`templates.json`;function p(t){let n=e.join(t,d,f);try{let e=u.readFileSync(n,`utf-8`).replace(/^\uFEFF/,``),t=JSON.parse(e);return{sources:Array.isArray(t.sources)?t.sources:[]}}catch{return{sources:[]}}}function m(t,n){let r=e.join(t,d,f);u.mkdirSync(e.dirname(r),{recursive:!0}),u.writeFileSync(r,`${JSON.stringify({sources:n},null,4)}\n`,`utf-8`)}function h(e,t){let n=p(e),r=e=>`${e.type}:${e.locate}`,i=n.sources.filter(e=>r(e)!==r(t));return i.push(t),m(e,i),{sources:i}}function g(e,t){let n=p(e),r=n.sources.filter(e=>e.id!==t&&`${e.type}:${e.locate}`!==t),i=n.sources.length-r.length;return i>0&&m(e,r),{registry:{sources:r},removed:i}}function _(e){return[...e.config&&r(e.config.templates)?n(e.config.templates)?.sources??[]:[],...p(e.cwd).sources,...e.sources??[]]}function v(e){if(e&&r(e.registry))return n(e.registry)?.templates}function y(n,r,i){return i?n.type===`local`?t(e.resolve(r,n.locate),i):n.type===`npm`?t(n.registry??s(r),i):t(n.locate,i):!0}async function b(e){try{let t=await fetch(e,{headers:{accept:`application/json`}});if(!t.ok)return[];let n=await t.json(),r=Array.isArray(n)?n:n.sources??n.templates;return Array.isArray(r)?r.filter(e=>!!e&&typeof e==`object`&&typeof e.type==`string`&&typeof e.locate==`string`):[]}catch{return[]}}async function x(e){let t=/* @__PURE__ */ new Set,n=[],r=e=>{t.has(e.id)||(t.add(e.id),n.push(e))};if(e.builtin!==!1)for(let e of i)r(e);let u=v(e.config),d=await o(e.cwd,u),f=[...[..._(e),...d.sources].filter(t=>y(t,e.cwd,u))],p=/* @__PURE__ */ new Set;for(;f.length>0;){let t=f.shift();switch(t.type){case`remote`:if(e.online&&!p.has(t.locate)){p.add(t.locate);let n=await b(t.locate);f.push(...n.filter(t=>y(t,e.cwd,u)))}break;case`builtin`:{let e=i.find(e=>e.id===t.locate);e&&r(t.id?{...e,id:t.id}:e);break}case`local`:for(let e of a(t.locate,t.id))r(e);break;case`git`:r(c(t));break;case`npm`:if(e.online)for(let n of await l(t.locate,t.registry??s(e.cwd)))r(n);break;case`vite-plus`:r({id:t.id??`vite-plus`,name:t.name??`Vite+ app`,...t.description?{description:t.description}:{},kind:t.kind??`project`,source:t,...t.tags?{tags:t.tags}:{},online:!0})}}for(let e of d.templates)r(e);return n}export{d as REGISTRY_DIR,f as REGISTRY_FILE,h as addTemplateSource,_ as collectSources,x as loadTemplates,p as readTemplateRegistry,g as removeTemplateSource,m as writeTemplateRegistry};
|
|
@@ -11,10 +11,14 @@ export interface ScaffoldOptions {
|
|
|
11
11
|
tokens?: Replacements;
|
|
12
12
|
/** Per-template variable values (merged over `tokens`). */
|
|
13
13
|
variables?: Record<string, string>;
|
|
14
|
-
/** Overwrite existing files (local templates; default
|
|
14
|
+
/** Overwrite existing files (local templates; default false). */
|
|
15
15
|
overwrite?: boolean;
|
|
16
|
+
/** Overwrite existing files (builtin + local templates). */
|
|
17
|
+
force?: boolean;
|
|
16
18
|
/** Action ids to run after writing the files (default: none). */
|
|
17
19
|
actions?: string[];
|
|
20
|
+
/** The monorepo workspaces tsconfig name (workspace scaffolds). */
|
|
21
|
+
tsconfigRootFile?: string;
|
|
18
22
|
}
|
|
19
23
|
export interface ScaffoldResult {
|
|
20
24
|
/** Absolute paths written (empty when delegated to `vp`). */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{default as e}from"node:path";import{pathToFileURL as t}from"node:url";import.meta.url;import{spawnCross as n}from"../../shared/src/run.js";import{applyReplacements as r}from"../../shared/src/template.js";import"../../shared/src/index.js";import{
|
|
1
|
+
import{default as e}from"node:path";import{pathToFileURL as t}from"node:url";import.meta.url;import{spawnCross as n}from"../../shared/src/run.js";import{applyReplacements as r}from"../../shared/src/template.js";import"../../shared/src/index.js";import{hasCatalog as i}from"../../project/src/catalogs.js";import{SCAFFOLD_CATALOG as a,createMonorepoRootFiles as o,createRootProjectFiles as s,createWorkspaceFiles as c,findRootOxcFiles as l,upsertWorkspaceTsconfig as u,writeGeneratedFiles as d}from"../../project/src/typescript.js";import"../../project/src/index.js";import{runVp as f}from"../../vite/src/vp.js";import"../../vite/src/index.js";import{readTemplateManifest as p}from"./local.js";import m from"node:fs";import{spawn as h}from"node:child_process";const g=/* @__PURE__ */ new Set([`node_modules`,`.git`,`dist`,`.turbo`,`.dbx`,`.DS_Store`,`template.json`]);function _(e){return{...e.tokens,...e.variables}}function v(e,t=!0){return e==null||e===``?t:typeof e==`boolean`?e:![`no`,`false`,`0`,`off`].includes(String(e).toLowerCase())}function y(e){let t=e=>e==null||e===``?void 0:String(e),n=t(e.repo)??t(e.repoUrl);return{...t(e.description)?{description:t(e.description)}:{},...t(e.author)?{author:t(e.author)}:{},...t(e.license)?{license:t(e.license)}:{},...t(e.homepage)?{homepage:t(e.homepage)}:{},...n?{repo:n}:{},...t(e.nodeVersion)?{nodeVersion:t(e.nodeVersion)}:{}}}function b(e,t){let n=_(t),r=e=>e==null||e===``?void 0:String(e),f=String(n.name??`app`),p=n.scope?String(n.scope):void 0,m=v(n.includeConfig),h=r(n.packageManager),g=r(t.tokens?.packageManager),b=r(t.tokens?.packageManagerVersion)??r(t.tokens?.yarnVersion),x=r(t.variables?.packageManagerVersion)??(h&&h===g?b:void 0),S={...y(n),...x?{packageManagerVersion:x}:{}},{description:C,...w}=S,T=[];switch(e.builtin){case`monorepo-root`:{let e=p??`@${f}`;T.push(...o({...S,name:f,scope:e,type:`monorepo-root`,includeConfig:m,...h?{packageManager:h}:{},workspaces:[]}));break}case`monorepo-example`:{let e=p??`@${f}`;T.push(...o({...S,name:f,scope:e,type:`monorepo-root`,includeConfig:m,...h?{packageManager:h}:{},workspaces:[{alias:`core`,dir:`packages/core`}]})),T.push(...c({...w,name:f,scope:e,wsName:`core`,wsDir:`packages/core`,type:`monorepo-workspace`,includeConfig:m,useCatalog:!0,...h?{packageManager:h}:{}}).map(e=>({...e,path:`packages/core/${e.path}`})));break}case`monorepo-workspace`:{let e=`packages/${f}`;T.push(...c({...w,name:f,...p?{scope:p}:{},wsName:f,wsDir:e,type:`monorepo-workspace`,includeConfig:m,useCatalog:i(t.cwd,h,Object.keys(a)),...h?{packageManager:h}:{}}).map(t=>({...t,path:`${e}/${t.path}`})));break}case`folder`:T.push({path:`README.md`,content:`# ${f}\n`});break;default:T.push(...s({...S,name:f,...p?{scope:p}:{},type:`project`,kind:e.builtin===`application`?`application`:`project`,includeConfig:m,rootOxc:l(t.cwd),...h?{packageManager:h}:{}}))}let E=d(T,t.cwd,{force:t.force===!0});return e.builtin===`monorepo-workspace`&&u(t.cwd,{alias:f,dir:`packages/${f}`},p,t.tsconfigRootFile),{written:E}}function x(t,n){let i=t.dir;if(!i)throw Error(`Local template "${t.id}" has no directory.`);let a=p(i),o=/* @__PURE__ */ new Set([...g,...a?.ignore??[]]);for(let e of t.actions??[])e.module&&o.add(e.module.replace(/\\/g,`/`));let s=t.tokens?.open??`{{`,c=t.tokens?.close??`}}`,l=_(n),u=n.force===!0||n.overwrite===!0,d=[],f=e.resolve(n.cwd),h=t=>{let n=e.join(i,t);for(let a of m.readdirSync(n,{withFileTypes:!0})){if(o.has(a.name))continue;let n=t?`${t}/${a.name}`:a.name;if(a.isDirectory()){h(n);continue}let p=e.resolve(f,r(n,l,{open:s,close:c})),g=process.platform===`win32`?f.toLowerCase():f,_=process.platform===`win32`?p.toLowerCase():p;if(_!==g&&!_.startsWith(`${g}${e.sep}`))throw Error(`refusing to write outside ${f}: ${p}`);if(!u&&m.existsSync(p))continue;let v=m.readFileSync(e.join(i,n),`utf-8`);d.push({target:p,content:r(v,l,{open:s,close:c})})}};h(``);let v=[];for(let t of d)m.mkdirSync(e.dirname(t.target),{recursive:!0}),m.writeFileSync(t.target,t.content,`utf-8`),v.push(t.target);return{written:v}}async function S(e,t){let n=e.source.subdir?`${e.source.locate}/${e.source.subdir}`:e.source.locate,r=[`create`];n&&r.push(n);let i=t.tokens?.name;return i&&r.push(String(i)),{written:[],code:(await f(r,{cwd:t.cwd})).code}}function C(e,t,r){return new Promise(i=>{let a;try{a=n(e,t,{cwd:r,stdio:`inherit`})}catch{i(1);return}a.on(`error`,()=>i(1)),a.on(`exit`,e=>i(e??0))})}function w(e,t){return new Promise(n=>{let r=h(e,{cwd:t,stdio:`inherit`,shell:!0});r.on(`error`,()=>n(1)),r.on(`exit`,e=>n(e??0))})}function T(e,t){let n=_(t),r={};for(let[e,n]of Object.entries(t.variables??{}))r[e]=n==null?``:String(n);return{cwd:t.cwd,...e.dir?{templateDir:e.dir}:{},tokens:n,variables:r,packageManager:String(n.packageManager??`yarn`),log:e=>console.log(e)}}async function E(n,r,i,a){if(r.builtin===`install`){a.log(`Installing dependencies with ${a.packageManager}…`);let e=await C(a.packageManager,[`install`],i.cwd);if(e!==0)throw Error(`\`${a.packageManager} install\` failed with exit code ${e}.`)}else if(r.module){let o=n.dir??i.cwd,s=e.resolve(o,r.module);if(!m.existsSync(s))throw Error(`template action module not found: ${r.module}`);let c=await import(t(s).href),l=c.default??c.run;if(typeof l!=`function`)throw Error(`template action module "${r.module}" does not export a function.`);await l(a)}else if(r.command){let e=await w(r.command,i.cwd);if(e!==0)throw Error(`template command failed with exit code ${e}: ${r.command}`)}else throw Error(`template action "${r.id}" declares no builtin, module or command.`)}async function D(e,t){let n=new Set(t.actions??[]),r=[];for(let i of e.actions??[])n.has(i.id)&&(await E(e,i,t,T(e,t)),r.push(i.id));return r}async function O(e,t){if(e.builtin){let n=b(e,t),r=await D(e,t);return r.length>0?{...n,ranActions:r}:n}switch(e.source.type){case`local`:{let n=x(e,t),r=await D(e,t);return r.length>0?{...n,ranActions:r}:n}case`vite-plus`:case`npm`:case`git`:return S(e,t);default:throw Error(`Template "${e.id}" has no scaffold handler.`)}}export{O as scaffoldTemplate};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import __tsdown_shims_path from 'node:path';
|
|
2
2
|
import __tsdown_shims_url from 'node:url';
|
|
3
|
+
import { TsconfigOverrides } from "../../overrides.js";
|
|
3
4
|
import { GeneratedTsconfigResult } from "./utils.js";
|
|
4
5
|
//#region packages/tsconfig/src/cli/generate/index.d.ts
|
|
5
6
|
export interface GenerateTsconfigsOptions {
|
|
@@ -29,6 +30,8 @@ export interface GenerateTsconfigsOptions {
|
|
|
29
30
|
log?: boolean;
|
|
30
31
|
/** Write the generated files to disk (default true; false for a dry run). */
|
|
31
32
|
write?: boolean;
|
|
33
|
+
/** Managed file overrides applied before generating each workspace. */
|
|
34
|
+
overrides?: TsconfigOverrides;
|
|
32
35
|
}
|
|
33
36
|
/**
|
|
34
37
|
* Extend every workspace default tsconfig (`tsconfig.default.json`) into a
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{default as e}from"node:path";import{fileURLToPath as t,pathToFileURL as n}from"node:url";import.meta.url;import{resolveIgnorePatterns as r}from"../../../../shared/src/ignore.js";import{logger as i}from"../../../../shared/src/logger.js";import"../../../../shared/src/index.js";import{generateTsconfig as a}from"./utils.js";import o from"node:fs";import{parseArgs as s}from"node:util";import{Glob as c}from"glob";function l(t={}){let{aliases:n=!0,composite:s=!1,refs:l=!1,indent:u=4,gitignore:d=!0,defaultFile:f=`tsconfig.default.json`,buildFile:p=`tsconfig.build.json`,monorepoTsconfigFilename:m=`tsconfig.workspaces.json`,log:h=!0,write:g=!0}=t,_=t.glob??`**/${f}`,v=t.cwd??process.cwd(),y=e=>{h&&i.info(e)};n||y(`Ignoring path aliases for all tsconfigs...`),s||y(`Disabling compilerOptions.composite for all tsconfigs...`),l||y(`Ignoring project references for all tsconfigs...`);let b=e.resolve(v,m),x=e.relative(v,b),S=o.existsSync(b),C=Array.isArray(_)?_:[_],w=C.filter(e=>!e.startsWith(`!`)),T=[...C.filter(e=>e.startsWith(`!`)).map(e=>e.slice(1)),...r(v,{...t.exclude===void 0?{}:{exclude:t.exclude},gitignore:d})],E=new c(w.length?w:[`**/${f}`],{cwd:v,withFileTypes:!0,ignore:T}).walkSync();y(S?`Extending ${E.length} tsconfigs with ${x}...`:`Extending ${E.length} tsconfigs (no ${x})...`);let D=[];for(let
|
|
1
|
+
import{default as e}from"node:path";import{fileURLToPath as t,pathToFileURL as n}from"node:url";import.meta.url;import{resolveIgnorePatterns as r}from"../../../../shared/src/ignore.js";import{logger as i}from"../../../../shared/src/logger.js";import"../../../../shared/src/index.js";import{generateTsconfig as a}from"./utils.js";import o from"node:fs";import{parseArgs as s}from"node:util";import{Glob as c}from"glob";function l(t={}){let{aliases:n=!0,composite:s=!1,refs:l=!1,indent:u=4,gitignore:d=!0,defaultFile:f=`tsconfig.default.json`,buildFile:p=`tsconfig.build.json`,monorepoTsconfigFilename:m=`tsconfig.workspaces.json`,log:h=!0,write:g=!0}=t,_=t.glob??`**/${f}`,v=t.cwd??process.cwd(),y=e=>{h&&i.info(e)};n||y(`Ignoring path aliases for all tsconfigs...`),s||y(`Disabling compilerOptions.composite for all tsconfigs...`),l||y(`Ignoring project references for all tsconfigs...`);let b=e.resolve(v,m),x=e.relative(v,b),S=o.existsSync(b),C=Array.isArray(_)?_:[_],w=C.filter(e=>!e.startsWith(`!`)),T=[...C.filter(e=>e.startsWith(`!`)).map(e=>e.slice(1)),...r(v,{...t.exclude===void 0?{}:{exclude:t.exclude},gitignore:d})],E=new c(w.length?w:[`**/${f}`],{cwd:v,withFileTypes:!0,ignore:T}).walkSync();y(S?`Extending ${E.length} tsconfigs with ${x}...`:`Extending ${E.length} tsconfigs (no ${x})...`);let D=[];for(let r of E){let i=r.fullpath(),o=e.dirname(i);D.push(a({cwd:v,dirname:o,tsconfigPath:i,monorepoTsconfigPath:b,tsconfigBuildPath:e.resolve(o,p),targetTsconfigPath:e.resolve(o,`tsconfig.json`),targetTsconfigBuildPath:e.resolve(o,p),indent:u,disableComposite:!s,ignoreAliases:!n,ignoreReferences:!l,write:g,log:y,...t.overrides?{overrides:t.overrides}:{}}))}if(!l)return D;y(`Checking for additional tsconfig changes...`);let O=new Map(D.map(t=>[e.resolve(t.targetTsconfigPath),t]));for(let t of D){let{dirname:n,dirnameRelative:r,targetTsconfigPath:i,config:a}=t;y(` - ${r}`),a.references?.length&&(a.references=a.references.filter(t=>{let r=e.resolve(n,t.path),i=O.get(r),a;if(i)a=i.config.compilerOptions?.composite;else if(o.existsSync(r))a=JSON.parse(o.readFileSync(r,`utf-8`)).compilerOptions?.composite;else return y(` tsconfig not found for ${t.path}, skipping.`),!1;return a!=null&&a!==!1})),g&&o.writeFileSync(i,`${JSON.stringify(a,null,u)}\n`)}return D}function u(e=process.argv.slice(2)){let{values:t}=s({args:e,options:{aliases:{type:`boolean`,short:`a`,default:!0},composite:{type:`boolean`,short:`c`,default:!1},refs:{type:`boolean`,short:`r`,default:!1},indent:{type:`string`,short:`i`,default:`4`},glob:{type:`string`,multiple:!0},exclude:{type:`string`,multiple:!0},gitignore:{type:`boolean`,default:!0},"default-file":{type:`string`},"build-file":{type:`string`},"root-file":{type:`string`}}});l({aliases:t.aliases,composite:t.composite,refs:t.refs,indent:Number.parseInt(t.indent,10),...t.glob?{glob:t.glob}:{},...t.exclude?{exclude:t.exclude}:{},gitignore:t.gitignore,...t[`default-file`]?{defaultFile:t[`default-file`]}:{},...t[`build-file`]?{buildFile:t[`build-file`]}:{},...t[`root-file`]?{monorepoTsconfigFilename:t[`root-file`]}:{}})}if(/[\\/]generate[\\/]index\.[cm]?[jt]s$/.test(t(import.meta.url))&&import.meta.url===n(process.argv[1]??``).href)try{u()}catch(e){i.error(`Failed to generate tsconfigs due to: ${e}`),process.exit(1)}export{l as generateTsconfigs,u as runTsconfigCli};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import __tsdown_shims_path from 'node:path';
|
|
2
2
|
import __tsdown_shims_url from 'node:url';
|
|
3
|
-
import {
|
|
3
|
+
import { TsconfigOverrides } from "../../overrides.js";
|
|
4
|
+
import { TsConfigJson } from "type-fest";
|
|
4
5
|
//#region packages/tsconfig/src/cli/generate/utils.d.ts
|
|
5
6
|
export type GeneratedTsconfigResult = ReturnType<typeof generateTsconfig>;
|
|
6
7
|
export declare function generateTsconfig(options: {
|
|
@@ -17,6 +18,10 @@ export declare function generateTsconfig(options: {
|
|
|
17
18
|
disableComposite?: boolean;
|
|
18
19
|
/** Write the generated files to disk (default true). */
|
|
19
20
|
write?: boolean;
|
|
21
|
+
/** Log sink (default: the shared info logger). Pass a no-op to stay quiet. */
|
|
22
|
+
log?: (message: string) => void;
|
|
23
|
+
/** Managed file overrides applied before generating. */
|
|
24
|
+
overrides?: TsconfigOverrides;
|
|
20
25
|
}): {
|
|
21
26
|
cwd: string;
|
|
22
27
|
dirname: string;
|
|
@@ -31,6 +36,10 @@ export declare function generateTsconfig(options: {
|
|
|
31
36
|
disableComposite?: boolean;
|
|
32
37
|
/** Write the generated files to disk (default true). */
|
|
33
38
|
write?: boolean;
|
|
39
|
+
/** Log sink (default: the shared info logger). Pass a no-op to stay quiet. */
|
|
40
|
+
log?: (message: string) => void;
|
|
41
|
+
/** Managed file overrides applied before generating. */
|
|
42
|
+
overrides?: TsconfigOverrides;
|
|
34
43
|
dirnameRelative: string;
|
|
35
44
|
tsconfigFilename: string;
|
|
36
45
|
config: TsConfigJson;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{default as e}from"node:path";import"node:url";import.meta.url;import{logger as t}from"../../../../shared/src/logger.js";import"../../../../shared/src/index.js";import n from"node:fs";function
|
|
1
|
+
import{default as e}from"node:path";import"node:url";import.meta.url;import{logger as t}from"../../../../shared/src/logger.js";import"../../../../shared/src/index.js";import{mergeOverride as n}from"../../overrides.js";import{readTsconfig as r,resolveTsconfig as i}from"../../resolve.js";import a from"node:fs";function o(o){let{cwd:c,dirname:l,tsconfigPath:u,monorepoTsconfigPath:d,tsconfigBuildPath:f,targetTsconfigPath:p,targetTsconfigBuildPath:m,indent:h=4,disableComposite:g,ignoreAliases:_,ignoreReferences:v,write:y=!0,log:b=e=>t.info(e),overrides:x}=o,S=e.relative(c,l).replace(/\\/g,`/`)||`.`;try{if(!a.existsSync(u))throw Error(`Source tsconfig not found: ${u}`);if(!d)throw Error(`options.monorepoTsconfigPath not set for ${u}`);b(` - ${S}`);let t=e.basename(u),m=a.existsSync(f),C=a.existsSync(d),w=C?r(d):{},T=n(w,x?.root),E=C?i({tsconfig:d,root:c,cwd:c,...x?.root?{overrides:x.root}:{}}):{alias:[],paths:{},references:[]},D=r(u),O=n(D,x?.default),k=m?r(f):void 0,A=k?n(k,x?.build):void 0,j=g?[]:[.../* @__PURE__ */ new Set([...O.compilerOptions?.types??[],...g?[]:T.compilerOptions?.types??[]])],M={};if(!_)for(let[e,t]of Object.entries(E.paths)){let n=t.map(e=>s(e,l,S)).filter(e=>e!==void 0);n.length>0&&(M[e]=n)}let N=[];if(!v){let t=/* @__PURE__ */ new Set,n=(e,n)=>{let r=s(e,l,S);r===void 0||t.has(r)||(t.add(r),N.push({...n,path:r}))};for(let t of O.references??[])n(e.resolve(c,t.path),t);for(let e of E.references)n(e.path,e)}let P={...g?{}:T,extends:`./${t}`,compilerOptions:{...g?{composite:!1}:T.compilerOptions,...j.length?{types:j}:{},..._?{}:{paths:{...O.compilerOptions?.paths,...M}}},...v?{}:{references:N}},F=m?{...A,extends:`./${t}`}:void 0;return y&&a.writeFileSync(p,`${JSON.stringify(P,null,h)}\n`),{...o,dirnameRelative:S,tsconfigFilename:t,config:P,newTsconfig:P,newTsconfigBuild:F,originalConfig:D,tsconfigMonorepo:T,tsconfigBuild:A}}catch(e){throw Error(`Failed to extend tsconfig for ${S}: ${e instanceof Error?e.message:String(e)}`)}}function s(t,n,r){let i=e.resolve(t),a=e.resolve(n),o=e.dirname(i);if((o===a||o.startsWith(`${a}${e.sep}`))&&r!==`.`)return;let s=e.relative(a,i).replace(/\\/g,`/`);return s.startsWith(`.`)||(s=`./${s}`),s}export{o as generateTsconfig};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import"node:path";import"node:url";import.meta.url;import{
|
|
1
|
+
import"node:path";import"node:url";import.meta.url;import{warningMessage as e}from"../../../shared/src/messages.js";import{logger as t}from"../../../shared/src/logger.js";import{sectionConfig as n}from"../../../shared/src/toolchain.js";import"../../../shared/src/index.js";import{TSCONFIG_OVERRIDE_KINDS as r,hasOverrideKeys as i}from"../overrides.js";import{resolveTsconfig as a}from"../resolve.js";import{generateTsconfigs as o}from"./generate/index.js";import{restoreTsconfigOverrides as s}from"../snapshots.js";function c(){return[{name:`tsconfig`,description:`Generate workspace tsconfig.json files from the default tsconfig (aliases + references).`,options:[{flags:`--cwd <dir>`,description:`Repo root to scan (default: cwd).`},{flags:`--no-aliases`,description:`Skip path aliases.`},{flags:`--composite`,description:`Emit composite + references.`},{flags:`--refs`,description:`Wire project references.`},{flags:`-i, --indent <n>`,description:`JSON indentation.`},{flags:`--glob <glob...>`,description:`Glob(s) for the default tsconfig files.`},{flags:`--exclude <glob...>`,description:`Glob(s) to exclude (on top of the common ignored paths).`},{flags:`--no-gitignore`,description:`Do not respect .gitignore files.`},{flags:`--default-file <file>`,description:`Default tsconfig file name.`},{flags:`--build-file <file>`,description:`Build tsconfig file name.`},{flags:`--root-file <file>`,description:`Workspaces tsconfig file name.`},{flags:`--tsconfig <file>`,description:`Resolve this tsconfig instead of <root>/tsconfig.json.`},{flags:`--root <dir>`,description:`Root used to detect/resolve the tsconfig (default: cwd).`},{flags:`--json`,description:`Print the resolved { alias, paths, references } object.`},{flags:`--alias`,description:`Print only the resolved Vite/Vitest aliases.`},{flags:`--paths`,description:`Print only the resolved compilerOptions.paths.`},{flags:`--references`,description:`Print only the resolved project references.`},{flags:`--no-extends`,description:`Do not follow the tsconfig extends chain.`},{flags:`--restore [kind]`,description:`Remove the applied tsconfig overrides (all, or base|root|default|build) using the manifest snapshots.`}],run:(c,l)=>{let u=c.cwd??l.cwd,d=c.root??u,f=n(l.config.tsconfig)??{},p=c.defaultFile??f.defaultFile??`tsconfig.default.json`,m=c.buildFile??f.buildFile??`tsconfig.build.json`,h=c.rootFile??f.rootFile??`tsconfig.workspaces.json`,g=[`alias`,`paths`,`references`].filter(e=>c[e]===!0),_=c.restore;if(_!==void 0&&_!==!1){let n=typeof _==`string`?_:void 0;if(n!==void 0&&!r.includes(n))throw Error(`invalid --restore kind "${n}" (expected ${r.join(`|`)}).`);let a=s({cwd:u,...n?{kind:n}:{},warn:(e,n)=>t.warn(e,n)});t.info(a.restored.length>0?`Restored ${a.restored.length} tsconfig file(s): ${a.restored.join(`, `)}.`:`No tsconfig overrides to restore.`);let o=f.overrides??{},c=a.kinds.filter(e=>i(o[e]));c.length>0&&t.warn(e(`tsconfig.restore-reapply`,{kinds:c.join(`, `)}),`tsconfig.restore-reapply`);return}if(c.json===!0||g.length>0){let e=a({cwd:u,root:d,...c.tsconfig?{tsconfig:c.tsconfig}:{},...c.extends===!1?{extends:!1}:{}}),n=g.length===0?e:g.length===1?e[g[0]]:Object.fromEntries(g.map(t=>[t,e[t]]));t.raw(JSON.stringify(n,(e,t)=>t instanceof RegExp?String(t):t,4));return}let v=c.glob;o({cwd:l.cwd,aliases:c.aliases??f.aliases??!0,composite:c.composite??f.composite??!1,refs:c.refs??f.refs??!1,indent:c.indent===void 0?f.indent:Number.parseInt(String(c.indent),10),glob:v??f.glob??`**/${p}`,exclude:c.exclude??f.exclude,gitignore:c.gitignore??f.gitignore,defaultFile:p,buildFile:m,monorepoTsconfigFilename:h,...f.overrides?{overrides:f.overrides}:{}})}}]}export{c as tsconfigCommands};
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import __tsdown_shims_path from 'node:path';
|
|
2
2
|
import __tsdown_shims_url from 'node:url';
|
|
3
|
+
import { AppliedOverride, OverrideLeaf, OverridesState, RevertOverrideResult, TSCONFIG_OVERRIDE_KINDS, TsconfigOverrideKind, TsconfigOverrides, addedOverrideLeaves, applyOverride, getPath, hasOverrideKeys, hasPath, isAppliedOverride, mergeOverride, overrideLeaves, recordOverrideSnapshot, removedOverrideLeaves, revertOverride } from "./overrides.js";
|
|
3
4
|
import { GenerateTsconfigsOptions, generateTsconfigs, runTsconfigCli } from "./cli/generate/index.js";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
5
|
+
import { ResolveTsconfigOptions, ResolvedTsconfig, TsconfigAlias, TsconfigJson, TsconfigReference, parseTsconfig, readTsconfig, resolveTsconfig } from "./resolve.js";
|
|
6
|
+
import { RestoreTsconfigOverridesOptions, RestoreTsconfigOverridesResult, SnapshotTree, TSCONFIG_MANIFEST_PATH, deleteSnapshot, detectIndent, getSnapshot, restoreTsconfigOverrides, setSnapshot, stringifyTsconfig, toRepoRelative } from "./snapshots.js";
|
|
7
|
+
import { TsconfigFileNames, tsconfigFileNames, tsconfigSyncTask } from "./sync.js";
|
|
8
|
+
import { DEFAULT_TSCONFIG_REPLACEMENTS, MonorepoTsconfigOptions, MonorepoWorkspace, TsconfigExtends, TsconfigExtendsOptions, buildMonorepoTsconfig, renderMonorepoTsconfig, renderTsconfigBase, renderTsconfigBuild, renderTsconfigDefault, renderTsconfigTemplates, tsconfigBaseTemplate, tsconfigBuildTemplate, tsconfigDefaultTemplate } from "./templates.js";
|
|
6
9
|
declare namespace index_d_exports {
|
|
7
|
-
export { DEFAULT_TSCONFIG_REPLACEMENTS, GenerateTsconfigsOptions, MonorepoTsconfigOptions, MonorepoWorkspace, buildMonorepoTsconfig, generateTsconfigs, renderMonorepoTsconfig, renderTsconfigBase, renderTsconfigBuild, renderTsconfigDefault, renderTsconfigTemplates, runTsconfigCli, tsconfigBaseTemplate, tsconfigBuildTemplate, tsconfigDefaultTemplate, tsconfigSyncTask };
|
|
10
|
+
export { AppliedOverride, DEFAULT_TSCONFIG_REPLACEMENTS, GenerateTsconfigsOptions, MonorepoTsconfigOptions, MonorepoWorkspace, OverrideLeaf, OverridesState, ResolveTsconfigOptions, ResolvedTsconfig, RestoreTsconfigOverridesOptions, RestoreTsconfigOverridesResult, RevertOverrideResult, SnapshotTree, TSCONFIG_MANIFEST_PATH, TSCONFIG_OVERRIDE_KINDS, TsconfigAlias, TsconfigExtends, TsconfigExtendsOptions, TsconfigFileNames, TsconfigJson, TsconfigOverrideKind, TsconfigOverrides, TsconfigReference, addedOverrideLeaves, applyOverride, buildMonorepoTsconfig, deleteSnapshot, detectIndent, generateTsconfigs, getPath, getSnapshot, hasOverrideKeys, hasPath, isAppliedOverride, mergeOverride, overrideLeaves, parseTsconfig, readTsconfig, recordOverrideSnapshot, removedOverrideLeaves, renderMonorepoTsconfig, renderTsconfigBase, renderTsconfigBuild, renderTsconfigDefault, renderTsconfigTemplates, resolveTsconfig, restoreTsconfigOverrides, revertOverride, runTsconfigCli, setSnapshot, stringifyTsconfig, toRepoRelative, tsconfigBaseTemplate, tsconfigBuildTemplate, tsconfigDefaultTemplate, tsconfigFileNames, tsconfigSyncTask };
|
|
8
11
|
}
|
|
9
12
|
//#endregion
|
|
10
|
-
export { DEFAULT_TSCONFIG_REPLACEMENTS, GenerateTsconfigsOptions, MonorepoTsconfigOptions, MonorepoWorkspace, buildMonorepoTsconfig, generateTsconfigs, index_d_exports, renderMonorepoTsconfig, renderTsconfigBase, renderTsconfigBuild, renderTsconfigDefault, renderTsconfigTemplates, runTsconfigCli, tsconfigBaseTemplate, tsconfigBuildTemplate, tsconfigDefaultTemplate, tsconfigSyncTask };
|
|
13
|
+
export { AppliedOverride, DEFAULT_TSCONFIG_REPLACEMENTS, GenerateTsconfigsOptions, MonorepoTsconfigOptions, MonorepoWorkspace, OverrideLeaf, OverridesState, ResolveTsconfigOptions, ResolvedTsconfig, RestoreTsconfigOverridesOptions, RestoreTsconfigOverridesResult, RevertOverrideResult, SnapshotTree, TSCONFIG_MANIFEST_PATH, TSCONFIG_OVERRIDE_KINDS, TsconfigAlias, TsconfigExtends, TsconfigExtendsOptions, TsconfigFileNames, TsconfigJson, TsconfigOverrideKind, TsconfigOverrides, TsconfigReference, addedOverrideLeaves, applyOverride, buildMonorepoTsconfig, deleteSnapshot, detectIndent, generateTsconfigs, getPath, getSnapshot, hasOverrideKeys, hasPath, index_d_exports, isAppliedOverride, mergeOverride, overrideLeaves, parseTsconfig, readTsconfig, recordOverrideSnapshot, removedOverrideLeaves, renderMonorepoTsconfig, renderTsconfigBase, renderTsconfigBuild, renderTsconfigDefault, renderTsconfigTemplates, resolveTsconfig, restoreTsconfigOverrides, revertOverride, runTsconfigCli, setSnapshot, stringifyTsconfig, toRepoRelative, tsconfigBaseTemplate, tsconfigBuildTemplate, tsconfigDefaultTemplate, tsconfigFileNames, tsconfigSyncTask };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import"node:path";import"node:url";import.meta.url;import{__exportAll as e}from"../../../_virtual/_rolldown/runtime.js";import{
|
|
1
|
+
import"node:path";import"node:url";import.meta.url;import{__exportAll as e}from"../../../_virtual/_rolldown/runtime.js";import{TSCONFIG_OVERRIDE_KINDS as t,addedOverrideLeaves as n,applyOverride as r,getPath as i,hasOverrideKeys as a,hasPath as o,isAppliedOverride as s,mergeOverride as c,overrideLeaves as l,recordOverrideSnapshot as u,removedOverrideLeaves as d,revertOverride as f}from"./overrides.js";import{parseTsconfig as p,readTsconfig as m,resolveTsconfig as h}from"./resolve.js";import{generateTsconfigs as g,runTsconfigCli as _}from"./cli/generate/index.js";import{TSCONFIG_MANIFEST_PATH as v,deleteSnapshot as y,detectIndent as b,getSnapshot as x,restoreTsconfigOverrides as S,setSnapshot as C,stringifyTsconfig as w,toRepoRelative as T}from"./snapshots.js";import{tsconfigFileNames as E,tsconfigSyncTask as D}from"./sync.js";import{DEFAULT_TSCONFIG_REPLACEMENTS as O,buildMonorepoTsconfig as k,renderMonorepoTsconfig as A,renderTsconfigBase as j,renderTsconfigBuild as M,renderTsconfigDefault as N,renderTsconfigTemplates as P,tsconfigBaseTemplate as F,tsconfigBuildTemplate as I,tsconfigDefaultTemplate as L}from"./templates.js";var R=/* @__PURE__ */ e({DEFAULT_TSCONFIG_REPLACEMENTS:()=>O,TSCONFIG_MANIFEST_PATH:()=>v,TSCONFIG_OVERRIDE_KINDS:()=>t,addedOverrideLeaves:()=>n,applyOverride:()=>r,buildMonorepoTsconfig:()=>k,deleteSnapshot:()=>y,detectIndent:()=>b,generateTsconfigs:()=>g,getPath:()=>i,getSnapshot:()=>x,hasOverrideKeys:()=>a,hasPath:()=>o,isAppliedOverride:()=>s,mergeOverride:()=>c,overrideLeaves:()=>l,parseTsconfig:()=>p,readTsconfig:()=>m,recordOverrideSnapshot:()=>u,removedOverrideLeaves:()=>d,renderMonorepoTsconfig:()=>A,renderTsconfigBase:()=>j,renderTsconfigBuild:()=>M,renderTsconfigDefault:()=>N,renderTsconfigTemplates:()=>P,resolveTsconfig:()=>h,restoreTsconfigOverrides:()=>S,revertOverride:()=>f,runTsconfigCli:()=>_,setSnapshot:()=>C,stringifyTsconfig:()=>w,toRepoRelative:()=>T,tsconfigBaseTemplate:()=>F,tsconfigBuildTemplate:()=>I,tsconfigDefaultTemplate:()=>L,tsconfigFileNames:()=>E,tsconfigSyncTask:()=>D});export{O as DEFAULT_TSCONFIG_REPLACEMENTS,v as TSCONFIG_MANIFEST_PATH,t as TSCONFIG_OVERRIDE_KINDS,n as addedOverrideLeaves,r as applyOverride,k as buildMonorepoTsconfig,y as deleteSnapshot,b as detectIndent,g as generateTsconfigs,i as getPath,x as getSnapshot,a as hasOverrideKeys,o as hasPath,s as isAppliedOverride,c as mergeOverride,l as overrideLeaves,p as parseTsconfig,m as readTsconfig,u as recordOverrideSnapshot,d as removedOverrideLeaves,A as renderMonorepoTsconfig,j as renderTsconfigBase,M as renderTsconfigBuild,N as renderTsconfigDefault,P as renderTsconfigTemplates,h as resolveTsconfig,S as restoreTsconfigOverrides,f as revertOverride,_ as runTsconfigCli,C as setSnapshot,R as src_exports,w as stringifyTsconfig,T as toRepoRelative,F as tsconfigBaseTemplate,I as tsconfigBuildTemplate,L as tsconfigDefaultTemplate,E as tsconfigFileNames,D as tsconfigSyncTask};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import __tsdown_shims_path from 'node:path';
|
|
2
|
+
import __tsdown_shims_url from 'node:url';
|
|
3
|
+
import { ToolchainTsconfigOverrides } from "../../shared/src/config-types.js";
|
|
4
|
+
import "../../shared/src/index.js";
|
|
5
|
+
import { TsConfigJson } from "type-fest";
|
|
6
|
+
//#region packages/tsconfig/src/overrides.d.ts
|
|
7
|
+
/** The file an override targets. */
|
|
8
|
+
export type TsconfigOverrideKind = 'base' | 'root' | 'default' | 'build';
|
|
9
|
+
/** Every override kind, in the order the sync task applies them. */
|
|
10
|
+
export declare const TSCONFIG_OVERRIDE_KINDS: readonly TsconfigOverrideKind[];
|
|
11
|
+
/** The `tsconfig.overrides` config section. */
|
|
12
|
+
export type TsconfigOverrides = ToolchainTsconfigOverrides;
|
|
13
|
+
/** One applied override, as recorded in the manifest. */
|
|
14
|
+
export interface AppliedOverride {
|
|
15
|
+
kind: TsconfigOverrideKind;
|
|
16
|
+
override: TsConfigJson;
|
|
17
|
+
}
|
|
18
|
+
/** Applied overrides keyed by repo-relative file path. */
|
|
19
|
+
export type OverridesState = Record<string, AppliedOverride>;
|
|
20
|
+
/** A leaf value set by an override, addressed by its object path. */
|
|
21
|
+
export interface OverrideLeaf {
|
|
22
|
+
path: string[];
|
|
23
|
+
value: unknown;
|
|
24
|
+
}
|
|
25
|
+
/** The outcome of {@link revertOverride}. */
|
|
26
|
+
export interface RevertOverrideResult {
|
|
27
|
+
/** Dotted keys that were removed or restored to their snapshot value. */
|
|
28
|
+
reverted: string[];
|
|
29
|
+
/** Dotted keys left alone because they changed after the override applied them. */
|
|
30
|
+
kept: string[];
|
|
31
|
+
}
|
|
32
|
+
type JsonObject = Record<string, unknown>;
|
|
33
|
+
/** Whether `value` is a plain object with at least one key. */
|
|
34
|
+
export declare function hasOverrideKeys(value: unknown): value is JsonObject;
|
|
35
|
+
/** Whether `path` exists in `target` (walking plain objects only). */
|
|
36
|
+
export declare function hasPath(target: unknown, path: string[]): boolean;
|
|
37
|
+
/** The value at `path`, or `undefined`. */
|
|
38
|
+
export declare function getPath(target: unknown, path: string[]): unknown;
|
|
39
|
+
/**
|
|
40
|
+
* The leaf values an override sets. Objects are walked (they merge); arrays,
|
|
41
|
+
* scalars and empty objects are leaves (they replace).
|
|
42
|
+
*/
|
|
43
|
+
export declare function overrideLeaves(override: object | undefined, base?: string[]): OverrideLeaf[];
|
|
44
|
+
/** The leaves of `previous` that `next` no longer sets. */
|
|
45
|
+
export declare function removedOverrideLeaves(previous: object | undefined, next: object | undefined): OverrideLeaf[];
|
|
46
|
+
/** The leaves of `next` that `previous` did not set yet. */
|
|
47
|
+
export declare function addedOverrideLeaves(previous: object | undefined, next: object | undefined): OverrideLeaf[];
|
|
48
|
+
/** Deep-merge `override` into `target` in place (objects merge, the rest replaces). */
|
|
49
|
+
export declare function applyOverride(target: JsonObject, override: object): void;
|
|
50
|
+
/** Deep-merge an override into a copy of `target` (for in-memory use). */
|
|
51
|
+
export declare function mergeOverride<T extends object>(target: T, override?: object): T;
|
|
52
|
+
/**
|
|
53
|
+
* Revert override `leaves` from `target`, using `snapshot` (the original file)
|
|
54
|
+
* to decide what each key goes back to:
|
|
55
|
+
*
|
|
56
|
+
* - the key still holds the override's value and the snapshot defines it: the
|
|
57
|
+
* snapshot value is restored (the original already had the key);
|
|
58
|
+
* - the key still holds the override's value and the snapshot does not define
|
|
59
|
+
* it: the key is removed, along with any parent object the override created
|
|
60
|
+
* that is now empty;
|
|
61
|
+
* - the key holds another value: it was edited after the override applied it,
|
|
62
|
+
* so it is kept.
|
|
63
|
+
*/
|
|
64
|
+
export declare function revertOverride(target: JsonObject, leaves: OverrideLeaf[], snapshot: unknown): RevertOverrideResult;
|
|
65
|
+
/**
|
|
66
|
+
* Record the current values of newly overridden keys in `snapshot`, so a key
|
|
67
|
+
* the user added after the snapshot was taken is restored (not removed) when the
|
|
68
|
+
* override is dropped again.
|
|
69
|
+
*/
|
|
70
|
+
export declare function recordOverrideSnapshot(snapshot: JsonObject, current: unknown, leaves: OverrideLeaf[]): void;
|
|
71
|
+
/** Whether a manifest value is a well-formed {@link AppliedOverride}. */
|
|
72
|
+
export declare function isAppliedOverride(value: unknown): value is AppliedOverride;
|
|
73
|
+
//#endregion
|
|
74
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"node:path";import"node:url";import.meta.url;import{isDeepStrictEqual as e}from"node:util";const t=[`base`,`root`,`default`,`build`];function n(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function r(e){return structuredClone(e)}function i(e){return n(e)&&Object.keys(e).length>0}function a(e,t){let r=e;for(let e of t){if(!n(r)||!Object.prototype.hasOwnProperty.call(r,e))return!1;r=r[e]}return!0}function o(e,t){let r=e;for(let e of t){if(!n(r))return;r=r[e]}return r}function s(e,t,r){let i=e;for(let e of t.slice(0,-1))n(i[e])||(i[e]={}),i=i[e];i[t[t.length-1]]=r}function c(e,t){let r=o(e,t.slice(0,-1));n(r)&&delete r[t[t.length-1]]}function l(e,t=[]){let n=[];if(!e)return n;for(let[r,a]of Object.entries(e)){let e=[...t,r];i(a)?n.push(...l(a,e)):n.push({path:e,value:a})}return n}function u(e,t){return l(e).filter(e=>!a(t,e.path))}function d(e,t){return l(t).filter(t=>!a(e,t.path))}function f(e,t){for(let[i,a]of Object.entries(t))n(a)?(n(e[i])||(e[i]={}),f(e[i],a)):e[i]=r(a)}function p(e,t){if(!t)return e;let n=r(e);return f(n,t),n}function m(t,i,l){let u={reverted:[],kept:[]};for(let d of i){let i=d.path.join(`.`);if(a(t,d.path)){if(!e(o(t,d.path),d.value))u.kept.push(i);else if(u.reverted.push(i),a(l,d.path))s(t,d.path,r(o(l,d.path)));else{c(t,d.path);for(let e=d.path.length-1;e>0;e--){let r=d.path.slice(0,e),i=o(t,r);if(!n(i)||Object.keys(i).length>0||a(l,r))break;c(t,r)}}}}return u}function h(e,t,n){for(let i of n)a(t,i.path)?s(e,i.path,r(o(t,i.path))):a(e,i.path)&&c(e,i.path)}function g(e){return n(e)&&t.includes(e.kind)&&n(e.override)}export{t as TSCONFIG_OVERRIDE_KINDS,d as addedOverrideLeaves,f as applyOverride,o as getPath,i as hasOverrideKeys,a as hasPath,g as isAppliedOverride,p as mergeOverride,l as overrideLeaves,h as recordOverrideSnapshot,u as removedOverrideLeaves,m as revertOverride};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import __tsdown_shims_path from 'node:path';
|
|
2
|
+
import __tsdown_shims_url from 'node:url';
|
|
3
|
+
//#region packages/tsconfig/src/resolve.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Resolve a `tsconfig.json` into Vite/Vitest aliases plus its project paths and
|
|
6
|
+
* references.
|
|
7
|
+
*
|
|
8
|
+
* `extends` is followed per field: a child can define `paths` while inheriting
|
|
9
|
+
* `references` (or the other way around), and the nearest definition wins.
|
|
10
|
+
*/
|
|
11
|
+
/** A Vite/Vitest compatible alias entry. */
|
|
12
|
+
export interface TsconfigAlias {
|
|
13
|
+
find: string | RegExp;
|
|
14
|
+
replacement: string;
|
|
15
|
+
}
|
|
16
|
+
/** A resolved project reference. */
|
|
17
|
+
export interface TsconfigReference {
|
|
18
|
+
/** Absolute path to the referenced tsconfig file. */
|
|
19
|
+
path: string;
|
|
20
|
+
[key: string]: unknown;
|
|
21
|
+
}
|
|
22
|
+
/** The result of {@link resolveTsconfig}. */
|
|
23
|
+
export interface ResolvedTsconfig {
|
|
24
|
+
/** Vite/Vitest `resolve.alias` entries (absolute replacements). */
|
|
25
|
+
alias: TsconfigAlias[];
|
|
26
|
+
/** Resolved `compilerOptions.paths` (absolute targets). */
|
|
27
|
+
paths: Record<string, string[]>;
|
|
28
|
+
/** Resolved project references (absolute paths). */
|
|
29
|
+
references: TsconfigReference[];
|
|
30
|
+
}
|
|
31
|
+
export interface ResolveTsconfigOptions {
|
|
32
|
+
/** Explicit tsconfig file (relative to `cwd`/`root`, or absolute). */
|
|
33
|
+
tsconfig?: string;
|
|
34
|
+
/** Directory used to resolve a relative `tsconfig` and to detect the config. */
|
|
35
|
+
cwd?: string;
|
|
36
|
+
/** Repo/workspace root (default: `cwd`). Used to detect the default config. */
|
|
37
|
+
root?: string;
|
|
38
|
+
/** Follow `extends` (default true). */
|
|
39
|
+
extends?: boolean;
|
|
40
|
+
/** Deep-merged into the selected config before reading its fields. */
|
|
41
|
+
overrides?: object;
|
|
42
|
+
}
|
|
43
|
+
export interface TsconfigJson {
|
|
44
|
+
extends?: string | string[];
|
|
45
|
+
compilerOptions?: {
|
|
46
|
+
baseUrl?: string;
|
|
47
|
+
paths?: Record<string, string[] | string>;
|
|
48
|
+
};
|
|
49
|
+
references?: {
|
|
50
|
+
path: string;
|
|
51
|
+
[key: string]: unknown;
|
|
52
|
+
}[];
|
|
53
|
+
}
|
|
54
|
+
/** Read a tsconfig file (JSONC: comments + trailing commas are allowed). */
|
|
55
|
+
export declare function readTsconfig(file: string): TsconfigJson;
|
|
56
|
+
/** Parse JSONC tsconfig text (comments, trailing commas and a BOM are allowed). */
|
|
57
|
+
export declare function parseTsconfig(text: string): TsconfigJson;
|
|
58
|
+
/**
|
|
59
|
+
* Resolve a tsconfig's `paths` and `references`, following `extends` per field.
|
|
60
|
+
*/
|
|
61
|
+
export declare function resolveTsconfig(options?: ResolveTsconfigOptions): ResolvedTsconfig;
|
|
62
|
+
//#endregion
|