@stepzen/transpiler 0.28.0-experimental.dd6fead → 0.28.0-experimental.f225ee8
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/lib/actions/configure.js +3 -3
- package/lib/actions/configure.js.map +1 -1
- package/lib/actions/lint.d.ts.map +1 -1
- package/lib/actions/lint.js +20 -12
- package/lib/actions/lint.js.map +1 -1
- package/lib/actions/merge.d.ts +7 -6
- package/lib/actions/merge.d.ts.map +1 -1
- package/lib/actions/merge.js +42 -26
- package/lib/actions/merge.js.map +1 -1
- package/lib/actions/stitch.d.ts +2 -2
- package/lib/actions/stitch.d.ts.map +1 -1
- package/lib/actions/stitch.js +30 -12
- package/lib/actions/stitch.js.map +1 -1
- package/lib/actions/transpile.d.ts.map +1 -1
- package/lib/actions/transpile.js +9 -3
- package/lib/actions/transpile.js.map +1 -1
- package/lib/actions/validate.js +4 -4
- package/lib/actions/validate.js.map +1 -1
- package/lib/utils/copy-workspace-content.js +4 -4
- package/lib/utils/copy-workspace-content.js.map +1 -1
- package/lib/utils/merge-helpers.d.ts.map +1 -1
- package/lib/utils/merge-helpers.js +23 -18
- package/lib/utils/merge-helpers.js.map +1 -1
- package/lib/utils/rmtemp.d.ts +11 -0
- package/lib/utils/rmtemp.d.ts.map +1 -0
- package/lib/utils/rmtemp.js +43 -0
- package/lib/utils/rmtemp.js.map +1 -0
- package/lib/utils/set-files-in-sdl.d.ts +2 -2
- package/lib/utils/set-files-in-sdl.d.ts.map +1 -1
- package/lib/utils/set-files-in-sdl.js +12 -12
- package/lib/utils/set-files-in-sdl.js.map +1 -1
- package/package.json +14 -12
- package/src/actions/configure.ts +3 -3
- package/src/actions/lint.ts +20 -17
- package/src/actions/merge.ts +70 -39
- package/src/actions/stitch.ts +32 -15
- package/src/actions/transpile.ts +9 -4
- package/src/actions/validate.ts +4 -4
- package/src/utils/copy-workspace-content.ts +4 -4
- package/src/utils/merge-helpers.ts +23 -19
- package/src/utils/rmtemp.ts +48 -0
- package/src/utils/set-files-in-sdl.ts +16 -13
|
@@ -5,7 +5,7 @@ const debug = require("debug");
|
|
|
5
5
|
const graphql_1 = require("graphql");
|
|
6
6
|
const utilities_1 = require("graphql/utilities");
|
|
7
7
|
const fetch_1 = require("@stepzen/fetch");
|
|
8
|
-
const
|
|
8
|
+
const fsx = require("fs-extra");
|
|
9
9
|
const glob = require("glob");
|
|
10
10
|
const os = require("os");
|
|
11
11
|
const path = require("path");
|
|
@@ -14,6 +14,7 @@ const graphql_helpers_1 = require("../utils/graphql-helpers");
|
|
|
14
14
|
const constants_1 = require("./constants");
|
|
15
15
|
const configure_1 = require("../actions/configure");
|
|
16
16
|
const transpile_1 = require("../actions/transpile");
|
|
17
|
+
const rmtemp_1 = require("./rmtemp");
|
|
17
18
|
const dedupeTempFolder = (dirpath) => {
|
|
18
19
|
do {
|
|
19
20
|
dirpath = (0, lodash_1.replace)(dirpath, os.tmpdir(), '');
|
|
@@ -25,7 +26,7 @@ exports.dedupeTempFolder = dedupeTempFolder;
|
|
|
25
26
|
const findNextAvailableSubfolder = (folder, name) => {
|
|
26
27
|
let subfolder = name;
|
|
27
28
|
let counter = 1;
|
|
28
|
-
while (
|
|
29
|
+
while (fsx.existsSync(path.join(folder, subfolder))) {
|
|
29
30
|
const suffix = `${counter++}`.padStart(2, '0');
|
|
30
31
|
subfolder = `${name}-${suffix}`;
|
|
31
32
|
}
|
|
@@ -68,24 +69,28 @@ const findTypeInSchema = (name, files) => {
|
|
|
68
69
|
exports.findTypeInSchema = findTypeInSchema;
|
|
69
70
|
const getConfiguration = async (directories, silent = false, answers = {}) => {
|
|
70
71
|
const tmp = path.join(os.tmpdir(), `stepzen-tmp-config-${Date.now()}`);
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
72
|
+
fsx.ensureDirSync(tmp);
|
|
73
|
+
try {
|
|
74
|
+
for (const directory of directories) {
|
|
75
|
+
const configs = [
|
|
76
|
+
...glob.sync('**/config.yaml', { cwd: directory }),
|
|
77
|
+
...glob.sync('**/stepzen.config.json', { cwd: directory }),
|
|
78
|
+
];
|
|
79
|
+
for (const config of configs) {
|
|
80
|
+
const configFolder = path.join(directory, config);
|
|
81
|
+
let writeFolder = path.join(tmp, directory, config);
|
|
82
|
+
writeFolder = (0, exports.dedupeTempFolder)(writeFolder);
|
|
83
|
+
const content = fsx.readFileSync(configFolder, 'utf8');
|
|
84
|
+
fsx.ensureFileSync(writeFolder);
|
|
85
|
+
fsx.writeFileSync(writeFolder, content, { mode: 0o600 });
|
|
86
|
+
}
|
|
84
87
|
}
|
|
88
|
+
const configuration = await (0, configure_1.default)(tmp, silent, answers);
|
|
89
|
+
return configuration;
|
|
90
|
+
}
|
|
91
|
+
finally {
|
|
92
|
+
(0, rmtemp_1.rmtemp)(tmp);
|
|
85
93
|
}
|
|
86
|
-
const configuration = await (0, configure_1.default)(tmp, silent, answers);
|
|
87
|
-
fs.removeSync(tmp);
|
|
88
|
-
return configuration;
|
|
89
94
|
};
|
|
90
95
|
exports.getConfiguration = getConfiguration;
|
|
91
96
|
const getExtensions = async () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"merge-helpers.js","sourceRoot":"","sources":["../../src/utils/merge-helpers.ts"],"names":[],"mappings":";;;AAAA,+BAA8B;AAC9B,qCAAmD;AACnD,iDAA6C;AAC7C,0CAAkC;AAClC
|
|
1
|
+
{"version":3,"file":"merge-helpers.js","sourceRoot":"","sources":["../../src/utils/merge-helpers.ts"],"names":[],"mappings":";;;AAAA,+BAA8B;AAC9B,qCAAmD;AACnD,iDAA6C;AAC7C,0CAAkC;AAClC,gCAA+B;AAC/B,6BAA4B;AAC5B,yBAAwB;AACxB,6BAA4B;AAC5B,mCAA8B;AAE9B,8DAAkD;AAClD,2C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KAAK,CAAC,GAAG,CAAC,CAAC,IAAS,EAAE,EAAE;QAC9B,OAAO;YACL,GAAG,IAAI;YACP,GAAG,EAAE,IAAA,eAAK,EAAC,IAAI,CAAC,GAAG,EAAE;gBACnB,oBAAoB,CAAC,IAAI;oBACvB,IAAI,IAAI,CAAC,IAAI,CAAC,KAAK,KAAK,IAAI,EAAE;wBAC5B,OAAO,IAAI,CAAA;qBACZ;gBACH,CAAC;aACF,CAAC;SACH,CAAA;IACH,CAAC,CAAC,CAAA;IACF,OAAO,KAAK,CAAA;AACd,CAAC,CAAA;AAdY,QAAA,oBAAoB,wBAchC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Verify that the given path is indeed inside the tmp folder,
|
|
3
|
+
* and delete it recursively suppressing any errors.
|
|
4
|
+
*
|
|
5
|
+
* If the given path is not inside the tmp folder, do nothing.
|
|
6
|
+
*
|
|
7
|
+
* @param {*} fileOrDirPath path to a temp file or folder to delete
|
|
8
|
+
*/
|
|
9
|
+
export declare const rmtemp: (fileOrDirPath?: string) => void;
|
|
10
|
+
export default rmtemp;
|
|
11
|
+
//# sourceMappingURL=rmtemp.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rmtemp.d.ts","sourceRoot":"","sources":["../../src/utils/rmtemp.ts"],"names":[],"mappings":"AAYA;;;;;;;GAOG;AACH,eAAO,MAAM,MAAM,mBAAoB,MAAM,SAyB5C,CAAA;AAED,eAAe,MAAM,CAAA"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) 2020,2021,2022,2023, StepZen, Inc.
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.rmtemp = void 0;
|
|
5
|
+
const fs = require("fs");
|
|
6
|
+
const path = require("path");
|
|
7
|
+
const os = require("os");
|
|
8
|
+
const debug = require("debug");
|
|
9
|
+
// ----------------------------------------------------------------------------
|
|
10
|
+
// THIS ENTIRE FILE IS COPIED FROM packages/cli/src/shared/rmtemp.ts
|
|
11
|
+
// (because there is no effective way to share util classes between packages yet)
|
|
12
|
+
// ----------------------------------------------------------------------------
|
|
13
|
+
/**
|
|
14
|
+
* Verify that the given path is indeed inside the tmp folder,
|
|
15
|
+
* and delete it recursively suppressing any errors.
|
|
16
|
+
*
|
|
17
|
+
* If the given path is not inside the tmp folder, do nothing.
|
|
18
|
+
*
|
|
19
|
+
* @param {*} fileOrDirPath path to a temp file or folder to delete
|
|
20
|
+
*/
|
|
21
|
+
const rmtemp = (fileOrDirPath) => {
|
|
22
|
+
if (!fileOrDirPath) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
// https://stackoverflow.com/a/45242825
|
|
26
|
+
const relative = path.relative(os.tmpdir(), fileOrDirPath);
|
|
27
|
+
const isInTemp = relative && !relative.startsWith('..') && !path.isAbsolute(relative);
|
|
28
|
+
if (isInTemp) {
|
|
29
|
+
try {
|
|
30
|
+
fs.rmSync(fileOrDirPath, { recursive: true, force: true });
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
// ignore errors
|
|
34
|
+
debug('stepzen:rmtemp')(`WARN: caught an exception while deleting ${fileOrDirPath}: `, error);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
debug('stepzen:rmtemp')(`WARN: got a temp path ${fileOrDirPath} out of the TMP folder -- ignoring`);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
exports.rmtemp = rmtemp;
|
|
42
|
+
exports.default = exports.rmtemp;
|
|
43
|
+
//# sourceMappingURL=rmtemp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rmtemp.js","sourceRoot":"","sources":["../../src/utils/rmtemp.ts"],"names":[],"mappings":";AAAA,mDAAmD;;;AAEnD,yBAAwB;AACxB,6BAA4B;AAC5B,yBAAwB;AACxB,+BAA8B;AAE9B,+EAA+E;AAC/E,yEAAyE;AACzE,iFAAiF;AACjF,+EAA+E;AAE/E;;;;;;;GAOG;AACI,MAAM,MAAM,GAAG,CAAC,aAAsB,EAAE,EAAE;IAC/C,IAAI,CAAC,aAAa,EAAE;QAClB,OAAM;KACP;IAED,uCAAuC;IACvC,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,EAAE,aAAa,CAAC,CAAA;IAC1D,MAAM,QAAQ,GACZ,QAAQ,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAA;IAEtE,IAAI,QAAQ,EAAE;QACZ,IAAI;YACF,EAAE,CAAC,MAAM,CAAC,aAAa,EAAE,EAAC,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAC,CAAC,CAAA;SACzD;QAAC,OAAO,KAAK,EAAE;YACd,gBAAgB;YAChB,KAAK,CAAC,gBAAgB,CAAC,CACrB,4CAA4C,aAAa,IAAI,EAC7D,KAAK,CACN,CAAA;SACF;KACF;SAAM;QACL,KAAK,CAAC,gBAAgB,CAAC,CACrB,yBAAyB,aAAa,oCAAoC,CAC3E,CAAA;KACF;AACH,CAAC,CAAA;AAzBY,QAAA,MAAM,UAyBlB;AAED,kBAAe,cAAM,CAAA"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { DirectiveNode, SchemaDefinitionNode } from 'graphql';
|
|
1
|
+
import { ConstDirectiveNode, DirectiveNode, SchemaDefinitionNode } from 'graphql';
|
|
2
2
|
import { DeepWriteable } from './graphql-helpers';
|
|
3
|
-
export declare const createOrUpdateSdlDirective: (importedGraphQLFiles: readonly string[], allGraphQLFiles: readonly string[], origSdlDirective?: DeepWriteable<DirectiveNode>) => DeepWriteable<
|
|
3
|
+
export declare const createOrUpdateSdlDirective: (importedGraphQLFiles: readonly string[], allGraphQLFiles: readonly string[], origSdlDirective?: DeepWriteable<DirectiveNode>) => DeepWriteable<ConstDirectiveNode>;
|
|
4
4
|
export declare const createSchemaElement: (importedGraphQLFiles: readonly string[], allGraphQLFiles: readonly string[]) => DeepWriteable<SchemaDefinitionNode>;
|
|
5
5
|
declare const _default: (source: string, importedGraphQLFiles: readonly string[]) => void;
|
|
6
6
|
export default _default;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"set-files-in-sdl.d.ts","sourceRoot":"","sources":["../../src/utils/set-files-in-sdl.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,aAAa,
|
|
1
|
+
{"version":3,"file":"set-files-in-sdl.d.ts","sourceRoot":"","sources":["../../src/utils/set-files-in-sdl.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,kBAAkB,EAClB,aAAa,EAIb,oBAAoB,EAIrB,MAAM,SAAS,CAAA;AAGhB,OAAO,EAAY,aAAa,EAAC,MAAM,mBAAmB,CAAA;AAQ1D,eAAO,MAAM,0BAA0B,yBACf,SAAS,MAAM,EAAE,mBACtB,SAAS,MAAM,EAAE,qBACf,cAAc,aAAa,CAAC,sCA2DhD,CAAA;AAED,eAAO,MAAM,mBAAmB,yBACR,SAAS,MAAM,EAAE,mBACtB,SAAS,MAAM,EAAE,wCAuBnC,CAAA;iCAEuB,MAAM,wBAAwB,SAAS,MAAM,EAAE;AAAvE,wBA4CC"}
|
|
@@ -16,23 +16,23 @@ const createOrUpdateSdlDirective = (importedGraphQLFiles, allGraphQLFiles, origS
|
|
|
16
16
|
}
|
|
17
17
|
else {
|
|
18
18
|
sdlDirective = {
|
|
19
|
-
kind:
|
|
19
|
+
kind: graphql_1.Kind.DIRECTIVE,
|
|
20
20
|
name: {
|
|
21
|
-
kind:
|
|
21
|
+
kind: graphql_1.Kind.NAME,
|
|
22
22
|
value: 'sdl',
|
|
23
23
|
},
|
|
24
24
|
arguments: [
|
|
25
25
|
{
|
|
26
|
-
kind:
|
|
26
|
+
kind: graphql_1.Kind.ARGUMENT,
|
|
27
27
|
name: {
|
|
28
|
-
kind:
|
|
28
|
+
kind: graphql_1.Kind.NAME,
|
|
29
29
|
value: 'files',
|
|
30
30
|
},
|
|
31
31
|
value: {
|
|
32
|
-
kind:
|
|
32
|
+
kind: graphql_1.Kind.LIST,
|
|
33
33
|
values: [
|
|
34
34
|
{
|
|
35
|
-
kind:
|
|
35
|
+
kind: graphql_1.Kind.STRING,
|
|
36
36
|
value: constants_1.ALL_GRAPHQL_FILES,
|
|
37
37
|
},
|
|
38
38
|
],
|
|
@@ -55,7 +55,7 @@ const createOrUpdateSdlDirective = (importedGraphQLFiles, allGraphQLFiles, origS
|
|
|
55
55
|
allGraphQLFiles.forEach(file => fileset.add(normalizePathSep(file)));
|
|
56
56
|
}
|
|
57
57
|
filesValueNodes.values = [...fileset].map(file => ({
|
|
58
|
-
kind:
|
|
58
|
+
kind: graphql_1.Kind.STRING,
|
|
59
59
|
value: file,
|
|
60
60
|
}));
|
|
61
61
|
}
|
|
@@ -66,18 +66,18 @@ const createOrUpdateSdlDirective = (importedGraphQLFiles, allGraphQLFiles, origS
|
|
|
66
66
|
exports.createOrUpdateSdlDirective = createOrUpdateSdlDirective;
|
|
67
67
|
const createSchemaElement = (importedGraphQLFiles, allGraphQLFiles) => {
|
|
68
68
|
const schemaElement = {
|
|
69
|
-
kind:
|
|
69
|
+
kind: graphql_1.Kind.SCHEMA_DEFINITION,
|
|
70
70
|
directives: [
|
|
71
71
|
(0, exports.createOrUpdateSdlDirective)(importedGraphQLFiles, allGraphQLFiles),
|
|
72
72
|
],
|
|
73
73
|
operationTypes: [
|
|
74
74
|
{
|
|
75
|
-
kind:
|
|
76
|
-
operation:
|
|
75
|
+
kind: graphql_1.Kind.OPERATION_TYPE_DEFINITION,
|
|
76
|
+
operation: graphql_1.OperationTypeNode.QUERY,
|
|
77
77
|
type: {
|
|
78
|
-
kind:
|
|
78
|
+
kind: graphql_1.Kind.NAMED_TYPE,
|
|
79
79
|
name: {
|
|
80
|
-
kind:
|
|
80
|
+
kind: graphql_1.Kind.NAME,
|
|
81
81
|
value: 'Query',
|
|
82
82
|
},
|
|
83
83
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"set-files-in-sdl.js","sourceRoot":"","sources":["../../src/utils/set-files-in-sdl.ts"],"names":[],"mappings":";;;AAAA,yBAAwB;AAExB,
|
|
1
|
+
{"version":3,"file":"set-files-in-sdl.js","sourceRoot":"","sources":["../../src/utils/set-files-in-sdl.ts"],"names":[],"mappings":";;;AAAA,yBAAwB;AAExB,qCAUgB;AAChB,6BAA4B;AAE5B,uDAA0D;AAC1D,4CAAoC;AACpC,2CAA6C;AAC7C,qEAA2D;AAE3D,MAAM,gBAAgB,GAAG,CAAC,QAAgB,EAAE,EAAE,CAC5C,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;AAErC,MAAM,0BAA0B,GAAG,CACxC,oBAAuC,EACvC,eAAkC,EAClC,gBAA+C,EAC/C,EAAE;IACF,IAAI,YAA+C,CAAA;IACnD,IAAI,gBAAgB,EAAE;QACpB,YAAY,GAAG,IAAA,2BAAS,EAAC,gBAAgB,CAAC,CAAA;KAC3C;SAAM;QACL,YAAY,GAAG;YACb,IAAI,EAAE,cAAI,CAAC,SAAS;YACpB,IAAI,EAAE;gBACJ,IAAI,EAAE,cAAI,CAAC,IAAI;gBACf,KAAK,EAAE,KAAK;aACb;YACD,SAAS,EAAE;gBACT;oBACE,IAAI,EAAE,cAAI,CAAC,QAAQ;oBACnB,IAAI,EAAE;wBACJ,IAAI,EAAE,cAAI,CAAC,IAAI;wBACf,KAAK,EAAE,OAAO;qBACf;oBACD,KAAK,EAAE;wBACL,IAAI,EAAE,cAAI,CAAC,IAAI;wBACf,MAAM,EAAE;4BACN;gCACE,IAAI,EAAE,cAAI,CAAC,MAAM;gCACjB,KAAK,EAAE,6BAAiB;6BACzB;yBACF;qBACF;iBACF;aACF;SACF,CAAA;KACF;I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AAU,GAAG,OAAO,CAAC,UAAU,IAAI,EAAE,CAAA;gBAC7C,OAAO,CAAC,UAAU,CAAC,IAAI,CACrB,IAAA,kCAA0B,EAAC,oBAAoB,EAAE,eAAe,CAAC,CAClE,CAAA;aACF;YACD,OAAO,OAAO,CAAA;QAChB,CAAC;KACF,CAAC,CAAA;IAEF,IAAI,CAAC,gBAAgB,EAAE;QACrB,GAAG,GAAG,IAAA,eAAK,EAAC,GAAG,EAAE;YACf,QAAQ,CAAC,IAAI;gBACX,MAAM,OAAO,GAAG,IAAA,2BAAS,EAAC,IAAI,CAAC,CAAA;gBAC/B,OAAO,CAAC,WAAW,CAAC,IAAI,CACtB,IAAA,2BAAmB,EAAC,oBAAoB,EAAE,eAAe,CAAC,CAC3D,CAAA;gBACD,OAAO,OAAO,CAAA;YAChB,CAAC;SACF,CAAC,CAAA;KACH;IAED,EAAE,CAAC,aAAa,CAAC,MAAM,EAAE,IAAA,eAAK,EAAC,GAAG,CAAC,CAAC,CAAA;AACtC,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stepzen/transpiler",
|
|
3
3
|
"description": "The StepZen transpiler",
|
|
4
|
-
"version": "0.28.0-experimental.
|
|
4
|
+
"version": "0.28.0-experimental.f225ee8",
|
|
5
5
|
"author": "Darren Waddell <darren@stepzen.com>",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"files": [
|
|
@@ -22,29 +22,31 @@
|
|
|
22
22
|
"posttest": "prettier . --check"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@graphql-tools/merge": "^
|
|
26
|
-
"@stepzen/fetch": "0.28.0-experimental.
|
|
25
|
+
"@graphql-tools/merge": "^8.3.15",
|
|
26
|
+
"@stepzen/fetch": "0.28.0-experimental.f225ee8",
|
|
27
27
|
"debug": "^4.3.4",
|
|
28
|
-
"dotenv": "^
|
|
28
|
+
"dotenv": "^16.0.3",
|
|
29
29
|
"fs-extra": "^9.1.0",
|
|
30
30
|
"glob": "^7.2.3",
|
|
31
|
-
"graphql": "^
|
|
32
|
-
"inquirer": "^8.2.
|
|
31
|
+
"graphql": "^16.6.0",
|
|
32
|
+
"inquirer": "^8.2.5",
|
|
33
33
|
"lodash": "^4.17.21",
|
|
34
|
-
"prettier": "^2.
|
|
34
|
+
"prettier": "^2.8.3",
|
|
35
35
|
"shelljs": "^0.8.5",
|
|
36
36
|
"yaml": "^1.10.2"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@types/debug": "^4.1.7",
|
|
40
|
-
"@types/fs-extra": "^9.0.
|
|
40
|
+
"@types/fs-extra": "^9.0.13",
|
|
41
41
|
"@types/glob": "^7.2.0",
|
|
42
|
-
"@types/inquirer": "^
|
|
42
|
+
"@types/inquirer": "^8.2.5",
|
|
43
43
|
"@types/lodash": "^4.14.168",
|
|
44
44
|
"@types/mocha": "^8.2.2",
|
|
45
45
|
"@types/mock-fs": "^4.13.0",
|
|
46
|
-
"@types/
|
|
47
|
-
"@types/
|
|
46
|
+
"@types/node": "^14.18.36",
|
|
47
|
+
"@types/node-fetch": "^2.6.2",
|
|
48
|
+
"@types/prettier": "^2.7.2",
|
|
49
|
+
"@types/shelljs": "^0.8.11",
|
|
48
50
|
"chai": "^4.3.4",
|
|
49
51
|
"fancy-test": "^1.4.10",
|
|
50
52
|
"mocha": "^9.0.1",
|
|
@@ -53,5 +55,5 @@
|
|
|
53
55
|
"nyc": "^14.1.1",
|
|
54
56
|
"ts-node": "^10.8.2"
|
|
55
57
|
},
|
|
56
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "f225ee811bee33325d404a0ee11314f8161f6b19"
|
|
57
59
|
}
|
package/src/actions/configure.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as debug from 'debug'
|
|
2
|
-
import * as
|
|
2
|
+
import * as fsx from 'fs-extra'
|
|
3
3
|
import * as glob from 'glob'
|
|
4
4
|
import * as inquirer from 'inquirer'
|
|
5
5
|
import * as path from 'path'
|
|
@@ -29,7 +29,7 @@ export default async (source: string, silent = false, answers: any = {}) => {
|
|
|
29
29
|
for (const y of glob.sync('**/config.yaml', {cwd: source})) {
|
|
30
30
|
const filePath = path.join(source, y)
|
|
31
31
|
|
|
32
|
-
const file =
|
|
32
|
+
const file = fsx.readFileSync(filePath, 'utf8')
|
|
33
33
|
let asYAML
|
|
34
34
|
try {
|
|
35
35
|
asYAML = yaml.parse(file, {schema: 'failsafe'})
|
|
@@ -79,7 +79,7 @@ export default async (source: string, silent = false, answers: any = {}) => {
|
|
|
79
79
|
})) {
|
|
80
80
|
const filePath = path.join(source, j)
|
|
81
81
|
|
|
82
|
-
const file =
|
|
82
|
+
const file = fsx.readFileSync(filePath, 'utf8')
|
|
83
83
|
const asJSON = JSON.parse(file)
|
|
84
84
|
|
|
85
85
|
configJsonCount += 1
|
package/src/actions/lint.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as fsx from 'fs-extra'
|
|
2
2
|
import * as os from 'os'
|
|
3
3
|
import * as path from 'path'
|
|
4
4
|
import * as shell from 'shelljs'
|
|
5
5
|
|
|
6
6
|
import stitch from '../actions/stitch'
|
|
7
7
|
import {getExtensions} from '../utils/merge-helpers'
|
|
8
|
+
import {rmtemp} from '../utils/rmtemp'
|
|
8
9
|
|
|
9
10
|
export default async (
|
|
10
11
|
source: string,
|
|
@@ -14,7 +15,7 @@ export default async (
|
|
|
14
15
|
extensions: '',
|
|
15
16
|
},
|
|
16
17
|
) => {
|
|
17
|
-
if (!
|
|
18
|
+
if (!fsx.existsSync(source)) {
|
|
18
19
|
throw new Error(`Cannot find source directory ${source}`)
|
|
19
20
|
}
|
|
20
21
|
|
|
@@ -24,21 +25,23 @@ export default async (
|
|
|
24
25
|
extensions = await getExtensions()
|
|
25
26
|
}
|
|
26
27
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
let stitched, tmp
|
|
29
|
+
try {
|
|
30
|
+
stitched = stitch(source)
|
|
31
|
+
const index = path.join(stitched, 'index.graphql')
|
|
32
|
+
const graphql = fsx.readFileSync(index, 'utf8')
|
|
30
33
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
34
|
+
tmp = path.join(os.tmpdir(), `stepzen-lint-${Date.now()}`)
|
|
35
|
+
fsx.ensureDirSync(tmp, 0o700)
|
|
36
|
+
const lintFile = path.join(tmp, 'index.graphql')
|
|
37
|
+
fsx.writeFileSync(lintFile, `${extensions}${os.EOL}${os.EOL}${graphql}`)
|
|
35
38
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
(
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
39
|
+
const {stdout} = shell.exec(`npx graphql-schema-linter ${lintFile}`, {
|
|
40
|
+
silent: true,
|
|
41
|
+
})
|
|
42
|
+
console.log(stdout)
|
|
43
|
+
} finally {
|
|
44
|
+
rmtemp(stitched)
|
|
45
|
+
rmtemp(tmp)
|
|
46
|
+
}
|
|
44
47
|
}
|
package/src/actions/merge.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as fsx from 'fs-extra'
|
|
2
2
|
import * as glob from 'glob'
|
|
3
3
|
import {mergeTypeDefs} from '@graphql-tools/merge'
|
|
4
4
|
import {parse, visit} from 'graphql'
|
|
@@ -23,6 +23,7 @@ import setFilesInSDL from '../utils/set-files-in-sdl'
|
|
|
23
23
|
import stripEmptyQueriesAndMutations from '../utils/strip-empty-queries-and-mutations'
|
|
24
24
|
import copyWorkspaceContent from '../utils/copy-workspace-content'
|
|
25
25
|
import {ALL_GRAPHQL_FILES} from '../utils/constants'
|
|
26
|
+
import {rmtemp} from '../utils/rmtemp'
|
|
26
27
|
|
|
27
28
|
// It's safe to use this special placeholder value here: in case of a failure
|
|
28
29
|
// in the merge / import process it will not reach the workspace folder.
|
|
@@ -41,34 +42,26 @@ type Query {
|
|
|
41
42
|
}
|
|
42
43
|
`.trim()
|
|
43
44
|
|
|
44
|
-
export
|
|
45
|
+
export type MergeOptions = {
|
|
46
|
+
answers: any
|
|
47
|
+
output: string | null
|
|
48
|
+
silent: boolean
|
|
49
|
+
/** when `false` merge only covers config files and updates @sdl directrive */
|
|
50
|
+
mergeTypes?: boolean
|
|
51
|
+
/** merge behaviour when a schema with the given name exists in the source */
|
|
52
|
+
onConflict?: 'overwrite' | 'append'
|
|
53
|
+
extensions?: string
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const doMerge = async (
|
|
45
57
|
original: string,
|
|
46
58
|
imported: {
|
|
47
59
|
name: string
|
|
48
60
|
source: string
|
|
49
61
|
},
|
|
50
|
-
options: {
|
|
51
|
-
answers: any
|
|
52
|
-
output: string | null
|
|
53
|
-
silent: boolean
|
|
54
|
-
/** when `false` merge only covers config files and updates @sdl directrive */
|
|
55
|
-
mergeTypes?: boolean
|
|
56
|
-
/** merge behaviour when a schema with the given name exists in the source */
|
|
57
|
-
onConflict?: 'overwrite' | 'append'
|
|
58
|
-
extensions?: string
|
|
59
|
-
} = {
|
|
60
|
-
answers: {},
|
|
61
|
-
output: null,
|
|
62
|
-
silent: false,
|
|
63
|
-
mergeTypes: true,
|
|
64
|
-
onConflict: 'append',
|
|
65
|
-
extensions: '',
|
|
66
|
-
},
|
|
62
|
+
options: MergeOptions & {output: string},
|
|
67
63
|
) => {
|
|
68
|
-
// Make sure there is an output directory
|
|
69
64
|
if (!options.answers) options.answers = {}
|
|
70
|
-
if (!options.output)
|
|
71
|
-
options.output = path.join(os.tmpdir(), `stepzen-tmp-${Date.now()}`)
|
|
72
65
|
if (!options.silent) options.silent = false
|
|
73
66
|
if (options.mergeTypes === undefined) options.mergeTypes = true
|
|
74
67
|
if (options.onConflict === undefined) options.onConflict = 'append'
|
|
@@ -79,19 +72,19 @@ export default async (
|
|
|
79
72
|
options.output = dedupeTempFolder(options.output)
|
|
80
73
|
|
|
81
74
|
// Ensure original, importing and output directories exist
|
|
82
|
-
if (!
|
|
75
|
+
if (!fsx.existsSync(original))
|
|
83
76
|
throw new Error(`Cannot find original directory ${original}`)
|
|
84
|
-
if (!
|
|
77
|
+
if (!fsx.existsSync(imported.source))
|
|
85
78
|
throw new Error(`Cannot find imported source directory ${imported.source}`)
|
|
86
|
-
|
|
79
|
+
fsx.ensureDirSync(options.output, 0o700)
|
|
87
80
|
|
|
88
81
|
// Copy the original into the output.
|
|
89
82
|
copyWorkspaceContent(original, options.output)
|
|
90
83
|
|
|
91
84
|
// Ensure an index.graphql exists
|
|
92
85
|
const outputIndex = path.join(options.output, 'index.graphql')
|
|
93
|
-
if (!
|
|
94
|
-
|
|
86
|
+
if (!fsx.existsSync(outputIndex)) {
|
|
87
|
+
fsx.writeFileSync(
|
|
95
88
|
outputIndex,
|
|
96
89
|
options.mergeTypes
|
|
97
90
|
? // (2022-03-09, vluakshov) Not sure what'd break without the
|
|
@@ -132,11 +125,11 @@ export default async (
|
|
|
132
125
|
|
|
133
126
|
const details = {
|
|
134
127
|
original: glob.sync('**/*.graphql', {cwd: options.output}).map(file => {
|
|
135
|
-
const content =
|
|
128
|
+
const content = fsx.readFileSync(`${options.output}/${file}`, 'utf8')
|
|
136
129
|
return {ast: parse(content), file}
|
|
137
130
|
}),
|
|
138
131
|
imported: glob.sync('**/*.graphql', {cwd: imported.source}).map(file => {
|
|
139
|
-
const content =
|
|
132
|
+
const content = fsx.readFileSync(`${imported.source}/${file}`, 'utf8')
|
|
140
133
|
return {ast: parse(content), file}
|
|
141
134
|
}),
|
|
142
135
|
}
|
|
@@ -197,8 +190,8 @@ export default async (
|
|
|
197
190
|
const file = path.join(options.output as any, a.file)
|
|
198
191
|
const deduped = dedupeTempFolder(file)
|
|
199
192
|
|
|
200
|
-
|
|
201
|
-
|
|
193
|
+
fsx.ensureFileSync(deduped)
|
|
194
|
+
fsx.writeFileSync(deduped, print(a.ast))
|
|
202
195
|
})
|
|
203
196
|
|
|
204
197
|
cleaned.imported.forEach(a => {
|
|
@@ -206,21 +199,21 @@ export default async (
|
|
|
206
199
|
const file = path.join(options.output as any, targetSubfolder, a.file)
|
|
207
200
|
const deduped = dedupeTempFolder(file)
|
|
208
201
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
importedGraphQLFiles.push(path.relative(options.output
|
|
202
|
+
fsx.ensureFileSync(deduped)
|
|
203
|
+
fsx.writeFileSync(deduped, print(a.ast))
|
|
204
|
+
importedGraphQLFiles.push(path.relative(options.output, deduped))
|
|
212
205
|
})
|
|
213
206
|
} else {
|
|
214
207
|
glob.sync('**/*.graphql', {cwd: imported.source}).forEach(relativePath => {
|
|
215
208
|
const importedFullPath = path.join(imported.source, relativePath)
|
|
216
209
|
const targetFullPath = path.join(
|
|
217
|
-
options.output
|
|
210
|
+
options.output,
|
|
218
211
|
targetSubfolder,
|
|
219
212
|
relativePath,
|
|
220
213
|
)
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
importedGraphQLFiles.push(path.relative(options.output
|
|
214
|
+
fsx.ensureDirSync(path.dirname(targetFullPath))
|
|
215
|
+
fsx.copyFileSync(importedFullPath, targetFullPath)
|
|
216
|
+
importedGraphQLFiles.push(path.relative(options.output, targetFullPath))
|
|
224
217
|
})
|
|
225
218
|
}
|
|
226
219
|
|
|
@@ -235,9 +228,47 @@ export default async (
|
|
|
235
228
|
)
|
|
236
229
|
if (config) {
|
|
237
230
|
const configFile = path.join(options.output, 'config.yaml')
|
|
238
|
-
|
|
231
|
+
fsx.writeFileSync(configFile, config as string, {mode: 0o600})
|
|
239
232
|
}
|
|
240
233
|
|
|
241
234
|
// Return a merged schema!
|
|
242
235
|
return options.output
|
|
243
236
|
}
|
|
237
|
+
|
|
238
|
+
const merge = (
|
|
239
|
+
original: string,
|
|
240
|
+
imported: {
|
|
241
|
+
name: string
|
|
242
|
+
source: string
|
|
243
|
+
},
|
|
244
|
+
options: MergeOptions = {
|
|
245
|
+
answers: {},
|
|
246
|
+
output: null,
|
|
247
|
+
silent: false,
|
|
248
|
+
mergeTypes: true,
|
|
249
|
+
onConflict: 'append',
|
|
250
|
+
extensions: '',
|
|
251
|
+
},
|
|
252
|
+
) => {
|
|
253
|
+
// Make sure there is an output directory
|
|
254
|
+
if (options.output) {
|
|
255
|
+
return doMerge(
|
|
256
|
+
original,
|
|
257
|
+
imported,
|
|
258
|
+
options as MergeOptions & {output: string},
|
|
259
|
+
)
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
const output = path.join(os.tmpdir(), `stepzen-tmp-${Date.now()}`)
|
|
263
|
+
try {
|
|
264
|
+
return doMerge(original, imported, {...options, output})
|
|
265
|
+
} catch (error) {
|
|
266
|
+
// In case of an error delete the temp output folder created earlier so that
|
|
267
|
+
// it does not "leak". In case of a success, deleting the output folder is
|
|
268
|
+
// the caller responsibility.
|
|
269
|
+
rmtemp(output)
|
|
270
|
+
throw error
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
export default merge
|