@cedarjs/babel-config 7.0.0-canary.3260 → 7.0.0-rc.127

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.
package/dist/api.d.ts CHANGED
@@ -1,21 +1,14 @@
1
- import type * as BabelCore from '@babel/core';
2
1
  import type { PluginOptions, PluginTarget, TransformOptions } from '@babel/core';
3
2
  import type { RegisterHookOptions } from './common.js';
4
3
  export declare const TARGETS_NODE = "24";
5
- interface ApiSideBabelPresetsOptions {
6
- presetEnv?: boolean;
7
- /**
8
- * Maps a preset's package name to what is put in the `presets` option.
9
- * Babel resolves bare package names relative to the file it compiles;
10
- * passing a resolver that returns absolute paths makes resolution explicit.
11
- */
12
- resolvePreset?: (packageName: string) => string;
13
- }
14
- export declare const getApiSideBabelPresets: ({ presetEnv, resolvePreset, }?: ApiSideBabelPresetsOptions) => TransformOptions["presets"];
4
+ export declare const getApiSideBabelPresets: ({ presetEnv }?: {
5
+ presetEnv: boolean;
6
+ }) => TransformOptions["presets"];
15
7
  export type PluginList = PluginShape[];
16
8
  type PluginShape = [PluginTarget, PluginOptions, undefined | string] | [PluginTarget, PluginOptions];
