@soda-gql/tsc 0.11.0
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/dist/index.cjs +4 -0
- package/dist/index.d.cts +53 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +53 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +3 -0
- package/dist/plugin.cjs +65 -0
- package/dist/plugin.cjs.map +1 -0
- package/dist/plugin.d.cts +19 -0
- package/dist/plugin.d.cts.map +1 -0
- package/dist/plugin.d.mts +19 -0
- package/dist/plugin.d.mts.map +1 -0
- package/dist/plugin.mjs +64 -0
- package/dist/plugin.mjs.map +1 -0
- package/dist/transformer-B1hCHut3.cjs +616 -0
- package/dist/transformer-B1hCHut3.cjs.map +1 -0
- package/dist/transformer-CnlBqU3I.mjs +572 -0
- package/dist/transformer-CnlBqU3I.mjs.map +1 -0
- package/package.json +75 -0
package/dist/index.cjs
ADDED
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { BuilderArtifact, GraphqlSystemIdentifyHelper } from "@soda-gql/builder";
|
|
2
|
+
import { ResolvedSodaGqlConfig } from "@soda-gql/config";
|
|
3
|
+
import * as ts$1 from "typescript";
|
|
4
|
+
import ts from "typescript";
|
|
5
|
+
|
|
6
|
+
//#region packages/tsc/src/ast/imports.d.ts
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Create an "after" transformer that stubs out require() calls for the runtimeModule.
|
|
10
|
+
* This runs after TypeScript's own transformers (including CommonJS down-leveling),
|
|
11
|
+
* so we can replace `const X = require("@/graphql-system")` with a lightweight stub.
|
|
12
|
+
*
|
|
13
|
+
* This prevents the heavy graphql-system module from being loaded at runtime.
|
|
14
|
+
*/
|
|
15
|
+
declare const createAfterStubTransformer: ({
|
|
16
|
+
sourceFile,
|
|
17
|
+
graphqlSystemIdentifyHelper
|
|
18
|
+
}: {
|
|
19
|
+
sourceFile: ts.SourceFile;
|
|
20
|
+
graphqlSystemIdentifyHelper: GraphqlSystemIdentifyHelper;
|
|
21
|
+
}) => ts.TransformerFactory<ts.SourceFile>;
|
|
22
|
+
//#endregion
|
|
23
|
+
//#region packages/tsc/src/transformer.d.ts
|
|
24
|
+
/**
|
|
25
|
+
* TypeScript-specific environment required for the adapter.
|
|
26
|
+
*/
|
|
27
|
+
type TypeScriptEnv = {
|
|
28
|
+
readonly sourceFile: ts$1.SourceFile;
|
|
29
|
+
readonly context: ts$1.TransformationContext;
|
|
30
|
+
};
|
|
31
|
+
declare const createTransformer: ({
|
|
32
|
+
compilerOptions,
|
|
33
|
+
config,
|
|
34
|
+
artifact
|
|
35
|
+
}: {
|
|
36
|
+
readonly compilerOptions: ts$1.CompilerOptions;
|
|
37
|
+
readonly config: ResolvedSodaGqlConfig;
|
|
38
|
+
readonly artifact: BuilderArtifact;
|
|
39
|
+
}) => {
|
|
40
|
+
transform: ({
|
|
41
|
+
sourceFile,
|
|
42
|
+
context
|
|
43
|
+
}: {
|
|
44
|
+
sourceFile: ts$1.SourceFile;
|
|
45
|
+
context: ts$1.TransformationContext;
|
|
46
|
+
}) => {
|
|
47
|
+
transformed: boolean;
|
|
48
|
+
sourceFile: ts$1.SourceFile;
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
//#endregion
|
|
52
|
+
export { type TypeScriptEnv, createAfterStubTransformer, createTransformer };
|
|
53
|
+
//# sourceMappingURL=index.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/ast/imports.ts","../src/transformer.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;;cAoMa;;;;cAIC,EAAA,CAAG;+BACc;MAC3B,EAAA,CAAG,mBAAmB,EAAA,CAAG;;;;;;AADE,KCtLnB,aAAA,GDsLmB;EACF,SAAA,UAAA,ECtLN,IAAA,CAAG,UDsLG;EAAtB,SAAA,OAAA,ECrLa,IAAA,CAAG,qBDqLhB;CAAkB;cCpKZ;;;;AAAb;4BAK4B,IAAA,CAAG;mBACZ;EAzBP,SAAA,QAAa,EA0BJ,eAzBK;AAkB1B,CAAA,EAAA,GAAa;EAAqB,SAAA,EAAA,CAAA;IAAA,UAAA;IAAA;EAKN,CALM,EAAA;IAAA,UAAA,EAqFqB,IAAA,CAAG,UArFxB;IAAA,OAAA,EAqF6C,IAAA,CAAG,qBArFhD;EAKN,CAAA,EAAG,GAAA;IACZ,WAAA,EAAA,OAAA;IACE,UAAA,iBAAA"}
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { BuilderArtifact, GraphqlSystemIdentifyHelper } from "@soda-gql/builder";
|
|
2
|
+
import * as ts$1 from "typescript";
|
|
3
|
+
import ts from "typescript";
|
|
4
|
+
import { ResolvedSodaGqlConfig } from "@soda-gql/config";
|
|
5
|
+
|
|
6
|
+
//#region packages/tsc/src/ast/imports.d.ts
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Create an "after" transformer that stubs out require() calls for the runtimeModule.
|
|
10
|
+
* This runs after TypeScript's own transformers (including CommonJS down-leveling),
|
|
11
|
+
* so we can replace `const X = require("@/graphql-system")` with a lightweight stub.
|
|
12
|
+
*
|
|
13
|
+
* This prevents the heavy graphql-system module from being loaded at runtime.
|
|
14
|
+
*/
|
|
15
|
+
declare const createAfterStubTransformer: ({
|
|
16
|
+
sourceFile,
|
|
17
|
+
graphqlSystemIdentifyHelper
|
|
18
|
+
}: {
|
|
19
|
+
sourceFile: ts.SourceFile;
|
|
20
|
+
graphqlSystemIdentifyHelper: GraphqlSystemIdentifyHelper;
|
|
21
|
+
}) => ts.TransformerFactory<ts.SourceFile>;
|
|
22
|
+
//#endregion
|
|
23
|
+
//#region packages/tsc/src/transformer.d.ts
|
|
24
|
+
/**
|
|
25
|
+
* TypeScript-specific environment required for the adapter.
|
|
26
|
+
*/
|
|
27
|
+
type TypeScriptEnv = {
|
|
28
|
+
readonly sourceFile: ts$1.SourceFile;
|
|
29
|
+
readonly context: ts$1.TransformationContext;
|
|
30
|
+
};
|
|
31
|
+
declare const createTransformer: ({
|
|
32
|
+
compilerOptions,
|
|
33
|
+
config,
|
|
34
|
+
artifact
|
|
35
|
+
}: {
|
|
36
|
+
readonly compilerOptions: ts$1.CompilerOptions;
|
|
37
|
+
readonly config: ResolvedSodaGqlConfig;
|
|
38
|
+
readonly artifact: BuilderArtifact;
|
|
39
|
+
}) => {
|
|
40
|
+
transform: ({
|
|
41
|
+
sourceFile,
|
|
42
|
+
context
|
|
43
|
+
}: {
|
|
44
|
+
sourceFile: ts$1.SourceFile;
|
|
45
|
+
context: ts$1.TransformationContext;
|
|
46
|
+
}) => {
|
|
47
|
+
transformed: boolean;
|
|
48
|
+
sourceFile: ts$1.SourceFile;
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
//#endregion
|
|
52
|
+
export { type TypeScriptEnv, createAfterStubTransformer, createTransformer };
|
|
53
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/ast/imports.ts","../src/transformer.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;;cAoMa;;;;cAIC,EAAA,CAAG;+BACc;MAC3B,EAAA,CAAG,mBAAmB,EAAA,CAAG;;;;;;AADE,KCtLnB,aAAA,GDsLmB;EACF,SAAA,UAAA,ECtLN,IAAA,CAAG,UDsLG;EAAtB,SAAA,OAAA,ECrLa,IAAA,CAAG,qBDqLhB;CAAkB;cCpKZ;;;;AAAb;4BAK4B,IAAA,CAAG;mBACZ;EAzBP,SAAA,QAAa,EA0BJ,eAzBK;AAkB1B,CAAA,EAAA,GAAa;EAAqB,SAAA,EAAA,CAAA;IAAA,UAAA;IAAA;EAKN,CALM,EAAA;IAAA,UAAA,EAqFqB,IAAA,CAAG,UArFxB;IAAA,OAAA,EAqF6C,IAAA,CAAG,qBArFhD;EAKN,CAAA,EAAG,GAAA;IACZ,WAAA,EAAA,OAAA;IACE,UAAA,iBAAA"}
|
package/dist/index.mjs
ADDED
package/dist/plugin.cjs
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
const require_transformer = require('./transformer-B1hCHut3.cjs');
|
|
2
|
+
let __soda_gql_builder = require("@soda-gql/builder");
|
|
3
|
+
let __soda_gql_common = require("@soda-gql/common");
|
|
4
|
+
let __soda_gql_config = require("@soda-gql/config");
|
|
5
|
+
|
|
6
|
+
//#region packages/tsc/src/plugin.ts
|
|
7
|
+
/**
|
|
8
|
+
* TypeScript compiler plugin entrypoint for soda-gql.
|
|
9
|
+
*
|
|
10
|
+
* This module provides TypeScript transformer integration for soda-gql
|
|
11
|
+
* when using Nest CLI with `builder: "tsc"`.
|
|
12
|
+
*/
|
|
13
|
+
const fallbackPlugin = { before: (_options, _program) => {
|
|
14
|
+
return (_context) => {
|
|
15
|
+
return (sourceFile) => sourceFile;
|
|
16
|
+
};
|
|
17
|
+
} };
|
|
18
|
+
const createTscPlugin = (options = {}) => {
|
|
19
|
+
if (!(options.enabled ?? true)) return fallbackPlugin;
|
|
20
|
+
const configResult = (0, __soda_gql_config.loadConfig)(options.configPath);
|
|
21
|
+
if (configResult.isErr()) {
|
|
22
|
+
console.error(`[@soda-gql/tsc] Failed to load config: ${configResult.error.message}`);
|
|
23
|
+
return fallbackPlugin;
|
|
24
|
+
}
|
|
25
|
+
const config = configResult.value;
|
|
26
|
+
const ensureBuilderService = (0, __soda_gql_common.cachedFn)(() => (0, __soda_gql_builder.createBuilderService)({ config }));
|
|
27
|
+
return { before(_options, program) {
|
|
28
|
+
const buildResult = ensureBuilderService().build();
|
|
29
|
+
if (buildResult.isErr()) {
|
|
30
|
+
console.error(`[@soda-gql/tsc] Failed to build initial artifact: ${buildResult.error.message}`);
|
|
31
|
+
return fallbackPlugin.before(_options, program);
|
|
32
|
+
}
|
|
33
|
+
const artifact = buildResult.value;
|
|
34
|
+
const transformer = require_transformer.createTransformer({
|
|
35
|
+
compilerOptions: program.getCompilerOptions(),
|
|
36
|
+
config,
|
|
37
|
+
artifact
|
|
38
|
+
});
|
|
39
|
+
console.log("[@soda-gql/tsc] Transforming program");
|
|
40
|
+
return (context) => {
|
|
41
|
+
return (sourceFile) => {
|
|
42
|
+
if (sourceFile.isDeclarationFile) return sourceFile;
|
|
43
|
+
const transformResult = transformer.transform({
|
|
44
|
+
sourceFile,
|
|
45
|
+
context
|
|
46
|
+
});
|
|
47
|
+
if (!transformResult.transformed) return sourceFile;
|
|
48
|
+
return transformResult.sourceFile;
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
} };
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Create a TypeScript transformer for testing purposes.
|
|
55
|
+
* This is a helper that wraps createTscPlugin to match the signature expected by tests.
|
|
56
|
+
*/
|
|
57
|
+
const createSodaGqlTransformer = (program, options = {}) => {
|
|
58
|
+
return createTscPlugin(options).before({}, program);
|
|
59
|
+
};
|
|
60
|
+
var plugin_default = createTscPlugin();
|
|
61
|
+
|
|
62
|
+
//#endregion
|
|
63
|
+
exports.createSodaGqlTransformer = createSodaGqlTransformer;
|
|
64
|
+
exports.createTscPlugin = createTscPlugin;
|
|
65
|
+
//# sourceMappingURL=plugin.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.cjs","names":["createTransformer"],"sources":["../src/plugin.ts"],"sourcesContent":["/**\n * TypeScript compiler plugin entrypoint for soda-gql.\n *\n * This module provides TypeScript transformer integration for soda-gql\n * when using Nest CLI with `builder: \"tsc\"`.\n */\n\nimport { createBuilderService } from \"@soda-gql/builder\";\nimport { cachedFn } from \"@soda-gql/common\";\nimport { loadConfig } from \"@soda-gql/config\";\nimport type * as ts from \"typescript\";\nimport { createTransformer } from \"./transformer\";\n\nexport type PluginOptions = {\n readonly configPath?: string;\n readonly enabled?: boolean;\n};\n\nconst fallbackPlugin = {\n before: (_options: unknown, _program: ts.Program): ts.TransformerFactory<ts.SourceFile> => {\n return (_context: ts.TransformationContext): ts.Transformer<ts.SourceFile> => {\n return (sourceFile: ts.SourceFile) => sourceFile;\n };\n },\n};\n\nexport const createTscPlugin = (options: PluginOptions = {}) => {\n const enabled = options.enabled ?? true;\n if (!enabled) {\n return fallbackPlugin;\n }\n\n const configResult = loadConfig(options.configPath);\n if (configResult.isErr()) {\n console.error(`[@soda-gql/tsc] Failed to load config: ${configResult.error.message}`);\n return fallbackPlugin;\n }\n\n const config = configResult.value;\n const ensureBuilderService = cachedFn(() => createBuilderService({ config }));\n\n const plugin = {\n /**\n * TypeScript Compiler Plugin hook: before() transformer.\n *\n * This function is called by TypeScript Compiler Plugin with (options, program) signature.\n * It must be exported as a top-level named export for CommonJS compatibility.\n */\n before(_options: unknown, program: ts.Program): ts.TransformerFactory<ts.SourceFile> {\n const builderService = ensureBuilderService();\n const buildResult = builderService.build();\n if (buildResult.isErr()) {\n console.error(`[@soda-gql/tsc] Failed to build initial artifact: ${buildResult.error.message}`);\n return fallbackPlugin.before(_options, program);\n }\n\n const artifact = buildResult.value;\n const compilerOptions = program.getCompilerOptions();\n const transformer = createTransformer({ compilerOptions, config, artifact });\n console.log(\"[@soda-gql/tsc] Transforming program\");\n\n return (context: ts.TransformationContext) => {\n return (sourceFile: ts.SourceFile) => {\n // Skip declaration files\n if (sourceFile.isDeclarationFile) {\n return sourceFile;\n }\n\n const transformResult = transformer.transform({ sourceFile, context });\n if (!transformResult.transformed) {\n return sourceFile;\n }\n\n return transformResult.sourceFile;\n };\n };\n },\n };\n\n return plugin;\n};\n\n/**\n * Create a TypeScript transformer for testing purposes.\n * This is a helper that wraps createTscPlugin to match the signature expected by tests.\n */\nexport const createSodaGqlTransformer = (\n program: ts.Program,\n options: PluginOptions = {},\n): ts.TransformerFactory<ts.SourceFile> => {\n const plugin = createTscPlugin(options);\n return plugin.before({}, program);\n};\n\nexport default createTscPlugin();\n"],"mappings":";;;;;;;;;;;;AAkBA,MAAM,iBAAiB,EACrB,SAAS,UAAmB,aAA+D;AACzF,SAAQ,aAAsE;AAC5E,UAAQ,eAA8B;;GAG3C;AAED,MAAa,mBAAmB,UAAyB,EAAE,KAAK;AAE9D,KAAI,EADY,QAAQ,WAAW,MAEjC,QAAO;CAGT,MAAM,iDAA0B,QAAQ,WAAW;AACnD,KAAI,aAAa,OAAO,EAAE;AACxB,UAAQ,MAAM,0CAA0C,aAAa,MAAM,UAAU;AACrF,SAAO;;CAGT,MAAM,SAAS,aAAa;CAC5B,MAAM,0GAA2D,EAAE,QAAQ,CAAC,CAAC;AAwC7E,QAtCe,EAOb,OAAO,UAAmB,SAA2D;EAEnF,MAAM,cADiB,sBAAsB,CACV,OAAO;AAC1C,MAAI,YAAY,OAAO,EAAE;AACvB,WAAQ,MAAM,qDAAqD,YAAY,MAAM,UAAU;AAC/F,UAAO,eAAe,OAAO,UAAU,QAAQ;;EAGjD,MAAM,WAAW,YAAY;EAE7B,MAAM,cAAcA,sCAAkB;GAAE,iBADhB,QAAQ,oBAAoB;GACK;GAAQ;GAAU,CAAC;AAC5E,UAAQ,IAAI,uCAAuC;AAEnD,UAAQ,YAAsC;AAC5C,WAAQ,eAA8B;AAEpC,QAAI,WAAW,kBACb,QAAO;IAGT,MAAM,kBAAkB,YAAY,UAAU;KAAE;KAAY;KAAS,CAAC;AACtE,QAAI,CAAC,gBAAgB,YACnB,QAAO;AAGT,WAAO,gBAAgB;;;IAI9B;;;;;;AASH,MAAa,4BACX,SACA,UAAyB,EAAE,KACc;AAEzC,QADe,gBAAgB,QAAQ,CACzB,OAAO,EAAE,EAAE,QAAQ;;AAGnC,qBAAe,iBAAiB"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import * as ts$1 from "typescript";
|
|
2
|
+
|
|
3
|
+
//#region packages/tsc/src/plugin.d.ts
|
|
4
|
+
|
|
5
|
+
type PluginOptions = {
|
|
6
|
+
readonly configPath?: string;
|
|
7
|
+
readonly enabled?: boolean;
|
|
8
|
+
};
|
|
9
|
+
declare const createTscPlugin: (options?: PluginOptions) => {
|
|
10
|
+
before: (_options: unknown, _program: ts$1.Program) => ts$1.TransformerFactory<ts$1.SourceFile>;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Create a TypeScript transformer for testing purposes.
|
|
14
|
+
* This is a helper that wraps createTscPlugin to match the signature expected by tests.
|
|
15
|
+
*/
|
|
16
|
+
declare const createSodaGqlTransformer: (program: ts$1.Program, options?: PluginOptions) => ts$1.TransformerFactory<ts$1.SourceFile>;
|
|
17
|
+
//#endregion
|
|
18
|
+
export { PluginOptions, createSodaGqlTransformer, createTscPlugin };
|
|
19
|
+
//# sourceMappingURL=plugin.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.d.cts","names":[],"sources":["../src/plugin.ts"],"sourcesContent":[],"mappings":";;;;AAmB8E,KANlE,aAAA,GAMkE;EAAzB,SAAG,UAAA,CAAA,EAAA,MAAA;EAAkB,SAAA,OAAA,CAAA,EAAA,OAAA;AAmE1E,CAAA;AACc,cA7DD,eA6DC,EAAA,CAAA,OAAA,CAAA,EA7D2B,aA6D3B,EAAA,GAAA;EACH,MAAA,EAAA,CAAA,QAAA,EAAA,OAAA,EAAA,QAAA,EArE6B,IAAA,CAAG,OAqEhC,EAAA,GArE0C,IAAA,CAAG,kBAqE7C,CArEgE,IAAA,CAAG,UAqEnE,CAAA;CACc;;;;;cAHZ,oCACF,IAAA,CAAG,mBACH,kBACR,IAAA,CAAG,mBAAmB,IAAA,CAAG"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import * as ts$1 from "typescript";
|
|
2
|
+
|
|
3
|
+
//#region packages/tsc/src/plugin.d.ts
|
|
4
|
+
|
|
5
|
+
type PluginOptions = {
|
|
6
|
+
readonly configPath?: string;
|
|
7
|
+
readonly enabled?: boolean;
|
|
8
|
+
};
|
|
9
|
+
declare const createTscPlugin: (options?: PluginOptions) => {
|
|
10
|
+
before: (_options: unknown, _program: ts$1.Program) => ts$1.TransformerFactory<ts$1.SourceFile>;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Create a TypeScript transformer for testing purposes.
|
|
14
|
+
* This is a helper that wraps createTscPlugin to match the signature expected by tests.
|
|
15
|
+
*/
|
|
16
|
+
declare const createSodaGqlTransformer: (program: ts$1.Program, options?: PluginOptions) => ts$1.TransformerFactory<ts$1.SourceFile>;
|
|
17
|
+
//#endregion
|
|
18
|
+
export { PluginOptions, createSodaGqlTransformer, createTscPlugin };
|
|
19
|
+
//# sourceMappingURL=plugin.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.d.mts","names":[],"sources":["../src/plugin.ts"],"sourcesContent":[],"mappings":";;;;AAmB8E,KANlE,aAAA,GAMkE;EAAzB,SAAG,UAAA,CAAA,EAAA,MAAA;EAAkB,SAAA,OAAA,CAAA,EAAA,OAAA;AAmE1E,CAAA;AACc,cA7DD,eA6DC,EAAA,CAAA,OAAA,CAAA,EA7D2B,aA6D3B,EAAA,GAAA;EACH,MAAA,EAAA,CAAA,QAAA,EAAA,OAAA,EAAA,QAAA,EArE6B,IAAA,CAAG,OAqEhC,EAAA,GArE0C,IAAA,CAAG,kBAqE7C,CArEgE,IAAA,CAAG,UAqEnE,CAAA;CACc;;;;;cAHZ,oCACF,IAAA,CAAG,mBACH,kBACR,IAAA,CAAG,mBAAmB,IAAA,CAAG"}
|
package/dist/plugin.mjs
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { t as createTransformer } from "./transformer-CnlBqU3I.mjs";
|
|
2
|
+
import { createBuilderService } from "@soda-gql/builder";
|
|
3
|
+
import { cachedFn } from "@soda-gql/common";
|
|
4
|
+
import { loadConfig } from "@soda-gql/config";
|
|
5
|
+
|
|
6
|
+
//#region packages/tsc/src/plugin.ts
|
|
7
|
+
/**
|
|
8
|
+
* TypeScript compiler plugin entrypoint for soda-gql.
|
|
9
|
+
*
|
|
10
|
+
* This module provides TypeScript transformer integration for soda-gql
|
|
11
|
+
* when using Nest CLI with `builder: "tsc"`.
|
|
12
|
+
*/
|
|
13
|
+
const fallbackPlugin = { before: (_options, _program) => {
|
|
14
|
+
return (_context) => {
|
|
15
|
+
return (sourceFile) => sourceFile;
|
|
16
|
+
};
|
|
17
|
+
} };
|
|
18
|
+
const createTscPlugin = (options = {}) => {
|
|
19
|
+
if (!(options.enabled ?? true)) return fallbackPlugin;
|
|
20
|
+
const configResult = loadConfig(options.configPath);
|
|
21
|
+
if (configResult.isErr()) {
|
|
22
|
+
console.error(`[@soda-gql/tsc] Failed to load config: ${configResult.error.message}`);
|
|
23
|
+
return fallbackPlugin;
|
|
24
|
+
}
|
|
25
|
+
const config = configResult.value;
|
|
26
|
+
const ensureBuilderService = cachedFn(() => createBuilderService({ config }));
|
|
27
|
+
return { before(_options, program) {
|
|
28
|
+
const buildResult = ensureBuilderService().build();
|
|
29
|
+
if (buildResult.isErr()) {
|
|
30
|
+
console.error(`[@soda-gql/tsc] Failed to build initial artifact: ${buildResult.error.message}`);
|
|
31
|
+
return fallbackPlugin.before(_options, program);
|
|
32
|
+
}
|
|
33
|
+
const artifact = buildResult.value;
|
|
34
|
+
const transformer = createTransformer({
|
|
35
|
+
compilerOptions: program.getCompilerOptions(),
|
|
36
|
+
config,
|
|
37
|
+
artifact
|
|
38
|
+
});
|
|
39
|
+
console.log("[@soda-gql/tsc] Transforming program");
|
|
40
|
+
return (context) => {
|
|
41
|
+
return (sourceFile) => {
|
|
42
|
+
if (sourceFile.isDeclarationFile) return sourceFile;
|
|
43
|
+
const transformResult = transformer.transform({
|
|
44
|
+
sourceFile,
|
|
45
|
+
context
|
|
46
|
+
});
|
|
47
|
+
if (!transformResult.transformed) return sourceFile;
|
|
48
|
+
return transformResult.sourceFile;
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
} };
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Create a TypeScript transformer for testing purposes.
|
|
55
|
+
* This is a helper that wraps createTscPlugin to match the signature expected by tests.
|
|
56
|
+
*/
|
|
57
|
+
const createSodaGqlTransformer = (program, options = {}) => {
|
|
58
|
+
return createTscPlugin(options).before({}, program);
|
|
59
|
+
};
|
|
60
|
+
var plugin_default = createTscPlugin();
|
|
61
|
+
|
|
62
|
+
//#endregion
|
|
63
|
+
export { createSodaGqlTransformer, createTscPlugin };
|
|
64
|
+
//# sourceMappingURL=plugin.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.mjs","names":[],"sources":["../src/plugin.ts"],"sourcesContent":["/**\n * TypeScript compiler plugin entrypoint for soda-gql.\n *\n * This module provides TypeScript transformer integration for soda-gql\n * when using Nest CLI with `builder: \"tsc\"`.\n */\n\nimport { createBuilderService } from \"@soda-gql/builder\";\nimport { cachedFn } from \"@soda-gql/common\";\nimport { loadConfig } from \"@soda-gql/config\";\nimport type * as ts from \"typescript\";\nimport { createTransformer } from \"./transformer\";\n\nexport type PluginOptions = {\n readonly configPath?: string;\n readonly enabled?: boolean;\n};\n\nconst fallbackPlugin = {\n before: (_options: unknown, _program: ts.Program): ts.TransformerFactory<ts.SourceFile> => {\n return (_context: ts.TransformationContext): ts.Transformer<ts.SourceFile> => {\n return (sourceFile: ts.SourceFile) => sourceFile;\n };\n },\n};\n\nexport const createTscPlugin = (options: PluginOptions = {}) => {\n const enabled = options.enabled ?? true;\n if (!enabled) {\n return fallbackPlugin;\n }\n\n const configResult = loadConfig(options.configPath);\n if (configResult.isErr()) {\n console.error(`[@soda-gql/tsc] Failed to load config: ${configResult.error.message}`);\n return fallbackPlugin;\n }\n\n const config = configResult.value;\n const ensureBuilderService = cachedFn(() => createBuilderService({ config }));\n\n const plugin = {\n /**\n * TypeScript Compiler Plugin hook: before() transformer.\n *\n * This function is called by TypeScript Compiler Plugin with (options, program) signature.\n * It must be exported as a top-level named export for CommonJS compatibility.\n */\n before(_options: unknown, program: ts.Program): ts.TransformerFactory<ts.SourceFile> {\n const builderService = ensureBuilderService();\n const buildResult = builderService.build();\n if (buildResult.isErr()) {\n console.error(`[@soda-gql/tsc] Failed to build initial artifact: ${buildResult.error.message}`);\n return fallbackPlugin.before(_options, program);\n }\n\n const artifact = buildResult.value;\n const compilerOptions = program.getCompilerOptions();\n const transformer = createTransformer({ compilerOptions, config, artifact });\n console.log(\"[@soda-gql/tsc] Transforming program\");\n\n return (context: ts.TransformationContext) => {\n return (sourceFile: ts.SourceFile) => {\n // Skip declaration files\n if (sourceFile.isDeclarationFile) {\n return sourceFile;\n }\n\n const transformResult = transformer.transform({ sourceFile, context });\n if (!transformResult.transformed) {\n return sourceFile;\n }\n\n return transformResult.sourceFile;\n };\n };\n },\n };\n\n return plugin;\n};\n\n/**\n * Create a TypeScript transformer for testing purposes.\n * This is a helper that wraps createTscPlugin to match the signature expected by tests.\n */\nexport const createSodaGqlTransformer = (\n program: ts.Program,\n options: PluginOptions = {},\n): ts.TransformerFactory<ts.SourceFile> => {\n const plugin = createTscPlugin(options);\n return plugin.before({}, program);\n};\n\nexport default createTscPlugin();\n"],"mappings":";;;;;;;;;;;;AAkBA,MAAM,iBAAiB,EACrB,SAAS,UAAmB,aAA+D;AACzF,SAAQ,aAAsE;AAC5E,UAAQ,eAA8B;;GAG3C;AAED,MAAa,mBAAmB,UAAyB,EAAE,KAAK;AAE9D,KAAI,EADY,QAAQ,WAAW,MAEjC,QAAO;CAGT,MAAM,eAAe,WAAW,QAAQ,WAAW;AACnD,KAAI,aAAa,OAAO,EAAE;AACxB,UAAQ,MAAM,0CAA0C,aAAa,MAAM,UAAU;AACrF,SAAO;;CAGT,MAAM,SAAS,aAAa;CAC5B,MAAM,uBAAuB,eAAe,qBAAqB,EAAE,QAAQ,CAAC,CAAC;AAwC7E,QAtCe,EAOb,OAAO,UAAmB,SAA2D;EAEnF,MAAM,cADiB,sBAAsB,CACV,OAAO;AAC1C,MAAI,YAAY,OAAO,EAAE;AACvB,WAAQ,MAAM,qDAAqD,YAAY,MAAM,UAAU;AAC/F,UAAO,eAAe,OAAO,UAAU,QAAQ;;EAGjD,MAAM,WAAW,YAAY;EAE7B,MAAM,cAAc,kBAAkB;GAAE,iBADhB,QAAQ,oBAAoB;GACK;GAAQ;GAAU,CAAC;AAC5E,UAAQ,IAAI,uCAAuC;AAEnD,UAAQ,YAAsC;AAC5C,WAAQ,eAA8B;AAEpC,QAAI,WAAW,kBACb,QAAO;IAGT,MAAM,kBAAkB,YAAY,UAAU;KAAE;KAAY;KAAS,CAAC;AACtE,QAAI,CAAC,gBAAgB,YACnB,QAAO;AAGT,WAAO,gBAAgB;;;IAI9B;;;;;;AASH,MAAa,4BACX,SACA,UAAyB,EAAE,KACc;AAEzC,QADe,gBAAgB,QAAQ,CACzB,OAAO,EAAE,EAAE,QAAQ;;AAGnC,qBAAe,iBAAiB"}
|