@cedarjs/internal 6.0.0-canary.2641 → 6.0.0-canary.2644
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.map +1 -1
- package/dist/build/api.js +26 -1
- package/dist/build/esbuild-plugin-api-graphql.d.ts.map +1 -1
- package/dist/build/esbuild-plugin-api-graphql.js +2 -0
- package/dist/build/import-dir.d.ts +22 -0
- package/dist/build/import-dir.d.ts.map +1 -0
- package/dist/build/import-dir.js +54 -0
- package/dist/cjs/build/api.d.ts.map +1 -1
- package/dist/cjs/build/api.js +26 -1
- package/dist/cjs/build/esbuild-plugin-api-graphql.d.ts.map +1 -1
- package/dist/cjs/build/esbuild-plugin-api-graphql.js +2 -0
- package/dist/cjs/build/import-dir.d.ts +22 -0
- package/dist/cjs/build/import-dir.d.ts.map +1 -0
- package/dist/cjs/build/import-dir.js +88 -0
- package/package.json +10 -9
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;AA0BtE,eAAO,MAAM,QAAQ,4DAIpB,CAAA;AAED,eAAO,MAAM,UAAU,4DAStB,CAAA;AAED,eAAO,MAAM,aAAa,qBAGzB,CAAA;AAkMD,eAAO,MAAM,gBAAgB,iHAyD5B,CAAA;AAcD,wBAAsB,aAAa,CACjC,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,IAAI,CAAC,CAoDf"}
|
package/dist/build/api.js
CHANGED
|
@@ -16,6 +16,7 @@ import { applyAutoImports } from "./auto-import.js";
|
|
|
16
16
|
import { cedarApiGraphqlPlugin } from "./esbuild-plugin-api-graphql.js";
|
|
17
17
|
import { applyOtelWrapping } from "./esbuild-plugin-cedar-otel-wrapping.js";
|
|
18
18
|
import { applyHandlerAlsWrapping } from "./esbuild-plugin-handler-als-wrapping.js";
|
|
19
|
+
import { applyImportDir } from "./import-dir.js";
|
|
19
20
|
import { applySrcAlias } from "./src-alias.js";
|
|
20
21
|
let BUILD_CTX = null;
|
|
21
22
|
const buildApi = async () => {
|
|
@@ -49,6 +50,7 @@ const runCedarBabelTransformsPlugin = {
|
|
|
49
50
|
)
|
|
50
51
|
);
|
|
51
52
|
fileContents = applyAutoImports(fileContents);
|
|
53
|
+
fileContents = applyImportDir(fileContents, args.path)?.code ?? fileContents;
|
|
52
54
|
const transformedCode = await transformWithBabel(
|
|
53
55
|
fileContents,
|
|
54
56
|
args.path,
|
|
@@ -80,6 +82,25 @@ const runCedarBabelTransformsPlugin = {
|
|
|
80
82
|
});
|
|
81
83
|
}
|
|
82
84
|
};
|
|
85
|
+
function createImportDirVitePlugin() {
|
|
86
|
+
return {
|
|
87
|
+
name: "cedar-internal-import-dir",
|
|
88
|
+
enforce: "pre",
|
|
89
|
+
transform(code, id) {
|
|
90
|
+
if (!/\.(js|ts|tsx|jsx)$/.test(id)) {
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
if (id.includes("node_modules")) {
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
const result = applyImportDir(code, id);
|
|
97
|
+
if (!result) {
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
return { code: result.code, map: result.map };
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
}
|
|
83
104
|
function createCedarViteApiPlugin() {
|
|
84
105
|
const cedarConfig = getConfig();
|
|
85
106
|
const isEsm = projectSideIsEsm("api");
|
|
@@ -177,7 +198,11 @@ const buildApiWithVite = async () => {
|
|
|
177
198
|
}
|
|
178
199
|
}
|
|
179
200
|
},
|
|
180
|
-
|
|
201
|
+
// cedarImportDirPlugin must run before the Babel transform so glob imports
|
|
202
|
+
// are expanded before Babel sees the code. The Babel import-dir plugin is
|
|
203
|
+
// disabled for forVite:true builds; this inline Vite plugin is its
|
|
204
|
+
// replacement for this code path (both CJS and ESM output via Rollup).
|
|
205
|
+
plugins: [createImportDirVitePlugin(), createCedarViteApiPlugin()]
|
|
181
206
|
});
|
|
182
207
|
};
|
|
183
208
|
const transpileApi = async (files) => {
|
|
@@ -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;AAkB1C,eAAO,MAAM,qBAAqB;;iBAEnB,WAAW;CA4EzB,CAAA"}
|
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
import { applyAutoImports } from "./auto-import.js";
|
|
13
13
|
import { applyOtelWrapping } from "./esbuild-plugin-cedar-otel-wrapping.js";
|
|
14
14
|
import { applyHandlerAlsWrapping } from "./esbuild-plugin-handler-als-wrapping.js";
|
|
15
|
+
import { applyImportDir } from "./import-dir.js";
|
|
15
16
|
import { applySrcAlias } from "./src-alias.js";
|
|
16
17
|
const cedarApiGraphqlPlugin = {
|
|
17
18
|
name: "cedar-api-graphql",
|
|
@@ -28,6 +29,7 @@ const cedarApiGraphqlPlugin = {
|
|
|
28
29
|
fileContents = applyGraphqlOptionsExtract(fileContents) ?? fileContents;
|
|
29
30
|
fileContents = applyGqlormInject(fileContents, args.path, ".js") ?? fileContents;
|
|
30
31
|
fileContents = applyAutoImports(fileContents);
|
|
32
|
+
fileContents = applyImportDir(fileContents, args.path)?.code ?? fileContents;
|
|
31
33
|
const transformedCode = await transformWithBabel(
|
|
32
34
|
fileContents,
|
|
33
35
|
args.path,
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { SourceMap } from 'magic-string';
|
|
2
|
+
/**
|
|
3
|
+
* Expands glob directory imports such as:
|
|
4
|
+
* import services from 'src/services/**\/*.{js,ts}'
|
|
5
|
+
* into individual namespace imports:
|
|
6
|
+
* let services = {}
|
|
7
|
+
* import * as services_a from 'src/services/a'
|
|
8
|
+
* services.a = services_a
|
|
9
|
+
*
|
|
10
|
+
* This is the esbuild-path equivalent of:
|
|
11
|
+
* - babel-plugin-redwood-import-dir (kept for Jest / console / data-migrate)
|
|
12
|
+
* - cedarImportDirPlugin (Vite plugin, for Vite build paths)
|
|
13
|
+
*
|
|
14
|
+
* Code duplication between the two non-Babel plugins is intentional.
|
|
15
|
+
*
|
|
16
|
+
* Returns the transformed source code, or null if no glob imports were found.
|
|
17
|
+
*/
|
|
18
|
+
export declare function applyImportDir(code: string, filePath: string): {
|
|
19
|
+
code: string;
|
|
20
|
+
map?: SourceMap;
|
|
21
|
+
} | null;
|
|
22
|
+
//# sourceMappingURL=import-dir.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"import-dir.d.ts","sourceRoot":"","sources":["../../src/build/import-dir.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAI7C;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,cAAc,CAC5B,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,GACf;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,SAAS,CAAA;CAAE,GAAG,IAAI,CAyE1C"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import MagicString from "magic-string";
|
|
4
|
+
import { getPaths, importStatementPath } from "@cedarjs/project-config";
|
|
5
|
+
function applyImportDir(code, filePath) {
|
|
6
|
+
if (!code.includes("**")) {
|
|
7
|
+
return null;
|
|
8
|
+
}
|
|
9
|
+
const GLOB_IMPORT_RE = /^import\s+(\w+)\s+from\s+['"]([^'"]+)['"]\s*;?/gm;
|
|
10
|
+
const s = new MagicString(code);
|
|
11
|
+
let hasTransformations = false;
|
|
12
|
+
for (const match of code.matchAll(GLOB_IMPORT_RE)) {
|
|
13
|
+
const importName = match[1];
|
|
14
|
+
const sourceValue = match[2];
|
|
15
|
+
if (!sourceValue.includes("**")) {
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
18
|
+
const importGlob = importStatementPath(sourceValue);
|
|
19
|
+
const cwd = importGlob.startsWith("src/") ? getPaths().api.base : path.dirname(filePath);
|
|
20
|
+
let dirFiles;
|
|
21
|
+
try {
|
|
22
|
+
dirFiles = fs.globSync(importGlob, {
|
|
23
|
+
cwd,
|
|
24
|
+
exclude: (n) => n.includes(".test.") || n.includes(".scenarios.") || n.includes(".d.ts")
|
|
25
|
+
});
|
|
26
|
+
} catch {
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
const staticGlob = importGlob.split("*")[0];
|
|
30
|
+
const filePathToVarName = (fp) => fp.replace(staticGlob, "").replace(/\.(js|ts)$/, "").replace(/[^a-zA-Z0-9]/g, "_");
|
|
31
|
+
hasTransformations = true;
|
|
32
|
+
let replacement = `let ${importName} = {};
|
|
33
|
+
`;
|
|
34
|
+
for (const fp of dirFiles) {
|
|
35
|
+
const { dir: fileDir, name: fileName } = path.parse(fp);
|
|
36
|
+
const normalizedDir = importStatementPath(fileDir);
|
|
37
|
+
const varName = filePathToVarName(fp);
|
|
38
|
+
const nsImport = `${importName}_${varName}`;
|
|
39
|
+
replacement += `import * as ${nsImport} from '${normalizedDir}/${fileName}';
|
|
40
|
+
`;
|
|
41
|
+
replacement += `${importName}.${varName} = ${nsImport};
|
|
42
|
+
`;
|
|
43
|
+
}
|
|
44
|
+
s.overwrite(
|
|
45
|
+
match.index,
|
|
46
|
+
match.index + match[0].length,
|
|
47
|
+
replacement.trimEnd()
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
return hasTransformations ? { code: s.toString(), map: s.generateMap({ hires: true }) } : null;
|
|
51
|
+
}
|
|
52
|
+
export {
|
|
53
|
+
applyImportDir
|
|
54
|
+
};
|
|
@@ -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;AA0BtE,eAAO,MAAM,QAAQ,4DAIpB,CAAA;AAED,eAAO,MAAM,UAAU,4DAStB,CAAA;AAED,eAAO,MAAM,aAAa,qBAGzB,CAAA;AAkMD,eAAO,MAAM,gBAAgB,iHAyD5B,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
|
@@ -47,6 +47,7 @@ var import_auto_import = require("./auto-import.js");
|
|
|
47
47
|
var import_esbuild_plugin_api_graphql = require("./esbuild-plugin-api-graphql.js");
|
|
48
48
|
var import_esbuild_plugin_cedar_otel_wrapping = require("./esbuild-plugin-cedar-otel-wrapping.js");
|
|
49
49
|
var import_esbuild_plugin_handler_als_wrapping = require("./esbuild-plugin-handler-als-wrapping.js");
|
|
50
|
+
var import_import_dir = require("./import-dir.js");
|
|
50
51
|
var import_src_alias = require("./src-alias.js");
|
|
51
52
|
let BUILD_CTX = null;
|
|
52
53
|
const buildApi = async () => {
|
|
@@ -80,6 +81,7 @@ const runCedarBabelTransformsPlugin = {
|
|
|
80
81
|
)
|
|
81
82
|
);
|
|
82
83
|
fileContents = (0, import_auto_import.applyAutoImports)(fileContents);
|
|
84
|
+
fileContents = (0, import_import_dir.applyImportDir)(fileContents, args.path)?.code ?? fileContents;
|
|
83
85
|
const transformedCode = await (0, import_babel_config.transformWithBabel)(
|
|
84
86
|
fileContents,
|
|
85
87
|
args.path,
|
|
@@ -111,6 +113,25 @@ const runCedarBabelTransformsPlugin = {
|
|
|
111
113
|
});
|
|
112
114
|
}
|
|
113
115
|
};
|
|
116
|
+
function createImportDirVitePlugin() {
|
|
117
|
+
return {
|
|
118
|
+
name: "cedar-internal-import-dir",
|
|
119
|
+
enforce: "pre",
|
|
120
|
+
transform(code, id) {
|
|
121
|
+
if (!/\.(js|ts|tsx|jsx)$/.test(id)) {
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
if (id.includes("node_modules")) {
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
const result = (0, import_import_dir.applyImportDir)(code, id);
|
|
128
|
+
if (!result) {
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
return { code: result.code, map: result.map };
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
}
|
|
114
135
|
function createCedarViteApiPlugin() {
|
|
115
136
|
const cedarConfig = (0, import_project_config.getConfig)();
|
|
116
137
|
const isEsm = (0, import_project_config.projectSideIsEsm)("api");
|
|
@@ -208,7 +229,11 @@ const buildApiWithVite = async () => {
|
|
|
208
229
|
}
|
|
209
230
|
}
|
|
210
231
|
},
|
|
211
|
-
|
|
232
|
+
// cedarImportDirPlugin must run before the Babel transform so glob imports
|
|
233
|
+
// are expanded before Babel sees the code. The Babel import-dir plugin is
|
|
234
|
+
// disabled for forVite:true builds; this inline Vite plugin is its
|
|
235
|
+
// replacement for this code path (both CJS and ESM output via Rollup).
|
|
236
|
+
plugins: [createImportDirVitePlugin(), createCedarViteApiPlugin()]
|
|
212
237
|
});
|
|
213
238
|
};
|
|
214
239
|
const transpileApi = async (files) => {
|
|
@@ -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;AAkB1C,eAAO,MAAM,qBAAqB;;iBAEnB,WAAW;CA4EzB,CAAA"}
|
|
@@ -39,6 +39,7 @@ var import_api_graphql_transforms = require("./api-graphql-transforms.js");
|
|
|
39
39
|
var import_auto_import = require("./auto-import.js");
|
|
40
40
|
var import_esbuild_plugin_cedar_otel_wrapping = require("./esbuild-plugin-cedar-otel-wrapping.js");
|
|
41
41
|
var import_esbuild_plugin_handler_als_wrapping = require("./esbuild-plugin-handler-als-wrapping.js");
|
|
42
|
+
var import_import_dir = require("./import-dir.js");
|
|
42
43
|
var import_src_alias = require("./src-alias.js");
|
|
43
44
|
const cedarApiGraphqlPlugin = {
|
|
44
45
|
name: "cedar-api-graphql",
|
|
@@ -55,6 +56,7 @@ const cedarApiGraphqlPlugin = {
|
|
|
55
56
|
fileContents = (0, import_api_graphql_transforms.applyGraphqlOptionsExtract)(fileContents) ?? fileContents;
|
|
56
57
|
fileContents = (0, import_api_graphql_transforms.applyGqlormInject)(fileContents, args.path, ".js") ?? fileContents;
|
|
57
58
|
fileContents = (0, import_auto_import.applyAutoImports)(fileContents);
|
|
59
|
+
fileContents = (0, import_import_dir.applyImportDir)(fileContents, args.path)?.code ?? fileContents;
|
|
58
60
|
const transformedCode = await (0, import_babel_config.transformWithBabel)(
|
|
59
61
|
fileContents,
|
|
60
62
|
args.path,
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { SourceMap } from 'magic-string';
|
|
2
|
+
/**
|
|
3
|
+
* Expands glob directory imports such as:
|
|
4
|
+
* import services from 'src/services/**\/*.{js,ts}'
|
|
5
|
+
* into individual namespace imports:
|
|
6
|
+
* let services = {}
|
|
7
|
+
* import * as services_a from 'src/services/a'
|
|
8
|
+
* services.a = services_a
|
|
9
|
+
*
|
|
10
|
+
* This is the esbuild-path equivalent of:
|
|
11
|
+
* - babel-plugin-redwood-import-dir (kept for Jest / console / data-migrate)
|
|
12
|
+
* - cedarImportDirPlugin (Vite plugin, for Vite build paths)
|
|
13
|
+
*
|
|
14
|
+
* Code duplication between the two non-Babel plugins is intentional.
|
|
15
|
+
*
|
|
16
|
+
* Returns the transformed source code, or null if no glob imports were found.
|
|
17
|
+
*/
|
|
18
|
+
export declare function applyImportDir(code: string, filePath: string): {
|
|
19
|
+
code: string;
|
|
20
|
+
map?: SourceMap;
|
|
21
|
+
} | null;
|
|
22
|
+
//# sourceMappingURL=import-dir.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"import-dir.d.ts","sourceRoot":"","sources":["../../../src/build/import-dir.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAI7C;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,cAAc,CAC5B,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,GACf;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,SAAS,CAAA;CAAE,GAAG,IAAI,CAyE1C"}
|
|
@@ -0,0 +1,88 @@
|
|
|
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 import_dir_exports = {};
|
|
30
|
+
__export(import_dir_exports, {
|
|
31
|
+
applyImportDir: () => applyImportDir
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(import_dir_exports);
|
|
34
|
+
var import_node_fs = __toESM(require("node:fs"), 1);
|
|
35
|
+
var import_node_path = __toESM(require("node:path"), 1);
|
|
36
|
+
var import_magic_string = __toESM(require("magic-string"), 1);
|
|
37
|
+
var import_project_config = require("@cedarjs/project-config");
|
|
38
|
+
function applyImportDir(code, filePath) {
|
|
39
|
+
if (!code.includes("**")) {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
const GLOB_IMPORT_RE = /^import\s+(\w+)\s+from\s+['"]([^'"]+)['"]\s*;?/gm;
|
|
43
|
+
const s = new import_magic_string.default(code);
|
|
44
|
+
let hasTransformations = false;
|
|
45
|
+
for (const match of code.matchAll(GLOB_IMPORT_RE)) {
|
|
46
|
+
const importName = match[1];
|
|
47
|
+
const sourceValue = match[2];
|
|
48
|
+
if (!sourceValue.includes("**")) {
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
const importGlob = (0, import_project_config.importStatementPath)(sourceValue);
|
|
52
|
+
const cwd = importGlob.startsWith("src/") ? (0, import_project_config.getPaths)().api.base : import_node_path.default.dirname(filePath);
|
|
53
|
+
let dirFiles;
|
|
54
|
+
try {
|
|
55
|
+
dirFiles = import_node_fs.default.globSync(importGlob, {
|
|
56
|
+
cwd,
|
|
57
|
+
exclude: (n) => n.includes(".test.") || n.includes(".scenarios.") || n.includes(".d.ts")
|
|
58
|
+
});
|
|
59
|
+
} catch {
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
const staticGlob = importGlob.split("*")[0];
|
|
63
|
+
const filePathToVarName = (fp) => fp.replace(staticGlob, "").replace(/\.(js|ts)$/, "").replace(/[^a-zA-Z0-9]/g, "_");
|
|
64
|
+
hasTransformations = true;
|
|
65
|
+
let replacement = `let ${importName} = {};
|
|
66
|
+
`;
|
|
67
|
+
for (const fp of dirFiles) {
|
|
68
|
+
const { dir: fileDir, name: fileName } = import_node_path.default.parse(fp);
|
|
69
|
+
const normalizedDir = (0, import_project_config.importStatementPath)(fileDir);
|
|
70
|
+
const varName = filePathToVarName(fp);
|
|
71
|
+
const nsImport = `${importName}_${varName}`;
|
|
72
|
+
replacement += `import * as ${nsImport} from '${normalizedDir}/${fileName}';
|
|
73
|
+
`;
|
|
74
|
+
replacement += `${importName}.${varName} = ${nsImport};
|
|
75
|
+
`;
|
|
76
|
+
}
|
|
77
|
+
s.overwrite(
|
|
78
|
+
match.index,
|
|
79
|
+
match.index + match[0].length,
|
|
80
|
+
replacement.trimEnd()
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
return hasTransformations ? { code: s.toString(), map: s.generateMap({ hires: true }) } : null;
|
|
84
|
+
}
|
|
85
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
86
|
+
0 && (module.exports = {
|
|
87
|
+
applyImportDir
|
|
88
|
+
});
|
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.2644",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/cedarjs/cedar.git",
|
|
@@ -169,13 +169,13 @@
|
|
|
169
169
|
"@babel/plugin-transform-react-jsx": "7.29.7",
|
|
170
170
|
"@babel/plugin-transform-typescript": "^7.26.8",
|
|
171
171
|
"@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.
|
|
172
|
+
"@cedarjs/babel-config": "6.0.0-canary.2644",
|
|
173
|
+
"@cedarjs/cli-helpers": "6.0.0-canary.2644",
|
|
174
|
+
"@cedarjs/graphql-server": "6.0.0-canary.2644",
|
|
175
|
+
"@cedarjs/project-config": "6.0.0-canary.2644",
|
|
176
|
+
"@cedarjs/router": "6.0.0-canary.2644",
|
|
177
|
+
"@cedarjs/structure": "6.0.0-canary.2644",
|
|
178
|
+
"@cedarjs/utils": "6.0.0-canary.2644",
|
|
179
179
|
"@graphql-codegen/add": "6.0.1",
|
|
180
180
|
"@graphql-codegen/cli": "6.3.1",
|
|
181
181
|
"@graphql-codegen/client-preset": "5.3.0",
|
|
@@ -204,6 +204,7 @@
|
|
|
204
204
|
"fast-glob": "3.3.3",
|
|
205
205
|
"graphql": "16.14.2",
|
|
206
206
|
"kill-port": "1.6.1",
|
|
207
|
+
"magic-string": "0.30.21",
|
|
207
208
|
"oxc-parser": "0.137.0",
|
|
208
209
|
"prettier": "3.8.4",
|
|
209
210
|
"rimraf": "6.1.3",
|
|
@@ -217,7 +218,7 @@
|
|
|
217
218
|
},
|
|
218
219
|
"devDependencies": {
|
|
219
220
|
"@arethetypeswrong/cli": "0.18.5",
|
|
220
|
-
"@cedarjs/framework-tools": "6.0.0-canary.
|
|
221
|
+
"@cedarjs/framework-tools": "6.0.0-canary.2644",
|
|
221
222
|
"concurrently": "9.2.1",
|
|
222
223
|
"graphql-tag": "2.12.6",
|
|
223
224
|
"publint": "0.3.21",
|