From 18e611279076efdcd9f4984766d852b4e1f7db99 Mon Sep 17 00:00:00 2001 From: Eemeli Aro Date: Fri, 29 Nov 2024 10:36:20 +0200 Subject: [PATCH] chore: Enable typescript --rewriteRelativeImportExtensions --- config/rollup.node-config.mjs | 33 ++++++++++++++++++++++++++++++++- eslint.config.mjs | 11 +++++++++++ tsconfig.json | 1 + 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/config/rollup.node-config.mjs b/config/rollup.node-config.mjs index ee79df1d..524b01d8 100644 --- a/config/rollup.node-config.mjs +++ b/config/rollup.node-config.mjs @@ -1,4 +1,33 @@ import typescript from '@rollup/plugin-typescript' +import * as ts from 'typescript' + +/** + * Strip out TS relative import path rewrite helper from dynamic import() calls + * + * Required due to + * https://github.com/rollup/plugins/issues/1820 + * + * @param {ts.TransformationContext} context + */ +function fixDynamicImportRewrite(context) { + /** @param {ts.SourceFile} source */ + return function fixDynamicImport(source) { + /** @param {ts.Node} node */ + function visitor(node) { + if ( + ts.isCallExpression(node) && + ts.isIdentifier(node.expression) && + String(node.expression.escapedText) === + '___rewriteRelativeImportExtension' && + node.arguments.length === 1 + ) { + return node.arguments[0] + } + return ts.visitEachChild(node, visitor, context) + } + return ts.visitNode(source, visitor) + } +} export default [ { @@ -20,6 +49,8 @@ export default [ input: 'src/cli.ts', output: { file: 'dist/cli.mjs' }, external: () => true, - plugins: [typescript()] + plugins: [ + typescript({ transformers: { after: [fixDynamicImportRewrite] } }) + ] } ] diff --git a/eslint.config.mjs b/eslint.config.mjs index fe2dab72..a07a4464 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -38,6 +38,17 @@ export default [ 'no-control-regex': 'off', 'no-fallthrough': ['error', { commentPattern: 'fallthrough' }], 'no-implicit-globals': 'error', + 'no-restricted-imports': [ + 'error', + { + patterns: [ + { + regex: '^\\..*(?