@sse-ui/builder 1.1.0 → 1.3.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.
@@ -0,0 +1,12 @@
1
+ import {
2
+ build,
3
+ cjsCopy,
4
+ getVersionEnvVariables
5
+ } from "./chunk-6NNEV5YX.js";
6
+ import "./chunk-N46AJ2OI.js";
7
+ import "./chunk-MLKGABMK.js";
8
+ export {
9
+ build,
10
+ cjsCopy,
11
+ getVersionEnvVariables
12
+ };
@@ -1,3 +1,5 @@
1
+ import "./chunk-MLKGABMK.js";
2
+
1
3
  // src/babel-config.ts
2
4
  import pluginTransformRuntime from "@ssets/babel/plugin/transform-runtime";
3
5
  import presetEnv from "@ssets/babel/preset/env";
@@ -43,11 +45,11 @@ function getBaseConfig({
43
45
  pluginTransformInlineEnvVars,
44
46
  {
45
47
  include: [
46
- "MUI_VERSION",
47
- "MUI_MAJOR_VERSION",
48
- "MUI_MINOR_VERSION",
49
- "MUI_PATCH_VERSION",
50
- "MUI_PRERELEASE"
48
+ "SSE_VERSION",
49
+ "SSE_MAJOR_VERSION",
50
+ "SSE_MINOR_VERSION",
51
+ "SSE_PATCH_VERSION",
52
+ "SSE_PRERELEASE"
51
53
  ]
52
54
  },
53
55
  "babel-plugin-transform-inline-environment-variables"
@@ -125,7 +127,9 @@ function getBaseConfig({
125
127
  ],
126
128
  [presetTypescript]
127
129
  ],
128
- plugins
130
+ plugins,
131
+ minified: process.env.SSE_MINIFY === "true",
132
+ shouldPrintComment: (val) => process.env.SSE_MINIFY !== "true" || /[@#]__PURE__|license|copyright/i.test(val)
129
133
  };
130
134
  }
131
135
  function getBabelConfig(api) {
@@ -139,16 +143,16 @@ function getBabelConfig(api) {
139
143
  noResolveImports = api.noResolveImports || false;
140
144
  }
141
145
  return getBaseConfig({
142
- debug: process.env.MUI_BUILD_VERBOSE === "true",
146
+ debug: process.env.SSE_BUILD_VERBOSE === "true",
143
147
  bundle,
144
- outExtension: process.env.MUI_OUT_FILE_EXTENSION || null,
148
+ outExtension: process.env.SSE_OUT_FILE_EXTENSION || null,
145
149
  // any package needs to declare 7.25.0 as a runtime dependency. default is ^7.0.0
146
- runtimeVersion: process.env.MUI_BABEL_RUNTIME_VERSION || "^7.25.0",
147
- optimizeClsx: process.env.MUI_OPTIMIZE_CLSX === "true",
148
- removePropTypes: process.env.MUI_REMOVE_PROP_TYPES === "true",
150
+ runtimeVersion: process.env.SSE_BABEL_RUNTIME_VERSION || "^7.25.0",
151
+ optimizeClsx: process.env.SSE_OPTIMIZE_CLSX === "true",
152
+ removePropTypes: process.env.SSE_REMOVE_PROP_TYPES === "true",
149
153
  noResolveImports,
150
- reactCompilerReactVersion: process.env.MUI_REACT_COMPILER_REACT_VERSION,
151
- reactCompilerMode: process.env.MUI_REACT_COMPILER_MODE
154
+ reactCompilerReactVersion: process.env.SSE_REACT_COMPILER_REACT_VERSION,
155
+ reactCompilerMode: process.env.SSE_REACT_COMPILER_MODE
152
156
  });
153
157
  }
154
158
  export {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  BASE_IGNORES
3
- } from "./chunk-44E7L73Q.js";
3
+ } from "./chunk-N46AJ2OI.js";
4
4
 
5
5
  // src/utils/babel.ts
6
6
  import { findWorkspacesRoot } from "find-workspaces";
@@ -8,6 +8,7 @@ import { $ } from "execa";
8
8
  import { globby } from "globby";
9
9
  import * as fs from "fs/promises";
10
10
  import * as path from "path";
11
+ import chalk from "chalk";
11
12
  var TO_TRANSFORM_EXTENSIONS = [".js", ".ts", ".tsx"];
