@sse-ui/builder 1.0.0 → 1.0.2

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.
@@ -1,96 +0,0 @@
1
- import * as fs from "node:fs/promises";
2
- import * as path from "node:path";
3
- import { Command } from "commander";
4
- import { $ } from "execa";
5
- import { PackageJson } from "./packageJson";
6
-
7
- /**
8
- * Auto-detects the package manager currently being used.
9
- * Looks at the npm_config_user_agent environment variable.
10
- */
11
- function getPackageManager(): "npm" | "yarn" | "pnpm" {
12
- const userAgent = process.env.npm_config_user_agent || "";
13
- if (userAgent.includes("pnpm")) return "pnpm";
14
- if (userAgent.includes("yarn")) return "yarn";
15
- return "npm";
16
- }
17
-
18
- export const publishCommand = new Command("publish")
19
- .description(
20
- "Automatically publishes the built package from the publishConfig.directory",
21
- )
22
- .option("--tag <tag>", "Registers the published package with the given tag")
23
- .option(
24
- "--access <access>",
25
- "Tells the registry whether this package should be published as public or restricted",
26
- )
27
- .option(
28
- "--dry-run",
29
- "Does everything publish would do except actually publishing",
30
- )
31
- .option(
32
- "--pm <manager>",
33
- "Force a specific package manager (npm, yarn, pnpm)",
34
- )
35
- .action(async (options) => {
36
- const cwd = process.cwd();
37
- const pkgJsonPath = path.join(cwd, "package.json");
38
-
39
- try {
40
- const packageJsonContent = await fs.readFile(pkgJsonPath, {
41
- encoding: "utf8",
42
- });
43
-
44
- const packageJson: PackageJson = JSON.parse(packageJsonContent);
45
- const publishDirBase = packageJson.publishConfig?.directory;
46
-
47
- if (!publishDirBase) {
48
- throw new Error(
49
- `No publish directory specified in "${packageJson.name}" package.json. Specify it in the "publishConfig.directory" field.`,
50
- );
51
- }
52
-
53
- const publishDir = path.join(cwd, publishDirBase);
54
- const dirExists = await fs.stat(publishDir).then(
55
- (stats) => stats.isDirectory(),
56
- () => false,
57
- );
58
-
59
- if (!dirExists) {
60
- throw new Error(
61
- `Publish directory "${publishDir}" does not exist. Please run the build command first.`,
62
- );
63
- }
64
-
65
- const pm = options.pm || getPackageManager();
66
- console.log(
67
- `🚀 Publishing via ${pm.toUpperCase()} from directory: ${publishDirBase}`,
68
- );
69
-
70
- const args = ["publish"];
71
- if (options.tag) args.push("--tag", options.tag);
72
- if (options.access) args.push("--access", options.access);
73
- if (options.dryRun) args.push("--dry-run");
74
-
75
- if (
76
- pm === "yarn" &&
77
- !process.env.npm_config_user_agent?.includes("yarn/3") &&
78
- !process.env.npm_config_user_agent?.includes("yarn/4")
79
- ) {
80
- args.push("--non-interactive");
81
- }
82
-
83
- await $({
84
- stdio: "inherit",
85
- cwd: publishDir,
86
- })`${pm} ${args}`;
87
-
88
- console.log("✅ Successfully published!");
89
- } catch (error) {
90
- console.error("❌ Error executing publish command:");
91
- if (error instanceof Error) {
92
- console.error(error.message);
93
- }
94
- process.exit(1);
95
- }
96
- });
@@ -1,28 +0,0 @@
1
- import { Command } from "commander";
2
- import { $ } from "execa";
3
-
4
- export const typecheckCommand = new Command("typecheck")
5
- .description(
6
- "Runs TypeScript validation across the project without emitting files",
7
- )
8
- .option("--watch", "Run typechecking in watch mode")
9
- .action(async (options) => {
10
- console.log("🔍 Running typecheck...");
11
-
12
- try {
13
- const args = ["tsc", "--noEmit"];
14
- if (options.watch) {
15
- args.push("--watch");
16
- }
17
-
18
- await $({ stdio: "inherit" })`${args.join(" ")}`;
19
- if (!options.watch) {
20
- console.log("✅ Typecheck passed! No errors found.");
21
- }
22
- } catch (error) {
23
- console.error(
24
- "❌ Typecheck failed. Please fix the TypeScript errors above.",
25
- );
26
- process.exit(1);
27
- }
28
- });
@@ -1,45 +0,0 @@
1
- import { Command } from "commander";
2
- import { $ } from "execa";
3
-
4
- export const versionCommand = new Command("version")
5
- .description("Bumps the package version (patch, minor, or major)")
6
- .argument(
7
- "<type>",
8
- "Version update type (patch, minor, major, or specific version like 1.2.3)",
9
- )
10
- .option("--no-git-tag-version", "Do not create a git tag")
11
- .action(async (type, options) => {
12
- const validTypes = [
13
- "patch",
14
- "minor",
15
- "major",
16
- "prepatch",
17
- "preminor",
18
- "premajor",
19
- "prerelease",
20
- ];
21
-
22
- // Basic validation to ensure they pass a valid type or a specific version number
23
- if (!validTypes.includes(type) && !/^\d+\.\d+\.\d+/.test(type)) {
24
- console.error(
25
- `❌ Invalid version type: ${type}. Use patch, minor, major, or a valid semver.`,
26
- );
27
- process.exit(1);
28
- }
29
-
30
- console.log(`📈 Bumping version (${type})...`);
31
-
32
- try {
33
- const args = ["version", type];
34
- if (!options.gitTagVersion) {
35
- args.push("--no-git-tag-version");
36
- }
37
-
38
- // Execute version bump
39
- await $({ stdio: "inherit" })`npm ${args}`;
40
- console.log("✅ Version bumped successfully!");
41
- } catch (error) {
42
- console.error("❌ Failed to bump version.");
43
- process.exit(1);
44
- }
45
- });
package/src/core/watch.ts DELETED
@@ -1,50 +0,0 @@
1
- import * as path from "node:path";
2
- import { Command } from "commander";
3
- import chokidar from "chokidar";
4
- import { $ } from "execa";
5
-
6
- export const watchCommand = new Command("watch")
7
- .description(
8
- "Watches the src directory and rebuilds automatically on changes",
9
- )
10
- .action(() => {
11
- const cwd = process.cwd();
12
- const srcDir = path.join(cwd, "src");
13
-
14
- console.log(`👀 Watching for changes in ./src...`);
15
-
16
- let isBuilding = false;
17
- let buildQueued = false;
18
-
19
- const runBuild = async () => {
20
- if (isBuilding) {
21
- buildQueued = true;
22
- return;
23
- }
24
- isBuilding = true;
25
- console.log(`\n⏳ Detected changes. Rebuilding...`);
26
-
27
- try {
28
- // Calls your own CLI's build command natively
29
- await $({ stdio: "inherit" })`npx sse-tools build`;
30
- console.log(`✅ Build updated successfully! Waiting for changes...`);
31
- } catch (err) {
32
- console.error(`❌ Build failed during watch.`);
33
- } finally {
34
- isBuilding = false;
35
- if (buildQueued) {
36
- buildQueued = false;
37
- runBuild();
38
- }
39
- }
40
- };
41
-
42
- // Initialize watcher
43
- const watcher = chokidar.watch(srcDir, {
44
- ignored: /(^|[\/\\])\../, // ignore dotfiles
45
- persistent: true,
46
- ignoreInitial: true, // Don't trigger on startup
47
- });
48
-
49
- watcher.on("add", runBuild).on("change", runBuild).on("unlink", runBuild);
50
- });
@@ -1,66 +0,0 @@
1
- declare module "@babel/plugin-transform-runtime" {
2
- import type { PluginItem } from "@babel/core";
3
-
4
- declare const plugin: PluginItem;
5
- export default plugin;
6
- }
7
-
8
- declare module "@babel/plugin-syntax-jsx" {
9
- import type { PluginItem } from "@babel/core";
10
-
11
- declare const plugin: PluginItem;
12
- export default plugin;
13
- }
14
-
15
- declare module "@babel/plugin-syntax-typescript" {
16
- import type { PluginItem } from "@babel/core";
17
-
18
- declare const plugin: PluginItem;
19
- export default plugin;
20
- }
21
-
22
- declare module "babel-plugin-optimize-clsx" {
23
- import type { PluginItem } from "@babel/core";
24
-
25
- declare const plugin: PluginItem;
26
- export default plugin;
27
- }
28
-
29
- declare module "babel-plugin-transform-react-remove-prop-types" {
30
- import type { PluginItem } from "@babel/core";
31
-
32
- declare const plugin: PluginItem;
33
- export default plugin;
34
- }
35
-
36
- declare module "babel-plugin-transform-import-meta" {
37
- import type { PluginItem } from "@babel/core";
38
-
39
- declare const plugin: PluginItem;
40
- export default plugin;
41
- }
42
-
43
- declare module "babel-plugin-transform-inline-environment-variables" {
44
- import type { PluginItem } from "@babel/core";
45
-
46
- declare const plugin: PluginItem;
47
- export default plugin;
48
- }
49
-
50
- declare module "@babel/preset-react" {
51
- import type { PluginItem } from "@babel/core";
52
-
53
- export type Options = {
54
- runtime: "string";
55
- };
56
-
57
- declare const preset: PluginItem;
58
- export default preset;
59
- }
60
-
61
- declare module "@babel/preset-typescript" {
62
- import type { PluginItem } from "@babel/core";
63
-
64
- declare const preset: PluginItem;
65
- export default preset;
66
- }
@@ -1,167 +0,0 @@
1
- import { findWorkspacesRoot } from "find-workspaces";
2
- import { $ } from "execa";
3
- import { globby } from "globby";
4
- import * as fs from "node:fs/promises";
5
- import * as path from "node:path";
6
- import { BASE_IGNORES, type BundleType } from "./build";
7
-
8
- const TO_TRANSFORM_EXTENSIONS = [".js", ".ts", ".tsx"] as const;
9
-
10
- export type VersionEnvVariables = Record<string, string | undefined>;
11
-
12
- export function getVersionEnvVariables(
13
- pkgVersion?: string,
14
- ): VersionEnvVariables {
15
- if (!pkgVersion) {
16
- throw new Error("No version found in package.json");
17
- }
18
-
19
- const [versionNumber, prerelease] = pkgVersion.split("-");
20
- const [major, minor, patch] = versionNumber.split(".");
21
-
22
- if (!major || !minor || !patch) {
23
- throw new Error(`Couldn't parse version from package.json`);
24
- }
25
-
26
- return {
27
- MUI_VERSION: pkgVersion,
28
- MUI_MAJOR_VERSION: major,
29
- MUI_MINOR_VERSION: minor,
30
- MUI_PATCH_VERSION: patch,
31
- MUI_PRERELEASE: prerelease,
32
- };
33
- }
34
-
35
- export interface CjsCopyOptions {
36
- from: string;
37
- to: string;
38
- }
39
-
40
- export async function cjsCopy({ from, to }: CjsCopyOptions): Promise<void> {
41
- const exists = await fs
42
- .stat(to)
43
- .then(() => true)
44
- .catch(() => false);
45
-
46
- if (!exists) {
47
- console.warn(`path ${to} does not exists`);
48
- return;
49
- }
50
-
51
- const files = await globby("**/*.cjs", { cwd: from });
52
-
53
- const cmds = files.map((file) =>
54
- fs.cp(path.resolve(from, file), path.resolve(to, file)),
55
- );
56
-
57
- await Promise.all(cmds);
58
- }
59
-
60
- export interface ErrorCodeMetadata {
61
- outputPath: string;
62
- runtimeModule?: string;
63
- }
64
-
65
- export interface ReactCompilerOptions {
66
- reactVersion?: string;
67
- }
68
-
69
- export interface BuildOptions {
70
- cwd: string;
71
- pkgVersion?: string;
72
- sourceDir: string;
73
- outDir: string;
74
- outExtension?: string;
75
- babelRuntimeVersion?: string;
76
- hasLargeFiles: boolean;
77
- bundle: BundleType;
78
- verbose?: boolean;
79
- optimizeClsx?: boolean;
80
- removePropTypes?: boolean;
81
- ignores?: string[];
82
- reactCompiler?: ReactCompilerOptions;
83
- }
84
-
85
- export async function build({
86
- cwd,
87
- sourceDir,
88
- outDir,
89
- babelRuntimeVersion,
90
- hasLargeFiles,
91
- bundle,
92
- pkgVersion,
93
- outExtension,
94
- optimizeClsx = false,
95
- removePropTypes = false,
96
- verbose = false,
97
- ignores = [],
98
- reactCompiler,
99
- }: BuildOptions): Promise<void> {
100
- console.log(
101
- `Transpiling files to "${path.relative(path.dirname(sourceDir), outDir)}" for "${bundle}" bundle.`,
102
- );
103
-
104
- const workspaceDir = await findWorkspacesRoot(cwd);
105
-
106
- // if (!workspaceDir) {
107
- // throw new Error(`No workspace found for ${cwd}`);
108
- // }
109
-
110
- const rootDir = workspaceDir ? workspaceDir.location : cwd;
111
-
112
- let configFile = path.join(rootDir, "babel.config.js");
113
-
114
- const exists = await fs
115
- .stat(configFile)
116
- .then(() => true)
117
- .catch(() => false);
118
-
119
- if (!exists) {
120
- configFile = path.join(rootDir, "babel.config.mjs");
121
- }
122
-
123
- const reactVersion = reactCompiler?.reactVersion;
124
-
125
- const env: Record<string, string | undefined> = {
126
- NODE_ENV: "production",
127
- BABEL_ENV: bundle === "esm" ? "stable" : "node",
128
- MUI_BUILD_VERBOSE: verbose ? "true" : undefined,
129
- MUI_OPTIMIZE_CLSX: optimizeClsx ? "true" : undefined,
130
- MUI_REMOVE_PROP_TYPES: removePropTypes ? "true" : undefined,
131
- MUI_BABEL_RUNTIME_VERSION: babelRuntimeVersion,
132
- MUI_OUT_FILE_EXTENSION: outExtension ?? ".js",
133
- ...getVersionEnvVariables(pkgVersion),
134
- MUI_REACT_COMPILER: reactVersion ? "1" : "0",
135
- MUI_REACT_COMPILER_REACT_VERSION: reactVersion,
136
- };
137
-
138
- const resolvedOutExtension = outExtension ?? ".js";
139
-
140
- const res = await $({
141
- stdio: "inherit",
142
- preferLocal: true,
143
- localDir: import.meta.dirname,
144
- env: {
145
- ...process.env,
146
- ...env,
147
- },
148
- })`babel --config-file ${configFile} --extensions ${TO_TRANSFORM_EXTENSIONS.join(
149
- ",",
150
- )} ${sourceDir} --out-dir ${outDir} --ignore ${BASE_IGNORES.concat(
151
- ignores,
152
- ).join(",")} --out-file-extension ${
153
- resolvedOutExtension !== ".js" ? resolvedOutExtension : ".js"
154
- } --compact ${hasLargeFiles ? "false" : "auto"}`;
155
-
156
- if (res.stderr) {
157
- throw new Error(
158
- `Command: '${res.escapedCommand}' failed with \n${res.stderr}`,
159
- );
160
- }
161
-
162
- if (verbose) {
163
- console.log(
164
- `Command: '${res.escapedCommand}' succeeded with \n${res.stdout}`,
165
- );
166
- }
167
- }
@@ -1,22 +0,0 @@
1
- import { loadConfig as loadC12Config } from "c12";
2
- import { BuildOptions } from "../config";
3
-
4
- export async function loadConfig(): Promise<BuildOptions> {
5
- try {
6
- const { config, configFile } = await loadC12Config<BuildOptions>({
7
- name: "sse",
8
- rcFile: false,
9
- globalRc: false,
10
- });
11
-
12
- if (configFile) {
13
- console.log(`📝 Loaded config from ${configFile}`);
14
- }
15
-
16
- return config || {};
17
- } catch (error) {
18
- console.error(`❌ Failed to parse configuration:`);
19
- console.error(error);
20
- process.exit(1);
21
- }
22
- }