From b508ba6fa647acef9463b22865dcb694cd995760 Mon Sep 17 00:00:00 2001 From: JrMasterModelBuilder Date: Tue, 6 Aug 2024 01:00:05 -0400 Subject: [PATCH] Import ts with extension --- babel.config.mjs | 8 ++------ package-lock.json | 10 +++++----- package.json | 2 +- src/archive.spec.ts | 6 +++--- src/archive.test.ts | 2 +- src/archive.ts | 4 ++-- src/archive/dir.test.ts | 6 +++--- src/archive/dir.ts | 6 +++--- src/archive/hdi.test.ts | 4 ++-- src/archive/hdi.ts | 6 +++--- src/archive/index.ts | 10 +++++----- src/archive/tar.test.ts | 4 ++-- src/archive/tar.ts | 4 ++-- src/archive/tar/bz2.test.ts | 4 ++-- src/archive/tar/bz2.ts | 2 +- src/archive/tar/gz.test.ts | 4 ++-- src/archive/tar/gz.ts | 2 +- src/archive/tar/index.ts | 4 ++-- src/archive/zip.test.ts | 4 ++-- src/archive/zip.ts | 6 +++--- src/create.test.ts | 2 +- src/create.ts | 14 +++++++------- src/index.ts | 12 ++++++------ src/meta.test.ts | 2 +- src/util.test.ts | 2 +- src/util.ts | 2 +- tsconfig.json | 1 + 27 files changed, 65 insertions(+), 68 deletions(-) diff --git a/babel.config.mjs b/babel.config.mjs index 4974cb0..84324aa 100644 --- a/babel.config.mjs +++ b/babel.config.mjs @@ -33,13 +33,9 @@ export default api => { ); plugins.push( [ - 'esm-resolver', + 'module-replace', { - source: { - extensions: [ - [['.js', '.mjs', '.jsx', '.mjsx', '.ts', '.tsx'], ext] - ] - } + replace: [[/^(\.\.?\/.+)\.(m|c)?tsx?$/i, `$1${ext}`]] } ], [ diff --git a/package-lock.json b/package-lock.json index bb25ac6..f0542d7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -24,7 +24,7 @@ "@types/node": "^22.1.0", "@types/unbzip2-stream": "^1.4.3", "@types/yauzl": "^2.10.3", - "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", @@ -2644,10 +2644,10 @@ "node": ">=8" } }, - "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 e70769a..3259dbc 100644 --- a/package.json +++ b/package.json @@ -78,7 +78,7 @@ "@types/node": "^22.1.0", "@types/unbzip2-stream": "^1.4.3", "@types/yauzl": "^2.10.3", - "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/archive.spec.ts b/src/archive.spec.ts index 8d05d22..e035580 100644 --- a/src/archive.spec.ts +++ b/src/archive.spec.ts @@ -8,8 +8,8 @@ import {join as pathJoin} from 'node:path'; import {Readable, Writable} from 'node:stream'; import {pipeline} from 'node:stream/promises'; -import {Archive, Entry, IEntryInfo} from './archive'; -import {PathType} from './types'; +import {Archive, Entry, IEntryInfo} from './archive.ts'; +import {PathType} from './types.ts'; import { fsLchmodSupported, fsLstat, @@ -17,7 +17,7 @@ import { modePermissionBits, pathResourceFork, streamToBuffer -} from './util'; +} from './util.ts'; export const specTmpPath = ( (i: number) => (s: string) => diff --git a/src/archive.test.ts b/src/archive.test.ts index b0af20e..34c4604 100644 --- a/src/archive.test.ts +++ b/src/archive.test.ts @@ -1,6 +1,6 @@ import {describe} from 'node:test'; -import {ArchiveTest, testArchive} from './archive.spec'; +import {ArchiveTest, testArchive} from './archive.spec.ts'; void describe('archive', () => { void describe('Archive', () => { diff --git a/src/archive.ts b/src/archive.ts index 92a1c5b..a1f910a 100644 --- a/src/archive.ts +++ b/src/archive.ts @@ -8,7 +8,7 @@ import {promisify} from 'node:util'; const pipe = promisify(pipeline); -import {PathType} from './types'; +import {PathType} from './types.ts'; import { fsChmod, fsLchmod, @@ -20,7 +20,7 @@ import { pathNormalize, pathResourceFork, streamToBuffer -} from './util'; +} from './util.ts'; export interface IArchiveAfterReadSetAttributesEntry { /** diff --git a/src/archive/dir.test.ts b/src/archive/dir.test.ts index 3b86149..40c1ac5 100644 --- a/src/archive/dir.test.ts +++ b/src/archive/dir.test.ts @@ -8,10 +8,10 @@ import { platformIsWin, safeToExtract, testArchive -} from '../archive.spec'; -import {PathType} from '../types'; +} from '../archive.spec.ts'; +import {PathType} from '../types.ts'; -import {ArchiveDir} from './dir'; +import {ArchiveDir} from './dir.ts'; void describe('archive/dir', () => { void describe('ArchiveDir', () => { diff --git a/src/archive/dir.ts b/src/archive/dir.ts index 8a577e4..159c124 100644 --- a/src/archive/dir.ts +++ b/src/archive/dir.ts @@ -3,8 +3,8 @@ import {Stats, createReadStream} from 'node:fs'; import {join as pathJoin} from 'node:path'; -import {Archive, Entry, IEntryInfo} from '../archive'; -import {PathType} from '../types'; +import {Archive, Entry, IEntryInfo} from '../archive.ts'; +import {PathType} from '../types.ts'; import { fsLstat, fsLstatExists, @@ -13,7 +13,7 @@ import { pathNormalize, pathResourceFork, statToPathType -} from '../util'; +} from '../util.ts'; const walkOpts = { ignoreUnreadableDirectories: true diff --git a/src/archive/hdi.test.ts b/src/archive/hdi.test.ts index b4e4a5a..2106deb 100644 --- a/src/archive/hdi.test.ts +++ b/src/archive/hdi.test.ts @@ -2,9 +2,9 @@ import {describe, it} from 'node:test'; import {deepStrictEqual} from 'node:assert'; import {join as pathJoin} from 'node:path'; -import {platformIsMac, specFixturesPath, testArchive} from '../archive.spec'; +import {platformIsMac, specFixturesPath, testArchive} from '../archive.spec.ts'; -import {ArchiveHdi} from './hdi'; +import {ArchiveHdi} from './hdi.ts'; // eslint-disable-next-line no-process-env const NO_HDI = /^(1|true|yes)$/i.test(process.env['SHOCKPKG_NO_HDI'] || ''); diff --git a/src/archive/hdi.ts b/src/archive/hdi.ts index 7bec970..cb6d584 100644 --- a/src/archive/hdi.ts +++ b/src/archive/hdi.ts @@ -5,8 +5,8 @@ import {basename, join as pathJoin} from 'node:path'; import {Mounter} from '@shockpkg/hdi-mac'; -import {Archive, Entry, IEntryInfo} from '../archive'; -import {PathType} from '../types'; +import {Archive, Entry, IEntryInfo} from '../archive.ts'; +import {PathType} from '../types.ts'; import { fsLstatExists, fsReadlinkRaw, @@ -14,7 +14,7 @@ import { pathNormalize, pathResourceFork, statToPathType -} from '../util'; +} from '../util.ts'; const walkOpts = { ignoreUnreadableDirectories: true diff --git a/src/archive/index.ts b/src/archive/index.ts index 49d43ee..08f66f0 100644 --- a/src/archive/index.ts +++ b/src/archive/index.ts @@ -1,5 +1,5 @@ -export * from './dir'; -export * from './hdi'; -export * from './tar'; -export * from './tar/'; -export * from './zip'; +export * from './dir.ts'; +export * from './hdi.ts'; +export * from './tar.ts'; +export * from './tar/index.ts'; +export * from './zip.ts'; diff --git a/src/archive/tar.test.ts b/src/archive/tar.test.ts index e6ded9d..7a62c29 100644 --- a/src/archive/tar.test.ts +++ b/src/archive/tar.test.ts @@ -2,9 +2,9 @@ import {describe, it} from 'node:test'; import {deepStrictEqual} from 'node:assert'; import {join as pathJoin} from 'node:path'; -import {specFixturesPath, testArchive} from '../archive.spec'; +import {specFixturesPath, testArchive} from '../archive.spec.ts'; -import {ArchiveTar} from './tar'; +import {ArchiveTar} from './tar.ts'; void describe('archive/tar', () => { void describe('ArchiveTar', () => { diff --git a/src/archive/tar.ts b/src/archive/tar.ts index 4963e7a..a3dbe50 100644 --- a/src/archive/tar.ts +++ b/src/archive/tar.ts @@ -3,8 +3,8 @@ import {createReadStream} from 'node:fs'; import {Readable} from 'node:stream'; -import {Archive, Entry, IEntryInfo} from '../archive'; -import {PathType} from '../types'; +import {Archive, Entry, IEntryInfo} from '../archive.ts'; +import {PathType} from '../types.ts'; // Based on it-tar TarEntryHeader. interface IHeader { diff --git a/src/archive/tar/bz2.test.ts b/src/archive/tar/bz2.test.ts index a65189e..1e7032d 100644 --- a/src/archive/tar/bz2.test.ts +++ b/src/archive/tar/bz2.test.ts @@ -2,9 +2,9 @@ import {describe, it} from 'node:test'; import {deepStrictEqual} from 'node:assert'; import {join as pathJoin} from 'node:path'; -import {specFixturesPath, testArchive} from '../../archive.spec'; +import {specFixturesPath, testArchive} from '../../archive.spec.ts'; -import {ArchiveTarBz2} from './bz2'; +import {ArchiveTarBz2} from './bz2.ts'; void describe('archive/tar/bz2', () => { void describe('ArchiveTarBz2', () => { diff --git a/src/archive/tar/bz2.ts b/src/archive/tar/bz2.ts index 82d8453..9a651cf 100644 --- a/src/archive/tar/bz2.ts +++ b/src/archive/tar/bz2.ts @@ -1,6 +1,6 @@ import unbzip2Stream from 'unbzip2-stream'; -import {ArchiveTar} from '../tar'; +import {ArchiveTar} from '../tar.ts'; /** * ArchiveTarBz2 object. diff --git a/src/archive/tar/gz.test.ts b/src/archive/tar/gz.test.ts index 70ee063..5d39e3a 100644 --- a/src/archive/tar/gz.test.ts +++ b/src/archive/tar/gz.test.ts @@ -2,9 +2,9 @@ import {describe, it} from 'node:test'; import {deepStrictEqual} from 'node:assert'; import {join as pathJoin} from 'node:path'; -import {specFixturesPath, testArchive} from '../../archive.spec'; +import {specFixturesPath, testArchive} from '../../archive.spec.ts'; -import {ArchiveTarGz} from './gz'; +import {ArchiveTarGz} from './gz.ts'; void describe('archive/tar/gz', () => { void describe('ArchiveTarGz', () => { diff --git a/src/archive/tar/gz.ts b/src/archive/tar/gz.ts index e3ab6fe..9b83e83 100644 --- a/src/archive/tar/gz.ts +++ b/src/archive/tar/gz.ts @@ -1,6 +1,6 @@ import {createGunzip} from 'node:zlib'; -import {ArchiveTar} from '../tar'; +import {ArchiveTar} from '../tar.ts'; /** * ArchiveTarGz object. diff --git a/src/archive/tar/index.ts b/src/archive/tar/index.ts index d1cd653..5d31ac8 100644 --- a/src/archive/tar/index.ts +++ b/src/archive/tar/index.ts @@ -1,2 +1,2 @@ -export * from './bz2'; -export * from './gz'; +export * from './bz2.ts'; +export * from './gz.ts'; diff --git a/src/archive/zip.test.ts b/src/archive/zip.test.ts index 775280e..9ff5c65 100644 --- a/src/archive/zip.test.ts +++ b/src/archive/zip.test.ts @@ -2,9 +2,9 @@ import {describe, it} from 'node:test'; import {deepStrictEqual} from 'node:assert'; import {join as pathJoin} from 'node:path'; -import {specFixturesPath, testArchive} from '../archive.spec'; +import {specFixturesPath, testArchive} from '../archive.spec.ts'; -import {ArchiveZip} from './zip'; +import {ArchiveZip} from './zip.ts'; void describe('archive/zip', () => { void describe('ArchiveZip', () => { diff --git a/src/archive/zip.ts b/src/archive/zip.ts index d3e1d1e..30b990f 100644 --- a/src/archive/zip.ts +++ b/src/archive/zip.ts @@ -4,9 +4,9 @@ import {Readable} from 'node:stream'; import yauzl from 'yauzl'; -import {Archive, Entry, IEntryInfo} from '../archive'; -import {PathType} from '../types'; -import {modeToPathType, streamToBuffer} from '../util'; +import {Archive, Entry, IEntryInfo} from '../archive.ts'; +import {PathType} from '../types.ts'; +import {modeToPathType, streamToBuffer} from '../util.ts'; /** * Read entry. diff --git a/src/create.test.ts b/src/create.test.ts index f2ac199..8fab5fa 100644 --- a/src/create.test.ts +++ b/src/create.test.ts @@ -1,7 +1,7 @@ import {describe, it} from 'node:test'; import {ok, strictEqual} from 'node:assert'; -import {createArchiveByFileExtension} from './create'; +import {createArchiveByFileExtension} from './create.ts'; void describe('create', () => { void describe('createArchiveByFileExtension', () => { diff --git a/src/create.ts b/src/create.ts index eba24ba..51d8713 100644 --- a/src/create.ts +++ b/src/create.ts @@ -1,12 +1,12 @@ import {stat} from 'node:fs/promises'; -import {Archive} from './archive'; -import {ArchiveDir} from './archive/dir'; -import {ArchiveHdi} from './archive/hdi'; -import {ArchiveTar} from './archive/tar'; -import {ArchiveTarBz2} from './archive/tar/bz2'; -import {ArchiveTarGz} from './archive/tar/gz'; -import {ArchiveZip} from './archive/zip'; +import {Archive} from './archive.ts'; +import {ArchiveDir} from './archive/dir.ts'; +import {ArchiveHdi} from './archive/hdi.ts'; +import {ArchiveTar} from './archive/tar.ts'; +import {ArchiveTarBz2} from './archive/tar/bz2.ts'; +import {ArchiveTarGz} from './archive/tar/gz.ts'; +import {ArchiveZip} from './archive/zip.ts'; export interface ICreateArchiveOptions { /** diff --git a/src/index.ts b/src/index.ts index 5fe6d65..b1f3373 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,6 @@ -export * from './meta'; -export * from './types'; -export * from './util'; -export * from './archive'; -export * from './archive/'; -export * from './create'; +export * from './meta.ts'; +export * from './types.ts'; +export * from './util.ts'; +export * from './archive.ts'; +export * from './archive/index.ts'; +export * from './create.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/util.test.ts b/src/util.test.ts index 631a4bc..a9983d8 100644 --- a/src/util.test.ts +++ b/src/util.test.ts @@ -2,7 +2,7 @@ import {describe, it} from 'node:test'; import {strictEqual} from 'node:assert'; import {mkdir, rm} from 'node:fs/promises'; -import {fsLstatExists, pathNormalize, fsSymlink} from './util'; +import {fsLstatExists, pathNormalize, fsSymlink} from './util.ts'; async function withSymlinksDir(f: (dir: string) => unknown) { const dir = 'spec/tmp/symlinks'; diff --git a/src/util.ts b/src/util.ts index dad02d5..a5be4f5 100644 --- a/src/util.ts +++ b/src/util.ts @@ -12,7 +12,7 @@ import {join as pathJoin} from 'node:path'; import {Readable, Writable} from 'node:stream'; import {pipeline} from 'node:stream/promises'; -import {PathType} from './types'; +import {PathType} from './types.ts'; export interface IFsWalkOptions { /** 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",