@isograph/babel-plugin 0.0.0-main-1cd3db6d → 0.0.0-main-2c275831
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/BabelPluginIsograph.js +8 -11
- package/compileTag.js +15 -27
- package/index.js +1 -1
- package/package.json +1 -1
package/BabelPluginIsograph.js
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
|
1
|
+
'use strict';
|
2
2
|
|
3
|
-
const compileTag = require(
|
4
|
-
const cosmiconfig = require(
|
3
|
+
const compileTag = require('./compileTag');
|
4
|
+
const cosmiconfig = require('cosmiconfig');
|
5
5
|
|
6
|
-
const configExplorer = cosmiconfig(
|
7
|
-
searchPlaces: [
|
6
|
+
const configExplorer = cosmiconfig('isograph', {
|
7
|
+
searchPlaces: ['isograph.config.json'],
|
8
8
|
loaders: {
|
9
|
-
|
9
|
+
'.json': cosmiconfig.loadJson,
|
10
10
|
},
|
11
11
|
});
|
12
12
|
|
@@ -15,17 +15,14 @@ const result = configExplorer.searchSync();
|
|
15
15
|
if (result) {
|
16
16
|
IsographConfig = result.config;
|
17
17
|
} else {
|
18
|
-
throw new Error(
|
19
|
-
"No config found. Do you have a isograph.config.json file somewhere?",
|
20
|
-
);
|
18
|
+
throw new Error('No config found. Do you have a isograph.config.json file somewhere?');
|
21
19
|
}
|
22
20
|
|
23
21
|
module.exports = function BabelPluginIsograph(context) {
|
24
22
|
const { types: t } = context;
|
25
23
|
if (!t) {
|
26
24
|
throw new Error(
|
27
|
-
'BabelPluginIsograph: Expected plugin context to include "types", but got:' +
|
28
|
-
String(context),
|
25
|
+
'BabelPluginIsograph: Expected plugin context to include "types", but got:' + String(context),
|
29
26
|
);
|
30
27
|
}
|
31
28
|
|
package/compileTag.js
CHANGED
@@ -1,39 +1,32 @@
|
|
1
|
-
|
1
|
+
'use strict';
|
2
2
|
|
3
|
-
const pathModule = require(
|
3
|
+
const pathModule = require('path');
|
4
4
|
|
5
5
|
function compileTag(t, path, config) {
|
6
|
-
const tag = path.get(
|
6
|
+
const tag = path.get('tag');
|
7
7
|
|
8
|
-
if (tag.isIdentifier({ name:
|
8
|
+
if (tag.isIdentifier({ name: 'iso' })) {
|
9
9
|
const { keyword, type, field } = getTypeAndField(path);
|
10
|
-
if (keyword ===
|
10
|
+
if (keyword === 'entrypoint') {
|
11
11
|
// This throws if the tag is invalid
|
12
|
-
compileImportStatement(t, path, type, field,
|
13
|
-
} else if (keyword ===
|
12
|
+
compileImportStatement(t, path, type, field, 'entrypoint', config);
|
13
|
+
} else if (keyword === 'field') {
|
14
14
|
// No-op
|
15
15
|
return false;
|
16
16
|
} else {
|
17
|
-
throw new Error(
|
18
|
-
"Invalid iso tag usage. Expected 'entrypoint' or 'field'."
|
19
|
-
);
|
17
|
+
throw new Error("Invalid iso tag usage. Expected 'entrypoint' or 'field'.");
|
20
18
|
}
|
21
19
|
}
|
22
20
|
|
23
21
|
return false;
|
24
22
|
}
|
25
23
|
|
26
|
-
const typeAndFieldRegex = new RegExp(
|
27
|
-
"\\s*(entrypoint|field)\\s*([^\\.\\s]+)\\.([^\\s\\(]+)",
|
28
|
-
"m"
|
29
|
-
);
|
24
|
+
const typeAndFieldRegex = new RegExp('\\s*(entrypoint|field)\\s*([^\\.\\s]+)\\.([^\\s\\(]+)', 'm');
|
30
25
|
|
31
26
|
function getTypeAndField(path) {
|
32
27
|
const quasis = path.node.quasi.quasis;
|
33
28
|
if (quasis.length !== 1) {
|
34
|
-
throw new Error(
|
35
|
-
"BabelPluginIsograph: Substitutions are not allowed in iso fragments."
|
36
|
-
);
|
29
|
+
throw new Error('BabelPluginIsograph: Substitutions are not allowed in iso fragments.');
|
37
30
|
}
|
38
31
|
|
39
32
|
const content = path.node.quasi.quasis[0].value.raw;
|
@@ -45,7 +38,7 @@ function getTypeAndField(path) {
|
|
45
38
|
|
46
39
|
if (keyword == null || type == null || field == null) {
|
47
40
|
throw new Error(
|
48
|
-
|
41
|
+
'Malformed iso literal. I hope the iso compiler failed to accept this literal!',
|
49
42
|
);
|
50
43
|
}
|
51
44
|
return { keyword, type, field };
|
@@ -59,18 +52,13 @@ function compileImportStatement(t, path, type, field, artifactType, config) {
|
|
59
52
|
|
60
53
|
const fileToArtifactDir = pathModule.relative(folder, artifactDirectory);
|
61
54
|
const artifactDirToArtifact = `/__isograph/${type}/${field}/${artifactType}.isograph.ts`;
|
62
|
-
const fileToArtifact = pathModule.join(
|
63
|
-
fileToArtifactDir,
|
64
|
-
artifactDirToArtifact
|
65
|
-
);
|
55
|
+
const fileToArtifact = pathModule.join(fileToArtifactDir, artifactDirToArtifact);
|
66
56
|
|
67
57
|
path.replaceWith(
|
68
58
|
t.memberExpression(
|
69
|
-
t.CallExpression(t.Identifier(
|
70
|
-
|
71
|
-
|
72
|
-
t.Identifier("default")
|
73
|
-
)
|
59
|
+
t.CallExpression(t.Identifier('require'), [t.StringLiteral(fileToArtifact)]),
|
60
|
+
t.Identifier('default'),
|
61
|
+
),
|
74
62
|
);
|
75
63
|
}
|
76
64
|
|
package/index.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
module.exports = require(
|
1
|
+
module.exports = require('./BabelPluginIsograph.js');
|