@yorozu/build 0.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.
Files changed (74) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +38 -0
  3. package/chunks/21EFCjEU.js +19160 -0
  4. package/chunks/CMapqBQB.js +2620 -0
  5. package/chunks/CYSd7-PF.js +623 -0
  6. package/chunks/Cr5v7tI0.js +1824 -0
  7. package/ci/github-actions.d.ts +3 -0
  8. package/ci/index.d.ts +1 -0
  9. package/cli/commands/_utils.d.ts +8 -0
  10. package/cli/commands/build.d.ts +40 -0
  11. package/cli/commands/bump-version.d.ts +27 -0
  12. package/cli/commands/cr.d.ts +27 -0
  13. package/cli/commands/docs.d.ts +9 -0
  14. package/cli/commands/find-changed-packages.d.ts +10 -0
  15. package/cli/commands/gen-changelog.d.ts +10 -0
  16. package/cli/commands/gen-deps-graph.d.ts +15 -0
  17. package/cli/commands/jsr.d.ts +6 -0
  18. package/cli/commands/lint/config.d.ts +1 -0
  19. package/cli/commands/lint/index.d.ts +11 -0
  20. package/cli/commands/lint/validate-workspace-deps.d.ts +23 -0
  21. package/cli/commands/publish.d.ts +62 -0
  22. package/cli/commands/release.d.ts +45 -0
  23. package/cli/index.d.ts +8 -0
  24. package/cli/log.d.ts +3 -0
  25. package/cli/main.d.ts +2 -0
  26. package/config.d.ts +57 -0
  27. package/git/github.d.ts +15 -0
  28. package/git/index.d.ts +2 -0
  29. package/git/utils.d.ts +38 -0
  30. package/index.d.ts +8 -0
  31. package/index.js +26 -0
  32. package/jsr/_deno-directives.d.ts +1 -0
  33. package/jsr/config.d.ts +1 -0
  34. package/jsr/create-packages.d.ts +8 -0
  35. package/jsr/deno-json.d.ts +19 -0
  36. package/jsr/generate-workspace.d.ts +9 -0
  37. package/jsr/index.d.ts +6 -0
  38. package/jsr/populate.d.ts +10 -0
  39. package/jsr/utils/external-libs.d.ts +8 -0
  40. package/jsr/utils/index.d.ts +4 -0
  41. package/jsr/utils/jsr-api.d.ts +23 -0
  42. package/jsr/utils/jsr-json.d.ts +10 -0
  43. package/jsr/utils/jsr.d.ts +10 -0
  44. package/jsr.d.ts +1 -0
  45. package/jsr.js +2 -0
  46. package/misc/_config.d.ts +2 -0
  47. package/misc/exec.d.ts +15 -0
  48. package/misc/fs.d.ts +4 -0
  49. package/misc/index.d.ts +6 -0
  50. package/misc/path.d.ts +1 -0
  51. package/misc/publish-order.d.ts +3 -0
  52. package/misc/tsconfig.d.ts +2 -0
  53. package/npm/index.d.ts +1 -0
  54. package/npm/npm-api.d.ts +6 -0
  55. package/package-json/collect-package-jsons.d.ts +9 -0
  56. package/package-json/find-package-json.d.ts +1 -0
  57. package/package-json/index.d.ts +6 -0
  58. package/package-json/parse.d.ts +11 -0
  59. package/package-json/process-package-json.d.ts +20 -0
  60. package/package-json/types.d.ts +39 -0
  61. package/package-json/utils.d.ts +4 -0
  62. package/package.json +59 -0
  63. package/versioning/bump-version.d.ts +31 -0
  64. package/versioning/collect-files.d.ts +21 -0
  65. package/versioning/generate-changelog.d.ts +8 -0
  66. package/versioning/index.d.ts +4 -0
  67. package/versioning/types.d.ts +21 -0
  68. package/vite/build-plugin.d.ts +73 -0
  69. package/vite/config.d.ts +47 -0
  70. package/vite/index.d.ts +2 -0
  71. package/vite.d.ts +1 -0
  72. package/vite.js +184 -0
  73. package/yorozu-build.d.ts +1 -0
  74. package/yorozu-build.js +527 -0
