@sse-ui/builder 1.0.0 → 1.0.1

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,110 @@
1
+ import {
2
+ BASE_IGNORES
3
+ } from "./chunk-5S2N5WDQ.js";
4
+
5
+ // src/utils/babel.ts
6
+ import { findWorkspacesRoot } from "find-workspaces";
7
+ import { $ } from "execa";
8
+ import { globby } from "globby";
9
+ import * as fs from "fs/promises";
10
+ import * as path from "path";
11
+ var TO_TRANSFORM_EXTENSIONS = [".js", ".ts", ".tsx"];
12
+ function getVersionEnvVariables(pkgVersion) {
13
+ if (!pkgVersion) {
14
+ throw new Error("No version found in package.json");
15
+ }
16
+ const [versionNumber, prerelease] = pkgVersion.split("-");
17
+ const [major, minor, patch] = versionNumber.split(".");
18
+ if (!major || !minor || !patch) {
19
+ throw new Error(`Couldn't parse version from package.json`);
20
+ }
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
27
+ };
28
+ }
29
+ async function cjsCopy({ from, to }) {
30
+ const exists = await fs.stat(to).then(() => true).catch(() => false);
31
+ if (!exists) {
32
+ console.warn(`path ${to} does not exists`);
33
+ return;
34
+ }
35
+ const files = await globby("**/*.cjs", { cwd: from });
36
+ const cmds = files.map(
37
+ (file) => fs.cp(path.resolve(from, file), path.resolve(to, file))
38
+ );
39
+ await Promise.all(cmds);
40
+ }
41
+ async function build({
42
+ cwd,
43
+ sourceDir,
44
+ outDir,
45
+ babelRuntimeVersion,
46
+ hasLargeFiles,
47
+ bundle,
48
+ pkgVersion,
49
+ outExtension,
50
+ optimizeClsx = false,
51
+ removePropTypes = false,
52
+ verbose = false,
53
+ ignores = [],
54
+ reactCompiler
55
+ }) {
56
+ console.log(
57
+ `Transpiling files to "${path.relative(path.dirname(sourceDir), outDir)}" for "${bundle}" bundle.`
58
+ );
59
+ const workspaceDir = await findWorkspacesRoot(cwd);
60
+ const rootDir = workspaceDir ? workspaceDir.location : cwd;
61
+ let configFile = path.join(rootDir, "babel.config.js");
62
+ const exists = await fs.stat(configFile).then(() => true).catch(() => false);
63
+ if (!exists) {
64
+ configFile = path.join(rootDir, "babel.config.mjs");
65
+ }
66
+ const reactVersion = reactCompiler?.reactVersion;
67
+ const env = {
68
+ NODE_ENV: "production",
69
+ 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",
75
+ ...getVersionEnvVariables(pkgVersion),
76
+ MUI_REACT_COMPILER: reactVersion ? "1" : "0",
77
+ MUI_REACT_COMPILER_REACT_VERSION: reactVersion
78
+ };
79
+ const resolvedOutExtension = outExtension ?? ".js";
80
+ const res = await $({
81
+ stdio: "inherit",
82
+ preferLocal: true,
83
+ localDir: import.meta.dirname,
84
+ env: {
85
+ ...process.env,
86
+ ...env
87
+ }
88
+ })`babel --config-file ${configFile} --extensions ${TO_TRANSFORM_EXTENSIONS.join(
89
+ ","
90
+ )} ${sourceDir} --out-dir ${outDir} --ignore ${BASE_IGNORES.concat(
91
+ ignores
92
+ ).join(",")} --out-file-extension ${resolvedOutExtension !== ".js" ? resolvedOutExtension : ".js"} --compact ${hasLargeFiles ? "false" : "auto"}`;
93
+ if (res.stderr) {
94
+ throw new Error(
95
+ `Command: '${res.escapedCommand}' failed with
96
+ ${res.stderr}`
97
+ );
98
+ }
99
+ if (verbose) {
100
+ console.log(
101
+ `Command: '${res.escapedCommand}' succeeded with
102
+ ${res.stdout}`
103
+ );
104
+ }
105
+ }
106
+ export {
107
+ build,
108
+ cjsCopy,
109
+ getVersionEnvVariables
110
+ };
@@ -0,0 +1,23 @@
1
+ import { B as BundleType } from './build-DZbrXe0V.js';
2
+ import { ConfigAPI, TransformOptions } from '@babel/core';
3
+
4
+ interface GetBaseConfigOptions {
5
+ debug: boolean;
6
+ optimizeClsx: boolean;
7
+ removePropTypes: boolean;
8
+ noResolveImports: boolean;
9
+ bundle: BundleType;
10
+ outExtension: string | null;
11
+ runtimeVersion: string;
12
+ reactCompilerReactVersion?: string;
13
+ reactCompilerMode?: string;
14
+ }
15
+ declare function getBaseConfig({ debug, optimizeClsx, removePropTypes, noResolveImports, bundle, runtimeVersion, outExtension, reactCompilerReactVersion, reactCompilerMode, }: GetBaseConfigOptions): TransformOptions;
16
+ interface GetBabelConfigOptions {
17
+ bundle: BundleType;
18
+ noResolveImports: boolean;
19
+ env: any;
20
+ }
21
+ declare function getBabelConfig(api: ConfigAPI | GetBabelConfigOptions): TransformOptions;
22
+
23
+ export { getBabelConfig as default, getBaseConfig };
@@ -1,189 +1,157 @@
1
- import pluginTransformRuntime from "@ssets/babel/plugin/transform-runtime";
2
- import presetEnv, { Options as EnvOptions } from "@ssets/babel/preset/env";
3
- import presetReact from "@babel/preset-react";
4
- import presetTypescript from "@babel/preset-typescript";
5
- import pluginDisplayName from "@ssets/babel/plugin/display-name";
6
- import pluginResolveImports from "@ssets/babel/plugin/resolve-imports";
7
- import pluginOptimizeClsx from "babel-plugin-optimize-clsx";
8
- import pluginReactCompiler, {
9
- PluginOptions as BabelReactPluginOptions,
10
- } from "babel-plugin-react-compiler";
11
- import pluginTransformImportMeta from "babel-plugin-transform-import-meta";
12
- import pluginTransformInlineEnvVars from "babel-plugin-transform-inline-environment-variables";
13
- import pluginRemovePropTypes from "babel-plugin-transform-react-remove-prop-types";
14
- import { BundleType } from "./utils/build";
15
- import { TransformOptions, ConfigAPI } from "@babel/core";
16
-
17
- interface GetBaseConfigOptions {
18
- debug: boolean;
19
- optimizeClsx: boolean;
20
- removePropTypes: boolean;
21
- noResolveImports: boolean;
22
- bundle: BundleType;
23
- outExtension: string | null;
24
- runtimeVersion: string;
25
- reactCompilerReactVersion?: string;
26
- reactCompilerMode?: string;
27
- }
28
-
29
- export function getBaseConfig({
30
- debug = false,
31
- optimizeClsx = false,
32
- removePropTypes = false,
33
- noResolveImports = false,
34
- bundle,
35
- runtimeVersion,
36
- outExtension,
37
- reactCompilerReactVersion,
38
- reactCompilerMode,
39
- }: GetBaseConfigOptions): TransformOptions {
40
- const presetEnvOptions: EnvOptions = {
41
- bugfixes: true,
42
- debug,
43
- modules: bundle === "esm" ? false : "commonjs",
44
- // @TODO
45
- browserslistEnv: bundle === "esm" ? "stable" : "node",
46
- };
47
-
48
- const plugins: TransformOptions["plugins"] = [
49
- [
50
- pluginTransformRuntime,
51
- {
52
- version: runtimeVersion,
53
- regenerator: false,
54
- useESModules: bundle === "esm",
55
- },
56
- "@babel/plugin-transform-runtime",
57
- ],
58
- [pluginDisplayName, {}, "babel-plugin-display-name"],
59
- [
60
- pluginTransformInlineEnvVars,
61
- {
62
- include: [
63
- "MUI_VERSION",
64
- "MUI_MAJOR_VERSION",
65
- "MUI_MINOR_VERSION",
66
- "MUI_PATCH_VERSION",
67
- "MUI_PRERELEASE",
68
- ],
69
- },
70
- "babel-plugin-transform-inline-environment-variables",
71
- ],
72
- ];
73
-
74
- if (bundle !== "esm") {
75
- plugins.push([
76
- pluginTransformImportMeta,
77
- {},
78
- "babel-plugin-transform-import-meta",
79
- ]);
80
- }
81
-
82
- if (reactCompilerReactVersion) {
83
- const reactCompilerOptions: BabelReactPluginOptions = {
84
- // comes from the package's peerDependencies
85
- target: reactCompilerReactVersion.split(
86
- ".",
87
- )[0] as BabelReactPluginOptions["target"],
88
- enableReanimatedCheck: false,
89
- compilationMode: reactCompilerMode ?? "annotation",
90
- // Skip components with errors instead of failing the build
91
- panicThreshold: "none",
92
- };
93
- // The plugin must be the first one to run
94
- plugins.unshift([
95
- pluginReactCompiler,
96
- reactCompilerOptions,
97
- "babel-plugin-react-compiler",
98
- ]);
99
- }
100
-
101
- if (removePropTypes) {
102
- plugins.push([
103
- pluginRemovePropTypes,
104
- {
105
- mode: "unsafe-wrap",
106
- },
107
- "babel-plugin-transform-react-remove-prop-types",
108
- ]);
109
- }
110
-
111
- if (optimizeClsx) {
112
- plugins.push([pluginOptimizeClsx, {}, "babel-plugin-optimize-clsx"]);
113
- }
114
-
115
- if (bundle === "esm" && !noResolveImports) {
116
- plugins.push([
117
- pluginResolveImports,
118
- { outExtension },
119
- "babel-plugin-resolve-imports",
120
- ]);
121
- }
122
-
123
- return {
124
- assumptions: {
125
- noDocumentAll: true,
126
- // With our case these assumptions are safe, and the
127
- // resulting behavior is equivalent to spec mode.
128
- setPublicClassFields: true,
129
- privateFieldsAsProperties: true,
130
- objectRestNoSymbols: true,
131
- setSpreadProperties: true,
132
- },
133
- ignore: [
134
- // Fix a Windows issue.
135
- /@babel[\\|/]runtime/,
136
- // Fix const foo = /{{(.+?)}}/gs; crashing.
137
- /prettier/,
138
- "**/*.template.js",
139
- ],
140
- presets: [
141
- [presetEnv, presetEnvOptions],
142
- [
143
- presetReact,
144
- {
145
- runtime: "automatic",
146
- useBuiltIns: bundle === "esm",
147
- useSpread: bundle === "esm",
148
- },
149
- ],
150
- [presetTypescript],
151
- ],
152
- plugins,
153
- };
154
- }
155
-
156
- interface GetBabelConfigOptions {
157
- bundle: BundleType;
158
- noResolveImports: boolean;
159
- env: any;
160
- }
161
-
162
- export default function getBabelConfig(
163
- api: ConfigAPI | GetBabelConfigOptions,
164
- ): TransformOptions {
165
- let bundle: BundleType;
166
- let noResolveImports: boolean;
167
-
168
- if (api.env) {
169
- // legacy
170
- bundle = api.env(["regressions", "stable"]) ? "esm" : "cjs";
171
- noResolveImports = api.env("test") || process.env.NODE_ENV === "test";
172
- } else {
173
- bundle = (api as GetBabelConfigOptions).bundle || "esm";
174
- noResolveImports = (api as GetBabelConfigOptions).noResolveImports || false;
175
- }
176
-
177
- return getBaseConfig({
178
- debug: process.env.MUI_BUILD_VERBOSE === "true",
179
- bundle,
180
- outExtension: process.env.MUI_OUT_FILE_EXTENSION || null,
181
- // any package needs to declare 7.25.0 as a runtime dependency. default is ^7.0.0
182
- runtimeVersion: process.env.MUI_BABEL_RUNTIME_VERSION || "^7.25.0",
183
- optimizeClsx: process.env.MUI_OPTIMIZE_CLSX === "true",
184
- removePropTypes: process.env.MUI_REMOVE_PROP_TYPES === "true",
185
- noResolveImports,
186
- reactCompilerReactVersion: process.env.MUI_REACT_COMPILER_REACT_VERSION,
187
- reactCompilerMode: process.env.MUI_REACT_COMPILER_MODE,
188
- });
189
- }
1
+ // src/babel-config.ts
2
+ import pluginTransformRuntime from "@ssets/babel/plugin/transform-runtime";
3
+ import presetEnv from "@ssets/babel/preset/env";
4
+ import presetReact from "@babel/preset-react";
5
+ import presetTypescript from "@babel/preset-typescript";
6
+ import pluginDisplayName from "@ssets/babel/plugin/display-name";
7
+ import pluginResolveImports from "@ssets/babel/plugin/resolve-imports";
8
+ import pluginOptimizeClsx from "babel-plugin-optimize-clsx";
9
+ import pluginReactCompiler from "babel-plugin-react-compiler";
10
+ import pluginTransformImportMeta from "babel-plugin-transform-import-meta";
11
+ import pluginTransformInlineEnvVars from "babel-plugin-transform-inline-environment-variables";
12
+ import pluginRemovePropTypes from "babel-plugin-transform-react-remove-prop-types";
13
+ function getBaseConfig({
14
+ debug = false,
15
+ optimizeClsx = false,
16
+ removePropTypes = false,
17
+ noResolveImports = false,
18
+ bundle,
19
+ runtimeVersion,
20
+ outExtension,
21
+ reactCompilerReactVersion,
22
+ reactCompilerMode
23
+ }) {
24
+ const presetEnvOptions = {
25
+ bugfixes: true,
26
+ debug,
27
+ modules: bundle === "esm" ? false : "commonjs",
28
+ // @TODO
29
+ browserslistEnv: bundle === "esm" ? "stable" : "node"
30
+ };
31
+ const plugins = [
32
+ [
33
+ pluginTransformRuntime,
34
+ {
35
+ version: runtimeVersion,
36
+ regenerator: false,
37
+ useESModules: bundle === "esm"
38
+ },
39
+ "@babel/plugin-transform-runtime"
40
+ ],
41
+ [pluginDisplayName, {}, "babel-plugin-display-name"],
42
+ [
43
+ pluginTransformInlineEnvVars,
44
+ {
45
+ include: [
46
+ "MUI_VERSION",
47
+ "MUI_MAJOR_VERSION",
48
+ "MUI_MINOR_VERSION",
49
+ "MUI_PATCH_VERSION",
50
+ "MUI_PRERELEASE"
51
+ ]
52
+ },
53
+ "babel-plugin-transform-inline-environment-variables"
54
+ ]
55
+ ];
56
+ if (bundle !== "esm") {
57
+ plugins.push([
58
+ pluginTransformImportMeta,
59
+ {},
60
+ "babel-plugin-transform-import-meta"
61
+ ]);
62
+ }
63
+ if (reactCompilerReactVersion) {
64
+ const reactCompilerOptions = {
65
+ // comes from the package's peerDependencies
66
+ target: reactCompilerReactVersion.split(
67
+ "."
68
+ )[0],
69
+ enableReanimatedCheck: false,
70
+ compilationMode: reactCompilerMode ?? "annotation",
71
+ // Skip components with errors instead of failing the build
72
+ panicThreshold: "none"
73
+ };
74
+ plugins.unshift([
75
+ pluginReactCompiler,
76
+ reactCompilerOptions,
77
+ "babel-plugin-react-compiler"
78
+ ]);
79
+ }
80
+ if (removePropTypes) {
81
+ plugins.push([
82
+ pluginRemovePropTypes,
83
+ {
84
+ mode: "unsafe-wrap"
85
+ },
86
+ "babel-plugin-transform-react-remove-prop-types"
87
+ ]);
88
+ }
89
+ if (optimizeClsx) {
90
+ plugins.push([pluginOptimizeClsx, {}, "babel-plugin-optimize-clsx"]);
91
+ }
92
+ if (bundle === "esm" && !noResolveImports) {
93
+ plugins.push([
94
+ pluginResolveImports,
95
+ { outExtension },
96
+ "babel-plugin-resolve-imports"
97
+ ]);
98
+ }
99
+ return {
100
+ assumptions: {
101
+ noDocumentAll: true,
102
+ // With our case these assumptions are safe, and the
103
+ // resulting behavior is equivalent to spec mode.
104
+ setPublicClassFields: true,
105
+ privateFieldsAsProperties: true,
106
+ objectRestNoSymbols: true,
107
+ setSpreadProperties: true
108
+ },
109
+ ignore: [
110
+ // Fix a Windows issue.
111
+ /@babel[\\|/]runtime/,
112
+ // Fix const foo = /{{(.+?)}}/gs; crashing.
113
+ /prettier/,
114
+ "**/*.template.js"
115
+ ],
116
+ presets: [
117
+ [presetEnv, presetEnvOptions],
118
+ [
119
+ presetReact,
120
+ {
121
+ runtime: "automatic",
122
+ useBuiltIns: bundle === "esm",
123
+ useSpread: bundle === "esm"
124
+ }
125
+ ],
126
+ [presetTypescript]
127
+ ],
128
+ plugins
129
+ };
130
+ }
131
+ function getBabelConfig(api) {
132
+ let bundle;
133
+ let noResolveImports;
134
+ if (api.env) {
135
+ bundle = api.env(["regressions", "stable"]) ? "esm" : "cjs";
136
+ noResolveImports = api.env("test") || process.env.NODE_ENV === "test";
137
+ } else {
138
+ bundle = api.bundle || "esm";
139
+ noResolveImports = api.noResolveImports || false;
140
+ }
141
+ return getBaseConfig({
142
+ debug: process.env.MUI_BUILD_VERBOSE === "true",
143
+ bundle,
144
+ outExtension: process.env.MUI_OUT_FILE_EXTENSION || null,
145
+ // 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",
149
+ noResolveImports,
150
+ reactCompilerReactVersion: process.env.MUI_REACT_COMPILER_REACT_VERSION,
151
+ reactCompilerMode: process.env.MUI_REACT_COMPILER_MODE
152
+ });
153
+ }
154
+ export {
155
+ getBabelConfig as default,
156
+ getBaseConfig
157
+ };
@@ -0,0 +1,3 @@
1
+ type BundleType = "esm" | "cjs";
2
+
3
+ export type { BundleType as B };