12
13
  function getVersionEnvVariables(pkgVersion) {
13
14
  if (!pkgVersion) {
@@ -19,17 +20,17 @@ function getVersionEnvVariables(pkgVersion) {
19
20
  throw new Error(`Couldn't parse version from package.json`);
20
21
  }
21
22
  return {
22
- MUI_VERSION: pkgVersion,
23
- MUI_MAJOR_VERSION: major,
24
- MUI_MINOR_VERSION: minor,
25
- MUI_PATCH_VERSION: patch,
26
- MUI_PRERELEASE: prerelease
23
+ SSE_VERSION: pkgVersion,
24
+ SSE_MAJOR_VERSION: major,
25
+ SSE_MINOR_VERSION: minor,
26
+ SSE_PATCH_VERSION: patch,
27
+ SSE_PRERELEASE: prerelease
27
28
  };
28
29
  }
29
30
  async function cjsCopy({ from, to }) {
30
31
  const exists = await fs.stat(to).then(() => true).catch(() => false);
31
32
  if (!exists) {
32
- console.warn(`path ${to} does not exists`);
33
+ console.warn(chalk.yellow(`\u26A0\uFE0F path ${to} does not exist`));
33
34
  return;
34
35
  }
35
36
  const files = await globby("**/*.cjs", { cwd: from });
@@ -51,11 +52,16 @@ async function build({
51
52
  removePropTypes = false,
52
53
  verbose = false,
53
54
  ignores = [],
54
- reactCompiler
55
+ reactCompiler,
56
+ minify = false
55
57
  }) {
56
- console.log(
57
- `Transpiling files to "${path.relative(path.dirname(sourceDir), outDir)}" for "${bundle}" bundle.`
58
- );
58
+ if (verbose) {
59
+ console.log(
60
+ chalk.blue(
61
+ `Transpiling files to "${path.relative(path.dirname(sourceDir), outDir)}" for "${bundle}" bundle.`
62
+ )
63
+ );
64
+ }
59
65
  const workspaceDir = await findWorkspacesRoot(cwd);
60
66
  const rootDir = workspaceDir ? workspaceDir.location : cwd;
61
67
  let configFile = path.join(rootDir, "babel.config.js");
@@ -67,16 +73,18 @@ async function build({
67
73
  const env = {
68
74
  NODE_ENV: "production",
69
75
  BABEL_ENV: bundle === "esm" ? "stable" : "node",
70
- MUI_BUILD_VERBOSE: verbose ? "true" : void 0,
71
- MUI_OPTIMIZE_CLSX: optimizeClsx ? "true" : void 0,
72
- MUI_REMOVE_PROP_TYPES: removePropTypes ? "true" : void 0,
73
- MUI_BABEL_RUNTIME_VERSION: babelRuntimeVersion,
74
- MUI_OUT_FILE_EXTENSION: outExtension ?? ".js",
76
+ SSE_BUILD_VERBOSE: verbose ? "true" : void 0,
77
+ SSE_OPTIMIZE_CLSX: optimizeClsx ? "true" : void 0,
78
+ SSE_REMOVE_PROP_TYPES: removePropTypes ? "true" : void 0,
79
+ SSE_BABEL_RUNTIME_VERSION: babelRuntimeVersion,
80
+ SSE_OUT_FILE_EXTENSION: outExtension ?? ".js",
75
81
  ...getVersionEnvVariables(pkgVersion),
76
- MUI_REACT_COMPILER: reactVersion ? "1" : "0",
77
- MUI_REACT_COMPILER_REACT_VERSION: reactVersion
82
+ SSE_REACT_COMPILER: reactVersion ? "1" : "0",
83
+ SSE_REACT_COMPILER_REACT_VERSION: reactVersion,
84
+ SSE_MINIFY: minify ? "true" : void 0
78
85
  };
79
86
  const resolvedOutExtension = outExtension ?? ".js";
87
+ const minifiedArgs = minify ? ["--minified"] : [];
80
88
  const res = await $({
81
89
  stdio: "inherit",
82
90
  preferLocal: true,
@@ -85,7 +93,7 @@ async function build({
85
93
  ...process.env,
86
94
  ...env
87
95
  }
88
- })`babel --config-file ${configFile} --extensions ${TO_TRANSFORM_EXTENSIONS.join(
96
+ })`babel --config-file ${configFile} ${minifiedArgs} --extensions ${TO_TRANSFORM_EXTENSIONS.join(
89
97
  ","
90
98
  )} ${sourceDir} --out-dir ${outDir} --ignore ${BASE_IGNORES.concat(
91
99
  ignores
@@ -97,14 +105,14 @@ ${res.stderr}`
97
105
  );
98
106
  }
99
107
  if (verbose) {
100
- console.log(
101
- `Command: '${res.escapedCommand}' succeeded with
102
- ${res.stdout}`
103
- );
108
+ const output = res.stdout ? `
109
+ ${res.stdout}` : "";
110
+ console.log(chalk.green(`\u2705 Babel compilation succeeded!${output}`));
104
111
  }
105
112
  }
113
+
106
114
  export {
107
- build,
115
+ getVersionEnvVariables,
108
116
  cjsCopy,
109
- getVersionEnvVariables
117
+ build
110
118
  };
@@ -0,0 +1,9 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __export = (target, all) => {
3
+ for (var name in all)
4
+ __defProp(target, name, { get: all[name], enumerable: true });
5
+ };
6
+
7
+ export {
8
+ __export
9
+ };
@@ -4,6 +4,7 @@ import * as path from "path";
4
4
  import { globby } from "globby";
5
5
  import { minimatch } from "minimatch";
6
6
  import * as semver from "semver";
7
+ import chalk from "chalk";
7
8
  function getOutExtension(bundle, options = {}) {
8
9
  const { isType = false, isFlat = false, packageType = "commonjs" } = options;
9
10
  const normalizedPackageType = packageType === "module" ? "module" : "commonjs";
@@ -185,6 +186,7 @@ async function createPackageExports({
185
186
  const buildFiles = await globby("**/*", { cwd: scanDir });
186
187
  const jsDirs = /* @__PURE__ */ new Set();
187
188
  const otherFiles = /* @__PURE__ */ new Set();
189
+ let exportableFileCount = 0;
188
190
  for (const file of buildFiles) {
189
191
  if (file.endsWith(".d.ts") || file.endsWith(".d.mts") || file.endsWith(".d.cts")) {
190
192
  continue;
@@ -193,12 +195,15 @@ async function createPackageExports({
193
195
  const normalizedFile = file.split(path.sep).join(path.posix.sep);
194
196
  if (exportExtensions.includes(ext)) {
195
197
  jsDirs.add(path.posix.dirname(normalizedFile));
198
+ exportableFileCount++;
196
199
  } else {
200
+ if (normalizedFile.endsWith("package.json")) continue;
197
201
  otherFiles.add(normalizedFile);
198
202
  }
199
203
  }
200
204
  const getIndexFileName = (type) => `index${getOutExtension(type, { isFlat, packageType: resolvedPackageType })}`;
201
205
  const rootIndexExists = await fs.stat(path.join(scanDir, getIndexFileName(baseBundle.type))).then((s) => s.isFile()).catch(() => false);
206
+ const hasOnlyRootIndex = exportableFileCount === 1 && rootIndexExists;
202
207
  if (rootIndexExists && originalExports["."] === void 0) {
203
208
  newExports["."] ??= {};
204
209
  const rootConditions = newExports["."];
@@ -226,6 +231,9 @@ async function createPackageExports({
226
231
  }
227
232
  for (const dir of jsDirs) {
228
233
  const globKey = dir === "." ? "./*" : `./${dir}/*`;
234
+ if (dir === "." && hasOnlyRootIndex) {
235
+ continue;
236
+ }
229
237
  if (originalExports[globKey] === void 0) {
230
238
  newExports[globKey] ??= {};
231
239
  const globConditions = newExports[globKey];
@@ -336,17 +344,17 @@ async function createPackageExports({
336
344
  if (typeFileExists && type === "cjs") {
337
345
  result.types = typeExportDir;
338
346
  }
339
- const exportKeys2 = Object.keys(originalExports);
340
- for (const key2 of exportKeys2) {
341
- const importPath2 = originalExports[key2];
342
- if (!importPath2) {
343
- newExports[key2] = null;
347
+ const subExportKeys = Object.keys(originalExports);
348
+ for (const subKey of subExportKeys) {
349
+ const subImportPath = originalExports[subKey];
350
+ if (!subImportPath) {
351
+ newExports[subKey] = null;
344
352
  continue;
345
353
  }
346
- if (key2 === ".") continue;
354
+ if (subKey === ".") continue;
347
355
  await createExportsFor({
348
- importPath: importPath2,
349
- key: key2,
356
+ importPath: subImportPath,
357
+ key: subKey,
350
358
  cwd,
351
359
  dir,
352
360
  type,
@@ -361,6 +369,7 @@ async function createPackageExports({
361
369
  }
362
370
  bundles.forEach(({ dir }) => {
363
371
  if (dir !== ".") {
372
+ newExports[`./${dir}/package.json`] = null;
364
373
  newExports[`./${dir}`] = null;
365
374
  newExports[`./${dir}/*`] = null;
366
375
  }
@@ -540,7 +549,8 @@ async function addLicense({
540
549
  ${content}`,
541
550
  { encoding: "utf8" }
542
551
  );
543
- if (process.env.SSE_BUILD_VERBOSE) console.log(`License added to ${file}`);
552
+ if (process.env.SSE_BUILD_VERBOSE)
553
+ console.log(chalk.gray(`License added to ${file}`));
544
554
  }
545
555
  async function writePackageJson({
546
556
  packageJson,