diff --git a/.editorconfig b/.editorconfig index 2733847d..f8256e8a 100644 --- a/.editorconfig +++ b/.editorconfig @@ -34,7 +34,7 @@ ij_javascript_align_multiline_extends_list = false ij_javascript_align_multiline_for = true ij_javascript_align_multiline_parameters = true ij_javascript_align_multiline_parameters_in_calls = false -ij_javascript_align_multiline_ternary_operation = false +ij_javascript_align_multiline_ternary_operation = true ij_javascript_align_object_properties = 0 ij_javascript_align_union_types = false ij_javascript_align_var_statements = 0 @@ -218,7 +218,7 @@ ij_typescript_align_multiline_extends_list = false ij_typescript_align_multiline_for = true ij_typescript_align_multiline_parameters = true ij_typescript_align_multiline_parameters_in_calls = false -ij_typescript_align_multiline_ternary_operation = false +ij_typescript_align_multiline_ternary_operation = true ij_typescript_align_object_properties = 0 ij_typescript_align_union_types = false ij_typescript_align_var_statements = 0 @@ -363,7 +363,7 @@ ij_typescript_ternary_operation_signs_on_next_line = false ij_typescript_ternary_operation_wrap = off ij_typescript_union_types_wrap = on_every_item ij_typescript_use_chained_calls_group_indents = false -ij_typescript_use_double_quotes = false +ij_typescript_use_double_quotes = true ij_typescript_use_explicit_js_extension = global ij_typescript_use_path_mapping = always ij_typescript_use_public_modifier = false diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c1b69cb3..a5eed62b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,6 +1,11 @@ name: Node.js CI -on: [ push, pull_request ] +on: + pull_request: + branches: [ master ] + types: [ opened, synchronize, closed ] + push: + branches: [ master ] jobs: build: @@ -14,25 +19,13 @@ jobs: - name: Checkout uses: actions/checkout@v2 - - name: Determine Yarn Cache Path - id: yarn-cache-dir-path - run: echo "::set-output name=dir::$(yarn cache dir)" - - - uses: actions/cache@v1 - id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`) - with: - path: ${{ steps.yarn-cache-dir-path.outputs.dir }} - key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} - restore-keys: | - ${{ runner.os }}-yarn- - - name: Use Node.js ${{ matrix.node-version }} uses: actions/setup-node@v1 with: node-version: ${{ matrix.node-version }} - - name: Install Packages - run: yarn install --frozen-lockfile + - name: Install + run: yarn run clean:all && yarn install --frozen-lockfile - name: Build run: yarn build diff --git a/.gitignore b/.gitignore index 6cfcd46f..f310fc56 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ # Yarn .yarn-cache +./test/yarn.lock # Built *.js.map diff --git a/package.json b/package.json index 6d66d68e..098bcde2 100755 --- a/package.json +++ b/package.json @@ -11,11 +11,11 @@ "release": "standard-version", "--------------": "", "format": "prettier --write \"{src,test}/**/{*.js,!(*.d).ts}\"", - "clean": "rimraf dist **/*.tsbuildinfo", - "clean:all": "yarn run clean && rimraf node_modules test/node_modules test/.yarn-cache", - "reset": "yarn run clean:all && yarn install", + "clean": "npx rimraf dist **/*.tsbuildinfo", + "clean:all": "yarn run clean && npx rimraf node_modules **/node_modules test/.yarn-cache", + "reset": "yarn run clean:all && yarn install && yarn build", "-------------- ": "", - "prebuild": "rimraf dist", + "prebuild": "npx rimraf dist", "install:tests": "cd test && yarn install && cd projects/extras && yarn install", "prepare": "yarn run install:tests" }, @@ -58,11 +58,11 @@ "prettier": "^2.3.2", "rimraf": "^3.0.2", "standard-version": "^9.3.1", - "ts-expose-internals": "^4.3.2", + "ts-expose-internals": "^4.4.3", "ts-jest": "^27.0.4", "ts-node": "^10.1.0", - "ts-patch": "^1.4.2", - "typescript": "^4.3.5" + "ts-patch": "^1.4.4", + "typescript": "^4.4.3" }, "peerDependencies": { "typescript": ">=3.6.5" diff --git a/src/transformer.ts b/src/transformer.ts index 634055c3..d9805932 100755 --- a/src/transformer.ts +++ b/src/transformer.ts @@ -18,30 +18,37 @@ function getTsProperties(args: Parameters) { let tsInstance: typeof ts; let compilerOptions: ts.CompilerOptions; let fileNames: readonly string[] | undefined; + let isTranspileOnly = false; let isTsNode = false; - const { 0: program, 2: extras, 3: manualTransformOptions } = args; + const [program, pluginConfig, extras, manualTransformOptions] = args; tsInstance = extras?.ts ?? ts; compilerOptions = manualTransformOptions?.compilerOptions!; + const config = { + ...pluginConfig, + outputMode: pluginConfig?.outputMode === "esm" ? "esm" : "commonjs", + }; + + const tsNodeProps = getTsNodeRegistrationProperties(tsInstance); + if (tsNodeProps) isTsNode = true; if (program) { - compilerOptions ??= program.getCompilerOptions(); + compilerOptions ??= Object.assign({}, program.getCompilerOptions(), tsNodeProps?.compilerOptions); } else if (manualTransformOptions) { fileNames = manualTransformOptions.fileNames; } else { - const tsNodeProps = getTsNodeRegistrationProperties(tsInstance); if (!tsNodeProps) throw new Error( `Cannot transform without a Program, ts-node instance, or manual parameters supplied. ` + `Make sure you're using ts-patch or ts-node with transpileOnly.` ); - isTsNode = true; + isTranspileOnly = true; compilerOptions = tsNodeProps.compilerOptions; fileNames = tsNodeProps.fileNames; } - return { tsInstance, compilerOptions, fileNames, isTsNode }; + return { tsInstance, compilerOptions, fileNames, isTranspileOnly, config, isTsNode }; } // endregion @@ -68,11 +75,12 @@ export default function transformer( tsInstance, compilerOptions, fileNames, - isTsNode + isTranspileOnly, + isTsNode, + config } = getTsProperties([ program, pluginConfig, transformerExtras, manualTransformOptions ]); const rootDirs = compilerOptions.rootDirs?.filter(path.isAbsolute); - const config: TsTransformPathsConfig = pluginConfig ?? {}; const getCanonicalFileName = tsInstance.createGetCanonicalFileName(tsInstance.sys.useCaseSensitiveFileNames); let emitHost = transformationContext.getEmitHost(); @@ -82,13 +90,12 @@ export default function transformer( `No EmitHost found and could not determine files to be processed. Please file an issue with a reproduction!` ); emitHost = createSyntheticEmitHost(compilerOptions, tsInstance, getCanonicalFileName, fileNames as string[]); - } else if (isTsNode) { + } else if (isTranspileOnly) { Object.assign(emitHost, { getCompilerOptions: () => compilerOptions }); } const { configFile, paths } = compilerOptions; - // TODO - Remove typecast when tryParsePatterns is recognized (probably after ts v4.4) - const { tryParsePatterns } = tsInstance as any; + const tryParsePatterns: typeof ts.tryParsePatterns | undefined = tsInstance.tryParsePatterns; const tsTransformPathsContext: TsTransformPathsContext = { compilerOptions, @@ -100,6 +107,7 @@ export default function transformer( transformationContext, tsInstance, emitHost, + isTranspileOnly, isTsNode, tsThreeInstance: cast(tsInstance), excludeMatchers: config.exclude?.map((globPattern) => new Minimatch(globPattern, { matchBase: true })), @@ -108,8 +116,7 @@ export default function transformer( pathsPatterns: paths && (tryParsePatterns - ? // TODO - Remove typecast when pathPatterns is recognized (probably after ts v4.4) - (configFile?.configFileSpecs as any)?.pathPatterns || tryParsePatterns(paths) + ? configFile?.configFileSpecs?.pathPatterns || tryParsePatterns(paths) : tsInstance.getOwnKeys(paths)), }; diff --git a/src/types.ts b/src/types.ts index 50826816..408cff1c 100755 --- a/src/types.ts +++ b/src/types.ts @@ -3,6 +3,7 @@ import ts, { CompilerOptions, EmitHost, Pattern, SourceFile } from "typescript"; import { PluginConfig } from "ts-patch"; import { HarmonyFactory } from "./utils/harmony-factory"; import { IMinimatch } from "minimatch"; +import { RequireSome } from "./utils"; /* ****************************************************************************************************************** */ // region: TS Types @@ -22,6 +23,7 @@ export type ImportOrExportClause = ts.ImportDeclaration["importClause"] | ts.Exp export interface TsTransformPathsConfig extends PluginConfig { readonly useRootDirs?: boolean; readonly exclude?: string[]; + readonly outputMode?: "commonjs" | "esm"; } // endregion @@ -41,16 +43,17 @@ export interface TsTransformPathsContext { readonly tsThreeInstance: TypeScriptThree; readonly tsFactory?: ts.NodeFactory; readonly program?: ts.Program | tsThree.Program; - readonly config: TsTransformPathsConfig; + readonly config: RequireSome; readonly compilerOptions: CompilerOptions; readonly elisionMap: Map>; readonly transformationContext: ts.TransformationContext; readonly rootDirs?: string[]; readonly excludeMatchers: IMinimatch[] | undefined; readonly outputFileNamesCache: Map; - readonly pathsPatterns: (string | Pattern)[] | undefined; + readonly pathsPatterns: readonly (string | Pattern)[] | undefined; readonly emitHost: EmitHost; readonly isTsNode: boolean; + readonly isTranspileOnly: boolean; } export interface VisitorContext extends TsTransformPathsContext { diff --git a/src/utils/general-utils.ts b/src/utils/general-utils.ts index 89652cb9..73cba2f5 100755 --- a/src/utils/general-utils.ts +++ b/src/utils/general-utils.ts @@ -12,3 +12,5 @@ export const isBaseDir = (baseDir: string, testDir: string): boolean => { return relative ? !relative.startsWith("..") && !path.isAbsolute(relative) : true; }; export const maybeAddRelativeLocalPrefix = (p: string) => (p[0] === "." ? p : `./${p}`); + +export type RequireSome = T & Pick, K>; diff --git a/src/utils/resolve-module-name.ts b/src/utils/resolve-module-name.ts index b31158b3..e9e3da05 100755 --- a/src/utils/resolve-module-name.ts +++ b/src/utils/resolve-module-name.ts @@ -2,7 +2,7 @@ import { VisitorContext } from "../types"; import { isBaseDir, isURL, maybeAddRelativeLocalPrefix } from "./general-utils"; import * as path from "path"; import { removeFileExtension, removeSuffix, ResolvedModuleFull, SourceFile } from "typescript"; -import { getOutputDirForSourceFile } from "./ts-helpers"; +import { getOutputPathForSourceFile } from "./ts-helpers"; /* ****************************************************************************************************************** */ // region: Types @@ -63,9 +63,9 @@ function getPathDetail(moduleName: string, resolvedModule: ResolvedModuleFull) { // prettier-ignore const indexType = implicitPackageIndex ? IndexType.ImplicitPackage : - baseNameNoExtension === 'index' && resolvedBaseNameNoExtension === 'index' ? IndexType.Explicit : - baseNameNoExtension !== 'index' && resolvedBaseNameNoExtension === 'index' ? IndexType.Implicit : - IndexType.NonIndex; + baseNameNoExtension === 'index' && resolvedBaseNameNoExtension === 'index' ? IndexType.Explicit : + baseNameNoExtension !== 'index' && resolvedBaseNameNoExtension === 'index' ? IndexType.Implicit : + IndexType.NonIndex; if (indexType === IndexType.Implicit) { baseName = void 0; @@ -121,6 +121,7 @@ function getResolvedSourceFile(context: VisitorContext, fileName: string): Sourc */ export function resolveModuleName(context: VisitorContext, moduleName: string): ResolvedModule | undefined { const { tsInstance, compilerOptions, sourceFile, config, rootDirs } = context; + const useEsmOutput = !context.isDeclarationFile && context.config.outputMode === "esm"; // Attempt to resolve with TS Compiler API const { resolvedModule, failedLookupLocations } = tsInstance.resolveModuleName( @@ -143,18 +144,22 @@ export function resolveModuleName(context: VisitorContext, moduleName: string): const resolvedSourceFile = getResolvedSourceFile(context, resolvedModule.resolvedFileName); - const { indexType, resolvedBaseNameNoExtension, resolvedFileName, implicitPackageIndex, extName, resolvedDir } = - getPathDetail(moduleName, resolvedModule); + const pathDetail = getPathDetail(moduleName, resolvedModule); + const { indexType, resolvedBaseNameNoExtension, resolvedFileName, implicitPackageIndex, resolvedDir } = pathDetail; + let extName = pathDetail.extName; /* Determine output filename */ let outputBaseName = resolvedBaseNameNoExtension ?? ""; - if (indexType === IndexType.Implicit) outputBaseName = outputBaseName.replace(/(\/index$)|(^index$)/, ""); + const moduleFileOutputPath = getOutputPathForSourceFile(context, resolvedSourceFile); + if (useEsmOutput) extName = path.extname(moduleFileOutputPath); + else if (indexType === IndexType.Implicit) outputBaseName = outputBaseName.replace(/(\/index$)|(^index$)/, ""); + if (outputBaseName && extName) outputBaseName = `${outputBaseName}${extName}`; /* Determine output dir */ - let srcFileOutputDir = getOutputDirForSourceFile(context, sourceFile); - let moduleFileOutputDir = implicitPackageIndex ? resolvedDir : getOutputDirForSourceFile(context, resolvedSourceFile); + let srcFileOutputDir = path.dirname(getOutputPathForSourceFile(context, sourceFile)); + let moduleFileOutputDir = implicitPackageIndex ? resolvedDir : path.dirname(moduleFileOutputPath); // Handle rootDirs remapping if (config.useRootDirs && rootDirs) { diff --git a/src/utils/resolve-path-update-node.ts b/src/utils/resolve-path-update-node.ts index 7fd2181c..f3c9fa1e 100755 --- a/src/utils/resolve-path-update-node.ts +++ b/src/utils/resolve-path-update-node.ts @@ -18,6 +18,7 @@ export function resolvePathAndUpdateNode( updaterFn: (newPath: ts.StringLiteral) => ts.Node | undefined ): ts.Node | undefined { const { sourceFile, tsInstance, factory } = context; + const { outputMode } = context.config; const { normalizePath } = tsInstance; /* Handle JSDoc statement tags */ @@ -36,7 +37,7 @@ export function resolvePathAndUpdateNode( /* Resolve Module */ // Skip if no paths match found - if (!isModulePathsMatch(context, moduleName)) return node; + if (outputMode !== "esm" && !isModulePathsMatch(context, moduleName)) return node; const res = resolveModuleName(context, moduleName); if (!res) return node; diff --git a/src/utils/ts-helpers.ts b/src/utils/ts-helpers.ts index 8c4e9deb..df1d368d 100755 --- a/src/utils/ts-helpers.ts +++ b/src/utils/ts-helpers.ts @@ -1,5 +1,4 @@ import ts, { GetCanonicalFileName, SourceFile } from "typescript"; -import path from "path"; import { VisitorContext } from "../types"; import type { REGISTER_INSTANCE } from "ts-node"; @@ -10,9 +9,8 @@ import type { REGISTER_INSTANCE } from "ts-node"; /** * Determine output file path for source file */ -export function getOutputDirForSourceFile(context: VisitorContext, sourceFile: SourceFile): string { +export function getOutputPathForSourceFile(context: VisitorContext, sourceFile: SourceFile): string { const { - tsInstance, emitHost, outputFileNamesCache, compilerOptions, @@ -34,11 +32,9 @@ export function getOutputDirForSourceFile(context: VisitorContext, sourceFile: S `https://github.com/LeDDGroup/typescript-transform-paths/issues` ); - const res = path.dirname(outputPath); + outputFileNamesCache.set(sourceFile, outputPath); - outputFileNamesCache.set(sourceFile, res); - - return tsInstance.normalizePath(res); + return outputPath; } /** @@ -49,7 +45,7 @@ export function isModulePathsMatch(context: VisitorContext, moduleName: string): pathsPatterns, tsInstance: { matchPatternOrExact }, } = context; - return !!(pathsPatterns && matchPatternOrExact(pathsPatterns as readonly string[], moduleName)); + return !!(pathsPatterns && matchPatternOrExact(pathsPatterns, moduleName)); } /** diff --git a/test/.yarnrc b/test/.yarnrc deleted file mode 100755 index c5a57595..00000000 --- a/test/.yarnrc +++ /dev/null @@ -1 +0,0 @@ ---cache-folder .yarn-cache diff --git a/test/package.json b/test/package.json index 2952315b..88e47c8f 100755 --- a/test/package.json +++ b/test/package.json @@ -5,7 +5,7 @@ "prepare": "node prepare.js" }, "devDependencies": { - "typescript-transform-paths": "link:../src", + "typescript-transform-paths": "link:../", "ts-expose-internals": "^4.1.2", "typescript": "npm:typescript@latest", "typescript-three": "npm:typescript@3.6.5", diff --git a/test/projects/extras/package.json b/test/projects/extras/package.json index c9d4ede6..5968d6db 100755 --- a/test/projects/extras/package.json +++ b/test/projects/extras/package.json @@ -3,6 +3,6 @@ "name": "@tests/extras", "version": "0.0.0", "dependencies": { - "typescript-transform-paths": "link:../../../" + "typescript-transform-paths": "*" } } diff --git a/test/projects/general/tsconfig.json b/test/projects/general/tsconfig.json index 5b773121..132e2028 100644 --- a/test/projects/general/tsconfig.json +++ b/test/projects/general/tsconfig.json @@ -16,8 +16,8 @@ "esModuleInterop": true, "plugins": [ - { "transform": "../../src/index.ts" }, - { "transform": "../../src/index.ts", "afterDeclarations": true } + { "transform": "../../../src/index.ts" }, + { "transform": "../../../src/index.ts", "afterDeclarations": true } ] } } diff --git a/test/projects/project-ref/package.json b/test/projects/project-ref/package.json index 7ff64a33..a4602890 100755 --- a/test/projects/project-ref/package.json +++ b/test/projects/project-ref/package.json @@ -3,6 +3,6 @@ "name": "@tests/project-ref", "version": "0.0.0", "dependencies": { - "typescript-transform-paths": "link:../../../" + "typescript-transform-paths": "*" } } diff --git a/test/projects/project-ref/tsconfig.base.json b/test/projects/project-ref/tsconfig.base.json index e562473b..b5bd3845 100755 --- a/test/projects/project-ref/tsconfig.base.json +++ b/test/projects/project-ref/tsconfig.base.json @@ -13,11 +13,12 @@ "#b/*": [ "./b/*" ] }, "plugins": [ + // Note - Paths are relative to one level deeper, due to tsp not resolving from base config dir { - "transform": "./src/index.ts", + "transform": "../../../../src/index.ts", }, { - "transform": "./src/index.ts", + "transform": "../../../../src/index.ts", "afterDeclarations": true } ] diff --git a/test/tests/transformer/specific.test.ts b/test/tests/transformer/specific.test.ts index 9f6f04ad..e6521368 100755 --- a/test/tests/transformer/specific.test.ts +++ b/test/tests/transformer/specific.test.ts @@ -1,3 +1,15 @@ +/** + * Note: To make debug testing easier, you can use the following environment variables to control what tests run: + * + * TS_MODULES - comma separated string of name fields in `tsModules` (config.ts) + * MODES - comma separated string of `modes` (see config heading below) + * OUTPUT_MODES - comma separated string of `outputModes` (see config heading below) + * + * Example — only test latest TS, using program and ts-node, with outputMode 'esm': + * TS_MODULES=latest; + * MODES=program,ts-node; + * OUTPUT_MODES=esm; + */ // noinspection ES6UnusedImports import {} from "ts-expose-internals"; import * as path from "path"; @@ -18,11 +30,8 @@ import TS from "typescript"; const baseConfig: TsTransformPathsConfig = { exclude: ["**/excluded/**", "excluded-file.*"] }; -/* Test Mapping */ const modes = ["program", "manual", "ts-node"] as const; -const testConfigs: { label: string; tsInstance: any; mode: typeof modes[number]; tsSpecifier: string }[] = []; -for (const cfg of tsModules) - testConfigs.push(...modes.map((mode) => ({ label: cfg[0], tsInstance: cfg[1], mode, tsSpecifier: cfg[2] }))); +const outputModes = ["[default]", "commonjs", "esm"] as const; /* File Paths */ const projectRoot = ts.normalizePath(path.join(projectsPaths, "specific")); @@ -35,14 +44,68 @@ const typeElisionIndex = ts.normalizePath(path.join(projectRoot, "src/type-elisi const subPackagesFile = ts.normalizePath(path.join(projectRoot, "src/sub-packages.ts")); const moduleAugmentFile = ts.normalizePath(path.join(projectRoot, "src/module-augment.ts")); +/* ****************************************************************************************************************** * + * Setup + * ****************************************************************************************************************** */ + +const testConfigs = (function prepareConfigs() { + let { TS_MODULES, MODES, OUTPUT_MODES } = process.env; + const opt = { + modules: TS_MODULES?.split(",").map((m) => m.trim().toLowerCase()), + modes: MODES?.split(",").map((m) => m.trim().toLowerCase()), + outputModes: OUTPUT_MODES?.split(",").map((m) => m.trim().toLowerCase()), + }; + + const cfgTsModules = !opt.modules ? tsModules : tsModules.filter((m) => opt.modules!.includes(m[0].toLowerCase())); + const cfgModes = !opt.modes ? modes : modes.filter((m) => opt.modes!.includes(m.toLowerCase())); + const cfgOutputModes = !opt.outputModes + ? outputModes + : outputModes.filter((m) => opt.outputModes!.includes(m.toLowerCase())); + + const res: { + label: string; + tsInstance: any; + mode: typeof modes[number]; + tsSpecifier: string; + config: TsTransformPathsConfig; + outputMode: typeof outputModes[number]; + }[] = []; + + cfgTsModules.forEach((cfg) => + cfgOutputModes.forEach((outputMode) => + res.push( + ...cfgModes.map((mode) => ({ + label: cfg[0], + tsInstance: cfg[1], + mode, + tsSpecifier: cfg[2], + config: { + ...baseConfig, + outputMode: outputMode === "[default]" ? void 0 : outputMode, + }, + outputMode, + })) + ) + ) + ); + + return res; +})(); + /* ****************************************************************************************************************** * * Types * ****************************************************************************************************************** */ +interface TransformedMatchesOpt { + base?: EmittedFiles[]; + kind?: ("dts" | "js")[]; + noEsmFix?: boolean; +} + declare global { namespace jest { interface Matchers { - transformedMatches(expected: RegExp | string, opt?: { base?: EmittedFiles[]; kind?: ("dts" | "js")[] }): void; + transformedMatches(expected: RegExp | string, opt?: TransformedMatchesOpt): void; } } } @@ -52,194 +115,228 @@ declare global { * ****************************************************************************************************************** */ describe(`Specific Tests`, () => { - describe.each(testConfigs)(`TypeScript $label - Mode: $mode`, ({ tsInstance, mode, tsSpecifier }) => { - const tsVersion = +tsInstance.versionMajorMinor.split(".").slice(0, 2).join(""); - let normalEmit: EmittedFiles; - let rootDirsEmit: EmittedFiles; - let skipDts = false; - - beforeAll(() => { - switch (mode) { - case "program": - const program = createTsProgram({ - tsInstance, - tsConfigFile, - pluginOptions: { - ...baseConfig, - useRootDirs: false, - }, - }); - normalEmit = getEmitResultFromProgram(program); - - const rootDirsProgram = createTsProgram({ - tsInstance, - tsConfigFile, - pluginOptions: { - ...baseConfig, - useRootDirs: true, - }, - }); - rootDirsEmit = getEmitResultFromProgram(rootDirsProgram); - break; - case "manual": { - skipDts = true; - const pcl = tsInstance.getParsedCommandLineOfConfigFile( - tsConfigFile, - {}, - tsInstance.sys - )! as TS.ParsedCommandLine; - normalEmit = getManualEmitResult({ ...baseConfig, useRootDirs: false }, tsInstance, pcl); - rootDirsEmit = getManualEmitResult({ ...baseConfig, useRootDirs: true }, tsInstance, pcl); - break; - } - case "ts-node": { - const pcl = tsInstance.getParsedCommandLineOfConfigFile( - tsConfigFile, - {}, - tsInstance.sys - )! as TS.ParsedCommandLine; - skipDts = true; - normalEmit = getTsNodeEmitResult({ ...baseConfig, useRootDirs: false }, pcl, tsSpecifier); - rootDirsEmit = getTsNodeEmitResult({ ...baseConfig, useRootDirs: true }, pcl, tsSpecifier); + describe.each(testConfigs)( + `TypeScript $label - Mode: $mode - OutputMode: $outputMode`, + ({ tsInstance, mode, tsSpecifier, config, outputMode }) => { + const tsVersion = +tsInstance.versionMajorMinor.split(".").slice(0, 2).join(""); + let normalEmit: EmittedFiles; + let rootDirsEmit: EmittedFiles; + let skipDts = false; + + beforeAll(() => { + switch (mode) { + case "program": + const program = createTsProgram({ + tsInstance, + tsConfigFile, + pluginOptions: { + ...config, + useRootDirs: false, + }, + }); + normalEmit = getEmitResultFromProgram(program); + + const rootDirsProgram = createTsProgram({ + tsInstance, + tsConfigFile, + pluginOptions: { + ...config, + useRootDirs: true, + }, + }); + rootDirsEmit = getEmitResultFromProgram(rootDirsProgram); + break; + case "manual": { + skipDts = true; + const pcl = tsInstance.getParsedCommandLineOfConfigFile( + tsConfigFile, + {}, + tsInstance.sys + )! as TS.ParsedCommandLine; + normalEmit = getManualEmitResult({ ...config, useRootDirs: false }, tsInstance, pcl); + rootDirsEmit = getManualEmitResult({ ...config, useRootDirs: true }, tsInstance, pcl); + break; + } + case "ts-node": { + const pcl = tsInstance.getParsedCommandLineOfConfigFile( + tsConfigFile, + {}, + tsInstance.sys + )! as TS.ParsedCommandLine; + skipDts = true; + normalEmit = getTsNodeEmitResult({ ...config, useRootDirs: false }, pcl, tsSpecifier); + rootDirsEmit = getTsNodeEmitResult({ ...config, useRootDirs: true }, pcl, tsSpecifier); + } } - } - - expect.extend({ - transformedMatches( - fileName: string, - expected: RegExp | string, - opt?: { base?: EmittedFiles[]; kind?: ("dts" | "js")[] } - ) { - const bases = opt?.base ?? [normalEmit, rootDirsEmit]; - const kinds = (opt?.kind ?? ["dts", "js"]).filter((k) => !skipDts || k !== "dts"); - - let failed: boolean = false; - const messages: string[] = []; - for (const base of bases) { - for (const kind of kinds) { - const content = base[fileName][kind]; - const isValid = typeof expected === "string" ? content.indexOf(expected) >= 0 : expected.test(content); - if (!isValid) { - failed = true; - messages.push( - `File: ${fileName}\nKind: ${kind}\nrootDirs: ${base === normalEmit}\n\n` + - `Expected: \`${expected}\`\nReceived:\n\t${content.replace(/(\r?\n)+/g, "$1\t")}` - ); + + expect.extend({ + transformedMatches(fileName: string, expected: RegExp | string, opt?: TransformedMatchesOpt) { + const bases = opt?.base ?? [normalEmit, rootDirsEmit]; + const kinds = (opt?.kind ?? ["dts", "js"]).filter((k) => !skipDts || k !== "dts"); + + let failed: boolean = false; + const messages: string[] = []; + for (const base of bases) { + for (const kind of kinds) { + const content = base[fileName][kind]; + const exp = getExpected(kind); + const isValid = typeof exp === "string" ? content.indexOf(exp) >= 0 : exp.test(content); + if (!isValid) { + failed = true; + messages.push( + `File: ${fileName}\nKind: ${kind}\nrootDirs: ${base === normalEmit}\n\n` + + `Expected: \`${exp}\`\nReceived:\n\t${content.replace(/(\r?\n)+/g, "$1\t")}` + ); + } } } - } - return { message: () => messages.join("\n\n"), pass: !failed }; - }, + return { message: () => messages.join("\n\n"), pass: !failed }; + + function getExpected(kind: "dts" | "js") { + if (!(expected instanceof RegExp) && !opt?.noEsmFix && kind === "js" && outputMode === "esm") { + const regEx = /"\.(.+?)"/g; + let res: string = ""; + + let match: RegExpExecArray | null; + let lastIndex = 0; + while ((match = regEx.exec(expected)) !== null) { + let p = match[1]; + if (!path.extname(p)) p += ".js"; + res += expected.slice(lastIndex, match.index) + `".${p}"`; + lastIndex = res.length; + } + + return res; + } + + return expected; + } + }, + }); + }); + + describe(`Options`, () => { + test(`(useRootDirs: true) Re-maps for rootDirs`, () => { + expect(genFile).transformedMatches(`import "./src-file"`, { base: [rootDirsEmit] }); + expect(srcFile).transformedMatches(`import "./gen-file"`, { base: [rootDirsEmit] }); + expect(indexFile).transformedMatches(`export { b } from "./dir/gen-file"`, { base: [rootDirsEmit] }); + expect(indexFile).transformedMatches(`export { a } from "./dir/src-file"`, { base: [rootDirsEmit] }); + }); + + test(`(useRootDirs: false) Ignores rootDirs`, () => { + expect(genFile).transformedMatches(`import "../../src/dir/src-file"`, { base: [normalEmit] }); + expect(srcFile).transformedMatches(`import "../../generated/dir/gen-file"`, { base: [normalEmit] }); + expect(indexFile).transformedMatches(`export { b } from "../generated/dir/gen-file"`, { base: [normalEmit] }); + expect(indexFile).transformedMatches(`export { a } from "./dir/src-file"`, { base: [normalEmit] }); + }); + + test(`(exclude) Doesn't transform for exclusion patterns`, () => { + expect(indexFile).transformedMatches( + /export { bb } from "#exclusion\/ex";\s*export { dd } from "#root\/excluded-file"/ + ); + }); }); - }); - - describe(`Options`, () => { - test(`(useRootDirs: true) Re-maps for rootDirs`, () => { - expect(genFile).transformedMatches(`import "./src-file"`, { base: [rootDirsEmit] }); - expect(srcFile).transformedMatches(`import "./gen-file"`, { base: [rootDirsEmit] }); - expect(indexFile).transformedMatches(`export { b } from "./dir/gen-file"`, { base: [rootDirsEmit] }); - expect(indexFile).transformedMatches(`export { a } from "./dir/src-file"`, { base: [rootDirsEmit] }); + + describe(`Tags`, () => { + test(`(@no-transform-path) Doesn't transform path`, () => { + for (let i = 1; i <= 4; i++) + expect(tagFile).transformedMatches(`import * as skipTransform${i} from "#root\/index`); + }); + + test(`(@transform-path) Transforms path with explicit value`, () => { + expect(tagFile).transformedMatches(`import * as explicitTransform1 from "./dir/src-file"`, { + noEsmFix: true, + }); + expect(tagFile).transformedMatches(`import * as explicitTransform2 from "http://www.go.com/react.js"`); + expect(tagFile).transformedMatches(`import * as explicitTransform3 from "./dir/src-file"`, { + noEsmFix: true, + }); + expect(tagFile).transformedMatches(`import * as explicitTransform4 from "http://www.go.com/react.js"`); + }); }); - test(`(useRootDirs: false) Ignores rootDirs`, () => { - expect(genFile).transformedMatches(`import "../../src/dir/src-file"`, { base: [normalEmit] }); - expect(srcFile).transformedMatches(`import "../../generated/dir/gen-file"`, { base: [normalEmit] }); - expect(indexFile).transformedMatches(`export { b } from "../generated/dir/gen-file"`, { base: [normalEmit] }); - expect(indexFile).transformedMatches(`export { a } from "./dir/src-file"`, { base: [normalEmit] }); + (mode === "program" ? test : test.skip)(`Type elision works properly`, () => { + expect(typeElisionIndex).transformedMatches( + outputMode === "esm" + ? /import { ConstB } from "\.\/a\.js";\s*export { ConstB };/ + : /import { ConstB } from "\.\/a";\s*export { ConstB };/, + { kind: ["js"] } + ); + expect(typeElisionIndex).transformedMatches( + /import { ConstB, TypeA } from "\.\/a";\s*import { TypeA as TypeA2 } from "\.\/a";\s*export { ConstB, TypeA };\s*export { TypeA2 };/, + { kind: ["dts"] } + ); }); - test(`(exclude) Doesn't transform for exclusion patterns`, () => { + (!skipDts && tsVersion >= 38 ? test : test.skip)(`Import type-only transforms`, () => { + expect(indexFile).transformedMatches(`import type { A as ATypeOnly } from "./dir/src-file"`, { kind: ["dts"] }); + }); + + test(`Copies comments in async import`, () => { + expect(indexFile).transformedMatches(`import(/* webpackChunkName: "Comment" */ "./dir/src-file");`, { + kind: ["js"], + }); expect(indexFile).transformedMatches( - /export { bb } from "#exclusion\/ex";\s*export { dd } from "#root\/excluded-file"/ + /\/\/ comment 1\r?\n\s*\r?\n\/\*\r?\n\s*comment 2\r?\n\s*\*\/\r?\n\s*"\.\/dir\/src-file(\.js)?"/, + { kind: ["js"] } ); }); - }); - describe(`Tags`, () => { - test(`(@no-transform-path) Doesn't transform path`, () => { - for (let i = 1; i <= 4; i++) - expect(tagFile).transformedMatches(`import * as skipTransform${i} from "#root\/index`); + test(`Preserves explicit extensions`, () => { + expect(indexFile).transformedMatches(`export { JsonValue } from "./data.json"`); + expect(indexFile).transformedMatches(`export { GeneralConstA } from "./general"`); + expect(indexFile).transformedMatches(`export { GeneralConstB } from "./general.js"`); }); - test(`(@transform-path) Transforms path with explicit value`, () => { - expect(tagFile).transformedMatches(`import * as explicitTransform1 from "./dir/src-file"`); - expect(tagFile).transformedMatches(`import * as explicitTransform2 from "http://www.go.com/react.js"`); - expect(tagFile).transformedMatches(`import * as explicitTransform3 from "./dir/src-file"`); - expect(tagFile).transformedMatches(`import * as explicitTransform4 from "http://www.go.com/react.js"`); + test(`Properly handles implicit index filenames`, () => { + const implicitMatch = `export { ConstB } from "./type-elision"`; + const explicitMatch = `export { ConstB } from "./type-elision/index.js"`; + + expect(indexFile).transformedMatches(outputMode === "esm" ? explicitMatch : implicitMatch, { kind: ["js"] }); + expect(indexFile).transformedMatches(implicitMatch, { kind: ["dts"] }); }); - }); - (mode === "program" ? test : test.skip)(`Type elision works properly`, () => { - expect(typeElisionIndex).transformedMatches(/import { ConstB } from "\.\/a";\s*export { ConstB };/, { - kind: ["js"], + test(`Resolves sub-modules properly`, () => { + const a = { + js: `export { packageAConst } from "./packages/pkg-a"`, + full: `export { packageAConst, PackageAType } from "./packages/pkg-a"`, + }; + const b = { + js: `export { packageBConst } from "./packages/pkg-b"`, + full: `export { packageBConst, PackageBType } from "./packages/pkg-b"`, + }; + const c = { + js: `export { packageCConst } from "./packages/pkg-c"`, + full: `export { packageCConst, PackageCType } from "./packages/pkg-c"`, + }; + const sub = { + js: `export { subPackageConst } from "./packages/pkg-a/sub-pkg"`, + full: `export { SubPackageType, subPackageConst } from "./packages/pkg-a/sub-pkg"`, + }; + + for (const exp of [a, b, c, sub]) { + expect(subPackagesFile).transformedMatches(mode !== "program" ? exp.full : exp.js, { + kind: ["js"], + noEsmFix: true, + }); + if (!skipDts) expect(subPackagesFile).transformedMatches(exp.full, { kind: ["dts"] }); + } + + expect(subPackagesFile).transformedMatches(`export { packageCConst as C2 } from "./packages/pkg-c/main"`); + expect(subPackagesFile).transformedMatches(`export { packageCConst as C3 } from "./packages/pkg-c/main.js"`); + expect(subPackagesFile).transformedMatches( + `export { subPackageConst as C4 } from "./packages/pkg-a/sub-pkg/main"` + ); + expect(subPackagesFile).transformedMatches( + `export { subPackageConst as C5 } from "./packages/pkg-a/sub-pkg/main.js"` + ); }); - expect(typeElisionIndex).transformedMatches( - /import { ConstB, TypeA } from "\.\/a";\s*import { TypeA as TypeA2 } from "\.\/a";\s*export { ConstB, TypeA };\s*export { TypeA2 };/, - { kind: ["dts"] } - ); - }); - - (!skipDts && tsVersion >= 38 ? test : test.skip)(`Import type-only transforms`, () => { - expect(indexFile).transformedMatches(`import type { A as ATypeOnly } from "./dir/src-file"`, { kind: ["dts"] }); - }); - - test(`Copies comments in async import`, () => { - expect(indexFile).transformedMatches(`import(/* webpackChunkName: "Comment" */ "./dir/src-file");`, { - kind: ["js"], + + (!skipDts ? test : test.skip)(`Resolves module augmentation`, () => { + expect(moduleAugmentFile).transformedMatches(`declare module "./general" {`, { kind: ["dts"] }); + expect(moduleAugmentFile).transformedMatches(`declare module "./excluded-file" {`, { kind: ["dts"] }); }); - expect(indexFile).transformedMatches( - /\/\/ comment 1\r?\n\s*\r?\n\/\*\r?\n\s*comment 2\r?\n\s*\*\/\r?\n\s*"\.\/dir\/src-file"/, - { kind: ["js"] } - ); - }); - - test(`Preserves explicit extensions`, () => { - expect(indexFile).transformedMatches(`export { JsonValue } from "./data.json"`); - expect(indexFile).transformedMatches(`export { GeneralConstA } from "./general"`); - expect(indexFile).transformedMatches(`export { GeneralConstB } from "./general.js"`); - }); - - test(`Does not output implicit index filenames`, () => { - expect(indexFile).transformedMatches(`export { ConstB } from "./type-elision"`); - }); - - test(`Resolves sub-modules properly`, () => { - const a = { - js: `export { packageAConst } from "./packages/pkg-a"`, - full: `export { packageAConst, PackageAType } from "./packages/pkg-a"`, - }; - const b = { - js: `export { packageBConst } from "./packages/pkg-b"`, - full: `export { packageBConst, PackageBType } from "./packages/pkg-b"`, - }; - const c = { - js: `export { packageCConst } from "./packages/pkg-c"`, - full: `export { packageCConst, PackageCType } from "./packages/pkg-c"`, - }; - const sub = { - js: `export { subPackageConst } from "./packages/pkg-a/sub-pkg"`, - full: `export { SubPackageType, subPackageConst } from "./packages/pkg-a/sub-pkg"`, - }; - - for (const exp of [a, b, c, sub]) { - expect(subPackagesFile).transformedMatches(mode !== "program" ? exp.full : exp.js, { kind: ["js"] }); - if (!skipDts) expect(subPackagesFile).transformedMatches(exp.full, { kind: ["dts"] }); - } - - expect(subPackagesFile).transformedMatches(`export { packageCConst as C2 } from "./packages/pkg-c/main"`); - expect(subPackagesFile).transformedMatches(`export { packageCConst as C3 } from "./packages/pkg-c/main.js"`); - expect(subPackagesFile).transformedMatches( - `export { subPackageConst as C4 } from "./packages/pkg-a/sub-pkg/main"` - ); - expect(subPackagesFile).transformedMatches( - `export { subPackageConst as C5 } from "./packages/pkg-a/sub-pkg/main.js"` - ); - }); - - (!skipDts ? test : test.skip)(`Resolves module augmentation`, () => { - expect(moduleAugmentFile).transformedMatches(`declare module "./general" {`, { kind: ["dts"] }); - expect(moduleAugmentFile).transformedMatches(`declare module "./excluded-file" {`, { kind: ["dts"] }); - }); - }); + } + ); }); diff --git a/test/yarn.lock b/test/yarn.lock deleted file mode 100755 index 91932f59..00000000 --- a/test/yarn.lock +++ /dev/null @@ -1,242 +0,0 @@ -# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. -# yarn lockfile v1 - - -ansi-regex@^5.0.0: - version "5.0.0" - resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-5.0.0.tgz#388539f55179bf39339c81af30a654d69f87cb75" - integrity sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg== - -ansi-styles@^4.1.0: - version "4.3.0" - resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-4.3.0.tgz#edd803628ae71c04c85ae7a0906edad34b648937" - integrity sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg== - dependencies: - color-convert "^2.0.1" - -balanced-match@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767" - integrity sha1-ibTRmasr7kneFk6gK4nORi1xt2c= - -brace-expansion@^1.1.7: - version "1.1.11" - resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.11.tgz#3c7fcbf529d87226f3d2f52b966ff5271eb441dd" - integrity sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA== - dependencies: - balanced-match "^1.0.0" - concat-map "0.0.1" - -chalk@^4.1.0: - version "4.1.0" - resolved "https://registry.yarnpkg.com/chalk/-/chalk-4.1.0.tgz#4e14870a618d9e2edd97dd8345fd9d9dc315646a" - integrity sha512-qwx12AxXe2Q5xQ43Ac//I6v5aXTipYrSESdOgzrN+9XjgEpyjpKuvSGaN4qE93f7TQTlerQQ8S+EQ0EyDoVL1A== - dependencies: - ansi-styles "^4.1.0" - supports-color "^7.1.0" - -color-convert@^2.0.1: - version "2.0.1" - resolved "https://registry.yarnpkg.com/color-convert/-/color-convert-2.0.1.tgz#72d3a68d598c9bdb3af2ad1e84f21d896abd4de3" - integrity sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ== - dependencies: - color-name "~1.1.4" - -color-name@~1.1.4: - version "1.1.4" - resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.4.tgz#c2a09a87acbde69543de6f63fa3995c826c536a2" - integrity sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA== - -concat-map@0.0.1: - version "0.0.1" - resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b" - integrity sha1-2Klr13/Wjfd5OnMDajug1UBdR3s= - -fs.realpath@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f" - integrity sha1-FQStJSMVjKpA20onh8sBQRmU6k8= - -function-bind@^1.1.1: - version "1.1.1" - resolved "https://registry.yarnpkg.com/function-bind/-/function-bind-1.1.1.tgz#a56899d3ea3c9bab874bb9773b7c5ede92f4895d" - integrity sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A== - -glob@^7.0.0: - version "7.1.6" - resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.6.tgz#141f33b81a7c2492e125594307480c46679278a6" - integrity sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA== - dependencies: - fs.realpath "^1.0.0" - inflight "^1.0.4" - inherits "2" - minimatch "^3.0.4" - once "^1.3.0" - path-is-absolute "^1.0.0" - -global-prefix@^3.0.0: - version "3.0.0" - resolved "https://registry.yarnpkg.com/global-prefix/-/global-prefix-3.0.0.tgz#fc85f73064df69f50421f47f883fe5b913ba9b97" - integrity sha512-awConJSVCHVGND6x3tmMaKcQvwXLhjdkmomy2W+Goaui8YPgYgXJZewhg3fWC+DlfqqQuWg8AwqjGTD2nAPVWg== - dependencies: - ini "^1.3.5" - kind-of "^6.0.2" - which "^1.3.1" - -has-flag@^4.0.0: - version "4.0.0" - resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-4.0.0.tgz#944771fd9c81c81265c4d6941860da06bb59479b" - integrity sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ== - -has@^1.0.3: - version "1.0.3" - resolved "https://registry.yarnpkg.com/has/-/has-1.0.3.tgz#722d7cbfc1f6aa8241f16dd814e011e1f41e8796" - integrity sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw== - dependencies: - function-bind "^1.1.1" - -inflight@^1.0.4: - version "1.0.6" - resolved "https://registry.yarnpkg.com/inflight/-/inflight-1.0.6.tgz#49bd6331d7d02d0c09bc910a1075ba8165b56df9" - integrity sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk= - dependencies: - once "^1.3.0" - wrappy "1" - -inherits@2: - version "2.0.4" - resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c" - integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ== - -ini@^1.3.5: - version "1.3.5" - resolved "https://registry.yarnpkg.com/ini/-/ini-1.3.5.tgz#eee25f56db1c9ec6085e0c22778083f596abf927" - integrity sha512-RZY5huIKCMRWDUqZlEi72f/lmXKMvuszcMBduliQ3nnWbx9X/ZBQO7DijMEYS9EhHBb2qacRUMtC7svLwe0lcw== - -interpret@^1.0.0: - version "1.4.0" - resolved "https://registry.yarnpkg.com/interpret/-/interpret-1.4.0.tgz#665ab8bc4da27a774a40584e812e3e0fa45b1a1e" - integrity sha512-agE4QfB2Lkp9uICn7BAqoscw4SZP9kTE2hxiFI3jBPmXJfdqiahTbUuKGsMoN2GtqL9AxhYioAcVvgsb1HvRbA== - -is-core-module@^2.1.0: - version "2.1.0" - resolved "https://registry.yarnpkg.com/is-core-module/-/is-core-module-2.1.0.tgz#a4cc031d9b1aca63eecbd18a650e13cb4eeab946" - integrity sha512-YcV7BgVMRFRua2FqQzKtTDMz8iCuLEyGKjr70q8Zm1yy2qKcurbFEd79PAdHV77oL3NrAaOVQIbMmiHQCHB7ZA== - dependencies: - has "^1.0.3" - -isexe@^2.0.0: - version "2.0.0" - resolved "https://registry.yarnpkg.com/isexe/-/isexe-2.0.0.tgz#e8fbf374dc556ff8947a10dcb0572d633f2cfa10" - integrity sha1-6PvzdNxVb/iUehDcsFctYz8s+hA= - -kind-of@^6.0.2: - version "6.0.3" - resolved "https://registry.yarnpkg.com/kind-of/-/kind-of-6.0.3.tgz#07c05034a6c349fa06e24fa35aa76db4580ce4dd" - integrity sha512-dcS1ul+9tmeD95T+x28/ehLgd9mENa3LsvDTtzm3vyBEO7RPptvAD+t44WVXaUjTBRcrpFeFlC8WCruUR456hw== - -minimatch@^3.0.4: - version "3.0.4" - resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083" - integrity sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA== - dependencies: - brace-expansion "^1.1.7" - -minimist@^1.2.5: - version "1.2.5" - resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.5.tgz#67d66014b66a6a8aaa0c083c5fd58df4e4e97602" - integrity sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw== - -once@^1.3.0: - version "1.4.0" - resolved "https://registry.yarnpkg.com/once/-/once-1.4.0.tgz#583b1aa775961d4b113ac17d9c50baef9dd76bd1" - integrity sha1-WDsap3WWHUsROsF9nFC6753Xa9E= - dependencies: - wrappy "1" - -path-is-absolute@^1.0.0: - version "1.0.1" - resolved "https://registry.yarnpkg.com/path-is-absolute/-/path-is-absolute-1.0.1.tgz#174b9268735534ffbc7ace6bf53a5a9e1b5c5f5f" - integrity sha1-F0uSaHNVNP+8es5r9TpanhtcX18= - -path-parse@^1.0.6: - version "1.0.6" - resolved "https://registry.yarnpkg.com/path-parse/-/path-parse-1.0.6.tgz#d62dbb5679405d72c4737ec58600e9ddcf06d24c" - integrity sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw== - -rechoir@^0.6.2: - version "0.6.2" - resolved "https://registry.yarnpkg.com/rechoir/-/rechoir-0.6.2.tgz#85204b54dba82d5742e28c96756ef43af50e3384" - integrity sha1-hSBLVNuoLVdC4oyWdW70OvUOM4Q= - dependencies: - resolve "^1.1.6" - -resolve@^1.1.6: - version "1.19.0" - resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.19.0.tgz#1af5bf630409734a067cae29318aac7fa29a267c" - integrity sha512-rArEXAgsBG4UgRGcynxWIWKFvh/XZCcS8UJdHhwy91zwAvCZIbcs+vAbflgBnNjYMs/i/i+/Ux6IZhML1yPvxg== - dependencies: - is-core-module "^2.1.0" - path-parse "^1.0.6" - -shelljs@^0.8.4: - version "0.8.4" - resolved "https://registry.yarnpkg.com/shelljs/-/shelljs-0.8.4.tgz#de7684feeb767f8716b326078a8a00875890e3c2" - integrity sha512-7gk3UZ9kOfPLIAbslLzyWeGiEqx9e3rxwZM0KE6EL8GlGwjym9Mrlx5/p33bWTu9YG6vcS4MBxYZDHYr5lr8BQ== - dependencies: - glob "^7.0.0" - interpret "^1.0.0" - rechoir "^0.6.2" - -strip-ansi@^6.0.0: - version "6.0.0" - resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.0.tgz#0b1571dd7669ccd4f3e06e14ef1eed26225ae532" - integrity sha512-AuvKTrTfQNYNIctbR1K/YGTR1756GycPsg7b9bdV9Duqur4gv6aKqHXah67Z8ImS7WEz5QVcOtlfW2rZEugt6w== - dependencies: - ansi-regex "^5.0.0" - -supports-color@^7.1.0: - version "7.2.0" - resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-7.2.0.tgz#1b7dcdcb32b8138801b3e478ba6a51caa89648da" - integrity sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw== - dependencies: - has-flag "^4.0.0" - -ts-expose-internals@^4.1.2: - version "4.1.2" - resolved "https://registry.yarnpkg.com/ts-expose-internals/-/ts-expose-internals-4.1.2.tgz#c89a64be5b7ae6634d2f0f25dffa798e2931d136" - integrity sha512-J5xYsQocO5tjP2UMkGlOb5U+joore0AiL1drA5bMPganlQR/9gPmQVO55pQDeHVfy8OATqZaBT5JweyjI6f3eA== - -"ts-patch@link:../node_modules/ts-patch": - version "0.0.0" - uid "" - -"typescript-three@npm:typescript@3.6.5": - version "3.6.5" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.6.5.tgz#dae20114a7b4ff4bd642db9c8c699f2953e8bbdb" - integrity sha512-BEjlc0Z06ORZKbtcxGrIvvwYs5hAnuo6TKdNFL55frVDlB+na3z5bsLhFaIxmT+dPWgBIjMo6aNnTOgHHmHgiQ== - -"typescript-transform-paths@link:..": - version "0.0.0" - uid "" - -"typescript-transform-paths@link:../src": - version "0.0.0" - uid "" - -"typescript@npm:typescript@latest": - version "4.3.5" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.3.5.tgz#4d1c37cc16e893973c45a06886b7113234f119f4" - integrity sha512-DqQgihaQ9cUrskJo9kIyW/+g0Vxsk8cDtZ52a3NGh0YNTfpUSArXSohyUGnvbPazEPLu398C0UxmKSOrPumUzA== - -which@^1.3.1: - version "1.3.1" - resolved "https://registry.yarnpkg.com/which/-/which-1.3.1.tgz#a45043d54f5805316da8d62f9f50918d3da70b0a" - integrity sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ== - dependencies: - isexe "^2.0.0" - -wrappy@1: - version "1.0.2" - resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f" - integrity sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8= diff --git a/types/index.d.ts b/types/index.d.ts index 0d8eddb1..67aef4ad 100755 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -8,9 +8,7 @@ import ts from 'typescript' export interface TsTransformPathsConfig { readonly useRootDirs?: boolean; readonly exclude?: string[]; - readonly afterDeclarations?: boolean; - readonly tsConfig?: string; - readonly transform?: string + readonly outputMode?: 'commonjs' | 'esm' } export interface TransformerExtras { diff --git a/yarn.lock b/yarn.lock index 16b40e9e..4b622de8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1827,7 +1827,7 @@ glob@^7.0.0, glob@^7.1.1, glob@^7.1.2, glob@^7.1.3: once "^1.3.0" path-is-absolute "^1.0.0" -glob@^7.1.4: +glob@^7.1.4, glob@^7.1.7: version "7.1.7" resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.7.tgz#3b193e9233f01d42d0b3f78294bbeeb418f94a90" integrity sha512-OvD9ENzPLbegENnYP5UUfJIirTg4+XwMWGaQfQTY0JenxNvvIKP3U3/tAQSPIu/lHxXYSZmpXlUHeqAIdKzBLQ== @@ -3637,10 +3637,10 @@ trim-off-newlines@^1.0.0: resolved "https://registry.yarnpkg.com/trim-off-newlines/-/trim-off-newlines-1.0.1.tgz#9f9ba9d9efa8764c387698bcbfeb2c848f11adb3" integrity sha1-n5up2e+odkw4dpi8v+sshI8RrbM= -ts-expose-internals@^4.3.2: - version "4.3.2" - resolved "https://registry.yarnpkg.com/ts-expose-internals/-/ts-expose-internals-4.3.2.tgz#99ea3fd7b2b0750e994143c20fe269a5d434dee1" - integrity sha512-QqBZDp8fOVFW+/+taGQXx6K/gmU+/Zs9yLxcZcrMObHhmvqBzuImjIU7ZTY/HfcZStO2eXWtJrIlFNjepCV1ew== +ts-expose-internals@^4.4.3: + version "4.4.3" + resolved "https://registry.yarnpkg.com/ts-expose-internals/-/ts-expose-internals-4.4.3.tgz#02cd43988403b35d266ac69bf5bee02a885093f4" + integrity sha512-hvdD6g3aOdh6vnTMBpKfy+mfG4uTxN7aq5PYC1/s0MCqEKY3+1QD0o1yEgafIGzp9Bi4k7ciaB/lPWV8s55xTQ== ts-jest@^27.0.4: version "27.0.4" @@ -3674,14 +3674,16 @@ ts-node@^10.1.0: source-map-support "^0.5.17" yn "3.1.1" -ts-patch@^1.4.2: - version "1.4.2" - resolved "https://registry.yarnpkg.com/ts-patch/-/ts-patch-1.4.2.tgz#2b763dc1de5a24631062844735ca169821c2c604" - integrity sha512-Nj3mjvQM3t8cB4wGfLKeE8zBT+cx1mDjttOcx9nb2fEl6Q/5u79w19tQniv2eLmeYEbki/+wdQc0zszPEpOxOg== +ts-patch@^1.4.4: + version "1.4.4" + resolved "https://registry.yarnpkg.com/ts-patch/-/ts-patch-1.4.4.tgz#c4814af4ab36183ddcf04c178f0153ce6ef48245" + integrity sha512-b0CxxrkrCGsD22gl5BtSFlXzyTFP2mbOVffxMOWRrwdSh37sM01wzxSY4wlbBiHHHAJICmaaDgESzJ8lKkVoZA== dependencies: chalk "^4.1.0" + glob "^7.1.7" global-prefix "^3.0.0" minimist "^1.2.5" + resolve "^1.20.0" shelljs "^0.8.4" strip-ansi "^6.0.0" @@ -3734,10 +3736,10 @@ typedarray@^0.0.6: resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777" integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c= -typescript@^4.3.5: - version "4.3.5" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.3.5.tgz#4d1c37cc16e893973c45a06886b7113234f119f4" - integrity sha512-DqQgihaQ9cUrskJo9kIyW/+g0Vxsk8cDtZ52a3NGh0YNTfpUSArXSohyUGnvbPazEPLu398C0UxmKSOrPumUzA== +typescript@^4.4.3: + version "4.4.3" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.4.3.tgz#bdc5407caa2b109efd4f82fe130656f977a29324" + integrity sha512-4xfscpisVgqqDfPaJo5vkd+Qd/ItkoagnHpufr+i2QCHBsNYp+G7UAoyFl8aPtx879u38wPV65rZ8qbGZijalA== uglify-js@^3.1.4: version "3.13.5"