Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions docs/src/content/docs/structure.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,3 @@ const greeting = await actor.greet('World');
### `<service-name>.d.ts`

This file contains the same TypeScript types as [`<service-name>.ts`](#service-namets). It is typically used to add to LLMs' contexts' to give knowledge about what types are available in the service. Set the [`output.actor.interfaceFile`](./core/api/type-aliases/GenerateOutputOptions.md#interfaceFile) option to `true` to generate this file.

### `canister-env.d.ts`

This file contains the strongly-typed canister environment variables. It is typically used make the `@icp-sdk/canister-env` package more type-safe. configure the [`additionalFeatures.canisterEnv`](./core/api/type-aliases/GenerateAdditionalFeaturesOptions.md#canisterEnv) option to generate this file.

> Not supported by the CLI yet.
2 changes: 0 additions & 2 deletions src/cli/icp-bindgen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@
* - `--actor-disabled`: If set, skips generating the actor file (`<service-name>.ts`). (default: `false`)
* - `--force`: If set, overwrite existing files instead of aborting. (default: `false`)
*
* > **Note**: The CLI does not support additional features yet.
*
* @module cli
*/

Expand Down
24 changes: 0 additions & 24 deletions src/core/generate/features/canister-env.ts

This file was deleted.

23 changes: 0 additions & 23 deletions src/core/generate/features/index.ts

This file was deleted.

14 changes: 0 additions & 14 deletions src/core/generate/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
import { basename, resolve } from 'node:path';
import { prepareBinding } from './bindings.ts';
import {
type GenerateAdditionalFeaturesOptions,
generateAdditionalFeatures,
} from './features/index.ts';
import { ensureDir, writeFileSafe } from './fs.ts';
import { type WasmGenerateResult, wasmGenerate, wasmInit } from './rs.ts';

export type { GenerateAdditionalFeaturesOptions } from './features/index.ts';

const DID_FILE_EXTENSION = '.did';

/**
Expand Down Expand Up @@ -63,10 +57,6 @@ export type GenerateOptions = {
* Options for controlling the generated output files.
*/
output?: GenerateOutputOptions;
/**
* Additional features to generate bindings with.
*/
additionalFeatures?: GenerateAdditionalFeaturesOptions;
};

/**
Expand Down Expand Up @@ -118,10 +108,6 @@ export async function generate(options: GenerateOptions) {
output,
force,
});

if (options.additionalFeatures) {
await generateAdditionalFeatures(options.additionalFeatures, options.outDir, force);
}
}

type WriteBindingsOptions = {
Expand Down
1 change: 0 additions & 1 deletion src/plugins/vite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ async function run(options: Options) {
// We want to overwrite existing files in the build process
force: true,
},
additionalFeatures: options.additionalFeatures,
});

console.log(cyan(`[${VITE_PLUGIN_NAME}] Bindings generated at`), green(options.outDir));
Expand Down
57 changes: 0 additions & 57 deletions tests/generate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,26 +134,6 @@ describe('generate', () => {
expect(fileExists(otherDidFilePath)).toBe(true);
});

it('should generate a bindgen with canister env feature', async () => {
const helloWorldServiceName = 'hello_world';
const helloWorldDidFile = `${TESTS_ASSETS_DIR}/${helloWorldServiceName}.did`;

await generate({
didFile: helloWorldDidFile,
outDir: OUTPUT_DIR,
additionalFeatures: {
canisterEnv: {
variableNames: ['IC_CANISTER_ID:backend'],
},
},
});

await expectGeneratedOutput(SNAPSHOTS_DIR, helloWorldServiceName);
await expect(await readFileFromOutput('canister-env.d.ts')).toMatchFileSnapshot(
`${SNAPSHOTS_DIR}/${helloWorldServiceName}/canister-env.d.ts.snapshot`,
);
});

it('should abort on existing files unless output.force is true', async () => {
const serviceName = 'hello_world';
const didFile = `${TESTS_ASSETS_DIR}/${serviceName}.did`;
Expand Down Expand Up @@ -185,43 +165,6 @@ describe('generate', () => {
}),
).resolves.toBeUndefined();
});

it('should abort feature file write on collision unless output.force is true', async () => {
const serviceName = 'example';
const didFile = `${TESTS_ASSETS_DIR}/${serviceName}.did`;

// Pre-create canister-env to trigger collision in additional features
vol.mkdirSync(OUTPUT_DIR, { recursive: true });
vol.writeFileSync(`${OUTPUT_DIR}/canister-env.d.ts`, '// existing', { encoding: 'utf-8' });

await expect(
generate({
didFile,
outDir: OUTPUT_DIR,
additionalFeatures: {
canisterEnv: {
variableNames: ['IC_CANISTER_ID:backend'],
},
},
}),
).rejects.toThrow(
/The generated file already exists: .*canister-env\.d\.ts. To overwrite it, use the `force` option./i,
);

// With force, it should overwrite and succeed
await expect(
generate({
didFile,
outDir: OUTPUT_DIR,
output: { force: true },
additionalFeatures: {
canisterEnv: {
variableNames: ['IC_CANISTER_ID:backend'],
},
},
}),
).resolves.toBeUndefined();
});
});

async function readFileFromOutput(path: string): Promise<string> {
Expand Down
Loading