From 62ab6d2a859239c5dfba505992ca5ab6d2498c9f Mon Sep 17 00:00:00 2001 From: JrMasterModelBuilder Date: Mon, 5 Aug 2024 22:28:49 -0400 Subject: [PATCH] Import ts with extension --- babel.config.mjs | 24 ++++++-------- package-lock.json | 10 +++--- package.json | 2 +- src/command.ts | 6 ++-- src/commands/about.ts | 4 +-- src/commands/available.ts | 2 +- src/commands/cleanup.ts | 2 +- src/commands/file.ts | 2 +- src/commands/help.ts | 2 +- src/commands/info.ts | 2 +- src/commands/install.ts | 2 +- src/commands/installed.ts | 2 +- src/commands/is-current.ts | 2 +- src/commands/is-installed.ts | 2 +- src/commands/is-obsolete.ts | 2 +- src/commands/list.ts | 2 +- src/commands/obsolete.ts | 2 +- src/commands/outdated.ts | 2 +- src/commands/path.ts | 2 +- src/commands/remove.ts | 2 +- src/commands/update.ts | 2 +- src/commands/upgrade.ts | 2 +- src/commands/url.ts | 2 +- src/commands/verify.ts | 2 +- src/commands/version.ts | 2 +- src/index.ts | 52 +++++++++++++++---------------- src/meta.test.ts | 2 +- src/test/commands/about.test.ts | 2 +- src/test/commands/help.test.ts | 2 +- src/test/commands/version.test.ts | 2 +- tsconfig.json | 1 + 31 files changed, 72 insertions(+), 75 deletions(-) diff --git a/babel.config.mjs b/babel.config.mjs index 35f7cfe..84324aa 100644 --- a/babel.config.mjs +++ b/babel.config.mjs @@ -31,23 +31,11 @@ export default api => { ], ['@babel/preset-typescript'] ); - if (modules === 'commonjs') { - plugins.push([ - '@babel/plugin-transform-modules-commonjs', - { - importInterop: 'node' - } - ]); - } plugins.push( [ - 'esm-resolver', + 'module-replace', { - source: { - extensions: [ - [['.js', '.mjs', '.jsx', '.mjsx', '.ts', '.tsx'], ext] - ] - } + replace: [[/^(\.\.?\/.+)\.(m|c)?tsx?$/i, `$1${ext}`]] } ], [ @@ -66,6 +54,14 @@ export default api => { } ] ); + if (modules === 'commonjs') { + plugins.push([ + '@babel/plugin-transform-modules-commonjs', + { + importInterop: 'node' + } + ]); + } return { presets, plugins diff --git a/package-lock.json b/package-lock.json index c57f929..2c96ae1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -25,7 +25,7 @@ "@stylistic/eslint-plugin": "^2.6.1", "@types/node": "^22.1.0", "@types/source-map-support": "^0.5.10", - "babel-plugin-esm-resolver": "^3.0.0", + "babel-plugin-module-replace": "^1.0.1", "babel-plugin-search-and-replace": "^1.1.1", "eslint": "^9.8.0", "eslint-config-prettier": "^9.1.0", @@ -4013,10 +4013,10 @@ "node": ">= 10.0.0" } }, - "node_modules/babel-plugin-esm-resolver": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/babel-plugin-esm-resolver/-/babel-plugin-esm-resolver-3.0.0.tgz", - "integrity": "sha512-UvPljUKB+/cWdoNL6otraFQkRGjUvD17CFlAbGL2YXmITyIFAR1KptyobXI3w2qKTIlT5wRiMV0TUsxA8tbkeA==", + "node_modules/babel-plugin-module-replace": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/babel-plugin-module-replace/-/babel-plugin-module-replace-1.0.1.tgz", + "integrity": "sha512-uT+5dPLqAVbul81dAK6RMTwA/kkOHiXGKre6kPDEaWb6HeoS9BNoSpD3CHsu+U39UKd6van6ITOBoQ0DulNb/A==", "dev": true, "engines": { "node": ">=6.9.0" diff --git a/package.json b/package.json index bb0d84b..d19f466 100755 --- a/package.json +++ b/package.json @@ -75,7 +75,7 @@ "@stylistic/eslint-plugin": "^2.6.1", "@types/node": "^22.1.0", "@types/source-map-support": "^0.5.10", - "babel-plugin-esm-resolver": "^3.0.0", + "babel-plugin-module-replace": "^1.0.1", "babel-plugin-search-and-replace": "^1.1.1", "eslint": "^9.8.0", "eslint-config-prettier": "^9.1.0", diff --git a/src/command.ts b/src/command.ts index 52ffb79..d657f99 100644 --- a/src/command.ts +++ b/src/command.ts @@ -8,9 +8,9 @@ import { DEBUG_ERROR_LOG, UPDATE_INTERVAL_DEFAULT, UPDATE_INTERVAL_ENV -} from './constants'; -import {divmod, envTrue, envInteger} from './util'; -import {Progress, ProgressCallback} from './progress'; +} from './constants.ts'; +import {divmod, envTrue, envInteger} from './util.ts'; +import {Progress, ProgressCallback} from './progress.ts'; // eslint-disable-next-line unicorn/prefer-export-from export {Help, Flags, Args, run}; diff --git a/src/commands/about.ts b/src/commands/about.ts index d693b87..bca8285 100644 --- a/src/commands/about.ts +++ b/src/commands/about.ts @@ -3,8 +3,8 @@ import { VERSION as SHOCKPKG_CORE_VERSION } from '@shockpkg/core'; -import {NAME, VERSION} from '../meta'; -import {Command, Flags} from '../command'; +import {NAME, VERSION} from '../meta.ts'; +import {Command, Flags} from '../command.ts'; /** * About command. diff --git a/src/commands/available.ts b/src/commands/available.ts index d6560bf..49ccca7 100644 --- a/src/commands/available.ts +++ b/src/commands/available.ts @@ -1,4 +1,4 @@ -import {Command, Flags} from '../command'; +import {Command, Flags} from '../command.ts'; /** * Available command. diff --git a/src/commands/cleanup.ts b/src/commands/cleanup.ts index 3a95b28..3e5787c 100644 --- a/src/commands/cleanup.ts +++ b/src/commands/cleanup.ts @@ -1,4 +1,4 @@ -import {Command, Flags} from '../command'; +import {Command, Flags} from '../command.ts'; /** * Cleanup command. diff --git a/src/commands/file.ts b/src/commands/file.ts index 50cac9a..14b5004 100644 --- a/src/commands/file.ts +++ b/src/commands/file.ts @@ -1,4 +1,4 @@ -import {Command, Flags, Args} from '../command'; +import {Command, Flags, Args} from '../command.ts'; /** * File command. diff --git a/src/commands/help.ts b/src/commands/help.ts index f047554..9b963f4 100644 --- a/src/commands/help.ts +++ b/src/commands/help.ts @@ -1,4 +1,4 @@ -import {Command, Flags, Args, Help} from '../command'; +import {Command, Flags, Args, Help} from '../command.ts'; /** * Help command. diff --git a/src/commands/info.ts b/src/commands/info.ts index 3864d53..29223a7 100644 --- a/src/commands/info.ts +++ b/src/commands/info.ts @@ -1,4 +1,4 @@ -import {Command, Flags, Args} from '../command'; +import {Command, Flags, Args} from '../command.ts'; /** * Info command. diff --git a/src/commands/install.ts b/src/commands/install.ts index 17fc986..f60e3dd 100644 --- a/src/commands/install.ts +++ b/src/commands/install.ts @@ -1,4 +1,4 @@ -import {Command, Flags, Args} from '../command'; +import {Command, Flags, Args} from '../command.ts'; /** * Install command. diff --git a/src/commands/installed.ts b/src/commands/installed.ts index 3a001e2..be4a21a 100644 --- a/src/commands/installed.ts +++ b/src/commands/installed.ts @@ -1,4 +1,4 @@ -import {Command, Flags} from '../command'; +import {Command, Flags} from '../command.ts'; /** * Installed command. diff --git a/src/commands/is-current.ts b/src/commands/is-current.ts index 23861ae..031d18c 100644 --- a/src/commands/is-current.ts +++ b/src/commands/is-current.ts @@ -1,4 +1,4 @@ -import {Command, Flags, Args} from '../command'; +import {Command, Flags, Args} from '../command.ts'; /** * IsCurrent command. diff --git a/src/commands/is-installed.ts b/src/commands/is-installed.ts index 17d8038..55cd5f3 100644 --- a/src/commands/is-installed.ts +++ b/src/commands/is-installed.ts @@ -1,4 +1,4 @@ -import {Command, Flags, Args} from '../command'; +import {Command, Flags, Args} from '../command.ts'; /** * IsInstalled command. diff --git a/src/commands/is-obsolete.ts b/src/commands/is-obsolete.ts index 8cf3303..09700f5 100644 --- a/src/commands/is-obsolete.ts +++ b/src/commands/is-obsolete.ts @@ -1,4 +1,4 @@ -import {Command, Flags, Args} from '../command'; +import {Command, Flags, Args} from '../command.ts'; /** * IsObsolete command. diff --git a/src/commands/list.ts b/src/commands/list.ts index f7ef6f2..cb17564 100644 --- a/src/commands/list.ts +++ b/src/commands/list.ts @@ -1,4 +1,4 @@ -import {Command, Flags} from '../command'; +import {Command, Flags} from '../command.ts'; /** * List command. diff --git a/src/commands/obsolete.ts b/src/commands/obsolete.ts index 2e1150a..ccda0b2 100644 --- a/src/commands/obsolete.ts +++ b/src/commands/obsolete.ts @@ -1,4 +1,4 @@ -import {Command, Flags} from '../command'; +import {Command, Flags} from '../command.ts'; /** * Obsolete command. diff --git a/src/commands/outdated.ts b/src/commands/outdated.ts index 2007270..2462303 100644 --- a/src/commands/outdated.ts +++ b/src/commands/outdated.ts @@ -1,4 +1,4 @@ -import {Command, Flags} from '../command'; +import {Command, Flags} from '../command.ts'; /** * Outdated command. diff --git a/src/commands/path.ts b/src/commands/path.ts index 3d61d92..515f2ad 100644 --- a/src/commands/path.ts +++ b/src/commands/path.ts @@ -1,4 +1,4 @@ -import {Command, Flags} from '../command'; +import {Command, Flags} from '../command.ts'; /** * Path command. diff --git a/src/commands/remove.ts b/src/commands/remove.ts index a33828e..9f9a34a 100644 --- a/src/commands/remove.ts +++ b/src/commands/remove.ts @@ -1,4 +1,4 @@ -import {Command, Flags, Args} from '../command'; +import {Command, Flags, Args} from '../command.ts'; /** * Remove command. diff --git a/src/commands/update.ts b/src/commands/update.ts index bc5cc7e..acd6b5b 100644 --- a/src/commands/update.ts +++ b/src/commands/update.ts @@ -1,4 +1,4 @@ -import {Command, Flags} from '../command'; +import {Command, Flags} from '../command.ts'; /** * Update command. diff --git a/src/commands/upgrade.ts b/src/commands/upgrade.ts index 6e4b434..8b431a8 100644 --- a/src/commands/upgrade.ts +++ b/src/commands/upgrade.ts @@ -1,4 +1,4 @@ -import {Command, Flags} from '../command'; +import {Command, Flags} from '../command.ts'; /** * Upgrade command. diff --git a/src/commands/url.ts b/src/commands/url.ts index 7615b58..594559c 100644 --- a/src/commands/url.ts +++ b/src/commands/url.ts @@ -1,4 +1,4 @@ -import {Command, Flags} from '../command'; +import {Command, Flags} from '../command.ts'; /** * Url command. diff --git a/src/commands/verify.ts b/src/commands/verify.ts index bb856a5..cf7707d 100644 --- a/src/commands/verify.ts +++ b/src/commands/verify.ts @@ -1,4 +1,4 @@ -import {Command, Flags, Args} from '../command'; +import {Command, Flags, Args} from '../command.ts'; /** * Verify command. diff --git a/src/commands/version.ts b/src/commands/version.ts index 66d570d..5be7658 100644 --- a/src/commands/version.ts +++ b/src/commands/version.ts @@ -1,4 +1,4 @@ -import {Command} from '../command'; +import {Command} from '../command.ts'; /** * Version command. diff --git a/src/index.ts b/src/index.ts index 1f63da9..64b14de 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,26 +1,26 @@ -export * from './meta'; -export * from './constants'; -export * from './util'; -export * from './progress'; -export * from './command'; -export * from './commands/about'; -export * from './commands/available'; -export * from './commands/cleanup'; -export * from './commands/file'; -export * from './commands/help'; -export * from './commands/info'; -export * from './commands/install'; -export * from './commands/installed'; -export * from './commands/is-current'; -export * from './commands/is-installed'; -export * from './commands/is-obsolete'; -export * from './commands/list'; -export * from './commands/obsolete'; -export * from './commands/outdated'; -export * from './commands/path'; -export * from './commands/remove'; -export * from './commands/update'; -export * from './commands/upgrade'; -export * from './commands/url'; -export * from './commands/verify'; -export * from './commands/version'; +export * from './meta.ts'; +export * from './constants.ts'; +export * from './util.ts'; +export * from './progress.ts'; +export * from './command.ts'; +export * from './commands/about.ts'; +export * from './commands/available.ts'; +export * from './commands/cleanup.ts'; +export * from './commands/file.ts'; +export * from './commands/help.ts'; +export * from './commands/info.ts'; +export * from './commands/install.ts'; +export * from './commands/installed.ts'; +export * from './commands/is-current.ts'; +export * from './commands/is-installed.ts'; +export * from './commands/is-obsolete.ts'; +export * from './commands/list.ts'; +export * from './commands/obsolete.ts'; +export * from './commands/outdated.ts'; +export * from './commands/path.ts'; +export * from './commands/remove.ts'; +export * from './commands/update.ts'; +export * from './commands/upgrade.ts'; +export * from './commands/url.ts'; +export * from './commands/verify.ts'; +export * from './commands/version.ts'; diff --git a/src/meta.test.ts b/src/meta.test.ts index 44dbd46..1dfeb1a 100644 --- a/src/meta.test.ts +++ b/src/meta.test.ts @@ -1,7 +1,7 @@ import {describe, it} from 'node:test'; import {match} from 'node:assert'; -import {NAME, VERSION} from './meta'; +import {NAME, VERSION} from './meta.ts'; void describe('meta', () => { void it('NAME', () => { diff --git a/src/test/commands/about.test.ts b/src/test/commands/about.test.ts index 2bf1c3b..fcb2633 100644 --- a/src/test/commands/about.test.ts +++ b/src/test/commands/about.test.ts @@ -1,7 +1,7 @@ import {describe, it} from 'node:test'; import {ok, strictEqual} from 'node:assert'; -import {cli} from '../../util.spec'; +import {cli} from '../../util.spec.ts'; void describe('about', () => { void it('output', async () => { diff --git a/src/test/commands/help.test.ts b/src/test/commands/help.test.ts index 8b2d535..852b446 100644 --- a/src/test/commands/help.test.ts +++ b/src/test/commands/help.test.ts @@ -1,7 +1,7 @@ import {describe, it} from 'node:test'; import {ok, strictEqual} from 'node:assert'; -import {cli} from '../../util.spec'; +import {cli} from '../../util.spec.ts'; void describe('help', () => { void it('output', async () => { diff --git a/src/test/commands/version.test.ts b/src/test/commands/version.test.ts index c6a9036..4c144e6 100644 --- a/src/test/commands/version.test.ts +++ b/src/test/commands/version.test.ts @@ -1,7 +1,7 @@ import {describe, it} from 'node:test'; import {ok, strictEqual} from 'node:assert'; -import {cli} from '../../util.spec'; +import {cli} from '../../util.spec.ts'; void describe('version', () => { void it('output', async () => { diff --git a/tsconfig.json b/tsconfig.json index a773b23..b65b296 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,6 +5,7 @@ "module": "commonjs", "moduleResolution": "Node", "allowSyntheticDefaultImports": true, + "allowImportingTsExtensions": true, "lib": ["ESNext"], "newLine": "lf",