@cedarjs/babel-config 5.0.4-next.167 → 5.0.4

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 (33) hide show
  1. package/dist/api.d.ts +10 -42
  2. package/dist/api.d.ts.map +1 -1
  3. package/dist/api.js +111 -84
  4. package/dist/common.d.ts +10 -2
  5. package/dist/common.d.ts.map +1 -1
  6. package/dist/common.js +75 -20
  7. package/dist/index.d.ts +3 -3
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +48 -28
  10. package/dist/plugins/babel-plugin-cedar-gqlorm-inject.d.ts +32 -0
  11. package/dist/plugins/babel-plugin-cedar-gqlorm-inject.d.ts.map +1 -0
  12. package/dist/plugins/babel-plugin-cedar-gqlorm-inject.js +154 -0
  13. package/dist/plugins/babel-plugin-cedar-graphql-options-extract.d.ts +5 -0
  14. package/dist/plugins/babel-plugin-cedar-graphql-options-extract.d.ts.map +1 -0
  15. package/dist/plugins/babel-plugin-cedar-graphql-options-extract.js +88 -0
  16. package/dist/plugins/{babel-plugin-handler-als-wrapping.d.ts → babel-plugin-redwood-context-wrapping.d.ts} +1 -1
  17. package/dist/plugins/babel-plugin-redwood-context-wrapping.d.ts.map +1 -0
  18. package/dist/plugins/{babel-plugin-handler-als-wrapping.js → babel-plugin-redwood-context-wrapping.js} +39 -19
  19. package/dist/plugins/babel-plugin-redwood-directory-named-import.js +39 -9
  20. package/dist/plugins/babel-plugin-redwood-import-dir.js +40 -10
  21. package/dist/plugins/babel-plugin-redwood-job-path-injector.js +37 -7
  22. package/dist/plugins/babel-plugin-redwood-mock-cell-data.d.ts.map +1 -1
  23. package/dist/plugins/babel-plugin-redwood-mock-cell-data.js +52 -19
  24. package/dist/plugins/babel-plugin-redwood-otel-wrapping.d.ts +5 -0
  25. package/dist/plugins/babel-plugin-redwood-otel-wrapping.d.ts.map +1 -0
  26. package/dist/plugins/babel-plugin-redwood-otel-wrapping.js +329 -0
  27. package/dist/plugins/babel-plugin-redwood-remove-dev-fatal-error-page.js +23 -3
  28. package/dist/plugins/babel-plugin-redwood-routes-auto-loader.js +51 -27
  29. package/dist/plugins/prettier.config.js +28 -0
  30. package/dist/web.d.ts.map +1 -1
  31. package/dist/web.js +71 -48
  32. package/package.json +7 -7
  33. package/dist/plugins/babel-plugin-handler-als-wrapping.d.ts.map +0 -1
package/dist/api.d.ts CHANGED
@@ -6,59 +6,27 @@ export declare const getApiSideBabelPresets: ({ presetEnv }?: {
6
6
  }) => TransformOptions["presets"];
7
7
  export type PluginList = PluginShape[];
8
8
  type PluginShape = [PluginTarget, PluginOptions, undefined | string] | [PluginTarget, PluginOptions];
9
- export declare const getApiSideBabelPlugins: ({ forVite, projectIsEsm, }?: {
10
- forVite?: boolean | undefined;
9
+ export declare const getApiSideBabelPlugins: ({ openTelemetry, projectIsEsm, }?: {
10
+ openTelemetry?: boolean | undefined;
11
11
  projectIsEsm?: boolean | undefined;
12
- }) => PluginList;
13
- /**
14
- * Purpose-built equivalent of `getApiSideBabelPlugins({ forVite: true })` for
15
- * the Vite-driven api pipelines (buildCedarApp, the api dev middleware, and
16
- * the esbuild/standalone-Vite api builds in @cedarjs/internal).
17
- *
18
- * Every Cedar-specific Babel plugin is gated behind `!forVite` in
19
- * `getApiSideBabelPlugins` because these pipelines replace them with
20
- * dedicated Vite/esbuild transforms:
21
- * - JSX/TypeScript compilation: handled natively by Vite/esbuild
22
- * - babel-plugin-module-resolver (`src/` and tsconfig `paths` aliases):
23
- * cedar-api-src-redirect + vite-tsconfig-paths (Vite) or applySrcAlias +
24
- * applyTsconfigPaths (esbuild); ESM extension rewriting is covered by
25
- * applyEsmExtensions
26
- * - directory-named imports: cedarDirectoryNamedImportPlugin /
27
- * applyDirectoryNamedImport
28
- * - auto-imports (gql, context): cedarAutoImportsPlugin / applyAutoImports
29
- * - graphql-tag: vite-plugin-graphql-tag
30
- * - glob imports: cedarImportDirPlugin / applyImportDir
31
- *
32
- * Only the common plugins remain — and that list is currently empty, which
33
- * is why the Vite pipelines skip Babel entirely unless the project has a
34
- * custom api/babel.config.js.
35
- *
36
- * The `projectIsEsm` option needs no equivalent here: it only affects the
37
- * module-resolver `resolvePath` hook, which is a `!forVite` plugin.
38
- */
39
- export declare const getApiSideBabelPluginsForVite: () => PluginList;
12
+ }) => ([PluginTarget, PluginOptions, string | undefined] | [PluginTarget, PluginOptions])[];
40
13
  export declare const getApiSideBabelConfigPath: () => string | undefined;
