Skip to content

Commit

Permalink
Create sourcemaps for easier debugging (react-native-community#996)
Browse files Browse the repository at this point in the history
* chore: create sourcemaps

* chore: get coverage for all files

* update collectCoverageFrom

* add files entry to cli-types

* remove scripts from tools

Co-authored-by: Michał Pierzchała <thymikee@gmail.com>
  • Loading branch information
molant and thymikee authored Feb 24, 2020
1 parent 8ed015a commit be0335b
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ build/
*.tsbuildinfo
.cache
.watchmanconfig
coverage
1 change: 1 addition & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ module.exports = {
}),
],
],
sourceMaps: true,
};
6 changes: 6 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,10 @@ module.exports = {
testMatch: ['<rootDir>/**/__tests__/*{.,-}test.[jt]s'],
},
],
collectCoverageFrom: [
'**/packages/*/**/*.ts',
'!**/__mocks__/**',
'!**/__tests__/**',
'!**/build/**',
],
};
4 changes: 4 additions & 0 deletions packages/cli-types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
"publishConfig": {
"access": "public"
},
"files": [
"build",
"!build/**/*.map"
],
"types": "build/index.d.ts",
"license": "MIT"
}
1 change: 1 addition & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
},
"files": [
"build",
"!build/**/*.map",
"setup_env.sh"
],
"engineStrict": true,
Expand Down
3 changes: 2 additions & 1 deletion packages/debugger-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"build:middleware": "tsc"
},
"files": [
"build"
"build",
"!build/**/*.map"
],
"devDependencies": {
"@babel/core": "^7.6.4",
Expand Down
1 change: 1 addition & 0 deletions packages/platform-android/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
},
"files": [
"build",
"!build/**/*.map",
"native_modules.gradle"
],
"devDependencies": {
Expand Down
1 change: 1 addition & 0 deletions packages/platform-ios/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
},
"files": [
"build",
"!build/**/*.map",
"native_modules.rb"
]
}
3 changes: 2 additions & 1 deletion packages/tools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"@types/node-fetch": "^2.3.3"
},
"files": [
"build"
"build",
"!build/**/*.map"
]
}
12 changes: 10 additions & 2 deletions scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,17 @@ function buildFile(file, silent) {
);
} else {
const options = Object.assign({}, transformOptions);
const transformed = babel.transformFileSync(file, options).code;
const filename = path.basename(destPath);

fs.writeFileSync(destPath, transformed);
let {code, map} = babel.transformFileSync(file, options);

if (!file.endsWith('.d.ts') && map.sources.length > 0) {
code = `${code}\n\n//# sourceMappingURL=${filename}.map`;
map.sources = [path.relative(path.dirname(destPath), file)];
fs.writeFileSync(`${destPath}.map`, JSON.stringify(map));
}

fs.writeFileSync(destPath, code);

silent ||
process.stdout.write(
Expand Down

0 comments on commit be0335b

Please sign in to comment.