isaacs / tshy

Other
894 stars 18 forks source link

Proposal: `"overrides"` #67

Open colinhacks opened 5 months ago

colinhacks commented 5 months ago

This is a second proposal to solve the core problem described here: https://github.com/isaacs/tshy/issues/65. Namely, I'm trying to construct a TypeScript monorepo with "live types" across package boundaries.

To do this, I'm now attempting to a custom "typescript" export condition that points to my TypeScript source code. I can then configure compilerOptions.customConditions such that TypeScript looks at the raw .ts source of my local packages in development instead of the .d.ts artifacts.

Currently tshy overrides everything in "exports" including any custom conditions I'd like to define. This could be resolved with a general-purpose "overrides" field that gets deep-merged into the generated package.json.

  "tshy": {
    "exports": {
      "./package.json": "./package.json",
      ".": "./src/index.ts"
    },
    "overrides": {
      "exports": {
        ".": { 
          "ts": "./src/index.ts" 
        }
      }
    }
  },

This config would result in something like this:

{
  "exports": {
    "./package.json": "./package.json",
    ".": {
      "ts": "./src/index.ts",
      "import": {
        "types": "./dist/esm/index.d.ts",
        "default": "./dist/esm/index.js"
      },
      "require": {
        "types": "./dist/commonjs/index.d.ts",
        "default": "./dist/commonjs/index.js"
      },
    }
  }
}
isaacs commented 4 months ago

Is exports the only thing that it'd be able to override? It feels like it could just be called exportsOverrides or something in that case, and then the logic is just that it'll be deep-merged on top of whatever else tshy generates. So kind of a general purpose manual escape-hatch for whatever.