-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): Option to inline JS source maps during sync (#5843)
- Loading branch information
1 parent
b9d5954
commit 7ce6dd4
Showing
5 changed files
with
71 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { | ||
readdirSync, | ||
existsSync, | ||
readFileSync, | ||
writeFileSync, | ||
unlinkSync, | ||
lstatSync, | ||
} from '@ionic/utils-fs'; | ||
import { join, extname } from 'path'; | ||
|
||
import type { Config } from '../definitions'; | ||
import { logger } from '../log'; | ||
|
||
function walkDirectory(dirPath: string) { | ||
const files = readdirSync(dirPath); | ||
files.forEach(file => { | ||
const targetFile = join(dirPath, file); | ||
if (existsSync(targetFile) && lstatSync(targetFile).isDirectory()) { | ||
walkDirectory(targetFile); | ||
} else { | ||
const mapFile = join(dirPath, `${file}.map`); | ||
if (extname(file) === '.js' && existsSync(mapFile)) { | ||
const bufMap = readFileSync(mapFile).toString('base64'); | ||
const bufFile = readFileSync(targetFile, 'utf8'); | ||
const result = bufFile.replace( | ||
`sourceMappingURL=${file}.map`, | ||
'sourceMappingURL=data:application/json;charset=utf-8;base64,' + | ||
bufMap, | ||
); | ||
writeFileSync(targetFile, result); | ||
unlinkSync(mapFile); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
export async function inlineSourceMaps( | ||
config: Config, | ||
platformName: string, | ||
): Promise<void> { | ||
let buildDir = ''; | ||
|
||
if (platformName == config.ios.name) { | ||
buildDir = await config.ios.webDirAbs; | ||
} | ||
|
||
if (platformName == config.android.name) { | ||
buildDir = await config.android.webDirAbs; | ||
} | ||
|
||
if (buildDir) { | ||
logger.info('Inlining sourcemaps'); | ||
walkDirectory(buildDir); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters