@sse-ui/builder 1.0.3 → 1.2.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-MBPIJFGX.js";
6
+ import "./chunk-B6FMAT44.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"
@@ -139,16 +141,16 @@ function getBabelConfig(api) {
139
141
  noResolveImports = api.noResolveImports || false;
140
142
  }
141
143
  return getBaseConfig({
142
- debug: process.env.MUI_BUILD_VERBOSE === "true",
144
+ debug: process.env.SSE_BUILD_VERBOSE === "true",
143
145
  bundle,
144
- outExtension: process.env.MUI_OUT_FILE_EXTENSION || null,
146
+ outExtension: process.env.SSE_OUT_FILE_EXTENSION || null,
145
147
  // 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",
148
+ runtimeVersion: process.env.SSE_BABEL_RUNTIME_VERSION || "^7.25.0",
149
+ optimizeClsx: process.env.SSE_OPTIMIZE_CLSX === "true",
150
+ removePropTypes: process.env.SSE_REMOVE_PROP_TYPES === "true",
149
151
  noResolveImports,
150
- reactCompilerReactVersion: process.env.MUI_REACT_COMPILER_REACT_VERSION,
151
- reactCompilerMode: process.env.MUI_REACT_COMPILER_MODE
152
+ reactCompilerReactVersion: process.env.SSE_REACT_COMPILER_REACT_VERSION,
153
+ reactCompilerMode: process.env.SSE_REACT_COMPILER_MODE
152
154
  });
153
155
  }
