prismicio / prismic-ts-codegen

A Prismic model-to-TypeScript-type generator.
Apache License 2.0
18 stars 6 forks source link

ManipulationError: Manipulation error: A syntax error was inserted. #6

Closed seanlail closed 2 years ago

seanlail commented 2 years ago

Versions

Reproduction

Not sure what this error means

ManipulationError: Manipulation error: A syntax error was inserted.
Error replacing tree: The children of the old and new trees were expected to have the same count (6:10).

Full error log below:

Error log
```bash > prismic-ts-codegen ManipulationError: Manipulation error: A syntax error was inserted. types.d.ts:18:5 - error TS1131: Property or signature expected. 18 main-image: prismicT.ImageField; ~~~~ types.d.ts:18:15 - error TS1005: ';' expected. 18 main-image: prismicT.ImageField; ~ types.d.ts:18:42 - error TS1005: '(' expected. 18 main-image: prismicT.ImageField; ~ types.d.ts:19:1 - error TS1128: Declaration or statement expected. 19 } ~ Error replacing tree: The children of the old and new trees were expected to have the same count (6:10). -- Details -- Path: /types.d.ts Text: "...eyof T]: T[KeyType] };\n\n/** Content for ArticlePage documents */\ninterface ArticlepageDocumentData {\n /**\n * main-image field in *ArticlePage*\n *\n * - **Field Type**: Image\n * - **Placeholder**: *None*\n * - **API ID Path**: articlepage.main-image\n * - **Documentation**: https://prismic.io/docs/core-concepts/image\n *\n */\n main-image: prismicT.ImageField;\n}\n" Stack: Error: Error replacing tree: The children of the old and new trees were expected to have the same count (6:10). at ParentFinderReplacementNodeHandler.handleChildren (/Users/x/node_modules/ts-morph/dist/ts-morph.js:1438:19) at ParentFinderReplacementNodeHandler.handleNode (/Users/x/node_modules/ts-morph/dist/ts-morph.js:1432:18) at ParentFinderReplacementNodeHandler.handleNode (/Users/x/node_modules/ts-morph/dist/ts-morph.js:1572:19) at NodeHandlerHelper.handleForValues (/Users/x/node_modules/ts-morph/dist/ts-morph.js:1375:21) at ParentFinderReplacementNodeHandler.handleChildren (/Users/x/node_modules/ts-morph/dist/ts-morph.js:1442:25) at ParentFinderReplacementNodeHandler.handleNode (/Users/x/node_modules/ts-morph/dist/ts-morph.js:1432:18) at ParentFinderReplacementNodeHandler.handleNode (/Users/x/node_modules/ts-morph/dist/ts-morph.js:1572:19) at doManipulation (/Users/x/node_modules/ts-morph/dist/ts-morph.js:2284:21) at insertIntoBracesOrSourceFile (/Users/x/node_modules/ts-morph/dist/ts-morph.js:2488:5) at insertIntoBracesOrSourceFileWithGetChildren (/Users/x/node_modules/ts-morph/dist/ts-morph.js:2519:5) at throwError (/Users/x/node_modules/ts-morph/dist/ts-morph.js:2300:19) at doManipulation (/Users/x/node_modules/ts-morph/dist/ts-morph.js:2294:13) at insertIntoBracesOrSourceFile (/Users/x/node_modules/ts-morph/dist/ts-morph.js:2488:5) at insertIntoBracesOrSourceFileWithGetChildren (/Users/x/node_modules/ts-morph/dist/ts-morph.js:2519:5) at insertChildren$1 (/Users/x/node_modules/ts-morph/dist/ts-morph.js:10346:12) at InterfaceDeclaration.insertProperties (/Users/x/node_modules/ts-morph/dist/ts-morph.js:10284:20) at InterfaceDeclaration.addProperties (/Users/x/node_modules/ts-morph/dist/ts-morph.js:10278:25) at InterfaceDeclaration.addProperty (/Users/x/node_modules/ts-morph/dist/ts-morph.js:10275:25) at addInterfacePropertyFromField (file:///Users/x/node_modules/prismic-ts-codegen/bin/cli.mjs:314:26) at addInterfacePropertiesForFields (file:///Users/x/node_modules/prismic-ts-codegen/bin/cli.mjs:672:5) { filePath: '/types.d.ts', oldText: '// Code generated by prismic-ts-codegen. DO NOT EDIT.\n' + '// ___BLANK_LINE_TO_BE_REPLACED___\n' + 'import type * as prismicT from "@prismicio/types";\n' + '// ___BLANK_LINE_TO_BE_REPLACED___\n' + 'type Simplify = { [KeyType in keyof T]: T[KeyType] };\n' + '\n' + '/** Content for ArticlePage documents */\n' + 'interface ArticlepageDocumentData {\n' + '}\n', newText: '// Code generated by prismic-ts-codegen. DO NOT EDIT.\n' + '// ___BLANK_LINE_TO_BE_REPLACED___\n' + 'import type * as prismicT from "@prismicio/types";\n' + '// ___BLANK_LINE_TO_BE_REPLACED___\n' + 'type Simplify = { [KeyType in keyof T]: T[KeyType] };\n' + '\n' + '/** Content for ArticlePage documents */\n' + 'interface ArticlepageDocumentData {\n' + ' /**\n' + ' * main-image field in *ArticlePage*\n' + ' *\n' + ' * - **Field Type**: Image\n' + ' * - **Placeholder**: *None*\n' + ' * - **API ID Path**: articlepage.main-image\n' + ' * - **Documentation**: https://prismic.io/docs/core-concepts/image\n' + ' *\n' + ' */\n' + ' main-image: prismicT.ImageField;\n' + '}\n' } ```

Steps to reproduce

npx prismic-ts-codegen

My configuration file:

prismicCodegen.config.ts
```typescript import type { Config } from "prismic-ts-codegen"; const config: Config = { repositoryName: "my-repo", customTypesAPIToken: "my-token", locales: { ids: ["en-gb"], fetchFromRepository: true, }, models: { fetchFromRepository: true, }, output: "./utils/prismic/types.generated.ts", }; export default config; ```

What is expected?

Expect types to be generated

What is actually happening?

An error is thrown

angeloashmore commented 2 years ago

Thanks for finding this bug and submitting a PR to fix it!


The fix has been published in v0.0.3. 🎉

To upgrade, install the latest version and re-generate your types:

npm install prismic-ts-codegen@latest
npx prismic-ts-codegen