@cedarjs/internal 6.0.0-canary.2662 → 6.0.0-canary.2663
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/build/api.d.ts +2 -0
- package/dist/build/api.d.ts.map +1 -1
- package/dist/build/api.js +11 -0
- package/dist/build/esbuild-plugin-api-graphql.d.ts.map +1 -1
- package/dist/build/esbuild-plugin-api-graphql.js +4 -0
- package/dist/build/esm-extensions.d.ts +33 -0
- package/dist/build/esm-extensions.d.ts.map +1 -0
- package/dist/build/esm-extensions.js +37 -0
- package/dist/cjs/build/api.d.ts +2 -0
- package/dist/cjs/build/api.d.ts.map +1 -1
- package/dist/cjs/build/api.js +13 -0
- package/dist/cjs/build/esbuild-plugin-api-graphql.d.ts.map +1 -1
- package/dist/cjs/build/esbuild-plugin-api-graphql.js +4 -0
- package/dist/cjs/build/esm-extensions.d.ts +33 -0
- package/dist/cjs/build/esm-extensions.d.ts.map +1 -0
- package/dist/cjs/build/esm-extensions.js +71 -0
- package/package.json +19 -9
package/dist/build/api.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { BuildOptions } from 'esbuild';
|
|
2
|
+
export { applySrcAlias } from './src-alias.js';
|
|
3
|
+
export { applyEsmExtensions } from './esm-extensions.js';
|
|
2
4
|
export declare const buildApi: () => Promise<import("esbuild").BuildResult<BuildOptions>>;
|
|
3
5
|
export declare const rebuildApi: () => Promise<import("esbuild").BuildResult<BuildOptions>>;
|
|
4
6
|
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;AA0CtE,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAC9C,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAIxD,eAAO,MAAM,QAAQ,4DAIpB,CAAA;AAED,eAAO,MAAM,UAAU,4DAStB,CAAA;AAED,eAAO,MAAM,aAAa,qBAGzB,CAAA;AAoRD,eAAO,MAAM,gBAAgB,iHAiE5B,CAAA;AAcD,wBAAsB,aAAa,CACjC,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,IAAI,CAAC,CAoDf"}
|
package/dist/build/api.js
CHANGED
|
@@ -28,9 +28,12 @@ import { applyDirectoryNamedImport } from "./directory-named-import.js";
|
|
|
28
28
|
import { cedarApiGraphqlPlugin } from "./esbuild-plugin-api-graphql.js";
|
|
29
29
|
import { applyOtelWrapping } from "./esbuild-plugin-cedar-otel-wrapping.js";
|
|
30
30
|
import { applyHandlerAlsWrapping } from "./esbuild-plugin-handler-als-wrapping.js";
|
|
31
|
+
import { applyEsmExtensions } from "./esm-extensions.js";
|
|
31
32
|
import { applyImportDir } from "./import-dir.js";
|
|
32
33
|
import { applySrcAlias } from "./src-alias.js";
|
|
33
34
|
import { applyTsconfigPaths } from "./tsconfig-paths.js";
|
|
35
|
+
import { applySrcAlias as applySrcAlias2 } from "./src-alias.js";
|
|
36
|
+
import { applyEsmExtensions as applyEsmExtensions2 } from "./esm-extensions.js";
|
|
34
37
|
let BUILD_CTX = null;
|
|
35
38
|
const buildApi = async () => {
|
|
36
39
|
BUILD_CTX?.dispose();
|
|
@@ -83,6 +86,9 @@ const runCedarBabelTransformsPlugin = {
|
|
|
83
86
|
const normalizedPath = normalizePath(args.path);
|
|
84
87
|
const cedarPaths = getPaths();
|
|
85
88
|
const isEsm = projectSideIsEsm("api");
|
|
89
|
+
if (isEsm) {
|
|
90
|
+
code = applyEsmExtensions(code, args.path);
|
|
91
|
+
}
|
|
86
92
|
const functionsDir = normalizePath(cedarPaths.api.functions);
|
|
87
93
|
if (normalizedPath.startsWith(functionsDir + "/")) {
|
|
88
94
|
code = applyHandlerAlsWrapping(code, {
|
|
@@ -192,6 +198,9 @@ function createCedarViteApiPlugin() {
|
|
|
192
198
|
if (cedarConfig.experimental?.opentelemetry?.enabled && cedarConfig.experimental?.opentelemetry?.wrapApi) {
|
|
193
199
|
code2 = applyOtelWrapping(code2, id, cedarPaths.api.src) ?? code2;
|
|
194
200
|
}
|
|
201
|
+
if (isEsm) {
|
|
202
|
+
code2 = applyEsmExtensions(code2, id);
|
|
203
|
+
}
|
|
195
204
|
const functionsDir = normalizePath(cedarPaths.api.functions);
|
|
196
205
|
if (normalizedId.startsWith(functionsDir + "/")) {
|
|
197
206
|
code2 = applyHandlerAlsWrapping(code2, {
|
|
@@ -329,6 +338,8 @@ function getEsbuildOptions(files) {
|
|
|
329
338
|
};
|
|
330
339
|
}
|
|
331
340
|
export {
|
|
341
|
+
applyEsmExtensions2 as applyEsmExtensions,
|
|
342
|
+
applySrcAlias2 as applySrcAlias,
|
|
332
343
|
buildApi,
|
|
333
344
|
buildApiWithVite,
|
|
334
345
|
cleanApiBuild,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"esbuild-plugin-api-graphql.d.ts","sourceRoot":"","sources":["../../src/build/esbuild-plugin-api-graphql.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"esbuild-plugin-api-graphql.d.ts","sourceRoot":"","sources":["../../src/build/esbuild-plugin-api-graphql.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAqB1C,eAAO,MAAM,qBAAqB;;iBAEnB,WAAW;CAmGzB,CAAA"}
|
|
@@ -13,6 +13,7 @@ import { applyAutoImports } from "./auto-import.js";
|
|
|
13
13
|
import { applyDirectoryNamedImport } from "./directory-named-import.js";
|
|
14
14
|
import { applyOtelWrapping } from "./esbuild-plugin-cedar-otel-wrapping.js";
|
|
15
15
|
import { applyHandlerAlsWrapping } from "./esbuild-plugin-handler-als-wrapping.js";
|
|
16
|
+
import { applyEsmExtensions } from "./esm-extensions.js";
|
|
16
17
|
import { applyImportDir } from "./import-dir.js";
|
|
17
18
|
import { applySrcAlias } from "./src-alias.js";
|
|
18
19
|
import { applyTsconfigPaths } from "./tsconfig-paths.js";
|
|
@@ -50,6 +51,9 @@ const cedarApiGraphqlPlugin = {
|
|
|
50
51
|
throw new Error(`Could not transform file: ${args.path}`);
|
|
51
52
|
}
|
|
52
53
|
let code = transformedCode.code;
|
|
54
|
+
if (projectSideIsEsm("api")) {
|
|
55
|
+
code = applyEsmExtensions(code, args.path);
|
|
56
|
+
}
|
|
53
57
|
if (cedarConfig.experimental?.opentelemetry?.enabled && cedarConfig.experimental?.opentelemetry?.wrapApi) {
|
|
54
58
|
code = applyOtelWrapping(code, args.path, getPaths().api.src) ?? code;
|
|
55
59
|
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* For ESM projects using esbuild with `bundle: false`, rewrites extensionless
|
|
3
|
+
* relative imports to include `.js` extension so that Node's ESM resolver can
|
|
4
|
+
* locate the compiled output files at runtime.
|
|
5
|
+
*
|
|
6
|
+
* Handles both static imports (`from '../lib/db'`) and dynamic imports
|
|
7
|
+
* (`import('../lib/db')`).
|
|
8
|
+
*
|
|
9
|
+
* Always outputs `.js` because esbuild with `loader: 'js'` compiles all source
|
|
10
|
+
* files (`.ts`, `.tsx`, `.jsx`) to `.js` output. For a source file `api/src/lib/db.ts`
|
|
11
|
+
* or `api/src/lib/db.tsx`, the output is always `api/dist/lib/db.js`, so all
|
|
12
|
+
* import specifiers must use `.js` at runtime.
|
|
13
|
+
*
|
|
14
|
+
* This replaces the `resolvePath` hook in `babel-plugin-module-resolver` for
|
|
15
|
+
* the standalone esbuild build path (`runCedarBabelTransformsPlugin`), which
|
|
16
|
+
* was previously responsible for this extension-appending behaviour. Vite
|
|
17
|
+
* and Rollup resolve extensions themselves during bundling; only the esbuild
|
|
18
|
+
* `bundle: false` path needs explicit extension suffixes in the source.
|
|
19
|
+
*
|
|
20
|
+
* It is a plain function called inline — not an esbuild plugin — following
|
|
21
|
+
* the same pattern as `applySrcAlias`, `applyTsconfigPaths`, etc.
|
|
22
|
+
*
|
|
23
|
+
* Also handles Cedar SDL files whose names include a compound extension:
|
|
24
|
+
* `contacts.sdl.ts` compiles to `contacts.sdl.js`, so an import specifier
|
|
25
|
+
* `../graphql/contacts.sdl` (generated by applyImportDir's glob expansion)
|
|
26
|
+
* is rewritten to `../graphql/contacts.sdl.js`.
|
|
27
|
+
*
|
|
28
|
+
* Example: in `api/src/functions/graphql.ts` importing `../lib/db`, this
|
|
29
|
+
* rewrites it to `../lib/db.js` when `api/src/lib/db.ts` (or `db.tsx`)
|
|
30
|
+
* exists on disk.
|
|
31
|
+
*/
|
|
32
|
+
export declare function applyEsmExtensions(code: string, fromFile: string): string;
|
|
33
|
+
//# sourceMappingURL=esm-extensions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"esm-extensions.d.ts","sourceRoot":"","sources":["../../src/build/esm-extensions.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAiEzE"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
function applyEsmExtensions(code, fromFile) {
|
|
4
|
+
const fromDir = path.dirname(fromFile);
|
|
5
|
+
const rewriteImportPath = (importPath, preservePrefix, preserveSuffix) => {
|
|
6
|
+
const existingExt = path.extname(importPath);
|
|
7
|
+
const absImport = path.join(fromDir, importPath);
|
|
8
|
+
if (existingExt && existingExt !== ".js" && existingExt !== ".jsx") {
|
|
9
|
+
if (fs.existsSync(absImport + ".ts") || fs.existsSync(absImport + ".js") || fs.existsSync(absImport + ".tsx") || fs.existsSync(absImport + ".jsx")) {
|
|
10
|
+
return preservePrefix + importPath + ".js" + preserveSuffix;
|
|
11
|
+
}
|
|
12
|
+
return preservePrefix + importPath + preserveSuffix;
|
|
13
|
+
}
|
|
14
|
+
const base = existingExt ? importPath.slice(0, -existingExt.length) : importPath;
|
|
15
|
+
const absBase = path.join(fromDir, base);
|
|
16
|
+
if (fs.existsSync(absBase + ".ts") || fs.existsSync(absBase + ".js") || fs.existsSync(absBase + ".tsx") || fs.existsSync(absBase + ".jsx")) {
|
|
17
|
+
return preservePrefix + base + ".js" + preserveSuffix;
|
|
18
|
+
}
|
|
19
|
+
return preservePrefix + importPath + preserveSuffix;
|
|
20
|
+
};
|
|
21
|
+
let result = code.replace(
|
|
22
|
+
/\bfrom\s+(['"])(\.\.?\/[^'"]+)\1/g,
|
|
23
|
+
(match, quote, importPath) => {
|
|
24
|
+
return `from ${rewriteImportPath(importPath, quote, quote)}`;
|
|
25
|
+
}
|
|
26
|
+
);
|
|
27
|
+
result = result.replace(
|
|
28
|
+
/\bimport\s*\(\s*(['"])(\.\.?\/[^'"]+)\1\s*\)/g,
|
|
29
|
+
(match, quote, importPath) => {
|
|
30
|
+
return `import(${rewriteImportPath(importPath, quote, quote)})`;
|
|
31
|
+
}
|
|
32
|
+
);
|
|
33
|
+
return result;
|
|
34
|
+
}
|
|
35
|
+
export {
|
|
36
|
+
applyEsmExtensions
|
|
37
|
+
};
|
package/dist/cjs/build/api.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { BuildOptions } from 'esbuild';
|
|
2
|
+
export { applySrcAlias } from './src-alias.js';
|
|
3
|
+
export { applyEsmExtensions } from './esm-extensions.js';
|
|
2
4
|
export declare const buildApi: () => Promise<import("esbuild").BuildResult<BuildOptions>>;
|
|
3
5
|
export declare const rebuildApi: () => Promise<import("esbuild").BuildResult<BuildOptions>>;
|
|
4
6
|
export declare const cleanApiBuild: () => Promise<void>;
|
|
@@ -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;AA0CtE,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAC9C,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAIxD,eAAO,MAAM,QAAQ,4DAIpB,CAAA;AAED,eAAO,MAAM,UAAU,4DAStB,CAAA;AAED,eAAO,MAAM,aAAa,qBAGzB,CAAA;AAoRD,eAAO,MAAM,gBAAgB,iHAiE5B,CAAA;AAcD,wBAAsB,aAAa,CACjC,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,IAAI,CAAC,CAoDf"}
|
package/dist/cjs/build/api.js
CHANGED
|
@@ -28,6 +28,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
29
|
var api_exports = {};
|
|
30
30
|
__export(api_exports, {
|
|
31
|
+
applyEsmExtensions: () => import_esm_extensions2.applyEsmExtensions,
|
|
32
|
+
applySrcAlias: () => import_src_alias2.applySrcAlias,
|
|
31
33
|
buildApi: () => buildApi,
|
|
32
34
|
buildApiWithVite: () => buildApiWithVite,
|
|
33
35
|
cleanApiBuild: () => cleanApiBuild,
|
|
@@ -49,9 +51,12 @@ var import_directory_named_import = require("./directory-named-import.js");
|
|
|
49
51
|
var import_esbuild_plugin_api_graphql = require("./esbuild-plugin-api-graphql.js");
|
|
50
52
|
var import_esbuild_plugin_cedar_otel_wrapping = require("./esbuild-plugin-cedar-otel-wrapping.js");
|
|
51
53
|
var import_esbuild_plugin_handler_als_wrapping = require("./esbuild-plugin-handler-als-wrapping.js");
|
|
54
|
+
var import_esm_extensions = require("./esm-extensions.js");
|
|
52
55
|
var import_import_dir = require("./import-dir.js");
|
|
53
56
|
var import_src_alias = require("./src-alias.js");
|
|
54
57
|
var import_tsconfig_paths = require("./tsconfig-paths.js");
|
|
58
|
+
var import_src_alias2 = require("./src-alias.js");
|
|
59
|
+
var import_esm_extensions2 = require("./esm-extensions.js");
|
|
55
60
|
const tsconfigPaths = (
|
|
56
61
|
// @ts-expect-error – .default only exists at runtime in CJS double-wrap
|
|
57
62
|
// interop
|
|
@@ -109,6 +114,9 @@ const runCedarBabelTransformsPlugin = {
|
|
|
109
114
|
const normalizedPath = (0, import_vite.normalizePath)(args.path);
|
|
110
115
|
const cedarPaths = (0, import_project_config.getPaths)();
|
|
111
116
|
const isEsm = (0, import_project_config.projectSideIsEsm)("api");
|
|
117
|
+
if (isEsm) {
|
|
118
|
+
code = (0, import_esm_extensions.applyEsmExtensions)(code, args.path);
|
|
119
|
+
}
|
|
112
120
|
const functionsDir = (0, import_vite.normalizePath)(cedarPaths.api.functions);
|
|
113
121
|
if (normalizedPath.startsWith(functionsDir + "/")) {
|
|
114
122
|
code = (0, import_esbuild_plugin_handler_als_wrapping.applyHandlerAlsWrapping)(code, {
|
|
@@ -218,6 +226,9 @@ function createCedarViteApiPlugin() {
|
|
|
218
226
|
if (cedarConfig.experimental?.opentelemetry?.enabled && cedarConfig.experimental?.opentelemetry?.wrapApi) {
|
|
219
227
|
code2 = (0, import_esbuild_plugin_cedar_otel_wrapping.applyOtelWrapping)(code2, id, cedarPaths.api.src) ?? code2;
|
|
220
228
|
}
|
|
229
|
+
if (isEsm) {
|
|
230
|
+
code2 = (0, import_esm_extensions.applyEsmExtensions)(code2, id);
|
|
231
|
+
}
|
|
221
232
|
const functionsDir = (0, import_vite.normalizePath)(cedarPaths.api.functions);
|
|
222
233
|
if (normalizedId.startsWith(functionsDir + "/")) {
|
|
223
234
|
code2 = (0, import_esbuild_plugin_handler_als_wrapping.applyHandlerAlsWrapping)(code2, {
|
|
@@ -356,6 +367,8 @@ function getEsbuildOptions(files) {
|
|
|
356
367
|
}
|
|
357
368
|
// Annotate the CommonJS export names for ESM import in node:
|
|
358
369
|
0 && (module.exports = {
|
|
370
|
+
applyEsmExtensions,
|
|
371
|
+
applySrcAlias,
|
|
359
372
|
buildApi,
|
|
360
373
|
buildApiWithVite,
|
|
361
374
|
cleanApiBuild,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"esbuild-plugin-api-graphql.d.ts","sourceRoot":"","sources":["../../../src/build/esbuild-plugin-api-graphql.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"esbuild-plugin-api-graphql.d.ts","sourceRoot":"","sources":["../../../src/build/esbuild-plugin-api-graphql.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAqB1C,eAAO,MAAM,qBAAqB;;iBAEnB,WAAW;CAmGzB,CAAA"}
|
|
@@ -40,6 +40,7 @@ var import_auto_import = require("./auto-import.js");
|
|
|
40
40
|
var import_directory_named_import = require("./directory-named-import.js");
|
|
41
41
|
var import_esbuild_plugin_cedar_otel_wrapping = require("./esbuild-plugin-cedar-otel-wrapping.js");
|
|
42
42
|
var import_esbuild_plugin_handler_als_wrapping = require("./esbuild-plugin-handler-als-wrapping.js");
|
|
43
|
+
var import_esm_extensions = require("./esm-extensions.js");
|
|
43
44
|
var import_import_dir = require("./import-dir.js");
|
|
44
45
|
var import_src_alias = require("./src-alias.js");
|
|
45
46
|
var import_tsconfig_paths = require("./tsconfig-paths.js");
|
|
@@ -77,6 +78,9 @@ const cedarApiGraphqlPlugin = {
|
|
|
77
78
|
throw new Error(`Could not transform file: ${args.path}`);
|
|
78
79
|
}
|
|
79
80
|
let code = transformedCode.code;
|
|
81
|
+
if ((0, import_project_config.projectSideIsEsm)("api")) {
|
|
82
|
+
code = (0, import_esm_extensions.applyEsmExtensions)(code, args.path);
|
|
83
|
+
}
|
|
80
84
|
if (cedarConfig.experimental?.opentelemetry?.enabled && cedarConfig.experimental?.opentelemetry?.wrapApi) {
|
|
81
85
|
code = (0, import_esbuild_plugin_cedar_otel_wrapping.applyOtelWrapping)(code, args.path, (0, import_project_config.getPaths)().api.src) ?? code;
|
|
82
86
|
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* For ESM projects using esbuild with `bundle: false`, rewrites extensionless
|
|
3
|
+
* relative imports to include `.js` extension so that Node's ESM resolver can
|
|
4
|
+
* locate the compiled output files at runtime.
|
|
5
|
+
*
|
|
6
|
+
* Handles both static imports (`from '../lib/db'`) and dynamic imports
|
|
7
|
+
* (`import('../lib/db')`).
|
|
8
|
+
*
|
|
9
|
+
* Always outputs `.js` because esbuild with `loader: 'js'` compiles all source
|
|
10
|
+
* files (`.ts`, `.tsx`, `.jsx`) to `.js` output. For a source file `api/src/lib/db.ts`
|
|
11
|
+
* or `api/src/lib/db.tsx`, the output is always `api/dist/lib/db.js`, so all
|
|
12
|
+
* import specifiers must use `.js` at runtime.
|
|
13
|
+
*
|
|
14
|
+
* This replaces the `resolvePath` hook in `babel-plugin-module-resolver` for
|
|
15
|
+
* the standalone esbuild build path (`runCedarBabelTransformsPlugin`), which
|
|
16
|
+
* was previously responsible for this extension-appending behaviour. Vite
|
|
17
|
+
* and Rollup resolve extensions themselves during bundling; only the esbuild
|
|
18
|
+
* `bundle: false` path needs explicit extension suffixes in the source.
|
|
19
|
+
*
|
|
20
|
+
* It is a plain function called inline — not an esbuild plugin — following
|
|
21
|
+
* the same pattern as `applySrcAlias`, `applyTsconfigPaths`, etc.
|
|
22
|
+
*
|
|
23
|
+
* Also handles Cedar SDL files whose names include a compound extension:
|
|
24
|
+
* `contacts.sdl.ts` compiles to `contacts.sdl.js`, so an import specifier
|
|
25
|
+
* `../graphql/contacts.sdl` (generated by applyImportDir's glob expansion)
|
|
26
|
+
* is rewritten to `../graphql/contacts.sdl.js`.
|
|
27
|
+
*
|
|
28
|
+
* Example: in `api/src/functions/graphql.ts` importing `../lib/db`, this
|
|
29
|
+
* rewrites it to `../lib/db.js` when `api/src/lib/db.ts` (or `db.tsx`)
|
|
30
|
+
* exists on disk.
|
|
31
|
+
*/
|
|
32
|
+
export declare function applyEsmExtensions(code: string, fromFile: string): string;
|
|
33
|
+
//# sourceMappingURL=esm-extensions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"esm-extensions.d.ts","sourceRoot":"","sources":["../../../src/build/esm-extensions.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAiEzE"}
|
|
@@ -0,0 +1,71 @@
|
|
|
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 esm_extensions_exports = {};
|
|
30
|
+
__export(esm_extensions_exports, {
|
|
31
|
+
applyEsmExtensions: () => applyEsmExtensions
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(esm_extensions_exports);
|
|
34
|
+
var import_node_fs = __toESM(require("node:fs"), 1);
|
|
35
|
+
var import_node_path = __toESM(require("node:path"), 1);
|
|
36
|
+
function applyEsmExtensions(code, fromFile) {
|
|
37
|
+
const fromDir = import_node_path.default.dirname(fromFile);
|
|
38
|
+
const rewriteImportPath = (importPath, preservePrefix, preserveSuffix) => {
|
|
39
|
+
const existingExt = import_node_path.default.extname(importPath);
|
|
40
|
+
const absImport = import_node_path.default.join(fromDir, importPath);
|
|
41
|
+
if (existingExt && existingExt !== ".js" && existingExt !== ".jsx") {
|
|
42
|
+
if (import_node_fs.default.existsSync(absImport + ".ts") || import_node_fs.default.existsSync(absImport + ".js") || import_node_fs.default.existsSync(absImport + ".tsx") || import_node_fs.default.existsSync(absImport + ".jsx")) {
|
|
43
|
+
return preservePrefix + importPath + ".js" + preserveSuffix;
|
|
44
|
+
}
|
|
45
|
+
return preservePrefix + importPath + preserveSuffix;
|
|
46
|
+
}
|
|
47
|
+
const base = existingExt ? importPath.slice(0, -existingExt.length) : importPath;
|
|
48
|
+
const absBase = import_node_path.default.join(fromDir, base);
|
|
49
|
+
if (import_node_fs.default.existsSync(absBase + ".ts") || import_node_fs.default.existsSync(absBase + ".js") || import_node_fs.default.existsSync(absBase + ".tsx") || import_node_fs.default.existsSync(absBase + ".jsx")) {
|
|
50
|
+
return preservePrefix + base + ".js" + preserveSuffix;
|
|
51
|
+
}
|
|
52
|
+
return preservePrefix + importPath + preserveSuffix;
|
|
53
|
+
};
|
|
54
|
+
let result = code.replace(
|
|
55
|
+
/\bfrom\s+(['"])(\.\.?\/[^'"]+)\1/g,
|
|
56
|
+
(match, quote, importPath) => {
|
|
57
|
+
return `from ${rewriteImportPath(importPath, quote, quote)}`;
|
|
58
|
+
}
|
|
59
|
+
);
|
|
60
|
+
result = result.replace(
|
|
61
|
+
/\bimport\s*\(\s*(['"])(\.\.?\/[^'"]+)\1\s*\)/g,
|
|
62
|
+
(match, quote, importPath) => {
|
|
63
|
+
return `import(${rewriteImportPath(importPath, quote, quote)})`;
|
|
64
|
+
}
|
|
65
|
+
);
|
|
66
|
+
return result;
|
|
67
|
+
}
|
|
68
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
69
|
+
0 && (module.exports = {
|
|
70
|
+
applyEsmExtensions
|
|
71
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cedarjs/internal",
|
|
3
|
-
"version": "6.0.0-canary.
|
|
3
|
+
"version": "6.0.0-canary.2663",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/cedarjs/cedar.git",
|
|
@@ -110,6 +110,16 @@
|
|
|
110
110
|
"default": "./dist/cjs/build/api.js"
|
|
111
111
|
}
|
|
112
112
|
},
|
|
113
|
+
"./dist/build/api.js": {
|
|
114
|
+
"import": {
|
|
115
|
+
"types": "./dist/build/api.d.ts",
|
|
116
|
+
"default": "./dist/build/api.js"
|
|
117
|
+
},
|
|
118
|
+
"require": {
|
|
119
|
+
"types": "./dist/cjs/build/api.d.ts",
|
|
120
|
+
"default": "./dist/cjs/build/api.js"
|
|
121
|
+
}
|
|
122
|
+
},
|
|
113
123
|
"./dist/build/api-graphql-transforms.js": {
|
|
114
124
|
"import": {
|
|
115
125
|
"types": "./dist/build/api-graphql-transforms.d.ts",
|
|
@@ -169,13 +179,13 @@
|
|
|
169
179
|
"@babel/plugin-transform-react-jsx": "7.29.7",
|
|
170
180
|
"@babel/plugin-transform-typescript": "^7.26.8",
|
|
171
181
|
"@babel/traverse": "7.29.7",
|
|
172
|
-
"@cedarjs/babel-config": "6.0.0-canary.
|
|
173
|
-
"@cedarjs/cli-helpers": "6.0.0-canary.
|
|
174
|
-
"@cedarjs/graphql-server": "6.0.0-canary.
|
|
175
|
-
"@cedarjs/project-config": "6.0.0-canary.
|
|
176
|
-
"@cedarjs/router": "6.0.0-canary.
|
|
177
|
-
"@cedarjs/structure": "6.0.0-canary.
|
|
178
|
-
"@cedarjs/utils": "6.0.0-canary.
|
|
182
|
+
"@cedarjs/babel-config": "6.0.0-canary.2663",
|
|
183
|
+
"@cedarjs/cli-helpers": "6.0.0-canary.2663",
|
|
184
|
+
"@cedarjs/graphql-server": "6.0.0-canary.2663",
|
|
185
|
+
"@cedarjs/project-config": "6.0.0-canary.2663",
|
|
186
|
+
"@cedarjs/router": "6.0.0-canary.2663",
|
|
187
|
+
"@cedarjs/structure": "6.0.0-canary.2663",
|
|
188
|
+
"@cedarjs/utils": "6.0.0-canary.2663",
|
|
179
189
|
"@graphql-codegen/add": "6.0.1",
|
|
180
190
|
"@graphql-codegen/cli": "6.3.1",
|
|
181
191
|
"@graphql-codegen/client-preset": "5.3.0",
|
|
@@ -220,7 +230,7 @@
|
|
|
220
230
|
},
|
|
221
231
|
"devDependencies": {
|
|
222
232
|
"@arethetypeswrong/cli": "0.18.5",
|
|
223
|
-
"@cedarjs/framework-tools": "6.0.0-canary.
|
|
233
|
+
"@cedarjs/framework-tools": "6.0.0-canary.2663",
|
|
224
234
|
"concurrently": "9.2.1",
|
|
225
235
|
"graphql-tag": "2.12.6",
|
|
226
236
|
"publint": "0.3.21",
|