package/misc/exec.d.ts ADDED
@@ -0,0 +1,15 @@
1
+ import { SpawnOptions } from 'node:child_process';
2
+ export interface ExecResult {
3
+ stdout: string;
4
+ stderr: string;
5
+ exitCode: number;
6
+ }
7
+ export declare class ExecError extends Error {
8
+ readonly cmd: Array<string>;
9
+ readonly result: ExecResult;
10
+ constructor(cmd: Array<string>, result: ExecResult);
11
+ }
12
+ export declare function exec(cmd: Array<string>, options?: SpawnOptions & {
13
+ throwOnError?: boolean;
14
+ quiet?: boolean;
15
+ }): Promise<ExecResult>;
package/misc/fs.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ import { CopyOptions } from 'node:fs';
2
+ export declare function fileExists(path: string): Promise<boolean>;
3
+ export declare function directoryExists(path: string): Promise<boolean>;
4
+ export declare function tryCopy(src: string, dest: string, options?: CopyOptions): Promise<void>;
@@ -0,0 +1,6 @@
1
+ export * from './_config';
2
+ export * from './exec';
3
+ export * from './fs';
4
+ export * from './path';
5
+ export * from './publish-order';
6
+ export * from './tsconfig';
package/misc/path.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare function normalizeFilePath(filePath: string | URL): string;
@@ -0,0 +1,3 @@
1
+ import { WorkspacePackage } from '../package-json/collect-package-jsons';
2
+ export declare function sortWorkspaceByPublishOrder(packages: Array<WorkspacePackage>): Array<WorkspacePackage>;
3
+ export declare function determinePublishOrder(dependencies: Record<string, Array<string>>): Array<string>;
@@ -0,0 +1,2 @@
1
+ export declare function getTsconfigFor(cwd: string): Promise<unknown>;
2
+ export declare function getTsconfigFiles(cwd: string): Promise<Array<string>>;
package/npm/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './npm-api';
@@ -0,0 +1,6 @@
1
+ export declare const NPM_PACKAGE_NAME_REGEX: RegExp;
2
+ export declare function npmCheckVersion(params: {
3
+ registry?: string;
4
+ package: string;
5
+ version: string;
6
+ }): Promise<boolean>;
@@ -0,0 +1,9 @@
1
+ import { PackageJson } from './types';
2
+ export interface WorkspacePackage {
3
+ path: string;
4
+ packageJsonPath: string;
5
+ root: boolean;
6
+ json: PackageJson;
7
+ }
8
+ export declare function collectPackageJsons(workspaceRoot: string | URL, includeRoot?: boolean): Promise<Array<WorkspacePackage>>;
9
+ export declare function filterPackageJsonsForPublish(packages: Array<WorkspacePackage>, registry: "jsr" | "npm"): Array<WorkspacePackage>;
@@ -0,0 +1 @@
1
+ export declare function findPackageJson(from: string | URL): Promise<string | null>;
@@ -0,0 +1,6 @@
1
+ export * from './collect-package-jsons';
2
+ export * from './find-package-json';
3
+ export * from './parse';
4
+ export * from './process-package-json';
5
+ export * from './types';
6
+ export * from './utils';
@@ -0,0 +1,11 @@
1
+ import { PackageJson } from './types';
2
+ export declare function parsePackageJson(packageJson: string, format?: "json" | "yaml"): PackageJson;
3
+ export declare function parsePackageJsonFile(packageJsonPath: string | URL): Promise<PackageJson>;
4
+ export declare function parsePackageJsonFromDir(dir: string | URL): Promise<{
5
+ path: string;
6
+ json: PackageJson;
7
+ }>;
8
+ export declare function parseWorkspaceRootPackageJson(workspaceRoot: string | URL): Promise<{
9
+ path: string;
10
+ json: PackageJson;
11
+ }>;
@@ -0,0 +1,20 @@
1
+ import { PackageJson } from './types';
2
+ interface ProcessPackageJsonParams {
3
+ packageJson: PackageJson;
4
+ onlyEntrypoints?: boolean;
5
+ workspaceVersions?: Map<string, string>;
6
+ bundledWorkspaceDeps?: Array<RegExp>;
7
+ rootPackageJson?: PackageJson;
8
+ rootFieldsToCopy?: Set<string>;
9
+ shouldCopyEntrypoint?: (name: string, target: string) => boolean;
10
+ fixedVersion?: string;
11
+ }
12
+ interface ProcessPackageJsonReturn {
13
+ packageJson: PackageJson;
14
+ packageJsonOriginal: PackageJson;
15
+ entrypoints: Map<string, string>;
16
+ entrypointsToCopy: Map<string, string>;
17
+ }
18
+ export declare function processPackageJson(params: ProcessPackageJsonParams): ProcessPackageJsonReturn;
19
+ export declare function removeCommonjsExports(exports: Record<string, unknown>): void;
20
+ export {};
@@ -0,0 +1,39 @@
1
+ import { ZodObject } from 'zod';
2
+ export interface PackageJson {
3
+ name?: string;
4
+ type?: "module" | "commonjs";
5
+ version?: string;
6
+ private?: boolean;
7
+ description?: string;
8
+ packageManager?: string;
9
+ license?: string;
10
+ homepage?: string;
11
+ repository?: string | {
12
+ type: string;
13
+ url: string;
14
+ };
15
+ keywords?: Array<string>;
16
+ catalogs?: Record<string, Record<string, string>>;
17
+ workspaces?: Array<string>;
18
+ scripts?: Record<string, string>;
19
+ dependencies?: Record<string, string>;
20
+ devDependencies?: Record<string, string>;
21
+ peerDependencies?: Record<string, string>;
22
+ optionalDependencies?: Record<string, string>;
23
+ bundledDependencies?: Array<string>;
24
+ engines?: Record<string, string>;
25
+ pnpm?: {
26
+ overrides: Record<string, string>;
27
+ };
28
+ yorozu?: {
29
+ jsr?: "skip" | "only";
30
+ npm?: "skip" | "only";
31
+ keepScripts?: Array<string>;
32
+ distOnlyFields?: Record<string, unknown>;
33
+ ownVersioning?: boolean;
34
+ private?: boolean;
35
+ standalone?: boolean;
36
+ };
37
+ [key: string]: any;
38
+ }
39
+ export declare const PackageJsonSchema: ZodObject;
@@ -0,0 +1,4 @@
1
+ import { WorkspacePackage } from './collect-package-jsons';
2
+ export declare function findPackageByName(packages: Array<WorkspacePackage>, name: string): WorkspacePackage;
3
+ export declare function findRootPackage(packages: Array<WorkspacePackage>): WorkspacePackage;
4
+ export declare function collectVersions(packages: Array<WorkspacePackage>): Map<string, string>;
package/package.json ADDED
@@ -0,0 +1,59 @@
1
+ {
2
+ "name": "@yorozu/build",
3
+ "type": "module",
4
+ "version": "0.1.0",
5
+ "description": "build and release utilities for yorozu packages",
6
+ "license": "MIT",
7
+ "dependencies": {
8
+ "@drizzle-team/brocli": "0.12.0",
9
+ "@yorozu/utils": "^0.1.0",
10
+ "cross-spawn": "7.0.6",
11
+ "detect-indent": "7.0.2",
12
+ "esbuild": "0.25.12",
13
+ "js-yaml": "4.1.1",
14
+ "json5": "2.2.3",
15
+ "picomatch": "4.0.4",
16
+ "semver": "7.7.4",
17
+ "tinyglobby": "0.2.16",
18
+ "zod": "4.3.6"
19
+ },
20
+ "peerDependencies": {
21
+ "typedoc": "0.28.19",
22
+ "typescript": "6.0.2",
23
+ "vite": "8.0.8"
24
+ },
25
+ "exports": {
26
+ ".": {
27
+ "import": {
28
+ "types": "./index.d.ts",
29
+ "default": "./index.js"
30
+ }
31
+ },
32
+ "./vite": {
33
+ "import": {
34
+ "types": "./vite.d.ts",
35
+ "default": "./vite.js"
36
+ }
37
+ },
38
+ "./jsr": {
39
+ "import": {
40
+ "types": "./jsr.d.ts",
41
+ "default": "./jsr.js"
42
+ }
43
+ }
44
+ },
45
+ "author": "inshinrei",
46
+ "sideEffects": false,
47
+ "bin": {
48
+ "yorozu-build": "yorozu-build.js"
49
+ },
50
+ "peerDependenciesMeta": {
51
+ "typedoc": {
52
+ "optional": true
53
+ }
54
+ },
55
+ "repository": {
56
+ "type": "git",
57
+ "url": "git+https://github.com/inshinrei/yorozu.git"
58
+ }
59
+ }
@@ -0,0 +1,31 @@
1
+ import { ReleaseType } from 'semver';
2
+ import { CommitInfo } from '../git/utils';
3
+ import { WorkspacePackage } from '../package-json/collect-package-jsons';
4
+ import { VersioningOptions } from './types';
5
+ export interface BumpVersionPackage {
6
+ package: WorkspacePackage;
7
+ prevVersion: string;
8
+ }
9
+ export interface BumpVersionResult {
10
+ previousVersion: string;
11
+ nextVersion: string;
12
+ nextVersions: Record<string, string>;
13
+ changedPackages: Array<BumpVersionPackage>;
14
+ releaseType: ReleaseType;
15
+ hasBreakingChanges: boolean;
16
+ hasFeatures: boolean;
17
+ }
18
+ export declare function determineBumpType(params: {
19
+ oldVersion: string;
20
+ commits: Array<CommitInfo>;
21
+ }): ReleaseType;
22
+ export declare function bumpVersion(params: {
23
+ workspace: Array<WorkspacePackage>;
24
+ all?: boolean;
25
+ type?: ReleaseType;
26
+ cwd?: string | URL;
27
+ since: string;
28
+ params?: VersioningOptions;
29
+ dryRun?: boolean;
30
+ withRoot?: boolean;
31
+ }): Promise<BumpVersionResult>;
@@ -0,0 +1,21 @@
1
+ import { WorkspacePackage } from '../package-json/index';
2
+ import { VersioningOptions } from './types';
3
+ export interface ProjectChangedFile {
4
+ package: WorkspacePackage;
5
+ file: string;
6
+ root: string;
7
+ }
8
+ export declare function findProjectChangedFiles(params: {
9
+ params?: VersioningOptions;
10
+ workspace?: Array<WorkspacePackage>;
11
+ root?: string | URL;
12
+ since: string;
13
+ until?: string;
14
+ }): Promise<Array<ProjectChangedFile>>;
15
+ export declare function findProjectChangedPackages(params: {
16
+ params?: VersioningOptions;
17
+ workspace?: Array<WorkspacePackage>;
18
+ root?: string | URL;
19
+ since: string;
20
+ until?: string;
21
+ }): Promise<Array<WorkspacePackage>>;
@@ -0,0 +1,8 @@
1
+ import { WorkspacePackage } from '../package-json/index';
2
+ import { VersioningOptions } from './types';
3
+ export declare function generateChangelog(params: {
4
+ workspace: Array<WorkspacePackage>;
5
+ cwd?: string | URL;
6
+ since: string;
7
+ params?: VersioningOptions;
8
+ }): Promise<string>;
@@ -0,0 +1,4 @@
1
+ export * from './bump-version';
2
+ export * from './collect-files';
3
+ export * from './generate-changelog';
4
+ export * from './types';
@@ -0,0 +1,21 @@
1
+ import { MaybePromise } from '@yorozu/utils';
2
+ import { CommitInfo, ConventionalCommit } from '../git/utils';
3
+ import { WorkspacePackage } from '../package-json/collect-package-jsons';
4
+ import { ProjectChangedFile } from './collect-files';
5
+ export interface ChangelogGeneratorParams {
6
+ onCommitParseFailed?: (commit: CommitInfo) => void;
7
+ onCommitsFetched?: (commits: Array<CommitInfo>) => Promise<void>;
8
+ commitFilter?: (commit: CommitInfo, parsed: ConventionalCommit) => boolean;
9
+ commitFilterWithFiles?: (commit: CommitInfo, parsed: ConventionalCommit, files: Array<string>) => boolean;
10
+ commitFormatter?: (commit: CommitInfo, parsed: ConventionalCommit, files: Array<string>) => string;
11
+ packageCommitsFormatter?: (packageName: string, commits: Record<string, string>) => string;
12
+ }
13
+ export interface VersioningOptions {
14
+ taggingSchema?: "semver" | "date";
15
+ include?: Array<string> | null;
16
+ exclude?: Array<string> | null;
17
+ bumpWithDependants?: boolean | "only-minor";
18
+ shouldInclude?: (file: ProjectChangedFile) => MaybePromise<boolean>;
19
+ changelog?: ChangelogGeneratorParams;
20
+ beforeReleaseCommit?: (workspace: Array<WorkspacePackage>) => MaybePromise<void>;
21
+ }
@@ -0,0 +1,73 @@
1
+ import { MaybeArray, MaybePromise } from '@yorozu/utils';
2
+ import { PluginOption } from 'vite';
3
+ import { BuildHookContext } from '../config';
4
+ export declare function yorozuBuild(params: {
5
+ root: URL | string;
6
+ /**
7
+ * package root, will be passed to vite's `root` option
8
+ *
9
+ * @default `process.cwd()`
10
+ */
11
+ packageRoot?: string;
12
+ /**
13
+ * files to copy from the workspace root directory to the build directory
14
+ *
15
+ * @default ['LICENSE']
16
+ */
17
+ copyRootFiles?: Array<string>;
18
+ /**
19
+ * files to copy from the package root directory to the build directory
20
+ *
21
+ * @default ['README.md']
22
+ */
23
+ copyPackageFiles?: Array<string>;
24
+ /**
25
+ * the modifiable part of the chunk file name
26
+ * there will be a prefix of `chunks/[format]/` and a suffix of `.js`
27
+ * @default `[hash]`
28
+ */
29
+ chunkFileName?: string;
30
+ /**
31
+ * workspace dependencies that are bundled with the library,
32
+ * and as such shouldn't present in the final package.json
33
+ */
34
+ bundledWorkspaceDeps?: MaybeArray<string | RegExp>;
35
+ rootFieldsToCopy?: Array<string>;
36
+ /** when true, will automatically add `sideEffects: false` to generated package.json-s */
37
+ autoSideEffectsFalse?: boolean;
38
+ /**
39
+ * hook to run *before* anything is done to the package.json file
40
+ * you **can** modify the .packageJson property of the context
41
+ *
42
+ * this hook is called before vite build has started,
43
+ * and as such `.outDir` is not available yet
44
+ * (note: this hook is run *before* package-level hooks)
45
+ */
46
+ preparePackageJson?: (ctx: BuildHookContext) => void;
47
+ /**
48
+ * hook to run *after* the package.json file is finalized,
49
+ * right before it is written to disk
50
+ * you **can** modify the .packageJson property of the context
51
+ * (note: this hook is run *before* package-level hooks)
52
+ */
53
+ finalizePackageJson?: (ctx: BuildHookContext) => MaybePromise<void>;
54
+ /**
55
+ * hook to run *after* the build is done,
56
+ * time to do any final modifications to the package contents
57
+ * (note: this hook is run *before* package-level hooks)
58
+ */
59
+ finalize?: (ctx: BuildHookContext) => MaybePromise<void>;
60
+ /**
61
+ * when using with `vite-plugin-dts`, use this flag instead of
62
+ * their `insertTypesEntry` option to insert the types entry,
63
+ * as their implementation doesn't always yield the correct result
64
+ *
65
+ * @default false
66
+ */
67
+ insertTypesEntry?: boolean;
68
+ /**
69
+ * when using with `vite-plugin-dts`, this value should match `entryRoot`
70
+ * value passed to the `vite-plugin-dts` plugin
71
+ */
72
+ typesEntryRoot?: string;
73
+ }): Promise<PluginOption[]>;
@@ -0,0 +1,47 @@
1
+ import { AnyToNever, MaybePromise } from '@yorozu/utils';
2
+ import { TypeDocOptions } from 'typedoc';
3
+ import { Plugin, UserConfig } from 'vite';
4
+ import { BuildHookContext, JsrConfig } from '../config';
5
+ export interface CustomBuildConfigObject {
6
+ /** jsr-specific configuration */
7
+ jsr?: JsrConfig;
8
+ /** any additional vite plugins to be added before the yorozu-build plugin */
9
+ pluginsPre?: Array<Plugin>;
10
+ /** any additional vite plugins to be added after the yorozu-build plugin */
11
+ pluginsPost?: Array<Plugin>;
12
+ /** vite config to be merged into the base config */
13
+ viteConfig?: UserConfig;
14
+ /**
15
+ * a predicate to determine if the entrypoint should be copied to the target directory as-is, without being processed by vite
16
+ *
17
+ * - `name` is the name of the entrypoint (e.g. `./foo.json`)
18
+ * - `target` is the target path (e.g. `./src/foo.json`)
19
+ *
20
+ * the default implementation skips any non-javascript entrypoints, which is particularly useful for json and wasm files
21
+ *
22
+ * @default (name, target) => !!target.match(/(?<!\.d)\.([mc]?[jt]sx?)$/i)
23
+ */
24
+ shouldCopyEntrypoint?: (name: string, target: string) => boolean;
25
+ /**
26
+ * hook to run *before* anything is done to the package.json file
27
+ * you **can** modify the .packageJson property of the context
28
+ *
29
+ * this hook is called before vite build has started,
30
+ * and as such `.outDir` is not available yet
31
+ */
32
+ preparePackageJson?: (ctx: BuildHookContext) => void;
33
+ /**
34
+ * hook to run *after* the package.json file is finalized,
35
+ * right before it is written to disk
36
+ * you **can** modify the .packageJson property of the context
37
+ */
38
+ finalizePackageJson?: (ctx: BuildHookContext) => MaybePromise<void>;
39
+ /**
40
+ * hook to run *after* the build is done,
41
+ * time to do any final modifications to the package contents
42
+ */
43
+ finalize?: (ctx: BuildHookContext) => MaybePromise<void>;
44
+ /** package-specific configuration for typedoc */
45
+ typedoc?: AnyToNever<Partial<TypeDocOptions>> | ((current: AnyToNever<Partial<TypeDocOptions>>) => AnyToNever<Partial<TypeDocOptions>>);
46
+ }
47
+ export type CustomBuildConfig = CustomBuildConfigObject | (() => CustomBuildConfigObject);
@@ -0,0 +1,2 @@
1
+ export * from './build-plugin';
2
+ export * from './config';
package/vite.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from "./vite/index.js"
package/vite.js ADDED
@@ -0,0 +1,184 @@
1
+ import { asNonNull, collectPackageJsons, collectVersions, directoryExists, fileExists, glob, loadBuildConfig, normalizeFilePath, parallelMap, processPackageJson, removeCommonjsExports, tryCopy, warn } from "./chunks/21EFCjEU.js";
2
+ import process from "node:process";
3
+ import { dirname, join, relative } from "node:path";
4
+ import * as fsp from "node:fs/promises";
5
+ //#region ../utils/src/misc/objects.ts
6
+ function deepMerge(into, from, options = {}) {
7
+ if (!Array.isArray(from)) from = [from];
8
+ if (from.length === 0) return into;
9
+ const { undefined: undefinedStrategy = "ignore", properties: propertiesStrategy = "replace", arrays: arraysStrategy = "replace", objects: objectsStrategy = "merge" } = options;
10
+ for (let i = 0; i < from.length; i++) {
11
+ const source = from[i];
12
+ for (const key in source) {
13
+ if (!Object.hasOwn(source, key)) continue;
14
+ const value = source[key];
15
+ const existing = into[key];
16
+ if (value === void 0) {
17
+ if (undefinedStrategy === "replace") into[key] = void 0;
18
+ continue;
19
+ }
20
+ if (Array.isArray(value)) {
21
+ if (arraysStrategy === "merge" && Array.isArray(existing)) existing.push(...value);
22
+ else if (arraysStrategy === "ignore" && existing !== void 0) {} else into[key] = [...value];
23
+ continue;
24
+ }
25
+ if (typeof value === "object" && value !== null) {
26
+ if (objectsStrategy === "merge" && typeof existing === "object" && existing !== null) into[key] = deepMerge(existing, value, options);
27
+ else if (objectsStrategy === "ignore" && existing !== void 0) {} else into[key] = { ...value };
28
+ continue;
29
+ }
30
+ if (propertiesStrategy === "ignore" && existing !== void 0) {} else into[key] = value;
31
+ }
32
+ }
33
+ return into;
34
+ }
35
+ //#endregion
36
+ //#region ../utils/src/misc/string.ts
37
+ function assertStartsWith(str, prefix) {
38
+ if (!str.startsWith(prefix)) throw new TypeError(`String does not starts with ${prefix}.`, { cause: {
39
+ str,
40
+ prefix
41
+ } });
42
+ }
43
+ //#endregion
44
+ //#region src/vite/build-plugin.ts
45
+ var DEFAULT_LIB_FORMATS = ["es"];
46
+ function stripTrailingSlash(filePath) {
47
+ return filePath.replace(/\/$/g, "");
48
+ }
49
+ function toBundledWorkspaceDeps(deps) {
50
+ if (deps === void 0) return void 0;
51
+ return (Array.isArray(deps) ? deps : [deps]).map((dep) => typeof dep === "string" ? new RegExp(dep) : dep);
52
+ }
53
+ async function yorozuBuild(params) {
54
+ let { copyRootFiles = ["LICENSE"], copyPackageFiles = ["README.md"], chunkFileName = "[hash]", rootFieldsToCopy, packageRoot = process.cwd(), bundledWorkspaceDeps, autoSideEffectsFalse = false, insertTypesEntry = false, typesEntryRoot } = params;
55
+ let rootDir = normalizeFilePath(params.root);
56
+ let fixedVersion = process.env.__YOROZU_INTERNAL_FIXED_VERSION;
57
+ let cachedWorkspace = process.env.__YOROZU_INTERNAL_PACKAGES_LIST;
58
+ let allPackageJsons = cachedWorkspace !== void 0 ? JSON.parse(cachedWorkspace) : await collectPackageJsons(rootDir, true);
59
+ let rootPackageJson = allPackageJsons.find((it) => it.root)?.json;
60
+ if (!rootPackageJson) throw new Error("Could not find root package.json");
61
+ let normalizedPackageRoot = stripTrailingSlash(packageRoot);
62
+ let ourPackageJson = allPackageJsons.find((it) => stripTrailingSlash(it.path) === normalizedPackageRoot)?.json;
63
+ if (!ourPackageJson) throw new Error(`Could not find package.json for ${packageRoot}`);
64
+ if (rootPackageJson === ourPackageJson) return [{
65
+ name: "vite-plugin-yorozu-build",
66
+ config(_ctx, env) {
67
+ if (env.command === "build" && env.mode === "production") throw new Error("[@yorozu/build] Cannot build the root package from root. Please change cwd to the package directory, or pass it via `packageRoot` option.");
68
+ }
69
+ }];
70
+ let workspaceVersions = collectVersions(allPackageJsons);
71
+ let isNoop = false;
72
+ let packageConfig = await loadBuildConfig(packageRoot);
73
+ let hookContext = {
74
+ outDir: "",
75
+ packageDir: packageRoot,
76
+ packageName: asNonNull(ourPackageJson.name),
77
+ packageJson: ourPackageJson,
78
+ jsr: false,
79
+ typedoc: false
80
+ };
81
+ params.preparePackageJson?.(hookContext);
82
+ packageConfig?.preparePackageJson?.(hookContext);
83
+ let { packageJson, entrypoints, entrypointsToCopy } = processPackageJson({
84
+ packageJson: hookContext.packageJson,
85
+ rootPackageJson,
86
+ workspaceVersions,
87
+ bundledWorkspaceDeps: toBundledWorkspaceDeps(bundledWorkspaceDeps),
88
+ rootFieldsToCopy: rootFieldsToCopy != null ? new Set(rootFieldsToCopy) : void 0,
89
+ fixedVersion,
90
+ shouldCopyEntrypoint: packageConfig?.shouldCopyEntrypoint
91
+ });
92
+ if (fixedVersion != null) packageJson.version = fixedVersion;
93
+ hookContext.packageJson = packageJson;
94
+ if (packageJson.sideEffects == null) if (autoSideEffectsFalse) packageJson.sideEffects = false;
95
+ else {
96
+ warn(`[@yorozu/build] package.json for ${packageJson.name} has no sideEffects field, this may cause issues with tree-shaking`);
97
+ warn("[@yorozu/build] (tip: set `autoSideEffectsFalse: true` in plugin params to add it automatically)");
98
+ }
99
+ let buildCjs = false;
100
+ let buildDir;
101
+ return [
102
+ ...packageConfig?.pluginsPre ?? [],
103
+ {
104
+ name: "vite-plugin-yorozu-build",
105
+ async config(config, env) {
106
+ if (env.command !== "build") {
107
+ isNoop = true;
108
+ return null;
109
+ }
110
+ buildDir = join(packageRoot, config.build?.outDir ?? "dist");
111
+ hookContext.outDir = buildDir;
112
+ let libOptions = config?.build?.lib;
113
+ let libOptionsCustom = packageConfig?.viteConfig?.build?.lib;
114
+ let outputFormats = (libOptions === false ? void 0 : libOptions?.formats) ?? (libOptionsCustom === false ? void 0 : libOptionsCustom?.formats) ?? [...DEFAULT_LIB_FORMATS];
115
+ buildCjs = outputFormats.includes("cjs");
116
+ return deepMerge({
117
+ root: packageRoot,
118
+ build: {
119
+ emptyOutDir: true,
120
+ target: "es2022",
121
+ minify: false,
122
+ rollupOptions: { output: {
123
+ minifyInternalExports: false,
124
+ chunkFileNames: buildCjs ? `chunks/[format]/${chunkFileName}.js` : `chunks/${chunkFileName}.js`
125
+ } },
126
+ lib: {
127
+ entry: Object.fromEntries(entrypoints),
128
+ formats: outputFormats
129
+ }
130
+ }
131
+ }, packageConfig?.viteConfig ?? {});
132
+ },
133
+ async closeBundle() {
134
+ if (isNoop) return;
135
+ if (!buildCjs) removeCommonjsExports(packageJson.exports);
136
+ await params.finalizePackageJson?.(hookContext);
137
+ await packageConfig?.finalizePackageJson?.(hookContext);
138
+ await fsp.writeFile(join(buildDir, "package.json"), JSON.stringify(packageJson, null, 4));
139
+ for (let file of copyRootFiles) await tryCopy(join(rootDir, file), join(buildDir, file));
140
+ for (let file of copyPackageFiles) await tryCopy(join(packageRoot, file), join(buildDir, file));
141
+ if (insertTypesEntry) for (let [name, value] of entrypoints) {
142
+ let dTsFile = join(buildDir, `${name}.d.ts`);
143
+ if (await fileExists(dTsFile)) continue;
144
+ let entrypointFile = value;
145
+ if (!value.endsWith(".ts")) continue;
146
+ if (typesEntryRoot == null) {
147
+ assertStartsWith(entrypointFile, "./");
148
+ while (true) {
149
+ if (await fileExists(join(buildDir, entrypointFile.replace(/\.ts$/, ".d.ts")))) break;
150
+ let idx = entrypointFile.indexOf("/", 2);
151
+ if (idx === -1) throw new Error(`Could not find d.ts for entrypoint ${entrypointFile}, please pass typesEntryRoot explicitly`);
152
+ entrypointFile = `./${entrypointFile.slice(idx + 1)}`;
153
+ }
154
+ } else {
155
+ entrypointFile = relative(typesEntryRoot, join(packageRoot, entrypointFile));
156
+ if (!entrypointFile.startsWith(".")) entrypointFile = `./${entrypointFile}`;
157
+ }
158
+ entrypointFile = entrypointFile.replace(/\.ts$/, ".js");
159
+ await fsp.writeFile(dTsFile, `export * from ${JSON.stringify(entrypointFile)}`);
160
+ }
161
+ if (buildCjs) {
162
+ if (await directoryExists(join(buildDir, "chunks/cjs"))) {
163
+ let cjsFile = join(buildDir, "chunks/cjs/package.json");
164
+ await fsp.writeFile(cjsFile, JSON.stringify({ type: "commonjs" }));
165
+ }
166
+ await parallelMap(await glob("**/*.d.ts", { cwd: buildDir }), async (file) => {
167
+ let fullPath = join(buildDir, file);
168
+ await fsp.cp(fullPath, fullPath.replace(/\.d\.ts$/, ".d.cts"));
169
+ });
170
+ }
171
+ for (let [name, value] of entrypointsToCopy) {
172
+ let target = join(buildDir, name);
173
+ await fsp.mkdir(dirname(target), { recursive: true });
174
+ await tryCopy(join(packageRoot, value), target);
175
+ }
176
+ await params.finalize?.(hookContext);
177
+ await packageConfig?.finalize?.(hookContext);
178
+ }
179
+ },
180
+ ...packageConfig?.pluginsPost ?? []
181
+ ];
182
+ }
183
+ //#endregion
184
+ export { yorozuBuild };
@@ -0,0 +1 @@
1
+ export * from "./cli/main.js"