diff --git a/docs/src/content/docs/structure.md b/docs/src/content/docs/structure.md index 746e814..14b6841 100644 --- a/docs/src/content/docs/structure.md +++ b/docs/src/content/docs/structure.md @@ -38,9 +38,3 @@ const greeting = await actor.greet('World'); ### `.d.ts` This file contains the same TypeScript types as [`.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. diff --git a/src/cli/icp-bindgen.ts b/src/cli/icp-bindgen.ts index 2b4c03d..08d8a77 100644 --- a/src/cli/icp-bindgen.ts +++ b/src/cli/icp-bindgen.ts @@ -43,8 +43,6 @@ * - `--actor-disabled`: If set, skips generating the actor file (`.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 */ diff --git a/src/core/generate/features/canister-env.ts b/src/core/generate/features/canister-env.ts deleted file mode 100644 index 3da9eec..0000000 --- a/src/core/generate/features/canister-env.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { resolve } from 'node:path'; -import { DISCLAIMER_COMMENT, ESLINT_DISABLE_COMMENT } from '../constants'; -import { writeFileSafe } from '../fs.ts'; - -const OUTPUT_CANISTER_ENV_FILE = 'canister-env.d.ts'; - -function envBinding(varNames: string[]): string { - if (varNames.length === 0) { - return ''; - } - - // we don't want to disable typescript checks for this file - let env = `${ESLINT_DISABLE_COMMENT}\n\n${DISCLAIMER_COMMENT}\n\ninterface CanisterEnv {\n`; - for (const varName of varNames) { - env += ` readonly ["${varName}"]: string;\n`; - } - env += '}'; - return env; -} - -export async function generateCanisterEnv(varNames: string[], outDir: string, force: boolean) { - const canisterEnv = envBinding(varNames); - await writeFileSafe(resolve(outDir, OUTPUT_CANISTER_ENV_FILE), canisterEnv, force); -} diff --git a/src/core/generate/features/index.ts b/src/core/generate/features/index.ts deleted file mode 100644 index 1900c87..0000000 --- a/src/core/generate/features/index.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { generateCanisterEnv } from './canister-env.ts'; - -export type GenerateAdditionalFeaturesOptions = { - /** - * If defined, generates a `canister-env.d.ts` file according to the provided options. - */ - canisterEnv?: { - /** - * The variable names to include in the `canister-env.d.ts` file. - */ - variableNames: string[]; - }; -}; - -export async function generateAdditionalFeatures( - options: GenerateAdditionalFeaturesOptions, - outDir: string, - force: boolean, -) { - if (options.canisterEnv) { - await generateCanisterEnv(options.canisterEnv.variableNames, outDir, force); - } -} diff --git a/src/core/generate/index.ts b/src/core/generate/index.ts index 8f2cd8c..5bb2d11 100644 --- a/src/core/generate/index.ts +++ b/src/core/generate/index.ts @@ -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'; /** @@ -63,10 +57,6 @@ export type GenerateOptions = { * Options for controlling the generated output files. */ output?: GenerateOutputOptions; - /** - * Additional features to generate bindings with. - */ - additionalFeatures?: GenerateAdditionalFeaturesOptions; }; /** @@ -118,10 +108,6 @@ export async function generate(options: GenerateOptions) { output, force, }); - - if (options.additionalFeatures) { - await generateAdditionalFeatures(options.additionalFeatures, options.outDir, force); - } } type WriteBindingsOptions = { diff --git a/src/plugins/vite.ts b/src/plugins/vite.ts index 9875df7..c6f8823 100644 --- a/src/plugins/vite.ts +++ b/src/plugins/vite.ts @@ -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)); diff --git a/tests/generate.test.ts b/tests/generate.test.ts index 2c44c8f..a4b3c20 100644 --- a/tests/generate.test.ts +++ b/tests/generate.test.ts @@ -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`; @@ -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 {