@cedarjs/babel-config 7.0.0-canary.3015 → 7.0.0-canary.3018
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 +24 -6
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +16 -7
- package/dist/resolveFromProject.d.ts +38 -0
- package/dist/resolveFromProject.d.ts.map +1 -0
- package/dist/resolveFromProject.js +51 -0
- package/package.json +17 -5
package/dist/api.d.ts
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
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
17
|
export declare const getApiSideBabelPlugins: ({ forVite }?: {
|
|
@@ -43,14 +51,24 @@ export declare const getApiSideBabelOverrides: ({ forVite }?: {
|
|
|
43
51
|
* (@cedarjs/eslint-config).
|
|
44
52
|
*/
|
|
45
53
|
export declare const getApiSideDefaultBabelConfig: () => {
|
|
46
|
-
presets:
|
|
54
|
+
presets: BabelCore.PluginItem[] | null | undefined;
|
|
47
55
|
plugins: PluginList;
|
|
48
|
-
overrides: TransformOptions[];
|
|
56
|
+
overrides: BabelCore.TransformOptions[];
|
|
49
57
|
extends: string | undefined;
|
|
50
58
|
babelrc: boolean;
|
|
51
59
|
ignore: string[];
|
|
52
60
|
};
|
|
53
61
|
export declare const registerApiSideBabelHook: ({ plugins, ...rest }?: RegisterHookOptions) => void;
|
|
54
|
-
|
|
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>;
|
|
55
73
|
export {};
|
|
56
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,6 +1,5 @@
|
|
|
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
4
|
import { getPaths } from "@cedarjs/project-config";
|
|
6
5
|
import {
|
|
@@ -11,11 +10,18 @@ import {
|
|
|
11
10
|
import pluginRedwoodDirectoryNamedImport from "./plugins/babel-plugin-redwood-directory-named-import.js";
|
|
12
11
|
import pluginRedwoodImportDir from "./plugins/babel-plugin-redwood-import-dir.js";
|
|
13
12
|
import pluginRedwoodJobPathInjector from "./plugins/babel-plugin-redwood-job-path-injector.js";
|
|
13
|
+
import {
|
|
14
|
+
loadBabelCoreFromProject,
|
|
15
|
+
resolveFromProject
|
|
16
|
+
} from "./resolveFromProject.js";
|
|
14
17
|
const TARGETS_NODE = "24";
|
|
15
|
-
const getApiSideBabelPresets = ({
|
|
18
|
+
const getApiSideBabelPresets = ({
|
|
19
|
+
presetEnv = false,
|
|
20
|
+
resolvePreset = (packageName) => packageName
|
|
21
|
+
} = {}) => {
|
|
16
22
|
return [
|
|
17
23
|
[
|
|
18
|
-
"@babel/preset-typescript",
|
|
24
|
+
resolvePreset("@babel/preset-typescript"),
|
|
19
25
|
{
|
|
20
26
|
isTSX: true,
|
|
21
27
|
allExtensions: true
|
|
@@ -24,7 +30,7 @@ const getApiSideBabelPresets = ({ presetEnv } = { presetEnv: false }) => {
|
|
|
24
30
|
],
|
|
25
31
|
// Preset-env is required when we are not doing the transpilation with esbuild
|
|
26
32
|
presetEnv && [
|
|
27
|
-
"@babel/preset-env",
|
|
33
|
+
resolvePreset("@babel/preset-env"),
|
|
28
34
|
{
|
|
29
35
|
targets: {
|
|
30
36
|
node: TARGETS_NODE
|
|
@@ -171,10 +177,13 @@ const registerApiSideBabelHook = ({
|
|
|
171
177
|
});
|
|
172
178
|
};
|
|
173
179
|
const transformWithBabel = async (sourceCode, filename, plugins, sourceMaps = "inline", forVite = false, inputSourceMap = void 0) => {
|
|
174
|
-
const
|
|
175
|
-
|
|
180
|
+
const customConfigPath = getApiSideBabelConfigPath();
|
|
181
|
+
const babel = loadBabelCoreFromProject();
|
|
182
|
+
const resolvePreset = resolveFromProject;
|
|
183
|
+
const result = babel.transformAsync(sourceCode, {
|
|
184
|
+
presets: getApiSideBabelPresets({ resolvePreset }),
|
|
176
185
|
overrides: getApiSideBabelOverrides({ forVite }),
|
|
177
|
-
extends:
|
|
186
|
+
extends: customConfigPath,
|
|
178
187
|
babelrc: false,
|
|
179
188
|
ignore: ["node_modules"],
|
|
180
189
|
cwd: getPaths().api.base,
|
|
@@ -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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cedarjs/babel-config",
|
|
3
|
-
"version": "7.0.0-canary.
|
|
3
|
+
"version": "7.0.0-canary.3018",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/cedarjs/cedar.git",
|
|
@@ -26,15 +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.8",
|
|
31
30
|
"@babel/plugin-transform-react-jsx": "7.29.7",
|
|
32
31
|
"@babel/preset-env": "7.29.7",
|
|
33
32
|
"@babel/preset-react": "7.29.7",
|
|
34
|
-
"@babel/preset-typescript": "7.29.7",
|
|
35
33
|
"@babel/register": "7.29.7",
|
|
36
34
|
"@babel/traverse": "7.29.8",
|
|
37
|
-
"@cedarjs/project-config": "7.0.0-canary.
|
|
35
|
+
"@cedarjs/project-config": "7.0.0-canary.3018",
|
|
38
36
|
"babel-plugin-auto-import": "1.1.0",
|
|
39
37
|
"babel-plugin-graphql-tag": "3.3.0",
|
|
40
38
|
"babel-plugin-module-resolver": "5.0.3",
|
|
@@ -43,7 +41,9 @@
|
|
|
43
41
|
"typescript": "5.9.3"
|
|
44
42
|
},
|
|
45
43
|
"devDependencies": {
|
|
46
|
-
"@
|
|
44
|
+
"@babel/core": "^7.26.10",
|
|
45
|
+
"@babel/preset-typescript": "7.29.7",
|
|
46
|
+
"@cedarjs/framework-tools": "7.0.0-canary.3018",
|
|
47
47
|
"@types/babel-plugin-tester": "11.0.0",
|
|
48
48
|
"@types/babel__core": "7.20.5",
|
|
49
49
|
"@types/babel__register": "7.17.3",
|
|
@@ -51,6 +51,18 @@
|
|
|
51
51
|
"babel-plugin-tester": "11.0.4",
|
|
52
52
|
"vitest": "4.1.10"
|
|
53
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
|
+
},
|
|
54
66
|
"engines": {
|
|
55
67
|
"node": ">=24"
|
|
56
68
|
},
|