@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,329 @@
|
|
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_otel_wrapping_exports = {};
|
30
|
+
__export(babel_plugin_redwood_otel_wrapping_exports, {
|
31
|
+
default: () => babel_plugin_redwood_otel_wrapping_default
|
32
|
+
});
|
33
|
+
module.exports = __toCommonJS(babel_plugin_redwood_otel_wrapping_exports);
|
34
|
+
var nodejsPath = __toESM(require("path"));
|
35
|
+
var import_project_config = require("@redmix/project-config");
|
36
|
+
function addOpenTelemetryImport(path, t) {
|
37
|
+
path.node.body.unshift(
|
38
|
+
t.importDeclaration(
|
39
|
+
[
|
40
|
+
t.importSpecifier(
|
41
|
+
t.identifier("RW_OTEL_WRAPPER_TRACE"),
|
42
|
+
t.identifier("trace")
|
43
|
+
)
|
44
|
+
],
|
45
|
+
t.stringLiteral("@opentelemetry/api")
|
46
|
+
)
|
47
|
+
);
|
48
|
+
}
|
49
|
+
function getRedwoodPaths(state) {
|
50
|
+
if (process.env.NODE_ENV === "test") {
|
51
|
+
return {
|
52
|
+
filename: "__MOCKED_FILENAME__",
|
53
|
+
apiFolder: "__MOCKED_API_FOLDER__"
|
54
|
+
};
|
55
|
+
}
|
56
|
+
const filename = state.file.opts.filename;
|
57
|
+
const filenameOffset = filename ? (0, import_project_config.getBaseDirFromFile)(filename).length + 9 : 0;
|
58
|
+
const apiFolder = filename ? filename.substring(
|
59
|
+
filenameOffset,
|
60
|
+
filename.substring(filenameOffset).indexOf(nodejsPath.sep) + filenameOffset
|
61
|
+
) : "?";
|
62
|
+
return {
|
63
|
+
filename,
|
64
|
+
apiFolder
|
65
|
+
};
|
66
|
+
}
|
67
|
+
function wrapExportNamedDeclaration(path, state, t) {
|
68
|
+
const declaration = path.node.declaration;
|
69
|
+
const declarationIsSupported = declaration != null && declaration.type === "VariableDeclaration" && declaration.declarations[0].init?.type === "ArrowFunctionExpression";
|
70
|
+
if (!declarationIsSupported) {
|
71
|
+
return;
|
72
|
+
}
|
73
|
+
const originalFunction = declaration.declarations[0].init;
|
74
|
+
if (!originalFunction) {
|
75
|
+
return;
|
76
|
+
}
|
77
|
+
const originalFunctionName = declaration.declarations[0].id.type === "Identifier" ? declaration.declarations[0].id.name : "?";
|
78
|
+
const wrappedFunctionName = `__${originalFunctionName === "?" ? "RW_OTEL_WRAPPER_UNKNOWN_FUNCTION" : originalFunctionName}`;
|
79
|
+
const originalFunctionArgumentsWithoutDefaults = [];
|
80
|
+
for (const param of originalFunction.params) {
|
81
|
+
if (param.type === "Identifier") {
|
82
|
+
originalFunctionArgumentsWithoutDefaults.push(param);
|
83
|
+
continue;
|
84
|
+
}
|
85
|
+
if (param.type === "ObjectPattern") {
|
86
|
+
const objectProperties = param.properties.filter(
|
87
|
+
(p) => p.type === "ObjectProperty"
|
88
|
+
);
|
89
|
+
originalFunctionArgumentsWithoutDefaults.push(
|
90
|
+
t.objectExpression(
|
91
|
+
objectProperties.map((p) => {
|
92
|
+
if (p.value.type === "AssignmentPattern") {
|
93
|
+
return t.objectProperty(p.key, p.value.left);
|
94
|
+
}
|
95
|
+
return p;
|
96
|
+
})
|
97
|
+
)
|
98
|
+
);
|
99
|
+
continue;
|
100
|
+
}
|
101
|
+
if (param.type === "AssignmentPattern") {
|
102
|
+
if (param.left.type === "Identifier") {
|
103
|
+
originalFunctionArgumentsWithoutDefaults.push(param.left);
|
104
|
+
} else if (param.left.type === "ObjectPattern") {
|
105
|
+
const objectProperties = param.left.properties.filter(
|
106
|
+
(p) => p.type === "ObjectProperty"
|
107
|
+
);
|
108
|
+
originalFunctionArgumentsWithoutDefaults.push(
|
109
|
+
t.objectExpression(
|
110
|
+
objectProperties.map((p) => {
|
111
|
+
if (p.value.type === "AssignmentPattern") {
|
112
|
+
return t.objectProperty(p.key, p.value.left);
|
113
|
+
}
|
114
|
+
return p;
|
115
|
+
})
|
116
|
+
)
|
117
|
+
);
|
118
|
+
} else {
|
119
|
+
return;
|
120
|
+
}
|
121
|
+
}
|
122
|
+
if (param.type === "ArrayPattern" || param.type === "RestElement") {
|
123
|
+
return;
|
124
|
+
}
|
125
|
+
}
|
126
|
+
const { filename, apiFolder } = getRedwoodPaths(state);
|
127
|
+
const activeSpanBlock = t.callExpression(
|
128
|
+
t.memberExpression(
|
129
|
+
t.identifier("RW_OTEL_WRAPPER_TRACER"),
|
130
|
+
t.identifier("startActiveSpan")
|
131
|
+
),
|
132
|
+
[
|
133
|
+
t.stringLiteral(`redwoodjs:api:${apiFolder}:${originalFunctionName}`),
|
134
|
+
t.arrowFunctionExpression(
|
135
|
+
[t.identifier("span")],
|
136
|
+
t.blockStatement([
|
137
|
+
t.expressionStatement(
|
138
|
+
t.callExpression(
|
139
|
+
t.memberExpression(
|
140
|
+
t.identifier("span"),
|
141
|
+
t.identifier("setAttribute")
|
142
|
+
),
|
143
|
+
[
|
144
|
+
t.stringLiteral("code.function"),
|
145
|
+
t.stringLiteral(originalFunctionName)
|
146
|
+
]
|
147
|
+
)
|
148
|
+
),
|
149
|
+
t.expressionStatement(
|
150
|
+
t.callExpression(
|
151
|
+
t.memberExpression(
|
152
|
+
t.identifier("span"),
|
153
|
+
t.identifier("setAttribute")
|
154
|
+
),
|
155
|
+
[
|
156
|
+
t.stringLiteral("code.filepath"),
|
157
|
+
t.stringLiteral(filename || "?")
|
158
|
+
]
|
159
|
+
)
|
160
|
+
),
|
161
|
+
t.tryStatement(
|
162
|
+
t.blockStatement([
|
163
|
+
t.variableDeclaration("const", [
|
164
|
+
t.variableDeclarator(
|
165
|
+
t.identifier("RW_OTEL_WRAPPER_INNER_RESULT"),
|
166
|
+
originalFunction.async ? t.awaitExpression(
|
167
|
+
t.callExpression(
|
168
|
+
t.identifier(wrappedFunctionName),
|
169
|
+
originalFunctionArgumentsWithoutDefaults
|
170
|
+
)
|
171
|
+
) : t.callExpression(
|
172
|
+
t.identifier(wrappedFunctionName),
|
173
|
+
originalFunctionArgumentsWithoutDefaults
|
174
|
+
)
|
175
|
+
)
|
176
|
+
]),
|
177
|
+
t.expressionStatement(
|
178
|
+
t.callExpression(
|
179
|
+
t.memberExpression(t.identifier("span"), t.identifier("end")),
|
180
|
+
[]
|
181
|
+
)
|
182
|
+
),
|
183
|
+
t.returnStatement(t.identifier("RW_OTEL_WRAPPER_INNER_RESULT"))
|
184
|
+
]),
|
185
|
+
t.catchClause(
|
186
|
+
t.identifier("error"),
|
187
|
+
t.blockStatement([
|
188
|
+
t.expressionStatement(
|
189
|
+
t.callExpression(
|
190
|
+
t.memberExpression(
|
191
|
+
t.identifier("span"),
|
192
|
+
t.identifier("recordException")
|
193
|
+
),
|
194
|
+
[t.identifier("error")]
|
195
|
+
)
|
196
|
+
),
|
197
|
+
t.expressionStatement(
|
198
|
+
t.callExpression(
|
199
|
+
t.memberExpression(
|
200
|
+
t.identifier("span"),
|
201
|
+
t.identifier("setStatus")
|
202
|
+
),
|
203
|
+
[
|
204
|
+
t.objectExpression([
|
205
|
+
t.objectProperty(
|
206
|
+
t.identifier("code"),
|
207
|
+
t.numericLiteral(2)
|
208
|
+
),
|
209
|
+
t.objectProperty(
|
210
|
+
t.identifier("message"),
|
211
|
+
t.logicalExpression(
|
212
|
+
"??",
|
213
|
+
t.optionalMemberExpression(
|
214
|
+
t.optionalCallExpression(
|
215
|
+
t.optionalMemberExpression(
|
216
|
+
t.optionalMemberExpression(
|
217
|
+
t.identifier("error"),
|
218
|
+
t.identifier("message"),
|
219
|
+
false,
|
220
|
+
true
|
221
|
+
),
|
222
|
+
t.identifier("split"),
|
223
|
+
false,
|
224
|
+
true
|
225
|
+
),
|
226
|
+
[t.stringLiteral("\n")],
|
227
|
+
false
|
228
|
+
),
|
229
|
+
t.numericLiteral(0),
|
230
|
+
true,
|
231
|
+
false
|
232
|
+
),
|
233
|
+
t.optionalMemberExpression(
|
234
|
+
t.optionalCallExpression(
|
235
|
+
t.optionalMemberExpression(
|
236
|
+
t.optionalCallExpression(
|
237
|
+
t.optionalMemberExpression(
|
238
|
+
t.identifier("error"),
|
239
|
+
t.identifier("toString"),
|
240
|
+
false,
|
241
|
+
true
|
242
|
+
),
|
243
|
+
[],
|
244
|
+
false
|
245
|
+
),
|
246
|
+
t.identifier("split"),
|
247
|
+
false,
|
248
|
+
true
|
249
|
+
),
|
250
|
+
[t.stringLiteral("\n")],
|
251
|
+
false
|
252
|
+
),
|
253
|
+
t.numericLiteral(0),
|
254
|
+
true,
|
255
|
+
false
|
256
|
+
)
|
257
|
+
)
|
258
|
+
)
|
259
|
+
])
|
260
|
+
]
|
261
|
+
)
|
262
|
+
),
|
263
|
+
t.expressionStatement(
|
264
|
+
t.callExpression(
|
265
|
+
t.memberExpression(
|
266
|
+
t.identifier("span"),
|
267
|
+
t.identifier("end")
|
268
|
+
),
|
269
|
+
[]
|
270
|
+
)
|
271
|
+
),
|
272
|
+
t.throwStatement(t.identifier("error"))
|
273
|
+
])
|
274
|
+
)
|
275
|
+
)
|
276
|
+
]),
|
277
|
+
originalFunction.async
|
278
|
+
)
|
279
|
+
]
|
280
|
+
);
|
281
|
+
const wrapper = t.arrowFunctionExpression(
|
282
|
+
originalFunction.params,
|
283
|
+
t.blockStatement(
|
284
|
+
[
|
285
|
+
t.variableDeclaration("const", [
|
286
|
+
t.variableDeclarator(
|
287
|
+
t.identifier(wrappedFunctionName),
|
288
|
+
originalFunction
|
289
|
+
)
|
290
|
+
]),
|
291
|
+
t.variableDeclaration("const", [
|
292
|
+
t.variableDeclarator(
|
293
|
+
t.identifier("RW_OTEL_WRAPPER_TRACER"),
|
294
|
+
t.callExpression(
|
295
|
+
t.memberExpression(
|
296
|
+
t.identifier("RW_OTEL_WRAPPER_TRACE"),
|
297
|
+
t.identifier("getTracer")
|
298
|
+
),
|
299
|
+
[t.stringLiteral("redwoodjs")]
|
300
|
+
)
|
301
|
+
)
|
302
|
+
]),
|
303
|
+
t.variableDeclaration("const", [
|
304
|
+
t.variableDeclarator(
|
305
|
+
t.identifier("RW_OTEL_WRAPPER_RESULT"),
|
306
|
+
originalFunction.async ? t.awaitExpression(activeSpanBlock) : activeSpanBlock
|
307
|
+
)
|
308
|
+
]),
|
309
|
+
t.returnStatement(t.identifier("RW_OTEL_WRAPPER_RESULT"))
|
310
|
+
],
|
311
|
+
originalFunction.body.type === "BlockStatement" ? originalFunction.body.directives : void 0
|
312
|
+
),
|
313
|
+
originalFunction.async
|
314
|
+
);
|
315
|
+
declaration.declarations[0].init = wrapper;
|
316
|
+
}
|
317
|
+
function babel_plugin_redwood_otel_wrapping_default({ types: t }) {
|
318
|
+
return {
|
319
|
+
name: "babel-plugin-redwood-otel-wrapping",
|
320
|
+
visitor: {
|
321
|
+
Program(path) {
|
322
|
+
addOpenTelemetryImport(path, t);
|
323
|
+
},
|
324
|
+
ExportNamedDeclaration(path, state) {
|
325
|
+
wrapExportNamedDeclaration(path, state, t);
|
326
|
+
}
|
327
|
+
}
|
328
|
+
};
|
329
|
+
}
|
@@ -0,0 +1 @@
|
|
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"}
|
@@ -0,0 +1,41 @@
|
|
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_remove_dev_fatal_error_page_exports = {};
|
20
|
+
__export(babel_plugin_redwood_remove_dev_fatal_error_page_exports, {
|
21
|
+
default: () => babel_plugin_redwood_remove_dev_fatal_error_page_default
|
22
|
+
});
|
23
|
+
module.exports = __toCommonJS(babel_plugin_redwood_remove_dev_fatal_error_page_exports);
|
24
|
+
function babel_plugin_redwood_remove_dev_fatal_error_page_default({ types: t }) {
|
25
|
+
return {
|
26
|
+
name: "babel-plugin-redwood-remove-dev-fatal-error-page",
|
27
|
+
visitor: {
|
28
|
+
ImportDeclaration(path) {
|
29
|
+
if (path.node.source.value === "@redmix/web/dist/components/DevFatalErrorPage") {
|
30
|
+
const variableDeclaration = t.variableDeclaration("const", [
|
31
|
+
t.variableDeclarator(
|
32
|
+
t.identifier("DevFatalErrorPage"),
|
33
|
+
t.identifier("undefined")
|
34
|
+
)
|
35
|
+
]);
|
36
|
+
path.replaceWith(variableDeclaration);
|
37
|
+
}
|
38
|
+
}
|
39
|
+
}
|
40
|
+
};
|
41
|
+
}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
import type { PluginObj, types } from '@babel/core';
|
2
|
+
import type { PagesDependency } from '@redmix/project-config';
|
3
|
+
export interface PluginOptions {
|
4
|
+
forPrerender?: boolean;
|
5
|
+
}
|
6
|
+
/**
|
7
|
+
* When running from the CLI: Babel-plugin-module-resolver will convert
|
8
|
+
* For dev/build/prerender (forJest == false): 'src/pages/ExamplePage' -> './pages/ExamplePage'
|
9
|
+
* For test (forJest == true): 'src/pages/ExamplePage' -> '/Users/blah/pathToProject/web/src/pages/ExamplePage'
|
10
|
+
*/
|
11
|
+
export declare const getPathRelativeToSrc: (maybeAbsolutePath: string) => string;
|
12
|
+
export declare const withRelativeImports: (page: PagesDependency) => {
|
13
|
+
relativeImport: string;
|
14
|
+
importName: string;
|
15
|
+
constName: string;
|
16
|
+
importPath: string;
|
17
|
+
path: string;
|
18
|
+
importStatement: string;
|
19
|
+
};
|
20
|
+
export default function ({ types: t }: {
|
21
|
+
types: typeof types;
|
22
|
+
}, { forPrerender }: PluginOptions): PluginObj;
|
23
|
+
//# sourceMappingURL=babel-plugin-redwood-routes-auto-loader.d.ts.map
|
@@ -0,0 +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":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAEnD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AAQ7D,MAAM,WAAW,aAAa;IAC5B,YAAY,CAAC,EAAE,OAAO,CAAA;CACvB;AAED;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,sBAAuB,MAAM,WAO7D,CAAA;AAED,eAAO,MAAM,mBAAmB,SAAU,eAAe;;;;;;;CAKxD,CAAA;AAED,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,CA0KX"}
|
@@ -0,0 +1,182 @@
|
|
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_routes_auto_loader_exports = {};
|
30
|
+
__export(babel_plugin_redwood_routes_auto_loader_exports, {
|
31
|
+
default: () => babel_plugin_redwood_routes_auto_loader_default,
|
32
|
+
getPathRelativeToSrc: () => getPathRelativeToSrc,
|
33
|
+
withRelativeImports: () => withRelativeImports
|
34
|
+
});
|
35
|
+
module.exports = __toCommonJS(babel_plugin_redwood_routes_auto_loader_exports);
|
36
|
+
var import_path = __toESM(require("path"));
|
37
|
+
var import_project_config = require("@redmix/project-config");
|
38
|
+
const getPathRelativeToSrc = (maybeAbsolutePath) => {
|
39
|
+
if (!import_path.default.isAbsolute(maybeAbsolutePath)) {
|
40
|
+
return maybeAbsolutePath;
|
41
|
+
}
|
42
|
+
return `./${import_path.default.relative((0, import_project_config.getPaths)().web.src, maybeAbsolutePath)}`;
|
43
|
+
};
|
44
|
+
const withRelativeImports = (page) => {
|
45
|
+
return {
|
46
|
+
...page,
|
47
|
+
relativeImport: (0, import_project_config.ensurePosixPath)(getPathRelativeToSrc(page.importPath))
|
48
|
+
};
|
49
|
+
};
|
50
|
+
function babel_plugin_redwood_routes_auto_loader_default({ types: t }, { forPrerender = false }) {
|
51
|
+
let pages = (0, import_project_config.processPagesDir)().map(withRelativeImports);
|
52
|
+
const duplicatePageImportNames = /* @__PURE__ */ new Set();
|
53
|
+
const sortedPageImportNames = pages.map((page) => page.importName).sort();
|
54
|
+
for (let i = 0; i < sortedPageImportNames.length - 1; i++) {
|
55
|
+
if (sortedPageImportNames[i + 1] === sortedPageImportNames[i]) {
|
56
|
+
duplicatePageImportNames.add(sortedPageImportNames[i]);
|
57
|
+
}
|
58
|
+
}
|
59
|
+
if (duplicatePageImportNames.size > 0) {
|
60
|
+
throw new Error(
|
61
|
+
`Unable to find only a single file ending in 'Page.{js,jsx,ts,tsx}' in the following page directories: ${Array.from(
|
62
|
+
duplicatePageImportNames
|
63
|
+
).map((name) => `'${name}'`).join(", ")}`
|
64
|
+
);
|
65
|
+
}
|
66
|
+
return {
|
67
|
+
name: "babel-plugin-redwood-routes-auto-loader",
|
68
|
+
visitor: {
|
69
|
+
// Remove any pages that have been explicitly imported in the Routes file,
|
70
|
+
// because when one is present, the user is requesting that the module be
|
71
|
+
// included in the main bundle.
|
72
|
+
ImportDeclaration(p) {
|
73
|
+
if (pages.length === 0) {
|
74
|
+
return;
|
75
|
+
}
|
76
|
+
const userImportRelativePath = getPathRelativeToSrc(
|
77
|
+
(0, import_project_config.importStatementPath)(p.node.source?.value)
|
78
|
+
);
|
79
|
+
const defaultSpecifier = p.node.specifiers.find(
|
80
|
+
(specifiers) => t.isImportDefaultSpecifier(specifiers)
|
81
|
+
);
|
82
|
+
if (!defaultSpecifier) {
|
83
|
+
return;
|
84
|
+
}
|
85
|
+
if (forPrerender) {
|
86
|
+
const pageThatUserImported = pages.find((page) => {
|
87
|
+
return page.relativeImport === (0, import_project_config.ensurePosixPath)(userImportRelativePath);
|
88
|
+
});
|
89
|
+
if (pageThatUserImported) {
|
90
|
+
pageThatUserImported.importName = defaultSpecifier.local.name;
|
91
|
+
p.node.specifiers = p.node.specifiers.filter(
|
92
|
+
(specifier) => !t.isImportDefaultSpecifier(specifier)
|
93
|
+
);
|
94
|
+
}
|
95
|
+
return;
|
96
|
+
}
|
97
|
+
if (userImportRelativePath && defaultSpecifier) {
|
98
|
+
pages = pages.filter(
|
99
|
+
(page) => !(page.relativeImport === (0, import_project_config.ensurePosixPath)(userImportRelativePath))
|
100
|
+
);
|
101
|
+
}
|
102
|
+
},
|
103
|
+
Program: {
|
104
|
+
enter() {
|
105
|
+
pages = (0, import_project_config.processPagesDir)().map(withRelativeImports);
|
106
|
+
},
|
107
|
+
exit(p) {
|
108
|
+
if (pages.length === 0) {
|
109
|
+
return;
|
110
|
+
}
|
111
|
+
const nodes = [];
|
112
|
+
nodes.unshift(
|
113
|
+
t.importDeclaration(
|
114
|
+
[t.importSpecifier(t.identifier("lazy"), t.identifier("lazy"))],
|
115
|
+
t.stringLiteral("react")
|
116
|
+
)
|
117
|
+
);
|
118
|
+
for (const { importName, relativeImport } of pages) {
|
119
|
+
const importArgument = t.stringLiteral(relativeImport);
|
120
|
+
nodes.push(
|
121
|
+
t.variableDeclaration("const", [
|
122
|
+
t.variableDeclarator(
|
123
|
+
t.identifier(importName),
|
124
|
+
t.objectExpression([
|
125
|
+
t.objectProperty(
|
126
|
+
t.identifier("name"),
|
127
|
+
t.stringLiteral(importName)
|
128
|
+
),
|
129
|
+
// prerenderLoader for ssr/prerender and first load of
|
130
|
+
// prerendered pages in browser (csr)
|
131
|
+
// prerenderLoader: (name) => { prerenderLoaderImpl }
|
132
|
+
t.objectProperty(
|
133
|
+
t.identifier("prerenderLoader"),
|
134
|
+
t.arrowFunctionExpression(
|
135
|
+
[t.identifier("name")],
|
136
|
+
prerenderLoaderImpl(forPrerender, relativeImport, t)
|
137
|
+
)
|
138
|
+
),
|
139
|
+
t.objectProperty(
|
140
|
+
t.identifier("LazyComponent"),
|
141
|
+
t.callExpression(t.identifier("lazy"), [
|
142
|
+
t.arrowFunctionExpression(
|
143
|
+
[],
|
144
|
+
t.callExpression(t.identifier("import"), [
|
145
|
+
importArgument
|
146
|
+
])
|
147
|
+
)
|
148
|
+
])
|
149
|
+
)
|
150
|
+
])
|
151
|
+
)
|
152
|
+
])
|
153
|
+
);
|
154
|
+
}
|
155
|
+
p.node.body.unshift(...nodes);
|
156
|
+
}
|
157
|
+
}
|
158
|
+
}
|
159
|
+
};
|
160
|
+
}
|
161
|
+
function prerenderLoaderImpl(forPrerender, relativeImport, t) {
|
162
|
+
if (forPrerender) {
|
163
|
+
return t.callExpression(t.identifier("require"), [
|
164
|
+
t.stringLiteral(relativeImport)
|
165
|
+
]);
|
166
|
+
}
|
167
|
+
return t.objectExpression([
|
168
|
+
t.objectProperty(
|
169
|
+
t.identifier("default"),
|
170
|
+
t.memberExpression(
|
171
|
+
t.identifier("globalThis.__REDWOOD__PRERENDER_PAGES"),
|
172
|
+
t.identifier("name"),
|
173
|
+
true
|
174
|
+
)
|
175
|
+
)
|
176
|
+
]);
|
177
|
+
}
|
178
|
+
// Annotate the CommonJS export names for ESM import in node:
|
179
|
+
0 && (module.exports = {
|
180
|
+
getPathRelativeToSrc,
|
181
|
+
withRelativeImports
|
182
|
+
});
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import type { PluginObj, types } from '@babel/core';
|
2
|
+
export default function ({ types: t }: {
|
3
|
+
types: typeof types;
|
4
|
+
}, options: {
|
5
|
+
/** absolute path to the `src` directory */
|
6
|
+
srcAbsPath: string;
|
7
|
+
}): PluginObj;
|
8
|
+
//# sourceMappingURL=babel-plugin-redwood-src-alias.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"babel-plugin-redwood-src-alias.d.ts","sourceRoot":"","sources":["../../src/plugins/babel-plugin-redwood-src-alias.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAEnD,MAAM,CAAC,OAAO,WACZ,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE;IAAE,KAAK,EAAE,OAAO,KAAK,CAAA;CAAE,EACrC,OAAO,EAAE;IACP,2CAA2C;IAC3C,UAAU,EAAE,MAAM,CAAA;CACnB,GACA,SAAS,CA6DX"}
|
@@ -0,0 +1,72 @@
|
|
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_src_alias_exports = {};
|
30
|
+
__export(babel_plugin_redwood_src_alias_exports, {
|
31
|
+
default: () => babel_plugin_redwood_src_alias_default
|
32
|
+
});
|
33
|
+
module.exports = __toCommonJS(babel_plugin_redwood_src_alias_exports);
|
34
|
+
var import_path = __toESM(require("path"));
|
35
|
+
function babel_plugin_redwood_src_alias_default({ types: t }, options) {
|
36
|
+
return {
|
37
|
+
name: "babel-plugin-redwood-src-alias",
|
38
|
+
visitor: {
|
39
|
+
ImportDeclaration(p, state) {
|
40
|
+
const { value } = p.node.source;
|
41
|
+
const { filename } = state.file.opts;
|
42
|
+
if (!filename || filename?.includes("/node_modules/") || !value.startsWith("src/")) {
|
43
|
+
return;
|
44
|
+
}
|
45
|
+
const absPath = import_path.default.join(options.srcAbsPath, value.substr(4));
|
46
|
+
let newImport = import_path.default.relative(import_path.default.dirname(filename), absPath);
|
47
|
+
if (process.platform === "win32") {
|
48
|
+
newImport = newImport.replaceAll("\\", "/");
|
49
|
+
}
|
50
|
+
if (!newImport.startsWith(".")) {
|
51
|
+
newImport = "./" + newImport;
|
52
|
+
}
|
53
|
+
const newSource = t.stringLiteral(newImport);
|
54
|
+
p.node.source = newSource;
|
55
|
+
},
|
56
|
+
ExportDeclaration(p, state) {
|
57
|
+
if (!p?.node?.source) {
|
58
|
+
return;
|
59
|
+
}
|
60
|
+
const { value } = p.node.source;
|
61
|
+
const { filename } = state.file.opts;
|
62
|
+
if (!filename || filename?.includes("/node_modules/") || !value.startsWith("src/")) {
|
63
|
+
return;
|
64
|
+
}
|
65
|
+
const absPath = import_path.default.join(options.srcAbsPath, value.substr(4));
|
66
|
+
const newImport = import_path.default.relative(import_path.default.dirname(filename), absPath);
|
67
|
+
const newSource = t.stringLiteral(newImport);
|
68
|
+
p.node.source = newSource;
|
69
|
+
}
|
70
|
+
}
|
71
|
+
};
|
72
|
+
}
|