@isograph/babel-plugin 0.0.0-main-c328b0c0 → 0.0.0-main-89fdf4a8

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.
Files changed (2) hide show
  1. package/compileTag.js +13 -2
  2. package/package.json +1 -1
package/compileTag.js CHANGED
@@ -58,15 +58,26 @@ function compileImportStatement(t, path, type, field, artifactType, config) {
58
58
  const filename = path.state.filename;
59
59
  const folder = pathModule.dirname(filename);
60
60
  const cwd = path.state.cwd;
61
- const artifactDirectory = pathModule.join(cwd, config.artifact_directory);
61
+ const artifactDirectory = pathModule.join(
62
+ cwd,
63
+ config.artifact_directory ?? config.project_root,
64
+ );
62
65
 
63
66
  const fileToArtifactDir = pathModule.relative(folder, artifactDirectory);
64
67
  const artifactDirToArtifact = `/__isograph/${type}/${field}/${artifactType}.ts`;
65
- const fileToArtifact = pathModule.join(
68
+ let fileToArtifact = pathModule.join(
66
69
  fileToArtifactDir,
67
70
  artifactDirToArtifact,
68
71
  );
69
72
 
73
+ // If we do not have to traverse upward, e.g. if the resolver is in
74
+ // src/HomePage, and the artifact directory is src/, then fileToArtifact
75
+ // will start with a /. require('/...') is not good, as that is treated
76
+ // as an absolute path. Or something. It should instead be './...'.
77
+ if (fileToArtifact.startsWith('/')) {
78
+ fileToArtifact = '.' + fileToArtifact;
79
+ }
80
+
70
81
  path.replaceWith(
71
82
  t.memberExpression(
72
83
  t.CallExpression(t.Identifier('require'), [
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@isograph/babel-plugin",
3
3
  "description": "A Babel plugin for use with Isograph applications.",
4
- "version": "0.0.0-main-c328b0c0",
4
+ "version": "0.0.0-main-89fdf4a8",
5
5
  "keywords": [
6
6
  "graphql",
7
7
  "isograph",