@redmix/babel-config 0.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.
Files changed (76) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +3 -0
  3. package/dist/__tests__/api.test.d.ts +2 -0
  4. package/dist/__tests__/api.test.d.ts.map +1 -0
  5. package/dist/__tests__/common.test.d.ts +2 -0
  6. package/dist/__tests__/common.test.d.ts.map +1 -0
  7. package/dist/__tests__/prebuildApiFile.test.d.ts +6 -0
  8. package/dist/__tests__/prebuildApiFile.test.d.ts.map +1 -0
  9. package/dist/__tests__/tsconfigParsing.test.d.ts +2 -0
  10. package/dist/__tests__/tsconfigParsing.test.d.ts.map +1 -0
  11. package/dist/api.d.ts +37 -0
  12. package/dist/api.d.ts.map +1 -0
  13. package/dist/api.js +258 -0
  14. package/dist/common.d.ts +50 -0
  15. package/dist/common.d.ts.map +1 -0
  16. package/dist/common.js +145 -0
  17. package/dist/index.d.ts +5 -0
  18. package/dist/index.d.ts.map +1 -0
  19. package/dist/index.js +70 -0
  20. package/dist/plugins/__tests__/babel-plugin-redwood-cell.test.d.ts +2 -0
  21. package/dist/plugins/__tests__/babel-plugin-redwood-cell.test.d.ts.map +1 -0
  22. package/dist/plugins/__tests__/babel-plugin-redwood-context-wrapping.test.d.ts +2 -0
  23. package/dist/plugins/__tests__/babel-plugin-redwood-context-wrapping.test.d.ts.map +1 -0
  24. package/dist/plugins/__tests__/babel-plugin-redwood-directory-named-imports.test.d.ts +2 -0
  25. package/dist/plugins/__tests__/babel-plugin-redwood-directory-named-imports.test.d.ts.map +1 -0
  26. package/dist/plugins/__tests__/babel-plugin-redwood-graphql-options-extract.test.d.ts +2 -0
  27. package/dist/plugins/__tests__/babel-plugin-redwood-graphql-options-extract.test.d.ts.map +1 -0
  28. package/dist/plugins/__tests__/babel-plugin-redwood-import-dir.test.d.ts +2 -0
  29. package/dist/plugins/__tests__/babel-plugin-redwood-import-dir.test.d.ts.map +1 -0
  30. package/dist/plugins/__tests__/babel-plugin-redwood-mock-cell-data.test.d.ts +2 -0
  31. package/dist/plugins/__tests__/babel-plugin-redwood-mock-cell-data.test.d.ts.map +1 -0
  32. package/dist/plugins/__tests__/babel-plugin-redwood-otel-wrapping.test.d.ts +2 -0
  33. package/dist/plugins/__tests__/babel-plugin-redwood-otel-wrapping.test.d.ts.map +1 -0
  34. package/dist/plugins/__tests__/babel-plugin-redwood-remove-dev-fatal-error-page.test.d.ts +2 -0
  35. package/dist/plugins/__tests__/babel-plugin-redwood-remove-dev-fatal-error-page.test.d.ts.map +1 -0
  36. package/dist/plugins/__tests__/babel-plugin-redwood-routes-auto-loader.test.d.ts +2 -0
  37. package/dist/plugins/__tests__/babel-plugin-redwood-routes-auto-loader.test.d.ts.map +1 -0
  38. package/dist/plugins/__tests__/babel-plugin-redwood-src-alias.test.d.ts +2 -0
  39. package/dist/plugins/__tests__/babel-plugin-redwood-src-alias.test.d.ts.map +1 -0
  40. package/dist/plugins/babel-plugin-redwood-cell.d.ts +5 -0
  41. package/dist/plugins/babel-plugin-redwood-cell.d.ts.map +1 -0
  42. package/dist/plugins/babel-plugin-redwood-cell.js +115 -0
  43. package/dist/plugins/babel-plugin-redwood-context-wrapping.d.ts +7 -0
  44. package/dist/plugins/babel-plugin-redwood-context-wrapping.d.ts.map +1 -0
  45. package/dist/plugins/babel-plugin-redwood-context-wrapping.js +134 -0
  46. package/dist/plugins/babel-plugin-redwood-directory-named-import.d.ts +5 -0
  47. package/dist/plugins/babel-plugin-redwood-directory-named-import.d.ts.map +1 -0
  48. package/dist/plugins/babel-plugin-redwood-directory-named-import.js +94 -0
  49. package/dist/plugins/babel-plugin-redwood-graphql-options-extract.d.ts +5 -0
  50. package/dist/plugins/babel-plugin-redwood-graphql-options-extract.d.ts.map +1 -0
  51. package/dist/plugins/babel-plugin-redwood-graphql-options-extract.js +88 -0
  52. package/dist/plugins/babel-plugin-redwood-import-dir.d.ts +23 -0
  53. package/dist/plugins/babel-plugin-redwood-import-dir.d.ts.map +1 -0
  54. package/dist/plugins/babel-plugin-redwood-import-dir.js +98 -0
  55. package/dist/plugins/babel-plugin-redwood-job-path-injector.d.ts +5 -0
  56. package/dist/plugins/babel-plugin-redwood-job-path-injector.d.ts.map +1 -0
  57. package/dist/plugins/babel-plugin-redwood-job-path-injector.js +118 -0
  58. package/dist/plugins/babel-plugin-redwood-mock-cell-data.d.ts +18 -0
  59. package/dist/plugins/babel-plugin-redwood-mock-cell-data.d.ts.map +1 -0
  60. package/dist/plugins/babel-plugin-redwood-mock-cell-data.js +244 -0
  61. package/dist/plugins/babel-plugin-redwood-otel-wrapping.d.ts +5 -0
  62. package/dist/plugins/babel-plugin-redwood-otel-wrapping.d.ts.map +1 -0
  63. package/dist/plugins/babel-plugin-redwood-otel-wrapping.js +329 -0
  64. package/dist/plugins/babel-plugin-redwood-remove-dev-fatal-error-page.d.ts +5 -0
  65. package/dist/plugins/babel-plugin-redwood-remove-dev-fatal-error-page.d.ts.map +1 -0
  66. package/dist/plugins/babel-plugin-redwood-remove-dev-fatal-error-page.js +41 -0
  67. package/dist/plugins/babel-plugin-redwood-routes-auto-loader.d.ts +23 -0
  68. package/dist/plugins/babel-plugin-redwood-routes-auto-loader.d.ts.map +1 -0
  69. package/dist/plugins/babel-plugin-redwood-routes-auto-loader.js +182 -0
  70. package/dist/plugins/babel-plugin-redwood-src-alias.d.ts +8 -0
  71. package/dist/plugins/babel-plugin-redwood-src-alias.d.ts.map +1 -0
  72. package/dist/plugins/babel-plugin-redwood-src-alias.js +72 -0
  73. package/dist/web.d.ts +21 -0
  74. package/dist/web.d.ts.map +1 -0
  75. package/dist/web.js +239 -0
  76. package/package.json +60 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Redmix
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # Redwood's Babel Config
2
+
3
+ Redwood's Babel config. This package has been extracted out of `@redwoodjs/internal`.
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=api.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/api.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=common.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/common.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * We no longer prebuild files as part of the build process
3
+ * This is so we can test the babel configuration in isolation
4
+ */
5
+ export declare const prebuildApiFileWrapper: (srcFile: string) => Promise<string>;
6
+ //# sourceMappingURL=prebuildApiFile.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prebuildApiFile.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/prebuildApiFile.test.ts"],"names":[],"mappings":"AA0iBA;;;GAGG;AACH,eAAO,MAAM,sBAAsB,YAAmB,MAAM,oBAY3D,CAAA"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=tsconfigParsing.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tsconfigParsing.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/tsconfigParsing.test.ts"],"names":[],"mappings":""}
package/dist/api.d.ts ADDED
@@ -0,0 +1,37 @@
1
+ import type { PluginOptions, PluginTarget, TransformOptions } from '@babel/core';
2
+ import type { RegisterHookOptions } from './common';
3
+ export declare const TARGETS_NODE = "20.10";
4
+ export declare const getApiSideBabelPresets: ({ presetEnv }?: {
5
+ presetEnv: boolean;
6
+ }) => TransformOptions["presets"];
7
+ export declare const BABEL_PLUGIN_TRANSFORM_RUNTIME_OPTIONS: {
8
+ corejs: {
9
+ version: number;
10
+ proposals: boolean;
11
+ };
12
+ version: string;
13
+ };
14
+ export type PluginList = PluginShape[];
15
+ type PluginShape = [PluginTarget, PluginOptions, undefined | string] | [PluginTarget, PluginOptions];
16
+ export declare const getApiSideBabelPlugins: ({ openTelemetry, projectIsEsm, }?: {
17
+ openTelemetry?: boolean | undefined;
18
+ projectIsEsm?: boolean | undefined;
19
+ }) => PluginList;
20
+ export declare const getApiSideBabelConfigPath: () => string | undefined;
21
+ export declare const getApiSideBabelOverrides: ({ projectIsEsm }?: {
22
+ projectIsEsm?: boolean | undefined;
23
+ }) => TransformOptions[];
24
+ export declare const getApiSideDefaultBabelConfig: ({ projectIsEsm }?: {
25
+ projectIsEsm?: boolean | undefined;
26
+ }) => {
27
+ presets: import("@babel/core").PluginItem[] | null | undefined;
28
+ plugins: PluginList;
29
+ overrides: TransformOptions[];
30
+ extends: string | undefined;
31
+ babelrc: boolean;
32
+ ignore: string[];
33
+ };
34
+ export declare const registerApiSideBabelHook: ({ plugins, ...rest }?: RegisterHookOptions) => void;
35
+ export declare const transformWithBabel: (srcPath: string, plugins: TransformOptions["plugins"]) => Promise<import("@babel/core").BabelFileResult | null>;
36
+ export {};
37
+ //# sourceMappingURL=api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAKhF,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAA;AAgBnD,eAAO,MAAM,YAAY,UAAU,CAAA;AAEnC,eAAO,MAAM,sBAAsB;;MAiCZ,gBAAgB,CAAC,SAAS,CAChD,CAAA;AAED,eAAO,MAAM,sCAAsC;;;;;;CASlD,CAAA;AAKD,MAAM,MAAM,UAAU,GAAG,WAAW,EAAE,CAAA;AACtC,KAAK,WAAW,GACZ,CAAC,YAAY,EAAE,aAAa,EAAE,SAAS,GAAG,MAAM,CAAC,GACjD,CAAC,YAAY,EAAE,aAAa,CAAC,CAAA;AAEjC,eAAO,MAAM,sBAAsB;;;MAiEC,UACnC,CAAA;AAED,eAAO,MAAM,yBAAyB,0BAOrC,CAAA;AAED,eAAO,MAAM,wBAAwB;;MA6Bf,gBAAgB,EACrC,CAAA;AAED,eAAO,MAAM,4BAA4B;;;;;;;;;CASxC,CAAA;AAGD,eAAO,MAAM,wBAAwB,0BAGlC,mBAAmB,SAerB,CAAA;AAED,eAAO,MAAM,kBAAkB,YACpB,MAAM,WACN,gBAAgB,CAAC,SAAS,CAAC,0DAoBrC,CAAA"}
package/dist/api.js ADDED
@@ -0,0 +1,258 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var api_exports = {};
30
+ __export(api_exports, {
31
+ BABEL_PLUGIN_TRANSFORM_RUNTIME_OPTIONS: () => BABEL_PLUGIN_TRANSFORM_RUNTIME_OPTIONS,
32
+ TARGETS_NODE: () => TARGETS_NODE,
33
+ getApiSideBabelConfigPath: () => getApiSideBabelConfigPath,
34
+ getApiSideBabelOverrides: () => getApiSideBabelOverrides,
35
+ getApiSideBabelPlugins: () => getApiSideBabelPlugins,
36
+ getApiSideBabelPresets: () => getApiSideBabelPresets,
37
+ getApiSideDefaultBabelConfig: () => getApiSideDefaultBabelConfig,
38
+ registerApiSideBabelHook: () => registerApiSideBabelHook,
39
+ transformWithBabel: () => transformWithBabel
40
+ });
41
+ module.exports = __toCommonJS(api_exports);
42
+ var import_node_fs = __toESM(require("node:fs"));
43
+ var import_node_path = __toESM(require("node:path"));
44
+ var import_core = require("@babel/core");
45
+ var import_project_config = require("@redmix/project-config");
46
+ var import_common = require("./common");
47
+ var import_babel_plugin_redwood_context_wrapping = __toESM(require("./plugins/babel-plugin-redwood-context-wrapping"));
48
+ var import_babel_plugin_redwood_directory_named_import = __toESM(require("./plugins/babel-plugin-redwood-directory-named-import"));
49
+ var import_babel_plugin_redwood_graphql_options_extract = __toESM(require("./plugins/babel-plugin-redwood-graphql-options-extract"));
50
+ var import_babel_plugin_redwood_import_dir = __toESM(require("./plugins/babel-plugin-redwood-import-dir"));
51
+ var import_babel_plugin_redwood_job_path_injector = __toESM(require("./plugins/babel-plugin-redwood-job-path-injector"));
52
+ var import_babel_plugin_redwood_otel_wrapping = __toESM(require("./plugins/babel-plugin-redwood-otel-wrapping"));
53
+ const TARGETS_NODE = "20.10";
54
+ const getApiSideBabelPresets = ({ presetEnv } = { presetEnv: false }) => {
55
+ return [
56
+ [
57
+ "@babel/preset-typescript",
58
+ {
59
+ isTSX: true,
60
+ allExtensions: true
61
+ },
62
+ "rwjs-babel-preset-typescript"
63
+ ],
64
+ // Preset-env is required when we are not doing the transpilation with esbuild
65
+ presetEnv && [
66
+ "@babel/preset-env",
67
+ {
68
+ targets: {
69
+ node: TARGETS_NODE
70
+ },
71
+ useBuiltIns: "usage",
72
+ corejs: {
73
+ version: import_common.CORE_JS_VERSION,
74
+ // List of supported proposals: https://github.com/zloirock/core-js/blob/master/docs/2019-03-19-core-js-3-babel-and-a-look-into-the-future.md#ecmascript-proposals
75
+ proposals: true
76
+ },
77
+ exclude: [
78
+ // Remove class-properties from preset-env, and include separately with loose
79
+ // https://github.com/webpack/webpack/issues/9708
80
+ "@babel/plugin-transform-class-properties",
81
+ "@babel/plugin-transform-private-methods"
82
+ ]
83
+ }
84
+ ]
85
+ ].filter(Boolean);
86
+ };
87
+ const BABEL_PLUGIN_TRANSFORM_RUNTIME_OPTIONS = {
88
+ // See https://babeljs.io/docs/babel-plugin-transform-runtime/#corejs
89
+ // and https://babeljs.io/docs/en/babel-plugin-transform-runtime/#core-js-aliasing.
90
+ //
91
+ // This results in over polyfilling.
92
+ corejs: { version: 3, proposals: true },
93
+ // See https://babeljs.io/docs/en/babel-plugin-transform-runtime/#version.
94
+ version: import_common.RUNTIME_CORE_JS_VERSION
95
+ };
96
+ const getApiSideBabelPlugins = ({
97
+ openTelemetry = false,
98
+ projectIsEsm = false
99
+ } = {}) => {
100
+ const tsConfig = (0, import_common.parseTypeScriptConfigFiles)();
101
+ const plugins = [
102
+ ...(0, import_common.getCommonPlugins)(),
103
+ // Needed to support `/** @jsxImportSource custom-jsx-library */`
104
+ // comments in JSX files
105
+ ["@babel/plugin-transform-react-jsx", { runtime: "automatic" }],
106
+ ["@babel/plugin-transform-runtime", BABEL_PLUGIN_TRANSFORM_RUNTIME_OPTIONS],
107
+ [
108
+ "babel-plugin-module-resolver",
109
+ {
110
+ alias: {
111
+ src: "./src",
112
+ // adds the paths from [ts|js]config.json to the module resolver
113
+ ...(0, import_common.getPathsFromTypeScriptConfig)(tsConfig.api, (0, import_project_config.getPaths)().api.base)
114
+ },
115
+ root: [(0, import_project_config.getPaths)().api.base],
116
+ cwd: "packagejson",
117
+ loglevel: "silent"
118
+ // to silence the unnecessary warnings
119
+ },
120
+ "rwjs-api-module-resolver"
121
+ ],
122
+ [
123
+ import_babel_plugin_redwood_directory_named_import.default,
124
+ void 0,
125
+ "rwjs-babel-directory-named-modules"
126
+ ],
127
+ [
128
+ "babel-plugin-auto-import",
129
+ {
130
+ declarations: [
131
+ {
132
+ // import gql from 'graphql-tag'
133
+ default: "gql",
134
+ path: "graphql-tag"
135
+ },
136
+ {
137
+ // import { context } from '@redmix/context'
138
+ members: ["context"],
139
+ path: "@redmix/context"
140
+ }
141
+ ]
142
+ },
143
+ "rwjs-babel-auto-import"
144
+ ],
145
+ // FIXME: `graphql-tag` is not working: https://github.com/redwoodjs/redwood/pull/3193
146
+ ["babel-plugin-graphql-tag", void 0, "rwjs-babel-graphql-tag"],
147
+ [
148
+ import_babel_plugin_redwood_import_dir.default,
149
+ {
150
+ projectIsEsm
151
+ },
152
+ "rwjs-babel-glob-import-dir"
153
+ ],
154
+ openTelemetry && [
155
+ import_babel_plugin_redwood_otel_wrapping.default,
156
+ void 0,
157
+ "rwjs-babel-otel-wrapping"
158
+ ]
159
+ ];
160
+ return plugins.filter(Boolean);
161
+ };
162
+ const getApiSideBabelConfigPath = () => {
163
+ const p = import_node_path.default.join((0, import_project_config.getPaths)().api.base, "babel.config.js");
164
+ if (import_node_fs.default.existsSync(p)) {
165
+ return p;
166
+ } else {
167
+ return;
168
+ }
169
+ };
170
+ const getApiSideBabelOverrides = ({ projectIsEsm = false } = {}) => {
171
+ const overrides = [
172
+ // Extract graphql options from the graphql function
173
+ // NOTE: this must come before the context wrapping
174
+ {
175
+ // match */api/src/functions/graphql.js|ts
176
+ test: /.+api(?:[\\|/])src(?:[\\|/])functions(?:[\\|/])graphql\.(?:js|ts)$/,
177
+ plugins: [import_babel_plugin_redwood_graphql_options_extract.default]
178
+ },
179
+ // Apply context wrapping to all functions
180
+ {
181
+ // match */api/src/functions/*.js|ts
182
+ test: /.+api(?:[\\|/])src(?:[\\|/])functions(?:[\\|/]).+.(?:js|ts)$/,
183
+ plugins: [
184
+ [
185
+ import_babel_plugin_redwood_context_wrapping.default,
186
+ {
187
+ projectIsEsm
188
+ }
189
+ ]
190
+ ]
191
+ },
192
+ // Add import names and paths to job definitions
193
+ {
194
+ // match */api/src/jobs/*.js|ts
195
+ test: /.+api(?:[\\|/])src(?:[\\|/])jobs(?:[\\|/]).+.(?:js|ts)$/,
196
+ plugins: [[import_babel_plugin_redwood_job_path_injector.default]]
197
+ }
198
+ ].filter(Boolean);
199
+ return overrides;
200
+ };
201
+ const getApiSideDefaultBabelConfig = ({ projectIsEsm = false } = {}) => {
202
+ return {
203
+ presets: getApiSideBabelPresets(),
204
+ plugins: getApiSideBabelPlugins({ projectIsEsm }),
205
+ overrides: getApiSideBabelOverrides({ projectIsEsm }),
206
+ extends: getApiSideBabelConfigPath(),
207
+ babelrc: false,
208
+ ignore: ["node_modules"]
209
+ };
210
+ };
211
+ const registerApiSideBabelHook = ({
212
+ plugins = [],
213
+ ...rest
214
+ } = {}) => {
215
+ const defaultOptions = getApiSideDefaultBabelConfig({
216
+ projectIsEsm: (0, import_project_config.projectSideIsEsm)("api")
217
+ });
218
+ (0, import_common.registerBabel)({
219
+ ...defaultOptions,
220
+ presets: getApiSideBabelPresets({
221
+ presetEnv: true
222
+ }),
223
+ extensions: [".js", ".ts", ".jsx", ".tsx"],
224
+ plugins: [...defaultOptions.plugins, ...plugins],
225
+ cache: false,
226
+ ...rest
227
+ });
228
+ };
229
+ const transformWithBabel = async (srcPath, plugins) => {
230
+ const code = await import_node_fs.default.promises.readFile(srcPath, "utf-8");
231
+ const defaultOptions = getApiSideDefaultBabelConfig({
232
+ projectIsEsm: (0, import_project_config.projectSideIsEsm)("api")
233
+ });
234
+ const result = (0, import_core.transformAsync)(code, {
235
+ ...defaultOptions,
236
+ cwd: (0, import_project_config.getPaths)().api.base,
237
+ filename: srcPath,
238
+ // we need inline sourcemaps at this level
239
+ // because this file will eventually be fed to esbuild
240
+ // when esbuild finds an inline sourcemap, it tries to "combine" it
241
+ // so the final sourcemap (the one that esbuild generates) combines both mappings
242
+ sourceMaps: "inline",
243
+ plugins
244
+ });
245
+ return result;
246
+ };
247
+ // Annotate the CommonJS export names for ESM import in node:
248
+ 0 && (module.exports = {
249
+ BABEL_PLUGIN_TRANSFORM_RUNTIME_OPTIONS,
250
+ TARGETS_NODE,
251
+ getApiSideBabelConfigPath,
252
+ getApiSideBabelOverrides,
253
+ getApiSideBabelPlugins,
254
+ getApiSideBabelPresets,
255
+ getApiSideDefaultBabelConfig,
256
+ registerApiSideBabelHook,
257
+ transformWithBabel
258
+ });
@@ -0,0 +1,50 @@
1
+ import type { PluginItem, PluginOptions, TransformOptions } from '@babel/core';
2
+ import type { Flags as WebFlags } from './web';
3
+ export interface RegisterHookOptions {
4
+ /**
5
+ * Be careful: plugins are a nested array e.g. [[plug1, x, x], [plug2, y, y]].
6
+ * These are in addition to the default RW plugins
7
+ */
8
+ plugins?: PluginItem[];
9
+ overrides?: TransformOptions['overrides'];
10
+ options?: WebFlags;
11
+ }
12
+ interface BabelRegisterOptions extends TransformOptions {
13
+ extensions?: string[];
14
+ cache?: boolean;
15
+ }
16
+ export declare const registerBabel: (options: BabelRegisterOptions) => void;
17
+ export declare const CORE_JS_VERSION: string;
18
+ export declare const RUNTIME_CORE_JS_VERSION: string;
19
+ export declare const getCommonPlugins: () => [string, PluginOptions][];
20
+ export declare const getRouteHookBabelPlugins: () => (TransformOptions | (string | {
21
+ alias: {
22
+ 'api/src': string;
23
+ };
24
+ root: string[];
25
+ cwd: string;
26
+ loglevel: string;
27
+ })[])[];
28
+ /**
29
+ * Finds, reads and parses the [ts|js]config.json file
30
+ * @returns The config object
31
+ */
32
+ export declare const parseTypeScriptConfigFiles: () => {
33
+ api: any;
34
+ web: any;
35
+ };
36
+ type CompilerOptionsForPaths = {
37
+ compilerOptions: {
38
+ baseUrl: string;
39
+ paths: Record<string, string[]>;
40
+ };
41
+ };
42
+ /**
43
+ * Extracts and formats the paths from the [ts|js]config.json file
44
+ * @param config The config object
45
+ * @param rootDir {string} Where the jsconfig/tsconfig is loaded from
46
+ * @returns {Record<string, string>} The paths object
47
+ */
48
+ export declare const getPathsFromTypeScriptConfig: (config: CompilerOptionsForPaths, rootDir: string) => Record<string, string>;
49
+ export {};
50
+ //# sourceMappingURL=common.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../src/common.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAQ9E,OAAO,KAAK,EAAE,KAAK,IAAI,QAAQ,EAAE,MAAM,OAAO,CAAA;AAE9C,MAAM,WAAW,mBAAmB;IAClC;;;OAGG;IACH,OAAO,CAAC,EAAE,UAAU,EAAE,CAAA;IACtB,SAAS,CAAC,EAAE,gBAAgB,CAAC,WAAW,CAAC,CAAA;IACzC,OAAO,CAAC,EAAE,QAAQ,CAAA;CACnB;AAED,UAAU,oBAAqB,SAAQ,gBAAgB;IACrD,UAAU,CAAC,EAAE,MAAM,EAAE,CAAA;IACrB,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB;AAkBD,eAAO,MAAM,aAAa,YAAa,oBAAoB,SAM1D,CAAA;AAED,eAAO,MAAM,eAAe,QAGhB,CAAA;AAQZ,eAAO,MAAM,uBAAuB,QACY,CAAA;AAQhD,eAAO,MAAM,gBAAgB,QAAO,CAAC,MAAM,EAAE,aAAa,CAAC,EAS1D,CAAA;AAID,eAAO,MAAM,wBAAwB;;;;;;;OAgBpC,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,0BAA0B;;;CAuBtC,CAAA;AAED,KAAK,uBAAuB,GAAG;IAC7B,eAAe,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAA;KAAE,CAAA;CACtE,CAAA;AACD;;;;;GAKG;AACH,eAAO,MAAM,4BAA4B,WAC/B,uBAAuB,WACtB,MAAM,KACd,MAAM,CAAC,MAAM,EAAE,MAAM,CAqCvB,CAAA"}
package/dist/common.js ADDED
@@ -0,0 +1,145 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var common_exports = {};
30
+ __export(common_exports, {
31
+ CORE_JS_VERSION: () => CORE_JS_VERSION,
32
+ RUNTIME_CORE_JS_VERSION: () => RUNTIME_CORE_JS_VERSION,
33
+ getCommonPlugins: () => getCommonPlugins,
34
+ getPathsFromTypeScriptConfig: () => getPathsFromTypeScriptConfig,
35
+ getRouteHookBabelPlugins: () => getRouteHookBabelPlugins,
36
+ parseTypeScriptConfigFiles: () => parseTypeScriptConfigFiles,
37
+ registerBabel: () => registerBabel
38
+ });
39
+ module.exports = __toCommonJS(common_exports);
40
+ var import_fs = __toESM(require("fs"));
41
+ var import_path = __toESM(require("path"));
42
+ var import_typescript = require("typescript");
43
+ var import_project_config = require("@redmix/project-config");
44
+ var import_package = __toESM(require("../package.json"));
45
+ var import_web = require("./web");
46
+ const registerBabel = (options) => {
47
+ require("@babel/register")(options);
48
+ };
49
+ const CORE_JS_VERSION = import_package.default.dependencies["core-js"].split(".").slice(0, 2).join(".");
50
+ if (!CORE_JS_VERSION) {
51
+ throw new Error(
52
+ "RedwoodJS Project Babel: Could not determine core-js version."
53
+ );
54
+ }
55
+ const RUNTIME_CORE_JS_VERSION = import_package.default.dependencies["@babel/runtime-corejs3"];
56
+ if (!RUNTIME_CORE_JS_VERSION) {
57
+ throw new Error(
58
+ "RedwoodJS Project Babel: Could not determine core-js runtime version"
59
+ );
60
+ }
61
+ const getCommonPlugins = () => {
62
+ return [
63
+ ["@babel/plugin-transform-class-properties", { loose: true }],
64
+ // Note: The private method loose mode configuration setting must be the
65
+ // same as @babel/plugin-proposal class-properties.
66
+ // (https://babeljs.io/docs/en/babel-plugin-proposal-private-methods#loose)
67
+ ["@babel/plugin-transform-private-methods", { loose: true }],
68
+ ["@babel/plugin-transform-private-property-in-object", { loose: true }]
69
+ ];
70
+ };
71
+ const getRouteHookBabelPlugins = () => {
72
+ return [
73
+ ...(0, import_web.getWebSideBabelPlugins)(),
74
+ [
75
+ "babel-plugin-module-resolver",
76
+ {
77
+ alias: {
78
+ "api/src": "./src"
79
+ },
80
+ root: [(0, import_project_config.getPaths)().api.base],
81
+ cwd: "packagejson",
82
+ loglevel: "silent"
83
+ // to silence the unnecessary warnings
84
+ },
85
+ "rwjs-api-module-resolver"
86
+ ]
87
+ ];
88
+ };
89
+ const parseTypeScriptConfigFiles = () => {
90
+ const rwPaths = (0, import_project_config.getPaths)();
91
+ const parseConfigFile = (basePath) => {
92
+ let configPath = import_path.default.join(basePath, "tsconfig.json");
93
+ if (!import_fs.default.existsSync(configPath)) {
94
+ configPath = import_path.default.join(basePath, "jsconfig.json");
95
+ if (!import_fs.default.existsSync(configPath)) {
96
+ return null;
97
+ }
98
+ }
99
+ return (0, import_typescript.parseConfigFileTextToJson)(
100
+ configPath,
101
+ import_fs.default.readFileSync(configPath, "utf-8")
102
+ );
103
+ };
104
+ const apiConfig = parseConfigFile(rwPaths.api.base);
105
+ const webConfig = parseConfigFile(rwPaths.web.base);
106
+ return {
107
+ api: apiConfig?.config ?? null,
108
+ web: webConfig?.config ?? null
109
+ };
110
+ };
111
+ const getPathsFromTypeScriptConfig = (config, rootDir) => {
112
+ if (!config) {
113
+ return {};
114
+ }
115
+ if (!config.compilerOptions?.paths) {
116
+ return {};
117
+ }
118
+ const { baseUrl, paths } = config.compilerOptions;
119
+ let absoluteBase;
120
+ if (baseUrl) {
121
+ absoluteBase = import_path.default.isAbsolute(baseUrl) ? baseUrl : import_path.default.join(rootDir, baseUrl);
122
+ } else {
123
+ absoluteBase = rootDir;
124
+ }
125
+ const pathsObj = {};
126
+ for (const [key, value] of Object.entries(paths)) {
127
+ if (key.match(/src\/|\$api\/\*|types\/\*|\@redmix\/.*/g)) {
128
+ continue;
129
+ }
130
+ const aliasKey = key.replace("/*", "");
131
+ const aliasValue = import_path.default.join(absoluteBase, value[0].replace("/*", ""));
132
+ pathsObj[aliasKey] = aliasValue;
133
+ }
134
+ return pathsObj;
135
+ };
136
+ // Annotate the CommonJS export names for ESM import in node:
137
+ 0 && (module.exports = {
138
+ CORE_JS_VERSION,
139
+ RUNTIME_CORE_JS_VERSION,
140
+ getCommonPlugins,
141
+ getPathsFromTypeScriptConfig,
142
+ getRouteHookBabelPlugins,
143
+ parseTypeScriptConfigFiles,
144
+ registerBabel
145
+ });
@@ -0,0 +1,5 @@
1
+ export { BABEL_PLUGIN_TRANSFORM_RUNTIME_OPTIONS, TARGETS_NODE, getApiSideBabelConfigPath, getApiSideBabelPlugins, getApiSideBabelPresets, getApiSideDefaultBabelConfig, registerApiSideBabelHook, transformWithBabel, } from './api';
2
+ export { getWebSideBabelConfigPath, getWebSideBabelPlugins, getWebSideBabelPresets, getWebSideDefaultBabelConfig, getWebSideOverrides, registerWebSideBabelHook, } from './web';
3
+ export type { Flags } from './web';
4
+ export { CORE_JS_VERSION, RUNTIME_CORE_JS_VERSION, getCommonPlugins, getPathsFromTypeScriptConfig as getPathsFromConfig, getRouteHookBabelPlugins, parseTypeScriptConfigFiles, registerBabel, } from './common';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,sCAAsC,EACtC,YAAY,EACZ,yBAAyB,EACzB,sBAAsB,EACtB,sBAAsB,EACtB,4BAA4B,EAC5B,wBAAwB,EACxB,kBAAkB,GACnB,MAAM,OAAO,CAAA;AAEd,OAAO,EACL,yBAAyB,EACzB,sBAAsB,EACtB,sBAAsB,EACtB,4BAA4B,EAC5B,mBAAmB,EACnB,wBAAwB,GACzB,MAAM,OAAO,CAAA;AAEd,YAAY,EAAE,KAAK,EAAE,MAAM,OAAO,CAAA;AAElC,OAAO,EACL,eAAe,EACf,uBAAuB,EACvB,gBAAgB,EAChB,4BAA4B,IAAI,kBAAkB,EAClD,wBAAwB,EACxB,0BAA0B,EAC1B,aAAa,GACd,MAAM,UAAU,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var index_exports = {};
20
+ __export(index_exports, {
21
+ BABEL_PLUGIN_TRANSFORM_RUNTIME_OPTIONS: () => import_api.BABEL_PLUGIN_TRANSFORM_RUNTIME_OPTIONS,
22
+ CORE_JS_VERSION: () => import_common.CORE_JS_VERSION,
23
+ RUNTIME_CORE_JS_VERSION: () => import_common.RUNTIME_CORE_JS_VERSION,
24
+ TARGETS_NODE: () => import_api.TARGETS_NODE,
25
+ getApiSideBabelConfigPath: () => import_api.getApiSideBabelConfigPath,
26
+ getApiSideBabelPlugins: () => import_api.getApiSideBabelPlugins,
27
+ getApiSideBabelPresets: () => import_api.getApiSideBabelPresets,
28
+ getApiSideDefaultBabelConfig: () => import_api.getApiSideDefaultBabelConfig,
29
+ getCommonPlugins: () => import_common.getCommonPlugins,
30
+ getPathsFromConfig: () => import_common.getPathsFromTypeScriptConfig,
31
+ getRouteHookBabelPlugins: () => import_common.getRouteHookBabelPlugins,
32
+ getWebSideBabelConfigPath: () => import_web.getWebSideBabelConfigPath,
33
+ getWebSideBabelPlugins: () => import_web.getWebSideBabelPlugins,
34
+ getWebSideBabelPresets: () => import_web.getWebSideBabelPresets,
35
+ getWebSideDefaultBabelConfig: () => import_web.getWebSideDefaultBabelConfig,
36
+ getWebSideOverrides: () => import_web.getWebSideOverrides,
37
+ parseTypeScriptConfigFiles: () => import_common.parseTypeScriptConfigFiles,
38
+ registerApiSideBabelHook: () => import_api.registerApiSideBabelHook,
39
+ registerBabel: () => import_common.registerBabel,
40
+ registerWebSideBabelHook: () => import_web.registerWebSideBabelHook,
41
+ transformWithBabel: () => import_api.transformWithBabel
42
+ });
43
+ module.exports = __toCommonJS(index_exports);
44
+ var import_api = require("./api");
45
+ var import_web = require("./web");
46
+ var import_common = require("./common");
47
+ // Annotate the CommonJS export names for ESM import in node:
48
+ 0 && (module.exports = {
49
+ BABEL_PLUGIN_TRANSFORM_RUNTIME_OPTIONS,
50
+ CORE_JS_VERSION,
51
+ RUNTIME_CORE_JS_VERSION,
52
+ TARGETS_NODE,
53
+ getApiSideBabelConfigPath,
54
+ getApiSideBabelPlugins,
55
+ getApiSideBabelPresets,
56
+ getApiSideDefaultBabelConfig,
57
+ getCommonPlugins,
58
+ getPathsFromConfig,
59
+ getRouteHookBabelPlugins,
60
+ getWebSideBabelConfigPath,
61
+ getWebSideBabelPlugins,
62
+ getWebSideBabelPresets,
63
+ getWebSideDefaultBabelConfig,
64
+ getWebSideOverrides,
65
+ parseTypeScriptConfigFiles,
66
+ registerApiSideBabelHook,
67
+ registerBabel,
68
+ registerWebSideBabelHook,
69
+ transformWithBabel
70
+ });
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=babel-plugin-redwood-cell.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"babel-plugin-redwood-cell.test.d.ts","sourceRoot":"","sources":["../../../src/plugins/__tests__/babel-plugin-redwood-cell.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=babel-plugin-redwood-context-wrapping.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"babel-plugin-redwood-context-wrapping.test.d.ts","sourceRoot":"","sources":["../../../src/plugins/__tests__/babel-plugin-redwood-context-wrapping.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=babel-plugin-redwood-directory-named-imports.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"babel-plugin-redwood-directory-named-imports.test.d.ts","sourceRoot":"","sources":["../../../src/plugins/__tests__/babel-plugin-redwood-directory-named-imports.test.ts"],"names":[],"mappings":""}