Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

duplicate ext .json.json #20

Closed
Innei opened this issue Nov 2, 2021 · 14 comments
Closed

duplicate ext .json.json #20

Innei opened this issue Nov 2, 2021 · 14 comments

Comments

@Innei
Copy link

Innei commented Nov 2, 2021

Hi guy, I run this tsconfig-replace-paths --project src/tsconfig.json, but got an error.

Error: ENOENT: no such file or directory, open '/Users/xiaoxun/github/innei-repo/mx-space/mx-api-client/tsconfig.json.json'
    at Object.openSync (node:fs:582:3)
    at Object.readFileSync (node:fs:450:35)
    at loadConfig (/Users/xiaoxun/github/innei-repo/mx-space/mx-api-client/node_modules/.pnpm/tsconfig-replace-paths@0.0.10/node_modules/tsconfig-replace-paths/dist/commonjs/util.js:16:28)
    at loadConfig (/Users/xiaoxun/github/innei-repo/mx-space/mx-api-client/node_modules/.pnpm/tsconfig-replace-paths@0.0.10/node_modules/tsconfig-replace-paths/dist/commonjs/util.js:46:53)
    at Object.<anonymous> (/Users/xiaoxun/github/innei-repo/mx-space/mx-api-client/node_modules/.pnpm/tsconfig-replace-paths@0.0.10/node_modules/tsconfig-replace-paths/dist/commonjs/index.js:41:48)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:79:12) {
  errno: -2,
  syscall: 'open',
  code: 'ENOENT',
  path: '/Users/xiaoxun/github/innei-repo/mx-space/mx-api-client/tsconfig.json.json'
}

Why it read tsconfig.json.json instead of tsconfig.json.

tsc -v
Version 4.4.3
@jonkwheeler
Copy link
Owner

This might be a new error introduced recently. Will debug in a bit. Thanks for bringing it up.

@jonkwheeler
Copy link
Owner

In the mean time, what happens if you just set "tsconfig"?

@jonkwheeler
Copy link
Owner

So far I'm unable to replicate this issue. Could you provide anymore info? A dummy repo to test on? What happens with you more your src/tsconfig.json to the root tsconfig.json?

@Innei
Copy link
Author

Innei commented Nov 2, 2021

In the mean time, what happens if you just set "tsconfig"?

If set tsconfig, will open /Users/xiaoxun/github/innei-repo/mx-space/mx-api-client/src/tsconfig


xiaoxun in mx-api-client on  master [!] is 📦 v0.0.4 via  v16.6.0 
at 21:12:50 ❯ tsconfig-replace-paths --project src/tsconfig     
node:internal/fs/utils:343
    throw err;
    ^

Error: ENOENT: no such file or directory, open '/Users/xiaoxun/github/innei-repo/mx-space/mx-api-client/src/tsconfig'
    at Object.openSync (node:fs:582:3)
    at Object.readFileSync (node:fs:450:35)
    at loadConfig (/Users/xiaoxun/github/innei-repo/mx-space/mx-api-client/node_modules/.pnpm/tsconfig-replace-paths@0.0.10/node_modules/tsconfig-replace-paths/dist/commonjs/util.js:16:28)
    at Object.<anonymous> (/Users/xiaoxun/github/innei-repo/mx-space/mx-api-client/node_modules/.pnpm/tsconfig-replace-paths@0.0.10/node_modules/tsconfig-replace-paths/dist/commonjs/index.js:41:48)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:79:12)
    at node:internal/main/run_main_module:17:47 {
  errno: -2,
  syscall: 'open',
  code: 'ENOENT',
  path: '/Users/xiaoxun/github/innei-repo/mx-space/mx-api-client/src/tsconfig'
}

@Innei
Copy link
Author

Innei commented Nov 2, 2021

So far I'm unable to replicate this issue. Could you provide anymore info? A dummy repo to test on? What happens with you more your src/tsconfig.json to the root tsconfig.json?

And my src/tsconfig.json.


{
  "extends": "../tsconfig.json",
  "compilerOptions": {
    "declaration": true,
    "outDir": "../esm",
    "baseUrl": ".",
    "jsx": "react"
  },
  "include": [
    "./**/*.ts"
  ]
}

It extends root tsconfig. <root>/tsconfig.json is:

