@cedarjs/internal 5.0.7-next.336 → 5.0.7-rc.3
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/ast.d.ts +0 -1
- package/dist/ast.d.ts.map +1 -1
- package/dist/ast.js +0 -21
- package/dist/build/api.d.ts +0 -2
- package/dist/build/api.d.ts.map +1 -1
- package/dist/build/api.js +39 -198
- package/dist/build/esbuild-plugin-cedar-context-wrapping.d.ts +4 -0
- package/dist/build/esbuild-plugin-cedar-context-wrapping.d.ts.map +1 -0
- package/dist/build/{esbuild-plugin-handler-als-wrapping.js → esbuild-plugin-cedar-context-wrapping.js} +12 -12
- package/dist/cjs/ast.d.ts +26 -0
- package/dist/cjs/ast.d.ts.map +1 -0
- package/dist/cjs/ast.js +201 -0
- package/dist/cjs/build/api.d.ts +7 -0
- package/dist/cjs/build/api.d.ts.map +1 -0
- package/dist/cjs/build/api.js +251 -0
- package/dist/cjs/build/esbuild-plugin-cedar-context-wrapping.d.ts +4 -0
- package/dist/cjs/build/esbuild-plugin-cedar-context-wrapping.d.ts.map +1 -0
- package/dist/cjs/build/esbuild-plugin-cedar-context-wrapping.js +59 -0
- package/dist/cjs/cliLogger.d.ts +11 -0
- package/dist/cjs/cliLogger.d.ts.map +1 -0
- package/dist/cjs/cliLogger.js +36 -0
- package/dist/cjs/dev.d.ts +2 -0
- package/dist/cjs/dev.d.ts.map +1 -0
- package/dist/cjs/dev.js +41 -0
- package/dist/cjs/files.d.ts +56 -0
- package/dist/cjs/files.d.ts.map +1 -0
- package/dist/cjs/files.js +230 -0
- package/dist/cjs/generate/clientPreset.d.ts +17 -0
- package/dist/cjs/generate/clientPreset.d.ts.map +1 -0
- package/dist/cjs/generate/clientPreset.js +84 -0
- package/dist/cjs/generate/generate.d.ts +10 -0
- package/dist/cjs/generate/generate.d.ts.map +1 -0
- package/dist/cjs/generate/generate.js +97 -0
- package/dist/cjs/generate/gqlormSchema.d.ts +113 -0
- package/dist/cjs/generate/gqlormSchema.d.ts.map +1 -0
- package/dist/cjs/generate/gqlormSchema.js +1061 -0
- package/dist/cjs/generate/graphqlCodeGen.d.ts +16 -0
- package/dist/cjs/generate/graphqlCodeGen.d.ts.map +1 -0
- package/dist/cjs/generate/graphqlCodeGen.js +380 -0
- package/dist/cjs/generate/graphqlSchema.d.ts +8 -0
- package/dist/cjs/generate/graphqlSchema.d.ts.map +1 -0
- package/dist/cjs/generate/graphqlSchema.js +157 -0
- package/dist/cjs/generate/plugins/rw-typescript-resolvers/index.d.ts +7 -0
- package/dist/cjs/generate/plugins/rw-typescript-resolvers/index.d.ts.map +1 -0
- package/dist/cjs/generate/plugins/rw-typescript-resolvers/index.js +65 -0
- package/dist/cjs/generate/plugins/rw-typescript-resolvers/visitor.d.ts +10 -0
- package/dist/cjs/generate/plugins/rw-typescript-resolvers/visitor.d.ts.map +1 -0
- package/dist/cjs/generate/plugins/rw-typescript-resolvers/visitor.js +92 -0
- package/dist/cjs/generate/possibleTypes.d.ts +36 -0
- package/dist/cjs/generate/possibleTypes.d.ts.map +1 -0
- package/dist/cjs/generate/possibleTypes.js +106 -0
- package/dist/cjs/generate/templates/all-currentUser.d.ts.template +30 -0
- package/dist/cjs/generate/templates/all-gqlorm.d.ts.template +7 -0
- package/dist/cjs/generate/templates/api-globImports.d.ts.template +9 -0
- package/dist/cjs/generate/templates/api-globalContext.d.ts.template +7 -0
- package/dist/cjs/generate/templates/api-scenarios.d.ts.template +10 -0
- package/dist/cjs/generate/templates/api-test-globals.d.ts.template +5 -0
- package/dist/cjs/generate/templates/mirror-cell.d.ts.template +13 -0
- package/dist/cjs/generate/templates/mirror-directoryNamedModule.d.ts.template +5 -0
- package/dist/cjs/generate/templates/web-routerRoutes.d.ts.template +20 -0
- package/dist/cjs/generate/templates/web-routesPages.d.ts.template +13 -0
- package/dist/cjs/generate/templates/web-test-globals.d.ts.template +7 -0
- package/dist/cjs/generate/templates.d.ts +6 -0
- package/dist/cjs/generate/templates.d.ts.map +1 -0
- package/dist/cjs/generate/templates.js +68 -0
- package/dist/cjs/generate/trustedDocuments.d.ts +3 -0
- package/dist/cjs/generate/trustedDocuments.d.ts.map +1 -0
- package/dist/cjs/generate/trustedDocuments.js +95 -0
- package/dist/cjs/generate/typeDefinitions.d.ts +31 -0
- package/dist/cjs/generate/typeDefinitions.d.ts.map +1 -0
- package/dist/cjs/generate/typeDefinitions.js +372 -0
- package/dist/cjs/generate/types.d.ts +6 -0
- package/dist/cjs/generate/types.d.ts.map +1 -0
- package/dist/cjs/generate/types.js +16 -0
- package/dist/cjs/generate/watch.d.ts +3 -0
- package/dist/cjs/generate/watch.d.ts.map +1 -0
- package/dist/cjs/generate/watch.js +132 -0
- package/dist/cjs/gql.d.ts +14 -0
- package/dist/cjs/gql.d.ts.map +1 -0
- package/dist/cjs/gql.js +108 -0
- package/dist/cjs/index.d.ts +11 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +49 -0
- package/dist/cjs/jsx.d.ts +16 -0
- package/dist/cjs/jsx.d.ts.map +1 -0
- package/dist/cjs/jsx.js +101 -0
- package/dist/cjs/jsxAttributeValue.d.ts +2 -0
- package/dist/cjs/jsxAttributeValue.d.ts.map +1 -0
- package/dist/cjs/jsxAttributeValue.js +129 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/project.d.ts +8 -0
- package/dist/cjs/project.d.ts.map +1 -0
- package/dist/cjs/project.js +82 -0
- package/dist/cjs/routes.d.ts +42 -0
- package/dist/cjs/routes.d.ts.map +1 -0
- package/dist/cjs/routes.js +111 -0
- package/dist/cjs/ts2js.d.ts +40 -0
- package/dist/cjs/ts2js.d.ts.map +1 -0
- package/dist/cjs/ts2js.js +159 -0
- package/dist/cjs/validateSchema.d.ts +14 -0
- package/dist/cjs/validateSchema.d.ts.map +1 -0
- package/dist/cjs/validateSchema.js +195 -0
- package/dist/generate/clientPreset.d.ts +7 -0
- package/dist/generate/clientPreset.d.ts.map +1 -1
- package/dist/generate/clientPreset.js +5 -12
- package/dist/generate/generate.d.ts.map +1 -1
- package/dist/generate/generate.js +0 -6
- package/dist/generate/graphqlCodeGen.d.ts.map +1 -1
- package/dist/generate/graphqlCodeGen.js +10 -36
- package/dist/generate/graphqlSchema.d.ts.map +1 -1
- package/dist/generate/templates.d.ts.map +1 -1
- package/dist/generate/templates.js +6 -1
- package/dist/generate/typeDefinitions.d.ts.map +1 -1
- package/dist/generate/typeDefinitions.js +1 -15
- package/dist/gql.d.ts +0 -20
- package/dist/gql.d.ts.map +1 -1
- package/dist/gql.js +0 -24
- package/dist/jsx.d.ts.map +1 -1
- package/dist/routes.d.ts.map +1 -1
- package/package.json +91 -55
- package/dist/build/api-graphql-transforms.d.ts +0 -34
- package/dist/build/api-graphql-transforms.d.ts.map +0 -1
- package/dist/build/api-graphql-transforms.js +0 -129
- package/dist/build/auto-import.d.ts +0 -10
- package/dist/build/auto-import.d.ts.map +0 -1
- package/dist/build/auto-import.js +0 -120
- package/dist/build/directory-named-import.d.ts +0 -2
- package/dist/build/directory-named-import.d.ts.map +0 -1
- package/dist/build/directory-named-import.js +0 -26
- package/dist/build/esbuild-plugin-api-graphql.d.ts +0 -6
- package/dist/build/esbuild-plugin-api-graphql.d.ts.map +0 -1
- package/dist/build/esbuild-plugin-api-graphql.js +0 -78
- package/dist/build/esbuild-plugin-cedar-otel-wrapping.d.ts +0 -13
- package/dist/build/esbuild-plugin-cedar-otel-wrapping.d.ts.map +0 -1
- package/dist/build/esbuild-plugin-cedar-otel-wrapping.js +0 -180
- package/dist/build/esbuild-plugin-handler-als-wrapping.d.ts +0 -4
- package/dist/build/esbuild-plugin-handler-als-wrapping.d.ts.map +0 -1
- package/dist/build/import-dir.d.ts +0 -22
- package/dist/build/import-dir.d.ts.map +0 -1
- package/dist/build/import-dir.js +0 -54
- package/dist/build/import-extensions.d.ts +0 -47
- package/dist/build/import-extensions.d.ts.map +0 -1
- package/dist/build/import-extensions.js +0 -59
- package/dist/build/job-path-injector.d.ts +0 -15
- package/dist/build/job-path-injector.d.ts.map +0 -1
- package/dist/build/job-path-injector.js +0 -69
- package/dist/build/src-alias.d.ts +0 -14
- package/dist/build/src-alias.d.ts.map +0 -1
- package/dist/build/src-alias.js +0 -17
- package/dist/build/tsconfig-paths.d.ts +0 -2
- package/dist/build/tsconfig-paths.d.ts.map +0 -1
- package/dist/build/tsconfig-paths.js +0 -72
- package/dist/generate/templates/mirror-cell-fragment.d.ts.template +0 -18
package/dist/ast.d.ts
CHANGED
|
@@ -17,7 +17,6 @@ export declare const getNamedExports: (ast: types.Node) => NamedExports[];
|
|
|
17
17
|
*/
|
|
18
18
|
export declare const getGqlQueries: (ast: types.Node) => string[];
|
|
19
19
|
export declare const getCellGqlQuery: (ast: types.Node) => undefined;
|
|
20
|
-
export declare const getCellGqlFragment: (ast: types.Node) => undefined;
|
|
21
20
|
export declare const hasDefaultExport: (ast: types.Node) => boolean;
|
|
22
21
|
export declare const getDefaultExportLocation: (ast: types.Node) => {
|
|
23
22
|
line: number;
|
package/dist/ast.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ast.d.ts","sourceRoot":"","sources":["../src/ast.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"ast.d.ts","sourceRoot":"","sources":["../src/ast.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAmBnC,eAAO,MAAM,SAAS,GAAI,UAAU,MAAM,KAAG,KAAK,CAAC,IAyBlD,CAAA;AAED,UAAU,YAAY;IACpB,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,WAAW,GAAG,UAAU,GAAG,UAAU,GAAG,OAAO,CAAA;IACrD,QAAQ,EAAE;QACR,IAAI,EAAE,MAAM,CAAA;QACZ,MAAM,EAAE,MAAM,CAAA;KACf,CAAA;CACF;AACD;;GAEG;AACH,eAAO,MAAM,eAAe,GAAI,KAAK,KAAK,CAAC,IAAI,KAAG,YAAY,EA4D7D,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,aAAa,GAAI,KAAK,KAAK,CAAC,IAAI,aAY5C,CAAA;AAED,eAAO,MAAM,eAAe,GAAI,KAAK,KAAK,CAAC,IAAI,cA8B9C,CAAA;AAED,eAAO,MAAM,gBAAgB,GAAI,KAAK,KAAK,CAAC,IAAI,KAAG,OASlD,CAAA;AAED,eAAO,MAAM,wBAAwB,GACnC,KAAK,KAAK,CAAC,IAAI,KACd;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG,IA0CrC,CAAA"}
|
package/dist/ast.js
CHANGED
|
@@ -115,26 +115,6 @@ const getCellGqlQuery = (ast) => {
|
|
|
115
115
|
});
|
|
116
116
|
return cellQuery;
|
|
117
117
|
};
|
|
118
|
-
const getCellGqlFragment = (ast) => {
|
|
119
|
-
let cellFragment = void 0;
|
|
120
|
-
traverse(ast, {
|
|
121
|
-
ExportNamedDeclaration({ node }) {
|
|
122
|
-
if (node.exportKind === "value" && types.isVariableDeclaration(node.declaration)) {
|
|
123
|
-
const exportedFragmentNode = node.declaration.declarations.find(
|
|
124
|
-
(d) => {
|
|
125
|
-
return types.isIdentifier(d.id) && d.id.name === "FRAGMENT" && types.isTaggedTemplateExpression(d.init);
|
|
126
|
-
}
|
|
127
|
-
);
|
|
128
|
-
if (exportedFragmentNode) {
|
|
129
|
-
const templateExpression = exportedFragmentNode.init;
|
|
130
|
-
cellFragment = templateExpression.quasi.quasis[0].value.raw;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
return;
|
|
134
|
-
}
|
|
135
|
-
});
|
|
136
|
-
return cellFragment;
|
|
137
|
-
};
|
|
138
118
|
const hasDefaultExport = (ast) => {
|
|
139
119
|
let exported = false;
|
|
140
120
|
traverse(ast, {
|
|
@@ -174,7 +154,6 @@ const getDefaultExportLocation = (ast) => {
|
|
|
174
154
|
};
|
|
175
155
|
export {
|
|
176
156
|
fileToAst,
|
|
177
|
-
getCellGqlFragment,
|
|
178
157
|
getCellGqlQuery,
|
|
179
158
|
getDefaultExportLocation,
|
|
180
159
|
getGqlQueries,
|
package/dist/build/api.d.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import type { BuildOptions } from 'esbuild';
|
|
2
|
-
export { applySrcAlias } from './src-alias.js';
|
|
3
|
-
export { applyImportExtensions } from './import-extensions.js';
|
|
4
2
|
export declare const buildApi: () => Promise<import("esbuild").BuildResult<BuildOptions>>;
|
|
5
3
|
export declare const rebuildApi: () => Promise<import("esbuild").BuildResult<BuildOptions>>;
|
|
6
4
|
export declare const cleanApiBuild: () => Promise<void>;
|
package/dist/build/api.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/build/api.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAgB,YAAY,EAAe,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/build/api.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAgB,YAAY,EAAe,MAAM,SAAS,CAAA;AAiBtE,eAAO,MAAM,QAAQ,4DAIpB,CAAA;AAED,eAAO,MAAM,UAAU,4DAStB,CAAA;AAED,eAAO,MAAM,aAAa,qBAGzB,CAAA;AA8FD,eAAO,MAAM,gBAAgB,iHAqD5B,CAAA;AAcD,wBAAsB,aAAa,CACjC,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,IAAI,CAAC,CAoDf"}
|
package/dist/build/api.js
CHANGED
|
@@ -1,42 +1,14 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { build, context } from "esbuild";
|
|
4
|
-
import MagicString from "magic-string";
|
|
5
4
|
import { build as viteBuild, normalizePath } from "vite";
|
|
6
|
-
import tsPathsMod from "vite-tsconfig-paths";
|
|
7
|
-
const tsconfigPaths = (
|
|
8
|
-
// @ts-expect-error – .default only exists at runtime in CJS double-wrap
|
|
9
|
-
// interop
|
|
10
|
-
tsPathsMod.default?.default || tsPathsMod.default || tsPathsMod
|
|
11
|
-
);
|
|
12
5
|
import {
|
|
13
|
-
|
|
14
|
-
getApiSideBabelPluginsForVite,
|
|
6
|
+
getApiSideBabelPlugins,
|
|
15
7
|
transformWithBabel
|
|
16
8
|
} from "@cedarjs/babel-config";
|
|
17
|
-
import {
|
|
18
|
-
getConfig,
|
|
19
|
-
getPaths,
|
|
20
|
-
projectSideIsEsm,
|
|
21
|
-
resolveFile
|
|
22
|
-
} from "@cedarjs/project-config";
|
|
9
|
+
import { getConfig, getPaths, projectSideIsEsm } from "@cedarjs/project-config";
|
|
23
10
|
import { findApiFiles } from "../files.js";
|
|
24
|
-
import {
|
|
25
|
-
applyGqlormInject,
|
|
26
|
-
applyGraphqlOptionsExtract
|
|
27
|
-
} from "./api-graphql-transforms.js";
|
|
28
|
-
import { applyAutoImports } from "./auto-import.js";
|
|
29
|
-
import { applyDirectoryNamedImport } from "./directory-named-import.js";
|
|
30
|
-
import { cedarApiGraphqlPlugin } from "./esbuild-plugin-api-graphql.js";
|
|
31
|
-
import { applyOtelWrapping } from "./esbuild-plugin-cedar-otel-wrapping.js";
|
|
32
|
-
import { applyHandlerAlsWrapping } from "./esbuild-plugin-handler-als-wrapping.js";
|
|
33
|
-
import { applyImportDir } from "./import-dir.js";
|
|
34
|
-
import { applyImportExtensions } from "./import-extensions.js";
|
|
35
|
-
import { applyJobPathInjector } from "./job-path-injector.js";
|
|
36
|
-
import { applySrcAlias } from "./src-alias.js";
|
|
37
|
-
import { applyTsconfigPaths } from "./tsconfig-paths.js";
|
|
38
|
-
import { applySrcAlias as applySrcAlias2 } from "./src-alias.js";
|
|
39
|
-
import { applyImportExtensions as applyImportExtensions2 } from "./import-extensions.js";
|
|
11
|
+
import { applyContextWrapping } from "./esbuild-plugin-cedar-context-wrapping.js";
|
|
40
12
|
let BUILD_CTX = null;
|
|
41
13
|
const buildApi = async () => {
|
|
42
14
|
BUILD_CTX?.dispose();
|
|
@@ -60,122 +32,33 @@ const cleanApiBuild = async () => {
|
|
|
60
32
|
const runCedarBabelTransformsPlugin = {
|
|
61
33
|
name: "cedar-esbuild-babel-transform",
|
|
62
34
|
setup(build2) {
|
|
35
|
+
const cedarConfig = getConfig();
|
|
63
36
|
build2.onLoad({ filter: /\.(js|ts|tsx|jsx)$/ }, async (args) => {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
fileContents,
|
|
67
|
-
path.dirname(
|
|
68
|
-
path.relative(build2.initialOptions.absWorkingDir + "/src", args.path)
|
|
69
|
-
)
|
|
70
|
-
);
|
|
71
|
-
fileContents = applyTsconfigPaths(
|
|
37
|
+
const fileContents = await fs.promises.readFile(args.path, "utf-8");
|
|
38
|
+
const transformedCode = await transformWithBabel(
|
|
72
39
|
fileContents,
|
|
73
40
|
args.path,
|
|
74
|
-
|
|
41
|
+
getApiSideBabelPlugins({
|
|
42
|
+
openTelemetry: cedarConfig.experimental.opentelemetry.enabled && cedarConfig.experimental.opentelemetry.wrapApi,
|
|
43
|
+
projectIsEsm: projectSideIsEsm("api")
|
|
44
|
+
})
|
|
75
45
|
);
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
fileContents = applyJobPathInjector(fileContents, args.path, getPaths().api.jobs) ?? fileContents;
|
|
80
|
-
const normalizedPath = normalizePath(args.path);
|
|
81
|
-
const cedarPaths = getPaths();
|
|
82
|
-
const isEsm = projectSideIsEsm("api");
|
|
83
|
-
const apiBabelConfigPath = getApiSideBabelConfigPath();
|
|
84
|
-
let code = fileContents;
|
|
85
|
-
if (apiBabelConfigPath) {
|
|
86
|
-
const transformedCode = await transformWithBabel(
|
|
87
|
-
fileContents,
|
|
88
|
-
args.path,
|
|
89
|
-
getApiSideBabelPluginsForVite(),
|
|
90
|
-
"inline",
|
|
91
|
-
true
|
|
46
|
+
if (transformedCode?.code) {
|
|
47
|
+
const functionsDir = normalizePath(
|
|
48
|
+
path.join(getPaths().api.src, "functions")
|
|
92
49
|
);
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
if (normalizedPath.startsWith(functionsDir + "/")) {
|
|
101
|
-
code = applyHandlerAlsWrapping(code, {
|
|
102
|
-
projectIsEsm: isEsm
|
|
103
|
-
}) ?? code;
|
|
104
|
-
}
|
|
105
|
-
if (normalizedPath.startsWith(normalizePath(cedarPaths.api.src) + "/")) {
|
|
106
|
-
code = applyOtelWrapping(code, args.path, cedarPaths.api.src) ?? code;
|
|
50
|
+
const code = normalizePath(args.path).startsWith(functionsDir + "/") ? applyContextWrapping(transformedCode.code, {
|
|
51
|
+
projectIsEsm: projectSideIsEsm("api")
|
|
52
|
+
}) ?? transformedCode.code : transformedCode.code;
|
|
53
|
+
return {
|
|
54
|
+
contents: code,
|
|
55
|
+
loader: "js"
|
|
56
|
+
};
|
|
107
57
|
}
|
|
108
|
-
|
|
109
|
-
contents: code,
|
|
110
|
-
// Babel output is always plain JS. Without Babel the contents are
|
|
111
|
-
// still TypeScript/JSX, so pick the loader matching the file's
|
|
112
|
-
// extension and let esbuild do the stripping.
|
|
113
|
-
loader: apiBabelConfigPath ? "js" : getEsbuildLoader(args.path)
|
|
114
|
-
};
|
|
58
|
+
throw new Error(`Could not transform file: ${args.path}`);
|
|
115
59
|
});
|
|
116
60
|
}
|
|
117
61
|
};
|
|
118
|
-
function getEsbuildLoader(filePath) {
|
|
119
|
-
switch (path.extname(filePath)) {
|
|
120
|
-
case ".ts":
|
|
121
|
-
return "ts";
|
|
122
|
-
case ".tsx":
|
|
123
|
-
return "tsx";
|
|
124
|
-
case ".jsx":
|
|
125
|
-
return "jsx";
|
|
126
|
-
default:
|
|
127
|
-
return "js";
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
function createImportDirVitePlugin() {
|
|
131
|
-
return {
|
|
132
|
-
name: "cedar-internal-import-dir",
|
|
133
|
-
enforce: "pre",
|
|
134
|
-
transform(code, id) {
|
|
135
|
-
if (!/\.(js|ts|tsx|jsx)$/.test(id)) {
|
|
136
|
-
return null;
|
|
137
|
-
}
|
|
138
|
-
if (id.includes("node_modules")) {
|
|
139
|
-
return null;
|
|
140
|
-
}
|
|
141
|
-
const result = applyImportDir(code, id);
|
|
142
|
-
if (!result) {
|
|
143
|
-
return null;
|
|
144
|
-
}
|
|
145
|
-
return { code: result.code, map: result.map };
|
|
146
|
-
}
|
|
147
|
-
};
|
|
148
|
-
}
|
|
149
|
-
function createDirectoryNamedImportVitePlugin() {
|
|
150
|
-
return {
|
|
151
|
-
name: "cedar-internal-directory-named-import",
|
|
152
|
-
enforce: "pre",
|
|
153
|
-
resolveId(id, importer) {
|
|
154
|
-
if (!id.startsWith(".") || !importer) {
|
|
155
|
-
return null;
|
|
156
|
-
}
|
|
157
|
-
if (importer.includes("node_modules")) {
|
|
158
|
-
return null;
|
|
159
|
-
}
|
|
160
|
-
const absolutePath = path.resolve(path.dirname(importer), id);
|
|
161
|
-
if (resolveFile(absolutePath)) {
|
|
162
|
-
return null;
|
|
163
|
-
}
|
|
164
|
-
const indexPath = path.join(absolutePath, "index");
|
|
165
|
-
const resolvedIndex = resolveFile(indexPath);
|
|
166
|
-
if (resolvedIndex) {
|
|
167
|
-
return normalizePath(resolvedIndex);
|
|
168
|
-
}
|
|
169
|
-
const basename = path.basename(absolutePath);
|
|
170
|
-
const dirNamedPath = path.join(absolutePath, basename);
|
|
171
|
-
const resolvedDirNamed = resolveFile(dirNamedPath);
|
|
172
|
-
if (resolvedDirNamed) {
|
|
173
|
-
return normalizePath(resolvedDirNamed);
|
|
174
|
-
}
|
|
175
|
-
return null;
|
|
176
|
-
}
|
|
177
|
-
};
|
|
178
|
-
}
|
|
179
62
|
function createCedarViteApiPlugin() {
|
|
180
63
|
const cedarConfig = getConfig();
|
|
181
64
|
const isEsm = projectSideIsEsm("api");
|
|
@@ -193,53 +76,28 @@ function createCedarViteApiPlugin() {
|
|
|
193
76
|
if (!normalizePath(id).startsWith(normalizePath(cedarPaths.api.base))) {
|
|
194
77
|
return null;
|
|
195
78
|
}
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
sourceCode = applySrcAlias(
|
|
199
|
-
sourceCode,
|
|
200
|
-
path.dirname(path.relative(cedarPaths.api.src, id))
|
|
201
|
-
);
|
|
202
|
-
sourceCode = applyAutoImports(sourceCode);
|
|
203
|
-
sourceCode = applyJobPathInjector(sourceCode, id, cedarPaths.api.jobs) ?? sourceCode;
|
|
204
|
-
if (normalizedId.endsWith("/graphql.ts") || normalizedId.endsWith("/graphql.js")) {
|
|
205
|
-
sourceCode = applyGraphqlOptionsExtract(sourceCode) ?? sourceCode;
|
|
206
|
-
sourceCode = applyGqlormInject(sourceCode, id) ?? sourceCode;
|
|
207
|
-
}
|
|
208
|
-
const apiBabelConfigPath = getApiSideBabelConfigPath();
|
|
209
|
-
const transformedCode = apiBabelConfigPath ? await transformWithBabel(
|
|
210
|
-
sourceCode,
|
|
79
|
+
const transformedCode = await transformWithBabel(
|
|
80
|
+
code,
|
|
211
81
|
id,
|
|
212
|
-
|
|
213
|
-
|
|
82
|
+
getApiSideBabelPlugins({
|
|
83
|
+
openTelemetry: cedarConfig.experimental.opentelemetry.enabled && cedarConfig.experimental.opentelemetry.wrapApi,
|
|
84
|
+
projectIsEsm: isEsm
|
|
85
|
+
}),
|
|
214
86
|
true
|
|
215
|
-
)
|
|
216
|
-
if (
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
outputCode = applyOtelWrapping(outputCode, id, cedarPaths.api.src) ?? outputCode;
|
|
222
|
-
}
|
|
223
|
-
outputCode = applyImportExtensions(outputCode, id);
|
|
224
|
-
const functionsDir = normalizePath(cedarPaths.api.functions);
|
|
225
|
-
if (normalizedId.startsWith(functionsDir + "/")) {
|
|
226
|
-
outputCode = applyHandlerAlsWrapping(outputCode, {
|
|
87
|
+
);
|
|
88
|
+
if (transformedCode?.code) {
|
|
89
|
+
const functionsDir = normalizePath(
|
|
90
|
+
path.join(cedarPaths.api.src, "functions")
|
|
91
|
+
);
|
|
92
|
+
const code2 = normalizePath(id).startsWith(functionsDir + "/") ? applyContextWrapping(transformedCode.code, {
|
|
227
93
|
projectIsEsm: isEsm
|
|
228
|
-
}) ??
|
|
229
|
-
}
|
|
230
|
-
if (!transformedCode) {
|
|
231
|
-
if (outputCode === code) {
|
|
232
|
-
return null;
|
|
233
|
-
}
|
|
94
|
+
}) ?? transformedCode.code : transformedCode.code;
|
|
234
95
|
return {
|
|
235
|
-
code:
|
|
236
|
-
map:
|
|
96
|
+
code: code2,
|
|
97
|
+
map: transformedCode.map ?? null
|
|
237
98
|
};
|
|
238
99
|
}
|
|
239
|
-
|
|
240
|
-
code: outputCode,
|
|
241
|
-
map: transformedCode.map ?? null
|
|
242
|
-
};
|
|
100
|
+
throw new Error(`Could not transform file: ${id}`);
|
|
243
101
|
}
|
|
244
102
|
};
|
|
245
103
|
}
|
|
@@ -283,19 +141,7 @@ const buildApiWithVite = async () => {
|
|
|
283
141
|
}
|
|
284
142
|
}
|
|
285
143
|
},
|
|
286
|
-
|
|
287
|
-
// are expanded before Babel sees the code. The Babel import-dir plugin is
|
|
288
|
-
// not part of getApiSideBabelPluginsForVite(); this inline Vite plugin is
|
|
289
|
-
// its replacement for this code path (both CJS and ESM output via Rollup).
|
|
290
|
-
// tsconfigPaths resolves user-defined tsconfig.json `paths` aliases; it
|
|
291
|
-
// replaces the Babel module-resolver's tsconfig-paths handling for this
|
|
292
|
-
// code path.
|
|
293
|
-
plugins: [
|
|
294
|
-
tsconfigPaths(),
|
|
295
|
-
createImportDirVitePlugin(),
|
|
296
|
-
createDirectoryNamedImportVitePlugin(),
|
|
297
|
-
createCedarViteApiPlugin()
|
|
298
|
-
]
|
|
144
|
+
plugins: [createCedarViteApiPlugin()]
|
|
299
145
|
});
|
|
300
146
|
};
|
|
301
147
|
const transpileApi = async (files) => {
|
|
@@ -353,10 +199,7 @@ function getEsbuildOptions(files) {
|
|
|
353
199
|
format,
|
|
354
200
|
allowOverwrite: true,
|
|
355
201
|
bundle: false,
|
|
356
|
-
|
|
357
|
-
// come first so it claims graphql.ts before runCedarBabelTransformsPlugin
|
|
358
|
-
// (broad filter) can. See the NOTE on cedarApiGraphqlPlugin.
|
|
359
|
-
plugins: [cedarApiGraphqlPlugin, runCedarBabelTransformsPlugin],
|
|
202
|
+
plugins: [runCedarBabelTransformsPlugin],
|
|
360
203
|
outdir: cedarPaths.api.dist,
|
|
361
204
|
// setting this to 'true' will generate an external sourcemap x.js.map
|
|
362
205
|
// AND set the sourceMappingURL comment
|
|
@@ -365,8 +208,6 @@ function getEsbuildOptions(files) {
|
|
|
365
208
|
};
|
|
366
209
|
}
|
|
367
210
|
export {
|
|
368
|
-
applyImportExtensions2 as applyImportExtensions,
|
|
369
|
-
applySrcAlias2 as applySrcAlias,
|
|
370
211
|
buildApi,
|
|
371
212
|
buildApiWithVite,
|
|
372
213
|
cleanApiBuild,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"esbuild-plugin-cedar-context-wrapping.d.ts","sourceRoot":"","sources":["../../src/build/esbuild-plugin-cedar-context-wrapping.ts"],"names":[],"mappings":"AAOA,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,MAAM,EACZ,EAAE,YAAoB,EAAE,GAAE;IAAE,YAAY,CAAC,EAAE,OAAO,CAAA;CAAO,GACxD,MAAM,GAAG,IAAI,CA0Cf"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
function
|
|
1
|
+
function applyContextWrapping(code, { projectIsEsm = false } = {}) {
|
|
2
2
|
const handlerRe = /^export\s+(?:const|let|var)\s+handler(?:[^=]|=>)*?=(?![>=])/m;
|
|
3
3
|
const handlerMatch = handlerRe.exec(code);
|
|
4
4
|
if (!handlerMatch) {
|
|
@@ -7,29 +7,29 @@ function applyHandlerAlsWrapping(code, { projectIsEsm = false } = {}) {
|
|
|
7
7
|
const afterEquals = code.slice(handlerMatch.index + handlerMatch[0].length).trimStart();
|
|
8
8
|
const isAsync = /^async(?:\s*[\(\*]|\s+function)/.test(afterEquals);
|
|
9
9
|
const storePath = projectIsEsm ? "@cedarjs/context/dist/store.js" : "@cedarjs/context/dist/store";
|
|
10
|
-
const importStatement = `import { getAsyncStoreInstance as
|
|
10
|
+
const importStatement = `import { getAsyncStoreInstance as __rw_getAsyncStoreInstance } from '${storePath}'
|
|
11
11
|
`;
|
|
12
12
|
const handlerStart = handlerMatch.index;
|
|
13
13
|
const before = code.slice(0, handlerStart);
|
|
14
14
|
const after = code.slice(handlerStart);
|
|
15
|
-
const renamed = after.replace(handlerRe, "const
|
|
15
|
+
const renamed = after.replace(handlerRe, "const __rw_handler =");
|
|
16
16
|
const wrappedHandler = `
|
|
17
|
-
export const handler = ${isAsync ? "async " : ""}(
|
|
17
|
+
export const handler = ${isAsync ? "async " : ""}(__rw_event, __rw__context) => {
|
|
18
18
|
// The store will be undefined if no context isolation has been performed yet
|
|
19
|
-
const
|
|
20
|
-
if (
|
|
21
|
-
return
|
|
19
|
+
const __rw_contextStore = __rw_getAsyncStoreInstance().getStore()
|
|
20
|
+
if (__rw_contextStore === undefined) {
|
|
21
|
+
return __rw_getAsyncStoreInstance().run(
|
|
22
22
|
new Map(),
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
__rw_handler,
|
|
24
|
+
__rw_event,
|
|
25
|
+
__rw__context
|
|
26
26
|
)
|
|
27
27
|
}
|
|
28
|
-
return
|
|
28
|
+
return __rw_handler(__rw_event, __rw__context)
|
|
29
29
|
}
|
|
30
30
|
`;
|
|
31
31
|
return before + importStatement + renamed + wrappedHandler;
|
|
32
32
|
}
|
|
33
33
|
export {
|
|
34
|
-
|
|
34
|
+
applyContextWrapping
|
|
35
35
|
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { types } from '@babel/core';
|
|
2
|
+
export declare const fileToAst: (filePath: string) => types.Node;
|
|
3
|
+
interface NamedExports {
|
|
4
|
+
name: string;
|
|
5
|
+
type: 're-export' | 'variable' | 'function' | 'class';
|
|
6
|
+
location: {
|
|
7
|
+
line: number;
|
|
8
|
+
column: number;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* get all the named exports in a given piece of code.
|
|
13
|
+
*/
|
|
14
|
+
export declare const getNamedExports: (ast: types.Node) => NamedExports[];
|
|
15
|
+
/**
|
|
16
|
+
* get all the gql queries from the supplied code
|
|
17
|
+
*/
|
|
18
|
+
export declare const getGqlQueries: (ast: types.Node) => string[];
|
|
19
|
+
export declare const getCellGqlQuery: (ast: types.Node) => undefined;
|
|
20
|
+
export declare const hasDefaultExport: (ast: types.Node) => boolean;
|
|
21
|
+
export declare const getDefaultExportLocation: (ast: types.Node) => {
|
|
22
|
+
line: number;
|
|
23
|
+
column: number;
|
|
24
|
+
} | null;
|
|
25
|
+
export {};
|
|
26
|
+
//# sourceMappingURL=ast.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ast.d.ts","sourceRoot":"","sources":["../../src/ast.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAmBnC,eAAO,MAAM,SAAS,GAAI,UAAU,MAAM,KAAG,KAAK,CAAC,IAyBlD,CAAA;AAED,UAAU,YAAY;IACpB,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,WAAW,GAAG,UAAU,GAAG,UAAU,GAAG,OAAO,CAAA;IACrD,QAAQ,EAAE;QACR,IAAI,EAAE,MAAM,CAAA;QACZ,MAAM,EAAE,MAAM,CAAA;KACf,CAAA;CACF;AACD;;GAEG;AACH,eAAO,MAAM,eAAe,GAAI,KAAK,KAAK,CAAC,IAAI,KAAG,YAAY,EA4D7D,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,aAAa,GAAI,KAAK,KAAK,CAAC,IAAI,aAY5C,CAAA;AAED,eAAO,MAAM,eAAe,GAAI,KAAK,KAAK,CAAC,IAAI,cA8B9C,CAAA;AAED,eAAO,MAAM,gBAAgB,GAAI,KAAK,KAAK,CAAC,IAAI,KAAG,OASlD,CAAA;AAED,eAAO,MAAM,wBAAwB,GACnC,KAAK,KAAK,CAAC,IAAI,KACd;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG,IA0CrC,CAAA"}
|
package/dist/cjs/ast.js
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
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 ast_exports = {};
|
|
30
|
+
__export(ast_exports, {
|
|
31
|
+
fileToAst: () => fileToAst,
|
|
32
|
+
getCellGqlQuery: () => getCellGqlQuery,
|
|
33
|
+
getDefaultExportLocation: () => getDefaultExportLocation,
|
|
34
|
+
getGqlQueries: () => getGqlQueries,
|
|
35
|
+
getNamedExports: () => getNamedExports,
|
|
36
|
+
hasDefaultExport: () => hasDefaultExport
|
|
37
|
+
});
|
|
38
|
+
module.exports = __toCommonJS(ast_exports);
|
|
39
|
+
var import_node_fs = __toESM(require("node:fs"), 1);
|
|
40
|
+
var import_path = __toESM(require("path"), 1);
|
|
41
|
+
var import_core = require("@babel/core");
|
|
42
|
+
var import_parser = require("@babel/parser");
|
|
43
|
+
var import_traverse = __toESM(require("@babel/traverse"), 1);
|
|
44
|
+
var import_ansis = __toESM(require("ansis"), 1);
|
|
45
|
+
var import_project_config = require("@cedarjs/project-config");
|
|
46
|
+
var import_files = require("./files.js");
|
|
47
|
+
const traverse = import_traverse.default.default || import_traverse.default;
|
|
48
|
+
const fileToAst = (filePath) => {
|
|
49
|
+
const code = import_node_fs.default.readFileSync(filePath, "utf-8");
|
|
50
|
+
const isJsxFile = import_path.default.extname(filePath).match(/[jt]sx$/) || (0, import_files.isFileInsideFolder)(filePath, (0, import_project_config.getPaths)().web.base);
|
|
51
|
+
const plugins = [
|
|
52
|
+
"typescript",
|
|
53
|
+
"nullishCoalescingOperator",
|
|
54
|
+
"objectRestSpread",
|
|
55
|
+
isJsxFile && "jsx"
|
|
56
|
+
].filter(Boolean);
|
|
57
|
+
try {
|
|
58
|
+
return (0, import_parser.parse)(code, {
|
|
59
|
+
sourceType: "module",
|
|
60
|
+
plugins
|
|
61
|
+
});
|
|
62
|
+
} catch (e) {
|
|
63
|
+
console.error(import_ansis.default.red(`Error parsing: ${filePath}`));
|
|
64
|
+
console.error(e);
|
|
65
|
+
throw new Error(e?.message);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
const getNamedExports = (ast) => {
|
|
69
|
+
const namedExports = [];
|
|
70
|
+
traverse(ast, {
|
|
71
|
+
ExportNamedDeclaration(path2) {
|
|
72
|
+
const specifiers = path2.node?.specifiers;
|
|
73
|
+
if (specifiers.length) {
|
|
74
|
+
for (const s of specifiers) {
|
|
75
|
+
const id = s.exported;
|
|
76
|
+
namedExports.push({
|
|
77
|
+
name: id.name,
|
|
78
|
+
type: "re-export",
|
|
79
|
+
location: {
|
|
80
|
+
line: id.loc?.start.line ?? 1,
|
|
81
|
+
column: id.loc?.start.column ?? 0
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
const declaration = path2.node.declaration;
|
|
88
|
+
if (!declaration) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
if (declaration.type === "VariableDeclaration") {
|
|
92
|
+
const id = declaration.declarations[0].id;
|
|
93
|
+
namedExports.push({
|
|
94
|
+
name: id.name,
|
|
95
|
+
type: "variable",
|
|
96
|
+
location: {
|
|
97
|
+
line: id.loc?.start.line ?? 1,
|
|
98
|
+
column: id.loc?.start.column ?? 0
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
} else if (declaration.type === "FunctionDeclaration") {
|
|
102
|
+
namedExports.push({
|
|
103
|
+
name: declaration?.id?.name,
|
|
104
|
+
type: "function",
|
|
105
|
+
location: {
|
|
106
|
+
line: declaration?.id?.loc?.start.line ?? 1,
|
|
107
|
+
column: declaration?.id?.loc?.start.column ?? 0
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
} else if (declaration.type === "ClassDeclaration") {
|
|
111
|
+
namedExports.push({
|
|
112
|
+
name: declaration?.id?.name,
|
|
113
|
+
type: "class",
|
|
114
|
+
location: {
|
|
115
|
+
line: declaration?.id?.loc?.start.line ?? 1,
|
|
116
|
+
column: declaration?.id?.loc?.start.column ?? 0
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
return namedExports;
|
|
123
|
+
};
|
|
124
|
+
const getGqlQueries = (ast) => {
|
|
125
|
+
const gqlQueries = [];
|
|
126
|
+
traverse(ast, {
|
|
127
|
+
TaggedTemplateExpression(path2) {
|
|
128
|
+
const gqlTag = path2.node.tag;
|
|
129
|
+
if (gqlTag.type === "Identifier" && gqlTag.name === "gql") {
|
|
130
|
+
gqlQueries.push(path2.node.quasi.quasis[0].value.raw);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
return gqlQueries;
|
|
135
|
+
};
|
|
136
|
+
const getCellGqlQuery = (ast) => {
|
|
137
|
+
let cellQuery = void 0;
|
|
138
|
+
traverse(ast, {
|
|
139
|
+
ExportNamedDeclaration({ node }) {
|
|
140
|
+
if (node.exportKind === "value" && import_core.types.isVariableDeclaration(node.declaration)) {
|
|
141
|
+
const exportedQueryNode = node.declaration.declarations.find(
|
|
142
|
+
(d) => {
|
|
143
|
+
return import_core.types.isIdentifier(d.id) && d.id.name === "QUERY" && import_core.types.isTaggedTemplateExpression(d.init);
|
|
144
|
+
}
|
|
145
|
+
);
|
|
146
|
+
if (exportedQueryNode) {
|
|
147
|
+
const templateExpression = exportedQueryNode.init;
|
|
148
|
+
cellQuery = templateExpression.quasi.quasis[0].value.raw;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
return cellQuery;
|
|
155
|
+
};
|
|
156
|
+
const hasDefaultExport = (ast) => {
|
|
157
|
+
let exported = false;
|
|
158
|
+
traverse(ast, {
|
|
159
|
+
ExportDefaultDeclaration() {
|
|
160
|
+
exported = true;
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
return exported;
|
|
165
|
+
};
|
|
166
|
+
const getDefaultExportLocation = (ast) => {
|
|
167
|
+
let defaultExport;
|
|
168
|
+
traverse(ast, {
|
|
169
|
+
ExportDefaultDeclaration(path2) {
|
|
170
|
+
defaultExport = path2.node;
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
if (!defaultExport) {
|
|
174
|
+
return null;
|
|
175
|
+
}
|
|
176
|
+
if (import_core.types.isIdentifier(defaultExport.declaration) && import_core.types.isFile(ast)) {
|
|
177
|
+
const exportedName = defaultExport.declaration.name;
|
|
178
|
+
const declaration = ast.program.body.find((node) => {
|
|
179
|
+
return import_core.types.isVariableDeclaration(node) && node.declarations.find((d) => {
|
|
180
|
+
return import_core.types.isVariableDeclarator(d) && import_core.types.isIdentifier(d.id) && d.id.name === exportedName;
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
return {
|
|
184
|
+
line: declaration?.loc?.start.line ?? 1,
|
|
185
|
+
column: declaration?.loc?.start.column ?? 0
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
return {
|
|
189
|
+
line: defaultExport.loc?.start.line ?? 1,
|
|
190
|
+
column: defaultExport.loc?.start.column ?? 0
|
|
191
|
+
};
|
|
192
|
+
};
|
|
193
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
194
|
+
0 && (module.exports = {
|
|
195
|
+
fileToAst,
|
|
196
|
+
getCellGqlQuery,
|
|
197
|
+
getDefaultExportLocation,
|
|
198
|
+
getGqlQueries,
|
|
199
|
+
getNamedExports,
|
|
200
|
+
hasDefaultExport
|
|
201
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { BuildOptions } from 'esbuild';
|
|
2
|
+
export declare const buildApi: () => Promise<import("esbuild").BuildResult<BuildOptions>>;
|
|
3
|
+
export declare const rebuildApi: () => Promise<import("esbuild").BuildResult<BuildOptions>>;
|
|
4
|
+
export declare const cleanApiBuild: () => Promise<void>;
|
|
5
|
+
export declare const buildApiWithVite: () => Promise<import("rollup").RollupOutput | import("rollup").RollupOutput[] | import("rollup").RollupWatcher>;
|
|
6
|
+
export declare function fixSourceMaps(distDir: string, srcDir: string): Promise<void>;
|
|
7
|
+
//# sourceMappingURL=api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../src/build/api.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAgB,YAAY,EAAe,MAAM,SAAS,CAAA;AAiBtE,eAAO,MAAM,QAAQ,4DAIpB,CAAA;AAED,eAAO,MAAM,UAAU,4DAStB,CAAA;AAED,eAAO,MAAM,aAAa,qBAGzB,CAAA;AA8FD,eAAO,MAAM,gBAAgB,iHAqD5B,CAAA;AAcD,wBAAsB,aAAa,CACjC,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,IAAI,CAAC,CAoDf"}
|