From 2c21af51fbd047a2a60f18300a24fd395fce5f61 Mon Sep 17 00:00:00 2001 From: David Goss Date: Sat, 7 Oct 2023 22:33:43 +0100 Subject: [PATCH] chore: remove old importer hack --- dependency-lint.yml | 1 - package.json | 2 +- src/api/support.ts | 5 +---- src/configuration/from_file.ts | 7 ++----- src/formatter/builder.ts | 4 +--- src/importer.js | 13 ------------- src/runtime/parallel/worker.ts | 4 +--- test-d/{api.ts => api.mts} | 0 tsconfig.json | 2 +- 9 files changed, 7 insertions(+), 31 deletions(-) delete mode 100644 src/importer.js rename test-d/{api.ts => api.mts} (100%) diff --git a/dependency-lint.yml b/dependency-lint.yml index 8bba52fca..92c40926b 100644 --- a/dependency-lint.yml +++ b/dependency-lint.yml @@ -48,7 +48,6 @@ requiredModules: - 'dist/**/*' - 'lib/**/*' - 'node_modules/**/*' - - 'src/importer.js' - 'tmp/**/*' root: '**/*.{js,ts}' stripLoaders: false diff --git a/package.json b/package.json index 45a9d3772..04d5f4def 100644 --- a/package.json +++ b/package.json @@ -311,7 +311,7 @@ "ansi-regex": "^5.0.1" }, "scripts": { - "build-local": "genversion --es6 src/version.ts && tsc --build tsconfig.node.json && shx cp src/importer.js lib/ && shx cp src/wrapper.mjs lib/ && shx cp src/api/wrapper.mjs lib/api/", + "build-local": "genversion --es6 src/version.ts && tsc --build tsconfig.node.json && shx cp src/wrapper.mjs lib/ && shx cp src/api/wrapper.mjs lib/api/", "cck-test": "mocha 'compatibility/**/*_spec.ts'", "docs:ci": "api-extractor run --verbose", "docs:local": "api-extractor run --verbose --local && api-documenter markdown --input-folder ./tmp/api-extractor --output-folder ./docs/api", diff --git a/src/api/support.ts b/src/api/support.ts index f1e0d91b8..91f007d43 100644 --- a/src/api/support.ts +++ b/src/api/support.ts @@ -4,9 +4,6 @@ import supportCodeLibraryBuilder from '../support_code_library_builder' import { pathToFileURL } from 'url' import tryRequire from '../try_require' -// eslint-disable-next-line @typescript-eslint/no-var-requires -const { importer } = require('../importer') - export async function getSupportCodeLibrary({ cwd, newId, @@ -30,7 +27,7 @@ export async function getSupportCodeLibrary({ requirePaths.map((path) => tryRequire(path)) for (const path of importPaths) { - await importer(pathToFileURL(path)) + await import(pathToFileURL(path).toString()) } return supportCodeLibraryBuilder.finalize() diff --git a/src/configuration/from_file.ts b/src/configuration/from_file.ts index ec47ce542..1749e7d61 100644 --- a/src/configuration/from_file.ts +++ b/src/configuration/from_file.ts @@ -11,9 +11,6 @@ import ArgvParser from './argv_parser' import { checkSchema } from './check_schema' import { ILogger } from '../logger' -// eslint-disable-next-line @typescript-eslint/no-var-requires -const { importer } = require('../importer') - export async function fromFile( logger: ILogger, cwd: string, @@ -74,7 +71,7 @@ async function loadFile( logger.debug( `Loading configuration file "${file}" as ESM based on extension` ) - definitions = await importer(pathToFileURL(filePath)) + definitions = await import(pathToFileURL(filePath).toString()) break case '.js': { @@ -89,7 +86,7 @@ async function loadFile( logger.debug( `Loading configuration file "${file}" as ESM based on "${parentPackage.name}" package type` ) - definitions = await importer(pathToFileURL(filePath)) + definitions = await import(pathToFileURL(filePath).toString()) } else { logger.debug( `Loading configuration file "${file}" as CommonJS based on "${parentPackage.name}" package type` diff --git a/src/formatter/builder.ts b/src/formatter/builder.ts index 2ddc68ba5..abb1dd8ae 100644 --- a/src/formatter/builder.ts +++ b/src/formatter/builder.ts @@ -15,8 +15,6 @@ import { Writable as WritableStream } from 'stream' import { SnippetInterface } from './step_definition_snippet_builder/snippet_syntax' import { pathToFileURL } from 'url' import Formatters from './helpers/formatters' -// eslint-disable-next-line @typescript-eslint/no-var-requires -const { importer } = require('../importer') interface IGetStepDefinitionSnippetBuilderOptions { cwd: string @@ -120,7 +118,7 @@ const FormatterBuilder = { }, async loadFile(urlOrName: URL | string) { - return await importer(urlOrName) + return await import(urlOrName.toString()) }, resolveConstructor(ImportedCode: any) { diff --git a/src/importer.js b/src/importer.js deleted file mode 100644 index 5347a38ca..000000000 --- a/src/importer.js +++ /dev/null @@ -1,13 +0,0 @@ -/** - * Provides the async `import()` function to source code that needs it, - * without having it transpiled down to commonjs `require()` by TypeScript. - * See https://github.com/microsoft/TypeScript/issues/43329. - * - * @param {any} descriptor - A URL or path for the module to load - * @return {Promise} Promise that resolves to the loaded module - */ -async function importer(descriptor) { - return await import(descriptor) -} - -module.exports = { importer } diff --git a/src/runtime/parallel/worker.ts b/src/runtime/parallel/worker.ts index 67babfed6..5aa65416f 100644 --- a/src/runtime/parallel/worker.ts +++ b/src/runtime/parallel/worker.ts @@ -16,8 +16,6 @@ import { } from './command_types' import tryRequire from '../../try_require' -// eslint-disable-next-line @typescript-eslint/no-var-requires -const { importer } = require('../../importer') const { uuid } = IdGenerator type IExitFunction = (exitCode: number, error?: Error, message?: string) => void @@ -78,7 +76,7 @@ export default class Worker { requireModules.map((module) => tryRequire(module)) requirePaths.map((module) => tryRequire(module)) for (const path of importPaths) { - await importer(pathToFileURL(path)) + await import(pathToFileURL(path).toString()) } this.supportCodeLibrary = supportCodeLibraryBuilder.finalize(supportCodeIds) diff --git a/test-d/api.ts b/test-d/api.mts similarity index 100% rename from test-d/api.ts rename to test-d/api.mts diff --git a/tsconfig.json b/tsconfig.json index c20aa7b4d..eded03c87 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,7 +2,7 @@ "compilerOptions": { "esModuleInterop": true, "lib": ["es2022"], - "module": "commonjs", + "module": "node16", "noImplicitAny": true, "noImplicitReturns": true, "noImplicitThis": true,