@redmix/babel-config 0.0.1
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/LICENSE +21 -0
- package/README.md +3 -0
- package/dist/__tests__/api.test.d.ts +2 -0
- package/dist/__tests__/api.test.d.ts.map +1 -0
- package/dist/__tests__/common.test.d.ts +2 -0
- package/dist/__tests__/common.test.d.ts.map +1 -0
- package/dist/__tests__/prebuildApiFile.test.d.ts +6 -0
- package/dist/__tests__/prebuildApiFile.test.d.ts.map +1 -0
- package/dist/__tests__/tsconfigParsing.test.d.ts +2 -0
- package/dist/__tests__/tsconfigParsing.test.d.ts.map +1 -0
- package/dist/api.d.ts +37 -0
- package/dist/api.d.ts.map +1 -0
- package/dist/api.js +258 -0
- package/dist/common.d.ts +50 -0
- package/dist/common.d.ts.map +1 -0
- package/dist/common.js +145 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +70 -0
- package/dist/plugins/__tests__/babel-plugin-redwood-cell.test.d.ts +2 -0
- package/dist/plugins/__tests__/babel-plugin-redwood-cell.test.d.ts.map +1 -0
- package/dist/plugins/__tests__/babel-plugin-redwood-context-wrapping.test.d.ts +2 -0
- package/dist/plugins/__tests__/babel-plugin-redwood-context-wrapping.test.d.ts.map +1 -0
- package/dist/plugins/__tests__/babel-plugin-redwood-directory-named-imports.test.d.ts +2 -0
- package/dist/plugins/__tests__/babel-plugin-redwood-directory-named-imports.test.d.ts.map +1 -0
- package/dist/plugins/__tests__/babel-plugin-redwood-graphql-options-extract.test.d.ts +2 -0
- package/dist/plugins/__tests__/babel-plugin-redwood-graphql-options-extract.test.d.ts.map +1 -0
- package/dist/plugins/__tests__/babel-plugin-redwood-import-dir.test.d.ts +2 -0
- package/dist/plugins/__tests__/babel-plugin-redwood-import-dir.test.d.ts.map +1 -0
- package/dist/plugins/__tests__/babel-plugin-redwood-mock-cell-data.test.d.ts +2 -0
- package/dist/plugins/__tests__/babel-plugin-redwood-mock-cell-data.test.d.ts.map +1 -0
- package/dist/plugins/__tests__/babel-plugin-redwood-otel-wrapping.test.d.ts +2 -0
- package/dist/plugins/__tests__/babel-plugin-redwood-otel-wrapping.test.d.ts.map +1 -0
- package/dist/plugins/__tests__/babel-plugin-redwood-remove-dev-fatal-error-page.test.d.ts +2 -0
- package/dist/plugins/__tests__/babel-plugin-redwood-remove-dev-fatal-error-page.test.d.ts.map +1 -0
- package/dist/plugins/__tests__/babel-plugin-redwood-routes-auto-loader.test.d.ts +2 -0
- package/dist/plugins/__tests__/babel-plugin-redwood-routes-auto-loader.test.d.ts.map +1 -0
- package/dist/plugins/__tests__/babel-plugin-redwood-src-alias.test.d.ts +2 -0
- package/dist/plugins/__tests__/babel-plugin-redwood-src-alias.test.d.ts.map +1 -0
- package/dist/plugins/babel-plugin-redwood-cell.d.ts +5 -0
- package/dist/plugins/babel-plugin-redwood-cell.d.ts.map +1 -0
- package/dist/plugins/babel-plugin-redwood-cell.js +115 -0
- package/dist/plugins/babel-plugin-redwood-context-wrapping.d.ts +7 -0
- package/dist/plugins/babel-plugin-redwood-context-wrapping.d.ts.map +1 -0
- package/dist/plugins/babel-plugin-redwood-context-wrapping.js +134 -0
- package/dist/plugins/babel-plugin-redwood-directory-named-import.d.ts +5 -0
- package/dist/plugins/babel-plugin-redwood-directory-named-import.d.ts.map +1 -0
- package/dist/plugins/babel-plugin-redwood-directory-named-import.js +94 -0
- package/dist/plugins/babel-plugin-redwood-graphql-options-extract.d.ts +5 -0
- package/dist/plugins/babel-plugin-redwood-graphql-options-extract.d.ts.map +1 -0
- package/dist/plugins/babel-plugin-redwood-graphql-options-extract.js +88 -0
- package/dist/plugins/babel-plugin-redwood-import-dir.d.ts +23 -0
- package/dist/plugins/babel-plugin-redwood-import-dir.d.ts.map +1 -0
- package/dist/plugins/babel-plugin-redwood-import-dir.js +98 -0
- package/dist/plugins/babel-plugin-redwood-job-path-injector.d.ts +5 -0
- package/dist/plugins/babel-plugin-redwood-job-path-injector.d.ts.map +1 -0
- package/dist/plugins/babel-plugin-redwood-job-path-injector.js +118 -0
- package/dist/plugins/babel-plugin-redwood-mock-cell-data.d.ts +18 -0
- package/dist/plugins/babel-plugin-redwood-mock-cell-data.d.ts.map +1 -0
- package/dist/plugins/babel-plugin-redwood-mock-cell-data.js +244 -0
- package/dist/plugins/babel-plugin-redwood-otel-wrapping.d.ts +5 -0
- package/dist/plugins/babel-plugin-redwood-otel-wrapping.d.ts.map +1 -0
- package/dist/plugins/babel-plugin-redwood-otel-wrapping.js +329 -0
- package/dist/plugins/babel-plugin-redwood-remove-dev-fatal-error-page.d.ts +5 -0
- package/dist/plugins/babel-plugin-redwood-remove-dev-fatal-error-page.d.ts.map +1 -0
- package/dist/plugins/babel-plugin-redwood-remove-dev-fatal-error-page.js +41 -0
- package/dist/plugins/babel-plugin-redwood-routes-auto-loader.d.ts +23 -0
- package/dist/plugins/babel-plugin-redwood-routes-auto-loader.d.ts.map +1 -0
- package/dist/plugins/babel-plugin-redwood-routes-auto-loader.js +182 -0
- package/dist/plugins/babel-plugin-redwood-src-alias.d.ts +8 -0
- package/dist/plugins/babel-plugin-redwood-src-alias.d.ts.map +1 -0
- package/dist/plugins/babel-plugin-redwood-src-alias.js +72 -0
- package/dist/web.d.ts +21 -0
- package/dist/web.d.ts.map +1 -0
- package/dist/web.js +239 -0
- package/package.json +60 -0
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"babel-plugin-redwood-graphql-options-extract.test.d.ts","sourceRoot":"","sources":["../../../src/plugins/__tests__/babel-plugin-redwood-graphql-options-extract.test.ts"],"names":[],"mappings":""}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"babel-plugin-redwood-import-dir.test.d.ts","sourceRoot":"","sources":["../../../src/plugins/__tests__/babel-plugin-redwood-import-dir.test.ts"],"names":[],"mappings":""}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"babel-plugin-redwood-mock-cell-data.test.d.ts","sourceRoot":"","sources":["../../../src/plugins/__tests__/babel-plugin-redwood-mock-cell-data.test.ts"],"names":[],"mappings":""}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"babel-plugin-redwood-otel-wrapping.test.d.ts","sourceRoot":"","sources":["../../../src/plugins/__tests__/babel-plugin-redwood-otel-wrapping.test.ts"],"names":[],"mappings":""}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"babel-plugin-redwood-remove-dev-fatal-error-page.test.d.ts","sourceRoot":"","sources":["../../../src/plugins/__tests__/babel-plugin-redwood-remove-dev-fatal-error-page.test.ts"],"names":[],"mappings":""}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"babel-plugin-redwood-routes-auto-loader.test.d.ts","sourceRoot":"","sources":["../../../src/plugins/__tests__/babel-plugin-redwood-routes-auto-loader.test.ts"],"names":[],"mappings":""}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"babel-plugin-redwood-src-alias.test.d.ts","sourceRoot":"","sources":["../../../src/plugins/__tests__/babel-plugin-redwood-src-alias.test.ts"],"names":[],"mappings":""}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"babel-plugin-redwood-cell.d.ts","sourceRoot":"","sources":["../../src/plugins/babel-plugin-redwood-cell.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AA+BnD,MAAM,CAAC,OAAO,WAAW,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE;IAAE,KAAK,EAAE,OAAO,KAAK,CAAA;CAAE,GAAG,SAAS,CAgHzE"}
|
@@ -0,0 +1,115 @@
|
|
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_redwood_cell_exports = {};
|
20
|
+
__export(babel_plugin_redwood_cell_exports, {
|
21
|
+
default: () => babel_plugin_redwood_cell_default
|
22
|
+
});
|
23
|
+
module.exports = __toCommonJS(babel_plugin_redwood_cell_exports);
|
24
|
+
var import_path = require("path");
|
25
|
+
const EXPECTED_EXPORTS_FROM_CELL = [
|
26
|
+
"beforeQuery",
|
27
|
+
"QUERY",
|
28
|
+
"data",
|
29
|
+
"isEmpty",
|
30
|
+
"afterQuery",
|
31
|
+
"Loading",
|
32
|
+
"Success",
|
33
|
+
"Failure",
|
34
|
+
"Empty"
|
35
|
+
];
|
36
|
+
function babel_plugin_redwood_cell_default({ types: t }) {
|
37
|
+
let exportNames = [];
|
38
|
+
let hasDefaultExport = false;
|
39
|
+
return {
|
40
|
+
name: "babel-plugin-redwood-cell",
|
41
|
+
visitor: {
|
42
|
+
ExportDefaultDeclaration() {
|
43
|
+
hasDefaultExport = true;
|
44
|
+
},
|
45
|
+
ExportNamedDeclaration(path) {
|
46
|
+
const declaration = path.node.declaration;
|
47
|
+
if (!declaration) {
|
48
|
+
return;
|
49
|
+
}
|
50
|
+
let name;
|
51
|
+
if (declaration.type === "VariableDeclaration") {
|
52
|
+
const id = declaration.declarations[0].id;
|
53
|
+
name = id.name;
|
54
|
+
}
|
55
|
+
if (declaration.type === "FunctionDeclaration") {
|
56
|
+
name = declaration?.id?.name;
|
57
|
+
}
|
58
|
+
if (name && EXPECTED_EXPORTS_FROM_CELL.includes(name)) {
|
59
|
+
exportNames.push(name);
|
60
|
+
}
|
61
|
+
},
|
62
|
+
Program: {
|
63
|
+
enter() {
|
64
|
+
exportNames = [];
|
65
|
+
hasDefaultExport = false;
|
66
|
+
},
|
67
|
+
exit(path) {
|
68
|
+
const hasQueryOrDataExport = exportNames.includes("QUERY") || exportNames.includes("data");
|
69
|
+
if (hasDefaultExport || !hasQueryOrDataExport) {
|
70
|
+
return;
|
71
|
+
}
|
72
|
+
const createCellHookName = exportNames.includes("data") ? "createServerCell" : "createCell";
|
73
|
+
const importFrom = exportNames.includes("data") ? "@redmix/web/dist/components/cell/createServerCell" : "@redmix/web";
|
74
|
+
path.node.body.unshift(
|
75
|
+
t.importDeclaration(
|
76
|
+
[
|
77
|
+
t.importSpecifier(
|
78
|
+
t.identifier(createCellHookName),
|
79
|
+
t.identifier(createCellHookName)
|
80
|
+
)
|
81
|
+
],
|
82
|
+
t.stringLiteral(importFrom)
|
83
|
+
)
|
84
|
+
);
|
85
|
+
path.node.body.push(
|
86
|
+
t.exportDefaultDeclaration(
|
87
|
+
t.callExpression(t.identifier(createCellHookName), [
|
88
|
+
t.objectExpression([
|
89
|
+
...exportNames.map(
|
90
|
+
(name) => t.objectProperty(
|
91
|
+
t.identifier(name),
|
92
|
+
t.identifier(name),
|
93
|
+
false,
|
94
|
+
true
|
95
|
+
)
|
96
|
+
),
|
97
|
+
// Add the `displayName` property so we can name the Cell
|
98
|
+
// after the filename.
|
99
|
+
t.objectProperty(
|
100
|
+
t.identifier("displayName"),
|
101
|
+
t.stringLiteral(
|
102
|
+
(0, import_path.parse)(this.file.opts.filename).name
|
103
|
+
),
|
104
|
+
false,
|
105
|
+
true
|
106
|
+
)
|
107
|
+
])
|
108
|
+
])
|
109
|
+
)
|
110
|
+
);
|
111
|
+
}
|
112
|
+
}
|
113
|
+
}
|
114
|
+
};
|
115
|
+
}
|
@@ -0,0 +1 @@
|
|
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"}
|
@@ -0,0 +1,134 @@
|
|
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_redwood_context_wrapping_exports = {};
|
20
|
+
__export(babel_plugin_redwood_context_wrapping_exports, {
|
21
|
+
default: () => babel_plugin_redwood_context_wrapping_default
|
22
|
+
});
|
23
|
+
module.exports = __toCommonJS(babel_plugin_redwood_context_wrapping_exports);
|
24
|
+
function generateWrappedHandler(t, isAsync) {
|
25
|
+
const contextStoreVariableDeclaration = t.variableDeclaration("const", [
|
26
|
+
t.variableDeclarator(
|
27
|
+
t.identifier("__rw_contextStore"),
|
28
|
+
t.callExpression(
|
29
|
+
t.memberExpression(
|
30
|
+
t.callExpression(t.identifier("__rw_getAsyncStoreInstance"), []),
|
31
|
+
t.identifier("getStore")
|
32
|
+
),
|
33
|
+
[]
|
34
|
+
)
|
35
|
+
)
|
36
|
+
]);
|
37
|
+
t.addComment(
|
38
|
+
contextStoreVariableDeclaration,
|
39
|
+
"leading",
|
40
|
+
" The store will be undefined if no context isolation has been performed yet",
|
41
|
+
true
|
42
|
+
);
|
43
|
+
return t.arrowFunctionExpression(
|
44
|
+
[t.identifier("__rw_event"), t.identifier("__rw__context")],
|
45
|
+
t.blockStatement([
|
46
|
+
contextStoreVariableDeclaration,
|
47
|
+
t.ifStatement(
|
48
|
+
t.binaryExpression(
|
49
|
+
"===",
|
50
|
+
t.identifier("__rw_contextStore"),
|
51
|
+
t.identifier("undefined")
|
52
|
+
),
|
53
|
+
t.blockStatement([
|
54
|
+
t.returnStatement(
|
55
|
+
t.callExpression(
|
56
|
+
t.memberExpression(
|
57
|
+
t.callExpression(
|
58
|
+
t.identifier("__rw_getAsyncStoreInstance"),
|
59
|
+
[]
|
60
|
+
),
|
61
|
+
t.identifier("run")
|
62
|
+
),
|
63
|
+
[
|
64
|
+
t.newExpression(t.identifier("Map"), []),
|
65
|
+
t.identifier("__rw_handler"),
|
66
|
+
t.identifier("__rw_event"),
|
67
|
+
t.identifier("__rw__context")
|
68
|
+
]
|
69
|
+
)
|
70
|
+
)
|
71
|
+
])
|
72
|
+
),
|
73
|
+
t.returnStatement(
|
74
|
+
t.callExpression(t.identifier("__rw_handler"), [
|
75
|
+
t.identifier("__rw_event"),
|
76
|
+
t.identifier("__rw__context")
|
77
|
+
])
|
78
|
+
)
|
79
|
+
]),
|
80
|
+
isAsync
|
81
|
+
);
|
82
|
+
}
|
83
|
+
function babel_plugin_redwood_context_wrapping_default({ types: t }, { projectIsEsm = false } = {}) {
|
84
|
+
return {
|
85
|
+
name: "babel-plugin-redwood-context-wrapping",
|
86
|
+
visitor: {
|
87
|
+
ExportNamedDeclaration(path, _state) {
|
88
|
+
const declaration = path.node.declaration;
|
89
|
+
if (!t.isVariableDeclaration(declaration)) {
|
90
|
+
return;
|
91
|
+
}
|
92
|
+
const identifier = declaration.declarations[0].id;
|
93
|
+
if (!t.isIdentifier(identifier)) {
|
94
|
+
return;
|
95
|
+
}
|
96
|
+
if (identifier.name !== "handler") {
|
97
|
+
return;
|
98
|
+
}
|
99
|
+
const parentNode = path.parentPath.node;
|
100
|
+
if (!t.isProgram(parentNode)) {
|
101
|
+
return;
|
102
|
+
}
|
103
|
+
path.insertBefore(
|
104
|
+
// import { getAsyncStoreInstance as __rw_getAsyncStoreInstance } from '@redmix/context/dist/store'
|
105
|
+
t.importDeclaration(
|
106
|
+
[
|
107
|
+
t.importSpecifier(
|
108
|
+
t.identifier("__rw_getAsyncStoreInstance"),
|
109
|
+
t.identifier("getAsyncStoreInstance")
|
110
|
+
)
|
111
|
+
],
|
112
|
+
t.stringLiteral(
|
113
|
+
projectIsEsm ? "@redmix/context/dist/store.js" : "@redmix/context/dist/store"
|
114
|
+
)
|
115
|
+
)
|
116
|
+
);
|
117
|
+
path.insertBefore(
|
118
|
+
t.variableDeclaration("const", [
|
119
|
+
t.variableDeclarator(
|
120
|
+
t.identifier("__rw_handler"),
|
121
|
+
declaration.declarations[0].init
|
122
|
+
)
|
123
|
+
])
|
124
|
+
);
|
125
|
+
let isAsync = false;
|
126
|
+
const originalInit = declaration.declarations[0].init;
|
127
|
+
if (t.isFunction(originalInit)) {
|
128
|
+
isAsync = originalInit.async;
|
129
|
+
}
|
130
|
+
declaration.declarations[0].init = generateWrappedHandler(t, isAsync);
|
131
|
+
}
|
132
|
+
}
|
133
|
+
};
|
134
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"babel-plugin-redwood-directory-named-import.d.ts","sourceRoot":"","sources":["../../src/plugins/babel-plugin-redwood-directory-named-import.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAuBnD,MAAM,CAAC,OAAO,WAAW,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE;IAAE,KAAK,EAAE,OAAO,KAAK,CAAA;CAAE,GAAG,SAAS,CA2DzE"}
|
@@ -0,0 +1,94 @@
|
|
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_redwood_directory_named_import_exports = {};
|
30
|
+
__export(babel_plugin_redwood_directory_named_import_exports, {
|
31
|
+
default: () => babel_plugin_redwood_directory_named_import_default
|
32
|
+
});
|
33
|
+
module.exports = __toCommonJS(babel_plugin_redwood_directory_named_import_exports);
|
34
|
+
var import_path = __toESM(require("path"));
|
35
|
+
var import_project_config = require("@redmix/project-config");
|
36
|
+
const getNewPath = (value, filename) => {
|
37
|
+
const dirname = import_path.default.dirname(value);
|
38
|
+
const basename = import_path.default.basename(value);
|
39
|
+
const indexImportPath = [dirname, basename, "index"].join("/");
|
40
|
+
if ((0, import_project_config.resolveFile)(import_path.default.resolve(import_path.default.dirname(filename), indexImportPath))) {
|
41
|
+
return indexImportPath;
|
42
|
+
} else {
|
43
|
+
const dirnameImportPath = [dirname, basename, basename].join("/");
|
44
|
+
if ((0, import_project_config.resolveFile)(import_path.default.resolve(import_path.default.dirname(filename), dirnameImportPath))) {
|
45
|
+
return dirnameImportPath;
|
46
|
+
}
|
47
|
+
}
|
48
|
+
return null;
|
49
|
+
};
|
50
|
+
function babel_plugin_redwood_directory_named_import_default({ types: t }) {
|
51
|
+
return {
|
52
|
+
visitor: {
|
53
|
+
ImportDeclaration(p, state) {
|
54
|
+
const { value } = p.node.source;
|
55
|
+
const { filename } = state.file.opts;
|
56
|
+
if (filename?.includes("/node_modules/")) {
|
57
|
+
return;
|
58
|
+
}
|
59
|
+
try {
|
60
|
+
require.resolve(value);
|
61
|
+
return;
|
62
|
+
} catch {
|
63
|
+
}
|
64
|
+
const newPath = getNewPath(value, filename);
|
65
|
+
if (!newPath) {
|
66
|
+
return;
|
67
|
+
}
|
68
|
+
const newSource = t.stringLiteral(newPath);
|
69
|
+
p.node.source = newSource;
|
70
|
+
},
|
71
|
+
ExportDeclaration(p, state) {
|
72
|
+
if (!p?.node?.source) {
|
73
|
+
return;
|
74
|
+
}
|
75
|
+
const { value } = p.node.source;
|
76
|
+
const { filename } = state.file.opts;
|
77
|
+
if (filename?.includes("/node_modules/")) {
|
78
|
+
return;
|
79
|
+
}
|
80
|
+
try {
|
81
|
+
require.resolve(value);
|
82
|
+
return;
|
83
|
+
} catch {
|
84
|
+
}
|
85
|
+
const newPath = getNewPath(value, filename);
|
86
|
+
if (!newPath) {
|
87
|
+
return;
|
88
|
+
}
|
89
|
+
const newSource = t.stringLiteral(newPath);
|
90
|
+
p.node.source = newSource;
|
91
|
+
}
|
92
|
+
}
|
93
|
+
};
|
94
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"babel-plugin-redwood-graphql-options-extract.d.ts","sourceRoot":"","sources":["../../src/plugins/babel-plugin-redwood-graphql-options-extract.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAY,SAAS,EAAc,KAAK,EAAE,MAAM,aAAa,CAAA;AAiCzE,MAAM,CAAC,OAAO,WAAW,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE;IAAE,KAAK,EAAE,OAAO,KAAK,CAAA;CAAE,GAAG,SAAS,CAoEzE"}
|
@@ -0,0 +1,88 @@
|
|
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_redwood_graphql_options_extract_exports = {};
|
20
|
+
__export(babel_plugin_redwood_graphql_options_extract_exports, {
|
21
|
+
default: () => babel_plugin_redwood_graphql_options_extract_default
|
22
|
+
});
|
23
|
+
module.exports = __toCommonJS(babel_plugin_redwood_graphql_options_extract_exports);
|
24
|
+
const exportVariableName = "__rw_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_redwood_graphql_options_extract_default({ types: t }) {
|
39
|
+
return {
|
40
|
+
name: "babel-plugin-redwood-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: "@redmix/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
|
+
}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
import type { PluginObj, types } from '@babel/core';
|
2
|
+
/**
|
3
|
+
* This babel plugin will search for import statements that include star `**`
|
4
|
+
* in the source part of the statement is a glob, the files that are matched are imported,
|
5
|
+
* and appended to an object.
|
6
|
+
*
|
7
|
+
* @example:
|
8
|
+
* Given a directory "src/services" that contains "a.js" and "b.ts", "nested/c.js",
|
9
|
+
* will produce the following results:
|
10
|
+
* ```js
|
11
|
+
* import services from 'src/services/**\/*.{js,ts}'
|
12
|
+
* console.log(services)
|
13
|
+
* // services.a = require('src/services/a.js')
|
14
|
+
* // services.b = require('src/services/b.ts')
|
15
|
+
* // services.nested_c = require('src/services/nested/c.js')
|
16
|
+
* ```
|
17
|
+
*/
|
18
|
+
export default function ({ types: t }: {
|
19
|
+
types: typeof types;
|
20
|
+
}, { projectIsEsm }?: {
|
21
|
+
projectIsEsm?: boolean;
|
22
|
+
}): PluginObj;
|
23
|
+
//# sourceMappingURL=babel-plugin-redwood-import-dir.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"babel-plugin-redwood-import-dir.d.ts","sourceRoot":"","sources":["../../src/plugins/babel-plugin-redwood-import-dir.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAKnD;;;;;;;;;;;;;;;GAeG;AACH,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,CAsFX"}
|
@@ -0,0 +1,98 @@
|
|
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_redwood_import_dir_exports = {};
|
30
|
+
__export(babel_plugin_redwood_import_dir_exports, {
|
31
|
+
default: () => babel_plugin_redwood_import_dir_default
|
32
|
+
});
|
33
|
+
module.exports = __toCommonJS(babel_plugin_redwood_import_dir_exports);
|
34
|
+
var import_path = __toESM(require("path"));
|
35
|
+
var import_fast_glob = __toESM(require("fast-glob"));
|
36
|
+
var import_project_config = require("@redmix/project-config");
|
37
|
+
function babel_plugin_redwood_import_dir_default({ types: t }, { projectIsEsm = false } = {}) {
|
38
|
+
return {
|
39
|
+
name: "babel-plugin-redwood-import-dir",
|
40
|
+
visitor: {
|
41
|
+
ImportDeclaration(p, state) {
|
42
|
+
if (!p.node.source.value.includes("**")) {
|
43
|
+
return;
|
44
|
+
}
|
45
|
+
const nodes = [];
|
46
|
+
const importName = p.node.specifiers[0].local.name;
|
47
|
+
nodes.push(
|
48
|
+
t.variableDeclaration("let", [
|
49
|
+
t.variableDeclarator(
|
50
|
+
t.identifier(importName),
|
51
|
+
t.objectExpression([])
|
52
|
+
)
|
53
|
+
])
|
54
|
+
);
|
55
|
+
const importGlob = (0, import_project_config.importStatementPath)(p.node.source.value);
|
56
|
+
const cwd = import_path.default.dirname(state.file.opts.filename);
|
57
|
+
const dirFiles = import_fast_glob.default.sync(importGlob, { cwd }).filter((n) => !n.includes(".test.")).filter((n) => !n.includes(".scenarios.")).filter((n) => !n.includes(".d.ts"));
|
58
|
+
const staticGlob = importGlob.split("*")[0];
|
59
|
+
const filePathToVarName = (filePath) => {
|
60
|
+
return filePath.replace(staticGlob, "").replace(/\.(js|ts)$/, "").replace(/[^a-zA-Z0-9]/g, "_");
|
61
|
+
};
|
62
|
+
for (const filePath of dirFiles) {
|
63
|
+
const { dir: fileDir, name: fileName } = import_path.default.parse(filePath);
|
64
|
+
const filePathWithoutExtension = fileDir + "/" + fileName;
|
65
|
+
const fpVarName = filePathToVarName(filePath);
|
66
|
+
nodes.push(
|
67
|
+
t.importDeclaration(
|
68
|
+
[
|
69
|
+
t.importNamespaceSpecifier(
|
70
|
+
t.identifier(importName + "_" + fpVarName)
|
71
|
+
)
|
72
|
+
],
|
73
|
+
t.stringLiteral(
|
74
|
+
projectIsEsm ? `${filePathWithoutExtension}.js` : filePathWithoutExtension
|
75
|
+
)
|
76
|
+
)
|
77
|
+
);
|
78
|
+
nodes.push(
|
79
|
+
t.expressionStatement(
|
80
|
+
t.assignmentExpression(
|
81
|
+
"=",
|
82
|
+
t.memberExpression(
|
83
|
+
t.identifier(importName),
|
84
|
+
t.identifier(fpVarName)
|
85
|
+
),
|
86
|
+
t.identifier(importName + "_" + fpVarName)
|
87
|
+
)
|
88
|
+
)
|
89
|
+
);
|
90
|
+
}
|
91
|
+
for (const node of nodes) {
|
92
|
+
p.insertBefore(node);
|
93
|
+
}
|
94
|
+
p.remove();
|
95
|
+
}
|
96
|
+
}
|
97
|
+
};
|
98
|
+
}
|