@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.
@@ -0,0 +1,39 @@
1
+ import { B as BundleType } from './build-DZbrXe0V.js';
2
+
3
+ interface BuildOptions {
4
+ /** The bundles to build. */
5
+ bundle: BundleType[];
6
+ /** The large files to build. */
7
+ hasLargeFiles: boolean;
8
+ /** Whether to skip generating a package.json file in the /esm folder. */
9
+ skipBundlePackageJson: boolean;
10
+ /** Whether to enable verbose logging. */
11
+ verbose: boolean;
12
+ /** Whether to build types for the package. */
13
+ buildTypes: boolean;
14
+ /** Whether to build types for the package. */
15
+ skipTsc: boolean;
16
+ /** Whether to skip checking for Babel runtime dependencies in the package. */
17
+ skipBabelRuntimeCheck: boolean;
18
+ /** Whether to skip generating the package.json file in the bundle output. */
19
+ skipPackageJson: boolean;
20
+ /** Whether to skip checking for main field in package.json. */
21
+ skipMainCheck: boolean;
22
+ /** Globs to be ignored by Babel. */
23
+ ignore: string[];
24
+ /** Files/Directories to be copied. Can be a glob pattern. */
25
+ copy: string[];
26
+ /** Whether to use the React compiler. */
27
+ enableReactCompiler: boolean;
28
+ /** Whether to build types using typescript native (tsgo). */
29
+ tsgo: boolean;
30
+ /** Builds the package in a flat structure without subdirectories for each module type. */
31
+ flat: boolean;
32
+ }
33
+
34
+ /**
35
+ * Helper to provide autocomplete and type checking for the sse-tools config.
36
+ */
37
+ declare function defineConfig(config: BuildOptions): BuildOptions;
38
+
39
+ export { type BuildOptions, defineConfig };
package/dist/config.js ADDED
@@ -0,0 +1,7 @@
1
+ // src/config.ts
2
+ function defineConfig(config) {
3
+ return config;
4
+ }
5
+ export {
6
+ defineConfig
7
+ };
@@ -0,0 +1,217 @@
1
+ import {
2
+ getOutExtension,
3
+ mapConcurrently
4
+ } from "./chunk-5S2N5WDQ.js";
5
+
6
+ // src/utils/typescript.ts
7
+ import * as babel from "@babel/core";
8
+ import pluginTypescriptSyntax from "@ssets/babel/plugin/syntax-typescript";
9
+ import pluginResolveImports from "@ssets/babel/plugin/resolve-imports";
10
+ import { findWorkspacesRoot } from "find-workspaces";
11
+ import pluginRemoveImports from "@ssets/babel/plugin/transform-remove-imports";
12
+ import { $ } from "execa";
13
+ import { globby } from "globby";
14
+ import * as fs from "fs/promises";
15
+ import * as os from "os";
16
+ import * as path from "path";
17
+ var $$ = $({ stdio: "inherit" });
18
+ async function findTsgo(cwd) {
19
+ const workspaceDir = await findWorkspacesRoot(cwd);
20
+ if (!workspaceDir) {
21
+ return null;
22
+ }
23
+ const tsgoPath = path.join(
24
+ workspaceDir.location,
25
+ "node_modules",
26
+ ".bin",
27
+ "tsgo"
28
+ );
29
+ const exists = await fs.stat(tsgoPath).then(
30
+ (stat2) => stat2.isFile(),
31
+ () => false
32
+ );
33
+ return exists ? tsgoPath : null;
34
+ }
35
+ async function emitDeclarations(tsconfig, outDir, options = {}) {
36
+ const { useTsgo = false } = options ?? {};
37
+ const tsconfigDir = path.dirname(tsconfig);
38
+ const rootDir = path.resolve(tsconfigDir, "./src");
39
+ const tsgoPath = useTsgo ? await findTsgo(tsconfigDir) : null;
40
+ if (useTsgo && !tsgoPath) {
41
+ throw new Error(
42
+ '--tsgo flag was passed or MUI_USE_TSGO environment was set but no tsgo cli was found. Either remove the flag to use tsc or install the native package "@typescript/native-preview" at the workspace level to use tsgo.'
43
+ );
44
+ }
45
+ if (tsgoPath) {
46
+ console.log("Using tsgo for declaration emit");
47
+ await $$`${tsgoPath}
48
+ -p ${tsconfig}
49
+ --rootDir ${rootDir}
50
+ --outDir ${outDir}
51
+ --declaration
52
+ --emitDeclarationOnly
53
+ --noEmit false
54
+ --composite false
55
+ --incremental false
56
+ --declarationMap false`;
57
+ } else {
58
+ await $$`tsc
59
+ -p ${tsconfig}
60
+ --rootDir ${rootDir}
61
+ --outDir ${outDir}
62
+ --declaration
63
+ --emitDeclarationOnly
64
+ --noEmit false
65
+ --composite false
66
+ --incremental false
67
+ --declarationMap false`;
68
+ }
69
+ }
70
+ async function copyDeclarations(sourceDirectory, destinationDirectory, options = {}) {
71
+ const fullSourceDirectory = path.resolve(sourceDirectory);
72
+ const fullDestinationDirectory = path.resolve(destinationDirectory);
73
+ if (options.verbose) {
74
+ console.log(
75
+ `Copying declarations from ${fullSourceDirectory} to ${fullDestinationDirectory}`
76
+ );
77
+ }
78
+ await fs.cp(fullSourceDirectory, fullDestinationDirectory, {
79
+ recursive: true,
80
+ filter: async (src) => {
81
+ if (path.basename(src).startsWith(".")) {
82
+ return false;
83
+ }
84
+ const stats = await fs.stat(src);
85
+ if (stats.isDirectory()) {
86
+ return true;
87
+ }
88
+ return src.endsWith(".d.ts") || src.endsWith(".d.mts") || src.endsWith(".d.cts");
89
+ }
90
+ });
91
+ }
92
+ async function moveAndTransformDeclarations({
93
+ inputDir,
94
+ buildDir,
95
+ bundles,
96
+ isFlat,
97
+ packageType
98
+ }) {
99
+ const toCopyDir = bundles.length === 1 ? path.join(buildDir, bundles[0].dir) : buildDir;
100
+ await fs.cp(inputDir, toCopyDir, {
101
+ recursive: true,
102
+ force: false
103
+ });
104
+ const dtsFiles = await globby("**/*.d.ts", {
105
+ absolute: true,
106
+ cwd: toCopyDir
107
+ });
108
+ if (dtsFiles.length === 0) {
109
+ console.log(
110
+ `No d.ts files found in ${toCopyDir}. Skipping transformation.`
111
+ );
112
+ return;
113
+ }
114
+ await mapConcurrently(
115
+ dtsFiles,
116
+ async (dtsFile) => {
117
+ const nativeDtsFile = path.normalize(dtsFile);
118
+ const content = await fs.readFile(nativeDtsFile, "utf8");
119
+ const relativePath = path.relative(toCopyDir, nativeDtsFile);
120
+ const writesToOriginalPath = isFlat && bundles.some((bundle) => {
121
+ const newFileExtension = getOutExtension(bundle.type, {
122
+ isFlat,
123
+ isType: true,
124
+ packageType
125
+ });
126
+ const outFileRelative = relativePath.replace(
127
+ /\.d\.ts$/,
128
+ newFileExtension
129
+ );
130
+ const outFilePath = path.join(buildDir, bundle.dir, outFileRelative);
131
+ return path.resolve(outFilePath) === path.resolve(nativeDtsFile);
132
+ });
133
+ await Promise.all(
134
+ bundles.map(async (bundle) => {
135
+ const importExtension = getOutExtension(bundle.type, {
136
+ isFlat,
137
+ packageType
138
+ });
139
+ const newFileExtension = getOutExtension(bundle.type, {
140
+ isFlat,
141
+ isType: true,
142
+ packageType
143
+ });
144
+ const outFileRelative = isFlat ? relativePath.replace(/\.d\.ts$/, newFileExtension) : relativePath;
145
+ const outFilePath = path.join(buildDir, bundle.dir, outFileRelative);
146
+ const babelPlugins = [
147
+ [pluginTypescriptSyntax, { dts: true }],
148
+ [pluginResolveImports, { outExtension: importExtension }],
149
+ [pluginRemoveImports, { test: /\.css$/ }]
150
+ ];
151
+ const result = await babel.transformAsync(content, {
152
+ configFile: false,
153
+ plugins: babelPlugins,
154
+ filename: nativeDtsFile
155
+ });
156
+ if (typeof result?.code === "string") {
157
+ await fs.mkdir(path.dirname(outFilePath), { recursive: true });
158
+ await fs.writeFile(outFilePath, result.code);
159
+ } else {
160
+ console.error("failed to transform", dtsFile);
161
+ }
162
+ })
163
+ );
164
+ if (isFlat && !writesToOriginalPath) {
165
+ await fs.unlink(nativeDtsFile);
166
+ }
167
+ },
168
+ 30
169
+ );
170
+ }
171
+ async function createTypes({
172
+ bundles,
173
+ srcDir,
174
+ buildDir,
175
+ cwd,
176
+ skipTsc,
177
+ useTsgo = false,
178
+ isFlat = false,
179
+ packageType,
180
+ verbose
181
+ }) {
182
+ const tmpDir = await fs.mkdtemp(
183
+ path.join(os.tmpdir(), "code-infra-build-tsc-")
184
+ );
185
+ try {
186
+ await copyDeclarations(srcDir, tmpDir, { verbose });
187
+ const tsconfigPath = path.join(cwd, "tsconfig.build.json");
188
+ const tsconfigExists = await fs.stat(tsconfigPath).then(
189
+ (file) => file.isFile(),
190
+ () => false
191
+ );
192
+ if (!skipTsc) {
193
+ if (!tsconfigExists) {
194
+ throw new Error(
195
+ `Unable to find a tsconfig to build this project. The package root needs to contain a 'tsconfig.build.json'. The package root is '${cwd}'`
196
+ );
197
+ }
198
+ console.log(`Building types for ${tsconfigPath} in ${tmpDir}`);
199
+ await emitDeclarations(tsconfigPath, tmpDir, { useTsgo });
200
+ }
201
+ await moveAndTransformDeclarations({
202
+ inputDir: tmpDir,
203
+ buildDir,
204
+ bundles,
205
+ isFlat,
206
+ packageType
207
+ });
208
+ } finally {
209
+ await fs.rm(tmpDir, { recursive: true, force: true });
210
+ }
211
+ }
212
+ export {
213
+ copyDeclarations,
214
+ createTypes,
215
+ emitDeclarations,
216
+ moveAndTransformDeclarations
217
+ };
package/package.json CHANGED
@@ -1,14 +1,16 @@
1
1
  {
2
2
  "name": "@sse-ui/builder",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "Builder By SSE",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "build": "tsup",
8
8
  "prepublish": "npm run build"
9
9
  },
