@graphql-codegen/cli 3.2.2-alpha-20230301201322-189cfbbc9 → 3.2.2-alpha-20230302095206-b34166c23

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/cjs/config.js CHANGED
@@ -56,15 +56,21 @@ function customLoader(ext) {
56
56
  return tsLoader(filepath, content);
57
57
  }
58
58
  catch (err) {
59
- if (typeof err.stack === 'string' && err.stack.startsWith('Error [ERR_REQUIRE_ESM]:')) {
59
+ if (isRequireESMError(err)) {
60
60
  const hash = hashContent(content, 'base64url');
61
61
  const tempDir = (0, file_system_js_1.getTempDir)();
62
- // TODO
63
62
  let inTempDir = [];
64
63
  try {
65
64
  inTempDir = await fs_1.promises.readdir(tempDir);
66
65
  }
67
- catch (err) { }
66
+ catch (err) {
67
+ if (err.code === 'ENOENT') {
68
+ // tsc will create the directory if it doesn't exist.
69
+ }
70
+ else {
71
+ throw err;
72
+ }
73
+ }
68
74
  let outDir = (0, path_1.join)(tempDir, new Date().getTime() + '-' + hash);
69
75
  const previousOutDir = inTempDir.find(s => s.endsWith(hash));
70
76
  if (previousOutDir) {
@@ -72,7 +78,7 @@ function customLoader(ext) {
72
78
  }
73
79
  else {
74
80
  // We're compiling the file, because ts-node doesn't work perfectly with ESM.
75
- (0, child_process_1.execSync)(`tsc ${filepath} --module commonjs --outDir ${outDir}`, { stdio: 'pipe' });
81
+ (0, child_process_1.execSync)(`tsc ${filepath} --module commonjs --outDir ${outDir} --skipLibCheck`);
76
82
  }
77
83
  const newPath = (0, path_1.join)(outDir, (0, path_1.basename)(filepath).replace(/\.ts$/, '.js'));
78
84
  const config = (_a = newPath, Promise.resolve().then(() => tslib_1.__importStar(require(_a)))).then(m => {
@@ -80,14 +86,7 @@ function customLoader(ext) {
80
86
  return 'default' in config ? config.default : config;
81
87
  });
82
88
  // If the cache has more than 10 files, we delete the oldest one.
83
- if (inTempDir.length > 10) {
84
- const oldest = inTempDir.sort((a, b) => {
85
- const aTime = Number(a.split('-')[0]);
86
- const bTime = Number(b.split('-')[0]);
87
- return aTime - bTime;
88
- })[0];
89
- await rm((0, path_1.join)(tempDir, oldest), { recursive: true, force: true });
90
- }
89
+ await removeOldestDirInCache(inTempDir, tempDir, 10);
91
90
  return config;
92
91
  }
93
92
  throw err;
@@ -122,7 +121,7 @@ async function loadContext(configFilePath) {
122
121
  graphqlConfig = await (0, graphql_config_js_1.findAndLoadGraphQLConfig)(configFilePath);
123
122
  }
124
123
  catch (err) {
125
- if (typeof err.stack === 'string' && err.stack.startsWith('Error [ERR_REQUIRE_ESM]:')) {
124
+ if (isRequireESMError(err)) {
126
125
  // TODO: This needs a fix in graphql-config
127
126
  }
128
127
  else {
@@ -408,3 +407,16 @@ function shouldEmitLegacyCommonJSImports(config) {
408
407
  return globalValue;
409
408
  }
410
409
  exports.shouldEmitLegacyCommonJSImports = shouldEmitLegacyCommonJSImports;
410
+ async function removeOldestDirInCache(inTempDir, tempDir, cacheLimit) {
411
+ if (inTempDir.length > cacheLimit) {
412
+ const oldest = inTempDir.sort((a, b) => {
413
+ const aTime = Number(a.split('-')[0]);
414
+ const bTime = Number(b.split('-')[0]);
415
+ return aTime - bTime;
416
+ })[0];
417
+ await rm((0, path_1.join)(tempDir, oldest), { recursive: true, force: true });
418
+ }
419
+ }
420
+ function isRequireESMError(err) {
421
+ return typeof err.stack === 'string' && err.stack.startsWith('Error [ERR_REQUIRE_ESM]:');
422
+ }
package/esm/config.js CHANGED
@@ -50,15 +50,21 @@ function customLoader(ext) {
50
50
  return tsLoader(filepath, content);
51
51
  }
52
52
  catch (err) {
53
- if (typeof err.stack === 'string' && err.stack.startsWith('Error [ERR_REQUIRE_ESM]:')) {
53
+ if (isRequireESMError(err)) {
54
54
  const hash = hashContent(content, 'base64url');
55
55
  const tempDir = getTempDir();
56
- // TODO
57
56
  let inTempDir = [];
58
57
  try {
59
58
  inTempDir = await promises.readdir(tempDir);
60
59
  }
61
- catch (err) { }
60
+ catch (err) {
61
+ if (err.code === 'ENOENT') {
62
+ // tsc will create the directory if it doesn't exist.
63
+ }
64
+ else {
65
+ throw err;
66
+ }
67
+ }
62
68
  let outDir = join(tempDir, new Date().getTime() + '-' + hash);
63
69
  const previousOutDir = inTempDir.find(s => s.endsWith(hash));
64
70
  if (previousOutDir) {
@@ -66,7 +72,7 @@ function customLoader(ext) {
66
72
  }
67
73
  else {
68
74
  // We're compiling the file, because ts-node doesn't work perfectly with ESM.
69
- execSync(`tsc ${filepath} --module commonjs --outDir ${outDir}`, { stdio: 'pipe' });
75
+ execSync(`tsc ${filepath} --module commonjs --outDir ${outDir} --skipLibCheck`);
70
76
  }
71
77
  const newPath = join(outDir, basename(filepath).replace(/\.ts$/, '.js'));
72
78
  const config = import(newPath).then(m => {
@@ -74,14 +80,7 @@ function customLoader(ext) {
74
80
  return 'default' in config ? config.default : config;
75
81
  });
76
82
  // If the cache has more than 10 files, we delete the oldest one.
77
- if (inTempDir.length > 10) {
78
- const oldest = inTempDir.sort((a, b) => {
79
- const aTime = Number(a.split('-')[0]);
80
- const bTime = Number(b.split('-')[0]);
81
- return aTime - bTime;
82
- })[0];
83
- await rm(join(tempDir, oldest), { recursive: true, force: true });
84
- }
83
+ await removeOldestDirInCache(inTempDir, tempDir, 10);
85
84
  return config;
86
85
  }
87
86
  throw err;
@@ -115,7 +114,7 @@ export async function loadContext(configFilePath) {
115
114
  graphqlConfig = await findAndLoadGraphQLConfig(configFilePath);
116
115
  }
117
116
  catch (err) {
118
- if (typeof err.stack === 'string' && err.stack.startsWith('Error [ERR_REQUIRE_ESM]:')) {
117
+ if (isRequireESMError(err)) {
119
118
  // TODO: This needs a fix in graphql-config
120
119
  }
121
120
  else {
@@ -393,3 +392,16 @@ export function shouldEmitLegacyCommonJSImports(config) {
393
392
  // }
394
393
  return globalValue;
395
394
  }
395
+ async function removeOldestDirInCache(inTempDir, tempDir, cacheLimit) {
396
+ if (inTempDir.length > cacheLimit) {
397
+ const oldest = inTempDir.sort((a, b) => {
398
+ const aTime = Number(a.split('-')[0]);
399
+ const bTime = Number(b.split('-')[0]);
400
+ return aTime - bTime;
401
+ })[0];
402
+ await rm(join(tempDir, oldest), { recursive: true, force: true });
403
+ }
404
+ }
405
+ function isRequireESMError(err) {
406
+ return typeof err.stack === 'string' && err.stack.startsWith('Error [ERR_REQUIRE_ESM]:');
407
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-codegen/cli",
3
- "version": "3.2.2-alpha-20230301201322-189cfbbc9",
3
+ "version": "3.2.2-alpha-20230302095206-b34166c23",
4
4
  "peerDependencies": {
5
5
  "graphql": "^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0",
6
6
  "typescript": ">=3.0"