17
- export declare const getApiSideBabelPlugins: ({ forVite }?: {
9
+ export declare const getApiSideBabelPlugins: ({ forVite, projectIsEsm, }?: {
18
10
  forVite?: boolean | undefined;
11
+ projectIsEsm?: boolean | undefined;
19
12
  }) => PluginList;
20
13
  /**
21
14
  * Purpose-built equivalent of `getApiSideBabelPlugins({ forVite: true })` for
@@ -40,35 +33,32 @@ export declare const getApiSideBabelPlugins: ({ forVite }?: {
40
33
  * is why the Vite pipelines skip Babel entirely unless the project has a
41
34
  * custom api/babel.config.js.
42
35
  *
36
+ * The `projectIsEsm` option needs no equivalent here: it only affects the
37
+ * module-resolver `resolvePath` hook, which is a `!forVite` plugin.
43
38
  */
44
39
  export declare const getApiSideBabelPluginsForVite: () => PluginList;
45
40
  export declare const getApiSideBabelConfigPath: () => string | undefined;
46
- export declare const getApiSideBabelOverrides: ({ forVite }?: {
41
+ export declare const getApiSideBabelOverrides: ({ forVite, projectIsEsm, forJest, }?: {
47
42
  forVite?: boolean | undefined;
43
+ projectIsEsm?: boolean | undefined;
44
+ forJest?: boolean | undefined;
48
45
  }) => TransformOptions[];
49
46
  /**
50
- * The default api-side Babel config for the Babel ESLint parser
51
- * (@cedarjs/eslint-config).
47
+ * The default api-side Babel config for Jest (@cedarjs/testing) and the
48
+ * Babel ESLint parser (@cedarjs/eslint-config). The Jest-only handler ALS
49
+ * wrapping override is always included: it only matches api/src/functions
50
+ * files, and for the parse-only ESLint consumer transform plugins have no
51
+ * effect.
52
52
  */
53
53
  export declare const getApiSideDefaultBabelConfig: () => {
54
- presets: BabelCore.PluginItem[] | null | undefined;
54
+ presets: import("@babel/core").PluginItem[] | null | undefined;
55
55
  plugins: PluginList;
56
- overrides: BabelCore.TransformOptions[];
56
+ overrides: TransformOptions[];
57
57
  extends: string | undefined;
58
58
  babelrc: boolean;
59
59
  ignore: string[];
60
60
  };
61
61
  export declare const registerApiSideBabelHook: ({ plugins, ...rest }?: RegisterHookOptions) => void;
62
- /**
63
- * Runs `sourceCode` through Babel with Cedar's api-side config plus the
64
- * project's `api/babel.config.js` when there is one.
65
- *
66
- * `@babel/core` and `@babel/preset-typescript` are optional peer dependencies
67
- * of this package, resolved from the project's api workspace; a missing
68
- * install fails with an actionable error. Every caller checks for
69
- * `api/babel.config.js` before calling this, so Babel is only ever loaded for
70
- * projects that opted into a custom api-side Babel config.
71
- */
72
- export declare const transformWithBabel: (sourceCode: string, filename: string, plugins: TransformOptions["plugins"], sourceMaps?: TransformOptions["sourceMaps"], forVite?: boolean, inputSourceMap?: TransformOptions["inputSourceMap"]) => Promise<BabelCore.BabelFileResult | null>;
62
+ export declare const transformWithBabel: (sourceCode: string, filename: string, plugins: TransformOptions["plugins"], sourceMaps?: TransformOptions["sourceMaps"], forVite?: boolean, inputSourceMap?: TransformOptions["inputSourceMap"]) => Promise<import("@babel/core").BabelFileResult | null>;
73
63
  export {};
74
64
  //# sourceMappingURL=api.d.ts.map
package/dist/api.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,KAAK,SAAS,MAAM,aAAa,CAAA;AAC7C,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAKhF,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AActD,eAAO,MAAM,YAAY,OAAO,CAAA;AAKhC,UAAU,0BAA0B;IAClC,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB;;;;OAIG;IACH,aAAa,CAAC,EAAE,CAAC,WAAW,EAAE,MAAM,KAAK,MAAM,CAAA;CAChD;AAED,eAAO,MAAM,sBAAsB,GAAI,gCAGpC,0BAA+B,KAoBX,gBAAgB,CAAC,SAAS,CAChD,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,GAAI;;CAAwB,eA4G9D,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,6BAA6B,QAAO,UAEhD,CAAA;AAED,eAAO,MAAM,yBAAyB,0BAOrC,CAAA;AAED,eAAO,MAAM,wBAAwB,GAAI;;CAAwB,KAU3C,gBAAgB,EACrC,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,4BAA4B;;;;;;;CASxC,CAAA;AAGD,eAAO,MAAM,wBAAwB,GAAI,uBAGtC,mBAAwB,SAc1B,CAAA;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,kBAAkB,GAC7B,YAAY,MAAM,EAClB,UAAU,MAAM,EAChB,SAAS,gBAAgB,CAAC,SAAS,CAAC,EACpC,aAAY,gBAAgB,CAAC,YAAY,CAAY,EACrD,iBAAe,EAIf,iBAAgB,gBAAgB,CAAC,gBAAgB,CAAa,8CAyB/D,CAAA"}
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;AAMhF,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AAWtD,eAAO,MAAM,YAAY,OAAO,CAAA;AAEhC,eAAO,MAAM,sBAAsB,GACjC;;CAAoC,KAqBf,gBAAgB,CAAC,SAAS,CAChD,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,GAAI;;;CAGjC,eA6GL,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,6BAA6B,QAAO,UAEhD,CAAA;AAED,eAAO,MAAM,yBAAyB,0BAOrC,CAAA;AAED,eAAO,MAAM,wBAAwB,GAAI;;;;CAInC,KAwBgB,gBAAgB,EACrC,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,4BAA4B;;;;;;;CASxC,CAAA;AAGD,eAAO,MAAM,wBAAwB,GAAI,uBAGtC,mBAAwB,SAgB1B,CAAA;AAED,eAAO,MAAM,kBAAkB,GAC7B,YAAY,MAAM,EAClB,UAAU,MAAM,EAChB,SAAS,gBAAgB,CAAC,SAAS,CAAC,EACpC,aAAY,gBAAgB,CAAC,YAAY,CAAY,EACrD,iBAAe,EAIf,iBAAgB,gBAAgB,CAAC,gBAAgB,CAAa,0DAuB/D,CAAA"}
package/dist/api.js CHANGED
@@ -1,27 +1,22 @@
1
1
  import fs from "node:fs";
2
2
  import path from "node:path";
3
+ import { transformAsync } from "@babel/core";
3
4
  import { resolvePath } from "babel-plugin-module-resolver";
4
- import { getPaths } from "@cedarjs/project-config";
5
+ import { getPaths, projectSideIsEsm } from "@cedarjs/project-config";
5
6
  import {
6
7
  getPathsFromTypeScriptConfig,
7
8
  parseTypeScriptConfigFiles,
8
9
  registerBabel
9
10
  } from "./common.js";
11
+ import handlerAlsWrappingPlugin from "./plugins/babel-plugin-handler-als-wrapping.js";
10
12
  import pluginRedwoodDirectoryNamedImport from "./plugins/babel-plugin-redwood-directory-named-import.js";
11
13
  import pluginRedwoodImportDir from "./plugins/babel-plugin-redwood-import-dir.js";
12
14
  import pluginRedwoodJobPathInjector from "./plugins/babel-plugin-redwood-job-path-injector.js";
13
- import {
14
- loadBabelCoreFromProject,
15
- resolveFromProject
16
- } from "./resolveFromProject.js";
17
15
  const TARGETS_NODE = "24";
18
- const getApiSideBabelPresets = ({
19
- presetEnv = false,
20
- resolvePreset = (packageName) => packageName
21
- } = {}) => {
16
+ const getApiSideBabelPresets = ({ presetEnv } = { presetEnv: false }) => {
22
17
  return [
23
18
  [
24
- resolvePreset("@babel/preset-typescript"),
19
+ "@babel/preset-typescript",
25
20
  {
26
21
  isTSX: true,
27
22
  allExtensions: true
@@ -30,7 +25,7 @@ const getApiSideBabelPresets = ({
30
25
  ],
31
26
  // Preset-env is required when we are not doing the transpilation with esbuild
32
27
  presetEnv && [
33
- resolvePreset("@babel/preset-env"),
28
+ "@babel/preset-env",
34
29
  {
35
30
  targets: {
36
31
  node: TARGETS_NODE
@@ -40,7 +35,10 @@ const getApiSideBabelPresets = ({
40
35
  ]
41
36
  ].filter(Boolean);
42
37
  };
43
- const getApiSideBabelPlugins = ({ forVite = false } = {}) => {
38
+ const getApiSideBabelPlugins = ({
39
+ forVite = false,
40
+ projectIsEsm = false
41
+ } = {}) => {
44
42
  if (forVite) {
45
43
  return getApiSideBabelPluginsForVite();
46
44
  }
@@ -49,13 +47,14 @@ const getApiSideBabelPlugins = ({ forVite = false } = {}) => {
49
47
  // Needed to support `/** @jsxImportSource custom-jsx-library */`
50
48
  // comments in JSX files
51
49
  ["@babel/plugin-transform-react-jsx", { runtime: "automatic" }],
52
- // For the non-Vite consumers this function serves (the Babel ESLint
53
- // parser and registerApiSideBabelHook):
50
+ // For the non-Vite consumers this function serves (Jest,
51
+ // registerApiSideBabelHook / Babel registerRequire paths such as
52
+ // data-migrate CJS and prerender CJS):
54
53
  // • alias config: rewrites `src/` and tsconfig paths to relative paths
55
- // • resolvePath: appends `.js`/`.jsx` to extensionless imports so Node's
56
- // module resolver can find them, and strips `.js` suffixes in
57
- // data-migrate / prerender contexts where the TypeScript source is
58
- // `.ts` but callers write `.js` import specifiers.
54
+ // • resolvePath: appends `.js`/`.jsx` to extensionless imports in ESM
55
+ // projects so Node's module resolver can find them, and strips `.js`
56
+ // suffixes in data-migrate / prerender contexts where the TypeScript
57
+ // source is `.ts` but callers write `.js` import specifiers.
59
58
  [
60
59
  "babel-plugin-module-resolver",
61
60
  {
@@ -73,7 +72,7 @@ const getApiSideBabelPlugins = ({ forVite = false } = {}) => {
73
72
  const isPrerender = process.argv[2] === "prerender";
74
73
  const importPath = /.*\/.*\.js$/.test(sourcePath) && (isDataMigrate || isPrerender) ? sourcePath.replace(/\.js$/, "") : sourcePath;
75
74
  const resolvedPath = resolvePath(importPath, currentFile, opts);
76
- if (!resolvedPath || resolvedPath.includes("/**/")) {
75
+ if (!resolvedPath || !projectIsEsm || resolvedPath.includes("/**/")) {
77
76
  return resolvedPath;
78
77
  }
79
78
  const currentFileDir = path.dirname(currentFile);
@@ -136,8 +135,26 @@ const getApiSideBabelConfigPath = () => {
136
135
  return;
137
136
  }
138
137
  };
139
- const getApiSideBabelOverrides = ({ forVite = false } = {}) => {
138
+ const getApiSideBabelOverrides = ({
139
+ forVite = false,
140
+ projectIsEsm = false,
141
+ forJest = false
142
+ } = {}) => {
140
143
  const overrides = [
144
+ // Apply handler ALS wrapping to all functions (Jest only; Vite uses
145
+ // handlerAlsWrappingPlugin instead)
146
+ forJest && {
147
+ // match */api/src/functions/*.js|ts
148
+ test: /.+api(?:[\\|/])src(?:[\\|/])functions(?:[\\|/]).+.(?:js|ts)$/,
149
+ plugins: [
150
+ [
151
+ handlerAlsWrappingPlugin,
152
+ {
153
+ projectIsEsm
154
+ }
155
+ ]
156
+ ]
157
+ },
141
158
  // Add import names and paths to job definitions. Vite uses
142
159
  // cedarjsJobPathInjectorPlugin instead.
143
160
  !forVite && {
@@ -152,7 +169,7 @@ const getApiSideDefaultBabelConfig = () => {
152
169
  return {
153
170
  presets: getApiSideBabelPresets(),
154
171
  plugins: getApiSideBabelPlugins(),
155
- overrides: getApiSideBabelOverrides(),
172
+ overrides: getApiSideBabelOverrides({ forJest: true }),
156
173
  extends: getApiSideBabelConfigPath(),
157
174
  babelrc: false,
158
175
  ignore: ["node_modules"]
@@ -162,28 +179,29 @@ const registerApiSideBabelHook = ({
162
179
  plugins = [],
163
180
  ...rest
164
181
  } = {}) => {
182
+ const projectIsEsm = projectSideIsEsm("api");
165
183
  registerBabel({
166
184
  presets: getApiSideBabelPresets({
167
185
  presetEnv: true
168
186
  }),
169
- overrides: getApiSideBabelOverrides(),
187
+ overrides: getApiSideBabelOverrides({ projectIsEsm }),
170
188
  extends: getApiSideBabelConfigPath(),
171
189
  babelrc: false,
172
190
  ignore: ["node_modules"],
173
191
  extensions: [".js", ".ts", ".jsx", ".tsx"],
174
- plugins: [...getApiSideBabelPlugins(), ...plugins],
192
+ plugins: [...getApiSideBabelPlugins({ projectIsEsm }), ...plugins],
175
193
  cache: false,
176
194
  ...rest
177
195
  });
178
196
  };
179
197
  const transformWithBabel = async (sourceCode, filename, plugins, sourceMaps = "inline", forVite = false, inputSourceMap = void 0) => {
180
- const customConfigPath = getApiSideBabelConfigPath();
181
- const babel = loadBabelCoreFromProject();
182
- const resolvePreset = resolveFromProject;
183
- const result = babel.transformAsync(sourceCode, {
184
- presets: getApiSideBabelPresets({ resolvePreset }),
185
- overrides: getApiSideBabelOverrides({ forVite }),
186
- extends: customConfigPath,
198
+ const result = transformAsync(sourceCode, {
199
+ presets: getApiSideBabelPresets(),
200
+ overrides: getApiSideBabelOverrides({
201
+ forVite,
202
+ projectIsEsm: projectSideIsEsm("api")
203
+ }),
204
+ extends: getApiSideBabelConfigPath(),
187
205
  babelrc: false,
188
206
  ignore: ["node_modules"],
189
207
  cwd: getPaths().api.base,
@@ -0,0 +1,7 @@
1
+ import type { PluginObj, types } from '@babel/core';
2
+ export default function ({ types: t }: {
3
+ types: typeof types;
4
+ }, { projectIsEsm }?: {
5
+ projectIsEsm?: boolean;
6
+ }): PluginObj;
7
+ //# sourceMappingURL=babel-plugin-handler-als-wrapping.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"babel-plugin-handler-als-wrapping.d.ts","sourceRoot":"","sources":["../../src/plugins/babel-plugin-handler-als-wrapping.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAkEnD,MAAM,CAAC,OAAO,WACZ,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE;IAAE,KAAK,EAAE,OAAO,KAAK,CAAA;CAAE,EACrC,EAAE,YAAoB,EAAE,GAAE;IAAE,YAAY,CAAC,EAAE,OAAO,CAAA;CAAO,GACxD,SAAS,CA+DX"}
@@ -0,0 +1,114 @@
1
+ function generateWrappedHandler(t, isAsync) {
2
+ const contextStoreVariableDeclaration = t.variableDeclaration("const", [
3
+ t.variableDeclarator(
4
+ t.identifier("__cedar_contextStore"),
5
+ t.callExpression(
6
+ t.memberExpression(
7
+ t.callExpression(t.identifier("__cedar_getAsyncStoreInstance"), []),
8
+ t.identifier("getStore")
9
+ ),
10
+ []
11
+ )
12
+ )
13
+ ]);
14
+ t.addComment(
15
+ contextStoreVariableDeclaration,
16
+ "leading",
17
+ " The store will be undefined if no context isolation has been performed yet",
18
+ true
19
+ );
20
+ return t.arrowFunctionExpression(
21
+ [t.identifier("__cedar_event"), t.identifier("__cedar_context")],
22
+ t.blockStatement([
23
+ contextStoreVariableDeclaration,
24
+ t.ifStatement(
25
+ t.binaryExpression(
26
+ "===",
27
+ t.identifier("__cedar_contextStore"),
28
+ t.identifier("undefined")
29
+ ),
30
+ t.blockStatement([
31
+ t.returnStatement(
32
+ t.callExpression(
33
+ t.memberExpression(
34
+ t.callExpression(
35
+ t.identifier("__cedar_getAsyncStoreInstance"),
36
+ []
37
+ ),
38
+ t.identifier("run")
39
+ ),
40
+ [
41
+ t.newExpression(t.identifier("Map"), []),
42
+ t.identifier("__cedar_handler"),
43
+ t.identifier("__cedar_event"),
44
+ t.identifier("__cedar_context")
45
+ ]
46
+ )
47
+ )
48
+ ])
49
+ ),
50
+ t.returnStatement(
51
+ t.callExpression(t.identifier("__cedar_handler"), [
52
+ t.identifier("__cedar_event"),
53
+ t.identifier("__cedar_context")
54
+ ])
55
+ )
56
+ ]),
57
+ isAsync
58
+ );
59
+ }
60
+ function babel_plugin_handler_als_wrapping_default({ types: t }, { projectIsEsm = false } = {}) {
61
+ return {
62
+ name: "babel-plugin-handler-als-wrapping",
63
+ visitor: {
64
+ ExportNamedDeclaration(path, _state) {
65
+ const declaration = path.node.declaration;
66
+ if (!t.isVariableDeclaration(declaration)) {
67
+ return;
68
+ }
69
+ const identifier = declaration.declarations[0].id;
70
+ if (!t.isIdentifier(identifier)) {
71
+ return;
72
+ }
73
+ if (identifier.name !== "handler") {
74
+ return;
75
+ }
76
+ const parentNode = path.parentPath.node;
77
+ if (!t.isProgram(parentNode)) {
78
+ return;
79
+ }
80
+ path.insertBefore(
81
+ // import { getAsyncStoreInstance as __cedar_getAsyncStoreInstance } from '@cedarjs/context/dist/store'
82
+ t.importDeclaration(
83
+ [
84
+ t.importSpecifier(
85
+ t.identifier("__cedar_getAsyncStoreInstance"),
86
+ t.identifier("getAsyncStoreInstance")
87
+ )
88
+ ],
89
+ t.stringLiteral(
90
+ projectIsEsm ? "@cedarjs/context/dist/store.js" : "@cedarjs/context/dist/store"
91
+ )
92
+ )
93
+ );
94
+ path.insertBefore(
95
+ t.variableDeclaration("const", [
96
+ t.variableDeclarator(
97
+ t.identifier("__cedar_handler"),
98
+ declaration.declarations[0].init
99
+ )
100
+ ])
101
+ );
102
+ let isAsync = false;
103
+ const originalInit = declaration.declarations[0].init;
104
+ if (t.isFunction(originalInit)) {
105
+ isAsync = originalInit.async;
106
+ }
107
+ declaration.declarations[0].init = generateWrappedHandler(t, isAsync);
108
+ }
109
+ }
110
+ };
111
+ }
112
+ export {
113
+ babel_plugin_handler_als_wrapping_default as default
114
+ };
@@ -0,0 +1,5 @@
1
+ import type { PluginObj, types } from '@babel/core';
2
+ export default function ({ types: t }: {
3
+ types: typeof types;
4
+ }): PluginObj;
5
+ //# sourceMappingURL=babel-plugin-redwood-remove-dev-fatal-error-page.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"babel-plugin-redwood-remove-dev-fatal-error-page.d.ts","sourceRoot":"","sources":["../../src/plugins/babel-plugin-redwood-remove-dev-fatal-error-page.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAOnD,MAAM,CAAC,OAAO,WAAW,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE;IAAE,KAAK,EAAE,OAAO,KAAK,CAAA;CAAE,GAAG,SAAS,CAuBzE"}
@@ -0,0 +1,21 @@
1
+ function babel_plugin_redwood_remove_dev_fatal_error_page_default({ types: t }) {
2
+ return {
3
+ name: "babel-plugin-redwood-remove-dev-fatal-error-page",
4
+ visitor: {
5
+ ImportDeclaration(path) {
6
+ if (path.node.source.value === "@cedarjs/web/dist/components/DevFatalErrorPage") {
7
+ const variableDeclaration = t.variableDeclaration("const", [
8
+ t.variableDeclarator(
9
+ t.identifier("DevFatalErrorPage"),
10
+ t.identifier("undefined")
11
+ )
12
+ ]);
13
+ path.replaceWith(variableDeclaration);
14
+ }
15
+ }
16
+ }
17
+ };
18
+ }
19
+ export {
20
+ babel_plugin_redwood_remove_dev_fatal_error_page_default as default
21
+ };
@@ -1 +1 @@
1
- {"version":3,"file":"babel-plugin-redwood-routes-auto-loader.d.ts","sourceRoot":"","sources":["../../src/plugins/babel-plugin-redwood-routes-auto-loader.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAWnD,MAAM,WAAW,aAAa;IAC5B,YAAY,CAAC,EAAE,OAAO,CAAA;CACvB;AA8CD,MAAM,CAAC,OAAO,WACZ,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE;IAAE,KAAK,EAAE,OAAO,KAAK,CAAA;CAAE,EACrC,EAAE,YAAoB,EAAE,EAAE,aAAa,GACtC,SAAS,CA8LX"}
1
+ {"version":3,"file":"babel-plugin-redwood-routes-auto-loader.d.ts","sourceRoot":"","sources":["../../src/plugins/babel-plugin-redwood-routes-auto-loader.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAWnD,MAAM,WAAW,aAAa;IAC5B,YAAY,CAAC,EAAE,OAAO,CAAA;CACvB;AAiDD,MAAM,CAAC,OAAO,WACZ,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE;IAAE,KAAK,EAAE,OAAO,KAAK,CAAA;CAAE,EACrC,EAAE,YAAoB,EAAE,EAAE,aAAa,GACtC,SAAS,CA8LX"}
package/dist/web.d.ts CHANGED
@@ -1,6 +1,11 @@
1
1
  import type { TransformOptions } from '@babel/core';
2
2
  import type { RegisterHookOptions } from './common.js';
3
3
  export interface Flags {
4
+ /**
5
+ * Will change the alias for module-resolver plugin and include a few extra
6
+ * babel plugins
7
+ */
8
+ forJest?: boolean;
4
9
  /** changes what babel-plugin-redwood-routes-auto-loader does */
5
10
  forPrerender?: boolean;
6
11
  /**
@@ -9,7 +14,7 @@ export interface Flags {
9
14
  */
10
15
  forVite?: boolean;
11
16
  }
12
- export declare const getWebSideBabelPlugins: ({ forVite }?: Flags) => TransformOptions[];
17
+ export declare const getWebSideBabelPlugins: ({ forJest, forVite }?: Flags) => TransformOptions[];
13
18
  export declare const getWebSideOverrides: ({ forPrerender, forVite }?: Flags) => TransformOptions[];
14
19
  export declare const getWebSideBabelPresets: (options: Flags) => ((string | undefined)[] | (string | object)[])[];
15
20
  export declare const getWebSideBabelConfigPath: () => string | undefined;
package/dist/web.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"web.d.ts","sourceRoot":"","sources":["../src/web.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAKnD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AAetD,MAAM,WAAW,KAAK;IACpB,gEAAgE;IAChE,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAED,eAAO,MAAM,sBAAsB,GAAI,cAAa,KAAU,uBAgG7D,CAAA;AAED,eAAO,MAAM,mBAAmB,GAC9B,4BAA2B,KAA+B,KACzD,gBAAgB,EAwClB,CAAA;AAED,eAAO,MAAM,sBAAsB,GAAI,SAAS,KAAK,qDAwCpD,CAAA;AAED,eAAO,MAAM,yBAAyB,0BAOrC,CAAA;AAED,eAAO,MAAM,4BAA4B,GAAI,UAAS,KAAU;;;;;;;CAa/D,CAAA;AAGD,eAAO,MAAM,wBAAwB,GAAI,mCAItC,mBAAwB,SAY1B,CAAA"}
1
+ {"version":3,"file":"web.d.ts","sourceRoot":"","sources":["../src/web.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAKnD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AAetD,MAAM,WAAW,KAAK;IACpB;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,gEAAgE;IAChE,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAED,eAAO,MAAM,sBAAsB,GACjC,uBAAsB,KAA0B,uBA2GjD,CAAA;AAED,eAAO,MAAM,mBAAmB,GAC9B,4BAA2B,KAA+B,KACzD,gBAAgB,EA0ClB,CAAA;AAED,eAAO,MAAM,sBAAsB,GAAI,SAAS,KAAK,qDAwCpD,CAAA;AAED,eAAO,MAAM,yBAAyB,0BAOrC,CAAA;AAED,eAAO,MAAM,4BAA4B,GAAI,UAAS,KAAU;;;;;;;CAa/D,CAAA;AAGD,eAAO,MAAM,wBAAwB,GAAI,mCAItC,mBAAwB,SAY1B,CAAA"}
package/dist/web.js CHANGED
@@ -9,7 +9,7 @@ import {
9
9
  getPathsFromTypeScriptConfig
10
10
  } from "./common.js";
11
11
  const require2 = createRequire(import.meta.url);
12
- const getWebSideBabelPlugins = ({ forVite } = {}) => {
12
+ const getWebSideBabelPlugins = ({ forJest, forVite } = { forJest: false }) => {
13
13
  const config = getConfig();
14
14
  const useReactCompiler = config.experimental?.reactCompiler?.enabled && config.experimental?.reactCompiler?.lintOnly === false;
15
15
  const useTrustedDocumentsGqlTag = config.graphql.trustedDocuments;
@@ -26,7 +26,10 @@ const getWebSideBabelPlugins = ({ forVite } = {}) => {
26
26
  "babel-plugin-module-resolver",
27
27
  {
28
28
  alias: {
29
- src: "./src",
29
+ // Jest monorepo and multi project runner is not correctly
30
+ // determining the `cwd`:
31
+ // https://github.com/facebook/jest/issues/7359
32
+ src: forJest ? rwjsPaths.web.src : "./src",
30
33
  // adds the paths from [ts|js]config.json to the module resolver
31
34
  ...getPathsFromTypeScriptConfig(tsConfigs.web, rwjsPaths.web.base),
32
35
  $api: rwjsPaths.api.base
@@ -87,6 +90,11 @@ const getWebSideBabelPlugins = ({ forVite } = {}) => {
87
90
  "babel-plugin-graphql-tag",
88
91
  void 0,
89
92
  "rwjs-babel-graphql-tag"
93
+ ],
94
+ forJest && process.env.NODE_ENV !== "development" && [
95
+ require2("./plugins/babel-plugin-redwood-remove-dev-fatal-error-page").default,
96
+ void 0,
97
+ "rwjs-remove-dev-fatal-error-page"
90
98
  ]
91
99
  ].filter(Boolean);
92
100
  return plugins;
@@ -112,9 +120,11 @@ const getWebSideOverrides = ({ forPrerender, forVite } = { forPrerender: false }
112
120
  },
113
121
  // ** Files ending in `Cell.mock.[js,ts]` **
114
122
  // Automatically determine keys for saving and retrieving mock data.
123
+ // Only required for storybook and jest
115
124
  // Vite/Vitest runs the mock-cell-data transform via its own plugin
116
- // (vite-plugin-cedar-mock-cell-data); this override covers the non-Vite
117
- // Babel contexts.
125
+ // (vite-plugin-cedar-mock-cell-data). Jest (CJS projects) still needs the
126
+ // Babel plugin because it doesn't go through Vite's pipeline, so we keep
127
+ // the override active for non-Vite contexts.
118
128
  !forVite && process.env.NODE_ENV !== "production" && {
119
129
  test: /.+Cell.mock.(js|ts)$/,
120
130
  plugins: [
@@ -129,7 +139,7 @@ const getWebSideOverrides = ({ forPrerender, forVite } = { forPrerender: false }
129
139
  );
130
140
  };
131
141
  const getWebSideBabelPresets = (options) => {
132
- if (options.forPrerender) {
142
+ if (options.forPrerender || options.forJest) {
133
143
  let reactPresetConfig = { runtime: "automatic" };
134
144
  if (getWebSideBabelConfigPath()) {
135
145
  const userProjectConfig = require2(getWebSideBabelConfigPath());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cedarjs/babel-config",
3
- "version": "7.0.0-canary.3260",
3
+ "version": "7.0.0-rc.127",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/cedarjs/cedar.git",
@@ -26,13 +26,16 @@
26
26
  "test:watch": "vitest watch"
27
27
  },
28
28
  "dependencies": {
29
+ "@babel/core": "^7.26.10",
29
30
  "@babel/parser": "7.29.9",
30
31
  "@babel/plugin-transform-react-jsx": "7.29.7",
32
+ "@babel/plugin-transform-runtime": "7.29.7",
31
33
  "@babel/preset-env": "7.29.7",
32
34
  "@babel/preset-react": "7.29.7",
35
+ "@babel/preset-typescript": "7.29.7",
33
36
  "@babel/register": "7.29.7",
34
37
  "@babel/traverse": "7.29.8",
35
- "@cedarjs/project-config": "7.0.0-canary.3260",
38
+ "@cedarjs/project-config": "7.0.0-rc.127",
36
39
  "babel-plugin-auto-import": "1.1.0",
37
40
  "babel-plugin-graphql-tag": "3.3.0",
38
41
  "babel-plugin-module-resolver": "5.0.3",
@@ -41,9 +44,8 @@
41
44
  "typescript": "5.9.3"
42
45
  },
43
46
  "devDependencies": {
44
- "@babel/core": "^7.26.10",
45
- "@babel/preset-typescript": "7.29.7",
46
- "@cedarjs/framework-tools": "7.0.0-canary.3260",
47
+ "@cedarjs/framework-tools": "7.0.0-rc.127",
48
+ "@jridgewell/trace-mapping": "0.3.31",
47
49
  "@types/babel-plugin-tester": "11.0.0",
48
50
  "@types/babel__core": "7.20.5",
49
51
  "@types/babel__register": "7.17.3",
@@ -51,18 +53,6 @@
51
53
  "babel-plugin-tester": "11.0.4",
52
54
  "vitest": "4.1.11"
53
55
  },
54
- "peerDependencies": {
55
- "@babel/core": "^7.26.10",
56
- "@babel/preset-typescript": "^7.29.7"
57
- },
58
- "peerDependenciesMeta": {
59
- "@babel/core": {
60
- "optional": true
61
- },
62
- "@babel/preset-typescript": {
63
- "optional": true
64
- }
65
- },
66
56
  "engines": {
67
57
  "node": ">=24"
68
58
  },
@@ -1,38 +0,0 @@
1
- import type * as BabelCore from '@babel/core';
2
- /**
3
- * The packages a project has to install in its api workspace to use a custom
4
- * `api/babel.config.js`. They are optional peer dependencies of
5
- * `@cedarjs/babel-config`, so projects without a custom config never pay for
6
- * them.
7
- */
8
- export declare const API_BABEL_CONFIG_PACKAGES: readonly ["@babel/core", "@babel/preset-typescript"];
9
- /**
10
- * The Babel major Cedar's api-side config is written for. The
11
- * `@babel/preset-typescript` options Cedar passes (`isTSX`, `allExtensions`)
12
- * only exist in this major.
13
- */
14
- export declare const SUPPORTED_BABEL_MAJOR = 7;
15
- /**
16
- * Builds the error thrown when `api/babel.config.js` exists but one of the
17
- * packages it needs is missing from the project.
18
- */
19
- export declare function getMissingApiBabelPackageMessage(packageName: string): string;
20
- /**
21
- * Builds the error thrown when `api/babel.config.js` exists but the installed
22
- * package is from a Babel major Cedar's api-side config doesn't support.
23
- */
24
- export declare function getUnsupportedApiBabelVersionMessage(packageName: string, version: string): string;
25
- /**
26
- * Resolves `packageName` to an absolute path from the project's api
27
- * workspace. Throws an actionable error when the package isn't installed
28
- * there (so the failure mode is the same no matter how the package manager
29
- * laid out `node_modules`) or when it's from an unsupported Babel major.
30
- */
31
- export declare function resolveFromProject(packageName: string): string;
32
- /**
33
- * Loads the project's copy of `@babel/core`. Resolving from the project
34
- * rather than from this package keeps `@babel/core` out of projects that
35
- * don't use `api/babel.config.js`.
36
- */
37
- export declare function loadBabelCoreFromProject(): typeof BabelCore;
38
- //# sourceMappingURL=resolveFromProject.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"resolveFromProject.d.ts","sourceRoot":"","sources":["../src/resolveFromProject.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,KAAK,SAAS,MAAM,aAAa,CAAA;AAI7C;;;;;GAKG;AACH,eAAO,MAAM,yBAAyB,sDAG5B,CAAA;AAEV;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,IAAI,CAAA;AAMtC;;;GAGG;AACH,wBAAgB,gCAAgC,CAAC,WAAW,EAAE,MAAM,UAMnE;AAED;;;GAGG;AACH,wBAAgB,oCAAoC,CAClD,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,MAAM,UAQhB;AA+BD;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,WAAW,EAAE,MAAM,UAcrD;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,IAAI,OAAO,SAAS,CAI3D"}
@@ -1,51 +0,0 @@
1
- import { createRequire } from "node:module";
2
- import path from "node:path";
3
- import { getPaths } from "@cedarjs/project-config";
4
- const API_BABEL_CONFIG_PACKAGES = [
5
- "@babel/core",
6
- "@babel/preset-typescript"
7
- ];
8
- const SUPPORTED_BABEL_MAJOR = 7;
9
- const INSTALL_COMMAND = `yarn workspace api add -D ${API_BABEL_CONFIG_PACKAGES.map(
10
- (packageName) => `${packageName}@^${SUPPORTED_BABEL_MAJOR}`
11
- ).join(" ")}`;
12
- function getMissingApiBabelPackageMessage(packageName) {
13
- return `api/babel.config.js was found, but ${packageName} is not installed. Custom Babel configuration for the api side needs ${API_BABEL_CONFIG_PACKAGES.join(" and ")}: run \`${INSTALL_COMMAND}\`.`;
14
- }
15
- function getUnsupportedApiBabelVersionMessage(packageName, version) {
16
- return `api/babel.config.js was found, but the installed ${packageName} (${version}) is not supported. Custom Babel configuration for the api side needs ${API_BABEL_CONFIG_PACKAGES.join(" and ")} ${SUPPORTED_BABEL_MAJOR}.x: run \`${INSTALL_COMMAND}\`.`;
17
- }
18
- function createProjectRequire() {
19
- return createRequire(path.join(getPaths().api.base, "package.json"));
20
- }
21
- function assertSupportedMajor(packageName, resolvedPath) {
22
- const packageJson = createRequire(resolvedPath)(
23
- `${packageName}/package.json`
24
- );
25
- const version = typeof packageJson === "object" && packageJson !== null && "version" in packageJson && typeof packageJson.version === "string" ? packageJson.version : void 0;
26
- if (version && Number(version.split(".")[0]) !== SUPPORTED_BABEL_MAJOR) {
27
- throw new Error(getUnsupportedApiBabelVersionMessage(packageName, version));
28
- }
29
- }
30
- function resolveFromProject(packageName) {
31
- const projectRequire = createProjectRequire();
32
- let resolvedPath;
33
- try {
34
- resolvedPath = projectRequire.resolve(packageName);
35
- } catch {
36
- throw new Error(getMissingApiBabelPackageMessage(packageName));
37
- }
38
- assertSupportedMajor(packageName, resolvedPath);
39
- return resolvedPath;
40
- }
41
- function loadBabelCoreFromProject() {
42
- return createProjectRequire()(resolveFromProject("@babel/core"));
43
- }
44
- export {
45
- API_BABEL_CONFIG_PACKAGES,
46
- SUPPORTED_BABEL_MAJOR,
47
- getMissingApiBabelPackageMessage,
48
- getUnsupportedApiBabelVersionMessage,
49
- loadBabelCoreFromProject,
50
- resolveFromProject
51
- };