@cedarjs/babel-config 5.0.0 → 6.0.0-canary.2615
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.map +1 -1
- package/dist/api.js +4 -13
- package/dist/plugins/{babel-plugin-redwood-context-wrapping.d.ts → babel-plugin-handler-als-wrapping.d.ts} +1 -1
- package/dist/plugins/babel-plugin-handler-als-wrapping.d.ts.map +1 -0
- package/dist/plugins/{babel-plugin-redwood-context-wrapping.js → babel-plugin-handler-als-wrapping.js} +6 -6
- package/package.json +3 -3
- package/dist/plugins/babel-plugin-cedar-gqlorm-inject.d.ts +0 -32
- package/dist/plugins/babel-plugin-cedar-gqlorm-inject.d.ts.map +0 -1
- package/dist/plugins/babel-plugin-cedar-gqlorm-inject.js +0 -154
- package/dist/plugins/babel-plugin-cedar-graphql-options-extract.d.ts +0 -5
- package/dist/plugins/babel-plugin-cedar-graphql-options-extract.d.ts.map +0 -1
- package/dist/plugins/babel-plugin-cedar-graphql-options-extract.js +0 -88
- package/dist/plugins/babel-plugin-redwood-context-wrapping.d.ts.map +0 -1
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;
|
|
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;AAatD,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,KAuBgB,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
|
@@ -44,9 +44,7 @@ var import_core = require("@babel/core");
|
|
|
44
44
|
var import_babel_plugin_module_resolver = require("babel-plugin-module-resolver");
|
|
45
45
|
var import_project_config = require("@cedarjs/project-config");
|
|
46
46
|
var import_common = require("./common.js");
|
|
47
|
-
var
|
|
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"));
|
|
47
|
+
var import_babel_plugin_handler_als_wrapping = __toESM(require("./plugins/babel-plugin-handler-als-wrapping.js"));
|
|
50
48
|
var import_babel_plugin_redwood_directory_named_import = __toESM(require("./plugins/babel-plugin-redwood-directory-named-import.js"));
|
|
51
49
|
var import_babel_plugin_redwood_import_dir = __toESM(require("./plugins/babel-plugin-redwood-import-dir.js"));
|
|
52
50
|
var import_babel_plugin_redwood_job_path_injector = __toESM(require("./plugins/babel-plugin-redwood-job-path-injector.js"));
|
|
@@ -165,21 +163,14 @@ const getApiSideBabelOverrides = ({
|
|
|
165
163
|
forJest = false
|
|
166
164
|
} = {}) => {
|
|
167
165
|
const overrides = [
|
|
168
|
-
//
|
|
169
|
-
//
|
|
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)
|
|
166
|
+
// Apply handler ALS wrapping to all functions (Jest only; Vite uses
|
|
167
|
+
// handlerAlsWrappingPlugin instead)
|
|
177
168
|
forJest && {
|
|
178
169
|
// match */api/src/functions/*.js|ts
|
|
179
170
|
test: /.+api(?:[\\|/])src(?:[\\|/])functions(?:[\\|/]).+.(?:js|ts)$/,
|
|
180
171
|
plugins: [
|
|
181
172
|
[
|
|
182
|
-
|
|
173
|
+
import_babel_plugin_handler_als_wrapping.default,
|
|
183
174
|
{
|
|
184
175
|
projectIsEsm
|
|
185
176
|
}
|
|
@@ -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"}
|
|
@@ -16,11 +16,11 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var
|
|
20
|
-
__export(
|
|
21
|
-
default: () =>
|
|
19
|
+
var babel_plugin_handler_als_wrapping_exports = {};
|
|
20
|
+
__export(babel_plugin_handler_als_wrapping_exports, {
|
|
21
|
+
default: () => babel_plugin_handler_als_wrapping_default
|
|
22
22
|
});
|
|
23
|
-
module.exports = __toCommonJS(
|
|
23
|
+
module.exports = __toCommonJS(babel_plugin_handler_als_wrapping_exports);
|
|
24
24
|
function generateWrappedHandler(t, isAsync) {
|
|
25
25
|
const contextStoreVariableDeclaration = t.variableDeclaration("const", [
|
|
26
26
|
t.variableDeclarator(
|
|
@@ -80,9 +80,9 @@ function generateWrappedHandler(t, isAsync) {
|
|
|
80
80
|
isAsync
|
|
81
81
|
);
|
|
82
82
|
}
|
|
83
|
-
function
|
|
83
|
+
function babel_plugin_handler_als_wrapping_default({ types: t }, { projectIsEsm = false } = {}) {
|
|
84
84
|
return {
|
|
85
|
-
name: "babel-plugin-
|
|
85
|
+
name: "babel-plugin-handler-als-wrapping",
|
|
86
86
|
visitor: {
|
|
87
87
|
ExportNamedDeclaration(path, _state) {
|
|
88
88
|
const declaration = path.node.declaration;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cedarjs/babel-config",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.0-canary.2615",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/cedarjs/cedar.git",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"@babel/preset-typescript": "7.29.7",
|
|
36
36
|
"@babel/register": "7.29.7",
|
|
37
37
|
"@babel/traverse": "7.29.7",
|
|
38
|
-
"@cedarjs/project-config": "
|
|
38
|
+
"@cedarjs/project-config": "6.0.0-canary.2615",
|
|
39
39
|
"babel-plugin-auto-import": "1.1.0",
|
|
40
40
|
"babel-plugin-graphql-tag": "3.3.0",
|
|
41
41
|
"babel-plugin-module-resolver": "5.0.3",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"typescript": "5.9.3"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"@cedarjs/framework-tools": "
|
|
47
|
+
"@cedarjs/framework-tools": "6.0.0-canary.2615",
|
|
48
48
|
"@jridgewell/trace-mapping": "0.3.31",
|
|
49
49
|
"@types/babel-plugin-tester": "11.0.0",
|
|
50
50
|
"@types/babel__core": "7.20.5",
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import type { PluginObj, types } from '@babel/core';
|
|
2
|
-
/**
|
|
3
|
-
* Babel plugin that injects the auto-generated gqlorm backend into
|
|
4
|
-
* `api/src/functions/graphql.ts` at build time.
|
|
5
|
-
*
|
|
6
|
-
* When `experimental.gqlorm.enabled = true` and `.cedar/gqlorm/backend.ts`
|
|
7
|
-
* exists, this plugin:
|
|
8
|
-
*
|
|
9
|
-
* 1. Adds imports at the top of graphql.ts:
|
|
10
|
-
* import * as __gqlorm_sdl__ from '../../../.cedar/gqlorm/backend'
|
|
11
|
-
* import { db as __gqlorm_db__ } from 'src/lib/db'
|
|
12
|
-
*
|
|
13
|
-
* 2. Inserts a statement immediately before the `createGraphQLHandler` call:
|
|
14
|
-
* sdls = {
|
|
15
|
-
* ...sdls,
|
|
16
|
-
* __gqlorm__: {
|
|
17
|
-
* schema: __gqlorm_sdl__.schema,
|
|
18
|
-
* resolvers: __gqlorm_sdl__.createGqlormResolvers(__gqlorm_db__),
|
|
19
|
-
* },
|
|
20
|
-
* }
|
|
21
|
-
*
|
|
22
|
-
* The `sdls` variable is already a `let` binding at this point because
|
|
23
|
-
* `babel-plugin-redwood-import-dir` transforms the glob import
|
|
24
|
-
* `import sdls from 'src/graphql/**\/*.sdl.{js,ts}'` into `let sdls = {}`.
|
|
25
|
-
*
|
|
26
|
-
* This plugin is a no-op when gqlorm is disabled or the backend file does
|
|
27
|
-
* not exist.
|
|
28
|
-
*/
|
|
29
|
-
export default function ({ types: t }: {
|
|
30
|
-
types: typeof types;
|
|
31
|
-
}): PluginObj;
|
|
32
|
-
//# sourceMappingURL=babel-plugin-cedar-gqlorm-inject.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"babel-plugin-cedar-gqlorm-inject.d.ts","sourceRoot":"","sources":["../../src/plugins/babel-plugin-cedar-gqlorm-inject.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAY,SAAS,EAAc,KAAK,EAAE,MAAM,aAAa,CAAA;AAIzE;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,CAAC,OAAO,WAAW,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE;IAAE,KAAK,EAAE,OAAO,KAAK,CAAA;CAAE,GAAG,SAAS,CA8KzE"}
|
|
@@ -1,154 +0,0 @@
|
|
|
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 babel_plugin_cedar_gqlorm_inject_exports = {};
|
|
30
|
-
__export(babel_plugin_cedar_gqlorm_inject_exports, {
|
|
31
|
-
default: () => babel_plugin_cedar_gqlorm_inject_default
|
|
32
|
-
});
|
|
33
|
-
module.exports = __toCommonJS(babel_plugin_cedar_gqlorm_inject_exports);
|
|
34
|
-
var import_node_fs = __toESM(require("node:fs"));
|
|
35
|
-
var import_node_path = __toESM(require("node:path"));
|
|
36
|
-
var import_project_config = require("@cedarjs/project-config");
|
|
37
|
-
function babel_plugin_cedar_gqlorm_inject_default({ types: t }) {
|
|
38
|
-
return {
|
|
39
|
-
name: "babel-plugin-cedar-gqlorm-inject",
|
|
40
|
-
visitor: {
|
|
41
|
-
Program(programPath, state) {
|
|
42
|
-
let config;
|
|
43
|
-
try {
|
|
44
|
-
config = (0, import_project_config.getConfig)();
|
|
45
|
-
} catch {
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
if (!config.experimental?.gqlorm?.enabled) {
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
let paths;
|
|
52
|
-
try {
|
|
53
|
-
paths = (0, import_project_config.getPaths)();
|
|
54
|
-
} catch {
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
const backendPathWithoutExt = import_node_path.default.join(
|
|
58
|
-
paths.generated.base,
|
|
59
|
-
"gqlorm",
|
|
60
|
-
"backend"
|
|
61
|
-
);
|
|
62
|
-
const backendExists = import_node_fs.default.existsSync(backendPathWithoutExt + ".ts") || import_node_fs.default.existsSync(backendPathWithoutExt + ".js");
|
|
63
|
-
if (!backendExists) {
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
const importNames = /* @__PURE__ */ new Set();
|
|
67
|
-
programPath.traverse({
|
|
68
|
-
ImportDeclaration(p) {
|
|
69
|
-
if (t.isStringLiteral(p.node.source, {
|
|
70
|
-
value: "@cedarjs/graphql-server"
|
|
71
|
-
})) {
|
|
72
|
-
for (const specifier of p.node.specifiers) {
|
|
73
|
-
if (t.isImportSpecifier(specifier) && t.isIdentifier(specifier.imported) && specifier.imported.name === "createGraphQLHandler") {
|
|
74
|
-
importNames.add(specifier.local.name);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
if (importNames.size === 0) {
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
const callExpressionPaths = [];
|
|
84
|
-
programPath.traverse({
|
|
85
|
-
CallExpression(p) {
|
|
86
|
-
if (t.isIdentifier(p.node.callee) && importNames.has(p.node.callee.name)) {
|
|
87
|
-
callExpressionPaths.push(p);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
if (callExpressionPaths.length === 0) {
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
const callExpressionPath = callExpressionPaths[0];
|
|
95
|
-
const statementParent = callExpressionPath.getStatementParent();
|
|
96
|
-
if (!statementParent) {
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
const filename = state.file.opts.filename;
|
|
100
|
-
if (!filename) {
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
const relPath = import_node_path.default.relative(import_node_path.default.dirname(filename), backendPathWithoutExt).replace(/\\/g, "/") + ".ts";
|
|
104
|
-
const importSdl = t.importDeclaration(
|
|
105
|
-
[t.importNamespaceSpecifier(t.identifier("__gqlorm_sdl__"))],
|
|
106
|
-
t.stringLiteral(relPath)
|
|
107
|
-
);
|
|
108
|
-
const importDb = t.importDeclaration(
|
|
109
|
-
[
|
|
110
|
-
t.importSpecifier(
|
|
111
|
-
t.identifier("__gqlorm_db__"),
|
|
112
|
-
t.identifier("db")
|
|
113
|
-
)
|
|
114
|
-
],
|
|
115
|
-
t.stringLiteral("src/lib/db")
|
|
116
|
-
);
|
|
117
|
-
programPath.unshiftContainer("body", [importDb, importSdl]);
|
|
118
|
-
const sdlsMutation = t.expressionStatement(
|
|
119
|
-
t.callExpression(
|
|
120
|
-
t.memberExpression(t.identifier("Object"), t.identifier("assign")),
|
|
121
|
-
[
|
|
122
|
-
t.identifier("sdls"),
|
|
123
|
-
t.objectExpression([
|
|
124
|
-
t.objectProperty(
|
|
125
|
-
t.identifier("__gqlorm__"),
|
|
126
|
-
t.objectExpression([
|
|
127
|
-
t.objectProperty(
|
|
128
|
-
t.identifier("schema"),
|
|
129
|
-
t.memberExpression(
|
|
130
|
-
t.identifier("__gqlorm_sdl__"),
|
|
131
|
-
t.identifier("schema")
|
|
132
|
-
)
|
|
133
|
-
),
|
|
134
|
-
t.objectProperty(
|
|
135
|
-
t.identifier("resolvers"),
|
|
136
|
-
t.callExpression(
|
|
137
|
-
t.memberExpression(
|
|
138
|
-
t.identifier("__gqlorm_sdl__"),
|
|
139
|
-
t.identifier("createGqlormResolvers")
|
|
140
|
-
),
|
|
141
|
-
[t.identifier("__gqlorm_db__")]
|
|
142
|
-
)
|
|
143
|
-
)
|
|
144
|
-
])
|
|
145
|
-
)
|
|
146
|
-
])
|
|
147
|
-
]
|
|
148
|
-
)
|
|
149
|
-
);
|
|
150
|
-
statementParent.insertBefore(sdlsMutation);
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
};
|
|
154
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"babel-plugin-cedar-graphql-options-extract.d.ts","sourceRoot":"","sources":["../../src/plugins/babel-plugin-cedar-graphql-options-extract.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAY,SAAS,EAAc,KAAK,EAAE,MAAM,aAAa,CAAA;AAkCzE,MAAM,CAAC,OAAO,WAAW,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE;IAAE,KAAK,EAAE,OAAO,KAAK,CAAA;CAAE,GAAG,SAAS,CAyEzE"}
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var babel_plugin_cedar_graphql_options_extract_exports = {};
|
|
20
|
-
__export(babel_plugin_cedar_graphql_options_extract_exports, {
|
|
21
|
-
default: () => babel_plugin_cedar_graphql_options_extract_default
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(babel_plugin_cedar_graphql_options_extract_exports);
|
|
24
|
-
const exportVariableName = "__cedar_graphqlOptions";
|
|
25
|
-
function optionsConstNode(t, value, state) {
|
|
26
|
-
if (t.isIdentifier(value) || t.isObjectExpression(value) || t.isCallExpression(value) || t.isConditionalExpression(value)) {
|
|
27
|
-
return t.exportNamedDeclaration(
|
|
28
|
-
t.variableDeclaration("const", [
|
|
29
|
-
t.variableDeclarator(t.identifier(exportVariableName), value)
|
|
30
|
-
])
|
|
31
|
-
);
|
|
32
|
-
} else {
|
|
33
|
-
throw new Error(
|
|
34
|
-
`Unable to parse graphql function options in '${state.file.opts.filename}'`
|
|
35
|
-
);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
function babel_plugin_cedar_graphql_options_extract_default({ types: t }) {
|
|
39
|
-
return {
|
|
40
|
-
name: "babel-plugin-cedar-graphql-options-extract",
|
|
41
|
-
visitor: {
|
|
42
|
-
Program(path, state) {
|
|
43
|
-
const importNames = /* @__PURE__ */ new Set();
|
|
44
|
-
path.traverse({
|
|
45
|
-
ImportDeclaration(p) {
|
|
46
|
-
if (t.isStringLiteral(p.node.source, {
|
|
47
|
-
value: "@cedarjs/graphql-server"
|
|
48
|
-
})) {
|
|
49
|
-
for (const specifier of p.node.specifiers) {
|
|
50
|
-
if (t.isImportSpecifier(specifier) && t.isIdentifier(specifier.imported) && specifier.imported.name === "createGraphQLHandler") {
|
|
51
|
-
importNames.add(specifier.local.name);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
const callExpressionPaths = [];
|
|
58
|
-
path.traverse({
|
|
59
|
-
CallExpression(p) {
|
|
60
|
-
if (t.isIdentifier(p.node.callee) && importNames.has(p.node.callee.name)) {
|
|
61
|
-
callExpressionPaths.push(p);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
if (callExpressionPaths.length > 1) {
|
|
66
|
-
console.log(
|
|
67
|
-
`There are ${callExpressionPaths.length} calls to 'createGraphQLHandler' in '${state.file.opts.filename}'. The automatic extraction of graphql options will fallback to the first usage.`
|
|
68
|
-
);
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
const callExpressionPath = callExpressionPaths[0];
|
|
72
|
-
if (!callExpressionPath) {
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
const options = callExpressionPath.node.arguments[0];
|
|
76
|
-
const optionsConst = optionsConstNode(t, options, state);
|
|
77
|
-
const statementParent = callExpressionPath.getStatementParent();
|
|
78
|
-
if (!statementParent) {
|
|
79
|
-
throw new Error(
|
|
80
|
-
`Unable to find statement parent for graphql function in '${state.file.opts.filename}'`
|
|
81
|
-
);
|
|
82
|
-
}
|
|
83
|
-
statementParent.insertBefore(optionsConst);
|
|
84
|
-
callExpressionPath.node.arguments[0] = t.identifier(exportVariableName);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"babel-plugin-redwood-context-wrapping.d.ts","sourceRoot":"","sources":["../../src/plugins/babel-plugin-redwood-context-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"}
|