@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
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import __tsdown_shims_path from 'node:path';
|
|
2
2
|
import __tsdown_shims_url from 'node:url';
|
|
3
|
+
import { ProjectType } from "../../shared/src/config-types.js";
|
|
4
|
+
import { SyncTask, ToolchainConfig } from "../../shared/src/toolchain.js";
|
|
5
|
+
import "../../shared/src/index.js";
|
|
3
6
|
import { RunSyncOptions } from "./sync.js";
|
|
4
7
|
//#region packages/core/src/watch.d.ts
|
|
5
8
|
export interface RunWatchOptions extends Omit<RunSyncOptions, 'check'> {
|
|
@@ -12,6 +15,12 @@ export interface RunWatchOptions extends Omit<RunSyncOptions, 'check'> {
|
|
|
12
15
|
/** Respect `.gitignore` files (default true). */
|
|
13
16
|
gitignore?: boolean;
|
|
14
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* The repo-relative input globs of the tasks that run for `config` (and
|
|
20
|
+
* `projectType`, when given): each task's `watch` globs, with function forms
|
|
21
|
+
* resolved against the config (eg. custom tsconfig file names).
|
|
22
|
+
*/
|
|
23
|
+
export declare function resolveWatchGlobs(tasks: SyncTask[], config: ToolchainConfig, projectType?: ProjectType): string[];
|
|
15
24
|
/**
|
|
16
25
|
* Run one sync, then watch the config file + every task's `watch` globs and
|
|
17
26
|
* re-run on change. Writing generated files must not re-trigger a run, so a
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{default as e}from"node:path";import"node:url";import.meta.url;import{isIgnoredPath as t,resolveIgnorePatterns as n}from"../../shared/src/ignore.js";import{logger as r}from"../../shared/src/logger.js";import"../../shared/src/index.js";import{runSync as
|
|
1
|
+
import{default as e}from"node:path";import"node:url";import.meta.url;import{isIgnoredPath as t,resolveIgnorePatterns as n}from"../../shared/src/ignore.js";import{logger as r}from"../../shared/src/logger.js";import{sectionConfig as i}from"../../shared/src/toolchain.js";import"../../shared/src/index.js";import{resolveProjectType as a}from"./project-type.js";import{findConfigFile as o,loadToolchainConfig as s}from"./loader.js";import{runSync as c}from"./sync.js";import l from"node:fs";import{Glob as u}from"glob";function d(e,t,n){let r=/* @__PURE__ */ new Set;for(let i of e){if(n&&i.projectTypes&&!i.projectTypes.includes(n)||i.enabled&&!i.enabled(t))continue;let e=typeof i.watch==`function`?i.watch(t):i.watch??[];for(let t of e)r.add(t)}return[...r]}async function f(f){let{cwd:p,tasks:m}=f,h=f.configPath?e.resolve(p,f.configPath):void 0,g=f.quiet?()=>{}:f.log??(e=>r.info(e)),_={...f},v=[],y=[],b=0,x,S=!1,C=!1,w=!1,T=!1,E=()=>i(_.config.watch)?.debounce??f.debounce??150,D=()=>{for(let e of y)e.close();y=[]},O=async()=>{let e=f.configPath?o(p):void 0,t=h&&l.existsSync(h)?h:e;if(!t)return!1;h=t;try{let e=await s(p,{config:t,fresh:!0});return _={..._,config:e.config,ownConfig:e.ownConfig,tokens:e.tokens,projectType:e.projectType},!0}catch(e){return r.error(`failed to reload ${h}: ${e instanceof Error?e.message:String(e)}`),!1}},k=async()=>{if(S)C=!0;else{S=!0;try{w&&(w=!1,await O()&&(T=!0)),await c(_)}finally{S=!1,b=Date.now()+Math.max(E()*3,300),T&&(T=!1,M()),C&&(C=!1,A())}}},A=()=>{clearTimeout(x),x=setTimeout(k,E())},j=n=>{if(!(Date.now()<b)){if(n){let r=e.relative(p,n).replace(/\\/g,`/`);if(t(r,v))return;e.basename(n).startsWith(`dbx.config.`)&&(w=!0)}_.config?.hooks?.onChange?.(n?{path:n}:{}),A()}};function M(){D();let r=i(_.config.watch);v=n(p,{...(r?.exclude??f.exclude)===void 0?{}:{exclude:r?.exclude??f.exclude},...(r?.gitignore??f.gitignore)===void 0?{}:{gitignore:r?.gitignore??f.gitignore}});let o=/* @__PURE__ */ new Set([p]),s=_.projectType??a(p,_.config);for(let n of d(m,_.config,s))try{let r=new u(n,{cwd:p,dot:!0,ignore:v}).walkSync();for(let n of r){let r=e.resolve(p,n),i=e.relative(p,r).replace(/\\/g,`/`);t(i,v)||o.add(e.dirname(r))}}catch{}if(h)try{y.push(l.watch(h,()=>{g(`config changed; re-syncing`),w=!0,j(h)}))}catch{}for(let t of o){let n=n=>j(e.join(t,n??``));try{y.push(l.watch(t,{recursive:!0},(e,t)=>n(t)))}catch{try{y.push(l.watch(t,(e,t)=>n(t)))}catch{}}}}await k(),M(),g(`watching for changes (Ctrl+C to stop)`),await new Promise(e=>{let t=()=>{x&&clearTimeout(x),x=void 0,D(),process.off(`SIGINT`,t),process.off(`SIGTERM`,t),e()};process.on(`SIGINT`,t),process.on(`SIGTERM`,t)})}export{d as resolveWatchGlobs,f as runWatch};
|
|
@@ -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{loadToolchainConfig as n}from"../../../core/src/loader.js";import{selectProjects as r}from"../../../core/src/select.js";import{runSync as i}from"../../../core/src/sync.js";import"../../../core/src/index.js";import{diffFiles as a,hasPending as o}from"../check.js";import{listMigrations as s,migrations as c}from"../registry.js";import{cancel as l,isCancel as u,multiselect as d}from"@clack/prompts";function f(e){return!!(process.stdin.isTTY&&process.stdout.isTTY)&&e.json!==!0}function p(){l(`Cancelled.`),process.exitCode=1}function m(){return[{name:`migrate`,description:`Migrate Biome / ESLint / Prettier / Dprint
|
|
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{loadToolchainConfig as n}from"../../../core/src/loader.js";import{selectProjects as r}from"../../../core/src/select.js";import{runSync as i}from"../../../core/src/sync.js";import"../../../core/src/index.js";import{diffFiles as a,hasPending as o}from"../check.js";import{listMigrations as s,migrations as c}from"../registry.js";import{cancel as l,isCancel as u,multiselect as d}from"@clack/prompts";function f(e){return!!(process.stdin.isTTY&&process.stdout.isTTY)&&e.json!==!0}function p(){l(`Cancelled.`),process.exitCode=1}function m(){return[{name:`migrate`,description:`Migrate Biome / ESLint / Prettier / Dprint / Oxc config, or fold vite.config.* into dbx.config.`,options:[{flags:`--from <tool>`,description:`Source tool (repeatable): biome | eslint | prettier | dprint | oxc | vite | all.`,multiple:!0},{flags:`--to <tool>`,description:`Target tool (default: oxc).`,default:`oxc`},{flags:`--cwd <dir>`,description:`Project root (default: cwd).`},{flags:`--recursive`,description:`Also migrate the discovered projects under the root (default: root only).`},{flags:`--write`,description:`Write the files (default: dry-run).`},{flags:`--dry-run`,description:`Do not write anything (default).`},{flags:`--check`,description:`CI: exit non-zero when the oxc config is stale.`},{flags:`--target <target>`,description:`files (default) | vite.`},{flags:`--online`,description:`Allow network (e.g. @oxlint/migrate).`},{flags:`--ignore-vite-config-file`,description:"Do not remove the folded `vite.config.*`."},{flags:`--ignore-managed-files`,description:`Skip the post-migration sync (leave the toolchain-managed files as-is).`},{flags:`--ignore-changelog`,description:`Skip the changelog task in the post-migration sync.`},{flags:`--json`,description:`Print the result as JSON.`}],run:async(s,l)=>{let m=s.cwd??l.cwd,h=!!s.check,g=!!s.write&&!s.dryRun&&!h,_=!!s.online,v=s.from,y=Array.isArray(v)?v:v?[v]:[],b=y.includes(`all`),x=y.filter(e=>e!==`all`),S=e=>y.length===0||b||x.includes(e.from),C=s.target??`files`,w=!!s.recursive,T=e=>c().filter(t=>S(t)&&t.detect(e)),E=[m];if(w){let n=r({root:m}).filter(e=>T(e.dir).length>0);if(n.length===0){t.info(`nothing to migrate under ${m}.`);return}let i=n;if(f(s)){let t=await d({message:`Which projects should I migrate?`,required:!0,options:[{value:`__all__`,label:`All projects`},...n.map(t=>({value:t.dir,label:t.rel===`.`?e.basename(m):t.rel,...t.name?{hint:t.name}:{}}))]});if(u(t)){p();return}let r=t;i=r.includes(`__all__`)?n:n.filter(e=>r.includes(e.dir))}E=i.map(e=>e.dir)}let D=[];for(let e of E)for(let t of T(e))D.push({dir:e,result:await t.run({cwd:e,write:g,online:_,target:C,ignoreViteConfigFile:!!s.ignoreViteConfigFile,ignoreManagedFiles:!!s.ignoreManagedFiles,ignoreChangelog:!!s.ignoreChangelog})});if(D.length===0){let e=c().some(e=>S(e));t.info(x.length>0&&!b&&!e?`no migration registered for: ${x.join(`, `)}.`:`nothing to migrate (no Biome/ESLint/Prettier/Dprint/Oxc/vite config detected).`);return}let O=t=>w?`${e.relative(m,t)||`.`}: `:``,k=[...new Set(D.filter(({result:e})=>e.written.length>0||(e.removed?.length??0)>0).map(({dir:e})=>e))];if(h){let n=D.flatMap(({result:e})=>a(e.files??[])),r=n.filter(e=>e.status!==`same`);if(s.json)t.raw(JSON.stringify(D.map(e=>e.result),null,4));else if(r.length){for(let n of r)t.info(`${n.status} ${e.relative(m,n.path)||n.path}`);t.info(`${r.length} file(s) out of date — run \`migrate --write\` to apply.`)}else t.info(`up to date.`);o(n)&&(process.exitCode=1);return}let A=async()=>{if(!g||k.length===0||s.ignoreManagedFiles||!l.syncTasks?.length)return;let e=s.ignoreChangelog?l.syncTasks.filter(e=>e.name!==`changelog`):l.syncTasks;for(let r of k){let a=await n(r);s.json||t.info(`${O(r)}regenerating managed files.`),await i({tasks:e,cwd:r,projectType:a.projectType,config:a.config,ownConfig:a.ownConfig,tokens:a.tokens,quiet:s.json===!0})}};if(s.json)await A(),t.raw(JSON.stringify(D.map(e=>e.result),null,4));else{for(let{dir:e,result:n}of D){t.info(`${O(e)}${n.from} -> ${n.to} ${g?`wrote`:`would write`}`);for(let e of n.written)t.info(` ${g?`+`:`?`} ${e}`);for(let e of n.removed??[])t.info(` ${g?`-`:`?`} ${e}`);for(let e of n.notes??[])t.info(` ${e}`);if(n.unmapped?.length){t.info(` unmapped (${n.unmapped.length}):`);for(let e of n.unmapped.slice(0,25))t.info(` - ${e.source}: ${e.reason}`)}}!g&&k.length>0&&!s.ignoreManagedFiles&&t.info(`managed files are regenerated after --write; pass --ignore-managed-files to skip.`),await A(),g||t.info(`dry-run — re-run with --write to apply.`)}}},{name:`migrate:list`,description:`List the registered migrations and whether each is detected.`,options:[{flags:`--cwd <dir>`,description:`Project root (default: cwd).`},{flags:`--json`,description:`Print as JSON.`}],run:(e,n)=>{let r=e.cwd??n.cwd,i=s(r);if(e.json)t.raw(JSON.stringify(i,null,4));else for(let e of i)t.info(` ${e.id.padEnd(16)} ${e.from} -> ${e.to} [${e.detected?`detected`:`not found`}]`),t.info(` ${e.description}`)}}]}export{m as migrateCommands};
|
|
@@ -6,10 +6,11 @@ import { FileDiff, FileStatus, diffFiles, hasPending } from "./check.js";
|
|
|
6
6
|
import { migrateCommands } from "./cli/index.js";
|
|
7
7
|
import { dprintToOx, findDprintConfig, mapDprintToOxfmt } from "./dprint.js";
|
|
8
8
|
import { eslintToOx, findEslintConfig, mapRuleName, runOxlintMigrate } from "./eslint.js";
|
|
9
|
+
import { OXC_FMT_FILE, OXC_LINT_FILE, findOxcConfigs, oxcToToolchain } from "./oxc.js";
|
|
9
10
|
import { DEFAULT_IGNORE, OxfmtMapping, mapBiomeFormatter, mapBiomeIncludes, mapBiomeToOxfmt, mapOrganizeImports } from "./oxfmt-map.js";
|
|
10
11
|
import { OxlintMapping, RULE_MAP, mapBiomeToOxlint } from "./oxlint-map.js";
|
|
11
12
|
import { findPrettierConfig, mapPrettierToOxfmt, prettierToOx, readPrettierIgnore } from "./prettier.js";
|
|
12
13
|
import { MigrationInfo, detectMigrations, findMigration, listMigrations, migrations, runDetectedMigrations, runMigration } from "./registry.js";
|
|
13
|
-
import { VITE_CONFIG_FILES, ensureViteFmtIgnore, extractViteObject, findDbxConfig, findViteConfig, foldViteIntoConfig, scanLiteralObject, viteToToolchain } from "./vite.js";
|
|
14
|
+
import { VITE_CONFIG_FILES, ensureViteFmtIgnore, extractViteObject, findDbxConfig, findViteConfig, foldToolchainSection, foldViteIntoConfig, mergeViteObjects, renderFreshSectionsConfig, scanLiteralObject, viteToToolchain } from "./vite.js";
|
|
14
15
|
import { findTopLevelValue, matchBracket, mergeViteConfig, renderViteTarget, serializeTs, writeViteTarget } from "./vite-target.js";
|
|
15
|
-
export { BIOME_CONFIG_FILES, DEFAULT_IGNORE, FileDiff, FileStatus, MigrateTarget, MigrateTool, MigrationContext, MigrationFile, MigrationInfo, MigrationResult, OxfmtMapping, OxlintMapping, RULE_MAP, ToolchainMigration, UnmappedItem, VITE_CONFIG_FILES, biomeToOx, detectMigrations, diffFiles, dprintToOx, ensureViteFmtIgnore, eslintToOx, extractViteObject, findBiomeConfig, findDbxConfig, findDprintConfig, findEslintConfig, findMigration, findPrettierConfig, findTopLevelValue, findViteConfig, foldViteIntoConfig, hasPending, listMigrations, mapBiomeFormatter, mapBiomeIncludes, mapBiomeToOxfmt, mapBiomeToOxlint, mapDprintToOxfmt, mapOrganizeImports, mapPrettierToOxfmt, mapRuleName, matchBracket, mergeViteConfig, migrateCommands, migrations, prettierToOx, readJsonc, readPrettierIgnore, renderViteTarget, runDetectedMigrations, runMigration, runOxlintMigrate, scanLiteralObject, serializeTs, stripJsonc, viteToToolchain, writeViteTarget };
|
|
16
|
+
export { BIOME_CONFIG_FILES, DEFAULT_IGNORE, FileDiff, FileStatus, MigrateTarget, MigrateTool, MigrationContext, MigrationFile, MigrationInfo, MigrationResult, OXC_FMT_FILE, OXC_LINT_FILE, OxfmtMapping, OxlintMapping, RULE_MAP, ToolchainMigration, UnmappedItem, VITE_CONFIG_FILES, biomeToOx, detectMigrations, diffFiles, dprintToOx, ensureViteFmtIgnore, eslintToOx, extractViteObject, findBiomeConfig, findDbxConfig, findDprintConfig, findEslintConfig, findMigration, findOxcConfigs, findPrettierConfig, findTopLevelValue, findViteConfig, foldToolchainSection, foldViteIntoConfig, hasPending, listMigrations, mapBiomeFormatter, mapBiomeIncludes, mapBiomeToOxfmt, mapBiomeToOxlint, mapDprintToOxfmt, mapOrganizeImports, mapPrettierToOxfmt, mapRuleName, matchBracket, mergeViteConfig, mergeViteObjects, migrateCommands, migrations, oxcToToolchain, prettierToOx, readJsonc, readPrettierIgnore, renderFreshSectionsConfig, renderViteTarget, runDetectedMigrations, runMigration, runOxlintMigrate, scanLiteralObject, serializeTs, stripJsonc, viteToToolchain, writeViteTarget };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import"node:path";import"node:url";import.meta.url;import{
|
|
1
|
+
import"node:path";import"node:url";import.meta.url;import{DEFAULT_IGNORE as e,mapBiomeFormatter as t,mapBiomeIncludes as n,mapBiomeToOxfmt as r,mapOrganizeImports as i}from"./oxfmt-map.js";import{RULE_MAP as a,mapBiomeToOxlint as o}from"./oxlint-map.js";import{findTopLevelValue as s,matchBracket as c,mergeViteConfig as l,renderViteTarget as u,serializeTs as d,writeViteTarget as f}from"./vite-target.js";import{BIOME_CONFIG_FILES as p,biomeToOx as m,findBiomeConfig as h,readJsonc as g,stripJsonc as _}from"./biome.js";import{diffFiles as v,hasPending as y}from"./check.js";import{dprintToOx as b,findDprintConfig as x,mapDprintToOxfmt as S}from"./dprint.js";import{eslintToOx as C,findEslintConfig as w,mapRuleName as T,runOxlintMigrate as E}from"./eslint.js";import{VITE_CONFIG_FILES as D,ensureViteFmtIgnore as O,extractViteObject as k,findDbxConfig as A,findViteConfig as j,foldToolchainSection as M,foldViteIntoConfig as N,mergeViteObjects as P,renderFreshSectionsConfig as F,scanLiteralObject as I,viteToToolchain as L}from"./vite.js";import{OXC_FMT_FILE as R,OXC_LINT_FILE as z,findOxcConfigs as B,oxcToToolchain as V}from"./oxc.js";import{findPrettierConfig as H,mapPrettierToOxfmt as U,prettierToOx as W,readPrettierIgnore as G}from"./prettier.js";import{detectMigrations as K,findMigration as q,listMigrations as J,migrations as Y,runDetectedMigrations as X,runMigration as Z}from"./registry.js";import{migrateCommands as Q}from"./cli/index.js";export{p as BIOME_CONFIG_FILES,e as DEFAULT_IGNORE,R as OXC_FMT_FILE,z as OXC_LINT_FILE,a as RULE_MAP,D as VITE_CONFIG_FILES,m as biomeToOx,K as detectMigrations,v as diffFiles,b as dprintToOx,O as ensureViteFmtIgnore,C as eslintToOx,k as extractViteObject,h as findBiomeConfig,A as findDbxConfig,x as findDprintConfig,w as findEslintConfig,q as findMigration,B as findOxcConfigs,H as findPrettierConfig,s as findTopLevelValue,j as findViteConfig,M as foldToolchainSection,N as foldViteIntoConfig,y as hasPending,J as listMigrations,t as mapBiomeFormatter,n as mapBiomeIncludes,r as mapBiomeToOxfmt,o as mapBiomeToOxlint,S as mapDprintToOxfmt,i as mapOrganizeImports,U as mapPrettierToOxfmt,T as mapRuleName,c as matchBracket,l as mergeViteConfig,P as mergeViteObjects,Q as migrateCommands,Y as migrations,V as oxcToToolchain,W as prettierToOx,g as readJsonc,G as readPrettierIgnore,F as renderFreshSectionsConfig,u as renderViteTarget,X as runDetectedMigrations,Z as runMigration,E as runOxlintMigrate,I as scanLiteralObject,d as serializeTs,_ as stripJsonc,L as viteToToolchain,f as writeViteTarget};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import __tsdown_shims_path from 'node:path';
|
|
2
|
+
import __tsdown_shims_url from 'node:url';
|
|
3
|
+
import { ToolchainMigration } from "./types.js";
|
|
4
|
+
//#region packages/migrate/src/oxc.d.ts
|
|
5
|
+
export declare const OXC_FMT_FILE = ".oxfmtrc.json";
|
|
6
|
+
export declare const OXC_LINT_FILE = ".oxlintrc.json";
|
|
7
|
+
/** A source Oxc config in `cwd`, when it is not managed by dbx itself. */
|
|
8
|
+
export declare function findOxcConfigs(cwd: string): {
|
|
9
|
+
fmt?: string;
|
|
10
|
+
lint?: string;
|
|
11
|
+
};
|
|
12
|
+
export declare const oxcToToolchain: ToolchainMigration;
|
|
13
|
+
//#endregion
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{default as e}from"node:path";import"node:url";import.meta.url;import{readManifest as t}from"../../core/src/manifest.js";import"../../core/src/index.js";import{serializeTs as n}from"./vite-target.js";import{readJsonc as r}from"./biome.js";import{foldToolchainSection as i,renderFreshSectionsConfig as a}from"./vite.js";import o from"node:fs";const s=`.oxfmtrc.json`,c=`.oxlintrc.json`;function l(e,n){try{return t(e).files.includes(n)}catch{return!1}}function u(t){let n=e.join(t,s),r=e.join(t,c);return{...o.existsSync(n)&&!l(t,`.oxfmtrc.json`)?{fmt:n}:{},...o.existsSync(r)&&!l(t,`.oxlintrc.json`)?{lint:r}:{}}}function d(e){let{$schema:t,...n}=e;return n}function f(t){for(let n of[`dbx.config.ts`,`dbx.config.mts`,`dbx.config.js`,`dbx.config.mjs`,`dbx.config.cjs`,`dbx.config.json`]){let r=e.join(t,n);if(o.existsSync(r))return r}}const p={id:`oxc-to-toolchain`,from:`oxc`,to:`toolchain`,description:`Fold .oxfmtrc.json / .oxlintrc.json into toolchain.fmt/lint.oxc.`,detect:e=>!!(u(e).fmt||u(e).lint),run:async t=>{let s=u(t.cwd);if(!s.fmt&&!s.lint)throw Error(`oxc-to-toolchain: no Oxc config found.`);let c=s.fmt?d(r(s.fmt)):void 0,l=s.lint?d(r(s.lint)):void 0,m=[...s.fmt?[`Source: ${e.basename(s.fmt)} (Oxfmt).`]:[],...s.lint?[`Source: ${e.basename(s.lint)} (Oxlint).`]:[]],h=[...c?[{key:`fmt`,objectText:n({oxc:c})}]:[],...l?[{key:`lint`,objectText:n({oxc:l})}]:[]],g=f(t.cwd),_,v;if(!g)_=e.join(t.cwd,`dbx.config.ts`),v=a(h);else if(g.endsWith(`.json`))return{id:p.id,from:`oxc`,to:`toolchain`,written:[],files:[],oxfmt:c,oxlint:l,unmapped:[{source:e.basename(g),reason:`JSON configs cannot hold the folded object by text-splice`}],notes:[...m,`Fold into the JSON config by hand.`]};else{let t=o.readFileSync(g,`utf-8`).replace(/^\uFEFF/,``);for(let n of h){let r=i(t,n.key,n.objectText);if(`error`in r)return{id:p.id,from:`oxc`,to:`toolchain`,written:[],files:[],oxfmt:c,oxlint:l,unmapped:[{source:e.basename(g),reason:r.error}],notes:[...m,`Left dbx.config.* unchanged; fold it by hand.`]};t=r.content}_=g,v=t}let y={path:_,content:v};t.write&&o.writeFileSync(_,v,`utf-8`);let b=[s.fmt,s.lint].filter(e=>!!e),x=t.ignoreManagedFiles?[]:b;if(t.ignoreManagedFiles)m.push(`Kept the source Oxc files (ignoreManagedFiles).`);else{if(t.write)for(let e of x)o.rmSync(e,{force:!0});x.length>0&&m.push(`${t.write?`Removed`:`Would remove`} the source Oxc files; \`dbx sync\` regenerates them.`)}return{id:p.id,from:`oxc`,to:`toolchain`,written:[_],removed:x,files:[y],oxfmt:c,oxlint:l,notes:[...m,"Folded into `toolchain.fmt.oxc` / `toolchain.lint.oxc`."]}}};export{s as OXC_FMT_FILE,c as OXC_LINT_FILE,u as findOxcConfigs,p as oxcToToolchain};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import"node:path";import"node:url";import.meta.url;import{biomeToOx as e}from"./biome.js";import{dprintToOx as t}from"./dprint.js";import{eslintToOx as n}from"./eslint.js";import{
|
|
1
|
+
import"node:path";import"node:url";import.meta.url;import{biomeToOx as e}from"./biome.js";import{dprintToOx as t}from"./dprint.js";import{eslintToOx as n}from"./eslint.js";import{viteToToolchain as r}from"./vite.js";import{oxcToToolchain as i}from"./oxc.js";import{prettierToOx as a}from"./prettier.js";function o(){return[e,a,t,n,i,r]}function s(e){return o().map(t=>({id:t.id,from:t.from,to:t.to,description:t.description,detected:t.detect(e)}))}function c(e){return o().filter(t=>t.detect(e))}function l(e){return o().find(t=>t.id===e||t.from===e)}async function u(e,t){let n=l(e);if(!n)throw Error(`Unknown migration "${e}".`);return n.run(t)}async function d(e){let t=[];for(let n of c(e.cwd))t.push(await n.run(e));return t}export{c as detectMigrations,l as findMigration,s as listMigrations,o as migrations,d as runDetectedMigrations,u as runMigration};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import{default as e}from"node:path";import"node:url";import.meta.url;import t from"node:fs";const n=/^[A-Za-z_$][\w$]*$/;function r(e,t=0){let i=` `.repeat(t),a=` `.repeat(t+1);if(e==null)return`null`;if(typeof e==`string`)return`'${e.replace(/\\/g,`\\\\`).replace(/'/g,`\\'`)}'`;if(typeof e==`number`||typeof e==`boolean`)return String(e);if(Array.isArray(e))return e.length===0?`[]`:`[\n${e.map(e=>`${a}${r(e,t+1)}`).join(`,
|
|
2
2
|
`)},\n${i}]`;if(typeof e==`object`){let o=Object.entries(e);return o.length===0?`{}`:`{\n${o.map(([e,i])=>{let o=n.test(e)?e:JSON.stringify(e);return`${a}${o}: ${r(i,t+1)}`}).join(`,
|
|
3
3
|
`)},\n${i}}`}return JSON.stringify(e)}function i(e,t){let n=e[t],r=e[t+1];if(n===`/`&&r===`/`){for(;t<e.length&&e[t]!==`
|
|
4
|
-
`;)t++;return t}if(n===`/`&&r===`*`){for(t+=2;t<e.length&&(e[t]!==`*`||e[t+1]!==`/`);)t++;return t+2}if(n===`"`||n===`'`||n==="`"){let r=n;for(t++;t<e.length&&e[t]!==r;)e[t]===`\\`&&t++,t++;return t+1}return t}function a(e,t){let n={"{":`}`,"[":`]`}[e[t]];if(!n)return-1;let r=0;for(let a=t;a<e.length;a++){let o=i(e,a);if(o!==a)a=o-1;else if(e[a]===e[t])r++;else if(e[a]===n&&(r--,r===0))return a+1}return-1}function o(e,t,r,o){let s=1;for(let c=t+1;c<r;c++){let t=i(e,c);if(t!==c){c=t-1;continue}let l=e[c];if(l===`{`||l===`[`)s++;else if(l===`}`||l===`]`)s--;else if(s===1&&n.test(l)){let t=c;for(;t<r&&/[\w$]/.test(e[t]);)t++;let n=e.slice(c,t),i=t;for(;i<r&&/\s/.test(e[i]);)i++;if(n===o&&e[i]===`:`){let t=i+1;for(;t<r&&/\s/.test(e[t]);)t++;let n=e[t];if(n===`{`||n===`[`)return[t,a(e,t)];let o=t;for(;o<r&&e[o]
|
|
4
|
+
`;)t++;return t}if(n===`/`&&r===`*`){for(t+=2;t<e.length&&(e[t]!==`*`||e[t+1]!==`/`);)t++;return t+2}if(n===`"`||n===`'`||n==="`"){let r=n;for(t++;t<e.length&&e[t]!==r;)e[t]===`\\`&&t++,t++;return t+1}return t}function a(e,t){let n={"{":`}`,"[":`]`}[e[t]];if(!n)return-1;let r=0;for(let a=t;a<e.length;a++){let o=i(e,a);if(o!==a)a=o-1;else if(e[a]===e[t])r++;else if(e[a]===n&&(r--,r===0))return a+1}return-1}function o(e,t,r,o){let s=1;for(let c=t+1;c<r;c++){let t=i(e,c);if(t!==c){c=t-1;continue}let l=e[c];if(l===`{`||l===`[`)s++;else if(l===`}`||l===`]`)s--;else if(s===1&&n.test(l)){let t=c;for(;t<r&&/[\w$]/.test(e[t]);)t++;let n=e.slice(c,t),i=t;for(;i<r&&/\s/.test(e[i]);)i++;if(n===o&&e[i]===`:`){let t=i+1;for(;t<r&&/\s/.test(e[t]);)t++;let n=e[t];if(n===`{`||n===`[`)return[t,a(e,t)];let o=t;for(;o<r&&e[o]!==`,`&&e[o]!==`}`;)o++;for(;o>t&&/\s/.test(e[o-1]);)o--;return[t,o]}c=t-1}}}function s(e,t){let n=Object.entries(t).filter(([,e])=>e!==void 0);if(!e)return`import { defineConfig } from 'vite-plus';\n\nexport default defineConfig({\n${n.map(([e,t])=>` ${e}: ${r(t,1)},`).join(`
|
|
5
5
|
`)}\n});\n`;let i=e,s=i.match(/defineConfig\s*\(\s*\{/);if(!s||s.index===void 0)return i;for(let[e,t]of n){let n=i.match(/defineConfig\s*\(\s*\{/);if(!n||n.index===void 0)break;let s=i.indexOf(`{`,n.index),c=a(i,s);if(c===-1)break;let l=r(t,1),u=o(i,s,c,e);i=u?`${i.slice(0,u[0])}${l}${i.slice(u[1])}`:`${i.slice(0,s+1)}\n ${e}: ${l},${i.slice(s+1)}`}return i}function c(n,r){let i=e.join(n,`vite.config.ts`);return{path:i,content:s(t.existsSync(i)?t.readFileSync(i,`utf-8`):void 0,r)}}function l(e,n,r){let i=c(e,n);return r&&t.writeFileSync(i.path,i.content,`utf-8`),i.path}export{o as findTopLevelValue,a as matchBracket,s as mergeViteConfig,c as renderViteTarget,r as serializeTs,l as writeViteTarget};
|
|
@@ -8,6 +8,14 @@ export declare const VITE_CONFIG_FILES: readonly ['vite.config.ts', 'vite.config
|
|
|
8
8
|
export declare function findViteConfig(cwd: string): string | undefined;
|
|
9
9
|
/** The nearest `dbx.config.*` in `cwd`, if present. */
|
|
10
10
|
export declare function findDbxConfig(cwd: string): string | undefined;
|
|
11
|
+
/**
|
|
12
|
+
* Deep-merge two object-literal texts: nested objects are merged recursively and
|
|
13
|
+
* every other value (arrays included) from `incoming` replaces the base's.
|
|
14
|
+
*
|
|
15
|
+
* Used when folding a hand-written `vite.config.*` into an existing
|
|
16
|
+
* `toolchain.vite`, so the settings already there are kept instead of replaced.
|
|
17
|
+
*/
|
|
18
|
+
export declare function mergeViteObjects(base: string, incoming: string): string;
|
|
11
19
|
/**
|
|
12
20
|
* Extract the object literal passed to `defineConfig(...)`, or the
|
|
13
21
|
* default-exported object when there is no `defineConfig`.
|
|
@@ -31,15 +39,29 @@ export declare function scanLiteralObject(text: string): {
|
|
|
31
39
|
};
|
|
32
40
|
/**
|
|
33
41
|
* Fold `objectText` into the `toolchain.vite` of a `dbx.config.*` source by
|
|
34
|
-
* text-splicing (inserting
|
|
35
|
-
* whole file. Returns the new source, or an error
|
|
36
|
-
* cannot be located.
|
|
42
|
+
* text-splicing (inserting the `vite` key, or deep-merging into an existing
|
|
43
|
+
* object), never rewriting the whole file. Returns the new source, or an error
|
|
44
|
+
* when the `toolchain` object cannot be located.
|
|
37
45
|
*/
|
|
38
46
|
export declare function foldViteIntoConfig(source: string, objectText: string): {
|
|
39
47
|
content: string;
|
|
40
48
|
} | {
|
|
41
49
|
error: string;
|
|
42
50
|
};
|
|
51
|
+
/**
|
|
52
|
+
* Fold an object literal into a top-level `toolchain.<section>` (or deep-merge
|
|
53
|
+
* into the existing object), without the Vite-specific `config: true` rewrite.
|
|
54
|
+
*/
|
|
55
|
+
export declare function foldToolchainSection(source: string, section: string, objectText: string): {
|
|
56
|
+
content: string;
|
|
57
|
+
} | {
|
|
58
|
+
error: string;
|
|
59
|
+
};
|
|
60
|
+
/** Render a fresh `dbx.config.ts` with one or more folded toolchain sections. */
|
|
61
|
+
export declare function renderFreshSectionsConfig(sections: {
|
|
62
|
+
key: string;
|
|
63
|
+
objectText: string;
|
|
64
|
+
}[]): string;
|
|
43
65
|
/**
|
|
44
66
|
* Ensure `fmt.ignorePatterns` contains `'/vite.config.ts'` in a folded Vite
|
|
45
67
|
* object literal, so Oxfmt does not reformat the generated root `vite.config.ts`
|
|
@@ -2,5 +2,10 @@ import{default as e}from"node:path";import"node:url";import.meta.url;import{CONF
|
|
|
2
2
|
`;)t++;return t}if(n===`/`&&r===`*`){for(t+=2;t<e.length&&(e[t]!==`*`||e[t+1]!==`/`);)t++;return t+2}if(n===`"`||n===`'`){let r=n;for(t++;t<e.length&&e[t]!==r;)e[t]===`\\`&&t++,t++;return t+1}return t}function l(e,t){let n=e.lastIndexOf(`
|
|
3
3
|
`,t-1)+1;return e.slice(n).match(/^[ \t]*/)?.[0]??``}function u(e,t){return e.split(`
|
|
4
4
|
`).map((e,n)=>n===0?e:`${t}${e}`).join(`
|
|
5
|
-
`)}function d(e
|
|
6
|
-
`)
|
|
5
|
+
`)}function d(e,t){return t?e.split(`
|
|
6
|
+
`).map((e,n)=>n>0&&e.startsWith(t)?e.slice(t.length):e).join(`
|
|
7
|
+
`):e}function f(e,t,n){let r=[],i=1;for(let a=t+1;a<n;a++){let t=c(e,a);if(t!==a){a=t-1;continue}let o=e[a];if(o===`{`||o===`[`)i++;else if(o===`}`||o===`]`)i--;else if(i===1&&/[A-Za-z_$]/.test(o)){let t=a;for(;t<n&&/[\w$]/.test(e[t]);)t++;let i=t;for(;i<n&&/\s/.test(e[i]);)i++;i<n&&e[i]===`:`&&r.push(e.slice(a,t)),a=t-1}}return r}function p(e,t){let i=e.indexOf(`{`),a=i===-1?-1:r(e,i);if(i===-1||a===-1)return e;let o=a-1,s=e.slice(0,o),c=e.slice(o),u=s.replace(/\s+$/,``),d=l(e,o),p=f(e,i,a)[0],m=p===void 0?void 0:n(e,i,a,p),h=s.includes(`
|
|
8
|
+
`)&&m?l(e,m[0]):`${d} `;return`${u}${u.endsWith(`{`)||u.endsWith(`,`)?``:`,`}${t.map(({key:e,value:t})=>`\n${h}${e}: ${t},`).join(``)}\n${d}${c}`}function m(e,t){let i=e.indexOf(`{`),a=t.indexOf(`{`),o=i===-1?-1:r(e,i),s=a===-1?-1:r(t,a);if(i===-1||o===-1||a===-1||s===-1)return t;let c=[],l=[];for(let r of f(t,a,s)){let u=n(t,a,s,r);if(!u)continue;let d=t.slice(u[0],u[1]),f=n(e,i,o,r);if(f){let t=e.slice(f[0],f[1]),n=t.trimStart().startsWith(`{`)&&d.trimStart().startsWith(`{`)?m(t,d):d;c.push({start:f[0],end:f[1],text:n})}else l.push({key:r,value:d})}let u=e;for(let e of c.sort((e,t)=>t.start-e.start))u=`${u.slice(0,e.start)}${e.text}${u.slice(e.end)}`;return l.length>0?p(u,l):u}function h(e){let t=e.indexOf(`{`),i=t===-1?-1:r(e,t);if(t===-1||i===-1)return e;let a=n(e,t,i,`config`);return!a||e.slice(a[0],a[1]).trim()!==`false`?e:`${e.slice(0,a[0])}true${e.slice(a[1])}`}function g(e){let t=e.match(/\bdefineConfig\s*\(/),n=0;if(t&&t.index!==void 0)n=t.index+t[0].length;else{let t=e.match(/export\s+default\s*/);if(!t||t.index===void 0)return;n=t.index+t[0].length}let i=n;for(;i<e.length&&e[i]!==`{`;)i++;if(i>=e.length)return;let a=r(e,i);return a===-1?void 0:[i,a]}function _(e){let t=e.match(/\bdefineConfig\s*\(/),n=-1;if(t&&t.index!==void 0)n=t.index+t[0].length;else{let t=e.match(/export\s+default\s*/);t&&t.index!==void 0&&(n=t.index+t[0].length)}if(n===-1)return{error:"no `defineConfig(...)` call or default-exported object found"};for(;n<e.length&&/\s/.test(e[n]);)n++;if(e[n]!==`{`)return{error:`the config value is not an object literal (it is a variable or an expression)`};let i=r(e,n);return i===-1?{error:`unbalanced braces in the config object`}:{text:e.slice(n,i)}}function v(e){let t=0;for(;t<e.length;){let n=e[t];if(n==="`")return{ok:!1,reason:`template literal`};let r=c(e,t);if(r!==t)t=r;else{if(n===`.`&&e[t+1]===`.`&&e[t+2]===`.`)return{ok:!1,reason:"spread (`...`)"};if(/[A-Za-z_$]/.test(n)){let n=t;for(;n<e.length&&/[\w$]/.test(e[n]);)n++;let r=e.slice(t,n),i=n;for(;i<e.length&&/\s/.test(e[i]);)i++;if(e[i]!==`:`&&![`true`,`false`,`null`,`undefined`].includes(r))return{ok:!1,reason:`non-literal value \`${r}\``};t=n}else t++}}return{ok:!0}}function y(e,t){let r=g(e);if(!r)return{error:`could not locate the config root object`};let[i,a]=r,o=n(e,i,a,`toolchain`);if(!o)return{error:"the config has no `toolchain` object to add `vite` to"};let[s,c]=o,f=n(e,s,c,`vite`);if(f){let[n,r]=f,i=l(e,n),a=d(e.slice(n,r),i),o=u(h(a.trimStart().startsWith(`{`)&&t.trimStart().startsWith(`{`)?m(a,t):t),i);return{content:`${e.slice(0,n)}${o}${e.slice(r)}`}}let p=`${l(e,s)} `,_=u(t,p);return{content:`${e.slice(0,s+1)}\n${p}vite: ${_},${e.slice(s+1)}`}}function b(e,t,r){let i=g(e);if(!i)return{error:`could not locate the config root object`};let[a,o]=i,s=n(e,a,o,`toolchain`);if(!s)return{error:`the config has no \`toolchain\` object to add \`${t}\` to`};let[c,f]=s,p=n(e,c,f,t);if(p){let[t,n]=p,i=l(e,t),a=d(e.slice(t,n),i),o=a.trimStart().startsWith(`{`)&&r.trimStart().startsWith(`{`)?m(a,r):r;return{content:`${e.slice(0,t)}${u(o,i)}${e.slice(n)}`}}let h=`${l(e,c)} `;return{content:`${e.slice(0,c+1)}\n${h}${t}: ${u(r,h)},${e.slice(c+1)}`}}function x(e){return[`import { defineConfig } from '@deltabox/toolchain';`,``,`export default defineConfig({`,` toolchain: {`,e.map(({key:e,objectText:t})=>` ${e}: ${u(t,` `)},`).join(`
|
|
9
|
+
`),` },`,`});`,``].join(`
|
|
10
|
+
`)}const S=`/vite.config.ts`;function C(e){return/resolveVite\s*(?:<[^>]*>)?\s*\(/.test(e)&&e.includes(`@deltabox/toolchain/vite`)}function w(e){return[`import { defineConfig } from '@deltabox/toolchain';`,``,`export default defineConfig({`,` toolchain: {`,` vite: ${u(e,` `)},`,` },`,`});`,``].join(`
|
|
11
|
+
`)}function T(e){let t=e.indexOf(`{`);if(t===-1)return e;let i=r(e,t);if(i===-1)return e;let a=`'${S}'`,o=n(e,t,i,`fmt`);if(o&&e[o[0]]===`{`&&e[o[1]-1]===`}`){let[t,r]=o,i=n(e,t,r,`ignorePatterns`);if(i){let[t,n]=i;return e.slice(t,n).includes(S)?e:e[t]===`[`?`${e.slice(0,t+1)}${a}, ${e.slice(t+1)}`:`${e.slice(0,t)}[${a}]${e.slice(n)}`}return`${e.slice(0,t+1)} ignorePatterns: [${a}],${e.slice(t+1)}`}return o?`${e.slice(0,o[0])}{ ignorePatterns: [${a}] }${e.slice(o[1])}`:`${e.slice(0,t+1)} fmt: { ignorePatterns: [${a}] },${e.slice(t+1)}`}const E={id:`vite-to-toolchain`,from:`vite`,to:`toolchain`,description:"Fold a hand-written vite.config.* into dbx.config.* (`toolchain.vite`).",detect:e=>{let t=o(e);if(!t)return!1;try{return!C(i.readFileSync(t,`utf-8`))}catch{return!0}},run:async t=>{let n=o(t.cwd);if(!n)throw Error(`vite-to-toolchain: no vite.config.* found.`);let r=i.readFileSync(n,`utf-8`).replace(/^\uFEFF/,``),a=[`Source: ${e.basename(n)}.`],c=[],l=()=>({id:E.id,from:`vite`,to:`toolchain`,written:[],files:[],unmapped:c,notes:a});if(C(r))return a.push("Already managed by `dbx sync`; nothing to fold."),l();let u=_(r);if(`error`in u)return c.push({source:e.basename(n),reason:u.error}),a.push(`Left vite.config.* unchanged; fold it by hand.`),l();let d=v(u.text);if(!d.ok)return c.push({source:e.basename(n),reason:`cannot fold faithfully (${d.reason})`}),a.push(`The config references helpers/imports or non-literal expressions; fold it by hand.`),l();let f=T(u.text),p=`added \`${S}\` to \`fmt.ignorePatterns\`; run \`dbx sync\` to regenerate vite.config.ts.`,m=s(t.cwd),h=()=>t.ignoreViteConfigFile?(a.push(`Kept \`${e.basename(n)}\` (ignoreViteConfigFile).`),[]):(t.write&&i.rmSync(n,{force:!0}),a.push(`Removed \`${e.basename(n)}\` (recreated by \`dbx sync\`).`),[n]);if(m&&m.endsWith(`.json`))return c.push({source:e.basename(m),reason:`JSON configs cannot hold the extracted object by text-splice`}),a.push(`Fold into the JSON config by hand.`),l();if(!m){let n=e.join(t.cwd,`dbx.config.ts`),r={path:n,content:w(f)};t.write&&i.writeFileSync(n,r.content,`utf-8`);let o=h();return a.push(`Created \`${e.basename(n)}\` with the folded \`toolchain.vite\`; ${p}`),{id:E.id,from:`vite`,to:`toolchain`,written:[n],removed:o,files:[r],notes:a}}let g=y(i.readFileSync(m,`utf-8`).replace(/^\uFEFF/,``),f);if(`error`in g)return c.push({source:e.basename(m),reason:g.error}),a.push("Left dbx.config.* unchanged; fold `toolchain.vite` in by hand."),l();let b={path:m,content:g.content};t.write&&i.writeFileSync(m,b.content,`utf-8`);let x=h();return a.push(`Folded into \`toolchain.vite\` (${e.basename(m)}); ${p}`),{id:E.id,from:`vite`,to:`toolchain`,written:[m],removed:x,files:[b],notes:a}}};export{a as VITE_CONFIG_FILES,T as ensureViteFmtIgnore,_ as extractViteObject,s as findDbxConfig,o as findViteConfig,b as foldToolchainSection,y as foldViteIntoConfig,m as mergeViteObjects,x as renderFreshSectionsConfig,v as scanLiteralObject,E as viteToToolchain};
|
|
@@ -18,6 +18,13 @@ export declare const CATALOG_MARKER = "# Managed by @deltabox/toolchain (catalog
|
|
|
18
18
|
export declare const CATALOG_PACKAGE_MANAGERS: readonly ['yarn', 'pnpm', 'bun'];
|
|
19
19
|
/** Whether a package manager supports catalogs (defaults to Yarn). */
|
|
20
20
|
export declare function supportsCatalogs(packageManager: string | undefined): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Whether a directory already declares a default catalog its workspaces can
|
|
23
|
+
* reference with `catalog:`. Bun keeps it in `package.json`; Yarn/pnpm in their
|
|
24
|
+
* catalog file. When `required` is given, every package must be present (so a
|
|
25
|
+
* partial catalog never produces dangling `catalog:` references).
|
|
26
|
+
*/
|
|
27
|
+
export declare function hasCatalog(root: string, packageManager: string | undefined, required?: string[]): boolean;
|
|
21
28
|
/** A resolved catalog: a default map and/or named catalogs. */
|
|
22
29
|
export interface Catalog {
|
|
23
30
|
/** The default catalog (`package -> version range`). */
|
|
@@ -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{readJsonFile as t}from"../../shared/src/fs-utils.js";import{sectionConfig as n,sectionEnabled as r}from"../../shared/src/toolchain.js";import{toYaml as i}from"../../shared/src/yaml.js";import"../../shared/src/index.js";import a from"node:fs";const o="# Managed by @deltabox/toolchain (catalogs) - edit dbx.config.* and run `dbx sync`.",s=[`yarn`,`pnpm`,`bun`];function c(e){let t=e??`yarn`;return s.includes(t)}function l(e){let t=[],n=!1;for(let r of e.split(/\r?\n/)){if(/^catalog:\s*(?:#.*)?$/.test(r)){n=!0;continue}if(!n)continue;if(/^\S/.test(r))break;let e=r.match(/^\s+"?([^":\s][^":]*)"?:\s*/);e?.[1]&&t.push(e[1])}return t}function u(n,r,i=[]){let o=r??`yarn`;if(!c(o))return!1;let s=e=>i.length===0?e.length>0:i.every(t=>e.includes(t));if(o===`bun`){let r=t(e.join(n,`package.json`));return r?s(Object.keys(r.workspaces?.catalog??{})):!1}let u=d(o);if(!u)return!1;try{return s(l(a.readFileSync(e.join(n,u),`utf-8`).replace(/^\uFEFF/,``)))}catch{return!1}}function d(e){switch(e??`yarn`){case`yarn`:return`.yarnrc.yml`;case`pnpm`:return`pnpm-workspace.yaml`;default:return}}function f(e){return`${o}\n${e}`}function p(e){let t={nodeLinker:`node-modules`};return e.packages&&Object.keys(e.packages).length>0&&(t.catalog=e.packages),e.named&&Object.keys(e.named).length>0&&(t.catalogs=e.named),f(i(t))}function m(e,t){let n={};return t&&t.length>0&&(n.packages=t),e.packages&&Object.keys(e.packages).length>0&&(n.catalog=e.packages),e.named&&Object.keys(e.named).length>0&&(n.catalogs=e.named),f(i(n))}function h(){return{name:`catalogs`,projectTypes:[`monorepo-root`,`project`],keep:[`.yarnrc.yml`,`pnpm-workspace.yaml`],enabled:e=>r(e.catalogs),run:t=>{let r=n(t.config.catalogs)??{},i=String(t.tokens.packageManager??`yarn`),o={...r.packages?{packages:r.packages}:{},...r.named?{named:r.named}:{}};if(Object.keys(o.packages??{}).length===0&&!o.named)return[];if(!c(i))return t.warn(`catalogs: ${i} has no catalog support; nothing written.`),[];if(i===`bun`)return t.warn(`catalogs: Bun catalogs live in package.json; declare them there (or use yarn/pnpm).`),[];let s=d(i);if(!s)return[];let l=e.resolve(t.cwd,s);return a.existsSync(l)&&!a.readFileSync(l,`utf-8`).includes("# Managed by @deltabox/toolchain (catalogs) - edit dbx.config.* and run `dbx sync`.")?(t.warn(`catalogs: ${s} exists and is not toolchain-managed; leaving it untouched.`),[]):[{path:s,content:i===`pnpm`?m(o,t.projectType===`monorepo-root`?[`packages/*`]:void 0):p(o)}]}}}export{o as CATALOG_MARKER,s as CATALOG_PACKAGE_MANAGERS,d as catalogFileFor,h as catalogsSyncTask,u as hasCatalog,m as renderPnpmWorkspace,p as renderYarnrc,c as supportsCatalogs};
|
|
@@ -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{createMonorepoRootFiles as
|
|
1
|
+
import{default as e}from"node:path";import"node:url";import.meta.url;import{logger as t}from"../../../shared/src/logger.js";import{sectionConfig as n}from"../../../shared/src/toolchain.js";import"../../../shared/src/index.js";import{loadToolchainConfig as r}from"../../../core/src/loader.js";import"../../../core/src/index.js";import{hasCatalog as i}from"../catalogs.js";import{tsconfigFileNames as a}from"../../../tsconfig/src/sync.js";import"../../../tsconfig/src/index.js";import{SCAFFOLD_CATALOG as o,createMonorepoRootFiles as s,createRootProjectFiles as c,createWorkspaceFiles as l,findRootOxcFiles as u,upsertWorkspaceTsconfig as d,writeGeneratedFiles as f}from"../typescript.js";import{generateProjectConfigs as p}from"../config.js";const m=[{flags:`--no-config`,description:`Skip the dbx.config.ts file.`},{flags:`--type <type>`,description:`Project type: project | monorepo-root | monorepo-workspace.`},{flags:`--force`,description:`Overwrite existing files in the output directory.`}],h={flags:`--package-manager <pm>`,description:`Package manager: yarn (default) | pnpm | npm | bun.`},g=[`project`,`monorepo-root`,`monorepo-workspace`];function _(e){if(e!=null&&e!==``)return String(e)}function v(e,t={}){let n=_(e.description);return{...t.description!==!1&&n?{description:n}:{},..._(e.author)?{author:_(e.author)}:{},..._(e.license)?{license:_(e.license)}:{},..._(e.homepage)?{homepage:_(e.homepage)}:{},..._(e.repo)?{repo:_(e.repo)}:{},..._(e.nodeVersion)?{nodeVersion:_(e.nodeVersion)}:{}}}function y(e,t){let n=_(t.packageManager),r=e.packageManager??n??`yarn`,i=r===n?_(t.packageManagerVersion)??_(t.yarnVersion):void 0;return{packageManager:r,...i?{packageManagerVersion:i}:{}}}function b(e,t){let n=String(e.name??t.project?.name??``).trim();if(!n)throw Error("a project name is required: pass `--name <name>` or set `project.name` in dbx.config.*.");return n}function x(t,n){return t===`.`?e.basename(e.resolve(n)):t}function S(e,t){let n=e.type??t;if(!g.includes(n))throw Error(`invalid project type "${n}" (expected one of: ${g.join(`, `)}).`);return n}function C(e){return n(e.tsconfig)?.extends}function w(){return[{name:`project:init`,description:`Scaffold a single-package TypeScript project.`,options:[{flags:`-n, --name <name>`,description:`Project name.`},{flags:`-s, --scope <scope>`,description:`npm scope, eg. @acme.`},{flags:`-o, --out <dir>`,description:`Output directory (default: cwd).`},h,...m],run:(e,n)=>{let r=e.out??n.cwd,i=x(b(e,n.config),r),a=C(n.config),o=e.scope??_(n.tokens.scope),s=c({...v(n.tokens),name:i,...o?{scope:o}:{},...y(e,n.tokens),type:S(e,`project`),includeConfig:n.noConfig?!1:e.config??!0,rootOxc:u(r),...a?{tsconfigExtends:a}:{}}),l=f(s,r,{force:!!e.force});for(let e of l)t.info(`Created ${e}`)}},{name:`project:init:monorepo`,description:`Scaffold a monorepo root (add --example for one example workspace).`,options:[{flags:`-n, --name <name>`,description:`Project name.`},{flags:`-s, --scope <scope>`,description:`npm scope, eg. @acme.`},{flags:`-o, --out <dir>`,description:`Output directory (default: cwd).`},{flags:`--example`,description:`Also scaffold one example workspace package.`},h,...m],run:(e,n)=>{let r=e.out??n.cwd,i=x(b(e,n.config),r),a=e.scope??_(n.tokens.scope)??`@${i}`,o=n.noConfig?!1:e.config??!0,c=S(e,`monorepo-root`),u=!!e.example,d=y(e,n.tokens),p=C(n.config),m=s({...v(n.tokens),name:i,scope:a,type:c,includeConfig:o,...d,...p?{tsconfigExtends:p}:{},workspaces:u?[{alias:`core`,dir:`packages/core`}]:[]});u&&m.push(...l({...v(n.tokens,{description:!1}),name:i,scope:a,wsName:`core`,wsDir:`packages/core`,type:`monorepo-workspace`,includeConfig:o,useCatalog:!0,...d,...p?{tsconfigExtends:p}:{}}).map(e=>({...e,path:`packages/core/${e.path}`})));let h=f(m,r,{force:!!e.force});for(let e of h)t.info(`Created ${e}`)}},{name:`project:init:workspace`,description:`Scaffold a monorepo workspace package into an existing monorepo root.`,options:[{flags:`-n, --name <name>`,description:`Workspace package name (unscoped).`},{flags:`-s, --scope <scope>`,description:`npm scope, eg. @acme.`},{flags:`-r, --root <dir>`,description:`Monorepo root (default: cwd).`},{flags:`-d, --dir <dir>`,description:`Workspace dir relative to the root (default: packages/<name>).`},h,...m],run:async(n,s)=>{let c=n.root??s.cwd,{config:u,tokens:p}=e.resolve(c)===e.resolve(s.cwd)?{config:s.config,tokens:s.tokens}:await r(c,{tolerant:!0,skipHooks:!0,...s.noConfig?{noConfig:!0}:{}}),m=String(n.name??``).trim();if(!m)throw Error("a workspace name is required: pass `--name <name>` (the root project name is not the workspace name).");let h=x(m,c),g=_(p.name)??e.basename(e.resolve(c)),b=n.scope??_(p.scope)??`@${g}`,w=(n.dir??`packages/${h}`).replace(/\\/g,`/`).replace(/\/+$/,``),T=s.noConfig?!1:n.config??!0,E=S(n,`monorepo-workspace`),D=y(n,p),O=C(u),k=l({...v(p,{description:!1}),name:h,scope:b,wsName:h,wsDir:w,type:E,includeConfig:T,useCatalog:i(c,D.packageManager,Object.keys(o)),...D,...O?{tsconfigExtends:O}:{}}).map(e=>({...e,path:`${w}/${e.path}`})),A=f(k,c,{force:!!n.force});d(c,{alias:h,dir:w},b,a(u).rootFile);for(let e of A)t.info(`Created ${e}`)}},{name:`project:config`,description:`Generate dbx.config.ts for existing projects that are missing one.`,options:[{flags:`--cwd <dir>`,description:`Root to scan (default: cwd).`},{flags:`--include <pattern...>`,description:`Only projects matching these patterns (glob or substring).`},{flags:`--exclude <pattern...>`,description:`Skip projects matching these patterns (glob or substring).`},{flags:`--type <type>`,description:`Force a project type for every config.`},{flags:`--force`,description:`Overwrite configs that already exist.`},{flags:`--dry-run`,description:`Report what would be written without writing.`},{flags:`--json`,description:`Print the result as JSON.`}],run:(n,r)=>{let i=n.cwd??r.cwd,a=p({root:i,...n.include?{include:n.include}:{},...n.exclude?{exclude:n.exclude}:{},...n.type?{type:n.type}:{},force:!!n.force,dryRun:!!n.dryRun});if(n.json){t.raw(JSON.stringify(a,null,4));return}let o=a.dryRun?`would create`:`created`;t.info(`${o} ${a.created.length} config(s), skipped ${a.skipped.length}.`);for(let n of a.configs)n.created&&(t.info(` + ${n.rel===`.`?`dbx.config.ts`:`${n.rel}/dbx.config.ts`} [${n.type}]`),n.vite&&t.info(n.vite.folded?` vite: folded ${e.basename(n.vite.path)} into toolchain.vite (run \`dbx sync\`)`:` vite: left ${e.basename(n.vite.path)} alone (${n.vite.error})`))}}]}export{w as projectCommands};
|
|
@@ -37,6 +37,12 @@ export interface GeneratedProjectConfig {
|
|
|
37
37
|
created: boolean;
|
|
38
38
|
/** Why the project was skipped, when it was. */
|
|
39
39
|
skipped?: string;
|
|
40
|
+
/** How an existing hand-written `vite.config.*` was handled. */
|
|
41
|
+
vite?: {
|
|
42
|
+
path: string;
|
|
43
|
+
folded: boolean;
|
|
44
|
+
error?: string;
|
|
45
|
+
};
|
|
40
46
|
}
|
|
41
47
|
export interface GenerateProjectConfigsResult {
|
|
42
48
|
configs: GeneratedProjectConfig[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{default as e}from"node:path";import"node:url";import.meta.url;import{readJsonAt as t}from"../../shared/src/fs-utils.js";import{projectFromPackageJson as n}from"../../shared/src/project.js";import"../../shared/src/index.js";import{detectProjectType as r}from"../../core/src/project-type.js";import{selectProjects as i}from"../../core/src/select.js";import"../../core/src/index.js";import{
|
|
1
|
+
import{default as e}from"node:path";import"node:url";import.meta.url;import{readJsonAt as t}from"../../shared/src/fs-utils.js";import{projectFromPackageJson as n}from"../../shared/src/project.js";import"../../shared/src/index.js";import{detectProjectType as r}from"../../core/src/project-type.js";import{selectProjects as i}from"../../core/src/select.js";import"../../core/src/index.js";import{ensureViteFmtIgnore as a,extractViteObject as o,findViteConfig as s,foldViteIntoConfig as c,scanLiteralObject as l}from"../../migrate/src/vite.js";import"../../migrate/src/index.js";import{renderToolchainConfig as u}from"./typescript.js";import d from"node:fs";const f=`dbx.config.ts`;function p(t,n){if(!t)return{name:e.basename(n)};let r=t.match(/^(@[^/]+)\/(.+)$/);return r?.[1]&&r[2]?{name:r[2],scope:r[1]}:{name:t}}function m(m){let h=m.dryRun??!1,g=m.force??!1,_=i({root:m.root,...m.include?{include:m.include}:{},...m.exclude?{exclude:m.exclude}:{},...m.maxDepth===void 0?{}:{maxDepth:m.maxDepth}}),v=[],y=[],b=[];for(let i of _){let _=e.join(i.dir,f);if((i.hasConfig||d.existsSync(_))&&!g){b.push(i.rel),v.push({dir:i.dir,rel:i.rel,...i.name?{name:i.name}:{},type:m.type??r(i.dir),configPath:_,created:!1,skipped:`has config`});continue}let x=m.type??r(i.dir),S=t(i.dir,`package.json`),{name:C,scope:w}=p(i.name??S?.name,i.dir),T=S?n(S):void 0,E=u({name:C,...w?{scope:w}:{},type:x,...T?.description?{description:T.description}:{},...T?.author?{author:T.author}:{},...T?.license?{license:T.license}:{},...T?.homepage?{homepage:T.homepage}:{},...T?.repo?{repo:T.repo}:{},...T?.nodeVersion?{nodeVersion:T.nodeVersion}:{},...T?.packageManager?{packageManager:T.packageManager}:{},...T?.packageManagerVersion?{packageManagerVersion:T.packageManagerVersion}:{}}),D=E,O,k=s(i.dir);if(k)try{let e=d.readFileSync(k,`utf-8`).replace(/^\uFEFF/,``);if(!e.includes(`@deltabox/toolchain/vite`)){let t=o(e),n=`error`in t?void 0:l(t.text);if(`error`in t||!n?.ok)O={path:k,folded:!1,error:`error`in t?t.error:n.reason};else{let e=c(E,a(t.text));`content`in e?(D=e.content,O={path:k,folded:!0}):O={path:k,folded:!1,error:e.error}}}}catch(e){O={path:k,folded:!1,error:String(e)}}h||d.writeFileSync(_,D,`utf-8`),y.push(i.rel),v.push({dir:i.dir,rel:i.rel,...i.name?{name:i.name}:{},type:x,configPath:_,created:!0,...O?{vite:O}:{}})}return{configs:v,created:y,skipped:b,dryRun:h}}export{f as GENERATED_CONFIG_FILENAME,m as generateProjectConfigs};
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import __tsdown_shims_path from 'node:path';
|
|
2
2
|
import __tsdown_shims_url from 'node:url';
|
|
3
|
-
import {
|
|
3
|
+
import { DEFAULT_PACKAGE_MANAGER_VERSIONS } from "../../shared/src/toolchain.js";
|
|
4
|
+
import { CATALOG_MARKER, CATALOG_PACKAGE_MANAGERS, Catalog, catalogFileFor, catalogsSyncTask, hasCatalog, renderPnpmWorkspace, renderYarnrc, supportsCatalogs } from "./catalogs.js";
|
|
4
5
|
import { projectCommands } from "./cli/index.js";
|
|
5
6
|
import { GENERATED_CONFIG_FILENAME, GenerateProjectConfigsOptions, GenerateProjectConfigsResult, GeneratedProjectConfig, generateProjectConfigs } from "./config.js";
|
|
6
7
|
import { projectSyncTask } from "./sync.js";
|
|
7
|
-
import {
|
|
8
|
+
import { MonorepoRootContext, ProjectContext, RootOxcFiles, SCAFFOLD_CATALOG, WorkspaceContext, WriteGeneratedFilesOptions, createMonorepoRootFiles, createRootProjectFiles, createWorkspaceFiles, findRootOxcFiles, renderApplicationEntry, renderApplicationHtml, renderGitignore, renderSourceEntry, renderSourceTest, renderToolchainConfig, renderWorkspaceTsconfig, upsertWorkspaceTsconfig, writeGeneratedFiles } from "./typescript.js";
|
|
8
9
|
declare namespace index_d_exports {
|
|
9
|
-
export { CATALOG_MARKER, CATALOG_PACKAGE_MANAGERS, Catalog, DEFAULT_PACKAGE_MANAGER_VERSIONS, GENERATED_CONFIG_FILENAME, GenerateProjectConfigsOptions, GenerateProjectConfigsResult, GeneratedProjectConfig, MonorepoRootContext, ProjectContext, SCAFFOLD_CATALOG, WorkspaceContext, catalogFileFor, catalogsSyncTask, createMonorepoRootFiles, createRootProjectFiles, createWorkspaceFiles, generateProjectConfigs, projectCommands, projectSyncTask, renderGitignore, renderPnpmWorkspace, renderToolchainConfig, renderWorkspaceTsconfig, renderYarnrc, supportsCatalogs, writeGeneratedFiles };
|
|
10
|
+
export { CATALOG_MARKER, CATALOG_PACKAGE_MANAGERS, Catalog, DEFAULT_PACKAGE_MANAGER_VERSIONS, GENERATED_CONFIG_FILENAME, GenerateProjectConfigsOptions, GenerateProjectConfigsResult, GeneratedProjectConfig, MonorepoRootContext, ProjectContext, RootOxcFiles, SCAFFOLD_CATALOG, WorkspaceContext, WriteGeneratedFilesOptions, catalogFileFor, catalogsSyncTask, createMonorepoRootFiles, createRootProjectFiles, createWorkspaceFiles, findRootOxcFiles, generateProjectConfigs, hasCatalog, projectCommands, projectSyncTask, renderApplicationEntry, renderApplicationHtml, renderGitignore, renderPnpmWorkspace, renderSourceEntry, renderSourceTest, renderToolchainConfig, renderWorkspaceTsconfig, renderYarnrc, supportsCatalogs, upsertWorkspaceTsconfig, writeGeneratedFiles };
|
|
10
11
|
}
|
|
11
12
|
//#endregion
|
|
12
|
-
export { CATALOG_MARKER, CATALOG_PACKAGE_MANAGERS, Catalog, DEFAULT_PACKAGE_MANAGER_VERSIONS, GENERATED_CONFIG_FILENAME, GenerateProjectConfigsOptions, GenerateProjectConfigsResult, GeneratedProjectConfig, MonorepoRootContext, ProjectContext, SCAFFOLD_CATALOG, WorkspaceContext, catalogFileFor, catalogsSyncTask, createMonorepoRootFiles, createRootProjectFiles, createWorkspaceFiles, generateProjectConfigs, index_d_exports, projectCommands, projectSyncTask, renderGitignore, renderPnpmWorkspace, renderToolchainConfig, renderWorkspaceTsconfig, renderYarnrc, supportsCatalogs, writeGeneratedFiles };
|
|
13
|
+
export { CATALOG_MARKER, CATALOG_PACKAGE_MANAGERS, Catalog, DEFAULT_PACKAGE_MANAGER_VERSIONS, GENERATED_CONFIG_FILENAME, GenerateProjectConfigsOptions, GenerateProjectConfigsResult, GeneratedProjectConfig, MonorepoRootContext, ProjectContext, RootOxcFiles, SCAFFOLD_CATALOG, WorkspaceContext, WriteGeneratedFilesOptions, catalogFileFor, catalogsSyncTask, createMonorepoRootFiles, createRootProjectFiles, createWorkspaceFiles, findRootOxcFiles, generateProjectConfigs, hasCatalog, index_d_exports, projectCommands, projectSyncTask, renderApplicationEntry, renderApplicationHtml, renderGitignore, renderPnpmWorkspace, renderSourceEntry, renderSourceTest, renderToolchainConfig, renderWorkspaceTsconfig, renderYarnrc, supportsCatalogs, upsertWorkspaceTsconfig, writeGeneratedFiles };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import"node:path";import"node:url";import.meta.url;import{__exportAll as e}from"../../../_virtual/_rolldown/runtime.js";import{CATALOG_MARKER as
|
|
1
|
+
import"node:path";import"node:url";import.meta.url;import{__exportAll as e}from"../../../_virtual/_rolldown/runtime.js";import{DEFAULT_PACKAGE_MANAGER_VERSIONS as t}from"../../shared/src/toolchain.js";import{CATALOG_MARKER as n,CATALOG_PACKAGE_MANAGERS as r,catalogFileFor as i,catalogsSyncTask as a,hasCatalog as o,renderPnpmWorkspace as s,renderYarnrc as c,supportsCatalogs as l}from"./catalogs.js";import{SCAFFOLD_CATALOG as u,createMonorepoRootFiles as d,createRootProjectFiles as f,createWorkspaceFiles as p,findRootOxcFiles as m,renderApplicationEntry as h,renderApplicationHtml as g,renderGitignore as _,renderSourceEntry as v,renderSourceTest as y,renderToolchainConfig as b,renderWorkspaceTsconfig as x,upsertWorkspaceTsconfig as S,writeGeneratedFiles as C}from"./typescript.js";import{GENERATED_CONFIG_FILENAME as w,generateProjectConfigs as T}from"./config.js";import{projectCommands as E}from"./cli/index.js";import{projectSyncTask as D}from"./sync.js";var O=/* @__PURE__ */ e({CATALOG_MARKER:()=>n,CATALOG_PACKAGE_MANAGERS:()=>r,DEFAULT_PACKAGE_MANAGER_VERSIONS:()=>t,GENERATED_CONFIG_FILENAME:()=>w,SCAFFOLD_CATALOG:()=>u,catalogFileFor:()=>i,catalogsSyncTask:()=>a,createMonorepoRootFiles:()=>d,createRootProjectFiles:()=>f,createWorkspaceFiles:()=>p,findRootOxcFiles:()=>m,generateProjectConfigs:()=>T,hasCatalog:()=>o,projectCommands:()=>E,projectSyncTask:()=>D,renderApplicationEntry:()=>h,renderApplicationHtml:()=>g,renderGitignore:()=>_,renderPnpmWorkspace:()=>s,renderSourceEntry:()=>v,renderSourceTest:()=>y,renderToolchainConfig:()=>b,renderWorkspaceTsconfig:()=>x,renderYarnrc:()=>c,supportsCatalogs:()=>l,upsertWorkspaceTsconfig:()=>S,writeGeneratedFiles:()=>C});export{n as CATALOG_MARKER,r as CATALOG_PACKAGE_MANAGERS,t as DEFAULT_PACKAGE_MANAGER_VERSIONS,w as GENERATED_CONFIG_FILENAME,u as SCAFFOLD_CATALOG,i as catalogFileFor,a as catalogsSyncTask,d as createMonorepoRootFiles,f as createRootProjectFiles,p as createWorkspaceFiles,m as findRootOxcFiles,T as generateProjectConfigs,o as hasCatalog,E as projectCommands,D as projectSyncTask,h as renderApplicationEntry,g as renderApplicationHtml,_ as renderGitignore,s as renderPnpmWorkspace,v as renderSourceEntry,y as renderSourceTest,b as renderToolchainConfig,x as renderWorkspaceTsconfig,c as renderYarnrc,O as src_exports,l as supportsCatalogs,S as upsertWorkspaceTsconfig,C as writeGeneratedFiles};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{default as e}from"node:path";import"node:url";import.meta.url;import{readJsonAt as t}from"../../shared/src/fs-utils.js";import{projectToPackageJson as n,splitPackageName as r}from"../../shared/src/project.js";import"../../shared/src/index.js";import i from"node:fs";function a(t){let n=e.resolve(t);for(;;){if(i.existsSync(e.join(n,`.git`)))return n;let t=e.dirname(n);if(t===n)return;n=t}}function o(){return{name:`project`,enabled:e=>e.project!==void 0,run:i=>{let o=i.config.project;if(!o)return[];let s=t(i.cwd,`package.json`);if(!s)return[];let c=a(i.cwd),l=c&&e.resolve(c)!==e.resolve(i.cwd)?e.relative(c,i.cwd).replace(/\\/g,`/`):void 0,u={...o};if(u.name!==void 0&&u.scope===void 0&&s.name){let{scope:e}=r(s.name);e&&(u.scope=e)}let d=n(u,l?{directory:l}:{});if(Object.keys(d).length===0)return[];let f={...s,...d};return[{path:`package.json`,content:`${JSON.stringify(f,null,4)}\n
|
|
1
|
+
import{default as e}from"node:path";import"node:url";import.meta.url;import{readJsonAt as t}from"../../shared/src/fs-utils.js";import{projectToPackageJson as n,splitPackageName as r}from"../../shared/src/project.js";import"../../shared/src/index.js";import i from"node:fs";function a(t){let n=e.resolve(t);for(;;){if(i.existsSync(e.join(n,`.git`)))return n;let t=e.dirname(n);if(t===n)return;n=t}}function o(){return{name:`project`,enabled:e=>e.project!==void 0,run:i=>{let o=i.config.project;if(!o)return[];let s=t(i.cwd,`package.json`);if(!s)return[];let c=a(i.cwd),l=c&&e.resolve(c)!==e.resolve(i.cwd)?e.relative(c,i.cwd).replace(/\\/g,`/`):void 0,u={...o};if(u.name!==void 0&&u.scope===void 0&&s.name){let{scope:e}=r(s.name);e&&(u.scope=e)}let d=n(u,l?{directory:l}:{});if(Object.keys(d).length===0)return[];let f={...s,...d};return[{path:`package.json`,content:`${JSON.stringify(f,null,4)}\n`,track:!1}]}}}export{o as projectSyncTask};
|
|
@@ -1,42 +1,75 @@
|
|
|
1
1
|
import __tsdown_shims_path from 'node:path';
|
|
2
2
|
import __tsdown_shims_url from 'node:url';
|
|
3
3
|
import { ProjectType } from "../../shared/src/config-types.js";
|
|
4
|
+
import { DEFAULT_PACKAGE_MANAGER_VERSIONS } from "../../shared/src/toolchain.js";
|
|
4
5
|
import { GeneratedFile } from "../../shared/src/types.js";
|
|
5
6
|
import "../../shared/src/index.js";
|
|
6
|
-
import { MonorepoWorkspace } from "../../tsconfig/src/templates.js";
|
|
7
|
+
import { MonorepoWorkspace, TsconfigExtendsOptions } from "../../tsconfig/src/templates.js";
|
|
7
8
|
import "../../tsconfig/src/index.js";
|
|
8
9
|
//#region packages/project/src/typescript.d.ts
|
|
9
10
|
/** The catalog a scaffolded root writes into its package-manager file. */
|
|
10
11
|
export declare const SCAFFOLD_CATALOG: Record<string, string>;
|
|
11
|
-
/**
|
|
12
|
-
* Default package-manager versions used when a scaffold does not specify one.
|
|
13
|
-
* A `packageManager` field must carry a version (corepack rejects a bare name),
|
|
14
|
-
* so the scaffold always writes `<pm>@<version>`.
|
|
15
|
-
*/
|
|
16
|
-
export declare const DEFAULT_PACKAGE_MANAGER_VERSIONS: Record<string, string>;
|
|
17
12
|
/** The replacement values a project scaffold understands. */
|
|
18
13
|
export interface ProjectContext {
|
|
19
14
|
/** The project/package name (unscoped). */
|
|
20
15
|
name: string;
|
|
21
16
|
/** The npm scope, eg. `@acme`. */
|
|
22
17
|
scope?: string;
|
|
18
|
+
/** Package description. */
|
|
19
|
+
description?: string;
|
|
23
20
|
/** Package author. */
|
|
24
21
|
author?: string;
|
|
25
22
|
/** SPDX license id. */
|
|
26
23
|
license?: string;
|
|
24
|
+
/** Project homepage. */
|
|
25
|
+
homepage?: string;
|
|
27
26
|
/** Repository URL. */
|
|
27
|
+
repo?: string;
|
|
28
|
+
/** Repository URL (legacy alias for {@link repo}). */
|
|
28
29
|
repoUrl?: string;
|
|
29
30
|
/** Node engine range. */
|
|
30
31
|
nodeVersion?: string;
|
|
31
|
-
/**
|
|
32
|
+
/** Package manager version. */
|
|
33
|
+
packageManagerVersion?: string;
|
|
34
|
+
/** Yarn version (legacy alias for {@link packageManagerVersion}). */
|
|
32
35
|
yarnVersion?: string;
|
|
33
36
|
/** Package manager name. */
|
|
34
37
|
packageManager?: string;
|
|
35
38
|
/** The project kind written into the scaffolded `dbx.config.ts`. */
|
|
36
39
|
type?: ProjectType;
|
|
40
|
+
/** The scaffold flavour (an application gets Vite entry files/scripts). */
|
|
41
|
+
kind?: 'project' | 'application';
|
|
42
|
+
/** Write `fmt.oxc` / `lint.oxc` defaults (and the Oxc config files). */
|
|
43
|
+
oxc?: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Oxc config files already present above the scaffold root. The matching
|
|
46
|
+
* local file + `dbx.config.ts` opt-in are omitted so the root owns them.
|
|
47
|
+
*/
|
|
48
|
+
rootOxc?: RootOxcFiles;
|
|
37
49
|
/** Write a `dbx.config.ts` (default true). */
|
|
38
50
|
includeConfig?: boolean;
|
|
51
|
+
/** Per-file `extends` overrides for the scaffolded tsconfig templates. */
|
|
52
|
+
tsconfigExtends?: TsconfigExtendsOptions;
|
|
53
|
+
}
|
|
54
|
+
/** Oxc config files found in an ancestor of a scaffold output directory. */
|
|
55
|
+
export interface RootOxcFiles {
|
|
56
|
+
fmt: boolean;
|
|
57
|
+
lint: boolean;
|
|
39
58
|
}
|
|
59
|
+
/**
|
|
60
|
+
* Find the nearest ancestor that owns Oxc config files. The walk stops at the
|
|
61
|
+
* repository boundary (`.git`) so a nested project cannot inherit files from an
|
|
62
|
+
* unrelated checkout above it.
|
|
63
|
+
*/
|
|
64
|
+
export declare function findRootOxcFiles(start: string): RootOxcFiles;
|
|
65
|
+
/** A minimal source entry so `tsdown` has an input and the scaffold builds. */
|
|
66
|
+
export declare function renderSourceEntry(): string;
|
|
67
|
+
/** The Vite entry point for an application scaffold. */
|
|
68
|
+
export declare function renderApplicationEntry(): string;
|
|
69
|
+
/** The `index.html` for an application scaffold. */
|
|
70
|
+
export declare function renderApplicationHtml(name: string): string;
|
|
71
|
+
/** A smoke test paired with {@link renderSourceEntry}. */
|
|
72
|
+
export declare function renderSourceTest(): string;
|
|
40
73
|
/**
|
|
41
74
|
* Render a `dbx.config.ts` scaffold (toolchain settings under `toolchain`). The
|
|
42
75
|
* `project.type` lets the sync know whether the folder is a monorepo root, a
|
|
@@ -44,9 +77,11 @@ export interface ProjectContext {
|
|
|
44
77
|
*/
|
|
45
78
|
export declare function renderToolchainConfig(ctx: ProjectContext & {
|
|
46
79
|
type: ProjectType;
|
|
80
|
+
fmtOxc?: boolean;
|
|
81
|
+
lintOxc?: boolean;
|
|
47
82
|
}): string;
|
|
48
83
|
/** A minimal tsconfig.json that extends the default template. */
|
|
49
|
-
export declare function renderWorkspaceTsconfig(composite?: boolean): string;
|
|
84
|
+
export declare function renderWorkspaceTsconfig(composite?: boolean, extendsValue?: string | string[] | false): string;
|
|
50
85
|
/** Files for a single-package TypeScript project (tsconfig + tooling). */
|
|
51
86
|
export declare function createRootProjectFiles(ctx: ProjectContext): GeneratedFile[];
|
|
52
87
|
export interface MonorepoRootContext extends ProjectContext {
|
|
@@ -57,6 +92,13 @@ export interface MonorepoRootContext extends ProjectContext {
|
|
|
57
92
|
}
|
|
58
93
|
/** Files for a monorepo root (workspaces + monorepo tsconfig). */
|
|
59
94
|
export declare function createMonorepoRootFiles(ctx: MonorepoRootContext): GeneratedFile[];
|
|
95
|
+
/**
|
|
96
|
+
* Add (or refresh) a workspace in a monorepo root's workspaces tsconfig.
|
|
97
|
+
* Keeps the existing file (including comments and formatting) and just upserts
|
|
98
|
+
* the aliases and project reference. Returns `false` when the configured file
|
|
99
|
+
* is absent.
|
|
100
|
+
*/
|
|
101
|
+
export declare function upsertWorkspaceTsconfig(root: string, workspace: MonorepoWorkspace, scope: string | undefined, rootFile?: string): boolean;
|
|
60
102
|
export interface WorkspaceContext extends ProjectContext {
|
|
61
103
|
/** The workspace name (unscoped), eg. `core`. */
|
|
62
104
|
wsName: string;
|
|
@@ -69,6 +111,16 @@ export interface WorkspaceContext extends ProjectContext {
|
|
|
69
111
|
export declare function createWorkspaceFiles(ctx: WorkspaceContext): GeneratedFile[];
|
|
70
112
|
/** A generic `.gitignore`. */
|
|
71
113
|
export declare function renderGitignore(): string;
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
114
|
+
export interface WriteGeneratedFilesOptions {
|
|
115
|
+
/** Overwrite files that already exist (default false). */
|
|
116
|
+
force?: boolean;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Write generated files under `cwd`, creating directories as needed. A target
|
|
120
|
+
* outside `cwd` is rejected, and an existing file is never overwritten unless
|
|
121
|
+
* `force` is set, so a scaffold cannot escape its output directory or silently
|
|
122
|
+
* clobber a user's files.
|
|
123
|
+
*/
|
|
124
|
+
export declare function writeGeneratedFiles(files: GeneratedFile[], cwd?: string, options?: WriteGeneratedFilesOptions): string[];
|
|
125
|
+
//#endregion
|
|
126
|
+
export { DEFAULT_PACKAGE_MANAGER_VERSIONS };
|