graphile-config
Advanced tools
Comparing version
# graphile-config | ||
## 0.0.1-beta.17 | ||
### Patch Changes | ||
- [#2577](https://github.com/graphile/crystal/pull/2577) | ||
[`0c6b1f1`](https://github.com/graphile/crystal/commit/0c6b1f1e188f6e2913832adfed9ca76dfdc25c47) | ||
Thanks [@benjie](https://github.com/benjie)! - Update dependencies | ||
- [#2588](https://github.com/graphile/crystal/pull/2588) | ||
[`e0cdabe`](https://github.com/graphile/crystal/commit/e0cdabe25c8894da550546c93bc03b895585544c) | ||
Thanks [@benjie](https://github.com/benjie)! - Add support for | ||
`--experimental-strip-types` to `graphile-config`'s loading of config files. | ||
No need for `ts-node`/`tsx` now. | ||
## 0.0.1-beta.16 | ||
@@ -4,0 +18,0 @@ |
@@ -63,2 +63,50 @@ "use strict"; | ||
} | ||
function isESMError(e) { | ||
return (typeof e === "object" && | ||
e != null && | ||
"code" in e && | ||
(e.code === "ERR_REQUIRE_ESM" || e.code === "ERR_REQUIRE_ASYNC_MODULE")); | ||
} | ||
async function loadDefaultExport(resolvedPath, extension) { | ||
// Attempt to import using native TypeScript support if appropriate | ||
if (process.features.typescript && /\.[cm]?tsx?$/.test(extension)) { | ||
try { | ||
// Node has `require(esm)` support, but also for a `.cjsx` file it should | ||
// still use `require()` | ||
return fixESMShenanigans(require(resolvedPath)); | ||
} | ||
catch (e) { | ||
if (isESMError(e)) { | ||
// This is the most likely result, since TypeScript uses ESM syntax. | ||
try { | ||
return (await import((0, node_url_1.pathToFileURL)(resolvedPath).href)).default; | ||
} | ||
catch { | ||
// Nevermind; try a loader | ||
} | ||
} | ||
// Nevermind; try a loader | ||
} | ||
} | ||
// No luck? Let's try loading the loaders | ||
try { | ||
registerLoader(interpret_1.jsVariants[extension]); | ||
} | ||
catch (e) { | ||
console.error(`No loader could be loaded for ${extension} files: ${e}`); | ||
} | ||
// And now lets attempt to import | ||
try { | ||
return fixESMShenanigans(require(resolvedPath)); | ||
} | ||
catch (e) { | ||
if (isESMError(e)) { | ||
// It's an ESModule, so `require()` won't work. Let's use `import()`! | ||
return (await import((0, node_url_1.pathToFileURL)(resolvedPath).href)).default; | ||
} | ||
else { | ||
throw e; | ||
} | ||
} | ||
} | ||
async function loadConfig(configPath) { | ||
@@ -68,11 +116,11 @@ if (configPath != null) { | ||
const resolvedPath = (0, node_path_1.resolve)(process.cwd(), configPath); | ||
// First try one of the supported loaders | ||
// First try one of the supported loaders. | ||
for (const extension of extensions) { | ||
if (resolvedPath.endsWith(extension)) { | ||
registerLoader(interpret_1.jsVariants[extension]); | ||
try { | ||
return fixESMShenanigans(require(resolvedPath)); | ||
return await loadDefaultExport(resolvedPath, extension); | ||
} | ||
catch { | ||
/* continue to the next one */ | ||
// Multiple extensions might match - e.g. both `.swc.tsx` and `.tsx`; | ||
// continue to the next one. | ||
} | ||
@@ -90,13 +138,9 @@ } | ||
if (await exists(resolvedPath)) { | ||
registerLoader(interpret_1.jsVariants[extension]); | ||
// This file exists; whatever happens, we will try this file only. | ||
try { | ||
return fixESMShenanigans(require(resolvedPath)); | ||
return await loadDefaultExport(resolvedPath, extension); | ||
} | ||
catch (e) { | ||
if (e.code === "ERR_REQUIRE_ESM") { | ||
return (await import((0, node_url_1.pathToFileURL)(resolvedPath).href)).default; | ||
} | ||
else { | ||
throw e; | ||
} | ||
catch { | ||
// Fallback to direct import | ||
return (await import((0, node_url_1.pathToFileURL)(resolvedPath).href)).default; | ||
} | ||
@@ -103,0 +147,0 @@ } |
{ | ||
"name": "graphile-config", | ||
"version": "0.0.1-beta.16", | ||
"version": "0.0.1-beta.17", | ||
"description": "Standard plugin interface and helpers to be used across the Graphile stack.", | ||
@@ -42,9 +42,9 @@ "type": "commonjs", | ||
"dependencies": { | ||
"@types/interpret": "^1.1.1", | ||
"@types/node": "^20.17.30", | ||
"@types/semver": "^7.5.1", | ||
"@types/interpret": "^1.1.3", | ||
"@types/node": "^22.15.32", | ||
"@types/semver": "^7.7.0", | ||
"chalk": "^4.1.2", | ||
"debug": "^4.3.4", | ||
"debug": "^4.4.1", | ||
"interpret": "^3.1.1", | ||
"semver": "^7.5.4", | ||
"semver": "^7.7.2", | ||
"tslib": "^2.8.1", | ||
@@ -60,9 +60,9 @@ "yargs": "^17.7.2" | ||
"devDependencies": { | ||
"@types/debug": "^4.1.8", | ||
"@types/mocha": "^10.0.1", | ||
"chai": "^4.3.8", | ||
"mocha": "^10.2.0", | ||
"ts-node": "^10.9.1", | ||
"@types/debug": "^4.1.12", | ||
"@types/mocha": "^10.0.10", | ||
"chai": "^5.2.0", | ||
"mocha": "^11.6.0", | ||
"ts-node": "^10.9.2", | ||
"typescript": "^5.8.3" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
99681
3.39%923
5.01%+ Added
- Removed
Updated
Updated
Updated
Updated
Updated