10
+ "main": "./bin/sse-tools.js",
11
+ "files": ["bin", "dist"],
10
12
  "bin": {
11
- "@sse-ui/builder": "./bin/sse-tools.js"
13
+ "sse-tool": "./bin/sse-tools.js"
12
14
  },
13
15
  "exports": {
14
16
  "./babel-config": {
package/src/cli.ts DELETED
@@ -1,44 +0,0 @@
1
- #!/usr/bin/env node
2
- import { Command } from "commander";
3
- import { buildCommand } from "./core/build";
4
- import { publishCommand } from "./core/publish";
5
- import { cleanCommand } from "./core/clean";
6
- import { typecheckCommand } from "./core/typecheck";
7
- import { packCommand } from "./core/pack";
8
- import { versionCommand } from "./core/version";
9
- import { infoCommand } from "./core/info";
10
- import { linkCommand } from "./core/link";
11
- import { checkExportsCommand } from "./core/check-exports";
12
- import { watchCommand } from "./core/watch";
13
-
14
- async function main() {
15
- const program = new Command();
16
-
17
- program
18
- .name("sse-tools")
19
- .description("CLI utilities for managing and building MUI packages")
20
- .version("1.0.0");
21
-
22
- program.addCommand(buildCommand);
23
- program.addCommand(publishCommand);
24
- program.addCommand(cleanCommand);
25
- program.addCommand(typecheckCommand);
26
- program.addCommand(packCommand);
27
- program.addCommand(versionCommand);
28
- program.addCommand(infoCommand);
29
- program.addCommand(linkCommand);
30
- program.addCommand(checkExportsCommand);
31
- program.addCommand(watchCommand);
32
-
33
- try {
34
- await program.parseAsync(process.argv);
35
- } catch (error) {
36
- console.error("Error executing command:");
37
- if (error instanceof Error) {
38
- console.error(error.message);
39
- }
40
- process.exit(1);
41
- }
42
- }
43
-
44
- main();
package/src/config.ts DELETED
@@ -1,10 +0,0 @@
1
- import { BuildOptions } from "./core/build";
2
-
3
- export type { BuildOptions };
4
-
5
- /**
6
- * Helper to provide autocomplete and type checking for the sse-tools config.
7
- */
8
- export function defineConfig(config: BuildOptions): BuildOptions {
9
- return config;
10
- }