Bit: components overrides are modified after bit import

Created on 20 May 2020  路  3Comments  路  Source: teambit/bit

When syncing a repo, I'm getting all these unwanted overrides.

--- Compiler configuration (1.0.3 original)
+++ Compiler configuration (1.0.3 modified)
{
- "compilerPath": "typescript/bin/tsc",
- "compilerArguments": [
- - "--declaration"
- ],
- "compiledFileTypes": [
- - ".ts",
- - ".tsx"
- ],
- "configFileName": "tsconfig.json",
- "tsconfig": {
- - "compilerOptions": {
- - - "outDir": "dist",
- - - "target": "ES5",
- - - "sourceMap": false,
- - - "moduleResolution": "Node",
- - - "esModuleInterop": true,
- - - "module": "CommonJS",
- - - "allowSyntheticDefaultImports": true,
- - - "resolveJsonModule": true,
- - - "declaration": true,
- - - "experimentalDecorators": true,
- - - "inlineSourceMap": false,
- - - "inlineSources": false,
- - - "lib": [
- - - - "dom",
- - - - "es2015"
- - - ],
- - - "jsx": "react",
- - - "rootDir": "./",
- - - "removeComments": true,
- - - "typeRoots": [
- - - - "./node_modules/@types"
- - - ],
- - - "importHelpers": false
- - },
- - "include": [
- - - "./**/*"
- - ],
- - "exclude": [
- - - "node_modules",
- - - ".dependencies",
- - - "dist"
- - ]
- },
- "development": false,
- "copyPolicy": {
- - "ignorePatterns": [
- - - "package.json",
- - - "package-lock.json",
- - - "tsconfig.json"
- - ],
- - "disable": false
- }
}
{
+ "tsconfig": {
+ + "compilerOptions": {
+ + + "target": "ES5",
+ + + "module": "CommonJS"
+ + }
+ }
}

...

I believe this is happening because bit stores 'dynamic compiler configuration' in the component metadata during the _build process_.
When the component is imported, bit detects these configurations as missing overrides, and marks the components as modified.
(Sometimes, bit also bridges this gap and adds the changes to package.json)

I think this can be fixed in 2 places:

  1. Return nothing at getDynamicConfig()(?) in the TS and TS-react compilers. The configuration is default and static, and not needed as metadata. I talked to @qballer about it, but we never made a followup.
  2. Bit should insert this override when it is first generated, not during import. I'd much rather see it when creating the component, and not when another team member clones the project.

Reproduction

You can see when syncing bit in the Evangelist project.

  1. git clone [email protected]:teambit/evangelist.git
  2. run bit import
  3. run bit checkout -a latest

expected:

successful sync without side effects

actual:

all imported components have their override modified.

Workaround

  1. sync the project with bit import and bit checkout
    (bit diff should show a full list of overrides)
  2. (if exists) revert overrides in package.json (discard git local changes)
  3. Run bit build to recreate compiler overrides in local memory. (it might fail on first build, run again to pass)

--> bit diff should show 0 changes.

Specifications

  • Bit version: 14.7.7
  • Node version: 14.7.7
  • npm / yarn version: 1.22.0
  • Platform: MacOS
  • Bit compiler (include version): bit.envs/compilers/[email protected]
typbug

Most helpful comment

I believe this won't be relevant anymore after the harmony release. but let's keep monitor this in the future.
@KutnerUri @davidfirst

All 3 comments

actually, seems like bit build fixes this.
Seems like something that should happen automatically on import without having to build the project at all.

I added this script to my package.json to automate this:

"scripts": {
    "build": "react-scripts build",
    "eject": "react-scripts eject",
    "start": "react-scripts start",
    "test": "react-scripts test",
+   "setup": "bit init && bit import -e && bit build"
  },

I believe this won't be relevant anymore after the harmony release. but let's keep monitor this in the future.
@KutnerUri @davidfirst

Hi, I would like to add something to this bug if I may (LMK if this should be in a separate issue):

When I tried to import the latest version of a component (bit import && bit checkout 1.0.2 <component-name>), the main file was updated, but the file with the actual component code was overridden.

When I bit diff'ed the component, I was shown the same diff as in this issue (tsconfig), but ALSO all the changes from v1.0.2 were changed back to the code in the previous version, v1.0.1.

This diff is only reflected in Bit, as far as Git goes - the files are unmodified, so I can't even discard the changes.

I'm using 14.8.8. Any suggestion/thought would be appreciated!

UPDATE: I've found the issue and was able to solve it. It might happened because of me fiddling with stuff that I shouldn't have, OR there might be an actual bug. When I get the time I'll double-check and if there's indeed one I'll open a new issue accordingly. Thanks!

Was this page helpful?
0 / 5 - 0 ratings