41
- export declare const getApiSideBabelOverrides: ({ forVite, projectIsEsm, forJest, }?: {
42
- forVite?: boolean | undefined;
14
+ export declare const getApiSideBabelOverrides: ({ projectIsEsm, forJest, }?: {
43
15
  projectIsEsm?: boolean | undefined;
44
16
  forJest?: boolean | undefined;
45
17
  }) => TransformOptions[];
46
- /**
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
- */
53
- export declare const getApiSideDefaultBabelConfig: () => {
18
+ export declare const getApiSideDefaultBabelConfig: ({ projectIsEsm, forJest, }?: {
19
+ projectIsEsm?: boolean | undefined;
20
+ forJest?: boolean | undefined;
21
+ }) => {
54
22
  presets: import("@babel/core").PluginItem[] | null | undefined;
55
- plugins: PluginList;
23
+ plugins: ([PluginTarget, PluginOptions, string | undefined] | [PluginTarget, PluginOptions])[];
56
24
  overrides: TransformOptions[];
57
25
  extends: string | undefined;
58
26
  babelrc: boolean;
59
27
  ignore: string[];
60
28
  };
61
29
  export declare const registerApiSideBabelHook: ({ plugins, ...rest }?: RegisterHookOptions) => void;
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>;
30
+ export declare const transformWithBabel: (sourceCode: string, filename: string, plugins: TransformOptions["plugins"], sourceMaps?: TransformOptions["sourceMaps"]) => Promise<import("@babel/core").BabelFileResult | null>;
63
31
  export {};
64
32
  //# 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,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"}
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;AAetD,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,0FAiGL,CAAA;AAED,eAAO,MAAM,yBAAyB,0BAOrC,CAAA;AAED,eAAO,MAAM,wBAAwB,GAAI;;;CAGnC,KA8BgB,gBAAgB,EACrC,CAAA;AAED,eAAO,MAAM,4BAA4B,GAAI;;;CAGvC;;;;;;;CASL,CAAA;AAGD,eAAO,MAAM,wBAAwB,GAAI,uBAGtC,mBAAwB,SAe1B,CAAA;AAED,eAAO,MAAM,kBAAkB,GAC7B,YAAY,MAAM,EAClB,UAAU,MAAM,EAChB,SAAS,gBAAgB,CAAC,SAAS,CAAC,EACpC,aAAY,gBAAgB,CAAC,YAAY,CAAY,0DAmBtD,CAAA"}
package/dist/api.js CHANGED
@@ -1,17 +1,56 @@
1
- import fs from "node:fs";
2
- import path from "node:path";
3
- import { transformAsync } from "@babel/core";
4
- import { resolvePath } from "babel-plugin-module-resolver";
5
- import { getPaths, projectSideIsEsm } from "@cedarjs/project-config";
6
- import {
7
- getPathsFromTypeScriptConfig,
8
- parseTypeScriptConfigFiles,
9
- registerBabel
10
- } from "./common.js";
11
- import handlerAlsWrappingPlugin from "./plugins/babel-plugin-handler-als-wrapping.js";
12
- import pluginRedwoodDirectoryNamedImport from "./plugins/babel-plugin-redwood-directory-named-import.js";
13
- import pluginRedwoodImportDir from "./plugins/babel-plugin-redwood-import-dir.js";
14
- import pluginRedwoodJobPathInjector from "./plugins/babel-plugin-redwood-job-path-injector.js";
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
+ TARGETS_NODE: () => TARGETS_NODE,
32
+ getApiSideBabelConfigPath: () => getApiSideBabelConfigPath,
33
+ getApiSideBabelOverrides: () => getApiSideBabelOverrides,
34
+ getApiSideBabelPlugins: () => getApiSideBabelPlugins,
35
+ getApiSideBabelPresets: () => getApiSideBabelPresets,
36
+ getApiSideDefaultBabelConfig: () => getApiSideDefaultBabelConfig,
37
+ registerApiSideBabelHook: () => registerApiSideBabelHook,
38
+ transformWithBabel: () => transformWithBabel
39
+ });
40
+ module.exports = __toCommonJS(api_exports);
41
+ var import_node_fs = __toESM(require("node:fs"));
42
+ var import_node_path = __toESM(require("node:path"));
43
+ var import_core = require("@babel/core");
44
+ var import_babel_plugin_module_resolver = require("babel-plugin-module-resolver");
45
+ var import_project_config = require("@cedarjs/project-config");
46
+ var import_common = require("./common.js");
47
+ var import_babel_plugin_cedar_gqlorm_inject = __toESM(require("./plugins/babel-plugin-cedar-gqlorm-inject.js"));
48
+ var import_babel_plugin_cedar_graphql_options_extract = __toESM(require("./plugins/babel-plugin-cedar-graphql-options-extract.js"));
49
+ var import_babel_plugin_redwood_context_wrapping = __toESM(require("./plugins/babel-plugin-redwood-context-wrapping.js"));
50
+ var import_babel_plugin_redwood_directory_named_import = __toESM(require("./plugins/babel-plugin-redwood-directory-named-import.js"));
51
+ var import_babel_plugin_redwood_import_dir = __toESM(require("./plugins/babel-plugin-redwood-import-dir.js"));
52
+ var import_babel_plugin_redwood_job_path_injector = __toESM(require("./plugins/babel-plugin-redwood-job-path-injector.js"));
53
+ var import_babel_plugin_redwood_otel_wrapping = __toESM(require("./plugins/babel-plugin-redwood-otel-wrapping.js"));
15
54
  const TARGETS_NODE = "24";
16
55
  const getApiSideBabelPresets = ({ presetEnv } = { presetEnv: false }) => {
17
56
  return [
@@ -36,34 +75,25 @@ const getApiSideBabelPresets = ({ presetEnv } = { presetEnv: false }) => {
36
75
  ].filter(Boolean);
37
76
  };
38
77
  const getApiSideBabelPlugins = ({
39
- forVite = false,
78
+ openTelemetry = false,
40
79
  projectIsEsm = false
41
80
  } = {}) => {
42
- if (forVite) {
43
- return getApiSideBabelPluginsForVite();
44
- }
45
- const tsConfig = parseTypeScriptConfigFiles();
81
+ const tsConfig = (0, import_common.parseTypeScriptConfigFiles)();
46
82
  const plugins = [
83
+ ...(0, import_common.getCommonPlugins)(),
47
84
  // Needed to support `/** @jsxImportSource custom-jsx-library */`
48
85
  // comments in JSX files
49
86
  ["@babel/plugin-transform-react-jsx", { runtime: "automatic" }],
50
- // For the non-Vite consumers this function serves (Jest,
51
- // registerApiSideBabelHook / Babel registerRequire paths such as
52
- // data-migrate CJS and prerender CJS):
53
- // • alias config: rewrites `src/` and tsconfig paths to relative paths
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.
87
+ ["@babel/plugin-transform-runtime", {}],
58
88
  [
59
89
  "babel-plugin-module-resolver",
60
90
  {
61
91
  alias: {
62
92
  src: "./src",
63
93
  // adds the paths from [ts|js]config.json to the module resolver
64
- ...getPathsFromTypeScriptConfig(tsConfig.api, getPaths().api.base)
94
+ ...(0, import_common.getPathsFromTypeScriptConfig)(tsConfig.api, (0, import_project_config.getPaths)().api.base)
65
95
  },
66
- root: [getPaths().api.base],
96
+ root: [(0, import_project_config.getPaths)().api.base],
67
97
  cwd: "packagejson",
68
98
  loglevel: "silent",
69
99
  // to silence the unnecessary warnings
@@ -71,16 +101,16 @@ const getApiSideBabelPlugins = ({
71
101
  const isDataMigrate = process.argv[2] === "data-migrate";
72
102
  const isPrerender = process.argv[2] === "prerender";
73
103
  const importPath = /.*\/.*\.js$/.test(sourcePath) && (isDataMigrate || isPrerender) ? sourcePath.replace(/\.js$/, "") : sourcePath;
74
- const resolvedPath = resolvePath(importPath, currentFile, opts);
104
+ const resolvedPath = (0, import_babel_plugin_module_resolver.resolvePath)(importPath, currentFile, opts);
75
105
  if (!resolvedPath || !projectIsEsm || resolvedPath.includes("/**/")) {
76
106
  return resolvedPath;
77
107
  }
78
- const currentFileDir = path.dirname(currentFile);
79
- const joinedPath = path.join(currentFileDir, resolvedPath);
80
- if (fs.existsSync(joinedPath + ".js") || fs.existsSync(joinedPath + ".ts")) {
108
+ const currentFileDir = import_node_path.default.dirname(currentFile);
109
+ const joinedPath = import_node_path.default.join(currentFileDir, resolvedPath);
110
+ if (import_node_fs.default.existsSync(joinedPath + ".js") || import_node_fs.default.existsSync(joinedPath + ".ts")) {
81
111
  return resolvedPath + ".js";
82
112
  }
83
- if (fs.existsSync(joinedPath + ".jsx") || fs.existsSync(joinedPath + ".tsx")) {
113
+ if (import_node_fs.default.existsSync(joinedPath + ".jsx") || import_node_fs.default.existsSync(joinedPath + ".tsx")) {
84
114
  return resolvedPath + ".jsx";
85
115
  }
86
116
  return resolvedPath;
@@ -88,16 +118,11 @@ const getApiSideBabelPlugins = ({
88
118
  },
89
119
  "rwjs-api-module-resolver"
90
120
  ],
91
- // Vite/esbuild use cedarDirectoryNamedImportPlugin / applyDirectoryNamedImport
92
- // instead of this babel plugin
93
121
  [
94
- pluginRedwoodDirectoryNamedImport,
122
+ import_babel_plugin_redwood_directory_named_import.default,
95
123
  void 0,
96
124
  "rwjs-babel-directory-named-modules"
97
125
  ],
98
- // Auto-import is handled by cedarAutoImportsPlugin / applyAutoImports for
99
- // Vite/esbuild; this Babel plugin serves the remaining non-Vite consumers
100
- // (Jest, registerApiSideBabelHook).
101
126
  [
102
127
  "babel-plugin-auto-import",
103
128
  {
@@ -116,60 +141,68 @@ const getApiSideBabelPlugins = ({
116
141
  },
117
142
  "rwjs-babel-auto-import"
118
143
  ],
144
+ // FIXME: `graphql-tag` is not working: https://github.com/redwoodjs/redwood/pull/3193
119
145
  ["babel-plugin-graphql-tag", void 0, "rwjs-babel-graphql-tag"],
120
- // For Vite builds, glob imports are handled by cedarImportDirPlugin (Vite)
121
- // or applyImportDir (esbuild). Keep the Babel plugin only for
122
- // non-Vite consumers: Jest, console, and data-migrate.
123
- [pluginRedwoodImportDir, {}, "rwjs-babel-glob-import-dir"]
146
+ [import_babel_plugin_redwood_import_dir.default, {}, "rwjs-babel-glob-import-dir"],
147
+ openTelemetry && [
148
+ import_babel_plugin_redwood_otel_wrapping.default,
149
+ void 0,
150
+ "rwjs-babel-otel-wrapping"
151
+ ]
124
152
  ];
125
- return plugins;
126
- };
127
- const getApiSideBabelPluginsForVite = () => {
128
- return [];
153
+ return plugins.filter((n) => Boolean(n));
129
154
  };
130
155
  const getApiSideBabelConfigPath = () => {
131
- const p = path.join(getPaths().api.base, "babel.config.js");
132
- if (fs.existsSync(p)) {
156
+ const p = import_node_path.default.join((0, import_project_config.getPaths)().api.base, "babel.config.js");
157
+ if (import_node_fs.default.existsSync(p)) {
133
158
  return p;
134
159
  } else {
135
160
  return;
136
161
  }
137
162
  };
138
163
  const getApiSideBabelOverrides = ({
139
- forVite = false,
140
164
  projectIsEsm = false,
141
165
  forJest = false
142
166
  } = {}) => {
143
167
  const overrides = [
144
- // Apply handler ALS wrapping to all functions (Jest only; Vite uses
145
- // handlerAlsWrappingPlugin instead)
168
+ // Extract graphql options from the graphql function
169
+ // NOTE: this must come before the context wrapping
170
+ {
171
+ // match */api/src/functions/graphql.js|ts
172
+ test: /.+api(?:[\\|/])src(?:[\\|/])functions(?:[\\|/])graphql\.(?:js|ts)$/,
173
+ plugins: [import_babel_plugin_cedar_graphql_options_extract.default, import_babel_plugin_cedar_gqlorm_inject.default]
174
+ },
175
+ // Apply context wrapping to all functions (Jest only; Vite uses
176
+ // cedarContextWrappingPlugin instead)
146
177
  forJest && {
147
178
  // match */api/src/functions/*.js|ts
148
179
  test: /.+api(?:[\\|/])src(?:[\\|/])functions(?:[\\|/]).+.(?:js|ts)$/,
149
180
  plugins: [
150
181
  [
151
- handlerAlsWrappingPlugin,
182
+ import_babel_plugin_redwood_context_wrapping.default,
152
183
  {
153
184
  projectIsEsm
154
185
  }
155
186
  ]
156
187
  ]
157
188
  },
158
- // Add import names and paths to job definitions. Vite uses
159
- // cedarjsJobPathInjectorPlugin instead.
160
- !forVite && {
189
+ // Add import names and paths to job definitions
190
+ {
161
191
  // match */api/src/jobs/*.js|ts
162
192
  test: /.+api(?:[\\|/])src(?:[\\|/])jobs(?:[\\|/]).+.(?:js|ts)$/,
163
- plugins: [[pluginRedwoodJobPathInjector]]
193
+ plugins: [[import_babel_plugin_redwood_job_path_injector.default]]
164
194
  }
165
195
  ].filter(Boolean);
166
196
  return overrides;
167
197
  };
168
- const getApiSideDefaultBabelConfig = () => {
198
+ const getApiSideDefaultBabelConfig = ({
199
+ projectIsEsm = false,
200
+ forJest = false
201
+ } = {}) => {
169
202
  return {
170
203
  presets: getApiSideBabelPresets(),
171
- plugins: getApiSideBabelPlugins(),
172
- overrides: getApiSideBabelOverrides({ forJest: true }),
204
+ plugins: getApiSideBabelPlugins({ projectIsEsm }),
205
+ overrides: getApiSideBabelOverrides({ projectIsEsm, forJest }),
173
206
  extends: getApiSideBabelConfigPath(),
174
207
  babelrc: false,
175
208
  ignore: ["node_modules"]
@@ -179,51 +212,45 @@ const registerApiSideBabelHook = ({
179
212
  plugins = [],
180
213
  ...rest
181
214
  } = {}) => {
182
- const projectIsEsm = projectSideIsEsm("api");
183
- registerBabel({
215
+ const defaultOptions = getApiSideDefaultBabelConfig({
216
+ projectIsEsm: (0, import_project_config.projectSideIsEsm)("api")
217
+ });
218
+ (0, import_common.registerBabel)({
219
+ ...defaultOptions,
184
220
  presets: getApiSideBabelPresets({
185
221
  presetEnv: true
186
222
  }),
187
- overrides: getApiSideBabelOverrides({ projectIsEsm }),
188
- extends: getApiSideBabelConfigPath(),
189
- babelrc: false,
190
- ignore: ["node_modules"],
191
223
  extensions: [".js", ".ts", ".jsx", ".tsx"],
192
- plugins: [...getApiSideBabelPlugins({ projectIsEsm }), ...plugins],
224
+ plugins: [...defaultOptions.plugins, ...plugins],
193
225
  cache: false,
194
226
  ...rest
195
227
  });
196
228
  };
197
- const transformWithBabel = async (sourceCode, filename, plugins, sourceMaps = "inline", forVite = false, inputSourceMap = void 0) => {
198
- const result = transformAsync(sourceCode, {
199
- presets: getApiSideBabelPresets(),
200
- overrides: getApiSideBabelOverrides({
201
- forVite,
202
- projectIsEsm: projectSideIsEsm("api")
203
- }),
204
- extends: getApiSideBabelConfigPath(),
205
- babelrc: false,
206
- ignore: ["node_modules"],
207
- cwd: getPaths().api.base,
229
+ const transformWithBabel = async (sourceCode, filename, plugins, sourceMaps = "inline") => {
230
+ const defaultOptions = getApiSideDefaultBabelConfig({
231
+ projectIsEsm: (0, import_project_config.projectSideIsEsm)("api")
232
+ });
233
+ const result = (0, import_core.transformAsync)(sourceCode, {
234
+ ...defaultOptions,
235
+ cwd: (0, import_project_config.getPaths)().api.base,
208
236
  filename,
209
237
  // The default 'inline' embeds the map as a data URL in result.code,
210
238
  // which esbuild consumes when it reads from the result. Vite callers
211
239
  // pass sourceMaps: true because they extract result.map separately for
212
240
  // SSR source map chaining.
213
241
  sourceMaps,
214
- plugins,
215
- inputSourceMap
242
+ plugins
216
243
  });
217
244
  return result;
218
245
  };
219
- export {
246
+ // Annotate the CommonJS export names for ESM import in node:
247
+ 0 && (module.exports = {
220
248
  TARGETS_NODE,
221
249
  getApiSideBabelConfigPath,
222
250
  getApiSideBabelOverrides,
223
251
  getApiSideBabelPlugins,
224
- getApiSideBabelPluginsForVite,
225
252
  getApiSideBabelPresets,
226
253
  getApiSideDefaultBabelConfig,
227
254
  registerApiSideBabelHook,
228
255
  transformWithBabel
229
- };
256
+ });
package/dist/common.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { PluginItem, TransformOptions } from '@babel/core';
1
+ import type { PluginItem, PluginOptions, TransformOptions } from '@babel/core';
2
2
  import type { RegisterOptions } from '@babel/register';
3
3
  import type { Flags as WebFlags } from './web.js';
4
4
  export interface RegisterHookOptions {
@@ -16,7 +16,15 @@ export interface BabelRegisterOptions extends TransformOptions {
16
16
  cache?: boolean;
17
17
  }
18
18
  export declare const registerBabel: (options: RegisterOptions) => void;
19
- export declare const getRouteHookBabelPlugins: () => TransformOptions[];
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
+ })[])[];
20
28
  /**
21
29
  * Finds, reads and parses the [ts|js]config.json file
22
30
  * @returns The config object
@@ -1 +1 @@
1
- {"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../src/common.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAC/D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAMtD,OAAO,KAAK,EAAE,KAAK,IAAI,QAAQ,EAAE,MAAM,UAAU,CAAA;AAOjD,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,sEAAsE;AACtE,MAAM,WAAW,oBAAqB,SAAQ,gBAAgB;IAC5D,UAAU,CAAC,EAAE,MAAM,EAAE,CAAA;IACrB,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB;AAkBD,eAAO,MAAM,aAAa,GAAI,SAAS,eAAe,SAOrD,CAAA;AAID,eAAO,MAAM,wBAAwB,0BAEpC,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,GACvC,QAAQ,uBAAuB,EAC/B,SAAS,MAAM,KACd,MAAM,CAAC,MAAM,EAAE,MAAM,CAqCvB,CAAA"}
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;AAC9E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAMtD,OAAO,KAAK,EAAE,KAAK,IAAI,QAAQ,EAAE,MAAM,UAAU,CAAA;AAEjD,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,sEAAsE;AACtE,MAAM,WAAW,oBAAqB,SAAQ,gBAAgB;IAC5D,UAAU,CAAC,EAAE,MAAM,EAAE,CAAA;IACrB,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB;AAkBD,eAAO,MAAM,aAAa,GAAI,SAAS,eAAe,SAOrD,CAAA;AAED,eAAO,MAAM,gBAAgB,QAAO,CAAC,MAAM,EAAE,aAAa,CAAC,EAE1D,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,GACvC,QAAQ,uBAAuB,EAC/B,SAAS,MAAM,KACd,MAAM,CAAC,MAAM,EAAE,MAAM,CAqCvB,CAAA"}
package/dist/common.js CHANGED
@@ -1,29 +1,82 @@
1
- import fs from "node:fs";
2
- import { createRequire } from "node:module";
3
- import path from "path";
4
- import { parseConfigFileTextToJson } from "typescript";
5
- import { getPaths } from "@cedarjs/project-config";
6
- import { getWebSideBabelPlugins } from "./web.js";
7
- const require2 = createRequire(import.meta.url);
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
+ getCommonPlugins: () => getCommonPlugins,
32
+ getPathsFromTypeScriptConfig: () => getPathsFromTypeScriptConfig,
33
+ getRouteHookBabelPlugins: () => getRouteHookBabelPlugins,
34
+ parseTypeScriptConfigFiles: () => parseTypeScriptConfigFiles,
35
+ registerBabel: () => registerBabel
36
+ });
37
+ module.exports = __toCommonJS(common_exports);
38
+ var import_node_fs = __toESM(require("node:fs"));
39
+ var import_path = __toESM(require("path"));
40
+ var import_typescript = require("typescript");
41
+ var import_project_config = require("@cedarjs/project-config");
42
+ var import_web = require("./web.js");
8
43
  const registerBabel = (options) => {
9
- require2("@babel/register")(options);
44
+ require("@babel/register")(options);
45
+ };
46
+ const getCommonPlugins = () => {
47
+ return [];
10
48
  };
11
49
  const getRouteHookBabelPlugins = () => {
12
- return [...getWebSideBabelPlugins()];
50
+ return [
51
+ ...(0, import_web.getWebSideBabelPlugins)(),
52
+ [
53
+ "babel-plugin-module-resolver",
54
+ {
55
+ alias: {
56
+ "api/src": "./src"
57
+ },
58
+ root: [(0, import_project_config.getPaths)().api.base],
59
+ cwd: "packagejson",
60
+ loglevel: "silent"
61
+ // to silence the unnecessary warnings
62
+ },
63
+ "rwjs-api-module-resolver"
64
+ ]
65
+ ];
13
66
  };
14
67
  const parseTypeScriptConfigFiles = () => {
15
- const rwPaths = getPaths();
68
+ const rwPaths = (0, import_project_config.getPaths)();
16
69
  const parseConfigFile = (basePath) => {
17
- let configPath = path.join(basePath, "tsconfig.json");
18
- if (!fs.existsSync(configPath)) {
19
- configPath = path.join(basePath, "jsconfig.json");
20
- if (!fs.existsSync(configPath)) {
70
+ let configPath = import_path.default.join(basePath, "tsconfig.json");
71
+ if (!import_node_fs.default.existsSync(configPath)) {
72
+ configPath = import_path.default.join(basePath, "jsconfig.json");
73
+ if (!import_node_fs.default.existsSync(configPath)) {
21
74
  return null;
22
75
  }
23
76
  }
24
- return parseConfigFileTextToJson(
77
+ return (0, import_typescript.parseConfigFileTextToJson)(
25
78
  configPath,
26
- fs.readFileSync(configPath, "utf-8")
79
+ import_node_fs.default.readFileSync(configPath, "utf-8")
27
80
  );
28
81
  };
29
82
  const apiConfig = parseConfigFile(rwPaths.api.base);
@@ -43,7 +96,7 @@ const getPathsFromTypeScriptConfig = (config, rootDir) => {
43
96
  const { baseUrl, paths } = config.compilerOptions;
44
97
  let absoluteBase;
45
98
  if (baseUrl) {
46
- absoluteBase = path.isAbsolute(baseUrl) ? baseUrl : path.join(rootDir, baseUrl);
99
+ absoluteBase = import_path.default.isAbsolute(baseUrl) ? baseUrl : import_path.default.join(rootDir, baseUrl);
47
100
  } else {
48
101
  absoluteBase = rootDir;
49
102
  }
@@ -53,14 +106,16 @@ const getPathsFromTypeScriptConfig = (config, rootDir) => {
53
106
  continue;
54
107
  }
55
108
  const aliasKey = key.replace("/*", "");
56
- const aliasValue = path.join(absoluteBase, value[0].replace("/*", ""));
109
+ const aliasValue = import_path.default.join(absoluteBase, value[0].replace("/*", ""));
57
110
  pathsObj[aliasKey] = aliasValue;
58
111
  }
59
112
  return pathsObj;
60
113
  };
61
- export {
114
+ // Annotate the CommonJS export names for ESM import in node:
115
+ 0 && (module.exports = {
116
+ getCommonPlugins,
62
117
  getPathsFromTypeScriptConfig,
63
118
  getRouteHookBabelPlugins,
64
119
  parseTypeScriptConfigFiles,
65
120
  registerBabel
66
- };
121
+ });
package/dist/index.d.ts CHANGED
@@ -11,13 +11,11 @@ TARGETS_NODE,
11
11
  getApiSideBabelConfigPath,
12
12
  /** Used by @cedarjs/internal and @cedarjs/testing */
13
13
  getApiSideBabelPlugins,
14
- /** Used by @cedarjs/internal and @cedarjs/vite */
15
- getApiSideBabelPluginsForVite,
16
14
  /** Used by @cedarjs/testing */
17
15
  getApiSideBabelPresets,
18
16
  /** Used by @cedarjs/testing and @cedarjs/eslint-config */
19
17
  getApiSideDefaultBabelConfig,
20
- /** Used by @cedarjs/cli, @cedarjs/cli-helpers and @cedarjs/prerender */
18
+ /** Used by @cedarjs/cli, @remix/cli-helpers and @cedarjs/prerender */
21
19
  registerApiSideBabelHook,
22
20
  /** Used by @cedarjs/internal and @cedarjs/vite */
23
21
  transformWithBabel, } from './api.js';
@@ -48,6 +46,8 @@ getWebSideOverrides,
48
46
  registerWebSideBabelHook, } from './web.js';
49
47
  export type { Flags } from './web.js';
50
48
  export {
49
+ /** Used by our eslint-config */
50
+ getCommonPlugins,
51
51
  /**
52
52
  * @deprecated This export isn't used by the framework, so it'll be removed
53
53
  * in a future version.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO;AACL;;;GAGG;AACH,YAAY;AACZ;;;GAGG;AACH,yBAAyB;AACzB,qDAAqD;AACrD,sBAAsB;AACtB,kDAAkD;AAClD,6BAA6B;AAC7B,+BAA+B;AAC/B,sBAAsB;AACtB,0DAA0D;AAC1D,4BAA4B;AAC5B,wEAAwE;AACxE,wBAAwB;AACxB,kDAAkD;AAClD,kBAAkB,GACnB,MAAM,UAAU,CAAA;AAEjB,OAAO;AACL;;;GAGG;AACH,yBAAyB;AACzB;;;GAGG;AACH,sBAAsB;AACtB;;;GAGG;AACH,sBAAsB;AACtB,mEAAmE;AACnE,4BAA4B;AAC5B;;;GAGG;AACH,mBAAmB;AACnB,iCAAiC;AACjC,wBAAwB,GACzB,MAAM,UAAU,CAAA;AAEjB,YAAY,EAAE,KAAK,EAAE,MAAM,UAAU,CAAA;AAErC,OAAO;AACL;;;GAGG;AACH,4BAA4B,IAAI,kBAAkB;AAClD,mBAAmB;AACnB,wBAAwB;AACxB;;;GAGG;AACH,0BAA0B;AAC1B;;;GAGG;AACH,aAAa,GACd,MAAM,aAAa,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO;AACL;;;GAGG;AACH,YAAY;AACZ;;;GAGG;AACH,yBAAyB;AACzB,qDAAqD;AACrD,sBAAsB;AACtB,+BAA+B;AAC/B,sBAAsB;AACtB,0DAA0D;AAC1D,4BAA4B;AAC5B,sEAAsE;AACtE,wBAAwB;AACxB,kDAAkD;AAClD,kBAAkB,GACnB,MAAM,UAAU,CAAA;AAEjB,OAAO;AACL;;;GAGG;AACH,yBAAyB;AACzB;;;GAGG;AACH,sBAAsB;AACtB;;;GAGG;AACH,sBAAsB;AACtB,mEAAmE;AACnE,4BAA4B;AAC5B;;;GAGG;AACH,mBAAmB;AACnB,iCAAiC;AACjC,wBAAwB,GACzB,MAAM,UAAU,CAAA;AAEjB,YAAY,EAAE,KAAK,EAAE,MAAM,UAAU,CAAA;AAErC,OAAO;AACL,iCAAiC;AACjC,gBAAgB;AAChB;;;GAGG;AACH,4BAA4B,IAAI,kBAAkB;AAClD,mBAAmB;AACnB,wBAAwB;AACxB;;;GAGG;AACH,0BAA0B;AAC1B;;;GAGG;AACH,aAAa,GACd,MAAM,aAAa,CAAA"}