@khanacademy/graphql-flow 3.4.2 → 4.0.1
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/.github/workflows/changeset-release.yml +1 -1
- package/.github/workflows/pr-checks.yml +6 -6
- package/CHANGELOG.md +16 -0
- package/dist/cli/run.js +1 -1
- package/dist/parser/parse.js +74 -21
- package/dist/parser/resolve.js +14 -1
- package/dist/parser/resolveImport.js +58 -0
- package/dist/parser/utils.js +2 -15
- package/package.json +71 -65
- package/schema.json +1 -17
- package/src/cli/run.ts +1 -1
- package/src/parser/__test__/parse.test.ts +196 -2
- package/src/parser/__test__/resolveImport.test.ts +98 -0
- package/src/parser/__test__/utils.test.ts +10 -47
- package/src/parser/parse.ts +89 -29
- package/src/parser/resolve.ts +18 -1
- package/src/parser/resolveImport.ts +65 -0
- package/src/parser/utils.ts +1 -15
- package/src/types.ts +0 -4
|
@@ -17,7 +17,7 @@ jobs:
|
|
|
17
17
|
node-version: [20.x]
|
|
18
18
|
steps:
|
|
19
19
|
- uses: actions/checkout@v4
|
|
20
|
-
- uses: Khan/actions@shared-node-cache-
|
|
20
|
+
- uses: Khan/actions@shared-node-cache-v3
|
|
21
21
|
with:
|
|
22
22
|
node-version: ${{ matrix.node-version }}
|
|
23
23
|
|
|
@@ -34,7 +34,7 @@ jobs:
|
|
|
34
34
|
|
|
35
35
|
- name: Run TypeScript
|
|
36
36
|
if: steps.ts-files.outputs.filtered != '[]'
|
|
37
|
-
run:
|
|
37
|
+
run: pnpm typecheck
|
|
38
38
|
|
|
39
39
|
- id: eslint-reset
|
|
40
40
|
uses: Khan/actions@filter-files-v1
|
|
@@ -47,9 +47,9 @@ jobs:
|
|
|
47
47
|
uses: Khan/actions@full-or-limited-v0
|
|
48
48
|
with:
|
|
49
49
|
full-trigger: ${{ steps.eslint-reset.outputs.filtered }}
|
|
50
|
-
full:
|
|
50
|
+
full: pnpm eslint src/**/*.ts
|
|
51
51
|
limited-trigger: ${{ steps.ts-files.outputs.filtered }}
|
|
52
|
-
limited:
|
|
52
|
+
limited: pnpm eslint {}
|
|
53
53
|
|
|
54
54
|
- id: jest-reset
|
|
55
55
|
uses: Khan/actions@filter-files-v1
|
|
@@ -62,6 +62,6 @@ jobs:
|
|
|
62
62
|
uses: Khan/actions@full-or-limited-v0
|
|
63
63
|
with:
|
|
64
64
|
full-trigger: ${{ steps.jest-reset.outputs.filtered }}
|
|
65
|
-
full:
|
|
65
|
+
full: pnpm jest
|
|
66
66
|
limited-trigger: ${{ steps.ts-files.outputs.filtered }}
|
|
67
|
-
limited:
|
|
67
|
+
limited: pnpm jest --findRelatedTests {}
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @khanacademy/graphql-flow
|
|
2
2
|
|
|
3
|
+
## 4.0.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 7fd8814: Improve unresolved import errors
|
|
8
|
+
|
|
9
|
+
## 4.0.0
|
|
10
|
+
|
|
11
|
+
### Major Changes
|
|
12
|
+
|
|
13
|
+
- 9d96c11: Overhaul import resolution, relying on tsconfig for import aliases, and rspack-resolver for package imports. This removes the `alias` config option, instead requiring that aliases be defined in a `tsconfig.json`.
|
|
14
|
+
|
|
15
|
+
### Minor Changes
|
|
16
|
+
|
|
17
|
+
- a27caca: Support "export \* from" for fragments
|
|
18
|
+
|
|
3
19
|
## 3.4.2
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
package/dist/cli/run.js
CHANGED
|
@@ -40,7 +40,7 @@ const inputFiles = (0, _config.getInputFiles)(options, config);
|
|
|
40
40
|
/** Step (2) */
|
|
41
41
|
|
|
42
42
|
const files = (0, _parse.processFiles)(inputFiles, config, f => {
|
|
43
|
-
const resolvedPath = (0, _utils.getPathWithExtension)(f
|
|
43
|
+
const resolvedPath = (0, _utils.getPathWithExtension)(f);
|
|
44
44
|
if (!resolvedPath) {
|
|
45
45
|
throw new Error(`Unable to find ${f}`);
|
|
46
46
|
}
|
package/dist/parser/parse.js
CHANGED
|
@@ -8,6 +8,7 @@ var _wonderStuffCore = require("@khanacademy/wonder-stuff-core");
|
|
|
8
8
|
var _parser = require("@babel/parser");
|
|
9
9
|
var _traverse = _interopRequireDefault(require("@babel/traverse"));
|
|
10
10
|
var _path = _interopRequireDefault(require("path"));
|
|
11
|
+
var _resolveImport = require("./resolveImport");
|
|
11
12
|
var _utils = require("./utils");
|
|
12
13
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
14
|
/**
|
|
@@ -47,12 +48,12 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
|
|
|
47
48
|
* potentially relevant, and of course any values referenced
|
|
48
49
|
* from a graphql template are treated as relevant.
|
|
49
50
|
*/
|
|
50
|
-
const listExternalReferences =
|
|
51
|
+
const listExternalReferences = file => {
|
|
51
52
|
const paths = {};
|
|
52
53
|
const add = (v, followImports) => {
|
|
53
54
|
if (v.type === "import") {
|
|
54
55
|
if (followImports) {
|
|
55
|
-
const absPath = (0, _utils.getPathWithExtension)(v.path
|
|
56
|
+
const absPath = (0, _utils.getPathWithExtension)(v.path);
|
|
56
57
|
if (absPath) {
|
|
57
58
|
paths[absPath] = true;
|
|
58
59
|
}
|
|
@@ -71,16 +72,18 @@ const listExternalReferences = (file, config) => {
|
|
|
71
72
|
file.operations.forEach(op => op.source.expressions.forEach(expr => add(expr,
|
|
72
73
|
// Imports that are used in graphql expressions definitely need to be followed.
|
|
73
74
|
true)));
|
|
75
|
+
file.exportAlls.forEach(expr => add(expr, true));
|
|
74
76
|
return Object.keys(paths);
|
|
75
77
|
};
|
|
76
78
|
const processFile = (filePath, contents, config) => {
|
|
77
|
-
const dir = _path.default.dirname(filePath);
|
|
78
79
|
const result = {
|
|
79
80
|
path: filePath,
|
|
80
81
|
operations: [],
|
|
81
82
|
exports: {},
|
|
83
|
+
exportAlls: [],
|
|
82
84
|
locals: {},
|
|
83
|
-
errors: []
|
|
85
|
+
errors: [],
|
|
86
|
+
unresolvedImports: {}
|
|
84
87
|
};
|
|
85
88
|
const text = typeof contents === "string" ? contents : contents.text;
|
|
86
89
|
const plugins = filePath.endsWith("x") ? ["typescript", "jsx"] : ["typescript"];
|
|
@@ -94,14 +97,33 @@ const processFile = (filePath, contents, config) => {
|
|
|
94
97
|
ast.program.body.forEach(toplevel => {
|
|
95
98
|
var _toplevel$declaration;
|
|
96
99
|
if (toplevel.type === "ImportDeclaration") {
|
|
97
|
-
const
|
|
100
|
+
const isUnresolvedModule = !toplevel.source.value.startsWith(".") && !_path.default.isAbsolute(toplevel.source.value) && toplevel.source.value !== "graphql-tag";
|
|
101
|
+
if (isUnresolvedModule) {
|
|
102
|
+
toplevel.specifiers.forEach(spec => {
|
|
103
|
+
if (spec.type === "ImportSpecifier" || spec.type === "ImportDefaultSpecifier") {
|
|
104
|
+
var _spec$start, _spec$end, _spec$loc$start$line, _spec$loc;
|
|
105
|
+
result.unresolvedImports[spec.local.name] = {
|
|
106
|
+
source: toplevel.source.value,
|
|
107
|
+
loc: {
|
|
108
|
+
start: (_spec$start = spec.start) !== null && _spec$start !== void 0 ? _spec$start : -1,
|
|
109
|
+
end: (_spec$end = spec.end) !== null && _spec$end !== void 0 ? _spec$end : -1,
|
|
110
|
+
line: (_spec$loc$start$line = (_spec$loc = spec.loc) === null || _spec$loc === void 0 ? void 0 : _spec$loc.start.line) !== null && _spec$loc$start$line !== void 0 ? _spec$loc$start$line : -1,
|
|
111
|
+
path: filePath
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
const newLocals = getLocals(toplevel, filePath);
|
|
98
118
|
if (newLocals) {
|
|
99
119
|
Object.keys(newLocals).forEach(k => {
|
|
120
|
+
var _local$resolvedPath$i, _local$resolvedPath;
|
|
100
121
|
const local = newLocals[k];
|
|
101
|
-
|
|
122
|
+
const isGraphqlTagImport = local.rawPath === "graphql-tag" || ((_local$resolvedPath$i = (_local$resolvedPath = local.resolvedPath) === null || _local$resolvedPath === void 0 ? void 0 : _local$resolvedPath.includes(`${_path.default.sep}node_modules${_path.default.sep}graphql-tag`)) !== null && _local$resolvedPath$i !== void 0 ? _local$resolvedPath$i : false);
|
|
123
|
+
if (_path.default.isAbsolute(local.path)) {
|
|
102
124
|
result.locals[k] = local;
|
|
103
125
|
}
|
|
104
|
-
if (
|
|
126
|
+
if (isGraphqlTagImport && local.name === "default") {
|
|
105
127
|
gqlTagNames.push(k);
|
|
106
128
|
}
|
|
107
129
|
});
|
|
@@ -111,18 +133,19 @@ const processFile = (filePath, contents, config) => {
|
|
|
111
133
|
if (toplevel.source) {
|
|
112
134
|
var _toplevel$specifiers;
|
|
113
135
|
const source = toplevel.source;
|
|
114
|
-
const
|
|
136
|
+
const resolvedPath = (0, _resolveImport.resolveImportPath)(filePath, source.value);
|
|
137
|
+
const importPath = resolvedPath !== null && resolvedPath !== void 0 ? resolvedPath : source.value;
|
|
115
138
|
(_toplevel$specifiers = toplevel.specifiers) === null || _toplevel$specifiers === void 0 || _toplevel$specifiers.forEach(spec => {
|
|
116
139
|
if (spec.type === "ExportSpecifier" && spec.exported.type === "Identifier") {
|
|
117
|
-
var _spec$
|
|
140
|
+
var _spec$start2, _spec$end2, _spec$loc$start$line2, _spec$loc2;
|
|
118
141
|
result.exports[spec.exported.name] = {
|
|
119
142
|
type: "import",
|
|
120
143
|
name: spec.local.name,
|
|
121
144
|
path: importPath,
|
|
122
145
|
loc: {
|
|
123
|
-
start: (_spec$
|
|
124
|
-
end: (_spec$
|
|
125
|
-
line: (_spec$loc$start$
|
|
146
|
+
start: (_spec$start2 = spec.start) !== null && _spec$start2 !== void 0 ? _spec$start2 : -1,
|
|
147
|
+
end: (_spec$end2 = spec.end) !== null && _spec$end2 !== void 0 ? _spec$end2 : -1,
|
|
148
|
+
line: (_spec$loc$start$line2 = (_spec$loc2 = spec.loc) === null || _spec$loc2 === void 0 ? void 0 : _spec$loc2.start.line) !== null && _spec$loc$start$line2 !== void 0 ? _spec$loc$start$line2 : -1,
|
|
126
149
|
path: filePath
|
|
127
150
|
}
|
|
128
151
|
};
|
|
@@ -140,6 +163,22 @@ const processFile = (filePath, contents, config) => {
|
|
|
140
163
|
});
|
|
141
164
|
}
|
|
142
165
|
}
|
|
166
|
+
if (toplevel.type === "ExportAllDeclaration" && toplevel.source) {
|
|
167
|
+
var _toplevel$start, _toplevel$end, _toplevel$loc$start$l, _toplevel$loc;
|
|
168
|
+
const source = toplevel.source;
|
|
169
|
+
const importPath = source.value.startsWith(".") ? _path.default.resolve(_path.default.join(_path.default.dirname(filePath), source.value)) : source.value;
|
|
170
|
+
result.exportAlls.push({
|
|
171
|
+
type: "import",
|
|
172
|
+
name: "*",
|
|
173
|
+
path: importPath,
|
|
174
|
+
loc: {
|
|
175
|
+
start: (_toplevel$start = toplevel.start) !== null && _toplevel$start !== void 0 ? _toplevel$start : -1,
|
|
176
|
+
end: (_toplevel$end = toplevel.end) !== null && _toplevel$end !== void 0 ? _toplevel$end : -1,
|
|
177
|
+
line: (_toplevel$loc$start$l = (_toplevel$loc = toplevel.loc) === null || _toplevel$loc === void 0 ? void 0 : _toplevel$loc.start.line) !== null && _toplevel$loc$start$l !== void 0 ? _toplevel$loc$start$l : -1,
|
|
178
|
+
path: filePath
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
}
|
|
143
182
|
const processDeclarator = (decl, isExported) => {
|
|
144
183
|
if (decl.id.type !== "Identifier" || !decl.init) {
|
|
145
184
|
return;
|
|
@@ -210,7 +249,8 @@ const processFile = (filePath, contents, config) => {
|
|
|
210
249
|
};
|
|
211
250
|
(0, _traverse.default)(ast, {
|
|
212
251
|
TaggedTemplateExpression(path) {
|
|
213
|
-
|
|
252
|
+
const node = path.node;
|
|
253
|
+
visitTpl(node, name => {
|
|
214
254
|
const binding = path.scope.getBinding(name);
|
|
215
255
|
if (!binding) {
|
|
216
256
|
return null;
|
|
@@ -246,14 +286,23 @@ const processTemplate = (tpl, result, getTemplate) => {
|
|
|
246
286
|
return null;
|
|
247
287
|
}
|
|
248
288
|
if (!result.locals[expr.name]) {
|
|
289
|
+
var _result$unresolvedImp;
|
|
249
290
|
if (getTemplate) {
|
|
250
291
|
const found = getTemplate(expr.name);
|
|
251
292
|
return found;
|
|
252
293
|
}
|
|
253
|
-
result.
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
294
|
+
const unresolved = (_result$unresolvedImp = result.unresolvedImports) === null || _result$unresolvedImp === void 0 ? void 0 : _result$unresolvedImp[expr.name];
|
|
295
|
+
if (unresolved) {
|
|
296
|
+
result.errors.push({
|
|
297
|
+
loc: unresolved.loc,
|
|
298
|
+
message: `Unable to resolve import ${expr.name} from "${unresolved.source}" at ${unresolved.loc.path}:${unresolved.loc.line}.`
|
|
299
|
+
});
|
|
300
|
+
} else {
|
|
301
|
+
result.errors.push({
|
|
302
|
+
loc,
|
|
303
|
+
message: `Unable to resolve ${expr.name}`
|
|
304
|
+
});
|
|
305
|
+
}
|
|
257
306
|
return null;
|
|
258
307
|
}
|
|
259
308
|
return result.locals[expr.name];
|
|
@@ -273,12 +322,12 @@ const processTemplate = (tpl, result, getTemplate) => {
|
|
|
273
322
|
}
|
|
274
323
|
};
|
|
275
324
|
};
|
|
276
|
-
const getLocals = (
|
|
325
|
+
const getLocals = (toplevel, myPath) => {
|
|
277
326
|
if (toplevel.importKind === "type") {
|
|
278
327
|
return null;
|
|
279
328
|
}
|
|
280
|
-
const
|
|
281
|
-
const importPath =
|
|
329
|
+
const resolvedPath = (0, _resolveImport.resolveImportPath)(myPath, toplevel.source.value);
|
|
330
|
+
const importPath = resolvedPath !== null && resolvedPath !== void 0 ? resolvedPath : toplevel.source.value;
|
|
282
331
|
const locals = {};
|
|
283
332
|
toplevel.specifiers.forEach(spec => {
|
|
284
333
|
if (spec.type === "ImportDefaultSpecifier") {
|
|
@@ -286,6 +335,8 @@ const getLocals = (dir, toplevel, myPath, config) => {
|
|
|
286
335
|
type: "import",
|
|
287
336
|
name: "default",
|
|
288
337
|
path: importPath,
|
|
338
|
+
rawPath: toplevel.source.value,
|
|
339
|
+
resolvedPath,
|
|
289
340
|
loc: {
|
|
290
341
|
start: spec.start,
|
|
291
342
|
end: spec.end,
|
|
@@ -297,6 +348,8 @@ const getLocals = (dir, toplevel, myPath, config) => {
|
|
|
297
348
|
type: "import",
|
|
298
349
|
name: spec.imported.type === "Identifier" ? spec.imported.name : spec.imported.value,
|
|
299
350
|
path: importPath,
|
|
351
|
+
rawPath: toplevel.source.value,
|
|
352
|
+
resolvedPath,
|
|
300
353
|
loc: {
|
|
301
354
|
start: spec.start,
|
|
302
355
|
end: spec.end,
|
|
@@ -321,7 +374,7 @@ const processFiles = (filePaths, config, getFileSource) => {
|
|
|
321
374
|
}
|
|
322
375
|
const result = processFile(next, source, config);
|
|
323
376
|
files[next] = result;
|
|
324
|
-
listExternalReferences(result
|
|
377
|
+
listExternalReferences(result).forEach(path => {
|
|
325
378
|
if (!files[path] && !toProcess.includes(path)) {
|
|
326
379
|
toProcess.push(path);
|
|
327
380
|
}
|
package/dist/parser/resolve.js
CHANGED
|
@@ -29,7 +29,7 @@ const resolveDocuments = (files, config) => {
|
|
|
29
29
|
};
|
|
30
30
|
exports.resolveDocuments = resolveDocuments;
|
|
31
31
|
const resolveImport = (expr, files, errors, seen, config) => {
|
|
32
|
-
const absPath = (0, _utils.getPathWithExtension)(expr.path
|
|
32
|
+
const absPath = (0, _utils.getPathWithExtension)(expr.path);
|
|
33
33
|
if (!absPath) {
|
|
34
34
|
return null;
|
|
35
35
|
}
|
|
@@ -50,6 +50,19 @@ const resolveImport = (expr, files, errors, seen, config) => {
|
|
|
50
50
|
return null;
|
|
51
51
|
}
|
|
52
52
|
if (!res.exports[expr.name]) {
|
|
53
|
+
if (expr.name !== "*" && res.exportAlls.length) {
|
|
54
|
+
for (const exportAll of res.exportAlls) {
|
|
55
|
+
const value = resolveImport({
|
|
56
|
+
...exportAll,
|
|
57
|
+
name: expr.name
|
|
58
|
+
}, files, errors, {
|
|
59
|
+
...seen
|
|
60
|
+
}, config);
|
|
61
|
+
if (value) {
|
|
62
|
+
return value;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
53
66
|
errors.push({
|
|
54
67
|
loc: expr.loc,
|
|
55
68
|
message: `${absPath} has no valid gql export ${expr.name}`
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.resetImportCache = resetImportCache;
|
|
7
|
+
exports.resolveImportPath = resolveImportPath;
|
|
8
|
+
var _nodePath = _interopRequireDefault(require("node:path"));
|
|
9
|
+
var _rspackResolver = require("rspack-resolver");
|
|
10
|
+
var _tsconfigPaths = require("tsconfig-paths");
|
|
11
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
|
+
// Copied from https://github.com/Khan/frontend/blob/main/libs/node/resolve-import/src/resolve-import.ts
|
|
13
|
+
// In future it would be cool to publish @khan/node-resolve-import as a public library so we
|
|
14
|
+
// could consume it here.
|
|
15
|
+
|
|
16
|
+
const CONDITION_NAMES = ["import"];
|
|
17
|
+
const matchPathCache = new Map();
|
|
18
|
+
let esmResolver = getEsmResolver();
|
|
19
|
+
function getEsmResolver() {
|
|
20
|
+
return new _rspackResolver.ResolverFactory({
|
|
21
|
+
conditionNames: CONDITION_NAMES,
|
|
22
|
+
mainFields: ["module", "main"],
|
|
23
|
+
extensions: [".mjs", ".js", ".jsx", ".ts", ".tsx"]
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
function resetImportCache() {
|
|
27
|
+
matchPathCache.clear();
|
|
28
|
+
esmResolver = getEsmResolver();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Resolves an import path using tsconfig and the rspack resolver.
|
|
33
|
+
*
|
|
34
|
+
* @param sourceFile - The file that is importing the path.
|
|
35
|
+
* @param importPath - The path to resolve.
|
|
36
|
+
* @returns The fully resolved path.
|
|
37
|
+
*/
|
|
38
|
+
function resolveImportPath(sourceFile, importPath) {
|
|
39
|
+
const dir = _nodePath.default.dirname(sourceFile);
|
|
40
|
+
let matchPath = matchPathCache.get(dir);
|
|
41
|
+
if (!matchPath) {
|
|
42
|
+
const foundConfig = (0, _tsconfigPaths.loadConfig)(dir);
|
|
43
|
+
if (foundConfig.resultType !== "success") {
|
|
44
|
+
throw new Error("Failed to load tsconfig");
|
|
45
|
+
}
|
|
46
|
+
matchPath = (0, _tsconfigPaths.createMatchPath)(foundConfig.absoluteBaseUrl, foundConfig.paths, CONDITION_NAMES);
|
|
47
|
+
matchPathCache.set(dir, matchPath);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// See if we can resolve the import path using the tsconfig.
|
|
51
|
+
const resolvedPath = matchPath(importPath);
|
|
52
|
+
|
|
53
|
+
// Get the directory of the source file to resolve against.
|
|
54
|
+
const sourceFileDir = _nodePath.default.dirname(sourceFile);
|
|
55
|
+
|
|
56
|
+
// Get the fully resolved path.
|
|
57
|
+
return esmResolver.sync(sourceFileDir, resolvedPath !== null && resolvedPath !== void 0 ? resolvedPath : importPath).path;
|
|
58
|
+
}
|
package/dist/parser/utils.js
CHANGED
|
@@ -3,23 +3,10 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.getPathWithExtension =
|
|
6
|
+
exports.getPathWithExtension = void 0;
|
|
7
7
|
var _fs = _interopRequireDefault(require("fs"));
|
|
8
8
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
-
const
|
|
10
|
-
if (config.alias) {
|
|
11
|
-
for (const {
|
|
12
|
-
find,
|
|
13
|
-
replacement
|
|
14
|
-
} of config.alias) {
|
|
15
|
-
path = path.replace(find, replacement);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
return path;
|
|
19
|
-
};
|
|
20
|
-
exports.fixPathResolution = fixPathResolution;
|
|
21
|
-
const getPathWithExtension = (pathWithoutExtension, config) => {
|
|
22
|
-
pathWithoutExtension = fixPathResolution(pathWithoutExtension, config);
|
|
9
|
+
const getPathWithExtension = pathWithoutExtension => {
|
|
23
10
|
if (/\.(less|css|png|gif|jpg|jpeg|js|jsx|ts|tsx|mjs)$/.test(pathWithoutExtension)) {
|
|
24
11
|
return pathWithoutExtension;
|
|
25
12
|
}
|
package/package.json
CHANGED
|
@@ -1,66 +1,72 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
"
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
2
|
+
"name": "@khanacademy/graphql-flow",
|
|
3
|
+
"version": "4.0.1",
|
|
4
|
+
"repository": {
|
|
5
|
+
"type": "git",
|
|
6
|
+
"url": "https://github.com/Khan/graphql-flow.git"
|
|
7
|
+
},
|
|
8
|
+
"bugs": {
|
|
9
|
+
"url": "https://github.com/Khan/graphql-flow/issues"
|
|
10
|
+
},
|
|
11
|
+
"publishConfig": {
|
|
12
|
+
"access": "public",
|
|
13
|
+
"provenance": true
|
|
14
|
+
},
|
|
15
|
+
"bin": {
|
|
16
|
+
"graphql-flow": "dist/cli/run.js"
|
|
17
|
+
},
|
|
18
|
+
"jest": {
|
|
19
|
+
"testPathIgnorePatterns": [
|
|
20
|
+
"dist"
|
|
21
|
+
]
|
|
22
|
+
},
|
|
23
|
+
"main": "dist/index.js",
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@babel/cli": "^7.17.6",
|
|
26
|
+
"@babel/eslint-parser": "^7.17.0",
|
|
27
|
+
"@babel/polyfill": "^7.0.0",
|
|
28
|
+
"@babel/preset-env": "^7.24.5",
|
|
29
|
+
"@babel/preset-typescript": "^7.24.1",
|
|
30
|
+
"@changesets/cli": "^2.21.1",
|
|
31
|
+
"@jest/globals": "^30.2.0",
|
|
32
|
+
"@khanacademy/eslint-config": "^4.0.0",
|
|
33
|
+
"@types/babel__generator": "^7.27.0",
|
|
34
|
+
"@types/babel__traverse": "^7.28.0",
|
|
35
|
+
"@types/jest": "^29.5.3",
|
|
36
|
+
"@types/minimist": "^1.2.5",
|
|
37
|
+
"@types/prop-types": "^15.7.12",
|
|
38
|
+
"@types/react": "^18.3.3",
|
|
39
|
+
"@typescript-eslint/eslint-plugin": "^7.17.0",
|
|
40
|
+
"@typescript-eslint/parser": "^7.17.0",
|
|
41
|
+
"babel-jest": "23.4.2",
|
|
42
|
+
"eslint": "^8.57.0",
|
|
43
|
+
"eslint-config-prettier": "7.0.0",
|
|
44
|
+
"eslint-plugin-jest": "^28.6.0",
|
|
45
|
+
"eslint-plugin-prettier": "^4.0.0",
|
|
46
|
+
"graphql-tag": "2.10.1",
|
|
47
|
+
"jest": "^27.5.1",
|
|
48
|
+
"prettier": "^2.5.1",
|
|
49
|
+
"prettier-eslint": "^13.0.0",
|
|
50
|
+
"typescript": "^5.1.6"
|
|
51
|
+
},
|
|
52
|
+
"dependencies": {
|
|
53
|
+
"@babel/core": "^7.24.5",
|
|
54
|
+
"@babel/generator": "^7.24.5",
|
|
55
|
+
"@babel/parser": "^7.24.5",
|
|
56
|
+
"@babel/traverse": "^7.24.5",
|
|
57
|
+
"@babel/types": "^7.24.5",
|
|
58
|
+
"@khanacademy/wonder-stuff-core": "^1.5.1",
|
|
59
|
+
"apollo-utilities": "^1.3.4",
|
|
60
|
+
"graphql": "^16.9.0",
|
|
61
|
+
"jsonschema": "^1.4.1",
|
|
62
|
+
"minimist": "^1.2.8",
|
|
63
|
+
"rspack-resolver": "^1.3.0",
|
|
64
|
+
"tsconfig-paths": "^4.2.0"
|
|
65
|
+
},
|
|
66
|
+
"scripts": {
|
|
67
|
+
"test": "jest",
|
|
68
|
+
"typecheck": "tsc --noEmit",
|
|
69
|
+
"publish:ci": "pnpm build && changeset publish",
|
|
70
|
+
"build": "babel src --extensions '.ts, .tsx' --out-dir dist --ignore 'src/**/*.spec.ts','src/**/*.test.ts' && chmod 755 dist/cli/run.js"
|
|
71
|
+
}
|
|
72
|
+
}
|
package/schema.json
CHANGED
|
@@ -94,23 +94,7 @@
|
|
|
94
94
|
"generate": {"oneOf": [
|
|
95
95
|
{"$ref": "#/definitions/GenerateConfig"},
|
|
96
96
|
{"type": "array", "items": {"$ref": "#/definitions/GenerateConfig"}}
|
|
97
|
-
]}
|
|
98
|
-
"alias": {
|
|
99
|
-
"type": "array",
|
|
100
|
-
"items": {
|
|
101
|
-
"type": "object",
|
|
102
|
-
"additionalProperties": false,
|
|
103
|
-
"properties": {
|
|
104
|
-
"find": {
|
|
105
|
-
"type": ["string", "object"]
|
|
106
|
-
},
|
|
107
|
-
"replacement": {
|
|
108
|
-
"type": "string"
|
|
109
|
-
}
|
|
110
|
-
},
|
|
111
|
-
"required": [ "find", "replacement" ]
|
|
112
|
-
}
|
|
113
|
-
}
|
|
97
|
+
]}
|
|
114
98
|
},
|
|
115
99
|
"required": [ "crawl", "generate" ]
|
|
116
100
|
}
|
package/src/cli/run.ts
CHANGED
|
@@ -56,7 +56,7 @@ const inputFiles = getInputFiles(options, config);
|
|
|
56
56
|
/** Step (2) */
|
|
57
57
|
|
|
58
58
|
const files = processFiles(inputFiles, config, (f) => {
|
|
59
|
-
const resolvedPath = getPathWithExtension(f
|
|
59
|
+
const resolvedPath = getPathWithExtension(f);
|
|
60
60
|
if (!resolvedPath) {
|
|
61
61
|
throw new Error(`Unable to find ${f}`);
|
|
62
62
|
}
|