diff --git a/projects/project24/.gitignore b/projects/project24/.gitignore new file mode 100644 index 0000000..637d92c --- /dev/null +++ b/projects/project24/.gitignore @@ -0,0 +1,2 @@ +.idea/ +node_modules/ \ No newline at end of file diff --git a/projects/project24/README.md b/projects/project24/README.md new file mode 100644 index 0000000..edac95b --- /dev/null +++ b/projects/project24/README.md @@ -0,0 +1,37 @@ +# tsc-alias-bug-demo + +Steps to reproduce https://github.com/justkey007/tsc-alias/issues/154: + +1) Install dependencies +```sh +npm install +``` + +2) Start the app using `ts-node` +```sh +npm start +``` +Output: +``` +[Function: i18nConfigure] +Translation +``` + +3) Compile TS files and start the app +```sh +npm run build && node dist/index.js +``` +Output: +``` +console.log(i18n_1.default.configure); + ^ +TypeError: Cannot read property 'configure' of undefined +``` +It happens because `dist/i18n/index.js` contains +```js +const i18n_1 = __importDefault(require("../i18n")); +``` +instead of +```js +const i18n_1 = __importDefault(require("i18n")); +``` \ No newline at end of file diff --git a/projects/project24/package.json b/projects/project24/package.json new file mode 100644 index 0000000..c8f0619 --- /dev/null +++ b/projects/project24/package.json @@ -0,0 +1,26 @@ +{ + "name": "tsc-alias-bug-demo", + "version": "1.0.0", + "description": "Demonstration of a bug with incorrect module path", + "private": true, + "main": "dist/index.js", + "scripts": { + "build": "npm install && tsc && tsc-alias", + "start": "npm run build && node dist/index.js" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/Jokero/tsc-alias-bug.git" + }, + "author": "Dmitry Kirilyuk ", + "license": "MIT", + "devDependencies": { + "@types/i18n": "^0.13.6", + "ts-node": "^10.9.1", + "tsc-alias": "^1.8.3", + "typescript": "^4.9.5" + }, + "dependencies": { + "i18n": "^0.15.1" + } +} diff --git a/projects/project24/src/i18n/index.ts b/projects/project24/src/i18n/index.ts new file mode 100644 index 0000000..db481ef --- /dev/null +++ b/projects/project24/src/i18n/index.ts @@ -0,0 +1,5 @@ +import i18n from 'i18n'; + +console.log(i18n.configure); + +export default () => 'Translation'; diff --git a/projects/project24/src/index.ts b/projects/project24/src/index.ts new file mode 100644 index 0000000..482505f --- /dev/null +++ b/projects/project24/src/index.ts @@ -0,0 +1,3 @@ +import i18n from './i18n'; + +console.log(i18n()); diff --git a/projects/project24/tsconfig.json b/projects/project24/tsconfig.json new file mode 100644 index 0000000..98d0118 --- /dev/null +++ b/projects/project24/tsconfig.json @@ -0,0 +1,10 @@ +{ + "compilerOptions": { + "module": "commonjs", + "esModuleInterop": true, + "moduleResolution": "node", + "target": "esnext", + "outDir": "dist" + }, + "include": ["src/**/*"] +} diff --git a/tests/test.spec.ts b/tests/test.spec.ts index 6f0c6df..35294fd 100644 --- a/tests/test.spec.ts +++ b/tests/test.spec.ts @@ -4,8 +4,8 @@ import { join, normalize } from 'path'; import * as rimraf from 'rimraf'; import * as shell from 'shelljs'; import { - prepareSingleFileReplaceTscAliasPaths, - ReplaceTscAliasPathsOptions + ReplaceTscAliasPathsOptions, + prepareSingleFileReplaceTscAliasPaths } from '../src'; import { newImportStatementRegex, newStringRegex } from '../src/utils'; @@ -92,7 +92,7 @@ it(`Import regex does not match edge cases from keywords in strings`, function ( // Run tests on projects. 9-11 are for testing fullpath file resolution [ - 1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 20, 21, 22, 23 + 1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 20, 21, 22, 23, 24 ].forEach((value) => { it(`Project ${value} runs after alias resolution`, () => { runTestProject(value);