You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[heft-typescript-plugin] Add emitModulePackageJson option for ESM output folders (#5665)
* [heft-typescript-plugin] Add emitModulePackageJson option for ESM output folders
Add a new 'emitModulePackageJson' option for 'additionalModuleKindsToEmit'
entries in typescript.json. When enabled, the TypeScript plugin writes a
package.json with the appropriate "type" field ("module" for ESNext/ES2015,
"commonjs" for CommonJS) to the output folder after compilation.
This ensures Node.js correctly interprets .js files in ESM output folders
like lib-esm/, fixing named import failures on Node 18 where .js files
without a nearest "type": "module" package.json are treated as CommonJS.
Enabled by default in local-node-rig and decoupled-local-node-rig for
their lib-esm output.
* fixup! [heft-typescript-plugin] Add emitModulePackageJson option for ESM output folders
* Convert something to a destructuring.
* fixup! [heft-typescript-plugin] Add emitModulePackageJson option for ESM output folders
"comment": "Add `emitModulePackageJson` option for `additionalModuleKindsToEmit` entries. When enabled, a `package.json` with the appropriate `\"type\"` field is written to the output folder after compilation, ensuring Node.js correctly interprets `.js` files regardless of the nearest ancestor package.json `\"type\"` setting.",
@@ -807,18 +811,19 @@ export class TypeScriptBuilder {
807
811
808
812
if(existingKind){
809
813
thrownewError(
810
-
`Module kind "${additionalModuleKindToEmit.moduleKind}" is already emitted at ${existingKind.outDir} with extension '${existingKind.extension}' by option ${existingKind.reason}.`
814
+
`Module kind "${moduleKind}" is already emitted at ${existingKind.outDir} with extension '${existingKind.extension}' by option ${existingKind.reason}.`
811
815
);
812
816
}elseif(existingDir){
813
817
thrownewError(
814
-
`Output folder "${additionalModuleKindToEmit.outFolderName}" already contains module kind ${existingDir.kind} with extension '${existingDir.extension}', specified by option ${existingDir.reason}.`
818
+
`Output folder "${outFolderName}" already contains module kind ${existingDir.kind} with extension '${existingDir.extension}', specified by option ${existingDir.reason}.`
Copy file name to clipboardExpand all lines: heft-plugins/heft-typescript-plugin/src/schemas/typescript.schema.json
+5Lines changed: 5 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -31,6 +31,11 @@
31
31
"outFolderName": {
32
32
"type": "string",
33
33
"pattern": "[^\\\\\\/]"
34
+
},
35
+
36
+
"emitModulePackageJson": {
37
+
"description": "If true, a package.json file will be written to the output folder with the appropriate \"type\" field for the specified module kind. This ensures that Node.js correctly interprets .js files in the output folder regardless of the nearest ancestor package.json \"type\" setting. Only valid for CommonJS, UMD, and ES module kinds.",
0 commit comments