{
  "compilerOptions": {
    "target": "ES2017",
    "lib": [
      "ESNext",
      "DOM",
      "DOM.Iterable"
    ],
    "module": "ESNext",
    "moduleResolution": "node",
    "strict": true,
    "resolveJsonModule": true,
    "esModuleInterop": true,
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true,
    "sourceMap": true,
    "declaration": true,
    "outDir": "./dist",
    "baseUrl": "./src",
    "paths": {
      "~/*": [
        "*"
      ]
    },
    "plugins": [
      {
        "transform": "@zerollup/ts-transform-paths",
      }
    ]
  }
}

@Innei
Copy link
Author

Innei commented Nov 2, 2021

So far I'm unable to replicate this issue. Could you provide anymore info? A dummy repo to test on? What happens with you more your src/tsconfig.json to the root tsconfig.json?

I try to run with root dir tsconfig tsconfig-replace-paths --project tsconfig.json , it worked. But src/tsconfig.json not work

@jonkwheeler
Copy link
Owner

Okay thanks. I'll debug around having it in another directory.

@dborstelmann
Copy link

I'm having this issue as well. I'm trying to use this repo to convert my baseurl absolute paths to relative paths in compiled javascript. My full structure using npm workspaces:

tsconfig.json // just used for references in the editor
tsconfig.packages.json // shared compilerOptions for all packages
packages/foo/src. // the code for foo package I am compiling
packages/foo/tsconfig.json // adds src baseurl, hence the problem I am trying to solve

{
  "extends": "../../tsconfig.packages.json",
  "compilerOptions": {
    "rootDir": "src",
    "outDir": "dist",
    "baseUrl": "./src"
  }
}

packages/foo/tsconfig.build.json

{
  "extends": "./tsconfig.json",
  "exclude": [
    "src/**/*.spec.ts",
    "dist"
  ]
}

This last file is what I use to compile the packages. It uses the paths from packages/foo/tsconfig.json and removes a few things for tests. If I run tsconfig-replace-paths with tsconfig.build.json this is the result:

Error: ENOENT: no such file or directory, open 'blah/blah/repo-root/packages/foo/tsconfig.json.json'

@jonkwheeler
Copy link
Owner

@dborstelmann Want to clear something up here. Currently this package not support the exclude option. All this package does is convert paths within .d.ts files that have previously been compiled. tsc does the compiling. I'll use the example in the README to explain.

Sample package.json script

"config": {
  "dirBuild": "./dist",
  "dirSrc": "./src",
},
"scripts": {
  "build:commonjs": "yarn nuke:build && cross-env BABEL_ENV=commonjs babel $npm_package_config_dirSrc --out-dir $npm_package_config_dirBuild --extensions \".ts,.tsx,.js,.jsx\" --source-maps inline",
  "build:types:commonjs": "tsc --project tsconfig.types.cjs.json && tsconfig-replace-paths --project tsconfig.types.cjs.json",
  "build:types": "yarn build:types:commonjs",
  "build": "yarn build:commonjs && yarn build:types",
  "nuke:build": "rm -rf $npm_package_config_dirBuild",
}

A recap of this package:

Here we have an example for CommonJs, but ignore that because it can be anything. Running yarn build does a few things, it first compiles the files using yarn build:commonjs by using Babel, though you could use any compiler you want, including TS. Then it builds the types with yarn build:types in 2 steps. First, it uses tsc (TypeScipt Compiler) to build the types for all the files I need. This is important to understand, as the --project you set you can include and exclude all the files you need. Unfortunately, tsc does not compiler the paths correctly. It uses absolute paths when we really want relative paths. Thus, second is runs this package (tsconfig-replace-paths) on the same exact tsconfig file to find the output directory of the first build:types step with tsc and opens each of the type files up in that directory and replaces the absolute paths with relative paths.

I just wanted to clear that up for any who may read this.


Onto the issue, thank you for the example. I'll try to replicate now.

@jonkwheeler
Copy link
Owner

Good news. Finally able to replicate!

@jonkwheeler
Copy link
Owner

Alright. I found the bug, fixed the bug, then added in an extra safe guard against the double extension. Install 0.0.11.

@dborstelmann
Copy link

@jonkwheeler Thanks for the quick fix. Are you saying that this only replaces paths in .d.ts files or it also does it in the compiled js files?

@jonkwheeler
Copy link
Owner

I misspoke. It'll fix paths in all your js files. It won't compile those js files though. They need to first be compiled using your compiler of choice, and then run this package to open each of those files, change the paths, and save those files.

@dborstelmann
Copy link

Yup for sure, I wound up getting typescript-transform-paths working last night but I'll give this another go soon. Thanks for fixing it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants