adelsz / pgtyped

pgTyped - Typesafe SQL in TypeScript
https://pgtyped.dev
MIT License
2.91k stars 94 forks source link

--file flag ignored (possible Windows issue?) #579

Open bbsimonbb opened 4 months ago

bbsimonbb commented 4 months ago

Describe the bug When I run pgtyped with a --file argument, it is ignored. All files in the workspace are regenerated (or checked), and at the end of the ouput, I see the message "File override specified, but file was not found in provided transforms". But the specified file is in fact found and processed. I'm 100% sure the filename I provide is correct.

I'm running pgtyped on Windows 10 with Node 18.18.0

Expected behavior pgtyped should only process the specified file. The output should not contain a long list of all the queries in my application.

Test case

I have forked the project and will try and do a test case soon.

bbsimonbb commented 4 months ago

Here is terminal output from the run. The filename is guaranteed correct because it comes from the RunOnSave extension I've installed. I tried replacing antislashes with slashes, no difference. Quotes or no quotes, no difference. Relative or absolute path, no difference. In the output, you can see the referenced file, deleteMajorVersion.psql, is found and processed.

PS C:\dev\simplyfirst-catalogues\catalogues\acme-pvc> node_modules/.bin/env-cmd npx pgtyped -c pgtyped-config.json --file 'c:\dev\simplyfirst-catalogues\catalogues\acme-pvc\installation\queries\deleteMajorVersion.psql' (node:23792) Warning: Setting the NODE_TLS_REJECT_UNAUTHORIZED environment variable to '0' makes TLS connections and HTTPS requests insecure by disabling certificate verification. (Use node --trace-warnings ... to show where the warning was created) Using a pool of 6 threads. Processing installation\queries\setCurrentMinorVersion.psql Processing installation\queries\setCurrentMajorVersion.psql Processing installation\queries\insertZVarHotNumbers.psql Processing installation\queries\insertZPath.psql Processing installation\queries\insertHotNumberValue.psql Processing installation\queries\insertDocumentInstance.psql Processing installation\queries\insertCatalogueMinorVersion.psql Processing installation\queries\insertCatalogueMajorVersion.psql Processing installation\queries\insertCatalogueDocument.psql Processing installation\queries\deleteMajorVersion.psql (node:23792) Warning: Setting the NODE_TLS_REJECT_UNAUTHORIZED environment variable to '0' makes TLS connections and HTTPS requests insecure by disabling certificate verification. (Use node --trace-warnings ... to show where the warning was created) (node:23792) Warning: Setting the NODE_TLS_REJECT_UNAUTHORIZED environment variable to '0' makes TLS connections and HTTPS requests insecure by disabling certificate verification. (Use node --trace-warnings ... to show where the warning was created) (node:23792) Warning: Setting the NODE_TLS_REJECT_UNAUTHORIZED environment variable to '0' makes TLS connections and HTTPS requests insecure by disabling certificate verification. (Use node --trace-warnings ... to show where the warning was created) (node:23792) Warning: Setting the NODE_TLS_REJECT_UNAUTHORIZED environment variable to '0' makes TLS connections and HTTPS requests insecure by disabling certificate verification. (Use node --trace-warnings ... to show where the warning was created) (node:23792) Warning: Setting the NODE_TLS_REJECT_UNAUTHORIZED environment variable to '0' makes TLS connections and HTTPS requests insecure by disabling certificate verification. (Use node --trace-warnings ... to show where the warning was created) (node:23792) Warning: Setting the NODE_TLS_REJECT_UNAUTHORIZED environment variable to '0' makes TLS connections and HTTPS requests insecure by disabling certificate verification. (Use node --trace-warnings ... to show where the warning was created) Skipped installation\queries\setCurrentMinorVersion.psql: no changes or no queries detected Skipped installation\queries\setCurrentMajorVersion.psql: no changes or no queries detected Skipped installation\queries\insertZVarHotNumbers.psql: no changes or no queries detected Skipped installation\queries\insertZPath.psql: no changes or no queries detected Skipped installation\queries\insertHotNumberValue.psql: no changes or no queries detected Skipped installation\queries\insertDocumentInstance.psql: no changes or no queries detected Skipped installation\queries\deleteMajorVersion.psql: no changes or no queries detected Skipped installation\queries\insertCatalogueDocument.psql: no changes or no queries detected Skipped installation\queries\insertCatalogueMajorVersion.psql: no changes or no queries detected Skipped installation\queries\insertCatalogueMinorVersion.psql: no changes or no queries detected File override specified, but file was not found in provided transforms

zacherkkila commented 1 month ago

Same issue here (Mac). Not sure if you ever found a solution for this but it should also crash if the filename is not found, instead you can just throw garbage in there and it will still run everything

I assume it is just because of this in the docs

Uses transforms defined in the config file to determine the mode and emit template, so a file path that doesn't fit the include glob patterns will not be processed.

However, my transform is pretty darn simple.. Also removing the transform all together will cause a crash immediately with File override specified, but file was not found in provided transforms rather than trying to run everything

  "transforms": [
    {
      "mode": "ts",
      "include": "**/*.ts",
      "emitTemplate": "{{dir}}/{{name}}.pgtyped.ts"
    }
  ]
zacherkkila commented 1 month ago

Only way I was able to get this to work was to create a temp config. Just pass in the transform for the single file you need, also don't pass the --file flag to pgtyped in this case

So in a bash script (mac or linux)

    #!/bin/bash

    file="$1"
    jq --arg new_include_path "$file" '
    .transforms |= map(
        if .mode == "ts" then
        .include = $new_include_path
        else
        .
        end
    )' pgtyped_config.json > temp_pgtyped_config.json

    pgtyped --uri ${ENV} -c temp_pgtyped_config.json

Kind of a hack but seems to do the trick