agency-lang 0.0.72 → 0.0.74

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.
@@ -6,7 +6,9 @@ export declare function parse(contents: string, config: AgencyConfig): AgencyPro
6
6
  export declare function readFile(inputFile: string): string;
7
7
  export declare function renderGraph(contents: string, config: AgencyConfig): void;
8
8
  export declare function resetCompilationCache(): void;
9
- export declare function compile(config: AgencyConfig, inputFile: string, _outputFile?: string): string | null;
9
+ export declare function compile(config: AgencyConfig, inputFile: string, _outputFile?: string, options?: {
10
+ ts?: boolean;
11
+ }): string | null;
10
12
  export declare function run(config: AgencyConfig, inputFile: string, outputFile?: string, resumeFile?: string): void;
11
13
  export declare function format(contents: string, config: AgencyConfig): Promise<string>;
12
14
  export declare function formatFile(inputPath: string, inPlace: boolean, config: AgencyConfig): void;
@@ -89,19 +89,20 @@ const compiledFiles = new Set();
89
89
  export function resetCompilationCache() {
90
90
  compiledFiles.clear();
91
91
  }
92
- export function compile(config, inputFile, _outputFile) {
92
+ export function compile(config, inputFile, _outputFile, options) {
93
93
  // Check if the input is a directory
94
94
  const stats = fs.statSync(inputFile);
95
95
  const verbose = config.verbose ?? false;
96
96
  if (stats.isDirectory()) {
97
97
  for (const { path } of findRecursively(inputFile)) {
98
- compile(config, path, undefined);
98
+ compile(config, path, undefined, options);
99
99
  }
100
100
  return null;
101
101
  }
102
102
  // Resolve the absolute path of the input file to avoid duplicates
103
103
  const absoluteInputFile = path.resolve(inputFile);
104
- let outputFile = _outputFile || inputFile.replace(".agency", ".js");
104
+ const ext = options?.ts ? ".ts" : ".js";
105
+ let outputFile = _outputFile || inputFile.replace(".agency", ext);
105
106
  if (config.outDir && !_outputFile) {
106
107
  const outputDir = path.resolve(config.outDir);
107
108
  if (!fs.existsSync(outputDir)) {
@@ -140,20 +141,23 @@ export function compile(config, inputFile, _outputFile) {
140
141
  throw new Error(`Import path '${importPath}' resolves to '${absPath}' which is outside the project directory '${projectRoot}'.`);
141
142
  }
142
143
  }
143
- compile(config, absPath, undefined);
144
+ compile(config, absPath, undefined, options);
144
145
  }
145
146
  // Update the import path in the AST to reference the new .ts file
146
147
  parsedProgram.nodes.forEach((node) => {
147
148
  if (node.type === "importStatement") {
148
- node.modulePath = node.modulePath.replace(".agency", ".js");
149
+ node.modulePath = node.modulePath.replace(".agency", ext);
149
150
  }
150
151
  });
151
- const generatedCode = generateTypeScript(parsedProgram, config);
152
+ let generatedCode = generateTypeScript(parsedProgram, config);
153
+ if (options?.ts) {
154
+ generatedCode = "//@ts-nocheck\n" + generatedCode;
155
+ }
152
156
  fs.writeFileSync(outputFile, generatedCode, "utf-8");
153
157
  // Generate .d.ts declarations if enabled
154
158
  if (config.declarations) {
155
159
  const declarations = generateDeclarations(parsedProgram, config);
156
- const dtsFile = outputFile.replace(/\.js$/, ".d.ts");
160
+ const dtsFile = outputFile.replace(/\.(js|ts)$/, ".d.ts");
157
161
  fs.writeFileSync(dtsFile, declarations, "utf-8");
158
162
  console.log(`${inputFile} → ${dtsFile}`);
159
163
  }
@@ -35,10 +35,11 @@ program
35
35
  .alias("build")
36
36
  .description("Compile .agency file(s) or directory(s) to JavaScript")
37
37
  .argument("<inputs...>", "Paths to .agency input files or directories")
38
- .action(async (inputs) => {
38
+ .option("--ts", "Output .ts files with // @no-check header")
39
+ .action(async (inputs, opts) => {
39
40
  const config = getConfig();
40
41
  for (const input of inputs) {
41
- compile(config, input);
42
+ compile(config, input, undefined, { ts: opts.ts });
42
43
  }
43
44
  });
44
45
  program
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agency-lang",
3
- "version": "0.0.72",
3
+ "version": "0.0.74",
4
4
  "description": "The Agency language",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {