From 4d418be23a42393c31c7560eb20c2964ac45e671 Mon Sep 17 00:00:00 2001 From: Roland Kuhn Date: Wed, 15 Feb 2023 13:39:28 +0100 Subject: [PATCH] fix imports in *.d.ts files for esm --- rename-imports.mjs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/rename-imports.mjs b/rename-imports.mjs index e90dab84..cb4ecae0 100644 --- a/rename-imports.mjs +++ b/rename-imports.mjs @@ -1,7 +1,7 @@ import FileHound from 'filehound'; import fs from 'fs'; -const files = FileHound.create().paths('./lib').ext('js').find(); +const files = FileHound.create().paths('./lib').ext(['js', 'ts']).find(); files.then((filePaths) => { filePaths.forEach((filepath) => { @@ -22,6 +22,9 @@ files.then((filePaths) => { "import * as Canvas from 'canvas';" ); + // Handle import("./x/y/z") syntax. + text = text.replace(/(import\s*\(\s*['"])(.*)(?=['"])/g, '$1$2.js'); + fs.writeFile(filepath, text, function (err) { if (err) { throw err;