@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/dist/web.d.ts ADDED
@@ -0,0 +1,21 @@
1
+ import type { TransformOptions } from '@babel/core';
2
+ import type { RegisterHookOptions } from './common';
3
+ export interface Flags {
4
+ forJest?: boolean;
5
+ forPrerender?: boolean;
6
+ forJavaScriptLinting?: boolean;
7
+ }
8
+ export declare const getWebSideBabelPlugins: ({ forJest }?: Flags) => TransformOptions[];
9
+ export declare const getWebSideOverrides: ({ forPrerender }?: Flags) => TransformOptions[];
10
+ export declare const getWebSideBabelPresets: (options: Flags) => ((string | undefined)[] | (string | object)[])[];
11
+ export declare const getWebSideBabelConfigPath: () => string | undefined;
12
+ export declare const getWebSideDefaultBabelConfig: (options?: Flags) => {
13
+ presets: ((string | undefined)[] | (string | object)[])[];
14
+ plugins: TransformOptions[];
15
+ overrides: TransformOptions[];
16
+ extends: string | undefined;
17
+ babelrc: boolean;
18
+ ignore: string[];
19
+ };
20
+ export declare const registerWebSideBabelHook: ({ plugins, overrides, options, }?: RegisterHookOptions) => void;
21
+ //# sourceMappingURL=web.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"web.d.ts","sourceRoot":"","sources":["../src/web.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAMnD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAA;AASnD,MAAM,WAAW,KAAK;IACpB,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,oBAAoB,CAAC,EAAE,OAAO,CAAA;CAC/B;AAED,eAAO,MAAM,sBAAsB,iBACpB,KAAK,uBAqFnB,CAAA;AAED,eAAO,MAAM,mBAAmB,sBACZ,KAAK,KACtB,gBAAgB,EAwClB,CAAA;AAED,eAAO,MAAM,sBAAsB,YAAa,KAAK,qDAkDpD,CAAA;AAED,eAAO,MAAM,yBAAyB,0BAOrC,CAAA;AAED,eAAO,MAAM,4BAA4B,aAAa,KAAK;;;;;;;CAa1D,CAAA;AAGD,eAAO,MAAM,wBAAwB,sCAIlC,mBAAmB,SAYrB,CAAA"}
package/dist/web.js ADDED
@@ -0,0 +1,239 @@
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 web_exports = {};
30
+ __export(web_exports, {
31
+ getWebSideBabelConfigPath: () => getWebSideBabelConfigPath,
32
+ getWebSideBabelPlugins: () => getWebSideBabelPlugins,
33
+ getWebSideBabelPresets: () => getWebSideBabelPresets,
34
+ getWebSideDefaultBabelConfig: () => getWebSideDefaultBabelConfig,
35
+ getWebSideOverrides: () => getWebSideOverrides,
36
+ registerWebSideBabelHook: () => registerWebSideBabelHook
37
+ });
38
+ module.exports = __toCommonJS(web_exports);
39
+ var import_fs = __toESM(require("fs"));
40
+ var import_path = __toESM(require("path"));
41
+ var import_project_config = require("@redmix/project-config");
42
+ var import_common = require("./common");
43
+ const getWebSideBabelPlugins = ({ forJest } = { forJest: false }) => {
44
+ const config = (0, import_project_config.getConfig)();
45
+ const useReactCompiler = config.experimental?.reactCompiler?.enabled && config.experimental?.reactCompiler?.lintOnly === false;
46
+ const useTrustedDocumentsGqlTag = config.graphql.trustedDocuments;
47
+ const rwjsPaths = (0, import_project_config.getPaths)();
48
+ const tsConfigs = (0, import_common.parseTypeScriptConfigFiles)();
49
+ const plugins = [
50
+ // It is important that this plugin run first, as noted here: https://react.dev/learn/react-compiler
51
+ useReactCompiler && ["babel-plugin-react-compiler", { target: "19" }],
52
+ // === Import path handling
53
+ [
54
+ "babel-plugin-module-resolver",
55
+ {
56
+ alias: {
57
+ src: (
58
+ // Jest monorepo and multi project runner is not correctly determining
59
+ // the `cwd`: https://github.com/facebook/jest/issues/7359
60
+ forJest ? rwjsPaths.web.src : "./src"
61
+ ),
62
+ // adds the paths from [ts|js]config.json to the module resolver
63
+ ...(0, import_common.getPathsFromTypeScriptConfig)(tsConfigs.web, rwjsPaths.web.base),
64
+ $api: rwjsPaths.api.base
65
+ },
66
+ root: [rwjsPaths.web.base],
67
+ cwd: "packagejson",
68
+ loglevel: "silent"
69
+ // to silence the unnecessary warnings
70
+ },
71
+ "rwjs-module-resolver"
72
+ ],
73
+ [
74
+ require("./plugins/babel-plugin-redwood-directory-named-import").default,
75
+ void 0,
76
+ "rwjs-directory-named-modules"
77
+ ],
78
+ // === Auto imports, and transforms
79
+ [
80
+ "babel-plugin-auto-import",
81
+ {
82
+ declarations: [
83
+ {
84
+ // import { React } from 'react'
85
+ default: "React",
86
+ path: "react"
87
+ },
88
+ // A project can turn on trusted graphql documents
89
+ // If projects do not use trusted documents (default)
90
+ // it auto-imports the gql tag from graphql-tag
91
+ !useTrustedDocumentsGqlTag && {
92
+ // import gql from 'graphql-tag'
93
+ default: "gql",
94
+ path: "graphql-tag"
95
+ },
96
+ // if projects use trusted documents
97
+ // then it auto-imports the gql function from the generated codegen client preset
98
+ useTrustedDocumentsGqlTag && {
99
+ // import { gql } from 'src/graphql/gql'
100
+ members: ["gql"],
101
+ path: `web/src/graphql/gql`
102
+ }
103
+ ].filter(Boolean)
104
+ },
105
+ "rwjs-web-auto-import"
106
+ ],
107
+ ["babel-plugin-graphql-tag", void 0, "rwjs-babel-graphql-tag"],
108
+ process.env.NODE_ENV !== "development" && [
109
+ require("./plugins/babel-plugin-redwood-remove-dev-fatal-error-page").default,
110
+ void 0,
111
+ "rwjs-remove-dev-fatal-error-page"
112
+ ]
113
+ ].filter(Boolean);
114
+ return plugins;
115
+ };
116
+ const getWebSideOverrides = ({ forPrerender } = { forPrerender: false }) => {
117
+ const overrides = [
118
+ {
119
+ test: /.+Cell.(js|tsx|jsx)$/,
120
+ plugins: [require("./plugins/babel-plugin-redwood-cell").default]
121
+ },
122
+ // Automatically import files in `./web/src/pages/*` in to
123
+ // the `./web/src/Routes.[ts|jsx]` file.
124
+ {
125
+ test: /Routes.(js|tsx|jsx)$/,
126
+ plugins: [
127
+ [
128
+ require("./plugins/babel-plugin-redwood-routes-auto-loader").default,
129
+ // The plugin will modify the Routes file differently based on what
130
+ // context we're building for
131
+ {
132
+ forPrerender
133
+ },
134
+ "babel-plugin-redwood-routes-auto-loader"
135
+ ]
136
+ ]
137
+ },
138
+ // ** Files ending in `Cell.mock.[js,ts]` **
139
+ // Automatically determine keys for saving and retrieving mock data.
140
+ // Only required for storybook and jest
141
+ process.env.NODE_ENV !== "production" && {
142
+ test: /.+Cell.mock.(js|ts)$/,
143
+ plugins: [
144
+ require("./plugins/babel-plugin-redwood-mock-cell-data").default
145
+ ]
146
+ }
147
+ ];
148
+ return overrides.filter(
149
+ (override) => {
150
+ return !!override;
151
+ }
152
+ );
153
+ };
154
+ const getWebSideBabelPresets = (options) => {
155
+ if (options.forPrerender || options.forJest || options.forJavaScriptLinting) {
156
+ let reactPresetConfig = { runtime: "automatic" };
157
+ if (getWebSideBabelConfigPath()) {
158
+ const userProjectConfig = require(getWebSideBabelConfigPath());
159
+ userProjectConfig.presets?.forEach(
160
+ (preset) => {
161
+ if (!Array.isArray(preset)) {
162
+ return;
163
+ }
164
+ const [presetName, presetConfig] = preset;
165
+ if (presetName === "@babel/preset-react") {
166
+ reactPresetConfig = presetConfig;
167
+ }
168
+ }
169
+ );
170
+ }
171
+ return [
172
+ ["@babel/preset-react", reactPresetConfig],
173
+ [
174
+ "@babel/preset-env",
175
+ {
176
+ // the targets are set in <userProject>/web/package.json
177
+ useBuiltIns: "usage",
178
+ corejs: {
179
+ version: import_common.CORE_JS_VERSION,
180
+ proposals: true
181
+ },
182
+ exclude: [
183
+ // Remove class-properties from preset-env, and include separately
184
+ // https://github.com/webpack/webpack/issues/9708
185
+ "@babel/plugin-transform-class-properties",
186
+ "@babel/plugin-transform-private-methods"
187
+ ]
188
+ },
189
+ "rwjs-babel-preset-env"
190
+ ],
191
+ ["@babel/preset-typescript", void 0, "rwjs-babel-preset-typescript"]
192
+ ];
193
+ }
194
+ return [];
195
+ };
196
+ const getWebSideBabelConfigPath = () => {
197
+ const customBabelConfig = import_path.default.join((0, import_project_config.getPaths)().web.base, "babel.config.js");
198
+ if (import_fs.default.existsSync(customBabelConfig)) {
199
+ return customBabelConfig;
200
+ } else {
201
+ return void 0;
202
+ }
203
+ };
204
+ const getWebSideDefaultBabelConfig = (options = {}) => {
205
+ return {
206
+ presets: getWebSideBabelPresets(options),
207
+ plugins: getWebSideBabelPlugins(options),
208
+ overrides: getWebSideOverrides(options),
209
+ extends: getWebSideBabelConfigPath(),
210
+ babelrc: false,
211
+ ignore: ["node_modules"]
212
+ };
213
+ };
214
+ const registerWebSideBabelHook = ({
215
+ plugins = [],
216
+ overrides = [],
217
+ options = {}
218
+ } = {}) => {
219
+ const defaultOptions = getWebSideDefaultBabelConfig(options);
220
+ (0, import_common.registerBabel)({
221
+ ...defaultOptions,
222
+ root: (0, import_project_config.getPaths)().base,
223
+ extensions: [".js", ".ts", ".tsx", ".jsx"],
224
+ plugins: [...defaultOptions.plugins, ...plugins],
225
+ cache: false,
226
+ // We only register for prerender currently
227
+ // Static importing pages makes sense
228
+ overrides: [...getWebSideOverrides({ forPrerender: true }), ...overrides]
229
+ });
230
+ };
231
+ // Annotate the CommonJS export names for ESM import in node:
232
+ 0 && (module.exports = {
233
+ getWebSideBabelConfigPath,
234
+ getWebSideBabelPlugins,
235
+ getWebSideBabelPresets,
236
+ getWebSideDefaultBabelConfig,
237
+ getWebSideOverrides,
238
+ registerWebSideBabelHook
239
+ });
package/package.json ADDED
@@ -0,0 +1,60 @@
1
+ {
2
+ "name": "@redmix/babel-config",
3
+ "version": "0.0.1",
4
+ "repository": {
5
+ "type": "git",
6
+ "url": "git+https://github.com/redmix-run/redmix.git",
7
+ "directory": "packages/babel-config"
8
+ },
9
+ "license": "MIT",
10
+ "exports": "./dist/index.js",
11
+ "types": "./dist/index.d.ts",
12
+ "files": [
13
+ "dist"
14
+ ],
15
+ "scripts": {
16
+ "build": "tsx ./build.mts && run build:types",
17
+ "build:pack": "yarn pack -o redmix-babel-config.tgz",
18
+ "build:types": "tsc --build --verbose",
19
+ "build:watch": "nodemon --watch src --ext \"js,ts,tsx\" --ignore dist --exec \"yarn build\"",
20
+ "prepublishOnly": "NODE_ENV=production yarn build",
21
+ "test": "vitest run",
22
+ "test:watch": "vitest watch"
23
+ },
24
+ "dependencies": {
25
+ "@babel/core": "^7.26.10",
26
+ "@babel/parser": "7.26.10",
27
+ "@babel/plugin-transform-class-properties": "7.25.9",
28
+ "@babel/plugin-transform-private-methods": "7.25.9",
29
+ "@babel/plugin-transform-private-property-in-object": "7.25.9",
30
+ "@babel/plugin-transform-react-jsx": "7.25.9",
31
+ "@babel/plugin-transform-runtime": "7.26.10",
32
+ "@babel/preset-env": "7.26.9",
33
+ "@babel/preset-react": "7.26.3",
34
+ "@babel/preset-typescript": "7.26.0",
35
+ "@babel/register": "7.25.9",
36
+ "@babel/runtime-corejs3": "7.26.10",
37
+ "@babel/traverse": "7.26.10",
38
+ "@redmix/project-config": "0.0.1",
39
+ "babel-plugin-auto-import": "1.1.0",
40
+ "babel-plugin-graphql-tag": "3.3.0",
41
+ "babel-plugin-module-resolver": "5.0.2",
42
+ "core-js": "3.38.1",
43
+ "fast-glob": "3.3.2",
44
+ "graphql": "16.9.0",
45
+ "typescript": "5.6.2"
46
+ },
47
+ "devDependencies": {
48
+ "@redmix/framework-tools": "0.0.1",
49
+ "@types/babel-plugin-tester": "9.0.10",
50
+ "@types/babel__core": "7.20.5",
51
+ "@types/node": "20.17.10",
52
+ "babel-plugin-tester": "11.0.4",
53
+ "tsx": "4.19.3",
54
+ "vitest": "2.1.9"
55
+ },
56
+ "publishConfig": {
57
+ "access": "public"
58
+ },
59
+ "gitHead": "688027c97502c500ebbede9cdc7cc51545a8dcf3"
60
+ }