@cedarjs/babel-config 7.0.0-rc.128 → 7.0.1-next.305
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 +28 -18
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +30 -48
- package/dist/plugins/babel-plugin-redwood-routes-auto-loader.d.ts.map +1 -1
- package/dist/resolveFromProject.d.ts +38 -0
- package/dist/resolveFromProject.d.ts.map +1 -0
- package/dist/resolveFromProject.js +51 -0
- package/dist/web.d.ts +1 -6
- package/dist/web.d.ts.map +1 -1
- package/dist/web.js +5 -15
- package/package.json +17 -7
- package/dist/plugins/babel-plugin-handler-als-wrapping.d.ts +0 -7
- package/dist/plugins/babel-plugin-handler-als-wrapping.d.ts.map +0 -1
- package/dist/plugins/babel-plugin-handler-als-wrapping.js +0 -114
- package/dist/plugins/babel-plugin-redwood-remove-dev-fatal-error-page.d.ts +0 -5
- package/dist/plugins/babel-plugin-redwood-remove-dev-fatal-error-page.d.ts.map +0 -1
- package/dist/plugins/babel-plugin-redwood-remove-dev-fatal-error-page.js +0 -21
package/dist/api.d.ts
CHANGED
|
@@ -1,14 +1,21 @@
|
|
|
1
|
+
import type * as BabelCore from '@babel/core';
|
|
1
2
|
import type { PluginOptions, PluginTarget, TransformOptions } from '@babel/core';
|
|
2
3
|
import type { RegisterHookOptions } from './common.js';
|
|
3
4
|
export declare const TARGETS_NODE = "24";
|
|
4
|
-
|
|
5
|
-
presetEnv
|
|
6
|
-
|
|
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"];
|
|
7
15
|
export type PluginList = PluginShape[];
|
|
8
16
|
type PluginShape = [PluginTarget, PluginOptions, undefined | string] | [PluginTarget, PluginOptions];
|
|
9
|
-
export declare const getApiSideBabelPlugins: ({ forVite
|
|
17
|
+
export declare const getApiSideBabelPlugins: ({ forVite }?: {
|
|
10
18
|
forVite?: boolean | undefined;
|
|
11
|
-
projectIsEsm?: boolean | undefined;
|
|
12
19
|
}) => PluginList;
|
|
13
20
|
/**
|
|
14
21
|
* Purpose-built equivalent of `getApiSideBabelPlugins({ forVite: true })` for
|
|
@@ -33,32 +40,35 @@ export declare const getApiSideBabelPlugins: ({ forVite, projectIsEsm, }?: {
|
|
|
33
40
|
* is why the Vite pipelines skip Babel entirely unless the project has a
|
|
34
41
|
* custom api/babel.config.js.
|
|
35
42
|
*
|
|
36
|
-
* The `projectIsEsm` option needs no equivalent here: it only affects the
|
|
37
|
-
* module-resolver `resolvePath` hook, which is a `!forVite` plugin.
|
|
38
43
|
*/
|
|
39
44
|
export declare const getApiSideBabelPluginsForVite: () => PluginList;
|
|
40
45
|
export declare const getApiSideBabelConfigPath: () => string | undefined;
|
|
41
|
-
export declare const getApiSideBabelOverrides: ({ forVite
|
|
46
|
+
export declare const getApiSideBabelOverrides: ({ forVite }?: {
|
|
42
47
|
forVite?: boolean | undefined;
|
|
43
|
-
projectIsEsm?: boolean | undefined;
|
|
44
|
-
forJest?: boolean | undefined;
|
|
45
48
|
}) => TransformOptions[];
|
|
46
49
|
/**
|
|
47
|
-
* The default api-side Babel config for
|
|
48
|
-
*
|
|
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.
|
|
50
|
+
* The default api-side Babel config for the Babel ESLint parser
|
|
51
|
+
* (@cedarjs/eslint-config).
|
|
52
52
|
*/
|
|
53
53
|
export declare const getApiSideDefaultBabelConfig: () => {
|
|
54
|
-
presets:
|
|
54
|
+
presets: BabelCore.PluginItem[] | null | undefined;
|
|
55
55
|
plugins: PluginList;
|
|
56
|
-
overrides: TransformOptions[];
|
|
56
|
+
overrides: BabelCore.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
|
-
|
|
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>;
|
|
63
73
|
export {};
|
|
64
74
|
//# 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;
|
|
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"}
|
package/dist/api.js
CHANGED
|
@@ -1,22 +1,27 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
|
-
import { transformAsync } from "@babel/core";
|
|
4
3
|
import { resolvePath } from "babel-plugin-module-resolver";
|
|
5
|
-
import { getPaths
|
|
4
|
+
import { getPaths } from "@cedarjs/project-config";
|
|
6
5
|
import {
|
|
7
6
|
getPathsFromTypeScriptConfig,
|
|
8
7
|
parseTypeScriptConfigFiles,
|
|
9
8
|
registerBabel
|
|
10
9
|
} from "./common.js";
|
|
11
|
-
import handlerAlsWrappingPlugin from "./plugins/babel-plugin-handler-als-wrapping.js";
|
|
12
10
|
import pluginRedwoodDirectoryNamedImport from "./plugins/babel-plugin-redwood-directory-named-import.js";
|
|
13
11
|
import pluginRedwoodImportDir from "./plugins/babel-plugin-redwood-import-dir.js";
|
|
14
12
|
import pluginRedwoodJobPathInjector from "./plugins/babel-plugin-redwood-job-path-injector.js";
|
|
13
|
+
import {
|
|
14
|
+
loadBabelCoreFromProject,
|
|
15
|
+
resolveFromProject
|
|
16
|
+
} from "./resolveFromProject.js";
|
|
15
17
|
const TARGETS_NODE = "24";
|
|
16
|
-
const getApiSideBabelPresets = ({
|
|
18
|
+
const getApiSideBabelPresets = ({
|
|
19
|
+
presetEnv = false,
|
|
20
|
+
resolvePreset = (packageName) => packageName
|
|
21
|
+
} = {}) => {
|
|
17
22
|
return [
|
|
18
23
|
[
|
|
19
|
-
"@babel/preset-typescript",
|
|
24
|
+
resolvePreset("@babel/preset-typescript"),
|
|
20
25
|
{
|
|
21
26
|
isTSX: true,
|
|
22
27
|
allExtensions: true
|
|
@@ -25,7 +30,7 @@ const getApiSideBabelPresets = ({ presetEnv } = { presetEnv: false }) => {
|
|
|
25
30
|
],
|
|
26
31
|
// Preset-env is required when we are not doing the transpilation with esbuild
|
|
27
32
|
presetEnv && [
|
|
28
|
-
"@babel/preset-env",
|
|
33
|
+
resolvePreset("@babel/preset-env"),
|
|
29
34
|
{
|
|
30
35
|
targets: {
|
|
31
36
|
node: TARGETS_NODE
|
|
@@ -35,10 +40,7 @@ const getApiSideBabelPresets = ({ presetEnv } = { presetEnv: false }) => {
|
|
|
35
40
|
]
|
|
36
41
|
].filter(Boolean);
|
|
37
42
|
};
|
|
38
|
-
const getApiSideBabelPlugins = ({
|
|
39
|
-
forVite = false,
|
|
40
|
-
projectIsEsm = false
|
|
41
|
-
} = {}) => {
|
|
43
|
+
const getApiSideBabelPlugins = ({ forVite = false } = {}) => {
|
|
42
44
|
if (forVite) {
|
|
43
45
|
return getApiSideBabelPluginsForVite();
|
|
44
46
|
}
|
|
@@ -47,14 +49,13 @@ const getApiSideBabelPlugins = ({
|
|
|
47
49
|
// Needed to support `/** @jsxImportSource custom-jsx-library */`
|
|
48
50
|
// comments in JSX files
|
|
49
51
|
["@babel/plugin-transform-react-jsx", { runtime: "automatic" }],
|
|
50
|
-
// For the non-Vite consumers this function serves (
|
|
51
|
-
//
|
|
52
|
-
// data-migrate CJS and prerender CJS):
|
|
52
|
+
// For the non-Vite consumers this function serves (the Babel ESLint
|
|
53
|
+
// parser and registerApiSideBabelHook):
|
|
53
54
|
// • alias config: rewrites `src/` and tsconfig paths to relative paths
|
|
54
|
-
// • resolvePath: appends `.js`/`.jsx` to extensionless imports
|
|
55
|
-
//
|
|
56
|
-
//
|
|
57
|
-
//
|
|
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.
|
|
58
59
|
[
|
|
59
60
|
"babel-plugin-module-resolver",
|
|
60
61
|
{
|
|
@@ -72,7 +73,7 @@ const getApiSideBabelPlugins = ({
|
|
|
72
73
|
const isPrerender = process.argv[2] === "prerender";
|
|
73
74
|
const importPath = /.*\/.*\.js$/.test(sourcePath) && (isDataMigrate || isPrerender) ? sourcePath.replace(/\.js$/, "") : sourcePath;
|
|
74
75
|
const resolvedPath = resolvePath(importPath, currentFile, opts);
|
|
75
|
-
if (!resolvedPath ||
|
|
76
|
+
if (!resolvedPath || resolvedPath.includes("/**/")) {
|
|
76
77
|
return resolvedPath;
|
|
77
78
|
}
|
|
78
79
|
const currentFileDir = path.dirname(currentFile);
|
|
@@ -135,26 +136,8 @@ const getApiSideBabelConfigPath = () => {
|
|
|
135
136
|
return;
|
|
136
137
|
}
|
|
137
138
|
};
|
|
138
|
-
const getApiSideBabelOverrides = ({
|
|
139
|
-
forVite = false,
|
|
140
|
-
projectIsEsm = false,
|
|
141
|
-
forJest = false
|
|
142
|
-
} = {}) => {
|
|
139
|
+
const getApiSideBabelOverrides = ({ forVite = false } = {}) => {
|
|
143
140
|
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
|
-
},
|
|
158
141
|
// Add import names and paths to job definitions. Vite uses
|
|
159
142
|
// cedarjsJobPathInjectorPlugin instead.
|
|
160
143
|
!forVite && {
|
|
@@ -169,7 +152,7 @@ const getApiSideDefaultBabelConfig = () => {
|
|
|
169
152
|
return {
|
|
170
153
|
presets: getApiSideBabelPresets(),
|
|
171
154
|
plugins: getApiSideBabelPlugins(),
|
|
172
|
-
overrides: getApiSideBabelOverrides(
|
|
155
|
+
overrides: getApiSideBabelOverrides(),
|
|
173
156
|
extends: getApiSideBabelConfigPath(),
|
|
174
157
|
babelrc: false,
|
|
175
158
|
ignore: ["node_modules"]
|
|
@@ -179,29 +162,28 @@ const registerApiSideBabelHook = ({
|
|
|
179
162
|
plugins = [],
|
|
180
163
|
...rest
|
|
181
164
|
} = {}) => {
|
|
182
|
-
const projectIsEsm = projectSideIsEsm("api");
|
|
183
165
|
registerBabel({
|
|
184
166
|
presets: getApiSideBabelPresets({
|
|
185
167
|
presetEnv: true
|
|
186
168
|
}),
|
|
187
|
-
overrides: getApiSideBabelOverrides(
|
|
169
|
+
overrides: getApiSideBabelOverrides(),
|
|
188
170
|
extends: getApiSideBabelConfigPath(),
|
|
189
171
|
babelrc: false,
|
|
190
172
|
ignore: ["node_modules"],
|
|
191
173
|
extensions: [".js", ".ts", ".jsx", ".tsx"],
|
|
192
|
-
plugins: [...getApiSideBabelPlugins(
|
|
174
|
+
plugins: [...getApiSideBabelPlugins(), ...plugins],
|
|
193
175
|
cache: false,
|
|
194
176
|
...rest
|
|
195
177
|
});
|
|
196
178
|
};
|
|
197
179
|
const transformWithBabel = async (sourceCode, filename, plugins, sourceMaps = "inline", forVite = false, inputSourceMap = void 0) => {
|
|
198
|
-
const
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
}),
|
|
204
|
-
extends:
|
|
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,
|
|
205
187
|
babelrc: false,
|
|
206
188
|
ignore: ["node_modules"],
|
|
207
189
|
cwd: getPaths().api.base,
|
|
@@ -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;
|
|
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"}
|
|
@@ -0,0 +1,38 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,51 @@
|
|
|
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
|
+
};
|
package/dist/web.d.ts
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
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;
|
|
9
4
|
/** changes what babel-plugin-redwood-routes-auto-loader does */
|
|
10
5
|
forPrerender?: boolean;
|
|
11
6
|
/**
|
|
@@ -14,7 +9,7 @@ export interface Flags {
|
|
|
14
9
|
*/
|
|
15
10
|
forVite?: boolean;
|
|
16
11
|
}
|
|
17
|
-
export declare const getWebSideBabelPlugins: ({
|
|
12
|
+
export declare const getWebSideBabelPlugins: ({ forVite }?: Flags) => TransformOptions[];
|
|
18
13
|
export declare const getWebSideOverrides: ({ forPrerender, forVite }?: Flags) => TransformOptions[];
|
|
19
14
|
export declare const getWebSideBabelPresets: (options: Flags) => ((string | undefined)[] | (string | object)[])[];
|
|
20
15
|
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
|
|
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"}
|
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 = ({
|
|
12
|
+
const getWebSideBabelPlugins = ({ forVite } = {}) => {
|
|
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,10 +26,7 @@ const getWebSideBabelPlugins = ({ forJest, forVite } = { forJest: false }) => {
|
|
|
26
26
|
"babel-plugin-module-resolver",
|
|
27
27
|
{
|
|
28
28
|
alias: {
|
|
29
|
-
|
|
30
|
-
// determining the `cwd`:
|
|
31
|
-
// https://github.com/facebook/jest/issues/7359
|
|
32
|
-
src: forJest ? rwjsPaths.web.src : "./src",
|
|
29
|
+
src: "./src",
|
|
33
30
|
// adds the paths from [ts|js]config.json to the module resolver
|
|
34
31
|
...getPathsFromTypeScriptConfig(tsConfigs.web, rwjsPaths.web.base),
|
|
35
32
|
$api: rwjsPaths.api.base
|
|
@@ -90,11 +87,6 @@ const getWebSideBabelPlugins = ({ forJest, forVite } = { forJest: false }) => {
|
|
|
90
87
|
"babel-plugin-graphql-tag",
|
|
91
88
|
void 0,
|
|
92
89
|
"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"
|
|
98
90
|
]
|
|
99
91
|
].filter(Boolean);
|
|
100
92
|
return plugins;
|
|
@@ -120,11 +112,9 @@ const getWebSideOverrides = ({ forPrerender, forVite } = { forPrerender: false }
|
|
|
120
112
|
},
|
|
121
113
|
// ** Files ending in `Cell.mock.[js,ts]` **
|
|
122
114
|
// Automatically determine keys for saving and retrieving mock data.
|
|
123
|
-
// Only required for storybook and jest
|
|
124
115
|
// Vite/Vitest runs the mock-cell-data transform via its own plugin
|
|
125
|
-
// (vite-plugin-cedar-mock-cell-data)
|
|
126
|
-
// Babel
|
|
127
|
-
// the override active for non-Vite contexts.
|
|
116
|
+
// (vite-plugin-cedar-mock-cell-data); this override covers the non-Vite
|
|
117
|
+
// Babel contexts.
|
|
128
118
|
!forVite && process.env.NODE_ENV !== "production" && {
|
|
129
119
|
test: /.+Cell.mock.(js|ts)$/,
|
|
130
120
|
plugins: [
|
|
@@ -139,7 +129,7 @@ const getWebSideOverrides = ({ forPrerender, forVite } = { forPrerender: false }
|
|
|
139
129
|
);
|
|
140
130
|
};
|
|
141
131
|
const getWebSideBabelPresets = (options) => {
|
|
142
|
-
if (options.forPrerender
|
|
132
|
+
if (options.forPrerender) {
|
|
143
133
|
let reactPresetConfig = { runtime: "automatic" };
|
|
144
134
|
if (getWebSideBabelConfigPath()) {
|
|
145
135
|
const userProjectConfig = require2(getWebSideBabelConfigPath());
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cedarjs/babel-config",
|
|
3
|
-
"version": "7.0.
|
|
3
|
+
"version": "7.0.1-next.305",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/cedarjs/cedar.git",
|
|
@@ -26,16 +26,13 @@
|
|
|
26
26
|
"test:watch": "vitest watch"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@babel/core": "^7.26.10",
|
|
30
29
|
"@babel/parser": "7.29.9",
|
|
31
30
|
"@babel/plugin-transform-react-jsx": "7.29.7",
|
|
32
|
-
"@babel/plugin-transform-runtime": "7.29.7",
|
|
33
31
|
"@babel/preset-env": "7.29.7",
|
|
34
32
|
"@babel/preset-react": "7.29.7",
|
|
35
|
-
"@babel/preset-typescript": "7.29.7",
|
|
36
33
|
"@babel/register": "7.29.7",
|
|
37
34
|
"@babel/traverse": "7.29.8",
|
|
38
|
-
"@cedarjs/project-config": "7.0.
|
|
35
|
+
"@cedarjs/project-config": "7.0.1-next.305",
|
|
39
36
|
"babel-plugin-auto-import": "1.1.0",
|
|
40
37
|
"babel-plugin-graphql-tag": "3.3.0",
|
|
41
38
|
"babel-plugin-module-resolver": "5.0.3",
|
|
@@ -44,8 +41,9 @@
|
|
|
44
41
|
"typescript": "5.9.3"
|
|
45
42
|
},
|
|
46
43
|
"devDependencies": {
|
|
47
|
-
"@
|
|
48
|
-
"@
|
|
44
|
+
"@babel/core": "^7.26.10",
|
|
45
|
+
"@babel/preset-typescript": "7.29.7",
|
|
46
|
+
"@cedarjs/framework-tools": "7.0.1-next.305",
|
|
49
47
|
"@types/babel-plugin-tester": "11.0.0",
|
|
50
48
|
"@types/babel__core": "7.20.5",
|
|
51
49
|
"@types/babel__register": "7.17.3",
|
|
@@ -53,6 +51,18 @@
|
|
|
53
51
|
"babel-plugin-tester": "11.0.4",
|
|
54
52
|
"vitest": "4.1.11"
|
|
55
53
|
},
|
|
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
|
+
},
|
|
56
66
|
"engines": {
|
|
57
67
|
"node": ">=24"
|
|
58
68
|
},
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,114 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,21 +0,0 @@
|
|
|
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
|
-
};
|