154
156
  export {
@@ -168,7 +168,8 @@ async function createPackageExports({
168
168
  cwd,
169
169
  addTypes = false,
170
170
  isFlat = false,
171
- packageType = "commonjs"
171
+ packageType = "commonjs",
172
+ exportExtensions = [".js", ".mjs", ".cjs"]
172
173
  }) {
173
174
  const resolvedPackageType = packageType === "module" ? "module" : "commonjs";
174
175
  const rawExports = typeof packageExports === "string" || Array.isArray(packageExports) ? { ".": packageExports } : packageExports || {};
@@ -179,8 +180,33 @@ async function createPackageExports({
179
180
  const result = {
180
181
  exports: newExports
181
182
  };
182
- await Promise.all(
183
- bundles.map(async ({ type, dir }) => {
183
+ const baseBundle = bundles.find((b) => b.type === "esm") || bundles[0];
184
+ const scanDir = isFlat ? outputDir : path.join(outputDir, baseBundle.dir);
185
+ const buildFiles = await globby("**/*", { cwd: scanDir });
186
+ const jsDirs = /* @__PURE__ */ new Set();
187
+ const otherFiles = /* @__PURE__ */ new Set();
188
+ let exportableFileCount = 0;
189
+ for (const file of buildFiles) {
190
+ if (file.endsWith(".d.ts") || file.endsWith(".d.mts") || file.endsWith(".d.cts")) {
191
+ continue;
192
+ }
193
+ const ext = path.extname(file);
194
+ const normalizedFile = file.split(path.sep).join(path.posix.sep);
195
+ if (exportExtensions.includes(ext)) {
196
+ jsDirs.add(path.posix.dirname(normalizedFile));
197
+ exportableFileCount++;
198
+ } else {
199
+ if (normalizedFile.endsWith("package.json")) continue;
200
+ otherFiles.add(normalizedFile);
201
+ }
202
+ }
203
+ const getIndexFileName = (type) => `index${getOutExtension(type, { isFlat, packageType: resolvedPackageType })}`;
204
+ const rootIndexExists = await fs.stat(path.join(scanDir, getIndexFileName(baseBundle.type))).then((s) => s.isFile()).catch(() => false);
205
+ const hasOnlyRootIndex = exportableFileCount === 1 && rootIndexExists;
206
+ if (rootIndexExists && originalExports["."] === void 0) {
207
+ newExports["."] ??= {};
208
+ const rootConditions = newExports["."];
209
+ for (const { type, dir: bundleDir } of bundles) {
184
210
  const outExtension = getOutExtension(type, {
185
211
  isFlat,
186
212
  packageType: resolvedPackageType
@@ -190,59 +216,161 @@ async function createPackageExports({
190
216
  isType: true,
191
217
  packageType: resolvedPackageType
192
218
  });
193
- const indexFileExists = await fs.stat(path.join(outputDir, dir, `index${outExtension}`)).then(
194
- (stats) => stats.isFile(),
195
- () => false
196
- );
197
- const typeFileExists = addTypes && await fs.stat(path.join(outputDir, dir, `index${typeOutExtension}`)).then(
198
- (stats) => stats.isFile(),
199
- () => false
200
- );
201
- const dirPrefix = dir === "." ? "" : `${dir}/`;
202
- const exportDir = `./${dirPrefix}index${outExtension}`;
203
- const typeExportDir = `./${dirPrefix}index${typeOutExtension}`;
204
- if (indexFileExists) {
205
- if (type === "cjs") {
206
- result.main = exportDir;
207
- }
208
- if (typeof newExports["."] === "string" || Array.isArray(newExports["."])) {
209
- throw new Error(
210
- `The export "." is already defined as a string or Array.`
211
- );
212
- }
213
- newExports["."] ??= {};
214
- newExports["."][type === "cjs" ? "require" : "import"] = typeFileExists ? {
215
- types: typeExportDir,
216
- default: exportDir
217
- } : exportDir;
219
+ const dirPrefix = bundleDir === "." ? "" : `${bundleDir}/`;
220
+ const exportPath = `./${dirPrefix}index${outExtension}`;
221
+ const typeExportPath = `./${dirPrefix}index${typeOutExtension}`;
222
+ const typeExists = addTypes && await fs.stat(path.join(outputDir, bundleDir, `index${typeOutExtension}`)).then((s) => s.isFile()).catch(() => false);
223
+ const conditionKey = type === "cjs" ? "require" : "import";
224
+ rootConditions[conditionKey] = typeExists ? { types: typeExportPath, default: exportPath } : exportPath;
225
+ if (type === "cjs" || type === "esm" && bundles.length === 1) {
226
+ result.main = exportPath;
227
+ if (typeExists) result.types = typeExportPath;
218
228
  }
219
- if (typeFileExists && type === "cjs") {
220
- result.types = typeExportDir;
229
+ }
230
+ }
231
+ for (const dir of jsDirs) {
232
+ const globKey = dir === "." ? "./*" : `./${dir}/*`;
233
+ if (dir === "." && hasOnlyRootIndex) {
234
+ continue;
235
+ }
236
+ if (originalExports[globKey] === void 0) {
237
+ newExports[globKey] ??= {};
238
+ const globConditions = newExports[globKey];
239
+ for (const { type, dir: bundleDir } of bundles) {
240
+ const outExtension = getOutExtension(type, {
241
+ isFlat,
242
+ packageType: resolvedPackageType
243
+ });
244
+ const typeOutExtension = getOutExtension(type, {
245
+ isFlat,
246
+ isType: true,
247
+ packageType: resolvedPackageType
248
+ });
249
+ const dirPrefix = bundleDir === "." ? "" : `${bundleDir}/`;
250
+ const basePath = dir === "." ? "" : `${dir}/`;
251
+ const exportPath = `./${dirPrefix}${basePath}*${outExtension}`;
252
+ const typeExportPath = `./${dirPrefix}${basePath}*${typeOutExtension}`;
253
+ const conditionKey = type === "cjs" ? "require" : "import";
254
+ globConditions[conditionKey] = addTypes ? { types: typeExportPath, default: exportPath } : exportPath;
221
255
  }
222
- const exportKeys = Object.keys(originalExports);
223
- for (const key of exportKeys) {
224
- const importPath = originalExports[key];
225
- if (!importPath) {
226
- newExports[key] = null;
227
- continue;
256
+ }
257
+ if (dir !== ".") {
258
+ const dirIndexExists = await fs.stat(path.posix.join(scanDir, dir, getIndexFileName(baseBundle.type))).then((s) => s.isFile()).catch(() => false);
259
+ const dirKey = `./${dir}`;
260
+ if (dirIndexExists && originalExports[dirKey] === void 0) {
261
+ newExports[dirKey] ??= {};
262
+ const dirConditions = newExports[dirKey];
263
+ for (const { type, dir: bundleDir } of bundles) {
264
+ const outExtension = getOutExtension(type, {
265
+ isFlat,
266
+ packageType: resolvedPackageType
267
+ });
268
+ const typeOutExtension = getOutExtension(type, {
269
+ isFlat,
270
+ isType: true,
271
+ packageType: resolvedPackageType
272
+ });
273
+ const dirPrefix = bundleDir === "." ? "" : `${bundleDir}/`;
274
+ const basePath = `${dir}/`;
275
+ const exportPath = `./${dirPrefix}${basePath}index${outExtension}`;
276
+ const typeExportPath = `./${dirPrefix}${basePath}index${typeOutExtension}`;
277
+ const typeExists = addTypes && await fs.stat(
278
+ path.join(
279
+ outputDir,
280
+ bundleDir,
281
+ dir,
282
+ `index${typeOutExtension}`
283
+ )
284
+ ).then((s) => s.isFile()).catch(() => false);
285
+ const conditionKey = type === "cjs" ? "require" : "import";
286
+ dirConditions[conditionKey] = typeExists ? { types: typeExportPath, default: exportPath } : exportPath;
228
287
  }
229
- await createExportsFor({
230
- importPath,
231
- key,
232
- cwd,
233
- dir,
234
- type,
235
- newExports,
236
- typeOutExtension,
237
- outExtension,
238
- addTypes
239
- });
240
288
  }
241
- })
242
- );
289
+ }
290
+ }
291
+ for (const file of otherFiles) {
292
+ const exportKey = `./${file}`;
293
+ if (originalExports[exportKey] !== void 0) continue;
294
+ const dirPrefix = baseBundle.dir === "." ? "" : `${baseBundle.dir}/`;
295
+ newExports[exportKey] = `./${dirPrefix}${file}`;
296
+ }
297
+ const exportKeys = Object.keys(originalExports);
298
+ for (const key of exportKeys) {
299
+ const importPath = originalExports[key];
300
+ if (!importPath) {
301
+ newExports[key] = null;
302
+ continue;
303
+ }
304
+ if (key === ".") continue;
305
+ await Promise.all(
306
+ bundles.map(async ({ type, dir }) => {
307
+ const outExtension = getOutExtension(type, {
308
+ isFlat,
309
+ packageType: resolvedPackageType
310
+ });
311
+ const typeOutExtension = getOutExtension(type, {
312
+ isFlat,
313
+ isType: true,
314
+ packageType: resolvedPackageType
315
+ });
316
+ const indexFileExists = await fs.stat(path.join(outputDir, dir, `index${outExtension}`)).then(
317
+ (stats) => stats.isFile(),
318
+ () => false
319
+ );
320
+ const typeFileExists = addTypes && await fs.stat(path.join(outputDir, dir, `index${typeOutExtension}`)).then(
321
+ (stats) => stats.isFile(),
322
+ () => false
323
+ );
324
+ const dirPrefix = dir === "." ? "" : `${dir}/`;
325
+ const exportDir = `./${dirPrefix}index${outExtension}`;
326
+ const typeExportDir = `./${dirPrefix}index${typeOutExtension}`;
327
+ if (indexFileExists && originalExports["."] !== void 0) {
328
+ if (type === "cjs") {
329
+ result.main = exportDir;
330
+ }
331
+ if (typeof newExports["."] === "string" || Array.isArray(newExports["."])) {
332
+ throw new Error(
333
+ `The export "." is already defined as a string or Array.`
334
+ );
335
+ }
336
+ newExports["."] ??= {};
337
+ const rootConditions = newExports["."];
338
+ rootConditions[type === "cjs" ? "require" : "import"] = typeFileExists ? {
339
+ types: typeExportDir,
340
+ default: exportDir
341
+ } : exportDir;
342
+ }
343
+ if (typeFileExists && type === "cjs") {
344
+ result.types = typeExportDir;
345
+ }
346
+ const subExportKeys = Object.keys(originalExports);
347
+ for (const subKey of subExportKeys) {
348
+ const subImportPath = originalExports[subKey];
349
+ if (!subImportPath) {
350
+ newExports[subKey] = null;
351
+ continue;
352
+ }
353
+ if (subKey === ".") continue;
354
+ await createExportsFor({
355
+ importPath: subImportPath,
356
+ key: subKey,
357
+ cwd,
358
+ dir,
359
+ type,
360
+ newExports,
361
+ typeOutExtension,
362
+ outExtension,
363
+ addTypes
364
+ });
365
+ }
366
+ })
367
+ );
368
+ }
243
369
  bundles.forEach(({ dir }) => {
244
370
  if (dir !== ".") {
371
+ newExports[`./${dir}/package.json`] = null;
245
372
  newExports[`./${dir}`] = null;
373
+ newExports[`./${dir}/*`] = null;
246
374
  }
247
375
  });
248
376
  Object.keys(newExports).forEach((key) => {
@@ -390,12 +518,101 @@ async function mapConcurrently(items, mapper, concurrency) {
390
518
  await Promise.all(workers);
391
519
  return results;
392
520
  }
521
+ async function addLicense({
522
+ name,
523
+ version,
524
+ license,
525
+ bundle,
526
+ outputDir,
527
+ isFlat,
528
+ packageType
529
+ }) {
530
+ const outExtension = getOutExtension(bundle, { isFlat, packageType });
531
+ const file = path.join(outputDir, `index${outExtension}`);
532
+ if (!await fs.stat(file).then(
533
+ (stats) => stats.isFile(),
534
+ () => false
535
+ )) {
536
+ return;
537
+ }
538
+ const content = await fs.readFile(file, { encoding: "utf8" });
539
+ await fs.writeFile(
540
+ file,
541
+ `/**
542
+ * ${name} v${version}
543
+ *
544
+ * @license ${license}
545
+ * This source code is licensed under the ${license} license found in the
546
+ * LICENSE file in the root directory of this source tree.
547
+ */
548
+ ${content}`,
549
+ { encoding: "utf8" }
550
+ );
551
+ if (process.env.SSE_BUILD_VERBOSE) console.log(`License added to ${file}`);
552
+ }
553
+ async function writePackageJson({
554
+ packageJson,
555
+ bundles,
556
+ outputDir,
557
+ cwd,
558
+ addTypes = false,
559
+ isFlat = false,
560
+ packageType,
561
+ exportExtensions
562
+ }) {
563
+ delete packageJson.scripts;
564
+ delete packageJson.publishConfig?.directory;
565
+ delete packageJson.devDependencies;
566
+ delete packageJson.imports;
567
+ const resolvedPackageType = packageType || packageJson.type || "commonjs";
568
+ packageJson.type = resolvedPackageType;
569
+ const originalExports = packageJson.exports;
570
+ delete packageJson.exports;
571
+ const originalBin = packageJson.bin;
572
+ delete packageJson.bin;
573
+ const {
574
+ exports: packageExports,
575
+ main,
576
+ types
577
+ } = await createPackageExports({
578
+ exports: originalExports,
579
+ bundles,
580
+ outputDir,
581
+ cwd,
582
+ addTypes,
583
+ isFlat,
584
+ packageType: resolvedPackageType,
585
+ exportExtensions
586
+ });
587
+ packageJson.exports = packageExports;
588
+ if (main) {
589
+ packageJson.main = main;
590
+ }
591
+ if (types) {
592
+ packageJson.types = types;
593
+ }
594
+ const bin = await createPackageBin({
595
+ bin: originalBin,
596
+ bundles,
597
+ cwd,
598
+ isFlat,
599
+ packageType: resolvedPackageType
600
+ });
601
+ if (bin) {
602
+ packageJson.bin = bin;
603
+ }
604
+ await fs.writeFile(
605
+ path.join(outputDir, "package.json"),
606
+ JSON.stringify(packageJson, null, 2),
607
+ "utf-8"
608
+ );
609
+ }
393
610
 
394
611
  export {
395
612
  getOutExtension,
396
- createPackageExports,
397
- createPackageBin,
398
613
  validatePkgJson,
399
614
  BASE_IGNORES,
400
- mapConcurrently
615
+ mapConcurrently,
616
+ addLicense,
617
+ writePackageJson
401
618
  };
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  BASE_IGNORES
3
- } from "./chunk-5S2N5WDQ.js";
3
+ } from "./chunk-B6FMAT44.js";
4
4
 
5
5
  // src/utils/babel.ts
6
6
  import { findWorkspacesRoot } from "find-workspaces";
@@ -19,11 +19,11 @@ function getVersionEnvVariables(pkgVersion) {
19
19
  throw new Error(`Couldn't parse version from package.json`);
20
20
  }
21
21
  return {
22
- MUI_VERSION: pkgVersion,
23
- MUI_MAJOR_VERSION: major,
24
- MUI_MINOR_VERSION: minor,
25
- MUI_PATCH_VERSION: patch,
26
- MUI_PRERELEASE: prerelease
22
+ SSE_VERSION: pkgVersion,
23
+ SSE_MAJOR_VERSION: major,
24
+ SSE_MINOR_VERSION: minor,
25
+ SSE_PATCH_VERSION: patch,
26
+ SSE_PRERELEASE: prerelease
27
27
  };
28
28
  }
29
29
  async function cjsCopy({ from, to }) {
@@ -53,9 +53,11 @@ async function build({
53
53
  ignores = [],
54
54
  reactCompiler
55
55
  }) {
56
- console.log(
57
- `Transpiling files to "${path.relative(path.dirname(sourceDir), outDir)}" for "${bundle}" bundle.`
58
- );
56
+ if (verbose) {
57
+ console.log(
58
+ `Transpiling files to "${path.relative(path.dirname(sourceDir), outDir)}" for "${bundle}" bundle.`
59
+ );
60
+ }
59
61
  const workspaceDir = await findWorkspacesRoot(cwd);
60
62
  const rootDir = workspaceDir ? workspaceDir.location : cwd;
61
63
  let configFile = path.join(rootDir, "babel.config.js");
@@ -67,14 +69,14 @@ async function build({
67
69
  const env = {
68
70
  NODE_ENV: "production",
69
71
  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",
72
+ SSE_BUILD_VERBOSE: verbose ? "true" : void 0,
73
+ SSE_OPTIMIZE_CLSX: optimizeClsx ? "true" : void 0,
74
+ SSE_REMOVE_PROP_TYPES: removePropTypes ? "true" : void 0,
75
+ SSE_BABEL_RUNTIME_VERSION: babelRuntimeVersion,
76
+ SSE_OUT_FILE_EXTENSION: outExtension ?? ".js",
75
77
  ...getVersionEnvVariables(pkgVersion),
76
- MUI_REACT_COMPILER: reactVersion ? "1" : "0",
77
- MUI_REACT_COMPILER_REACT_VERSION: reactVersion
78
+ SSE_REACT_COMPILER: reactVersion ? "1" : "0",
79
+ SSE_REACT_COMPILER_REACT_VERSION: reactVersion
78
80
  };
79
81
  const resolvedOutExtension = outExtension ?? ".js";
80
82
  const res = await $({
@@ -103,8 +105,9 @@ ${res.stdout}`
103
105
  );
104
106
  }
105
107
  }
108
+
106
109
  export {
107
- build,
110
+ getVersionEnvVariables,
108
111
  cjsCopy,
109
- getVersionEnvVariables
112
+ build
110
113
  };
@@ -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
+ };